[RFC PATCH v2 5/5] RDMA: Avoid compile-time PAGE_SIZE in FRMR pools, IPoIB and uverbs
From: Eric Curtin
Date: Tue Dec 01 2026 - 22:25:17 EST
From: Eric Curtin <eric.curtin@xxxxxxxxxx>
With arm64 boot-time page size selection PAGE_SIZE is not a
compile-time constant. Enum values, array sizes and BUILD_BUG_ON() need
one.
FRMR pools: make handles[] in struct frmr_handles_page a flexible array
and allocate a full PAGE_SIZE for each page structure, so that
NUM_HANDLES_PER_PAGE is evaluated at run time.
IPoIB: IPOIB_CM_HEAD_SIZE and IPOIB_CM_RX_SG move out of the enum into
macros. Add IPOIB_CM_RX_SG_MAX and IPOIB_CM_HEAD_SIZE_MIN, based on
PAGE_SIZE_MIN, and use the former for the mapping and rx_sge arrays and
the matching function arguments, and the latter in the copybreak
BUILD_BUG_ON().
uverbs: use PAGE_SIZE_MIN in the attribute length BUILD_BUG_ON_ZERO()
in include/rdma/uverbs_ioctl.h.
No functional change for compile-time page sizes.
Signed-off-by: Eric Curtin <eric.curtin@xxxxxxxxxx>
---
drivers/infiniband/core/frmr_pools.c | 2 +-
drivers/infiniband/core/frmr_pools.h | 2 +-
drivers/infiniband/ulp/ipoib/ipoib.h | 13 +++++++++----
drivers/infiniband/ulp/ipoib/ipoib_cm.c | 8 ++++----
drivers/infiniband/ulp/ipoib/ipoib_main.c | 2 +-
include/rdma/uverbs_ioctl.h | 2 +-
6 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/drivers/infiniband/core/frmr_pools.c b/drivers/infiniband/core/frmr_pools.c
index 4af36dc8cf38..8412a1693318 100644
--- a/drivers/infiniband/core/frmr_pools.c
+++ b/drivers/infiniband/core/frmr_pools.c
@@ -20,7 +20,7 @@ static int push_handle_to_queue_locked(struct frmr_queue *queue, u32 handle)
struct frmr_handles_page *page;
if (queue->ci >= queue->num_pages * NUM_HANDLES_PER_PAGE) {
- page = kzalloc_obj(*page, GFP_ATOMIC);
+ page = kzalloc(PAGE_SIZE, GFP_ATOMIC);
if (!page)
return -ENOMEM;
queue->num_pages++;
diff --git a/drivers/infiniband/core/frmr_pools.h b/drivers/infiniband/core/frmr_pools.h
index 67e1402169ae..b714ecaa4816 100644
--- a/drivers/infiniband/core/frmr_pools.h
+++ b/drivers/infiniband/core/frmr_pools.h
@@ -18,7 +18,7 @@
struct frmr_handles_page {
struct list_head list;
- u32 handles[NUM_HANDLES_PER_PAGE];
+ u32 handles[];
};
/* FRMR queue holds a list of frmr_handles_page.
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 143e03b64902..34a19e96d0a0 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -70,8 +70,6 @@ enum {
IPOIB_CM_MTU = 0x10000 - 0x10, /* padding to align header to 16 */
IPOIB_CM_BUF_SIZE = IPOIB_CM_MTU + IPOIB_ENCAP_LEN,
- IPOIB_CM_HEAD_SIZE = IPOIB_CM_BUF_SIZE % PAGE_SIZE,
- IPOIB_CM_RX_SG = ALIGN(IPOIB_CM_BUF_SIZE, PAGE_SIZE) / PAGE_SIZE,
IPOIB_RX_RING_SIZE = 256,
IPOIB_TX_RING_SIZE = 128,
IPOIB_MAX_QUEUE_SIZE = 8192,
@@ -118,6 +116,13 @@ enum {
IPOIB_RTNL_CHILD = 2,
};
+#define IPOIB_CM_HEAD_SIZE ((int)(IPOIB_CM_BUF_SIZE % PAGE_SIZE))
+#define IPOIB_CM_HEAD_SIZE_MIN ((int)(IPOIB_CM_BUF_SIZE % PAGE_SIZE_MIN))
+#define IPOIB_CM_RX_SG \
+ ((unsigned int)(ALIGN(IPOIB_CM_BUF_SIZE, PAGE_SIZE) / PAGE_SIZE))
+#define IPOIB_CM_RX_SG_MAX \
+ ((int)(ALIGN(IPOIB_CM_BUF_SIZE, PAGE_SIZE_MIN) / PAGE_SIZE_MIN))
+
#define IPOIB_OP_RECV (1ul << 31)
#ifdef CONFIG_INFINIBAND_IPOIB_CM
#define IPOIB_OP_CM (1ul << 30)
@@ -259,7 +264,7 @@ struct ipoib_cm_tx {
struct ipoib_cm_rx_buf {
struct sk_buff *skb;
- u64 mapping[IPOIB_CM_RX_SG];
+ u64 mapping[IPOIB_CM_RX_SG_MAX];
};
struct ipoib_cm_dev_priv {
@@ -280,7 +285,7 @@ struct ipoib_cm_dev_priv {
struct list_head start_list;
struct list_head reap_list;
struct ib_wc ibwc[IPOIB_NUM_WC];
- struct ib_sge rx_sge[IPOIB_CM_RX_SG];
+ struct ib_sge rx_sge[IPOIB_CM_RX_SG_MAX];
struct ib_recv_wr rx_wr;
int nonsrq_conn_qp;
int max_cm_mtu;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index ed0592898384..314f9de684e3 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -81,7 +81,7 @@ static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
const struct ib_cm_event *event);
static void ipoib_cm_dma_unmap_rx(struct ipoib_dev_priv *priv, int frags,
- u64 mapping[IPOIB_CM_RX_SG])
+ u64 mapping[IPOIB_CM_RX_SG_MAX])
{
int i;
@@ -141,7 +141,7 @@ static int ipoib_cm_post_receive_nonsrq(struct net_device *dev,
static struct sk_buff *ipoib_cm_alloc_rx_skb(struct net_device *dev,
struct ipoib_cm_rx_buf *rx_ring,
int id, int frags,
- u64 mapping[IPOIB_CM_RX_SG],
+ u64 mapping[IPOIB_CM_RX_SG_MAX],
gfp_t gfp)
{
struct ipoib_dev_priv *priv = ipoib_priv(dev);
@@ -350,7 +350,7 @@ static int ipoib_cm_nonsrq_init_rx(struct net_device *dev, struct ib_cm_id *cm_i
struct ipoib_dev_priv *priv = ipoib_priv(dev);
struct {
struct ib_recv_wr wr;
- struct ib_sge sge[IPOIB_CM_RX_SG];
+ struct ib_sge sge[IPOIB_CM_RX_SG_MAX];
} *t;
int ret;
int i;
@@ -565,7 +565,7 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
struct sk_buff *skb, *newskb;
struct ipoib_cm_rx *p;
unsigned long flags;
- u64 mapping[IPOIB_CM_RX_SG];
+ u64 mapping[IPOIB_CM_RX_SG_MAX];
int frags;
int has_srq;
struct sk_buff *small_skb;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index d1e1c5c89dad..a51d1c43f628 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -2760,7 +2760,7 @@ static int __init ipoib_init_module(void)
* When copying small received packets, we only copy from the
* linear data part of the SKB, so we rely on this condition.
*/
- BUILD_BUG_ON(IPOIB_CM_COPYBREAK > IPOIB_CM_HEAD_SIZE);
+ BUILD_BUG_ON(IPOIB_CM_COPYBREAK > IPOIB_CM_HEAD_SIZE_MIN);
ipoib_register_debugfs();
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index 1aaaadb8daf6..e6b5aa88571f 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -489,7 +489,7 @@ struct uapi_definition {
.id = (_attr_id) + \
BUILD_BUG_ON_ZERO((_min_len) == 0 || \
(_max_len) > \
- PAGE_SIZE / sizeof(void *) || \
+ PAGE_SIZE_MIN / sizeof(void *) || \
(_min_len) > (_max_len) || \
(_access) == UVERBS_ACCESS_NEW || \
(_access) == UVERBS_ACCESS_DESTROY), \