From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 203D01B25B for ; Mon, 6 Nov 2017 02:42:14 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C5DA720C1B; Sun, 5 Nov 2017 20:42:13 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Sun, 05 Nov 2017 20:42:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=bXc3zkULORGgsI mC2oeYVmTihzJdg2FDvtKqKzBN38Y=; b=Q+febtDRicYyux+g/Pn1sylV0NFmkN 1q5RSeCSnZVpXFtDrPv9Z/+f8PW2DQZCy2pYxAyVoBQcPPXrIWJUb79LSZtcWSiL R+x3cyE/4K5QN16OQBSKohCC41AK9JRLZ0znw137awqdWQAGbHFX6qQvE/V1epeZ Q6XrDfz80MbnI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=bXc3zkULORGgsImC2oeYVmTihzJdg2FDvtKqKzBN38Y=; b=VkK2SlLM +3098r8B2inyCI1Mu3MAdljvkEhP/v8wV+fI8e/V/iS9ooD8b1BcDB8il4vhub4p 7WPBhyv5JeDIBh6Noo/O7hxGdVgd+ElvcR9R41IQzVlSRH14nTi9XRDKFxGGQ6Cr ypbGixsPxJz53h0XcPGo/QxkljjkPbbyF8XGeHsea7JaqvCs+cRpSSH6nBwLxR/9 lzIkjQsvrxtORz5oTb+MUG3SBd0MF8pFfgS3PClyqmeXp7N5eomIU5k7T7BSUevr 7SVfQHBPLWSCeaC0h81tR4Hzq9V2QubyBb1i89aVdeYYsUYjFQ4Ab90tnXpVirp4 L68txx/gJ5xrtA== X-ME-Sender: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 000402469F; Sun, 5 Nov 2017 20:42:12 -0500 (EST) From: Thomas Monjalon To: Santosh Shukla Cc: olivier.matz@6wind.com, sergio.gonzalez.monroy@intel.com, anatoly.burakov@intel.com, dev@dpdk.org Date: Mon, 6 Nov 2017 02:41:30 +0100 Message-Id: <20171106014141.13266-5-thomas@monjalon.net> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171106014141.13266-1-thomas@monjalon.net> References: <20170814151537.29454-1-santosh.shukla@caviumnetworks.com> <20171106014141.13266-1-thomas@monjalon.net> Subject: [dpdk-dev] [PATCH v4 04/15] mem: rename address mapping function to IOVA 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: , X-List-Received-Date: Mon, 06 Nov 2017 01:42:14 -0000 The function rte_mem_virt2phy() is kept and used in functions which works only with physical addresses. For all other calls this function is replaced by rte_mem_virt2iova() which does a direct mapping (no conversion) in the VA case. Note: the new function rte_mem_virt2iova() function matches the behaviour implemented in rte_mem_virt2phy() by the commit 680f6c12600f ("mem: honor IOVA mode in virt2phy") Signed-off-by: Thomas Monjalon --- drivers/bus/dpaa/base/qbman/qman.c | 2 +- drivers/bus/dpaa/base/qbman/qman.h | 2 +- drivers/net/bnxt/bnxt_ethdev.c | 8 ++++---- drivers/net/bnxt/bnxt_hwrm.c | 20 ++++++++++---------- drivers/net/bnxt/bnxt_ring.c | 4 ++-- drivers/net/bnxt/bnxt_vnic.c | 4 ++-- drivers/net/liquidio/lio_rxtx.c | 2 +- lib/librte_cryptodev/rte_cryptodev.c | 2 +- lib/librte_eal/bsdapp/eal/eal_memory.c | 5 +++++ lib/librte_eal/common/include/rte_memory.h | 10 ++++++++++ lib/librte_eal/linuxapp/eal/eal_memory.c | 11 ++++++++--- lib/librte_eal/rte_eal_version.map | 1 + lib/librte_mempool/rte_mempool.c | 4 ++-- lib/librte_vhost/vhost_user.c | 4 ++-- test/test/test_mempool.c | 4 ++-- 15 files changed, 52 insertions(+), 31 deletions(-) diff --git a/drivers/bus/dpaa/base/qbman/qman.c b/drivers/bus/dpaa/base/qbman/qman.c index 8c8d270f8..87fec60d1 100644 --- a/drivers/bus/dpaa/base/qbman/qman.c +++ b/drivers/bus/dpaa/base/qbman/qman.c @@ -1351,7 +1351,7 @@ int qman_init_fq(struct qman_fq *fq, u32 flags, struct qm_mcc_initfq *opts) memset(&mcc->initfq.fqd.context_a, 0, sizeof(mcc->initfq.fqd.context_a)); } else { - phys_fq = rte_mem_virt2phy(fq); + phys_fq = rte_mem_virt2iova(fq); qm_fqd_stashing_set64(&mcc->initfq.fqd, phys_fq); } } diff --git a/drivers/bus/dpaa/base/qbman/qman.h b/drivers/bus/dpaa/base/qbman/qman.h index 7c645f478..2c0f694cd 100644 --- a/drivers/bus/dpaa/base/qbman/qman.h +++ b/drivers/bus/dpaa/base/qbman/qman.h @@ -240,7 +240,7 @@ struct qm_portal { #define EQCR_CARRYCLEAR(p) \ (void *)((unsigned long)(p) & (~(unsigned long)(QM_EQCR_SIZE << 6))) -extern dma_addr_t rte_mem_virt2phy(const void *addr); +extern dma_addr_t rte_mem_virt2iova(const void *addr); /* Bit-wise logic to convert a ring pointer to a ring index */ static inline u8 EQCR_PTR2IDX(struct qm_eqcr_entry *e) diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c index b6c1daec7..9dc3901e1 100644 --- a/drivers/net/bnxt/bnxt_ethdev.c +++ b/drivers/net/bnxt/bnxt_ethdev.c @@ -2852,8 +2852,8 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev) RTE_LOG(WARNING, PMD, "Memzone physical address same as virtual.\n"); RTE_LOG(WARNING, PMD, - "Using rte_mem_virt2phy()\n"); - mz_phys_addr = rte_mem_virt2phy(mz->addr); + "Using rte_mem_virt2iova()\n"); + mz_phys_addr = rte_mem_virt2iova(mz->addr); if (mz_phys_addr == 0) { RTE_LOG(ERR, PMD, "unable to map address to physical memory\n"); @@ -2887,8 +2887,8 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev) RTE_LOG(WARNING, PMD, "Memzone physical address same as virtual.\n"); RTE_LOG(WARNING, PMD, - "Using rte_mem_virt2phy()\n"); - mz_phys_addr = rte_mem_virt2phy(mz->addr); + "Using rte_mem_virt2iova()\n"); + mz_phys_addr = rte_mem_virt2iova(mz->addr); if (mz_phys_addr == 0) { RTE_LOG(ERR, PMD, "unable to map address to physical memory\n"); diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c index 6e0e40f82..1fdc51cba 100644 --- a/drivers/net/bnxt/bnxt_hwrm.c +++ b/drivers/net/bnxt/bnxt_hwrm.c @@ -277,7 +277,7 @@ int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, if (!(mask & HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN)) mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY; req.vlan_tag_tbl_addr = rte_cpu_to_le_64( - rte_mem_virt2phy(vlan_table)); + rte_mem_virt2iova(vlan_table)); req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count); } req.mask = rte_cpu_to_le_32(mask); @@ -318,7 +318,7 @@ int bnxt_hwrm_cfa_vlan_antispoof_cfg(struct bnxt *bp, uint16_t fid, req.fid = rte_cpu_to_le_16(fid); req.vlan_tag_mask_tbl_addr = - rte_cpu_to_le_64(rte_mem_virt2phy(vlan_table)); + rte_cpu_to_le_64(rte_mem_virt2iova(vlan_table)); req.num_vlan_entries = rte_cpu_to_le_32((uint32_t)vlan_count); rc = bnxt_hwrm_send_message(bp, &req, sizeof(req)); @@ -644,7 +644,7 @@ int bnxt_hwrm_ver_get(struct bnxt *bp) } rte_mem_lock_page(bp->hwrm_cmd_resp_addr); bp->hwrm_cmd_resp_dma_addr = - rte_mem_virt2phy(bp->hwrm_cmd_resp_addr); + rte_mem_virt2iova(bp->hwrm_cmd_resp_addr); if (bp->hwrm_cmd_resp_dma_addr == 0) { RTE_LOG(ERR, PMD, "Unable to map response buffer to physical memory.\n"); @@ -670,7 +670,7 @@ int bnxt_hwrm_ver_get(struct bnxt *bp) } rte_mem_lock_page(bp->hwrm_short_cmd_req_addr); bp->hwrm_short_cmd_req_dma_addr = - rte_mem_virt2phy(bp->hwrm_short_cmd_req_addr); + rte_mem_virt2iova(bp->hwrm_short_cmd_req_addr); if (bp->hwrm_short_cmd_req_dma_addr == 0) { rte_free(bp->hwrm_short_cmd_req_addr); RTE_LOG(ERR, PMD, @@ -1753,7 +1753,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp) if (bp->hwrm_cmd_resp_addr == NULL) return -ENOMEM; bp->hwrm_cmd_resp_dma_addr = - rte_mem_virt2phy(bp->hwrm_cmd_resp_addr); + rte_mem_virt2iova(bp->hwrm_cmd_resp_addr); if (bp->hwrm_cmd_resp_dma_addr == 0) { RTE_LOG(ERR, PMD, "unable to map response address to physical memory\n"); @@ -2622,7 +2622,7 @@ int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp) page_getenum(bp->pf.active_vfs * HWRM_MAX_REQ_LEN)); req.req_buf_len = rte_cpu_to_le_16(HWRM_MAX_REQ_LEN); req.req_buf_page_addr[0] = - rte_cpu_to_le_64(rte_mem_virt2phy(bp->pf.vf_req_buf)); + rte_cpu_to_le_64(rte_mem_virt2iova(bp->pf.vf_req_buf)); if (req.req_buf_page_addr[0] == 0) { RTE_LOG(ERR, PMD, "unable to map buffer address to physical memory\n"); @@ -3044,7 +3044,7 @@ int bnxt_get_nvram_directory(struct bnxt *bp, uint32_t len, uint8_t *data) rte_mem_lock_page(buf); if (buf == NULL) return -ENOMEM; - dma_handle = rte_mem_virt2phy(buf); + dma_handle = rte_mem_virt2iova(buf); if (dma_handle == 0) { RTE_LOG(ERR, PMD, "unable to map response address to physical memory\n"); @@ -3080,7 +3080,7 @@ int bnxt_hwrm_get_nvram_item(struct bnxt *bp, uint32_t index, if (!buf) return -ENOMEM; - dma_handle = rte_mem_virt2phy(buf); + dma_handle = rte_mem_virt2iova(buf); if (dma_handle == 0) { RTE_LOG(ERR, PMD, "unable to map response address to physical memory\n"); @@ -3141,7 +3141,7 @@ int bnxt_hwrm_flash_nvram(struct bnxt *bp, uint16_t dir_type, if (!buf) return -ENOMEM; - dma_handle = rte_mem_virt2phy(buf); + dma_handle = rte_mem_virt2iova(buf); if (dma_handle == 0) { RTE_LOG(ERR, PMD, "unable to map response address to physical memory\n"); @@ -3196,7 +3196,7 @@ static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf, req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf); req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics); - req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2phy(vnic_ids)); + req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2iova(vnic_ids)); if (req.vnic_id_tbl_addr == 0) { HWRM_UNLOCK(); diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c index 583c82569..efec2048e 100644 --- a/drivers/net/bnxt/bnxt_ring.c +++ b/drivers/net/bnxt/bnxt_ring.c @@ -177,10 +177,10 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx, RTE_LOG(WARNING, PMD, "Memzone physical address same as virtual.\n"); RTE_LOG(WARNING, PMD, - "Using rte_mem_virt2phy()\n"); + "Using rte_mem_virt2iova()\n"); for (sz = 0; sz < total_alloc_len; sz += getpagesize()) rte_mem_lock_page(((char *)mz->addr) + sz); - mz_phys_addr = rte_mem_virt2phy(mz->addr); + mz_phys_addr = rte_mem_virt2iova(mz->addr); if (mz_phys_addr == 0) { RTE_LOG(ERR, PMD, "unable to map ring address to physical memory\n"); diff --git a/drivers/net/bnxt/bnxt_vnic.c b/drivers/net/bnxt/bnxt_vnic.c index 6f7c05bdf..cbcf9920a 100644 --- a/drivers/net/bnxt/bnxt_vnic.c +++ b/drivers/net/bnxt/bnxt_vnic.c @@ -197,8 +197,8 @@ int bnxt_alloc_vnic_attributes(struct bnxt *bp) RTE_LOG(WARNING, PMD, "Memzone physical address same as virtual.\n"); RTE_LOG(WARNING, PMD, - "Using rte_mem_virt2phy()\n"); - mz_phys_addr = rte_mem_virt2phy(mz->addr); + "Using rte_mem_virt2iova()\n"); + mz_phys_addr = rte_mem_virt2iova(mz->addr); if (mz_phys_addr == 0) { RTE_LOG(ERR, PMD, "unable to map vnic address to physical memory\n"); diff --git a/drivers/net/liquidio/lio_rxtx.c b/drivers/net/liquidio/lio_rxtx.c index 2bbb893c2..773dfd30a 100644 --- a/drivers/net/liquidio/lio_rxtx.c +++ b/drivers/net/liquidio/lio_rxtx.c @@ -1790,7 +1790,7 @@ lio_dev_xmit_pkts(void *tx_queue, struct rte_mbuf **pkts, uint16_t nb_pkts) m = m->next; } - phyaddr = rte_mem_virt2phy(g->sg); + phyaddr = rte_mem_virt2iova(g->sg); if (phyaddr == RTE_BAD_PHYS_ADDR) { PMD_TX_LOG(lio_dev, ERR, "bad phys addr\n"); goto xmit_failed; diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index 80632117e..e5f287634 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -1284,7 +1284,7 @@ rte_crypto_op_init(struct rte_mempool *mempool, __rte_crypto_op_reset(op, type); - op->phys_addr = rte_mem_virt2phy(_op_data); + op->phys_addr = rte_mem_virt2iova(_op_data); op->mempool = mempool; } diff --git a/lib/librte_eal/bsdapp/eal/eal_memory.c b/lib/librte_eal/bsdapp/eal/eal_memory.c index 66fab768f..0e021fff1 100644 --- a/lib/librte_eal/bsdapp/eal/eal_memory.c +++ b/lib/librte_eal/bsdapp/eal/eal_memory.c @@ -58,6 +58,11 @@ rte_mem_virt2phy(const void *virtaddr) (void)virtaddr; return RTE_BAD_IOVA; } +rte_iova_t +rte_mem_virt2iova(const void *virtaddr) +{ + return rte_mem_virt2phy(virtaddr); +} int rte_eal_hugepage_init(void) diff --git a/lib/librte_eal/common/include/rte_memory.h b/lib/librte_eal/common/include/rte_memory.h index 78f48503e..c13300cc7 100644 --- a/lib/librte_eal/common/include/rte_memory.h +++ b/lib/librte_eal/common/include/rte_memory.h @@ -146,6 +146,16 @@ int rte_mem_lock_page(const void *virt); */ phys_addr_t rte_mem_virt2phy(const void *virt); +/** + * Get IO virtual address of any mapped virtual address in the current process. + * + * @param virt + * The virtual address. + * @return + * The IO address or RTE_BAD_IOVA on error. + */ +rte_iova_t rte_mem_virt2iova(const void *virt); + /** * Get the layout of the available physical memory. * diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 284758ac4..a54b822ab 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -128,9 +128,6 @@ rte_mem_virt2phy(const void *virtaddr) int page_size; off_t offset; - if (rte_eal_iova_mode() == RTE_IOVA_VA) - return (uintptr_t)virtaddr; - /* Cannot parse /proc/self/pagemap, no need to log errors everywhere */ if (!phys_addrs_available) return RTE_BAD_IOVA; @@ -180,6 +177,14 @@ rte_mem_virt2phy(const void *virtaddr) return physaddr; } +rte_iova_t +rte_mem_virt2iova(const void *virtaddr) +{ + if (rte_eal_iova_mode() == RTE_IOVA_VA) + return (uintptr_t)virtaddr; + return rte_mem_virt2phy(virtaddr); +} + /* * For each hugepage in hugepg_tbl, fill the physaddr value. We find * it by browsing the /proc/self/pagemap special file. diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 7c9bdc2ae..a600881f0 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -234,6 +234,7 @@ DPDK_17.11 { rte_eal_vfio_intr_mode; rte_lcore_has_role; rte_memcpy_ptr; + rte_mem_virt2iova; vfio_enable; vfio_is_enabled; vfio_noiommu_is_enabled; diff --git a/lib/librte_mempool/rte_mempool.c b/lib/librte_mempool/rte_mempool.c index 6357fd48e..f62054e23 100644 --- a/lib/librte_mempool/rte_mempool.c +++ b/lib/librte_mempool/rte_mempool.c @@ -503,7 +503,7 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, for (off = 0; off + pg_sz <= len && mp->populated_size < mp->size; off += phys_len) { - paddr = rte_mem_virt2phy(addr + off); + paddr = rte_mem_virt2iova(addr + off); if (paddr == RTE_BAD_PHYS_ADDR && rte_eal_has_hugepages()) { ret = -EINVAL; @@ -514,7 +514,7 @@ rte_mempool_populate_virt(struct rte_mempool *mp, char *addr, for (phys_len = pg_sz; off + phys_len < len; phys_len += pg_sz) { phys_addr_t paddr_tmp; - paddr_tmp = rte_mem_virt2phy(addr + off + phys_len); + paddr_tmp = rte_mem_virt2iova(addr + off + phys_len); if (paddr_tmp != paddr + phys_len) break; diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 1f6cba4b9..97a5c3f1c 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -526,7 +526,7 @@ add_guest_pages(struct virtio_net *dev, struct rte_vhost_mem_region *reg, uint64_t host_phys_addr; uint64_t size; - host_phys_addr = rte_mem_virt2phy((void *)(uintptr_t)host_user_addr); + host_phys_addr = rte_mem_virt2iova((void *)(uintptr_t)host_user_addr); size = page_size - (guest_phys_addr & (page_size - 1)); size = RTE_MIN(size, reg_size); @@ -537,7 +537,7 @@ add_guest_pages(struct virtio_net *dev, struct rte_vhost_mem_region *reg, while (reg_size > 0) { size = RTE_MIN(reg_size, page_size); - host_phys_addr = rte_mem_virt2phy((void *)(uintptr_t) + host_phys_addr = rte_mem_virt2iova((void *)(uintptr_t) host_user_addr); add_one_guest_page(dev, guest_phys_addr, host_phys_addr, size); diff --git a/test/test/test_mempool.c b/test/test/test_mempool.c index dee73d658..fa8bad39f 100644 --- a/test/test/test_mempool.c +++ b/test/test/test_mempool.c @@ -144,9 +144,9 @@ test_mempool_basic(struct rte_mempool *mp, int use_external_cache) MEMPOOL_HEADER_SIZE(mp, mp->cache_size)) GOTO_ERR(ret, out); -#ifndef RTE_EXEC_ENV_BSDAPP /* rte_mem_virt2phy() not supported on bsd */ +#ifndef RTE_EXEC_ENV_BSDAPP /* rte_mem_virt2iova() not supported on bsd */ printf("get physical address of an object\n"); - if (rte_mempool_virt2phy(mp, obj) != rte_mem_virt2phy(obj)) + if (rte_mempool_virt2phy(mp, obj) != rte_mem_virt2iova(obj)) GOTO_ERR(ret, out); #endif -- 2.14.2