Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits
@ 2026-04-07  9:26 Wei Gao via ltp
  2026-04-10 13:14 ` Andrea Cervesato via ltp
  2026-04-13  6:19 ` [LTP] [PATCH v2] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation Wei Gao via ltp
  0 siblings, 2 replies; 13+ messages in thread
From: Wei Gao via ltp @ 2026-04-07  9:26 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.

Link: https://lore.kernel.org/ltp/aJm5SBOaRoe1e0PB@yuki.lan/
Signed-off-by: Wei Gao <wegao@suse.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 include/tst_assert.h                          | 10 +++++---
 lib/tst_assert.c                              | 25 ++++++++++++++-----
 .../kernel/syscalls/ipc/shmctl/shmctl03.c     | 12 ++++++---
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/include/tst_assert.h b/include/tst_assert.h
index dcb62dfea..5b3bd0e12 100644
--- a/include/tst_assert.h
+++ b/include/tst_assert.h
@@ -21,14 +21,18 @@ 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)
 
+#define TST_ASSERT_SATURATED_INT   0x01
+#define TST_ASSERT_SATURATED_ULONG 0x02
+#define TST_ASSERT_BITWISE         0x04
+
 /*
  * Same as tst_assert_int() but for unsigned long.
  */
 void tst_assert_ulong(const char *file, const int lineno,
-                      const char *path, unsigned long val);
+                      const char *path, unsigned long val, int 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, (0, ##__VA_ARGS__))
 
 /*
  * 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..09d7d8a6f 100644
--- a/lib/tst_assert.c
+++ b/lib/tst_assert.c
@@ -23,18 +23,31 @@ 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, int 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) {
+		expected_val = (sys_val_64 > 2147483647ULL) ? 2147483647UL : (unsigned long)sys_val_64;
+	} else if (flags & TST_ASSERT_SATURATED_ULONG) {
+		expected_val = (sys_val_64 > 4294967295ULL) ? 4294967295UL : (unsigned long)sys_val_64;
+	} else if (flags & TST_ASSERT_BITWISE) {
+		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)
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
index a1f53e7c1..6d073789c 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
@@ -30,9 +30,15 @@ static void verify_ipcinfo(void)
 	else
 		tst_res(TPASS, "shmmin = 1");
 
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	if (tst_is_compat_mode()) {
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax, TST_ASSERT_SATURATED_INT);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni, TST_ASSERT_BITWISE);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall, TST_ASSERT_BITWISE);
+	} else {
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	}
 }
 
 static struct tst_test test = {
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits
  2026-04-07  9:26 [LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits Wei Gao via ltp
@ 2026-04-10 13:14 ` Andrea Cervesato via ltp
  2026-04-10 14:12   ` Wei Gao via ltp
  2026-04-13  6:19 ` [LTP] [PATCH v2] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation Wei Gao via ltp
  1 sibling, 1 reply; 13+ messages in thread
From: Andrea Cervesato via ltp @ 2026-04-10 13:14 UTC (permalink / raw)
  To: Wei Gao via ltp; +Cc: Dan Carpenter, ltp

Hi Wei,

this review is pretty accurate. Please follow the suggestions here first:
https://github.com/acerv/ltp-agent/actions/runs/24074831444

King regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits
  2026-04-10 13:14 ` Andrea Cervesato via ltp
@ 2026-04-10 14:12   ` Wei Gao via ltp
  2026-04-10 14:32     ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 13+ messages in thread
From: Wei Gao via ltp @ 2026-04-10 14:12 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: Dan Carpenter, Wei Gao via ltp

On Fri, Apr 10, 2026 at 01:14:41PM +0000, Andrea Cervesato via ltp wrote:
> Hi Wei,
> 
> this review is pretty accurate. Please follow the suggestions here first:
> https://github.com/acerv/ltp-agent/actions/runs/24074831444

I will update the subject line and use INT_MAX/UINT_MAX as AI suggested.
But I'd prefer to keep TST_ASSERT_SATURATED_ULONG even without a current caller,
as it completes the logic for the helper function. The logic is clear enough
that an extra comment isn't needed also, if you are agree then i will sent next patch.

Thanks.

> 
> King regards,
> --
> Andrea Cervesato
> SUSE QE Automation Engineer Linux
> andrea.cervesato@suse.com
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits
  2026-04-10 14:12   ` Wei Gao via ltp
@ 2026-04-10 14:32     ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato via ltp @ 2026-04-10 14:32 UTC (permalink / raw)
  To: Wei Gao; +Cc: Dan Carpenter, Wei Gao via ltp

Hi Wei,

> I will update the subject line and use INT_MAX/UINT_MAX as AI suggested.
> But I'd prefer to keep TST_ASSERT_SATURATED_ULONG even without a current caller,
> as it completes the logic for the helper function. The logic is clear enough
> that an extra comment isn't needed also, if you are agree then i will sent next patch.

Fair enough, feel free to ignore that part and to send a new patch.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [LTP] [PATCH v2] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-04-07  9:26 [LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits Wei Gao via ltp
  2026-04-10 13:14 ` Andrea Cervesato via ltp
@ 2026-04-13  6:19 ` Wei Gao via ltp
  2026-04-29  8:04   ` [LTP] " linuxtestproject.agent
  2026-04-29 11:18   ` [LTP] [PATCH v3] " Wei Gao via ltp
  1 sibling, 2 replies; 13+ messages in thread
From: Wei Gao via ltp @ 2026-04-13  6:19 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.

Link: https://lore.kernel.org/ltp/aJm5SBOaRoe1e0PB@yuki.lan/
Signed-off-by: Wei Gao <wegao@suse.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 include/tst_assert.h                          | 10 ++++---
 lib/tst_assert.c                              | 26 ++++++++++++++-----
 .../kernel/syscalls/ipc/shmctl/shmctl03.c     | 12 ++++++---
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/include/tst_assert.h b/include/tst_assert.h
index dcb62dfea..5b3bd0e12 100644
--- a/include/tst_assert.h
+++ b/include/tst_assert.h
@@ -21,14 +21,18 @@ 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)
 
+#define TST_ASSERT_SATURATED_INT   0x01
+#define TST_ASSERT_SATURATED_ULONG 0x02
+#define TST_ASSERT_BITWISE         0x04
+
 /*
  * Same as tst_assert_int() but for unsigned long.
  */
 void tst_assert_ulong(const char *file, const int lineno,
-                      const char *path, unsigned long val);
+                      const char *path, unsigned long val, int 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, (0, ##__VA_ARGS__))
 
 /*
  * 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..1598244c0 100644
--- a/lib/tst_assert.c
+++ b/lib/tst_assert.c
@@ -5,6 +5,7 @@
  * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
  */
 #include <stdio.h>
+#include <limits.h>
 #define TST_NO_DEFAULT_MAIN
 #include "tst_assert.h"
 #include "tst_test.h"
@@ -23,18 +24,31 @@ 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, int 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) {
+		expected_val = (sys_val_64 > (unsigned long long)INT_MAX) ? (unsigned long)INT_MAX : (unsigned long)sys_val_64;
+	} else if (flags & TST_ASSERT_SATURATED_ULONG) {
+		expected_val = (sys_val_64 > (unsigned long long)UINT_MAX) ? (unsigned long)UINT_MAX : (unsigned long)sys_val_64;
+	} else if (flags & TST_ASSERT_BITWISE) {
+		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)
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
index a1f53e7c1..6d073789c 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
@@ -30,9 +30,15 @@ static void verify_ipcinfo(void)
 	else
 		tst_res(TPASS, "shmmin = 1");
 
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	if (tst_is_compat_mode()) {
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax, TST_ASSERT_SATURATED_INT);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni, TST_ASSERT_BITWISE);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall, TST_ASSERT_BITWISE);
+	} else {
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	}
 }
 
 static struct tst_test test = {
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [LTP] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-04-13  6:19 ` [LTP] [PATCH v2] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation Wei Gao via ltp
@ 2026-04-29  8:04   ` linuxtestproject.agent
  2026-04-29 11:18   ` [LTP] [PATCH v3] " Wei Gao via ltp
  1 sibling, 0 replies; 13+ messages in thread
From: linuxtestproject.agent @ 2026-04-29  8:04 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

Hi Wei,

On Mon, 13 Apr 2026 06:19:53 +0000, Wei Gao wrote:
> shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation

> +#define TST_ASSERT_SATURATED_INT   0x01
> +#define TST_ASSERT_SATURATED_ULONG 0x02
> +#define TST_ASSERT_BITWISE         0x04

TST_ASSERT_SATURATED_ULONG is never used in this patch. Either remove it
or rename it to TST_ASSERT_SATURATED_U32 — the current name implies
saturation at ULONG_MAX but it actually clamps to UINT_MAX (32-bit).

> +void tst_assert_ulong(const char *file, const int lineno, const char *path,
> +			unsigned long val, int flags)

Continuation should align with the opening '(' to match the declaration
in tst_assert.h.

> +	if (tst_is_compat_mode()) {
> +		TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax, TST_ASSERT_SATURATED_INT);
> +		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni, TST_ASSERT_BITWISE);
> +		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall, TST_ASSERT_BITWISE);

Add a comment here explaining why shmmax uses saturation at INT_MAX while
shmmni/shmall use bitwise truncation — the choice is non-obvious without
knowing the kernel compat path behaviour.

> +Signed-off-by: Wei Gao <wegao@suse.com>

This is a bug fix; please add a Fixes: tag pointing to the commit that
originally added shmctl03 without compat mode handling.

Pre-existing issues noticed in the surrounding code (not introduced
by this patch):

- testcases/kernel/syscalls/ipc/shmctl/shmctl03.c:12 — includes
  tse_newipc.h using the non-standard tse_ prefix instead of tst_.

---
Note:

Our agent completed the review of the patch. The full review can be
found at: https://patchwork.ozlabs.org/project/ltp/list/?series=499648

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] 13+ messages in thread

* [LTP] [PATCH v3] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-04-13  6:19 ` [LTP] [PATCH v2] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation Wei Gao via ltp
  2026-04-29  8:04   ` [LTP] " linuxtestproject.agent
@ 2026-04-29 11:18   ` Wei Gao via ltp
  2026-04-29 12:33     ` [LTP] " linuxtestproject.agent
  2026-04-30  3:47     ` [LTP] [PATCH v4] " Wei Gao via ltp
  1 sibling, 2 replies; 13+ messages in thread
From: Wei Gao via ltp @ 2026-04-29 11:18 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.

Link: https://lore.kernel.org/ltp/aJm5SBOaRoe1e0PB@yuki.lan/
Signed-off-by: Wei Gao <wegao@suse.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 include/tst_assert.h                          |  9 +++++---
 lib/tst_assert.c                              | 22 ++++++++++++++-----
 .../kernel/syscalls/ipc/shmctl/shmctl03.c     | 17 +++++++++++---
 3 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/include/tst_assert.h b/include/tst_assert.h
index dcb62dfea..8b2c8f655 100644
--- a/include/tst_assert.h
+++ b/include/tst_assert.h
@@ -21,14 +21,17 @@ 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)
 
