From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86088C43381 for ; Sun, 24 Feb 2019 06:47:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3D9DA204EC for ; Sun, 24 Feb 2019 06:47:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=Mellanox.com header.i=@Mellanox.com header.b="fgaDk6K4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728173AbfBXGqz (ORCPT ); Sun, 24 Feb 2019 01:46:55 -0500 Received: from mail-eopbgr80082.outbound.protection.outlook.com ([40.107.8.82]:37246 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725965AbfBXGqt (ORCPT ); Sun, 24 Feb 2019 01:46:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7EEVBs3OjBWFuAxuNbGURnme0IwuxGA39300Ymh61aw=; b=fgaDk6K4phzRo1LOhDEPycaC03PuOxhLUxHrQ8F29sOi5cq7vXgFvqKL9LgNnAEY/2LbHbye3q8+zRV7M5OmtlO24hXCC8+UiEpxJWrsrwEo6twwCBGyEuZlUA9876QQY0f1c+I/8hj9gD3/sy9YiS60nasvu/hqBz0bOYtvaQI= Received: from AM6PR05MB5240.eurprd05.prod.outlook.com (20.177.196.214) by AM6PR05MB4343.eurprd05.prod.outlook.com (52.135.162.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1643.18; Sun, 24 Feb 2019 06:46:28 +0000 Received: from AM6PR05MB5240.eurprd05.prod.outlook.com ([fe80::3542:889c:3a85:3866]) by AM6PR05MB5240.eurprd05.prod.outlook.com ([fe80::3542:889c:3a85:3866%5]) with mapi id 15.20.1643.019; Sun, 24 Feb 2019 06:46:28 +0000 From: Ido Schimmel To: "netdev@vger.kernel.org" CC: "davem@davemloft.net" , Jiri Pirko , mlxsw , Ido Schimmel Subject: [PATCH net-next 07/15] mlxsw: spectrum_acl: Introduce a mutex to guard objagg instance manipulation Thread-Topic: [PATCH net-next 07/15] mlxsw: spectrum_acl: Introduce a mutex to guard objagg instance manipulation Thread-Index: AQHUzAyqP7b3dfqcWE+//FwQ6mebvw== Date: Sun, 24 Feb 2019 06:46:28 +0000 Message-ID: <20190224064525.14913-8-idosch@mellanox.com> References: <20190224064525.14913-1-idosch@mellanox.com> In-Reply-To: <20190224064525.14913-1-idosch@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P194CA0033.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::46) To AM6PR05MB5240.eurprd05.prod.outlook.com (2603:10a6:20b:64::22) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: fcf2a271-1f4b-4bf8-56b1-08d69a23cd46 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600110)(711020)(4605104)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:AM6PR05MB4343; x-ms-traffictypediagnostic: AM6PR05MB4343: x-microsoft-exchange-diagnostics: =?iso-8859-1?Q?1;AM6PR05MB4343;23:7eNdtJSclDrVXjPe3mqdpc9Cj8ap1uV8RxVadvd?= =?iso-8859-1?Q?5fbhL9FDLFwTGeURYHNiU90SO84dEX6/v2aR/kvIN3vNfFoIgMAsY8z4rw?= =?iso-8859-1?Q?7kRLDu0RIBs87p3Xim5+KHtUau8df+CZg1FrQydVXBBhGc6t7CJiWNHu6n?= =?iso-8859-1?Q?e6Etm5jVsz7/Q6eHEhqmLwwHShF0v7pwckzOXy8emul4ZoW/zKYxmBnQ3T?= =?iso-8859-1?Q?ekWhVpQuLJ49KoNaYMTSSbnJBYI3SM1lU4tI5j9uBhfoUgV/oHSv/EY6Cb?= =?iso-8859-1?Q?RYQPFjfqDkeYozal9d/5t27BOGL5plehNwY/DQCdE30opuxXHu6d0bI6Gm?= =?iso-8859-1?Q?/ZSpht+YjkBSsLuV1kXGBuuFdI/jGCHQRP+LbIsDREq8xVHhVcmQt8Xxq5?= =?iso-8859-1?Q?rQvR3zvblf2W4QyQdGPN8J7zflied7EQi6xoqjvqAvN+BYvAjUgaDG0WPU?= =?iso-8859-1?Q?vY5ykWeZ0US9OwgAXIGRXUFZsg9SVVSs05M6OWAMe1gdaa/aKbooomM4gz?= =?iso-8859-1?Q?eNg9ajbxreHo2yKGDOYZcH8nzhRfZ2Pmb5irnklp3+Vn1/RC7r8tzl/V52?= =?iso-8859-1?Q?ufIMAqwPAXYmqFl4PSIYcg0m2lc6iE2eMYCFSWmHbpYBZL8xv3XshVroDv?= =?iso-8859-1?Q?iEhUoKjuGUyEl67eGs9JIYU9shTfut7FYh6aqnOogMEs8U5dskFPcjVjLG?= =?iso-8859-1?Q?5LLdET6T+Ijz56MHD6H70GUsKD9FtcS8CgInErt7XauIGX96WhJLnkrdA+?= =?iso-8859-1?Q?QHCFxLttEPDFmn4a3Hwt2XIr/zWUUA6OhqAHYOmZ4bKuByRC52lFpQAPR6?= =?iso-8859-1?Q?pgprXRzkFUAY3agl2OJHKgd5g0F0toG8nSM2w96JPe1lBVcBMNyJzEN9AR?= =?iso-8859-1?Q?7k4abs9SG27LZ7hWI3PXkzkFlqvyyTTpZ624fy/FMDO+xpNpRtq48rRHN4?= =?iso-8859-1?Q?higDMQc5dHv/2hszVv7maGeLJzAS7zdq3J+yEz8oubVeSfHibKQnA4vrsM?= =?iso-8859-1?Q?3ZiVsSLq9S+I5TmnE9pjnfuGulI7zGxnkO4SQJfhtHz7jX7kPLxuHdIwBx?= =?iso-8859-1?Q?WWRyibDAq+NFmym5yovLJKR6Fw1wlbE8KgdcNkh6fpjbqNJOuBe9lzhSyn?= =?iso-8859-1?Q?BsiilgehoKLtCN5RjYb3HHXaoi8l9CqN/4jrHfaTgJrEAfMPBpF7pPPUZe?= =?iso-8859-1?Q?aHVEalKjf2YJGvfg+BOp3QAA6c4nabk96PWWV+dwTLaG2RL+ZOmVhsmdnT?= =?iso-8859-1?Q?8abLPO/ug6FYWBCBHHK1uD5DzRYq4zts6Q9Mkka2zLNVTMy8dJlbFtq/aQ?= =?iso-8859-1?Q?bsF36OG3lDyzBsafhuLEGI6HU+xku+PAYQHCVHDohu4gSR1pDE1ZrNU1th?= =?iso-8859-1?Q?ODqpgzrSNsiDnJhzDfxFfb+P2v7NircDCv7FQDUynLBG6Qdy7/Q=3D=3D?= x-microsoft-antispam-prvs: x-forefront-prvs: 09583628E0 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(396003)(136003)(376002)(346002)(39850400004)(199004)(189003)(102836004)(5660300002)(3846002)(14444005)(8936002)(6116002)(5640700003)(256004)(6506007)(386003)(1076003)(71200400001)(71190400001)(14454004)(6512007)(6436002)(81166006)(2351001)(81156014)(1730700003)(6346003)(50226002)(26005)(6916009)(107886003)(2906002)(99286004)(86362001)(2501003)(486006)(2616005)(4326008)(11346002)(54906003)(66066001)(316002)(476003)(446003)(53936002)(68736007)(52116002)(7736002)(6486002)(8676002)(478600001)(106356001)(305945005)(105586002)(25786009)(186003)(36756003)(76176011)(97736004);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR05MB4343;H:AM6PR05MB5240.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=idosch@mellanox.com; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: RfbGfa7ocvQc/KWlo2zA/MeNS5KUOyNtX3j9MRp26uLezlo1AHDv0Cox3upx1mtMosZDRbuGiUKqxHXsN80mw0GDZ5P6IYgiBcR9Fzhu2cpGEg60ahcNc4kJ4aim9KKy+O4/CDNssUFFY2zqBOIVBID8PsudztxyL90IX4gqPhNRenFZmoCwu1k3fOGG9zXsC882nMUn9yXBv301i3zkEc8g2YFVQxylUKiqHjU9Kly2jjTtKUtlrT1Qi1RGCrw6d870aqKoQTYGGRXhicpfwj7eDEBO+2beR5rvOPo501ly8lOOsf/KyTpeeMRt08fqyY0I4p+BuNhxwjixWCxbep2eA2qMMrP3VjWc6i0r9yNaij6QR73nzLjKW01AUuYHeZfQ+omseutGGu4UfwlnlOSXCCcXw2/92nr+6SzOXg8= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcf2a271-1f4b-4bf8-56b1-08d69a23cd46 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2019 06:46:27.3392 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR05MB4343 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Protect objagg structures by adding a mutex to ERP code and take it during the structure manipulation. Signed-off-by: Jiri Pirko Signed-off-by: Ido Schimmel --- .../mellanox/mlxsw/spectrum_acl_erp.c | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c b/drive= rs/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c index e935c36638d9..d6961dd0c556 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ struct mlxsw_sp_acl_erp_table { unsigned int num_ctcam_erps; unsigned int num_deltas; struct objagg *objagg; + struct mutex objagg_lock; /* guards objagg manipulation */ }; =20 struct mlxsw_sp_acl_erp_table_ops { @@ -1001,6 +1003,7 @@ struct mlxsw_sp_acl_erp_mask * mlxsw_sp_acl_erp_mask_get(struct mlxsw_sp_acl_atcam_region *aregion, const char *mask, bool ctcam) { + struct mlxsw_sp_acl_erp_table *erp_table =3D aregion->erp_table; struct mlxsw_sp_acl_erp_key key; struct objagg_obj *objagg_obj; =20 @@ -1011,7 +1014,9 @@ mlxsw_sp_acl_erp_mask_get(struct mlxsw_sp_acl_atcam_r= egion *aregion, =20 memcpy(key.mask, mask, MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN); key.ctcam =3D ctcam; - objagg_obj =3D objagg_obj_get(aregion->erp_table->objagg, &key); + mutex_lock(&erp_table->objagg_lock); + objagg_obj =3D objagg_obj_get(erp_table->objagg, &key); + mutex_unlock(&erp_table->objagg_lock); if (IS_ERR(objagg_obj)) return ERR_CAST(objagg_obj); return (struct mlxsw_sp_acl_erp_mask *) objagg_obj; @@ -1021,8 +1026,11 @@ void mlxsw_sp_acl_erp_mask_put(struct mlxsw_sp_acl_a= tcam_region *aregion, struct mlxsw_sp_acl_erp_mask *erp_mask) { struct objagg_obj *objagg_obj =3D (struct objagg_obj *) erp_mask; + struct mlxsw_sp_acl_erp_table *erp_table =3D aregion->erp_table; =20 - objagg_obj_put(aregion->erp_table->objagg, objagg_obj); + mutex_lock(&erp_table->objagg_lock); + objagg_obj_put(erp_table->objagg, objagg_obj); + mutex_unlock(&erp_table->objagg_lock); } =20 int mlxsw_sp_acl_erp_bf_insert(struct mlxsw_sp *mlxsw_sp, @@ -1334,6 +1342,7 @@ mlxsw_sp_acl_erp_table_create(struct mlxsw_sp_acl_atc= am_region *aregion, erp_table->ops =3D &erp_no_mask_ops; INIT_LIST_HEAD(&erp_table->atcam_erps_list); erp_table->aregion =3D aregion; + mutex_init(&erp_table->objagg_lock); =20 return erp_table; =20 @@ -1346,6 +1355,7 @@ static void mlxsw_sp_acl_erp_table_destroy(struct mlxsw_sp_acl_erp_table *erp_table) { WARN_ON(!list_empty(&erp_table->atcam_erps_list)); + mutex_destroy(&erp_table->objagg_lock); objagg_destroy(erp_table->objagg); kfree(erp_table); } @@ -1376,14 +1386,16 @@ mlxsw_sp_acl_erp_hints_check(struct mlxsw_sp *mlxsw= _sp, struct mlxsw_sp_acl_atcam_region *aregion, struct objagg_hints *hints, bool *p_rehash_needed) { - struct objagg *objagg =3D aregion->erp_table->objagg; + struct mlxsw_sp_acl_erp_table *erp_table =3D aregion->erp_table; const struct objagg_stats *ostats; const struct objagg_stats *hstats; int err; =20 *p_rehash_needed =3D false; =20 - ostats =3D objagg_stats_get(objagg); + mutex_lock(&erp_table->objagg_lock); + ostats =3D objagg_stats_get(erp_table->objagg); + mutex_unlock(&erp_table->objagg_lock); if (IS_ERR(ostats)) { dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get ERP stats\n"= ); return PTR_ERR(ostats); @@ -1411,13 +1423,16 @@ mlxsw_sp_acl_erp_hints_check(struct mlxsw_sp *mlxsw= _sp, void * mlxsw_sp_acl_erp_rehash_hints_get(struct mlxsw_sp_acl_atcam_region *aregio= n) { + struct mlxsw_sp_acl_erp_table *erp_table =3D aregion->erp_table; struct mlxsw_sp *mlxsw_sp =3D aregion->region->mlxsw_sp; struct objagg_hints *hints; bool rehash_needed; int err; =20 - hints =3D objagg_hints_get(aregion->erp_table->objagg, + mutex_lock(&erp_table->objagg_lock); + hints =3D objagg_hints_get(erp_table->objagg, OBJAGG_OPT_ALGO_SIMPLE_GREEDY); + mutex_unlock(&erp_table->objagg_lock); if (IS_ERR(hints)) { dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to create ERP hints= \n"); return ERR_CAST(hints); --=20 2.20.1