[PATCH v4 0/5] selftests/mm: skip several tests when thp is not available

Chunyu Hu posted 5 patches 2 weeks, 3 days ago
There is a newer version of this series
tools/testing/selftests/mm/guard-regions.c    |  4 ++++
tools/testing/selftests/mm/soft-dirty.c       |  4 +++-
.../selftests/mm/split_huge_page_test.c       | 19 ++++-----------
tools/testing/selftests/mm/thp_settings.c     | 24 +------------------
tools/testing/selftests/mm/thp_settings.h     |  1 -
tools/testing/selftests/mm/transhuge-stress.c |  4 ++++
tools/testing/selftests/mm/vm_util.c          | 16 +++++++++++++
tools/testing/selftests/mm/vm_util.h          |  2 ++
8 files changed, 34 insertions(+), 40 deletions(-)
[PATCH v4 0/5] selftests/mm: skip several tests when thp is not available
Posted by Chunyu Hu 2 weeks, 3 days ago
There are several tests requires transprarent hugepages, when run on thp
disabled kernel such as realtime kernel, there will be false negative.
Mark those tests as skip when thp is not available.

Changes in v4:
  - patch 1 update to use thp_available instead of thp_is_enabled,
    suggested by ai review
  - removed reviewed-by and acked-by

Changes in v3:
  - patch 1 update commit message to show the log snippet with where the
    fail happens, change the 'false positive' to 'false negative'.
    Update reviwed by
  - patch 2 update reviewed-by
  - patch 3 make write_file to void return
  - patch 4 and patch 5 updated reviewed-by/acked-by

Changes in v2:
  - replace 'false postive' with 'false negative' in cover letter
  - patch 1 and patch 2 add reviewed-by/acked-by
  - new patch 3 to add write_file() in vm_util as a common helper
  - patch 4 removed the {} in if block, removed the write_file helper
    rename chunk in v1. Add reviewed-by
  - patch 5 move the exit chunk to the front of ksft_print_headers() as
    suggested by David.  Add review by.

Chunyu Hu (5):
  selftests/mm/guard-regions: skip collapse test when thp not enabled
  selftests/mm: soft-dirty: skip two tests when thp is not available
  selftests/mm: move write_file helper to vm_util
  selftests/mm: split_huge_page_test: skip the test when thp is not
    available
  selftests/mm: transhuge_stress: skip the test when thp not available

 tools/testing/selftests/mm/guard-regions.c    |  4 ++++
 tools/testing/selftests/mm/soft-dirty.c       |  4 +++-
 .../selftests/mm/split_huge_page_test.c       | 19 ++++-----------
 tools/testing/selftests/mm/thp_settings.c     | 24 +------------------
 tools/testing/selftests/mm/thp_settings.h     |  1 -
 tools/testing/selftests/mm/transhuge-stress.c |  4 ++++
 tools/testing/selftests/mm/vm_util.c          | 16 +++++++++++++
 tools/testing/selftests/mm/vm_util.h          |  2 ++
 8 files changed, 34 insertions(+), 40 deletions(-)


base-commit: 8a30aeb0d1b4e4aaf7f7bae72f20f2ae75385ccb
-- 
2.53.0
Re: [PATCH v4 0/5] selftests/mm: skip several tests when thp is not available
Posted by Andrew Morton 2 weeks, 3 days ago
On Fri, 20 Mar 2026 00:06:51 +0800 Chunyu Hu <chuhu@redhat.com> wrote:

> There are several tests requires transprarent hugepages, when run on thp
> disabled kernel such as realtime kernel, there will be false negative.
> Mark those tests as skip when thp is not available.

A couple of questions from Sashiko:
	https://sashiko.dev/#/patchset/20260319160656.1480279-1-chuhu%40redhat.com
Re: [PATCH v4 0/5] selftests/mm: skip several tests when thp is not available
Posted by Chunyu Hu 2 weeks ago
On Thu, Mar 19, 2026 at 07:46:04PM -0700, Andrew Morton wrote:
> On Fri, 20 Mar 2026 00:06:51 +0800 Chunyu Hu <chuhu@redhat.com> wrote:
> 
> > There are several tests requires transprarent hugepages, when run on thp
> > disabled kernel such as realtime kernel, there will be false negative.
> > Mark those tests as skip when thp is not available.
> 
> A couple of questions from Sashiko:
> 	https://sashiko.dev/#/patchset/20260319160656.1480279-1-chuhu%40redhat.com
> 

AI question one:
```
> +void write_file(const char *path, const char *buf, size_t buflen)
> +{
> +	int fd;
> +	ssize_t numwritten;
> +
> +	fd = open(path, O_WRONLY);
> +	if (fd == -1)
> +		ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno));
> +
> +	numwritten = write(fd, buf, buflen - 1);
Is it safe to keep the buflen - 1 behavior in a shared generic utility?
Since this is now a generic API in vm_util, callers passing the exact buffer
size (like sizeof(buf) or strlen(buf)) will suffer a 1-byte data truncation.
Additionally, if a caller passes buflen = 0, buflen - 1 will underflow,
causing write() to attempt writing an invalid size.
```

Here I think there's no single anwser. We can use buflen, but if user don't
provide a '\0' in the end of buffer, out of boundary access could happen
when such as printf(). We called it buflen, then we expect it's a '\0'
ended buffer as I undersand. So maye we can just leave as it is and user
should be awared of the requiremnt of the helper here.


AI question two:
```
> +	close(fd);
> +	if (numwritten < 1)
> +		ksft_exit_fail_msg("Write failed\n");

Does this drop useful debugging context compared to the previous version
in thp_settings.c?
The old implementation printed the buffer contents on failure. With this
generic message, if a test fails to write, it will only print "Write failed"
without indicating which file path failed, what data was being written, or
the underlying errno.
```

That makes sense, indeed we dropped the printing of the buffer content
compared with the version in the thp_settings.c. I can append a new
patch in v5 to improve this, together with other safety checks.