All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xu Xin (vivo)" <xu.xin@linux.dev>
Cc: akpm@linux-foundation.org, chengming.zhou@linux.dev,
	david@kernel.org, donettom@linux.ibm.com, linux-mm@kvack.org
Subject: Re: [PATCH v2 3/3] selftests/mm: verify ksm_zero_pages is not inherited on fork
Date: Sat, 21 Nov 2026 07:45:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-226796@kernel.org> (raw)
In-Reply-To: <20261120074459.41517-1-xu.xin@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/mm: unchecked negative error returns in
  test_fork_ksm_statistic_count()
--

commit a4b057316a412b00cfd864404acbc77cd671159c
Author: Xu Xin (vivo) <xu.xin@linux.dev>

selftests/mm: verify ksm_zero_pages is not inherited on fork

This commit renames test_fork_ksm_merging_page_count() to
test_fork_ksm_statistic_count() and extends it to verify that neither
ksm_merging_pages nor ksm_zero_pages is inherited across fork().

> diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
> index c20982b0aff0e..321f8abc85f91 100644
> --- a/tools/testing/selftests/mm/ksm_functional_tests.c
> +++ b/tools/testing/selftests/mm/ksm_functional_tests.c
> @@ -655,40 +655,57 @@ static void test_prot_none(void)
>  	munmap(map, size);
>  }
>  
> -static void test_fork_ksm_merging_page_count(void)
> +static void test_fork_ksm_statistic_count(void)
>  {
>  	const unsigned int size = 2 * MiB;
>  	char *map;
> +	char *zero_map;
>  	pid_t child_pid;
>  	int status;
>  
>  	ksft_print_msg("[RUN] %s\n", __func__);
>  
> +	if (ksm_use_zero_pages() < 0) {
> +		ksft_test_result_skip("write \"/sys/kernel/mm/ksm/use_zero_pages\" failed\n");
> +		return;
> +	}
> +
>  	map = mmap_and_merge_range(0xcf, size, PROT_READ | PROT_WRITE, KSM_MERGE_MADVISE);
>  	if (map == MAP_FAILED)
>  		return;
>  
> +	zero_map = mmap_and_merge_range(0x00, size, PROT_READ | PROT_WRITE, KSM_MERGE_MADVISE);
> +	if (zero_map == MAP_FAILED)
> +		goto unmap;
> +
> +	if (!ksm_get_self_merging_pages() || !ksm_get_self_zero_pages()) {
> +		ksft_test_result_fail("KSM failed to merge pages before fork\n");
> +		goto unmap_zero;
> +	}
> +
>  	child_pid = fork();
>  	if (!child_pid) {
> -		exit(ksm_get_self_merging_pages());
> +		exit(!!(ksm_get_self_merging_pages() + ksm_get_self_zero_pages()));

[Severity: Low]
Can negative error returns from ksm_get_self_zero_pages() or
ksm_get_self_merging_pages() bypass the pre-fork check and corrupt the
child status check?

Both helpers return a negative error code on open() or pread() failure
(for example when /proc/self/ksm_stat is unavailable, which
test_unmerge_zero_pages() checks for with ksm_get_self_zero_pages() < 0
to skip the test).  Because a negative value is non-zero, testing with !
treats the error as a valid positive page count before fork(), and
summing the two signed values in the child either causes the test to fail
instead of skipping or allows a negative error return to cancel out an
equal positive page count.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120074230.40269-1-xu.xin@linux.dev?part=3


      reply	other threads:[~2026-11-21  7:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  7:42 [PATCH v2 0/3] mm/ksm: fix ksm_zero_pages accounting on fork Xu Xin (vivo)
2026-11-20  7:43 ` [PATCH v2 1/3] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers " Xu Xin (vivo)
2026-11-20  7:44 ` [PATCH v2 2/3] selftests/mm: fix false-positive KSM fork test by dropping init_global_file_handles() Xu Xin (vivo)
2026-11-21  7:45   ` sashiko-bot
2026-11-20  7:44 ` [PATCH v2 3/3] selftests/mm: verify ksm_zero_pages is not inherited on fork Xu Xin (vivo)
2026-11-21  7:45   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-226796@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=david@kernel.org \
    --cc=donettom@linux.ibm.com \
    --cc=linux-mm@kvack.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xu.xin@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.