mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: alex.williamson@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	peterx@redhat.com, mitchell.augustin@canonical.com,
	clg@redhat.com, jgg@nvidia.com
Subject: [PATCH v2 2/6] vfio/type1: Convert all vaddr_get_pfns() callers to use vfio_batch
Date: Tue, 18 Feb 2025 15:22:02 -0700	[thread overview]
Message-ID: <20250218222209.1382449-3-alex.williamson@redhat.com> (raw)
In-Reply-To: <20250218222209.1382449-1-alex.williamson@redhat.com>

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>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/vfio/vfio_iommu_type1.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 119cf886d8c0..2e95f5f4d881 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -471,12 +471,12 @@ static int put_pfn(unsigned long pfn, int prot)
 
 #define VFIO_BATCH_MAX_CAPACITY (PAGE_SIZE / sizeof(struct page *))
 
-static void vfio_batch_init(struct vfio_batch *batch)
+static void __vfio_batch_init(struct vfio_batch *batch, bool single)
 {
 	batch->size = 0;
 	batch->offset = 0;
 
-	if (unlikely(disable_hugepages))
+	if (single || unlikely(disable_hugepages))
 		goto fallback;
 
 	batch->pages = (struct page **) __get_free_page(GFP_KERNEL);
@@ -491,6 +491,16 @@ static void vfio_batch_init(struct vfio_batch *batch)
 	batch->capacity = 1;
 }
 
+static void vfio_batch_init(struct vfio_batch *batch)
+{
+	__vfio_batch_init(batch, false);
+}
+
+static void vfio_batch_init_single(struct vfio_batch *batch)
+{
+	__vfio_batch_init(batch, true);
+}
+
 static void vfio_batch_unpin(struct vfio_batch *batch, struct vfio_dma *dma)
 {
 	while (batch->size) {
@@ -730,7 +740,7 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
 static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
 				  unsigned long *pfn_base, bool do_accounting)
 {
-	struct page *pages[1];
+	struct vfio_batch batch;
 	struct mm_struct *mm;
 	int ret;
 
@@ -738,7 +748,9 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
 	if (!mmget_not_zero(mm))
 		return -ENODEV;
 
-	ret = vaddr_get_pfns(mm, vaddr, 1, dma->prot, pfn_base, pages);
+	vfio_batch_init_single(&batch);
+
+	ret = vaddr_get_pfns(mm, vaddr, 1, dma->prot, pfn_base, batch.pages);
 	if (ret != 1)
 		goto out;
 
@@ -757,6 +769,7 @@ static int vfio_pin_page_external(struct vfio_dma *dma, unsigned long vaddr,
 	}
 
 out:
+	vfio_batch_fini(&batch);
 	mmput(mm);
 	return ret;
 }
-- 
2.48.1


  parent reply	other threads:[~2025-02-18 22:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18 22:22 [PATCH v2 0/6] vfio: Improve DMA mapping performance for huge pfnmaps Alex Williamson
2025-02-18 22:22 ` [PATCH v2 1/6] vfio/type1: Catch zero from pin_user_pages_remote() Alex Williamson
2025-02-18 22:22 ` Alex Williamson [this message]
2025-02-18 22:22 ` [PATCH v2 3/6] vfio/type1: Use vfio_batch for vaddr_get_pfns() Alex Williamson
2025-02-18 22:22 ` [PATCH v2 4/6] vfio/type1: Use consistent types for page counts Alex Williamson
2025-02-18 22:46   ` Peter Xu
2025-02-19  0:55     ` Mitchell Augustin
2025-02-25  0:17   ` Jason Gunthorpe
2025-02-18 22:22 ` [PATCH v2 5/6] mm: Provide address mask in struct follow_pfnmap_args Alex Williamson
2025-02-19  8:31   ` David Hildenbrand
2025-02-26 19:54     ` Alex Williamson
2025-02-26 20:05       ` David Hildenbrand
2025-02-18 22:22 ` [PATCH v2 6/6] vfio/type1: Use mapping page mask for pfnmaps Alex Williamson
2025-02-18 22:47   ` Peter Xu
2025-02-18 23:14     ` Alex Williamson
2025-02-19  2:36       ` Mitchell Augustin
2025-02-19 15:08         ` Alex Williamson
2025-02-19 20:32           ` Mitchell Augustin
2025-02-26 17:55             ` Alex Williamson
2025-02-27 20:22               ` Mitchell Augustin
2025-02-25  0:17   ` Jason Gunthorpe
2025-02-19  2:37 ` [PATCH v2 0/6] vfio: Improve DMA mapping performance for huge pfnmaps Mitchell Augustin
2025-02-28 16:32 ` Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250218222209.1382449-3-alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=clg@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mitchell.augustin@canonical.com \
    --cc=peterx@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®