FAILED: patch "[PATCH] RDMA/ionic: Embed counter driver data in rdma_counter" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x cf3ebd89e754015625fee90aa938f6bc79a2c974
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090319-cesspool-drapery-a749@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From cf3ebd89e754015625fee90aa938f6bc79a2c974 Mon Sep 17 00:00:00 2001
From: Abhijit Gangurde <[email protected]>
Date: Wed, 5 Aug 2026 11:02:54 +0530
Subject: [PATCH] RDMA/ionic: Embed counter driver data in rdma_counter
allocation
Commit 7e53b31acc7f ("RDMA/core: Create and destroy rdma_counter using rdma_zalloc_drv_obj()") requires drivers implementing counter ops to embed struct rdma_counter in a driver-specific struct, register its size via INIT_RDMA_OBJ_SIZE, and provide a counter_init callback.
The ionic driver was merged without this adaptation, causing a NULL pointer dereference in alloc_and_bind() since rdma_zalloc_drv_obj() allocates zero bytes when size_rdma_counter is unset.
Consolidate struct ionic_counter into a new struct ionic_rdma_counter that embeds struct rdma_counter, replace the xarray with a lightweight ida for ID allocation, and add the required counter_init and INIT_RDMA_OBJ_SIZE declarations.
drivers/infiniband/hw/ionic/ionic_hw_stats.c +42 -53
@@ -235,35 +235,34 @@ static int ionic_get_hw_stats(struct ib_device *ibdev,static struct rdma_hw_stats *ionic_counter_alloc_stats (struct rdma_counter *counter) { +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter);struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); -struct ionic_counter *cntr; -int err; +struct rdma_hw_stats *stats; +int id; - cntr =kzalloc_obj (*cntr); -if (!cntr) -return NULL ; - -/* buffer for current values from the device */ cntr->vals =kzalloc (PAGE_SIZE ,GFP_KERNEL );if (!cntr->vals) - goto err_vals; +return NULL ; - err =xa_alloc (&dev->counter_stats->xa_counters, &counter->id, - cntr, -XA_LIMIT (0 ,IONIC_MAX_QPID ), -GFP_KERNEL ); -if (err) - goto err_xa; + id =ida_alloc_max (&dev->counter_stats->counter_ida, +IONIC_MAX_QPID ,GFP_KERNEL ); +if (id <0 ) + goto err_ida; -INIT_LIST_HEAD (&cntr->qp_list); + counter->id = id; -return rdma_alloc_hw_stats_struct (dev->counter_stats->stats_hdrs, - dev->counter_stats->queue_stats_count, -RDMA_HW_STATS_DEFAULT_LIFESPAN ); -err_xa: + stats =rdma_alloc_hw_stats_struct (dev->counter_stats->stats_hdrs, + dev->counter_stats->queue_stats_count, +RDMA_HW_STATS_DEFAULT_LIFESPAN ); +if (!stats) + goto err_hw_stats; + +return stats; + +err_hw_stats: +ida_free (&dev->counter_stats->counter_ida, id); +err_ida:kfree (cntr->vals); -err_vals: -kfree (cntr);return NULL ; }
@@ -271,14 +270,10 @@ ionic_counter_alloc_stats(struct rdma_counter *counter)static int ionic_counter_dealloc (struct rdma_counter *counter) {struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); -struct ionic_counter *cntr; - - cntr =xa_erase (&dev->counter_stats->xa_counters, counter->id); -if (!cntr) -return -EINVAL ; +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter); +ida_free (&dev->counter_stats->counter_ida, counter->id);kfree (cntr->vals); -kfree (cntr);return 0 ; }
@@ -287,13 +282,8 @@ static int ionic_counter_bind_qp(struct rdma_counter *counter, struct ib_qp *ibqp, u32 port) { -struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter);struct ionic_qp *qp =to_ionic_qp (ibqp); -struct ionic_counter *cntr; - - cntr =xa_load (&dev->counter_stats->xa_counters, counter->id); -if (!cntr) -return -EINVAL ;list_add_tail (&qp->qp_list_counter, &cntr->qp_list); ibqp->counter = counter;
@@ -313,29 +303,23 @@ static int ionic_counter_unbind_qp(struct ib_qp *ibqp, u32 port)return 0 ; } -static int ionic_get_qp_stats (struct ib_device *ibdev, -struct rdma_hw_stats *hw_stats, -u32 counter_id) +static int ionic_counter_update_stats (struct rdma_counter *counter) { -struct ionic_ibdev *dev =to_ionic_ibdev (ibdev); -struct ionic_counter_stats *cs; -struct ionic_counter *cntr; +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter); +struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); +struct ionic_counter_stats *cs = dev->counter_stats;dma_addr_t hw_stats_dma;struct ionic_qp *qp;int rc, stat_i =0 ; - cs = dev->counter_stats; - cntr =xa_load (&cs->xa_counters, counter_id); -if (!cntr) -return -EINVAL ; - hw_stats_dma =dma_map_single (dev->lif_cfg.hwdev, cntr->vals,PAGE_SIZE ,DMA_FROM_DEVICE ); rc =dma_mapping_error (dev->lif_cfg.hwdev, hw_stats_dma);if (rc)return rc; -memset (hw_stats->value,0 ,sizeof (u64) * hw_stats->num_counters); +memset (counter->stats->value,0 , +sizeof (u64) * counter->stats->num_counters);list_for_each_entry (qp, &cntr->qp_list, qp_list_counter) { rc = ionic_hw_stats_cmd(dev, hw_stats_dma, PAGE_SIZE,
@@ -345,7 +329,7 @@ static int ionic_get_qp_stats(struct ib_device *ibdev, goto err_cmd;for (stat_i =0 ; stat_i < cs->queue_stats_count; ++stat_i) - hw_stats->value[stat_i] += + counter->stats->value[stat_i] +=ionic_v1_stat_val (&cs->hdr[stat_i], cntr->vals,PAGE_SIZE );
@@ -360,11 +344,6 @@ static int ionic_get_qp_stats(struct ib_device *ibdev,return rc; } -static int ionic_counter_update_stats (struct rdma_counter *counter) -{ -return ionic_get_qp_stats (counter->device, counter->stats, counter->id); -} -static int ionic_alloc_counters (struct ionic_ibdev *dev) {struct ionic_counter_stats *cs = dev->counter_stats;
@@ -424,12 +403,22 @@ static const struct ib_device_ops ionic_hw_stats_ops = { .get_hw_stats = ionic_get_hw_stats, }; +static void ionic_counter_init (struct rdma_counter *counter) +{ +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter); + +INIT_LIST_HEAD (&cntr->qp_list); +} +static const struct ib_device_ops ionic_counter_stats_ops = { .counter_alloc_stats = ionic_counter_alloc_stats, .counter_dealloc = ionic_counter_dealloc, .counter_bind_qp = ionic_counter_bind_qp, .counter_unbind_qp = ionic_counter_unbind_qp, .counter_update_stats = ionic_counter_update_stats, + .counter_init = ionic_counter_init, + +INIT_RDMA_OBJ_SIZE (rdma_counter, ionic_rdma_counter, rdma_counter), };void ionic_stats_init (struct ionic_ibdev *dev)
@@ -458,7 +447,7 @@ void ionic_stats_init(struct ionic_ibdev *dev)return ; } -xa_init_flags (&dev->counter_stats->xa_counters,XA_FLAGS_ALLOC ); +ida_init (&dev->counter_stats->counter_ida);ib_set_device_ops (&dev->ibdev, &ionic_counter_stats_ops); }
@@ -467,7 +456,7 @@ void ionic_stats_init(struct ionic_ibdev *dev)void ionic_stats_cleanup (struct ionic_ibdev *dev) {if (dev->counter_stats) { -xa_destroy (&dev->counter_stats->xa_counters); +ida_destroy (&dev->counter_stats->counter_ida);kfree (dev->counter_stats->hdr);kfree (dev->counter_stats->stats_hdrs);kfree (dev->counter_stats);
drivers/infiniband/hw/ionic/ionic_ibdev.h +9 -2
@@ -332,14 +332,21 @@ struct ionic_counter_stats {int queue_stats_count;struct ionic_v1_stat *hdr;struct rdma_stat_desc *stats_hdrs; -struct xarray xa_counters; +struct ida counter_ida; }; -struct ionic_counter { +struct ionic_rdma_counter { +struct rdma_counter rdma_counter;void *vals;struct list_head qp_list; }; +static inline struct ionic_rdma_counter * +to_ionic_rdma_counter (struct rdma_counter *counter) +{ + return container_of(counter, struct ionic_rdma_counter, rdma_counter); +} +static inline struct ionic_ibdev *to_ionic_ibdev (struct ib_device *ibdev) { return container_of(ibdev, struct ionic_ibdev, ibdev);
Sasha Levin
maintainerPATCH 1/1 RDMA/ionic: Embed counter driver data in rdma_counter allocation
From: Abhijit Gangurde <[email protected]>
[ Upstream commit cf3ebd89e754015625fee90aa938f6bc79a2c974 ]
Commit 7e53b31acc7f ("RDMA/core: Create and destroy rdma_counter using rdma_zalloc_drv_obj()") requires drivers implementing counter ops to embed struct rdma_counter in a driver-specific struct, register its size via INIT_RDMA_OBJ_SIZE, and provide a counter_init callback.
The ionic driver was merged without this adaptation, causing a NULL pointer dereference in alloc_and_bind() since rdma_zalloc_drv_obj() allocates zero bytes when size_rdma_counter is unset.
Consolidate struct ionic_counter into a new struct ionic_rdma_counter that embeds struct rdma_counter, replace the xarray with a lightweight ida for ID allocation, and add the required counter_init and INIT_RDMA_OBJ_SIZE declarations.
--- drivers/infiniband/hw/ionic/ionic_hw_stats.c | 95 +++++++++----------- drivers/infiniband/hw/ionic/ionic_ibdev.h | 11 ++- 2 files changed, 51 insertions(+), 55 deletions(-)
drivers/infiniband/hw/ionic/ionic_hw_stats.c +42 -53
@@ -237,35 +237,34 @@ static int ionic_get_hw_stats(struct ib_device *ibdev,static struct rdma_hw_stats *ionic_counter_alloc_stats (struct rdma_counter *counter) { +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter);struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); -struct ionic_counter *cntr; -int err; +struct rdma_hw_stats *stats; +int id; - cntr =kzalloc (sizeof (*cntr),GFP_KERNEL ); -if (!cntr) -return NULL ; - -/* buffer for current values from the device */ cntr->vals =kzalloc (PAGE_SIZE ,GFP_KERNEL );if (!cntr->vals) - goto err_vals; +return NULL ; - err =xa_alloc (&dev->counter_stats->xa_counters, &counter->id, - cntr, -XA_LIMIT (0 ,IONIC_MAX_QPID ), -GFP_KERNEL ); -if (err) - goto err_xa; + id =ida_alloc_max (&dev->counter_stats->counter_ida, +IONIC_MAX_QPID ,GFP_KERNEL ); +if (id <0 ) + goto err_ida; -INIT_LIST_HEAD (&cntr->qp_list); + counter->id = id; + + stats =rdma_alloc_hw_stats_struct (dev->counter_stats->stats_hdrs, + dev->counter_stats->queue_stats_count, +RDMA_HW_STATS_DEFAULT_LIFESPAN ); +if (!stats) + goto err_hw_stats; + +return stats; -return rdma_alloc_hw_stats_struct (dev->counter_stats->stats_hdrs, - dev->counter_stats->queue_stats_count, -RDMA_HW_STATS_DEFAULT_LIFESPAN ); -err_xa: +err_hw_stats: +ida_free (&dev->counter_stats->counter_ida, id); +err_ida:kfree (cntr->vals); -err_vals: -kfree (cntr);return NULL ; }
@@ -273,14 +272,10 @@ ionic_counter_alloc_stats(struct rdma_counter *counter)static int ionic_counter_dealloc (struct rdma_counter *counter) {struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); -struct ionic_counter *cntr; - - cntr =xa_erase (&dev->counter_stats->xa_counters, counter->id); -if (!cntr) -return -EINVAL ; +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter); +ida_free (&dev->counter_stats->counter_ida, counter->id);kfree (cntr->vals); -kfree (cntr);return 0 ; }
@@ -289,13 +284,8 @@ static int ionic_counter_bind_qp(struct rdma_counter *counter, struct ib_qp *ibqp, u32 port) { -struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter);struct ionic_qp *qp =to_ionic_qp (ibqp); -struct ionic_counter *cntr; - - cntr =xa_load (&dev->counter_stats->xa_counters, counter->id); -if (!cntr) -return -EINVAL ;list_add_tail (&qp->qp_list_counter, &cntr->qp_list); ibqp->counter = counter;
@@ -315,29 +305,23 @@ static int ionic_counter_unbind_qp(struct ib_qp *ibqp, u32 port)return 0 ; } -static int ionic_get_qp_stats (struct ib_device *ibdev, -struct rdma_hw_stats *hw_stats, -u32 counter_id) +static int ionic_counter_update_stats (struct rdma_counter *counter) { -struct ionic_ibdev *dev =to_ionic_ibdev (ibdev); -struct ionic_counter_stats *cs; -struct ionic_counter *cntr; +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter); +struct ionic_ibdev *dev =to_ionic_ibdev (counter->device); +struct ionic_counter_stats *cs = dev->counter_stats;dma_addr_t hw_stats_dma;struct ionic_qp *qp;int rc, stat_i =0 ; - cs = dev->counter_stats; - cntr =xa_load (&cs->xa_counters, counter_id); -if (!cntr) -return -EINVAL ; - hw_stats_dma =dma_map_single (dev->lif_cfg.hwdev, cntr->vals,PAGE_SIZE ,DMA_FROM_DEVICE ); rc =dma_mapping_error (dev->lif_cfg.hwdev, hw_stats_dma);if (rc)return rc; -memset (hw_stats->value,0 ,sizeof (u64) * hw_stats->num_counters); +memset (counter->stats->value,0 , +sizeof (u64) * counter->stats->num_counters);list_for_each_entry (qp, &cntr->qp_list, qp_list_counter) { rc = ionic_hw_stats_cmd(dev, hw_stats_dma, PAGE_SIZE,
@@ -347,7 +331,7 @@ static int ionic_get_qp_stats(struct ib_device *ibdev, goto err_cmd;for (stat_i =0 ; stat_i < cs->queue_stats_count; ++stat_i) - hw_stats->value[stat_i] += + counter->stats->value[stat_i] +=ionic_v1_stat_val (&cs->hdr[stat_i], cntr->vals,PAGE_SIZE );
@@ -362,11 +346,6 @@ static int ionic_get_qp_stats(struct ib_device *ibdev,return rc; } -static int ionic_counter_update_stats (struct rdma_counter *counter) -{ -return ionic_get_qp_stats (counter->device, counter->stats, counter->id); -} -static int ionic_alloc_counters (struct ionic_ibdev *dev) {struct ionic_counter_stats *cs = dev->counter_stats;
@@ -427,12 +406,22 @@ static const struct ib_device_ops ionic_hw_stats_ops = { .get_hw_stats = ionic_get_hw_stats, }; +static void ionic_counter_init (struct rdma_counter *counter) +{ +struct ionic_rdma_counter *cntr =to_ionic_rdma_counter (counter); + +INIT_LIST_HEAD (&cntr->qp_list); +} +static const struct ib_device_ops ionic_counter_stats_ops = { .counter_alloc_stats = ionic_counter_alloc_stats, .counter_dealloc = ionic_counter_dealloc, .counter_bind_qp = ionic_counter_bind_qp, .counter_unbind_qp = ionic_counter_unbind_qp, .counter_update_stats = ionic_counter_update_stats, + .counter_init = ionic_counter_init, + +INIT_RDMA_OBJ_SIZE (rdma_counter, ionic_rdma_counter, rdma_counter), };void ionic_stats_init (struct ionic_ibdev *dev)
@@ -462,7 +451,7 @@ void ionic_stats_init(struct ionic_ibdev *dev)return ; } -xa_init_flags (&dev->counter_stats->xa_counters,XA_FLAGS_ALLOC ); +ida_init (&dev->counter_stats->counter_ida);ib_set_device_ops (&dev->ibdev, &ionic_counter_stats_ops); }
@@ -471,7 +460,7 @@ void ionic_stats_init(struct ionic_ibdev *dev)void ionic_stats_cleanup (struct ionic_ibdev *dev) {if (dev->counter_stats) { -xa_destroy (&dev->counter_stats->xa_counters); +ida_destroy (&dev->counter_stats->counter_ida);kfree (dev->counter_stats->hdr);kfree (dev->counter_stats->stats_hdrs);kfree (dev->counter_stats);
drivers/infiniband/hw/ionic/ionic_ibdev.h +9 -2
@@ -331,14 +331,21 @@ struct ionic_counter_stats {int queue_stats_count;struct ionic_v1_stat *hdr;struct rdma_stat_desc *stats_hdrs; -struct xarray xa_counters; +struct ida counter_ida; }; -struct ionic_counter { +struct ionic_rdma_counter { +struct rdma_counter rdma_counter;void *vals;struct list_head qp_list; }; +static inline struct ionic_rdma_counter * +to_ionic_rdma_counter (struct rdma_counter *counter) +{ + return container_of(counter, struct ionic_rdma_counter, rdma_counter); +} +static inline struct ionic_ibdev *to_ionic_ibdev (struct ib_device *ibdev) { return container_of(ibdev, struct ionic_ibdev, ibdev);
Signature · 1 line
2.53.0