From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796312370; b=sX455C2idOEHlvF9A8lNcZN7K/1GT51pduietBpzD1680l99xhpY9PCz/aQTElq//O51 X1ID5YQCXkMr9q4K2Ob5hyOliFTEq9WEgtD41JgSnFos+hS/AMGteRatiaP1SW7ZL2Czm z80EfRNwxwCoVCySJKTKpQ8wh5R/Y+yz0LlXkQWYqOAYu5J3wcn4qy1IdZkfyDjPXyro/ IJkVOHOJ7zmPZcNo1rguKMeTJzu6y59/w8wsSQ6sf57H13Y3qS8ll7yeq6LphnFa+pGx0 yTv5561fFA3SjTkWI5SR34u+2lBpSitg+tO+Rbxp2a9Nx5zECEY2MTGv9oZYyprc7dw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796312370; 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=xzAw7RzbGivCSZjyT/lRKLEZOQeYP2N+9PCoUBgOa5LCNp73vGgkgM9b4Q+G9DFu2sTC Nenn9y3aNl74GhYxW1MW1tCVBeMHbCPNKF4jnNYS2JzF13tMZg6Qgj6OQVedJaPW/S8Mi dfsmNRMJXMu9h/hj8fZmBcKDAv5LeFmT5uPnn0TNJHObLTjGSGfcAx+wC4NVK6yPrt/4c w4TF65oo0wtKbZYA0nMZi+dmNTWZoTizePp2dYC8LHFFszADHJtB3ZxG4Eeob9VUV5w0G kQQTwqSNPFJTvSwzJHNYxA353mK7mfS+MkfxH+6aLqWtAmcEFkSpOHwCN/OCaTm4x2A== 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.43 Received: from mail-dl1-f43.google.com (mail-dl1-f43.google.com [74.125.82.43]) (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 07BFA606A335 for ; Thu, 3 Dec 2026 15:39:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 07BFA606A335 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-f43.google.com with SMTP id a92af1059eb24-1a2af4c8d00so5967421c88.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=Bc5calMYB/c905GUABAvaI5LWEy9+dri3DVCrcmDmHRENSd5Ah6IzJywDY5YOI5H+B slnLoIS2+rSnV7mnI5JHhzXnAf4zTZEwRsc3wdZ4zuuRjN9za07ZNQq5T3Rmm/wsJw/E r9VteT6zuarT8V9C8xjGKa6YsGg+GsSkYDtSK6qi7q3Icb13RhyKCvzSh8hgDSah5ngy OsyG2stULFeokgImszgjPV5Z8NScKWU18viRR0xq0zp90keVlAe8A+znN+bLfR79LvUR JsmDvrpxN2tKmcQ+PZLLlK4Fuq6poDEHOTo0n3DfQ9ztZlTTClt74lDCs4zqj8hPRGzw rsIQ== X-Forwarded-Encrypted: i=1; AL+hErF3Y7qM4iZkFYwDMAAZ3D6iAxrRYhR+trT7Z4YPSFmswIvGGxX+cC7hFylnFuwN/SzDgsnE7XkSjK7I@vger.kernel.org X-Gm-Message-State: APuU4Z/k0bVUNRbO/B3PqD32DGiLEVdILAjx53zLbMYr/YavejreeQSk 7sprFOFQw9AvGfM+kGF2PCHe49IphSLUjl50qJJo/v22VSO5nfd7hNRQ X-Gm-Gg: AZFdTZc8AW266MDGWBlxuT8nAPmrANKl95MN9SkXHsV+bUt84k70dFWTLmWphQtMEo+ VnsXYi3AQkiOlo/pVhbGQnxjTI2pfidQLB4AU+41lznt5ejOmWviY9JUIHPYOs10QZDXH1WEC1p gZaK7pbk76CogXdYvBGlU5cD44fC54f0vQ0iB/kTl0wE/l3DKsgEZAqv2vxrJ5MCk4D3aj6vBgT aBdD2wENrZ3Wil5rds4XMtvHxMoEjeXrbBsYqV3aj84DFLRNNs3G3tbmum+tD/PQG7Y3PlG2MB3 Y5jDVGeEqUtzKzd7roWbveN9t6z3S7Wroa+Qhr3oGXDJAt9PIEaTEzxNLqLE6vfPxK21mjHiZh9 SVcpBplXwiW23h7BTMOGmwNDK/A6NALhny9Qq21La4BBHaHxQMfP76fc7yeySb2lwkjNsbMT3AN G/DvJlnecD+u5iX5hU9Pxt6gZVMXT0SCSLkZa8k+DOvdQ3O9DF0eP+slfZfzqJxEk+m1TNmVB0O t8Kxo27SVGHDzWdo61n/4oEFWlReGwhy+sdoDLSiJ0bMIUX4GxmQezCpVHdWoiuyYXTjvtBtL82 4lIFk0nuNv8KvJ3YiGDnBmsDx8ZsuM0bMQVewc7oNWD2q2JbBCqMs0202oKFxUnE9YKxQGcflH4 lP6KPd5TYmEtz+7zVFw== 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: linux-s390@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