linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: ksm_tests: skip when not run as root
@ 2026-01-09  9:43 Sun Jian
  2026-01-10  1:16 ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: Sun Jian @ 2026-01-09  9:43 UTC (permalink / raw)
  To: Shuah Khan
  Cc: linux-kselftest, linux-mm, Andrew Morton, linux-kernel, Sun Jian

ksm_tests writes KSM sysfs knobs under /sys/kernel/mm/ksm, which requires
root privileges. When run unprivileged, it fails with permission errors
and reports FAIL, which is misleading.

Skip the test early when not run as root to avoid false failures.

Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
 tools/testing/selftests/mm/ksm_tests.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
index a0b48b839d54..c22cd9c61711 100644
--- a/tools/testing/selftests/mm/ksm_tests.c
+++ b/tools/testing/selftests/mm/ksm_tests.c
@@ -766,6 +766,11 @@ int main(int argc, char *argv[])
 	bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT;
 	long size_MB = 0;
 
+	if (geteuid() != 0) {
+		printf("# SKIP ksm_tests requires root privileges\n");
+		return KSFT_SKIP;
+	}
+
 	while ((opt = getopt(argc, argv, "dha:p:l:z:m:s:t:MUZNPCHD")) != -1) {
 		switch (opt) {
 		case 'a':
-- 
2.43.0



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

* Re: [PATCH] selftests/mm: ksm_tests: skip when not run as root
  2026-01-09  9:43 [PATCH] selftests/mm: ksm_tests: skip when not run as root Sun Jian
@ 2026-01-10  1:16 ` SeongJae Park
  2026-01-10 12:44   ` sun jian
  0 siblings, 1 reply; 4+ messages in thread
From: SeongJae Park @ 2026-01-10  1:16 UTC (permalink / raw)
  To: Sun Jian
  Cc: SeongJae Park, Shuah Khan, linux-kselftest, linux-mm,
	Andrew Morton, linux-kernel

On Fri,  9 Jan 2026 17:43:13 +0800 Sun Jian <sun.jian.kdev@gmail.com> wrote:

> ksm_tests writes KSM sysfs knobs under /sys/kernel/mm/ksm, which requires
> root privileges. When run unprivileged, it fails with permission errors
> and reports FAIL, which is misleading.
> 
> Skip the test early when not run as root to avoid false failures.
> 
> Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
> ---
>  tools/testing/selftests/mm/ksm_tests.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c
> index a0b48b839d54..c22cd9c61711 100644
> --- a/tools/testing/selftests/mm/ksm_tests.c
> +++ b/tools/testing/selftests/mm/ksm_tests.c
> @@ -766,6 +766,11 @@ int main(int argc, char *argv[])
>  	bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT;
>  	long size_MB = 0;
>  
> +	if (geteuid() != 0) {
> +		printf("# SKIP ksm_tests requires root privileges\n");
> +		return KSFT_SKIP;

What about using ksft_exit_skip() instead, like compaction_test.c does?


Thanks,
SJ

[...]


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

* Re: [PATCH] selftests/mm: ksm_tests: skip when not run as root
  2026-01-10  1:16 ` SeongJae Park
@ 2026-01-10 12:44   ` sun jian
  2026-01-10 17:00     ` SeongJae Park
  0 siblings, 1 reply; 4+ messages in thread
From: sun jian @ 2026-01-10 12:44 UTC (permalink / raw)
  To: SeongJae Park
  Cc: Shuah Khan, linux-kselftest, linux-mm, Andrew Morton, linux-kernel

On Sat, Jan 10, 2026 at 9:16 AM SeongJae Park <sj@kernel.org> wrote:
> What about using ksft_exit_skip() instead, like compaction_test.c does?
ksm_tests is a legacy selftest binary and doesn't use kselftest harness/TAP
APIs. It only includes kselftest.h for the KSFT_* exit codes.

This patch is a minimal prerequisite fix. Returning KSFT_SKIP already
provides the correct semantic to the runner, without pulling ksm_tests into the
harness model, which would be a larger refactor.

Regards,
Sun Jian


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

* Re: [PATCH] selftests/mm: ksm_tests: skip when not run as root
  2026-01-10 12:44   ` sun jian
@ 2026-01-10 17:00     ` SeongJae Park
  0 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2026-01-10 17:00 UTC (permalink / raw)
  To: sun jian
  Cc: SeongJae Park, Shuah Khan, linux-kselftest, linux-mm,
	Andrew Morton, linux-kernel

On Sat, 10 Jan 2026 20:44:21 +0800 sun jian <sun.jian.kdev@gmail.com> wrote:

> On Sat, Jan 10, 2026 at 9:16 AM SeongJae Park <sj@kernel.org> wrote:
> > What about using ksft_exit_skip() instead, like compaction_test.c does?
> ksm_tests is a legacy selftest binary and doesn't use kselftest harness/TAP
> APIs. It only includes kselftest.h for the KSFT_* exit codes.
> 
> This patch is a minimal prerequisite fix. Returning KSFT_SKIP already
> provides the correct semantic to the runner, without pulling ksm_tests into the
> harness model, which would be a larger refactor.

I agree such refactoring would be unnecessary for this small change.  But you
can use ksft_exit_skip() without such refactoring, isn't it?  The function is
declared in kselftest.h, not kselftest_harness.h.  ksm_functional_tests.c is
also using ksft_exit_skip() without the harness model.


Thanks,
SJ

[...]


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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-09  9:43 [PATCH] selftests/mm: ksm_tests: skip when not run as root Sun Jian
2026-01-10  1:16 ` SeongJae Park
2026-01-10 12:44   ` sun jian
2026-01-10 17:00     ` SeongJae Park

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