All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>,
	Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: "Zi Yan" <ziy@nvidia.com>,
	"Baolin Wang" <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Nico Pache" <nico.pache@linux.dev>,
	"Ryan Roberts" <ryan.roberts@arm.com>,
	"Dev Jain" <dev.jain@arm.com>, "Barry Song" <baohua@kernel.org>,
	"Lance Yang" <lance.yang@linux.dev>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Kiryl Shutsemau" <kas@kernel.org>,
	"Peter Xu" <peterx@redhat.com>,
	"Alex Williamson" <alex@shazbot.org>,
	kvm@vger.kernel.org,
	"Loïc Molinari" <loic.molinari@collabora.com>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Shuah Khan" <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, dri-devel@lists.freedesktop.org,
	"Madhavan Srinivasan" <maddy@linux.ibm.com>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, "Jason Gunthorpe" <jgg@ziepe.ca>,
	"Yeoreum Yun" <yeoreum.yun@arm.com>
Subject: Re: [PATCH v6 4/4] selftests/mm: test fork of PMD-mapped shmem THPs
Date: Sun, 22 Nov 2026 17:44:54 +0100	[thread overview]
Message-ID: <cb535634-2d87-451f-be28-ba975281dde8@kernel.org> (raw)
In-Reply-To: <20261119103210.24a7612ee26c3ffc3db49451@linux-foundation.org>

On 11/19/26 19:32, Andrew Morton wrote:
> On Thu, 19 Nov 2026 14:44:05 +0100 Konstantin Khorenko <khorenko@virtuozzo.com> wrote:
> 
>> Fork a process that maps shmem THPs with PMDs, in a VMA whose page
>> tables fork copies: a private mapping with an anon_vma, and a shared
>> one with a guard region. The child must find the PMDs before it
>> touches the mapping, and its exit must leave the parent's mapping and
>> the system-wide ShmemPmdMapped counter as they were.
>>
>> With folio_dup_file_rmap_pmd() adding PTE mappings, the child's exit
>> takes the parent's share off ShmemPmdMapped while the parent still maps
>> the folios. Unmapping them drops it once more, so every mapping stays
>> until exit, where the kernel reports "Bad page cache", or hits a
>> VM_BUG_ON with CONFIG_DEBUG_VM. A kernel that leaves file THPs to a
>> refault in the child skips the test.
>>
>> ShmemPmdMapped is system-wide, and reclaim or NUMA balancing can take a
>> PMD from the parent while the test runs. So the test makes up to three
>> attempts, each on a fresh file, and fails only if all of them see the
>> counter drop by exactly the parent's share: the bug does that on every
>> fork, other processes only by chance. It passes on the first clean
>> attempt and skips when none is clean.
>>
>> The test mounts a tmpfs with huge=always over /tmp in a private mount
>> namespace, so it leaves the THP settings and the host's mounts and
>> files alone.
>>
>> ...
>>
>> +static void test_fork(bool shared)
>> +{
>> +	const char *desc = shared ? "shared mapping with a guard region" :
>> +				    "private mapping with an anon_vma";
>> +	long before = 0, after = 0;
>> +	enum result res = NO_THP;
>> +	int i, drops = 0;
>> +	char *mem;
>> +
>> +	for (i = 0; i < ATTEMPTS; i++) {
>> +		mem = map_file(shared);
>> +		/* Make fork copy the page tables; the last PMD gets zapped. */
>> +		if (shared) {
>> +			if (madvise(mem + size - pagesize, pagesize,
>> +				    MADV_GUARD_INSTALL)) {
>> +				ksft_test_result_skip("%s: MADV_GUARD_INSTALL: %s\n",
>> +						      desc, strerror(errno));
>> +				return;
>> +			}
>> +		} else {
>> +			mem[size - pagesize] = 'p';
>> +		}
>> +
>> +		res = pmds_ok(mem) ? fork_once(mem, shared, &before, &after) :
>> +				     res == NO_THP ? NO_THP : LOST_PMDS;
>> +		/* Later children get only their own mapping. */
>> +		madvise(mem, size, MADV_DONTFORK);
> 
> autobot want the return value checked:
> 
> : If this fails, the next child inherits an earlier test mapping too. 
> : Its exit can then change ShmemPmdMapped by more than the expected
> : amount, causing the test to skip a real failure.
> 
> which seems ignorable - MADV_DONTFORK failures are super unlikely at present.
> 
>>
>> ...
>>
>> +int main(void)
>> +{
>> +	ksft_print_header();
>> +	pagesize = getpagesize();
>> +	pmdsize = read_pmd_pagesize();
> 
> This is going to ruin Mark's day again, thanks to "kselftest: mm:
> rename read_pmd_pagesize() to pmd_psize()".
> 
> I think I'll alter Yeoreum's above patch like this (presently untested):
> 
> --- a/tools/testing/selftests/mm/vm_util.h~kselftest-mm-rename-read_pmd_pagesize-to-pmd_psize-fix
> +++ a/tools/testing/selftests/mm/vm_util.h
> @@ -93,6 +93,8 @@ unsigned long pagemap_get_pfn(int fd, ch
>  void clear_softdirty(void);
>  bool check_for_pattern(FILE *fp, const char *pattern, char *buf, size_t len);
>  uint64_t pmd_psize(void);
> +/* temporary cross-tree compatibility thing: */
> +#define read_pmd_pagesize() pmd_psize()

Thanks! Otherwise we could route selftest through a single tree.

They would fail on the tree until the fix is in ... but that's rpecisely what
selftests are for.

-- 
Cheers,

David


  reply	other threads:[~2026-11-22 16:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 13:44 [PATCH v6 0/4] mm/huge_memory: copy PMDs at fork like the PTE path does Konstantin Khorenko
2026-11-19 13:44 ` [PATCH v6 1/4] mm/rmap: duplicate a PMD mapping as one in folio_dup_file_rmap_pmd() Konstantin Khorenko
2026-11-19 13:44 ` [PATCH v6 2/4] mm/huge_memory: copy file THPs at fork like copy_present_ptes() does Konstantin Khorenko
2026-11-22 16:38   ` David Hildenbrand (Arm)
2026-11-19 13:44 ` [PATCH v6 3/4] mm/huge_memory: read a special PMD under the lock in copy_huge_pmd() Konstantin Khorenko
2026-11-19 13:44 ` [PATCH v6 4/4] selftests/mm: test fork of PMD-mapped shmem THPs Konstantin Khorenko
2026-11-19 18:32   ` Andrew Morton
2026-11-22 16:44     ` David Hildenbrand (Arm) [this message]
2026-11-22 16:52   ` David Hildenbrand (Arm)
2026-11-22 17:00 ` (subset) [PATCH v6 0/4] mm/huge_memory: copy PMDs at fork like the PTE path does David Hildenbrand

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=cb535634-2d87-451f-be28-ba975281dde8@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex@shazbot.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=dev.jain@arm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jgg@ziepe.ca \
    --cc=kas@kernel.org \
    --cc=khorenko@virtuozzo.com \
    --cc=kvm@vger.kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=ljs@kernel.org \
    --cc=loic.molinari@collabora.com \
    --cc=maddy@linux.ibm.com \
    --cc=nico.pache@linux.dev \
    --cc=peterx@redhat.com \
    --cc=ritesh.list@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=shuah@kernel.org \
    --cc=usama.arif@linux.dev \
    --cc=yeoreum.yun@arm.com \
    --cc=ziy@nvidia.com \
    /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.