From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C99E9A04B5; Mon, 26 Oct 2020 11:23:02 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9FE5F2BC7; Mon, 26 Oct 2020 11:23:01 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 81EF92BA3 for ; Mon, 26 Oct 2020 11:22:59 +0100 (CET) IronPort-SDR: tkpjl5aTUYrMRjpjo2S0NGLQ1ScnWH96xP/6rhaePm60/C/RKCUP6PSCcRjsYqPJuYeQsOHuUi +TelerByVJVw== X-IronPort-AV: E=McAfee;i="6000,8403,9785"; a="147757978" X-IronPort-AV: E=Sophos;i="5.77,419,1596524400"; d="scan'208";a="147757978" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2020 03:22:57 -0700 IronPort-SDR: Vt3+/N4SlGXUn6jnstJngWVdfiHZor1VpkkY6rq2DnWK5Zsmd6FaxpsUZTSAkv0DpIWuDQ5sln 0IjxuW42mceA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,419,1596524400"; d="scan'208";a="322492418" Received: from npg-dpdk-patrickfu-casc2.sh.intel.com ([10.67.119.92]) by orsmga006.jf.intel.com with ESMTP; 26 Oct 2020 03:22:56 -0700 From: Patrick Fu To: dev@dpdk.org, maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: patrick.fu@intel.com Date: Mon, 26 Oct 2020 18:10:42 +0800 Message-Id: <20201026101042.4102442-1-patrick.fu@intel.com> X-Mailer: git-send-email 2.18.4 Subject: [dpdk-dev] [PATCH v1] vhost: fix gpa to hpa conversion X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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