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: 12007001 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=-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 X-Patchwork-Delegate: kuba@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);