Received: by 2002:a05:7208:70d5:b0:7f:5597:fa5c with SMTP id q21csp2215673rba; Sun, 24 Mar 2024 06:59:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrs7H+qnW/2YMC1MvPyoFWfKFmx68UmTYcH+v3t7SAn1GWWH1VHijijFNpZRDC7PPGKuBh8OMBgzw8TcOVIJwUA1rMCpq9xwPBsnq89g== X-Google-Smtp-Source: AGHT+IEcuottW5HE3Bi8Bw/rMRrhoV9/k60zMnaZFUoDVW3Qmocc1U/zl1j81xVYmcOC57McGfZg X-Received: by 2002:a17:907:868d:b0:a47:52f6:9ff0 with SMTP id qa13-20020a170907868d00b00a4752f69ff0mr1573251ejc.15.1711288785888; Sun, 24 Mar 2024 06:59:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711288785; cv=pass; d=google.com; s=arc-20160816; b=ZpAq7sGpdTv/yfNa1GsEaOpg8ILMHjD6fIS7wEZ7WaV+lFHZhRMo4IpqUdSzSpwcxP 0pG/CZW02Sb5l1y2zQm5EGk2tYyRKqdXpIoiqEtx9UzICS6K+Cy90l2QaeIJrfIdM1L/ j94cZx7SAk+J14vM9r51NSoTofdgFDUmobA7EVBHr6op0m1jkZcJlpg1TDb/PXe/stHL i3DDeQvI6IRUHnGmSRtwRlZPtLuzFO+DTRltLXgV25FzSgUHue+ejM1ots92Ee+1HAQv JtqT2aGOaBGbx5rxg0Y9NcUW/yapyWIChPDR0hsaVaQrat5E6b0FrswIyKn3cJ+69u9B VppA== 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=7mu1bAnb4l7G1Oqg6FtYEfRH8TPZdH4clawae2CV+OI=; fh=dZ+5j4HvJgOzvN8nB02tgPlkwHWSh0WzjxQ9fqEQCrY=; b=G3pRAyKEMbUvO/PZFXxyrRG6YUqKphiJuDuA8wUv3mVL1NuRios2JHY8j+VlznL0eF vXNm8idg33UwRKdiSFp3ZF49PNR3dAwfHd74Mr0P9447O/ORLzkMAlLfuW9Jf/TvLfFO G6mf+Tfv4gA9dGeHsImGo3iSpONGVMdEq4lIWmcSwn65gMrF5Q7+Lg7CwyUXUAZO+g18 VSqGVLXxHgmnZu0dmT4Yczhl6sooOa8rl/BTS3cVGjqx4jJ/1ffsXjkZhiYj8LuB61zr SD9ykP/yIWgASkrPLW9Vvf5t5LYqeKz4JRMQSro6LJ6BKS8IcR1Xv08SBclJ7byY5BjD PU7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=N6QaobJ0; 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-112699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112699-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 am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z2-20020a1709060be200b00a46e6d3a27esi1676165ejg.527.2024.03.24.06.59.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 06:59:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=N6QaobJ0; 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-112699-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112699-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6873F1F212C5 for ; Sun, 24 Mar 2024 13:59:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BD3F3A1D9; Sun, 24 Mar 2024 13:56:03 +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="N6QaobJ0" Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) (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 E7FDE383B4; Sun, 24 Mar 2024 13:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711288562; cv=none; b=ByYZPf3nae+GA5WQ7LZRcUbNgsfxXXvOoy3Egjw6FquDuFys+wGDBrgTQ30J9QciK98jXCr084wmDN3RKY4DPYV1HTU+E5ztZZiJXy8xmE0R7KVGfZZxp0hSHYbn0OASuAsfttNwx8ZtBXNzlvP8W9sh/x0O2bnV2HrrtzgQRAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711288562; c=relaxed/simple; bh=MEMyVWwFXUdYJbDBPPuv+X0Lhx+p+uOvDEHukNdAhCk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sm/X845xeoEq/WiaN6u39SRicLeFg9S0DrxNxwf1/AGM61irMeRR2T20DTaMzQ1kc/Wbqo627Fz/K2RgmMxkBu/epQY7SXBSWv/+2zitGk8+czRc+7FDxLi/h8w01NRZtJXsdYt6l+J5OouMcLgNsjIULbzCtWJURktC1S78Z2o= 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=N6QaobJ0; arc=none smtp.client-ip=115.124.30.131 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=1711288552; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=7mu1bAnb4l7G1Oqg6FtYEfRH8TPZdH4clawae2CV+OI=; b=N6QaobJ0X8ms/qiCdNG1yuki6vDrX2LNARUNjBHZgQm5s8CQXTY5ca/bX3eaAcb3noJI5gKSsCltwQebhPc+WEasS//+Q2ZC4Ho2omvwmyQbPtv8tiqAGXGu5FU8fANuSrPIl9DNRhv+JtUj2GzXD1HqWztcfIN/FxK8a8/XeOU= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0W372tDs_1711288549; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0W372tDs_1711288549) by smtp.aliyun-inc.com; Sun, 24 Mar 2024 21:55:51 +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: [RFC PATCH net-next v5 11/11] net/smc: implement DMB-merged operations of loopback-ism Date: Sun, 24 Mar 2024 21:55:22 +0800 Message-Id: <20240324135522.108564-12-guwen@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240324135522.108564-1-guwen@linux.alibaba.com> References: <20240324135522.108564-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 This implements operations related to merging sndbuf with peer DMB in loopback-ism. The DMB won't be freed until no sndbuf is attached to it. Signed-off-by: Wen Gu --- net/smc/smc_loopback.c | 120 +++++++++++++++++++++++++++++++++++------ net/smc/smc_loopback.h | 3 ++ 2 files changed, 108 insertions(+), 15 deletions(-) diff --git a/net/smc/smc_loopback.c b/net/smc/smc_loopback.c index 5b35e68d9cdf..994fe39930ad 100644 --- a/net/smc/smc_loopback.c +++ b/net/smc/smc_loopback.c @@ -21,6 +21,7 @@ #if IS_ENABLED(CONFIG_SMC_LO) #define SMC_LO_V2_CAPABLE 0x1 /* loopback-ism acts as ISMv2 */ +#define SMC_LO_SUPPORT_NOCOPY 0x1 #define SMC_DMA_ADDR_INVALID (~(dma_addr_t)0) static const char smc_lo_dev_name[] = "loopback-ism"; @@ -82,6 +83,7 @@ static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, goto err_node; } dmb_node->dma_addr = SMC_DMA_ADDR_INVALID; + refcount_set(&dmb_node->refcnt, 1); again: /* add new dmb into hash table */ @@ -95,6 +97,7 @@ static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, } hash_add(ldev->dmb_ht, &dmb_node->list, dmb_node->token); write_unlock_bh(&ldev->dmb_ht_lock); + atomic_inc(&ldev->dmb_cnt); dmb->sba_idx = dmb_node->sba_idx; dmb->dmb_tok = dmb_node->token; @@ -111,13 +114,29 @@ static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, return rc; } +static void __smc_lo_unregister_dmb(struct smc_lo_dev *ldev, + struct smc_lo_dmb_node *dmb_node) +{ + /* remove dmb from hash table */ + write_lock_bh(&ldev->dmb_ht_lock); + hash_del(&dmb_node->list); + write_unlock_bh(&ldev->dmb_ht_lock); + + clear_bit(dmb_node->sba_idx, ldev->sba_idx_mask); + kvfree(dmb_node->cpu_addr); + kfree(dmb_node); + + if (atomic_dec_and_test(&ldev->dmb_cnt)) + wake_up(&ldev->ldev_release); +} + static int smc_lo_unregister_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb) { struct smc_lo_dmb_node *dmb_node = NULL, *tmp_node; struct smc_lo_dev *ldev = smcd->priv; - /* remove dmb from hash table */ - write_lock_bh(&ldev->dmb_ht_lock); + /* find dmb from hash table */ + read_lock_bh(&ldev->dmb_ht_lock); hash_for_each_possible(ldev->dmb_ht, tmp_node, list, dmb->dmb_tok) { if (tmp_node->token == dmb->dmb_tok) { dmb_node = tmp_node; @@ -125,16 +144,76 @@ static int smc_lo_unregister_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb) } } if (!dmb_node) { - write_unlock_bh(&ldev->dmb_ht_lock); + read_unlock_bh(&ldev->dmb_ht_lock); return -EINVAL; } - hash_del(&dmb_node->list); - write_unlock_bh(&ldev->dmb_ht_lock); + read_unlock_bh(&ldev->dmb_ht_lock); - clear_bit(dmb_node->sba_idx, ldev->sba_idx_mask); - kfree(dmb_node->cpu_addr); - kfree(dmb_node); + if (refcount_dec_and_test(&dmb_node->refcnt)) + __smc_lo_unregister_dmb(ldev, dmb_node); + return 0; +} + +static int smc_lo_support_dmb_nocopy(struct smcd_dev *smcd) +{ + return SMC_LO_SUPPORT_NOCOPY; +} + +static int smc_lo_attach_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb) +{ + struct smc_lo_dmb_node *dmb_node = NULL, *tmp_node; + struct smc_lo_dev *ldev = smcd->priv; + + /* find dmb_node according to dmb->dmb_tok */ + read_lock_bh(&ldev->dmb_ht_lock); + hash_for_each_possible(ldev->dmb_ht, tmp_node, list, dmb->dmb_tok) { + if (tmp_node->token == dmb->dmb_tok) { + dmb_node = tmp_node; + break; + } + } + if (!dmb_node) { + read_unlock_bh(&ldev->dmb_ht_lock); + return -EINVAL; + } + read_unlock_bh(&ldev->dmb_ht_lock); + + if (!refcount_inc_not_zero(&dmb_node->refcnt)) + /* the dmb is being unregistered, but has + * not been removed from the hash table. + */ + return -EINVAL; + /* provide dmb information */ + dmb->sba_idx = dmb_node->sba_idx; + dmb->dmb_tok = dmb_node->token; + dmb->cpu_addr = dmb_node->cpu_addr; + dmb->dma_addr = dmb_node->dma_addr; + dmb->dmb_len = dmb_node->len; + return 0; +} + +static int smc_lo_detach_dmb(struct smcd_dev *smcd, u64 token) +{ + struct smc_lo_dmb_node *dmb_node = NULL, *tmp_node; + struct smc_lo_dev *ldev = smcd->priv; + + /* find dmb_node according to dmb->dmb_tok */ + read_lock_bh(&ldev->dmb_ht_lock); + hash_for_each_possible(ldev->dmb_ht, tmp_node, list, token) { + if (tmp_node->token == token) { + dmb_node = tmp_node; + break; + } + } + if (!dmb_node) { + read_unlock_bh(&ldev->dmb_ht_lock); + return -EINVAL; + } + read_unlock_bh(&ldev->dmb_ht_lock); + + if (refcount_dec_and_test(&dmb_node->refcnt)) + __smc_lo_unregister_dmb(ldev, dmb_node); return 0; } @@ -172,6 +251,12 @@ static int smc_lo_move_data(struct smcd_dev *smcd, u64 dmb_tok, struct smc_lo_dev *ldev = smcd->priv; struct smc_connection *conn; + if (!sf) + /* since sndbuf is merged with peer DMB, there is + * no need to copy data from sndbuf to peer DMB. + */ + return 0; + read_lock_bh(&ldev->dmb_ht_lock); hash_for_each_possible(ldev->dmb_ht, tmp_node, list, dmb_tok) { if (tmp_node->token == dmb_tok) { @@ -186,13 +271,10 @@ static int smc_lo_move_data(struct smcd_dev *smcd, u64 dmb_tok, memcpy((char *)rmb_node->cpu_addr + offset, data, size); read_unlock_bh(&ldev->dmb_ht_lock); - if (sf) { - conn = smcd->conn[rmb_node->sba_idx]; - if (conn && !conn->killed) - tasklet_schedule(&conn->rx_tsklet); - else - return -EPIPE; - } + conn = smcd->conn[rmb_node->sba_idx]; + if (!conn || conn->killed) + return -EPIPE; + tasklet_schedule(&conn->rx_tsklet); return 0; } @@ -224,6 +306,9 @@ static const struct smcd_ops lo_ops = { .query_remote_gid = smc_lo_query_rgid, .register_dmb = smc_lo_register_dmb, .unregister_dmb = smc_lo_unregister_dmb, + .support_dmb_nocopy = smc_lo_support_dmb_nocopy, + .attach_dmb = smc_lo_attach_dmb, + .detach_dmb = smc_lo_detach_dmb, .add_vlan_id = smc_lo_add_vlan_id, .del_vlan_id = smc_lo_del_vlan_id, .set_vlan_required = smc_lo_set_vlan_required, @@ -302,12 +387,17 @@ static int smc_lo_dev_init(struct smc_lo_dev *ldev) smc_lo_generate_ids(ldev); rwlock_init(&ldev->dmb_ht_lock); hash_init(ldev->dmb_ht); + atomic_set(&ldev->dmb_cnt, 0); + init_waitqueue_head(&ldev->ldev_release); + return smcd_lo_register_dev(ldev); } static void smc_lo_dev_exit(struct smc_lo_dev *ldev) { smcd_lo_unregister_dev(ldev); + if (atomic_read(&ldev->dmb_cnt)) + wait_event(ldev->ldev_release, !atomic_read(&ldev->dmb_cnt)); } static void smc_lo_dev_release(struct device *dev) diff --git a/net/smc/smc_loopback.h b/net/smc/smc_loopback.h index 6c4a390430f3..9a1c5eee5bbc 100644 --- a/net/smc/smc_loopback.h +++ b/net/smc/smc_loopback.h @@ -30,6 +30,7 @@ struct smc_lo_dmb_node { u32 sba_idx; void *cpu_addr; dma_addr_t dma_addr; + refcount_t refcnt; }; struct smc_lo_dev { @@ -37,9 +38,11 @@ struct smc_lo_dev { struct device dev; u16 chid; struct smcd_gid local_gid; + atomic_t dmb_cnt; rwlock_t dmb_ht_lock; DECLARE_BITMAP(sba_idx_mask, SMC_LO_MAX_DMBS); DECLARE_HASHTABLE(dmb_ht, SMC_LO_DMBS_HASH_BITS); + wait_queue_head_t ldev_release; }; #endif -- 2.32.0.3.g01195cf9f