From nobody Mon Aug 24 05:24:40 2026 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F02027466A for ; Tue, 18 Aug 2026 16:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787070933; cv=none; b=Jnq+iaEuPuVUORxw2IB7abT4Nu0NYiP+rk1klLpfVnYnrURNGAmQPD9v4EVsr8I4GPqyHzD9Cd6hkpUmMpi4nAC4Hs53OcKjxz2pAHPGLMFXU41/aiWFLGcb5SqHIRYhopg9+K1V1EP3DGt7ofPkta2ZRgjt1Bwsp72sh9Zx1Ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787070933; c=relaxed/simple; bh=BvjZPzsmTtdcfM31lpAirAvn7r1tTrHVTkq8Nift3Vo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aQj0gwS4yCz/lXrBnDnxUyS1RKt+YXmUxTWg3FSVnSJVTnjOs9XU9XRxA2/R3R3TUw0YPV6sFBYu7Pui/AYzKuZBaD6skiohCjoXtFcxQd/kKv+rsmW0JmR7WAuvu3UDmFl5j/fCuGtyluFrffxgJapwxoWBgLcojXtnbWMIUjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FKPRXBeE; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FKPRXBeE" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-84eb992a881so124503b3a.2 for ; Tue, 18 Aug 2026 09:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787070931; x=1787675731; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FlvrqSjJb88EG2rPVhBx1VgGjmZj/R+UCbrV7qRmUoY=; b=FKPRXBeE3tol25pRI72NkZmmGEXVgHBwk0KUCuhJHd3B86t59wvM5F9e1XnqKWlAhC NzZHTC4PSig86JhG8mJ1q/Gj731eXPJCWuFn2HrQrTGDTS8mDfoP32/r1N0KKVDxdgSX Y7F4LsBNhU20pXrcckZ6N0Eg1hm2Z2p8DzDKu8sc1rs2i7En4cjeYFEw6EbP9w3eNf41 KyOfmELngcmj+U4s+OE1CzlStSMOqbg3sYtluMjSWgoA7wUnUKKjSLbM/TwvdbNLrne7 udAmb8Iua7SfwjhNKzgOWvnVcJ6fFIfianuJRqUSDR6livC1uFkvGnmyW2PEvQ3R/dQe /k+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787070931; x=1787675731; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=FlvrqSjJb88EG2rPVhBx1VgGjmZj/R+UCbrV7qRmUoY=; b=onlS3cZ9XIhkihXhCSBzd1FLIsAeZ+rYmGWAub7/NEdKy2nVUfbVlhTjQTjjrwvXaM 5cZfRSKyfWL5JeIHIYqH/V9xrht9s3pEzHuTxnmsAoCdHHdP2oqlTUvhJ23fT0fyjY8d 2E111klRm42+l5jc+wOQV/RDZqx9XLXlvdym8Vak/ErvldqPZ0Qpj5bft7Ev0Celvpex +YLDolqcE67zt3kx23EnKvcEcQ1K4IWJ/NlaWR9e1modKGOaQDtUAETGHQQr0uG8JTs3 GvxGeNt2nj5X+uEwjIAPzjGTlT32F60hq4bRvpLxBtKW7C4aKzAd4m4hGIQ1RhdQxdlr lYNQ== X-Forwarded-Encrypted: i=1; AHgh+RqWGFWXzXbf9IUvNNW/F0dNZrfyneTimWGOWMEuCdA9j7nVMsO3nYPobRy9aBUzF2RlXZed4drY5Gsyq2Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yxc6CF1dcq0iOekrWhG5MdSE7RExLrfl2U+D3YMB9f1v3OVhSed fcxKMQXg5irR5supCYYgOmJHhj7wjR6Xed/6tycWkdGvR2F84sksqNmD X-Gm-Gg: AR+sD12I3b5nv5EjaLqVQTo+cZ/3De0+0lbIoIvs2L8xXu/VllQwhA6ffF1iu0vq3U2 5l91RO1vPSKoz8hjQcc60qgyUMmWs6e2n/3ORXGTDyXCIJx/mF2mGSFbwnmWDNT8mz2+4uwtl3Q i5WSW4W06FGeTL5f4s5L7ACjCnXUIoxKZVM3jdya1zqZLsOpNVjBIFAky9eT9GcnNegTuL+Z2dt GKXmgnrHQji58u8sWTSLikbVmRxW0K+GRg66uXA5lhyvZuCY4NKNs5Hmo5fD1iXs+CwBnkUn+uE OgCv1I4ABB8bsY7AX93blMSS12ErBbX9ArWA3DE/9ROWFArNS6gy3XKC+niI1C+IglBXBZWBdqu elm5htsi4I38+PlnOx+4lqBVUVeYqEqp1lnTcI46tjd5kXASrStZxfQMtw208HfL1MUeQOHLqot S8J3JieZXCPSiS3za+Defm+lyinomM0LKcZc6ubjvuUSwyBwRg1WJnIGoFRpWzhKdMnXyi8uuqf BMRm+QC7wGQ9ZFUsPBcQMQvY5v5luK7 X-Received: by 2002:a05:6a00:1c9e:b0:845:ba94:a56 with SMTP id d2e1a72fcca58-84fddfbf1cbmr37206428b3a.5.1787070931166; Tue, 18 Aug 2026 09:35:31 -0700 (PDT) Received: from localhost.localdomain ([240a:4282:4801:1b98:2558:3176:8229:fc85]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cc13bf235fcsm2378298a12.9.2026.08.18.09.35.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 18 Aug 2026 09:35:30 -0700 (PDT) From: Liu Zhenlong To: "Md . Haris Iqbal" , Jack Wang Cc: Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Liu Zhenlong , Jack Wang Subject: [PATCH v2] RDMA/rtrs-clt: use find_next_zero_bit() for permit allocation Date: Wed, 19 Aug 2026 00:35:13 +0800 Message-ID: <20260818163513.53875-1-dragonliu2018@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816165935.90523-1-dragonliu2018@gmail.com> References: <20260816165935.90523-1-dragonliu2018@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __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=3Dm, rtrs-clt.o Reviewed-by: Jack Wang Assisted-by: Claude:claude-opus-5 Signed-off-by: Liu Zhenlong Reviewed-by carried. --- 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/ul= p/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 =3D clt->queue_depth; struct rtrs_permit *permit; - int bit; + unsigned long bit =3D 0; =20 /* - * 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 =3D find_first_zero_bit(clt->permits_map, max_depth); - if (bit >=3D max_depth) - return NULL; + bit =3D find_next_zero_bit(clt->permits_map, max_depth, bit); + if (bit >=3D max_depth) { + bit =3D find_first_zero_bit(clt->permits_map, max_depth); + if (bit >=3D max_depth) + return NULL; + } } while (test_and_set_bit_lock(bit, clt->permits_map)); =20 permit =3D get_permit(clt, bit); --=20 2.55.0