Misc patches for RTRS
Subsystems (2)
Md Haris Iqbal
maintainercover Misc patches for RTRS
Hi Jason, hi Leon,
Please consider including the following changes in the next merge window.
Benjamin Stürz (1):
RDMA/rtrs-srv: Snapshot the READ request header instead of reusing it
Danil Kipnis (3):
RDMA/rtrs-clt: Add mpath_policy module parameter RDMA/rtrs-clt: rename pathname parameter to sessname in
rtrs_clt_open()
RDMA/rtrs-clt: Back off the reconnect delay exponentially
Grzegorz Prajsner (1):
RDMA/rtrs-srv: Fix processing messages for Big-Endian archs
Jack Wang (2):
RDMA/rtrs-clt: Fix refcount imbalance in rtrs_clt_write_req error path RDMA/rtrs-clt: Trigger error recovery when posting LOCAL_INV fails
Md Haris Iqbal (2):
RDMA/rtrs-clt: Fix reconnect jitter being applied in milliseconds RDMA/rtrs-clt: Close all paths before freeing any in rtrs_clt_close()
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 132 +++++++++++++++++++------ drivers/infiniband/ulp/rtrs/rtrs-srv.c | 38 +++---- drivers/infiniband/ulp/rtrs/rtrs-srv.h | 13 ++- drivers/infiniband/ulp/rtrs/rtrs.h | 2 +- 4 files changed, 137 insertions(+), 48 deletions(-)
Signature · 1 line
2.43.0
Md Haris Iqbal
maintainerPATCH 1/9 RDMA/rtrs-clt: Add mpath_policy module parameter
From: Danil Kipnis <[email protected]>
Add a module parameter to set the default multipath policy for newly created sessions. This simplifies configuration when all sessions should use the same policy, allowing administrators to set the default at module load time or boot time via kernel parameters.
The parameter accepts numeric values 0-2:
- 0: Round-robin (MP_POLICY_RR)
- 1: Minimum inflight requests (MP_POLICY_MIN_INFLIGHT) - default
- 2: Minimum latency (MP_POLICY_MIN_LATENCY)
Invalid values are clamped to the valid range. The parameter is runtime adjustable via /sys/module/rtrs_client/parameters/mpath_policy, affecting only newly created sessions. Existing sessions retain their current policy.
The per-session sysfs interface remains fully functional for session- specific overrides, maintaining backward compatibility.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +12 -1
@@ -39,6 +39,13 @@MODULE_DESCRIPTION ("RDMA Transport Client" );MODULE_LICENSE ("GPL" ); +static int mpath_policy =MP_POLICY_MIN_INFLIGHT ; +module_param_named (mpath_policy, mpath_policy, int,0644 ); +MODULE_PARM_DESC (mpath_policy, + "Default multipath policy for new sessions (default: " + __stringify(MP_POLICY_MIN_INFLIGHT) +" (min-inflight), 0: round-robin, 1: min-inflight, 2: min-latency)" ); +static const struct rtrs_rdma_dev_pd_ops dev_pd_ops;static struct rtrs_rdma_dev_pd dev_pd = { .ops = &dev_pd_ops
@@ -2758,7 +2765,7 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num, clt->max_reconnect_attempts = max_reconnect_attempts; clt->priv = priv; clt->link_ev = link_ev; - clt->mp_policy =MP_POLICY_MIN_INFLIGHT ; + clt->mp_policy = mpath_policy;strscpy (clt->sessname, sessname,sizeof (clt->sessname));init_waitqueue_head (&clt->permits_wait);mutex_init (&clt->paths_ev_mutex);
@@ -3220,6 +3227,10 @@ static int __init rtrs_client_init(void)int ret =0 ;rtrs_rdma_dev_pd_init (0 , &dev_pd); + +/* Validate and clamp mpath_policy to valid range */ + mpath_policy =clamp (mpath_policy,MP_POLICY_RR ,MP_POLICY_MIN_LATENCY ); + ret =class_register (&rtrs_clt_dev_class);if (ret) {pr_err ("Failed to create rtrs-client dev class\n" );
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 1/9] RDMA/rtrs-clt: Add mpath_policy module parameter
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] RDMA/rtrs-clt: unclamped runtime sysfs writes to mpath_policy in alloc_clt() - [Low]…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] RDMA/rtrs-clt: unclamped runtime sysfs writes to mpath_policy in alloc_clt()
- [Low] RDMA/rtrs-clt: __stringify() on enum MP_POLICY_MIN_INFLIGHT in MODULE_PARM_DESC
--
commit 9f1bdddc73a41e6280e607ffdea1faff0f78b52e
Author: Danil Kipnis <[email protected]>
RDMA/rtrs-clt: Add mpath_policy module parameter
This commit adds a runtime-adjustable mpath_policy module parameter to configure the default multipath policy for newly created RTRS client sessions.
Quoted 5 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0
-0
drivers/infiniband/ulp/rtrs/rtrs-clt.c line 47
Quoted 9 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +6
-0@@ -39,6 +39,13 @@MODULE_DESCRIPTION ("RDMA Transport Client" );MODULE_LICENSE ("GPL" ); +static int mpath_policy =MP_POLICY_MIN_INFLIGHT ; +module_param_named (mpath_policy, mpath_policy, int,0644 ); +MODULE_PARM_DESC (mpath_policy, + "Default multipath policy for new sessions (default: " + __stringify(MP_POLICY_MIN_INFLIGHT) +" (min-inflight), 0: round-robin, 1: min-inflight, 2: min-latency)" );
[Severity: Low]
Does __stringify(MP_POLICY_MIN_INFLIGHT) expand to the literal token name "MP_POLICY_MIN_INFLIGHT" in modinfo rather than "1"? MP_POLICY_MIN_INFLIGHT is an enum constant in enum rtrs_mp_policy, not a preprocessor macro.
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +1
-1@@ -2758,7 +2765,7 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num, clt->max_reconnect_attempts = max_reconnect_attempts; clt->priv = priv; clt->link_ev = link_ev; - clt->mp_policy =MP_POLICY_MIN_INFLIGHT ; + clt->mp_policy = mpath_policy;strscpy (clt->sessname, sessname,sizeof (clt->sessname));init_waitqueue_head (&clt->permits_wait);mutex_init (&clt->paths_ev_mutex);
drivers/infiniband/ulp/rtrs/rtrs-clt.c static int __init rtrs_client_init(void) · line 3236
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +4
-0@@ -3220,6 +3227,10 @@ static int __init rtrs_client_init(void)int ret =0 ;rtrs_rdma_dev_pd_init (0 , &dev_pd); + +/* Validate and clamp mpath_policy to valid range */ + mpath_policy =clamp (mpath_policy,MP_POLICY_RR ,MP_POLICY_MIN_LATENCY ); + ret =class_register (&rtrs_clt_dev_class);if (ret) {pr_err ("Failed to create rtrs-client dev class\n" );
[Severity: Medium]
Does clamping mpath_policy only in rtrs_client_init() leave runtime writes to /sys/module/rtrs_client/parameters/mpath_policy unclamped?
Because mpath_policy uses mode 0644 with standard param_ops_int, writing an out-of-range value via sysfs after module load stores that value directly into clt->mp_policy in alloc_clt(). New sessions then report "Unknown (<val>)" in mpath_policy_show(), and negative values fall through path_it_init() to get_next_path_min_latency instead of clamping to MP_POLICY_RR.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/9] RDMA/rtrs-clt: Add mpath_policy module parameter
In reply to Md Haris IqbalQuoted 12 lines · Md Haris Iqbal
From: Danil Kipnis <[email protected]>
Add a module parameter to set the default multipath policy for newly created sessions. This simplifies configuration when all sessions should use the same policy, allowing administrators to set the default at module load time or boot time via kernel parameters.
The parameter accepts numeric values 0-2:
- 0: Round-robin (MP_POLICY_RR)
- 1: Minimum inflight requests (MP_POLICY_MIN_INFLIGHT) - default
- 2: Minimum latency (MP_POLICY_MIN_LATENCY)
Quoted 6 lines
Invalid values are clamped to the valid range. The parameter is runtime adjustable via
/sys/module/rtrs_client/parameters/mpath_policy, affecting only newly created sessions. Existing sessions retain their current policy.The per-session sysfs interface remains fully functional for session- specific overrides, maintaining backward compatibility.
Your AI tool merely restated what this patch implements and provided general information about module parameters.
It does not explain why this parameter is needed, especially given that IONOS is the only user of RTRS.
Thanks
Quoted 50 lines
Signed-off-by Danil Kipnis <[email protected]>Signed-off-by Jack Wang <[email protected]>Signed-off-by Md Haris Iqbal <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/infiniband/ulp/rtrs/rtrs-clt.c +12
-1@@ -39,6 +39,13 @@MODULE_DESCRIPTION ("RDMA Transport Client" );MODULE_LICENSE ("GPL" ); +static int mpath_policy =MP_POLICY_MIN_INFLIGHT ; +module_param_named (mpath_policy, mpath_policy, int,0644 ); +MODULE_PARM_DESC (mpath_policy, + "Default multipath policy for new sessions (default: " + __stringify(MP_POLICY_MIN_INFLIGHT) +" (min-inflight), 0: round-robin, 1: min-inflight, 2: min-latency)" ); +static const struct rtrs_rdma_dev_pd_ops dev_pd_ops;static struct rtrs_rdma_dev_pd dev_pd = { .ops = &dev_pd_ops@@ -2758,7 +2765,7 @@ static struct rtrs_clt_sess *alloc_clt(const char *sessname, size_t paths_num, clt->max_reconnect_attempts = max_reconnect_attempts; clt->priv = priv; clt->link_ev = link_ev; - clt->mp_policy =MP_POLICY_MIN_INFLIGHT ; + clt->mp_policy = mpath_policy;strscpy (clt->sessname, sessname,sizeof (clt->sessname));init_waitqueue_head (&clt->permits_wait);mutex_init (&clt->paths_ev_mutex);@@ -3220,6 +3227,10 @@ static int __init rtrs_client_init(void)int ret =0 ;rtrs_rdma_dev_pd_init (0 , &dev_pd); + +/* Validate and clamp mpath_policy to valid range */ + mpath_policy =clamp (mpath_policy,MP_POLICY_RR ,MP_POLICY_MIN_LATENCY ); + ret =class_register (&rtrs_clt_dev_class);if (ret) {pr_err ("Failed to create rtrs-client dev class\n" );Signature · 1 line
2.43.0
Md Haris Iqbal
maintainerPATCH 2/9 RDMA/rtrs-clt: Fix refcount imbalance in rtrs_clt_write_req error path
In reply to Md Haris IqbalFrom: Jack Wang <[email protected]>
When commit bab9f8db4295 ("RDMA/rtrs-clt: Do local invalidate after write io completion") removed the chained LOCAL_INV WR for write requests, it deleted the matching refcount_inc(&req->ref) under the "req->mr->need_inval = true" assignment. The corresponding refcount_dec(&req->ref) in the rtrs_post_rdma_write_sg() error path was left behind, creating a refcount imbalance.
On synchronous post failure (e.g. -ENOMEM from ib_post_send()) the refcount drops from 1 to 0 via refcount_dec(), which is annotated to WARN ("decrement hit 0; leaking memory") because callers should use refcount_dec_and_test() in that situation. The req is then reset to 1 on the next rtrs_clt_init_req(), but the WARN still fires and the imbalance can race with an in-flight invalidate completion during failover.
Drop the orphan refcount_dec(); clearing need_inval is sufficient.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +1 -3
@@ -1163,10 +1163,8 @@ static int rtrs_clt_write_req(struct rtrs_clt_io_req *req) clt_path->hca_name, clt_path->hca_port);if (req->mp_policy ==MP_POLICY_MIN_INFLIGHT )atomic_dec (&clt_path->stats->inflight); -if (req->mr->need_inval) { +if (req->mr->need_inval) req->mr->need_inval = false; -refcount_dec (&req->ref); - }if (req->sg_cnt)ib_dma_unmap_sg (clt_path->s.dev->ib_dev, req->sglist, req->sg_cnt, req->dir);
Signature · 1 line
2.43.0
Md Haris Iqbal
maintainerPATCH 3/9 RDMA/rtrs-clt: Trigger error recovery when posting LOCAL_INV fails
In reply to Md Haris IqbalFrom: Jack Wang <[email protected]>
When ib_post_send() rejects the LOCAL_INV WR synchronously (e.g. -ENOMEM on a full SQ), no completion will ever fire, but complete_rdma_req() previously just logged the error and returned early via refcount_dec_and_test() (count goes 2->1, returns false). That left the request with need_inval=true forever, the rkey live on the HCA, the DMA mapping pinned, and req->conf never invoked.
A subsequent reuse of the same permit/req would call rtrs_clt_init_req() which blindly resets need_inval=false; combined with the still-live rkey on the HCA this is the kind of state mismatch that has previously surfaced as LOCAL_PROT_ERR.
On synchronous post failure: clear need_inval (we genuinely cannot invalidate from this context) and call rtrs_rdma_error_recovery() so the path goes to RECONNECTING, fail_all_outstanding_reqs() runs, and complete_rdma_req(can_wait=true) reaps the request cleanly with DMA unmap + failover. The refcount path is unchanged on success and now matches the success-path early-return shape on failure.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +13 -0
@@ -436,6 +436,19 @@ static void complete_rdma_req(struct rtrs_clt_io_req *req, int errno,if (err) {rtrs_err_rl (con->c.path,"Send INV WR key=%#x: %pe\n" , req->mr->rkey,ERR_PTR (err)); +/* +* No LOCAL_INV completion will fire, so the +* rkey is still live on the HCA but we cannot +* invalidate it from this context. Clear +* need_inval so subsequent reapers don't +* wait on an invalidate that will never +* happen, and kick off error recovery so the +* QP (and MR) is torn down cleanly via +* fail_all_outstanding_reqs() -> +* complete_rdma_req(can_wait=true). +*/ + req->mr->need_inval = false; +rtrs_rdma_error_recovery (con); }else if (can_wait) {wait_for_completion (&req->inv_comp); }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 3/9] RDMA/rtrs-clt: Trigger error recovery when posting LOCAL_INV fails
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] RDMA/rtrs-clt: early return in complete_rdma_req() leaks DMA mappings --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] RDMA/rtrs-clt: early return in complete_rdma_req() leaks DMA mappings
--
commit 61b2b66e033c3217c1bebe6348e99899004f5550
Author: Jack Wang <[email protected]>
RDMA/rtrs-clt: Trigger error recovery when posting LOCAL_INV fails
This commit clears req->mr->need_inval and triggers RDMA error recovery when rtrs_inv_rkey() fails synchronously in complete_rdma_req().
Quoted 14 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +6
-0@@ -436,6 +436,19 @@ static void complete_rdma_req(struct rtrs_clt_io_req *req, int errno,if (err) {rtrs_err_rl (con->c.path,"Send INV WR key=%#x: %pe\n" , req->mr->rkey,ERR_PTR (err)); +/* +* No LOCAL_INV completion will fire, so the +* rkey is still live on the HCA but we cannot +* invalidate it from this context. Clear +* need_inval so subsequent reapers don't +* wait on an invalidate that will never
drivers/infiniband/ulp/rtrs/rtrs-clt.c static void complete_rdma_req(struct rtrs_clt_io_req *req, int errno, · line 454
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +7
-0+* happen, and kick off error recovery so the +* QP (and MR) is torn down cleanly via +* fail_all_outstanding_reqs() -> +* complete_rdma_req(can_wait=true). +*/ + req->mr->need_inval = false; +rtrs_rdma_error_recovery (con); }else if (can_wait) {wait_for_completion (&req->inv_comp); }
[Severity: High]
Does complete_rdma_req() leak the DMA mapping on req->sglist when called from fail_all_outstanding_reqs() on an in-flight request that still has req->mr->need_inval set?
During recovery, rtrs_clt_stop_and_destroy_conns() drains QPs via stop_cm() and then runs fail_all_outstanding_reqs(), which calls complete_rdma_req() with can_wait = true and req->ref == 1. complete_rdma_req() increments req->ref to 2 before rtrs_inv_rkey(), and neither the if (err) branch (when posting to the stopped QP fails) nor the else if (can_wait) branch (where rtrs_clt_inv_rkey_done() only signals req->inv_comp without dropping a reference) decrements req->ref:
drivers/infiniband/ulp/rtrs/rtrs-clt.c:complete_rdma_req() {
...
refcount_inc(&req->ref);
err = rtrs_inv_rkey(req);
if (err) {
...
req->mr->need_inval = false;
rtrs_rdma_error_recovery(con);
} else if (can_wait) {
wait_for_completion(&req->inv_comp);
}
if (!refcount_dec_and_test(&req->ref))
return;
}
ib_dma_unmap_sg(clt_path->s.dev->ib_dev, req->sglist,
req->sg_cnt, req->dir);
...
}refcount_dec_and_test(&req->ref) drops req->ref from 2 to 1 and returns early, skipping ib_dma_unmap_sg() and the clt_path->stats->inflight decrement right before fail_all_outstanding_reqs() fails over or completes the request.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH 3/9] RDMA/rtrs-clt: Trigger error recovery when posting LOCAL_INV fails
Quoted 72 lines · On Mon, Nov 23, 2026 at 4:02 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] RDMA/rtrs-clt: early return incomplete_rdma_req()leaks DMA mappings
--commit
61b2b66e033c3217c1bebe6348e99899004f5550
Author: Jack Wang <[email protected]>RDMA/rtrs-clt: Trigger error recovery when posting
LOCAL_INVfailsThis commit clears
req->mr->need_invaland triggers RDMA error recovery whenrtrs_inv_rkey()fails synchronously incomplete_rdma_req().Quoted 14 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +6
-0@@ -436,6 +436,19 @@ static void complete_rdma_req(struct rtrs_clt_io_req *req, int errno,if (err) {rtrs_err_rl (con->c.path,"Send INV WR key=%#x: %pe\n" , req->mr->rkey,ERR_PTR (err)); +/* +* No LOCAL_INV completion will fire, so the +* rkey is still live on the HCA but we cannot +* invalidate it from this context. Clear +* need_inval so subsequent reapers don't +* wait on an invalidate that will never drivers/infiniband/ulp/rtrs/rtrs-clt.c static void complete_rdma_req(struct rtrs_clt_io_req *req, int errno, · line 454
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +7
-0+* happen, and kick off error recovery so the +* QP (and MR) is torn down cleanly via +* fail_all_outstanding_reqs() -> +* complete_rdma_req(can_wait=true). +*/ + req->mr->need_inval = false; +rtrs_rdma_error_recovery (con); }else if (can_wait) {wait_for_completion (&req->inv_comp); }[Severity: High]
Doescomplete_rdma_req()leak the DMA mapping onreq->sglistwhen called fromfail_all_outstanding_reqs()on an in-flight request that still hasreq->mr->need_invalset?During recovery,
rtrs_clt_stop_and_destroy_conns()drains QPs viastop_cm()and then runsfail_all_outstanding_reqs(), which callscomplete_rdma_req()withcan_wait= true andreq->ref== 1.complete_rdma_req()incrementsreq->refto 2 beforertrs_inv_rkey(), and neither the if (err) branch (when posting to the stopped QP fails) nor the else if (can_wait) branch (wherertrs_clt_inv_rkey_done()only signalsreq->inv_compwithout dropping a reference) decrementsreq->ref:drivers/infiniband/ulp/rtrs/rtrs-clt.c:complete_rdma_req() { ... refcount_inc(&req->ref); err = rtrs_inv_rkey(req); if (err) { ... req->mr->need_inval = false; rtrs_rdma_error_recovery(con); } else if (can_wait) { wait_for_completion(&req->inv_comp); } if (!refcount_dec_and_test(&req->ref)) return; } ib_dma_unmap_sg(clt_path->s.dev->ib_dev, req->sglist, req->sg_cnt, req->dir); ... }
Quoted 4 lines
refcount_dec_and_test(&req->ref)dropsreq->reffrom 2 to 1 and returns early, skippingib_dma_unmap_sg()and theclt_path->stats->inflightdecrement right beforefail_all_outstanding_reqs()fails over or completes the request.
This is a real bug. We verified it internally. And as mentioned, it is unrelated to the patch above.
We will send a separate patch for this bug.
Quoted 3 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Signature · 2 lines
Regards -Haris
Md Haris Iqbal
maintainerPATCH 4/9 RDMA/rtrs-srv: Fix processing messages for Big-Endian archs
In reply to Md Haris IqbalFrom: Grzegorz Prajsner <[email protected]>
Convert msg->sg_cnt from le16 to cpu endianness before processing it. This fixes bug processing messages on Big-Endian architectures.
--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +3 -2
@@ -1045,7 +1045,7 @@ static void process_read(struct rtrs_srv_con *con,struct rtrs_srv_ctx *ctx = srv->ctx;struct rtrs_srv_op *id; -size_t usr_len, data_len; +size_t usr_len, data_len, sg_cnt;void *data;int ret;
@@ -1055,7 +1055,8 @@ static void process_read(struct rtrs_srv_con *con, rtrs_srv_state_str(srv_path->state));return ; } -if (msg->sg_cnt !=1 && msg->sg_cnt !=0 ) { + sg_cnt =le16_to_cpu (msg->sg_cnt); +if (sg_cnt !=1 && sg_cnt !=0 ) {rtrs_err_rl (s,"Processing read request failed, invalid message\n" );return ;
Signature · 1 line
2.43.0
Md Haris Iqbal
maintainerPATCH 5/9 RDMA/rtrs-clt: rename pathname parameter to sessname in rtrs_clt_open()
In reply to Md Haris IqbalFrom: Danil Kipnis <[email protected]>
The parameter has always referred to the RTRS session name, not a filesystem path. Rename it to sessname throughout the API declaration in rtrs.h and the implementation in rtrs-clt.c for clarity.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 10 +++++----- drivers/infiniband/ulp/rtrs/rtrs.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +5 -5
@@ -2832,7 +2832,7 @@ static void free_clt(struct rtrs_clt_sess *clt)/** * rtrs_clt_open() - Open a path to an RTRS server * @ops: holds the link event callback and the private pointer. -* @pathname: name of the path to an RTRS server +* @sessname: name of the RTRS session * @paths: Paths to be established defined by their src and dst addresses * @paths_num: Number of elements in the @paths array * @port: port to be used by the RTRS session
@@ -2848,7 +2848,7 @@ static void free_clt(struct rtrs_clt_sess *clt)* Return a valid pointer on success otherwise PTR_ERR. */ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, - const char *pathname, + const char *sessname, const struct rtrs_addr *paths, size_t paths_num, u16 port, size_t pdu_sz, u8 reconnect_delay_sec,
@@ -2858,13 +2858,13 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,struct rtrs_clt_sess *clt;int err, i; -if (strchr (pathname,'/' ) ||strchr (pathname,'.' )) { -pr_err ("pathname cannot contain / and .\n" ); +if (strchr (sessname,'/' ) ||strchr (sessname,'.' )) { +pr_err ("sessname cannot contain / and .\n" ); err = -EINVAL ; goto out; } - clt =alloc_clt (pathname, paths_num, port, pdu_sz, ops->priv, + clt =alloc_clt (sessname, paths_num, port, pdu_sz, ops->priv, ops->link_ev, reconnect_delay_sec, max_reconnect_attempts);
drivers/infiniband/ulp/rtrs/rtrs.h +1 -1
@@ -55,7 +55,7 @@ struct rtrs_clt_ops { }; struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, - const char *pathname, + const char *sessname, const struct rtrs_addr *paths, size_t path_cnt, u16 port, size_t pdu_sz, u8 reconnect_delay_sec,
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 5/9] RDMA/rtrs-clt: rename pathname parameter to sessname in rtrs_clt_open()
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] RDMA/rtrs-clt: use-after-free in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] RDMA/rtrs-clt: use-after-free in rtrs_clt_open() [1] --
commit d270a6058ae45a4fbd952be02c065eb235215fda
Author: Danil Kipnis <[email protected]>
RDMA/rtrs-clt: rename pathname parameter to sessname in rtrs_clt_open()
This commit renames the pathname parameter of rtrs_clt_open() to sessname in the header declaration and implementation.
Quoted 4 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0
-0
[ ... ]
Quoted 16 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2
-3@@ -2848,7 +2848,7 @@ static void free_clt(struct rtrs_clt_sess *clt)* Return a valid pointer on success otherwise PTR_ERR. */ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, - const char *pathname, + const char *sessname, const struct rtrs_addr *paths, size_t paths_num, u16 port, size_t pdu_sz, u8 reconnect_delay_sec,@@ -2858,13 +2858,13 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,struct rtrs_clt_sess *clt;int err, i; -if (strchr (pathname,'/' ) ||strchr (pathname,'.' )) { -pr_err ("pathname cannot contain / and .\n" ); +if (strchr (sessname,'/' ) ||strchr (sessname,'.' )) {
drivers/infiniband/ulp/rtrs/rtrs-clt.c struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, · line 2870
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2
-1+pr_err ("sessname cannot contain / and .\n" ); err = -EINVAL ; goto out; } - clt =alloc_clt (pathname, paths_num, port, pdu_sz, ops->priv, + clt =alloc_clt (sessname, paths_num, port, pdu_sz, ops->priv, ops->link_ev, reconnect_delay_sec, max_reconnect_attempts);
[Severity: Critical]
This problem wasn't introduced by this patch, but can a failure in rtrs_clt_create_path_files() later in rtrs_clt_open() cause a use-after-free and double free of clt_path [1]?
When kobject_init_and_add() fails in rtrs_clt_create_path_files(), it calls kobject_put(&clt_path->kobj), which invokes rtrs_clt_path_release() and frees clt_path via free_path():
drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c:rtrs_clt_create_path_files() {
...
err = kobject_init_and_add(&clt_path->kobj, &ktype_sess,
clt->kobj_paths,
"%s", str);
if (err) {
pr_err("kobject_init_and_add: %pe\n", ERR_PTR(err));
kobject_put(&clt_path->kobj);
return err;
}
...
}rtrs_clt_open() then touches the freed clt_path in list_del_rcu(), rtrs_clt_close_conns(), and free_percpu() before calling free_path() a second time:
drivers/infiniband/ulp/rtrs/rtrs-clt.c:rtrs_clt_open() {
...
err = rtrs_clt_create_path_files(clt_path);
if (err) {
list_del_rcu(&clt_path->s.entry);
rtrs_clt_close_conns(clt_path, true);
free_percpu(clt_path->stats->pcpu_stats);
free_path(clt_path);
goto close_all_path;
}
...
}[1] https://sashiko.dev/#/bug/linux-982ecccb-b1ca-401f-8293-d1973992f3f6
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH 5/9] RDMA/rtrs-clt: rename pathname parameter to sessname in rtrs_clt_open()
Quoted 75 lines · On Mon, Nov 23, 2026 at 3:42 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] RDMA/rtrs-clt: use-after-free inrtrs_clt_open()[1] --commit
d270a6058ae45a4fbd952be02c065eb235215fda
Author: Danil Kipnis <[email protected]>RDMA/rtrs-clt: rename pathname parameter to sessname in
rtrs_clt_open()This commit renames the pathname parameter of
rtrs_clt_open()to sessname in the header declaration and implementation.Quoted 4 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0
-0[ ... ]
Quoted 16 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2
-3@@ -2848,7 +2848,7 @@ static void free_clt(struct rtrs_clt_sess *clt)* Return a valid pointer on success otherwise PTR_ERR. */ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, - const char *pathname, + const char *sessname, const struct rtrs_addr *paths, size_t paths_num, u16 port, size_t pdu_sz, u8 reconnect_delay_sec,@@ -2858,13 +2858,13 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,struct rtrs_clt_sess *clt;int err, i; -if (strchr (pathname,'/' ) ||strchr (pathname,'.' )) { -pr_err ("pathname cannot contain / and .\n" ); +if (strchr (sessname,'/' ) ||strchr (sessname,'.' )) {drivers/infiniband/ulp/rtrs/rtrs-clt.c struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, · line 2870
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +2
-1+pr_err ("sessname cannot contain / and .\n" ); err = -EINVAL ; goto out; } - clt =alloc_clt (pathname, paths_num, port, pdu_sz, ops->priv, + clt =alloc_clt (sessname, paths_num, port, pdu_sz, ops->priv, ops->link_ev, reconnect_delay_sec, max_reconnect_attempts);[Severity: Critical]
This problem wasn't introduced by this patch, but can a failure inrtrs_clt_create_path_files()later inrtrs_clt_open()cause a use-after-free and double free ofclt_path[1]?When
kobject_init_and_add()fails inrtrs_clt_create_path_files(), it callskobject_put(&clt_path->kobj), which invokesrtrs_clt_path_release()and freesclt_pathviafree_path():drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c:rtrs_clt_create_path_files() { ... err = kobject_init_and_add(&clt_path->kobj, &ktype_sess, clt->kobj_paths, "%s", str); if (err) { pr_err("kobject_init_and_add: %pe\n", ERR_PTR(err)); kobject_put(&clt_path->kobj); return err; } ... }
rtrs_clt_open()then touches the freedclt_pathinlist_del_rcu(),rtrs_clt_close_conns(), andfree_percpu()before callingfree_path()a second time:
Quoted 12 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c:rtrs_clt_open() {
...
err = rtrs_clt_create_path_files(clt_path);
if (err) {
list_del_rcu(&clt_path->s.entry);
rtrs_clt_close_conns(clt_path, true);
free_percpu(clt_path->stats->pcpu_stats);
free_path(clt_path);
goto close_all_path;
}
...
}This is the same bug being discussed here.
https://lore.kernel.org/linux-rdma/AB*APAAaLFrQFfZxcNOqk4oI.3.1795529068345.Hmail.202321181@mail.sdu.edu.cn/
We will send a patch soon.
Quoted 5 lines
[1] https://sashiko.dev/#/bug/linux-982ecccb-b1ca-401f-8293-d1973992f3f6
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Signature · 2 lines
Regards -Haris
Md Haris Iqbal
maintainerPATCH 6/9 RDMA/rtrs-clt: Fix reconnect jitter being applied in milliseconds
In reply to Md Haris IqbalRTRS_RECONNECT_SEED was introduced to spread reconnect attempts of different clients over an 8 second window, so that a major network outage does not make all of them hammer the server at the same moment.
The random value is however added to delay_ms, which is already in milliseconds, before the sum is converted with msecs_to_jiffies():
delay_ms = clt->reconnect_delay_sec * 1000; queue_delayed_work(rtrs_wq, &clt_path->reconnect_dwork, msecs_to_jiffies(delay_ms + get_random_u32_below(RTRS_RECONNECT_SEED)));
With the seed defined as 8, the jitter is therefore 0 to 7 milliseconds instead of the intended 0 to 8 seconds, which is far too small to stagger reconnects and leaves the thundering herd it was meant to prevent.
Define the seed in milliseconds, matching RTRS_RECONNECT_BACKOFF and the unit of the expression it is added to, and reword the comment to state the resulting half open range.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +5 -3
@@ -26,11 +26,13 @@*/ #define RTRS_RECONNECT_BACKOFF 1000/* -* Wait for additional random time between 0 and 8 seconds +* Wait for additional random time in the range [0, 8) seconds * before starting to reconnect to avoid clients reconnecting -* all at once in case of a major network outage +* all at once in case of a major network outage. +* Expressed in milliseconds, like RTRS_RECONNECT_BACKOFF, since +* it is added to a millisecond delay before conversion to jiffies. */ -#define RTRS_RECONNECT_SEED 8 +#define RTRS_RECONNECT_SEED 8000#define FIRST_CONN 0x01/* limit to 128 * 4k = 512k max IO */
Signature · 1 line
2.43.0
Md Haris Iqbal
maintainerPATCH 7/9 RDMA/rtrs-clt: Back off the reconnect delay exponentially
In reply to Md Haris IqbalFrom: Danil Kipnis <[email protected]>
A path that loses its link waits out the full, flat reconnect_delay_sec (30s on rnbd, + 0-8s jitter) before its first retry, and every retry after that, no matter how quickly the far end actually comes back. Nothing about that delay depends on how the path went down:rtrs_clt_err_recovery_work() runs the same way whether the trigger was a CM disconnect, a heartbeat timeout, or a port error, so a transient blip pays the same price as a genuinely dead fabric.
Start the delay at RTRS_RECONNECT_BACKOFF_INIT_MS (1s) after the first failure and double it on each further consecutive failure, capped at the configured reconnect_delay_sec, which becomes the steady-state ceiling rather than a constant. reconnect_attempts already counts consecutive failures since the path last came up and already resets to 0 in rtrs_clt_path_up() on success, so it doubles as the backoff step with no new per-path state. The existing anti-herd jitter (RTRS_RECONNECT_SEED) is kept as-is on top of every step. RTRS_RECONNECT_BACKOFF_MAX_SHIFT (8) only bounds the shift below reconnect_delay_sec's u8 range (max 255s); it is a safety margin, not a behavior knob.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 35 ++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +33 -2
@@ -34,6 +34,26 @@*/ #define RTRS_RECONNECT_SEED 8000 +/* +* Delay before the first reconnect attempt after a failure, doubled on each +* further consecutive failure and capped at reconnect_delay_sec. Lets a path +* that recovers quickly (a transient CM error, a brief port flap) start +* retrying off this short initial delay instead of the full configured +* delay, while a path facing a genuinely dead fabric still settles at the +* same steady state as before. RTRS_RECONNECT_SEED jitter is added on top +* of every attempt as before, so the actual first retry lands anywhere in +* [RTRS_RECONNECT_BACKOFF_INIT_MS, RTRS_RECONNECT_BACKOFF_INIT_MS + +* RTRS_RECONNECT_SEED). +*/ +/* Matches RTRS_RECONNECT_BACKOFF's value by coincidence, not by shared purpose. */ +#define RTRS_RECONNECT_BACKOFF_INIT_MS 1000 +/* +* Shifting RTRS_RECONNECT_BACKOFF_INIT_MS by more than this always exceeds +* reconnect_delay_sec's range (u8, so at most 255000 ms); capping the shift +* avoids relying on shift-by-large-amount being well defined. +*/ +#define RTRS_RECONNECT_BACKOFF_MAX_SHIFT 8 +#define FIRST_CONN 0x01/* limit to 128 * 4k = 512k max IO */ #define RTRS_MAX_SEGMENTS 128
@@ -1537,11 +1557,22 @@ static void rtrs_clt_err_recovery_work(struct work_struct *work) {struct rtrs_clt_path *clt_path;struct rtrs_clt_sess *clt; -int delay_ms; +unsigned int shift; +u32 delay_ms; clt_path = container_of(work, struct rtrs_clt_path, err_recovery_work); clt = clt_path->clt; - delay_ms = clt->reconnect_delay_sec *1000 ; +/* +* reconnect_attempts counts consecutive failures since the path last +* came up (rtrs_clt_path_up() resets it to 0), so it doubles as the +* backoff step: 0 failures so far -> the initial delay, each further +* failure doubles it, capped once it reaches the configured steady +* state delay. +*/ + shift = min_t(unsigned int, clt_path->reconnect_attempts, +RTRS_RECONNECT_BACKOFF_MAX_SHIFT ); + delay_ms =min_t (u32, clt->reconnect_delay_sec *1000 , +RTRS_RECONNECT_BACKOFF_INIT_MS << shift);rtrs_clt_stop_and_destroy_conns (clt_path); queue_delayed_work(rtrs_wq, &clt_path->reconnect_dwork, msecs_to_jiffies(delay_ms +
Signature · 1 line
2.43.0
Re: [PATCH 7/9] RDMA/rtrs-clt: Back off the reconnect delay exponentially
Quoted 72 lines · Md Haris Iqbal
From: Danil Kipnis <[email protected]>
A path that loses its link waits out the full, flat
reconnect_delay_sec(30s on rnbd, + 0-8s jitter) before its first retry, and every retry after that, no matter how quickly the far end actually comes back. Nothing about that delay depends on how the path went down:rtrs_clt_err_recovery_work()runs the same way whether the trigger was a CM disconnect, a heartbeat timeout, or a port error, so a transient blip pays the same price as a genuinely dead fabric.Start the delay at
RTRS_RECONNECT_BACKOFF_INIT_MS(1s) after the first failure and double it on each further consecutive failure, capped at the configuredreconnect_delay_sec, which becomes the steady-state ceiling rather than a constant.reconnect_attemptsalready counts consecutive failures since the path last came up and already resets to 0 inrtrs_clt_path_up()on success, so it doubles as the backoff step with no new per-path state. The existing anti-herd jitter (RTRS_RECONNECT_SEED) is kept as-is on top of every step.RTRS_RECONNECT_BACKOFF_MAX_SHIFT(8) only bounds the shift below reconnect_delay_sec's u8 range (max 255s); it is a safety margin, not a behavior knob.Signed-off-by Danil Kipnis <[email protected]>Reviewed-by Md Haris Iqbal <[email protected]>Signed-off-by Jack Wang <[email protected]>Signed-off-by Md Haris Iqbal <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 35 ++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-clt.c +23
-2@@ -34,6 +34,26 @@*/ #define RTRS_RECONNECT_SEED 8000 +/* +* Delay before the first reconnect attempt after a failure, doubled on each +* further consecutive failure and capped at reconnect_delay_sec. Lets a path +* that recovers quickly (a transient CM error, a brief port flap) start +* retrying off this short initial delay instead of the full configured +* delay, while a path facing a genuinely dead fabric still settles at the +* same steady state as before. RTRS_RECONNECT_SEED jitter is added on top +* of every attempt as before, so the actual first retry lands anywhere in +* [RTRS_RECONNECT_BACKOFF_INIT_MS, RTRS_RECONNECT_BACKOFF_INIT_MS + +* RTRS_RECONNECT_SEED). +*/ +/* Matches RTRS_RECONNECT_BACKOFF's value by coincidence, not by shared purpose. */ +#define RTRS_RECONNECT_BACKOFF_INIT_MS 1000 +/* +* Shifting RTRS_RECONNECT_BACKOFF_INIT_MS by more than this always exceeds +* reconnect_delay_sec's range (u8, so at most 255000 ms); capping the shift +* avoids relying on shift-by-large-amount being well defined. +*/ +#define RTRS_RECONNECT_BACKOFF_MAX_SHIFT 8 +#define FIRST_CONN 0x01/* limit to 128 * 4k = 512k max IO */ #define RTRS_MAX_SEGMENTS 128@@ -1537,11 +1557,22 @@ static void rtrs_clt_err_recovery_work(struct work_struct *work) {struct rtrs_clt_path *clt_path;struct rtrs_clt_sess *clt; -int delay_ms; +unsigned int shift; +u32 delay_ms; clt_path = container_of(work, struct rtrs_clt_path, err_recovery_work); clt = clt_path->clt; - delay_ms = clt->reconnect_delay_sec *1000 ; +/*
drivers/infiniband/ulp/rtrs/rtrs-clt.c static void rtrs_clt_err_recovery_work(struct work_struct *work) · line 1575
Quoted 10 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +10
-0+* reconnect_attempts counts consecutive failures since the path last +* came up (rtrs_clt_path_up() resets it to 0), so it doubles as the +* backoff step: 0 failures so far -> the initial delay, each further +* failure doubles it, capped once it reaches the configured steady +* state delay. +*/ + shift = min_t(unsigned int, clt_path->reconnect_attempts, +RTRS_RECONNECT_BACKOFF_MAX_SHIFT ); + delay_ms =min_t (u32, clt->reconnect_delay_sec *1000 , +RTRS_RECONNECT_BACKOFF_INIT_MS << shift);
Please avoid the min_t() and max_t() macros, as they implicitly cast operands of different types. Use the correct types from the beginning.
Thanks
Quoted 7 lines
drivers/infiniband/ulp/rtrs/rtrs-clt.c +0
-0rtrs_clt_stop_and_destroy_conns (clt_path); queue_delayed_work(rtrs_wq, &clt_path->reconnect_dwork, msecs_to_jiffies(delay_ms +Signature · 1 line
2.43.0
Md Haris Iqbal
maintainerPATCH 8/9 RDMA/rtrs-srv: Snapshot the READ request header instead of reusing it
In reply to Md Haris IqbalFrom: Benjamin Stürz <[email protected]>
process_read() validates the READ request header and then keeps a pointer to it in srv->chunks[buf_id]. The client's permits normally keep that chunk stable until the server responds, but the server does not enforce it: once the client gives up on a request and releases the permit, the chunk is reused for an unrelated I/O, while a slow backend can leave the original operation in flight on a path the server has not yet declared dead.
rdma_write_sg(), send_io_resp_imm() and rtrs_srv_resp_rdma() re-read sg_cnt, the invalidate flag and the descriptor from there at completion time, so they act on whatever now lives at that offset. The RDMA write can then go to another request's remote address with its length and rkey, or the response can invalidate the wrong rkey.
Snapshot sg_cnt, the invalidate flag and the descriptor into rtrs_srv_op when the request arrives, and drop rd_msg. The WRITE path reads none of them, so nothing needs clearing there.
--- drivers/infiniband/ulp/rtrs/rtrs-srv.c | 33 ++++++++++++++------------ drivers/infiniband/ulp/rtrs/rtrs-srv.h | 13 +++++++++- 2 files changed, 30 insertions(+), 16 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-srv.c +18 -15
@@ -210,8 +210,8 @@ static int rdma_write_sg(struct rtrs_srv_op *id)struct ib_sge *plist;struct ib_sge list; - sg_cnt =le16_to_cpu (id->rd_msg->sg_cnt); - need_inval =le16_to_cpu (id->rd_msg->flags) &RTRS_MSG_NEED_INVAL_F ; + sg_cnt = id->sg_cnt; + need_inval = id->need_inval;if (sg_cnt !=1 )return -EINVAL ;
@@ -220,7 +220,7 @@ static int rdma_write_sg(struct rtrs_srv_op *id) wr = &id->tx_wr; plist = &id->tx_sg; plist->addr = dma_addr + offset; - plist->length =le32_to_cpu (id->rd_msg->desc[0 ].len); + plist->length =le32_to_cpu (id->desc.len);/* WR will fail with length error * if this is 0
@@ -236,8 +236,8 @@ static int rdma_write_sg(struct rtrs_srv_op *id) wr->wr.sg_list = plist; wr->wr.num_sge =1 ; - wr->remote_addr =le64_to_cpu (id->rd_msg->desc[0 ].addr); - wr->rkey =le32_to_cpu (id->rd_msg->desc[0 ].key); + wr->remote_addr =le64_to_cpu (id->desc.addr); + wr->rkey =le32_to_cpu (id->desc.key); wr->wr.opcode =IB_WR_RDMA_WRITE ; wr->wr.wr_cqe = &io_comp_cqe;
@@ -347,15 +347,10 @@ static int send_io_resp_imm(struct rtrs_srv_con *con, struct rtrs_srv_op *id,int err;if (id->dir ==READ ) { -struct rtrs_msg_rdma_read *rd_msg = id->rd_msg; -size_t sg_cnt; - - need_inval =le16_to_cpu (rd_msg->flags) & -RTRS_MSG_NEED_INVAL_F ; - sg_cnt =le16_to_cpu (rd_msg->sg_cnt); + need_inval = id->need_inval;if (need_inval) { -if (sg_cnt) { +if (id->sg_cnt) { inv_wr.wr_cqe = &io_comp_cqe; inv_wr.sg_list =NULL ; inv_wr.num_sge =0 ;
@@ -363,7 +358,7 @@ static int send_io_resp_imm(struct rtrs_srv_con *con, struct rtrs_srv_op *id, inv_wr.send_flags =0 ;/* Only one key is actually used */ inv_wr.ex.invalidate_rkey = -le32_to_cpu (rd_msg->desc[0 ].key); +le32_to_cpu (id->desc.key); }else {WARN_ON_ONCE (1 ); need_inval = false;
@@ -512,7 +507,7 @@ bool rtrs_srv_resp_rdma(struct rtrs_srv_op *id, int status)return false; } -if (status || id->dir ==WRITE || !id->rd_msg->sg_cnt) +if (status || id->dir ==WRITE || !id->sg_cnt) err =send_io_resp_imm (con, id, status);else err =rdma_write_sg (id);
@@ -1072,7 +1067,15 @@ static void process_read(struct rtrs_srv_con *con, id->con = con; id->dir =READ ; id->msg_id = buf_id; - id->rd_msg = msg; +/* +* Take a private copy of everything we still need once the I/O +* completes: by then the chunk is not guaranteed to still hold +* this request's header, see struct rtrs_srv_op. +*/ + id->sg_cnt = sg_cnt; + id->need_inval =le16_to_cpu (msg->flags) &RTRS_MSG_NEED_INVAL_F ; +if (sg_cnt) + id->desc = msg->desc[0 ]; data_len = off - usr_len; data =page_address (srv->chunks[buf_id]); ret = ctx->ops.rdma_ev(srv->priv, id, data, data_len,
drivers/infiniband/ulp/rtrs/rtrs-srv.h +12 -1
@@ -52,7 +52,18 @@ struct rtrs_srv_op {struct rtrs_srv_con *con;u32 msg_id;u8 dir; -struct rtrs_msg_rdma_read *rd_msg; +/* +* Snapshot of the READ request header, taken when the request is +* received and validated. The client's permits normally keep the +* chunk stable until we respond, but that is the client's +* bookkeeping and not something we enforce: reconnect and failover +* edge cases can leave the chunk rewritten by a newer request while +* this I/O is still running. The completion path must use this copy +* and never read srv->chunks[msg_id] back. +*/ +bool need_inval; +u16 sg_cnt; +struct rtrs_sg_desc desc;struct ib_rdma_wr tx_wr;struct ib_sge tx_sg;struct list_head wait_list;
Signature · 1 line
2.43.0
Md Haris Iqbal
maintainerPATCH 9/9 RDMA/rtrs-clt: Close all paths before freeing any in rtrs_clt_close()
In reply to Md Haris Iqbalrtrs_clt_close() closes and frees the paths one at a time. Meanwhile, the paths that are not closed yet can still walk clt->paths_list: a reconnect fires link_ev(RECONNECTED), whose handler calls rtrs_clt_query(), and a closing path fails its requests over through rtrs_clt_failover_req(). Either can then touch a path that is already freed:
BUG: KASAN: slab-use-after-free in rtrs_clt_query Workqueue: rtrs_client_wq rtrs_clt_reconnect_work rtrs_clt_query rnbd_clt_link_ev init_path rtrs_clt_reconnect_work
Move every path to CLOSING first, wait for all close works, and only then unlink and free the paths. A close work cancels the reconnect work of its path synchronously, so no path is freed while another one still uses the list.
rtrs_clt_open() tears down its paths on error the same way, so move the sequence into rtrs_clt_destroy_all_paths() and use it from both, with sysfs torn down first.
--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 49 ++++++++++++++++++-------- 1 file changed, 34 insertions(+), 15 deletions(-)
drivers/infiniband/ulp/rtrs/rtrs-clt.c +34 -15
@@ -2862,6 +2862,38 @@ static void free_clt(struct rtrs_clt_sess *clt)device_unregister (&clt->dev); } +/* +* Close and free every path of @clt. The caller has torn down sysfs, so +* no paths can be added or removed, and does not use the session any more +* (no IO, no rtrs_clt_query()). +* +* Until its close work has finished, a path can still reconnect (firing +* link_ev, whose user may call rtrs_clt_query()) or fail requests over, +* and both walk clt->paths_list. So move every path to CLOSING first, +* which keeps further reconnect attempts from starting, wait for all of +* them, and only then free. +*/ +static void rtrs_clt_destroy_all_paths (struct rtrs_clt_sess *clt) +{ +struct rtrs_clt_path *clt_path, *tmp; + +list_for_each_entry (clt_path, &clt->paths_list, s.entry) +rtrs_clt_close_conns (clt_path, false); +list_for_each_entry (clt_path, &clt->paths_list, s.entry) +flush_work (&clt_path->close_work); + +/* +* The close works have flushed every reconnect and stopped the +* heartbeat, and the caller issues nothing, so nobody walks the list +* any more and no grace period is needed. +*/ +list_for_each_entry_safe (clt_path, tmp, &clt->paths_list, s.entry) { +list_del (&clt_path->s.entry); +rtrs_clt_destroy_path_files (clt_path,NULL ); +kobject_put (&clt_path->kobj); + } +} +/** * rtrs_clt_open() - Open a path to an RTRS server * @ops: holds the link event callback and the private pointer.
@@ -2887,7 +2919,6 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, size_t pdu_sz, u8 reconnect_delay_sec, s16 max_reconnect_attempts, u32 nr_poll_queues) { - struct rtrs_clt_path *clt_path, *tmp; struct rtrs_clt_sess *clt;int err, i;
@@ -2943,12 +2974,8 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,return clt; close_all_path: -list_for_each_entry_safe (clt_path, tmp, &clt->paths_list, s.entry) { -rtrs_clt_destroy_path_files (clt_path,NULL ); -rtrs_clt_close_conns (clt_path, true); -kobject_put (&clt_path->kobj); - }rtrs_clt_destroy_sysfs_root (clt); +rtrs_clt_destroy_all_paths (clt);free_clt (clt); out:
@@ -2962,17 +2989,9 @@ EXPORT_SYMBOL(rtrs_clt_open);*/ void rtrs_clt_close (struct rtrs_clt_sess *clt) { -struct rtrs_clt_path *clt_path, *tmp; -/* Firstly forbid sysfs access */ rtrs_clt_destroy_sysfs_root (clt); - -/* Now it is safe to iterate over all paths without locks */ -list_for_each_entry_safe (clt_path, tmp, &clt->paths_list, s.entry) { -rtrs_clt_close_conns (clt_path, true); -rtrs_clt_destroy_path_files (clt_path,NULL ); -kobject_put (&clt_path->kobj); - } +rtrs_clt_destroy_all_paths (clt);free_permits (clt);free_clt (clt); }
Signature · 1 line
2.43.0
Re: [PATCH 9/9] RDMA/rtrs-clt: Close all paths before freeing any in rtrs_clt_close()
Quoted 6 lines · Md Haris Iqbal
rtrs_clt_close()closes and frees the paths one at a time. Meanwhile, the paths that are not closed yet can still walkclt->paths_list: a reconnect fireslink_ev(RECONNECTED), whose handler callsrtrs_clt_query(), and a closing path fails its requests over throughrtrs_clt_failover_req(). Either can then touch a path that is already freed:
Quoted 6 lines
BUG: KASAN: slab-use-after-free in rtrs_clt_query Workqueue: rtrs_client_wq rtrs_clt_reconnect_work rtrs_clt_query rnbd_clt_link_ev init_path rtrs_clt_reconnect_work
Please include the full dmesg stack trace in commit messages for RDMA-related changes.
Thanks
Quoted 106 lines
Move every path to CLOSING first, wait for all close works, and only then unlink and free the paths. A close work cancels the reconnect work of its path synchronously, so no path is freed while another one still uses the list.
rtrs_clt_open()tears down its paths on error the same way, so move the sequence intortrs_clt_destroy_all_paths()and use it from both, with sysfs torn down first.Fixes 6a98d71daea1 ("RDMA/rtrs: client: main functionality")Reported-by Shuangpeng Bai <[email protected]>Signed-off-by Md Haris Iqbal <[email protected]>--- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 49 ++++++++++++++++++-------- 1 file changed, 34 insertions(+), 15 deletions(-)drivers/infiniband/ulp/rtrs/rtrs-clt.c +34
-15@@ -2862,6 +2862,38 @@ static void free_clt(struct rtrs_clt_sess *clt)device_unregister (&clt->dev); } +/* +* Close and free every path of @clt. The caller has torn down sysfs, so +* no paths can be added or removed, and does not use the session any more +* (no IO, no rtrs_clt_query()). +* +* Until its close work has finished, a path can still reconnect (firing +* link_ev, whose user may call rtrs_clt_query()) or fail requests over, +* and both walk clt->paths_list. So move every path to CLOSING first, +* which keeps further reconnect attempts from starting, wait for all of +* them, and only then free. +*/ +static void rtrs_clt_destroy_all_paths (struct rtrs_clt_sess *clt) +{ +struct rtrs_clt_path *clt_path, *tmp; + +list_for_each_entry (clt_path, &clt->paths_list, s.entry) +rtrs_clt_close_conns (clt_path, false); +list_for_each_entry (clt_path, &clt->paths_list, s.entry) +flush_work (&clt_path->close_work); + +/* +* The close works have flushed every reconnect and stopped the +* heartbeat, and the caller issues nothing, so nobody walks the list +* any more and no grace period is needed. +*/ +list_for_each_entry_safe (clt_path, tmp, &clt->paths_list, s.entry) { +list_del (&clt_path->s.entry); +rtrs_clt_destroy_path_files (clt_path,NULL ); +kobject_put (&clt_path->kobj); + } +} +/** * rtrs_clt_open() - Open a path to an RTRS server * @ops: holds the link event callback and the private pointer. @@ -2887,7 +2919,6 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops, size_t pdu_sz, u8 reconnect_delay_sec, s16 max_reconnect_attempts, u32 nr_poll_queues) { - struct rtrs_clt_path *clt_path, *tmp; struct rtrs_clt_sess *clt;int err, i;@@ -2943,12 +2974,8 @@ struct rtrs_clt_sess *rtrs_clt_open(struct rtrs_clt_ops *ops,return clt; close_all_path: -list_for_each_entry_safe (clt_path, tmp, &clt->paths_list, s.entry) { -rtrs_clt_destroy_path_files (clt_path,NULL ); -rtrs_clt_close_conns (clt_path, true); -kobject_put (&clt_path->kobj); - }rtrs_clt_destroy_sysfs_root (clt); +rtrs_clt_destroy_all_paths (clt);free_clt (clt); out:@@ -2962,17 +2989,9 @@ EXPORT_SYMBOL(rtrs_clt_open);*/ void rtrs_clt_close (struct rtrs_clt_sess *clt) { -struct rtrs_clt_path *clt_path, *tmp; -/* Firstly forbid sysfs access */ rtrs_clt_destroy_sysfs_root (clt); - -/* Now it is safe to iterate over all paths without locks */ -list_for_each_entry_safe (clt_path, tmp, &clt->paths_list, s.entry) { -rtrs_clt_close_conns (clt_path, true); -rtrs_clt_destroy_path_files (clt_path,NULL ); -kobject_put (&clt_path->kobj); - } +rtrs_clt_destroy_all_paths (clt);free_permits (clt);free_clt (clt); }Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has finished reviewing this 9-patch series:
Sashiko has finished reviewing this 9-patch series:
- Patches 2, 4, and 6-9: no issues found.
- Patch 1 ("RDMA/rtrs-clt: Add mpath_policy module parameter"): 2 potential issues (1 Medium, 1 Low)
- Patch 3 ("RDMA/rtrs-clt: Trigger error recovery when posting L..."): 1 potential issue (1 High)
- Patch 5 ("RDMA/rtrs-clt: rename pathname parameter to sessname..."): 1 related pre-existing bug noted
Detailed reviews have been sent as separate replies to patches 1, 3, and 5.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]