From patchwork Sat Jan 23 04:53:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edwin Peer X-Patchwork-Id: 12041099 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 X-Spam-Level: X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1934C433E6 for ; Sat, 23 Jan 2021 04:54:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D04223AF8 for ; Sat, 23 Jan 2021 04:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726720AbhAWEyk (ORCPT ); Fri, 22 Jan 2021 23:54:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726654AbhAWEyO (ORCPT ); Fri, 22 Jan 2021 23:54:14 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82284C061788 for ; Fri, 22 Jan 2021 20:53:34 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id u11so4414871plg.13 for ; Fri, 22 Jan 2021 20:53:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=K83YF7GcNY82TVK2vJYspKj0xmLPWlJ36U3nO8TnBUE=; b=AEj2GmuSq9bAwmytXSXrvfU1Tvb3GkGgDFWbpAjFqi2td1IS73PkWrfpN/UyL5+CD4 70kXImoeWMlbmJWuN5/GL0+blgrmnUviMGLcD29o9UOp28bU7Y4jaG10Fu3IKWHWyWBy fYluih1Yy9c8An4nEP1/kCQJuTmQWfAeIpwnc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version; bh=K83YF7GcNY82TVK2vJYspKj0xmLPWlJ36U3nO8TnBUE=; b=hU/lUSNPMuFR44W4YIaE77k4NFUMJ38AnKsE3qJ2LPAHDkgCIuxYW7IwkG1cFvV3Ed tx1qupfCdZQ7ZsruMOwCETqlV+X3cdM/3WXYZkpZduJaokgmvQC0z8gmgsRda7GtNRys X2N1LCx1zKkGOxxr9uf98LQUGohzlphEGWWPxKJioc06OyRp2Ao6bnSrdDojpepQbozy 5nrNART27wyPwrzC26jEuBJoT5jrzPfdZFpSHQ5A7s0IBgCPgJVdUsVr9DnnpL27W/SO QaNLVTXd13UvHpJ7NH/Cdv54HIxLOaoNobcVQBu/yMPB9Au8yv6gaNnsXDEoT+speXbm TbKQ== X-Gm-Message-State: AOAM533CTp1GkC1ggBoAYVO8TjicFzv+HvT2WxwfM+QY2Kf8GPgO4O1U jx4QQxRJnfBo2Sx3sktQEydSoXk1K0tcXQb8wzs/y0pgrx9uPlFWK8MIgiTVuAWksIxD6PayLo0 S/CJnZs+dxFQ6lycbLISH+LJGQ67XC6jlnP+fuyLWEyoA0HFmf9m7y9LUtdtJZxYZghi9OnDd X-Google-Smtp-Source: ABdhPJxDPNUZI9t3LGRfbfRNqdv9D1LgnQFipdU7hhrCtRRe5CVwmQcG76I8yH1uqw+i1UIiRSvoIA== X-Received: by 2002:a17:90a:bd8c:: with SMTP id z12mr9270511pjr.204.1611377613505; Fri, 22 Jan 2021 20:53:33 -0800 (PST) Received: from hex.swdvt.lab.broadcom.net ([2600:8802:d04:de02::77c]) by smtp.gmail.com with ESMTPSA id d2sm10725832pjd.29.2021.01.22.20.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 20:53:32 -0800 (PST) From: Edwin Peer To: netdev@vger.kernel.org Cc: Edwin Peer , Jakub Kicinski , Andrew Gospodarek , Michael Chan , Stephen Hemminger , Michal Kubecek , David Ahern Subject: [PATCH net-next 3/4] rtnetlink: refactor IFLA_VF_INFO stats into rtnl_fill_vfstats() Date: Fri, 22 Jan 2021 20:53:20 -0800 Message-Id: <20210123045321.2797360-4-edwin.peer@broadcom.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210123045321.2797360-1-edwin.peer@broadcom.com> References: <20210123045321.2797360-1-edwin.peer@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Moving VF stats into their own function will facilitate separating them out later. No functional change. Signed-off-by: Edwin Peer --- net/core/rtnetlink.c | 66 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 466f920ac974..95564fd12f24 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1223,6 +1223,42 @@ static noinline_for_stack int rtnl_fill_stats(struct sk_buff *skb, return 0; } +static noinline_for_stack int rtnl_fill_vfstats(struct sk_buff *skb, + struct net_device *dev, + int vf_num) +{ + struct ifla_vf_stats vf_stats; + struct nlattr *vfstats; + + memset(&vf_stats, 0, sizeof(vf_stats)); + if (dev->netdev_ops->ndo_get_vf_stats) + dev->netdev_ops->ndo_get_vf_stats(dev, vf_num, &vf_stats); + vfstats = nla_nest_start_noflag(skb, IFLA_VF_STATS); + if (!vfstats) + return -EMSGSIZE; + if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS, + vf_stats.rx_packets, IFLA_VF_STATS_PAD) || + nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_PACKETS, + vf_stats.tx_packets, IFLA_VF_STATS_PAD) || + nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_BYTES, + vf_stats.rx_bytes, IFLA_VF_STATS_PAD) || + nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_BYTES, + vf_stats.tx_bytes, IFLA_VF_STATS_PAD) || + nla_put_u64_64bit(skb, IFLA_VF_STATS_BROADCAST, + vf_stats.broadcast, IFLA_VF_STATS_PAD) || + nla_put_u64_64bit(skb, IFLA_VF_STATS_MULTICAST, + vf_stats.multicast, IFLA_VF_STATS_PAD) || + nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_DROPPED, + vf_stats.rx_dropped, IFLA_VF_STATS_PAD) || + nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_DROPPED, + vf_stats.tx_dropped, IFLA_VF_STATS_PAD)) { + nla_nest_cancel(skb, vfstats); + return -EMSGSIZE; + } + nla_nest_end(skb, vfstats); + return 0; +} + static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb, struct net_device *dev, int vfs_num, @@ -1230,12 +1266,11 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb, u32 ext_filter_mask) { struct ifla_vf_rss_query_en vf_rss_query_en; - struct nlattr *vf, *vfstats, *vfvlanlist; + struct nlattr *vf, *vfvlanlist; struct ifla_vf_link_state vf_linkstate; struct ifla_vf_vlan_info vf_vlan_info; struct ifla_vf_spoofchk vf_spoofchk; struct ifla_vf_tx_rate vf_tx_rate; - struct ifla_vf_stats vf_stats; struct ifla_vf_trust vf_trust; struct ifla_vf_vlan vf_vlan; struct ifla_vf_rate vf_rate; @@ -1334,33 +1369,8 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb, } nla_nest_end(skb, vfvlanlist); if (~ext_filter_mask & RTEXT_FILTER_SKIP_STATS) { - memset(&vf_stats, 0, sizeof(vf_stats)); - if (dev->netdev_ops->ndo_get_vf_stats) - dev->netdev_ops->ndo_get_vf_stats(dev, vfs_num, - &vf_stats); - vfstats = nla_nest_start_noflag(skb, IFLA_VF_STATS); - if (!vfstats) - goto nla_put_vf_failure; - if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS, - vf_stats.rx_packets, IFLA_VF_STATS_PAD) || - nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_PACKETS, - vf_stats.tx_packets, IFLA_VF_STATS_PAD) || - nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_BYTES, - vf_stats.rx_bytes, IFLA_VF_STATS_PAD) || - nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_BYTES, - vf_stats.tx_bytes, IFLA_VF_STATS_PAD) || - nla_put_u64_64bit(skb, IFLA_VF_STATS_BROADCAST, - vf_stats.broadcast, IFLA_VF_STATS_PAD) || - nla_put_u64_64bit(skb, IFLA_VF_STATS_MULTICAST, - vf_stats.multicast, IFLA_VF_STATS_PAD) || - nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_DROPPED, - vf_stats.rx_dropped, IFLA_VF_STATS_PAD) || - nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_DROPPED, - vf_stats.tx_dropped, IFLA_VF_STATS_PAD)) { - nla_nest_cancel(skb, vfstats); + if (rtnl_fill_vfstats(skb, dev, vfs_num)) goto nla_put_vf_failure; - } - nla_nest_end(skb, vfstats); } nla_nest_end(skb, vf); return 0;