DPDK patches and discussions
 help / color / mirror / Atom feed
From: Patrick Fu <patrick.fu@intel.com>
To: dev@dpdk.org, maxime.coquelin@redhat.com, chenbo.xia@intel.com
Cc: patrick.fu@intel.com
Subject: [dpdk-dev] [PATCH v1] vhost: fix gpa to hpa conversion
Date: Mon, 26 Oct 2020 18:10:42 +0800	[thread overview]
Message-ID: <20201026101042.4102442-1-patrick.fu@intel.com> (raw)

gpa_to_hpa() function almost always fails due to the wrong setup of
the b tree search key. Since there has been already a similar function
gpa_to_first_hap() available in the vhost, instead of fixing the
issue in its original logic, gpa_to_hpa() function is rewritten to be
a wrapper of the gpa_to_first_hpa() to avoid code redundancy.

Fixes: e246896178e6 ("vhost: get guest/host physical address mappings")
Fixes: faa9867c4da2 ("vhost: use binary search in address conversion")

Signed-off-by: Patrick Fu <patrick.fu@intel.com>
---
 lib/librte_vhost/vhost.h | 43 ++++++++++------------------------------
 1 file changed, 11 insertions(+), 32 deletions(-)

diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 75d79f80a..361c9f79b 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -563,38 +563,6 @@ static __rte_always_inline int guest_page_addrcmp(const void *p1,
 	return 0;
 }
 
-/* Convert guest physical address to host physical address */
-static __rte_always_inline rte_iova_t
-gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
-{
-	uint32_t i;
-	struct guest_page *page;
-	struct guest_page key;
-
-	if (dev->nr_guest_pages >= VHOST_BINARY_SEARCH_THRESH) {
-		key.guest_phys_addr = gpa;
-		page = bsearch(&key, dev->guest_pages, dev->nr_guest_pages,
-			       sizeof(struct guest_page), guest_page_addrcmp);
-		if (page) {
-			if (gpa + size < page->guest_phys_addr + page->size)
-				return gpa - page->guest_phys_addr +
-					page->host_phys_addr;
-		}
-	} else {
-		for (i = 0; i < dev->nr_guest_pages; i++) {
-			page = &dev->guest_pages[i];
-
-			if (gpa >= page->guest_phys_addr &&
-			    gpa + size < page->guest_phys_addr +
-			    page->size)
-				return gpa - page->guest_phys_addr +
-				       page->host_phys_addr;
-		}
-	}
-
-	return 0;
-}
-
 static __rte_always_inline rte_iova_t
 gpa_to_first_hpa(struct virtio_net *dev, uint64_t gpa,
 	uint64_t gpa_size, uint64_t *hpa_size)
@@ -645,6 +613,17 @@ gpa_to_first_hpa(struct virtio_net *dev, uint64_t gpa,
 	return 0;
 }
 
+/* Convert guest physical address to host physical address */
+static __rte_always_inline rte_iova_t
+gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, uint64_t size)
+{
+	rte_iova_t hpa;
+	uint64_t hpa_size;
+
+	hpa = gpa_to_first_hpa(dev, gpa, size, &hpa_size);
+	return hpa_size == size ? hpa : 0;
+}
+
 static __rte_always_inline uint64_t
 hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len)
 {
-- 
2.18.4


             reply	other threads:[~2020-10-26 10:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 10:10 Patrick Fu [this message]
2020-10-27  2:06 ` [dpdk-dev] [PATCH v1] vhost: fix guest/host physical address conversion Patrick Fu
2020-10-28 11:16   ` Maxime Coquelin
2020-10-29  8:28   ` Maxime Coquelin

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=20201026101042.4102442-1-patrick.fu@intel.com \
    --to=patrick.fu@intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@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;
as well as URLs for NNTP newsgroup(s).