Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp809640pxu; Fri, 4 Dec 2020 16:45:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJyz1FrDXbkHI0s29OT7koqz5imSb3UTfentCslO3erJb8wqVCK54tCfX23va7elzBUrI/2T X-Received: by 2002:a17:907:20a6:: with SMTP id pw6mr9896840ejb.73.1607129132512; Fri, 04 Dec 2020 16:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607129132; cv=none; d=google.com; s=arc-20160816; b=cbpyQ+a5VPHyA4w0A3TDd1TtHcaSQtVoYZpJPm15OuFhgYsHn9+b1iWO3P40664XKl 1w2RIzdAHM60zisKhThdODeLFisE8VjE4XDudMkzTQ6R7agb/Rbd5SWQJvyoOWN+c1gG srtWrgy/4+VnhxDh4CaDZ1UySBcfVh4HpFTGN/pC24XvtQOptF4OlQlrgCoWu6+SzZig 3yvgvyDJJ3alrkmGUe/TOr1lbGMXycKq3xpEmAuhD0o5hTXhuRh2w8dwZIY+PhV15Ytd yZDmvt/UCdZJIjecAMS9WTN5L6bdiR6EE8MpgrCyWygU1q5gliA5QWpU60BVUEi8haE8 d89g== 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=42oTlVVD9fT3v5V3QWaOyNIsgmezLhRoaa1TDHD+3jc=; b=RCaa2PkGyOir3aXGezoJi5t5rgjiOOYJCAxxai/U4zXlXiuELfiv2E2PlN7+awJFqa +y3KZgA9cXw7dfh7XHprq/6NxAA35wUQ/PkFndwaZfL/R1F2h8nSiQdXrbj9SweSRpZx UTx/LllMNcGOfjW0SQsvG6iwLoivlfUmkAfXt4UXWBGdDDcHFPQHGYBfZ8srSCGAABWW GeFvuRRr5uE/hY1piXpxay0DeVLVknCTcRQ4swaXgCzXlg57Hlvh5IdKLSlnD+56R856 RhNuNkHTGzgV9cCqLoKwQUr6qsflEOigEjdPt4G8OPGFJ1tiF/4ew2xh9jbzTe5q5btk NuPg== 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 a9si3999346edn.611.2020.12.04.16.45.10; Fri, 04 Dec 2020 16:45:32 -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 S1730988AbgLEAl6 (ORCPT + 99 others); Fri, 4 Dec 2020 19:41:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:48806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbgLEAll (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" , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , linux-mm@kvack.org, Andrii Nakryiko Subject: [PATCH sl-b 3/6] rcu: Make call_rcu() print allocation address of double-freed callback Date: Fri, 4 Dec 2020 16:40:54 -0800 Message-Id: <20201205004057.32199-3-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" The debug-object double-free checks in __call_rcu() print out the RCU callback function, which is usually sufficient to track down the double free. However, all uses of things like queue_rcu_work() will have the same RCU callback function (rcu_work_rcufn() in this case), so a diagnostic message for a double queue_rcu_work() needs more than just the callback function. This commit therefore prints the last allocation address of the double-freed callback when the callback is slab-allocated and sufficient debugging is enabled. It uses the shiny new kmem_last_alloc() and kmem_last_alloc_errstring() functions for this purpose. Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Cc: Andrew Morton Cc: Cc: Andrii Nakryiko Signed-off-by: Paul E. McKenney --- kernel/rcu/tree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index b6c9c49..788a072 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2957,6 +2957,8 @@ static void check_cb_ovld(struct rcu_data *rdp) static void __call_rcu(struct rcu_head *head, rcu_callback_t func) { + void *allocaddr; + const char *allocerr; unsigned long flags; struct rcu_data *rdp; bool was_alldone; @@ -2970,8 +2972,14 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func) * Use rcu:rcu_callback trace event to find the previous * time callback was passed to __call_rcu(). */ - WARN_ONCE(1, "__call_rcu(): Double-freed CB %p->%pS()!!!\n", - head, head->func); + allocaddr = kmem_last_alloc(head); + allocerr = kmem_last_alloc_errstring(allocaddr); + if (allocerr) + WARN_ONCE(1, "__call_rcu(): Double-freed CB %p->%pS()!!! (%s)\n", + head, head->func, allocerr); + else + WARN_ONCE(1, "__call_rcu(): Double-freed CB %p->%pS()!!! (Allocated at %pS)\n", + head, head->func, allocaddr); WRITE_ONCE(head->func, rcu_leak_callback); return; } -- 2.9.5