From patchwork Wed Mar 2 16:31:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 12766273 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 B4E4BC433FE for ; Wed, 2 Mar 2022 16:33:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242596AbiCBQdn (ORCPT ); Wed, 2 Mar 2022 11:33:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242703AbiCBQdi (ORCPT ); Wed, 2 Mar 2022 11:33:38 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2071.outbound.protection.outlook.com [40.107.243.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 303F34477C for ; Wed, 2 Mar 2022 08:32:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=khKI7SvYHXHxrOH47Xwls+NhbdpsnUOlJnD8rYKau5q2F2u+QHYBtbIIZrqPwDTmXhj/KAzHQG2gsGEXJbfWGfkjUesK19ZdyRmPB0g3HeEgJ5aJT9JivMxVLLBgrFA1MRZV+BCymb/HHD9z2GpSiLzxB0ieUo3R/APj3G4mcSlQqBQuQAL71wCkmDhHYMY0ZORx8oDmAHvoLxu5fyF+9+g3wj9XcOKTUhFOejwo081vVPV+LPCa3dYq+46//diTV3GYhrtj6fooQ1hxKLGrguUpgvr/91NXpX7mkx5HbqNFpM9yRI3QXQBa8x6IhenRjn6cgP2SE3vF0Rdm5ZULPQ== 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=GnMId5Dt96gJcgd6j8kKg1opGcT6em7rqjwA6F2glRs=; b=P9Td9ugQj2BebMelK8N+jRP6nQc/Dzf9Sqxy1sN88HeVQeH7zTlJZgG9mioVaDCqVg9OYq4Sx5pWmpHz7hG8USJj1vSo0oxQu8cMERizctr7aT8Yw0IONPirISJ58VawTPtoRTAlgKDQsvHNJI8jZkvP9sdfnQYNdDVcAc/64B6bUqOpq0WP1zqR3h+prpsp109goobcughqJk0Qnf0cLJALucj6fK2PHk0wTE+R2N9nEBYqQtAaGAW0yHUu1357nijHTmO8KXbOHijRYpD36lKr2Ox/e0exc/d5oMyFWIGe0gmJE41gx1qip1jBqNbQadQBc0CvYtSuC3MCERoQtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GnMId5Dt96gJcgd6j8kKg1opGcT6em7rqjwA6F2glRs=; b=Af1moQqvgYsqyLWzc1eSPBMunmQgR0b1Os2CWTO44uCgwQYQgPY1pkDuvzeNy51E0FG0a+TzN/JrQOzfTwCmVSP6kDV1TOdIX6ahrvhLcNMF/VPMMzfeXqt0WCj1j4xlthxJoKyqa5ZrPX6bu2odPTN+D9MOsTjGyEq1f29wApppCpj7FO3b34nAY68QCCac8T5RW2tAj7fJMvSTdGdqX65tbHXIP0RlU4caEC7xL24/8aYaR08V5PzBvdipzOY143FXNbxMfoZa9LfcRY4C2GQPlNCI1HP7hhxDPworQrCj32SUm7FTlQBpqM7aTh0OVpGhEOpyU8BktMFEupy1lg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) by MN2PR12MB3998.namprd12.prod.outlook.com (2603:10b6:208:16d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23; Wed, 2 Mar 2022 16:32:45 +0000 Received: from DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581]) by DM6PR12MB4337.namprd12.prod.outlook.com ([fe80::95a1:8c7f:10ef:2581%6]) with mapi id 15.20.5038.014; Wed, 2 Mar 2022 16:32:45 +0000 From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, petrm@nvidia.com, jiri@nvidia.com, roopa@nvidia.com, razor@blackwall.org, dsahern@gmail.com, andrew@lunn.ch, mlxsw@nvidia.com, Ido Schimmel Subject: [PATCH net-next v2 08/14] net: rtnetlink: Add RTM_SETSTATS Date: Wed, 2 Mar 2022 18:31:22 +0200 Message-Id: <20220302163128.218798-9-idosch@nvidia.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220302163128.218798-1-idosch@nvidia.com> References: <20220302163128.218798-1-idosch@nvidia.com> X-ClientProxiedBy: VI1PR0801CA0073.eurprd08.prod.outlook.com (2603:10a6:800:7d::17) To DM6PR12MB4337.namprd12.prod.outlook.com (2603:10b6:5:2a9::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b32c26a-6fb2-4119-c486-08d9fc6a47c4 X-MS-TrafficTypeDiagnostic: MN2PR12MB3998:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gWBbrCVtqqXdTelc/bm40JgZcKoZ3mfEwApdVEnnjqZWu6Jm1ezM9WSJ04dAYVKBH/r+Qy2ZwMO9fl0D5xRUCCUUmVst0fZj5mLMF4QajFOwV9M9oZDq7Jpsu4/ogXWMryMED6vnsEUQ2svb/+nfOT4U6QK9iDsCPF+Edmdpfq42SYFBFXS05kgnR4K1NEUpwjJHKbz0Gci4w8NoIIrJgKOswI133i0P/HqpG83WIYCbaHfcsJ6KjJpCgFtwooSUXf5U0Iojm7s5ora0V04l+3aIkeDXzvCNFOwKP12G49igWiwjzzkx59dkr0mbYDULhqhNK7FWOsMecXmX5CHLKw5oNQALNZ2x94OockRcPRjtFAYdJPvFXyy/44Qut0R2+38iO+Cs7yCz2PaDMi//GNLkeXdgDUyMgcrWRrEOMe2iJFXW66vZ3Kr4iJkWJQ8WACKvDNN0SET9qxK2AtPIamHkyUg7vsnblVU0nxlA/FEBqhVf6Rpz8fT+0+CoumdNXH0yUUD/ZyuG0W5rRCQh5YO/FKRD7I97UCBNAlFs+39joBiRvt2Jw+49M9OrHoY6wonyQCYlidWzQFhGbuoD+sDB6w6T3ldWdHsehSfkMLu9KwbfIKSn0yB0hGQ5dk9Y3T71OF+27xKek8brwS+73Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4337.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(8936002)(86362001)(2616005)(316002)(6916009)(6506007)(6666004)(26005)(1076003)(186003)(6512007)(107886003)(83380400001)(38100700002)(8676002)(66556008)(4326008)(66476007)(2906002)(508600001)(66946007)(6486002)(5660300002)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rRupLE00jacbI1HAsEhP+yFHHAaoknhUs0TMgGMSve5U47uit23t+WuvDSrzpHyabFgOMQERbgGGRKAVNo+fsyhsC9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ifq+OIwI75hgg0M60BJSnlRRxyQVjZiWZ4WqADuDIOPApLiHx710730asHfG8smx50p1CPyJueHaKdG0/C7suemYQow2uffbYVoX94NpksaezPXpA0hZepyvIino3TD+jomAqe2RpWnZa0aSbCwViSffzplbYGZf8CJwOA/naCtnunzYu3t2AdPFRJbkQj2n41q2IeZxt5paAOzLxTjvy629a7l3rzfRy0i1coLrvwtbWUznPG1EV6yxqXUARfL9CHkFhC7r2CNeuSO6KTmcoVtIASdTZ4sDMVvUL2zp7X/52990uoO00IV1vdL9pXSYD3IbbNjZDJ1z34lOmiRbxtoMv07HZ0mxfkjzvzW/egEQ0aGzTjZNBsdqX57pKjbI2fclVPrDxTNx99V6cXW6BVdldD5kxGGUBM0+Sn0zOGIZhxK8iGaxUoGBnodwtDmlBL+hAjZavf33WsMsxj+qCA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b32c26a-6fb2-4119-c486-08d9fc6a47c4 X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4337.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2022 16:32:45.2321 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kQYTOmjKQ5y8cODsLCDIxBEz6jwjAq4T+lI+BuD45PBLF4CBnC37E1gKp3mhO+AzPYKM18jZSsFSahicMyg07Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3998 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Petr Machata The offloaded HW stats are designed to allow per-netdevice enablement and disablement. These stats are only accessible through RTM_GETSTATS, and therefore should be toggled by a RTM_SETSTATS message. Add it, and the necessary skeleton handler. Signed-off-by: Petr Machata Signed-off-by: Ido Schimmel --- include/uapi/linux/rtnetlink.h | 2 ++ net/core/rtnetlink.c | 66 ++++++++++++++++++++++++++++++++++ security/selinux/nlmsgtab.c | 1 + 3 files changed, 69 insertions(+) diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index 0970cb4b1b88..14462dc159fd 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -146,6 +146,8 @@ enum { #define RTM_NEWSTATS RTM_NEWSTATS RTM_GETSTATS = 94, #define RTM_GETSTATS RTM_GETSTATS + RTM_SETSTATS, +#define RTM_SETSTATS RTM_SETSTATS RTM_NEWCACHEREPORT = 96, #define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 9ce894a9454c..d09354514355 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -5564,6 +5564,10 @@ rtnl_stats_get_policy[IFLA_STATS_GETSET_MAX + 1] = { NLA_POLICY_NESTED(rtnl_stats_get_policy_filters), }; +static const struct nla_policy +ifla_stats_set_policy[IFLA_STATS_GETSET_MAX + 1] = { +}; + static int rtnl_stats_get_parse_filters(struct nlattr *ifla_filters, struct rtnl_stats_dump_filters *filters, struct netlink_ext_ack *extack) @@ -5769,6 +5773,67 @@ static int rtnl_stats_dump(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +static int rtnl_stats_set(struct sk_buff *skb, struct nlmsghdr *nlh, + struct netlink_ext_ack *extack) +{ + struct rtnl_stats_dump_filters response_filters = {}; + struct nlattr *tb[IFLA_STATS_GETSET_MAX + 1]; + struct net *net = sock_net(skb->sk); + struct net_device *dev = NULL; + int idxattr = 0, prividx = 0; + struct if_stats_msg *ifsm; + struct sk_buff *nskb; + int err; + + err = rtnl_valid_stats_req(nlh, netlink_strict_get_check(skb), + false, extack); + if (err) + return err; + + ifsm = nlmsg_data(nlh); + if (ifsm->family != AF_UNSPEC) { + NL_SET_ERR_MSG(extack, "Address family should be AF_UNSPEC"); + return -EINVAL; + } + + if (ifsm->ifindex > 0) + dev = __dev_get_by_index(net, ifsm->ifindex); + else + return -EINVAL; + + if (!dev) + return -ENODEV; + + if (ifsm->filter_mask) { + NL_SET_ERR_MSG(extack, "Filter mask must be 0 for stats set"); + return -EINVAL; + } + + err = nlmsg_parse(nlh, sizeof(*ifsm), tb, IFLA_STATS_GETSET_MAX, + ifla_stats_set_policy, extack); + if (err < 0) + return err; + + nskb = nlmsg_new(if_nlmsg_stats_size(dev, &response_filters), + GFP_KERNEL); + if (!nskb) + return -ENOBUFS; + + err = rtnl_fill_statsinfo(nskb, dev, RTM_NEWSTATS, + NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0, + 0, &response_filters, &idxattr, &prividx, + extack); + if (err < 0) { + /* -EMSGSIZE implies BUG in if_nlmsg_stats_size */ + WARN_ON(err == -EMSGSIZE); + kfree_skb(nskb); + } else { + err = rtnl_unicast(nskb, net, NETLINK_CB(skb).portid); + } + + return err; +} + /* Process one rtnetlink message. */ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, @@ -5994,4 +6059,5 @@ void __init rtnetlink_init(void) rtnl_register(PF_UNSPEC, RTM_GETSTATS, rtnl_stats_get, rtnl_stats_dump, 0); + rtnl_register(PF_UNSPEC, RTM_SETSTATS, rtnl_stats_set, NULL, 0); } diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c index 6ad3ee02e023..d8ceee9e0d6f 100644 --- a/security/selinux/nlmsgtab.c +++ b/security/selinux/nlmsgtab.c @@ -76,6 +76,7 @@ static const struct nlmsg_perm nlmsg_route_perms[] = { RTM_GETNSID, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_NEWSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_GETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, + { RTM_SETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_NEWCACHEREPORT, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_NEWCHAIN, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, { RTM_DELCHAIN, NETLINK_ROUTE_SOCKET__NLMSG_WRITE },