From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796312369; b=e1FrbrUTpy2U7qYZgXWoDC5axD37G1gcVmnCXmbDLIIwCLOEYDhk/akvmKmX+EUhUlME wuwmysqkVlf55HjfbRUN7+JOFYCVcRdwzMtjuTcFOp5xySpgLmBwoEOUSdK6lsezkp0bL T4qlIZJsUd9HyLHnTUcDJdnhlWIYOMKHssZprIlqHyBN2VAcyEW0xf8Vhq+ISVE+pZD2c BsILzqKu+aT1B6iBZ553Vvv9QmS3vkBqaxWu2Ni0Mq8149ty0xamiejhticw8BYLD093i WtXSkqhRE+DAGntuO1WGINfrsRIlWSCsPP/LNjbZBqmt6B6ebcINXuA79XP7WgFuChg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796312369; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=LFPUVnmPi2MXroNBd9inVRAd/IrfbFBuAUh6uK4HCEc=; b=ry7zMXxfaRiP1wP0DD2RlIfpvxt8XCF3EFemspIAzT5tv1yg6pOIpvgD8bnojUh242F+ 5LxGcfgHuVjIWoAv3xthkAAfPppzUMYJyfOrPHns2hXrHdSruYxignqzz+VD99TmYlZse JV9pwSE6PN355ZAl7LU503HeqGskq6+g3QjOrkJmNiBOZr04940NNxIMNFbhEeZiB2a2Q bmj+5tDLxw+U97J/FXFYoBgjD7vYH4RYX9KRRJUxcdtXUGQZkSogmiYUUspPqYCj4pcaH fdyPQ6knDy1EEsFedYVNGWesaO/Y61Hec4vZorWir4REdh0BSJt0Y0WuNseF1sdOFhg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=S43e7TpV; arc=none smtp.remote-ip=74.125.82.46 Received: from mail-dl1-f46.google.com (mail-dl1-f46.google.com [74.125.82.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2442606A330 for ; Thu, 3 Dec 2026 15:39:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F2442606A330 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.a=rsa-sha256 header.s=20260707 header.b=S43e7TpV Received: by mail-dl1-f46.google.com with SMTP id a92af1059eb24-1a2af4c8d00so5967423c88.0 for ; Thu, 03 Dec 2026 07:39:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796312368; x=1796917168; 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=LFPUVnmPi2MXroNBd9inVRAd/IrfbFBuAUh6uK4HCEc=; b=S43e7TpVk0Q8xxNdBwWnL9vtnrEmwOqopaZ5Bx2PBgl+i1KqTQFtv7TI/R/8w6hl3L L9lySeeSk5PUpLT/y3UQQpEAQQUG8hi7YLBja67EALrqJ/ESllEksiUoipF89ANp+z2g 2GWG8OKldzPfiKRNJBr+14vleRojKe6p2TSTrjSyYmtDxkgMvADrTRCnn7FKutkt1Ilm ci/Udl3VhNNWcR2NyDh6c1HYyFof0Ad7nheuKTrA2PfHiVqOFcMemEkBe4qQFkZ3RxDo FQKogyFO1Vg2Pxx76yONTFJV0J+k8FkeXQH0rblI1Z45wW9iKhY4VXIOCHT1GpZmStVf csAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796312368; x=1796917168; 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=LFPUVnmPi2MXroNBd9inVRAd/IrfbFBuAUh6uK4HCEc=; b=CU4XhOLKCRZo6nAiDSofJC2ncNjN+w6fkf0gjENl/QzuXxxuflaStFL4+FT76+wjF+ ruj+fnIF3wb5Q6Ik9hDq+j5OVFQXNxsQZSwIx94Kxhu5mA5wuCjS/aYTrn7MbAoar9mD nTDLkOzKGk2rK+sB/5Y0F+MDlxC1E0b6XDKzrrJ6RggTjd0KDgLcP1uiBYoQ6T5dIxE+ jJzD9O8E8oTf+WsGZ76KZtYxHw8VS9wAmS+yIYthM1IK2GkSp1kPVclBvr5YxDB7xqkc /KO7xHhmgNA3NCXXUUe3T4d+5XIlPl2C8CErY1GO1PEegRbkBrkVF49utw4cB42w0Fug PONg== X-Forwarded-Encrypted: i=1; AL+hErEAiLKpW0yaGhlwS0cZhKutXZJrsSUBTX7r6OoLndvzrZexkgHurdZoDs9or/9r/tk6DTguDPw=@vger.kernel.org X-Gm-Message-State: APuU4Z+uzpjDU1Kn8AxQ2Fg+kvg3kQBGUb0HQ5MYjO4GnJNBu/8l/yHx rYlBvrnKlyX66nP3T42RAd56kOK3FrkrQGZgaM2MuZFbXNgkWwUv2/qg X-Gm-Gg: AZFdTZeyPqS5xVrFhX0dJRGMH69ZvwKAlT4ockOeRMvC87uxJcPm1b42T3yosEu+jKR 2aJY0Igbsp3Jo+F1OenC6mVRerquG4Ws7GWUYW1e0zDNU77BeJJ3f4kMfc4xSkoStPcEAk5ccmq uSaoOUy7srvx/gfYAEg6Grs+M1c3gjdKecwU7ZryPUzxV0pVyDhmaEjOiWU8Tkw7a/N+PgC2wph 9Lu9SdZTFcNTvnLiRtQ4xhDMRCzwJ/s10g025fz4H/R80+SltzfylNdqTZA8WnRZQUPPox/nRNy mcvf+gpPqxtfdZTHPb7quXggilEq2rD+QbdILxpIvP/DsVHj0Z2wsxQMJNS0uX1HrawIkInEby8 JSpMfjCy9Zfjiruzt/ikJ6RCXyJ9yVB/0DdRRwvqV2xpLXzh/J/HfIyhYf+aI37d5mN7gs+keqL ChuTf49IIQpTGqpPFmmhqeJ9V9Skit816/FwwK3O54OL2VC30HGY+/jmsq+mY6cNrME3OSNKqR9 o0tsu4YnLDyY6UKyCkzHR1snKqubaonpsaBz6y7H9DdcCir8NTHlc2tTmJPN5gZbDRil/seRxOh QIveTI3+5KomWzowzYJE/31dlh8zWNvqrpj35sgD5AiblUVF5fXx+ds2fxdCSjG02JwNeYU3sHU ZSvb9tpbNC7CiDalZ5g== X-Received: by 2002:a05:701b:450b:10b0:1b2:4e2e:d95a with SMTP id a92af1059eb24-1b55e06c4d7mr40250194c88.2.1796312368050; Thu, 03 Dec 2026 07:39:28 -0800 (PST) Received: from zorinLS.. ([2804:19c:2591:7000:8394:f950:9202:6c9b]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b562a82b3fsm129329352c88.5.2026.12.03.07.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 07:39:27 -0800 (PST) From: Ermenson Junior To: alibuda@linux.alibaba.com, dust.li@linux.alibaba.com, sidraya@linux.ibm.com, mjambigi@linux.ibm.com Cc: tonylu@linux.alibaba.com, guwen@linux.alibaba.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH net-next v2 1/4] net/smc: bound the SMC-Rv1 add-link rkey exchange Date: Thu, 3 Dec 2026 12:35:11 -0300 Message-ID: <20261203153514.1440337-2-ermenson.sec@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203153514.1440337-1-ermenson.sec@gmail.com> References: <20261203153514.1440337-1-ermenson.sec@gmail.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit smc_llc_srv_rkey_exchange() and smc_llc_cli_rkey_exchange() drive the SMC-Rv1 ADD_LINK_CONT exchange with a loop whose termination condition is re-read from the peer on every round: do { ... qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME, SMC_LLC_ADD_LINK_CONT); ... num_rkeys_recv = addc_llc->num_rkeys; max = min_t(u8, num_rkeys_recv, SMC_LLC_RKEYS_PER_CONT_MSG); for (i = 0; i < max; i++) { smc_rtoken_set(...); num_rkeys_recv--; } ... } while (num_rkeys_send || num_rkeys_recv); num_rkeys_recv is taken from each ADD_LINK_CONT message the peer sends and is decremented by at most SMC_LLC_RKEYS_PER_CONT_MSG, which is 2. A peer that answers num_rkeys=255 every time leaves it at 253 at the bottom of every round, so the condition never goes false. num_rkeys_send does not help: it reaches zero on its own, after which the local side keeps emitting ADD_LINK_CONT messages with num_rkeys=0 while the peer's half of the condition holds the loop open. There is no iteration count, no deadline and no total work budget, so the peer decides both how many rounds the exchange takes and, by replying just inside SMC_LLC_WAIT_TIME, how long each round lasts. Both loops run with a module-global mutex held. On the server, smc_llc_srv_rkey_exchange() is reached from smc_listen_work() through smc_listen_rdma_finish() and smcr_serv_conf_first_link(), between mutex_lock(&smc_server_lgr_pending) and its matching unlock, so every incoming SMC connection on the host waits behind it. On the client, smcr_clnt_conf_first_link() is called from smc_connect_rdma() inside the smc_client_lgr_pending region, so a hostile server stalls every outgoing SMC connection on the host. lgr->rmbs_lock and lgr->llc_conf_mutex are held across the loop as well. Bound the exchange in both directions. An ADD_LINK_CONT message carries at most SMC_LLC_RKEYS_PER_CONT_MSG rkeys and a link group holds at most SMC_RMBS_PER_LGR_MAX of them, so a peer that keeps to the protocol never needs more than DIV_ROUND_UP(SMC_RMBS_PER_LGR_MAX, SMC_LLC_RKEYS_PER_CONT_MSG) messages, which is 128, and anything beyond that is a protocol error. Cap the rounds at that derived limit and give the exchange as a whole a deadline: the round cap on its own would still allow 128 * SMC_LLC_WAIT_TIME of held mutex, and a deadline on its own would still allow an unbounded number of instant rounds under it. Neither check rejects a message a conforming peer can send. SMC_LLC_RKEY_EXCHG_TIME is ten times the existing per-message timeout. The exchange is reactive on a QP that is already up, so this is generous; the value is a policy choice and easy to change if a different one is preferred. Aborting the exchange costs only the optional second link. No caller propagates the result: smcr_clnt_conf_first_link() and smcr_serv_conf_first_link() ignore it, smc_llc_process_cli_add_link() ignores it, smc_llc_process_srv_add_link() uses it only to decide whether to drop an asymmetric link, and smc_llc_cli_add_link() already maps an rkey-exchange failure to rc = 0. A link group that hits either limit keeps running on its first link instead of failing the connection. The SMC-Rv2 counterparts of this same trust in a peer-supplied count were bounded in commit 2d1e7c5aaa33 ("net/smc: bound the peer rkey counts in SMC-Rv2 LLC messages"). The v1 loops were left as they were; this is the same field on the other side of the version test in smc_llc_srv_add_link(). Not reproduced dynamically, and I want to be explicit about that. The loop is on the SMC-Rv1 path, which needs a GID of type IB_GID_TYPE_ROCE (smc_ib_determine_gid_rcu()); the soft-RoCE driver publishes only IB_GID_TYPE_ROCE_UDP_ENCAP, so SMC-Rv1 cannot be negotiated on an rxe setup, and I have no RoCEv1 hardware to test on. The reasoning above is from source reading and the patch is compile-tested only. This patch was written with the help of an AI coding assistant (Claude). Fixes: 87f88cda2128 ("net/smc: rkey processing for a new link as SMC client") Fixes: 57b499242cb8 ("net/smc: rkey processing for a new link as SMC server") Signed-off-by: Ermenson Junior --- net/smc/smc_llc.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- net/smc/smc_llc.h | 7 +++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/net/smc/smc_llc.c b/net/smc/smc_llc.c index c9ccd8480369..818dd84e720f 100644 --- a/net/smc/smc_llc.c +++ b/net/smc/smc_llc.c @@ -111,6 +111,13 @@ struct smc_llc_msg_req_add_link_v2 { #define SMC_LLC_RKEYS_PER_CONT_MSG 2 +/* An ADD_LINK_CONT message carries at most SMC_LLC_RKEYS_PER_CONT_MSG rkeys and + * a link group holds at most SMC_RMBS_PER_LGR_MAX of them, so a peer that keeps + * to the protocol never needs more messages than this to finish the exchange. + */ +#define SMC_LLC_RKEY_CONT_MSG_MAX \ + DIV_ROUND_UP(SMC_RMBS_PER_LGR_MAX, SMC_LLC_RKEYS_PER_CONT_MSG) + struct smc_llc_msg_add_link_cont { /* type 0x03 */ struct smc_llc_hdr hd; u8 link_num; @@ -914,6 +921,8 @@ static int smc_llc_cli_rkey_exchange(struct smc_link *link, u8 max, num_rkeys_send, num_rkeys_recv; struct smc_llc_qentry *qentry; struct smc_buf_desc *buf_pos; + unsigned long expire; + int rounds = 0; int buf_lst; int rc = 0; int i; @@ -921,9 +930,23 @@ static int smc_llc_cli_rkey_exchange(struct smc_link *link, down_write(&lgr->rmbs_lock); num_rkeys_send = lgr->conns_num; buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst); + expire = jiffies + SMC_LLC_RKEY_EXCHG_TIME; do { - qentry = smc_llc_wait(lgr, NULL, SMC_LLC_WAIT_TIME, - SMC_LLC_ADD_LINK_CONT); + long timeo; + + if (rounds++ >= SMC_LLC_RKEY_CONT_MSG_MAX) { + rc = -EPROTO; + break; + } + timeo = (long)(expire - jiffies); + if (timeo <= 0) { + rc = -ETIMEDOUT; + break; + } + if (timeo > SMC_LLC_WAIT_TIME) + timeo = SMC_LLC_WAIT_TIME; + + qentry = smc_llc_wait(lgr, NULL, timeo, SMC_LLC_ADD_LINK_CONT); if (!qentry) { rc = -ETIMEDOUT; break; @@ -1352,6 +1375,8 @@ static int smc_llc_srv_rkey_exchange(struct smc_link *link, u8 max, num_rkeys_send, num_rkeys_recv; struct smc_llc_qentry *qentry = NULL; struct smc_buf_desc *buf_pos; + unsigned long expire; + int rounds = 0; int buf_lst; int rc = 0; int i; @@ -1359,11 +1384,25 @@ static int smc_llc_srv_rkey_exchange(struct smc_link *link, down_write(&lgr->rmbs_lock); num_rkeys_send = lgr->conns_num; buf_pos = smc_llc_get_first_rmb(lgr, &buf_lst); + expire = jiffies + SMC_LLC_RKEY_EXCHG_TIME; do { + long timeo; + + if (rounds++ >= SMC_LLC_RKEY_CONT_MSG_MAX) { + rc = -EPROTO; + goto out; + } + timeo = (long)(expire - jiffies); + if (timeo <= 0) { + rc = -ETIMEDOUT; + goto out; + } + if (timeo > SMC_LLC_WAIT_TIME) + timeo = SMC_LLC_WAIT_TIME; + smc_llc_add_link_cont(link, link_new, &num_rkeys_send, &buf_lst, &buf_pos); - qentry = smc_llc_wait(lgr, link, SMC_LLC_WAIT_TIME, - SMC_LLC_ADD_LINK_CONT); + qentry = smc_llc_wait(lgr, link, timeo, SMC_LLC_ADD_LINK_CONT); if (!qentry) { rc = -ETIMEDOUT; goto out; diff --git a/net/smc/smc_llc.h b/net/smc/smc_llc.h index 7e7a3162c68b..0a1c6c141a57 100644 --- a/net/smc/smc_llc.h +++ b/net/smc/smc_llc.h @@ -21,6 +21,13 @@ #define SMC_LLC_WAIT_TIME (2 * HZ) #define SMC_LLC_TESTLINK_DEFAULT_TIME (30 * HZ) +/* Total time budget for the rkey exchange of one SMC-Rv1 add-link flow, across + * all ADD_LINK_CONT messages. The peer decides how many messages the exchange + * takes, so the exchange as a whole needs a deadline and not only a per-message + * timeout. + */ +#define SMC_LLC_RKEY_EXCHG_TIME (SMC_LLC_WAIT_TIME * 10) + enum smc_llc_reqresp { SMC_LLC_REQ, SMC_LLC_RESP -- 2.43.0