From patchwork Sat Jan 23 04:53:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edwin Peer X-Patchwork-Id: 12041103 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=-16.1 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, UNWANTED_LANGUAGE_BODY,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 E372DC433E9 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 B505223B16 for ; Sat, 23 Jan 2021 04:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726733AbhAWEym (ORCPT ); Fri, 22 Jan 2021 23:54:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbhAWEyQ (ORCPT ); Fri, 22 Jan 2021 23:54:16 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96C55C06178B for ; Fri, 22 Jan 2021 20:53:36 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id 30so5228837pgr.6 for ; Fri, 22 Jan 2021 20:53:36 -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=ILT1zsp1gp4scssLPHXpg9nOq/pEWZdcrMBoO8vJPso=; b=FDHG9xt/uUv4UCDAT7XXiyEpUfYUbGqCzgr57SUu6eINvIsFKq9BvEJ0yPdg8PS69Q eYO5Cd/IqLEFKFUs0R5Q1cIUa1eYtwyOwemQhekp05pnQP1i9vW7pFzI+pZ7W0GyWOpD iRelljGFJ9W/a4ABlqWYz0SD0LBhTLTtpLM4Y= 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=ILT1zsp1gp4scssLPHXpg9nOq/pEWZdcrMBoO8vJPso=; b=dcrbjXwUXsuwpm7hKaTw/HzD70NZHZBFct1mwNpjhtUzMLVz4pguYUYZ06cDSxbe2e H12IYdEFGbsyryyQKqs0f+SCC2e6xVZeFum5RLhPZjfzYBuVzTap1XziCIRFII8te1IX swCw3v/g656kypYBxvQ5niW9KHPNRq5pe2fXgxYXcuhh+UaXJXrXQLpr7b10LZmBdCYl pJEw2i0jDLrnMQPLp8zdis96cOWMdm231ekUAgJV0H3jHtUEEjDntX5/zNZlOeeFlA8X RCNFNz1SL2vR5jGHhDeFRaLAXvlrhx9Mw/kIFAhN1CdlUzSe1jIEoX998QgtFii8Bq60 Y2Eg== X-Gm-Message-State: AOAM531/NmTlx4ASbZHPTldehR+dS2Retw6vILBLeftgdcN29YWy1EYw 8Azh7MFDaTbrCmQIJc1nHyN/wO3+nemP3NHjCiQ/qbHGf0+3+xe2YdvmewRZxJKHHJPkYACDrwf Ob1OW4tmAJNly4P/gjLFZee8sy5BD9wnBOmYXRWu88JNrsMFoJ2rakDgFj4L/alNn/M0736qh X-Google-Smtp-Source: ABdhPJySCY33xJR4VeDi1DgVlWuCpV9QTkW315eyZKeZZEYSuPRBO3z+J86cBy7oIX+KFjtL3pqmwA== X-Received: by 2002:a65:6405:: with SMTP id a5mr7953724pgv.389.1611377615593; Fri, 22 Jan 2021 20:53:35 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 20:53:34 -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 4/4] rtnetlink: promote IFLA_VF_STATS to same level as IFLA_VF_INFO Date: Fri, 22 Jan 2021 20:53:21 -0800 Message-Id: <20210123045321.2797360-5-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 Separating the VF stats out of IFLA_VF_INFO appears to be the least impact way of resolving the nlattr overflow bug in IFLA_VFINFO_LIST. Since changing the hierarchy does constitute an ABI change, it must be explicitly requested via RTEXT_FILTER_VF_SEPARATE_STATS. Otherwise, the old location is maintained for compatibility. A new container type, namely IFLA_VFSTATS_LIST, is introduced to group the stats objects into an ordered list that corresponds with the order of VFs in IFLA_VFINFO_LIST. Fixes: 3b766cd83232 ("net/core: Add reading VF statistics through the PF netdevice") Fixes: c5a9f6f0ab40 ("net/core: Add drop counters to VF statistics") Signed-off-by: Edwin Peer --- include/uapi/linux/if_link.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/core/rtnetlink.c | 24 +++++++++++++++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 2bd0d8bbcdb2..db12ffd2bffd 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -341,6 +341,7 @@ enum { IFLA_ALT_IFNAME, /* Alternative ifname */ IFLA_PERM_ADDRESS, IFLA_PROTO_DOWN_REASON, + IFLA_VFSTATS_LIST, __IFLA_MAX }; diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h index b841caa4657e..f2f4f9b4d595 100644 --- a/include/uapi/linux/rtnetlink.h +++ b/include/uapi/linux/rtnetlink.h @@ -789,6 +789,7 @@ enum { #define RTEXT_FILTER_MRP (1 << 4) #define RTEXT_FILTER_CFM_CONFIG (1 << 5) #define RTEXT_FILTER_CFM_STATUS (1 << 6) +#define RTEXT_FILTER_VF_SEPARATE_STATS (1 << 7) /* End of information exported to user level */ diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 95564fd12f24..cddd3945bc11 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -933,6 +933,8 @@ static inline int rtnl_vfinfo_size(const struct net_device *dev, nla_total_size(sizeof(struct ifla_vf_rss_query_en)) + nla_total_size(sizeof(struct ifla_vf_trust))); if (~ext_filter_mask & RTEXT_FILTER_SKIP_STATS) { + if (ext_filter_mask & RTEXT_FILTER_VF_SEPARATE_STATS) + size += nla_total_size(0); /* IFLA_VFSTATS_LIST */ size += num_vfs * (nla_total_size(0) + /* nest IFLA_VF_STATS */ /* IFLA_VF_STATS_RX_PACKETS */ @@ -1368,7 +1370,8 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb, goto nla_put_vf_failure; } nla_nest_end(skb, vfvlanlist); - if (~ext_filter_mask & RTEXT_FILTER_SKIP_STATS) { + if (~ext_filter_mask & RTEXT_FILTER_SKIP_STATS && + ~ext_filter_mask & RTEXT_FILTER_VF_SEPARATE_STATS) { if (rtnl_fill_vfstats(skb, dev, vfs_num)) goto nla_put_vf_failure; } @@ -1386,7 +1389,7 @@ static noinline_for_stack int rtnl_fill_vf(struct sk_buff *skb, struct net_device *dev, u32 ext_filter_mask) { - struct nlattr *vfinfo; + struct nlattr *vfinfo, *vfstats; int i, num_vfs; if (!dev->dev.parent || ((ext_filter_mask & RTEXT_FILTER_VF) == 0)) @@ -1407,8 +1410,23 @@ static noinline_for_stack int rtnl_fill_vf(struct sk_buff *skb, if (rtnl_fill_vfinfo(skb, dev, i, vfinfo, ext_filter_mask)) return -EMSGSIZE; } - nla_nest_end(skb, vfinfo); + + if (~ext_filter_mask & RTEXT_FILTER_SKIP_STATS && + ext_filter_mask & RTEXT_FILTER_VF_SEPARATE_STATS) { + vfstats = nla_nest_start_noflag(skb, IFLA_VFSTATS_LIST); + if (!vfstats) + return -EMSGSIZE; + + for (i = 0; i < num_vfs; i++) { + if (rtnl_fill_vfstats(skb, dev, i)) { + nla_nest_cancel(skb, vfstats); + return -EMSGSIZE; + } + } + nla_nest_end(skb, vfstats); + } + return 0; }