Skip to content

Commit 91a10c5

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Use same device when mapping or syncing DMA buffers
When the underlying device driver is reloaded, ia->ri_device will be replaced. All cached copies of that device pointer have to be updated as well. Commit 54cbd6b ("xprtrdma: Delay DMA mapping Send and Receive buffers") added the rg_device field to each regbuf. As part of handling a device removal, rpcrdma_dma_unmap_regbuf is invoked on all regbufs for a transport. Simply calling rpcrdma_dma_map_regbuf for each Receive buffer after the driver has been reloaded should reinitialize rg_device correctly for every case except rpcrdma_wc_receive, which still uses rpcrdma_rep::rr_device. Ensure the same device that was used to map a Receive buffer is also used to sync it in rpcrdma_wc_receive by using rg_device there instead of rr_device. This is the only use of rr_device, so it can be removed. The use of regbufs in the send path is also updated, for completeness. Fixes: 54cbd6b ("xprtrdma: Delay DMA mapping Send and ... ") Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent fff0959 commit 91a10c5

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

net/sunrpc/xprtrdma/rpc_rdma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ rpcrdma_prepare_hdr_sge(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
494494
}
495495
sge->length = len;
496496

497-
ib_dma_sync_single_for_device(ia->ri_device, sge->addr,
497+
ib_dma_sync_single_for_device(rdmab_device(rb), sge->addr,
498498
sge->length, DMA_TO_DEVICE);
499499
req->rl_send_wr.num_sge++;
500500
return true;
@@ -523,7 +523,7 @@ rpcrdma_prepare_msg_sges(struct rpcrdma_ia *ia, struct rpcrdma_req *req,
523523
sge[sge_no].addr = rdmab_addr(rb);
524524
sge[sge_no].length = xdr->head[0].iov_len;
525525
sge[sge_no].lkey = rdmab_lkey(rb);
526-
ib_dma_sync_single_for_device(device, sge[sge_no].addr,
526+
ib_dma_sync_single_for_device(rdmab_device(rb), sge[sge_no].addr,
527527
sge[sge_no].length, DMA_TO_DEVICE);
528528

529529
/* If there is a Read chunk, the page list is being handled

net/sunrpc/xprtrdma/verbs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ rpcrdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc)
180180
rep->rr_wc_flags = wc->wc_flags;
181181
rep->rr_inv_rkey = wc->ex.invalidate_rkey;
182182

183-
ib_dma_sync_single_for_cpu(rep->rr_device,
183+
ib_dma_sync_single_for_cpu(rdmab_device(rep->rr_rdmabuf),
184184
rdmab_addr(rep->rr_rdmabuf),
185185
rep->rr_len, DMA_FROM_DEVICE);
186186

@@ -878,7 +878,6 @@ struct rpcrdma_rep *
878878
rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt)
879879
{
880880
struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
881-
struct rpcrdma_ia *ia = &r_xprt->rx_ia;
882881
struct rpcrdma_rep *rep;
883882
int rc;
884883

@@ -894,7 +893,6 @@ rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt)
894893
goto out_free;
895894
}
896895

897-
rep->rr_device = ia->ri_device;
898896
rep->rr_cqe.done = rpcrdma_wc_receive;
899897
rep->rr_rxprt = r_xprt;
900898
INIT_WORK(&rep->rr_work, rpcrdma_reply_handler);
@@ -1232,17 +1230,19 @@ rpcrdma_alloc_regbuf(size_t size, enum dma_data_direction direction,
12321230
bool
12331231
__rpcrdma_dma_map_regbuf(struct rpcrdma_ia *ia, struct rpcrdma_regbuf *rb)
12341232
{
1233+
struct ib_device *device = ia->ri_device;
1234+
12351235
if (rb->rg_direction == DMA_NONE)
12361236
return false;
12371237

1238-
rb->rg_iov.addr = ib_dma_map_single(ia->ri_device,
1238+
rb->rg_iov.addr = ib_dma_map_single(device,
12391239
(void *)rb->rg_base,
12401240
rdmab_length(rb),
12411241
rb->rg_direction);
1242-
if (ib_dma_mapping_error(ia->ri_device, rdmab_addr(rb)))
1242+
if (ib_dma_mapping_error(device, rdmab_addr(rb)))
12431243
return false;
12441244

1245-
rb->rg_device = ia->ri_device;
1245+
rb->rg_device = device;
12461246
rb->rg_iov.lkey = ia->ri_pd->local_dma_lkey;
12471247
return true;
12481248
}

net/sunrpc/xprtrdma/xprt_rdma.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ rdmab_to_msg(struct rpcrdma_regbuf *rb)
164164
return (struct rpcrdma_msg *)rb->rg_base;
165165
}
166166

167+
static inline struct ib_device *
168+
rdmab_device(struct rpcrdma_regbuf *rb)
169+
{
170+
return rb->rg_device;
171+
}
172+
167173
#define RPCRDMA_DEF_GFP (GFP_NOIO | __GFP_NOWARN)
168174

169175
/* To ensure a transport can always make forward progress,
@@ -209,7 +215,6 @@ struct rpcrdma_rep {
209215
unsigned int rr_len;
210216
int rr_wc_flags;
211217
u32 rr_inv_rkey;
212-
struct ib_device *rr_device;
213218
struct rpcrdma_xprt *rr_rxprt;
214219
struct work_struct rr_work;
215220
struct list_head rr_list;

0 commit comments

Comments
 (0)