smb: client: fix (remove) drop_dir_cache module parameter
Subsystems (2)
PATCH v3 1/1 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.
---
v3:
- missing change from CONFIG_CIFS_DEBUG2 to DEBUG
- change open_dirs entry perms from 0644 to 0600 (when DEBUG=y) to keep similar when DEBUG=n (0400)
v2:
- change to depend on CONFIG_CIFS_DEBUG instead of DEBUG2 (as per Bharath's request)
- remove redundant !IS_ENABLED(CONFIG_CIFS_DEBUG2) check from cifs_debug_dirs_proc_write() (already wrapped in ifdef)
fs/smb/client/cached_dir.c | 5 ++-- fs/smb/client/cached_dir.h | 2 +- fs/smb/client/cifs_debug.c | 56 ++++++++++++++++++++++++++++++++++++-- fs/smb/client/cifsfs.c | 37 ------------------------- fs/smb/client/file.c | 2 +- fs/smb/client/smb2pdu.c | 2 +- 6 files changed, 59 insertions(+), 45 deletions(-)
fs/smb/client/cached_dir.c +3 -2
@@ -593,7 +593,7 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb)* Invalidate all cached dirs when a TCON has been reset * due to a session loss. */ -void invalidate_all_cached_dirs (struct cifs_tcon *tcon) +void invalidate_all_cached_dirs (struct cifs_tcon *tcon,bool sync) {struct cached_fids *cfids = tcon->cfids;struct cached_fid *cfid, *q;
@@ -625,7 +625,8 @@ void invalidate_all_cached_dirs(struct cifs_tcon *tcon)/* run laundromat unconditionally now as there might have been previously queued work */ mod_delayed_work (cfid_put_wq, &cfids->laundromat_work,0 ); -flush_delayed_work (&cfids->laundromat_work); +if (sync) +flush_delayed_work (&cfids->laundromat_work); } static void
fs/smb/client/cached_dir.h +1 -1
@@ -90,7 +90,7 @@ void close_cached_dir(struct cached_fid *cfid);void drop_cached_dir_by_name (const unsigned int xid,struct cifs_tcon *tcon,const char *name,struct cifs_sb_info *cifs_sb);void close_all_cached_dirs (struct cifs_sb_info *cifs_sb); -void invalidate_all_cached_dirs (struct cifs_tcon *tcon); +void invalidate_all_cached_dirs (struct cifs_tcon *tcon,bool sync);bool cached_dir_lease_break (struct cifs_tcon *tcon,__u8 lease_key[16 ]);#endif /* _CACHED_DIR_H */
fs/smb/client/cifs_debug.c +53 -3
74 lines not on this page · raw message
fs/smb/client/cifsfs.c +0 -37
@@ -127,43 +127,6 @@ atomic64_t cifs_dircache_bytes_used = ATOMIC64_INIT(0);atomic_t cifs_sillycounter;atomic_t cifs_tmpcounter; -/* -* Write-only module parameter to drop all cached directory entries across -* all CIFS mounts. Echo a non-zero value to trigger. -*/ -static void cifs_drop_all_dir_caches (void ) -{ -struct TCP_Server_Info *server; -struct cifs_ses *ses; -struct cifs_tcon *tcon; - -spin_lock (&cifs_tcp_ses_lock); -list_for_each_entry (server, &cifs_tcp_ses_list, tcp_ses_list) { -list_for_each_entry (ses, &server->smb_ses_list, smb_ses_list) { -if (cifs_ses_exiting (ses)) -continue ; -list_for_each_entry (tcon, &ses->tcon_list, tcon_list) -invalidate_all_cached_dirs (tcon); - } - } -spin_unlock (&cifs_tcp_ses_lock); -} - -static int cifs_param_set_drop_dir_cache (const char *val,const struct kernel_param *kp) -{ -bool bv; -int rc =kstrtobool (val, &bv); - -if (rc) -return rc; -if (bv) -cifs_drop_all_dir_caches (); -return 0 ; -} - -module_param_call (drop_dir_cache, cifs_param_set_drop_dir_cache,NULL ,NULL ,0200 ); -MODULE_PARM_DESC (drop_dir_cache,"Write 1 to drop all cached directory entries across all CIFS mounts" ); -#ifdef CONFIG_CIFS_STATS2 unsigned int slow_rsp_threshold =1 ;module_param (slow_rsp_threshold, uint,0644 );
fs/smb/client/file.c +1 -1
@@ -393,7 +393,7 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon) }spin_unlock (&tcon->open_file_lock); -invalidate_all_cached_dirs (tcon); +invalidate_all_cached_dirs (tcon, true);spin_lock (&tcon->tc_lock);if (tcon->status ==TID_IN_FILES_INVALIDATE ) tcon->status =TID_NEED_TCON ;
fs/smb/client/smb2pdu.c +1 -1
@@ -2257,7 +2257,7 @@ SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon) }spin_unlock (&ses->chan_lock); -invalidate_all_cached_dirs (tcon); +invalidate_all_cached_dirs (tcon, true); rc = smb2_plain_req_init(SMB2_TREE_DISCONNECT, tcon, server, (void **) &req,
Signature · 1 line
2.53.0