Skip to content

Commit

Permalink
Merge branch '32compat'
Browse files Browse the repository at this point in the history
The design of the uAPI had intended all structs to share the same layout on 32
and 64 bit compiles. Unfortunately over the years some errors have crept in.

This series fixes all the incompatabilities. It goes along with a userspace
rdma-core series that causes the providers to use these structs directly and
then does various self-checks on the command formation.

Those checks were combined with output from pahole on 32 and 64 bit compiles
to confirm that the structure layouts are the same.

This series does not make implicit padding explicit, as long as the implicit
padding is the same on 32 and 64 bit compiles.

Finally, the issue is put to rest by using __aligned_u64 in the uapi headers,
if new code copies that type, and is checked in userspace, it is unlikely we
will see problems in future.

There are two patches that break the ABI for a 32 bit kernel, one for rxe and
one for mlx4. Both patches have notes, but the overall feeling from Doug and I
is that providing compat is just too difficult and not necessary since there
is no real user of a 32 bit userspace and 32 bit kernel for various good
reasons.

The 32 bit userspace / 64 bit kernel case however does seem to have some real
users and does need to work as designed.

* 32compat:
  RDMA: Change all uapi headers to use __aligned_u64 instead of __u64
  RDMA/rxe: Fix uABI structure layouts for 32/64 compat
  RDMA/mlx4: Fix uABI structure layouts for 32/64 compat
  RDMA/qedr: Fix uABI structure layouts for 32/64 compat
  RDMA/ucma: Fix uABI structure layouts for 32/64 compat
  RDMA: Remove minor pahole differences between 32/64
  • Loading branch information
jgunthorpe committed Mar 27, 2018
2 parents f64705b + 26b9906 commit 819b602
Show file tree
Hide file tree
Showing 21 changed files with 310 additions and 280 deletions.
9 changes: 7 additions & 2 deletions drivers/infiniband/core/ucma.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
struct ucma_event *uevent;
int ret = 0;

if (out_len < sizeof uevent->resp)
/*
* Old 32 bit user space does not send the 4 byte padding in the
* reserved field. We don't care, allow it to keep working.
*/
if (out_len < sizeof(uevent->resp) - sizeof(uevent->resp.reserved))
return -ENOSPC;

if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
Expand Down Expand Up @@ -417,7 +421,8 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
}

if (copy_to_user((void __user *)(unsigned long)cmd.response,
&uevent->resp, sizeof uevent->resp)) {
&uevent->resp,
min_t(size_t, out_len, sizeof(uevent->resp)))) {
ret = -EFAULT;
goto done;
}
Expand Down
6 changes: 5 additions & 1 deletion drivers/infiniband/sw/rxe/rxe.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
#include "rxe_verbs.h"
#include "rxe_loc.h"

#define RXE_UVERBS_ABI_VERSION (1)
/*
* Version 1 and Version 2 are identical on 64 bit machines, but on 32 bit
* machines Version 2 has a different struct layout.
*/
#define RXE_UVERBS_ABI_VERSION 2

#define IB_PHYS_STATE_LINK_UP (5)
#define IB_PHYS_STATE_LINK_DOWN (3)
Expand Down
14 changes: 7 additions & 7 deletions include/uapi/rdma/bnxt_re-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ struct bnxt_re_pd_resp {
} __attribute__((packed, aligned(4)));

struct bnxt_re_cq_req {
__u64 cq_va;
__u64 cq_handle;
__aligned_u64 cq_va;
__aligned_u64 cq_handle;
};

