Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3611418pxu; Tue, 8 Dec 2020 17:16:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmEj5TuKmDQ3Am/gOuE6oFHzcDsd7E2vhEYp1CJB41LiUzWp0lX69KRf2a0OuykTOWAsjC X-Received: by 2002:a17:906:38d6:: with SMTP id r22mr62121ejd.149.1607476603084; Tue, 08 Dec 2020 17:16:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607476603; cv=none; d=google.com; s=arc-20160816; b=qhPmqag25cWAPVYChLB7PgO5GJ2+4ruay0la3JGddoDx6IJOYLaAv4kKoegjOZnfA2 ZxZcwikM3iwovJq/HfehVC3lXpZH3e0NxdP6MwFUeT7y/fY8j7ggSyhkWbnEPliinNS/ ASEbEgeMr3c5qLveNO1ne0Oi7aVD7Ze73lCZUQiuA8/odSY9MEIwWWK1Jwvyc+kEqzry 0o2twdFAcxZ8/jG4LL43BPnLn2XusThZd1+jrRoCand93HY/rrIgaHbSQa2HhuEDYvKx SkUgrBjvIsKcjZ78zoi+Y2SICGkXdG4fE7vAQlY3jUzrnoQvsGD5y0AWsDs7QeegoUoe m53w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=ync4CPltsl/nCV2YYjaTMjTxBOlApWXUk+cd9RbyM9k=; b=vG4WQFeB84z8iZQ3qUo4GxbyN7D35h4Y8WQ1/wPUIarqSx82oYgpEew+BR51zxEch9 Jcrb8t0+SbibcHalk4MbU6bj7NZsqDaEYPmTWgonGvRbXh0JqS/gTcuCVlJREWKadK13 CIOsYaRI4XLwzlXB7A6rIlQRsZKvIF0sLO3O+Crl/6dsaIaRrL8tp+cG7iJv2YrbFF+b maIOS4yBvypFmN7lD7EvKmRb0nMGdzXaDbHrgYk71m5tUQJLSUVDEyDB94Lf5T2N5kwu wUA4AsX24P2BYRB1AL/0ZeNNVh2XW9OeBpdnhBqiMHDoquohq8VSjFHvDG/5AyuqfwV5 z/LQ== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt10si77358ejc.145.2020.12.08.17.16.21; Tue, 08 Dec 2020 17:16:43 -0800 (PST) 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; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726791AbgLIBNy (ORCPT + 99 others); Tue, 8 Dec 2020 20:13:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:37678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726754AbgLIBNr (ORCPT ); Tue, 8 Dec 2020 20:13:47 -0500 From: paulmck@kernel.org Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, iamjoonsoo.kim@lge.com, andrii@kernel.org, "Paul E. McKenney" , Ming Lei , Jens Axboe Subject: [PATCH v2 sl-b 5/5] percpu_ref: Dump mem_dump_obj() info upon reference-count underflow Date: Tue, 8 Dec 2020 17:13:03 -0800 Message-Id: <20201209011303.32737-5-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20201209011124.GA31164@paulmck-ThinkPad-P72> References: <20201209011124.GA31164@paulmck-ThinkPad-P72> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Paul E. McKenney" Reference-count underflow for percpu_ref is detected in the RCU callback percpu_ref_switch_to_atomic_rcu(), and the resulting warning does not print anything allowing easy identification of which percpu_ref use case is underflowing. This is of course not normally a problem when developing a new percpu_ref use case because it is most likely that the problem resides in this new use case. However, when deploying a new kernel to a large set of servers, the underflow might well be a new corner case in any of the old percpu_ref use cases. This commit therefore calls mem_dump_obj() to dump out any additional available information on the underflowing percpu_ref instance. Cc: Ming Lei Cc: Jens Axboe Reported-by: Andrii Nakryiko Signed-off-by: Paul E. McKenney --- lib/percpu-refcount.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c index e59eda0..a1071cd 100644 --- a/lib/percpu-refcount.c +++ b/lib/percpu-refcount.c @@ -5,6 +5,7 @@ #include #include #include +#include #include /* @@ -168,6 +169,7 @@ static void percpu_ref_switch_to_atomic_rcu(struct rcu_head *rcu) struct percpu_ref_data, rcu); struct percpu_ref *ref = data->ref; unsigned long __percpu *percpu_count = percpu_count_ptr(ref); + static atomic_t underflows; unsigned long count = 0; int cpu; @@ -191,9 +193,13 @@ static void percpu_ref_switch_to_atomic_rcu(struct rcu_head *rcu) */ atomic_long_add((long)count - PERCPU_COUNT_BIAS, &data->count); - WARN_ONCE(atomic_long_read(&data->count) <= 0, - "percpu ref (%ps) <= 0 (%ld) after switching to atomic", - data->release, atomic_long_read(&data->count)); + if (WARN_ONCE(atomic_long_read(&data->count) <= 0, + "percpu ref (%ps) <= 0 (%ld) after switching to atomic", + data->release, atomic_long_read(&data->count)) && + atomic_inc_return(&underflows) < 4) { + pr_err("%s(): percpu_ref underflow", __func__); + mem_dump_obj(data); + } /* @ref is viewed as dead on all CPUs, send out switch confirmation */ percpu_ref_call_confirm_rcu(rcu); -- 2.9.5