Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp457510pxb; Thu, 21 Oct 2021 03:02:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyHm15rBiKNiSsXjAEO4NHid86o1N95qaj3iz6zEpGvp0hOV2rHCcC2ZkV9JEAlNKznSRf X-Received: by 2002:a63:7e5c:: with SMTP id o28mr3617638pgn.201.1634810545746; Thu, 21 Oct 2021 03:02:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634810545; cv=none; d=google.com; s=arc-20160816; b=oGCSOtuMD2c/SWv82CYpOaEJL53YUkCb4FxlRub6vsmrJ0USqipln9XsPj8FwpWwtf nGozFgfDyM4Se1x46dKnkzBh6gpWP6D5z8qvZ0oGkretv8HBQDXVuDwRppHDZKBQl3C0 xjABZB1bma10xcJNe4vuvWqY4fqSPZaEkMV3ja79KyScmdYhK15yE87BGcmmrlDXk8oU efccRwxrc5schp4kWBdz1XS8CWDV9wflUQMBHI2jMi+RBuVBaJH6qIXHkf4JzQ3DFT/z D7iGP5A540mpo0G1ZoGTCDXAGWSSKFjyjiiLWLSP5vcmpeQvBWLcOksakGpCoBQnYSZg +oaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=OL0pK6Dja6OFwt9P0STH6Hk8jRb77fx4V/3DfAlCWo0=; b=HtUMPga1APMEZ+G4ymjF/UIQmUtWiPRuNtY9PtirMy1+DlF68yUy0X/G+YuQfK9y7E hHwoFs7sZk6mKXpkBgulAekimMhRqnWNxE2mLvDOQ6dieOFwS6a/Fu+1tGUXvaN6mdkX AnFBL+6+ofVbs20RVs5ZDIv7TMXZZVDZ8uf1LA+GGBUa3ARmre/H2ORImC0e0RSty0wZ EevJOUrHyoncd4Ca9fx1ZMUAWifvkETnzBuccuW3rKraIoVwK7IoBmMlvkuiv/THGBPN XCB8iJuVqUKiHuAEUVLX/JASm10fnD40lMjlngSf4xUUaqVKcmzCCjkfh0Q+3ZNGMiiO raig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=r1lvf6V5; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si7093473pgb.372.2021.10.21.03.02.10; Thu, 21 Oct 2021 03:02:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=r1lvf6V5; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231640AbhJUKBl (ORCPT + 99 others); Thu, 21 Oct 2021 06:01:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbhJUKBj (ORCPT ); Thu, 21 Oct 2021 06:01:39 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02023C06174E; Thu, 21 Oct 2021 02:59:23 -0700 (PDT) Date: Thu, 21 Oct 2021 11:59:19 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1634810361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OL0pK6Dja6OFwt9P0STH6Hk8jRb77fx4V/3DfAlCWo0=; b=r1lvf6V5x2mK5X2V4JCDNxR5auizhnZfBhP2mBdfxThmqxVGpmWSSv4XBBcRhgcxoDmboj EHhfbmzy7Z9eOLDNuFYcxqjjDt9cR/WCXhlSO+mR9bOjRKFszXUvIWNRZe4jsg4ZPPZVCv N80EdD3728XW8algd6sZgRqZpeO/4Jciz0DgRXUbXMPsmGcIYC8suWTe0q5KqYv1G9EyY0 Q2qmC4rUZTANCwfLhuRpHYxPcFmOHo5H7Rc9jl91y3yfvQJv8eUXUKdN0gicRv7qgQZ+M6 koNGRsoUd8n1hMnQL9wvdmC9Hl9VS9QS/XFXVosNW1BUl6mMjQ0SXYgIjaouQg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1634810361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OL0pK6Dja6OFwt9P0STH6Hk8jRb77fx4V/3DfAlCWo0=; b=UQB6HYxcIOKLxWaoVFz9VyzWlzlDLqFogQlynBRAxMZ7DB7jUh84ay7K3of1ZgrazTK9VH dgVNE4puyyICrMDg== From: Sebastian Andrzej Siewior To: Naresh Kamboju Cc: Netdev , Linux-Next Mailing List , open list , lkft-triage@lists.linaro.org, "David S. Miller" , Jakub Kicinski , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Thomas Gleixner , "Ahmed S. Darwish" Subject: [PATCH net-next] net: stats: Read the statistics in ___gnet_stats_copy_basic() instead of adding. Message-ID: <20211021095919.bi3szpt3c2kcoiso@linutronix.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the rework, the statistics code always adds up the byte and packet value(s). On 32bit architectures a seqcount_t is used in gnet_stats_basic_sync to ensure that the 64bit values are not modified during the read since two 32bit loads are required. The usage of a seqcount_t requires a lock to ensure that only one writer is active at a time. This lock leads to disabled preemption during the update. The lack of disabling preemption is now creating a warning as reported by Naresh since the query done by gnet_stats_copy_basic() is in preemptible context. For ___gnet_stats_copy_basic() there is no need to disable preemption since the update is performed on stack and can't be modified by another writer. Instead of disabling preemption, to avoid the warning, simply create a read function to just read the values and return as u64. Reported-by: Naresh Kamboju Fixes: 67c9e6270f301 ("net: sched: Protect Qdisc::bstats with u64_stats") Signed-off-by: Sebastian Andrzej Siewior --- net/core/gen_stats.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/net/core/gen_stats.c b/net/core/gen_stats.c index 15c270e22c5ef..a10335b4ba2d0 100644 --- a/net/core/gen_stats.c +++ b/net/core/gen_stats.c @@ -171,20 +171,51 @@ void gnet_stats_add_basic(struct gnet_stats_basic_sync *bstats, } EXPORT_SYMBOL(gnet_stats_add_basic); +static void gnet_stats_read_basic(u64 *ret_bytes, u64 *ret_packets, + struct gnet_stats_basic_sync __percpu *cpu, + struct gnet_stats_basic_sync *b, bool running) +{ + unsigned int start; + + if (cpu) { + u64 t_bytes = 0, t_packets = 0; + int i; + + for_each_possible_cpu(i) { + struct gnet_stats_basic_sync *bcpu = per_cpu_ptr(cpu, i); + unsigned int start; + u64 bytes, packets; + + do { + start = u64_stats_fetch_begin_irq(&bcpu->syncp); + bytes = u64_stats_read(&bcpu->bytes); + packets = u64_stats_read(&bcpu->packets); + } while (u64_stats_fetch_retry_irq(&bcpu->syncp, start)); + + t_bytes += bytes; + t_packets += packets; + } + *ret_bytes = t_bytes; + *ret_packets = t_packets; + return; + } + do { + if (running) + start = u64_stats_fetch_begin_irq(&b->syncp); + *ret_bytes = u64_stats_read(&b->bytes); + *ret_packets = u64_stats_read(&b->packets); + } while (running && u64_stats_fetch_retry_irq(&b->syncp, start)); +} + static int ___gnet_stats_copy_basic(struct gnet_dump *d, struct gnet_stats_basic_sync __percpu *cpu, struct gnet_stats_basic_sync *b, int type, bool running) { - struct gnet_stats_basic_sync bstats; u64 bstats_bytes, bstats_packets; - gnet_stats_basic_sync_init(&bstats); - gnet_stats_add_basic(&bstats, cpu, b, running); - - bstats_bytes = u64_stats_read(&bstats.bytes); - bstats_packets = u64_stats_read(&bstats.packets); + gnet_stats_read_basic(&bstats_bytes, &bstats_packets, cpu, b, running); if (d->compat_tc_stats && type == TCA_STATS_BASIC) { d->tc_stats.bytes = bstats_bytes; -- 2.33.0