Skip to content

Commit 17d912d

Browse files
ematsumiyasmfrench
authored andcommitted
smb: client: fix (remove) drop_dir_cache module parameter
Being a module parameter, it's possible to do: # modprobe cifs drop_dir_cache=1 Which will lead to a crash, because cifs_tcp_ses_list hasn't been initialized yet: [ 168.242624] BUG: kernel NULL pointer dereference, address: 0000000000000010 [ 168.242952] #PF: supervisor read access in kernel mode [ 168.243175] #PF: error_code(0x0000) - not-present page [ 168.243394] PGD 0 P4D 0 [ 168.243524] Oops: Oops: 0000 [#1] SMP NOPTI [ 168.243703] CPU: 2 UID: 0 PID: 1105 Comm: modprobe Not tainted 7.0.0-lku #5 PREEMPT(lazy) [ 168.244054] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.17.0-2-g4f253b9b-prebuilt.qemu.org 04/01/2014 [ 168.244557] RIP: 0010:cifs_param_set_drop_dir_cache+0x7c/0x100 [cifs] ... [ 168.248785] Call Trace: [ 168.248915] <TASK> [ 168.249023] parse_args+0x285/0x3a0 [ 168.249204] ? __pfx_unknown_module_param_cb+0x10/0x10 [ 168.249448] load_module+0x192b/0x1bb0 [ 168.249637] ? __pfx_unknown_module_param_cb+0x10/0x10 [ 168.249882] ? kernel_read_file+0x27d/0x2b0 [ 168.250088] init_module_from_file+0xce/0xf0 [ 168.250291] idempotent_init_module+0xfb/0x2f0 [ 168.250496] __x64_sys_finit_module+0x5a/0xa0 [ 168.250694] do_syscall_64+0xe0/0x5a0 [ 168.250863] ? exc_page_fault+0x65/0x160 [ 168.251050] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 168.251284] RIP: 0033:0x7fcaa12b774d Instead of fixing this with some kind of "is module initialized" approach, this patch instead moves that functionality to procfs, setting a write op for the existing open_dirs entry, where writing a 0 to it will drop the cached directory entries. Also make it available only when CONFIG_CIFS_DEBUG=y. A small change needed now is to not call flush_delayed_work() on invalidate_all_cached_dirs() when called from procfs (can't sleep in that context). So add a @sync arg to invalidate_all_cached_dirs() to control when to flush the delayed works. Fixes: dde6667 ("smb: client: add drop_dir_cache module parameter to invalidate cached dirents") Signed-off-by: Enzo Matsumiya <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 2757ad3 commit 17d912d

6 files changed

Lines changed: 59 additions & 45 deletions

File tree

fs/smb/client/cached_dir.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb)
593593
* Invalidate all cached dirs when a TCON has been reset
594594
* due to a session loss.
595595
*/
596-
void invalidate_all_cached_dirs(struct cifs_tcon *tcon)
596+
void invalidate_all_cached_dirs(struct cifs_tcon *tcon, bool sync)
597597
{
598598
struct cached_fids *cfids = tcon->cfids;
599599
struct cached_fid *cfid, *q;
@@ -625,7 +625,8 @@ void invalidate_all_cached_dirs(struct cifs_tcon *tcon)
625625

626626
/* run laundromat unconditionally now as there might have been previously queued work */
627627
mod_delayed_work(cfid_put_wq, &cfids->laundromat_work, 0);
628-
flush_delayed_work(&cfids->laundromat_work);
628+
if (sync)
629+
flush_delayed_work(&cfids->laundromat_work);
629630
}
630631

631632
static void

fs/smb/client/cached_dir.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void close_cached_dir(struct cached_fid *cfid);
9090
void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
9191
const char *name, struct cifs_sb_info *cifs_sb);
9292
void close_all_cached_dirs(struct cifs_sb_info *cifs_sb);
93-
void invalidate_all_cached_dirs(struct cifs_tcon *tcon);
93+
void invalidate_all_cached_dirs(struct cifs_tcon *tcon, bool sync);
9494
bool cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]);
9595

9696
#endif /* _CACHED_DIR_H */

fs/smb/client/cifs_debug.c

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
306306
LIST_HEAD(entry);
307307

308308
seq_puts(m, "# Version:1\n");
309+
#ifdef CONFIG_CIFS_DEBUG
310+
seq_puts(m, "# Write 0 to this file to drop all cached directory entries\n");
311+
#endif /* CONFIG_CIFS_DEBUG */
309312
seq_puts(m, "# Format:\n");
310313
seq_puts(m, "# <tree id> <sess id> <persistent fid> <lease-key> <path>\n");
311314

@@ -353,6 +356,51 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
353356
return 0;
354357
}
355358

359+
#ifdef CONFIG_CIFS_DEBUG
360+
static int cifs_debug_dirs_proc_open(struct inode *inode, struct file *file)
361+
{
362+
return single_open(file, cifs_debug_dirs_proc_show, NULL);
363+
}
364+
365+
/* Drop all cached directory entries across all CIFS mounts. */
366+
static ssize_t cifs_debug_dirs_proc_write(struct file *file, const char __user *buffer,
367+
size_t count, loff_t *ppos)
368+
{
369+
int rc, v;
370+
371+
rc = kstrtoint_from_user(buffer, count, 10, &v);
372+
if (rc)
373+
return rc;
374+
375+
if (v == 0) {
376+
struct TCP_Server_Info *server;
377+
struct cifs_ses *ses;
378+
struct cifs_tcon *tcon;
379+
380+
spin_lock(&cifs_tcp_ses_lock);
381+
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
382+
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
383+
if (cifs_ses_exiting(ses))
384+
continue;
385+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list)
386+
invalidate_all_cached_dirs(tcon, false);
387+
}
388+
}
389+
spin_unlock(&cifs_tcp_ses_lock);
390+
}
391+
392+
return count;
393+
}
394+
395+
static const struct proc_ops cifs_debug_dirs_proc_ops = {
396+
.proc_open = cifs_debug_dirs_proc_open,
397+
.proc_read = seq_read,
398+
.proc_lseek = seq_lseek,
399+
.proc_release = single_release,
400+
.proc_write = cifs_debug_dirs_proc_write,
401+
};
402+
#endif /* CONFIG_CIFS_DEBUG */
403+
356404
static __always_inline const char *compression_alg_str(__le16 alg)
357405
{
358406
switch (alg) {
@@ -885,9 +933,11 @@ cifs_proc_init(void)
885933
proc_create_single("open_files", 0400, proc_fs_cifs,
886934
cifs_debug_files_proc_show);
887935

888-
proc_create_single("open_dirs", 0400, proc_fs_cifs,
889-
cifs_debug_dirs_proc_show);
890-
936+
#ifdef CONFIG_CIFS_DEBUG
937+
proc_create("open_dirs", 0600, proc_fs_cifs, &cifs_debug_dirs_proc_ops);
938+
#else /* CONFIG_CIFS_DEBUG */
939+
proc_create_single("open_dirs", 0400, proc_fs_cifs, cifs_debug_dirs_proc_show);
940+
#endif /* !CONFIG_CIFS_DEBUG */
891941
proc_create("Stats", 0644, proc_fs_cifs, &cifs_stats_proc_ops);
892942
proc_create("cifsFYI", 0644, proc_fs_cifs, &cifsFYI_proc_ops);
893943
proc_create("traceSMB", 0644, proc_fs_cifs, &traceSMB_proc_ops);

fs/smb/client/cifsfs.c

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -127,43 +127,6 @@ atomic64_t cifs_dircache_bytes_used = ATOMIC64_INIT(0);
127127
atomic_t cifs_sillycounter;
128128
atomic_t cifs_tmpcounter;
129129

130-
/*
131-
* Write-only module parameter to drop all cached directory entries across
132-
* all CIFS mounts. Echo a non-zero value to trigger.
133-
*/
134-
static void cifs_drop_all_dir_caches(void)
135-
{
136-
struct TCP_Server_Info *server;
137-
struct cifs_ses *ses;
138-
struct cifs_tcon *tcon;
139-
140-
spin_lock(&cifs_tcp_ses_lock);
141-
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
142-
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
143-
if (cifs_ses_exiting(ses))
144-
continue;
145-
list_for_each_entry(tcon, &ses->tcon_list, tcon_list)
146-
invalidate_all_cached_dirs(tcon);
147-
}
148-
}
149-
spin_unlock(&cifs_tcp_ses_lock);
150-
}
151-
152-
static int cifs_param_set_drop_dir_cache(const char *val, const struct kernel_param *kp)
153-
{
154-
bool bv;
155-
int rc = kstrtobool(val, &bv);
156-
157-
if (rc)
158-
return rc;
159-
if (bv)
160-
cifs_drop_all_dir_caches();
161-
return 0;
162-
}
163-
164-
module_param_call(drop_dir_cache, cifs_param_set_drop_dir_cache, NULL, NULL, 0200);
165-
MODULE_PARM_DESC(drop_dir_cache, "Write 1 to drop all cached directory entries across all CIFS mounts");
166-
167130
#ifdef CONFIG_CIFS_STATS2
168131
unsigned int slow_rsp_threshold = 1;
169132
module_param(slow_rsp_threshold, uint, 0644);

fs/smb/client/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
393393
}
394394
spin_unlock(&tcon->open_file_lock);
395395

396-
invalidate_all_cached_dirs(tcon);
396+
invalidate_all_cached_dirs(tcon, true);
397397
spin_lock(&tcon->tc_lock);
398398
if (tcon->status == TID_IN_FILES_INVALIDATE)
399399
tcon->status = TID_NEED_TCON;

fs/smb/client/smb2pdu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,7 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon)
22572257
}
22582258
spin_unlock(&ses->chan_lock);
22592259

2260-
invalidate_all_cached_dirs(tcon);
2260+
invalidate_all_cached_dirs(tcon, true);
22612261

22622262
rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, server,
22632263
(void **) &req,

0 commit comments

Comments
 (0)