Skip to content

Commit 7a701e9

Browse files
committed
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 <[email protected]> Reviewed-by: Mitchell Augustin <[email protected]> Tested-by: Mitchell Augustin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent afe84f3 commit 7a701e9

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
@@ -471,12 +471,12 @@ static int put_pfn(unsigned long pfn, int prot)
471471

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

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

479-
if (unlikely(disable_hugepages))
479+
if (single || unlikely(disable_hugepages))
480480
goto fallback;
481481

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

494+
static void vfio_batch_init(struct vfio_batch *batch)
495+
{
496+
__vfio_batch_init(batch, false);
497+
}
498+
499+
static void vfio_batch_init_single(struct vfio_batch *batch)
500+
{
501+
__vfio_batch_init(batch, true);
502+
}
503+
494504
static void vfio_batch_unpin(struct vfio_batch *batch, struct vfio_dma *dma)
495505
{
496506
while (batch->size) {
@@ -730,15 +740,17 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
730740
static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
731741
unsigned long *pfn_base, bool do_accounting)
732742
{
733-
struct page *pages[1];
743+
struct vfio_batch batch;
734744
struct mm_struct *mm;
735745
int ret;
736746

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

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

@@ -757,6 +769,7 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
757769
}
758770

759771
out:
772+
vfio_batch_fini(&batch);
760773
mmput(mm);
761774
return ret;
762775
}

0 commit comments

Comments
 (0)