From: Liu Zhenlong <dragonliu2018@gmail.com>
To: "Md . Haris Iqbal" <haris.iqbal@ionos.com>,
Jack Wang <jinpu.wang@ionos.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
Liu Zhenlong <dragonliu2018@gmail.com>,
Jack Wang <jinpu.wang@cloud.ionos.com>
Subject: [PATCH v2] RDMA/rtrs-clt: use find_next_zero_bit() for permit allocation
Date: Wed, 19 Aug 2026 00:35:13 +0800 [thread overview]
Message-ID: <20260818163513.53875-1-dragonliu2018@gmail.com> (raw)
In-Reply-To: <20260816165935.90523-1-dragonliu2018@gmail.com>
__rtrs_get_permit() scans permits_map with find_first_zero_bit() and
claims the bit with test_and_set_bit_lock(), restarting from bit 0 on a
lost race. Use find_next_zero_bit() to resume from the last position so
a lost race does not rescan the already-set low bits; on reaching the
end, wrap to the beginning to exhaust the map.
Compile-tested: arm64 defconfig + INFINIBAND_RTRS_CLIENT=m, rtrs-clt.o
Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Assisted-by: Claude:claude-opus-5
Signed-off-by: Liu Zhenlong <dragonliu2018@gmail.com>
---
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index d34d7e5f34d6..a1df90243c41 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -70,19 +70,24 @@ __rtrs_get_permit(struct rtrs_clt_sess *clt, enum rtrs_clt_con_type con_type)
{
size_t max_depth = clt->queue_depth;
struct rtrs_permit *permit;
- int bit;
+ unsigned long bit = 0;
/*
- * Adapted from null_blk get_tag(). Callers from different cpus may
- * grab the same bit, since find_first_zero_bit is not atomic.
- * But then the test_and_set_bit_lock will fail for all the
- * callers but one, so that they will loop again.
- * This way an explicit spinlock is not required.
+ * Callers from different CPUs may grab the same bit, since the bitmap
+ * scan is not atomic. But then the test_and_set_bit_lock() will fail
+ * for all the callers but one, so that they loop again. This way an
+ * explicit spinlock is not required. find_next_zero_bit() resumes
+ * from the last position so that a lost race does not rescan the
+ * already-set low bits; if it reaches the end, wrap to the beginning
+ * to exhaust the map and still find a permit freed below the cursor.
*/
do {
- bit = find_first_zero_bit(clt->permits_map, max_depth);
- if (bit >= max_depth)
- return NULL;
+ bit = find_next_zero_bit(clt->permits_map, max_depth, bit);
+ if (bit >= max_depth) {
+ bit = find_first_zero_bit(clt->permits_map, max_depth);
+ if (bit >= max_depth)
+ return NULL;
+ }
} while (test_and_set_bit_lock(bit, clt->permits_map));
permit = get_permit(clt, bit);
--
2.55.0
next prev parent reply other threads:[~2026-08-18 16:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 16:59 [PATCH] RDMA/rtrs-clt: use find_next_zero_bit() for permit allocation Liu Zhenlong
2026-08-17 4:57 ` Jinpu Wang
2026-08-18 16:35 ` Liu Zhenlong [this message]
2026-08-18 17:22 ` [PATCH v2] " Liu Zhenlong
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=20260818163513.53875-1-dragonliu2018@gmail.com \
--to=dragonliu2018@gmail.com \
--cc=haris.iqbal@ionos.com \
--cc=jgg@ziepe.ca \
--cc=jinpu.wang@cloud.ionos.com \
--cc=jinpu.wang@ionos.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox