Skip to content

Commit f10ff38

Browse files
committed
RDMA/rvt: Do not use a kernel header in the ABI
rvt was using ib_sge as part of it's ABI, which is not allowed. Introduce a new struct with the same layout and use it instead. Fixes: dabac6e ("IB/hfi1: Move receive work queue struct into uapi directory") Reported-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 4c7d6dc commit f10ff38

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

‎drivers/infiniband/sw/rdmavt/qp.c‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,8 +1847,11 @@ int rvt_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
18471847
wqe = rvt_get_rwqe_ptr(&qp->r_rq, wq->head);
18481848
wqe->wr_id = wr->wr_id;
18491849
wqe->num_sge = wr->num_sge;
1850-
for (i = 0; i < wr->num_sge; i++)
1851-
wqe->sg_list[i] = wr->sg_list[i];
1850+
for (i = 0; i < wr->num_sge; i++) {
1851+
wqe->sg_list[i].addr = wr->sg_list[i].addr;
1852+
wqe->sg_list[i].length = wr->sg_list[i].length;
1853+
wqe->sg_list[i].lkey = wr->sg_list[i].lkey;
1854+
}
18521855
/*
18531856
* Make sure queue entry is written
18541857
* before the head index.
@@ -2250,15 +2253,34 @@ int rvt_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
22502253
wqe = rvt_get_rwqe_ptr(&srq->rq, wq->head);
22512254
wqe->wr_id = wr->wr_id;
22522255
wqe->num_sge = wr->num_sge;
2253-
for (i = 0; i < wr->num_sge; i++)
2254-
wqe->sg_list[i] = wr->sg_list[i];
2256+
for (i = 0; i < wr->num_sge; i++) {
2257+
wqe->sg_list[i].addr = wr->sg_list[i].addr;
2258+
wqe->sg_list[i].length = wr->sg_list[i].length;
2259+
wqe->sg_list[i].lkey = wr->sg_list[i].lkey;
2260+
}
22552261
/* Make sure queue entry is written before the head index. */
22562262
smp_store_release(&wq->head, next);
22572263
spin_unlock_irqrestore(&srq->rq.kwq->p_lock, flags);
22582264
}
22592265
return 0;
22602266
}
22612267

2268+
/*
2269+
* rvt used the internal kernel struct as part of its ABI, for now make sure
2270+
* the kernel struct does not change layout. FIXME: rvt should never cast the
2271+
* user struct to a kernel struct.
2272+
*/
2273+
static struct ib_sge *rvt_cast_sge(struct rvt_wqe_sge *sge)
2274+
{
2275+
BUILD_BUG_ON(offsetof(struct ib_sge, addr) !=
2276+
offsetof(struct rvt_wqe_sge, addr));
2277+
BUILD_BUG_ON(offsetof(struct ib_sge, length) !=
2278+
offsetof(struct rvt_wqe_sge, length));
2279+
BUILD_BUG_ON(offsetof(struct ib_sge, lkey) !=
2280+
offsetof(struct rvt_wqe_sge, lkey));
2281+
return (struct ib_sge *)sge;
2282+
}
2283+
22622284
/*
22632285
* Validate a RWQE and fill in the SGE state.
22642286
* Return 1 if OK.
@@ -2282,7 +2304,7 @@ static int init_sge(struct rvt_qp *qp, struct rvt_rwqe *wqe)
22822304
continue;
22832305
/* Check LKEY */
22842306
ret = rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge,
2285-
NULL, &wqe->sg_list[i],
2307+
NULL, rvt_cast_sge(&wqe->sg_list[i]),
22862308
IB_ACCESS_LOCAL_WRITE);
22872309
if (unlikely(ret <= 0))
22882310
goto bad_lkey;

‎include/uapi/rdma/rvt-abi.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010

1111
#include <linux/types.h>
1212
#include <rdma/ib_user_verbs.h>
13-
#include <rdma/ib_verbs.h>
1413
#ifndef RDMA_ATOMIC_UAPI
1514
#define RDMA_ATOMIC_UAPI(_type, _name) struct{ _type val; } _name
1615
#endif
1716

17+
struct rvt_wqe_sge {
18+
__aligned_u64 addr;
19+
__u32 length;
20+
__u32 lkey;
21+
};
22+
1823
/*
1924
* This structure is used to contain the head pointer, tail pointer,
2025
* and completion queue entries as a single memory allocation so
@@ -39,7 +44,7 @@ struct rvt_rwqe {
3944
__u64 wr_id;
4045
__u8 num_sge;
4146
__u8 padding[7];
42-
struct ib_sge sg_list[];
47+
struct rvt_wqe_sge sg_list[];
4348
};
4449

4550
/*

0 commit comments

Comments
 (0)