struct bnxt_re_cq_resp {
Expand All @@ -77,9 +77,9 @@ struct bnxt_re_cq_resp {
};

struct bnxt_re_qp_req {
__u64 qpsva;
__u64 qprva;
__u64 qp_handle;
__aligned_u64 qpsva;
__aligned_u64 qprva;
__aligned_u64 qp_handle;
};

struct bnxt_re_qp_resp {
Expand All @@ -88,8 +88,8 @@ struct bnxt_re_qp_resp {
};

struct bnxt_re_srq_req {
__u64 srqva;
__u64 srq_handle;
__aligned_u64 srqva;
__aligned_u64 srq_handle;
};

struct bnxt_re_srq_resp {
Expand Down
12 changes: 6 additions & 6 deletions include/uapi/rdma/cxgb3-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@
* Make sure that all structs defined in this file remain laid out so
* that they pack the same way on 32-bit and 64-bit architectures (to
* avoid incompatibility between 32-bit userspace and 64-bit kernels).
* In particular do not use pointer types -- pass pointers in __u64
* In particular do not use pointer types -- pass pointers in __aligned_u64
* instead.
*/
struct iwch_create_cq_req {
__u64 user_rptr_addr;
__aligned_u64 user_rptr_addr;
};

struct iwch_create_cq_resp_v0 {
__u64 key;
__aligned_u64 key;
__u32 cqid;
__u32 size_log2;
};

struct iwch_create_cq_resp {
__u64 key;
__aligned_u64 key;
__u32 cqid;
__u32 size_log2;
__u32 memsize;
__u32 reserved;
};

struct iwch_create_qp_resp {
__u64 key;
__u64 db_key;
__aligned_u64 key;
__aligned_u64 db_key;
__u32 qpid;
__u32 size_log2;
__u32 sq_size_log2;
Expand Down
24 changes: 12 additions & 12 deletions include/uapi/rdma/cxgb4-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
* Make sure that all structs defined in this file remain laid out so
* that they pack the same way on 32-bit and 64-bit architectures (to
* avoid incompatibility between 32-bit userspace and 64-bit kernels).
* In particular do not use pointer types -- pass pointers in __u64
* In particular do not use pointer types -- pass pointers in __aligned_u64
* instead.
*/
struct c4iw_create_cq_resp {
__u64 key;
__u64 gts_key;
__u64 memsize;
__aligned_u64 key;
__aligned_u64 gts_key;
__aligned_u64 memsize;
__u32 cqid;
__u32 size;
__u32 qid_mask;
Expand All @@ -59,13 +59,13 @@ enum {
};

struct c4iw_create_qp_resp {
__u64 ma_sync_key;
__u64 sq_key;
__u64 rq_key;
__u64 sq_db_gts_key;
__u64 rq_db_gts_key;
__u64 sq_memsize;
__u64 rq_memsize;
__aligned_u64 ma_sync_key;
__aligned_u64 sq_key;
__aligned_u64 rq_key;
__aligned_u64 sq_db_gts_key;
__aligned_u64 rq_db_gts_key;
__aligned_u64 sq_memsize;
__aligned_u64 rq_memsize;
__u32 sqid;
__u32 rqid;
__u32 sq_size;
Expand All @@ -75,7 +75,7 @@ struct c4iw_create_qp_resp {
};

struct c4iw_alloc_ucontext_resp {
__u64 status_page_key;
__aligned_u64 status_page_key;
__u32 status_page_size;
__u32 reserved; /* explicit padding (optional for i386) */
};
Expand Down
32 changes: 16 additions & 16 deletions include/uapi/rdma/hfi/hfi1_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct hfi1_user_info {
};

struct hfi1_ctxt_info {
__u64 runtime_flags; /* chip/drv runtime flags (HFI1_CAP_*) */
__aligned_u64 runtime_flags; /* chip/drv runtime flags (HFI1_CAP_*) */
__u32 rcvegr_size; /* size of each eager buffer */
__u16 num_active; /* number of active units */
__u16 unit; /* unit (chip) assigned to caller */
Expand All @@ -98,9 +98,9 @@ struct hfi1_ctxt_info {

struct hfi1_tid_info {
/* virtual address of first page in transfer */
__u64 vaddr;
__aligned_u64 vaddr;
/* pointer to tid array. this array is big enough */
__u64 tidlist;
__aligned_u64 tidlist;
/* number of tids programmed by this request */
__u32 tidcnt;
/* length of transfer buffer programmed by this request */
Expand Down Expand Up @@ -131,44 +131,44 @@ struct hfi1_base_info {
*/
__u32 bthqp;
/* PIO credit return address, */
__u64 sc_credits_addr;
__aligned_u64 sc_credits_addr;
/*
* Base address of write-only pio buffers for this process.
* Each buffer has sendpio_credits*64 bytes.
*/
__u64 pio_bufbase_sop;
__aligned_u64 pio_bufbase_sop;
/*
* Base address of write-only pio buffers for this process.
* Each buffer has sendpio_credits*64 bytes.
*/
__u64 pio_bufbase;
__aligned_u64 pio_bufbase;
/* address where receive buffer queue is mapped into */
__u64 rcvhdr_bufbase;
__aligned_u64 rcvhdr_bufbase;
/* base address of Eager receive buffers. */
__u64 rcvegr_bufbase;
__aligned_u64 rcvegr_bufbase;
/* base address of SDMA completion ring */
__u64 sdma_comp_bufbase;
__aligned_u64 sdma_comp_bufbase;
/*
* User register base for init code, not to be used directly by
* protocol or applications. Always maps real chip register space.
* the register addresses are:
* ur_rcvhdrhead, ur_rcvhdrtail, ur_rcvegrhead, ur_rcvegrtail,
* ur_rcvtidflow
*/
__u64 user_regbase;
__aligned_u64 user_regbase;
/* notification events */
__u64 events_bufbase;
__aligned_u64 events_bufbase;
/* status page */
__u64 status_bufbase;
__aligned_u64 status_bufbase;
/* rcvhdrtail update */
__u64 rcvhdrtail_base;
__aligned_u64 rcvhdrtail_base;
/*
* shared memory pages for subctxts if ctxt is shared; these cover
* all the processes in the group sharing a single context.
* all have enough space for the num_subcontexts value on this job.
*/
__u64 subctxt_uregbase;
__u64 subctxt_rcvegrbuf;
__u64 subctxt_rcvhdrbuf;
__aligned_u64 subctxt_uregbase;
__aligned_u64 subctxt_rcvegrbuf;
__aligned_u64 subctxt_rcvhdrbuf;
};
#endif /* _LINIUX__HFI1_IOCTL_H */
4 changes: 2 additions & 2 deletions include/uapi/rdma/hfi/hfi1_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ struct hfi1_sdma_comp_entry {
* Device status and notifications from driver to user-space.
*/
struct hfi1_status {
__u64 dev; /* device/hw status bits */
__u64 port; /* port state and status bits */
__aligned_u64 dev; /* device/hw status bits */
__aligned_u64 port; /* port state and status bits */
char freezemsg[0];
};

Expand Down
14 changes: 7 additions & 7 deletions include/uapi/rdma/hns-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@
#include <linux/types.h>

struct hns_roce_ib_create_cq {
__u64 buf_addr;
__u64 db_addr;
__aligned_u64 buf_addr;
__aligned_u64 db_addr;
};

struct hns_roce_ib_create_cq_resp {
__u64 cqn; /* Only 32 bits used, 64 for compat */
__u64 cap_flags;
__aligned_u64 cqn; /* Only 32 bits used, 64 for compat */
__aligned_u64 cap_flags;
};

struct hns_roce_ib_create_qp {
__u64 buf_addr;
__u64 db_addr;
__aligned_u64 buf_addr;
__aligned_u64 db_addr;
__u8 log_sq_bb_count;
__u8 log_sq_stride;
__u8 sq_no_prefetch;
__u8 reserved[5];
};

struct hns_roce_ib_create_qp_resp {
__u64 cap_flags;
__aligned_u64 cap_flags;
};

struct hns_roce_ib_alloc_ucontext_resp {
Expand Down
12 changes: 6 additions & 6 deletions include/uapi/rdma/i40iw-abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ struct i40iw_alloc_pd_resp {
};

struct i40iw_create_cq_req {
__u64 user_cq_buffer;
__u64 user_shadow_area;
__aligned_u64 user_cq_buffer;
__aligned_u64 user_shadow_area;
};

struct i40iw_create_qp_req {
__u64 user_wqe_buffers;
__u64 user_compl_ctx;
__aligned_u64 user_wqe_buffers;
__aligned_u64 user_compl_ctx;

/* UDA QP PHB */
__u64 user_sq_phb; /* place for VA of the sq phb buff */
__u64 user_rq_phb; /* place for VA of the rq phb buff */
__aligned_u64 user_sq_phb; /* place for VA of the sq phb buff */
__aligned_u64 user_rq_phb; /* place for VA of the rq phb buff */
};

enum i40iw_memreg_type {
Expand Down
Loading

0 comments on commit 819b602

Please sign in to comment.