From d38ef181d8250b083553ec95209c28c1dc11fa99 Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Wed, 23 Mar 2022 01:21:06 -0500 Subject: [PATCH] LU-15689 libcfs: libcfs_debug_mb set incorrectly on init If libcfs_debug_mb parameter is specified to insmod (i.e. set before module is initialized) then it does not get initialized correctly. libcfs_param_debug_mb_set() expects cfs_trace_get_debug_mb() to return zero if the module has not been initialized yet, but cfs_trace_get_debug_mb() will return 1 in this case. Modify cfs_trace_get_debug_mb() to return zero as expected. A related issue is that in this case we need to call cfs_trace_get_debug_mb() after cfs_tracefile_init() so that libcfs_debug_mb gets the same value it would get if we had set it after module init. When libcfs_debug_mb is specified to insmod, libcfs_debug_init() divides its value by num_possible_cpus(), but this is already done in libcfs_param_debug_mb_set(). Test-Parameters: trivial Fixes: 8b78a3ffb5 ("LU-9859 libcfs: always range-check libcfs_debug_mb setting.") HPE-bug-id: LUS-10839 Signed-off-by: Chris Horn Change-Id: I1003758156acb5cf6ea30bbdfd7b45a743a2a5aa Reviewed-on: https://review.whamcloud.com/46925 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- libcfs/libcfs/debug.c | 9 +++------ libcfs/libcfs/tracefile.c | 5 ++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libcfs/libcfs/debug.c b/libcfs/libcfs/debug.c index f8ad146..a0dbffa 100644 --- a/libcfs/libcfs/debug.c +++ b/libcfs/libcfs/debug.c @@ -684,12 +684,10 @@ int libcfs_debug_init(unsigned long bufsize) /* If libcfs_debug_mb is uninitialized then just make the * total buffers smp_num_cpus * TCD_MAX_PAGES */ - if (max < num_possible_cpus()) { + if (max < num_possible_cpus()) max = TCD_MAX_PAGES; - } else { - max = (max / num_possible_cpus()); + else max <<= (20 - PAGE_SHIFT); - } rc = cfs_tracefile_init(max); if (rc) @@ -697,8 +695,7 @@ int libcfs_debug_init(unsigned long bufsize) libcfs_register_panic_notifier(); kernel_param_lock(THIS_MODULE); - if (libcfs_debug_mb == 0) - libcfs_debug_mb = cfs_trace_get_debug_mb(); + libcfs_debug_mb = cfs_trace_get_debug_mb(); kernel_param_unlock(THIS_MODULE); return rc; } diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index ac473c5..d79ec06 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -967,7 +967,10 @@ int cfs_trace_get_debug_mb(void) up_read(&cfs_tracefile_sem); - return (total_pages >> (20 - PAGE_SHIFT)) + 1; + if (total_pages) + return (total_pages >> (20 - PAGE_SHIFT)) + 1; + else + return 0; } static int tracefiled(void *arg) -- 1.8.3.1