From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796312370; b=1Yif+zxMxjF52HsuNjQuRDPFniG7Rn05lvbobYkvKz0ZUHUGQY0XC4KKUprVn3cY+YAD uhDCKiu00SAXHSLOREOm6Pc/NL0XLWxT4K/elQrROPCgkujd98G5Gn+MQ0/RTBq/h2ChB WKEroHrSX7tnfT1JzmFPNJMykp8iNxigX+teCTmrzHeoPMfp3JJOCziT1mfKuDDkOPXw4 NlQrUlKOsDeQDcBT+HeB1MJz2npRHPca5pAYP4jPbwKfpvg4zy5FSkIYjebyfaN1wqU4P bdCSgalgn+0CGOtG5WTJLg5iKsT4/sSCns2ETLciQfasdksjNuPN6ATw57LVgCuVV1A== 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=jpSSKbMpnuTx/7trgwrnOsGj0PkIQu0PBo9ObXburocNyT6c5zTU5QOe8m6hvr7U0YXT gka7Z5ka4NFUyaCbjaTdeTOma5TYqCaQgyvZjDPnQc892m91g1QiQxs0vfdRp18W+Bvk1 jGsMOgUBEIDFwyWBKWsF/o2cXlPhz0QyDeiwDy0smKMY+6lyPIf6HXGcU17ZTH8lXRZmG l7BdnBIW5d8mA9anJlALFHVngKrkvNfjHF0QQx9KmWaxqzZuptV/Wso1HF4bhLxdftU1K uZC+LxnvIVIm7LQ1ftXh/P5EveN8XOP9tE2G71QWFXc3fSCOP/Ipr0u0DmeJ6e94EUA== 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.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (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 06386606A333 for ; Thu, 3 Dec 2026 15:39:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 06386606A333 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-f54.google.com with SMTP id a92af1059eb24-1b5adf7eacdso5114650c88.1 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=tL3FSSP/7XC7CpnXEjWQk7+n9HBf7bpkS1OxYXEt/ro2pW0tokxfnNmskD4u8jrFRV X9+QQTo0JmI+atTqGJdPItzQx1RmpqrHOWgfcDBmWCbZmRt0pGOb7CMOSpaDlbgqug2a 2dMbdIRFv3bGUHYVL+FanyPO2zEkc+itZpUAgwzBMtOPYCcKDYk8GCSdLa/bKalhxXG/ f9oIZpFT/avkMYxUBoaZWzS5wNY5euA/HlN+28qPQuvliKedzIZeTOCxfdkcp48Efod3 W+WMEs8/BHkMCDQKMt1OhmEwtPpr7PzhgkonbWWqrPDBBqMN+ui29BDH3jfG2pf5l6re 6Oyg== X-Forwarded-Encrypted: i=1; AL+hErHGuH0dLcvPtuBmvsVd4L4bKx/UW54IQtzuZe2XVdVcegciRMirSwwgNsz3LcrepCcPAMl3IXcA3jSH@vger.kernel.org X-Gm-Message-State: APuU4Z/WDoDcq25PcKklVaFCb4PqgPqm3SIp7Gh7sTVOJi9ZerGCltO6 e/e0/EjOQo9dGYWo4SW3uRRy8hV2yWGNKdp981PMdsynGTNka4+esPm/ X-Gm-Gg: AZFdTZf4q5vMSxbnYZtaysFZcb8+yVC+tPpgrR5WIPlC6bcxu+lsQdFC1ptdu21PQfS urlhAYSU+hh+DMD5uUY7h9hxBkO2uTBP+Nc4n1MOCNtweoIsIx8ng3kypbuAWYEg1vuyKtCDHJA BBonIHMnHyCIHAbhtEYerY9ttZuW6G9RRbEvPQsf6UW3iH5ehTaG6Taj4rFNptybjUBlHO+bHGr WEGFxDKy1M9/IGGgGHs5itpPLulIxGb6thw+LEDF5C32KQaJUE7BHW/sN5QTyFsKyQJg0FMuauw nG7QdNJLk+KBmiijeakum4H0b1SVuV9JJVyID3/y/4k7m8O2F2H94DGneQWGU+481EWIvACYJUS pNaaCtqarZQl3aSnNcTjt9B/qg3cDxJj47ychy4RP9OeOONC33jhrjDlPENpoQhGfxaobjVcBJx IBewNhIFaIBwdy1287Gd30D1E09Nh2+G+jtgPqDmDiCFWtOBy8+U5XYtCkuhcUyHc4jRThavCtc ENujisXs5cSRqzIROU5fgunjPu72uQvzphgMCei8q0VueOJcKXAS0P2Q8S9p/tYuzWxpY7CbGsu h92vExAaF8KNF4ZUDuLnid5hfq6CRNlN+PtsX8eZvW4aXF8vbHPtRyP2EgpJK4tsfSIB062T9A+ 0erZLhgJ01TCEoaOf7Q== 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-rdma@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