From patchwork Wed Feb 15 16:18:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp283891wrn; Wed, 15 Feb 2023 08:22:58 -0800 (PST) X-Google-Smtp-Source: AK7set/qdVoYWAK+2nJIPfXYW6LnAFcVK6RtXNs8nVS30jU7If9bZRQaaZgfMraZWHDPl2/E6l+e X-Received: by 2002:a17:907:76f1:b0:881:23a:aba5 with SMTP id kg17-20020a17090776f100b00881023aaba5mr2941464ejc.11.1676478178184; Wed, 15 Feb 2023 08:22:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478178; cv=none; d=google.com; s=arc-20160816; b=Yrn/60FzYRs8HDtVjTn0KyLXPxc0Xl1TQk//vhRqDOxRVOLAQOAuCdyvQAQHwPLC4j O0RCbvIJFRP1x32SAmvdDwXJyAK05KoSQFsojmFO5LYEjf8eJUja5jkT6xJLwAxP2m0E EsRezN5BsUyPTDRxTAockiZCl8YfM3EoQRA58bnpH1sEtOe0MEuzw+IRRYMXbXtErkJ/ mTH1Z1ZK1H79dVhwDyMLl1Dqg+VciQZhUEVTsnuuTt4mi+Yiq/noclEJVNbHRZD6VMON a8bR5u5FEC74GxLGhgFG5SRc3pmJ+S9UVoq3kZZL8L21jCQA4JdTFueKsPZAIQRNutXp Gcyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=kcUaLd98gKUmSpZCasNiD4VR800ezQTFIaps69GCWJg=; b=wxEEqBnthwgRe5Joavy7bEs7EuABkA9SpyzLCTDM8P3sBhZzuInFn+eHsH8rThINFJ wp4HLmRAe7iqqtt0h5NGdgUqRk1AJzWwTOMP3V8Uk6Z/yZw7ySIdWS96yBJDqyxoe8YT AIFNTztkmjmy6OwItG5jeNr4Hb+7XwGMhiwMD3gk3NGfVACxGYGLjtjfU8jtJPWbHptU PhZYwCkDG4YSwGG0ZNErCk+S+2WvPXSnr0PnA7PiQ5aNIv2CNVjkk7xvlqu7VmcJojx1 Yd3kKQ1WUZ11yFeBXO86XvrjJe9SnFN90HkC512JE2CJXSP7XGHlo+Dk0pEjB/imlf+e cS0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a17090791c600b008b1438fcb9csi2125800ejz.531.2023.02.15.08.22.32; Wed, 15 Feb 2023 08:22:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbjBOQTB (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbjBOQSs (ORCPT ); Wed, 15 Feb 2023 11:18:48 -0500 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4059B2FCC7; Wed, 15 Feb 2023 08:18:41 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R941e4;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=10;SR=0;TI=SMTPD_---0Vbl3Oxi_1676477916; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl3Oxi_1676477916) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:37 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 1/9] net/smc: Decouple ism_dev from SMC-D device dump Date: Thu, 16 Feb 2023 00:18:17 +0800 Message-Id: <1676477905-88043-2-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914781925225293?= X-GMAIL-MSGID: =?utf-8?q?1757914781925225293?= This patch helps to decouple SMC-D device and ISM device, allowing different underlying device forms, such as non-PCI devices. Signed-off-by: Wen Gu --- include/net/smc.h | 1 + net/smc/smc_ism.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/net/smc.h b/include/net/smc.h index 597cb93..debf126 100644 --- a/include/net/smc.h +++ b/include/net/smc.h @@ -76,6 +76,7 @@ struct smcd_ops { struct smcd_dev { const struct smcd_ops *ops; void *priv; + struct device *parent_pci_dev; struct list_head list; spinlock_t lock; struct smc_connection **conn; diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c index 3b0b771..8023bb0 100644 --- a/net/smc/smc_ism.c +++ b/net/smc/smc_ism.c @@ -231,11 +231,9 @@ static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd, struct smc_pci_dev smc_pci_dev; struct nlattr *port_attrs; struct nlattr *attrs; - struct ism_dev *ism; int use_cnt = 0; void *nlh; - ism = smcd->priv; nlh = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, &smc_gen_nl_family, NLM_F_MULTI, SMC_NETLINK_GET_DEV_SMCD); @@ -250,7 +248,8 @@ static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd, if (nla_put_u8(skb, SMC_NLA_DEV_IS_CRIT, use_cnt > 0)) goto errattr; memset(&smc_pci_dev, 0, sizeof(smc_pci_dev)); - smc_set_pci_values(to_pci_dev(ism->dev.parent), &smc_pci_dev); + if (smcd->parent_pci_dev) + smc_set_pci_values(to_pci_dev(smcd->parent_pci_dev), &smc_pci_dev); if (nla_put_u32(skb, SMC_NLA_DEV_PCI_FID, smc_pci_dev.pci_fid)) goto errattr; if (nla_put_u16(skb, SMC_NLA_DEV_PCI_CHID, smc_pci_dev.pci_pchid)) @@ -420,6 +419,7 @@ static void smcd_register_dev(struct ism_dev *ism) if (!smcd) return; smcd->priv = ism; + smcd->parent_pci_dev = ism->dev.parent; ism_set_priv(ism, &smc_ism_client, smcd); if (smc_pnetid_by_dev_port(&ism->pdev->dev, 0, smcd->pnetid)) smc_pnetid_by_table_smcd(smcd); From patchwork Wed Feb 15 16:18:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57612 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp283735wrn; Wed, 15 Feb 2023 08:22:40 -0800 (PST) X-Google-Smtp-Source: AK7set+SjXwVGP1TWHwQA726D4DVmXm7JWSzdqt2EPHuW+hvvk0a6b/S8ko0v8LkkDBcyODpEnzB X-Received: by 2002:a17:906:4b03:b0:878:714b:5e16 with SMTP id y3-20020a1709064b0300b00878714b5e16mr3099508eju.28.1676478160779; Wed, 15 Feb 2023 08:22:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478160; cv=none; d=google.com; s=arc-20160816; b=BlO98qrlzjQga7keYqo2gSjJmYvcpLY/z5o9AjZnZOHsBF7Avtm9coyMROf0N7HZhl doFkVSX1mRfNsriXtKlaW8JR5Ty1Oo/bMFB1jH7TdQOGEMtvzau84xL5Q78L0pOnBbwe +I+sm79xIKH8yECej8G4p6VY0EoiU1AxiwhBvwwmfaOcBF6NT4tMyrDERO/YPjsZgrZD t/cFpCEnjuxQLp5yTzbFBDzwXSHglWM+K3n7G57zODarz2OTtwJlgiB2sfxQFNleXjZ5 VvJq1dYFhzNqU5qJiNuQX0QCjDSBrJlWesNoKmEMnVLfKwlAAACtn48C0/PhEbfvFJlZ YOEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=w/fhzklauGUaV6VQeWGLovjhHHyXwjgaMvT++MHQtQc=; b=LSWEm/Bg7VqtF2iBi24U8JyPUtGpHNsqGDsysaBhq6os8/JppO4PXa58mcJszoLlQL ODjh0ihne48rZRuJcRwXNFpu7+qTh+XadKG+VVDVt6KtcEQqTCRHcqUuu3+tjOwehEvf UX5mKS4EQ3++70m5CC2qIOPmBW1cHV4PV6l1CJ16T4PuEC4FVUc/3KaJRSfZDijLQh3Q GS+Ze/tDkofXf3R8rzn2yDEK9JcEgOts6Z/P9KWUznu3PJETBcIQvz/HfnyyYMiiMiwF 4jQlXHapTD95kjplQaSLx1MJN5qbqrKxHjV/AiA1srE9eGMEL8DuSEXtlvx3F03ZDL3Z izUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a17090620d300b008b13147d91csi5561568ejc.487.2023.02.15.08.22.15; Wed, 15 Feb 2023 08:22:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229927AbjBOQSv (ORCPT + 99 others); Wed, 15 Feb 2023 11:18:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbjBOQSs (ORCPT ); Wed, 15 Feb 2023 11:18:48 -0500 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 791832DE4A; Wed, 15 Feb 2023 08:18:42 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R671e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Vbl04wX_1676477917; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl04wX_1676477917) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:39 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 2/9] net/smc: Decouple ism_dev from SMC-D DMB registration Date: Thu, 16 Feb 2023 00:18:18 +0800 Message-Id: <1676477905-88043-3-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914763576661373?= X-GMAIL-MSGID: =?utf-8?q?1757914763576661373?= This patch tries to decouple ISM device from SMC-D DMB registration, So that the register_dmb option is not restricted to be used by ISM device. Signed-off-by: Wen Gu --- drivers/s390/net/ism_drv.c | 5 +++-- include/net/smc.h | 4 ++-- net/smc/smc_ism.c | 7 ++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/s390/net/ism_drv.c b/drivers/s390/net/ism_drv.c index eb7e134..93aff58 100644 --- a/drivers/s390/net/ism_drv.c +++ b/drivers/s390/net/ism_drv.c @@ -799,9 +799,10 @@ static int smcd_query_rgid(struct smcd_dev *smcd, u64 rgid, u32 vid_valid, } static int smcd_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, - struct ism_client *client) + void *client_priv) { - return ism_register_dmb(smcd->priv, (struct ism_dmb *)dmb, client); + return ism_register_dmb(smcd->priv, (struct ism_dmb *)dmb, + (struct ism_client *)client_priv); } static int smcd_unregister_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb) diff --git a/include/net/smc.h b/include/net/smc.h index debf126..9b0da45 100644 --- a/include/net/smc.h +++ b/include/net/smc.h @@ -50,13 +50,12 @@ struct smcd_dmb { #define ISM_ERROR 0xFFFF struct smcd_dev; -struct ism_client; struct smcd_ops { int (*query_remote_gid)(struct smcd_dev *dev, u64 rgid, u32 vid_valid, u32 vid); int (*register_dmb)(struct smcd_dev *dev, struct smcd_dmb *dmb, - struct ism_client *client); + void *client_priv); int (*unregister_dmb)(struct smcd_dev *dev, struct smcd_dmb *dmb); int (*add_vlan_id)(struct smcd_dev *dev, u64 vlan_id); int (*del_vlan_id)(struct smcd_dev *dev, u64 vlan_id); @@ -76,6 +75,7 @@ struct smcd_ops { struct smcd_dev { const struct smcd_ops *ops; void *priv; + void *client_priv; struct device *parent_pci_dev; struct list_head list; spinlock_t lock; diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c index 8023bb0..93c7415 100644 --- a/net/smc/smc_ism.c +++ b/net/smc/smc_ism.c @@ -200,7 +200,6 @@ int smc_ism_unregister_dmb(struct smcd_dev *smcd, struct smc_buf_desc *dmb_desc) int smc_ism_register_dmb(struct smc_link_group *lgr, int dmb_len, struct smc_buf_desc *dmb_desc) { -#if IS_ENABLED(CONFIG_ISM) struct smcd_dmb dmb; int rc; @@ -209,7 +208,7 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int dmb_len, dmb.sba_idx = dmb_desc->sba_idx; dmb.vlan_id = lgr->vlan_id; dmb.rgid = lgr->peer_gid; - rc = lgr->smcd->ops->register_dmb(lgr->smcd, &dmb, &smc_ism_client); + rc = lgr->smcd->ops->register_dmb(lgr->smcd, &dmb, lgr->smcd->client_priv); if (!rc) { dmb_desc->sba_idx = dmb.sba_idx; dmb_desc->token = dmb.dmb_tok; @@ -218,9 +217,6 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int dmb_len, dmb_desc->len = dmb.dmb_len; } return rc; -#else - return 0; -#endif } static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd, @@ -419,6 +415,7 @@ static void smcd_register_dev(struct ism_dev *ism) if (!smcd) return; smcd->priv = ism; + smcd->client_priv = &smc_ism_client; smcd->parent_pci_dev = ism->dev.parent; ism_set_priv(ism, &smc_ism_client, smcd); if (smc_pnetid_by_dev_port(&ism->pdev->dev, 0, smcd->pnetid)) From patchwork Wed Feb 15 16:18:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57613 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp283783wrn; Wed, 15 Feb 2023 08:22:44 -0800 (PST) X-Google-Smtp-Source: AK7set9oAQ+gc5yFLBKSdRcF+Plu6uENexxsz0sqhyZKxJVZq52K+I5Tn2xov06DTo5Tpu0IHJUy X-Received: by 2002:a17:906:9442:b0:879:ab3:93d1 with SMTP id z2-20020a170906944200b008790ab393d1mr2884919ejx.4.1676478164280; Wed, 15 Feb 2023 08:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478164; cv=none; d=google.com; s=arc-20160816; b=N3hnwqvfm8YSsF6S9CqmnxVUrZm9d0yDt5X8X8C3AM9fpoUYFAL1zCgL7R6vTM3J1r v6yN/cNiU7vWKRh0fRvy7B30Jg1n5ALZCM0w0ToieVAqFNmOqyaXkaChEkMhQPm8rQN5 +85ANT3FCaGtDh6iAenpQcSKTOsDEVR932OQlDwohm9XItl8ULSMlkaX2EaR/s50toM3 KFJ1qDN/nxBL6CnGXVruLn8LxraVCM+FS5+HCVzty7HxF22Ppte7pDuUrQ/nvzPrWtxX ZQqH7uGqXxirr181N4alAYaJk2z7p1CrhRaj8zZ9FFB2vryACOIokWrcITuSslhwZ6ml WOtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=pf9r//eKUmTWZPd76PbRy6nFWcPmc0n8C6G5jX9v1CI=; b=kugZBGRs+1A6lGWneucUrKopcu5Y5B3R6+XA1OPvK9x1BROD8S2YRCpY1GJLCT5uGy b5iqwje4nvcK2AipYu8IYecDmzleD4/0RXLs0MrHtqSSdfXtvrr70pvy20j8gKWFl461 iqWbmlBlHlcQwJYuobOyTIbkPRCc9KYymANIRe/DAKzELkyAX8pGW8FDutpmXbHnVBd6 uJKWGK3te+t4Gp84Hm68oHHndLblzSolJWf1IswVsmC7SrvLFLgxOJvtI4ZL7uFkW1B5 MmnPLc93vSCljO+doUoMy9qijdfqsrPolzrFCQMtwrNED/wOzjQGkl9Fmh8FxS2fZfYP gkww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c12-20020a1709063f0c00b00893526bc776si24168124ejj.231.2023.02.15.08.22.19; Wed, 15 Feb 2023 08:22:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbjBOQTG (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbjBOQSs (ORCPT ); Wed, 15 Feb 2023 11:18:48 -0500 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1619539CC3; Wed, 15 Feb 2023 08:18:43 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Vbl3meW_1676477919; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl3meW_1676477919) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:40 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 3/9] net/smc: Extract v2 check helper from SMC-D device registration Date: Thu, 16 Feb 2023 00:18:19 +0800 Message-Id: <1676477905-88043-4-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914767728621675?= X-GMAIL-MSGID: =?utf-8?q?1757914767728621675?= This patch extracts v2-capable logic from the process of registering the ISM device as an SMC-D device, so that the registration process of other underlying devices can also use it. Signed-off-by: Wen Gu --- net/smc/smc_ism.c | 27 +++++++++++++++++---------- net/smc/smc_ism.h | 1 + 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c index 93c7415..9504273 100644 --- a/net/smc/smc_ism.c +++ b/net/smc/smc_ism.c @@ -69,6 +69,22 @@ bool smc_ism_is_v2_capable(void) return smc_ism_v2_capable; } +/* must be called under smcd_dev_list.mutex lock */ +void smc_ism_check_v2_capable(struct smcd_dev *smcd) +{ + u8 *system_eid = NULL; + + if (!list_empty(&smcd_dev_list.list)) + return; + + system_eid = smcd->ops->get_system_eid(); + if (system_eid[24] != '0' || system_eid[28] != '0') { + smc_ism_v2_capable = true; + memcpy(smc_ism_v2_system_eid, system_eid, + SMC_MAX_EID_LEN); + } +} + /* Set a connection using this DMBE. */ void smc_ism_set_conn(struct smc_connection *conn) { @@ -422,16 +438,7 @@ static void smcd_register_dev(struct ism_dev *ism) smc_pnetid_by_table_smcd(smcd); mutex_lock(&smcd_dev_list.mutex); - if (list_empty(&smcd_dev_list.list)) { - u8 *system_eid = NULL; - - system_eid = smcd->ops->get_system_eid(); - if (system_eid[24] != '0' || system_eid[28] != '0') { - smc_ism_v2_capable = true; - memcpy(smc_ism_v2_system_eid, system_eid, - SMC_MAX_EID_LEN); - } - } + smc_ism_check_v2_capable(smcd); /* sort list: devices without pnetid before devices with pnetid */ if (smcd->pnetid[0]) list_add_tail(&smcd->list, &smcd_dev_list.list); diff --git a/net/smc/smc_ism.h b/net/smc/smc_ism.h index 832b2f4..14d2e77 100644 --- a/net/smc/smc_ism.h +++ b/net/smc/smc_ism.h @@ -42,6 +42,7 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size, void smc_ism_get_system_eid(u8 **eid); u16 smc_ism_get_chid(struct smcd_dev *dev); bool smc_ism_is_v2_capable(void); +void smc_ism_check_v2_capable(struct smcd_dev *dev); int smc_ism_init(void); void smc_ism_exit(void); int smcd_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb); From patchwork Wed Feb 15 16:18:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57615 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp283814wrn; Wed, 15 Feb 2023 08:22:49 -0800 (PST) X-Google-Smtp-Source: AK7set8nLFam1dDge3FihhoojlSKC5UUkiwHCVKgYaPJ3IvVdsByHXlHv7r8+WA6fuLRut/KKK+m X-Received: by 2002:a17:907:2d10:b0:8b1:438e:9b3f with SMTP id gs16-20020a1709072d1000b008b1438e9b3fmr3089401ejc.20.1676478169304; Wed, 15 Feb 2023 08:22:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478169; cv=none; d=google.com; s=arc-20160816; b=AaPt/fknTLjvpHK4u1ste08qRsFS7tzq5nrxAmr28o39Pu4oT2GzZBjrhC0RbnY+7G d60K40yF3hDuVcIp0nh5Ez3UaxMh13f7dc58Oodru7vNSYD6YF53xEf9jDX+boZLH2G5 vgk9oTTfPNxjseFZohw+RnXYdH/D3VDhEmMCe6xSNtSzMqaPhXpHtYV6TInDtJoNnX0X mRkQnZtHBUZDro64v7DqdSb9U2YkglUZzwu6Y9AFFyQos5hPrdGrGQjVEfftVW0oDyjH hKgODd/yJmZSoVAvWaRkye/Ufs3qeAERuSCzeBFlHTemD4pDK2/FJQowR49pQQQ8Xfd1 suJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=3rQwrsMSmGp7UmxHe8UkzFuJDk7zSWRtaWrPUGHaK9E=; b=1Dbzf0NktYkN0g4ttXIO1igjIjdfb2ZrALaXKNGZsvohnFBVPPBFg5+NK2lrPP6kLp 7SBornxpvU9KkKW9nyhcw32kqQuV8jFROG/d4YSNmqQr/Ygk5Ov7Nni0hKIB4pEw4qL/ gHp6laqaIk6UYGtA5tBjN3qNMgsrDkCTDJYxdHinri4Bmhsq1p1UAEoYmgTMK9W7v2K/ 6Dc+Z4rgYZoZYJxJbUA6vcu2JqosBB7IntCEWRbRYnojnEKh/3v7bwTdTbGdMl79wSNy 556xUOKGMSGBokjWbZhg3akpOnJ4KB55ZbR37rCKCU1lf5pk+uW/rm76CNmezKPtt241 9VhA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 11-20020a170906208b00b008b126531c6esi320464ejq.763.2023.02.15.08.22.24; Wed, 15 Feb 2023 08:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbjBOQTM (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbjBOQSu (ORCPT ); Wed, 15 Feb 2023 11:18:50 -0500 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 663103A864; Wed, 15 Feb 2023 08:18:46 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;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=10;SR=0;TI=SMTPD_---0Vbl3mf1_1676477921; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl3mf1_1676477921) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:42 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 4/9] net/smc: Introduce SMC-D loopback device Date: Thu, 16 Feb 2023 00:18:20 +0800 Message-Id: <1676477905-88043-5-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914772827430244?= X-GMAIL-MSGID: =?utf-8?q?1757914772827430244?= This patch introduces a kind of loopback device for SMC-D, thus enabling the SMC communication between two local sockets within one OS instance. The loopback device supports basic capabilities defined by SMC-D options, and exposed as an SMC-D v2 device. Signed-off-by: Wen Gu --- include/net/smc.h | 6 + net/smc/Makefile | 2 +- net/smc/af_smc.c | 12 +- net/smc/smc_cdc.c | 9 +- net/smc/smc_cdc.h | 1 + net/smc/smc_loopback.c | 363 +++++++++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_loopback.h | 51 +++++++ 7 files changed, 441 insertions(+), 3 deletions(-) create mode 100644 net/smc/smc_loopback.c create mode 100644 net/smc/smc_loopback.h diff --git a/include/net/smc.h b/include/net/smc.h index 9b0da45..50df54d 100644 --- a/include/net/smc.h +++ b/include/net/smc.h @@ -41,6 +41,12 @@ struct smcd_dmb { dma_addr_t dma_addr; }; +struct smcd_seid { + u8 seid_string[24]; + u8 serial_number[4]; + u8 type[4]; +}; + #define ISM_EVENT_DMB 0 #define ISM_EVENT_GID 1 #define ISM_EVENT_SWR 2 diff --git a/net/smc/Makefile b/net/smc/Makefile index 875efcd..a8c3711 100644 --- a/net/smc/Makefile +++ b/net/smc/Makefile @@ -4,5 +4,5 @@ obj-$(CONFIG_SMC) += smc.o obj-$(CONFIG_SMC_DIAG) += smc_diag.o smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o smc_ism.o smc_netlink.o smc_stats.o -smc-y += smc_tracepoint.o +smc-y += smc_tracepoint.o smc_loopback.o smc-$(CONFIG_SYSCTL) += smc_sysctl.o diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 1c0fe9b..dcbd7e3 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -53,6 +53,7 @@ #include "smc_stats.h" #include "smc_tracepoint.h" #include "smc_sysctl.h" +#include "smc_loopback.h" static DEFINE_MUTEX(smc_server_lgr_pending); /* serialize link group * creation on server @@ -3454,15 +3455,23 @@ static int __init smc_init(void) goto out_sock; } + rc = smc_loopback_init(); + if (rc) { + pr_err("%s: smc_loopback_init fails with %d\n", __func__, rc); + goto out_ib; + } + rc = tcp_register_ulp(&smc_ulp_ops); if (rc) { pr_err("%s: tcp_ulp_register fails with %d\n", __func__, rc); - goto out_ib; + goto out_lo; } static_branch_enable(&tcp_have_smc); return 0; +out_lo: + smc_loopback_exit(); out_ib: smc_ib_unregister_client(); out_sock: @@ -3499,6 +3508,7 @@ static void __exit smc_exit(void) tcp_unregister_ulp(&smc_ulp_ops); sock_unregister(PF_SMC); smc_core_exit(); + smc_loopback_exit(); smc_ib_unregister_client(); smc_ism_exit(); destroy_workqueue(smc_close_wq); diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c index 53f63bf..9023684 100644 --- a/net/smc/smc_cdc.c +++ b/net/smc/smc_cdc.c @@ -407,7 +407,14 @@ static void smc_cdc_msg_recv(struct smc_sock *smc, struct smc_cdc_msg *cdc) */ static void smcd_cdc_rx_tsklet(struct tasklet_struct *t) { - struct smc_connection *conn = from_tasklet(conn, t, rx_tsklet); + struct smc_connection *conn = + from_tasklet(conn, t, rx_tsklet); + + smcd_cdc_rx_handler(conn); +} + +void smcd_cdc_rx_handler(struct smc_connection *conn) +{ struct smcd_cdc_msg *data_cdc; struct smcd_cdc_msg cdc; struct smc_sock *smc; diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h index 696cc11..11559d4 100644 --- a/net/smc/smc_cdc.h +++ b/net/smc/smc_cdc.h @@ -301,5 +301,6 @@ int smcr_cdc_msg_send_validation(struct smc_connection *conn, struct smc_wr_buf *wr_buf); int smc_cdc_init(void) __init; void smcd_cdc_rx_init(struct smc_connection *conn); +void smcd_cdc_rx_handler(struct smc_connection *conn); #endif /* SMC_CDC_H */ diff --git a/net/smc/smc_loopback.c b/net/smc/smc_loopback.c new file mode 100644 index 0000000..38bacd8 --- /dev/null +++ b/net/smc/smc_loopback.c @@ -0,0 +1,363 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Shared Memory Communications Direct over loopback device. + * + * Provide a SMC-D loopback dummy device. + * + * Copyright (c) 2022, Alibaba Inc. + * + * Author: Wen Gu + * Tony Lu + * + */ + +#include +#include +#include + +#include "smc_cdc.h" +#include "smc_ism.h" +#include "smc_loopback.h" + +static struct smc_lo_dev *lo_dev; +static const char smc_lo_dev_name[] = "smcd_loopback_dev"; + +static struct smcd_seid SMC_DEFAULT_V2_SEID = { + .seid_string = "IBM-SYSZ-ISMSEID00000000", + .serial_number = "1000", + .type = "1000", +}; + +static inline void smc_lo_gen_id(struct smc_lo_dev *ldev) +{ + /* TODO: ensure local_gid is unique. + */ + get_random_bytes(&ldev->local_gid, sizeof(ldev->local_gid)); + ldev->chid = SMC_LO_CHID; +} + +static int smc_lo_query_rgid(struct smcd_dev *smcd, u64 rgid, + u32 vid_valid, u32 vid) +{ + struct smc_lo_dev *ldev = smcd->priv; + + /* rgid should equal to lgid in loopback */ + if (!ldev || rgid != ldev->local_gid) + return -ENETUNREACH; + return 0; +} + +static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, + void *client_priv) +{ + struct smc_lo_dev *ldev = smcd->priv; + struct smc_lo_dmb_node *dmb_node; + int sba_idx, rc; + + /* check space for new dmb */ + for_each_clear_bit(sba_idx, ldev->sba_idx_mask, SMC_LODEV_MAX_DMBS) { + if (!test_and_set_bit(sba_idx, ldev->sba_idx_mask)) + break; + } + if (sba_idx == SMC_LODEV_MAX_DMBS) + return -ENOSPC; + + dmb_node = kzalloc(sizeof(*dmb_node), GFP_KERNEL); + if (!dmb_node) { + rc = -ENOMEM; + goto err_bit; + } + + dmb_node->sba_idx = sba_idx; + dmb_node->cpu_addr = kzalloc(dmb->dmb_len, GFP_KERNEL | + __GFP_NOWARN | __GFP_NORETRY | + __GFP_NOMEMALLOC); + if (!dmb_node->cpu_addr) { + rc = -ENOMEM; + goto err_node; + } + dmb_node->len = dmb->dmb_len; + + /* TODO: token is random but not exclusive ! + * suppose to find token in dmb hask table, if has this token + * already, then generate another one. + */ + /* add new dmb into hash table */ + get_random_bytes(&dmb_node->token, sizeof(dmb_node->token)); + write_lock(&ldev->dmb_ht_lock); + hash_add(ldev->dmb_ht, &dmb_node->list, dmb_node->token); + write_unlock(&ldev->dmb_ht_lock); + + 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; + +err_node: + kfree(dmb_node); +err_bit: + clear_bit(sba_idx, ldev->sba_idx_mask); + return rc; +} + +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(&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) { + write_unlock(&ldev->dmb_ht_lock); + return -EINVAL; + } + hash_del(&dmb_node->list); + write_unlock(&ldev->dmb_ht_lock); + + clear_bit(dmb_node->sba_idx, ldev->sba_idx_mask); + kfree(dmb_node->cpu_addr); + kfree(dmb_node); + + return 0; +} + +static int smc_lo_add_vlan_id(struct smcd_dev *smcd, u64 vlan_id) +{ + return -EOPNOTSUPP; +} + +static int smc_lo_del_vlan_id(struct smcd_dev *smcd, u64 vlan_id) +{ + return -EOPNOTSUPP; +} + +static int smc_lo_set_vlan_required(struct smcd_dev *smcd) +{ + return -EOPNOTSUPP; +} + +static int smc_lo_reset_vlan_required(struct smcd_dev *smcd) +{ + return -EOPNOTSUPP; +} + +static int smc_lo_move_data(struct smcd_dev *smcd, u64 dmb_tok, unsigned int idx, + bool sf, unsigned int offset, void *data, + unsigned int size) +{ + struct smc_lo_dmb_node *rmb_node = NULL, *tmp_node; + struct smc_lo_dev *ldev = smcd->priv; + + read_lock(&ldev->dmb_ht_lock); + hash_for_each_possible(ldev->dmb_ht, tmp_node, list, dmb_tok) { + if (tmp_node->token == dmb_tok) { + rmb_node = tmp_node; + break; + } + } + if (!rmb_node) { + read_unlock(&ldev->dmb_ht_lock); + return -EINVAL; + } + read_unlock(&ldev->dmb_ht_lock); + + memcpy((char *)rmb_node->cpu_addr + offset, data, size); + + if (sf) { + struct smc_connection *conn = + smcd->conn[rmb_node->sba_idx]; + + if (conn && !conn->killed) + smcd_cdc_rx_handler(conn); + } + return 0; +} + +static u8 *smc_lo_get_system_eid(void) +{ + return SMC_DEFAULT_V2_SEID.seid_string; +} + +static u64 smc_lo_get_local_gid(struct smcd_dev *smcd) +{ + return ((struct smc_lo_dev *)smcd->priv)->local_gid; +} + +static u16 smc_lo_get_chid(struct smcd_dev *smcd) +{ + return ((struct smc_lo_dev *)smcd->priv)->chid; +} + +static struct device *smc_lo_get_dev(struct smcd_dev *smcd) +{ + return &((struct smc_lo_dev *)smcd->priv)->dev; +} + +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, + .add_vlan_id = smc_lo_add_vlan_id, + .del_vlan_id = smc_lo_del_vlan_id, + .set_vlan_required = smc_lo_set_vlan_required, + .reset_vlan_required = smc_lo_reset_vlan_required, + .signal_event = NULL, + .move_data = smc_lo_move_data, + .get_system_eid = smc_lo_get_system_eid, + .get_local_gid = smc_lo_get_local_gid, + .get_chid = smc_lo_get_chid, + .get_dev = smc_lo_get_dev, +}; + +static struct smcd_dev *smcd_lo_alloc_dev(const struct smcd_ops *ops, + int max_dmbs) +{ + struct smcd_dev *smcd; + + smcd = kzalloc(sizeof(*smcd), GFP_KERNEL); + if (!smcd) + return NULL; + + smcd->conn = kcalloc(max_dmbs, sizeof(struct smc_connection *), + GFP_KERNEL); + if (!smcd->conn) + goto out_smcd; + + smcd->ops = ops; + + spin_lock_init(&smcd->lock); + spin_lock_init(&smcd->lgr_lock); + INIT_LIST_HEAD(&smcd->vlan); + INIT_LIST_HEAD(&smcd->lgr_list); + init_waitqueue_head(&smcd->lgrs_deleted); + return smcd; + +out_smcd: + kfree(smcd); + return NULL; +} + +static int smcd_lo_register_dev(struct smc_lo_dev *ldev) +{ + struct smcd_dev *smcd; + + smcd = smcd_lo_alloc_dev(&lo_ops, SMC_LODEV_MAX_DMBS); + if (!smcd) + return -ENOMEM; + + ldev->smcd = smcd; + smcd->priv = ldev; + smcd->parent_pci_dev = NULL; + mutex_lock(&smcd_dev_list.mutex); + smc_ism_check_v2_capable(smcd); + list_add(&smcd->list, &smcd_dev_list.list); + mutex_unlock(&smcd_dev_list.mutex); + pr_warn_ratelimited("smc: adding smcd device %s with pnetid %.16s%s\n", + smc_lo_dev_name, smcd->pnetid, + smcd->pnetid_by_user ? " (user defined)" : ""); + return 0; +} + +static void smcd_lo_unregister_dev(struct smc_lo_dev *ldev) +{ + struct smcd_dev *smcd = ldev->smcd; + + pr_warn_ratelimited("smc: removing smcd device %s\n", + smc_lo_dev_name); + smcd->going_away = 1; + smc_smcd_terminate_all(smcd); + mutex_lock(&smcd_dev_list.mutex); + list_del_init(&smcd->list); + mutex_unlock(&smcd_dev_list.mutex); +} + +static void smc_lo_dev_release(struct device *dev) +{ + struct smc_lo_dev *ldev = + container_of(dev, struct smc_lo_dev, dev); + struct smcd_dev *smcd = ldev->smcd; + + kfree(smcd->conn); + kfree(smcd); + kfree(ldev); +} + +static int smc_lo_dev_init(struct smc_lo_dev *ldev) +{ + smc_lo_gen_id(ldev); + rwlock_init(&ldev->dmb_ht_lock); + hash_init(ldev->dmb_ht); + + return smcd_lo_register_dev(ldev); +} + +static int smc_lo_dev_probe(void) +{ + struct smc_lo_dev *ldev; + int ret; + + ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); + if (!ldev) + return -ENOMEM; + + ldev->dev.parent = NULL; + ldev->dev.release = smc_lo_dev_release; + device_initialize(&ldev->dev); + dev_set_name(&ldev->dev, smc_lo_dev_name); + ret = device_add(&ldev->dev); + if (ret) + goto free_dev; + + ret = smc_lo_dev_init(ldev); + if (ret) + goto put_dev; + + lo_dev = ldev; /* global loopback device */ + return 0; + +put_dev: + device_del(&ldev->dev); +free_dev: + kfree(ldev); + return ret; +} + +static void smc_lo_dev_exit(struct smc_lo_dev *ldev) +{ + smcd_lo_unregister_dev(ldev); +} + +static void smc_lo_dev_remove(void) +{ + if (!lo_dev) + return; + + smc_lo_dev_exit(lo_dev); + device_del(&lo_dev->dev); /* device_add in smc_lo_dev_probe */ + put_device(&lo_dev->dev); /* device_initialize in smc_lo_dev_probe */ +} + +int smc_loopback_init(void) +{ +#if !IS_ENABLED(CONFIG_ISM) + return smc_lo_dev_probe(); +#else + return 0; +#endif +} + +void smc_loopback_exit(void) +{ +#if !IS_ENABLED(CONFIG_ISM) + smc_lo_dev_remove(); +#endif +} diff --git a/net/smc/smc_loopback.h b/net/smc/smc_loopback.h new file mode 100644 index 0000000..9d34aba --- /dev/null +++ b/net/smc/smc_loopback.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Shared Memory Communications Direct over loopback device. + * + * Provide a SMC-D loopback dummy device. + * + * Copyright (c) 2022, Alibaba Inc. + * + * Author: Wen Gu + * Tony Lu + * + */ + +#ifndef _SMC_LOOPBACK_H +#define _SMC_LOOPBACK_H + +#include +#include +#include +#include +#include + +#include "smc_core.h" + +#define SMC_LO_CHID 0xFFFF +#define SMC_LODEV_MAX_DMBS 5000 +#define SMC_LODEV_MAX_DMBS_BUCKETS 16 + +struct smc_lo_dmb_node { + struct hlist_node list; + u64 token; + u32 len; + u32 sba_idx; + void *cpu_addr; + dma_addr_t dma_addr; +}; + +struct smc_lo_dev { + struct smcd_dev *smcd; + struct device dev; + u16 chid; + u64 local_gid; + DECLARE_BITMAP(sba_idx_mask, SMC_LODEV_MAX_DMBS); + rwlock_t dmb_ht_lock; + DECLARE_HASHTABLE(dmb_ht, SMC_LODEV_MAX_DMBS_BUCKETS); +}; + +int smc_loopback_init(void); +void smc_loopback_exit(void); + +#endif /* _SMC_LOOPBACK_H */ From patchwork Wed Feb 15 16:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57614 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp283784wrn; Wed, 15 Feb 2023 08:22:44 -0800 (PST) X-Google-Smtp-Source: AK7set9J9xrvuZPvJP3MmAYj/2M58qunBtrdbQmUMTlhDykKdM7dLmdogB31jvk4gNFUGSrt/tRH X-Received: by 2002:a05:6402:284:b0:4ac:b5c6:45c3 with SMTP id l4-20020a056402028400b004acb5c645c3mr2601560edv.36.1676478164539; Wed, 15 Feb 2023 08:22:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478164; cv=none; d=google.com; s=arc-20160816; b=UDxwGRKas8ZBaBbZIzeUipOY4q55B4263SSRE0PUwpLEX/vNIo+uD4LiDDEPUj8nEN 1iXJELT89QL6n9cvCZCZP34L5yxU4VZmplpCeb0OmKIx3AuBlVqLDYGpQm4YJSUImQBY BYjsKqLOdhVEkD0rvRSEPqEL6Y+IG9L0AkOfWckfdP7eSjO6/2jGpDAzyrh7oDbjxAz4 PAK7Py9UFrZxLQoqUcW9o4UCzPHwRmuDcVfekubYEOYbjqmzRB8wpkw7KOsGBIukKFwX OQzGAz3OoxspRItJqIQ0AO32XypLyMFAUI/uqwE78GwtatwgWvmgrL5clAzY1o04e8Hy dHsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=U36Uo493azS6l2fQudEXtQ14kX+Ow/2V697hiscbazE=; b=VhX0i+RRoUVlGNGiW7A+QDtYZu6OI5PkY4Mq9FXtwhUor6CR9ttIbzUMoLh1eoyl4p QHf2ywm0GqRypWlHzJHBHcp0Att+29Piv8BPaojfPE4NZ8CERWksER9SKMyy3Lb8XGsv ZnZ0JtpM7rs5+r0HcTYrQITgxZIQuGft4UD5MrrrmoJhEWDfNvHLeFP6qE05HEHZFene T7raa7c509AfF7WGI78DZNLXuiqgF+gx1aQC+IjFda7XeyVXYAJA6GCgOBT91TmR46Ls mBezBOtn7qiPTFTOEGj1p1TyrCjpR82+7ffS4P2//f9SF/rndjmJTHmG3zgbI+Z6PJgG dTvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k20-20020a056402049400b0049e48d13300si20902928edv.459.2023.02.15.08.22.20; Wed, 15 Feb 2023 08:22:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230097AbjBOQTJ (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230014AbjBOQSt (ORCPT ); Wed, 15 Feb 2023 11:18:49 -0500 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EEF13A85D; Wed, 15 Feb 2023 08:18:46 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Vbl2feR_1676477922; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl2feR_1676477922) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:44 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 5/9] net/smc: Introduce an interface for getting DMB attribute Date: Thu, 16 Feb 2023 00:18:21 +0800 Message-Id: <1676477905-88043-6-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914767962815837?= X-GMAIL-MSGID: =?utf-8?q?1757914767962815837?= On s390, since all OSs run on a kind of machine level hypervisor which is a partitioning hypervisor without paging, the sndbufs and DMBs in such case are unable to be mapped to the same physical memory. However, in other scene, such as communication within the same OS instance (loopback) or between guests of a paging hypervisor, eg. KVM, the sndbufs and DMBs can be mapped to the same physical memory to avoid memory copy from sndbufs to DMBs. So this patch introduces an interface to smcd_ops for users to judge whether DMB-map is available. And for reuse, the interface is designed to return DMB attribute, not only mappability. Signed-off-by: Wen Gu --- include/net/smc.h | 5 +++++ net/smc/smc_ism.c | 8 ++++++++ net/smc/smc_ism.h | 1 + 3 files changed, 14 insertions(+) diff --git a/include/net/smc.h b/include/net/smc.h index 50df54d..256d600 100644 --- a/include/net/smc.h +++ b/include/net/smc.h @@ -55,6 +55,10 @@ struct smcd_seid { #define ISM_ERROR 0xFFFF +enum { + ISM_DMB_MAPPABLE = 0, +}; + struct smcd_dev; struct smcd_ops { @@ -76,6 +80,7 @@ struct smcd_ops { u64 (*get_local_gid)(struct smcd_dev *dev); u16 (*get_chid)(struct smcd_dev *dev); struct device* (*get_dev)(struct smcd_dev *dev); + int (*get_dev_dmb_attr)(struct smcd_dev *dev); }; struct smcd_dev { diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c index 9504273..e085c48 100644 --- a/net/smc/smc_ism.c +++ b/net/smc/smc_ism.c @@ -213,6 +213,14 @@ int smc_ism_unregister_dmb(struct smcd_dev *smcd, struct smc_buf_desc *dmb_desc) return rc; } +bool smc_ism_dmb_mappable(struct smcd_dev *smcd) +{ + if (smcd->ops->get_dev_dmb_attr && + (smcd->ops->get_dev_dmb_attr(smcd) & (1 << ISM_DMB_MAPPABLE))) + return true; + return false; +} + int smc_ism_register_dmb(struct smc_link_group *lgr, int dmb_len, struct smc_buf_desc *dmb_desc) { diff --git a/net/smc/smc_ism.h b/net/smc/smc_ism.h index 14d2e77..aabea35 100644 --- a/net/smc/smc_ism.h +++ b/net/smc/smc_ism.h @@ -38,6 +38,7 @@ struct smc_ism_vlanid { /* VLAN id set on ISM device */ int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size, struct smc_buf_desc *dmb_desc); int smc_ism_unregister_dmb(struct smcd_dev *dev, struct smc_buf_desc *dmb_desc); +bool smc_ism_dmb_mappable(struct smcd_dev *smcd); int smc_ism_signal_shutdown(struct smc_link_group *lgr); void smc_ism_get_system_eid(u8 **eid); u16 smc_ism_get_chid(struct smcd_dev *dev); From patchwork Wed Feb 15 16:18:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp283973wrn; Wed, 15 Feb 2023 08:23:08 -0800 (PST) X-Google-Smtp-Source: AK7set8B9ty2Jx3ZDEZLmxSEPlfVEXBar5234nyvwXjdtcaFXCPvruc46Gycqx3Rf2H4BMPF08uZ X-Received: by 2002:a05:6402:516b:b0:4ac:bd93:e453 with SMTP id d11-20020a056402516b00b004acbd93e453mr2710625ede.22.1676478188102; Wed, 15 Feb 2023 08:23:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478188; cv=none; d=google.com; s=arc-20160816; b=JAAoFXtPW6OKk37sw8L8TPfsZRvq4gSjQ5JbpwJ49p5K7bpHsGwc4Vif8Fq6UJFbhE ojbx+uIiQhVvqfLLQFO/2+OxagHoKRwmA6JVxOv/80Rh+4uGpxXmlcmGWBWkCsf7PPyu i/Bg7rxg+Pwx9sHOiOBDZ3mT1j/nz09F9BiKHzZcgpC1+SmGxL+PTtNbPbHQQqLuMnN4 M09V1j8RFYcM7PkRvBlfMpwXFG3whUEBkUwN08g7po2uAWhKP0BTQ5IKhF10PIyjL3KI fV+srK5UjAO6q5A0va8F5m9adrUeSIxs+LDvDB21mPZw1LsB4oF5nqN+FAYbKIr8skoJ 3whA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=jKxxqr4ChVk6NmGXSYxCvZYpLMf7WwhXQjJUwH/T3Nw=; b=XFbOWwCE/hKL+0EZELg4C/np8cGptlA+48QGUojXvqjOEGmEh0h0clbokEB2u6TCiC extHnSnmndblmk+e7H49oOcCFLHcuj+VlzPsDZ6grFHf7UrnO26VmpS5J+k8vpBxmZhV Bztaampo6DRY+a7SzCjzotlIWaBfMmgABeekJFKZ7yMXI9he68DXkq5wAfoOMvbHzzbQ 1Tmwz7kuaf8b/g7jucVpWuthnbKz9ol4fl9uBHpZCl9dBGH/Gec8z8u1g/hU1SG8GZWp tDOUgKXTIsPAlIR+qQrxDGz6W8GaM4QKWX9ooCC5HtzSxG2ONn9KTFMFIZBUllzDcdEJ qn2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020aa7c0cb000000b004acd971cf09si6464edp.503.2023.02.15.08.22.42; Wed, 15 Feb 2023 08:23:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjBOQTW (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbjBOQSx (ORCPT ); Wed, 15 Feb 2023 11:18:53 -0500 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5B643B0E8; Wed, 15 Feb 2023 08:18:50 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Vbl3P-7_1676477924; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl3P-7_1676477924) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:45 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 6/9] net/smc: Introudce interfaces for DMB attach and detach Date: Thu, 16 Feb 2023 00:18:22 +0800 Message-Id: <1676477905-88043-7-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914793003484580?= X-GMAIL-MSGID: =?utf-8?q?1757914793003484580?= This patch extends smcd_ops, adding two more semantic for SMC-D DMB: - attach_dmb: Attach an already registered DMB to a specific buf_desc, so that we can refer to the DMB through this buf_desc. - detach_dmb: Reverse operation of attach_dmb. detach the DMB from the buf_desc. This interface extension is to prepare for the avoidance of memory copy from sndbuf to DMB with SMC-D device whose DMBs has ISM_DMB_MAPPABLE attribute. Signed-off-by: Wen Gu --- include/net/smc.h | 2 ++ net/smc/smc_ism.c | 31 +++++++++++++++++++++++++++++++ net/smc/smc_ism.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/include/net/smc.h b/include/net/smc.h index 256d600..0790e64 100644 --- a/include/net/smc.h +++ b/include/net/smc.h @@ -67,6 +67,8 @@ struct smcd_ops { int (*register_dmb)(struct smcd_dev *dev, struct smcd_dmb *dmb, void *client_priv); int (*unregister_dmb)(struct smcd_dev *dev, struct smcd_dmb *dmb); + int (*attach_dmb)(struct smcd_dev *dev, struct smcd_dmb *dmb); + int (*detach_dmb)(struct smcd_dev *dev, u64 token); int (*add_vlan_id)(struct smcd_dev *dev, u64 vlan_id); int (*del_vlan_id)(struct smcd_dev *dev, u64 vlan_id); int (*set_vlan_required)(struct smcd_dev *dev); diff --git a/net/smc/smc_ism.c b/net/smc/smc_ism.c index e085c48..e2670e3 100644 --- a/net/smc/smc_ism.c +++ b/net/smc/smc_ism.c @@ -243,6 +243,37 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int dmb_len, return rc; } +int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token, + struct smc_buf_desc *dmb_desc) +{ + struct smcd_dmb dmb; + int rc = 0; + + memset(&dmb, 0, sizeof(dmb)); + dmb.dmb_tok = token; + + if (!dev->ops->attach_dmb) + return -EINVAL; + + rc = dev->ops->attach_dmb(dev, &dmb); + if (!rc) { + dmb_desc->sba_idx = dmb.sba_idx; + dmb_desc->token = dmb.dmb_tok; + dmb_desc->cpu_addr = dmb.cpu_addr; + dmb_desc->dma_addr = dmb.dma_addr; + dmb_desc->len = dmb.dmb_len; + } + return rc; +} + +int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token) +{ + if (!dev->ops->detach_dmb) + return -EINVAL; + + return dev->ops->detach_dmb(dev, token); +} + static int smc_nl_handle_smcd_dev(struct smcd_dev *smcd, struct sk_buff *skb, struct netlink_callback *cb) diff --git a/net/smc/smc_ism.h b/net/smc/smc_ism.h index aabea35..fc16dc2 100644 --- a/net/smc/smc_ism.h +++ b/net/smc/smc_ism.h @@ -39,6 +39,8 @@ int smc_ism_register_dmb(struct smc_link_group *lgr, int buf_size, struct smc_buf_desc *dmb_desc); int smc_ism_unregister_dmb(struct smcd_dev *dev, struct smc_buf_desc *dmb_desc); bool smc_ism_dmb_mappable(struct smcd_dev *smcd); +int smc_ism_attach_dmb(struct smcd_dev *dev, u64 token, struct smc_buf_desc *dmb_desc); +int smc_ism_detach_dmb(struct smcd_dev *dev, u64 token); int smc_ism_signal_shutdown(struct smc_link_group *lgr); void smc_ism_get_system_eid(u8 **eid); u16 smc_ism_get_chid(struct smcd_dev *dev); From patchwork Wed Feb 15 16:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp284067wrn; Wed, 15 Feb 2023 08:23:18 -0800 (PST) X-Google-Smtp-Source: AK7set8JZ7Zwxer9E9ruSXPvJ4tJEtKMbr3HOtx/5v4M9azP8Hgy8GNTIpDP0PBYtdB3m3Bj0v7T X-Received: by 2002:aa7:c04d:0:b0:4ac:bdeb:6dce with SMTP id k13-20020aa7c04d000000b004acbdeb6dcemr2262291edo.39.1676478198686; Wed, 15 Feb 2023 08:23:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478198; cv=none; d=google.com; s=arc-20160816; b=wg/QrArGqd2vif6f0+59Q3aQPA8y0exv0ceBVlGN0mDihSwCB48QTXiahX+i6wamRn krpDRqFM4KlgIFniwFgOJdEaM5CPEfDdxAs9qZQO4QfMLazJRlNHW+vbBQV8/E5dym4b LZqNLHJQhI++2QISiDz0J3V7AC48pBn6bpr0mMSMhGNsIsv1k6QEyBhPCy5//ETUe+d7 0sc9tSX2MemCvvFmYIVw35j4Oq3guhcwO/vhQgs0RvZ8X9My6Kv1eJqlZBwUjXfzPE42 /HFu1uCq1LrX5gd1dZUEmpTBJeDlOMXtTX2kmV/BNh2BVqnDBAhdOt5DYVS9/pX5q9qq qj0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=4OhS6ng66lSBXKq7FuNeulie3od4SxPGEUi8pCSExRo=; b=ijzLKiZ7j46q24NT4E7uIvObqoZ+E0/7A2rbbhr60DruscsmZp2MxSkKyM4q33P78t d10vRKccyHKz5O8Xge33CKsaL8yeIIn9/I6HsH/kgVlobkZ8YpbGyGRPYc6GSD0KOwaF KXM1zWg6QdHmjNhdwOoNqVX5s0p+xkLnXhwUyI8CcWLzfNrCxYO5QhNqBwtaPbemQT+q 6hsXh68nQxMQbm8r4CCnz+w4g9sYeurNd9slLX8EKfxkTAVUv54RYEbRV4POef8SbwtX n4Cyeq7i6+wige5HTm7G3y/iw5l7Noj+guhHmiQjYzTN7YyvpqTBbTA6nWQDke6V+yEz WcTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020aa7df8f000000b004ab44dde183si441507edy.281.2023.02.15.08.22.54; Wed, 15 Feb 2023 08:23:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbjBOQTZ (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229982AbjBOQS6 (ORCPT ); Wed, 15 Feb 2023 11:18:58 -0500 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C61563B0E6; Wed, 15 Feb 2023 08:18:50 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Vbl.oTZ_1676477926; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl.oTZ_1676477926) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:47 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 7/9] net/smc: Avoid data copy from sndbuf to peer RMB in SMC-D Date: Thu, 16 Feb 2023 00:18:23 +0800 Message-Id: <1676477905-88043-8-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914803498769512?= X-GMAIL-MSGID: =?utf-8?q?1757914803498769512?= This patch aims to avoid data copy from local sndbuf to peer RMB by attaching local sndbuf to peer RMB when DMBs have ISM_DMB_MAPPABLE attribute. After this, local sndbuf and peer RMB share the same physical memory. +----------+ +----------+ | socket A | | socket B | +----------+ +----------+ | ^ | +---------+ | regard as | | ----------| local sndbuf | B's | regard as | | RMB | local RMB |-------> | | +---------+ 1. Actions on local RMB. a. Create or reuse RMB when connection is created; b. Unuse RMB when connection is freed; c. Free RMB when link group is freed; 2. Actions on local sndbuf.Attach local sndbuf to peer RMB. a. Attach local sndbuf to peer RMB by the rtoken exchanged through CLC message. Since then, accessing local sndbuf is equivalent to accessing peer RMB b. sndbuf_desc is exclusive to specific connection and won't be added to lgr buffer pool for reuse. c. Local sndbuf is detached from peer RMB when connection is freed, and sndbuf_desc will be freed. Therefore, the data written to local sndbuf will directly reach peer RMB. Signed-off-by: Wen Gu --- net/smc/af_smc.c | 14 +++++++++++ net/smc/smc_core.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++- net/smc/smc_core.h | 1 + 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index dcbd7e3..079a9f1 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -1366,6 +1366,12 @@ static int smc_connect_ism(struct smc_sock *smc, } smc_conn_save_peer_info(smc, aclc); + + if (smc_ism_dmb_mappable(smc->conn.lgr->smcd)) { + rc = smcd_buf_attach(smc); + if (rc) + goto connect_abort; + } smc_close_init(smc); smc_rx_init(smc); smc_tx_init(smc); @@ -2422,6 +2428,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_dmb_mappable(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 7642b16..5ed018b 100644 --- a/net/smc/smc_core.c +++ b/net/smc/smc_core.c @@ -1129,6 +1129,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) { @@ -1175,6 +1189,10 @@ void smc_conn_free(struct smc_connection *conn) if (!list_empty(&lgr->list)) smc_ism_unset_conn(conn); tasklet_kill(&conn->rx_tsklet); + + /* detach sndbuf from peer RMB */ + if (smc_ism_dmb_mappable(lgr->smcd)) + smcd_buf_detach(conn); } else { smc_cdc_wait_pend_tx_wr(conn); if (current_work() != &conn->abort_work) @@ -2425,15 +2443,23 @@ void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn) */ int smc_buf_create(struct smc_sock *smc, bool is_smcd) { + bool sndbuf_created = false; int rc; + if (is_smcd && + smc_ism_dmb_mappable(smc->conn.lgr->smcd)) + goto create_rmb; + /* create send buffer */ rc = __smc_buf_create(smc, is_smcd, false); if (rc) return rc; + sndbuf_created = true; + +create_rmb: /* create rmb */ rc = __smc_buf_create(smc, is_smcd, true); - if (rc) { + if (rc && sndbuf_created) { mutex_lock(&smc->conn.lgr->sndbufs_lock); list_del(&smc->conn.sndbuf_desc->list); mutex_unlock(&smc->conn.lgr->sndbufs_lock); @@ -2443,6 +2469,48 @@ 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; + + /* map local sndbuf desc to peer RMB, so operations on local + * sndbuf are equivalent to operations on peer RMB. + */ + rc = smc_ism_attach_dmb(smcd, peer_token, buf_desc); + if (rc) { + rc = SMC_CLC_DECL_MEM; + 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: + if (conn->rmb_desc) { + /* free local RMB as well */ + mutex_lock(&conn->lgr->rmbs_lock); + list_del(&conn->rmb_desc->list); + mutex_unlock(&conn->lgr->rmbs_lock); + smc_buf_free(conn->lgr, true, conn->rmb_desc); + conn->rmb_desc = NULL; + } + 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 285f9bd..080c810 100644 --- a/net/smc/smc_core.h +++ b/net/smc/smc_core.h @@ -518,6 +518,7 @@ void smc_smcd_terminate(struct smcd_dev *dev, u64 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); From patchwork Wed Feb 15 16:18:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp284701wrn; Wed, 15 Feb 2023 08:24:37 -0800 (PST) X-Google-Smtp-Source: AK7set+I36rnP9p/ceFjxFUODG/NMsixWpZu2PCH8DBnIGlwct5eUePB+3w6mmkcWeJDb6DU8rN3 X-Received: by 2002:a17:906:a41a:b0:877:ef84:c7de with SMTP id l26-20020a170906a41a00b00877ef84c7demr2408143ejz.61.1676478277323; Wed, 15 Feb 2023 08:24:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478277; cv=none; d=google.com; s=arc-20160816; b=sl7dzF0KifQ9p9cWwrAmt3GFFQ3wrPFM2stWMhOAW5VNnGHf6jD9vc7X2zySvjlT88 2aoPYrDsYkLdo0uu5GQqfmkCEO/S7E0mTPL9HlTy9m+TZTMTLJYtBrsgQ/0WecHXjWQs ZxOwsNLSbt+u+eZFa/dg6ZTR7cZvJMqtczbnHaTcAkAFu/oAXSYyh6HpjWGCplLc5aXN yGj8006Pb8F96QspLPX/5er6kpuHfJJGsb3yHulhwlzqPcDoeG3XfeBxj7X+ZzWY0H4a rdt1dy7nGcu0C/74QLrREM0+C85QtsTYjenX3KDtWf9Wwu+4baHJRm2WklMhaUcAUhOO lnqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=RE5yQDtIYXcVGRdSptSw8SumkpVF5dzzzQlZyO6QjA0=; b=h9kMVhlGS4LVOFDz4Rj4wxLyzAJU4HX5yWU8H20xO8S7U3Yjz08uRu22Cgt79O6J4p qH56ijR0Fn8UkISK4VSunmaqmQmmB8BHxACJrgu4fkYdkIK9zCy3kGMHPGPl9ORmoZsk dITYJT9V+SHBW5wXt8faA/7Sjxtj76gc2nsQm45wdQgMS/cUkYmC71nhAlzb6AIsuzeD yk5VNTkDlyRc0aw0wd8UuPLGkPRw74vSQ/m/gWgoHezu3n2FpsA/51RI4iUEaEIbc3or hPy+hEUWKxHdLVoEOS4Aj2UZ0u4A6FnPmKN5TNOrwmkLjUJH9Zjf13heaCVvzGT9MilF wgBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id uo37-20020a170907cc2500b008aa6e271052si20954288ejc.540.2023.02.15.08.24.13; Wed, 15 Feb 2023 08:24:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229795AbjBOQT2 (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbjBOQS7 (ORCPT ); Wed, 15 Feb 2023 11:18:59 -0500 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33F6F3B0CE; Wed, 15 Feb 2023 08:18:52 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R811e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Vbl04yG_1676477927; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl04yG_1676477927) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:49 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 8/9] net/smc: Modify cursor update logic when using mappable DMB Date: Thu, 16 Feb 2023 00:18:24 +0800 Message-Id: <1676477905-88043-9-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914886159295086?= X-GMAIL-MSGID: =?utf-8?q?1757914886159295086?= Since local sndbuf shares the same physical memory region with peer RMB when using mappable DMBs, the cursor update logic needs to be adapted. The main concern is to ensure that the data written by local to this memory region won't overwrite the data that has not been consumed by the peer. So in this scene, the fin_curs and sndbuf_space that were originally updated when sending out CDC message are not updated until the cons_curs update from the peer is received. Signed-off-by: Wen Gu --- net/smc/smc_cdc.c | 50 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c index 9023684..74fcd2f 100644 --- a/net/smc/smc_cdc.c +++ b/net/smc/smc_cdc.c @@ -18,6 +18,7 @@ #include "smc_tx.h" #include "smc_rx.h" #include "smc_close.h" +#include "smc_ism.h" /********************************** send *************************************/ @@ -253,17 +254,24 @@ int smcd_cdc_msg_send(struct smc_connection *conn) return rc; smc_curs_copy(&conn->rx_curs_confirmed, &curs, conn); conn->local_rx_ctrl.prod_flags.cons_curs_upd_req = 0; - /* Calculate transmitted data and increment free send buffer space */ - diff = smc_curs_diff(conn->sndbuf_desc->len, &conn->tx_curs_fin, - &conn->tx_curs_sent); - /* increased by confirmed number of bytes */ - smp_mb__before_atomic(); - atomic_add(diff, &conn->sndbuf_space); - /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */ - smp_mb__after_atomic(); - smc_curs_copy(&conn->tx_curs_fin, &conn->tx_curs_sent, conn); + if (!smc_ism_dmb_mappable(conn->lgr->smcd)) { + /* If local sndbuf has been mapped to peer RMB, then + * don't update the tx_curs_fin and sndbuf_space until + * peer has consumed the data in RMB. + */ - smc_tx_sndbuf_nonfull(smc); + /* Calculate transmitted data and increment free send buffer space */ + diff = smc_curs_diff(conn->sndbuf_desc->len, &conn->tx_curs_fin, + &conn->tx_curs_sent); + /* increased by confirmed number of bytes */ + smp_mb__before_atomic(); + atomic_add(diff, &conn->sndbuf_space); + /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */ + smp_mb__after_atomic(); + smc_curs_copy(&conn->tx_curs_fin, &conn->tx_curs_sent, conn); + + smc_tx_sndbuf_nonfull(smc); + } return rc; } @@ -321,7 +329,7 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc, { union smc_host_cursor cons_old, prod_old; struct smc_connection *conn = &smc->conn; - int diff_cons, diff_prod; + int diff_cons, diff_prod, diff_tx; smc_curs_copy(&prod_old, &conn->local_rx_ctrl.prod, conn); smc_curs_copy(&cons_old, &conn->local_rx_ctrl.cons, conn); @@ -337,6 +345,26 @@ static void smc_cdc_msg_recv_action(struct smc_sock *smc, atomic_add(diff_cons, &conn->peer_rmbe_space); /* guarantee 0 <= peer_rmbe_space <= peer_rmbe_size */ smp_mb__after_atomic(); + + if (conn->lgr->is_smcd && + smc_ism_dmb_mappable(conn->lgr->smcd)) { + /* If local sndbuf has been mapped to peer RMB, then + * update tx_curs_fin and sndbuf_space when peer has + * consumed the data in it's RMB. + */ + + /* calculate peer rmb consumed data */ + diff_tx = smc_curs_diff(conn->sndbuf_desc->len, &conn->tx_curs_fin, + &conn->local_rx_ctrl.cons); + /* increase local sndbuf space and fin_curs */ + smp_mb__before_atomic(); + atomic_add(diff_tx, &conn->sndbuf_space); + /* guarantee 0 <= sndbuf_space <= sndbuf_desc->len */ + smp_mb__after_atomic(); + smc_curs_copy(&conn->tx_curs_fin, &conn->local_rx_ctrl.cons, conn); + + smc_tx_sndbuf_nonfull(smc); + } } diff_prod = smc_curs_diff(conn->rmb_desc->len, &prod_old, From patchwork Wed Feb 15 16:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Gu X-Patchwork-Id: 57619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp284211wrn; Wed, 15 Feb 2023 08:23:35 -0800 (PST) X-Google-Smtp-Source: AK7set+OvSed1Rv7CZR70XsAQYe8TAZPJIezg+KoYsK9qmFPmuCBesAdMtqRorv5R4KTVpBxiape X-Received: by 2002:a17:907:78c1:b0:8b1:32dd:3b0 with SMTP id kv1-20020a17090778c100b008b132dd03b0mr2646534ejc.57.1676478215693; Wed, 15 Feb 2023 08:23:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676478215; cv=none; d=google.com; s=arc-20160816; b=qJMeGU/ZqOtA5aSwC0E/S0DaJu7qXyFFO0FHuX/zxbb+moYIev8ZBwbpW2k1KJybl9 FATcuQ28pbwH4RvnN8BeUxMfOBUA/sawK936nr+mn0a3CmGZu3LiOJVYAYg8wIXbJnbT PWBZwbYuga3SoHz4GgGiuXQtIfPqoacLzcx8DrqjqFIn2JdgJrmp8Mz2Ss3eaPtSLftG AamqCIezz7lMIlbmplgLNBemPlSKdArMXVIzcxKKa9INUvah2ReMEGEkn4F6l5oQ9qvc tAUKDlYk9UtdWohJgqvZc9NK1sVwzrbcli2gNSIVGdwrqYAzupK94L1i04XneC4mqPjM sNDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=+4Lts5DLFMat3sIK5Edh81WN6bSYvKIEKaArgwHVd5s=; b=LipgF4/K+qYoQDeJrwBD4TVBijH8w3wd0rXc17D/fqUPCCSjaj18Pn1++2GI9moSkb O7uIqY9AvH8IoZIX6VfwC53JY39B4kLl8g3Ik4WJBJr4AduYJtSeghl7Pag4mjy7Xuws uYAK2YJerI7mAmfkbvsu1QVMLwsFpT2+Ovob6dfL9v8SHo8P1rjb157HUgge+CMbUm1z upjq9Iu+WvYTf/cFvcLpjnleBhXHYIdwMFbCrkmRSiOn5du0jRdD1VUcoxtQUHDC1L5c TqzTUUEdUjoVmuWNrmLOhDii3arhitz3V8Qm7TFJAsamQguwzWo/BT12UGEplFhyNtBG HuIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cq22-20020a170906d51600b0087bd501de66si20925757ejc.828.2023.02.15.08.23.08; Wed, 15 Feb 2023 08:23:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbjBOQTb (ORCPT + 99 others); Wed, 15 Feb 2023 11:19:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230100AbjBOQTL (ORCPT ); Wed, 15 Feb 2023 11:19:11 -0500 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772E13B0DF; Wed, 15 Feb 2023 08:18:55 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R991e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=10;SR=0;TI=SMTPD_---0Vbl2fgZ_1676477929; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0Vbl2fgZ_1676477929) by smtp.aliyun-inc.com; Thu, 16 Feb 2023 00:18:51 +0800 From: Wen Gu To: kgraul@linux.ibm.com, wenjia@linux.ibm.com, jaka@linux.ibm.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH net-next v3 9/9] net/smc: Add interface implementation of loopback device Date: Thu, 16 Feb 2023 00:18:25 +0800 Message-Id: <1676477905-88043-10-git-send-email-guwen@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> References: <1676477905-88043-1-git-send-email-guwen@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757914821675646478?= X-GMAIL-MSGID: =?utf-8?q?1757914821675646478?= This patch completes the specific implementation of loopback device for the newly added SMC-D DMB-related interface. The loopback device always provides mappable DMB because the device users are in the same OS instance. Signed-off-by: Wen Gu --- net/smc/smc_loopback.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++---- net/smc/smc_loopback.h | 4 +++ 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/net/smc/smc_loopback.c b/net/smc/smc_loopback.c index 38bacd8..2fa2a73 100644 --- a/net/smc/smc_loopback.c +++ b/net/smc/smc_loopback.c @@ -77,6 +77,7 @@ static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, goto err_node; } dmb_node->len = dmb->dmb_len; + refcount_set(&dmb_node->refcnt, 1); /* TODO: token is random but not exclusive ! * suppose to find token in dmb hask table, if has this token @@ -87,6 +88,7 @@ static int smc_lo_register_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb, write_lock(&ldev->dmb_ht_lock); hash_add(ldev->dmb_ht, &dmb_node->list, dmb_node->token); write_unlock(&ldev->dmb_ht_lock); + atomic_inc(&ldev->dmb_cnt); dmb->sba_idx = dmb_node->sba_idx; dmb->dmb_tok = dmb_node->token; @@ -124,12 +126,76 @@ static int smc_lo_unregister_dmb(struct smcd_dev *smcd, struct smcd_dmb *dmb) write_unlock(&ldev->dmb_ht_lock); clear_bit(dmb_node->sba_idx, ldev->sba_idx_mask); + + /* wait for dmb refcnt to be 0 */ + if (!refcount_dec_and_test(&dmb_node->refcnt)) + wait_event(ldev->dmbs_release, !refcount_read(&dmb_node->refcnt)); kfree(dmb_node->cpu_addr); kfree(dmb_node); + if (atomic_dec_and_test(&ldev->dmb_cnt)) + wake_up(&ldev->ldev_release); + return 0; +} + +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(&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(&ldev->dmb_ht_lock); + return -EINVAL; + } + read_unlock(&ldev->dmb_ht_lock); + refcount_inc(&dmb_node->refcnt); + + /* 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(&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(&ldev->dmb_ht_lock); + return -EINVAL; + } + read_unlock(&ldev->dmb_ht_lock); + + if (refcount_dec_and_test(&dmb_node->refcnt)) + wake_up_all(&ldev->dmbs_release); return 0; } +static int smc_lo_get_dev_dmb_attr(struct smcd_dev *smcd) +{ + return (1 << ISM_DMB_MAPPABLE); +} + static int smc_lo_add_vlan_id(struct smcd_dev *smcd, u64 vlan_id) { return -EOPNOTSUPP; @@ -156,7 +222,15 @@ static int smc_lo_move_data(struct smcd_dev *smcd, u64 dmb_tok, unsigned int idx { struct smc_lo_dmb_node *rmb_node = NULL, *tmp_node; struct smc_lo_dev *ldev = smcd->priv; - + struct smc_connection *conn; + + if (!sf) { + /* local sndbuf shares the same physical memory with + * peer RMB, so no need to copy data from local sndbuf + * to peer RMB. + */ + return 0; + } read_lock(&ldev->dmb_ht_lock); hash_for_each_possible(ldev->dmb_ht, tmp_node, list, dmb_tok) { if (tmp_node->token == dmb_tok) { @@ -172,13 +246,10 @@ static int smc_lo_move_data(struct smcd_dev *smcd, u64 dmb_tok, unsigned int idx memcpy((char *)rmb_node->cpu_addr + offset, data, size); - if (sf) { - struct smc_connection *conn = - smcd->conn[rmb_node->sba_idx]; + conn = smcd->conn[rmb_node->sba_idx]; + if (conn && !conn->killed) + smcd_cdc_rx_handler(conn); - if (conn && !conn->killed) - smcd_cdc_rx_handler(conn); - } return 0; } @@ -206,6 +277,8 @@ static struct device *smc_lo_get_dev(struct smcd_dev *smcd) .query_remote_gid = smc_lo_query_rgid, .register_dmb = smc_lo_register_dmb, .unregister_dmb = smc_lo_unregister_dmb, + .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, @@ -216,6 +289,7 @@ static struct device *smc_lo_get_dev(struct smcd_dev *smcd) .get_local_gid = smc_lo_get_local_gid, .get_chid = smc_lo_get_chid, .get_dev = smc_lo_get_dev, + .get_dev_dmb_attr = smc_lo_get_dev_dmb_attr, }; static struct smcd_dev *smcd_lo_alloc_dev(const struct smcd_ops *ops, @@ -296,6 +370,9 @@ static int smc_lo_dev_init(struct smc_lo_dev *ldev) smc_lo_gen_id(ldev); rwlock_init(&ldev->dmb_ht_lock); hash_init(ldev->dmb_ht); + atomic_set(&ldev->dmb_cnt, 0); + init_waitqueue_head(&ldev->dmbs_release); + init_waitqueue_head(&ldev->ldev_release); return smcd_lo_register_dev(ldev); } @@ -334,6 +411,8 @@ static int smc_lo_dev_probe(void) 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_remove(void) diff --git a/net/smc/smc_loopback.h b/net/smc/smc_loopback.h index 9d34aba..0a09330 100644 --- a/net/smc/smc_loopback.h +++ b/net/smc/smc_loopback.h @@ -33,6 +33,7 @@ struct smc_lo_dmb_node { u32 sba_idx; void *cpu_addr; dma_addr_t dma_addr; + refcount_t refcnt; }; struct smc_lo_dev { @@ -43,6 +44,9 @@ struct smc_lo_dev { DECLARE_BITMAP(sba_idx_mask, SMC_LODEV_MAX_DMBS); rwlock_t dmb_ht_lock; DECLARE_HASHTABLE(dmb_ht, SMC_LODEV_MAX_DMBS_BUCKETS); + atomic_t dmb_cnt; + wait_queue_head_t dmbs_release; + wait_queue_head_t ldev_release; }; int smc_loopback_init(void);