Skip to content

Commit 28ec429

Browse files
author
Alex Williamson
committed
mm: Provide address mask in struct follow_pfnmap_args
JIRA: https://issues.redhat.com/browse/RHEL-85587 commit 62fb8ad Author: Alex Williamson <alex.williamson@redhat.com> Date: Tue Feb 18 15:22:05 2025 -0700 mm: Provide address mask in struct follow_pfnmap_args follow_pfnmap_start() walks the page table for a given address and fills out the struct follow_pfnmap_args in pfnmap_args_setup(). The address mask of the page table level is already provided to this latter function for calculating the pfn. This address mask can also be useful for the caller to determine the extent of the contiguous mapping. For example, vfio-pci now supports huge_fault for pfnmaps and is able to insert pud and pmd mappings. When we DMA map these pfnmaps, ex. PCI MMIO BARs, we iterate follow_pfnmap_start() to get each pfn to test for a contiguous pfn range. Providing the mapping address mask allows us to skip the extent of the mapping level. Assuming a 1GB pud level and 4KB page size, iterations are reduced by a factor of 256K. In wall clock time, mapping a 32GB PCI BAR is reduced from ~1s to <1ms. Cc: Andrew Morton <akpm@linux-foundation.org> Cc: David Hildenbrand <david@redhat.com> Cc: linux-mm@kvack.org Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com> Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: David Hildenbrand <david@redhat.com> Link: https://lore.kernel.org/r/20250218222209.1382449-6-alex.williamson@redhat.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 3560c0d commit 28ec429

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

include/linux/mm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,11 +2405,13 @@ struct follow_pfnmap_args {
24052405
* Outputs:
24062406
*
24072407
* @pfn: the PFN of the address
2408+
* @addr_mask: address mask covering pfn
24082409
* @pgprot: the pgprot_t of the mapping
24092410
* @writable: whether the mapping is writable
24102411
* @special: whether the mapping is a special mapping (real PFN maps)
24112412
*/
24122413
unsigned long pfn;
2414+
unsigned long addr_mask;
24132415
pgprot_t pgprot;
24142416
bool writable;
24152417
bool special;

mm/memory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6353,6 +6353,7 @@ static inline void pfnmap_args_setup(struct follow_pfnmap_args *args,
63536353
args->lock = lock;
63546354
args->ptep = ptep;
63556355
args->pfn = pfn_base + ((args->address & ~addr_mask) >> PAGE_SHIFT);
6356+
args->addr_mask = addr_mask;
63566357
args->pgprot = pgprot;
63576358
args->writable = writable;
63586359
args->special = special;

0 commit comments

Comments
 (0)