Skip to content

Commit d108720

Browse files
Li ZheAlex Williamson
authored andcommitted
vfio/type1: batch vfio_find_vpfn() in function vfio_unpin_pages_remote()
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>
1 parent f6c84a5 commit d108720

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

drivers/vfio/vfio_iommu_type1.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -802,16 +802,12 @@ static long vfio_unpin_pages_remote(struct vfio_dma *dma, dma_addr_t iova,
802802
unsigned long pfn, unsigned long npage,
803803
bool do_accounting)
804804
{
805-
long unlocked = 0, locked = 0;
805+
long unlocked = 0, locked = vpfn_pages(dma, iova, npage);
806806
long i;
807807

808-
for (i = 0; i < npage; i++, iova += PAGE_SIZE) {
809-
if (put_pfn(pfn++, dma->prot)) {
808+
for (i = 0; i < npage; i++)
809+
if (put_pfn(pfn++, dma->prot))
810810
unlocked++;
811-
if (vfio_find_vpfn(dma, iova))
812-
locked++;
813-
}
814-
}
815811

816812
if (do_accounting)
817813
vfio_lock_acct(dma, locked - unlocked, true);

0 commit comments

Comments
 (0)