* [PATCH v3 1/3] selftests/mm: handle EINVAL when configuring gigantic hugepages
2026-07-08 6:59 [PATCH v3 0/3] selftests/mm: avoid false failures in hugetlb and KSM tests Sayali Patil
@ 2026-07-08 6:59 ` Sayali Patil
2026-07-08 7:38 ` David Hildenbrand (Arm)
2026-07-08 13:48 ` Usama Arif
2026-07-08 6:59 ` [PATCH v3 2/3] selftests/mm: fix ksm NUMA merge test for systems with memoryless NUMA nodes Sayali Patil
` (2 subsequent siblings)
3 siblings, 2 replies; 8+ messages in thread
From: Sayali Patil @ 2026-07-08 6:59 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan, linux-mm, linux-kernel,
linux-kselftest, Ritesh Harjani
Cc: David Hildenbrand, Zi Yan, Michal Hocko, Oscar Salvador,
Lorenzo Stoakes, Dev Jain, Liam.Howlett, linuxppc-dev, Miaohe Lin,
Venkat Rao Bagalkote, Sayali Patil
Some MM selftests attempt to configure the amount of
HugeTLB pages of different sizes by writing to nr_hugepages.
PowerPC hash MMU pSeries systems advertise gigantic hugepage sizes
but do not support runtime allocation of such pages, writes
to the corresponding nr_hugepages file fail with -EINVAL.
This causes the test to bail out even though the failure is due
to a platform limitation rather than the
functionality being tested.
Ignore -EINVAL when configuring nr_hugepages so that tests continue to
run on systems where gigantic hugepage allocation is unsupported.
Before patch:
-------------------------
running ./hugetlb-madvise
-------------------------
TAP version 13
1..1
[INFO] detected hugetlb page size: 16777216 KiB
[INFO] detected hugetlb page size: 16384 KiB
ok 1 MADV_DONTNEED and MADV_REMOVE on hugetlb
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
Bail out! /sys/kernel/mm/hugepages/hugepages-16777216kB/nr_hugepages
write(0) failed: Invalid argument
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
[FAIL]
After patch:
-------------------------
running ./hugetlb-madvise
-------------------------
TAP version 13
1..1
[INFO] detected hugetlb page size: 16777216 KiB
[INFO] detected hugetlb page size: 16384 KiB
ok 1 MADV_DONTNEED and MADV_REMOVE on hugetlb
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
[PASS]
Fixes: 27477b28b74f ("selftests/mm: hugepage_settings: add APIs to get and set nr_hugepages")
Co-developed-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
---
.../testing/selftests/mm/hugepage_settings.c | 2 +-
tools/testing/selftests/mm/vm_util.c | 26 ++++++++++++++++---
tools/testing/selftests/mm/vm_util.h | 1 +
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/mm/hugepage_settings.c b/tools/testing/selftests/mm/hugepage_settings.c
index 2eab2110ac6a..d7917dce3aba 100644
--- a/tools/testing/selftests/mm/hugepage_settings.c
+++ b/tools/testing/selftests/mm/hugepage_settings.c
@@ -437,7 +437,7 @@ void hugetlb_set_nr_pages(unsigned long size, unsigned long nr)
hugetlb_sysfs_path(path, sizeof(path), size, "nr_hugepages");
- write_num(path, nr);
+ write_num_ignore_einval(path, nr);
}
unsigned long hugetlb_free_pages(unsigned long size)
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index 311fc5b4513e..ef1ea11981a7 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -719,7 +719,7 @@ int read_file(const char *path, char *buf, size_t buflen)
return (unsigned int) numread;
}
-void write_file(const char *path, const char *buf, size_t buflen)
+static void __write_file(const char *path, const char *buf, size_t buflen, bool ignore_einval)
{
int fd, saved_errno;
ssize_t numwritten;
@@ -735,14 +735,22 @@ void write_file(const char *path, const char *buf, size_t buflen)
saved_errno = errno;
close(fd);
errno = saved_errno;
- if (numwritten < 0)
+ if (numwritten < 0) {
+ if (ignore_einval && errno == EINVAL)
+ return;
ksft_exit_fail_msg("%s write(%.*s) failed: %s\n", path, (int)(buflen - 1),
buf, strerror(errno));
+ }
if (numwritten != buflen - 1)
ksft_exit_fail_msg("%s write(%.*s) is truncated, expected %zu bytes, got %zd bytes\n",
path, (int)(buflen - 1), buf, buflen - 1, numwritten);
}
+void write_file(const char *path, const char *buf, size_t buflen)
+{
+ __write_file(path, buf, buflen, /* ignore_einval = */ false);
+}
+
unsigned long read_num(const char *path)
{
char buf[21];
@@ -753,12 +761,22 @@ unsigned long read_num(const char *path)
return strtoul(buf, NULL, 10);
}
-void write_num(const char *path, unsigned long num)
+static void __write_num(const char *path, unsigned long num, bool ignore_einval)
{
char buf[21];
sprintf(buf, "%lu", num);
- write_file(path, buf, strlen(buf) + 1);
+ __write_file(path, buf, strlen(buf) + 1, ignore_einval);
+}
+
+void write_num(const char *path, unsigned long num)
+{
+ return __write_num(path, num, /* ignore_einval = */ false);
+}
+
+void write_num_ignore_einval(const char *path, unsigned long num)
+{
+ return __write_num(path, num, /* ignore_einval = */ true);
}
static unsigned long shmall, shmmax;
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
index ea8fc8fdf0eb..7799154b67ee 100644
--- a/tools/testing/selftests/mm/vm_util.h
+++ b/tools/testing/selftests/mm/vm_util.h
@@ -168,6 +168,7 @@ void write_file(const char *path, const char *buf, size_t buflen);
int read_file(const char *path, char *buf, size_t buflen);
unsigned long read_num(const char *path);
void write_num(const char *path, unsigned long num);
+void write_num_ignore_einval(const char *path, unsigned long num);
void shm_limits_prepare(unsigned long length);
void __shm_limits_restore(void);
--
2.52.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v3 1/3] selftests/mm: handle EINVAL when configuring gigantic hugepages
2026-07-08 6:59 ` [PATCH v3 1/3] selftests/mm: handle EINVAL when configuring gigantic hugepages Sayali Patil
@ 2026-07-08 7:38 ` David Hildenbrand (Arm)
2026-07-08 13:48 ` Usama Arif
1 sibling, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-07-08 7:38 UTC (permalink / raw)
To: Sayali Patil, Andrew Morton, Shuah Khan, linux-mm, linux-kernel,
linux-kselftest, Ritesh Harjani
Cc: Zi Yan, Michal Hocko, Oscar Salvador, Lorenzo Stoakes, Dev Jain,
Liam.Howlett, linuxppc-dev, Miaohe Lin, Venkat Rao Bagalkote
On 7/8/26 08:59, Sayali Patil wrote:
> Some MM selftests attempt to configure the amount of
> HugeTLB pages of different sizes by writing to nr_hugepages.
>
> PowerPC hash MMU pSeries systems advertise gigantic hugepage sizes
> but do not support runtime allocation of such pages, writes
> to the corresponding nr_hugepages file fail with -EINVAL.
> This causes the test to bail out even though the failure is due
> to a platform limitation rather than the
> functionality being tested.
>
> Ignore -EINVAL when configuring nr_hugepages so that tests continue to
> run on systems where gigantic hugepage allocation is unsupported.
>
> Before patch:
> -------------------------
> running ./hugetlb-madvise
> -------------------------
> TAP version 13
> 1..1
> [INFO] detected hugetlb page size: 16777216 KiB
> [INFO] detected hugetlb page size: 16384 KiB
> ok 1 MADV_DONTNEED and MADV_REMOVE on hugetlb
> Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> Bail out! /sys/kernel/mm/hugepages/hugepages-16777216kB/nr_hugepages
> write(0) failed: Invalid argument
> Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> [FAIL]
>
> After patch:
> -------------------------
> running ./hugetlb-madvise
> -------------------------
> TAP version 13
> 1..1
> [INFO] detected hugetlb page size: 16777216 KiB
> [INFO] detected hugetlb page size: 16384 KiB
> ok 1 MADV_DONTNEED and MADV_REMOVE on hugetlb
> Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> [PASS]
>
> Fixes: 27477b28b74f ("selftests/mm: hugepage_settings: add APIs to get and set nr_hugepages")
> Co-developed-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
LGTM. Using proper flags would maybe be nicer, but no need for that for this
corner case for now.
--
Cheers,
David
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v3 1/3] selftests/mm: handle EINVAL when configuring gigantic hugepages
2026-07-08 6:59 ` [PATCH v3 1/3] selftests/mm: handle EINVAL when configuring gigantic hugepages Sayali Patil
2026-07-08 7:38 ` David Hildenbrand (Arm)
@ 2026-07-08 13:48 ` Usama Arif
1 sibling, 0 replies; 8+ messages in thread
From: Usama Arif @ 2026-07-08 13:48 UTC (permalink / raw)
To: Sayali Patil
Cc: Usama Arif, Andrew Morton, Shuah Khan, linux-mm, linux-kernel,
linux-kselftest, Ritesh Harjani, David Hildenbrand, Zi Yan,
Michal Hocko, Oscar Salvador, Lorenzo Stoakes, Dev Jain,
Liam.Howlett, linuxppc-dev, Miaohe Lin, Venkat Rao Bagalkote
On Wed, 8 Jul 2026 12:29:05 +0530 Sayali Patil <sayalip@linux.ibm.com> wrote:
> Some MM selftests attempt to configure the amount of
> HugeTLB pages of different sizes by writing to nr_hugepages.
>
> PowerPC hash MMU pSeries systems advertise gigantic hugepage sizes
> but do not support runtime allocation of such pages, writes
> to the corresponding nr_hugepages file fail with -EINVAL.
> This causes the test to bail out even though the failure is due
> to a platform limitation rather than the
> functionality being tested.
>
> Ignore -EINVAL when configuring nr_hugepages so that tests continue to
> run on systems where gigantic hugepage allocation is unsupported.
>
> Before patch:
> -------------------------
> running ./hugetlb-madvise
> -------------------------
> TAP version 13
> 1..1
> [INFO] detected hugetlb page size: 16777216 KiB
> [INFO] detected hugetlb page size: 16384 KiB
> ok 1 MADV_DONTNEED and MADV_REMOVE on hugetlb
> Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> Bail out! /sys/kernel/mm/hugepages/hugepages-16777216kB/nr_hugepages
> write(0) failed: Invalid argument
> Totals: pass:0 fail:0 xfail:0 xpass:0 skip:0 error:0
> [FAIL]
>
> After patch:
> -------------------------
> running ./hugetlb-madvise
> -------------------------
> TAP version 13
> 1..1
> [INFO] detected hugetlb page size: 16777216 KiB
> [INFO] detected hugetlb page size: 16384 KiB
> ok 1 MADV_DONTNEED and MADV_REMOVE on hugetlb
> Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> [PASS]
>
> Fixes: 27477b28b74f ("selftests/mm: hugepage_settings: add APIs to get and set nr_hugepages")
> Co-developed-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
> ---
> .../testing/selftests/mm/hugepage_settings.c | 2 +-
> tools/testing/selftests/mm/vm_util.c | 26 ++++++++++++++++---
> tools/testing/selftests/mm/vm_util.h | 1 +
> 3 files changed, 24 insertions(+), 5 deletions(-)
>
Acked-by: Usama Arif <usama.arif@linux.dev>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 2/3] selftests/mm: fix ksm NUMA merge test for systems with memoryless NUMA nodes
2026-07-08 6:59 [PATCH v3 0/3] selftests/mm: avoid false failures in hugetlb and KSM tests Sayali Patil
2026-07-08 6:59 ` [PATCH v3 1/3] selftests/mm: handle EINVAL when configuring gigantic hugepages Sayali Patil
@ 2026-07-08 6:59 ` Sayali Patil
2026-07-08 13:55 ` Usama Arif
2026-07-08 6:59 ` [PATCH v3 3/3] selftests/mm: fix ternary operator precedence in ksm_tests Sayali Patil
2026-07-10 1:53 ` [PATCH v3 0/3] selftests/mm: avoid false failures in hugetlb and KSM tests Andrew Morton
3 siblings, 1 reply; 8+ messages in thread
From: Sayali Patil @ 2026-07-08 6:59 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan, linux-mm, linux-kernel,
linux-kselftest, Ritesh Harjani
Cc: David Hildenbrand, Zi Yan, Michal Hocko, Oscar Salvador,
Lorenzo Stoakes, Dev Jain, Liam.Howlett, linuxppc-dev, Miaohe Lin,
Venkat Rao Bagalkote, Sayali Patil
The KSM NUMA merge test allocates identical pages on different NUMA
nodes and verifies KSM behavior with merge_across_nodes enabled and
disabled.
On systems with memoryless NUMA nodes, for example:
#numactl -H
available: 2 nodes (0,4)
.....
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
node 0 size: 14825 MB
node 0 free: 1382 MB
node 4 cpus:
node 4 size: 0 MB
node 4 free: 0 MB
the test may attempt to allocate memory on a node without memory,
causing numa_alloc_onnode() to fail and resulting in a spurious test
failure.
The test currently checks numa_num_configured_nodes() to determine
whether sufficient NUMA nodes are available. However, configured nodes
do not necessarily have memory.
Reuse the existing get_first_mem_node() and get_next_mem_node()
helpers to locate NUMA nodes that actually contain memory, and skip
the test when fewer than two such nodes are available.
Before patch:
---------------------------
running ./ksm_tests -N -m 1
---------------------------
mbind: Invalid argument
ok 1 KSM NUMA merging
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
[PASS]
ok 1 ksm_tests -N -m 1
---------------------------
running ./ksm_tests -N -m 0
---------------------------
mbind: Invalid argument
not ok 1 KSM NUMA merging
Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
[FAIL]
not ok 2 ksm_tests -N -m 0 # exit=1
After patch:
---------------------------
running ./ksm_tests -N -m 1
---------------------------
At least 2 NUMA nodes with memory must be available
ok 1
SKIP KSM NUMA merging
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0
[PASS]
ok 1 ksm_tests -N -m 1
---------------------------
running ./ksm_tests -N -m 0
---------------------------
At least 2 NUMA nodes with memory must be available
ok 1
SKIP KSM NUMA merging
Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0
[PASS]
ok 2 ksm_tests -N -m 0
Fixes: e3820ab252dd ("selftest/vm: fix ksm selftest to run with different NUMA topologies")
Co-developed-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
---
tools/testing/selftests/mm/ksm_tests.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
index a050f4840cfa..2ebbb544c671 100644
--- a/tools/testing/selftests/mm/ksm_tests.c
+++ b/tools/testing/selftests/mm/ksm_tests.c
@@ -440,9 +440,9 @@ static int get_next_mem_node(int node)
mem_node = i % (max_node + 1);
node_size = numa_node_size(mem_node, NULL);
if (node_size > 0)
- break;
+ return mem_node;
}
- return mem_node;
+ return -ENODEV;
}
static int get_first_mem_node(void)
@@ -455,8 +455,8 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeo
{
void *numa1_map_ptr, *numa2_map_ptr;
struct timespec start_time;
+ int first_node, second_node;
int page_count = 2;
- int first_node;
if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) {
ksft_perror("clock_gettime");
@@ -467,17 +467,19 @@ static int check_ksm_numa_merge(int merge_type, int mapping, int prot, int timeo
ksft_print_msg("NUMA support not enabled\n");
return KSFT_SKIP;
}
- if (numa_num_configured_nodes() <= 1) {
- ksft_print_msg("At least 2 NUMA nodes must be available\n");
+ first_node = get_first_mem_node();
+ second_node = get_next_mem_node(first_node);
+
+ if (second_node < 0) {
+ ksft_print_msg("At least 2 NUMA nodes with memory must be available\n");
return KSFT_SKIP;
}
if (ksm_write_sysfs(KSM_FP("merge_across_nodes"), merge_across_nodes))
return KSFT_FAIL;
/* allocate 2 pages in 2 different NUMA nodes and fill them with the same data */
- first_node = get_first_mem_node();
numa1_map_ptr = numa_alloc_onnode(page_size, first_node);
- numa2_map_ptr = numa_alloc_onnode(page_size, get_next_mem_node(first_node));
+ numa2_map_ptr = numa_alloc_onnode(page_size, second_node);
if (!numa1_map_ptr || !numa2_map_ptr) {
ksft_perror("numa_alloc_onnode");
return KSFT_FAIL;
--
2.52.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v3 2/3] selftests/mm: fix ksm NUMA merge test for systems with memoryless NUMA nodes
2026-07-08 6:59 ` [PATCH v3 2/3] selftests/mm: fix ksm NUMA merge test for systems with memoryless NUMA nodes Sayali Patil
@ 2026-07-08 13:55 ` Usama Arif
0 siblings, 0 replies; 8+ messages in thread
From: Usama Arif @ 2026-07-08 13:55 UTC (permalink / raw)
To: Sayali Patil
Cc: Usama Arif, Andrew Morton, Shuah Khan, linux-mm, linux-kernel,
linux-kselftest, Ritesh Harjani, David Hildenbrand, Zi Yan,
Michal Hocko, Oscar Salvador, Lorenzo Stoakes, Dev Jain,
Liam.Howlett, linuxppc-dev, Miaohe Lin, Venkat Rao Bagalkote
On Wed, 8 Jul 2026 12:29:06 +0530 Sayali Patil <sayalip@linux.ibm.com> wrote:
> The KSM NUMA merge test allocates identical pages on different NUMA
> nodes and verifies KSM behavior with merge_across_nodes enabled and
> disabled.
>
> On systems with memoryless NUMA nodes, for example:
> #numactl -H
> available: 2 nodes (0,4)
> .....
> node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
> node 0 size: 14825 MB
> node 0 free: 1382 MB
> node 4 cpus:
> node 4 size: 0 MB
> node 4 free: 0 MB
>
> the test may attempt to allocate memory on a node without memory,
> causing numa_alloc_onnode() to fail and resulting in a spurious test
> failure.
>
> The test currently checks numa_num_configured_nodes() to determine
> whether sufficient NUMA nodes are available. However, configured nodes
> do not necessarily have memory.
>
> Reuse the existing get_first_mem_node() and get_next_mem_node()
> helpers to locate NUMA nodes that actually contain memory, and skip
> the test when fewer than two such nodes are available.
>
> Before patch:
> ---------------------------
> running ./ksm_tests -N -m 1
> ---------------------------
> mbind: Invalid argument
> ok 1 KSM NUMA merging
> Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> [PASS]
> ok 1 ksm_tests -N -m 1
> ---------------------------
> running ./ksm_tests -N -m 0
> ---------------------------
> mbind: Invalid argument
> not ok 1 KSM NUMA merging
> Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0
> [FAIL]
> not ok 2 ksm_tests -N -m 0 # exit=1
>
> After patch:
> ---------------------------
> running ./ksm_tests -N -m 1
> ---------------------------
> At least 2 NUMA nodes with memory must be available
> ok 1
> SKIP KSM NUMA merging
> Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0
> [PASS]
> ok 1 ksm_tests -N -m 1
> ---------------------------
> running ./ksm_tests -N -m 0
> ---------------------------
> At least 2 NUMA nodes with memory must be available
> ok 1
> SKIP KSM NUMA merging
> Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0
> [PASS]
> ok 2 ksm_tests -N -m 0
>
> Fixes: e3820ab252dd ("selftest/vm: fix ksm selftest to run with different NUMA topologies")
> Co-developed-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
> ---
> tools/testing/selftests/mm/ksm_tests.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
Acked-by: Usama Arif <usama.arif@linux.dev>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 3/3] selftests/mm: fix ternary operator precedence in ksm_tests
2026-07-08 6:59 [PATCH v3 0/3] selftests/mm: avoid false failures in hugetlb and KSM tests Sayali Patil
2026-07-08 6:59 ` [PATCH v3 1/3] selftests/mm: handle EINVAL when configuring gigantic hugepages Sayali Patil
2026-07-08 6:59 ` [PATCH v3 2/3] selftests/mm: fix ksm NUMA merge test for systems with memoryless NUMA nodes Sayali Patil
@ 2026-07-08 6:59 ` Sayali Patil
2026-07-10 1:53 ` [PATCH v3 0/3] selftests/mm: avoid false failures in hugetlb and KSM tests Andrew Morton
3 siblings, 0 replies; 8+ messages in thread
From: Sayali Patil @ 2026-07-08 6:59 UTC (permalink / raw)
To: Andrew Morton, Shuah Khan, linux-mm, linux-kernel,
linux-kselftest, Ritesh Harjani
Cc: David Hildenbrand, Zi Yan, Michal Hocko, Oscar Salvador,
Lorenzo Stoakes, Dev Jain, Liam.Howlett, linuxppc-dev, Miaohe Lin,
Venkat Rao Bagalkote, Sayali Patil
The KSM selftest uses conditional expressions to skip accesses to
merge_across_nodes on systems without NUMA support. However, the
ternary operator is combined with logical OR without parentheses:
a || numa_available() ? 0 : b || c
Due to operator precedence rules, this is parsed as:
(a || numa_available()) ? 0 : (b || c)
instead of the intended:
a || (numa_available() ? 0 : b) || c
Add parentheses around the conditional expressions to ensure the
correct evaluation order.
Fixes: 9aa1af954db0 ("selftests: vm: check numa_available() before operating "merge_across_nodes" in ksm_tests")
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Sayali Patil <sayalip@linux.ibm.com>
---
tools/testing/selftests/mm/ksm_tests.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
index 2ebbb544c671..5fd7792a0d47 100644
--- a/tools/testing/selftests/mm/ksm_tests.c
+++ b/tools/testing/selftests/mm/ksm_tests.c
@@ -288,8 +288,8 @@ static bool assert_ksm_pages_count(long dupl_page_count)
static int ksm_save_def(struct ksm_sysfs *ksm_sysfs)
{
if (ksm_read_sysfs(KSM_FP("max_page_sharing"), &ksm_sysfs->max_page_sharing) ||
- numa_available() ? 0 :
- ksm_read_sysfs(KSM_FP("merge_across_nodes"), &ksm_sysfs->merge_across_nodes) ||
+ (numa_available() ? 0 :
+ ksm_read_sysfs(KSM_FP("merge_across_nodes"), &ksm_sysfs->merge_across_nodes)) ||
ksm_read_sysfs(KSM_FP("sleep_millisecs"), &ksm_sysfs->sleep_millisecs) ||
ksm_read_sysfs(KSM_FP("pages_to_scan"), &ksm_sysfs->pages_to_scan) ||
ksm_read_sysfs(KSM_FP("run"), &ksm_sysfs->run) ||
@@ -304,8 +304,8 @@ static int ksm_save_def(struct ksm_sysfs *ksm_sysfs)
static int ksm_restore(struct ksm_sysfs *ksm_sysfs)
{
if (ksm_write_sysfs(KSM_FP("max_page_sharing"), ksm_sysfs->max_page_sharing) ||
- numa_available() ? 0 :
- ksm_write_sysfs(KSM_FP("merge_across_nodes"), ksm_sysfs->merge_across_nodes) ||
+ (numa_available() ? 0 :
+ ksm_write_sysfs(KSM_FP("merge_across_nodes"), ksm_sysfs->merge_across_nodes)) ||
ksm_write_sysfs(KSM_FP("pages_to_scan"), ksm_sysfs->pages_to_scan) ||
ksm_write_sysfs(KSM_FP("run"), ksm_sysfs->run) ||
ksm_write_sysfs(KSM_FP("sleep_millisecs"), ksm_sysfs->sleep_millisecs) ||
@@ -846,8 +846,8 @@ int main(int argc, char *argv[])
if (ksm_write_sysfs(KSM_FP("run"), 2) ||
ksm_write_sysfs(KSM_FP("sleep_millisecs"), 0) ||
- numa_available() ? 0 :
- ksm_write_sysfs(KSM_FP("merge_across_nodes"), 1) ||
+ (numa_available() ? 0 :
+ ksm_write_sysfs(KSM_FP("merge_across_nodes"), 1)) ||
ksm_write_sysfs(KSM_FP("pages_to_scan"), page_count))
ksft_exit_fail_msg("Cannot set up KSM tunables\n");
--
2.52.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v3 0/3] selftests/mm: avoid false failures in hugetlb and KSM tests
2026-07-08 6:59 [PATCH v3 0/3] selftests/mm: avoid false failures in hugetlb and KSM tests Sayali Patil
` (2 preceding siblings ...)
2026-07-08 6:59 ` [PATCH v3 3/3] selftests/mm: fix ternary operator precedence in ksm_tests Sayali Patil
@ 2026-07-10 1:53 ` Andrew Morton
3 siblings, 0 replies; 8+ messages in thread
From: Andrew Morton @ 2026-07-10 1:53 UTC (permalink / raw)
To: Sayali Patil
Cc: Shuah Khan, linux-mm, linux-kernel, linux-kselftest,
Ritesh Harjani, David Hildenbrand, Zi Yan, Michal Hocko,
Oscar Salvador, Lorenzo Stoakes, Dev Jain, Liam.Howlett,
linuxppc-dev, Miaohe Lin, Venkat Rao Bagalkote
On Wed, 8 Jul 2026 12:29:04 +0530 Sayali Patil <sayalip@linux.ibm.com> wrote:
> This series fixes issues in the hugetlb and KSM MM selftest categories
> that can report failures when the prerequisites for the tests are not
> satisfied.
Thanks. AI review asked one question:
https://sashiko.dev/#/patchset/cover.1783446924.git.sayalip@linux.ibm.com
^ permalink raw reply [flat|nested] 8+ messages in thread