Skip to content

Commit 03f6fb9

Browse files
Bart Van Asschedledford
authored andcommitted
IB/srp: Create an insecure all physical rkey only if needed
The SRP initiator only needs this if the insecure register_always=N performance optimization is enabled, or if FRWR/FMR is not supported in the driver. Do not create an all physical MR unless it is needed to support either of those modes. Default register_always to true so the out of the box configuration does not create an insecure all physical MR. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> [bvanassche: reworked and rebased this patch] Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 330179f commit 03f6fb9

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

drivers/infiniband/ulp/srp/ib_srp.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static unsigned int srp_sg_tablesize;
6868
static unsigned int cmd_sg_entries;
6969
static unsigned int indirect_sg_entries;
7070
static bool allow_ext_sg;
71-
static bool prefer_fr;
72-
static bool register_always;
71+
static bool prefer_fr = true;
72+
static bool register_always = true;
7373
static int topspin_workarounds = 1;
7474

7575
module_param(srp_sg_tablesize, uint, 0444);
@@ -1353,9 +1353,9 @@ static int srp_finish_mapping(struct srp_map_state *state,
13531353
if (state->npages == 0)
13541354
return 0;
13551355

1356-
if (state->npages == 1 && !register_always)
1356+
if (state->npages == 1 && target->global_mr)
13571357
srp_map_desc(state, state->base_dma_addr, state->dma_len,
1358-
target->rkey);
1358+
target->global_mr->rkey);
13591359
else
13601360
ret = dev->use_fast_reg ? srp_map_finish_fr(state, ch) :
13611361
srp_map_finish_fmr(state, ch);
@@ -1442,7 +1442,8 @@ static int srp_map_sg(struct srp_map_state *state, struct srp_rdma_ch *ch,
14421442
} else {
14431443
for_each_sg(scat, sg, count, i) {
14441444
srp_map_desc(state, ib_sg_dma_address(dev->dev, sg),
1445-
ib_sg_dma_len(dev->dev, sg), target->rkey);
1445+
ib_sg_dma_len(dev->dev, sg),
1446+
target->global_mr->rkey);
14461447
}
14471448
}
14481449

@@ -1531,7 +1532,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch,
15311532
fmt = SRP_DATA_DESC_DIRECT;
15321533
len = sizeof (struct srp_cmd) + sizeof (struct srp_direct_buf);
15331534

1534-
if (count == 1 && !register_always) {
1535+
if (count == 1 && target->global_mr) {
15351536
/*
15361537
* The midlayer only generated a single gather/scatter
15371538
* entry, or DMA mapping coalesced everything to a
@@ -1541,7 +1542,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch,
15411542
struct srp_direct_buf *buf = (void *) cmd->add_data;
15421543

15431544
buf->va = cpu_to_be64(ib_sg_dma_address(ibdev, scat));
1544-
buf->key = cpu_to_be32(target->rkey);
1545+
buf->key = cpu_to_be32(target->global_mr->rkey);
15451546
buf->len = cpu_to_be32(ib_sg_dma_len(ibdev, scat));
15461547

15471548
req->nmdesc = 0;
@@ -1595,14 +1596,14 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch,
15951596
memcpy(indirect_hdr->desc_list, req->indirect_desc,
15961597
count * sizeof (struct srp_direct_buf));
15971598

1598-
if (register_always && (dev->use_fast_reg || dev->use_fmr)) {
1599+
if (!target->global_mr) {
15991600
ret = srp_map_idb(ch, req, state.gen.next, state.gen.end,
16001601
idb_len, &idb_rkey);
16011602
if (ret < 0)
16021603
return ret;
16031604
req->nmdesc++;
16041605
} else {
1605-
idb_rkey = target->rkey;
1606+
idb_rkey = target->global_mr->rkey;
16061607
}
16071608

16081609
indirect_hdr->table_desc.va = cpu_to_be64(req->indirect_dma_addr);
@@ -3157,7 +3158,7 @@ static ssize_t srp_create_target(struct device *dev,
31573158
target->scsi_host = target_host;
31583159
target->srp_host = host;
31593160
target->lkey = host->srp_dev->pd->local_dma_lkey;
3160-
target->rkey = host->srp_dev->mr->rkey;
3161+
target->global_mr = host->srp_dev->global_mr;
31613162
target->cmd_sg_cnt = cmd_sg_entries;
31623163
target->sg_tablesize = indirect_sg_entries ? : cmd_sg_entries;
31633164
target->allow_ext_sg = allow_ext_sg;
@@ -3447,12 +3448,16 @@ static void srp_add_one(struct ib_device *device)
34473448
if (IS_ERR(srp_dev->pd))
34483449
goto free_dev;
34493450

3450-
srp_dev->mr = ib_get_dma_mr(srp_dev->pd,
3451-
IB_ACCESS_LOCAL_WRITE |
3452-
IB_ACCESS_REMOTE_READ |
3453-
IB_ACCESS_REMOTE_WRITE);
3454-
if (IS_ERR(srp_dev->mr))
3455-
goto err_pd;
3451+
if (!register_always || (!srp_dev->has_fmr && !srp_dev->has_fr)) {
3452+
srp_dev->global_mr = ib_get_dma_mr(srp_dev->pd,
3453+
IB_ACCESS_LOCAL_WRITE |
3454+
IB_ACCESS_REMOTE_READ |
3455+
IB_ACCESS_REMOTE_WRITE);
3456+
if (IS_ERR(srp_dev->global_mr))
3457+
goto err_pd;
3458+
} else {
3459+
srp_dev->global_mr = NULL;
3460+
}
34563461

34573462
for (p = rdma_start_port(device); p <= rdma_end_port(device); ++p) {
34583463
host = srp_add_port(srp_dev, p);
@@ -3509,7 +3514,8 @@ static void srp_remove_one(struct ib_device *device, void *client_data)
35093514
kfree(host);
35103515
}
35113516

3512-
ib_dereg_mr(srp_dev->mr);
3517+
if (srp_dev->global_mr)
3518+
ib_dereg_mr(srp_dev->global_mr);
35133519
ib_dealloc_pd(srp_dev->pd);
35143520

35153521
kfree(srp_dev);

drivers/infiniband/ulp/srp/ib_srp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct srp_device {
9595
struct list_head dev_list;
9696
struct ib_device *dev;
9797
struct ib_pd *pd;
98-
struct ib_mr *mr;
98+
struct ib_mr *global_mr;
9999
u64 mr_page_mask;
100100
int mr_page_size;
101101
int mr_max_size;
@@ -183,10 +183,10 @@ struct srp_target_port {
183183
spinlock_t lock;
184184

185185
/* read only in the hot path */
186+
struct ib_mr *global_mr;
186187
struct srp_rdma_ch *ch;
187188
u32 ch_count;
188189
u32 lkey;
189-
u32 rkey;
190190
enum srp_target_state state;
191191
unsigned int max_iu_len;
192192
unsigned int cmd_sg_cnt;

0 commit comments

Comments
 (0)