Skip to content

Commit e6cdd80

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
Pull rdma fixes from Jason Gunthorpe: "Here is the first rc pull request for RDMA. This includes an important core fix for a regression in iWarp if SELinux is enabled, a fix for a compilation regression introduced in this merge window, and one obscure kconfig combination that oops's the kernel. For drivers, we have hns fixes needed to make their devices work on certain ARM IOMMU configurations, a stack data leak for hfi1, and various testing discovered -rc bug fixes for i40iw. This cycle we pushed back on the driver maintainers to have better commit messages for -rc material" * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: IB/core: Only enforce security for InfiniBand RDMA/hns: Get rid of page operation after dma_alloc_coherent RDMA/hns: Get rid of virt_to_page and vmap calls after dma_alloc_coherent RDMA/hns: Fix the issue of IOVA not page continuous in hip08 IB/core: Init subsys if compiled to vmlinuz-core RDMA/cma: Make sure that PSN is not over max allowed i40iw: Notify user of established connection after QP in RTS i40iw: Move MPA request event for loopback after connect i40iw: Correct ARP index mask i40iw: Do not free sqbuf when event is I40IW_TIMER_TYPE_CLOSE i40iw: Allocate a sdbuf per CQP WQE IB: INFINIBAND should depend on HAS_DMA IB/hfi1: Initialize bth1 in 16B rc ack builder
2 parents 6a5e05a + 315d160 commit e6cdd80

File tree

13 files changed

+134
-78
lines changed

13 files changed

+134
-78
lines changed

drivers/infiniband/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
menuconfig INFINIBAND
22
tristate "InfiniBand support"
3-
depends on HAS_IOMEM
3+
depends on HAS_IOMEM && HAS_DMA
44
depends on NET
55
depends on INET
66
depends on m || IPV6 != m

drivers/infiniband/core/cma.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ struct rdma_cm_id *rdma_create_id(struct net *net,
801801
INIT_LIST_HEAD(&id_priv->mc_list);
802802
get_random_bytes(&id_priv->seq_num, sizeof id_priv->seq_num);
803803
id_priv->id.route.addr.dev_addr.net = get_net(net);
804+
id_priv->seq_num &= 0x00ffffff;
804805

805806
return &id_priv->id;
806807
}

drivers/infiniband/core/device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,5 +1253,5 @@ static void __exit ib_core_cleanup(void)
12531253

12541254
MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_LS, 4);
12551255

1256-
module_init(ib_core_init);
1256+
subsys_initcall(ib_core_init);
12571257
module_exit(ib_core_cleanup);

drivers/infiniband/core/security.c

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,17 @@ void ib_close_shared_qp_security(struct ib_qp_security *sec)
417417

