From patchwork Fri Jan 8 00:19:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 359568 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 5A3F6C433DB for ; Fri, 8 Jan 2021 00:21:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B01C23716 for ; Fri, 8 Jan 2021 00:21:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729573AbhAHAVq (ORCPT ); Thu, 7 Jan 2021 19:21:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728954AbhAHAVp (ORCPT ); Thu, 7 Jan 2021 19:21:45 -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 EE2A0C0612FA for ; Thu, 7 Jan 2021 16:20:31 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id dk8so9556640edb.1 for ; Thu, 07 Jan 2021 16:20: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=RnIaag0tweoJmelZ4Q1Xq1u3Ft4Miz3Y1p4DbCIrsek=; b=RuYTgz1lXSX0WHSUrBi/GXNCTSta453FL88vJdsGijA/EU6x97o9iiRiDL0VD36Pqr 5NmhMKKkglOkPN5PBEgEDIQMn9zCp9++2jAIWBZawf7fKfFeypFN9vHbRm3Nh/RFjenM wbQTbgkVHYiOiJNFUFg6MSxdY+EnvY0ap4+ty8++AOTnvzTq1CsJ5kG6/S02NPNkf+Z/ JyNqKp3XdFdipm7ywz6Nixfqar5zij1k67mje85DvKmyD3muB+Yt+/oWQrVqUV+A8xHs 2mL5DsBriwkAQbf2+UBbNfW1/ns7VrmuQ60SjyqCPhSCNr//+jpHQSCBLqp43LgJ+POe mdRQ== 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=RnIaag0tweoJmelZ4Q1Xq1u3Ft4Miz3Y1p4DbCIrsek=; b=AFgzVYBM3caAGVj2RYaMCWH8ao9o0+AtcFH18Z2ZbFTIBOTdu2NF1CrjfyyNNLxANM 7XwdU0WS2d4072qWddkUvumvdCTRIroLRjRIzbQWJY88Mvg0iN+xb1E4FUfdGxq0KPl+ uUNmBzN/UKucHit31D25kekfE4dg6sHSELAW/kQ6feVuv8npUyrfoGWryN+7erSirK7y FNjXhs7Isy0dwPcsaU3YzDXhJsTwwSaglZ2tAX38eclfn9EslberCPCfPnWLoXiMIjwE 0QTMv30o87jfDwPs8T2gb2el4lI1PCCzj/hPwhZnxaJ/r/9TRBt0QyRfI1c33/N8CpBD OIaw== X-Gm-Message-State: AOAM532+tUqmu851CbcNHrJ8FNuVa9PhzTcgy1GUd02UYiRpYsJ/nAHS KroSIApW3D+8yn/6CMsarYU= X-Google-Smtp-Source: ABdhPJzhxUs2AliG9AB7n500jiE0u4I3rBRmPCuzaCt8cCB3AzcsxMmBnQWoQhJaWfPCrDbmdXAUlg== X-Received: by 2002:a05:6402:1692:: with SMTP id a18mr3321206edv.321.1610065230737; Thu, 07 Jan 2021 16:20:30 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id rk12sm2981691ejb.75.2021.01.07.16.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 16:20:30 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski , Nikolay Aleksandrov 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 v4 net-next 05/18] s390/appldata_net_sum: hold the netdev lists lock when retrieving device statistics Date: Fri, 8 Jan 2021 02:19:52 +0200 Message-Id: <20210108002005.3429956-6-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210108002005.3429956-1-olteanv@gmail.com> References: <20210108002005.3429956-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. In the case of the appldata driver, an RCU read-side critical section is used to ensure the integrity of the list of network interfaces, because the driver iterates through all net devices in the netns to aggregate statistics. We still need some protection against an interface registering or deregistering, and the writer-side lock, the netns's mutex, is fine for that, because it offers sleepable context. The ops->callback function is called from under appldata_ops_mutex protection, so this is proof that the context is sleepable and holding a mutex is therefore fine. Cc: Heiko Carstens Cc: Vasily Gorbik Cc: linux-s390@vger.kernel.org Signed-off-by: Vladimir Oltean --- Changes in v4: None. Changes in v3: None. Changes in v2: None. arch/s390/appldata/appldata_net_sum.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/s390/appldata/appldata_net_sum.c b/arch/s390/appldata/appldata_net_sum.c index 59c282ca002f..4db886980cba 100644 --- a/arch/s390/appldata/appldata_net_sum.c +++ b/arch/s390/appldata/appldata_net_sum.c @@ -78,8 +78,9 @@ static void appldata_get_net_sum_data(void *data) tx_dropped = 0; collisions = 0; - rcu_read_lock(); - for_each_netdev_rcu(&init_net, dev) { + netif_lists_lock(&init_net); + + for_each_netdev(&init_net, dev) { const struct rtnl_link_stats64 *stats; struct rtnl_link_stats64 temp; @@ -95,7 +96,8 @@ static void appldata_get_net_sum_data(void *data) collisions += stats->collisions; i++; } - rcu_read_unlock(); + + netif_lists_unlock(&init_net); net_data->nr_interfaces = i; net_data->rx_packets = rx_packets;