From patchwork Tue Jan 5 18:58: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: 357369 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,USER_AGENT_GIT autolearn=unavailable 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 AA3A0C4361A for ; Tue, 5 Jan 2021 19:02:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7509822D5B for ; Tue, 5 Jan 2021 19:02:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730828AbhAETCL (ORCPT ); Tue, 5 Jan 2021 14:02:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730733AbhAETCH (ORCPT ); Tue, 5 Jan 2021 14:02:07 -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 22212C0617A5; Tue, 5 Jan 2021 11:00:59 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id q22so1906708eja.2; Tue, 05 Jan 2021 11:00:59 -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=pumKytNb6HfM0fji93xr5G/BhQEYT7JsjEW2ZBlR5iU=; b=JEckJaQsFgR2VLSNLG5i7z0+KlnFs83ZYxvR0iQpvNPQVQcSticPBwdGCbSF9D1XDP faMVx76guT6YBo+oghMniuv45XGzCI9kOXx34jKAUzWzgH3l2lWQ8qRYGB6JP12yfGdf PXk1Uyi+mFeT3ptjmyVyAmzEG8s03OO8PMaQEcI5fSbhi+CZdoBgQozSyOlIBYee4ka/ TuQC8hW7oOtFk41zzRi7d5iy1v8jOvtmUcz3y0ARCtdpxBwKE5wnx5JZLZIicLXqTBHJ Aqa1KrvCJBQmuvF7CwMtnx1arxBqIA8R27l2ApWKEoYhQLef8w9qWcrMbb+cWzRe4dls E77Q== 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=pumKytNb6HfM0fji93xr5G/BhQEYT7JsjEW2ZBlR5iU=; b=ihVIQGBykCeYFC4LDic7xfQ7ebN7NNGOI3pf6+NsCyNm1GWWxNYOi/qsf56ytEFjDE jScEIeZlmwktxfXx+iVfgH0VixxiDedd7bRgU49xkOTjJxuulBkdg5qS2KvZzKtUvMlU CBXnc1c7M8IWcmT2EueMaSa5jQ0hRq1Skm9KCTlPCPQP7A9HnW33nvlV6+8v/sXiH+NO 7VP1lMvd1GbBAYQxin8dRJE1NXIy080mLBTOBwaXGtW9fB5nvoje+nqRwd9fNpgJpUxu IEY41GxFgqRuRh7e5ypF+Vjc/AYxTbbda/1MFhqcfMPWl2nB5KTzvhKnaoWxnZnZ670m aXvg== X-Gm-Message-State: AOAM531J2qZQAynWxNTn42JmEvSijqi26/cEOfloB2N63UR7SagY5+dT YjWQlxUct51eoVhxicaiGw0= X-Google-Smtp-Source: ABdhPJz+1ICzC5RVM3oZs0oQoaJmiaftG0zPzA6tae5qdGfc+GpxdTiRp0F9FQexln0n4DdvvvIthg== X-Received: by 2002:a17:907:d10:: with SMTP id gn16mr478354ejc.496.1609873257847; Tue, 05 Jan 2021 11:00:57 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id z13sm205084edq.48.2021.01.05.11.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 11:00:57 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev@vger.kernel.org, Andrew Lunn , Florian Fainelli , Paul Gortmaker , Pablo Neira Ayuso , Jiri Benc , Cong Wang , Jamal Hadi Salim , Stephen Hemminger , Eric Dumazet , George McCollister , Oleksij Rempel , Jay Vosburgh , Veaceslav Falico , Andy Gospodarek , Arnd Bergmann , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Taehee Yoo , Jiri Pirko , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Paolo Abeni , Christian Brauner , Florian Westphal , linux-s390@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-parisc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-usb@vger.kernel.org, dev@openvswitch.org Subject: [RFC PATCH v2 net-next 07/12] parisc/led: hold the netdev lists lock when retrieving device statistics Date: Tue, 5 Jan 2021 20:58:57 +0200 Message-Id: <20210105185902.3922928-8-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210105185902.3922928-1-olteanv@gmail.com> References: <20210105185902.3922928-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. The LED driver for HP-PARISC workstations uses a workqueue to periodically check for updates in network interface statistics, and flicker when those have changed (i.e. there has been activity on the line). Ignoring the fact that this driver is completely duplicating drivers/leds/trigger/ledtrig-netdev.c, there is an even bigger problem. Now, the dev_get_stats call can sleep, and iterating through the list of network interfaces still needs to ensure the integrity of list of network interfaces. So that leaves us only one locking option given the current design of the network stack, and that is the netns mutex. Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: linux-parisc@vger.kernel.org Signed-off-by: Vladimir Oltean --- drivers/parisc/led.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c index 3cada632a4be..c8c6b2301dc9 100644 --- a/drivers/parisc/led.c +++ b/drivers/parisc/led.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -355,25 +354,29 @@ static __inline__ int led_get_net_activity(void) int retval; rx_total = tx_total = 0; - - /* we are running as a workqueue task, so we can use an RCU lookup */ - rcu_read_lock(); - for_each_netdev_rcu(&init_net, dev) { + + /* we are running as a workqueue task, so we can sleep */ + netif_lists_lock(&init_net); + + 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 in_device *in_dev = __in_dev_get_rcu(dev); - if (!in_dev || !in_dev->ifa_list) + if (!in_dev || !in_dev->ifa_list || + ipv4_is_loopback(in_dev->ifa_list->ifa_local)) { + in_dev_put(in_dev); continue; + } - if (ipv4_is_loopback(in_dev->ifa_list->ifa_local)) - continue; + in_dev_put(in_dev); stats = dev_get_stats(dev, &temp); rx_total += stats->rx_packets; tx_total += stats->tx_packets; } - rcu_read_unlock(); + + netif_lists_unlock(&init_net); retval = 0;