Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1592436rdd; Thu, 11 Jan 2024 04:03:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZJtZlfCu+x6ni2Wcq6KrlgfMewW61BB+uScZnh0xgXNh2j9lYJTVmQ+zkHz6Ydrd7KKZT X-Received: by 2002:aa7:dd03:0:b0:557:79b8:d474 with SMTP id i3-20020aa7dd03000000b0055779b8d474mr595163edv.57.1704974611508; Thu, 11 Jan 2024 04:03:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704974611; cv=none; d=google.com; s=arc-20160816; b=E6DtR304G4xY8w6rLgsiyuGQI35FceqJ62JubxuAAzZtuG3q4KEd13fgpQm3nb9Jdu pDvJjhqWLRfcwm9EUFu0cV0D4zWwjOSs1xz1KQe+RkXPpmrbUsg+XyVi+mQONmF4mc6o 7n+S4LRWlHmXIG1BB4t8N0Iw+Lg9/HlqsOJ1JSW3KsDsU730ew9bnPeZvwqAe24IBTR4 pJEnEA70aEwFz6i+mtfqk7+eQSVHF8tyDFcbnM05SXArecEmCa4AVU/wxUb6P8bmjV+g mBvXEXhijXCyh/sNiYZdE5lW5t85CrGwUYYmp5E//qCG+/uGCFob+zBT4x74LYeGmCcL Ol9g== ARC-Message-Signature: i=1; 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; bh=w+z/LjZ4Ct+IkPkQtf1aRUIoKzspUTC/6K1THTsz410=; fh=jvQSXgb9+Gwj+2SIugFJuht8/m1b8ZaGKJU/ZBOVFgM=; b=0LfpTTqsrWTPIrFIX0bQ6WBTIIHU8Om07aWF6KPRnWQinxSqtjJUyB1rEOX4UCdy17 32DoGbPKCCSl8B++ksXgpr5pCrUjcu+VspYRWJxeOhiHT7YoKpgE//7yEzC+b1UQ5pRv NtwuiP6IzoP06H5eswbGU8GHQCu1BaLIInqGgp/wVHZp8XNfZe7ctRVwVVYLrAkOhuaZ gglu2Zq56k9MuEL9qr51ZJry94kpXvFkDrrbnslcg0DW/h89k91ED/qBNgz2cKM3Guwu 0Kjd81FPtcRbDY01j0Hql0gyeZvbV+gUqkgo7zGA52q6lq7EZoz8/+kfFYhBe0Qj6Z4N ui4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c9-20020a0564021f8900b005588037a93bsi464439edc.29.2024.01.11.04.03.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 04:03:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=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 450901F261F8 for ; Thu, 11 Jan 2024 12:03:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD3D4171A8; Thu, 11 Jan 2024 12:01:29 +0000 (UTC) Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (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 29A93168A6; Thu, 11 Jan 2024 12:01:25 +0000 (UTC) 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 X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=guwen@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0W-PdqI7_1704974481; Received: from localhost(mailfrom:guwen@linux.alibaba.com fp:SMTPD_---0W-PdqI7_1704974481) by smtp.aliyun-inc.com; Thu, 11 Jan 2024 20:01:23 +0800 From: Wen Gu To: wintera@linux.ibm.com, wenjia@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, 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-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 08/15] net/smc: introduce loopback-ism runtime switch Date: Thu, 11 Jan 2024 20:00:29 +0800 Message-Id: <20240111120036.109903-9-guwen@linux.alibaba.com> X-Mailer: git-send-email 2.32.0.3.g01195cf9f In-Reply-To: <20240111120036.109903-1-guwen@linux.alibaba.com> References: <20240111120036.109903-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 provides a runtime switch to activate or deactivate loopback-ism device by echo {1|0} > /sys/devices/virtual/smc/loopback-ism/active. It will trigger the registration or removal of loopback-ism from the SMC-D device list. Signed-off-by: Wen Gu --- net/smc/smc_loopback.c | 55 ++++++++++++++++++++++++++++++++++++++++++ net/smc/smc_loopback.h | 1 + 2 files changed, 56 insertions(+) diff --git a/net/smc/smc_loopback.c b/net/smc/smc_loopback.c index db0b45f8560c..3bf7bf5e8c96 100644 --- a/net/smc/smc_loopback.c +++ b/net/smc/smc_loopback.c @@ -27,6 +27,58 @@ static const char smc_lo_dev_name[] = "loopback-ism"; static struct smc_lo_dev *lo_dev; static struct class *smc_class; +static int smcd_lo_register_dev(struct smc_lo_dev *ldev); +static void smcd_lo_unregister_dev(struct smc_lo_dev *ldev); + +static ssize_t active_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct smc_lo_dev *ldev = + container_of(dev, struct smc_lo_dev, dev); + + return sysfs_emit(buf, "%d\n", ldev->active); +} + +static ssize_t active_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct smc_lo_dev *ldev = + container_of(dev, struct smc_lo_dev, dev); + bool active; + int ret; + + ret = kstrtobool(buf, &active); + if (ret) + return ret; + + if (active && !ldev->active) { + /* activate loopback-ism */ + ret = smcd_lo_register_dev(ldev); + if (ret) + return ret; + } else if (!active && ldev->active) { + /* deactivate loopback-ism */ + smcd_lo_unregister_dev(ldev); + } + + return count; +} +static DEVICE_ATTR_RW(active); +static struct attribute *smc_lo_attrs[] = { + &dev_attr_active.attr, + NULL, +}; + +static struct attribute_group smc_lo_attr_group = { + .attrs = smc_lo_attrs, +}; + +static const struct attribute_group *smc_lo_attr_groups[] = { + &smc_lo_attr_group, + NULL, +}; + static void smc_lo_generate_id(struct smc_lo_dev *ldev) { struct smcd_gid *lgid = &ldev->local_gid; @@ -282,6 +334,7 @@ static int smcd_lo_register_dev(struct smc_lo_dev *ldev) mutex_lock(&smcd_dev_list.mutex); list_add(&smcd->list, &smcd_dev_list.list); mutex_unlock(&smcd_dev_list.mutex); + ldev->active = 1; pr_warn_ratelimited("smc: adding smcd device %s\n", smc_lo_dev_name); return 0; @@ -293,6 +346,7 @@ static void smcd_lo_unregister_dev(struct smc_lo_dev *ldev) pr_warn_ratelimited("smc: removing smcd device %s\n", smc_lo_dev_name); + ldev->active = 0; smcd->going_away = 1; smc_smcd_terminate_all(smcd); mutex_lock(&smcd_dev_list.mutex); @@ -340,6 +394,7 @@ static int smc_lo_dev_probe(void) ldev->dev.parent = NULL; ldev->dev.class = smc_class; + ldev->dev.groups = smc_lo_attr_groups; ldev->dev.release = smc_lo_dev_release; device_initialize(&ldev->dev); dev_set_name(&ldev->dev, smc_lo_dev_name); diff --git a/net/smc/smc_loopback.h b/net/smc/smc_loopback.h index 24ab9d747613..02a522e322b4 100644 --- a/net/smc/smc_loopback.h +++ b/net/smc/smc_loopback.h @@ -35,6 +35,7 @@ struct smc_lo_dmb_node { struct smc_lo_dev { struct smcd_dev *smcd; struct device dev; + u8 active; u16 chid; struct smcd_gid local_gid; rwlock_t dmb_ht_lock; -- 2.32.0.3.g01195cf9f