hw/rdma: Last step in eliminating data-path processing
cover hw/rdma: Last step in eliminating data-path processing
With emulated device we have the luxury of doing things in data-path. Considering a future virtio-rdma device we no longer have this luxury. The driver will directly post WQEs to HW queues, bypassing the device emulator in qemu. These WQEs will consist of addresses known to the device (even if it is guest addresses) and ID of an HW memory region (mr).
Commit 68b89aee71 ("Utilize ibv_reg_mr_iova for memory registration") did the first important step of utilizing a new rdma API so addresses translation is no longer needed.
This patch-set continues and remove entirely the processing in data-path by eliminating the need to translate emulated mr_id to backend device mr_id.
Yuval Shaia (2):
hw/rdma: Cosmetic change - no need for two sge arrays hw/rdma: Skip data-path mr_id translation
hw/rdma/rdma_backend.c | 61 +++++++++++++++++++++--------------------- hw/rdma/rdma_backend.h | 5 ---- hw/rdma/rdma_rm.c | 13 +++++---- 3 files changed, 36 insertions(+), 43 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 hw/rdma: Cosmetic change - no need for two sge arrays
The function build_host_sge_array uses two sge arrays, one for input and one for output.
Since the size of the two arrays is the same, the function can write directly to the given source array (i.e. input/output argument).
--- hw/rdma/rdma_backend.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)
hw/rdma/rdma_backend.c +17 -23
@@ -378,30 +378,27 @@ static void ah_cache_init(void) }static int build_host_sge_array (RdmaDeviceResources *rdma_dev_res, -struct ibv_sge *dsge,struct ibv_sge *ssge, -uint8_t num_sge,uint64_t *total_length) +struct ibv_sge *sge,uint8_t num_sge, +uint64_t *total_length) {RdmaRmMR *mr; -int ssge_idx; +int idx; -for (ssge_idx =0 ; ssge_idx < num_sge; ssge_idx++) { - mr =rdma_rm_get_mr (rdma_dev_res, ssge[ssge_idx].lkey); +for (idx =0 ; idx < num_sge; idx++) { + mr =rdma_rm_get_mr (rdma_dev_res, sge[idx].lkey);if (unlikely (!mr)) { -rdma_error_report ("Invalid lkey 0x%x" , ssge[ssge_idx].lkey); -return VENDOR_ERR_INVLKEY | ssge[ssge_idx].lkey; +rdma_error_report ("Invalid lkey 0x%x" , sge[idx].lkey); +return VENDOR_ERR_INVLKEY | sge[idx].lkey; }#ifdef LEGACY_RDMA_REG_MR - dsge->addr = (uintptr_t )mr->virt + ssge[ssge_idx].addr - mr->start; + sge[idx].addr = (uintptr_t )mr->virt + sge[idx].addr - mr->start;#else - dsge->addr = ssge[ssge_idx].addr; + sge[idx].addr = sge[idx].addr;#endif - dsge->length = ssge[ssge_idx].length; - dsge->lkey =rdma_backend_mr_lkey (&mr->backend_mr); + sge[idx].lkey =rdma_backend_mr_lkey (&mr->backend_mr); - *total_length += dsge->length; - - dsge++; + *total_length += sge[idx].length; }return 0 ;
@@ -484,7 +481,6 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev, void *ctx) {BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_send_wr wr = {}, *bad_wr;
@@ -518,7 +514,7 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev,rdma_protected_gslist_append_int32 (&qp->cqe_ctx_list, bctx_id); - rc =build_host_sge_array (backend_dev->rdma_dev_res, new_sge, sge, num_sge, + rc =build_host_sge_array (backend_dev->rdma_dev_res, sge, num_sge, &backend_dev->rdma_dev_res->stats.tx_len);if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);
@@ -538,7 +534,7 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev, wr.num_sge = num_sge; wr.opcode =IBV_WR_SEND ; wr.send_flags =IBV_SEND_SIGNALED ; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_send (qp->ibqp, &wr, &bad_wr);
@@ -601,7 +597,6 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev, struct ibv_sge *sge, uint32_t num_sge, void *ctx) { BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_recv_wr wr = {}, *bad_wr;
@@ -635,7 +630,7 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev,rdma_protected_gslist_append_int32 (&qp->cqe_ctx_list, bctx_id); - rc =build_host_sge_array (backend_dev->rdma_dev_res, new_sge, sge, num_sge, + rc =build_host_sge_array (backend_dev->rdma_dev_res, sge, num_sge, &backend_dev->rdma_dev_res->stats.rx_bufs_len);if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);
@@ -643,7 +638,7 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev, } wr.num_sge = num_sge; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_recv (qp->ibqp, &wr, &bad_wr);if (rc) {
@@ -671,7 +666,6 @@ void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev, uint32_t num_sge, void *ctx) { BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_recv_wr wr = {}, *bad_wr;
@@ -688,7 +682,7 @@ void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev,rdma_protected_gslist_append_int32 (&srq->cqe_ctx_list, bctx_id); - rc =build_host_sge_array (backend_dev->rdma_dev_res, new_sge, sge, num_sge, + rc =build_host_sge_array (backend_dev->rdma_dev_res, sge, num_sge, &backend_dev->rdma_dev_res->stats.rx_bufs_len);if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);
@@ -696,7 +690,7 @@ void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev, } wr.num_sge = num_sge; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_srq_recv (srq->ibsrq, &wr, &bad_wr);if (rc) {
Signature · 1 line
2.20.1
Re: [PATCH 1/2] hw/rdma: Cosmetic change - no need for two sge arrays
Hi Yuval,
Quoted 34 lines · Yuval Shaia
The function
build_host_sge_arrayuses two sge arrays, one for input and one for output.
Since the size of the two arrays is the same, the function can write directly to the given source array (i.e. input/output argument).Signed-off-by Yuval Shaia <[email protected]>--- hw/rdma/rdma_backend.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)hw/rdma/rdma_backend.c +5
-7@@ -378,30 +378,27 @@ static void ah_cache_init(void) }static int build_host_sge_array (RdmaDeviceResources *rdma_dev_res, -struct ibv_sge *dsge,struct ibv_sge *ssge, -uint8_t num_sge,uint64_t *total_length) +struct ibv_sge *sge,uint8_t num_sge, +uint64_t *total_length) {RdmaRmMR *mr; -int ssge_idx; +int idx; -for (ssge_idx =0 ; ssge_idx < num_sge; ssge_idx++) { - mr =rdma_rm_get_mr (rdma_dev_res, ssge[ssge_idx].lkey); +for (idx =0 ; idx < num_sge; idx++) { + mr =rdma_rm_get_mr (rdma_dev_res, sge[idx].lkey);if (unlikely (!mr)) { -rdma_error_report ("Invalid lkey 0x%x" , ssge[ssge_idx].lkey); -return VENDOR_ERR_INVLKEY | ssge[ssge_idx].lkey;
hw/rdma/rdma_backend.c static void ah_cache_init(void) · line 397
Quoted 10 lines
hw/rdma/rdma_backend.c +4
-2+rdma_error_report ("Invalid lkey 0x%x" , sge[idx].lkey); +return VENDOR_ERR_INVLKEY | sge[idx].lkey; }#ifdef LEGACY_RDMA_REG_MR - dsge->addr = (uintptr_t )mr->virt + ssge[ssge_idx].addr - mr->start; + sge[idx].addr = (uintptr_t )mr->virt + sge[idx].addr - mr->start;#else - dsge->addr = ssge[ssge_idx].addr; + sge[idx].addr = sge[idx].addr;
It seems we don't need the above line.
Other than that it looks good to me.
Thanks,
Marcel
Quoted 90 lines
hw/rdma/rdma_backend.c +8
-14#endif - dsge->length = ssge[ssge_idx].length; - dsge->lkey =rdma_backend_mr_lkey (&mr->backend_mr); + sge[idx].lkey =rdma_backend_mr_lkey (&mr->backend_mr); - *total_length += dsge->length; - - dsge++; + *total_length += sge[idx].length; }return 0 ;@@ -484,7 +481,6 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev, void *ctx) {BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_send_wr wr = {}, *bad_wr;@@ -518,7 +514,7 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev,rdma_protected_gslist_append_int32 (&qp->cqe_ctx_list, bctx_id); - rc =build_host_sge_array (backend_dev->rdma_dev_res, new_sge, sge, num_sge, + rc =build_host_sge_array (backend_dev->rdma_dev_res, sge, num_sge, &backend_dev->rdma_dev_res->stats.tx_len);if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);@@ -538,7 +534,7 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev, wr.num_sge = num_sge; wr.opcode =IBV_WR_SEND ; wr.send_flags =IBV_SEND_SIGNALED ; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_send (qp->ibqp, &wr, &bad_wr);@@ -601,7 +597,6 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev, struct ibv_sge *sge, uint32_t num_sge, void *ctx) { BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_recv_wr wr = {}, *bad_wr;@@ -635,7 +630,7 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev,rdma_protected_gslist_append_int32 (&qp->cqe_ctx_list, bctx_id); - rc =build_host_sge_array (backend_dev->rdma_dev_res, new_sge, sge, num_sge, + rc =build_host_sge_array (backend_dev->rdma_dev_res, sge, num_sge, &backend_dev->rdma_dev_res->stats.rx_bufs_len);if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);@@ -643,7 +638,7 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev, } wr.num_sge = num_sge; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_recv (qp->ibqp, &wr, &bad_wr);if (rc) {@@ -671,7 +666,6 @@ void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev, uint32_t num_sge, void *ctx) { BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_recv_wr wr = {}, *bad_wr;@@ -688,7 +682,7 @@ void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev,rdma_protected_gslist_append_int32 (&srq->cqe_ctx_list, bctx_id); - rc =build_host_sge_array (backend_dev->rdma_dev_res, new_sge, sge, num_sge, + rc =build_host_sge_array (backend_dev->rdma_dev_res, sge, num_sge, &backend_dev->rdma_dev_res->stats.rx_bufs_len);if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);@@ -696,7 +690,7 @@ void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev, } wr.num_sge = num_sge; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_srq_recv (srq->ibsrq, &wr, &bad_wr);if (rc) {
Re: [PATCH 1/2] hw/rdma: Cosmetic change - no need for two sge arrays
Quoted 44 lines · Marcel Apfelbaum
Hi Yuval,
Quoted 15 lines · Yuval Shaia
The function
build_host_sge_arrayuses two sge arrays, one for input and one for output.
Since the size of the two arrays is the same, the function can write directly to the given source array (i.e. input/output argument).Signed-off-by Yuval Shaia <[email protected]>--- hw/rdma/rdma_backend.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-)hw/rdma/rdma_backend.c +0
-0hw/rdma/rdma_backend.c static void ah_cache_init(void) · line 381
Quoted 4 lines
hw/rdma/rdma_backend.c +0
-1@@ -378,30 +378,27 @@ static void ah_cache_init(void) } static int build_host_sge_array(RdmaDeviceResources *rdma_dev_res, - struct ibv_sge *dsge, struct ibv_sge*ssge,
Quoted 11 lines
hw/rdma/rdma_backend.c +4
-4- uint8_t num_sge, uint64_t *total_length) + struct ibv_sge *sge, uint8_t num_sge, + uint64_t *total_length) { RdmaRmMR *mr; -int ssge_idx; +int idx; -for (ssge_idx =0 ; ssge_idx < num_sge; ssge_idx++) { - mr =rdma_rm_get_mr (rdma_dev_res, ssge[ssge_idx].lkey); +for (idx =0 ; idx < num_sge; idx++) {hw/rdma/rdma_backend.c static void ah_cache_init(void)
Quoted 10 lines
hw/rdma/rdma_backend.c +3
-3+ mr =rdma_rm_get_mr (rdma_dev_res, sge[idx].lkey);if (unlikely (!mr)) { -rdma_error_report ("Invalid lkey 0x%x" , ssge[ssge_idx].lkey); -return VENDOR_ERR_INVLKEY | ssge[ssge_idx].lkey; +rdma_error_report ("Invalid lkey 0x%x" , sge[idx].lkey); +return VENDOR_ERR_INVLKEY | sge[idx].lkey; }#ifdef LEGACY_RDMA_REG_MR - dsge->addr = (uintptr_t)mr->virt + ssge[ssge_idx].addr -
Quoted 9 lines
mr->start;hw/rdma/rdma_backend.c static void ah_cache_init(void) · line 397
Quoted 4 lines
hw/rdma/rdma_backend.c +2
-1+ sge[idx].addr = (uintptr_t )mr->virt + sge[idx].addr - mr->start;#else - dsge->addr = ssge[ssge_idx].addr; + sge[idx].addr = sge[idx].addr;It seems we don't need the above line.
Other than that it looks good to me.
Yeah, thanks.
It is fixed in the next patch but better be fixed here. Will fix and post new set.
Quoted 112 lines
Thanks,
Marcelhw/rdma/rdma_backend.c void rdma_backend_post_send(RdmaBackendDev
Quoted 13 lines
hw/rdma/rdma_backend.c +2
-5#endif - dsge->length = ssge[ssge_idx].length; - dsge->lkey =rdma_backend_mr_lkey (&mr->backend_mr); + sge[idx].lkey =rdma_backend_mr_lkey (&mr->backend_mr); - *total_length += dsge->length; - - dsge++; + *total_length += sge[idx].length; }return 0 ;@@ -484,7 +481,6 @@ void rdma_backend_post_send(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_send(RdmaBackendDev
Quoted 8 lines
hw/rdma/rdma_backend.c +0
-1void *ctx) {BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_send_wr wr = {}, *bad_wr;@@ -518,7 +514,7 @@ void rdma_backend_post_send(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_send(RdmaBackendDev *backend_dev,
Quoted 4 lines
hw/rdma/rdma_backend.c +0
-1rdma_protected_gslist_append_int32 (&qp->cqe_ctx_list, bctx_id); - rc = build_host_sge_array(backend_dev->rdma_dev_res, new_sge, sge,
num_sge,hw/rdma/rdma_backend.c void rdma_backend_post_send(RdmaBackendDev · line 517
Quoted 2 lines
hw/rdma/rdma_backend.c +1
-0+ rc = build_host_sge_array(backend_dev->rdma_dev_res, sge, num_sge,
&backend_dev->rdma_dev_res->stats.tx_len);hw/rdma/rdma_backend.c void rdma_backend_post_send(RdmaBackendDev
Quoted 3 lines
hw/rdma/rdma_backend.c +0
-0if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);@@ -538,7 +534,7 @@ void rdma_backend_post_send(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_recv(RdmaBackendDev
Quoted 9 lines
hw/rdma/rdma_backend.c +1
-1wr.num_sge = num_sge; wr.opcode =IBV_WR_SEND ; wr.send_flags =IBV_SEND_SIGNALED ; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_send (qp->ibqp, &wr, &bad_wr);@@ -601,7 +597,6 @@ void rdma_backend_post_recv(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_recv(RdmaBackendDev · line 597
Quoted 1 line
hw/rdma/rdma_backend.c +0
-0struct ibv_sge *sge, uint32_t num_sge,void *ctx)
hw/rdma/rdma_backend.c void rdma_backend_post_recv(RdmaBackendDev
Quoted 7 lines
hw/rdma/rdma_backend.c +0
-1{BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_recv_wr wr = {}, *bad_wr;@@ -635,7 +630,7 @@ void rdma_backend_post_recv(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_send(RdmaBackendDev *backend_dev,
Quoted 4 lines
hw/rdma/rdma_backend.c +0
-1rdma_protected_gslist_append_int32 (&qp->cqe_ctx_list, bctx_id); - rc = build_host_sge_array(backend_dev->rdma_dev_res, new_sge, sge,
num_sge,hw/rdma/rdma_backend.c void rdma_backend_post_recv(RdmaBackendDev · line 633
Quoted 2 lines
hw/rdma/rdma_backend.c +1
-0+ rc = build_host_sge_array(backend_dev->rdma_dev_res, sge, num_sge,
&backend_dev->rdma_dev_res->stats.rx_bufs_len);hw/rdma/rdma_backend.c void rdma_backend_post_recv(RdmaBackendDev
Quoted 3 lines
hw/rdma/rdma_backend.c +0
-0if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);@@ -643,7 +638,7 @@ void rdma_backend_post_recv(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_srq_recv(RdmaBackendDev
Quoted 9 lines
hw/rdma/rdma_backend.c +1
-1} wr.num_sge = num_sge; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_recv (qp->ibqp, &wr, &bad_wr);if (rc) {@@ -671,7 +666,6 @@ void rdma_backend_post_srq_recv(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_srq_recv(RdmaBackendDev
Quoted 8 lines
hw/rdma/rdma_backend.c +0
-1uint32_t num_sge, void *ctx) { BackendCtx *bctx; -struct ibv_sge new_sge[MAX_SGE ];uint32_t bctx_id;int rc;struct ibv_recv_wr wr = {}, *bad_wr;@@ -688,7 +682,7 @@ void rdma_backend_post_srq_recv(RdmaBackendDev
*backend_dev,hw/rdma/rdma_backend.c void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev,
Quoted 4 lines
hw/rdma/rdma_backend.c +0
-1rdma_protected_gslist_append_int32 (&srq->cqe_ctx_list, bctx_id); - rc = build_host_sge_array(backend_dev->rdma_dev_res, new_sge, sge,
num_sge,hw/rdma/rdma_backend.c void rdma_backend_post_srq_recv(RdmaBackendDev · line 685
Quoted 2 lines
hw/rdma/rdma_backend.c +1
-0+ rc = build_host_sge_array(backend_dev->rdma_dev_res, sge, num_sge,
&backend_dev->rdma_dev_res->stats.rx_bufs_len);hw/rdma/rdma_backend.c void rdma_backend_post_srq_recv(RdmaBackendDev
Quoted 3 lines
hw/rdma/rdma_backend.c +0
-0if (rc) {complete_work (IBV_WC_GENERAL_ERR , rc, ctx);@@ -696,7 +690,7 @@ void rdma_backend_post_srq_recv(RdmaBackendDev
*backend_dev,Quoted 8 lines
hw/rdma/rdma_backend.c +1
-1} wr.num_sge = num_sge; - wr.sg_list = new_sge; + wr.sg_list = sge; wr.wr_id = bctx_id; rc =ibv_post_srq_recv (srq->ibsrq, &wr, &bad_wr);if (rc) {
PATCH 2/2 hw/rdma: Skip data-path mr_id translation
In reply to Yuval ShaiaWith the change made in commit 68b89aee71 ("Utilize ibv_reg_mr_iova for memory registration") the MR emulation is no longer needed in order to translate the guest addresses into host addresses.
With that, the next obvious step is to skip entirely the processing in data-path.
To accomplish this, return the backend's lkey to driver so we will not need to do the emulated mr_id to backend mr_id translation in data-path.
The function build_host_sge_array is still called in data-path but only for backward computability with statistics collection.
While there, as a cosmetic change to make the code cleaner - make one copy of the function rdma_backend_create_mr and leave the redundant guest_start argument in the legacy code.
--- hw/rdma/rdma_backend.c | 23 ++++++++++++++--------- hw/rdma/rdma_backend.h | 5 ----- hw/rdma/rdma_rm.c | 13 ++++++------- 3 files changed, 20 insertions(+), 21 deletions(-)
hw/rdma/rdma_backend.c +14 -9
@@ -377,6 +377,7 @@ static void ah_cache_init(void) destroy_ah_hash_key, destroy_ah_hast_data); } +#ifdef LEGACY_RDMA_REG_MR static int build_host_sge_array (RdmaDeviceResources *rdma_dev_res,struct ibv_sge *sge,uint8_t num_sge,uint64_t *total_length)
@@ -391,11 +392,7 @@ static int build_host_sge_array(RdmaDeviceResources *rdma_dev_res,return VENDOR_ERR_INVLKEY | sge[idx].lkey; } -#ifdef LEGACY_RDMA_REG_MR sge[idx].addr = (uintptr_t )mr->virt + sge[idx].addr - mr->start; -#else - sge[idx].addr = sge[idx].addr; -#endif sge[idx].lkey =rdma_backend_mr_lkey (&mr->backend_mr); *total_length += sge[idx].length;
@@ -403,6 +400,19 @@ static int build_host_sge_array(RdmaDeviceResources *rdma_dev_res, return 0; } +#else +static inline int build_host_sge_array (RdmaDeviceResources *rdma_dev_res, +struct ibv_sge *sge,uint8_t num_sge, +uint64_t *total_length) +{ +int idx; + +for (idx =0 ; idx < num_sge; idx++) { + *total_length += sge[idx].length; + } +return 0 ; +} +#endif static void trace_mad_message (const char *title,char *buf,int len) {
@@ -733,13 +743,8 @@ void rdma_backend_destroy_pd(RdmaBackendPD *pd) } } -#ifdef LEGACY_RDMA_REG_MR -int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr, - size_t length, int access) -#else int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr,size_t length,uint64_t guest_start,int access) -#endif {#ifdef LEGACY_RDMA_REG_MR mr->ibmr =ibv_reg_mr (pd->ibpd, addr, length, access);
hw/rdma/rdma_backend.h +0 -5
@@ -78,13 +78,8 @@ int rdma_backend_query_port(RdmaBackendDev *backend_dev,int rdma_backend_create_pd (RdmaBackendDev *backend_dev,RdmaBackendPD *pd);void rdma_backend_destroy_pd (RdmaBackendPD *pd); -#ifdef LEGACY_RDMA_REG_MR -int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr, -size_t length,int access); -#else int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr,size_t length,uint64_t guest_start,int access); -#endif void rdma_backend_destroy_mr (RdmaBackendMR *mr); int rdma_backend_create_cq(RdmaBackendDev *backend_dev, RdmaBackendCQ *cq,
hw/rdma/rdma_rm.c +6 -7
@@ -227,21 +227,20 @@ int rdma_rm_alloc_mr(RdmaDeviceResources *dev_res, uint32_t pd_handle, mr->length = guest_length; mr->virt += (mr->start & (TARGET_PAGE_SIZE -1 )); -#ifdef LEGACY_RDMA_REG_MR - ret =rdma_backend_create_mr (&mr->backend_mr, &pd->backend_pd, mr->virt, - mr->length, access_flags); -#else ret =rdma_backend_create_mr (&mr->backend_mr, &pd->backend_pd, mr->virt, mr->length, guest_start, access_flags); -#endif if (ret) { ret = -EIO ; goto out_dealloc_mr; } +#ifdef LEGACY_RDMA_REG_MR +/* We keep mr_handle in lkey so send and recv get get mr ptr */ + *lkey = *mr_handle; +#else + *lkey =rdma_backend_mr_lkey (&mr->backend_mr); +#endif } -/* We keep mr_handle in lkey so send and recv get get mr ptr */ - *lkey = *mr_handle; *rkey =-1 ; mr->pd_handle = pd_handle;
Signature · 1 line
2.20.1
Re: [PATCH 2/2] hw/rdma: Skip data-path mr_id translation
Hi Yuval,
Quoted 120 lines · Yuval Shaia
With the change made in commit
68b89aee71("Utilizeibv_reg_mr_iovafor memory registration") the MR emulation is no longer needed in order to translate the guest addresses into host addresses.
With that, the next obvious step is to skip entirely the processing in data-path.
To accomplish this, return the backend's lkey to driver so we will not need to do the emulatedmr_idto backendmr_idtranslation in data-path.The function
build_host_sge_arrayis still called in data-path but only for backward computability with statistics collection.While there, as a cosmetic change to make the code cleaner - make one copy of the function
rdma_backend_create_mrand leave the redundantguest_startargument in the legacy code.Signed-off-by Yuval Shaia <[email protected]>--- hw/rdma/rdma_backend.c | 23 ++++++++++++++--------- hw/rdma/rdma_backend.h | 5 ----- hw/rdma/rdma_rm.c | 13 ++++++------- 3 files changed, 20 insertions(+), 21 deletions(-)hw/rdma/rdma_backend.c +14
-9@@ -377,6 +377,7 @@ static void ah_cache_init(void) destroy_ah_hash_key, destroy_ah_hast_data); } +#ifdef LEGACY_RDMA_REG_MR static int build_host_sge_array (RdmaDeviceResources *rdma_dev_res,struct ibv_sge *sge,uint8_t num_sge,uint64_t *total_length)@@ -391,11 +392,7 @@ static int build_host_sge_array(RdmaDeviceResources *rdma_dev_res,return VENDOR_ERR_INVLKEY | sge[idx].lkey; } -#ifdef LEGACY_RDMA_REG_MR sge[idx].addr = (uintptr_t )mr->virt + sge[idx].addr - mr->start; -#else - sge[idx].addr = sge[idx].addr; -#endif sge[idx].lkey =rdma_backend_mr_lkey (&mr->backend_mr); *total_length += sge[idx].length;@@ -403,6 +400,19 @@ static int build_host_sge_array(RdmaDeviceResources *rdma_dev_res, return 0; } +#else +static inline int build_host_sge_array (RdmaDeviceResources *rdma_dev_res, +struct ibv_sge *sge,uint8_t num_sge, +uint64_t *total_length) +{ +int idx; + +for (idx =0 ; idx < num_sge; idx++) { + *total_length += sge[idx].length; + } +return 0 ; +} +#endif static void trace_mad_message (const char *title,char *buf,int len) {@@ -733,13 +743,8 @@ void rdma_backend_destroy_pd(RdmaBackendPD *pd) } } -#ifdef LEGACY_RDMA_REG_MR -int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr, - size_t length, int access) -#else int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr,size_t length,uint64_t guest_start,int access) -#endif {#ifdef LEGACY_RDMA_REG_MR mr->ibmr =ibv_reg_mr (pd->ibpd, addr, length, access);hw/rdma/rdma_backend.h +0
-5@@ -78,13 +78,8 @@ int rdma_backend_query_port(RdmaBackendDev *backend_dev,int rdma_backend_create_pd (RdmaBackendDev *backend_dev,RdmaBackendPD *pd);void rdma_backend_destroy_pd (RdmaBackendPD *pd); -#ifdef LEGACY_RDMA_REG_MR -int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr, -size_t length,int access); -#else int rdma_backend_create_mr (RdmaBackendMR *mr,RdmaBackendPD *pd,void *addr,size_t length,uint64_t guest_start,int access); -#endif void rdma_backend_destroy_mr (RdmaBackendMR *mr); int rdma_backend_create_cq(RdmaBackendDev *backend_dev, RdmaBackendCQ *cq,hw/rdma/rdma_rm.c +3
-5@@ -227,21 +227,20 @@ int rdma_rm_alloc_mr(RdmaDeviceResources *dev_res, uint32_t pd_handle, mr->length = guest_length; mr->virt += (mr->start & (TARGET_PAGE_SIZE -1 )); -#ifdef LEGACY_RDMA_REG_MR - ret =rdma_backend_create_mr (&mr->backend_mr, &pd->backend_pd, mr->virt, - mr->length, access_flags); -#else ret =rdma_backend_create_mr (&mr->backend_mr, &pd->backend_pd, mr->virt, mr->length, guest_start, access_flags); -#endif if (ret) { ret = -EIO ; goto out_dealloc_mr; } +#ifdef LEGACY_RDMA_REG_MR +/* We keep mr_handle in lkey so send and recv get get mr ptr */ + *lkey = *mr_handle;
hw/rdma/rdma_rm.c int rdma_rm_alloc_mr(RdmaDeviceResources *dev_res, uint32_t pd_handle, · line 246
Quoted 10 lines
hw/rdma/rdma_rm.c +3
-2+#else + *lkey =rdma_backend_mr_lkey (&mr->backend_mr); +#endif } -/* We keep mr_handle in lkey so send and recv get get mr ptr */ - *lkey = *mr_handle; *rkey =-1 ; mr->pd_handle = pd_handle;
Thanks,
Marcel