From: Edward Srouji <edwards@nvidia.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
"Saeed Mahameed" <saeedm@nvidia.com>,
Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-rdma@vger.kernel.org>,
<netdev@vger.kernel.org>,
Michael Guralnik <michaelgur@nvidia.com>,
"Edward Srouji" <edwards@nvidia.com>,
Yishai Hadas <yishaih@nvidia.com>
Subject: [PATCH rdma-next 4/9] RDMA/core: Add pinned handles to FRMR pools
Date: Sun, 16 Nov 2025 21:10:25 +0200 [thread overview]
Message-ID: <20251116-frmr_pools-v1-4-5eb3c8f5c9c4@nvidia.com> (raw)
In-Reply-To: <20251116-frmr_pools-v1-0-5eb3c8f5c9c4@nvidia.com>
From: Michael Guralnik <michaelgur@nvidia.com>
Add a configuration of pinned handles on a specific FRMR pool.
The configured amount of pinned handles will not be aged and will stay
available for users to claim.
Upon setting the amount of pinned handles to an FRMR pool, we will make
sure we have at least the pinned amount of handles associated with the
pool and create more, if necessary.
The count for pinned handles take into account handles that are used by
user MRs and handles in the queue.
Introduce a new FRMR operation of build_key that allows drivers to
manipulate FRMR keys supplied by the user, allowing failing for
unsupported properties and masking of properties that are modifiable.
Signed-off-by: Michael Guralnik <michaelgur@nvidia.com>
Reviewed-by: Yishai Hadas <yishaih@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
---
drivers/infiniband/core/frmr_pools.c | 123 +++++++++++++++++++++++++++++++++++
drivers/infiniband/core/frmr_pools.h | 3 +
include/rdma/frmr_pools.h | 2 +
3 files changed, 128 insertions(+)
diff --git a/drivers/infiniband/core/frmr_pools.c b/drivers/infiniband/core/frmr_pools.c
index 9af2f6aa6c06cee8a1157aac05aa64f361451083..254113d2442d5d6956587a1c444dc74cd48204fb 100644
--- a/drivers/infiniband/core/frmr_pools.c
+++ b/drivers/infiniband/core/frmr_pools.c
@@ -96,6 +96,51 @@ static void destroy_all_handles_in_queue(struct ib_device *device,
}
}
+static bool age_pinned_pool(struct ib_device *device, struct ib_frmr_pool *pool)
+{
+ struct ib_frmr_pools *pools = device->frmr_pools;
+ u32 total, to_destroy, destroyed = 0;
+ bool has_work = false;
+ u32 *handles;
+ u32 handle;
+
+ spin_lock(&pool->lock);
+ total = pool->queue.ci + pool->inactive_queue.ci + pool->in_use;
+ if (total <= pool->pinned_handles) {
+ spin_unlock(&pool->lock);
+ return false;
+ }
+
+ to_destroy = total - pool->pinned_handles;
+
+ handles = kcalloc(to_destroy, sizeof(*handles), GFP_ATOMIC);
+ if (!handles) {
+ spin_unlock(&pool->lock);
+ return true;
+ }
+
+ /* Destroy all excess handles in the inactive queue */
+ while (pool->inactive_queue.ci && destroyed < to_destroy) {
+ handles[destroyed++] = pop_handle_from_queue_locked(
+ &pool->inactive_queue);
+ }
+
+ /* Move all handles from regular queue to inactive queue */
+ while (pool->queue.ci) {
+ handle = pop_handle_from_queue_locked(&pool->queue);
+ push_handle_to_queue_locked(&pool->inactive_queue,
+ handle);
+ has_work = true;
+ }
+
+ spin_unlock(&pool->lock);
+
+ if (destroyed)
+ pools->pool_ops->destroy_frmrs(device, handles, destroyed);
+ kfree(handles);
+ return has_work;
+}
+
static void pool_aging_work(struct work_struct *work)
{
struct ib_frmr_pool *pool = container_of(
@@ -103,6 +148,11 @@ static void pool_aging_work(struct work_struct *work)
struct ib_frmr_pools *pools = pool->device->frmr_pools;
bool has_work = false;
+ if (pool->pinned_handles) {
+ has_work = age_pinned_pool(pool->device, pool);
+ goto out;
+ }
+
destroy_all_handles_in_queue(pool->device, pool, &pool->inactive_queue);
/* Move all pages from regular queue to inactive queue */
@@ -119,6 +169,7 @@ static void pool_aging_work(struct work_struct *work)
}
spin_unlock(&pool->lock);
+out:
/* Reschedule if there are handles to age in next aging period */
if (has_work)
queue_delayed_work(
@@ -307,6 +358,78 @@ static struct ib_frmr_pool *create_frmr_pool(struct ib_device *device,
return pool;
}
+int ib_frmr_pools_set_pinned(struct ib_device *device, struct ib_frmr_key *key,
+ u32 pinned_handles)
+{
+ struct ib_frmr_pools *pools = device->frmr_pools;
+ struct ib_frmr_key driver_key = {};
+ struct ib_frmr_pool *pool;
+ u32 needed_handles;
+ u32 current_total;
+ int i, ret = 0;
+ u32 *handles;
+
+ if (!pools)
+ return -EINVAL;
+
+ if (pools->pool_ops->build_key) {
+ ret = pools->pool_ops->build_key(device, key, &driver_key);
+ if (ret)
+ return ret;
+ } else {
+ memcpy(&driver_key, key, sizeof(*key));
+ }
+
+ pool = ib_frmr_pool_find(pools, &driver_key);
+ if (!pool) {
+ pool = create_frmr_pool(device, &driver_key);
+ if (IS_ERR(pool))
+ return PTR_ERR(pool);
+ }
+
+ spin_lock(&pool->lock);
+ current_total = pool->in_use + pool->queue.ci + pool->inactive_queue.ci;
+
+ if (current_total < pinned_handles)
+ needed_handles = pinned_handles - current_total;
+ else
+ needed_handles = 0;
+
+ pool->pinned_handles = pinned_handles;
+ spin_unlock(&pool->lock);
+
+ if (!needed_handles)
+ goto schedule_aging;
+
+ handles = kcalloc(needed_handles, sizeof(*handles), GFP_KERNEL);
+ if (!handles)
+ return -ENOMEM;
+
+ ret = pools->pool_ops->create_frmrs(device, key, handles,
+ needed_handles);
+ if (ret) {
+ kfree(handles);
+ return ret;
+ }
+
+ spin_lock(&pool->lock);
+ for (i = 0; i < needed_handles; i++) {
+ ret = push_handle_to_queue_locked(&pool->queue,
+ handles[i]);
+ if (ret)
+ goto end;
+ }
+
+end:
+ spin_unlock(&pool->lock);
+ kfree(handles);
+
+schedule_aging:
+ mod_delayed_work(pools->aging_wq, &pool->aging_work, 0);
+
+ return ret;
+}
+
static int get_frmr_from_pool(struct ib_device *device,
struct ib_frmr_pool *pool, struct ib_mr *mr)
{
diff --git a/drivers/infiniband/core/frmr_pools.h b/drivers/infiniband/core/frmr_pools.h
index 814d8a2106c2978a1a1feca3ba50420025fca994..b144273ee34785623d2254d19f5af40869e00e83 100644
--- a/drivers/infiniband/core/frmr_pools.h
+++ b/drivers/infiniband/core/frmr_pools.h
@@ -45,6 +45,7 @@ struct ib_frmr_pool {
u32 max_in_use;
u32 in_use;
+ u32 pinned_handles;
};
struct ib_frmr_pools {
@@ -55,4 +56,6 @@ struct ib_frmr_pools {
struct workqueue_struct *aging_wq;
};
+int ib_frmr_pools_set_pinned(struct ib_device *device, struct ib_frmr_key *key,
+ u32 pinned_handles);
#endif /* RDMA_CORE_FRMR_POOLS_H */
diff --git a/include/rdma/frmr_pools.h b/include/rdma/frmr_pools.h
index da92ef4d7310c0fe0cebf937a0049f81580ad386..333ce31fc762efb786cd458711617e7ffbd971d0 100644
--- a/include/rdma/frmr_pools.h
+++ b/include/rdma/frmr_pools.h
@@ -26,6 +26,8 @@ struct ib_frmr_pool_ops {
u32 *handles, u32 count);
void (*destroy_frmrs)(struct ib_device *device, u32 *handles,
u32 count);
+ int (*build_key)(struct ib_device *device, const struct ib_frmr_key *in,
+ struct ib_frmr_key *out);
};
int ib_frmr_pools_init(struct ib_device *device,
--
2.47.1
next prev parent reply other threads:[~2025-11-16 19:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-16 19:10 [PATCH rdma-next 0/9] RDMA/core: Introduce FRMR pools infrastructure Edward Srouji
2025-11-16 19:10 ` [PATCH rdma-next 1/9] IB/core: Introduce FRMR pools Edward Srouji
2025-11-16 19:10 ` [PATCH rdma-next 2/9] RDMA/core: Add aging to " Edward Srouji
2025-11-16 19:10 ` [PATCH rdma-next 3/9] RDMA/core: Add FRMR pools statistics Edward Srouji
2025-11-16 19:10 ` Edward Srouji [this message]
2025-11-16 19:10 ` [PATCH rdma-next 5/9] RDMA/mlx5: Switch from MR cache to FRMR pools Edward Srouji
2025-11-16 19:10 ` [PATCH rdma-next 6/9] net/mlx5: Drop MR cache related code Edward Srouji
2025-11-16 19:10 ` [PATCH rdma-next 7/9] RDMA/nldev: Add command to get FRMR pools Edward Srouji
2025-11-16 19:10 ` [PATCH rdma-next 8/9] RDMA/core: Add netlink command to modify FRMR aging Edward Srouji
2025-11-16 19:10 ` [PATCH rdma-next 9/9] RDMA/core: Add command to set pinned FRMR handles Edward Srouji
2025-11-17 18:18 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251116-frmr_pools-v1-4-5eb3c8f5c9c4@nvidia.com \
--to=edwards@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jgg@ziepe.ca \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=michaelgur@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.com \
--cc=yishaih@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.