From patchwork Wed Nov 16 08:57:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 20818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp33996wru; Wed, 16 Nov 2022 01:02:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf6/QDoGvX/bEhB8b66sNw01Z5ID+YB9Qj1J+qRc7Z2qoEIqraxMHSCsLtqk5LkGHWIO5lP/ X-Received: by 2002:a63:4a64:0:b0:430:3d93:8c57 with SMTP id j36-20020a634a64000000b004303d938c57mr19759284pgl.397.1668589361551; Wed, 16 Nov 2022 01:02:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668589361; cv=none; d=google.com; s=arc-20160816; b=tok8aOsnv0NGO0hAN9rHEyOgzssCwzkmmN2rGnLIsJ8hJz5qzcnAHHT48Ji8Ed4WPb RSl63Bu74b4fJOqwAhQNkQrJEekTRziw6iYknU130eBdDE7InY18g38DjS0bAZZ/aQun aaKxeTfrhXO9RL6RxHNuDOZ1OforeKeqRV6zJy+mFG1IGDc5osUNDl/ilaKB8O3uv2C9 Hl8L8VStvu5Wns3iUI6FSCTbz5ogym8JXc6336nz8Dd1vW7twjcEPT/+yYOXbTArd0i5 MOCeJjBlzzfjF/V6oMJCjVVYJDuHSfMIiCqjgUazQlDF/787gtS6oObM9m6eeBAPUSeF hpWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eOXjmtqiQUdgbkS/e5/ak8XczSa1ohtTP+tzMg10gfY=; b=Kn7ehSpINb1WuLEyrDu3WzNWfbbHXjESCJc+igCBXAMu4zlO/SyfINx/VaBF09GPam j5wWaWCGNxTpwI0cqq+T1ma8TTvhqxol5grlhCaxsnSXbk7NT9sqQ9swhi3Il9UPwwBk JjiCuhDrn6uETkGwIIeLuRjjhsLEy19xIlp6pqs7m+MwE7DQWiaIBGQ1jL+t81zkQ564 6lbaaD0ltegvUDImL0n6kkzp10DBbt/xu47CFG8q/7UC7vcmpPh/w0x1/KvmgRl8swns lMUOLQYKU58DxpkOWk945YB5YEGCZt4wEYNYMzZM8jecLPQXR4zb5Y4tSclrf0xoXBz3 5wtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=U0SevKPJ; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ok5-20020a17090b1d4500b001ed40b70436si1404628pjb.155.2022.11.16.01.02.27; Wed, 16 Nov 2022 01:02:41 -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; dkim=pass header.i=@microchip.com header.s=mchp header.b=U0SevKPJ; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233471AbiKPJBE (ORCPT + 99 others); Wed, 16 Nov 2022 04:01:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238742AbiKPI7H (ORCPT ); Wed, 16 Nov 2022 03:59:07 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E19241DF3E; Wed, 16 Nov 2022 00:58:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1668589104; x=1700125104; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ECkmPcPVfC1Fd1lbFAa6NaTrAzf5Mg9N0wBNbfFFNO8=; b=U0SevKPJ06ygtHh+rSZL6Mzi0/XrhUwTkhcc6dKFj2718ERS+EPAIA8n /EWr1Dzdee1OJDuB+RVLAd2PX/3/juaFcZnWgpa/7eXCa1znXAl/VaYaJ ujsz6FCuZIpp8Ox6Cc5GkJJOysW0CkeMnTJCVTv+w43cxS39c0BhPksXC +YpncoawA1fP43leYzURA1H3CZ6vvKY9DUJseg74bpuylXQXpU62i81Ra g9SRvDvWtpGMqdgUGgQmzgGpc+G7B35j59TNPLGXrOhUcSE9zM6XpIi6i z2rvvC6fSp47GDHT5EoN1i5CThe2tbDrmzbFLamj1sZvgeiNU1X22S2nT w==; X-IronPort-AV: E=Sophos;i="5.96,167,1665471600"; d="scan'208";a="187219751" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 16 Nov 2022 01:58:21 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Wed, 16 Nov 2022 01:58:20 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Wed, 16 Nov 2022 01:58:17 -0700 From: Steen Hegelund To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Steen Hegelund , , Randy Dunlap , "Casper Andersson" , Russell King , Wan Jiabing , "Nathan Huckleberry" , , , , "Steen Hegelund" , Daniel Machon , Horatiu Vultur , Lars Povlsen Subject: [PATCH net-next 7/8] net: microchip: sparx5: Add VCAP locking to protect rules Date: Wed, 16 Nov 2022 09:57:46 +0100 Message-ID: <20221116085747.3810427-8-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116085747.3810427-1-steen.hegelund@microchip.com> References: <20221116085747.3810427-1-steen.hegelund@microchip.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS 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?1749642758191109244?= X-GMAIL-MSGID: =?utf-8?q?1749642758191109244?= This ensures that the VCAP cache and the lists maintained in the VCAP instance is protected when accessed by different clients. Signed-off-by: Steen Hegelund --- .../net/ethernet/microchip/sparx5/sparx5_vcap_impl.c | 2 ++ drivers/net/ethernet/microchip/vcap/vcap_api.c | 10 ++++++++++ drivers/net/ethernet/microchip/vcap/vcap_api.h | 1 + drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c | 2 ++ 4 files changed, 15 insertions(+) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c index e70ff1aa6d57..0c4d4e6d51e6 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_impl.c @@ -579,6 +579,7 @@ static void sparx5_vcap_admin_free(struct vcap_admin *admin) { if (!admin) return; + mutex_destroy(&admin->lock); kfree(admin->cache.keystream); kfree(admin->cache.maskstream); kfree(admin->cache.actionstream); @@ -598,6 +599,7 @@ sparx5_vcap_admin_alloc(struct sparx5 *sparx5, struct vcap_control *ctrl, INIT_LIST_HEAD(&admin->list); INIT_LIST_HEAD(&admin->rules); INIT_LIST_HEAD(&admin->enabled); + mutex_init(&admin->lock); admin->vtype = cfg->vtype; admin->vinst = cfg->vinst; admin->lookups = cfg->lookups; diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c index 3415605350c9..ac7a32ff755e 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c @@ -1054,6 +1054,7 @@ int vcap_add_rule(struct vcap_rule *rule) if (ret) return ret; /* Insert the new rule in the list of vcap rules */ + mutex_lock(&ri->admin->lock); ret = vcap_insert_rule(ri, &move); if (ret < 0) { pr_err("%s:%d: could not insert rule in vcap list: %d\n", @@ -1072,6 +1073,7 @@ int vcap_add_rule(struct vcap_rule *rule) if (ret) pr_err("%s:%d: rule write error: %d\n", __func__, __LINE__, ret); out: + mutex_unlock(&ri->admin->lock); return ret; } EXPORT_SYMBOL_GPL(vcap_add_rule); @@ -1221,9 +1223,11 @@ int vcap_del_rule(struct vcap_control *vctrl, struct net_device *ndev, u32 id) gap = vcap_fill_rule_gap(ri); /* Delete the rule from the list of rules and the cache */ + mutex_lock(&admin->lock); list_del(&ri->list); vctrl->ops->init(ndev, admin, admin->last_used_addr, ri->size + gap); kfree(ri); + mutex_unlock(&admin->lock); /* Update the last used address, set to default when no rules */ if (list_empty(&admin->rules)) { @@ -1246,6 +1250,8 @@ int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin) if (ret) return ret; + + mutex_lock(&admin->lock); list_for_each_entry_safe(ri, next_ri, &admin->rules, list) { vctrl->ops->init(ri->ndev, admin, ri->addr, ri->size); list_del(&ri->list); @@ -1258,6 +1264,7 @@ int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin) list_del(&eport->list); kfree(eport); } + mutex_unlock(&admin->lock); return 0; } @@ -1687,10 +1694,13 @@ int vcap_enable_lookups(struct vcap_control *vctrl, struct net_device *ndev, if (chain_id) { if (vcap_is_enabled(admin, ndev, cookie)) return -EADDRINUSE; + mutex_lock(&admin->lock); vcap_enable(admin, ndev, cookie); } else { + mutex_lock(&admin->lock); vcap_disable(admin, ndev, cookie); } + mutex_unlock(&admin->lock); return 0; } diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.h b/drivers/net/ethernet/microchip/vcap/vcap_api.h index e71e7d3d79c2..f4a5ba5ffa87 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api.h +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.h @@ -167,6 +167,7 @@ struct vcap_admin { struct list_head list; /* for insertion in vcap_control */ struct list_head rules; /* list of rules */ struct list_head enabled; /* list of enabled ports */ + struct mutex lock; /* control access to rules */ enum vcap_type vtype; /* type of vcap */ int vinst; /* instance number within the same type */ int first_cid; /* first chain id in this vcap */ diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c index 8e5b1cc24d80..534c51f2ec4f 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c @@ -618,6 +618,7 @@ static int vcap_show_admin(struct vcap_control *vctrl, int ret = 0; vcap_show_admin_info(vctrl, admin, out); + mutex_lock(&admin->lock); list_for_each_entry(elem, &admin->rules, list) { ri = vcap_dup_rule(elem); if (IS_ERR(ri)) @@ -631,6 +632,7 @@ static int vcap_show_admin(struct vcap_control *vctrl, free_rule: vcap_free_rule((struct vcap_rule *)ri); } + mutex_unlock(&admin->lock); return ret; }