Skip to content

Commit b17269a

Browse files
xzpeterakpm00
authored andcommitted
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/[email protected] Signed-off-by: Peter Xu <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Alex Williamson <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Gavin Shan <[email protected]> Cc: Gerald Schaefer <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Niklas Schnelle <[email protected]> Cc: Paolo Bonzini <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Sean Christopherson <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Will Deacon <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e6bc784 commit b17269a

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
@@ -6341,34 +6341,34 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
63416341
resource_size_t phys_addr;
63426342
unsigned long prot = 0;
63436343
void __iomem *maddr;
6344-
pte_t *ptep, pte;
6345-
spinlock_t *ptl;
63466344
int offset = offset_in_page(addr);
63476345
int ret = -EINVAL;
6346+
bool writable;
6347+
struct follow_pfnmap_args args = { .vma = vma, .address = addr };
63486348

63496349
retry:
6350-
if (follow_pte(vma, addr, &ptep, &ptl))
6350+
if (follow_pfnmap_start(&args))
63516351
return -EINVAL;
6352-
pte = ptep_get(ptep);
6353-
pte_unmap_unlock(ptep, ptl);
6352+
prot = pgprot_val(args.pgprot);
6353+
phys_addr = (resource_size_t)args.pfn << PAGE_SHIFT;
6354+
writable = args.writable;
6355+
follow_pfnmap_end(&args);
63546356

6355-
prot = pgprot_val(pte_pgprot(pte));
6356-
phys_addr = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
6357-
6358-
if ((write & FOLL_WRITE) && !pte_write(pte))
6357+
if ((write & FOLL_WRITE) && !writable)
63596358
return -EINVAL;
63606359

63616360
maddr = ioremap_prot(phys_addr, PAGE_ALIGN(len + offset), prot);
63626361
if (!maddr)
63636362
return -ENOMEM;
63646363

6365-
if (follow_pte(vma, addr, &ptep, &ptl))
6364+
if (follow_pfnmap_start(&args))
63666365
goto out_unmap;
63676366

6368-
if (!pte_same(pte, ptep_get(ptep))) {
6369-
pte_unmap_unlock(ptep, ptl);
6367+
if ((prot != pgprot_val(args.pgprot)) ||
6368+
(phys_addr != (args.pfn << PAGE_SHIFT)) ||
6369+
(writable != args.writable)) {
6370+
follow_pfnmap_end(&args);
63706371
iounmap(maddr);
6371-
63726372
goto retry;
63736373
}
63746374

@@ -6377,7 +6377,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
63776377
else
63786378
memcpy_fromio(buf, maddr + offset, len);
63796379
ret = len;
6380-
pte_unmap_unlock(ptep, ptl);
6380+
follow_pfnmap_end(&args);
63816381
out_unmap:
63826382
iounmap(maddr);
63836383

0 commit comments

Comments
 (0)