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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F148C433F5 for ; Thu, 18 Nov 2021 14:28:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 151E36128C for ; Thu, 18 Nov 2021 14:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233110AbhKRObQ (ORCPT ); Thu, 18 Nov 2021 09:31:16 -0500 Received: from mail-eopbgr60107.outbound.protection.outlook.com ([40.107.6.107]:23958 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233068AbhKRObO (ORCPT ); Thu, 18 Nov 2021 09:31:14 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QxdENT6iWjEeCL6C+Hl7sjc6LT0Mzi8QKECEu5/uaUjlYsqcKrpjRsAjPTmX7B0pS7PsyNUcx0YcktjOHQgE72aHDt3NFjHYlVhr50/IVpSpv4mWVB+i0ue7aMGrfs95P6Lf2c3E0x6xIXfirmX81AGk1fvRRj8rHRb+AJ2k5L0ZAVi4LoKGcxGzkx7NmS2JogsYNWJW1c+a1hC871dyKUnU5lvEe6QtYjtMGQEAz0qcJYF0cMtPYfjl8zL8r8nehQ3q7GfbqA1zKUmL9Ffc4Nb9mWu4n/9lfKIskIBHILPpCraMoANxwPfPjv3pi01lRrVpPtrM0nhqKXJzuSfPvQ== 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=ukw+F8OlFKYnXRm4ZZcGSJjFRpEEF2IriZce5z3iE4A=; b=EzrC/D0kouf+AxNWrHqechZBD68bpZygeDGhiwRgwXx1Pc1fquzQTW+LAUFCMKZqIWBHilftkIpbBOOp484J6ElgKUuFZVnVZtMhX0UB0SCrsiq6RleiQfj9LTGt8wgQRfMp+1Ua1kCLbIx/2Vi9/nF1PED7o41nK4ICcfPhtHYta8g28srFwUXBrEOBkoX3ivPB8nPccV5uJ52ME0lNfoURY0kGOJFoB0I+thI+6tEhx4y28wm2r0STdyfZMhtPBd4rPqFZeVbHIUqJBenCZUhUQfxeci0sZXXMykC8FGcwqgVjGUxCyuVm+GCwcvwKQlPpqG9u1IbM672QXMfctA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=plvision.eu; dmarc=pass action=none header.from=plvision.eu; dkim=pass header.d=plvision.eu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plvision.eu; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ukw+F8OlFKYnXRm4ZZcGSJjFRpEEF2IriZce5z3iE4A=; b=FjPNc6uF4AC5s0ynSNdkT1+5qw3lzea6KPp5GRYHrLcjz2H/ZjEk96QvMF7pYgeLHkCPS54ZvYGhgj1GHHFYtWCU4tRBOnZgWxUxseYTU3swsc39tte+CaUautOuSMWji3YISW82uQm6uPpnzKje3MamLDWr7UVBODwPmnoycc0= Received: from AM0P190MB0721.EURP190.PROD.OUTLOOK.COM (2603:10a6:208:1a0::24) by AM0P190MB0788.EURP190.PROD.OUTLOOK.COM (2603:10a6:208:198::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21; Thu, 18 Nov 2021 14:28:13 +0000 Received: from AM0P190MB0721.EURP190.PROD.OUTLOOK.COM ([fe80::51a2:f804:af89:1c51]) by AM0P190MB0721.EURP190.PROD.OUTLOOK.COM ([fe80::51a2:f804:af89:1c51%9]) with mapi id 15.20.4713.021; Thu, 18 Nov 2021 14:28:13 +0000 From: Volodymyr Mytnyk To: Vladimir Oltean CC: "netdev@vger.kernel.org" , "mickeyr@marvell.com" , Serhiy Pshyk , Taras Chornyi , Volodymyr Mytnyk , Taras Chornyi , "David S. Miller" , Jakub Kicinski , Ioana Ciornei , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH net] net: marvell: prestera: fix brige port operation Thread-Topic: [PATCH net] net: marvell: prestera: fix brige port operation Thread-Index: AQHX25fKzpoMjMiw7UirNXMLlQh9S6wH9PqAgAFWNFA= Date: Thu, 18 Nov 2021 14:28:12 +0000 Message-ID: References: <1637142232-19344-1-git-send-email-volodymyr.mytnyk@plvision.eu> <20211117171054.cupmcwwi2ruxjxuh@skbuf> In-Reply-To: <20211117171054.cupmcwwi2ruxjxuh@skbuf> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=plvision.eu; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: da381e59-e21c-4f2f-816b-08d9aa9fa72d x-ms-traffictypediagnostic: AM0P190MB0788: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: N4G+Zh50PwJKycNxa8dvGc1Bm5NP1ttMaMhM00ji/95NU4UPUJjAxJubQEMHmJWFw1lwrwLKrAhPRIPTyXQlUZzPuN/BEW9M5sZvPd2xX+EzYj4S5Fby80o+MgFXx2KhKnQ1M2dQVlV7uINj7xubDh6dGGK+DLutoLPy3ea8miyusOkHQvrVwooehvkQ+zwGUPdG7hrJ27RduvuPydAV+B10dZTScsmD/olbTquXl1NJ2u3CE7BK5LtDaBOiEUUehyusQtGcGgNU+umWux9MuS0gHXabtwinTbXDSwMJYcBtnCgi0uu+eN4iYwPvzy1fh0W4M7Jmn3lgJAS0xoa+F4s25QckMdQ3VuotvihSRXkMGuzgpHEvmOoqezwMD1Emyp3jb3qzB7vga2FWbAPj0MWY6Z+2VhugJDPE39jvDkZY9kV3JqN/nSzuqfhJL4cuu6VpphjxNLkX7MFQ5g1PRje1AH9bOaXjT2paqiVySpItygZdbpQF2uMRPOYvQryT62q2riIt7jm7kithUM5c5vNx/1H2BlvNePvkDJRXVUYoN4sDKrg4Zwgp85euBB1IrKqluD91gRTFYXq8I8KW3btb8k/sTg8H4u6YZ13lXcnU8+pU6SjHXIaGJJNkc1YIzwALe5h6JWgQ++V0VWEqBJfDlk/Tbs1IWJGSM7aF9TuLUQC21DwA9RBerdRaZb9JItYVYHGekxjAwMKrhlczfQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0P190MB0721.EURP190.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(366004)(396003)(136003)(39830400003)(376002)(346002)(186003)(44832011)(26005)(38100700002)(66446008)(8676002)(122000001)(55016002)(9686003)(86362001)(8936002)(64756008)(45080400002)(66556008)(66476007)(6506007)(33656002)(76116006)(66946007)(508600001)(71200400001)(2906002)(316002)(52536014)(83380400001)(54906003)(5660300002)(6916009)(4326008)(7696005)(38070700005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?3HpYbxfsfeWKyOMLJ/xoeKyr/BR+OO8PS80aavMMVQUl9Kf//3OWrOxX8y7f?= =?us-ascii?Q?/HxPtLhlPXS6VHsYDZthz4k0gW1tD3zOPEJf2iBfFhw6dCBlqbPMt1Bjb+tH?= =?us-ascii?Q?qfFx8hUd0FNtkk7eNv+p5//1tkj6You3GOVPMjpDk5KmLX9JMc6eSIk70mBh?= =?us-ascii?Q?1OT6vYEN3cJ4U9U41p68iLd77nhUK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=?us-ascii?Q?3qaVs7kv+im4Y3Q8Z2Y57U19LIs++089I2ncmz7ax/DkETA1HfitIcNd+4Y5?= =?us-ascii?Q?nyAhhWwWpGhLJpOpDFh9BMf5HqPELNsFWkzReUrtEZdXxP4sNyLYMoK2WPz1?= =?us-ascii?Q?An5eX100x4BrdkYGGeVzArlDSssHczSJ2rtflQyoowWH0s0/mS4VMmgumudH?= =?us-ascii?Q?6RsiGoTJzDRVfqGk/cleeMtp3OEvdrWEm411pFjn61Tw8j3n+eQa67Dk5Itp?= =?us-ascii?Q?3up0yiR3Q3/n2veyNkndNxyYlMXMO92Me/2kJpp+BYCtT/xYFHxTZlluhXPa?= =?us-ascii?Q?yq9UlRFmQJ5nd5/AKgddtYSWpddrNtQt0wwJ6kzMuZyH7b8AU3esHq6vqQaM?= =?us-ascii?Q?MLx/VSyEEu+6O69aAYXM+9u623rE+TPEWQyoQxnlA1p0nSu8KS+W8lXIyH9n?= =?us-ascii?Q?rE+7zoNf0+MXY9vyvx3I20qDAXPFTRvPI4XwQ9d5VSiBjkrJJwMKQN4g8cKX?= =?us-ascii?Q?Qkj5pOoRn8NBjqILy41rYy8znOh8mfddVaXU1aZAmubvwfcSpzT4Q5wgua0y?= =?us-ascii?Q?lzZAfxRQ/JC3mY3OfmOc/I7ehr/L4w4shxZpuENaFfAOKvqlJJLuStLOIy+J?= =?us-ascii?Q?JheSxw=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: plvision.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AM0P190MB0721.EURP190.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: da381e59-e21c-4f2f-816b-08d9aa9fa72d X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Nov 2021 14:28:12.9690 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 03707b74-30f3-46b6-a0e0-ff0a7438c9c4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: jhHoN2ZDgS6Mkn/baiLNvhIr0PMD6XdV2neGllgX9iUVSq9r7Ou0HkE1koPTu1Ov6YZAmctGi/Y1ZIRNCzDmj5zsrJz2Z7oohaBj4nRWz7U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0P190MB0788 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Wed, Nov 17, 2021 at 11:43:51AM +0200, Volodymyr Mytnyk wrote: > > From: Volodymyr Mytnyk > >=20 > > - handle SWITCHDEV_BRPORT_[UN]OFFLOADED events for > > switchdev_bridge_port_offload to avoid fail return. > > - fix error path handling in prestera_bridge_port_join to > > fix double free issue (see below). > >=20 > > Trace: > > Internal error: Oops: 96000044 [#1] SMP > > Modules linked in: prestera_pci prestera uio_pdrv_genirq > > CPU: 1 PID: 881 Comm: ip Not tainted 5.15.0 #1 > > pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=3D--) > > pc : prestera_bridge_destroy+0x2c/0xb0 [prestera] > > lr : prestera_bridge_port_join+0x2cc/0x350 [prestera] > > sp : ffff800011a1b0f0 > > ... > > x2 : ffff000109ca6c80 x1 : dead000000000100 x0 : dead000000000122 > > Call trace: > > prestera_bridge_destroy+0x2c/0xb0 [prestera] > > prestera_bridge_port_join+0x2cc/0x350 [prestera] > > prestera_netdev_port_event.constprop.0+0x3c4/0x450 [prestera] > > prestera_netdev_event_handler+0xf4/0x110 [prestera] > > raw_notifier_call_chain+0x54/0x80 > > call_netdevice_notifiers_info+0x54/0xa0 > > __netdev_upper_dev_link+0x19c/0x380 > >=20 > > Fixes: 2f5dc00f7a3e ("net: bridge: switchdev: let drivers inform which= =20 > > bridge ports are offloaded") > > Signed-off-by: Volodymyr Mytnyk > > --- > > drivers/net/ethernet/marvell/prestera/prestera_switchdev.c | 9=20 > > +++++---- > > 1 file changed, 5 insertions(+), 4 deletions(-) > >=20 > > diff --git=20 > > a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c=20 > > b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c > > index 3ce6ccd0f539..f1bc6699ec8b 100644 > > --- a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c > > +++ b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c > > @@ -497,8 +497,8 @@ int prestera_bridge_port_join(struct net_device=20 > > *br_dev, > > =20 > > br_port =3D prestera_bridge_port_add(bridge, port->dev); > > if (IS_ERR(br_port)) { > > - err =3D PTR_ERR(br_port); > > - goto err_brport_create; > > + prestera_bridge_put(bridge); > > + return PTR_ERR(br_port); > > } >=20 > Here is how the function looked _before_ my patch: >=20 > int prestera_bridge_port_join(struct net_device *br_dev, > struct prestera_port *port) > { > struct prestera_switchdev *swdev =3D port->sw->swdev; > struct prestera_bridge_port *br_port; > struct prestera_bridge *bridge; > int err; >=20 > bridge =3D prestera_bridge_by_dev(swdev, br_dev); > if (!bridge) { > bridge =3D prestera_bridge_create(swdev, br_dev); > if (IS_ERR(bridge)) > return PTR_ERR(bridge); > } >=20 > br_port =3D prestera_bridge_port_add(bridge, port->dev); > if (IS_ERR(br_port)) { > err =3D PTR_ERR(br_port); > goto err_brport_create; > } >=20 > if (bridge->vlan_enabled) > return 0; >=20 > err =3D prestera_bridge_1d_port_join(br_port); > if (err) > goto err_port_join; >=20 > return 0; >=20 > err_port_join: > prestera_bridge_port_put(br_port); > err_brport_create: > prestera_bridge_put(bridge); > return err; > } >=20 > The double free is due to the fact that prestera_bridge_port_put() calls > prestera_bridge_put() by itself too. >=20 > But the code was already buggy, for example the error path of > prestera_bridge_1d_port_join() would trigger this double free as well. > The change itself is ok (but is very poorly explained), if > prestera_bridge_port_add() fails, you want to undo just prestera_bridge_c= reate(), otherwise, prestera_bridge_port_put() will undo both prestera_brid= ge_port_add() and prestera_bridge_create(). >=20 > So the honest Fixes: tag should be: >=20 > Fixes: e1189d9a5fbe ("net: marvell: prestera: Add Switchdev driver implem= entation") Right, the double free was before. Will change this the commit tag with e11= 89d9a5fbe. Thx. >=20 > because you want this change to be backported even to stable kernels wher= e commit 2f5dc00f7a3e ("net: bridge: switchdev: let drivers inform which br= idge ports are offloaded") is not present. >=20 > > =20 > > err =3D switchdev_bridge_port_offload(br_port->dev, port->dev, NULL,= =20 > > @@ -519,8 +519,6 @@ int prestera_bridge_port_join(struct net_device *br= _dev, > > switchdev_bridge_port_unoffload(br_port->dev, NULL, NULL, NULL); > > err_switchdev_offload: > > prestera_bridge_port_put(br_port); > > -err_brport_create: > > - prestera_bridge_put(bridge); > > return err; > > } > > =20 > > @@ -1123,6 +1121,9 @@ static int prestera_switchdev_blk_event(struct no= tifier_block *unused, > > prestera_netdev_check, > > prestera_port_obj_attr_set); > > break; > > + case SWITCHDEV_BRPORT_OFFLOADED: > > + case SWITCHDEV_BRPORT_UNOFFLOADED: > > + return NOTIFY_DONE; > > default: > > err =3D -EOPNOTSUPP; >=20 > May I suggest that the root cause of the problem is that you're returning= -EOPNOTSUPP here? The switchdev events may just as well not be destined fo= r your prestera switch. You should return NOTIFY_DONE ("don't > care") for event types you don't know how to handle. Yes, I think NOTIFY_DONE can be returned by default. It makes sense to spli= t this change into two commits with their fix tag set respectively.=20 >=20 > And technically, this part of the patch should have: > Fixes: 957e2235e526 ("net: make switchdev_bridge_port_{,unoffload} loosel= y coupled with the bridge") >=20 Regards, Volodymyr