418418
int ib_create_qp_security(struct ib_qp *qp, struct ib_device *dev)
419419
{
420+
u8 i = rdma_start_port(dev);
421+
bool is_ib = false;
420422
int ret;
421423

424+
while (i <= rdma_end_port(dev) && !is_ib)
425+
is_ib = rdma_protocol_ib(dev, i++);
426+
427+
/* If this isn't an IB device don't create the security context */
428+
if (!is_ib)
429+
return 0;
430+
422431
qp->qp_sec = kzalloc(sizeof(*qp->qp_sec), GFP_KERNEL);
423432
if (!qp->qp_sec)
424433
return -ENOMEM;
@@ -441,6 +450,10 @@ EXPORT_SYMBOL(ib_create_qp_security);
441450

442451
void ib_destroy_qp_security_begin(struct ib_qp_security *sec)
443452
{
453+
/* Return if not IB */
454+
if (!sec)
455+
return;
456+
444457
mutex_lock(&sec->mutex);
445458

446459
/* Remove the QP from the lists so it won't get added to
@@ -470,6 +483,10 @@ void ib_destroy_qp_security_abort(struct ib_qp_security *sec)
470483
int ret;
471484
int i;
472485

486+
/* Return if not IB */
487+
if (!sec)
488+
return;
489+
473490
/* If a concurrent cache update is in progress this
474491
* QP security could be marked for an error state
475492
* transition. Wait for this to complete.
@@ -505,6 +522,10 @@ void ib_destroy_qp_security_end(struct ib_qp_security *sec)
505522
{
506523
int i;
507524

525+
/* Return if not IB */
526+
if (!sec)
527+
return;
528+
508529
/* If a concurrent cache update is occurring we must
509530
* wait until this QP security structure is processed
510531
* in the QP to error flow before destroying it because
@@ -557,26 +578,35 @@ int ib_security_modify_qp(struct ib_qp *qp,
557578
{
558579
int ret = 0;
559580
struct ib_ports_pkeys *tmp_pps;
560-
struct ib_ports_pkeys *new_pps;
581+
struct ib_ports_pkeys *new_pps = NULL;
561582
struct ib_qp *real_qp = qp->real_qp;
562583
bool special_qp = (real_qp->qp_type == IB_QPT_SMI ||
563584
real_qp->qp_type == IB_QPT_GSI ||
564585
real_qp->qp_type >= IB_QPT_RESERVED1);
565586
bool pps_change = ((qp_attr_mask & (IB_QP_PKEY_INDEX | IB_QP_PORT)) ||
566587
(qp_attr_mask & IB_QP_ALT_PATH));
567588

589+
WARN_ONCE((qp_attr_mask & IB_QP_PORT &&
590+
rdma_protocol_ib(real_qp->device, qp_attr->port_num) &&
591+
!real_qp->qp_sec),
592+
"%s: QP security is not initialized for IB QP: %d\n",
593+
__func__, real_qp->qp_num);
594+
568595
/* The port/pkey settings are maintained only for the real QP. Open
569596
* handles on the real QP will be in the shared_qp_list. When
570597
* enforcing security on the real QP all the shared QPs will be
571598
* checked as well.
572599
*/
573600

574-
if (pps_change && !special_qp) {
601+
if (pps_change && !special_qp && real_qp->qp_sec) {
575602
mutex_lock(&real_qp->qp_sec->mutex);
576603
new_pps = get_new_pps(real_qp,
577604
qp_attr,
578605
qp_attr_mask);
579-
606+
if (!new_pps) {
607+
mutex_unlock(&real_qp->qp_sec->mutex);
608+
return -ENOMEM;
609+
}
580610
/* Add this QP to the lists for the new port
581611
* and pkey settings before checking for permission
582612
* in case there is a concurrent cache update
@@ -600,7 +630,7 @@ int ib_security_modify_qp(struct ib_qp *qp,
600630
qp_attr_mask,
601631
udata);
602632

603-
if (pps_change && !special_qp) {
633+
if (new_pps) {
604634
/* Clean up the lists and free the appropriate
605635
* ports_pkeys structure.
606636
*/
@@ -631,6 +661,9 @@ int ib_security_pkey_access(struct ib_device *dev,
631661
u16 pkey;
632662
int ret;
633663

664+
if (!rdma_protocol_ib(dev, port_num))
665+
return 0;
666+
634667
ret = ib_get_cached_pkey(dev, port_num, pkey_index, &pkey);
635668
if (ret)
636669
return ret;
@@ -665,6 +698,9 @@ int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
665698
{
666699
int ret;
667700

701+
if (!rdma_protocol_ib(agent->device, agent->port_num))
702+
return 0;
703+
668704
ret = security_ib_alloc_security(&agent->security);
669705
if (ret)
670706
return ret;
@@ -690,13 +726,19 @@ int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
690726

691727
void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)
692728
{
729+
if (!rdma_protocol_ib(agent->device, agent->port_num))
730+
return;
731+
693732
security_ib_free_security(agent->security);
694733
if (agent->lsm_nb_reg)
695734
unregister_lsm_notifier(&agent->lsm_nb);
696735
}
697736

698737
int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index)
699738
{
739+
if (!rdma_protocol_ib(map->agent.device, map->agent.port_num))
740+
return 0;
741+
700742
if (map->agent.qp->qp_type == IB_QPT_SMI && !map->agent.smp_allowed)
701743
return -EACCES;
702744

drivers/infiniband/hw/hfi1/rc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ static inline void hfi1_make_rc_ack_16B(struct rvt_qp *qp,
814814
struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
815815
struct hfi1_16b_header *hdr = &opa_hdr->opah;
816816
struct ib_other_headers *ohdr;
817-
u32 bth0, bth1;
817+
u32 bth0, bth1 = 0;
818818
u16 len, pkey;
819819
u8 becn = !!is_fecn;
820820
u8 l4 = OPA_16B_L4_IB_LOCAL;

drivers/infiniband/hw/hns/hns_roce_alloc.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,10 @@ void hns_roce_buf_free(struct hns_roce_dev *hr_dev, u32 size,
162162
{
163163
int i;
164164
struct device *dev = hr_dev->dev;
165-
u32 bits_per_long = BITS_PER_LONG;
166165

167166
if (buf->nbufs == 1) {
168167
dma_free_coherent(dev, size, buf->direct.buf, buf->direct.map);
169168
} else {
170-
if (bits_per_long == 64 && buf->page_shift == PAGE_SHIFT)
171-
vunmap(buf->direct.buf);
172-
173169
for (i = 0; i < buf->nbufs; ++i)
174170
if (buf->page_list[i].buf)
175171
dma_free_coherent(dev, 1 << buf->page_shift,
@@ -185,9 +181,7 @@ int hns_roce_buf_alloc(struct hns_roce_dev *hr_dev, u32 size, u32 max_direct,
185181
{
186182
int i = 0;
187183
dma_addr_t t;
188-
struct page **pages;
189184
struct device *dev = hr_dev->dev;
190-
u32 bits_per_long = BITS_PER_LONG;
191185
u32 page_size = 1 << page_shift;
192186
u32 order;
193187

@@ -236,23 +230,6 @@ int hns_roce_buf_alloc(struct hns_roce_dev *hr_dev, u32 size, u32 max_direct,
236230
buf->page_list[i].map = t;
237231
memset(buf->page_list[i].buf, 0, page_size);
238232
}
239-
if (bits_per_long == 64 && page_shift == PAGE_SHIFT) {
240-
pages = kmalloc_array(buf->nbufs, sizeof(*pages),
241-
GFP_KERNEL);
242-
if (!pages)
243-
goto err_free;
244-
245-
for (i = 0; i < buf->nbufs; ++i)
246-
pages[i] = virt_to_page(buf->page_list[i].buf);
247-
248-
buf->direct.buf = vmap(pages, buf->nbufs, VM_MAP,
249-
PAGE_KERNEL);
250-
kfree(pages);
251-
if (!buf->direct.buf)
252-
goto err_free;
253-
} else {
254-
buf->direct.buf = NULL;
255-
}
256233
}
257234

258235
return 0;

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,9 @@ static inline struct hns_roce_qp
726726

727727
static inline void *hns_roce_buf_offset(struct hns_roce_buf *buf, int offset)
728728
{
729-
u32 bits_per_long_val = BITS_PER_LONG;
730729
u32 page_size = 1 << buf->page_shift;
731730

732-
if ((bits_per_long_val == 64 && buf->page_shift == PAGE_SHIFT) ||
733-
buf->nbufs == 1)
731+
if (buf->nbufs == 1)
734732
return (char *)(buf->direct.buf) + offset;
735733
else
736734
return (char *)(buf->page_list[offset >> buf->page_shift].buf) +

drivers/infiniband/hw/hns/hns_roce_hem.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ static struct hns_roce_hem *hns_roce_alloc_hem(struct hns_roce_dev *hr_dev,
224224
sg_init_table(chunk->mem, HNS_ROCE_HEM_CHUNK_LEN);
225225
chunk->npages = 0;
226226
chunk->nsg = 0;
227+
memset(chunk->buf, 0, sizeof(chunk->buf));
227228
list_add_tail(&chunk->list, &hem->chunk_list);
228229
}
229230

@@ -240,8 +241,7 @@ static struct hns_roce_hem *hns_roce_alloc_hem(struct hns_roce_dev *hr_dev,
240241
if (!buf)
241242
goto fail;
242243

243-
sg_set_buf(mem, buf, PAGE_SIZE << order);
244-
WARN_ON(mem->offset);
244+
chunk->buf[chunk->npages] = buf;
245245
sg_dma_len(mem) = PAGE_SIZE << order;
246246

247247
++chunk->npages;
@@ -267,8 +267,8 @@ void hns_roce_free_hem(struct hns_roce_dev *hr_dev, struct hns_roce_hem *hem)
267267
list_for_each_entry_safe(chunk, tmp, &hem->chunk_list, list) {
268268
for (i = 0; i < chunk->npages; ++i)
269269
dma_free_coherent(hr_dev->dev,
270-
chunk->mem[i].length,
271-
lowmem_page_address(sg_page(&chunk->mem[i])),
270+
sg_dma_len(&chunk->mem[i]),
271+
chunk->buf[i],
272272
sg_dma_address(&chunk->mem[i]));
273273
kfree(chunk);
274274
}
@@ -722,11 +722,12 @@ void *hns_roce_table_find(struct hns_roce_dev *hr_dev,
722722
struct hns_roce_hem_chunk *chunk;
723723
struct hns_roce_hem_mhop mhop;
724724
struct hns_roce_hem *hem;
725-
struct page *page = NULL;
725+
void *addr = NULL;
726726
unsigned long mhop_obj = obj;
727727
unsigned long obj_per_chunk;
728728
unsigned long idx_offset;
729729
int offset, dma_offset;
730+
int length;
730731
int i, j;
731732
u32 hem_idx = 0;
732733

@@ -763,25 +764,25 @@ void *hns_roce_table_find(struct hns_roce_dev *hr_dev,
763764

764765
list_for_each_entry(chunk, &hem->chunk_list, list) {
765766
for (i = 0; i < chunk->npages; ++i) {
767+
length = sg_dma_len(&chunk->mem[i]);
766768
if (dma_handle && dma_offset >= 0) {
767-
if (sg_dma_len(&chunk->mem[i]) >
768-
(u32)dma_offset)
769+
if (length > (u32)dma_offset)
769770
*dma_handle = sg_dma_address(
770771
&chunk->mem[i]) + dma_offset;
771-
dma_offset -= sg_dma_len(&chunk->mem[i]);
772+
dma_offset -= length;
772773
}
773774

774-
if (chunk->mem[i].length > (u32)offset) {
775-
page = sg_page(&chunk->mem[i]);
775+
if (length > (u32)offset) {
776+
addr = chunk->buf[i] + offset;
776777
goto out;
777778
}
778-
offset -= chunk->mem[i].length;
779+
offset -= length;
779780
}
780781
}
781782

782783
out:
783784
mutex_unlock(&table->mutex);
784-
return page ? lowmem_page_address(page) + offset : NULL;
785+
return addr;
785786
}
786787
EXPORT_SYMBOL_GPL(hns_roce_table_find);
787788

drivers/infiniband/hw/hns/hns_roce_hem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct hns_roce_hem_chunk {
7878
int npages;
7979
int nsg;
8080
struct scatterlist mem[HNS_ROCE_HEM_CHUNK_LEN];
81+
void *buf[HNS_ROCE_HEM_CHUNK_LEN];
8182
};
8283

8384
struct hns_roce_hem {

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,11 @@ static int hns_roce_v2_write_mtpt(void *mb_buf, struct hns_roce_mr *mr,
11261126
{
11271127
struct hns_roce_v2_mpt_entry *mpt_entry;
11281128
struct scatterlist *sg;
1129+
u64 page_addr;
11291130
u64 *pages;
1131+
int i, j;
1132+
int len;
11301133
int entry;
1131-
int i;
11321134

11331135
mpt_entry = mb_buf;
11341136
memset(mpt_entry, 0, sizeof(*mpt_entry));
@@ -1186,14 +1188,20 @@ static int hns_roce_v2_write_mtpt(void *mb_buf, struct hns_roce_mr *mr,
11861188

11871189
i = 0;
11881190
for_each_sg(mr->umem->sg_head.sgl, sg, mr->umem->nmap, entry) {
1189-
pages[i] = ((u64)sg_dma_address(sg)) >> 6;
1190-
1191-
/* Record the first 2 entry directly to MTPT table */
1192-
if (i >= HNS_ROCE_V2_MAX_INNER_MTPT_NUM - 1)
1193-
break;
1194-
i++;
1191+
len = sg_dma_len(sg) >> PAGE_SHIFT;
1192+
for (j = 0; j < len; ++j) {
1193+
page_addr = sg_dma_address(sg) +
1194+
(j << mr->umem->page_shift);
1195+
pages[i] = page_addr >> 6;
1196+
1197+
/* Record the first 2 entry directly to MTPT table */
1198+
if (i >= HNS_ROCE_V2_MAX_INNER_MTPT_NUM - 1)
1199+
goto found;
1200+
i++;
1201+
}
11951202
}
11961203

1204+
found:
11971205
mpt_entry->pa0_l = cpu_to_le32(lower_32_bits(pages[0]));
11981206
roce_set_field(mpt_entry->byte_56_pa0_h, V2_MPT_BYTE_56_PA0_H_M,
11991207
V2_MPT_BYTE_56_PA0_H_S,

0 commit comments

Comments
 (0)