mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Garg, Shivank" <shivankg@amd.com>
To: "pratyush@kernel.org" <pratyush@kernel.org>,
	"ying.huang@linux.alibaba.com" <ying.huang@linux.alibaba.com>,
	"xu.xin@linux.dev" <xu.xin@linux.dev>,
	"aneesh.kumar@kernel.org" <aneesh.kumar@kernel.org>,
	"baoquan.he@linux.dev" <baoquan.he@linux.dev>,
	"riel@surriel.com" <riel@surriel.com>,
	"usama.arif@linux.dev" <usama.arif@linux.dev>,
	"david@kernel.org" <david@kernel.org>,
	"mhocko@suse.com" <mhocko@suse.com>,
	"ryan.roberts@arm.com" <ryan.roberts@arm.com>,
	"hannes@cmpxchg.org" <hannes@cmpxchg.org>,
	"pfalcato@suse.de" <pfalcato@suse.de>,
	"kasong@tencent.com" <kasong@tencent.com>,
	"jack@suse.cz" <jack@suse.cz>,
	"shakeel.butt@linux.dev" <shakeel.butt@linux.dev>,
	"weixugc@google.com" <weixugc@google.com>,
	"kees@kernel.org" <kees@kernel.org>,
	"liam@infradead.org" <liam@infradead.org>,
	"gourry@gourry.net" <gourry@gourry.net>,
	"lance.yang@linux.dev" <lance.yang@linux.dev>,
	"jannh@google.com" <jannh@google.com>,
	"chrisl@kernel.org" <chrisl@kernel.org>,
	"yuanchu@google.com" <yuanchu@google.com>,
	"youngjun.park@lge.com" <youngjun.park@lge.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"rakie.kim@sk.com" <rakie.kim@sk.com>,
	"joshua.hahnjy@gmail.com" <joshua.hahnjy@gmail.com>,
	"rppt@kernel.org" <rppt@kernel.org>,
	"axelrasmussen@google.com" <axelrasmussen@google.com>,
	"jgg@ziepe.ca" <jgg@ziepe.ca>,
	"willy@infradead.org" <willy@infradead.org>,
	"osalvador@suse.de" <osalvador@suse.de>,
	"surenb@google.com" <surenb@google.com>,
	"peterx@redhat.com" <peterx@redhat.com>,
	"matthew.brost@intel.com" <matthew.brost@intel.com>,
	"minchan@kernel.org" <minchan@kernel.org>,
	"baolin.wang@linux.alibaba.com" <baolin.wang@linux.alibaba.com>,
	"will@kernel.org" <will@kernel.org>,
	"hughd@google.com" <hughd@google.com>,
	"nico.pache@linux.dev" <nico.pache@linux.dev>,
	"qi.zheng@linux.dev" <qi.zheng@linux.dev>,
	"baohua@kernel.org" <baohua@kernel.org>,
	"muchun.song@linux.dev" <muchun.song@linux.dev>,
	"harry@kernel.org" <harry@kernel.org>,
	"nphamcs@gmail.com" <nphamcs@gmail.com>,
	"dev.jain@arm.com" <dev.jain@arm.com>,
	"apopple@nvidia.com" <apopple@nvidia.com>,
	"chengming.zhou@linux.dev" <chengming.zhou@linux.dev>,
	"vbabka@kernel.org" <vbabka@kernel.org>,
	"ziy@nvidia.com" <ziy@nvidia.com>,
	"shikemeng@huaweicloud.com" <shikemeng@huaweicloud.com>,
	"npiggin@gmail.com" <npiggin@gmail.com>,
	"ljs@kernel.org" <ljs@kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"jhubbard@nvidia.com" <jhubbard@nvidia.com>,
	"pasha.tatashin@soleen.com" <pasha.tatashin@soleen.com>,
	"kas@kernel.org" <kas@kernel.org>,
	"mhocko@kernel.org" <mhocko@kernel.org>
Cc: "kexec@lists.infradead.org" <kexec@lists.infradead.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-cxl@vger.kernel.org" <linux-cxl@vger.kernel.org>,
	"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"josef@toxicpanda.com" <josef@toxicpanda.com>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"usama.anjum@arm.com" <usama.anjum@arm.com>
Subject: Re: [PATCH v3 09/47] mm/rmap: handle device-exclusive entries in folio_referenced_one()
Date: Mon, 9 Nov 2026 10:30:11 +0000	[thread overview]
Message-ID: <7194ff7d170f8b47eec8361fa9e195ff2d1581c9.camel@amd.com> (raw)
In-Reply-To: <db93735f-2452-453f-bfe2-f1cef00f143a@kernel.org>

