Hi Rik,

On Fri, Jul 24, 2026 at 06:29:34PM -0400, Rik van Riel wrote:
> follow_page_mask() now batches a PTE-mapped large folio (mTHP) into one
> contiguous run for the slow get_user_pages() path. A mis-batched run would
> hand back the wrong pages or a stale COW copy, which the existing tests do
> not catch: gup_test checks only pin/unpin integrity, and cow exercises COW
> mostly at PMD size.
> 
> Add mthp_gup_cow_test. It forces 64kB-only mTHP, writes a per-page-distinct
> pattern, then pins the region on the slow path (PIN_LONGTERM without
> USE_FAST) and compares the bytes the kernel copies back from the pinned
> pages against that pattern.
> 
> The test covers a read pin, a write pin, and COW after fork(): a child
> write-pins to force per-page unshare and checks the copied contents, then
> rewrites its copy while the parent verifies its own contents are intact.
> 
> It also reports how many pages sit in contiguous large-folio runs, so a
> kernel without mTHP shows light coverage rather than passing vacuously.
> 
> Assisted-by: Claude:claude-opus-4.8
> Signed-off-by: Rik van Riel <[email protected]>
> ---
>  tools/testing/selftests/mm/Makefile           |   1 +
>  .../testing/selftests/mm/mthp_gup_cow_test.c  | 213 ++++++++++++++++++
>  tools/testing/selftests/mm/run_vmtests.sh     |   1 +
>  3 files changed, 215 insertions(+)
>  create mode 100644 tools/testing/selftests/mm/mthp_gup_cow_test.c
> 
> +
> +static long PS;
> +static int fails;
> +static int tap;
> +
> +static void ok(int cond, const char *desc)
> +{
> +     printf("%s %d %s\n", cond ? "ok" : "not ok", ++tap, desc);

Please (instruct claude to) use ksft_* helpers for printing messages and
tracking failed and passed tests.

> +     if (!cond)
> +             fails++;
> +}
> +
> +/* Deterministic, per-page-distinct pattern so any mis-order or leak shows. 
> */
> +static void fill(char *base, size_t sz, uint32_t salt)
> +{
> +     for (size_t off = 0; off < sz; off += PS) {
> +             uint32_t k = off / PS;
> +             uint64_t v = ((uint64_t)salt << 32) ^ (k * 0x9E3779B1u + 
> 0x1234);
> +
> +             for (size_t i = 0; i < PS; i += sizeof(v))
> +                     memcpy(base + off + i, &v, sizeof(v));
> +     }
> +}
> +
> +static int wsysfs(const char *path, const char *val)

There are existing helpers to read/write sysfs in vm_util.h

> +{
> +     int fd = open(path, O_WRONLY);
> +
> +     if (fd < 0)
> +             return -1;
> +     int r = write(fd, val, strlen(val));
> +
> +     close(fd);
> +     return r < 0 ? -1 : 0;
> +}

-- 
Sincerely yours,
Mike.

Reply via email to