Skip to content

Commit e8ccfb8

Browse files
author
Alex Williamson
committed
vfio/type1: Convert all vaddr_get_pfns() callers to use vfio_batch
JIRA: https://issues.redhat.com/browse/RHEL-85587 commit 7a701e9 Author: Alex Williamson <alex.williamson@redhat.com> Date: Tue Feb 18 15:22:02 2025 -0700 vfio/type1: Convert all vaddr_get_pfns() callers to use vfio_batch This is a step towards passing the structure to vaddr_get_pfns() directly in order to provide greater distinction between page backed pfns and pfnmaps. Reviewed-by: Peter Xu <peterx@redhat.com> Reviewed-by: Mitchell Augustin <mitchell.augustin@canonical.com> Tested-by: Mitchell Augustin <mitchell.augustin@canonical.com> Link: https://lore.kernel.org/r/20250218222209.1382449-3-alex.williamson@redhat.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 4eb4e96 commit e8ccfb8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,12 @@ static int put_pfn(unsigned long pfn, int prot)
472472

473473
#define VFIO_BATCH_MAX_CAPACITY (PAGE_SIZE / sizeof(struct page *))
474474

475-
static void vfio_batch_init(struct vfio_batch *batch)
475+
static void __vfio_batch_init(struct vfio_batch *batch, bool single)
476476
{
477477
batch->size = 0;
478478
batch->offset = 0;
479479

480-
if (unlikely(disable_hugepages))
480+
if (single || unlikely(disable_hugepages))
481481
goto fallback;
482482

483483
batch->pages = (struct page **) __get_free_page(GFP_KERNEL);
@@ -492,6 +492,16 @@ static void vfio_batch_init(struct vfio_batch *batch)
492492
batch->capacity = 1;
493493
}
494494

495+
static void vfio_batch_init(struct vfio_batch *batch)
496+
{
497+
__vfio_batch_init(batch, false);
498+
}
499+
500+
static void vfio_batch_init_single(struct vfio_batch *batch)
501+
{
502+
__vfio_batch_init(batch, true);
503+
}
504+
495505
static void vfio_batch_unpin(struct vfio_batch *batch, struct vfio_dma *dma)
496506
{
497507
while (batch->size) {
@@ -731,15 +741,17 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
731741
static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
732742
unsigned long *pfn_base, bool do_accounting)
733743
{
734-
struct page *pages[1];
744+
struct vfio_batch batch;
735745
struct mm_struct *mm;
736746
int ret;
737747

738748
mm = dma->mm;
739749
if (!mmget_not_zero(mm))
740750
return -ENODEV;
741751

742-
ret = vaddr_get_pfns(mm, vaddr, 1, dma->prot, pfn_base, pages);
752+
vfio_batch_init_single(&batch);
753+
754+
ret = vaddr_get_pfns(mm, vaddr, 1, dma->prot, pfn_base, batch.pages);
743755
if (ret != 1)
744756
goto out;
745757

@@ -758,6 +770,7 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
758770
}
759771

760772
out:
773+
vfio_batch_fini(&batch);
761774
mmput(mm);
762775
return ret;
763776
}

0 commit comments

Comments
 (0)