From patchwork Tue May 3 11:57:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12835671 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4236C433FE for ; Tue, 3 May 2022 11:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234976AbiECMB1 (ORCPT ); Tue, 3 May 2022 08:01:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234966AbiECMB0 (ORCPT ); Tue, 3 May 2022 08:01:26 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2058.outbound.protection.outlook.com [40.107.20.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F204C2D1DB for ; Tue, 3 May 2022 04:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EqkmYwd+3bOUPYtwvKgvTSZZvWs/MXsK2/KV7ZvhX1KBq53kfXtcOj1ROCcSTdREpQdjhltVVM9cwKNNy9ZwYIyGVUnA0qNb5nYzCVN0Uk9y1LBhi4JempA1PYQ+sxlwEzNIlPLLqxAn0YJTqMLoqVGPG8uVb0pFV1Wgec3z75rAxEkfLc/R2pS+gpvfy0w2oS1TW2ry+DjR+1W/Ii1SVQBfqjs4YMtk/Ag3uf4tiqiCPji5p5nDSB5UE/NY5pfutPuokt9SHu3yAhlrTqzHLTboXrBIWp6UZ+7AWdSxdcUe+jlFKaoYH3+Nkoga8TYOdBZr16RYJsQGBaEUaWTEeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qSivyKgznuAPLMFF+PoseqMqbwW8eejLxAG6O7GhnkM=; b=fkm9vHwSQ3lD9HH5EaRtwCDM3cI2lOw7BF+7TIYoYBBb8kIxZrdfwVqIwF8MBYmwOdqz1CbmObAzZDAdBydj/0N5GGDXCsXwn1dyXXq84KobhrL4rOrr2hwB1keKiRRmLdmWhvwObvc0Oy4aH6BoCOCD3zzJGbCVFnbRv8Sfae2cYzu72VUiTaI9VnJ166iQmqUjA98ito4dPt0hPBLPu62O3+2ymvEawtz8zhOXwiMTcGcNMiF9FbhDFSpknnvPik489SopB37WPI4GxWroJ4x9w03s9gqXghtsjxOjmDXIzpHLsVMCoeR4O2vO2sREh3pTpbkSHVvsrBxwckTpig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qSivyKgznuAPLMFF+PoseqMqbwW8eejLxAG6O7GhnkM=; b=q7TFj4PR0bDm/yk2NyycqYu87x/ElvN/q9AjKAdJ5N8IRwwZ7vokGUqoIwd5xtXMI2KgGHdrf85tQCWv/KUNfrZOpDNuTm0FGigbcGg9HAbgR3PIBei5a9qUM6nGogQ/Va7BOXMYsYYAzsLf/Sgw6X/1SPkJlIaRZ+X50ZWqRJk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) by VI1PR04MB4813.eurprd04.prod.outlook.com (2603:10a6:803:51::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 11:57:50 +0000 Received: from AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb]) by AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb%4]) with mapi id 15.20.5206.024; Tue, 3 May 2022 11:57:50 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Paolo Abeni , Eric Dumazet , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Xiaoliang Yang , Colin Foster Subject: [PATCH net 1/6] net: mscc: ocelot: don't use list_empty() on non-initialized list element Date: Tue, 3 May 2022 14:57:23 +0300 Message-Id: <20220503115728.834457-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503115728.834457-1-vladimir.oltean@nxp.com> References: <20220503115728.834457-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1P190CA0009.EURP190.PROD.OUTLOOK.COM (2603:10a6:802:2b::22) To AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6ed3d2f3-30ce-4f62-165e-08da2cfc25a6 X-MS-TrafficTypeDiagnostic: VI1PR04MB4813:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KXbYIx00qeBjT25phtlsxdQA48PGmbylHhGKPnHTakLMtjf5ccCcFe0V/OICeMl17ILl4RMmzcxn8NI7q9kvzIBqjPF4JGOBsKtIHPqoXoHsfhRCh2jl+f/+4oV71aIXEkmeHJLNRFodnG6a5tYJjpfvwExBVA5ZyeLCd7yh7P3r956TF3IxU/baIwrbYKRoYylZemSLeoO0q17tR7j6RcxNprb962krli8wfI0kSwcgNIn+aB9tVj/iX/n3dypNySTl7uWralNTthAejMKTl2GMPyZfFyvzvAAwxboZSe0/va/xwzpYUamRU+skU9x2UMOv5dFe0NtqzW6v3DBYcdAFJnmXaFwIj7u23K5I2y9NjxJWwaC1WgtrpZxVfshIGGsG1xIT3Z5yUmglt5Zgvu0Ophx2aRcQrrr909S2iFB04BMgFgtiNHMuX25OcUjJ6yADrj/FgyJX/2rA5JpiIFVyxdB6z6BSvm3M4Ae+Gc5KxaT+AoeOdOSs7QuXBbFgfREZLjzSIfOZzRCg/zXAWi6ighKDT6lJWhQ4N4sGTMzWYnSS1LkoOs7eQlFfbnhtdnvyUFVDCPZ1Tfk1NMqsz0/0igV0wqW+n50EpKLCxvfvThRJYx4a7VYXiRn3RmhNbtwKZvkD7uRTOTWyoFRZesR7NiwSyb/5k5OrAugalVU1IJk8eP9hiW06RW3udj8B9rtg3P3zyJIVQ6VDjH7VFw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5121.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(66946007)(44832011)(8936002)(2906002)(8676002)(66476007)(4326008)(1076003)(2616005)(186003)(508600001)(5660300002)(66556008)(7416002)(6506007)(6512007)(6666004)(36756003)(86362001)(52116002)(83380400001)(26005)(38350700002)(38100700002)(6916009)(54906003)(6486002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z8XDmSdlFVcFZ5p/Zh2cRmjRgKYQwsBYtz6pREXWh0jgdh1qhx8pXzWpQbgdFQFnxwA/vYeO5CSf2iZ6CCmwBVN+XmU/RIhdGX2qAyrNYi0QmHWNpScKtz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llU6SA1y6LWLrC1vgqmNvqTkN8BvpOS/Z6PHNDzUMWiSbu2LXRtk8O4NCcLDGSmUB9DgX4guKRvAYeLrPsFVxGSVwDsHhJl0mkqlUKwfSYYOSEbwu6mcp5b7AP2WRcV5BKHsSzpygtH1wy13d0f+E2yoiu1VBlfPQvbwN0+piwJxykD2ZLoj7cKkZ4GupsLA4yzEaQWonGwCK+DuTkEGlwMvdkdNd6RrkN1Fmv/ezvw3+dyA7bK3fNxrCVv+3YBmP9BqnYmmfuSL/oSmV5UrhBKTBjPVUxZGSnT/dlJkgLf9R2PyS0JluQo9RXgrJGXmDhYFqrIT8HHP42RGnml3+b8eSUebiPCXW0TtwAniW0CU5n5CPvn3ihANaVHUwLoFNxyTlcAiR4YjiNoHtFUPZVx4xC5NdZocxljuDB/5lduly6FuJvKTUSJfwj+S4RTTgSnPr0exEXeEHWmPCjqhjN6UptUpV6VGaoFje/vIu29ByW/X3x+Ddr1+EUUEbwZ9W3zRzhvl0QYFks0x7LqIArpJI2BHF+zj4XW2M6QNd01zMgytxG70ZsM7OcU= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6ed3d2f3-30ce-4f62-165e-08da2cfc25a6 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5121.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 11:57:50.4806 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EAjBxL104L71n502KdLFiRB63KPq3YA+rrJfrOX2lL+cHyTaXYi0xYVRFpJOqTWwyYxDJi1+BvDxpKJzG+RnBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4813 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Since the blamed commit, VCAP filters can appear on more than one list. If their action is "trap", they are chained on ocelot->traps via filter->trap_list. Consequently, when we free a VCAP filter, we must remove it from all lists it is a member of, including ocelot->traps. Normally, conditionally removing an element from a list (depending on whether it is present or not) involves traversing the list, but we already have a reference to the element, so that isn't really necessary. Moreover, the operation "list_del(&filter->trap_list)" operation is fundamentally the same regardless of whether we've iterated through the list or just happened to have the element. So I thought it would be ok to check whether the element has been added to a list by calling list_empty(). However, this does not do the correct thing. list_empty() checks whether "head->next == head", but in our case, head->next == head->prev == NULL, and head != NULL. This makes us proceed to call list_del(), which modifies the prev pointer of the next element, and the next pointer of the prev element. But the next and prev elements are NULL, so we dereference those pointers and die. It would appear that list_empty() is not the function to use to detect that condition. But if we had previously called INIT_LIST_HEAD() on &filter->trap_list, then we could use list_empty() to denote whether we are members of a list (any list). Although the more "natural" thing seems to be to iterate through ocelot->traps and only remove the filter from the list if it was a member of it, it seems pointless to do that. So fix the bug by calling INIT_LIST_HEAD() on the non-head element. Fixes: e42bd4ed09aa ("net: mscc: ocelot: keep traps in a list") Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_flower.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot_flower.c b/drivers/net/ethernet/mscc/ocelot_flower.c index 03b5e59d033e..b8617e940063 100644 --- a/drivers/net/ethernet/mscc/ocelot_flower.c +++ b/drivers/net/ethernet/mscc/ocelot_flower.c @@ -793,6 +793,11 @@ static struct ocelot_vcap_filter filter->egress_port.mask = GENMASK(key_length - 1, 0); } + /* Allow the filter to be removed from ocelot->traps + * without traversing the list + */ + INIT_LIST_HEAD(&filter->trap_list); + return filter; } From patchwork Tue May 3 11:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12835672 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B163C433EF for ; Tue, 3 May 2022 11:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234978AbiECMB2 (ORCPT ); Tue, 3 May 2022 08:01:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234969AbiECMB1 (ORCPT ); Tue, 3 May 2022 08:01:27 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2058.outbound.protection.outlook.com [40.107.20.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1055D26AF2 for ; Tue, 3 May 2022 04:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q4XVOyOUaXw9uELDPW8X3HDUpHgGRkiKERijLwxB+8ivHTKAASFRoXvMoVlFpsxoGq2246NRMEusrxB4COhJFl5IVGJuwdJeihySP6RlPRTCm9UOy3JjLtzEwSoE0tRwI5+dtGPJiBIYc1C4h3Po8g62PgibAuZDK1X3sZCbsv2KFgfH+45y/UtaCG0BinMeo/cr4wULMSg8HT6oB5T5YEJzFGeyjJjXBZ5RB5187pN5oPYrOnmBPmsnjoxT9zuFJHnGnDtI86p8LOOJ6lIfdcDJFP6LoiFnwG+BtQpyumr86mf8hDCd2QmUSA2e3p2j1DPyaAQdN3GE3Y7unHLE9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4MkwsFHZHF1/GIeId2DDdi1FH3uR2zS7u58Igkl4YQ0=; b=j+YSiFunH2OMI5VwqeBUX+/Pjl1idLRfWodvkUGsB1itNmsdr746o6bsGV5Q912z74zBCzIMMyUJW4wTpJanhPO0BCfIVQVsnCnbOJCAaz+k1Vx4/WkotHF6ZNm08mXrWx63PnGYVjGKWPI2hpRCw3EUoAJFRUF1F2r/3/G66VWt8mLkHbvqAWQsPbX+m6oGcF38oQWH+1Yf3vbaTJ5RqKv9KQgDzu8ofu981q/BidzFtTN2ymmLzoI9nL7758Pr1gfW0h3bdYQHpGfP0KxwGIqNnaWNIeJNRSZ7JKNcLOjf+X0+W8AVfdmxtZ/ZadiH+Xhuyr14N9EPsLP+4mJIug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4MkwsFHZHF1/GIeId2DDdi1FH3uR2zS7u58Igkl4YQ0=; b=ELKmWXQQaiANEpatOPOll22oPyNFCP1cICBMDMPQjb6HGD5M9tE270Hp/mcBrQaqX/xYtz4+7+F8fB3KUwlR2tzIrezuCJUI2fIWsYJdG9zhRt/eggPkjvmE11/IFGKWJNLhNT8XL5nSo4eK/PgaifZMhckpVrWENzUau6+BxmE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) by VI1PR04MB4813.eurprd04.prod.outlook.com (2603:10a6:803:51::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 11:57:51 +0000 Received: from AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb]) by AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb%4]) with mapi id 15.20.5206.024; Tue, 3 May 2022 11:57:52 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Paolo Abeni , Eric Dumazet , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Xiaoliang Yang , Colin Foster Subject: [PATCH net 2/6] net: mscc: ocelot: avoid use after free with deleted tc-trap rules Date: Tue, 3 May 2022 14:57:24 +0300 Message-Id: <20220503115728.834457-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503115728.834457-1-vladimir.oltean@nxp.com> References: <20220503115728.834457-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1P190CA0009.EURP190.PROD.OUTLOOK.COM (2603:10a6:802:2b::22) To AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c948c795-a59b-44a1-a3bd-08da2cfc269b X-MS-TrafficTypeDiagnostic: VI1PR04MB4813:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WTcIgmiSOa8qXViK0lkCDSv/6oeRxMu5NdTlhFPb38R3d92ZlxoMsTNbDpZydI8lgc/k9nxaXJ9WESTkX1LrwpxbG3vxVcTK3XtV8xef359A61S6S+aCuwM5xu2mTQhakyttMpdlUdqIW4gsKesjXtExlBmoTIfoMs3SdVt9x6A3gXeGMnr0irFh0M2XPsC5AgFnrXAZv/6IuQQQLWufUKbMUE6NgVggkp5thvZ4EwMSUjYFp9fjT9i1CgzsAOnwsaUk5x7K8xWLp6QZMWLBvRckDnpe51VuMlWyExD0BWDod8jA5j/9YTKLTAInUwOX1Gt0WPnPn8eW6LTyrKlANZCuB1Jg5KgMQ2S0NdT2gTkKmCHIMhAccJoo8061AdnJYvvTmmFAgD1ZPuh9OCUdR9jowfAVDCcsn12WklBGP2iY5s1kDwmSvSKLgONl2YUu1Ub0O0PO7qtue9rQpU2Wf68MqNl2OpCp1PdyVdDrJzPbFvF5qWoAp57xDjz5ZaFrfUIGfWt7mH1Ymf1MDnj/S7WRGEJ0rtgD+hyXEILFq7+Q/gwIW1M+A8tD73lugDyLlUFYEbxu2Jue63O+i25HXPHiqMHD9mdCW13nC8RRhNupex5pN6+TNpW2vmKmBi0aRKNReEEtFc4SD6AR3qt4YwsWlR7GM3FF++DBLQHuzeRrW/X3a1jCwUhimBVs553D3fKM9HneBsNu4T9Tp/AJ9Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5121.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(66946007)(44832011)(8936002)(2906002)(8676002)(66476007)(4326008)(1076003)(2616005)(186003)(508600001)(5660300002)(66556008)(7416002)(6506007)(6512007)(6666004)(36756003)(86362001)(52116002)(83380400001)(26005)(38350700002)(38100700002)(6916009)(54906003)(6486002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WrovBL/KRnhBz1r4wlNY2iqo1eA6zUyXYxWwEN8Fawr8kA6LsnaZz6qCDcXo5+PBbaufgDvmV+VkjEzwN1J5sRHPfuN/0ctfh7i2EUYca5qciYkZirJ/QSEw4rjKHRu3XiPsi7wMWAaq0rBlpEx3zMDmg+n6Fifxxzw+DhK7/99KYHaCdO4GvQjNQdYi5UQi+7WlkfbOUQjC1dZVwoCzdjQBHUEoaDD2NEhsbz8CnP6VUdKNi6pKwfZ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gEPYD6JnS2bo2rcpSYBplWV2aNQ9nfAFn52C12aXHmKQymLA7Cjtzl2lfhQnQvgKWSMq2rF3bov9F9WHUpOzT6+CnNpJY9M2Claqe1mIgR64vlL6keWOpWAx041TfJUEw6QUEGGs/c6FjTaPQJWXBRJVJFQfNqvv1NnxgzGdep7mAs++0I4JjDqMM00UfD77hwM5VbZed/XmIne80rvWX6EjfLBtR82lk/rbsGcANhEByKshH/cWWJc5RbfYQ37TaOKvIFG1KcNCdxpQ2K1Dm3y4TdsyHbR7Z81Njtylk5ueQAFlaadoG27UMVH3bq+AwF+NUN6FLR9+/N62H7Mj7NS5RWUqCSaL9atxtL9O08YdS6Pi+xhsur93w1npXvxfGoB+55C6/eG7IepEkV9DFADx5haEu5CIK6nhV/nvEZcWHPvnpcrXdKeVdASxRAaV26xszDHgGeirA= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c948c795-a59b-44a1-a3bd-08da2cfc269b X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5121.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 11:57:51.9492 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +Ti0G25AiDE0y3eN86KnUAp3Sy2t3t5bgtGRvdxCRUpuWm7633LOTPGcsODydcHtCu5h546gz5voUfS3yCy/1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4813 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The error path of ocelot_flower_parse() removes a VCAP filter from ocelot->traps, but the main deletion path - ocelot_vcap_filter_del() - does not. So functions such as felix_update_trapping_destinations() can still access the freed VCAP filter via ocelot->traps. Fix this bug by removing the filter from ocelot->traps when it gets deleted. Fixes: e42bd4ed09aa ("net: mscc: ocelot: keep traps in a list") Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_vcap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c index 1e74bdb215ec..571d43e59f63 100644 --- a/drivers/net/ethernet/mscc/ocelot_vcap.c +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c @@ -1232,6 +1232,8 @@ static void ocelot_vcap_block_remove_filter(struct ocelot *ocelot, if (ocelot_vcap_filter_equal(filter, tmp)) { ocelot_vcap_filter_del_aux_resources(ocelot, tmp); list_del(&tmp->list); + if (!list_empty(&tmp->trap_list)) + list_del(&tmp->trap_list); kfree(tmp); } } From patchwork Tue May 3 11:57:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12835673 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E609DC433EF for ; Tue, 3 May 2022 11:58:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234982AbiECMBa (ORCPT ); Tue, 3 May 2022 08:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234977AbiECMB2 (ORCPT ); Tue, 3 May 2022 08:01:28 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2058.outbound.protection.outlook.com [40.107.20.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 128FA2D1CA for ; Tue, 3 May 2022 04:57:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dZue/8XZ06kyUd3W/0AeFrWuyY1VBN+3JBnh6Sj7VopTgS6NlIU/jTZtCmjSFtdITbqdbIGwk5rrvLBYl/O7ZotHxtgH9HxHzWPk3KSV///EydsieY9XXzXUSREbZwnm5Pjy3JbnkPfASx0nAQ6iIMCuVUEU5O8/p08hZ1jfY3hrHiXx8Hf/XazlpiuZq49cbwBL4ZiLr3SOuXtfHfai37SaZNLaO/lw9c/Jd32ovQsW4mlQvqJb5Kvu7ZmaopfAHXDtW7H06D4B+Z1gGR63HfmgB8Gv708+C34x2RdTTbI2ppr5xns3qi+isQElnUERNmyB1iI+pTBuHQZo/f/e+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+VyBPSwdCdMRPZ7sjBypnq7JURITLymu1/FHrdpkvek=; b=Lu+wPGrrw/8vD0xOLPLis43jfklb4JvcsfcvmrlE0g2l5wdb4ffsEBPyU2p55bwpm+8Q3emVfIEFrgYM0iqNM8Wr8nm29PyDOqOz30LVVi+jwQxt5A8my15n32GqgiJwt4iuKQsDwW+/IeAq05A1ReNiquzrJwuT88wsFaD1PO4XKX8J8FG9Fc8aCTUK1T7Y+ypjUWpXVhpW/V0fcPSRdjiGzLQozHBpzU9yKvVj9/vAZTFcIo/WyyHBz42kg6Tei8OwvO7pZxtMQpTSljWudYv1GsGtN11w4T1MaA3DYuHB5js25G5TVudpHaK+gAQPa65Q/9eCdEcMnh/3eiKhnQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+VyBPSwdCdMRPZ7sjBypnq7JURITLymu1/FHrdpkvek=; b=k1v22ynTZkHNQNmVxoY2RnGR30/Jbve1eQ4azjtTfthTmMJ2AWs26o7izRyJThLizMlhZOGVRc9HZlgXR4KBDwqXt/PgFM4CIjzcvt8St6OsT+nphoMZl2sCAQAmH0oj+w83AYAl83b8P8p2TACZ/O5R0AqvRT8xchrtPJJDqQA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) by VI1PR04MB4813.eurprd04.prod.outlook.com (2603:10a6:803:51::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 11:57:53 +0000 Received: from AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb]) by AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb%4]) with mapi id 15.20.5206.024; Tue, 3 May 2022 11:57:53 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Paolo Abeni , Eric Dumazet , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Xiaoliang Yang , Colin Foster Subject: [PATCH net 3/6] net: mscc: ocelot: fix last VCAP IS1/IS2 filter persisting in hardware when deleted Date: Tue, 3 May 2022 14:57:25 +0300 Message-Id: <20220503115728.834457-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503115728.834457-1-vladimir.oltean@nxp.com> References: <20220503115728.834457-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1P190CA0009.EURP190.PROD.OUTLOOK.COM (2603:10a6:802:2b::22) To AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d9fa61b8-053e-4973-f7b8-08da2cfc2776 X-MS-TrafficTypeDiagnostic: VI1PR04MB4813:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SGjvDdSvL+f9df2Mz6RaCJ3Sdb5PRFvFOjAZWbnpAPds55pvIgdgIU7MEwRU/Gmndsp0qdyU79XkzR2/hK6+ILuojMA+w5Q/m7VuRWdyNid2kdg2UyBSvJHCZFjfDRgBKaHkWSxZnA/KeNEGUTVYq3OBu5rIq0v/tkfZsWkHrWHrXpgq3ICkIHAphfzvSOXj00q6osNlm/T3ABFR3l08WTbllirAgSBQEVicVQSrVGClhUweqsOhwUCgMlnKwYKM3/ihhzYZfE4WKW51tlx+fq3mAFOJjV1tL6iqDyMNVsv9QfLbm+mEul7b3snb5H7KeKw2PsuXqoxcwCOvnChyZwx2pzl9ujS9A4Vc6Xr5B+JtxZjMHyHGgT4W8gfoI9TxC7+fVWiYWDfNYn7b+WsCBmDKuIaWN073ytPjm22cqIVLgIcnHgL5JR+YZLtFdhXVUzwD6HHqoq9dWCYRUMu+Lk/wxD0XqOg7HrgHzqaUYfYSkXPHjgt9svgeq/3EATK0Ndz2+xGyeoxh1uRtiivetOrKrNeKBahdpErUyLextUawhs2OaHCs1eWhiK/ot+kZvZp+PrEbXgtr9TbrcH4OVUhK/ZJeboeuIJBwSFHrvR5pZ676qhsI37EZDWeeb8cTf8iTgaSWz4seKvx/xuMIcinkSmrX6gxB9LGBESvWpxQRgWyQvD3ZkVcVwhlU/853eC/dj3C8zh7i+B28d+Eekg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5121.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(66946007)(44832011)(8936002)(2906002)(8676002)(66476007)(4326008)(1076003)(2616005)(186003)(508600001)(5660300002)(66556008)(7416002)(6506007)(6512007)(6666004)(36756003)(86362001)(52116002)(83380400001)(26005)(38350700002)(38100700002)(6916009)(54906003)(6486002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wrNkwSv1MOLhGaEHOxcbxO4y8ESQZSDvh43+BtqNcy0xqvaeepKsdBfh5K+8rLh6GE+LEU3qbxLY5Hbu9yP7wmQXJrNgi62PoE/xYdMckngDE81BFTmYQr9DJv0XxlIE+/HzuAkr5FvzSbJOcmBp7W6DxZFzUCWYGfHYrjRtqhbQrQUAyEGt0Ki4S0ve9NO284aYPzFNkzVmURqAwVjVz2PNUHkVhIFCvYja1P4l67kITQ1moNE0xDEGW33OUdryoZTCoEteDn6a0v8TVui/14EFaKyZVstYOeBuqp7zyrOVOqpuQQLV3w8mo7CAIRJaZreHwiS17E1WS8pfZ+sJqthqgDZbAJBjkuEArDuK88MdNf6BxsBJKJy3T5anywf1KX4lsE+OQYf5IjG1NwDdjDC4wQ1yiIJ+EZjmV3L0TagCmJ+hpFhTfnSahBJDvGXEfkFvmmgkEMaB4uXC8pikU/aDVYA0QU9EUHxxPSvIPohs+xGApRtMjUJSmTuF18oO51bMoMLu7qHgejJQ05p0GOgom3b0zh9sAZSMeGs6zLPoSBhfaOxUmK/OBtI5htILTkaO2LEVHbloR542e9uVBYzfhewK5X7h1MorT6gUYPPhthr6a76hGYRd4vgnRaAifSMuIG8Ln0sFrrhy4F2za+BD9Pw+v/YhvWv0Vq4OhJLwp5AfmI2aOIpJtrTdPSN4oHDy5XRntosrfrHrHWQTNlmJsG/MEUVBcO14B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id: d9fa61b8-053e-4973-f7b8-08da2cfc2776 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5121.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 11:57:53.3397 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gKenrR2VIVyS1+aBVJvps7SRAsUkFvV0f3cQVvUrQLMdWZcK/oFaiiSEGjxFXvK/AawQYQkqMa8M/h8JOYWUwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4813 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org ocelot_vcap_filter_del() works by moving the next filters over the current one, and then deleting the last filter by calling vcap_entry_set() with a del_filter which was specially created by memsetting its memory to zeroes. vcap_entry_set() then programs this to the TCAM and action RAM via the cache registers. The problem is that vcap_entry_set() is a dispatch function which looks at del_filter->block_id. But since del_filter is zeroized memory, the block_id is 0, or otherwise said, VCAP_ES0. So practically, what we do is delete the entry at the same TCAM index from VCAP ES0 instead of IS1 or IS2. The code was not always like this. vcap_entry_set() used to simply be is2_entry_set(), and then, the logic used to work. Restore the functionality by populating the block_id of the del_filter based on the VCAP block of the filter that we're deleting. This makes vcap_entry_set() know what to do. Fixes: 1397a2eb52e2 ("net: mscc: ocelot: create TCAM skeleton from tc filter chains") Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_vcap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c index 571d43e59f63..469145205312 100644 --- a/drivers/net/ethernet/mscc/ocelot_vcap.c +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c @@ -1248,7 +1248,11 @@ int ocelot_vcap_filter_del(struct ocelot *ocelot, struct ocelot_vcap_filter del_filter; int i, index; + /* Need to inherit the block_id so that vcap_entry_set() + * does not get confused and knows where to install it. + */ memset(&del_filter, 0, sizeof(del_filter)); + del_filter.block_id = filter->block_id; /* Gets index of the filter */ index = ocelot_vcap_block_get_filter_index(block, filter); From patchwork Tue May 3 11:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12835674 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0CB3C433EF for ; Tue, 3 May 2022 11:58:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235010AbiECMBl (ORCPT ); Tue, 3 May 2022 08:01:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234980AbiECMB3 (ORCPT ); Tue, 3 May 2022 08:01:29 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80054.outbound.protection.outlook.com [40.107.8.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A55A72DAB6 for ; Tue, 3 May 2022 04:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dOxwJrSh/Vwsqb/4lzOMPS+Sc81jKvhwUIVji6qTwV++mdYs0A5MN2AJg5zysJB7z14lfEYIqUkm5eK5iZIycknL4vgn0H9Oz5qQ12STfjyHs23gQOmDcV463brfFN+ZKANul/mp6njcJAkk+GLm/wxMzwkbpqqTUWYB8cdGXFl5Bj+FprtT82MAUtVavniWWcW0GKmzPVu39BOspunaQ7wwrbRmNbZ7J+vDoMrsMs+hJEVgXqdGWHxyj+WPop0GDNgcVhKFmu7pch8mzxw2tguMhlT4MOQZumr6RU17TfHpGrvoOnYbI0R4Cn6YoVDVjMIrDOT80/9Qpe0IMWN+Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZDuo9nD1XVXSjfbiCviVSvPSLbhpczxubl9E7hV4bRo=; b=IPOuNVaD3/AIKUhaomcvm/Z8g+M46d/8rEQAxh6TF3Ura/Dq5MLn7Cn2i8c59B5afnKZNUyFNbT60RVTJuWGNx/P/hiSjTRQhnmOTNRNuyguhBRdM8lggzGGxJtmNrwe4rrGbRw+Uh3SSUjdKcyLWUVC8el/v1eNBjd0qNbHQvv5d9slBjVm93fPolqAV5vo3DgL4ExdMsc0TfVy915hgqSc19XFgeDg2v2DkZM6LRsWfooIoC0o+xIxW4bK2BMgEkELeHQclxUdO3O/8ZsRI0CkZ/Uyhek7Z1GSCiZxn6rwtw4dsqurZZ5IuyviBUnSqXpCxJYdcJ0RTrmGhttFhA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZDuo9nD1XVXSjfbiCviVSvPSLbhpczxubl9E7hV4bRo=; b=OiD90QB5IokFqfRGol6wppK4SGXUvZ4P+g79Lm+JMkEVbtZX70W+htyA45q3U+6ERnj6iVv47Shm10R3CeKqpI19TfWARAnIj+YgB4tA3t5Bbiv2ysS5N9YDE1ktZDqnL9QYr2R5//88sFhoyTP+hfdkcCu9bGjeOny/RfNbvX0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) by DB7PR04MB5513.eurprd04.prod.outlook.com (2603:10a6:10:88::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 11:57:54 +0000 Received: from AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb]) by AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb%4]) with mapi id 15.20.5206.024; Tue, 3 May 2022 11:57:54 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Paolo Abeni , Eric Dumazet , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Xiaoliang Yang , Colin Foster Subject: [PATCH net 4/6] net: mscc: ocelot: fix VCAP IS2 filters matching on both lookups Date: Tue, 3 May 2022 14:57:26 +0300 Message-Id: <20220503115728.834457-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503115728.834457-1-vladimir.oltean@nxp.com> References: <20220503115728.834457-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1P190CA0009.EURP190.PROD.OUTLOOK.COM (2603:10a6:802:2b::22) To AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 026bd613-1e5b-481f-24c7-08da2cfc284b X-MS-TrafficTypeDiagnostic: DB7PR04MB5513:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Lg+FDTN88giKVTtCvFA7ucDTVkUthc5zLdeyXKz+nSV+Bwjlb+R9/HVIzXkHkUAh8/BvR8z1jJMqdd5HANo+/HeNOQSMhQFdFHb+LYr7858EnQkA/QGDdScCVKhZF3RmR9SRNTxGRr30F4uvWWV4wAb6ciUnHBKYJbdWX5cKgWT183TGX73S8UBOxOcY4Injp1q6+8Gs0/PFSHC6IeiloL7A5DmNjE23UKFNj0s2VlHND1cxoxUj11CngMhlujEWZoDaM2EbdI/mwBTYOHzaV21blKttj6xBaY6vQQNY50c1c73xCezaRpV+dPKEwriClT//RexM63m3W2sm0bua5rNsQohn5efo2Xsb5pZqktsXaKrbPu9i9CStpdDibLQlim3NJ1olPfzkapAJrXyZ0BCzMOEq6Sv3JA1kpTAFjOYgaTrd6+hZFhJD+pLAbj6RelSmKTCgvARfF20OCitQ3SDYMWozO+73T3t3/Jxz/6wkEGpiexQLgisKirSJTtkhGIQBo7L/6igkbbezeyxNscNHB9iJ/P5Yg9VBFX9ReSucZc5+8Q6TVxYBzDMz8nNV+EfCzVboGDc/7qhw8wmvxaAgnqHjS5CLuEInwzfyEIiuouq/n16pxtO+XoIa55w793HF2vyCgGR+cAJtMAoJIsLjkXosfxgQC4Nzz+R32Zcbb512WgH7AzTcYm9eG3I2C9Nm87s/Pev886qzBgCeqQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5121.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(52116002)(26005)(6512007)(6506007)(83380400001)(2616005)(186003)(54906003)(1076003)(86362001)(8936002)(4326008)(8676002)(66476007)(66556008)(66946007)(6486002)(6666004)(2906002)(316002)(7416002)(508600001)(5660300002)(44832011)(38350700002)(38100700002)(36756003)(6916009);DIR:OUT;SFP:1101; X-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SyXPiM83+Tg5MVxtJhB2are15dNbQyOSunCYnkWbdkUumyDQ00saP3oTKHlC4J6GOK9BmJ8fJRvaBbkN9MsMjgwJioXAB3Ms0b/zGrqw0lwB1KH2WYvBXHmgg4tgC3ifogTlJNFiVxXO0Y0QgSP4eLSHfzkQoZUGfyatffh1W4LpkUdq0qk79j+SXZJmgHcpILrJBwtL4hQ2ADrE3lGSTG83eWbdhqXqo5ta0Up9FfwNbgtPjXG5BlftwQEaD30itakDlaei7z20pI+UemZvB7AzHwCHshk7b1pEw9b9lTcNMhwsebGKiPE8WQyPIJoztdNYriySPKV1+JYmjphgDIcYUI9UcBAg56PKSMs0/N0+pr3RAKuYDsNhdPqoDXro2M/Qnn1e2B5QyHnKpnDbMjoadNCrALBMk7rsdY0kN0LNyhcztcvWXvY8mhnSDnzguru8STBdp4ZcgQ6zqRDw6u7g0nZxXXz8CP/24B/oGSi5ao1VD9GKe3sAippLPoutAdFb4w4y9X6vUDVg1ZYikbqzUClxofyMmuMI9a+9A8auygNYy6WYk73/D1RCipRAqM1SCx4vpxTJnVxWPsQ0QVF6EpXCCrMBsv06WFSpZN6HaSgoRR4NzzwXaGYzhbWo3F+2kekHke2dcGY00X2YXJ90Tza1oGuDg64slmhqdKFgYFLBOKtUzah3UOEHwG1ddN/xu+1ZY+G4hYpWP750O3ag8hQ96nrTkw/csVlDLzoac= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 026bd613-1e5b-481f-24c7-08da2cfc284b X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5121.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 11:57:54.8865 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C6NBPoynC1/NvlCsdW49yym2Qj16xuMNP0Rzcw2C6FMPTKxpYnw0Tmft2pE1I5Y2NZRfbqic4BzPbdOJEOIB2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB5513 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The VCAP IS2 TCAM is looked up twice per packet, and each filter can be configured to only match during the first, second lookup, or both, or none. The blamed commit wrote the code for making VCAP IS2 filters match only on the given lookup. But right below that code, there was another line that explicitly made the lookup a "don't care", and this is overwriting the lookup we've selected. So the code had no effect. Some of the more noticeable effects of having filters match on both lookups: - in "tc -s filter show dev swp0 ingress", we see each packet matching a VCAP IS2 filter counted twice. This throws off scripts such as tools/testing/selftests/net/forwarding/tc_actions.sh and makes them fail. - a "tc-drop" action offloaded to VCAP IS2 needs a policer as well, because once the CPU port becomes a member of the destination port mask of a packet, nothing removes it, not even a PERMIT/DENY mask mode with a port mask of 0. But VCAP IS2 rules with the POLICE_ENA bit in the action vector can only appear in the first lookup. What happens when a filter matches both lookups is that the action vector is combined, and this makes the POLICE_ENA bit ineffective, since the last lookup in which it has appeared is the second one. In other words, "tc-drop" actions do not drop packets for the CPU port, dropped packets are still seen by software unless there was an FDB entry that directed those packets to some other place different from the CPU. The last bit used to work, because in the initial commit b596229448dd ("net: mscc: ocelot: Add support for tcam"), we were writing the FIRST field of the VCAP IS2 half key with a 1, not with a "don't care". The change to "don't care" was made inadvertently by me in commit c1c3993edb7c ("net: mscc: ocelot: generalize existing code for VCAP"), which I just realized, and which needs a separate fix from this one, for "stable" kernels that lack the commit blamed below. Fixes: 226e9cd82a96 ("net: mscc: ocelot: only install TCAM entries into a specific lookup and PAG") Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_vcap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c index 469145205312..a4e3ff160890 100644 --- a/drivers/net/ethernet/mscc/ocelot_vcap.c +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c @@ -374,7 +374,6 @@ static void is2_entry_set(struct ocelot *ocelot, int ix, OCELOT_VCAP_BIT_0); vcap_key_set(vcap, &data, VCAP_IS2_HK_IGR_PORT_MASK, 0, ~filter->ingress_port_mask); - vcap_key_bit_set(vcap, &data, VCAP_IS2_HK_FIRST, OCELOT_VCAP_BIT_ANY); vcap_key_bit_set(vcap, &data, VCAP_IS2_HK_HOST_MATCH, OCELOT_VCAP_BIT_ANY); vcap_key_bit_set(vcap, &data, VCAP_IS2_HK_L2_MC, filter->dmac_mc); From patchwork Tue May 3 11:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12835675 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 828AFC433FE for ; Tue, 3 May 2022 11:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234979AbiECMBm (ORCPT ); Tue, 3 May 2022 08:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234977AbiECMBb (ORCPT ); Tue, 3 May 2022 08:01:31 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80054.outbound.protection.outlook.com [40.107.8.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECFBE2E6A0 for ; Tue, 3 May 2022 04:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=heBnbI/SXQPfWw/HNUD6k7rZ42zNDFb65wain9Attu1ytsP5998GiH7xEkozbBZqWD5w+XFCGufjUwnapeNGvFjK9aYgcldibU9Se+DwilvaRuB0XrbS8AkWKnOdcWt/7OvPqTTO/tXHeDlpwyziNmHKkyUQAtqeApxAK6b9D31csNPzsQxlcMtM5BfAzBW+Zx8mIEsk/xfaxej47TwhSxb48AeYlNMyJaJtR3PUr6T49Yz3stzbr2OyalJmvgbzP4bZI15exgYhZgqPQzrE0eKXBycye7OgACy5sAvYMr/Nzi73JOiGRWbSwn4LovV5EoaTBRG8+RJkxX2Jq+hWJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OISQ4WW5Wt5BjgCvi3n7jql5wEL6vqi3Eil0dqImHU4=; b=c9GVLVvkF/+vN+O3WCe/1wxsMK7sZmW8rDQsgClksqahDDVclMGvL6mv9L3tX8RibAcwuXegXiS9CY0H7YQc2tJ5MSocWZwp4Nh3AVXPS730DoV3Z5trmLKJy1hgOmiLkm1GNFbJjcNwnJ9SVVI1zWgXvsvtp3o9vb+NptXZ/K8W60pmcv4bu8msPjMJaQ/mroUUV3KTgkceXnV0EqeVu4bHHxPXfr/TpBfVX3YDy0gV9aDitx7D03u+2zMOUR7FqElG+8MNCvxr2ZGpCcbIx41M3lA9l/6NN2R3txf6951rKdoW2T9qhMp0EHtETWwEq9lsV1azAGP4+82M7G3GdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OISQ4WW5Wt5BjgCvi3n7jql5wEL6vqi3Eil0dqImHU4=; b=A37fgD2KL/Sy8BPyB7L6Dp3zj4f4guK0yl/pxwnMpV5MX8HIfzy1Cerk7UZM5OgfL9eAqWCRjghmQ2djtKPk6eZRu1ZsT953tSiz2yfksCH3FNJGVAeWP+h6wMTfFkYg67PDEcF74yDq95v2h2CiBDXS4rq2AKAoXgny+tUvDic= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) by DB7PR04MB5513.eurprd04.prod.outlook.com (2603:10a6:10:88::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 11:57:56 +0000 Received: from AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb]) by AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb%4]) with mapi id 15.20.5206.024; Tue, 3 May 2022 11:57:56 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Paolo Abeni , Eric Dumazet , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Xiaoliang Yang , Colin Foster Subject: [PATCH net 5/6] net: mscc: ocelot: restrict tc-trap actions to VCAP IS2 lookup 0 Date: Tue, 3 May 2022 14:57:27 +0300 Message-Id: <20220503115728.834457-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503115728.834457-1-vladimir.oltean@nxp.com> References: <20220503115728.834457-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1P190CA0009.EURP190.PROD.OUTLOOK.COM (2603:10a6:802:2b::22) To AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 12855711-2fce-4d97-c077-08da2cfc2991 X-MS-TrafficTypeDiagnostic: DB7PR04MB5513:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4PF3zmxDUB1KpBEr7YCWdjw4W1D/hPTgWKhFctfTUzLkX6VoDTxSfrwnZZzaYFG85RWNDfgg8nwU17hvZH9zU122PvXNy7Da21oHwtriKbP5XyDbB/uCHgA2T7s6SnhsHytfAKCPoIAzA07qvAu4Mz4SnDmQx/5hJRcuNLXEfm3CqXTn7fwudGqP6JTQ+TiklxqfK0JWQaY8poAcKHIIGQEi7sde0eG13KqDA1WO8sKkRvcpGzCZIjNT0Wf3d3LJk02EhO3/W5JiJM6yOSynpnvC5TiXOjw/T6gSGJ/O4eNgWi1DZsZo94vPJ40VC04gvZDIo9wjwx353wRg/pXWNw6vRG3dwzM6X0i6uHhXzpjVM+lf++cYInCkOVwkZWNZZkp228XaPrkzDaaJp1u1UXOsxZ1h+yUEAI8bDlVPlPDnnpgpYMnfLEyEh2XEz/LlaSdoBcPxuMSDWrn6dB2Akwh3jpRgd1n3XTUPi8no7AIyWcqMlIxCaQT4sSPLGekJVndSKifzmBggOVC7lqlt6g13YmD+RVzDiiYv5MtzjREnrzOhRVXla/xmF3uC7Q3LXE0wC+wzh+WlB+yx0AeRBV0Ln+Zy78Ab4Nqab4ySfbKnb1Z2lphX84nZa6BFaIwDRYu9NOuHqRK5XE1glOvKWaUp8gdlxHc8/1H8HF+ZxkwUAth7a5wOyBdG94l3tjAERNdI5vVdDBKxaybA0SeHyQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5121.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(52116002)(26005)(6512007)(6506007)(83380400001)(2616005)(186003)(54906003)(1076003)(86362001)(8936002)(4326008)(8676002)(66476007)(66556008)(66946007)(6486002)(6666004)(2906002)(316002)(7416002)(508600001)(5660300002)(44832011)(38350700002)(38100700002)(36756003)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tuS1wkrzzjw1xSWQjDSHRfJUYoye/lrfAIANAKCeGPdazXyDpZqixWFaRzRqtwJL9SHQj4/ewAQpFtDm/5tegWhh5bYaZSU7su/l8iTkyL1Se0mjwLEvQIqsRcGLLlCY12h7gUAbY11S08uqRTz6XfuzUIiHp6bQ+bbAVBo8GvGV9wtLhtxv1lE1vm9H//vpalA4/gWZiTasc2/ZO0MugdnDyvyoAvfhE3+rq6JKoUliD/0WVhs79KfDidcb2iFm+LusZtIuDn69QLTnScJ0aMTE+4wZsUpOAvoNeWZf9+pDPoa60smEwd99rEIyeXQ9gEZmIA/OcCSTcqibc6bRufQXxzmTgNCwcEHlm3HJFN/VGPsV7p8xEaoEchdt7P8snl2G2xuCVldMbWC6PU2lZTIABOm8WIvKTzEW8FJMhbnhclEuy+hqkTs/xhT0k5WNe4MlmRAsJmkTCaDyiE4bpst87efz0hafruWAz0G0QK7cp8SR6uwAt1mIDqkrUOeX7lMgFkUyp8Oq/TGMNXm9eon9ZdR2lz1he7jKPh5NlvNfQveSYdb0gmvvVilGqXHgqjrFdd5nOWpi8DWB/2UblffboOMR9mMAb80fKYCuyMiIwMOH92xRep0vUhNYPYnr9Ixzp4rve4XesZ7/G0QQH74irmUAEbBh7plrj7mSzvft7x3lSw8G394xk3iZY4pkXjsyRS1xy7m0C4QPof16Wcr4/UXyH0yHzGF3W5BHI9tb8HK2Ao97u1QxI88AQqxF/B7cRvuaB+fv1tGoaIizsOdtMLEEVIhD4eWbzjJjtAnU1TYREqbXWqFhu39xxHP91w7I4FRF7q4L+tfHUt6lWXV0Y8ANZVuZmrxP3dlw6Zdt95XU8g9jI3/7KjrQZ1tgwH37XfMpYnW35XadJKDtMKDM9r4aF4jD3S3tlip9XypgZwjZ7WHcAh8SyQkFbX81LGmvS89rew5CBai4vqh4e+Y9t/exo9XjY+Fg/woGSQNMI8uOB6P78wfVTj6M8vc7f2dNP+7Lvw1eMuz3EraXnlVl883e9Hs7kPCjJDzq6blVsmsYoqdMiGXRPkJhtFgqznE49pMKAykHREKNRaYCDlatjPcR8Ai1opkxx8aDEq2Y/RWF8QH8tAzszQ7NTTvRJFPO2c5/cbNdmUBaVNqDrK1a4D23tBTYH0M8H4neFpGFAv5EfcICIRzZnQNgZjY1ud1w3dJlZdqdOwURa+xfDx2ftQE1eMYtNMA0c4rAuYa1ysCC+ZuwLkdRkecfOWb41mhkrL5xKLfmhuiJPjuP/MjrAVN99p7b8fRk3Xo7PFt6uWNarzA524LxnreujKJXumOANSOoFk3vgv0KG4SoxgRYpcVcQgtydO/HXX1TgnasjS5BZNDW2RXAX9xJtz/bGS6uTqjL6/+mx3on6QN9F3/mmZpHszLGT41EjFcI7SIuN+jIpgA5XyYC4yNDb6w5608rg/abKoK1vJxoFzMaZDVnWBnbLH2gApWZSXm9RRbjFyVK51/Eq2HN52PUpSp2pq+45ozZeVoPWA/3qph73Up1TLTe02bozrHvFsZd2lPWo0T0H0r1S9+50a45D18wbfK9fd1/WTShJrqCuV2jDn20ZsHQp1QCTTuj0EPTAcjuvE/q3eHnUB1uykg9OkmO0g/PRKSs+kJYlt0sS3HaisAAqj669saM/YKNPqJf739bI1smxSpHPVPF125Il6eRKS64vIbJIItMP1Us8LE5YRZyDww5wjsU2KPvjNKXOBs= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12855711-2fce-4d97-c077-08da2cfc2991 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5121.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 11:57:56.8863 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: TjKtipX74NQQpFauWH0J6ECOQv6y/VABBFiWFr1OILnALh7g4tHyiLRY2WCkSiHnxtq/9KqZedMqavrGaiHYGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB5513 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Once the CPU port was added to the destination port mask of a packet, it can never be cleared, so even packets marked as dropped by the MASK_MODE of a VCAP IS2 filter will still reach it. This is why we need the OCELOT_POLICER_DISCARD to "kill dropped packets dead" and make software stop seeing them. We disallow policer rules from being put on any other chain than the one for the first lookup, but we don't do this for "drop" rules, although we should. This change is merely ascertaining that the rules dont't (completely) work and letting the user know. The blamed commit is the one that introduced the multi-chain architecture in ocelot. Prior to that, we should have always offloaded the filters to VCAP IS2 lookup 0, where they did work. Fixes: 1397a2eb52e2 ("net: mscc: ocelot: create TCAM skeleton from tc filter chains") Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_flower.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_flower.c b/drivers/net/ethernet/mscc/ocelot_flower.c index b8617e940063..e598308ef09d 100644 --- a/drivers/net/ethernet/mscc/ocelot_flower.c +++ b/drivers/net/ethernet/mscc/ocelot_flower.c @@ -280,9 +280,10 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, filter->type = OCELOT_VCAP_FILTER_OFFLOAD; break; case FLOW_ACTION_TRAP: - if (filter->block_id != VCAP_IS2) { + if (filter->block_id != VCAP_IS2 || + filter->lookup != 0) { NL_SET_ERR_MSG_MOD(extack, - "Trap action can only be offloaded to VCAP IS2"); + "Trap action can only be offloaded to VCAP IS2 lookup 0"); return -EOPNOTSUPP; } if (filter->goto_target != -1) { From patchwork Tue May 3 11:57:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12835676 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 306C3C433F5 for ; Tue, 3 May 2022 11:58:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234980AbiECMBn (ORCPT ); Tue, 3 May 2022 08:01:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234985AbiECMBk (ORCPT ); Tue, 3 May 2022 08:01:40 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80054.outbound.protection.outlook.com [40.107.8.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E67F2E6BC for ; Tue, 3 May 2022 04:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6Y9+tcymY8QqRNRoS3NIL+TVC+ksQVQg7g8MS4xHXBU5pVZ0+mA5W4iMLnUVcC74TDG/aYvPWT2EGrXUIOLHrXf+tNCqlYJjfAA/frngeLh+rjJSnPLvFXEKZojU8Ars+Ufl6KquT4uAA6He4vP/xolunpmARp/urbgTaERsNjxSXVbaHVMt3WtTUbhvJoTcyaGAwJZmXVsktWwYQ4PSmlCjlLvwpYG72tuDK+o2/RABo4JfrMiCbfyMNs3ydI3/CoTUAfg1syua7UH8OMaA6BZMUnmRFO+Vhc2GjmaypFd0QHbOWJ2aI6g79tTM41qsKun8DDI/YQmMe/t0+OxzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5mHlgCmUwAElRPeFqwY8lrBhYfcjGpPdLManQ4A4e98=; b=aO620/pAIsORhMnrP/9qbtI0fVxG3JfxUFrvyf9An9mYy19ZBjVLtffhFapHP+BvLvhyhLIUoScIESCpEExMjsSwzF3DyY6iqc5PCPNZcgld8pq5WpqfzqbwA7e74x2sWsjrbDoPUCKYvp7JokKmExBl/eBPxf56UBjj4q1BRTtvNMAg8lkJmLu+/PpflWjH/h5QjN0zEbR4K+NMPi5xZy4xWELbCzBZDzm3alRkrm1cXkxkJ/H4wNDlcsFHTKBNwz3xr4Gn5ZtP+19tZyOwRmlE3x3Fqi2G3J36Fv4dnqRAdglWbhnhCuRlORLYnrGwhGyt79BoHOOmIVLZUCdnQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5mHlgCmUwAElRPeFqwY8lrBhYfcjGpPdLManQ4A4e98=; b=kb39PnZBpXmYDatTkWXwk4Obt2kwBzFczO8AF1/PbGuwyHMQRz4YiW4LFKchKKqfDnShzNi54n0LNaBbs7aZzMPqqPn+g/ZTPmugMueIzrLbd4UIiGiDNFtNyQaDPguXi5JX5iuZRm3xqJmL7i2FtWwbxyUpJAD9u8SkvRni6fU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) by DB7PR04MB5513.eurprd04.prod.outlook.com (2603:10a6:10:88::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Tue, 3 May 2022 11:57:58 +0000 Received: from AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb]) by AM0PR04MB5121.eurprd04.prod.outlook.com ([fe80::d42:c23c:780e:78eb%4]) with mapi id 15.20.5206.024; Tue, 3 May 2022 11:57:58 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Paolo Abeni , Eric Dumazet , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Xiaoliang Yang , Colin Foster Subject: [PATCH net 6/6] net: mscc: ocelot: avoid corrupting hardware counters when moving VCAP filters Date: Tue, 3 May 2022 14:57:28 +0300 Message-Id: <20220503115728.834457-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220503115728.834457-1-vladimir.oltean@nxp.com> References: <20220503115728.834457-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1P190CA0009.EURP190.PROD.OUTLOOK.COM (2603:10a6:802:2b::22) To AM0PR04MB5121.eurprd04.prod.outlook.com (2603:10a6:208:c1::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1af042ff-4363-491b-ed8a-08da2cfc2a65 X-MS-TrafficTypeDiagnostic: DB7PR04MB5513:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aM550SMl6tHX1aUnRkzUH5kFoGhV5Ou3yGUlqBHvL1EKwn3wt81PzxldAOWG4TAxxhHW4AJRjPahHJZJjE25/jIGqvBrEd+OMph8wk8pvUlzGYjSFWgN8Wurvd/jB7/LVZKeLeQuNc49FQO5FefYg+0eB4oQbGpwnHwbh/3T3oGQoZDYqglznmlAzhul3G1YHkzq6n2vs1oJD5N22oPVY/yjqrnjGDoWWAdDgwhWzifxdJWvG1SL+ddmh6m6QgHj89nUfJkWETY45k6YnI81MrXg35zVW/J2LaRe2z3NkLpYHahY9S76PqzNQyrWxS0J572PWaqS5mZGv2ZIas4zQRBL/L/LtmFYnWMtTOcq00A4X0iRNhoq63vxpjYjwMPJOAlUzpjcoTHPu78cJvGUUwrHmlk3u6jxLtP8Iclt1o73KDnr0hyKyNfDtJ6n/IJK9X0DMOfj38f94w/cyNfGQKp4+sMzYf2vI9EiHPHrf9BUrXOIHHPJKbmE0tnAiEf+UmuZDhghVtGXtsLMuFnq/Zp/Tw4YWmPWd7UrZxllXbOwhwtaDPFgWdHfIv0ze4CxOfxIuL6vH2/tRqPsL9KBE6S7NCtS4eQ3oeO7Y15+aI8TK2ifNyKIUil4uHHq6GTZuhh9Edf1QwnanQNsY0Yx7XHCM5pWHvPrarbo+mT+huUjAZmsQPAxyX3z0AEb2FNFoCcTgdJWKEqo+nSwM9JeXw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB5121.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(52116002)(26005)(6512007)(6506007)(83380400001)(2616005)(186003)(54906003)(1076003)(86362001)(8936002)(4326008)(8676002)(66476007)(66556008)(66946007)(6486002)(6666004)(2906002)(316002)(7416002)(508600001)(5660300002)(44832011)(38350700002)(38100700002)(36756003)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YGnMednd4xSHFf2IwARKnZbaNfbwkVUuYVJgQOPWxm0L8eE7CuwqstFVUmyOc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JagmaYNtE43vsUYQlBovb73G9d4UquekCRDvE5qSVBtMaus+GgTe1nngi572rWUd/wSpW8scyVW7QPOOds8UCpcJwb2rAWjxV6nkdnR0vMw06BGwQkIJxfP32yP9EwuSEzVJUY7ZyEOr02MIDVC7RInOCurGYC4hyl9xmqDk9qNlaK3gS4RolN0oUoZcf1Sap8H4niptTIqRRJJoy0gtmfAc4qR6vM33bV7Fg06HRFFtUfbgtb+9pQE7wId+merjsLzljPJTzOeHiqH0fcOh3dZ6j/BpfA3wWD/kljKJ3dfsWCaBULe8iPKwBXz/mpw1eAg3QZQPWYWKXUBs1L4cBaYqEtAs3jriY6HAI7rQypNU/gU49T/HWLoQOihQDzeC6rWy61oJesGR74Q4OuS/DSUfvSCZ2y9eluhZP1WentNG84v83NcicY0KLZ8RDeBBfT2NIvLWGF1Ak/kvJZbfgh8KB1n/QV2gOmV2KlAR7GotkwIb87OMPvTqxqyPV7gXvhmNkT6AlXb2cL/RRyvEIEDKOBwlSDCJ2RmnkbBZYha2DYTwsHkttRRpa75ixzsagU88enfZSzHFKPJzSDhTGgW3FtYTByDWHVQ= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1af042ff-4363-491b-ed8a-08da2cfc2a65 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB5121.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 11:57:58.2768 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oOD1Mw4UypYDcqYMrkBXn24j0sEMMsDFltj/WEwPxgGQS2ZI1eIvY4lWQjPSZ5mZyPCnVxLMltKXQORYWgFiLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB5513 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Given the following order of operations: (1) we add filter A using tc-flower (2) we send a packet that matches it (3) we read the filter's statistics to find a hit count of 1 (4) we add a second filter B with a higher preference than A, and A moves one position to the right to make room in the TCAM for it (5) we send another packet, and this matches the second filter B (6) we read the filter statistics again. When this happens, the hit count of filter A is 2 and of filter B is 1, despite a single packet having matched each filter. Furthermore, in an alternate history, reading the filter stats a second time between steps (3) and (4) makes the hit count of filter A remain at 1 after step (6), as expected. The reason why this happens has to do with the filter->stats.pkts field, which is written to hardware through the call path below: vcap_entry_set / | \ / | \ / | \ / | \ es0_entry_set is1_entry_set is2_entry_set \ | / \ | / \ | / vcap_data_set(data.counter, ...) The primary role of filter->stats.pkts is to transport the filter hit counters from the last readout all the way from vcap_entry_get() -> ocelot_vcap_filter_stats_update() -> ocelot_cls_flower_stats(). The reason why vcap_entry_set() writes it to hardware is so that the counters (saturating and having a limited bit width) are cleared after each user space readout. The writing of filter->stats.pkts to hardware during the TCAM entry movement procedure is an unintentional consequence of the code design, because the hit count isn't up to date at this point. So at step (4), when filter A is moved by ocelot_vcap_filter_add() to make room for filter B, the hardware hit count is 0 (no packet matched on it in the meantime), but filter->stats.pkts is 1, because the last readout saw the earlier packet. The movement procedure programs the old hit count back to hardware, so this creates the impression to user space that more packets have been matched than they really were. The bug can be seen when running the gact_drop_and_ok_test() from the tc_actions.sh selftest. Fix the issue by reading back the hit count to tmp->stats.pkts before migrating the VCAP filter. Sure, this is a best-effort technique, since the packets that hit the rule between vcap_entry_get() and vcap_entry_set() won't be counted, but at least it allows the counters to be reliably used for selftests where the traffic is under control. The vcap_entry_get() name is a bit unintuitive, but it only reads back the counter portion of the TCAM entry, not the entire entry. The index from which we retrieve the counter is also a bit unintuitive (i - 1 during add, i + 1 during del), but this is the way in which TCAM entry movement works. The "entry index" isn't a stored integer for a TCAM filter, instead it is dynamically computed by ocelot_vcap_block_get_filter_index() based on the entry's position in the &block->rules list. That position (as well as block->count) is automatically updated by ocelot_vcap_filter_add_to_block() on add, and by ocelot_vcap_block_remove_filter() on del. So "i" is the new filter index, and "i - 1" or "i + 1" respectively are the old addresses of that TCAM entry (we only support installing/deleting one filter at a time). Fixes: b596229448dd ("net: mscc: ocelot: Add support for tcam") Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_vcap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c index a4e3ff160890..e98e7527da21 100644 --- a/drivers/net/ethernet/mscc/ocelot_vcap.c +++ b/drivers/net/ethernet/mscc/ocelot_vcap.c @@ -1212,6 +1212,8 @@ int ocelot_vcap_filter_add(struct ocelot *ocelot, struct ocelot_vcap_filter *tmp; tmp = ocelot_vcap_block_find_filter_by_index(block, i); + /* Read back the filter's counters before moving it */ + vcap_entry_get(ocelot, i - 1, tmp); vcap_entry_set(ocelot, i, tmp); } @@ -1266,6 +1268,8 @@ int ocelot_vcap_filter_del(struct ocelot *ocelot, struct ocelot_vcap_filter *tmp; tmp = ocelot_vcap_block_find_filter_by_index(block, i); + /* Read back the filter's counters before moving it */ + vcap_entry_get(ocelot, i + 1, tmp); vcap_entry_set(ocelot, i, tmp); }