From: Shachar Raindel <shacharr@google.com>
To: Alex Williamson <alex.williamson@redhat.com>,
Cornelia Huck <cohuck@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Shachar Raindel <shacharr@google.com>
Subject: [PATCH] Convert backwards goto into a while loop
Date: Wed, 28 Dec 2022 21:32:12 +0000 [thread overview]
Message-ID: <20221228213212.628636-1-shacharr@google.com> (raw)
The function vaddr_get_pfns used a goto retry structure to implement
retrying. This is discouraged by the coding style guide (which is
only recommending goto for handling function exits). Convert the code
to a while loop, making it explicit that the follow block only runs
when the pin attempt failed.
Signed-off-by: Shachar Raindel <shacharr@google.com>
---
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..7f38d7fc3f62 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
next reply other threads:[~2022-12-28 21:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-28 21:32 Shachar Raindel [this message]
2023-01-03 17:43 ` Alex Williamson
2023-01-03 19:49 ` [PATCH v2] Convert backwards goto with " Shachar Raindel
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=20221228213212.628636-1-shacharr@google.com \
--to=shacharr@google.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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®