Commit b17269a5 authored by Peter Xu's avatar Peter Xu Committed by Andrew Morton

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.comSigned-off-by: default avatarPeter 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: default avatarAndrew Morton <akpm@linux-foundation.org>
parent e6bc784c
...@@ -6341,34 +6341,34 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, ...@@ -6341,34 +6341,34 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
resource_size_t phys_addr; resource_size_t phys_addr;
unsigned long prot = 0; unsigned long prot = 0;
void __iomem *maddr; void __iomem *maddr;
pte_t *ptep, pte;
spinlock_t *ptl;
int offset = offset_in_page(addr); int offset = offset_in_page(addr);
int ret = -EINVAL; int ret = -EINVAL;
bool writable;
struct follow_pfnmap_args args = { .vma = vma, .address = addr };
retry: retry:
if (follow_pte(vma, addr, &ptep, &ptl)) if (follow_pfnmap_start(&args))
return -EINVAL; return -EINVAL;
pte = ptep_get(ptep); prot = pgprot_val(args.pgprot);
pte_unmap_unlock(ptep, ptl); phys_addr = (resource_size_t)args.pfn << PAGE_SHIFT;
writable = args.writable;
follow_pfnmap_end(&args);
prot = pgprot_val(pte_pgprot(pte)); if ((write & FOLL_WRITE) && !writable)
phys_addr = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
if ((write & FOLL_WRITE) && !pte_write(pte))
return -EINVAL; return -EINVAL;
maddr = ioremap_prot(phys_addr, PAGE_ALIGN(len + offset), prot); maddr = ioremap_prot(phys_addr, PAGE_ALIGN(len + offset), prot);
if (!maddr) if (!maddr)
return -ENOMEM; return -ENOMEM;
if (follow_pte(vma, addr, &ptep, &ptl)) if (follow_pfnmap_start(&args))
goto out_unmap; goto out_unmap;
if (!pte_same(pte, ptep_get(ptep))) { if ((prot != pgprot_val(args.pgprot)) ||
pte_unmap_unlock(ptep, ptl); (phys_addr != (args.pfn << PAGE_SHIFT)) ||
(writable != args.writable)) {
follow_pfnmap_end(&args);
iounmap(maddr); iounmap(maddr);
goto retry; goto retry;
} }
...@@ -6377,7 +6377,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, ...@@ -6377,7 +6377,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
else else
memcpy_fromio(buf, maddr + offset, len); memcpy_fromio(buf, maddr + offset, len);
ret = len; ret = len;
pte_unmap_unlock(ptep, ptl); follow_pfnmap_end(&args);
out_unmap: out_unmap:
iounmap(maddr); iounmap(maddr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment