From patchwork Fri Jan 8 16:31:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359535 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 4BCD0C43331 for ; Fri, 8 Jan 2021 16:33:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CC8023A51 for ; Fri, 8 Jan 2021 16:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728317AbhAHQdD (ORCPT ); Fri, 8 Jan 2021 11:33:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728292AbhAHQdC (ORCPT ); Fri, 8 Jan 2021 11:33:02 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8671C0612FE for ; Fri, 8 Jan 2021 08:32:21 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id c7so11778824edv.6 for ; Fri, 08 Jan 2021 08:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eH3qpeJWhBhUclxAjuxgpD80hx2i1ZWe5ao+Mipp3Ec=; b=qtatG2tQLAo1ZLV0j63KdJS8ZwsvbAtg1/+Q24oXqgp6vuaJaiQEj4Nd6ZeIk1CbQy Ae6vHjMiXgCNmD8CO6CiiOwQDWwSqr332zFlnOROid3kvEzQdd7DPjWWQxT8zx4IV560 6q5zFNoZz7zO6iMINKAII7O3OiSbbiGnBTFEdP6z4KMy8uGI0fMjcxafq41XO+HglqM5 1ehazd67WNoUaM3dUSav0Y7ReoLCQrzqDRdysaJgTMF7cGHL2Grckzk8dUpEffICvsNi LPCZ9S1HkZzVwDUHO4xyghh9uvejmkGpcMFkuFzlsOeTz2lCH5poliGX5t9SiPVu/HpM zaLw== 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:content-transfer-encoding; bh=eH3qpeJWhBhUclxAjuxgpD80hx2i1ZWe5ao+Mipp3Ec=; b=RIAD2baoAo9Bp1aRj0x8n4y+hgcoy92mJa5SNW409Ab6Kj5dH7pwGLkgp9zTeuUNbl 5hvzhb8o3L7M8iwgxw2kpX7vSV+RjRWbTjmzoIAIPl12KQdfOHLGVVIqoNxhBdtborpf iJ+V4ldK97DpE8Ob1IzWkzv7tmsXq0CVhbwFsQQF4RN4N5l4NcHF/tBtS0iBr7cQSm2Q nvLkNvr2gmf5ramv+Oko29KAwU5a58lcPAa9DiJkUbs4aGPfMo0B1qc9VlOB4IjWerIo JO3byOUeimwR09MTKhawQQm3x/99tE6a8yg5JJR1ifL5tf+GParz2N6pXMTzZn9sYQ7h GjKQ== X-Gm-Message-State: AOAM530YRFqRnoY8ECq7kVfxP4DtTe23RTyYdNP8f6NQ5kWa7U0C/Tr8 lij3Z+BkBvvnoW60wTZRQ9k= X-Google-Smtp-Source: ABdhPJycHAKukbeTUsWpfIxXeWrSLyVSbBICfKP7DGl13o//s1gjcXZPxoNj7BUbFq3a77ppm7jf0Q== X-Received: by 2002:aa7:cac2:: with SMTP id l2mr5795734edt.141.1610123540624; Fri, 08 Jan 2021 08:32:20 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id x6sm3957737edl.67.2021.01.08.08.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:32:20 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala , Saeed Mahameed Subject: [PATCH v5 net-next 02/16] net: introduce a mutex for the netns interface lists Date: Fri, 8 Jan 2021 18:31:45 +0200 Message-Id: <20210108163159.358043-3-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108163159.358043-1-olteanv@gmail.com> References: <20210108163159.358043-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Currently, any writer that wants to alter the lists of network interfaces (either the plain list net->dev_base_head, or the hash tables net->dev_index_head and net->dev_name_head) can keep other writers at bay using the RTNL mutex. However, the RTNL mutex has become a very contended resource over the years, so there is a movement to do finer grained locking. This patch adds one more way for writers to the network interface lists to serialize themselves. We assume that all writers to the network interface lists are easily identifiable because the write side of dev_base_lock also needs to be held (note that some instances of that were deliberately skipped, since they only dealt with protecting the operational state of the netdev). Holding the RTNL mutex is now optional for new code that alters the lists, since all relevant writers were made to also hold the new lock. Signed-off-by: Vladimir Oltean --- Changes in v5: None. Changes in v4: None. Changes in v3: None. include/linux/netdevice.h | 10 +++++++++ include/net/net_namespace.h | 6 +++++ net/core/dev.c | 44 +++++++++++++++++++++++++------------ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 1ec3ac5d5bbf..8aae2386bd37 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4376,6 +4376,16 @@ static inline void netif_addr_unlock_bh(struct net_device *dev) spin_unlock_bh(&dev->addr_list_lock); } +static inline void netif_lists_lock(struct net *net) +{ + mutex_lock(&net->netif_lists_lock); +} + +static inline void netif_lists_unlock(struct net *net) +{ + mutex_unlock(&net->netif_lists_lock); +} + /* * dev_addrs walker. Should be used only for read access. Call with * rcu_read_lock held. diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index 29567875f428..cac64c3c7ce0 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h @@ -183,6 +183,12 @@ struct net { struct sock *crypto_nlsk; #endif struct sock *diag_nlsk; + + /* Serializes writers to @dev_base_head, @dev_name_head and + * @dev_index_head. It does _not_ protect the netif adjacency lists + * (struct net_device::adj_list). + */ + struct mutex netif_lists_lock; } __randomize_layout; #include diff --git a/net/core/dev.c b/net/core/dev.c index 8e02240bb11c..53c12f92025c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -175,13 +175,16 @@ static struct napi_struct *napi_by_id(unsigned int napi_id); * * Pure readers should hold rcu_read_lock() which should protect them against * concurrent changes to the interface lists made by the writers. Pure writers - * must serialize by holding the RTNL mutex while they loop through the list - * and make changes to it. + * must serialize by holding the @net->netif_lists_lock mutex while they loop + * through the list and make changes to it. + * + * It is possible to hold the RTNL mutex for serializing the writers too, but + * this should be avoided in new code due to lock contention. * * It is also possible to hold the global rwlock_t @dev_base_lock for * protection (holding its read side as an alternative to rcu_read_lock, and - * its write side as an alternative to the RTNL mutex), however this should not - * be done in new code, since it is deprecated and pending removal. + * its write side as an alternative to @net->netif_lists_lock), however this + * should not be done in new code, since it is deprecated and pending removal. * * One other role of @dev_base_lock is to protect against changes in the * operational state of a network interface. @@ -360,12 +363,14 @@ static void list_netdevice(struct net_device *dev) ASSERT_RTNL(); + netif_lists_lock(net); write_lock_bh(&dev_base_lock); list_add_tail_rcu(&dev->dev_list, &net->dev_base_head); netdev_name_node_add(net, dev->name_node); hlist_add_head_rcu(&dev->index_hlist, dev_index_hash(net, dev->ifindex)); write_unlock_bh(&dev_base_lock); + netif_lists_unlock(net); dev_base_seq_inc(net); } @@ -375,16 +380,20 @@ static void list_netdevice(struct net_device *dev) */ static void unlist_netdevice(struct net_device *dev) { + struct net *net = dev_net(dev); + ASSERT_RTNL(); /* Unlink dev from the device chain */ + netif_lists_lock(net); write_lock_bh(&dev_base_lock); list_del_rcu(&dev->dev_list); netdev_name_node_del(dev->name_node); hlist_del_rcu(&dev->index_hlist); write_unlock_bh(&dev_base_lock); + netif_lists_unlock(net); - dev_base_seq_inc(dev_net(dev)); + dev_base_seq_inc(net); } /* @@ -850,11 +859,11 @@ EXPORT_SYMBOL_GPL(dev_fill_metadata_dst); * @net: the applicable net namespace * @name: name to find * - * Find an interface by name. Must be called under RTNL semaphore - * or @dev_base_lock. If the name is found a pointer to the device - * is returned. If the name is not found then %NULL is returned. The - * reference counters are not incremented so the caller must be - * careful with locks. + * Find an interface by name. Must be called under RTNL semaphore, + * @net->netif_lists_lock or @dev_base_lock. If the name is found, + * a pointer to the device is returned. If the name is not found then + * %NULL is returned. The reference counters are not incremented so the + * caller must be careful with locks. */ struct net_device *__dev_get_by_name(struct net *net, const char *name) @@ -920,8 +929,8 @@ EXPORT_SYMBOL(dev_get_by_name); * Search for an interface by index. Returns %NULL if the device * is not found or a pointer to the device. The device has not * had its reference counter increased so the caller must be careful - * about locking. The caller must hold either the RTNL semaphore - * or @dev_base_lock. + * about locking. The caller must hold either the RTNL semaphore, + * @net->netif_lists_lock or @dev_base_lock. */ struct net_device *__dev_get_by_index(struct net *net, int ifindex) @@ -1330,15 +1339,19 @@ int dev_change_name(struct net_device *dev, const char *newname) netdev_adjacent_rename_links(dev, oldname); + netif_lists_lock(net); write_lock_bh(&dev_base_lock); netdev_name_node_del(dev->name_node); write_unlock_bh(&dev_base_lock); + netif_lists_unlock(net); synchronize_rcu(); + netif_lists_lock(net); write_lock_bh(&dev_base_lock); netdev_name_node_add(net, dev->name_node); write_unlock_bh(&dev_base_lock); + netif_lists_unlock(net); ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev); ret = notifier_to_errno(ret); @@ -9415,8 +9428,9 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, * @net: the applicable net namespace * * Returns a suitable unique value for a new device interface - * number. The caller must hold the rtnl semaphore or the - * dev_base_lock to be sure it remains unique. + * number. + * The caller must hold the rtnl semaphore, @net->netif_lists_lock or the + * @dev_base_lock to be sure it remains unique. */ static int dev_new_index(struct net *net) { @@ -10999,6 +11013,8 @@ static int __net_init netdev_init(struct net *net) if (net->dev_index_head == NULL) goto err_idx; + mutex_init(&net->netif_lists_lock); + RAW_INIT_NOTIFIER_HEAD(&net->netdev_chain); return 0; From patchwork Fri Jan 8 16:31:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359536 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 CFECAC43381 for ; Fri, 8 Jan 2021 16:33:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A733D238EC for ; Fri, 8 Jan 2021 16:33:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728346AbhAHQdG (ORCPT ); Fri, 8 Jan 2021 11:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727132AbhAHQdF (ORCPT ); Fri, 8 Jan 2021 11:33:05 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772BDC06129C for ; Fri, 8 Jan 2021 08:32:25 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id r5so11715072eda.12 for ; Fri, 08 Jan 2021 08:32:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+vm+7xbZC0uXlRy64slHngow5lwfLKRAZrJ2gjlNLBs=; b=d9H31afCy25mPtswkMUumNK9DRMLwDIRNGL52Qqol3rHq+pBUMeZgyGYoXlx3GhjEZ p9vm4bXSNyTHJJwDnJNfiY2KiMOFguU30Hgv85V01LDN8tqWDWRyK2h9UlyfUl7PSjET FFl5ktZVf1PDPf8SlfkASVCLAdnaAfpXBplNuDxzRbKDpxrAXH1K5oZuRp+NKUFadV7Q PUj94I+BGNdqg7p7g/L4+Q+VigZ3zZLAdBIxSXH5rv1nJUcELHP0y+tf72FLum2sBZUk R6ytM4+UsfMVHL7qUXDJfqTIr/cDSOCWIKS2kaTel13CU/yOVFvLyd6EsjqiEceQz4Jz E6PQ== 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:content-transfer-encoding; bh=+vm+7xbZC0uXlRy64slHngow5lwfLKRAZrJ2gjlNLBs=; b=d4R11+CMxYHMcyE0dgH4y27vw6WW+N5DfqtT3cJ7GaN2lZmDUEJ3iBf9vl+zSuW6UN 8o7lMCV/Eh7cJmBFD2F1p5csupCfCfWwBXtKkwXfC/l8z/tINm7gyXiRxZ8PGF1u/dbh gD+IT2DhBhV3jcoxN5y1RcqtgW3H9trddkALP2Q8fn949JxVOT8603om1dXg18sw3WK0 AJGizb7gsnIgD/vSNz4WNtkIBxbN1OdaEhiBQf5BLlmcYFHFBx2v948Q3WlZtZyzGTqu 586A09MFmScVHn/O7P4rn7vyB6UiigVTVdoy1NSYWPBaWgHZBsNwYB/cGt4NUgtXtg1j G6pQ== X-Gm-Message-State: AOAM5308u4AMENAhZoJxjhVxi/CXo7tDPoxTTgfxjDYP1XnsFY6spJ0e +/ubJr0pWKTu2Tz2WHYM9vw= X-Google-Smtp-Source: ABdhPJyormt5o0A+jnHndbROltikWg332ybxXaGgTlC/uYmV/mczHDvPU9uN6Z//WjozwwNhRqiMTA== X-Received: by 2002:a50:d4d9:: with SMTP id e25mr5907064edj.243.1610123544152; Fri, 08 Jan 2021 08:32:24 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id x6sm3957737edl.67.2021.01.08.08.32.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:32:23 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala , Saeed Mahameed Subject: [PATCH v5 net-next 04/16] net: sysfs: don't hold dev_base_lock while retrieving device statistics Date: Fri, 8 Jan 2021 18:31:47 +0200 Message-Id: <20210108163159.358043-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108163159.358043-1-olteanv@gmail.com> References: <20210108163159.358043-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean In the effort of making .ndo_get_stats64 be able to sleep, we need to ensure the callers of dev_get_stats do not use atomic context. I need to preface this by saying that I have no idea why netstat_show takes the dev_base_lock rwlock. Two things can be observed: (a) it does not appear to be due to dev_isalive requiring it for some reason, because broadcast_show() also calls dev_isalive() and has had no problem existing since the beginning of git. (b) the dev_get_stats function definitely does not need dev_base_lock protection either. In fact, holding the dev_base_lock is the entire problem here, because we want to make dev_get_stats sleepable, and holding a rwlock gives us atomic context. So since no protection seems to be necessary, just run unlocked while retrieving the /sys/class/net/eth0/statistics/* values. Cc: Christian Brauner Cc: Eric Dumazet Signed-off-by: Vladimir Oltean --- Changes in v5: None. Changes in v4: None. Changes in v3: None. Changes in v2: None. net/core/net-sysfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index daf502c13d6d..8604183678fc 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -585,14 +585,13 @@ static ssize_t netstat_show(const struct device *d, WARN_ON(offset > sizeof(struct rtnl_link_stats64) || offset % sizeof(u64) != 0); - read_lock(&dev_base_lock); if (dev_isalive(dev)) { struct rtnl_link_stats64 temp; const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset)); } - read_unlock(&dev_base_lock); + return ret; } From patchwork Fri Jan 8 16:31:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359534 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 9F5B9C43333 for ; Fri, 8 Jan 2021 16:33:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7771D238EC for ; Fri, 8 Jan 2021 16:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728387AbhAHQdS (ORCPT ); Fri, 8 Jan 2021 11:33:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728367AbhAHQdP (ORCPT ); Fri, 8 Jan 2021 11:33:15 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 885DBC06129F for ; Fri, 8 Jan 2021 08:32:31 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id ce23so15273861ejb.8 for ; Fri, 08 Jan 2021 08:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Txs71qFcti7jW5li5cu6lszM23fwsuzTg8OlUoo2SPU=; b=jVib4MJqrtlos5hLYVM8MpeD4yCCP7u48WnoiB7y9AwxLitZ65/8HKbX0Gy/+yOApj Dt+2Iyg6NrmujsceAJpoY0RkVh9N/1knNhTOnsxC1adH864k7odNsYggulOtzuYHFM4p QVdRcI4YLMWbqFotmzCtyQxd6vYQFlfnEUYzdhsRfGxj18nEpImD6ihKVGm1cXfoe8iq k6RWwZlZ7VtTRRf1Pc3U4BHBOOOuaudlHaBeUPQVDekJyXyB0hwDw6j3IuWaynlyyrAZ j2Lvqthm6NxekwwF+5o/JKvGkF5r55TgEkoGbHOGWbmxhDx3xmjH1TUU0wVZ7p2gN2lG QXtQ== 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:content-transfer-encoding; bh=Txs71qFcti7jW5li5cu6lszM23fwsuzTg8OlUoo2SPU=; b=tzXzoo02m9l8ikEds2azYsnU9+thvxolmxCO3jGKYiUBsj1Q94EMQslc4iN/OnnHuU JUFG26ikS1isZF0PG1bePv7WHKJCSF/DjIFkIkKkeFMtocFwFujs1CXtX2vC57GRtI7o N2RV8qg7G0T12o/rZwns97QKp4RI+Yog6It38Dz9/HDTV3r8IOIbOWgDJzHLdeC+ofNh BhYxLgVxKKWKF3mNetw3lJaMOIZRiZGLR8cYz3IjsmGKI2Dc8/QR7dZhmgDDy6jjGvl7 2DZlMH0TCD9WkVB96pxzUEtcj+BZJFUoWyx73Qypcc4HgCuWMQkAFTS6E+3sYTBwofMD AMbw== X-Gm-Message-State: AOAM533HKkyoJrq1mhcklkOZvyAmv5XDVjIG850Afq8P8X48cJh7Sy0l vx1suSeqGlvpyKK5EP1PMqnYJZ31LYs= X-Google-Smtp-Source: ABdhPJz7GZB7eH+YN4XrocQ6VZwneIT2r2gUQpOoY8aHY2tN0HSk8tOjB6EKOsdt822KMlxX4sVrPA== X-Received: by 2002:a17:906:fcda:: with SMTP id qx26mr3180920ejb.213.1610123549059; Fri, 08 Jan 2021 08:32:29 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id x6sm3957737edl.67.2021.01.08.08.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:32:28 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala , Saeed Mahameed Subject: [PATCH v5 net-next 07/16] net: remove return value from dev_get_stats Date: Fri, 8 Jan 2021 18:31:50 +0200 Message-Id: <20210108163159.358043-8-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108163159.358043-1-olteanv@gmail.com> References: <20210108163159.358043-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean After commit 28172739f0a2 ("net: fix 64 bit counters on 32 bit arches"), dev_get_stats got an additional argument for storage of statistics. At this point, dev_get_stats could return either the passed "storage" argument, or the output of .ndo_get_stats64. Then commit caf586e5f23c ("net: add a core netdev->rx_dropped counter") came, and the output of .ndo_get_stats64 (still returning a pointer to struct rtnl_link_stats64) started being ignored. Then came commit bc1f44709cf2 ("net: make ndo_get_stats64 a void function") which made .ndo_get_stats64 stop returning anything. So now, dev_get_stats always reports the "storage" pointer received as argument. This is useless. Some drivers are dealing with unnecessary complexity due to this, using another pointer to poke around the returned statistics, when they can do that directly through the stack-allocated struct rtnl_link_stats64. Refactor these callers to ignore the return value completely and just access the values from their struct rtnl_link_stats64 local variable. Signed-off-by: Vladimir Oltean --- Changes in v5: - Renamed "stats" to "dev_stats" in fcoe_transport.c. - Slightly reworded the commit title and message. Changes in v4: None. Changes in v3: None. Changes in v2: Patch is new. arch/s390/appldata/appldata_net_sum.c | 25 +++++---- drivers/leds/trigger/ledtrig-netdev.c | 9 ++-- drivers/net/bonding/bond_main.c | 7 ++- .../net/ethernet/hisilicon/hns/hns_ethtool.c | 51 +++++++++---------- .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 7 ++- drivers/net/ethernet/intel/ixgbevf/ethtool.c | 7 ++- drivers/net/net_failover.c | 13 +++-- drivers/parisc/led.c | 9 ++-- drivers/scsi/fcoe/fcoe_transport.c | 6 +-- drivers/usb/gadget/function/rndis.c | 45 ++++++---------- include/linux/netdevice.h | 3 +- net/8021q/vlanproc.c | 15 +++--- net/core/dev.c | 6 +-- net/core/net-procfs.c | 35 ++++++------- net/core/net-sysfs.c | 7 +-- net/openvswitch/vport.c | 25 +++++---- 16 files changed, 123 insertions(+), 147 deletions(-) diff --git a/arch/s390/appldata/appldata_net_sum.c b/arch/s390/appldata/appldata_net_sum.c index 4db886980cba..6146606ac9a3 100644 --- a/arch/s390/appldata/appldata_net_sum.c +++ b/arch/s390/appldata/appldata_net_sum.c @@ -81,19 +81,18 @@ static void appldata_get_net_sum_data(void *data) netif_lists_lock(&init_net); for_each_netdev(&init_net, dev) { - const struct rtnl_link_stats64 *stats; - struct rtnl_link_stats64 temp; - - stats = dev_get_stats(dev, &temp); - rx_packets += stats->rx_packets; - tx_packets += stats->tx_packets; - rx_bytes += stats->rx_bytes; - tx_bytes += stats->tx_bytes; - rx_errors += stats->rx_errors; - tx_errors += stats->tx_errors; - rx_dropped += stats->rx_dropped; - tx_dropped += stats->tx_dropped; - collisions += stats->collisions; + struct rtnl_link_stats64 stats; + + dev_get_stats(dev, &stats); + rx_packets += stats.rx_packets; + tx_packets += stats.tx_packets; + rx_bytes += stats.rx_bytes; + tx_bytes += stats.tx_bytes; + rx_errors += stats.rx_errors; + tx_errors += stats.tx_errors; + rx_dropped += stats.rx_dropped; + tx_dropped += stats.tx_dropped; + collisions += stats.collisions; i++; } diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index d5e774d83021..4382ee278309 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -347,9 +347,8 @@ static void netdev_trig_work(struct work_struct *work) { struct led_netdev_data *trigger_data = container_of(work, struct led_netdev_data, work.work); - struct rtnl_link_stats64 *dev_stats; + struct rtnl_link_stats64 dev_stats; unsigned int new_activity; - struct rtnl_link_stats64 temp; unsigned long interval; int invert; @@ -364,12 +363,12 @@ static void netdev_trig_work(struct work_struct *work) !test_bit(NETDEV_LED_RX, &trigger_data->mode)) return; - dev_stats = dev_get_stats(trigger_data->net_dev, &temp); + dev_get_stats(trigger_data->net_dev, &dev_stats); new_activity = (test_bit(NETDEV_LED_TX, &trigger_data->mode) ? - dev_stats->tx_packets : 0) + + dev_stats.tx_packets : 0) + (test_bit(NETDEV_LED_RX, &trigger_data->mode) ? - dev_stats->rx_packets : 0); + dev_stats.rx_packets : 0); if (trigger_data->last_activity != new_activity) { led_stop_software_blink(trigger_data->led_cdev); diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 5fe5232cc3f3..714aa0e5d041 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -3753,13 +3753,12 @@ static void bond_get_stats(struct net_device *bond_dev, memcpy(stats, &bond->bond_stats, sizeof(*stats)); bond_for_each_slave_rcu(bond, slave, iter) { - const struct rtnl_link_stats64 *new = - dev_get_stats(slave->dev, &temp); + dev_get_stats(slave->dev, &temp); - bond_fold_stats(stats, new, &slave->slave_stats); + bond_fold_stats(stats, &temp, &slave->slave_stats); /* save off the slave stats for the next run */ - memcpy(&slave->slave_stats, new, sizeof(*new)); + memcpy(&slave->slave_stats, &temp, sizeof(temp)); } memcpy(&bond->bond_stats, stats, sizeof(*stats)); diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c index a6e3f07caf99..ee2172011051 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c @@ -839,8 +839,7 @@ static void hns_get_ethtool_stats(struct net_device *netdev, u64 *p = data; struct hns_nic_priv *priv = netdev_priv(netdev); struct hnae_handle *h = priv->ae_handle; - const struct rtnl_link_stats64 *net_stats; - struct rtnl_link_stats64 temp; + struct rtnl_link_stats64 net_stats; if (!h->dev->ops->get_stats || !h->dev->ops->update_stats) { netdev_err(netdev, "get_stats or update_stats is null!\n"); @@ -849,32 +848,32 @@ static void hns_get_ethtool_stats(struct net_device *netdev, h->dev->ops->update_stats(h, &netdev->stats); - net_stats = dev_get_stats(netdev, &temp); + dev_get_stats(netdev, &net_stats); /* get netdev statistics */ - p[0] = net_stats->rx_packets; - p[1] = net_stats->tx_packets; - p[2] = net_stats->rx_bytes; - p[3] = net_stats->tx_bytes; - p[4] = net_stats->rx_errors; - p[5] = net_stats->tx_errors; - p[6] = net_stats->rx_dropped; - p[7] = net_stats->tx_dropped; - p[8] = net_stats->multicast; - p[9] = net_stats->collisions; - p[10] = net_stats->rx_over_errors; - p[11] = net_stats->rx_crc_errors; - p[12] = net_stats->rx_frame_errors; - p[13] = net_stats->rx_fifo_errors; - p[14] = net_stats->rx_missed_errors; - p[15] = net_stats->tx_aborted_errors; - p[16] = net_stats->tx_carrier_errors; - p[17] = net_stats->tx_fifo_errors; - p[18] = net_stats->tx_heartbeat_errors; - p[19] = net_stats->rx_length_errors; - p[20] = net_stats->tx_window_errors; - p[21] = net_stats->rx_compressed; - p[22] = net_stats->tx_compressed; + p[0] = net_stats.rx_packets; + p[1] = net_stats.tx_packets; + p[2] = net_stats.rx_bytes; + p[3] = net_stats.tx_bytes; + p[4] = net_stats.rx_errors; + p[5] = net_stats.tx_errors; + p[6] = net_stats.rx_dropped; + p[7] = net_stats.tx_dropped; + p[8] = net_stats.multicast; + p[9] = net_stats.collisions; + p[10] = net_stats.rx_over_errors; + p[11] = net_stats.rx_crc_errors; + p[12] = net_stats.rx_frame_errors; + p[13] = net_stats.rx_fifo_errors; + p[14] = net_stats.rx_missed_errors; + p[15] = net_stats.tx_aborted_errors; + p[16] = net_stats.tx_carrier_errors; + p[17] = net_stats.tx_fifo_errors; + p[18] = net_stats.tx_heartbeat_errors; + p[19] = net_stats.rx_length_errors; + p[20] = net_stats.tx_window_errors; + p[21] = net_stats.rx_compressed; + p[22] = net_stats.tx_compressed; p[23] = netdev->rx_dropped.counter; p[24] = netdev->tx_dropped.counter; diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c index a280aa34ca1d..2b8084664403 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c @@ -1295,19 +1295,18 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { struct ixgbe_adapter *adapter = netdev_priv(netdev); - struct rtnl_link_stats64 temp; - const struct rtnl_link_stats64 *net_stats; + struct rtnl_link_stats64 net_stats; unsigned int start; struct ixgbe_ring *ring; int i, j; char *p = NULL; ixgbe_update_stats(adapter); - net_stats = dev_get_stats(netdev, &temp); + dev_get_stats(netdev, &net_stats); for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { switch (ixgbe_gstrings_stats[i].type) { case NETDEV_STATS: - p = (char *) net_stats + + p = (char *) &net_stats + ixgbe_gstrings_stats[i].stat_offset; break; case IXGBE_STATS: diff --git a/drivers/net/ethernet/intel/ixgbevf/ethtool.c b/drivers/net/ethernet/intel/ixgbevf/ethtool.c index e49fb1cd9a99..3b9b7e5c2998 100644 --- a/drivers/net/ethernet/intel/ixgbevf/ethtool.c +++ b/drivers/net/ethernet/intel/ixgbevf/ethtool.c @@ -420,19 +420,18 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { struct ixgbevf_adapter *adapter = netdev_priv(netdev); - struct rtnl_link_stats64 temp; - const struct rtnl_link_stats64 *net_stats; + struct rtnl_link_stats64 net_stats; unsigned int start; struct ixgbevf_ring *ring; int i, j; char *p; ixgbevf_update_stats(adapter); - net_stats = dev_get_stats(netdev, &temp); + dev_get_stats(netdev, &net_stats); for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) { switch (ixgbevf_gstrings_stats[i].type) { case NETDEV_STATS: - p = (char *)net_stats + + p = (char *)&net_stats + ixgbevf_gstrings_stats[i].stat_offset; break; case IXGBEVF_STATS: diff --git a/drivers/net/net_failover.c b/drivers/net/net_failover.c index 2a4892402ed8..4f83165412bd 100644 --- a/drivers/net/net_failover.c +++ b/drivers/net/net_failover.c @@ -183,7 +183,6 @@ static void net_failover_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) { struct net_failover_info *nfo_info = netdev_priv(dev); - const struct rtnl_link_stats64 *new; struct rtnl_link_stats64 temp; struct net_device *slave_dev; @@ -194,16 +193,16 @@ static void net_failover_get_stats(struct net_device *dev, slave_dev = rcu_dereference(nfo_info->primary_dev); if (slave_dev) { - new = dev_get_stats(slave_dev, &temp); - net_failover_fold_stats(stats, new, &nfo_info->primary_stats); - memcpy(&nfo_info->primary_stats, new, sizeof(*new)); + dev_get_stats(slave_dev, &temp); + net_failover_fold_stats(stats, &temp, &nfo_info->primary_stats); + memcpy(&nfo_info->primary_stats, &temp, sizeof(temp)); } slave_dev = rcu_dereference(nfo_info->standby_dev); if (slave_dev) { - new = dev_get_stats(slave_dev, &temp); - net_failover_fold_stats(stats, new, &nfo_info->standby_stats); - memcpy(&nfo_info->standby_stats, new, sizeof(*new)); + dev_get_stats(slave_dev, &temp); + net_failover_fold_stats(stats, &temp, &nfo_info->standby_stats); + memcpy(&nfo_info->standby_stats, &temp, sizeof(temp)); } rcu_read_unlock(); diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c index c8c6b2301dc9..cc6108785323 100644 --- a/drivers/parisc/led.c +++ b/drivers/parisc/led.c @@ -360,8 +360,7 @@ static __inline__ int led_get_net_activity(void) for_each_netdev(&init_net, dev) { struct in_device *in_dev = in_dev_get(dev); - const struct rtnl_link_stats64 *stats; - struct rtnl_link_stats64 temp; + struct rtnl_link_stats64 stats; if (!in_dev || !in_dev->ifa_list || ipv4_is_loopback(in_dev->ifa_list->ifa_local)) { @@ -371,9 +370,9 @@ static __inline__ int led_get_net_activity(void) in_dev_put(in_dev); - stats = dev_get_stats(dev, &temp); - rx_total += stats->rx_packets; - tx_total += stats->tx_packets; + dev_get_stats(dev, &stats); + rx_total += stats.rx_packets; + tx_total += stats.tx_packets; } netif_lists_unlock(&init_net); diff --git a/drivers/scsi/fcoe/fcoe_transport.c b/drivers/scsi/fcoe/fcoe_transport.c index b927b3d84523..213ee9efb044 100644 --- a/drivers/scsi/fcoe/fcoe_transport.c +++ b/drivers/scsi/fcoe/fcoe_transport.c @@ -170,11 +170,11 @@ void __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb, struct net_device *netdev) { + struct rtnl_link_stats64 dev_stats; unsigned int cpu; u32 lfc, vlfc, mdac; struct fc_stats *stats; struct fcoe_fc_els_lesb *lesb; - struct rtnl_link_stats64 temp; lfc = 0; vlfc = 0; @@ -190,8 +190,8 @@ void __fcoe_get_lesb(struct fc_lport *lport, lesb->lesb_link_fail = htonl(lfc); lesb->lesb_vlink_fail = htonl(vlfc); lesb->lesb_miss_fka = htonl(mdac); - lesb->lesb_fcs_error = - htonl(dev_get_stats(netdev, &temp)->rx_crc_errors); + dev_get_stats(netdev, &dev_stats); + lesb->lesb_fcs_error = htonl(dev_stats.rx_crc_errors); } EXPORT_SYMBOL_GPL(__fcoe_get_lesb); diff --git a/drivers/usb/gadget/function/rndis.c b/drivers/usb/gadget/function/rndis.c index 64de9f1b874c..7ec29e007ae9 100644 --- a/drivers/usb/gadget/function/rndis.c +++ b/drivers/usb/gadget/function/rndis.c @@ -169,14 +169,13 @@ static const u32 oid_supported_list[] = { static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf, unsigned buf_len, rndis_resp_t *r) { + struct rtnl_link_stats64 stats; int retval = -ENOTSUPP; u32 length = 4; /* usually */ __le32 *outbuf; int i, count; rndis_query_cmplt_type *resp; struct net_device *net; - struct rtnl_link_stats64 temp; - const struct rtnl_link_stats64 *stats; if (!r) return -ENOMEM; resp = (rndis_query_cmplt_type *)r->buf; @@ -199,7 +198,7 @@ static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf, resp->InformationBufferOffset = cpu_to_le32(16); net = params->dev; - stats = dev_get_stats(net, &temp); + dev_get_stats(net, &stats); switch (OID) { @@ -353,51 +352,41 @@ static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf, case RNDIS_OID_GEN_XMIT_OK: if (rndis_debug > 1) pr_debug("%s: RNDIS_OID_GEN_XMIT_OK\n", __func__); - if (stats) { - *outbuf = cpu_to_le32(stats->tx_packets - - stats->tx_errors - stats->tx_dropped); - retval = 0; - } + *outbuf = cpu_to_le32(stats.tx_packets - stats.tx_errors - + stats.tx_dropped); + retval = 0; break; /* mandatory */ case RNDIS_OID_GEN_RCV_OK: if (rndis_debug > 1) pr_debug("%s: RNDIS_OID_GEN_RCV_OK\n", __func__); - if (stats) { - *outbuf = cpu_to_le32(stats->rx_packets - - stats->rx_errors - stats->rx_dropped); - retval = 0; - } + *outbuf = cpu_to_le32(stats.rx_packets - stats.rx_errors - + stats.rx_dropped); + retval = 0; break; /* mandatory */ case RNDIS_OID_GEN_XMIT_ERROR: if (rndis_debug > 1) pr_debug("%s: RNDIS_OID_GEN_XMIT_ERROR\n", __func__); - if (stats) { - *outbuf = cpu_to_le32(stats->tx_errors); - retval = 0; - } + *outbuf = cpu_to_le32(stats.tx_errors); + retval = 0; break; /* mandatory */ case RNDIS_OID_GEN_RCV_ERROR: if (rndis_debug > 1) pr_debug("%s: RNDIS_OID_GEN_RCV_ERROR\n", __func__); - if (stats) { - *outbuf = cpu_to_le32(stats->rx_errors); - retval = 0; - } + *outbuf = cpu_to_le32(stats.rx_errors); + retval = 0; break; /* mandatory */ case RNDIS_OID_GEN_RCV_NO_BUFFER: pr_debug("%s: RNDIS_OID_GEN_RCV_NO_BUFFER\n", __func__); - if (stats) { - *outbuf = cpu_to_le32(stats->rx_dropped); - retval = 0; - } + *outbuf = cpu_to_le32(stats.rx_dropped); + retval = 0; break; /* ieee802.3 OIDs (table 4-3) */ @@ -449,10 +438,8 @@ static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf, /* mandatory */ case RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT: pr_debug("%s: RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); - if (stats) { - *outbuf = cpu_to_le32(stats->rx_frame_errors); - retval = 0; - } + *outbuf = cpu_to_le32(stats.rx_frame_errors); + retval = 0; break; /* mandatory */ diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 8aae2386bd37..9faaacbfe45a 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4545,8 +4545,7 @@ void netdev_notify_peers(struct net_device *dev); void netdev_features_change(struct net_device *dev); /* Load a device via the kmod */ void dev_load(struct net *net, const char *name); -struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, - struct rtnl_link_stats64 *storage); +void dev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage); void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, const struct net_device_stats *netdev_stats); void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s, diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c index ec87dea23719..3a6682d79630 100644 --- a/net/8021q/vlanproc.c +++ b/net/8021q/vlanproc.c @@ -242,26 +242,25 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset) { struct net_device *vlandev = (struct net_device *) seq->private; const struct vlan_dev_priv *vlan = vlan_dev_priv(vlandev); - struct rtnl_link_stats64 temp; - const struct rtnl_link_stats64 *stats; static const char fmt64[] = "%30s %12llu\n"; + struct rtnl_link_stats64 stats; int i; if (!is_vlan_dev(vlandev)) return 0; - stats = dev_get_stats(vlandev, &temp); + dev_get_stats(vlandev, &stats); seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n", vlandev->name, vlan->vlan_id, (int)(vlan->flags & 1), vlandev->priv_flags); - seq_printf(seq, fmt64, "total frames received", stats->rx_packets); - seq_printf(seq, fmt64, "total bytes received", stats->rx_bytes); - seq_printf(seq, fmt64, "Broadcast/Multicast Rcvd", stats->multicast); + seq_printf(seq, fmt64, "total frames received", stats.rx_packets); + seq_printf(seq, fmt64, "total bytes received", stats.rx_bytes); + seq_printf(seq, fmt64, "Broadcast/Multicast Rcvd", stats.multicast); seq_puts(seq, "\n"); - seq_printf(seq, fmt64, "total frames transmitted", stats->tx_packets); - seq_printf(seq, fmt64, "total bytes transmitted", stats->tx_bytes); + seq_printf(seq, fmt64, "total frames transmitted", stats.tx_packets); + seq_printf(seq, fmt64, "total bytes transmitted", stats.tx_bytes); seq_printf(seq, "Device: %s", vlan->real_dev->name); /* now show all PRIORITY mappings relating to this VLAN */ seq_printf(seq, "\nINGRESS priority mappings: " diff --git a/net/core/dev.c b/net/core/dev.c index 53c12f92025c..2b423d7a39e7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10398,13 +10398,12 @@ EXPORT_SYMBOL(netdev_stats_to_stats64); * @dev: device to get statistics from * @storage: place to store stats * - * Get network statistics from device. Return @storage. + * Get network statistics from device. * The device driver may provide its own method by setting * dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats; * otherwise the internal statistics structure is used. */ -struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, - struct rtnl_link_stats64 *storage) +void dev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage) { const struct net_device_ops *ops = dev->netdev_ops; @@ -10419,7 +10418,6 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, storage->rx_dropped += (unsigned long)atomic_long_read(&dev->rx_dropped); storage->tx_dropped += (unsigned long)atomic_long_read(&dev->tx_dropped); storage->rx_nohandler += (unsigned long)atomic_long_read(&dev->rx_nohandler); - return storage; } EXPORT_SYMBOL(dev_get_stats); diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c index 4784703c1e39..64666ba7ccab 100644 --- a/net/core/net-procfs.c +++ b/net/core/net-procfs.c @@ -80,26 +80,27 @@ static void dev_seq_stop(struct seq_file *seq, void *v) static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) { - struct rtnl_link_stats64 temp; - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); + struct rtnl_link_stats64 stats; + + dev_get_stats(dev, &stats); seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu " "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n", - dev->name, stats->rx_bytes, stats->rx_packets, - stats->rx_errors, - stats->rx_dropped + stats->rx_missed_errors, - stats->rx_fifo_errors, - stats->rx_length_errors + stats->rx_over_errors + - stats->rx_crc_errors + stats->rx_frame_errors, - stats->rx_compressed, stats->multicast, - stats->tx_bytes, stats->tx_packets, - stats->tx_errors, stats->tx_dropped, - stats->tx_fifo_errors, stats->collisions, - stats->tx_carrier_errors + - stats->tx_aborted_errors + - stats->tx_window_errors + - stats->tx_heartbeat_errors, - stats->tx_compressed); + dev->name, stats.rx_bytes, stats.rx_packets, + stats.rx_errors, + stats.rx_dropped + stats.rx_missed_errors, + stats.rx_fifo_errors, + stats.rx_length_errors + stats.rx_over_errors + + stats.rx_crc_errors + stats.rx_frame_errors, + stats.rx_compressed, stats.multicast, + stats.tx_bytes, stats.tx_packets, + stats.tx_errors, stats.tx_dropped, + stats.tx_fifo_errors, stats.collisions, + stats.tx_carrier_errors + + stats.tx_aborted_errors + + stats.tx_window_errors + + stats.tx_heartbeat_errors, + stats.tx_compressed); } /* diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 8604183678fc..5d89c85b42d4 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -586,10 +586,11 @@ static ssize_t netstat_show(const struct device *d, offset % sizeof(u64) != 0); if (dev_isalive(dev)) { - struct rtnl_link_stats64 temp; - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); + struct rtnl_link_stats64 stats; - ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)stats) + offset)); + dev_get_stats(dev, &stats); + + ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *)&stats) + offset)); } return ret; diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c index 4ed7e52c7012..215a818bf9ce 100644 --- a/net/openvswitch/vport.c +++ b/net/openvswitch/vport.c @@ -269,19 +269,18 @@ void ovs_vport_del(struct vport *vport) */ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats) { - const struct rtnl_link_stats64 *dev_stats; - struct rtnl_link_stats64 temp; - - dev_stats = dev_get_stats(vport->dev, &temp); - stats->rx_errors = dev_stats->rx_errors; - stats->tx_errors = dev_stats->tx_errors; - stats->tx_dropped = dev_stats->tx_dropped; - stats->rx_dropped = dev_stats->rx_dropped; - - stats->rx_bytes = dev_stats->rx_bytes; - stats->rx_packets = dev_stats->rx_packets; - stats->tx_bytes = dev_stats->tx_bytes; - stats->tx_packets = dev_stats->tx_packets; + struct rtnl_link_stats64 dev_stats; + + dev_get_stats(vport->dev, &dev_stats); + stats->rx_errors = dev_stats.rx_errors; + stats->tx_errors = dev_stats.tx_errors; + stats->tx_dropped = dev_stats.tx_dropped; + stats->rx_dropped = dev_stats.rx_dropped; + + stats->rx_bytes = dev_stats.rx_bytes; + stats->rx_packets = dev_stats.rx_packets; + stats->tx_bytes = dev_stats.tx_bytes; + stats->tx_packets = dev_stats.tx_packets; } /** From patchwork Fri Jan 8 16:31:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359533 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 13BF5C433E0 for ; Fri, 8 Jan 2021 16:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2ADD23A01 for ; Fri, 8 Jan 2021 16:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728466AbhAHQdr (ORCPT ); Fri, 8 Jan 2021 11:33:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728092AbhAHQdk (ORCPT ); Fri, 8 Jan 2021 11:33:40 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7756C0612A5 for ; Fri, 8 Jan 2021 08:32:35 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id d17so15258686ejy.9 for ; Fri, 08 Jan 2021 08:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZD9IDARfyDQAfyn8rtiOrhgy3CFrtxmODytn6yLlrbk=; b=KN216R5AczqiSIVIBS2LKw93x5U+0mjmySlOiqpwFX9SVu2mnKRnmF2NJpOrli7fcF 4iMrATULZsh+LTJFLmX6DOVifGnn7DOb38g70Tqaxbw7hgemEbKieV4LAnOlOtJGxhNo RoznfjKPP4pAUgBlrDXEwKNhKcfrJ5yJEGZT78S8EfzdwUz2r10KRo3JDxDxb4xXnGMX FEMQloFy5c/aEkm2YwPKowZZjrX2X9iyiDWpn/wHhMxya7b8iCziIvVwhhIn0woLnCiZ 8/Q5GWBawXDo2xryIKcl/TK+82bdQsR15GDvhmua/8Tx/1kA1rBci83/opC1e4CjNvmV Eekg== 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:content-transfer-encoding; bh=ZD9IDARfyDQAfyn8rtiOrhgy3CFrtxmODytn6yLlrbk=; b=tIKqMG2i6vbHqAcL4LEAqNBDC8L96lSB91rN16p4QlX2/vYn6Oo7qfU9zD1Wp3pG7v GOaHTC00AGT+D1LAdDgal2Bgnrc11NCmdBM4x4QiHZcgAVVyeJZlt0TmlpVu6dM4VeHA UvWqmJ1XkOaqzXoXtmubwRq6SC0ulXu/6t0oBv3yMb4oHHA3qU4bLLZtnWgc5ZtZKVH9 OO6UoL/fAnkuAUFMs9EsdEMFzrT1bjgkoLfX/uE/Dh1QwX+eaQA6Gkd+UFA2UMDYbReu v0N3VOPLzD4VA721WNunwJgEVQHw03SKiqN6jaMuIA8SFc2ixY6dt8dOLoiygwINTrN9 gSog== X-Gm-Message-State: AOAM533hBBH2Vy/14Fto8Zevc2BCv8yDuSLaVDlZG8oBGTQG2+2Xv4pX XGixUVhs0y2p/PsVYq1b0wU= X-Google-Smtp-Source: ABdhPJxIP9nkmlXPaZ23g8dkFkpmBG3t8QKvWdSr7wd+IrIPthBdY+Qq5nwZfHqxJWDXbS2+25jkKw== X-Received: by 2002:a17:906:1f8e:: with SMTP id t14mr3232503ejr.350.1610123554359; Fri, 08 Jan 2021 08:32:34 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id x6sm3957737edl.67.2021.01.08.08.32.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:32:33 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala , Saeed Mahameed Subject: [PATCH v5 net-next 10/16] net: openvswitch: propagate errors from dev_get_stats Date: Fri, 8 Jan 2021 18:31:53 +0200 Message-Id: <20210108163159.358043-11-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108163159.358043-1-olteanv@gmail.com> References: <20210108163159.358043-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The dev_get_stats function can now return an error code, so the code that retrieves vport statistics and sends them through netlink needs to propagate that error code. Modify the drastic BUG_ON checks to operate only on the -EMSGSIZE error code (the only error code previously possible), and not crash the kernel in case dev_get_stats fails. This is in line with what rtnetlink.c does. Signed-off-by: Vladimir Oltean --- Changes in v5: Still keeping the BUG_ON condition except for the output of ovs_vport_get_stats. Changes in v4: Patch is new (Eric's suggestion). net/openvswitch/datapath.c | 25 +++++++++++++++++++------ net/openvswitch/vport.c | 10 ++++++++-- net/openvswitch/vport.h | 2 +- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 9d6ef6cb9b26..160b8dc453da 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -1987,7 +1987,10 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, goto nla_put_failure; } - ovs_vport_get_stats(vport, &vport_stats); + err = ovs_vport_get_stats(vport, &vport_stats); + if (err) + goto error; + if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS, sizeof(struct ovs_vport_stats), &vport_stats, OVS_VPORT_ATTR_PAD)) @@ -2028,7 +2031,9 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, struct net *net, retval = ovs_vport_cmd_fill_info(vport, skb, net, portid, seq, 0, cmd, GFP_KERNEL); - BUG_ON(retval < 0); + BUG_ON(retval == -EMSGSIZE); + if (retval) + return ERR_PTR(retval); return skb; } @@ -2173,6 +2178,9 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, OVS_VPORT_CMD_NEW, GFP_KERNEL); + BUG_ON(err == -EMSGSIZE); + if (err) + goto exit_unlock_free; new_headroom = netdev_get_fwd_headroom(vport->dev); @@ -2181,7 +2189,6 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info) else netdev_set_rx_headroom(vport->dev, dp->max_headroom); - BUG_ON(err < 0); ovs_unlock(); ovs_notify(&dp_vport_genl_family, reply, info); @@ -2234,7 +2241,9 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info) err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, OVS_VPORT_CMD_SET, GFP_KERNEL); - BUG_ON(err < 0); + BUG_ON(err == -EMSGSIZE); + if (err) + goto exit_unlock_free; ovs_unlock(); ovs_notify(&dp_vport_genl_family, reply, info); @@ -2274,7 +2283,9 @@ static int ovs_vport_cmd_del(struct sk_buff *skb, struct genl_info *info) err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, OVS_VPORT_CMD_DEL, GFP_KERNEL); - BUG_ON(err < 0); + BUG_ON(err == -EMSGSIZE); + if (err) + goto exit_unlock_free; /* the vport deletion may trigger dp headroom update */ dp = vport->dp; @@ -2321,7 +2332,9 @@ static int ovs_vport_cmd_get(struct sk_buff *skb, struct genl_info *info) err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info), info->snd_portid, info->snd_seq, 0, OVS_VPORT_CMD_GET, GFP_ATOMIC); - BUG_ON(err < 0); + BUG_ON(err == -EMSGSIZE); + if (err) + goto exit_unlock_free; rcu_read_unlock(); return genlmsg_reply(reply, info); diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c index 215a818bf9ce..e66c949fd97a 100644 --- a/net/openvswitch/vport.c +++ b/net/openvswitch/vport.c @@ -267,11 +267,15 @@ void ovs_vport_del(struct vport *vport) * * Must be called with ovs_mutex or rcu_read_lock. */ -void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats) +int ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats) { struct rtnl_link_stats64 dev_stats; + int err; + + err = dev_get_stats(vport->dev, &dev_stats); + if (err) + return err; - dev_get_stats(vport->dev, &dev_stats); stats->rx_errors = dev_stats.rx_errors; stats->tx_errors = dev_stats.tx_errors; stats->tx_dropped = dev_stats.tx_dropped; @@ -281,6 +285,8 @@ void ovs_vport_get_stats(struct vport *vport, struct ovs_vport_stats *stats) stats->rx_packets = dev_stats.rx_packets; stats->tx_bytes = dev_stats.tx_bytes; stats->tx_packets = dev_stats.tx_packets; + + return 0; } /** diff --git a/net/openvswitch/vport.h b/net/openvswitch/vport.h index 1eb7495ac5b4..8927ba5c491b 100644 --- a/net/openvswitch/vport.h +++ b/net/openvswitch/vport.h @@ -30,7 +30,7 @@ void ovs_vport_del(struct vport *); struct vport *ovs_vport_locate(const struct net *net, const char *name); -void ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *); +int ovs_vport_get_stats(struct vport *, struct ovs_vport_stats *); int ovs_vport_set_options(struct vport *, struct nlattr *options); int ovs_vport_get_options(const struct vport *, struct sk_buff *); From patchwork Fri Jan 8 16:31:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359532 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 6DD96C433E9 for ; Fri, 8 Jan 2021 16:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3790F23A01 for ; Fri, 8 Jan 2021 16:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728429AbhAHQdp (ORCPT ); Fri, 8 Jan 2021 11:33:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727524AbhAHQdl (ORCPT ); Fri, 8 Jan 2021 11:33:41 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEAC1C0612A6 for ; Fri, 8 Jan 2021 08:32:38 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id g24so11746245edw.9 for ; Fri, 08 Jan 2021 08:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3vapg5N7Fc/ixtYN48myajBDkQucglPi1gl4RMw/uOI=; b=GuBNmA9bsECl9WIjoYWvjSe6H6Vifm0+m5J4NiJKSVDwS76ERpMfqj/8oLNCiLAgp3 ZQKv+uL9fRKk7U5k+ZIYVo398Ie53sF7DrH830sHDDSBr6NkwgSzf5cNdZ0yXXAm+8Sd EK4wTXjs7yS5P9O+WlNQXBBbH8I9V26e4SMyTlyHx53fgkDaYMW3xlRH7i1Xg31RHupD dOUKapjm0kg6dHz4JU0M+L9oHIbC4+ujdLB/oXKAx1mMgc1AQbM6uKNG1c417tJTNN5V zir+qMFwyOK84I4KDhIsfWURWfkOuqqofaufzklIzAsMwO7HpOG175fnBQUACbv+uhdO 3urQ== 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:content-transfer-encoding; bh=3vapg5N7Fc/ixtYN48myajBDkQucglPi1gl4RMw/uOI=; b=PHjPWXAaMaUoazF1r4Z49djQvFVUA0vRLMi1Py/wT0LlYRdQzCs0HJLlyhHf8u5P5i 4YpXe2UXpMEWInuyEzvSEoTWnpcynQ9OM5XMW+RCJ2pzbsnaR6Rwc8sZAf3qtK0o+Pr3 pLE6k0xtaHUTLm2fflvA8gXUIDy/kgYoIjNyJ2GMvchLaJ9cUTtzDBETppCfhF8OP4Dx 2E+SlH6FbYJJs+bbGvacInNkxc76OufyYRbt5J8Qar0k3FwZEYTJZnbE1DzOo72PqObr 9olYRWcsULch9NSf7/xtpUXReIrV3Ocs70Q2Y7Q+C5rvYo/NrS4S8rPYye7Oa59N1R5f f1hQ== X-Gm-Message-State: AOAM530GiX/P7xLqUdMqoG6Mb2nllmRMXocDSlvtiXDHE+QOchYBO90N /8A1+gA0uvgAd1FoseZkC6A= X-Google-Smtp-Source: ABdhPJydIEi8VyA1ddPJRarHxZevlzNr5EHnE5Sa0r9q+S3RVhSEJrvouJ51s32YKoQAa6Af3k2cyQ== X-Received: by 2002:a05:6402:1d18:: with SMTP id dg24mr5686580edb.221.1610123557521; Fri, 08 Jan 2021 08:32:37 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id x6sm3957737edl.67.2021.01.08.08.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:32:37 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala , Saeed Mahameed Subject: [PATCH v5 net-next 12/16] net: terminate errors from dev_get_stats Date: Fri, 8 Jan 2021 18:31:55 +0200 Message-Id: <20210108163159.358043-13-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108163159.358043-1-olteanv@gmail.com> References: <20210108163159.358043-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean dev_get_stats can now return errors. Some call sites are coming from a context that returns void (ethtool stats, workqueue context). So since we can't report to the upper layer, do the next best thing: shout. This patch wraps up the conversion of existing dev_get_stats callers, so we can add the __must_check attribute now to ensure that future callers keep doing this too. Signed-off-by: Vladimir Oltean --- Changes in v5: Added the __must_check to dev_get_stats. Changes in v4: Patch is new (Eric's suggestion). arch/s390/appldata/appldata_net_sum.c | 10 ++++++++-- drivers/leds/trigger/ledtrig-netdev.c | 9 ++++++++- drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c | 9 +++++++-- drivers/net/ethernet/hisilicon/hns/hns_ethtool.c | 7 ++++++- drivers/net/ethernet/intel/e1000e/ethtool.c | 9 +++++++-- drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c | 9 +++++++-- drivers/net/ethernet/intel/ixgbevf/ethtool.c | 9 +++++++-- include/linux/netdevice.h | 3 ++- net/core/dev.c | 3 ++- 9 files changed, 54 insertions(+), 14 deletions(-) diff --git a/arch/s390/appldata/appldata_net_sum.c b/arch/s390/appldata/appldata_net_sum.c index 6146606ac9a3..72cb5344e488 100644 --- a/arch/s390/appldata/appldata_net_sum.c +++ b/arch/s390/appldata/appldata_net_sum.c @@ -58,11 +58,11 @@ struct appldata_net_sum_data { */ static void appldata_get_net_sum_data(void *data) { - int i; struct appldata_net_sum_data *net_data; struct net_device *dev; unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors, tx_errors, rx_dropped, tx_dropped, collisions; + int ret, i; net_data = data; net_data->sync_count_1++; @@ -83,7 +83,13 @@ static void appldata_get_net_sum_data(void *data) for_each_netdev(&init_net, dev) { struct rtnl_link_stats64 stats; - dev_get_stats(dev, &stats); + ret = dev_get_stats(dev, &stats); + if (ret) { + netif_lists_unlock(&init_net); + netdev_err(dev, "dev_get_stats returned %d\n", ret); + return; + } + rx_packets += stats.rx_packets; tx_packets += stats.tx_packets; rx_bytes += stats.rx_bytes; diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 4382ee278309..c717b7e7dd81 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -351,6 +351,7 @@ static void netdev_trig_work(struct work_struct *work) unsigned int new_activity; unsigned long interval; int invert; + int err; /* If we dont have a device, insure we are off */ if (!trigger_data->net_dev) { @@ -363,7 +364,13 @@ static void netdev_trig_work(struct work_struct *work) !test_bit(NETDEV_LED_RX, &trigger_data->mode)) return; - dev_get_stats(trigger_data->net_dev, &dev_stats); + err = dev_get_stats(trigger_data->net_dev, &dev_stats); + if (err) { + netdev_err(trigger_data->net_dev, + "dev_get_stats returned %d\n", err); + return; + } + new_activity = (test_bit(NETDEV_LED_TX, &trigger_data->mode) ? dev_stats.tx_packets : 0) + diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c b/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c index ada70425b48c..aab6a81f0438 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_ethtool.c @@ -266,9 +266,14 @@ static void xgene_get_ethtool_stats(struct net_device *ndev, { struct xgene_enet_pdata *pdata = netdev_priv(ndev); struct rtnl_link_stats64 stats; - int i; + int err, i; + + err = dev_get_stats(ndev, &stats); + if (err) { + netdev_err(ndev, "dev_get_stats returned %d\n", err); + return; + } - dev_get_stats(ndev, &stats); for (i = 0; i < XGENE_STATS_LEN; i++) data[i] = *(u64 *)((char *)&stats + gstrings_stats[i].offset); diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c index ee2172011051..d05fa7b3f6e0 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c @@ -840,6 +840,7 @@ static void hns_get_ethtool_stats(struct net_device *netdev, struct hns_nic_priv *priv = netdev_priv(netdev); struct hnae_handle *h = priv->ae_handle; struct rtnl_link_stats64 net_stats; + int err; if (!h->dev->ops->get_stats || !h->dev->ops->update_stats) { netdev_err(netdev, "get_stats or update_stats is null!\n"); @@ -848,7 +849,11 @@ static void hns_get_ethtool_stats(struct net_device *netdev, h->dev->ops->update_stats(h, &netdev->stats); - dev_get_stats(netdev, &net_stats); + err = dev_get_stats(netdev, &net_stats); + if (err) { + netdev_err(netdev, "dev_get_stats returned %d\n", err); + return; + } /* get netdev statistics */ p[0] = net_stats.rx_packets; diff --git a/drivers/net/ethernet/intel/e1000e/ethtool.c b/drivers/net/ethernet/intel/e1000e/ethtool.c index 06442e6bef73..41bd3e0598ce 100644 --- a/drivers/net/ethernet/intel/e1000e/ethtool.c +++ b/drivers/net/ethernet/intel/e1000e/ethtool.c @@ -2060,15 +2060,20 @@ static void e1000_get_ethtool_stats(struct net_device *netdev, { struct e1000_adapter *adapter = netdev_priv(netdev); struct rtnl_link_stats64 net_stats; - int i; char *p = NULL; + int err, i; pm_runtime_get_sync(netdev->dev.parent); - dev_get_stats(netdev, &net_stats); + err = dev_get_stats(netdev, &net_stats); pm_runtime_put_sync(netdev->dev.parent); + if (err) { + netdev_err(netdev, "dev_get_stats returned %d\n", err); + return; + } + for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { switch (e1000_gstrings_stats[i].type) { case NETDEV_STATS: diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c index 2b8084664403..a647e2774f76 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c @@ -1298,11 +1298,16 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev, struct rtnl_link_stats64 net_stats; unsigned int start; struct ixgbe_ring *ring; - int i, j; char *p = NULL; + int err, i, j; ixgbe_update_stats(adapter); - dev_get_stats(netdev, &net_stats); + err = dev_get_stats(netdev, &net_stats); + if (err) { + netdev_err(netdev, "dev_get_stats returned %d\n", err); + return; + } + for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) { switch (ixgbe_gstrings_stats[i].type) { case NETDEV_STATS: diff --git a/drivers/net/ethernet/intel/ixgbevf/ethtool.c b/drivers/net/ethernet/intel/ixgbevf/ethtool.c index 3b9b7e5c2998..665e39301092 100644 --- a/drivers/net/ethernet/intel/ixgbevf/ethtool.c +++ b/drivers/net/ethernet/intel/ixgbevf/ethtool.c @@ -423,11 +423,16 @@ static void ixgbevf_get_ethtool_stats(struct net_device *netdev, struct rtnl_link_stats64 net_stats; unsigned int start; struct ixgbevf_ring *ring; - int i, j; + int err, i, j; char *p; ixgbevf_update_stats(adapter); - dev_get_stats(netdev, &net_stats); + err = dev_get_stats(netdev, &net_stats); + if (err) { + netdev_err(netdev, "dev_get_stats returned %d\n", err); + return; + } + for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) { switch (ixgbevf_gstrings_stats[i].type) { case NETDEV_STATS: diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index bd471f1e1fa3..b1aebab916a8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4545,7 +4545,8 @@ void netdev_notify_peers(struct net_device *dev); void netdev_features_change(struct net_device *dev); /* Load a device via the kmod */ void dev_load(struct net *net, const char *name); -int dev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage); +int __must_check dev_get_stats(struct net_device *dev, + struct rtnl_link_stats64 *storage); void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, const struct net_device_stats *netdev_stats); void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s, diff --git a/net/core/dev.c b/net/core/dev.c index dfbd66ba3cad..30facac95d5e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10403,7 +10403,8 @@ EXPORT_SYMBOL(netdev_stats_to_stats64); * dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats; * otherwise the internal statistics structure is used. */ -int dev_get_stats(struct net_device *dev, struct rtnl_link_stats64 *storage) +int __must_check dev_get_stats(struct net_device *dev, + struct rtnl_link_stats64 *storage) { const struct net_device_ops *ops = dev->netdev_ops; int err = 0; From patchwork Fri Jan 8 16:31:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359531 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 E1B86C4332B for ; Fri, 8 Jan 2021 16:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D130239A1 for ; Fri, 8 Jan 2021 16:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728414AbhAHQdo (ORCPT ); Fri, 8 Jan 2021 11:33:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728156AbhAHQdm (ORCPT ); Fri, 8 Jan 2021 11:33:42 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D45CCC0612A8 for ; Fri, 8 Jan 2021 08:32:41 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id w1so15190596ejf.11 for ; Fri, 08 Jan 2021 08:32:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/Wtdvg0EU8CbIz7qyhphZGYCfzOo7O5XFwV++uubOBY=; b=MTrXXeQ9imQFEz1KFqxOeeW4Mdb7hfaTHz4rMkkEayqBu6f28DSPaDaQf9UoUY1WcG S5x5OzIdiO0R7NL35MO40IiVpYkvTDfuI5mlvIvkHOJWKkVQ4YNPB8CdiTo83RfLpUDY EIDRvNzwMkT84hynIeXngOACyQrTg6pENECgM13ZGGgMkEmc+Se6OawaXOzy1Vea0OBN 2pz9svZLjXjbTZoBIqdotEJUfJ6IcjaYfMzQFDT1qwbOiKG7DCwyEU4sVHEYHTI5lvQ+ tF11+pfIlJFlNtPxGjpcELJHaMbaiEL/WmSbD7MWV2oqZdg+Ocp2LZydjwmp68RkgJU1 A5yw== 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:content-transfer-encoding; bh=/Wtdvg0EU8CbIz7qyhphZGYCfzOo7O5XFwV++uubOBY=; b=WH5C090LPgy0UrjY/9paZ7Lq9+esQyT6A0D2KBFJx0RNJYZe9DjKgOzZHGo57F+C4K pi7afiukUBWvdTxyUoCG5FqMCBnxaMvboA10QX2S0yzH2NtcbMw2/NJIu6wv+u7iGiy5 ytGY73jssL645HsTohD59jwBvW9jrbzK/jjmSHMjdG4aZf9SVPSdImWuN873tboMGGIN h4KpDmQX0FXK4vUoxtDQiULkFJameslHuhTN7Yf8XZ1dbsEXe8Au3ONmMPQh4CLbovOD ruakzzREKEqmv8TKpvXawbFWOEqDeAGV952O1GXRsQJ6BTA1wrj0FaHrZVgSSB+Chv55 Xp8g== X-Gm-Message-State: AOAM530dM53B0XYmv10RCHvEpBENqjj3+vLRO1HnQ7aMUeXKSNNdB3T7 MqTyu3nEMrs/CfV5GTGos+8= X-Google-Smtp-Source: ABdhPJzoPZoGmR61nb6T72kxXmFdBOjw50nr+7fDAjJOJR/KOlR39RRQNFsZei2EDXJbJsPm9j1PZQ== X-Received: by 2002:a17:906:fa12:: with SMTP id lo18mr3292593ejb.354.1610123560572; Fri, 08 Jan 2021 08:32:40 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id x6sm3957737edl.67.2021.01.08.08.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:32:40 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala , Saeed Mahameed Subject: [PATCH v5 net-next 14/16] net: net_failover: ensure .ndo_get_stats64 can sleep Date: Fri, 8 Jan 2021 18:31:57 +0200 Message-Id: <20210108163159.358043-15-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108163159.358043-1-olteanv@gmail.com> References: <20210108163159.358043-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean The failover framework sets up a virtio_net interface [ when it has the VIRTIO_NET_F_STANDBY feature ] and a VF interface, having the same MAC address, in a standby/active relationship. When the active VF is unplugged, the standby virtio_net temporarily kicks in. The failover framework registers a common upper for the active and the standby interface, which is what the application layer uses. This is similar to bonding/team. The statistics of the upper interface are the sum of the statistics of the active and of the standby interface. There is an effort to convert .ndo_get_stats64 to sleepable context, and for that to work, we need to prevent callers of dev_get_stats from using atomic locking. The failover driver needs protection via an RCU read-side critical section to access the standby and the active interface. This has two features: - It is atomic: this needs to change. - It is reentrant: this is ok, because generally speaking, dev_get_stats is recursive, and taking global locks is a bad thing from a recursive context. The existing logic can be rehashed just a little bit such that the recursive dev_get_stats call will not be under any lock. We can achieve that by "cheating" a little bit and use dev_hold() to take a reference on the active and backup interfaces, and netdev_wait_allrefs() will just have to wait until dev_get_stats() finishes. Signed-off-by: Vladimir Oltean --- Changes in v5: Use rcu_read_lock() and do not change the locking architecture of the driver. Changes in v4: Now there is code to propagate errors. Changes in v3: None. Changes in v2: Switched to the new scheme of holding just a refcnt to the slave interfaces while recursing with dev_get_stats. drivers/net/net_failover.c | 64 ++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/drivers/net/net_failover.c b/drivers/net/net_failover.c index 7f70555e68d1..3e8a4046c748 100644 --- a/drivers/net/net_failover.c +++ b/drivers/net/net_failover.c @@ -183,38 +183,64 @@ static int net_failover_get_stats(struct net_device *dev, struct rtnl_link_stats64 *stats) { struct net_failover_info *nfo_info = netdev_priv(dev); - struct rtnl_link_stats64 temp; - struct net_device *slave_dev; + struct rtnl_link_stats64 primary_stats; + struct rtnl_link_stats64 standby_stats; + struct net_device *primary_dev; + struct net_device *standby_dev; int err = 0; - spin_lock(&nfo_info->stats_lock); - memcpy(stats, &nfo_info->failover_stats, sizeof(*stats)); - rcu_read_lock(); - slave_dev = rcu_dereference(nfo_info->primary_dev); - if (slave_dev) { - err = dev_get_stats(slave_dev, &temp); + primary_dev = rcu_dereference(nfo_info->primary_dev); + if (primary_dev) + dev_hold(primary_dev); + + standby_dev = rcu_dereference(nfo_info->standby_dev); + if (standby_dev) + dev_hold(standby_dev); + + rcu_read_unlock(); + + /* Don't hold rcu_read_lock while calling dev_get_stats, just a + * reference to ensure they won't get unregistered. + */ + if (primary_dev) { + err = dev_get_stats(primary_dev, &primary_stats); if (err) goto out; - net_failover_fold_stats(stats, &temp, &nfo_info->primary_stats); - memcpy(&nfo_info->primary_stats, &temp, sizeof(temp)); } - slave_dev = rcu_dereference(nfo_info->standby_dev); - if (slave_dev) { - err = dev_get_stats(slave_dev, &temp); + if (standby_dev) { + err = dev_get_stats(standby_dev, &standby_stats); if (err) goto out; - net_failover_fold_stats(stats, &temp, &nfo_info->standby_stats); - memcpy(&nfo_info->standby_stats, &temp, sizeof(temp)); } -out: - rcu_read_unlock(); + spin_lock(&nfo_info->stats_lock); + + memcpy(stats, &nfo_info->failover_stats, sizeof(*stats)); + + if (primary_dev) { + net_failover_fold_stats(stats, &primary_stats, + &nfo_info->primary_stats); + memcpy(&nfo_info->primary_stats, &primary_stats, + sizeof(primary_stats)); + } + if (standby_dev) { + net_failover_fold_stats(stats, &standby_stats, + &nfo_info->standby_stats); + memcpy(&nfo_info->standby_stats, &standby_stats, + sizeof(standby_stats)); + } memcpy(&nfo_info->failover_stats, stats, sizeof(*stats)); + spin_unlock(&nfo_info->stats_lock); +out: + if (primary_dev) + dev_put(primary_dev); + if (standby_dev) + dev_put(standby_dev); return err; } @@ -728,6 +754,7 @@ static struct failover_ops net_failover_ops = { struct failover *net_failover_create(struct net_device *standby_dev) { struct device *dev = standby_dev->dev.parent; + struct net_failover_info *nfo_info; struct net_device *failover_dev; struct failover *failover; int err; @@ -772,6 +799,9 @@ struct failover *net_failover_create(struct net_device *standby_dev) failover_dev->min_mtu = standby_dev->min_mtu; failover_dev->max_mtu = standby_dev->max_mtu; + nfo_info = netdev_priv(failover_dev); + spin_lock_init(&nfo_info->stats_lock); + err = register_netdev(failover_dev); if (err) { dev_err(dev, "Unable to register failover_dev!\n"); From patchwork Fri Jan 8 16:31:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359530 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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 1B4EDC43331 for ; Fri, 8 Jan 2021 16:34:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBD7D23A01 for ; Fri, 8 Jan 2021 16:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728478AbhAHQeA (ORCPT ); Fri, 8 Jan 2021 11:34:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728410AbhAHQdo (ORCPT ); Fri, 8 Jan 2021 11:33:44 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E76C0612AB for ; Fri, 8 Jan 2021 08:32:44 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id b2so11821809edm.3 for ; Fri, 08 Jan 2021 08:32:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W3636oXSLwvTxglbe6goTnJNgcJx/+xGzy9J0B9Ns6o=; b=TIM4uP1A0WiQkbXTb8uq6m8ugXIaOhxE8JynI5fX7qZvMyChYHd3e/4fmamNqBwTpf GunNUY7jFQB2cJsmpvPtWFncHfzK46dceIe1IEwQ7qVhU1klXg8vh6PhvO8u3tLbND5o HMAoOryDZjUYDtrpT3jCyehudlHrvK6OCFp8wkijbhtcxX9TMi1Etn2mrzaXvl37lrty GPuLOetiA8MPvqYkZjjEB9wsngFGcg5U4BWposuY3cBa7ryGAwjCALorZ7UShe0CvZ6m Ddi13mbK4s8hiK8/ekGl5lyPpUsYfHQSvVJEXV2mkmWKzIj2/Cqitu2cMUVCX+o1+nlN Deng== 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:content-transfer-encoding; bh=W3636oXSLwvTxglbe6goTnJNgcJx/+xGzy9J0B9Ns6o=; b=uVUB5NA002BxMk8gKxkJ1uZ5VMp/z2tZSkyv5pGG+00CJLEQm/IX65eXeG2vFEjwpn 4iEL8Wnxm4pvFUOUY8FwgNAPHvj00KaysmHfO62eWNTjywTTkNfzpCC78iMwL0dTzSQ8 ZYoLAMMwzf/Ono1679SszkSvyyxri5+oGn2Dy+LvT/cU+yb/sbdGlU8eSw8qmlCq6HDv xFfdOlJkjqfabM3FiCUggELxxeceyN2VljIZPebp1GT5ilDqIyAKFMk4R888tAO+Fsob JjUlOGBVKDDKWbdQRPn2P3vVFVHMRNNweKx53cLRuy0u2o58WWTnHRlSUH0a7M6YRGqY Tm0w== X-Gm-Message-State: AOAM530wnnwVo5KbWmhP+BzSPJUL8uuEA5g/dqNM18QlVr9Tls+zMaFh 8lQW8jwYcCCPX4BYVGtLVRM= X-Google-Smtp-Source: ABdhPJypX/y4cPaUsyCdhKkiPX47xljAHVv1qv2A1t7Z5TtfDYLU17WrZQnEVUkw24Dyz7hC3PTEYg== X-Received: by 2002:a05:6402:2066:: with SMTP id bd6mr5812719edb.211.1610123563678; Fri, 08 Jan 2021 08:32:43 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id x6sm3957737edl.67.2021.01.08.08.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:32:43 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Cong Wang , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Taehee Yoo , Jiri Pirko , Florian Westphal , Nikolay Aleksandrov , Pravin B Shelar , Sridhar Samudrala , Saeed Mahameed Subject: [PATCH v5 net-next 16/16] net: mark ndo_get_stats64 as being able to sleep Date: Fri, 8 Jan 2021 18:31:59 +0200 Message-Id: <20210108163159.358043-17-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108163159.358043-1-olteanv@gmail.com> References: <20210108163159.358043-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean Now that all callers have been converted to not use atomic context when calling dev_get_stats, it is time to update the documentation and put a notice in the function that it expects process context. Signed-off-by: Vladimir Oltean --- Changes in v5: None. Changes in v4: None. Changes in v3: None. Changes in v2: Updated the documentation. Documentation/networking/netdevices.rst | 8 ++++++-- Documentation/networking/statistics.rst | 9 ++++----- net/core/dev.c | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst index 5a85fcc80c76..944599722c76 100644 --- a/Documentation/networking/netdevices.rst +++ b/Documentation/networking/netdevices.rst @@ -64,8 +64,12 @@ ndo_do_ioctl: Context: process ndo_get_stats: - Synchronization: dev_base_lock rwlock. - Context: nominally process, but don't sleep inside an rwlock + Synchronization: + none. netif_lists_lock(net) might be held, but not guaranteed. + It is illegal to hold rtnl_lock() in this method, since it will + cause a lock inversion with netif_lists_lock and a deadlock. + Context: + process ndo_start_xmit: Synchronization: __netif_tx_lock spinlock. diff --git a/Documentation/networking/statistics.rst b/Documentation/networking/statistics.rst index 234abedc29b2..ad3e353df0dd 100644 --- a/Documentation/networking/statistics.rst +++ b/Documentation/networking/statistics.rst @@ -155,11 +155,10 @@ Drivers must ensure best possible compliance with Please note for example that detailed error statistics must be added into the general `rx_error` / `tx_error` counters. -The `.ndo_get_stats64` callback can not sleep because of accesses -via `/proc/net/dev`. If driver may sleep when retrieving the statistics -from the device it should do so periodically asynchronously and only return -a recent copy from `.ndo_get_stats64`. Ethtool interrupt coalescing interface -allows setting the frequency of refreshing statistics, if needed. +Drivers may sleep when retrieving the statistics from the device, or they might +read the counters periodically and only return in `.ndo_get_stats64` a recent +copy collected asynchronously. In the latter case, the ethtool interrupt +coalescing interface allows setting the frequency of refreshing statistics. Retrieving ethtool statistics is a multi-syscall process, drivers are advised to keep the number of statistics constant to avoid race conditions with diff --git a/net/core/dev.c b/net/core/dev.c index 30facac95d5e..afd0e226efd4 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10409,6 +10409,8 @@ int __must_check dev_get_stats(struct net_device *dev, const struct net_device_ops *ops = dev->netdev_ops; int err = 0; + might_sleep(); + if (ops->ndo_get_stats64) { memset(storage, 0, sizeof(*storage)); err = ops->ndo_get_stats64(dev, storage);