Skip to content

Commit 33cba85

Browse files
committed
fscache: Fix fscache_cookie_put() to not deref after dec
fscache_cookie_put() accesses the cookie it has just put inside the tracepoint that monitors the change - but this is something it's not allowed to do if we didn't reduce the count to zero. Fix this by dropping most of those values from the tracepoint and grabbing the cookie debug ID before doing the dec. Also take the opportunity to switch over the usage and where arguments on the tracepoint to put the reason last. Fixes: a18feb5 ("fscache: Add tracepoints") Signed-off-by: David Howells <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/162431203107.2908479.3259582550347000088.stgit@warthog.procyon.org.uk/
1 parent 35b7257 commit 33cba85

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

fs/fscache/cookie.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ struct fscache_cookie *fscache_hash_cookie(struct fscache_cookie *candidate)
225225

226226
collision:
227227
if (test_and_set_bit(FSCACHE_COOKIE_ACQUIRED, &cursor->flags)) {
228-
trace_fscache_cookie(cursor, fscache_cookie_collision,
229-
atomic_read(&cursor->usage));
228+
trace_fscache_cookie(cursor->debug_id, atomic_read(&cursor->usage),
229+
fscache_cookie_collision);
230230
pr_err("Duplicate cookie detected\n");
231231
fscache_print_cookie(cursor, 'O');
232232
fscache_print_cookie(candidate, 'N');
@@ -305,7 +305,8 @@ struct fscache_cookie *__fscache_acquire_cookie(
305305

306306
cookie = fscache_hash_cookie(candidate);
307307
if (!cookie) {
308-
trace_fscache_cookie(candidate, fscache_cookie_discard, 1);
308+
trace_fscache_cookie(candidate->debug_id, 1,
309+
fscache_cookie_discard);
309310
goto out;
310311
}
311312

@@ -866,8 +867,9 @@ void fscache_cookie_put(struct fscache_cookie *cookie,
866867
_enter("%x", cookie->debug_id);
867868

868869
do {
870+
unsigned int cookie_debug_id = cookie->debug_id;
869871
usage = atomic_dec_return(&cookie->usage);
870-
trace_fscache_cookie(cookie, where, usage);
872+
trace_fscache_cookie(cookie_debug_id, usage, where);
871873

872874
if (usage > 0)
873875
return;

fs/fscache/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static inline void fscache_cookie_get(struct fscache_cookie *cookie,
291291
{
292292
int usage = atomic_inc_return(&cookie->usage);
293293

294-
trace_fscache_cookie(cookie, where, usage);
294+
trace_fscache_cookie(cookie->debug_id, usage, where);
295295
}
296296

297297
/*

fs/fscache/netfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int __fscache_register_netfs(struct fscache_netfs *netfs)
3737
if (!cookie)
3838
goto already_registered;
3939
if (cookie != candidate) {
40-
trace_fscache_cookie(candidate, fscache_cookie_discard, 1);
40+
trace_fscache_cookie(candidate->debug_id, 1, fscache_cookie_discard);
4141
fscache_free_cookie(candidate);
4242
}
4343

include/trace/events/fscache.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,37 +160,27 @@ fscache_cookie_traces;
160160

161161

162162
TRACE_EVENT(fscache_cookie,
163-
TP_PROTO(struct fscache_cookie *cookie,
164-
enum fscache_cookie_trace where,
165-
int usage),
163+
TP_PROTO(unsigned int cookie_debug_id,
164+
int usage,
165+
enum fscache_cookie_trace where),
166166

167-
TP_ARGS(cookie, where, usage),
167+
TP_ARGS(cookie_debug_id, usage, where),
168168

169169
TP_STRUCT__entry(
170170
__field(unsigned int, cookie )
171-
__field(unsigned int, parent )
172171
__field(enum fscache_cookie_trace, where )
173172
__field(int, usage )
174-
__field(int, n_children )
175-
__field(int, n_active )
176-
__field(u8, flags )
177173
),
178174

179175
TP_fast_assign(
180-
__entry->cookie = cookie->debug_id;
181-
__entry->parent = cookie->parent ? cookie->parent->debug_id : 0;
176+
__entry->cookie = cookie_debug_id;
182177
__entry->where = where;
183178
__entry->usage = usage;
184-
__entry->n_children = atomic_read(&cookie->n_children);
185-
__entry->n_active = atomic_read(&cookie->n_active);
186-
__entry->flags = cookie->flags;
187179
),
188180

189-
TP_printk("%s c=%08x u=%d p=%08x Nc=%d Na=%d f=%02x",
181+
TP_printk("%s c=%08x u=%d",
190182
__print_symbolic(__entry->where, fscache_cookie_traces),
191-
__entry->cookie, __entry->usage,
192-
__entry->parent, __entry->n_children, __entry->n_active,
193-
__entry->flags)
183+
__entry->cookie, __entry->usage)
194184
);
195185

196186
TRACE_EVENT(fscache_netfs,

0 commit comments

Comments
 (0)