From patchwork Thu Nov 17 21:31:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steen Hegelund X-Patchwork-Id: 21941 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp636899wrr; Thu, 17 Nov 2022 13:44:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf4hTRd8mpWzYYL1Dg5FfleE9dhCov9aHXEGTjAWrffkwQtvCKjBe2rAnIkSewWz4HpxKvdZ X-Received: by 2002:a17:907:1a53:b0:7b2:b15e:86e6 with SMTP id mf19-20020a1709071a5300b007b2b15e86e6mr317055ejc.410.1668721476827; Thu, 17 Nov 2022 13:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668721476; cv=none; d=google.com; s=arc-20160816; b=J/eO0Qs9IjfPbtHFTAx7G3pckytTc43QEqZm+qYtgkU1YzAq95iLwvbdOmWv/gVHV9 UIc3APGsdm19Rlq+DkenAFLy0GSv/o2T2L/kNp2JBqzV/ABGDlcFSrqH0PnZD1wqDwPL SxofLbgB1vG5j7Kb2mW+x5tCtZJMXDRnySdsyg8naYPVgL4LFMasgQWD9jA5FcB9877b DgxbAy/GPDuZTswC2FCgDjE1QhjiMVnlxNSGkJ1tTt9zIyA0WGt70ZAVuyegx6Zns6do Y17AMEFPx2XjM0dKIGbiXTkmkEDC967owJwTA/A+oWaUXDb/OAeqCUtOaHpTkmtcBnHy JuGw== 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=Gu/3GAkSES8qps+i5Vx95GYo/oJC46QuKMEDTHoxYmk=; b=grzy7wGlEBDNWOdtTOgUUuN/amx+NcZm+tSi5+dKjzjEhV/FL0+3Ws+mFimgNVgFVG sYKVqlG6Zzt2uK9Sd/QZeUNejJMJcwrQpXzrBr6eL5QhGP4E7baiBUJCxbgfQ2LxHIDO MZ742sqVm9PGSvC8NYlXlzi2ZKP8W6DHBPutUO5/l5FjicGr/EjFBFi2nuedsH7vbNqg JHvrhbNHKHpF6aKeqJYG6NlCdYoHswXZQAKDkE6z52IoStqmRmgsFofgadAwl0kXj4ZY paIdQb838PW8YXhNEU6EEHHiqAJLn7/RQifvS6QDye75FVovtuO6vHuZGa/6CPrrTLNf yZkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b="2dV/WTyP"; 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 js3-20020a17090797c300b007aa6262f627si1613506ejc.640.2022.11.17.13.44.12; Thu, 17 Nov 2022 13:44:36 -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="2dV/WTyP"; 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 S241023AbiKQVdD (ORCPT + 99 others); Thu, 17 Nov 2022 16:33:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240997AbiKQVcD (ORCPT ); Thu, 17 Nov 2022 16:32:03 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A179061520; Thu, 17 Nov 2022 13:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1668720712; x=1700256712; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=daU/1NauHUHLkSJsDhAoxGxvrqsIoO4bsGuUOZCnFtc=; b=2dV/WTyPancHgyOKWe3tIBr0KL5xilHYmktGCliSAkTOlGvGuPTpmB+g /DXNzGb/flbEL8gvLi6ZumenZave65oB7alsF3AOruAu9aKf6hYE+66Kn 2jy4TPlM0I2fkKQXk7SBR/C/oAXGKF74TJnLDSEl4h53kmHVvw3HgI6ah WL1X5fdHANcc7SHPpURmFttab4q3U3jnNpRQazZejn5neArl2zgfRckTO rf/bKGnjYg32+oSwQ1tjTYCLULnXVbMiAkxrCrR/BpHAaDeUUOb4GS01H /x344sLHBr1xFLLANzGEQIHvNdUmnbE2a15rGW16/0usZcte3fYDdGSZ9 w==; X-IronPort-AV: E=Sophos;i="5.96,172,1665471600"; d="scan'208";a="123980093" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 17 Nov 2022 14:31:51 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.12; Thu, 17 Nov 2022 14:31:47 -0700 Received: from den-dk-m31857.microchip.com (10.10.115.15) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.12 via Frontend Transport; Thu, 17 Nov 2022 14:31:44 -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 v2 7/8] net: microchip: sparx5: Add VCAP locking to protect rules Date: Thu, 17 Nov 2022 22:31:13 +0100 Message-ID: <20221117213114.699375-8-steen.hegelund@microchip.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221117213114.699375-1-steen.hegelund@microchip.com> References: <20221117213114.699375-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?1749781291279068382?= X-GMAIL-MSGID: =?utf-8?q?1749781291279068382?= 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 981c4ed6ad7d..891034e349de 100644 --- a/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c +++ b/drivers/net/ethernet/microchip/vcap/vcap_api_debugfs.c @@ -625,6 +625,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)) @@ -638,6 +639,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; }