On Mon, 2026-11-09 at 10:51 +0100, David Hildenbrand (Arm) wrote:
> On 11/9/26 06:22, Garg, Shivank wrote:
> > On Sat, 2026-10-31 at 10:39 +0100, David Hildenbrand (Arm) wrote:
> > > page_vma_mapped_walk() can return non-present device-exclusive entries,
> > > but folio_referenced_one() passes them to PTE young-bit accessors that
> > > require present PTEs.
> > > 
> > > We must neither call clear_flush_young_ptes_notify() nor
> > > folio_pte_batch() with non-present entries. For example, clearing the
> > > young bit on non-present PTEs can corrupt the entry: on arm64
> > > PTE_AF overlaps the swap type, so clearing it turns a device-exclusive
> > > entry into an ordinary swap entry.
> > > 
> > > folio_pte_batch() will VM_WARN_ON_FOLIO.
> > > 
> > > Apply the same approach as the previous fixes to e.g., damon_ptep_mkold():
> > > treat these entries as old from the CPU's perspective and obtain their
> > > young state through the MMU notifier.
> > > 
> > > Skip PTE batching and MGLRU look-around for non-present entries, and
> > > don't modify non-present PTEs.
> > > 
> > > Fixes: b756a3b5e7ea ("mm: device exclusive memory access")
> > > Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> > > Cc: stable@vger.kernel.org
> > > Reported-by: Josef Bacik <josef@toxicpanda.com>
> > > Reviewed-by: Harry Yoo (Meta) <harry@kernel.org>
> > > Reviewed-by: Barry Song <baohua@kernel.org>
> > > Reviewed-by: Dev Jain <dev.jain@arm.com>
> > > Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com>
> > > Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
> > > ---
> > >  mm/rmap.c | 23 +++++++++++++++++++----
> > >  1 file changed, 19 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/mm/rmap.c b/mm/rmap.c
> > > index 1131b76bbbc28..0faef46806e5c 100644
> > > --- a/mm/rmap.c
> > > +++ b/mm/rmap.c
> > > @@ -924,6 +924,7 @@ static bool folio_referenced_one(struct folio *folio,
> > >  	DEFINE_FOLIO_VMA_WALK(pvmw, folio, vma, address, 0);
> > >  	int ptes = 0, referenced = 0;
> > >  	unsigned int nr;
> > > +	pte_t pteval;
> > >  
> > >  	while (page_vma_mapped_walk(&pvmw)) {
> > >  		address = pvmw.address;
> > > @@ -968,10 +969,12 @@ static bool folio_referenced_one(struct folio *folio,
> > >  			return false;
> > >  		}
> > >  
> > > -		if (pvmw.pte && folio_test_large(folio)) {
> > > +		if (pvmw.pte)
> > > +			pteval = ptep_get(pvmw.pte);
> > > +
> > > +		if (pvmw.pte && pte_present(pteval) && folio_test_large(folio)) {
> > >  			const unsigned long end_addr = pmd_addr_end(address, vma->vm_end);
> > >  			const unsigned int max_nr = (end_addr - address) >> PAGE_SHIFT;
> > > -			pte_t pteval = ptep_get(pvmw.pte);
> > >  
> > >  			nr = folio_pte_batch(folio, pvmw.pte, pteval, max_nr);
> > >  		}
> > > @@ -981,11 +984,23 @@ static bool folio_referenced_one(struct folio *folio,
> > >  		 * are. —they could be on active/inactive lists or on MGLRU. So the
> > >  		 * simplest approach is to disable this look-around optimization.
> > >  		 */
> > > -		if (lru_gen_enabled() && !lru_gen_switching() && pvmw.pte) {
> > > +		if (lru_gen_enabled() && !lru_gen_switching() && pvmw.pte &&
> > > +		    pte_present(pteval)) {
> > >  			if (lru_gen_look_around(&pvmw, nr))
> > >  				referenced++;
> > >  		} else if (pvmw.pte) {
> > > -			if (clear_flush_young_ptes_notify(vma, address, pvmw.pte, nr))
> > 
> > This was the only caller of clear_flush_young_ptes_notify(), so this
> > leaves both definitions in mm/internal.h unused.
> > 
> > Would you prefer to remove them, or keep them for company with their
> > still used test_and_clear_young_ptes_notify friend?
> 
> Can you send a cleanup? Thanks!

Sure, thanks. Will do.

I'll include it in V2 of my previous series [1].

Do you have any comment on [1] now, before I send V2.

[1]
https://lore.kernel.org/linux-mm/20261026-unused-sym-v1-0-82ca2dceabe1@amd.com


Thanks,
Shivank

  reply	other threads:[~2026-11-09 10:32 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31  9:39 [PATCH v3 00/47] mm: various (urgent?) fixes David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 01/47] mm/mglru: don't use stack pointers when walking PUD and PMD tables David Hildenbrand (Arm)
2026-11-01  3:17   ` Baoquan He
2026-10-31  9:39 ` [PATCH v3 02/47] fork: take mmap_lock before copying mm_struct David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 03/47] mm/shmem: make shmem_file() check the file's inode David Hildenbrand (Arm)
2026-11-02  3:52   ` Baolin Wang
2026-10-31  9:39 ` [PATCH v3 04/47] mm/memfd: make f_pos accesses atomic David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 05/47] mm/truncate: look again if a folio left the mapping David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 06/47] mm/filemap: read mapping->a_ops->free_folio under i_lock David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 07/47] mm/filemap: don't lose a folio lock wakeup to a signal David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 08/47] mm/filemap: finish fault cleanup before dropping the fault lock David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 09/47] mm/rmap: handle device-exclusive entries in folio_referenced_one() David Hildenbrand (Arm)
2026-11-02  6:08   ` Baolin Wang
2026-11-09  5:22   ` Garg, Shivank
2026-11-09  9:51     ` David Hildenbrand (Arm)
2026-11-09 10:30       ` Garg, Shivank [this message]
2026-10-31  9:39 ` [PATCH v3 10/47] mm/huge_memory: fix list corruption when deferred_split_scan() races with deferred_split_folio() David Hildenbrand (Arm)
2026-11-02  6:20   ` Baolin Wang
2026-10-31  9:39 ` [PATCH v3 11/47] mm/huge_memory: properly handle refcounted PUD mappings on fork David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 12/47] mm/huge_memory: fix livelock on device private folio David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 13/47] mm/huge_memory: fix truncate racing with PMD zapping David Hildenbrand (Arm)
2026-11-01  2:15   ` Zi Yan
2026-11-02  7:57   ` Baolin Wang
2026-10-31  9:39 ` [PATCH v3 14/47] mm/huge_memory: fix zapping migration entries for device-private THPs David Hildenbrand (Arm)
2026-11-01  2:15   ` Zi Yan
2026-11-02  4:46   ` Lance Yang
2026-10-31  9:39 ` [PATCH v3 15/47] mm/khugepaged: always recheck the pmd in try_collapse_pte_mapped_thp() David Hildenbrand (Arm)
2026-11-02  4:57   ` Lance Yang
2026-11-02  7:09   ` Baolin Wang
2026-10-31  9:39 ` [PATCH v3 16/47] mm/khugepaged: fix PMD table lock leak " David Hildenbrand (Arm)
2026-11-02  5:42   ` Lance Yang
2026-11-02  7:14   ` Baolin Wang
2026-10-31  9:39 ` [PATCH v3 17/47] mm/khugepaged: preserve dirty bits when collapsing PTE-mapped THPs David Hildenbrand (Arm)
2026-11-02  6:05   ` Lance Yang
2026-11-02  7:25   ` Baolin Wang
2026-10-31  9:39 ` [PATCH v3 18/47] mm/khugepaged: check if PTE table is empty in try_collapse_pte_mapped_thp() David Hildenbrand (Arm)
2026-11-02  7:04   ` Lance Yang
2026-11-02  8:20   ` Baolin Wang
2026-11-02  8:43     ` David Hildenbrand (Arm)
2026-11-04  9:13     ` David Hildenbrand (Arm)
2026-11-05  3:43       ` Baolin Wang
2026-10-31  9:39 ` [PATCH v3 19/47] mm/gup: recheck the PUD under PTL in follow_pud_mask() David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 20/47] mm/gup: fix clearing folios in memfd_pin_folios() David Hildenbrand (Arm)
2026-11-02 11:22   ` Lance Yang
2026-10-31  9:39 ` [PATCH v3 21/47] mm/gup: fix out-of-bounds write for nr_pages == 0 in GUP-fast David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 22/47] mm/gup: check for overflow when converting nr_pages to bytes " David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 23/47] mm/userfaultfd: write-lock the VMA before waking waiters when unregistering David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 24/47] mm/userfaultfd: wake all waiters on unregister David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 25/47] mm/userfaultfd: wake waiters when registration modes are removed David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 26/47] mm/userfaultfd: compare exact registration modes before skipping David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 27/47] mm/mmu_gather: fix flushing ranges with 4 GiB or larger David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 28/47] mm/mmu_notifier: finish non-blocking interval invalidation on error David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 29/47] mm/mmu_notifier: set ->mm only after mmgrab() David Hildenbrand (Arm)
2026-10-31  9:39 ` [PATCH v3 30/47] mm/mremap: use pudp_huge_get_and_clear() when moving huge PUDs David Hildenbrand (Arm)
2026-11-02 11:44   ` Lance Yang
2026-10-31  9:40 ` [PATCH v3 31/47] mm/mremap: recheck PUDs under the page table lock David Hildenbrand (Arm)
2026-11-02 12:19   ` Lance Yang
2026-10-31  9:40 ` [PATCH v3 32/47] mm/mremap: fix moving PUD leaves David Hildenbrand (Arm)
2026-11-03  3:08   ` Lance Yang
2026-10-31  9:40 ` [PATCH v3 33/47] mm/memory_hotplug: avoid races in pfn_to_online_page() with dying pgmap David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 34/47] mm/madvise: fix data loss from MADV_FREE on a KSM page David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 35/47] mm/memory: reject remote COW faults on PFN mappings David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 36/47] mm: fix unmap_mapping_range() beyond 4 GiB on 32-bit David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 37/47] mm: fix unkillable fault loop on MAP_DROPPABLE memory David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 38/47] mm: fix deadlock of mremap() against UFFDIO_MOVE David Hildenbrand (Arm)
2026-11-03  6:26   ` Lance Yang
2026-10-31  9:40 ` [PATCH v3 39/47] mm/ksm: reset the unstable trees of all nodes David Hildenbrand (Arm)
2026-11-02 10:38   ` xu.xin
2026-10-31  9:40 ` [PATCH v3 40/47] mm/ksm: fix use of a freed anon_vma at swap-in David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 41/47] mm/ksm: check large swap-cache folios before mapping them David Hildenbrand (Arm)
2026-11-03 11:46   ` Lance Yang
2026-10-31  9:40 ` [PATCH v3 42/47] mm/vma: call ->may_split() before a partial merge David Hildenbrand (Arm)
2026-11-03 14:49   ` Lance Yang
2026-10-31  9:40 ` [PATCH v3 43/47] mm/huge_memory: split huge PUDs when adjusting VMA boundaries David Hildenbrand (Arm)
2026-11-04  3:12   ` Lance Yang
2026-11-04  9:11     ` David Hildenbrand (Arm)
2026-11-04 15:15       ` Lance Yang
2026-10-31  9:40 ` [PATCH v3 44/47] mm/vma: don't leak the charge for stack growth David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 45/47] mm/cma: don't release CMA pages still in use David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 46/47] mm/memory-tiers: unregister empty tiers outside memory_tier_lock David Hildenbrand (Arm)
2026-10-31  9:40 ` [PATCH v3 47/47] fs/proc/task_mmu: refuse addresses beyond 32 bits on 32bit David Hildenbrand (Arm)
2026-10-31 10:55 ` [PATCH v3 00/47] mm: various (urgent?) fixes David Hildenbrand
2026-11-03 19:10   ` David Hildenbrand (Arm)

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=7194ff7d170f8b47eec8361fa9e195ff2d1581c9.camel@amd.com \
    --to=shivankg@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=apopple@nvidia.com \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=chengming.zhou@linux.dev \
    --cc=chrisl@kernel.org \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=harry@kernel.org \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=jannh@google.com \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=josef@toxicpanda.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kas@kernel.org \
    --cc=kasong@tencent.com \
    --cc=kees@kernel.org \
    --cc=kexec@lists.infradead.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@kernel.org \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=nico.pache@linux.dev \
    --cc=nphamcs@gmail.com \
    --cc=npiggin@gmail.com \
    --cc=osalvador@suse.de \
    --cc=pasha.tatashin@soleen.com \
    --cc=peterx@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pfalcato@suse.de \
    --cc=pratyush@kernel.org \
    --cc=qi.zheng@linux.dev \
    --cc=rakie.kim@sk.com \
    --cc=riel@surriel.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=shikemeng@huaweicloud.com \
    --cc=stable@vger.kernel.org \
    --cc=surenb@google.com \
    --cc=usama.anjum@arm.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=will@kernel.org \
    --cc=willy@infradead.org \
    --cc=xu.xin@linux.dev \
    --cc=ying.huang@linux.alibaba.com \
    --cc=youngjun.park@lge.com \
    --cc=yuanchu@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®