]> www.infradead.org Git - users/hch/misc.git/commitdiff
vfio/type1: batch vfio_find_vpfn() in function vfio_unpin_pages_remote()
authorLi Zhe <lizhe.67@bytedance.com>
Thu, 14 Aug 2025 06:47:12 +0000 (14:47 +0800)
committerAlex Williamson <alex.williamson@redhat.com>
Mon, 6 Oct 2025 17:21:26 +0000 (11:21 -0600)
The function vpfn_pages() can help us determine the number of vpfn
nodes on the vpfn rb tree within a specified range. This allows us
to avoid searching for each vpfn individually in the function
vfio_unpin_pages_remote(). This patch batches the vfio_find_vpfn()
calls in function vfio_unpin_pages_remote().

Signed-off-by: Li Zhe <lizhe.67@bytedance.com>
Link: https://lore.kernel.org/r/20250814064714.56485-4-lizhe.67@bytedance.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/vfio_iommu_type1.c

index 7829b5e268c29a18dd2ff3c20c13a8a5e33590a0..dbacd852efae1e56fe34b80811e2e6bb8fe0efe8 100644 (file)
@@ -802,16 +802,12 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
                                    unsigned long pfn, unsigned long npage,
                                    bool do_accounting)
 {
-       long unlocked = 0, locked = 0;
+       long unlocked = 0, locked = vpfn_pages(dma, iova, npage);
        long i;
 
-       for (i = 0; i < npage; i++, iova += PAGE_SIZE) {
-               if (put_pfn(pfn++, dma->prot)) {
+       for (i = 0; i < npage; i++)
+               if (put_pfn(pfn++, dma->prot))
                        unlocked++;
-                       if (vfio_find_vpfn(dma, iova))
-                               locked++;
-               }
-       }
 
        if (do_accounting)
                vfio_lock_acct(dma, locked - unlocked, true);