From 72d907f23ef092d63caac96ca3af6fcae4506008 Mon Sep 17 00:00:00 2001 From: Jinjie Ruan Date: Wed, 2 Sep 2026 15:47:59 +0800 Subject: lib/vsprintf: Use acquire/release for ptr_key publication Replace the smp_wmb() + WRITE_ONCE() and READ_ONCE() + smp_rmb() barrier pair with smp_store_release()/smp_load_acquire() on filled_random_ptr_key. This expresses the publish/subscribe pattern more clearly and allows architectures with native acquire/release instructions (e.g. arm64's STLR/LDAR) to avoid the cost of full one-way barriers (DMB ISHST/ISHLD). No functional change intended. Cc: Petr Mladek Cc: Steven Rostedt Cc: Andy Shevchenko Cc: Rasmus Villemoes Cc: Sergey Senozhatsky Cc: Andrew Morton Assisted-by: DeepSeek:DeepSeek-V3 Signed-off-by: Jinjie Ruan Reviewed-by: Petr Mladek Link: https://patch.msgid.link/20260902074805.398540-3-ruanjinjie@huawei.com Signed-off-by: Petr Mladek --- lib/vsprintf.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/vsprintf.c b/lib/vsprintf.c index e285e8bc4712..d6f235e143b7 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -762,9 +762,8 @@ static int fill_ptr_key(struct notifier_block *nb, unsigned long action, void *d { get_random_bytes(&ptr_key, sizeof(ptr_key)); - /* Pairs with smp_rmb() before reading ptr_key. */ - smp_wmb(); - WRITE_ONCE(filled_random_ptr_key, true); + /* Pairs with smp_load_acquire() before reading ptr_key. */ + smp_store_release(&filled_random_ptr_key, true); return NOTIFY_DONE; } @@ -781,12 +780,10 @@ static inline int __ptr_to_hashval(const void *ptr, unsigned long *hashval_out) { unsigned long hashval; - if (!READ_ONCE(filled_random_ptr_key)) + /* Pairs with smp_store_release() after writing ptr_key. */ + if (!smp_load_acquire(&filled_random_ptr_key)) return -EBUSY; - /* Pairs with smp_wmb() after writing ptr_key. */ - smp_rmb(); - #ifdef CONFIG_64BIT hashval = (unsigned long)siphash_1u64((u64)ptr, &ptr_key); /* -- cgit v1.2.3 From a75d9cc33d8102cd9fd103a7f0466b8ffb2a2d1b Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Tue, 14 Jul 2026 14:21:43 +0200 Subject: lib/vsprintf: Use EXPORT_SYMBOL_IF_KUNIT() to export symbols Replace EXPORT_SYMBOL_FOR_MODULES() with EXPORT_SYMBOL_IF_KUNIT() to mark the symbols as visible only if CONFIG_KUNIT is enabled. Kunit test should import the namespace EXPORTED_FOR_KUNIT_TESTING to use these marked symbols. This is the standard way for all KUnit tests. Signed-off-by: Andy Shevchenko Acked-by: Tamir Duberstein Link: https://patch.msgid.link/20260714122143.743227-1-andriy.shevchenko@linux.intel.com Signed-off-by: Petr Mladek --- lib/tests/printf_kunit.c | 1 + lib/vsprintf.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c index eccf041ebd56..290d59b22c29 100644 --- a/lib/tests/printf_kunit.c +++ b/lib/tests/printf_kunit.c @@ -876,3 +876,4 @@ kunit_test_suite(printf_test_suite); MODULE_AUTHOR("Rasmus Villemoes "); MODULE_DESCRIPTION("Test cases for printf facility"); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index d6f235e143b7..a430753dd702 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -25,6 +25,7 @@ #include /* for KSYM_SYMBOL_LEN */ #include #include +#include #include #include #include @@ -54,12 +55,13 @@ #include /* cpu_to_le16 */ #include -#include +#include + #include "kstrtox.h" /* Disable pointer hashing if requested */ bool no_hash_pointers __ro_after_init; -EXPORT_SYMBOL_FOR_MODULES(no_hash_pointers, "printf_kunit"); +EXPORT_SYMBOL_IF_KUNIT(no_hash_pointers); /* * Hashed pointers policy selected by "hash_pointers=..." boot param @@ -847,7 +849,7 @@ static char *default_pointer(char *buf, char *end, const void *ptr, } int kptr_restrict __read_mostly; -EXPORT_SYMBOL_FOR_MODULES(kptr_restrict, "printf_kunit"); +EXPORT_SYMBOL_IF_KUNIT(kptr_restrict); static noinline_for_stack char *restricted_pointer(char *buf, char *end, const void *ptr, -- cgit v1.2.3