+#define TST_ASSERT_SATURATED_INT   0x01
+#define TST_ASSERT_BITWISE         0x04
+
 /*
  * Same as tst_assert_int() but for unsigned long.
  */
 void tst_assert_ulong(const char *file, const int lineno,
-                      const char *path, unsigned long val);
+                      const char *path, unsigned long val, int 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, (0, ##__VA_ARGS__))
 
 /*
  * 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..773a10e49 100644
--- a/lib/tst_assert.c
+++ b/lib/tst_assert.c
@@ -5,6 +5,7 @@
  * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
  */
 #include <stdio.h>
+#include <limits.h>
 #define TST_NO_DEFAULT_MAIN
 #include "tst_assert.h"
 #include "tst_test.h"
@@ -23,18 +24,29 @@ 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, int flags)
 {
-	unsigned long sys_val;
+	unsigned long long sys_val_64;
+	unsigned long expected_val;
 
-	safe_file_scanf(file, lineno, NULL, path, "%lu", &sys_val);
+	safe_file_scanf(file, lineno, NULL, path, "%llu", &sys_val_64);
 
-	if (val == sys_val) {
+	if (flags & TST_ASSERT_SATURATED_INT) {
+		expected_val = (sys_val_64 > (unsigned long long)INT_MAX) ? (unsigned long)INT_MAX : (unsigned long)sys_val_64;
+	} else if (flags & TST_ASSERT_BITWISE) {
+		expected_val = (unsigned long)(sys_val_64 & 0xFFFFFFFFULL);
+	} else {
+		expected_val = (unsigned long)sys_val_64;
+	}
+
+	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)
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
index a1f53e7c1..e6c7a8027 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
@@ -30,9 +30,20 @@ static void verify_ipcinfo(void)
 	else
 		tst_res(TPASS, "shmmin = 1");
 
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	if (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("/proc/sys/kernel/shmmax", info.shmmax, TST_ASSERT_SATURATED_INT);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni, TST_ASSERT_BITWISE);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall, TST_ASSERT_BITWISE);
+	} else {
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	}
 }
 
 static struct tst_test test = {
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [LTP] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-04-29 11:18   ` [LTP] [PATCH v3] " Wei Gao via ltp
@ 2026-04-29 12:33     ` linuxtestproject.agent
  2026-04-30  3:47     ` [LTP] [PATCH v4] " Wei Gao via ltp
  1 sibling, 0 replies; 13+ messages in thread
From: linuxtestproject.agent @ 2026-04-29 12:33 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

Hi Wei,

On Wed, 29 Apr 2026, Wei Gao wrote:
> shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation

> Link: https://lore.kernel.org/ltp/aJm5SBOaRoe1e0PB@yuki.lan/
> Signed-off-by: Wei Gao <wegao@suse.com>

This is a bugfix; please add a Fixes: tag pointing to the commit that
introduced the regression.

[...]

> +#define TST_ASSERT_SATURATED_INT   0x01
> +#define TST_ASSERT_BITWISE         0x04

0x02 is unused without explanation. Either renumber TST_ASSERT_BITWISE
to 0x02 or add a comment marking the gap as reserved.

[...]

> +	if (flags & TST_ASSERT_SATURATED_INT) {
> +		expected_val = (sys_val_64 > (unsigned long long)INT_MAX) ? (unsigned long)INT_MAX : (unsigned long)sys_val_64;

Line exceeds 80 columns. Split into an if/else block:

	if (sys_val_64 > (unsigned long long)INT_MAX)
		expected_val = (unsigned long)INT_MAX;
	else
		expected_val = (unsigned long)sys_val_64;

---
Note:

Our agent completed the review of the patch. The full review can be
found at: https://patchwork.ozlabs.org/project/ltp/list/?series=502039

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] 13+ messages in thread

* [LTP] [PATCH v4] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-04-29 11:18   ` [LTP] [PATCH v3] " Wei Gao via ltp
  2026-04-29 12:33     ` [LTP] " linuxtestproject.agent
@ 2026-04-30  3:47     ` Wei Gao via ltp
  2026-04-30  6:35       ` [LTP] " linuxtestproject.agent
  1 sibling, 1 reply; 13+ messages in thread
From: Wei Gao via ltp @ 2026-04-30  3:47 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.

Link: https://lore.kernel.org/ltp/aJm5SBOaRoe1e0PB@yuki.lan/
Signed-off-by: Wei Gao <wegao@suse.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 include/tst_assert.h                          |  9 ++++---
 lib/tst_assert.c                              | 27 ++++++++++++++-----
 .../kernel/syscalls/ipc/shmctl/shmctl03.c     | 17 +++++++++---
 3 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/include/tst_assert.h b/include/tst_assert.h
index dcb62dfea..2f1051270 100644
--- a/include/tst_assert.h
+++ b/include/tst_assert.h
@@ -21,14 +21,17 @@ 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)
 
+#define TST_ASSERT_SATURATED_INT   0x01
+#define TST_ASSERT_BITWISE         0x02
+
 /*
  * Same as tst_assert_int() but for unsigned long.
  */
 void tst_assert_ulong(const char *file, const int lineno,
-                      const char *path, unsigned long val);
+                      const char *path, unsigned long val, int 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, (0, ##__VA_ARGS__))
 
 /*
  * 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..fd651f53a 100644
--- a/lib/tst_assert.c
+++ b/lib/tst_assert.c
@@ -5,6 +5,7 @@
  * Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
  */
 #include <stdio.h>
+#include <limits.h>
 #define TST_NO_DEFAULT_MAIN
 #include "tst_assert.h"
 #include "tst_test.h"
@@ -23,18 +24,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, int 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_BITWISE) {
+		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)
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
index a1f53e7c1..e6c7a8027 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
@@ -30,9 +30,20 @@ static void verify_ipcinfo(void)
 	else
 		tst_res(TPASS, "shmmin = 1");
 
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
-	TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	if (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("/proc/sys/kernel/shmmax", info.shmmax, TST_ASSERT_SATURATED_INT);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni, TST_ASSERT_BITWISE);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall, TST_ASSERT_BITWISE);
+	} else {
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmax", info.shmmax);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmmni", info.shmmni);
+		TST_ASSERT_ULONG("/proc/sys/kernel/shmall", info.shmall);
+	}
 }
 
 static struct tst_test test = {
-- 
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [LTP] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-04-30  3:47     ` [LTP] [PATCH v4] " Wei Gao via ltp
@ 2026-04-30  6:35       ` linuxtestproject.agent
  2026-05-06 17:28         ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 13+ messages in thread
From: linuxtestproject.agent @ 2026-04-30  6:35 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

Hi Wei,

On Thu, 30 Apr 2026, Wei Gao wrote:
> shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for
> compat mode truncation

> +#define TST_ASSERT_SATURATED_INT   0x01
[...]
> +	if (flags & TST_ASSERT_SATURATED_INT) {
> +		if (sys_val_64 > (unsigned long long)INT_MAX)
> +			expected_val = (unsigned long)INT_MAX;

For shmmax in compat mode, can you confirm the saturation is to INT_MAX
(2^31-1) rather than UINT_MAX (2^32-1)?  The compat_shminfo64.shmmax
field is __compat_ulong_t (unsigned 32-bit), so truncation to UINT_MAX
would be the natural expectation.  A reference to the relevant kernel
compat code path in ipc/shm.c would help clarify.

Pre-existing issues noticed in the surrounding code (not introduced
by this patch):

- testcases/kernel/syscalls/ipc/shmctl/shmctl03.c:13 — #include
  "tse_newipc.h" appears unused; no symbols from it are referenced.

---
Note:

Our agent completed the review of the patch. The full review can be
found at: https://github.com/linux-test-project/ltp-agent/actions/runs/25150858881

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] 13+ messages in thread

* Re: [LTP] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-04-30  6:35       ` [LTP] " linuxtestproject.agent
@ 2026-05-06 17:28         ` Andrea Cervesato via ltp
  2026-05-07  9:51           ` Wei Gao via ltp
  0 siblings, 1 reply; 13+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-06 17:28 UTC (permalink / raw)
  To: linuxtestproject.agent; +Cc: ltp

Hi Wei,

the agent review seems to be valid. The shmmax is defined as
unsigned long and we should keep the unsigned state of the
variable.

Please verify that it works and we can proceed with the patch.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-05-06 17:28         ` Andrea Cervesato via ltp
@ 2026-05-07  9:51           ` Wei Gao via ltp
  2026-05-07 10:01             ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 13+ messages in thread
From: Wei Gao via ltp @ 2026-05-07  9:51 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: ltp, linuxtestproject.agent

On Wed, May 06, 2026 at 05:28:18PM +0000, Andrea Cervesato wrote:
> Hi Wei,
> 
> the agent review seems to be valid. The shmmax is defined as
> unsigned long and we should keep the unsigned state of the
> variable.

Kernel indeed saturates shmmax to INT_MAX for compat syscalls
Relevant kernel code in ipc/shm.c:

static int copy_compat_shminfo_to_user(void __user *buf, struct shminfo64 *in,
                                        int version)
{
        if (in->shmmax > INT_MAX)
                in->shmmax = INT_MAX; <<<<<<<
        if (version == IPC_64) {
                struct compat_shminfo64 info;
                memset(&info, 0, sizeof(info));
                info.shmmax = in->shmmax;

> 
> Please verify that it works and we can proceed with the patch.
> 
> Regards,
> --
> Andrea Cervesato
> SUSE QE Automation Engineer Linux
> andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [LTP] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation
  2026-05-07  9:51           ` Wei Gao via ltp
@ 2026-05-07 10:01             ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 13+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-07 10:01 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp, linuxtestproject.agent

Hi Wei,

> 
> Kernel indeed saturates shmmax to INT_MAX for compat syscalls
> Relevant kernel code in ipc/shm.c:
> 
> static int copy_compat_shminfo_to_user(void __user *buf, struct shminfo64 *in,
>                                         int version)
> {
>         if (in->shmmax > INT_MAX)
>                 in->shmmax = INT_MAX; <<<<<<<
>         if (version == IPC_64) {
>                 struct compat_shminfo64 info;
>                 memset(&info, 0, sizeof(info));
>                 info.shmmax = in->shmmax;
> 

You are right, LGTM

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-05-07 10:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07  9:26 [LTP] [PATCH v1] shmctl03: Fix 32-bit compat mode failure by forcing limits Wei Gao via ltp
2026-04-10 13:14 ` Andrea Cervesato via ltp
2026-04-10 14:12   ` Wei Gao via ltp
2026-04-10 14:32     ` Andrea Cervesato via ltp
2026-04-13  6:19 ` [LTP] [PATCH v2] shmctl03: Fix 32-bit compat mode failure by adjusting comparisons for compat mode truncation Wei Gao via ltp
2026-04-29  8:04   ` [LTP] " linuxtestproject.agent
2026-04-29 11:18   ` [LTP] [PATCH v3] " Wei Gao via ltp
2026-04-29 12:33     ` [LTP] " linuxtestproject.agent
2026-04-30  3:47     ` [LTP] [PATCH v4] " Wei Gao via ltp
2026-04-30  6:35       ` [LTP] " linuxtestproject.agent
2026-05-06 17:28         ` Andrea Cervesato via ltp
2026-05-07  9:51           ` Wei Gao via ltp
2026-05-07 10:01             ` Andrea Cervesato via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox