From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0CFE337BB0 for ; Mon, 23 Feb 2026 17:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771869532; cv=none; b=mZOEU5SYdeDewF1xk2a5vXgrhPQBlVTCf53JyuLsZngibcuZ4e2SaoK3Hh5Vsy5PZWImO+vXQhJp211AmnAG8IBWxUHOTr9HuTqd0cLVsxhnldzDG0+PHqJV2oigKFQTkN+M31i+xY7ygJ3hHsVKz0JwqH+vKhieCM5qIauyCfM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771869532; c=relaxed/simple; bh=NLSxOGpCBaltS8lvQ0EkL+/J+ORZCvAjkdnHrAGVnb8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qMwL2pQDcZAxVshTZ+4DgcwHLp4dGsGT9PigLHDwYH36+M4IySmXYI9vQwKm2MiSRMpTSvcRUuLY8hYxyTQZmZBgUdfJn6ooKCx2sSz+R2ilYAYA3pTw68dL0bAUmW4j3B94Xw0ceYnE2QOIwjiS6dgfbkChaQM+/36BN7kqPcE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=qypjK432; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="qypjK432" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=X6hhQd/zwZB5Y7oNLD/9Y+hbvtBW2IoFn4XVI5CiByI=; b=qypjK4329fPA5rLc8olYDtNU8g 6elZ6tCXsbzQ3+WJaFIBDU6ZH8WMYywiC7Aum8RitYn0INkKO5qeF8Gu2Hb/9ldRrBXFAk2wUhq2t GbnZ9eozDGHRw11crd1NOto27vnQ8vuHVhZxCwP+WLzGwNZrocwg7AvIa7ZJdOkB3QuDKG610de6b rhDUUYMpxFhu8s5Jp/NpCk/zlr7hlhwlcE6Evg9Vx2oiuuwDr1foWQQ40GhXbj3lv9g+pTm9jS69f AiOA/otQNvoDJFXXziwBwSJ7R1WIDoHYtaZr0hQQSrs1Xd56/7N2fDfegr9pti9K4oBSZnAQo/d43 kObriIIg==; Received: from willy by casper.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1vuaCk-0000000ErtN-392U; Mon, 23 Feb 2026 17:58:46 +0000 Date: Mon, 23 Feb 2026 17:58:46 +0000 From: Matthew Wilcox To: "David Hildenbrand (Arm)" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Rik van Riel , Harry Yoo , Jann Horn Subject: Re: [PATCH v1] mm: centralize+fix comments about compound_mapcount() in new sync_with_folio_pmd_zap() Message-ID: References: <20260223163920.287720-1-david@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260223163920.287720-1-david@kernel.org> On Mon, Feb 23, 2026 at 05:39:20PM +0100, David Hildenbrand (Arm) wrote: > void pmd_install(struct mm_struct *mm, pmd_t *pmd, pgtable_t *pte); > > +/** > + * sync_with_folio_pmd_zap - sync with concurrent zapping of a folio PMD > + * @mm: The mm_struct. > + * @pmdp: Pointer to the pmd that was found to be pmd_none(). > + * > + * When we stumble over a pmd_none() without holding the PTL while unmapping a > + * folio that could have been mapped at that PMD, it could be that concurrent > + * zapping of the PMD is not complete yet. While the PMD might be pmd_none() > + * already, the folio might still appear to be mapped (folio_mapped()). > + * > + * Wait for concurrent zapping to complete by grabbing the PTL. > + */ I like this. The one thing we've lost is the name of the function which does the zapping, which I think was a helpful detail. Perhaps not to someone who's deep in "how page tables work", but I wouldn't know where to look for the counterpart to this. So how about: Option A: + * When we stumble over a pmd_none() without holding the PTL while + * unmapping a folio that could have been mapped at that PMD, + * zap_huge_pmd() may not be complete yet. While the PMD might be pmd_none() + * already, the folio might still appear to be mapped (folio_mapped()). Option B: + * When we find a pmd_none() while unmapping a folio without holding + * the PTL, zap_huge_pmd() may have cleared the PMD but not yet + * modified the folio to indicate that it's unmapped. (for both options, I'm just changing that one paragraph; the paragraph starting "Wait", I would leave unchanged) > +static inline void sync_with_folio_pmd_zap(struct mm_struct *mm, pmd_t *pmdp) > +{ > + spinlock_t *ptl = pmd_lock(mm, pmdp); > + > + spin_unlock(ptl); > +} > + > struct zap_details; > void unmap_page_range(struct mmu_gather *tlb, > struct vm_area_struct *vma, > diff --git a/mm/memory.c b/mm/memory.c > index 876bf73959c6..c87d796050ba 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2006,13 +2006,7 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb, > } else if (details && details->single_folio && > folio_test_pmd_mappable(details->single_folio) && > next - addr == HPAGE_PMD_SIZE && pmd_none(*pmd)) { > - spinlock_t *ptl = pmd_lock(tlb->mm, pmd); > - /* > - * Take and drop THP pmd lock so that we cannot return > - * prematurely, while zap_huge_pmd() has cleared *pmd, > - * but not yet decremented compound_mapcount(). > - */ > - spin_unlock(ptl); > + sync_with_folio_pmd_zap(tlb->mm, pmd); > } > if (pmd_none(*pmd)) { > addr = next; > diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c > index b38a1d00c971..a4d52fdb3056 100644 > --- a/mm/page_vma_mapped.c > +++ b/mm/page_vma_mapped.c > @@ -269,11 +269,6 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) > spin_unlock(pvmw->ptl); > pvmw->ptl = NULL; > } else if (!pmd_present(pmde)) { > - /* > - * If PVMW_SYNC, take and drop THP pmd lock so that we > - * cannot return prematurely, while zap_huge_pmd() has > - * cleared *pmd but not decremented compound_mapcount(). > - */ > const softleaf_t entry = softleaf_from_pmd(pmde); > > if (softleaf_is_device_private(entry)) { > @@ -284,11 +279,9 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) > if ((pvmw->flags & PVMW_SYNC) && > thp_vma_suitable_order(vma, pvmw->address, > PMD_ORDER) && > - (pvmw->nr_pages >= HPAGE_PMD_NR)) { > - spinlock_t *ptl = pmd_lock(mm, pvmw->pmd); > + (pvmw->nr_pages >= HPAGE_PMD_NR)) > + sync_with_folio_pmd_zap(mm, pvmw->pmd); > > - spin_unlock(ptl); > - } > step_forward(pvmw, PMD_SIZE); > continue; > } > -- > 2.43.0 > >