Skip to content

Commit 71ea9e5

Browse files
committed
mm/access_process_vm: use the new follow_pfnmap API
JIRA: https://issues.redhat.com/browse/RHEL-73613 commit b17269a Author: Peter Xu <peterx@redhat.com> Date: Mon Aug 26 16:43:49 2024 -0400 mm/access_process_vm: use the new follow_pfnmap API Use the new API that can understand huge pfn mappings. Link: https://lkml.kernel.org/r/20240826204353.2228736-16-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Alex Williamson <alex.williamson@redhat.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Hildenbrand <david@redhat.com> Cc: Gavin Shan <gshan@redhat.com> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Niklas Schnelle <schnelle@linux.ibm.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Will Deacon <will@kernel.org> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Donald Dutile <ddutile@redhat.com>
1 parent 6427f62 commit 71ea9e5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

mm/memory.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5839,34 +5839,34 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
58395839
resource_size_t phys_addr;
58405840
unsigned long prot = 0;
58415841
void __iomem *maddr;
5842-
pte_t *ptep, pte;
5843-
spinlock_t *ptl;
58445842
int offset = offset_in_page(addr);
58455843
int ret = -EINVAL;
5844+
bool writable;
5845+
struct follow_pfnmap_args args = { .vma = vma, .address = addr };
58465846

58475847
retry:
5848-
if (follow_pte(vma, addr, &ptep, &ptl))
5848+
if (follow_pfnmap_start(&args))
58495849
return -EINVAL;
5850-
pte = ptep_get(ptep);
5851-
pte_unmap_unlock(ptep, ptl);
5850+
prot = pgprot_val(args.pgprot);
5851+
phys_addr = (resource_size_t)args.pfn << PAGE_SHIFT;
5852+
writable = args.writable;
5853+
follow_pfnmap_end(&args);
58525854

5853-
prot = pgprot_val(pte_pgprot(pte));
5854-
phys_addr = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
5855-
5856-
if ((write & FOLL_WRITE) && !pte_write(pte))
5855+
if ((write & FOLL_WRITE) && !writable)
58575856
return -EINVAL;
58585857

58595858
maddr = ioremap_prot(phys_addr, PAGE_ALIGN(len + offset), prot);
58605859
if (!maddr)
58615860
return -ENOMEM;
58625861

5863-
if (follow_pte(vma, addr, &ptep, &ptl))
5862+
if (follow_pfnmap_start(&args))
58645863
goto out_unmap;
58655864

5866-
if (!pte_same(pte, ptep_get(ptep))) {
5867-
pte_unmap_unlock(ptep, ptl);
5865+
if ((prot != pgprot_val(args.pgprot)) ||
5866+
(phys_addr != (args.pfn << PAGE_SHIFT)) ||
5867+
(writable != args.writable)) {
5868+
follow_pfnmap_end(&args);
58685869
iounmap(maddr);
5869-
58705870
goto retry;
58715871
}
58725872

@@ -5875,7 +5875,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
58755875
else
58765876
memcpy_fromio(buf, maddr + offset, len);
58775877
ret = len;
5878-
pte_unmap_unlock(ptep, ptl);
5878+
follow_pfnmap_end(&args);
58795879
out_unmap:
58805880
iounmap(maddr);
58815881

0 commit comments

Comments
 (0)