Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Preetam Sundar Das" <daspreetam4@gmail.com>, nphamcs@gmail.com
Cc: hannes@cmpxchg.org, shuah@kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] selftests/cachestat: test unaligned and zero-length ranges
Date: Sat, 05 Dec 2026 22:26:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-251961@kernel.org> (raw)
In-Reply-To: <20261204222623.50735-1-daspreetam4@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] selftests/cachestat: allow_eperm masks regressions and
  hardcodes index
- [Low] selftests/cachestat: read of clobbered errno after
  ksft_print_msg()
- [Low] selftests/cachestat: setup errors reported as test failures in
  ranges
- [Low] selftests/cachestat: empty commit message bundles unrelated
  fixes
--

commit 53d9d32356be8f076423856bd41d85c09de99078
Author: Preetam Sundar Das <daspreetam4@gmail.com>

> selftests/cachestat: test unaligned and zero-length ranges
>
> Signed-off-by: Preetam Sundar Das <daspreetam4@gmail.com>

[Severity: Low]
This commit message has no body explaining the new range tests, and the
patch bundles two unrelated changes not mentioned in the subject:

- adding allow_eperm for /proc/version and /proc after commit
  5f537664e705 ("cachestat: fix page cache statistics permission
  checking"), and
- bumping NR_TESTS by 3 instead of 2 to fix the count mismatch from
  commit d6a511dea45c ("selftests: cachestat: add tests for mmap,
  refactor and enhance mmap test for cachestat validation").

Should those two fixes be split into separate patches, with a brief
changelog added here?

> diff --git a/tools/testing/selftests/cachestat/test_cachestat.c b/tools/testing/selftests/cachestat/test_cachestat.c
> index 542cd09cb4434..c7aa58bdcf7af 100644
> --- a/tools/testing/selftests/cachestat/test_cachestat.c
> +++ b/tools/testing/selftests/cachestat/test_cachestat.c

[ ... ]

> @@ -154,10 +154,14 @@ static int test_cachestat(const char *filename, bool write_random, bool create,
>  	ksft_print_msg("Cachestat call returned %ld\n", syscall_ret);
>  
>  	if (syscall_ret) {
> -		ksft_print_msg("Cachestat returned non-zero.\n");
> -		ret = KSFT_FAIL;
> -		goto out1;
> -
> +		if (allow_eperm && errno == EPERM) {
> +			ksft_print_msg("Cachestat denied by permission check.\n");
> +		} else {
> +			ksft_print_msg("Cachestat returned non-zero: %s.\n",
> +				       strerror(errno));
> +			ret = KSFT_FAIL;
> +			goto out1;
> +		}
>  	} else {

[Severity: Low]
Can ksft_print_msg() clobber errno before it is checked here?

ksft_print_msg() in tools/testing/selftests/kselftest.h restores errno
before calling vprintf(), but not after vprintf() returns.  If vprintf()
modifies errno, test_cachestat() can misclassify a valid EPERM as a
failure or print the wrong strerror() message.

Saving errno immediately after syscall(__NR_cachestat, ...) avoids this.

[ ... ]

> +static int test_cachestat_ranges(void)
> +{
> +	size_t ps = sysconf(_SC_PAGESIZE);
> +	int fd, ret = 0;
> +
> +	fd = open("tmpfilecachestat-range",
> +		  O_CREAT | O_RDWR | O_TRUNC, 0600);
> +	if (fd < 0) {
> +		ksft_print_msg("Unable to create range test file.\n");
> +		return 0;
> +	}
> +
> +	if (!write_exactly(fd, 4 * ps)) {
> +		ksft_print_msg("Unable to populate range test file.\n");
> +		goto out;
> +	}

[Severity: Low]
Should setup failures in open() or write_exactly() be reported with
ksft_test_result_error() instead of ksft_test_result_fail()?

Returning 0 on those paths produces the same bitmask as both
check_cachestat_range() calls failing, so main() reports both range
tests as kernel failures even though cachestat() was never called.

Reporting results directly in test_cachestat_ranges() or returning a
distinct error status would keep setup errors separate.

[ ... ]

> @@ -317,9 +375,9 @@ int main(void)
>  	for (int i = 0; i < 5; i++) {
>  		const char *dev_filename = dev_files[i];
>  
> -		if (test_cachestat(dev_filename, false, false, false,
> -			4, O_RDONLY, 0400) == KSFT_PASS)
> -			ksft_test_result_pass("cachestat works with %s\n", dev_filename);
> +		if (test_cachestat(dev_filename, false, false, false, i >= 3,
> +				   4, O_RDONLY, 0400) == KSFT_PASS)
> +			ksft_test_result_pass("cachestat handles %s\n", dev_filename);
>  		else {
>  			ksft_test_result_fail("cachestat fails with %s\n", dev_filename);
>  			ret = 1;

[Severity: Medium]
Does accepting both 0 and EPERM as KSFT_PASS mask permission regressions
in can_do_cachestat()?

With allow_eperm set unconditionally for /proc/version and /proc, a
privileged run that wrongly returns EPERM passes silently, and an
unprivileged run that wrongly succeeds on those root-owned read-only
files also passes.

Validating the expected result based on caller permissions, or reporting
KSFT_SKIP with a reason when unprivileged, would preserve coverage.

In addition, passing i >= 3 with a hardcoded loop bound of 5 couples
allow_eperm to dev_files[] ordering; pairing each path with its expected
behavior in a table using ARRAY_SIZE() avoids silent breakage on edits.

Also, the allow_eperm branch in test_cachestat() does not jump to out1,
so it would fall through into the test_fsync block if those flags were
ever combined.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204222623.50735-1-daspreetam4@gmail.com?part=1


      parent reply	other threads:[~2026-12-05 22:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 22:26 [PATCH] selftests/cachestat: test unaligned and zero-length ranges Preetam Sundar Das
2026-12-04 22:39 ` Nhat Pham
2026-12-05  9:20   ` Preetam Sundar Das
2026-12-05 12:53   ` Preetam Sundar Das
2026-12-05 13:04   ` Preetam Sundar Das
2026-12-05 22:26 ` 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-251961@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=daspreetam4@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox