Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp449954lqi; Thu, 7 Mar 2024 02:01:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW26zUbK1+j4xIZzbwbKLv8Vnbv4l3agundBqFXiJujUOJo3DuHKZeBAv4D6oD9X5jjaj/xNGpW2NUjUL2/zpiZ577vibmTHa67qTm5nA== X-Google-Smtp-Source: AGHT+IEZpilMkC84IOaXwzdLUFBc6ipdVP7CDn8yWdVDAoKY3VhxH7zK00Iwp2eMDBztrOfq5xv0 X-Received: by 2002:a05:620a:2909:b0:788:471c:5f5d with SMTP id m9-20020a05620a290900b00788471c5f5dmr1432304qkp.62.1709805697626; Thu, 07 Mar 2024 02:01:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709805697; cv=pass; d=google.com; s=arc-20160816; b=fWeoE7DjoEpnzCBU2OVnFHyS6nLlrlLWomnrx4yCWBwy/Ph+cshvFdf8DxPOx3w98L oxgc283uYbGEwWD+lTsJWq4y1euYZL81kmXADMzv98vXwmBTII1zm7+kie5/iGBBu2TH W5cVysTxc3Cw0eMAbPAdnvC8S+xJqXab7itKjEXb3H/pTq8UroLQtV/0teaLUcP+NnpI d7mdT2CoNUWlV1Q7mR7uuiz2LAndm3nq8v5F//bI4+jXaB3L2rHXc3GgSpf5/z0E+cTI nVrpcY+PvX1iS2ZB7xRVtyJ49sC19GT5W92xaOGfryrf58CwcsJ5dLbOdWOGZk5CZ9p9 01mA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fSelHZESROM0Ka6YP0PC72uoMYqmMaUB1kibaryyfU4=; fh=dZ+5j4HvJgOzvN8nB02tgPlkwHWSh0WzjxQ9fqEQCrY=; b=e3x7d0eWkXHHk/89zvgNkakprcCItqjtoLn3frKWBruPV8MmrpxP6fIOxrwmpCzt3F uKomWPv64A7otmsxzNK/Pp1BIX3o1vcyTLOp+Y54sY7sJK09I2JB0M2LdTdqJr0Dz4FL CMknb9UUlYK1BjbAIia+g6eIwFwP1b+yQMVhsodnHFsUImr/EW0i1ObqZ5PvE0VikVtu vB+XGHDf12Qv7UGeJ3uC/AMqF++cqmZ82JOcMAIDdlhBycRoFb5J4zxU/TFB9YAFJCh3 U1muEPRSFsT/T+6z5xCjX+MvL8fuWH7zmPcn8ELtIEcb+wPJjGKpvE+A02TbdYmm39Ko WY4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=IWtClpfw; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-95277-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g16-20020ae9e110000000b00788265aef28si9031714qkm.662.2024.03.07.02.01.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 02:01:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-95277-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=IWtClpfw; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-95277-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-95277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 35D6B1C21F73 for ; Thu, 7 Mar 2024 10:01:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 785E612D753; Thu, 7 Mar 2024 09:56:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="IWtClpfw" Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C403012CD94; Thu, 7 Mar 2024 09:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709805371; cv=none; b=W7fApgtfkk4SOsy4qtjIBiM+g1egPOpRCGUvtFYub6BYigekGr3XFnsNiqEE23AlV3msrAcJWUSJ3SgN6/pnenorIKqfJPp2JKsjivQFNDOc8OhgT34vGOiDoMwQU14sK4uUXd5K6Y5q1l6WXWS46WoHgQMNsqi2vLFQH5NtSBI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709805371; c=relaxed/simple; bh=448tqIjdGJFxxJ0g+tBbMKYg5dpbKXvzMlxswSFA2HU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZTsez1GbAjIzXeSCGlwI7wnPPoO55UVV3Z49KAuvlDsrppF2tgXC9oU8qjsglXhM40t3phGCTSFt9kJvFntuF22s0LdK247J+k/1ErBcryK54DypCf8cZxd7jQD6WmwUICYiht5GcXCTHbxSqQuQ/e6bjaxkF1drRgrS4FdZsqE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=IWtClpfw; arc=none smtp.client-ip=115.124.30.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1709805360; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=fSelHZESROM0Ka6YP0PC72uoMYqmMaUB1kibaryyfU4=; b=IWtClpfwuJdFkavl9AMOI2AonoerpD9+mEFcc1UPFVIrlwh3M5O6y6dyKaTDiZbBMduSMeSgMcT8v6/ZzTpZh5xQ5Jk/GX3GGGjy8eKDvmAPZKz2yaWU7so39Nucl/SpBCUm0AhNB12aQcpf22m2JJqoNJdl4iL72oQe/803zAw= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R691e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0W2-HiFv_1709805358; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0W2-HiFv_1709805358) by smtp.aliyun-inc.com; Thu, 07 Mar 2024 17:56:00 +0800 From: Wen Gu To: wintera@linux.ibm.com, twinkler@linux.ibm.com, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, wenjia@linux.ibm.com, jaka@linux.ibm.com Cc: borntraeger@linux.ibm.com, svens@linux.ibm.com, alibuda@linux.alibaba.com, tonylu@linux.alibaba.com, guwen@linux.alibaba.com, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH net-next v2 09/11] net/smc: attach or detach ghost sndbuf to peer DMB Date: Thu, 7 Mar 2024 17:55:34 +0800 Message-Id: <20240307095536.29648-10-guwen@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240307095536.29648-1-guwen@linux.alibaba.com> References: <20240307095536.29648-1-guwen@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The ghost sndbuf descriptor will be created and attached to peer DMB once peer token is obtained and it will be detach and freed when the connection is freed. Signed-off-by: Wen Gu --- net/smc/af_smc.c | 16 ++++++++++++ net/smc/smc_core.c | 61 +++++++++++++++++++++++++++++++++++++++++++++- net/smc/smc_core.h | 1 + 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 751a8fdd6eb0..fce7a5b2ce5c 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -1438,6 +1438,14 @@ static int smc_connect_ism(struct smc_sock *smc, } smc_conn_save_peer_info(smc, aclc); + + if (smc_ism_support_dmb_nocopy(smc->conn.lgr->smcd)) { + rc = smcd_buf_attach(smc); + if (rc) { + rc = SMC_CLC_DECL_MEM; /* try to fallback */ + goto connect_abort; + } + } smc_close_init(smc); smc_rx_init(smc); smc_tx_init(smc); @@ -2542,6 +2550,14 @@ static void smc_listen_work(struct work_struct *work) mutex_unlock(&smc_server_lgr_pending); } smc_conn_save_peer_info(new_smc, cclc); + + if (ini->is_smcd && + smc_ism_support_dmb_nocopy(new_smc->conn.lgr->smcd)) { + rc = smcd_buf_attach(new_smc); + if (rc) + goto out_decl; + } + smc_listen_out_connected(new_smc); SMC_STAT_SERV_SUCC_INC(sock_net(newclcsock->sk), ini); goto out_free; diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c index 9b84d5897aa5..fafdb97adfad 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -1149,6 +1149,20 @@ static void smcr_buf_unuse(struct smc_buf_desc *buf_desc, bool is_rmb, } } +static void smcd_buf_detach(struct smc_connection *conn) +{ + struct smcd_dev *smcd = conn->lgr->smcd; + u64 peer_token = conn->peer_token; + + if (!conn->sndbuf_desc) + return; + + smc_ism_detach_dmb(smcd, peer_token); + + kfree(conn->sndbuf_desc); + conn->sndbuf_desc = NULL; +} + static void smc_buf_unuse(struct smc_connection *conn, struct smc_link_group *lgr) { @@ -1192,6 +1206,8 @@ void smc_conn_free(struct smc_connection *conn) if (lgr->is_smcd) { if (!list_empty(&lgr->list)) smc_ism_unset_conn(conn); + if (smc_ism_support_dmb_nocopy(lgr->smcd)) + smcd_buf_detach(conn); tasklet_kill(&conn->rx_tsklet); } else { smc_cdc_wait_pend_tx_wr(conn); @@ -1445,6 +1461,8 @@ static void smc_conn_kill(struct smc_connection *conn, bool soft) smc_sk_wake_ups(smc); if (conn->lgr->is_smcd) { smc_ism_unset_conn(conn); + if (smc_ism_support_dmb_nocopy(conn->lgr->smcd)) + smcd_buf_detach(conn); if (soft) tasklet_kill(&conn->rx_tsklet); else @@ -2464,12 +2482,18 @@ int smc_buf_create(struct smc_sock *smc, bool is_smcd) int rc; /* create send buffer */ + if (is_smcd && + smc_ism_support_dmb_nocopy(smc->conn.lgr->smcd)) + goto create_rmb; + rc = __smc_buf_create(smc, is_smcd, false); if (rc) return rc; + +create_rmb: /* create rmb */ rc = __smc_buf_create(smc, is_smcd, true); - if (rc) { + if (rc && smc->conn.sndbuf_desc) { down_write(&smc->conn.lgr->sndbufs_lock); list_del(&smc->conn.sndbuf_desc->list); up_write(&smc->conn.lgr->sndbufs_lock); @@ -2479,6 +2503,41 @@ int smc_buf_create(struct smc_sock *smc, bool is_smcd) return rc; } +int smcd_buf_attach(struct smc_sock *smc) +{ + struct smc_connection *conn = &smc->conn; + struct smcd_dev *smcd = conn->lgr->smcd; + u64 peer_token = conn->peer_token; + struct smc_buf_desc *buf_desc; + int rc; + + buf_desc = kzalloc(sizeof(*buf_desc), GFP_KERNEL); + if (!buf_desc) + return -ENOMEM; + + /* The ghost sndbuf_desc describes the same memory region as + * peer RMB. Its lifecycle is consistent with the connection's + * and it will be freed with the connections instead of the + * link group. + */ + rc = smc_ism_attach_dmb(smcd, peer_token, buf_desc); + if (rc) + goto free; + + smc->sk.sk_sndbuf = buf_desc->len; + buf_desc->cpu_addr = + (u8 *)buf_desc->cpu_addr + sizeof(struct smcd_cdc_msg); + buf_desc->len -= sizeof(struct smcd_cdc_msg); + conn->sndbuf_desc = buf_desc; + conn->sndbuf_desc->used = 1; + atomic_set(&conn->sndbuf_space, conn->sndbuf_desc->len); + return 0; + +free: + kfree(buf_desc); + return rc; +} + static inline int smc_rmb_reserve_rtoken_idx(struct smc_link_group *lgr) { int i; diff --git a/net/smc/smc_core.h b/net/smc/smc_core.h index 1f175376037b..d93cf51dbd7c 100644 --- a/net/smc/smc_core.h +++ b/net/smc/smc_core.h @@ -557,6 +557,7 @@ void smc_smcd_terminate(struct smcd_dev *dev, struct smcd_gid *peer_gid, void smc_smcd_terminate_all(struct smcd_dev *dev); void smc_smcr_terminate_all(struct smc_ib_device *smcibdev); int smc_buf_create(struct smc_sock *smc, bool is_smcd); +int smcd_buf_attach(struct smc_sock *smc); int smc_uncompress_bufsize(u8 compressed); int smc_rmb_rtoken_handling(struct smc_connection *conn, struct smc_link *link, struct smc_clc_msg_accept_confirm *clc); -- 2.32.0.3.g01195cf9f