[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20230103194948.1806373-1-shacharr@google.com>
Date: Tue, 3 Jan 2023 19:49:48 +0000
From: Shachar Raindel <shacharr@...gle.com>
To: Alex Williamson <alex.williamson@...hat.com>,
Cornelia Huck <cohuck@...hat.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
Shachar Raindel <shacharr@...gle.com>
Subject: [PATCH v2] Convert backwards goto with a while loop
The function vaddr_get_pfns used a goto retry structure to implement
retrying. This is a gray area in the coding style guide (which is
only explicitly recommending goto for handling function exits).
Convert the code to a while loop, making it explicit that the
following block only runs when the pin attempt failed.
Signed-off-by: Shachar Raindel <shacharr@...gle.com>
---
Changelog:
v1 -> v2: Refine commit message, fix minor code style issue
drivers/vfio/vfio_iommu_type1.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 23c24fe98c00..6335eabe1b7c 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -570,27 +570,28 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
}
*pfn = page_to_pfn(pages[0]);
- goto done;
- }
+ } else {
+ do {
+
+ /* This is not a normal page, lookup PFN for P2P DMA */
+ vaddr = untagged_addr(vaddr);
- vaddr = untagged_addr(vaddr);
+ vma = vma_lookup(mm, vaddr);
-retry:
- vma = vma_lookup(mm, vaddr);
+ if (!vma || !(vma->vm_flags & VM_PFNMAP))
+ break;
- if (vma && vma->vm_flags & VM_PFNMAP) {
- ret = follow_fault_pfn(vma, mm, vaddr, pfn, prot & IOMMU_WRITE);
- if (ret == -EAGAIN)
- goto retry;
+ ret = follow_fault_pfn(vma, mm, vaddr, pfn,
+ prot & IOMMU_WRITE);
+ if (ret)
+ continue; /* Retry for EAGAIN, otherwise bail */
- if (!ret) {
if (is_invalid_reserved_pfn(*pfn))
ret = 1;
else
ret = -EFAULT;
- }
- }
-done:
+ } while (ret == -EAGAIN);
+ }
mmap_read_unlock(mm);
return ret;
}
--
2.39.0.314.g84b9a713c41-goog
Powered by blists - more mailing lists