* [LTP] [PATCH v9 0/2] shmctl03: Fix 32-bit compat mode failure @ 2026-08-31 8:16 Wei Gao via ltp 2026-08-31 8:16 ` [LTP] [PATCH v9 1/2] lib: Extend tst_assert_ulong() with enum flags Wei Gao via ltp 2026-08-31 8:16 ` [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp 0 siblings, 2 replies; 7+ messages in thread From: Wei Gao via ltp @ 2026-08-31 8:16 UTC (permalink / raw) To: ltp v8->v9: - use enum for type of tst_assert_flags - update comments format Wei Gao (2): lib: Extend tst_assert_ulong() with enum flags shmctl03: Fix 32-bit compat mode failure include/tst_assert.h | 36 ++++++++++++++++++--- lib/tst_assert.c | 26 +++++++++++---- testcases/kernel/syscalls/shmctl/shmctl03.c | 13 ++++++-- 3 files changed, 61 insertions(+), 14 deletions(-) -- 2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH v9 1/2] lib: Extend tst_assert_ulong() with enum flags 2026-08-31 8:16 [LTP] [PATCH v9 0/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp @ 2026-08-31 8:16 ` Wei Gao via ltp 2026-08-31 9:00 ` [LTP] " linuxtestproject.agent 2026-09-02 9:04 ` [LTP] [PATCH v9 1/2] " Petr Vorel 2026-08-31 8:16 ` [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp 1 sibling, 2 replies; 7+ messages in thread From: Wei Gao via ltp @ 2026-08-31 8:16 UTC (permalink / raw) To: ltp Introduce enum tst_assert_flags (including TST_ASSERT_NONE, TST_ASSERT_SATURATED_INT, and TST_ASSERT_TRUNC_32BIT) to tst_assert_ulong(). This enables type-safe handling of 32-bit compat-mode truncation and clamping behaviors on 64-bit kernels when verifying sysfs/procfs limits. Signed-off-by: Wei Gao <wegao@suse.com> --- include/tst_assert.h | 36 +++++++++++++++++++++++++++++++----- lib/tst_assert.c | 26 ++++++++++++++++++++------ 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/include/tst_assert.h b/include/tst_assert.h index dcb62dfea..9154b7249 100644 --- a/include/tst_assert.h +++ b/include/tst_assert.h @@ -21,14 +21,40 @@ void tst_assert_int(const char *file, const int lineno, #define TST_ASSERT_FILE_INT(path, prefix, val) \ tst_assert_file_int(__FILE__, __LINE__, path, prefix, val) -/* - * Same as tst_assert_int() but for unsigned long. +/** + * enum tst_assert_flags - Flags for tst_assert_ulong(). + * + * @TST_ASSERT_NONE: No flags, default direct comparison. + * @TST_ASSERT_SATURATED_INT: Clamps the value at %INT_MAX if it exceeds it. + * @TST_ASSERT_TRUNC_32BIT: Keeps only the low 32 bits of the read value, + * truncating any higher bits. + */ +enum tst_assert_flags { + TST_ASSERT_NONE = 0x00, + TST_ASSERT_SATURATED_INT = 0x01, + TST_ASSERT_TRUNC_32BIT = 0x02, +}; + +/** + * tst_assert_ulong() - Assert that an unsigned long value in a file matches. + * @file: The source file of the assertion (usually __FILE__). + * @lineno: The source line number of the assertion (usually __LINE__). + * @path: Path to the sysfs or procfs file to read from. + * @val: The expected unsigned long value to compare against. + * @flags: Bitwise flags controlling how the read value is processed. + * See &enum tst_assert_flags. + * + * This function reads an integer value from the file specified by @path + * and compares it with @val. It allows handling of 32-bit compat mode + * truncation/clamping on 64-bit systems via @flags. */ void tst_assert_ulong(const char *file, const int lineno, - const char *path, unsigned long val); + const char *path, unsigned long val, + enum tst_assert_flags flags); -#define TST_ASSERT_ULONG(path, val) \ - tst_assert_ulong(__FILE__, __LINE__, path, val) +#define TST_ASSERT_ULONG(path, val, ...) \ + tst_assert_ulong(__FILE__, __LINE__, path, val, \ + TST_2_(dummy, ##__VA_ARGS__, TST_ASSERT_NONE)) /* * Asserts that integer value stored in the prefix field of file pointed by path diff --git a/lib/tst_assert.c b/lib/tst_assert.c index b68bd5d39..04241d31b 100644 --- a/lib/tst_assert.c +++ b/lib/tst_assert.c @@ -23,18 +23,32 @@ void tst_assert_int(const char *file, const int lineno, const char *path, int va tst_res_(file, lineno, TFAIL, "%s != %d got %d", path, val, sys_val); } -void tst_assert_ulong(const char *file, const int lineno, const char *path, unsigned long val) +void tst_assert_ulong(const char *file, const int lineno, const char *path, + unsigned long val, enum tst_assert_flags flags) { - unsigned long sys_val; - - safe_file_scanf(file, lineno, NULL, path, "%lu", &sys_val); + unsigned long long sys_val_64; + unsigned long expected_val; + + safe_file_scanf(file, lineno, NULL, path, "%llu", &sys_val_64); + + if (flags & TST_ASSERT_SATURATED_INT) { + if (sys_val_64 > (unsigned long long)INT_MAX) + expected_val = (unsigned long)INT_MAX; + else + expected_val = (unsigned long)sys_val_64; + } else if (flags & TST_ASSERT_TRUNC_32BIT) { + expected_val = (unsigned long)(sys_val_64 & 0xFFFFFFFFULL); + } else { + expected_val = (unsigned long)sys_val_64; + } - if (val == sys_val) { + if (val == expected_val) { tst_res_(file, lineno, TPASS, "%s = %lu", path, val); return; } - tst_res_(file, lineno, TFAIL, "%s != %lu got %lu", path, val, sys_val); + tst_res_(file, lineno, TFAIL, "%s != %lu got %lu (raw: %llu)", + path, val, expected_val, sys_val_64); } void tst_assert_file_int(const char *file, const int lineno, const char *path, const char *prefix, int val) -- 2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] lib: Extend tst_assert_ulong() with enum flags 2026-08-31 8:16 ` [LTP] [PATCH v9 1/2] lib: Extend tst_assert_ulong() with enum flags Wei Gao via ltp @ 2026-08-31 9:00 ` linuxtestproject.agent 2026-09-02 9:04 ` [LTP] [PATCH v9 1/2] " Petr Vorel 1 sibling, 0 replies; 7+ messages in thread From: linuxtestproject.agent @ 2026-08-31 9:00 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, On Aug 31, 2026, Wei Gao wrote: > lib: Extend tst_assert_ulong() with enum flags --- [PATCH 1/2] --- > #define TST_ASSERT_ULONG(path, val, ...) \ > tst_assert_ulong(__FILE__, __LINE__, path, val, \ > TST_2_(dummy, ##__VA_ARGS__, TST_ASSERT_NONE)) The modified public TST_ASSERT_ULONG() macro needs a kernel-doc comment documenting its optional flags argument. Verdict - Needs revision --- Note: The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions. Regards, LTP AI Reviewer -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v9 1/2] lib: Extend tst_assert_ulong() with enum flags 2026-08-31 8:16 ` [LTP] [PATCH v9 1/2] lib: Extend tst_assert_ulong() with enum flags Wei Gao via ltp 2026-08-31 9:00 ` [LTP] " linuxtestproject.agent @ 2026-09-02 9:04 ` Petr Vorel 1 sibling, 0 replies; 7+ messages in thread From: Petr Vorel @ 2026-09-02 9:04 UTC (permalink / raw) To: Wei Gao; +Cc: ltp Hi Wei, > Introduce enum tst_assert_flags (including TST_ASSERT_NONE, > TST_ASSERT_SATURATED_INT, and TST_ASSERT_TRUNC_32BIT) to > tst_assert_ulong(). This enables type-safe handling of 32-bit > compat-mode truncation and clamping behaviors on 64-bit kernels > when verifying sysfs/procfs limits. > Signed-off-by: Wei Gao <wegao@suse.com> > --- > include/tst_assert.h | 36 +++++++++++++++++++++++++++++++----- > lib/tst_assert.c | 26 ++++++++++++++++++++------ > 2 files changed, 51 insertions(+), 11 deletions(-) > diff --git a/include/tst_assert.h b/include/tst_assert.h > index dcb62dfea..9154b7249 100644 > --- a/include/tst_assert.h > +++ b/include/tst_assert.h > @@ -21,14 +21,40 @@ void tst_assert_int(const char *file, const int lineno, > #define TST_ASSERT_FILE_INT(path, prefix, val) \ > tst_assert_file_int(__FILE__, __LINE__, path, prefix, val) > -/* > - * Same as tst_assert_int() but for unsigned long. > +/** > + * enum tst_assert_flags - Flags for tst_assert_ulong(). nit: I'd use "Bitwise flags" as you write below. > + * > + * @TST_ASSERT_NONE: No flags, default direct comparison. > + * @TST_ASSERT_SATURATED_INT: Clamps the value at %INT_MAX if it exceeds it. > + * @TST_ASSERT_TRUNC_32BIT: Keeps only the low 32 bits of the read value, > + * truncating any higher bits. > + */ > +enum tst_assert_flags { > + TST_ASSERT_NONE = 0x00, IMHO TST_ASSERT_NONE is overkill, I'd just use 0. But others might have a different opinion. > + TST_ASSERT_SATURATED_INT = 0x01, > + TST_ASSERT_TRUNC_32BIT = 0x02, Also, I'd use decimal numbers instead of hexadecimal when we have just 3 values (specially 0x00 looks really strange). The rest LGTM. Reviewed-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure 2026-08-31 8:16 [LTP] [PATCH v9 0/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp 2026-08-31 8:16 ` [LTP] [PATCH v9 1/2] lib: Extend tst_assert_ulong() with enum flags Wei Gao via ltp @ 2026-08-31 8:16 ` Wei Gao via ltp 2026-09-02 9:06 ` Petr Vorel 2026-09-02 9:18 ` Petr Vorel 1 sibling, 2 replies; 7+ messages in thread From: Wei Gao via ltp @ 2026-08-31 8:16 UTC (permalink / raw) To: ltp; +Cc: Dan Carpenter On 64-bit kernels, the default shmmax and shmall values often exceed the range of a 32-bit unsigned long or are clipped differently by the kernel's compat syscall layer than they appear in /proc. Fix this by utilizing the new TST_ASSERT_ULONG() flags to properly clamp and truncate the expected values under compat mode. Link: https://lore.kernel.org/ltp/aJm5SBOaRoe1e0PB@yuki.lan/ Suggested-by: Cyril Hrubis <chrubis@suse.cz> Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: Wei Gao <wegao@suse.com> --- testcases/kernel/syscalls/shmctl/shmctl03.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/syscalls/shmctl/shmctl03.c b/testcases/kernel/syscalls/shmctl/shmctl03.c index 9e1c2f099..fcb416a1d 100644 --- a/testcases/kernel/syscalls/shmctl/shmctl03.c +++ b/testcases/kernel/syscalls/shmctl/shmctl03.c @@ -30,9 +30,16 @@ static void verify_ipcinfo(void) else tst_res(TPASS, "shmmin = 1"); - TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax); - TST_ASSERT_ULONG(PATH_KERN_SHMMNI, info.shmmni); - TST_ASSERT_ULONG(PATH_KERN_SHMALL, info.shmall); + int c = tst_is_compat_mode(); + + /* + * On 64-bit kernel, shmmax is clamped to INT_MAX for 32-bit + * compat syscall, while shmmni and shmall are truncated + * to 32-bit. + */ + TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax, c ? TST_ASSERT_SATURATED_INT : TST_ASSERT_NONE); + TST_ASSERT_ULONG(PATH_KERN_SHMMNI, info.shmmni, c ? TST_ASSERT_TRUNC_32BIT : TST_ASSERT_NONE); + TST_ASSERT_ULONG(PATH_KERN_SHMALL, info.shmall, c ? TST_ASSERT_TRUNC_32BIT : TST_ASSERT_NONE); } static struct tst_test test = { -- 2.55.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure 2026-08-31 8:16 ` [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp @ 2026-09-02 9:06 ` Petr Vorel 2026-09-02 9:18 ` Petr Vorel 1 sibling, 0 replies; 7+ messages in thread From: Petr Vorel @ 2026-09-02 9:06 UTC (permalink / raw) To: Wei Gao; +Cc: Dan Carpenter, ltp Hi Wei, > On 64-bit kernels, the default shmmax and shmall values often exceed > the range of a 32-bit unsigned long or are clipped differently by > the kernel's compat syscall layer than they appear in /proc. > Fix this by utilizing the new TST_ASSERT_ULONG() flags to properly > clamp and truncate the expected values under compat mode. ... > - TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax); > - TST_ASSERT_ULONG(PATH_KERN_SHMMNI, info.shmmni); > - TST_ASSERT_ULONG(PATH_KERN_SHMALL, info.shmall); > + int c = tst_is_compat_mode(); > + > + /* > + * On 64-bit kernel, shmmax is clamped to INT_MAX for 32-bit > + * compat syscall, while shmmni and shmall are truncated > + * to 32-bit. > + */ > + TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax, c ? TST_ASSERT_SATURATED_INT : TST_ASSERT_NONE); > + TST_ASSERT_ULONG(PATH_KERN_SHMMNI, info.shmmni, c ? TST_ASSERT_TRUNC_32BIT : TST_ASSERT_NONE); > + TST_ASSERT_ULONG(PATH_KERN_SHMALL, info.shmall, c ? TST_ASSERT_TRUNC_32BIT : TST_ASSERT_NONE); Obviously correct (with the fact I already noted, that I'd use 0 instead adding TST_ASSERT_NONE into enum). Reviewed-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure 2026-08-31 8:16 ` [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp 2026-09-02 9:06 ` Petr Vorel @ 2026-09-02 9:18 ` Petr Vorel 1 sibling, 0 replies; 7+ messages in thread From: Petr Vorel @ 2026-09-02 9:18 UTC (permalink / raw) To: Wei Gao; +Cc: ltp, Dan Carpenter Hi all, [ Cc Dan's actual address, Linaro one no longer works ] > On 64-bit kernels, the default shmmax and shmall values often exceed > the range of a 32-bit unsigned long or are clipped differently by > the kernel's compat syscall layer than they appear in /proc. > Fix this by utilizing the new TST_ASSERT_ULONG() flags to properly > clamp and truncate the expected values under compat mode. > Link: https://lore.kernel.org/ltp/aJm5SBOaRoe1e0PB@yuki.lan/ > Suggested-by: Cyril Hrubis <chrubis@suse.cz> > Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> > Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Reported-by: Dan Carpenter <error27@gmail.com> > Signed-off-by: Wei Gao <wegao@suse.com> > --- > testcases/kernel/syscalls/shmctl/shmctl03.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > diff --git a/testcases/kernel/syscalls/shmctl/shmctl03.c b/testcases/kernel/syscalls/shmctl/shmctl03.c > index 9e1c2f099..fcb416a1d 100644 > --- a/testcases/kernel/syscalls/shmctl/shmctl03.c > +++ b/testcases/kernel/syscalls/shmctl/shmctl03.c > @@ -30,9 +30,16 @@ static void verify_ipcinfo(void) > else > tst_res(TPASS, "shmmin = 1"); > - TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax); > - TST_ASSERT_ULONG(PATH_KERN_SHMMNI, info.shmmni); > - TST_ASSERT_ULONG(PATH_KERN_SHMALL, info.shmall); > + int c = tst_is_compat_mode(); > + > + /* > + * On 64-bit kernel, shmmax is clamped to INT_MAX for 32-bit > + * compat syscall, while shmmni and shmall are truncated > + * to 32-bit. > + */ > + TST_ASSERT_ULONG(PATH_KERN_SHMMAX, info.shmmax, c ? TST_ASSERT_SATURATED_INT : TST_ASSERT_NONE); > + TST_ASSERT_ULONG(PATH_KERN_SHMMNI, info.shmmni, c ? TST_ASSERT_TRUNC_32BIT : TST_ASSERT_NONE); > + TST_ASSERT_ULONG(PATH_KERN_SHMALL, info.shmall, c ? TST_ASSERT_TRUNC_32BIT : TST_ASSERT_NONE); > } > static struct tst_test test = { -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-09-02 9:19 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-08-31 8:16 [LTP] [PATCH v9 0/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp 2026-08-31 8:16 ` [LTP] [PATCH v9 1/2] lib: Extend tst_assert_ulong() with enum flags Wei Gao via ltp 2026-08-31 9:00 ` [LTP] " linuxtestproject.agent 2026-09-02 9:04 ` [LTP] [PATCH v9 1/2] " Petr Vorel 2026-08-31 8:16 ` [LTP] [PATCH v9 2/2] shmctl03: Fix 32-bit compat mode failure Wei Gao via ltp 2026-09-02 9:06 ` Petr Vorel 2026-09-02 9:18 ` Petr Vorel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox