From patchwork Sun Apr 2 12:37:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197379 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 B33D0C7619A for ; Sun, 2 Apr 2023 12:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjDBMiS (ORCPT ); Sun, 2 Apr 2023 08:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjDBMiR (ORCPT ); Sun, 2 Apr 2023 08:38:17 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2073.outbound.protection.outlook.com [40.107.20.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6640086B8 for ; Sun, 2 Apr 2023 05:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gMIyynHcK0D563kiCT6n/mESpn4eJjOelU2kov7Bmb0/gZKXrOw1fsg6FGaOxSs17kUme+/j8OOVBQatGc5mySvH2JcCQ21UnYMm+aRtxMPbgYhVKx5iTozfaWiQKKsyPtYSWQWijvkN3g1N1k2owiEz8A3KmI2KloON/4wn0tDfkCWLEl9Eq1uWx5nP7dSbxLTWcClwo+uiY+g4oe/JPIamAB7k9ZzBHvTE0BhGCqRGlKbFIw6gSHbTggFNF3x+Vv4hocxQ4faF0MNFA3U2b9xoUPw9idl2RYahwMfCz83CkvM34iFiierpI3zCUJXzPnpD16YmyefpKLiosf0EEA== 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=YoRCkb0kid4Kj6peG5F9uhXdZtDhjurvqFoezPM0DU4=; b=CaowlHR24hHHuIXyXFrA5xO33A63roT1hFbw0A0IZxxTomlTqQE/0maRN9LRJ1C225L2Xgp7QaNKNEg5v+Pwl2hzpWPu13QHCO3phqGp/iak3nImau25GCrOG5Gxw49U/inyD+5nyFQn86piHZiVbLSSUuTMbPzjqflh6TROCo2LkOswv3xOdSEoQzirKdaCFu9tOKkDlUq+D0xndnjKEBJXO2Voif9m/zahB+FR9vcXlXVGOqfaBvG6oE7kMa94psAV5XccAUDxxzRkP7ZW536GVMEND4NSsC+X9C1T8mXQbhCj1q73arJkrNjBXypun9Rfcxl/XZY6LWOnli/O9g== 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=YoRCkb0kid4Kj6peG5F9uhXdZtDhjurvqFoezPM0DU4=; b=Q4YRU+cPpDSTXJVu9hQ379JeJJ9akbV1JMq7gXuOnEL1pl8hPoM758HYoc8siecv22H5x2y8UxrPmPNwTvsrrU7eMI1qtGuWz5bRuV83pbrmlgNjfc5WktpQMo7YeSeCz5AncXokk1ERUzDuMW8ehPJvl7QFxXh34gYAf/IMWbU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10052.eurprd04.prod.outlook.com (2603:10a6:800:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Sun, 2 Apr 2023 12:38:12 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Sun, 2 Apr 2023 12:38:12 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier Subject: [PATCH net-next 1/7] net: don't abuse "default" case for unknown ioctl in dev_ifsioc() Date: Sun, 2 Apr 2023 15:37:49 +0300 Message-Id: <20230402123755.2592507-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230402123755.2592507-1-vladimir.oltean@nxp.com> References: <20230402123755.2592507-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10052:EE_ X-MS-Office365-Filtering-Correlation-Id: 283b73e8-8c9c-4204-941b-08db33771dca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QbkmKZDBU4NHY6E2VC6jXzmFHeK9vWJMSaYsHa8EWV5k8maU5r7+ir6erQATEQZ5t1KV50zSewwwQsLLZqbgHRxpPFatLZkVXeQ5xAzkk/sSrfOMkzO39yZ4czbELKHSBFIAhmX+WgII74S5FGV69GPVO1RuFEJpg5p4A2Sb6xT8Et4xqBW8sielt/MF5/VLtqIPR5Ku7TanA9ZX94o8w8wEjGr3lgKRfFGnBa/RE4gKGkjzK0NmAMeFRZOEYMGsMD1nbJn0fq4aymdGcwgIlTlmWi66rKdTVGFqi11GINPkpfmDBCsQRnYXDFGTsxrBqkHaJFPPjlAUOQ0iIDF46KTDNE5YYAuxAAJ92rvvTbKOoEksXKBhCzNju3+cGR888eh02MrE69X9DVNQzdm94gB2MeQxDVNjGPlE7jeDsFS02VrLfSKn+wxBuk07EiaPuRX8WbS+uDcb7ip0oCfRgTX5Y5mevQbQyDRP/Qs4jaZzyIaRTn4SojkaIAIvP3tvAeI9pDh1Jwsre/DWDm0cYeMK4YZQ2bGV8nnKdGYUu9/FMI38antjybv9BiPOrq5ng2wDC5Tb8n3c7zVN7Tq7NKoCkBvpeDgCaE+XXoLQUfxKgQchRGcy0Y276GGZlQQG X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(396003)(136003)(376002)(366004)(346002)(451199021)(66476007)(86362001)(36756003)(83380400001)(52116002)(41300700001)(316002)(66946007)(54906003)(6486002)(4326008)(66556008)(6916009)(8676002)(478600001)(7416002)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(186003)(6506007)(6666004)(1076003)(26005)(6512007)(2616005)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SKxrg+93DfWK3dK3jnfPgOfoNmTJkBPBZDDhvsP309wto6g0ZY+zz+dg73jUx/6lYrGSiuGTFdxz351rbJ9p7N832lVoI9Z53odFYVwNcQk/TS0ym2IpDY0ZGnR4UCGjT7m/3FG2D4uvV1bNe6jlUTadDkCt+6j9Ku6j0DkL7uLmpb8ATlNR4I4YcGSrO/7nEgHPxHLcR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UBpKP9VcHLU0vuPYt5Vz7jQMMWZGl7rDYLsPttoAXycicAKZyS9NnFkWjA1MT/HbEVLIAE+qYmiVQwTASLndl4ofXXYOZDg/BRVvfRsJgVR/xM+ARd5Xu3dudzkLgdAnwwZ5wPOccaUPRQRH40OzX4TsQdB0VDG5qAu2XGp9bg86q6dFYKqKeObQ21cWW7ndPsaxq0JBLvi3hxsmiSlzO5KOnvCG3L3zdLNrY1npbFvqBD0SBGAmlPGkkCh6Bd1AggrqWA6RIBPozNT+YLkW13g+Em3ruvMfOsZhZnCQhdsMQuTu3Dz5oLyBuLsjG3TV4HxRLVjeZxmjenn1ZC6UKXDrrftePKTBIv794/bPOfPAw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 283b73e8-8c9c-4204-941b-08db33771dca X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2023 12:38:09.8966 (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: kx0H86PQRu7EHIU5s9tv4PyUKPgPQ9tdbi1SJJsqNI74guZzgx+kMzM06ehtQaO87t7szMwDQHPwRNJIVn3pcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The "switch (cmd)" block from dev_ifsioc() gained a bit too much unnecessary manual handling of "cmd" in the "default" case, starting with the private ioctls. Clean that up by using the "ellipsis" gcc extension, adding separate cases for the rest of the ioctls, and letting the default case only return -EINVAL. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- net/core/dev_ioctl.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 846669426236..1c0256ea522f 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -391,36 +391,32 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data, rtnl_lock(); return err; + case SIOCDEVPRIVATE ... SIOCDEVPRIVATE + 15: + return dev_siocdevprivate(dev, ifr, data, cmd); + case SIOCSHWTSTAMP: err = net_hwtstamp_validate(ifr); if (err) return err; fallthrough; - /* - * Unknown or private ioctl - */ - default: - if (cmd >= SIOCDEVPRIVATE && - cmd <= SIOCDEVPRIVATE + 15) - return dev_siocdevprivate(dev, ifr, data, cmd); - - if (cmd == SIOCGMIIPHY || - cmd == SIOCGMIIREG || - cmd == SIOCSMIIREG || - cmd == SIOCSHWTSTAMP || - cmd == SIOCGHWTSTAMP) { - err = dev_eth_ioctl(dev, ifr, cmd); - } else if (cmd == SIOCBONDENSLAVE || - cmd == SIOCBONDRELEASE || - cmd == SIOCBONDSETHWADDR || - cmd == SIOCBONDSLAVEINFOQUERY || - cmd == SIOCBONDINFOQUERY || - cmd == SIOCBONDCHANGEACTIVE) { - err = dev_siocbond(dev, ifr, cmd); - } else - err = -EINVAL; + case SIOCGHWTSTAMP: + case SIOCGMIIPHY: + case SIOCGMIIREG: + case SIOCSMIIREG: + return dev_eth_ioctl(dev, ifr, cmd); + + case SIOCBONDENSLAVE: + case SIOCBONDRELEASE: + case SIOCBONDSETHWADDR: + case SIOCBONDSLAVEINFOQUERY: + case SIOCBONDINFOQUERY: + case SIOCBONDCHANGEACTIVE: + return dev_siocbond(dev, ifr, cmd); + /* Unknown ioctl */ + default: + err = -EINVAL; } return err; } From patchwork Sun Apr 2 12:37:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197381 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 36473C761AF for ; Sun, 2 Apr 2023 12:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbjDBMiU (ORCPT ); Sun, 2 Apr 2023 08:38:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjDBMiS (ORCPT ); Sun, 2 Apr 2023 08:38:18 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2073.outbound.protection.outlook.com [40.107.20.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB5E93D1 for ; Sun, 2 Apr 2023 05:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZEY5fdOZ4CskLrs2G271RdOR7t1Crd6/nbXNszvciWFPcWboER7XZiLPBVJzRSTMXhmndQqkNazy0G2w59PeD/dfv+do0CskFkbgVg98O/1r0WtxS6ang5voK6aZuxXiGYuMA1zKuKdOWl+d+svasKdEtg/hHnAdQ+l4812Ggr+wBzMZUSCVDe5FmJ+BJbG3Qh94C2WyRXQ7xA+yomnzhiX4b8kiSSM7AZS/DOZayBqiB1RR3SiC0HpxtNm1eYR45U33+QjwP8US6qsf7TX4sFzLxjwAgRF0UAVJMep+XvEjh3iiM52MVQD8x0e7Y2yvBndl8D4fIcosGD0u+Wy8dQ== 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=TJKZ4jScCOD0QKMA46fdwXTSUx6h+4dMxubnj51ST+0=; b=lB1otC29A9ax1Cotz6D7O3xBgoEjf80hwrFfWGlr2Un+yg2j+s4B4YMA8DhSgeGHNdz4karBTp5FXOaO6TSgM1W6tw1ffk8pbqIpXzjaltyQhMSNRHHMS5IgmLsR7zASllGC+03oIF9e5VKJUg5Rw/3KN0ja7sW5J4o17N0Cbb+v3el7ASwF1MeTh1D6vD8TdRU/1scKUt2L41VZyGvtPf16eROY/NFI53YWqKCNcr6Ryrq93jhelATdHkgUnsu4fb9jBCznZQrAp18kQtXnu70Z94El/X0xzZ1mkhZMWNtazqmkWTOW9PGPhnRKb6iGnFYXSdbpOEN18PKEbacWkA== 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=TJKZ4jScCOD0QKMA46fdwXTSUx6h+4dMxubnj51ST+0=; b=d1YrLplAsrwVH5KQazb61PV0K4fObHD1lROqwXyvIMEVdZmcHDDazKXlFUIKZO6wvUV57BRuZz32QMhMC41Y6rTjdjfBxMhvVnjCTDZc08IBWVMlFiuepU8qkT9epnS7f0WeqqI3o3USgizmmrZ7C5iFfE1HWC+XN+ZuasnnAEM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10052.eurprd04.prod.outlook.com (2603:10a6:800:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Sun, 2 Apr 2023 12:38:12 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Sun, 2 Apr 2023 12:38:12 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier Subject: [PATCH net-next 2/7] net: simplify handling of dsa_ndo_eth_ioctl() return code Date: Sun, 2 Apr 2023 15:37:50 +0300 Message-Id: <20230402123755.2592507-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230402123755.2592507-1-vladimir.oltean@nxp.com> References: <20230402123755.2592507-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10052:EE_ X-MS-Office365-Filtering-Correlation-Id: 07b34845-d3d8-48df-3d4c-08db33771e57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iaomrOhMlA6YzOMEonMlArna5HTghAuPaL/Y5JLZSf8E8URE8lj1dqrlCxenS9lbOu0DrJHRaYSxDzae/lItAR+42JDFdaQQ9GZVDOzcUcVENUOzGS2AnANcN+6luVaHebdt4wpbYYePcexJmikBa0kULrVlNyM3QiOeJMyuaD+dfchwiHboCSdAJG5NSWmXGR8aNKXL8AY/geIBIhi+JjYUsDjALF+vN9cM/C9IPCrZ9tszlAUIgbYypfgCQQoMS7nfEUsHpk/gVJH+X+ttRNgdrhubR3uUZSdN6hemd8Gw2m7bUaiwzbwtdiqxDQM6JrD/OA/AMz0kdmM+km1nxRE/pHBo+beZgDHV4wFB+Fq6L0muE6y/y1lU3iON0eHbv1zSQpSEJ7amb03fi4bGhmviPeo3uQ1eho/GWSwPZivwaCAysbbBMgNbZjIfUysPHo9tM+MZDh9yw+nxHPe+ZVeDnM1w/+JdhJpX6zNCCJRJcQfvoAgTCnHGko4a9Q2OHt0BB0jfQlmypVuGn6HuNykKFjbpMnPfqUKhJYHHMeb3FPP0R3apiiUS9kgQQeWjTqpKcOUTNnH7tm6bQdK1+fZFiGRDbqcSByq3b3yTpMLrVJFuXFGS7jMpZEnZUb5K X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(396003)(136003)(376002)(366004)(346002)(451199021)(66476007)(86362001)(36756003)(83380400001)(52116002)(41300700001)(316002)(66946007)(54906003)(6486002)(4326008)(66556008)(6916009)(8676002)(478600001)(4744005)(7416002)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(186003)(6506007)(6666004)(1076003)(26005)(6512007)(2616005)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RnbQ0XFaWjErEqvjpjjLH9G+Bfxc4F2VJZi7i+eDr8N6Ve3gQLsT1lSo2LbaGjUiTag8cC4PoQL86/BmcOhZUWmXHAt7psHnvf7To5q8BlG5UIdHAn9Yz0k72IGlJ6EdMOg7g/UqMclrYzwbBJ/pHytkqWGd8p1KskIb22kzt19160gESYLSw6ITWOV+k2p1/PljNrr7oAUoaQT1LFqc7JpdGSBKxA2/eKSNj+R0aMsoVAE4IxXr6Lc53pkxUpQLbqfsYwc4B/2DX6syKmJFh3xyhpo0XO13MlGa3JUk7g+9Q5h4RbBa6d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EP80CGVxAOk38kBEmU40TDFCp7YwMfbU8BJ9Kn5aksvhgyvSpPSxk+UDsmqmwa0VB6TFGoJcrcmtU+laTYNsm4rF9d91F0VCuMP4IX/CZ1jFy6lpmtq4QYVESZpHU2kcud+ClWpRa7vOBkze2TrrlD4dAVP44h711lL2zTBWtqvLNUMwlUhffO6AArmXLuaMSbHFAz1R52D2qRCvJGhhtUq1Na2fI6ASwZqsKdQwVsHDzA6jUA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07b34845-d3d8-48df-3d4c-08db33771e57 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2023 12:38:10.7672 (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: zXwYLllckGF7OVIuvtBG7q5FKaWll619U6qq2batoYqJmBxcoaFnMCBDqr9OeNbZ07d3iGVKn7tDX2AFNfH59w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In the expression "x == 0 || x != -95", the term "x == 0" does not change the expression's logical value, because 0 != -95, and so, if x is 0, the expression would still be true by virtue of the second term. If x is non-zero, the expression depends on the truth value of the second term anyway. As such, the first term is redundant and can be deleted. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- net/core/dev_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 1c0256ea522f..b299fb23fcfa 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -249,7 +249,7 @@ static int dev_eth_ioctl(struct net_device *dev, int err; err = dsa_ndo_eth_ioctl(dev, ifr, cmd); - if (err == 0 || err != -EOPNOTSUPP) + if (err != -EOPNOTSUPP) return err; if (ops->ndo_eth_ioctl) { From patchwork Sun Apr 2 12:37:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197385 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 0489EC76196 for ; Sun, 2 Apr 2023 12:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbjDBMic (ORCPT ); Sun, 2 Apr 2023 08:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjDBMiU (ORCPT ); Sun, 2 Apr 2023 08:38:20 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2073.outbound.protection.outlook.com [40.107.20.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE349746 for ; Sun, 2 Apr 2023 05:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ReblW3N9It9gol1ykJIlcfioZqASJmTmdRHIqi+rRxhszSf5Y8y1dl6MD1Wzox2htQoyXPvkGXdVjFdg7u0nQWT30ieswdwHtgqOBKK3KQO6A7pGBTunCaBH8UMuK4C2FXKBPBZXR3SILiB6W98YU2Iy05QbB4F1sEDeN0GvgBDQmaGkULTh+OWnpAzCQpXUmleiAjfXRqJqEz0bwKQfVVvT1an5MibJvxHTO9E+i/FbehNvlGwVw8B1k+ZqwyD4u5Vv+2rWnVI790YPmVama8h2R7OWpFTOcphWYgWZk+1GFlze8Eg9E5AlB4jMlaHIULQByHA9YMLPjJcZr3CUlA== 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=u5i/joyYfYMmMLyMkHQ4rTnE3tBMEr+HaCBiNSVlW5I=; b=I7NeertU4RURbrC+YI2U2dQbRDwZBbqTLlS1lEWOAY4+JOxJg3TGGPhb8yadEf+7yNw4xZ7eh2DMAIjX4LMlMgMqm4Nw/6KJH4tbVXaV1F+b09cNdOJTMQmlKVzq9kLCjMjLAItdTe+sndaSdEdZVXDN/WECyAH1gypDHeIIDZ2FmuH/S94nTvwdOeMLhEqoAyZjaAdHqoH5cQbwFk7u/tVV/C6HwFtEb+8PDFQjXl8C+ysRf1Hsdrt4WMJ0IH8leczdAP9Y3nKc94KCQvCgCspKiXqyAz/v2XwQFMCMk8+ecwJz0Xg6swX9tRNCTvA/F/y7JJ3X0qTthk86T+3Spg== 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=u5i/joyYfYMmMLyMkHQ4rTnE3tBMEr+HaCBiNSVlW5I=; b=k6YqQFZaOWoHe1D/XpXF/t5FH5wUhau/7pkeiIwRNndug6lIeBwleKSRxHyqLHKTnb9ApraZzIdGQ+hWx+2Vrw4B2LQFQVqSkpuNfmw1xPZQnIN11coJEWG9hSLaIdzGXTM2ORuGsVprYKdX2DrpcxloYUCYgyK8QAvhzav4YLo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10052.eurprd04.prod.outlook.com (2603:10a6:800:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Sun, 2 Apr 2023 12:38:13 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Sun, 2 Apr 2023 12:38:13 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier Subject: [PATCH net-next 3/7] net: promote SIOCSHWTSTAMP and SIOCGHWTSTAMP ioctls to dedicated handlers Date: Sun, 2 Apr 2023 15:37:51 +0300 Message-Id: <20230402123755.2592507-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230402123755.2592507-1-vladimir.oltean@nxp.com> References: <20230402123755.2592507-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10052:EE_ X-MS-Office365-Filtering-Correlation-Id: f4d2afba-717c-4f12-bf8d-08db33771edc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nGTYVZ288te2qJJSmMaGzsXXnFxDZhgHHJc6iTqKYUm/GStsF1cGYGP4Ob0CFf7OqsEYZa8AdmyWDv0sg1NLMdEtXHUYdBLZNeSdsZeJk0AbIJdtcrv3+Vex5hR4cYNy3YLZxY5qUfToEVyId3YWl1zUXy46r0y8X4+ptGoS7mF52ZIDNFUNQpPcqgxIcV4LhH3viKd67OVlbHZFQuDtvE7Ouq8ghcuMN8M6ct5NNYXXtO2dilkrsMgVGZG6524QcEjEZKEqkS4MfvLsA6Lw9V34ABfuKmrdsqkXnSmUvHpr8LqviQ61yidHEj9GTgkYjmLw5/pJ2DA08M5c3Mwjep02ZHtsiA6ltFrIwThSh4aDlqilOMDqX9jcw81O9isDmL0U6GAZP59c0CcQvLav4zwiP7iOZzdZ6SK9vvbFcFCIIUDy+kQjf4thdXbk5FSXOM5vj12Aqlzmb9PuU/i+K/gOwwWSpEbzLaF+TbJjBlKipOkZfeS8yEfadNMF+v/VLtTBecVNSWGgW4Ggd5m+CDV99vcJRX7/Fx3v1Zork19XDTh9Gf0YAPNC2uWchdE+U+aNkJBSuN1vVIXG+i8SC575OetX0HGOUWxJQQum4I7voj+WMHGoNFVn6sxfhyg9 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(396003)(136003)(376002)(366004)(346002)(451199021)(66476007)(86362001)(36756003)(83380400001)(52116002)(41300700001)(316002)(66946007)(54906003)(6486002)(4326008)(66556008)(6916009)(8676002)(478600001)(7416002)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(186003)(6506007)(6666004)(1076003)(26005)(6512007)(2616005)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OvvP4lBtmD3Pal/+Q2s92XMT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B85zqnkARKL5hAriCbjeHVjugIU32UWmR8PSJhmCZ+r/XVrlWggI61FnqcYWiNWo2cmDMP9vl8i0gyqpdCYkZwwxOsa6cC805rFxAlh0/SCsxChM+SyQTdQhLzReGaqQ69JO2GCEg2pJj4YuO2eByz/eZo6bAR9O3Aopqd9fEBy2nDWiVkVdT5Y6DE6ZwL7N1Su1Jc2Jy1oZqzrWUuSAFJUbnmhTIUXTTF5JI46hPKbALpMmitXYEQ9eCDVJGyNzTOZ/P7Epu6ZkASuiz5WHQCdnevweMG5BUob23dyup1k6Ql2Mzwh4tiaJM5LdFVGJU8gwk3mu5ko4HguqcM8Q5FQja81iC5sueOPEalcQxjZ/mWThNlin7+mHurMALi6xeqtTWglJxxznwKBRAqwAy0TPO8RwYPJfX9oBnXguF1LgtWtQCs2PBaODfH2S5GiF2AUvovw/aDpEwAiyqOPmCAQuCvMLciZTnELuzBDyjdg0Lwqm0tqjKhTsIBAFUusQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4d2afba-717c-4f12-bf8d-08db33771edc X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2023 12:38:11.6870 (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: yLW7lDE4Lwt3Z+ToWvzDXfOHnlW01R8RtIwDUqQ+ZqhG6IpcvSCXsttlj6apyzkOSZQkVVELbyaP1Qv0t6JvCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org DSA does not want to intercept all ioctls handled by dev_eth_ioctl(), only SIOCSHWTSTAMP. This can be seen from commit f685e609a301 ("net: dsa: Deny PTP on master if switch supports it"). However, the way in which the dsa_ndo_eth_ioctl() is called would suggest otherwise. Split the handling of SIOCSHWTSTAMP and SIOCGHWTSTAMP ioctls into separate case statements of dev_ifsioc(), and make each one call its own sub-function. This also removes the dsa_ndo_eth_ioctl() call from dev_eth_ioctl(), which from now on exclusively handles PHY ioctls. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- net/core/dev_ioctl.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index b299fb23fcfa..3b1402f6897c 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -246,20 +246,34 @@ static int dev_eth_ioctl(struct net_device *dev, struct ifreq *ifr, unsigned int cmd) { const struct net_device_ops *ops = dev->netdev_ops; + + if (!ops->ndo_eth_ioctl) + return -EOPNOTSUPP; + + if (!netif_device_present(dev)) + return -ENODEV; + + return ops->ndo_eth_ioctl(dev, ifr, cmd); +} + +static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) +{ + return dev_eth_ioctl(dev, ifr, SIOCGHWTSTAMP); +} + +static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) +{ int err; - err = dsa_ndo_eth_ioctl(dev, ifr, cmd); - if (err != -EOPNOTSUPP) + err = net_hwtstamp_validate(ifr); + if (err) return err; - if (ops->ndo_eth_ioctl) { - if (netif_device_present(dev)) - err = ops->ndo_eth_ioctl(dev, ifr, cmd); - else - err = -ENODEV; - } + err = dsa_ndo_eth_ioctl(dev, ifr, SIOCSHWTSTAMP); + if (err != -EOPNOTSUPP) + return err; - return err; + return dev_eth_ioctl(dev, ifr, SIOCSHWTSTAMP); } static int dev_siocbond(struct net_device *dev, @@ -395,12 +409,11 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data, return dev_siocdevprivate(dev, ifr, data, cmd); case SIOCSHWTSTAMP: - err = net_hwtstamp_validate(ifr); - if (err) - return err; - fallthrough; + return dev_set_hwtstamp(dev, ifr); case SIOCGHWTSTAMP: + return dev_get_hwtstamp(dev, ifr); + case SIOCGMIIPHY: case SIOCGMIIREG: case SIOCSMIIREG: From patchwork Sun Apr 2 12:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197382 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 46D8FC77B62 for ; Sun, 2 Apr 2023 12:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjDBMiZ (ORCPT ); Sun, 2 Apr 2023 08:38:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230200AbjDBMiU (ORCPT ); Sun, 2 Apr 2023 08:38:20 -0400 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2071.outbound.protection.outlook.com [40.107.247.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C8889740 for ; Sun, 2 Apr 2023 05:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NiffzvOWmTy5DKF3ezNoFTuToIV3du2urA+fg2ZbNh9ytp/U/JThJr7nuaeDMDCNyO3vRutvq+Ta7SDg19vkcB0iO6yEyTXGD/tLTZKcYMHzag3XNIu3zhL8RacXDCE26Yu9MxSFQSXgNAW5tCjzpdr4rzG4cqWW3I5sKFTHkISYfi41D12o5yrimhOYGN5wAp+C4YJ4fFYWim5mFcyLpXQE9sJXb2F6iYsHSCtvjNlaHwsDPoKIhv6ojUN0oPlCAlFaLy1Vii6ieq1CTGrBui3p2ukEarU+APbdl7uaPg5guzx7QcDnQtqwpMp4aMthkgOGXFEHuQ+of3jf2j2dnQ== 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=yAtuOgQZ8gP2z4Snp06w4GyQSc6lSb0Hyo7pkzukcEc=; b=I/2VYBhbyiodnZ3GBAUm1Is5e6bAXuvU7T+VwJT+BiYNuZtETmAvc5YyCNkx/689T0qxnyvXOrr5ajW2GBHOjtKL8we1G5q7RIHWPHo2eorq6w+0MPKw/9wR5mRZa0vx0EOR+cS3lTw3qRh4rCK21STeOyEA2kJ2xA04jl79x/zJjMPzYWEr0lViWEdswRFYh+Jw36WATzYTNrLE6gaLTL59zbPh1Nd04wK20x93frESuP6c2JN1twAy8eB6Sf7JErZhMNZQf25mEPf7eeMEXK3CN9FQcL4LpdmosGHQl9StvO7z8OJOfCx7WXcBsAAiZx3sFuhk7MqrutMrXThBAQ== 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=yAtuOgQZ8gP2z4Snp06w4GyQSc6lSb0Hyo7pkzukcEc=; b=n0PQg6OdSe6wWzW6g/WBLgEqieh6tNwc88SE4KGBjFmT90zE0YFjc9r75VwXMrd08IvPOW0LNTkpSZZe3wPi5Sb47P9a+u7TUIXITiimgT/XBepagjKXLj8rjgFb7EpaCIlQ2aeYuMdRI0C5NfKKKY8UK0S017yRXpDYvjJbLR0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10052.eurprd04.prod.outlook.com (2603:10a6:800:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Sun, 2 Apr 2023 12:38:13 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Sun, 2 Apr 2023 12:38:13 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier Subject: [PATCH net-next 4/7] net: move copy_from_user() out of net_hwtstamp_validate() Date: Sun, 2 Apr 2023 15:37:52 +0300 Message-Id: <20230402123755.2592507-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230402123755.2592507-1-vladimir.oltean@nxp.com> References: <20230402123755.2592507-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10052:EE_ X-MS-Office365-Filtering-Correlation-Id: 9d8f6762-e374-4162-cb1d-08db33771f6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EhgejxNzoFA1Yb3cUzH2hWIZ5USznIsjwdKlsYznX3rNS4M2yEhZMA6R++8Ps47YFsgsTkb1J9U9R39ZPTL3hUMwwnSofc+VhdV2WOydbmi1VzcKkKXzs08QcMORDV/6SM9MTz6xgHpqafCqTJEu9zPhvF7RbVuMP1EnJ1mu9Fz4+leDGVIUprkkCG6+UBbaWwe2FVolrtntMy6yWsFzkLbEV4BIBa4TtpszdWQOzQNLmynNmTm25pH80FkHLgZwUbZDo+5YxOCPx4GGjjcijIdTT4wHpc6oI3SAjMhw4ilUK8AKc1/+/C9k6AmAxkZ14TMWWsczAoM+3EnRKrnwHQygRydvFVn1S/LPVVAmBtjPi0WhfRoRSHwMJHGPsbhcYxjq3H7GoLiwSmmq9y66+RLNjm/MF5CN9FMPmKPTVC7gCQXSh6t41FrvV44uG4vEQeBN5DzZqcZTZO/TNe+dFHlrAXuuoKEXel1tMA9b/KD4thlkFaciuuE+wCDcSCU2xv/s+Z4dnaYVbDetBDrIhr5hOgX9YF3rZqfZ1W02dOqX22dQFcD+VQRMvDrNeTjAjmOJuIFEJmnUSUpF8qjBkgncuqJP4sw+FkNmuZ5a/dURgK+o7/XXYyhPSi47iVEr X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(396003)(136003)(376002)(366004)(346002)(451199021)(66476007)(86362001)(36756003)(83380400001)(52116002)(41300700001)(316002)(66946007)(54906003)(6486002)(4326008)(66556008)(6916009)(8676002)(478600001)(7416002)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(186003)(6506007)(6666004)(1076003)(26005)(6512007)(2616005)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jTFk0so2920Af9cOx3rKw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8yBHEgHh1vq3bIHpOl4yMrlFQ6D1VXInjWA60XI9HTdPL3cvBaDbc2ZI0cWE0kp1Pq48fXBgGleM/GggOmoiepcsAf2WbbodjFTdpyDLZrlYmLhprWpucOug2xfbKjYfai9QA4E8FlhSBaNWaHZG/ciwP+9nKGgTzUeaJne6qbsqVW/kqp/MdMju/QuQC8h8kc20xJQI2fBkgOde1lnWyAOSHsBIjwE8pbloz7AT+JfyZ5Kn5HDJ1BvItWOUGOLD+bPyubpfw/sT+YzqPZsI6+leneQsWAw/+wqFUXnYWw8ljF09aBTCvKQ/eug5EMeWixPwhfCjc9eNtflRfuYBAmhHdypuyPlSSo8gaI67YZUCyG6U0QPYWqhcIruNTqClG4JscXQLw59Xtse9gNxe0H74CRaoKbI5TC1Ml0aKARysl90JMDKMM3rZqPcgvSmXrG3XYmfl3vhpHhGhKk1S3gYwY8J528Y0xt/Zgtaya2Ub4j+4WJPaQhohRNxZfDOX/nOeJF7A== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d8f6762-e374-4162-cb1d-08db33771f6b X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2023 12:38:12.5978 (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: dF1zFcNgi3uHWNK05O0eBTeC5QQGvYpuABqHL47BAkmaYmV8pJtzRhAIVZ0C8+zNSX9mjGs/6UY/lw32slMh3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The kernel will want to start using the more meaningful struct hwtstamp_config pointer in more places, so move the copy_from_user() at the beginning of dev_set_hwtstamp() in order to get to that, and pass this argument to net_hwtstamp_validate(). Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- net/core/dev_ioctl.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 3b1402f6897c..34a0da5fbcfc 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -183,22 +183,18 @@ static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cm return err; } -static int net_hwtstamp_validate(struct ifreq *ifr) +static int net_hwtstamp_validate(const struct hwtstamp_config *cfg) { - struct hwtstamp_config cfg; enum hwtstamp_tx_types tx_type; enum hwtstamp_rx_filters rx_filter; int tx_type_valid = 0; int rx_filter_valid = 0; - if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) - return -EFAULT; - - if (cfg.flags & ~HWTSTAMP_FLAG_MASK) + if (cfg->flags & ~HWTSTAMP_FLAG_MASK) return -EINVAL; - tx_type = cfg.tx_type; - rx_filter = cfg.rx_filter; + tx_type = cfg->tx_type; + rx_filter = cfg->rx_filter; switch (tx_type) { case HWTSTAMP_TX_OFF: @@ -263,9 +259,13 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) { + struct hwtstamp_config cfg; int err; - err = net_hwtstamp_validate(ifr); + if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) + return -EFAULT; + + err = net_hwtstamp_validate(&cfg); if (err) return err; From patchwork Sun Apr 2 12:37:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197383 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 080E3C76196 for ; Sun, 2 Apr 2023 12:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbjDBMi2 (ORCPT ); Sun, 2 Apr 2023 08:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230225AbjDBMiW (ORCPT ); Sun, 2 Apr 2023 08:38:22 -0400 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2071.outbound.protection.outlook.com [40.107.247.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E787686B8 for ; Sun, 2 Apr 2023 05:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n4qXoneJSmV7LEqsjsQkE67ipbur3Gcr7zq5p8rrL/11DhFaLMEiorKfHwV8d9Rp1aj0hZcycbZ57erVeG6yE94sNXE7qV/S1pWJF2AJe3xGKZVdnm0S8x0aWOivWBe4WrJM6Zpo+jLkfB7LmTnP1yWrzXg4bVdLj+n3pSVgndL12BBNFyW2mlx2x4IVkVj3GwrsYXlSe9hv7sdXK1VXckJMKdP+XwJtBTmbJRDgzC8FLWIjy8lScwQ7mEFgi8CFbwLjU1GZZ0w2eWyTDkhymZ2SQfy7rP8b+LgE0H82at3ulDQZtpwgZyr0nd5dL/p5G4/lOU+byh5A+HwyNV4Shw== 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=HAhilcWHRxdfbLLXmeHgRlfEUm6xL+cotOezIssLQT0=; b=PKjOy7RiWTURbpVVvm0Qag/hiMDYhZTnOchghjWilDXYZRAfLc0XRBx2zc0UYeGFiIbdqiKXRooK/5qLxNVaqt174vOr50EChvFL2UbEh4PwP/G7ySjRv6YRhfy++QZpQxPxlfSCwfm5/dlfULh+Xe8F0R3zxu+03YKhOC4fgelDCEhHYN1m4hShdCcoPOZaONx34rwjrWRxd4Vqyid4qgAl9MoSnRppnALf2simnQLwLiM14vt0iBrDdBsc1nZKdtzmk9k5g1jkvPhKo9EJ+EyIU8Hb5GUr7FSLS0KWB0TwxJmu16Z3ANqv8DxhdXxgLGvbUwlb2sUMh0DQbSpmCw== 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=HAhilcWHRxdfbLLXmeHgRlfEUm6xL+cotOezIssLQT0=; b=nosbxF4TKh+9dXss2YoWN/sei6jnqr6j/KEXysUYi4Ehm8d8bvuSbDsL+lLMeGy47LVjPwDFuqPQWj5CV3kr/phEZOx41giUjGxwKhanV7hEC56SnEOzM4GogzsKaL23MZ17sHjW0TTR6kKvtxCokpJ7yyh0h0iHz6PGTqobeLE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10052.eurprd04.prod.outlook.com (2603:10a6:800:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Sun, 2 Apr 2023 12:38:13 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Sun, 2 Apr 2023 12:38:13 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier Subject: [PATCH net-next 5/7] net: add struct kernel_hwtstamp_config and make net_hwtstamp_validate() use it Date: Sun, 2 Apr 2023 15:37:53 +0300 Message-Id: <20230402123755.2592507-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230402123755.2592507-1-vladimir.oltean@nxp.com> References: <20230402123755.2592507-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10052:EE_ X-MS-Office365-Filtering-Correlation-Id: ed014770-67f7-41fa-afb1-08db33771ff3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UGYixuRfTHNQjun9flqWGGWkeKm1AD2am8yXwUCd/NYMCkh3RV8uOruc9PIH5382TOonOHIIajB9Mi2UopszTYeiRb90QLmn3EZ9sEh5HMa+K3ecIcTrXecC5lAi3LkIkb0EwlF1q51Pu8QVpdo8kWjmeEMKC+4QWRkO3Y2QNAcOeycxQk4zlx4Zo9NJ2BvD04VLpR8kniEOBUB7tGrItRdTD1dP039tpalk8E5YCJyTn5bVW5TBn6J9/1g4Xwu2szfWhsP0OCa9w4a6t0sf72zeNsdVsoSVt7OjmB6vJLgsp/63yKu57HppAMMmb/vn1KZGaNuxZ+jtnR3ykbKOLGQ20aPgvQXfJNF8vxLEpJ5AHYb1B0XoEIwhaqQbkyROcP0uIIlqdghwSp8t8rbW0rp3z7qsziPzPrdk1zvkwVLCqPYNkIcNN/xFltbvtX8qfFxmuAMMzIrX97qLQIgvcriiE4K6WlhLxShWrbkh9t/vAKVOpqeh2S31bxP7HftXeqAvsUtnKYDpZwdFtIWDN3TxuLFU3aNOzFF6WP8FWurspxMQC/2NmhXwvsN8SlqCnPppkuPwE5kJ1sktKztS42HrjnK9hSD9SjDxgn9uW4V+RRXI9R+OG1NiY44YRUsk X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(396003)(136003)(376002)(366004)(346002)(451199021)(66476007)(86362001)(36756003)(83380400001)(52116002)(41300700001)(316002)(66946007)(54906003)(6486002)(966005)(4326008)(66556008)(6916009)(8676002)(478600001)(7416002)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(186003)(6506007)(6666004)(1076003)(26005)(6512007)(2616005)(8936002)(134885004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GO1/JFIQq+VOXD6HVVDjr9iT3bYjgpQ9qeteapYnVR8ZowazsCcBVZUT0rqN4WVjFASqEgkDduvvsitY2BqAvJWUKi9JaeTl5HA+FsKoru9yWlBiFA5mi9LlG0UrYc2ScolOs2xo2vQ6w3ZXVjuRAYtGaJjTNgSWj65xvr/bTgK2Sp5Qn6T4vDFxFtoJD0Z5jnSiQreHRV0VCdQ+URh1ucVvIQwXkHzyzyaKtdUbNEQNEkt+HoWH3ihbAO5srUApmRA4nPY6yovlfdPnTVllIHpM2Y4tJSieTCebmd6+E29k3BX1sPlDPgTLs71DpkI44ltETffBI6H8wOPQUelSPZUL+url1pVK54h5JnMVqdeDnuNuoMC27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XVRmwsDdJVjj7ueWVNVI/pdM4wudHCcZ1jXsJsqqFI9IjKH79BPnPYewSc3TFKzrZ6xPpcGoc2O+vcRb1HrA8CojvPCXlx85c6Nmis2Om+H9TNO5JvuQ3pkrkpm+7GYye1lHdvcGilscMV3o/JkEUCci5LTLgFsHNt2GvCQ8g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed014770-67f7-41fa-afb1-08db33771ff3 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2023 12:38:13.5328 (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: HwL0htoKVTWp3oQmSHnU0oir8iQdDoRv0uXga7YUwDdyw4ERNETvjH7ttz+f8r5gxkDykDBqS7m8FE+Urml9Wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Jakub Kicinski suggested that we may want to add new UAPI for controlling hardware timestamping through netlink in the future, and in that case, we will be limited to the struct hwtstamp_config that is currently passed in fixed binary format through the SIOCGHWTSTAMP and SIOCSHWTSTAMP ioctls. It would be good if new kernel code already started operating on an extensible kernel variant of that structure, similar in concept to struct kernel_ethtool_coalesce vs struct ethtool_coalesce. Since struct hwtstamp_config is in include/uapi/linux/net_tstamp.h, here we introduce include/linux/net_tstamp.h which shadows that other header, but also includes it, so that existing includers of this header work as before. In addition to that, we add the definition for the kernel-only structure, and a helper which translates all fields by manual copying. I am doing a manual copy in order to not force the alignment (or type) of the fields of struct kernel_hwtstamp_config to be the same as of struct hwtstamp_config, even though now, they are the same. Link: https://lore.kernel.org/netdev/20230330223519.36ce7d23@kernel.org/ Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- include/linux/net_tstamp.h | 33 +++++++++++++++++++++++++++++++++ net/core/dev_ioctl.c | 7 +++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 include/linux/net_tstamp.h diff --git a/include/linux/net_tstamp.h b/include/linux/net_tstamp.h new file mode 100644 index 000000000000..fd67f3cc0c4b --- /dev/null +++ b/include/linux/net_tstamp.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_NET_TIMESTAMPING_H_ +#define _LINUX_NET_TIMESTAMPING_H_ + +#include + +/** + * struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config + * + * @flags: see struct hwtstamp_config + * @tx_type: see struct hwtstamp_config + * @rx_filter: see struct hwtstamp_config + * + * Prefer using this structure for in-kernel processing of hardware + * timestamping configuration, over the inextensible struct hwtstamp_config + * exposed to the %SIOCGHWTSTAMP and %SIOCSHWTSTAMP ioctl UAPI. + */ +struct kernel_hwtstamp_config { + int flags; + int tx_type; + int rx_filter; +}; + +static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg, + const struct hwtstamp_config *cfg) +{ + kernel_cfg->flags = cfg->flags; + kernel_cfg->tx_type = cfg->tx_type; + kernel_cfg->rx_filter = cfg->rx_filter; +} + +#endif /* _LINUX_NET_TIMESTAMPING_H_ */ diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index 34a0da5fbcfc..c532ef4d5dff 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -183,7 +183,7 @@ static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cm return err; } -static int net_hwtstamp_validate(const struct hwtstamp_config *cfg) +static int net_hwtstamp_validate(const struct kernel_hwtstamp_config *cfg) { enum hwtstamp_tx_types tx_type; enum hwtstamp_rx_filters rx_filter; @@ -259,13 +259,16 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) { + struct kernel_hwtstamp_config kernel_cfg; struct hwtstamp_config cfg; int err; if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) return -EFAULT; - err = net_hwtstamp_validate(&cfg); + hwtstamp_config_to_kernel(&kernel_cfg, &cfg); + + err = net_hwtstamp_validate(&kernel_cfg); if (err) return err; From patchwork Sun Apr 2 12:37:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197384 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 2910AC761AF for ; Sun, 2 Apr 2023 12:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230225AbjDBMia (ORCPT ); Sun, 2 Apr 2023 08:38:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230245AbjDBMiW (ORCPT ); Sun, 2 Apr 2023 08:38:22 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2073.outbound.protection.outlook.com [40.107.20.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0232D93D1 for ; Sun, 2 Apr 2023 05:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Aq4gxwSRDKUTjy6TrH562GdwpFyl9n/IXXXd8JeWjoPaFZoqirZZjjIkpLdWxE8T9qgB4bHrXRLVO0BQ9q0/VYmhU9140dlrRsNA533e43IVXSZPweMtuAI9gsypyeoN0FU2IhGcM+Q1XwlPbAPSvy4aObEh5i061DFrIXCCd5wCF28XkEqaHIqJNUR/cETRkKq7kJQNIPPyu8+8mGa8WH3rpAdVwOs+tX/ml9MaIN0ZY8frcwLXojCW8KwKZ7D40dvTHvMjPUhG69Y5U/1vAWBryLGPBvu6+b8qhCdpxTJuJjqOSanzhgYcf37cWwW5WVJiJLvaPFdcwKk/l5rAPw== 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=eL+cB0v/0Xkp/smxgdxzoKE4eevSxBe37gUKT5xBW6s=; b=jGnJTeiccx2UUkfubVBXVFoKZ3r9XujR6uhH1xGujp3lmxNRAMw22cxaxg4Lm5rUF5dq2NCi3WnpVRrl4MvdkdW2l8k1YAH6KCfLpRIbxp1gStcdQlrQtp/0ZQwurqu/O7CDLODXWbgU0uhcgGIaZO/F8NvQx8A/uSRE3uIGJRBRab5SvbsIe9wsoVZyaz9at9HoS7gptVdR4pGo8XPaLqL5JQou40qBQ6JUV2dHLjnXI3wZstXbaiFnxZjQlgt6EcxjI0D0ia3j6kLrLpM9idbPm+pRFGHJhQ4NmxN9EAroQ+l0zZ0pZJiUy8EktnzFFlu9JYuWV8C8eFzftzr1RA== 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=eL+cB0v/0Xkp/smxgdxzoKE4eevSxBe37gUKT5xBW6s=; b=ZbJKx18kSBds8lX4OBkPpjKcrKiXS1AqA1w9m7ejr+iTpPUH2R6/pRbabxmM6Px+bjBnsiZ+gSKVcvjq/XIu1cPaIuzgZ4CncZKOuRkbu6bzfnC3hU4MIiIZRuX4VFDoC4SIJ2WaC3sRcoTpWI61f7btHmx8jm/zz25wibcCcCc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10052.eurprd04.prod.outlook.com (2603:10a6:800:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Sun, 2 Apr 2023 12:38:14 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Sun, 2 Apr 2023 12:38:14 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier Subject: [PATCH net-next 6/7] net: dsa: make dsa_port_supports_hwtstamp() construct a fake ifreq Date: Sun, 2 Apr 2023 15:37:54 +0300 Message-Id: <20230402123755.2592507-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230402123755.2592507-1-vladimir.oltean@nxp.com> References: <20230402123755.2592507-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10052:EE_ X-MS-Office365-Filtering-Correlation-Id: 3268e623-e5fd-4f1a-1da1-08db33772085 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k2RvZoYo2s5mHS+mHT9MGx/54BB/w/0bvMrB1G2XLTBN84oOI4K1YexK+5eyezlICcZxJVUfRW8iAv6SI+kPs+lGJdTvPlcmp39VZMwFfaSFlnea0RO+K8shg5EOj9Xc54snGNPIHhSjbt2wmr6pQKPIroAKBAPPJentn3GUbdxX89Fqem2uveetjBZkoW4t3KW9RFovJLz39appmF2JyMrQeohUSyAv9vZ3QwtbcTcHV/oJVWV/+CZGjkRRJkB2vBbFdnp6jRsyYXdhDiGoqoWEvINlVetHUp2xMA7Y65iH+NBGzmBnZ5p/kQzdnb7DAgFJt1QA7NkkCkphc7X/V4IQ5lt4WVsu/dR8PT+rbC5Cqx/nWjQbqHYTTlX5kNPOh9DlxFnnGa85tSWK9XYSS5e0Ahh6vdLwYdq2EtuRpOrAyw/5dPLwddngP2SLlj9fwzpmEpQ/7YlGclqRQ52a+RVfPnkvUKJFaZkij3niQJO3DMqr5zEe5uE059zvva9NIUglnZYdyv/AuSFxuXw1HQGuYh+OVqG6RSkna55J6oLGJfDneArxmHHe9slquTyE8Gi6te63QhfYlE6hXNscKkRYrQOS6N3BmYOPjFEVIu9ZKS4XXAt9PVH04d4XkBHD X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(396003)(136003)(376002)(366004)(346002)(451199021)(66476007)(86362001)(36756003)(83380400001)(52116002)(41300700001)(316002)(66946007)(54906003)(6486002)(4326008)(66556008)(6916009)(8676002)(478600001)(7416002)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(186003)(6506007)(6666004)(1076003)(26005)(6512007)(2616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w2p89+8bg4BhDKSvYZGIQq/QhPJ2jOde86KngMffWEhZHfwtB5vS/yC8l7fYa5fQID7XDl1a/cfGs/MmG6c2fnVN+JQ8hYj3ede9QMtuKLaVkWs7VXwmjoHlh3wrSqmu5Wr3aXb6FteUNKFtabmQycCQxevVqQ8s5DNkIY5Gn1axJWtTx/4oAYm9jf+p6Sp5LX5IR74KB7GZrwI6o5Dv44zgdawLMP0Ux8At/ahtEy00I1HS646k10iVQsafJ45EsUgx0a3KA3ufstMiTU1BxrRsu732bL5NgKebykSjgjX3zphxoVymMv1AndUXwRggE33y2HIjElISaVNzbF6pLrQU/x1JG9Pr4DBnvMJf/J+DNIiTf6/WNMSALbJgr9dZDSZ7k77y1fHFElf6/2O5wMSPtojpUiTYSNMspHKKWExMyfGXIYfS1B4f5Q1YSKt5m21hOiXTi4avEHMhrUSE4GMujLaMD+dwDaAsGY3Jfi8ZPzshuC5MwBfZEffo/u5kurMwpjXD325iWI8mXl2u5NjJPA5KxoXRuU0fNV/ACJYlfO9uf76UVh1o38iOZtI9me6MSLyP4t18mEZkhIgRzlzNRm8j0netDsxes4Lo6eA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3268e623-e5fd-4f1a-1da1-08db33772085 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2023 12:38:14.4365 (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: EXy5+lYznoTqp/d/rpyN/1NikJh8owuxOduY0LbY69tNXL3aLI8a/WJokHjad09vlaWXaE9uEDKZLfFSzpTiFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org dsa_master_ioctl() is in the process of getting converted to a different API, where we won't have access to a struct ifreq * anymore, but rather, to a struct kernel_hwtstamp_config. Since ds->ops->port_hwtstamp_get() still uses struct ifreq *, this creates a difficult situation where we have to make up such a dummy pointer. The conversion is a bit messy, because it forces a "good" implementation of ds->ops->port_hwtstamp_get() to return -EFAULT in copy_to_user() because of the NULL ifr->ifr_data pointer. However, it works, and it is only a transient step until ds->ops->port_hwtstamp_get() gets converted to the new API which passes struct kernel_hwtstamp_config and does not call copy_to_user(). Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- net/dsa/master.c | 2 +- net/dsa/port.c | 10 ++++++---- net/dsa/port.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/net/dsa/master.c b/net/dsa/master.c index 22d3f16b0e6d..e397641382ca 100644 --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -212,7 +212,7 @@ static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) * switch in the tree that is PTP capable. */ list_for_each_entry(dp, &dst->ports, list) - if (dsa_port_supports_hwtstamp(dp, ifr)) + if (dsa_port_supports_hwtstamp(dp)) return -EBUSY; break; } diff --git a/net/dsa/port.c b/net/dsa/port.c index 15cee17769e9..71ba30538411 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -114,19 +114,21 @@ static bool dsa_port_can_configure_learning(struct dsa_port *dp) return !err; } -bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr) +bool dsa_port_supports_hwtstamp(struct dsa_port *dp) { struct dsa_switch *ds = dp->ds; + struct ifreq ifr = {}; int err; if (!ds->ops->port_hwtstamp_get || !ds->ops->port_hwtstamp_set) return false; /* "See through" shim implementations of the "get" method. - * This will clobber the ifreq structure, but we will either return an - * error, or the master will overwrite it with proper values. + * Since we can't cook up a complete ioctl request structure, this will + * fail in copy_to_user() with -EFAULT, which hopefully is enough to + * detect a valid implementation. */ - err = ds->ops->port_hwtstamp_get(ds, dp->index, ifr); + err = ds->ops->port_hwtstamp_get(ds, dp->index, &ifr); return err != -EOPNOTSUPP; } diff --git a/net/dsa/port.h b/net/dsa/port.h index 9c218660d223..dc812512fd0e 100644 --- a/net/dsa/port.h +++ b/net/dsa/port.h @@ -15,7 +15,7 @@ struct switchdev_obj_port_mdb; struct switchdev_vlan_msti; struct phy_device; -bool dsa_port_supports_hwtstamp(struct dsa_port *dp, struct ifreq *ifr); +bool dsa_port_supports_hwtstamp(struct dsa_port *dp); void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, const struct dsa_device_ops *tag_ops); int dsa_port_set_state(struct dsa_port *dp, u8 state, bool do_fast_age); From patchwork Sun Apr 2 12:37:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197386 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 20F91C761AF for ; Sun, 2 Apr 2023 12:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230350AbjDBMie (ORCPT ); Sun, 2 Apr 2023 08:38:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjDBMiY (ORCPT ); Sun, 2 Apr 2023 08:38:24 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2073.outbound.protection.outlook.com [40.107.20.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71CEF1B368 for ; Sun, 2 Apr 2023 05:38:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b/2pFjBrlr9Wv9wv2tn7xeTVRTo2yMpHikxGSr4jTpoeJRNEe1s0DvWLMVfr/KXt+q0pbelxJ5HtEZp7yMhOvZwidXyfK8gKRH2uZFD+CsImP8fhFQM0q+60O2kkHnmYBBIYdLIvFpC6sQL7FhfaKpopHj3clZ/s7YzaqN6sY7WHdmbASO8bbwebOF6QC8OeifCfP4K/mmQW6W64cF0gVZhnutTMud/eKLgUnxsdxGDzk2IVy+/Xlr5D1OmRYmsCK3w0n9FlyhXpEY/N8mxBDq0gpW9qMcqypdjZxSK8N+U2Xk+qg+9oJQTc0JQBCrrIqI7i+vLCYYHBuD0GGCr+mQ== 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=9Fje+wdwt/MLubd8R3uVtOO49MpN5KL/YruQyK+mjHA=; b=h6pUPQ6d7VYD0vzlmTTlBWwaSJOk9X34aFFaBghCAMYpKasAjLrx6t5xagXAUidg2X982kQOzEWfxt+9ES047toOc4WZaOnqeLHfEmaUwm9U1zr6J6JqbIWsWhssNrnjrWxAU7xWfqFCFnsWjBQvNkZ+28I0jykG84DNC4izxgZHcfGyUeahO+FuX26ikfPt6aiF5B4NdwhrBgL5JvRedVFcjeAxGhh7gAomsxc6eXeXmgjwUB9hCgreQnaxluPGwJsUjbkK9MgeIC2qbeD/onnN0L002Wgf7YVyrU+girVkgIxBAEtPqRm58um9VNQmBCtru/Qk4QNAloWPk58t8g== 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=9Fje+wdwt/MLubd8R3uVtOO49MpN5KL/YruQyK+mjHA=; b=huSXMCk7n/8chET1dt8NJ0zBK2JqkeHQOHBZtd24EejLi06o3zcwkqzSuaPO0Fgt6wrCrMkHXgLlazClRPevKtQnmZPnzB4eUVi470IEQ2ZMiMoqXihiZadb/Btf+xaoNdOKzhVMJVcdv2fgjFHgIN/qIIf9OEzrcNAWB0E0raU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by VI1PR04MB10052.eurprd04.prod.outlook.com (2603:10a6:800:1db::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.28; Sun, 2 Apr 2023 12:38:15 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Sun, 2 Apr 2023 12:38:15 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Florian Fainelli , Maxim Georgiev , Horatiu Vultur , =?utf-8?q?K=C3=B6ry_Maincent?= , Maxime Chevallier Subject: [PATCH net-next 7/7] net: create a netdev notifier for DSA to reject PTP on DSA master Date: Sun, 2 Apr 2023 15:37:55 +0300 Message-Id: <20230402123755.2592507-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230402123755.2592507-1-vladimir.oltean@nxp.com> References: <20230402123755.2592507-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR2P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a::28) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|VI1PR04MB10052:EE_ X-MS-Office365-Filtering-Correlation-Id: e8d82cd6-64d7-485d-8b66-08db33772116 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q8tJ9/7C9Avy1fWfvg8GFSFxCOLiSS2LQNG14URI/cRFDWRXgsA5AVoepwiGOEtKVGHBu3audprUGlAzK4JjxNc7Rre4F6PnpHvzyb4M4bZM5TlpHy1IJEb5giZ5hjPwtx2a8ncrowFax5RPBn2mLAGbYmAUnLQKetuA/TRlL+qQmRCVaNESt48M0DsXR/nMKK9gxpDyVQdnVtxniKA3X18dImKiIOQEXbKKlhTOrp/SGAI0+H+R9UJmjro8ASgTw4lHnA20yjDZj08d/9rtJyXON3usGMtZLOBCzsKWpM7yOKvbYepVIZRHTx2i7iW+DWlF42+FbCwuvyx/7H6wZyWK2tZKXIcw/mZhpVS7iPOlQnxM4cAZu0AmUVMCificBBADDL7IRa++9DQtfbhjvZl9oWsYY3MhZWYJC0TTT6Vzn5eEU3bFVIy1lPkCQHlazmLrqpKgkqV+AEZdfc0hkAXiRyR+iZPMCaG3GcBFtmwaolf4WYr0kuH/MpIL6fqqJ/36ljigR6bK3aMSnIRv7gO6rFLvyNJzdLacdN4yN+PXGqrplk9HFA7QvJUEetdxFmJWjwQzklirLehgbIZsXHihv8tzVf06Q9Zjikc/vnBjH3a0wvIcET8l+NO7Nfgl21QdRIW8M/wLVuSSDhNy3A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39850400004)(396003)(136003)(376002)(366004)(346002)(451199021)(66476007)(86362001)(36756003)(83380400001)(52116002)(41300700001)(316002)(66946007)(54906003)(6486002)(966005)(4326008)(66556008)(6916009)(8676002)(478600001)(7416002)(30864003)(5660300002)(44832011)(2906002)(38100700002)(38350700002)(186003)(6506007)(6666004)(1076003)(26005)(6512007)(2616005)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4uwFmgRM2Sz+Yk62uTlhQRIer6R7JGtJXhWkpMmuOUwtXMlcPGaVFoQK5W1trxJBfhwalxvO3PMrbXmn8isekvo66hcEaWWQfFSKGZNoBW9KAil2XovgeQnNwIiu88ofrpFYRQj1K9qqkmOHISq6wDl5uv/F9nxEuRrEzO3KbU4ULRA1oXBgREtG8m2tz3T0GuvdK5dCXMxjmOjopqDRyoaFXjclUDRn1GnC4meAzZOnkHB2ajjhgeLhy0QGa+q/TgW7cChRPDCXIBQMFIb19usIx9NzcOoGrCGUb95NB6S71DEewGgwXJtDTKh/fohayx8/XPGS+hCsO4IGRw2wLnSIjA/lLNA4/mSumYnsqdeztkjSEfrhYw/S2FHRbe7rVC2wYaqeUL0Hia9zK4wWoqx6zakX6UzKejlmJXyDaM2eBU0Txnip6VOPagBOChf+czEDfwcYqs85IIEuRCsDMLF8KrXd5QRVbiuoVh8W/WsaL0se6S7ngpfTuaiDDf6XOT8iGA4W40wsZednDkhxe1mDrOtfL3eyCwZv4A6OpyKktT6GyhQRvbn3rDd6e9VjTebcKcmGIQjTcFZBNhyCT/JRXxftUNV5RKtGeIOYUugP2GtLfq4NaDh/DnzPpZLyrysn/G8nQ3wnhSYc6YJwoB9P7PmVMdMxR0gn01B3ZPLLttSiZziX0nAj2H1ipLrQBqi0pSo4Xq3vvSUG7CuqvxO3Ja/B1a6SU2H0RjiINijBpVkvEjCixKjy+Q2yrH1OWgkFlYgn9JrwoD95UpzDDui71I9d/JEtiAWPje9ZkLH9XRTbl5zatynnVFa31Uu4eT6neURW+gKvdIEf1N0SvcefVJLV8mFSt9KTWBaxkv7pRl1EwZjQzMPZLmf4VEHuqOgor7sT3cLuZYDEag87qxToYoAWWue4K5WWFondJMMYnVIKEPAyP4nAIiJlgLTQzfh2DczrdS5rcdkoAg25yLqa1CTCLpM+eRk0A4htXtZqXvNoCJSZga3s+YPSF2yhUFjQw/un39QrCEIZ0WFJSMq/j8+Er8nxnVjNQsXoQBBGUMFkHD2OrehFBe3ebL8cJ7GRO5p2rvymnMRyz2K0ucA9LBZ/pz3XpfMhNjhPsqxdeu0kZnyGhRXBfBkKrky8QEO2uXpx2qE7ZqXW6TD3d2z8C9jir1Kcdu5pTXKCLFMETImjtAojzQEz+oeJzs8B+h+JV/KqGlMHVZLlP7ud9wsglPSgq5mmvtbIUgi8IegGJ9oFl0LRbhTX4BIZ+1Xi/WAdvPoaZwf+epE1UroV098I9QzYpTyffN+Kc9lV+y0JY+khWAQQOm7oQ1FPDMWTjuFrkQ3zWX2MG66cEHUzEQPyvEcc3q7EvDhkchiH6y4DIDYLqg6Qpy3Lgrz6Nkp6LlVN9z9SO6ZtWmOJGPnGpk1tEjx21tMjhxEKlkskjvr6SBTbTo0+77CoYFmum/GcnnUHYxEUl8YCmd5W2jrDbiVFEEXg3neEtapnWfyBVA/qFH/blMuxLZPbNpfTXNjFp4SWNCAdL5pd2uA8+pMlfUYpnItgTJxO2AZvV4yp6n+dUVML/0Mk0wuRqpSwNXPbvPxPV37Mw+KU+shnl1bP6g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8d82cd6-64d7-485d-8b66-08db33772116 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2023 12:38:15.4183 (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: ljo+FTVilU+xrte0YWnuTOUKObXlBZcuNgik+9S2WNap1drfzVkbnvjlFkf1+5t8N8VWlE3Lw85QFminiWfFRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB10052 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The fact that PTP 2-step TX timestamping is broken on DSA switches if the master also timestamps the same packets is documented by commit f685e609a301 ("net: dsa: Deny PTP on master if switch supports it"). We attempt to help the users avoid shooting themselves in the foot by making DSA reject the timestamping ioctls on an interface that is a DSA master, and the switch tree beneath it contains switches which are aware of PTP. The only problem is that there isn't an established way of intercepting ndo_eth_ioctl calls, so DSA creates avoidable burden upon the network stack by creating a struct dsa_netdevice_ops with overlaid function pointers that are manually checked from the relevant call sites. There used to be 2 such dsa_netdevice_ops, but now, ndo_eth_ioctl is the only one left. There is an ongoing effort to migrate driver-visible hardware timestamping control from the ndo_eth_ioctl() based API to a new ndo_hwtstamp_set() model, but DSA actively prevents that migration, since dsa_master_ioctl() is currently coded to manually call the master's legacy ndo_eth_ioctl(), and so, whenever a network device driver would be converted to the new API, DSA's restrictions would be circumvented, because any device could be used as a DSA master. The established way for unrelated modules to react on a net device event is via netdevice notifiers. So we create a new notifier which gets called whenever there is an attempt to change hardware timestamping settings on a device. Finally, there is another reason why a netdev notifier will be a good idea, besides strictly DSA, and this has to do with PHY timestamping. With ndo_eth_ioctl(), all MAC drivers must manually call phy_has_hwtstamp() before deciding whether to act upon SIOCSHWTSTAMP, otherwise they must pass this ioctl to the PHY driver via phy_mii_ioctl(). With the new ndo_hwtstamp_set() API, it will be desirable to simply not make any calls into the MAC device driver when timestamping should be performed at the PHY level. But there exist drivers, such as the lan966x switch, which need to install packet traps for PTP regardless of whether they are the layer that provides the hardware timestamps, or the PHY is. That would be impossible to support with the new API. The proposal there, too, is to introduce a netdev notifier which acts as a better cue for switching drivers to add or remove PTP packet traps, than ndo_hwtstamp_set(). The one introduced here "almost" works there as well, except for the fact that packet traps should only be installed if the PHY driver succeeded to enable hardware timestamping, whereas here, we need to deny hardware timestamping on the DSA master before it actually gets enabled. This is why this notifier is called "PRE_", and the notifier that would get used for PHY timestamping and packet traps would be called NETDEV_CHANGE_HWTSTAMP. This isn't a new concept, for example NETDEV_CHANGEUPPER and NETDEV_PRECHANGEUPPER do the same thing. In expectation of future netlink UAPI, we also pass a non-NULL extack pointer to the netdev notifier, and we make DSA populate it with an informative reason for the rejection. To avoid making it go to waste, we make the ioctl-based dev_set_hwtstamp() create a fake extack and print the message to the kernel log. Link: https://lore.kernel.org/netdev/20230401191215.tvveoi3lkawgg6g4@skbuf/ Link: https://lore.kernel.org/netdev/20230310164451.ls7bbs6pdzs4m6pw@skbuf/ Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- include/linux/netdevice.h | 9 ++++++- include/net/dsa.h | 51 --------------------------------------- net/core/dev.c | 8 +++--- net/core/dev_ioctl.c | 16 ++++++++++-- net/dsa/master.c | 50 ++++++++++++-------------------------- net/dsa/master.h | 3 +++ net/dsa/slave.c | 11 +++++++++ 7 files changed, 54 insertions(+), 94 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index c8c634091a65..336c62e5df3b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2877,6 +2877,7 @@ enum netdev_cmd { NETDEV_OFFLOAD_XSTATS_REPORT_USED, NETDEV_OFFLOAD_XSTATS_REPORT_DELTA, NETDEV_XDP_FEAT_CHANGE, + NETDEV_PRE_CHANGE_HWTSTAMP, }; const char *netdev_cmd_to_name(enum netdev_cmd cmd); @@ -2927,6 +2928,11 @@ struct netdev_notifier_pre_changeaddr_info { const unsigned char *dev_addr; }; +struct netdev_notifier_hwtstamp_info { + struct netdev_notifier_info info; /* must be first */ + struct kernel_hwtstamp_config *config; +}; + enum netdev_offload_xstats_type { NETDEV_OFFLOAD_XSTATS_TYPE_L3 = 1, }; @@ -2983,7 +2989,8 @@ netdev_notifier_info_to_extack(const struct netdev_notifier_info *info) } int call_netdevice_notifiers(unsigned long val, struct net_device *dev); - +int call_netdevice_notifiers_info(unsigned long val, + struct netdev_notifier_info *info); extern rwlock_t dev_base_lock; /* Device list lock */ diff --git a/include/net/dsa.h b/include/net/dsa.h index a15f17a38eca..8903053fa5aa 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -109,16 +109,6 @@ struct dsa_device_ops { bool promisc_on_master; }; -/* This structure defines the control interfaces that are overlayed by the - * DSA layer on top of the DSA CPU/management net_device instance. This is - * used by the core net_device layer while calling various net_device_ops - * function pointers. - */ -struct dsa_netdevice_ops { - int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, - int cmd); -}; - struct dsa_lag { struct net_device *dev; unsigned int id; @@ -317,11 +307,6 @@ struct dsa_port { */ const struct ethtool_ops *orig_ethtool_ops; - /* - * Original copy of the master netdev net_device_ops - */ - const struct dsa_netdevice_ops *netdev_ops; - /* List of MAC addresses that must be forwarded on this port. * These are only valid on CPU ports and DSA links. */ @@ -1339,42 +1324,6 @@ static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, #endif } -#if IS_ENABLED(CONFIG_NET_DSA) -static inline int __dsa_netdevice_ops_check(struct net_device *dev) -{ - int err = -EOPNOTSUPP; - - if (!dev->dsa_ptr) - return err; - - if (!dev->dsa_ptr->netdev_ops) - return err; - - return 0; -} - -static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, - int cmd) -{ - const struct dsa_netdevice_ops *ops; - int err; - - err = __dsa_netdevice_ops_check(dev); - if (err) - return err; - - ops = dev->dsa_ptr->netdev_ops; - - return ops->ndo_eth_ioctl(dev, ifr, cmd); -} -#else -static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, - int cmd) -{ - return -EOPNOTSUPP; -} -#endif - void dsa_unregister_switch(struct dsa_switch *ds); int dsa_register_switch(struct dsa_switch *ds); void dsa_switch_shutdown(struct dsa_switch *ds); diff --git a/net/core/dev.c b/net/core/dev.c index 0c4b21291348..7ce5985be84b 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -160,8 +160,6 @@ struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; struct list_head ptype_all __read_mostly; /* Taps */ static int netif_rx_internal(struct sk_buff *skb); -static int call_netdevice_notifiers_info(unsigned long val, - struct netdev_notifier_info *info); static int call_netdevice_notifiers_extack(unsigned long val, struct net_device *dev, struct netlink_ext_ack *extack); @@ -1614,7 +1612,7 @@ const char *netdev_cmd_to_name(enum netdev_cmd cmd) N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO) N(PRE_CHANGEADDR) N(OFFLOAD_XSTATS_ENABLE) N(OFFLOAD_XSTATS_DISABLE) N(OFFLOAD_XSTATS_REPORT_USED) N(OFFLOAD_XSTATS_REPORT_DELTA) - N(XDP_FEAT_CHANGE) + N(XDP_FEAT_CHANGE) N(PRE_CHANGE_HWTSTAMP) } #undef N return "UNKNOWN_NETDEV_EVENT"; @@ -1919,8 +1917,8 @@ static void move_netdevice_notifiers_dev_net(struct net_device *dev, * are as for raw_notifier_call_chain(). */ -static int call_netdevice_notifiers_info(unsigned long val, - struct netdev_notifier_info *info) +int call_netdevice_notifiers_info(unsigned long val, + struct netdev_notifier_info *info) { struct net *net = dev_net(info->dev); int ret; diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c index c532ef4d5dff..6d772837eb3f 100644 --- a/net/core/dev_ioctl.c +++ b/net/core/dev_ioctl.c @@ -259,7 +259,11 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr) static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) { + struct netdev_notifier_hwtstamp_info info = { + .info.dev = dev, + }; struct kernel_hwtstamp_config kernel_cfg; + struct netlink_ext_ack extack = {}; struct hwtstamp_config cfg; int err; @@ -272,9 +276,17 @@ static int dev_set_hwtstamp(struct net_device *dev, struct ifreq *ifr) if (err) return err; - err = dsa_ndo_eth_ioctl(dev, ifr, SIOCSHWTSTAMP); - if (err != -EOPNOTSUPP) + info.info.extack = &extack; + info.config = &kernel_cfg; + + err = call_netdevice_notifiers_info(NETDEV_PRE_CHANGE_HWTSTAMP, + &info.info); + err = notifier_to_errno(err); + if (err) { + if (extack._msg) + netdev_err(dev, "%s\n", extack._msg); return err; + } return dev_eth_ioctl(dev, ifr, SIOCSHWTSTAMP); } diff --git a/net/dsa/master.c b/net/dsa/master.c index e397641382ca..c2cabe6248b1 100644 --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -195,38 +195,31 @@ static void dsa_master_get_strings(struct net_device *dev, uint32_t stringset, } } -static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) +/* Deny PTP operations on master if there is at least one switch in the tree + * that is PTP capable. + */ +int dsa_master_pre_change_hwtstamp(struct net_device *dev, + const struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack) { struct dsa_port *cpu_dp = dev->dsa_ptr; struct dsa_switch *ds = cpu_dp->ds; struct dsa_switch_tree *dst; - int err = -EOPNOTSUPP; struct dsa_port *dp; dst = ds->dst; - switch (cmd) { - case SIOCGHWTSTAMP: - case SIOCSHWTSTAMP: - /* Deny PTP operations on master if there is at least one - * switch in the tree that is PTP capable. - */ - list_for_each_entry(dp, &dst->ports, list) - if (dsa_port_supports_hwtstamp(dp)) - return -EBUSY; - break; + list_for_each_entry(dp, &dst->ports, list) { + if (dsa_port_supports_hwtstamp(dp)) { + NL_SET_ERR_MSG(extack, + "HW timestamping not allowed on DSA master when switch supports the operation"); + return -EBUSY; + } } - if (dev->netdev_ops->ndo_eth_ioctl) - err = dev->netdev_ops->ndo_eth_ioctl(dev, ifr, cmd); - - return err; + return 0; } -static const struct dsa_netdevice_ops dsa_netdev_ops = { - .ndo_eth_ioctl = dsa_master_ioctl, -}; - static int dsa_master_ethtool_setup(struct net_device *dev) { struct dsa_port *cpu_dp = dev->dsa_ptr; @@ -267,15 +260,6 @@ static void dsa_master_ethtool_teardown(struct net_device *dev) cpu_dp->orig_ethtool_ops = NULL; } -static void dsa_netdev_ops_set(struct net_device *dev, - const struct dsa_netdevice_ops *ops) -{ - if (netif_is_lag_master(dev)) - return; - - dev->dsa_ptr->netdev_ops = ops; -} - /* Keep the master always promiscuous if the tagging protocol requires that * (garbles MAC DA) or if it doesn't support unicast filtering, case in which * it would revert to promiscuous mode as soon as we call dev_uc_add() on it @@ -414,16 +398,13 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) if (ret) goto out_err_reset_promisc; - dsa_netdev_ops_set(dev, &dsa_netdev_ops); - ret = sysfs_create_group(&dev->dev.kobj, &dsa_group); if (ret) - goto out_err_ndo_teardown; + goto out_err_ethtool_teardown; return ret; -out_err_ndo_teardown: - dsa_netdev_ops_set(dev, NULL); +out_err_ethtool_teardown: dsa_master_ethtool_teardown(dev); out_err_reset_promisc: dsa_master_set_promiscuity(dev, -1); @@ -433,7 +414,6 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) void dsa_master_teardown(struct net_device *dev) { sysfs_remove_group(&dev->dev.kobj, &dsa_group); - dsa_netdev_ops_set(dev, NULL); dsa_master_ethtool_teardown(dev); dsa_master_reset_mtu(dev); dsa_master_set_promiscuity(dev, -1); diff --git a/net/dsa/master.h b/net/dsa/master.h index 3fc0e610b5b5..80842f4e27f7 100644 --- a/net/dsa/master.h +++ b/net/dsa/master.h @@ -15,5 +15,8 @@ int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp, struct netlink_ext_ack *extack); void dsa_master_lag_teardown(struct net_device *lag_dev, struct dsa_port *cpu_dp); +int dsa_master_pre_change_hwtstamp(struct net_device *dev, + const struct kernel_hwtstamp_config *config, + struct netlink_ext_ack *extack); #endif diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 165bb2cb8431..8abc1658ac47 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -3289,6 +3289,7 @@ static int dsa_master_changeupper(struct net_device *dev, static int dsa_slave_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { + struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(ptr); struct net_device *dev = netdev_notifier_info_to_dev(ptr); switch (event) { @@ -3418,6 +3419,16 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb, return NOTIFY_OK; } + case NETDEV_PRE_CHANGE_HWTSTAMP: { + struct netdev_notifier_hwtstamp_info *info = ptr; + int err; + + if (!netdev_uses_dsa(dev)) + return NOTIFY_DONE; + + err = dsa_master_pre_change_hwtstamp(dev, info->config, extack); + return notifier_from_errno(err); + } default: break; }