Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

svcrdma: fix miss destroy percpu_counter in svc_rdma_proc_init()

There's issue as follows:
RPC: Registered rdma transport module.
RPC: Registered rdma backchannel transport module.
RPC: Unregistered rdma transport module.
RPC: Unregistered rdma backchannel transport module.
BUG: unable to handle page fault for address: fffffbfff80c609a
PGD 123fee067 P4D 123fee067 PUD 123fea067 PMD 10c624067 PTE 0
Oops: Oops: 0000 [#1] PREEMPT SMP KASAN NOPTI
RIP: 0010:percpu_counter_destroy_many+0xf7/0x2a0
Call Trace:
<TASK>
__die+0x1f/0x70
page_fault_oops+0x2cd/0x860
spurious_kernel_fault+0x36/0x450
do_kern_addr_fault+0xca/0x100
exc_page_fault+0x128/0x150
asm_exc_page_fault+0x26/0x30
percpu_counter_destroy_many+0xf7/0x2a0
mmdrop+0x209/0x350
finish_task_switch.isra.0+0x481/0x840
schedule_tail+0xe/0xd0
ret_from_fork+0x23/0x80
ret_from_fork_asm+0x1a/0x30
</TASK>

If register_sysctl() return NULL, then svc_rdma_proc_cleanup() will not
destroy the percpu counters which init in svc_rdma_proc_init().
If CONFIG_HOTPLUG_CPU is enabled, residual nodes may be in the
'percpu_counters' list. The above issue may occur once the module is
removed. If the CONFIG_HOTPLUG_CPU configuration is not enabled, memory
leakage occurs.
To solve above issue just destroy all percpu counters when
register_sysctl() return NULL.

Fixes: 1e7e55731628 ("svcrdma: Restore read and write stats")
Fixes: 22df5a22462e ("svcrdma: Convert rdma_stat_sq_starve to a per-CPU counter")
Fixes: df971cd853c0 ("svcrdma: Convert rdma_stat_recv to a per-CPU counter")
Signed-off-by: Ye Bin <yebin10@huawei.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>

authored by

Ye Bin and committed by
Chuck Lever
ce89e742 573954a9

+14 -5
+14 -5
net/sunrpc/xprtrdma/svc_rdma.c
··· 233 233 234 234 rc = percpu_counter_init(&svcrdma_stat_read, 0, GFP_KERNEL); 235 235 if (rc) 236 - goto out_err; 236 + goto err; 237 237 rc = percpu_counter_init(&svcrdma_stat_recv, 0, GFP_KERNEL); 238 238 if (rc) 239 - goto out_err; 239 + goto err_read; 240 240 rc = percpu_counter_init(&svcrdma_stat_sq_starve, 0, GFP_KERNEL); 241 241 if (rc) 242 - goto out_err; 242 + goto err_recv; 243 243 rc = percpu_counter_init(&svcrdma_stat_write, 0, GFP_KERNEL); 244 244 if (rc) 245 - goto out_err; 245 + goto err_sq; 246 246 247 247 svcrdma_table_header = register_sysctl("sunrpc/svc_rdma", 248 248 svcrdma_parm_table); 249 + if (!svcrdma_table_header) 250 + goto err_write; 251 + 249 252 return 0; 250 253 251 - out_err: 254 + err_write: 255 + rc = -ENOMEM; 256 + percpu_counter_destroy(&svcrdma_stat_write); 257 + err_sq: 252 258 percpu_counter_destroy(&svcrdma_stat_sq_starve); 259 + err_recv: 253 260 percpu_counter_destroy(&svcrdma_stat_recv); 261 + err_read: 254 262 percpu_counter_destroy(&svcrdma_stat_read); 263 + err: 255 264 return rc; 256 265 } 257 266