Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp808955pxu; Fri, 4 Dec 2020 16:44:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJznRvpCzmKvbKjq4QGMYk/dUfvzwib3qIJVyPaR0F5XT+JCjP7P2jpe2T4znyeCuNxTjRij X-Received: by 2002:a17:906:314f:: with SMTP id e15mr9378825eje.496.1607129061841; Fri, 04 Dec 2020 16:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607129061; cv=none; d=google.com; s=arc-20160816; b=Fi6B4NPmR3h9UUSX9xZmsXI/zwdItbXnP4rWthzC/6nBhDiBpQwyEjb+MyKc0L7T77 UOYYJB6PBLq2pyWepKms5bHLtgtTFHabPWp8Hu3mU4ie8N3V5lSO470rdSf/iL1NaoVk n71kOq0SLj4w9Dw7iaahUJRIlkvjxGIUfXRAGI+0gH0R16eGZJbJYCkF9SYWSJz/edpH kMKNBcOF+akrW11QutwLP8Jvc9/DpyCWKhDD9MZDCIAbf7IYFlBxX0UjHMnVJyOR5ijh 7A2v9MErFfFs1Dapgk15fAD7XzhK+wgeP4e68Wh4IwOaLa8aW5JYEmYKdN7hO/LTdbvS Rtkg== 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=KbaeJ8QlSyFUH0GVTxpw3rgJ1SmDBqkdbZooR4/DdFw=; b=tvKMFfsgX/aW/ox2DcDfnWgvewi6Hy1QM4kXWtUlCoQY11Q2r+Ccimiho5Su2nsZF0 b6Lgj76XfCCnwXoZQoaOJftlR/uCi9K7WUz+WTRIVJswneIx/Qj4TXxCzXeK1koSTa1i CFPFZEDr9PYoLdrCQoKNxt/bK3QkQzk/JGPEL78Yism1DT9nuOXf9REoLcwxueykmFGj UJ6z3D4Qi8Q/WJvG5TyzFm+PSSqugRt6vp683mKa4BJLUOkmLTuTv+ey+aGBjRuKGCWy Sx3MJ0PAejfcT7obuRLrCUWA0SZKp6eScH2nifxV0/ve8FXV/CdnsRwW2Amen42klV2U 2RIA== 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 e7si139090ejm.291.2020.12.04.16.43.59; Fri, 04 Dec 2020 16:44:21 -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 S1730659AbgLEAlm (ORCPT + 99 others); Fri, 4 Dec 2020 19:41:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:48878 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727566AbgLEAll (ORCPT ); Fri, 4 Dec 2020 19:41:41 -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, "Paul E. McKenney" , Ming Lei , Jens Axboe Subject: [PATCH sl-b 5/6] percpu_ref: Print allocator upon reference-count underflow Date: Fri, 4 Dec 2020 16:40:56 -0800 Message-Id: <20201205004057.32199-5-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20201205004022.GA31166@paulmck-ThinkPad-P72> References: <20201205004022.GA31166@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 prints the percpu_ref allocation site using the new kmem_last_alloc() and kmem_last_alloc_errstring() functions in order to provide a bit more information for the kernel-deployment case. Cc: Ming Lei Cc: Jens Axboe Reported-by: Andrii Nakryiko Signed-off-by: Paul E. McKenney --- lib/percpu-refcount.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c index e59eda0..8c7b21a0 100644 --- a/lib/percpu-refcount.c +++ b/lib/percpu-refcount.c @@ -169,6 +169,8 @@ static void percpu_ref_switch_to_atomic_rcu(struct rcu_head *rcu) struct percpu_ref *ref = data->ref; unsigned long __percpu *percpu_count = percpu_count_ptr(ref); unsigned long count = 0; + void *allocaddr; + const char *allocerr; int cpu; for_each_possible_cpu(cpu) @@ -191,9 +193,16 @@ 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 (atomic_long_read(&data->count) <= 0) { + allocaddr = kmem_last_alloc(data); + allocerr = kmem_last_alloc_errstring(allocaddr); + if (allocerr) + WARN_ONCE(1, "percpu ref (%ps) <= 0 (%ld) after switching to atomic (%s)", + data->release, atomic_long_read(&data->count), allocerr); + else + WARN_ONCE(1, "percpu ref (%ps) <= 0 (%ld) after switching to atomic (allocated at %pS)", + data->release, atomic_long_read(&data->count), allocaddr); + } /* @ref is viewed as dead on all CPUs, send out switch confirmation */ percpu_ref_call_confirm_rcu(rcu); -- 2.9.5