From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A699BA0543; Fri, 7 Oct 2022 23:02:46 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D5177427F1; Fri, 7 Oct 2022 23:02:39 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 16BBC427EE for ; Fri, 7 Oct 2022 23:02:38 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 297FLkcZ007146; Fri, 7 Oct 2022 14:02:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=JbgTvMujSY5LgGA54NKsXf1gQSVEEufXseynnaT35T8=; b=CxlrvuD3QP+UZtU1zJFk8IRwZ43oIeL9spqAmvGmTw8MyjYomslJX61hqBL2DFTuWN7G E8qMYXfB6+bAgwkw62YSRfOeCCArJzStHLbtat7VrgeSrNen+VnNxh3GDXBk7dyTmzER xCFycWOHHwZXyC8kmw4LCP2I78GVT2SvNzIXo8Q2EY2bJAY/f7XqkWxAaIPOKH349qsa P4chPrGOXEl1RiMPYd9+K0A587zcb8LmQVlpVD3ga2vBL/UhTydC9x3A4x6PmlwlceVP UUGKceCGXcC1iFmBTNg5S7pGmt0lA5B9J6TT+Mi5Bz2YKkBHTJEnUm3pzmdQvxc9Axsr dQ== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3k2ppes8qn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 07 Oct 2022 14:02:32 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 7 Oct 2022 14:02:29 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 7 Oct 2022 14:02:29 -0700 Received: from localhost.localdomain (unknown [10.28.34.29]) by maili.marvell.com (Postfix) with ESMTP id 97D393F70D4; Fri, 7 Oct 2022 14:02:18 -0700 (PDT) From: Shijith Thotton To: CC: Shijith Thotton , , , , , , , , Nicolas Chautru , Ciara Power , "Konstantin Ananyev" , Reshma Pattan , Cristian Dumitrescu , Maxime Coquelin , Chenbo Xia Subject: [PATCH v5 1/7] mbuf: add API to get and set mbuf physical address Date: Sat, 8 Oct 2022 02:32:05 +0530 Message-ID: <859249ecb375950eba98901777fae3c70c9388c7.1665176094.git.sthotton@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: Sy3UeZO638sBgqSgStJywZ55REGTORcj X-Proofpoint-ORIG-GUID: Sy3UeZO638sBgqSgStJywZ55REGTORcj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-10-07_04,2022-10-07_01,2022-06-22_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Added APIs rte_mbuf_iova_set and rte_mbuf_iova_get to set and get the physical address of an mbuf respectively. Updated applications and library to use the same. Signed-off-by: Shijith Thotton Acked-by: Olivier Matz --- app/test-bbdev/test_bbdev_perf.c | 2 +- app/test-crypto-perf/cperf_test_common.c | 5 ++-- app/test/test_bpf.c | 2 +- app/test/test_mbuf.c | 2 +- app/test/test_pcapng.c | 2 +- lib/kni/rte_kni.c | 3 +- lib/mbuf/rte_mbuf.c | 12 ++++---- lib/mbuf/rte_mbuf.h | 38 ++++++++++++++++++++---- lib/mbuf/rte_mbuf_core.h | 3 +- lib/pipeline/rte_table_action.c | 2 +- lib/vhost/vhost.h | 2 +- lib/vhost/vhost_crypto.c | 25 ++++++++-------- 12 files changed, 61 insertions(+), 37 deletions(-) diff --git a/app/test-bbdev/test_bbdev_perf.c b/app/test-bbdev/test_bbdev_perf.c index 311e5d1a96..e7fbf71f6d 100644 --- a/app/test-bbdev/test_bbdev_perf.c +++ b/app/test-bbdev/test_bbdev_perf.c @@ -1002,7 +1002,7 @@ init_op_data_objs(struct rte_bbdev_op_data *bufs, seg->length); memcpy(data, seg->addr, seg->length); m_head->buf_addr = data; - m_head->buf_iova = rte_malloc_virt2iova(data); + rte_mbuf_iova_set(m_head, rte_malloc_virt2iova(data)); m_head->data_off = 0; m_head->data_len = seg->length; } else { diff --git a/app/test-crypto-perf/cperf_test_common.c b/app/test-crypto-perf/cperf_test_common.c index 00aadc9a47..27646cd619 100644 --- a/app/test-crypto-perf/cperf_test_common.c +++ b/app/test-crypto-perf/cperf_test_common.c @@ -26,8 +26,7 @@ fill_single_seg_mbuf(struct rte_mbuf *m, struct rte_mempool *mp, /* start of buffer is after mbuf structure and priv data */ m->priv_size = 0; m->buf_addr = (char *)m + mbuf_hdr_size; - m->buf_iova = rte_mempool_virt2iova(obj) + - mbuf_offset + mbuf_hdr_size; + rte_mbuf_iova_set(m, rte_mempool_virt2iova(obj) + mbuf_offset + mbuf_hdr_size); m->buf_len = segment_sz; m->data_len = data_len; m->pkt_len = data_len; @@ -58,7 +57,7 @@ fill_multi_seg_mbuf(struct rte_mbuf *m, struct rte_mempool *mp, /* start of buffer is after mbuf structure and priv data */ m->priv_size = 0; m->buf_addr = (char *)m + mbuf_hdr_size; - m->buf_iova = next_seg_phys_addr; + rte_mbuf_iova_set(m, next_seg_phys_addr); next_seg_phys_addr += mbuf_hdr_size + segment_sz; m->buf_len = segment_sz; m->data_len = data_len; diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c index 97f500809e..f5af5e8a3f 100644 --- a/app/test/test_bpf.c +++ b/app/test/test_bpf.c @@ -2600,7 +2600,7 @@ dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len, uint8_t *db; mb->buf_addr = buf; - mb->buf_iova = (uintptr_t)buf; + rte_mbuf_iova_set(mb, (uintptr_t)buf); mb->buf_len = buf_len; rte_mbuf_refcnt_set(mb, 1); diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index be4c3ff970..f94d33f212 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -1233,7 +1233,7 @@ test_failing_mbuf_sanity_check(struct rte_mempool *pktmbuf_pool) } badbuf = *buf; - badbuf.buf_iova = 0; + rte_mbuf_iova_set(&badbuf, 0); if (verify_mbuf_check_panics(&badbuf)) { printf("Error with bad-physaddr mbuf test\n"); return -1; diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c index 320dacea34..abbf00f6da 100644 --- a/app/test/test_pcapng.c +++ b/app/test/test_pcapng.c @@ -40,7 +40,7 @@ dummy_mbuf_prep(struct rte_mbuf *mb, uint8_t buf[], uint32_t buf_len, uint8_t *db; mb->buf_addr = buf; - mb->buf_iova = (uintptr_t)buf; + rte_mbuf_iova_set(mb, (uintptr_t)buf); mb->buf_len = buf_len; rte_mbuf_refcnt_set(mb, 1); diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c index 7971c56bb4..3737a91de7 100644 --- a/lib/kni/rte_kni.c +++ b/lib/kni/rte_kni.c @@ -357,8 +357,7 @@ static void * va2pa(struct rte_mbuf *m) { return (void *)((unsigned long)m - - ((unsigned long)m->buf_addr - - (unsigned long)m->buf_iova)); + ((unsigned long)m->buf_addr - (unsigned long)rte_mbuf_iova_get(m))); } static void * diff --git a/lib/mbuf/rte_mbuf.c b/lib/mbuf/rte_mbuf.c index a2307cebe6..16f6ed6731 100644 --- a/lib/mbuf/rte_mbuf.c +++ b/lib/mbuf/rte_mbuf.c @@ -89,7 +89,7 @@ rte_pktmbuf_init(struct rte_mempool *mp, /* start of buffer is after mbuf structure and priv data */ m->priv_size = priv_size; m->buf_addr = (char *)m + mbuf_size; - m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size; + rte_mbuf_iova_set(m, rte_mempool_virt2iova(m) + mbuf_size); m->buf_len = (uint16_t)buf_len; /* keep some headroom between start of buffer and data */ @@ -187,8 +187,8 @@ __rte_pktmbuf_init_extmem(struct rte_mempool *mp, RTE_ASSERT(ctx->off + ext_mem->elt_size <= ext_mem->buf_len); m->buf_addr = RTE_PTR_ADD(ext_mem->buf_ptr, ctx->off); - m->buf_iova = ext_mem->buf_iova == RTE_BAD_IOVA ? - RTE_BAD_IOVA : (ext_mem->buf_iova + ctx->off); + rte_mbuf_iova_set(m, ext_mem->buf_iova == RTE_BAD_IOVA ? RTE_BAD_IOVA : + (ext_mem->buf_iova + ctx->off)); ctx->off += ext_mem->elt_size; if (ctx->off + ext_mem->elt_size > ext_mem->buf_len) { @@ -388,7 +388,7 @@ int rte_mbuf_check(const struct rte_mbuf *m, int is_header, *reason = "bad mbuf pool"; return -1; } - if (m->buf_iova == 0) { + if (rte_mbuf_iova_get(m) == 0) { *reason = "bad IO addr"; return -1; } @@ -669,8 +669,8 @@ rte_pktmbuf_dump(FILE *f, const struct rte_mbuf *m, unsigned dump_len) __rte_mbuf_sanity_check(m, 1); - fprintf(f, "dump mbuf at %p, iova=%#"PRIx64", buf_len=%u\n", - m, m->buf_iova, m->buf_len); + fprintf(f, "dump mbuf at %p, iova=%#" PRIx64 ", buf_len=%u\n", m, rte_mbuf_iova_get(m), + m->buf_len); fprintf(f, " pkt_len=%u, ol_flags=%#"PRIx64", nb_segs=%u, port=%u", m->pkt_len, m->ol_flags, m->nb_segs, m->port); diff --git a/lib/mbuf/rte_mbuf.h b/lib/mbuf/rte_mbuf.h index b6e23d98ce..c9f74586c3 100644 --- a/lib/mbuf/rte_mbuf.h +++ b/lib/mbuf/rte_mbuf.h @@ -135,6 +135,34 @@ rte_mbuf_prefetch_part2(struct rte_mbuf *m) static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp); +/** + * Get the IOVA address of the mbuf data buffer. + * + * @param m + * The pointer to the mbuf. + * @return + * The IOVA address of the mbuf. + */ +static inline rte_iova_t +rte_mbuf_iova_get(const struct rte_mbuf *m) +{ + return m->buf_iova; +} + +/** + * Set the IOVA address of the mbuf data buffer + * + * @param m + * The pointer to the mbuf. + * @param iova + * Value to set as IOVA address of the mbuf. + */ +static inline void +rte_mbuf_iova_set(struct rte_mbuf *m, rte_iova_t iova) +{ + m->buf_iova = iova; +} + /** * Return the IO address of the beginning of the mbuf data * @@ -146,7 +174,7 @@ static inline uint16_t rte_pktmbuf_priv_size(struct rte_mempool *mp); static inline rte_iova_t rte_mbuf_data_iova(const struct rte_mbuf *mb) { - return mb->buf_iova + mb->data_off; + return rte_mbuf_iova_get(mb) + mb->data_off; } /** @@ -164,7 +192,7 @@ rte_mbuf_data_iova(const struct rte_mbuf *mb) static inline rte_iova_t rte_mbuf_data_iova_default(const struct rte_mbuf *mb) { - return mb->buf_iova + RTE_PKTMBUF_HEADROOM; + return rte_mbuf_iova_get(mb) + RTE_PKTMBUF_HEADROOM; } /** @@ -1053,7 +1081,7 @@ rte_pktmbuf_attach_extbuf(struct rte_mbuf *m, void *buf_addr, RTE_ASSERT(shinfo->free_cb != NULL); m->buf_addr = buf_addr; - m->buf_iova = buf_iova; + rte_mbuf_iova_set(m, buf_iova); m->buf_len = buf_len; m->data_len = 0; @@ -1140,7 +1168,7 @@ static inline void rte_pktmbuf_attach(struct rte_mbuf *mi, struct rte_mbuf *m) mi->data_off = m->data_off; mi->data_len = m->data_len; - mi->buf_iova = m->buf_iova; + rte_mbuf_iova_set(mi, rte_mbuf_iova_get(m)); mi->buf_addr = m->buf_addr; mi->buf_len = m->buf_len; @@ -1242,7 +1270,7 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m) m->priv_size = priv_size; m->buf_addr = (char *)m + mbuf_size; - m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size; + rte_mbuf_iova_set(m, rte_mempool_virt2iova(m) + mbuf_size); m->buf_len = (uint16_t)buf_len; rte_pktmbuf_reset_headroom(m); m->data_len = 0; diff --git a/lib/mbuf/rte_mbuf_core.h b/lib/mbuf/rte_mbuf_core.h index e672d59b36..51a12a1fb9 100644 --- a/lib/mbuf/rte_mbuf_core.h +++ b/lib/mbuf/rte_mbuf_core.h @@ -736,8 +736,7 @@ struct rte_mbuf_ext_shared_info { * @param o * The offset into the data to calculate address from. */ -#define rte_pktmbuf_iova_offset(m, o) \ - (rte_iova_t)((m)->buf_iova + (m)->data_off + (o)) +#define rte_pktmbuf_iova_offset(m, o) (rte_iova_t)(rte_mbuf_iova_get(m) + (m)->data_off + (o)) /** * A macro that returns the IO address that points to the start of the diff --git a/lib/pipeline/rte_table_action.c b/lib/pipeline/rte_table_action.c index cb792bbe0d..de5da0b695 100644 --- a/lib/pipeline/rte_table_action.c +++ b/lib/pipeline/rte_table_action.c @@ -1923,7 +1923,7 @@ pkt_work_sym_crypto(struct rte_mbuf *mbuf, struct sym_crypto_data *data, op->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC; op->sess_type = RTE_CRYPTO_OP_WITH_SESSION; - op->phys_addr = mbuf->buf_iova + cfg->op_offset - sizeof(*mbuf); + op->phys_addr = rte_mbuf_iova_get(mbuf) + cfg->op_offset - sizeof(*mbuf); op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; sym->m_src = mbuf; sym->m_dst = NULL; diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h index eeeda681cc..ef211ed519 100644 --- a/lib/vhost/vhost.h +++ b/lib/vhost/vhost.h @@ -971,7 +971,7 @@ restore_mbuf(struct rte_mbuf *m) /* start of buffer is after mbuf structure and priv data */ m->buf_addr = (char *)m + mbuf_size; - m->buf_iova = rte_mempool_virt2iova(m) + mbuf_size; + rte_mbuf_iova_set(m, rte_mempool_virt2iova(m) + mbuf_size); m = m->next; } } diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c index 7321da21b7..b448b6685d 100644 --- a/lib/vhost/vhost_crypto.c +++ b/lib/vhost/vhost_crypto.c @@ -807,11 +807,10 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op, switch (vcrypto->option) { case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE: m_src->data_len = cipher->para.src_data_len; - m_src->buf_iova = gpa_to_hpa(vcrypto->dev, desc->addr, - cipher->para.src_data_len); + rte_mbuf_iova_set(m_src, + gpa_to_hpa(vcrypto->dev, desc->addr, cipher->para.src_data_len)); m_src->buf_addr = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO); - if (unlikely(m_src->buf_iova == 0 || - m_src->buf_addr == NULL)) { + if (unlikely(rte_mbuf_iova_get(m_src) == 0 || m_src->buf_addr == NULL)) { VC_LOG_ERR("zero_copy may fail due to cross page data"); ret = VIRTIO_CRYPTO_ERR; goto error_exit; @@ -851,10 +850,10 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op, switch (vcrypto->option) { case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE: - m_dst->buf_iova = gpa_to_hpa(vcrypto->dev, - desc->addr, cipher->para.dst_data_len); + rte_mbuf_iova_set(m_dst, + gpa_to_hpa(vcrypto->dev, desc->addr, cipher->para.dst_data_len)); m_dst->buf_addr = get_data_ptr(vc_req, desc, VHOST_ACCESS_RW); - if (unlikely(m_dst->buf_iova == 0 || m_dst->buf_addr == NULL)) { + if (unlikely(rte_mbuf_iova_get(m_dst) == 0 || m_dst->buf_addr == NULL)) { VC_LOG_ERR("zero_copy may fail due to cross page data"); ret = VIRTIO_CRYPTO_ERR; goto error_exit; @@ -965,10 +964,10 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op, m_src->data_len = chain->para.src_data_len; m_dst->data_len = chain->para.dst_data_len; - m_src->buf_iova = gpa_to_hpa(vcrypto->dev, desc->addr, - chain->para.src_data_len); + rte_mbuf_iova_set(m_src, + gpa_to_hpa(vcrypto->dev, desc->addr, chain->para.src_data_len)); m_src->buf_addr = get_data_ptr(vc_req, desc, VHOST_ACCESS_RO); - if (unlikely(m_src->buf_iova == 0 || m_src->buf_addr == NULL)) { + if (unlikely(rte_mbuf_iova_get(m_src) == 0 || m_src->buf_addr == NULL)) { VC_LOG_ERR("zero_copy may fail due to cross page data"); ret = VIRTIO_CRYPTO_ERR; goto error_exit; @@ -1008,10 +1007,10 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op, switch (vcrypto->option) { case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE: - m_dst->buf_iova = gpa_to_hpa(vcrypto->dev, - desc->addr, chain->para.dst_data_len); + rte_mbuf_iova_set(m_dst, + gpa_to_hpa(vcrypto->dev, desc->addr, chain->para.dst_data_len)); m_dst->buf_addr = get_data_ptr(vc_req, desc, VHOST_ACCESS_RW); - if (unlikely(m_dst->buf_iova == 0 || m_dst->buf_addr == NULL)) { + if (unlikely(rte_mbuf_iova_get(m_dst) == 0 || m_dst->buf_addr == NULL)) { VC_LOG_ERR("zero_copy may fail due to cross page data"); ret = VIRTIO_CRYPTO_ERR; goto error_exit; -- 2.25.1