From patchwork Thu Jan 7 09:49:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12003441 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,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 9C192C433DB for ; Thu, 7 Jan 2021 09:52:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BF852333D for ; Thu, 7 Jan 2021 09:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727914AbhAGJvu (ORCPT ); Thu, 7 Jan 2021 04:51:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727902AbhAGJvq (ORCPT ); Thu, 7 Jan 2021 04:51:46 -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 ECAA2C0612A2 for ; Thu, 7 Jan 2021 01:51:09 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id jx16so8785442ejb.10 for ; Thu, 07 Jan 2021 01:51:09 -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=Y7uWbEbsBXF1F/7KTwfTITzqENv+hT1Vv+Tffl7XOas=; b=ETy99AdZ/mJWPRKQFR7xqYZIbb71D6nz346zTPW1YqzdAWA6xBwfQvofu/UvU1IwSo U11AauqptZqYNE6sBMQh9aIEQO+caTutKVDorKbAAubC9x8SduQs6iumsAHvnrDlmL/5 H+1pmScT30t5kP/MX0ziMYQjFCgcdTnmSUnt0R2zPBbTzg39BTDRku04Y1ivyjnKL6np fvTFqRy/o+S8A9eM7qo1VLyilJiJpxGds1OSUw0vGXkXKLL/aP5BepdnQ864z2Mwj01z hELiRJNL5557032D/9PnXPPy08QOh2cgsVGOT+ai8w+nJAUa7NVmmz9e8+qp1s00XxMl JfLA== 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=Y7uWbEbsBXF1F/7KTwfTITzqENv+hT1Vv+Tffl7XOas=; b=pdwP4Bad7aogdJ5+u+q3dSmCc3g+WmaPeZ457sQ15MlDX3z51aQm/YlqH+u2eCBKPx 6vOom7XGcPmKw+CzA2fTIOF/f7qNUyz8jiALO5ygT2lDxfOk3wA+MeY5WRvRcOeDnSAw mZ4GQR/+OsC0LngI6+TDyH4pu9O7vsGgRBbPR2Limb6PXMOclsrifXiptTXTGNnos8gU AoMpMmIIPEx/QezB3wAp+AN+dJqRnrlw3IqzicKf3Cn1x3v4Ic8mJycZwTC2sdzzfISQ sIAU1hVuk4vHpMN5JZ2Iq779e6bikFXHj0cCCGaL1iKZ+W3TWWKByLrUstmfQ/im0tt6 bUQQ== X-Gm-Message-State: AOAM531nwLdOfyQxnBxnpI6bsPsAqn/rE4po5k7Ui5WVyGfT76w9yx2+ OgOV/IfgFmvWfR/XhFHOyg0= X-Google-Smtp-Source: ABdhPJyYAXwiQBpgQwBRgp0KNcDktY0u+M7P6NA0yHOkxdggKlQOHXQj+Xhsd7qalbebt6zrryygYQ== X-Received: by 2002:a17:906:1a01:: with SMTP id i1mr5747698ejf.315.1610013068671; Thu, 07 Jan 2021 01:51:08 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k15sm2251571ejc.79.2021.01.07.01.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 01:51:08 -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 Subject: [PATCH v3 net-next 04/12] net: sysfs: don't hold dev_base_lock while retrieving device statistics Date: Thu, 7 Jan 2021 11:49:43 +0200 Message-Id: <20210107094951.1772183-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210107094951.1772183-1-olteanv@gmail.com> References: <20210107094951.1772183-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 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 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; }