Skip to content

Commit 71d3bda

Browse files
jakemoronirleon
authored andcommitted
RDMA/irdma: Do not directly rely on IB_PD_UNSAFE_GLOBAL_RKEY
The HW disables bounds checking for MRs with a length of zero, so the driver will only allow a zero length MR if the "all_memory" flag is set, and this flag is only set if IB_PD_UNSAFE_GLOBAL_RKEY is set for the PD. This means that the "get_dma_mr" method will currently fail unless the IB_PD_UNSAFE_GLOBAL_RKEY flag is set. This has not been an issue because the "get_dma_mr" method is only ever invoked if the device does not support the local DMA key or if IB_PD_UNSAFE_GLOBAL_RKEY is set, and so far, all IRDMA HW supports the local DMA lkey. However, some new HW does not support the local DMA lkey, so the "get_dma_mr" method needs to work without IB_PD_UNSAFE_GLOBAL_RKEY being set. To support HW that does not allow the local DMA lkey, the logic has been changed to pass an explicit flag to indicate when a dma_mr is being created so that the zero length will be allowed. Also, the "all_memory" flag has been forced to false for normal MR allocation since these MRs are never supposed to provide global unsafe rkey semantics anyway; only the MR created with "get_dma_mr" should support this. Fixes: bb6d73d ("RDMA/irdma: Prevent zero-length STAG registration") Signed-off-by: Jacob Moroni <jmoroni@google.com> Signed-off-by: Tatyana Nikolova <tatyana.e.nikolova@intel.com> Link: https://patch.msgid.link/20251125025350.180-7-tatyana.e.nikolova@intel.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 35bd787 commit 71d3bda

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

