From patchwork Sat Jan 23 04:53:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edwin Peer X-Patchwork-Id: 12041111 X-Patchwork-Delegate: dsahern@gmail.com 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 51880C433E0 for ; Sat, 23 Jan 2021 04:55:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E2B223AA1 for ; Sat, 23 Jan 2021 04:55:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726866AbhAWEz0 (ORCPT ); Fri, 22 Jan 2021 23:55:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbhAWEyy (ORCPT ); Fri, 22 Jan 2021 23:54:54 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 756E1C0617A7 for ; Fri, 22 Jan 2021 20:54:03 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id a20so2110435pjs.1 for ; Fri, 22 Jan 2021 20:54:03 -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=2HiPQbERNmDJsN7tLgdcD8TxeTumghftwa9JpFzrsGw=; b=IABNyNRTOlckv/zPzdqeMTlVKQFHP/wNME7+ExBFDp7V8jmAl4e/YcHwU/IBBpdDlR lKKr/7xuOZsqUTC2Kg1ZMi6hjrz6gxSuAKZuVkNstURCeicZHQxgFFx4xfHLrqxOAdX3 EYBGXUY/fSa9dUrGJbtsEeE+uCevaH4oYhtCo= 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=2HiPQbERNmDJsN7tLgdcD8TxeTumghftwa9JpFzrsGw=; b=HM/4lIkShcLdqGWOXRd3U/SH2yAdgrpPlXXIzNtL3L6yuZeUX3HAjFU5tt8aVgyfwq ctU0Nzyg6phfGdCeRq95yqEA1dAq/Qln1acvdnwMqajqClyreKOtsrz1nFcPS9ZYLudy rhQQ8gLiCae2JCWzUFEhaGe2Yjhfna0sMJzRAJ0C8zUVNbD9m67INib77zGnGL4Vvtml FeNn5ycimPnVHH1/R7i89JYXtjdWF7cyx+mXdnfus1d6Z/IZqpJ8R4c1NagpQw1GISys ZFqgO8Y+6F++io8iefExN5lZOwKtSonkHfkr6KTUoabYCDp4Ba/y+M19ea0/qOGtuZug narQ== X-Gm-Message-State: AOAM53124MdtiKzWWhFn21PTB1xEPKjGt+e9aqigsuwikN35iye56ogB wyUkwBS+X7yYtvu87MlnIrve8GB96UBa/LIneszoFhukNpi36NmkdoBaBd8zYaoCYXr3gakSOiT lxBTWiAZVuy8juyGt6gw14yPr9wRoLM+gVE/4VUghntyxXLZZYuBYqvABZJdSZXzomhov8vLU X-Google-Smtp-Source: ABdhPJz53qIoW4PMu7VJuoVvc9aV3hRpjMR7/ySPOnd5YTTlDdmeFWok0s8Cp3iQynzsL2EhQ1Kx7A== X-Received: by 2002:a17:90a:c82:: with SMTP id v2mr9217635pja.171.1611377642233; Fri, 22 Jan 2021 20:54:02 -0800 (PST) Received: from hex.swdvt.lab.broadcom.net ([2600:8802:d04:de02::77c]) by smtp.gmail.com with ESMTPSA id k3sm9675743pgm.94.2021.01.22.20.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 20:54:01 -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 iproute2-next 4/4] iplink: render IFLA_VF_STATS from IFLA_VFSTATS_LIST Date: Fri, 22 Jan 2021 20:53:51 -0800 Message-Id: <20210123045351.2797433-4-edwin.peer@broadcom.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210123045351.2797433-1-edwin.peer@broadcom.com> References: <20210123045351.2797433-1-edwin.peer@broadcom.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: dsahern@gmail.com The maximum possible length of a netlink attribute is 64KB, but the IFLA_VFINFO_LIST exceeds this when stats are included and more than about 220 VFs are present (each VF consumes approximately 300 bytes, depending on alignment and optional fields). Exceeding the limit will cause the list to be truncated by the kernel's nla_nest_end(). A recent ABI fix moves the VF stats into an independent list when requested, thus avoiding the problem. Send requests using the new RTEXT_FILTER_VF_SEPARATE_STATS filter and render the stats from the alternate list instead. Signed-off-by: Edwin Peer --- ip/ipaddress.c | 14 +++++++++++--- ip/iplink.c | 1 + lib/libnetlink.c | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 75511881050d..a048b3db601c 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1200,12 +1200,20 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) if ((do_link || show_details) && tb[IFLA_VFINFO_LIST] && tb[IFLA_NUM_VF]) { struct rtattr *i, *vflist = tb[IFLA_VFINFO_LIST]; - int rem = RTA_PAYLOAD(vflist), count = 0; + struct rtattr *j, *vfstats = tb[IFLA_VFSTATS_LIST]; + int rem_stats, rem = RTA_PAYLOAD(vflist), count = 0; + j = vfstats ? RTA_DATA(vfstats) : NULL; + rem_stats = vfstats ? RTA_PAYLOAD(vfstats) : 0; open_json_array(PRINT_JSON, "vfinfo_list"); for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { open_json_object(NULL); print_vfinfo(fp, ifi, i); + if (show_stats && j) { + print_vf_stats64(fp, j); + j = RTA_OK(j, rem_stats) ? + RTA_NEXT(j, rem_stats) : NULL; + } close_json_object(); count++; } @@ -1885,7 +1893,7 @@ static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen) __u32 filt_mask; int err; - filt_mask = RTEXT_FILTER_VF; + filt_mask = RTEXT_FILTER_VF | RTEXT_FILTER_VF_SEPARATE_STATS; if (!show_stats) filt_mask |= RTEXT_FILTER_SKIP_STATS; err = addattr32(nlh, reqlen, IFLA_EXT_MASK, filt_mask); @@ -1923,7 +1931,7 @@ static int ipaddr_link_get(int index, struct nlmsg_chain *linfo) .i.ifi_family = filter.family, .i.ifi_index = index, }; - __u32 filt_mask = RTEXT_FILTER_VF; + __u32 filt_mask = RTEXT_FILTER_VF | RTEXT_FILTER_VF_SEPARATE_STATS; struct nlmsghdr *answer; if (!show_stats) diff --git a/ip/iplink.c b/ip/iplink.c index 6a973213dc11..3cce8aa2a0b7 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -1117,6 +1117,7 @@ int iplink_get(char *name, __u32 filt_mask) name, strlen(name) + 1); } + filt_mask |= RTEXT_FILTER_VF_SEPARATE_STATS; if (!show_stats) filt_mask |= RTEXT_FILTER_SKIP_STATS; addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask); diff --git a/lib/libnetlink.c b/lib/libnetlink.c index b1f07d4570cf..b4aa9d16b446 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -486,7 +486,8 @@ static int __rtnl_linkdump_req(struct rtnl_handle *rth, int family) int rtnl_linkdump_req(struct rtnl_handle *rth, int family) { if (family == AF_UNSPEC) - return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF); + return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF | + RTEXT_FILTER_VF_SEPARATE_STATS); return __rtnl_linkdump_req(rth, family); }