Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/huge_memory: don't ignore queried cachemode in vmf_insert_pfn_pud()

Patch series "mm/huge_memory: vmf_insert_folio_*() and
vmf_insert_pfn_pud() fixes", v3.

While working on improving vm_normal_page() and friends, I stumbled over
this issues: refcounted "normal" folios must not be marked using
pmd_special() / pud_special(). Otherwise, we're effectively telling the
system that these folios are no "normal", violating the rules we
documented for vm_normal_page().

Fortunately, there are not many pmd_special()/pud_special() users yet. So
far there doesn't seem to be serious damage.

Tested using the ndctl tests ("ndctl:dax" suite).


This patch (of 3):

We set up the cache mode but ... don't forward the updated pgprot to
insert_pfn_pud().

Only a problem on x86-64 PAT when mapping PFNs using PUDs that require a
special cachemode.

Fix it by using the proper pgprot where the cachemode was setup.

It is unclear in which configurations we would get the cachemode wrong:
through vfio seems possible. Getting cachemodes wrong is usually ...
bad. As the fix is easy, let's backport it to stable.

Identified by code inspection.

Link: https://lkml.kernel.org/r/20250613092702.1943533-1-david@redhat.com
Link: https://lkml.kernel.org/r/20250613092702.1943533-2-david@redhat.com
Fixes: 7b806d229ef1 ("mm: remove vmf_insert_pfn_xxx_prot() for huge page-table entries")
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Tested-by: Dan Williams <dan.j.williams@intel.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Zi Yan <ziy@nvidia.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
09fefdca f081a460

+3 -4
+3 -4
mm/huge_memory.c
··· 1516 1516 } 1517 1517 1518 1518 static void insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr, 1519 - pud_t *pud, pfn_t pfn, bool write) 1519 + pud_t *pud, pfn_t pfn, pgprot_t prot, bool write) 1520 1520 { 1521 1521 struct mm_struct *mm = vma->vm_mm; 1522 - pgprot_t prot = vma->vm_page_prot; 1523 1522 pud_t entry; 1524 1523 1525 1524 if (!pud_none(*pud)) { ··· 1580 1581 pfnmap_setup_cachemode_pfn(pfn_t_to_pfn(pfn), &pgprot); 1581 1582 1582 1583 ptl = pud_lock(vma->vm_mm, vmf->pud); 1583 - insert_pfn_pud(vma, addr, vmf->pud, pfn, write); 1584 + insert_pfn_pud(vma, addr, vmf->pud, pfn, pgprot, write); 1584 1585 spin_unlock(ptl); 1585 1586 1586 1587 return VM_FAULT_NOPAGE; ··· 1624 1625 add_mm_counter(mm, mm_counter_file(folio), HPAGE_PUD_NR); 1625 1626 } 1626 1627 insert_pfn_pud(vma, addr, vmf->pud, pfn_to_pfn_t(folio_pfn(folio)), 1627 - write); 1628 + vma->vm_page_prot, write); 1628 1629 spin_unlock(ptl); 1629 1630 1630 1631 return VM_FAULT_NOPAGE;