drivers/infiniband/hw/irdma/cm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,7 @@ int irdma_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37103710
iwpd = iwqp->iwpd;
37113711
tagged_offset = (uintptr_t)iwqp->ietf_mem.va;
37123712
ibmr = irdma_reg_phys_mr(&iwpd->ibpd, iwqp->ietf_mem.pa, buf_len,
3713-
IB_ACCESS_LOCAL_WRITE, &tagged_offset);
3713+
IB_ACCESS_LOCAL_WRITE, &tagged_offset, false);
37143714
if (IS_ERR(ibmr)) {
37153715
ret = -ENOMEM;
37163716
goto error;

drivers/infiniband/hw/irdma/main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ void irdma_copy_ip_htonl(__be32 *dst, u32 *src);
556556
u16 irdma_get_vlan_ipv4(u32 *addr);
557557
void irdma_get_vlan_mac_ipv6(u32 *addr, u16 *vlan_id, u8 *mac);
558558
struct ib_mr *irdma_reg_phys_mr(struct ib_pd *ib_pd, u64 addr, u64 size,
559-
int acc, u64 *iova_start);
559+
int acc, u64 *iova_start, bool dma_mr);
560560
int irdma_upload_qp_context(struct irdma_qp *iwqp, bool freeze, bool raw);
561561
void irdma_cqp_ce_handler(struct irdma_pci_f *rf, struct irdma_sc_cq *cq);
562562
int irdma_ah_cqp_op(struct irdma_pci_f *rf, struct irdma_sc_ah *sc_ah, u8 cmd,

drivers/infiniband/hw/irdma/verbs.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,6 @@ static int irdma_hw_alloc_stag(struct irdma_device *iwdev,
31163116
info->stag_idx = iwmr->stag >> IRDMA_CQPSQ_STAG_IDX_S;
31173117
info->pd_id = iwpd->sc_pd.pd_id;
31183118
info->total_len = iwmr->len;
3119-
info->all_memory = pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY;
31203119
info->remote_access = true;
31213120
cqp_info->cqp_cmd = IRDMA_OP_ALLOC_STAG;
31223121
cqp_info->post_sq = 1;
@@ -3127,7 +3126,7 @@ static int irdma_hw_alloc_stag(struct irdma_device *iwdev,
31273126
if (status)
31283127
return status;
31293128

3130-
iwmr->is_hwreg = 1;
3129+
iwmr->is_hwreg = true;
31313130
return 0;
31323131
}
31333132

@@ -3270,7 +3269,7 @@ static int irdma_hwreg_mr(struct irdma_device *iwdev, struct irdma_mr *iwmr,
32703269
if (iwdev->rf->sc_dev.hw_attrs.uk_attrs.feature_flags & IRDMA_FEATURE_ATOMIC_OPS)
32713270
stag_info->remote_atomics_en = (access & IB_ACCESS_REMOTE_ATOMIC) ? 1 : 0;
32723271
stag_info->pd_id = iwpd->sc_pd.pd_id;
3273-
stag_info->all_memory = pd->flags & IB_PD_UNSAFE_GLOBAL_RKEY;
3272+
stag_info->all_memory = iwmr->dma_mr;
32743273
if (stag_info->access_rights & IRDMA_ACCESS_FLAGS_ZERO_BASED)
32753274
stag_info->addr_type = IRDMA_ADDR_TYPE_ZERO_BASED;
32763275
else
@@ -3297,7 +3296,7 @@ static int irdma_hwreg_mr(struct irdma_device *iwdev, struct irdma_mr *iwmr,
32973296
irdma_put_cqp_request(&iwdev->rf->cqp, cqp_request);
32983297

32993298
if (!ret)
3300-
iwmr->is_hwreg = 1;
3299+
iwmr->is_hwreg = true;
33013300

33023301
return ret;
33033302
}
@@ -3669,7 +3668,7 @@ static int irdma_hwdereg_mr(struct ib_mr *ib_mr)
36693668
if (status)
36703669
return status;
36713670

3672-
iwmr->is_hwreg = 0;
3671+
iwmr->is_hwreg = false;
36733672
return 0;
36743673
}
36753674

@@ -3792,9 +3791,10 @@ static struct ib_mr *irdma_rereg_user_mr(struct ib_mr *ib_mr, int flags,
37923791
* @size: size of memory to register
37933792
* @access: Access rights
37943793
* @iova_start: start of virtual address for physical buffers
3794+
* @dma_mr: Flag indicating whether this region is a PD DMA MR
37953795
*/
37963796
struct ib_mr *irdma_reg_phys_mr(struct ib_pd *pd, u64 addr, u64 size, int access,
3797-
u64 *iova_start)
3797+
u64 *iova_start, bool dma_mr)
37983798
{
37993799
struct irdma_device *iwdev = to_iwdev(pd->device);
38003800
struct irdma_pbl *iwpbl;
@@ -3811,6 +3811,7 @@ struct ib_mr *irdma_reg_phys_mr(struct ib_pd *pd, u64 addr, u64 size, int access
38113811
iwpbl = &iwmr->iwpbl;
38123812
iwpbl->iwmr = iwmr;
38133813
iwmr->type = IRDMA_MEMREG_TYPE_MEM;
3814+
iwmr->dma_mr = dma_mr;
38143815
iwpbl->user_base = *iova_start;
38153816
stag = irdma_create_stag(iwdev);
38163817
if (!stag) {
@@ -3849,7 +3850,7 @@ static struct ib_mr *irdma_get_dma_mr(struct ib_pd *pd, int acc)
38493850
{
38503851
u64 kva = 0;
38513852

3852-
return irdma_reg_phys_mr(pd, 0, 0, acc, &kva);
3853+
return irdma_reg_phys_mr(pd, 0, 0, acc, &kva, true);
38533854
}
38543855

38553856
/**

drivers/infiniband/hw/irdma/verbs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ struct irdma_mr {
111111
};
112112
struct ib_umem *region;
113113
int access;
114-
u8 is_hwreg;
114+
bool is_hwreg:1;
115+
bool dma_mr:1;
115116
u16 type;
116117
u32 page_cnt;
117118
u64 page_size;

0 commit comments

Comments
 (0)