Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp808312pxu; Fri, 4 Dec 2020 16:43:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxzhNHviSNcicD4eHkGPnypPTl4LvR3mesV23v7KyOPk1Sw904XkvNKHgz7JpET18rhK21 X-Received: by 2002:a05:6402:4d2:: with SMTP id n18mr9938862edw.169.1607128981460; Fri, 04 Dec 2020 16:43:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607128981; cv=none; d=google.com; s=arc-20160816; b=Grxbll0VzMLkLy7Bg4yf42uqa5UN0SdjG8/aXVRUYT7QFJGH2bALqXt6uBwhrU+tmf am0moRp10ftE/+GULSfL6NWXC0ckH5ljtqxLtC6ozFFF6sOCjiEeV/yrIsiNVgJcPG8J ZvtJvud+/gYoLNmn7ONoQsAhDm74a11xc0RR38qEXZNwLnZOZ85L+OBe7afb2aguv6Bm y0K4c376+pggqIBgTPhhKGKpA9UZNM1pqSnt7PldNzSzqRcRXii3wYYw5uW1664EISDj h/1lHViVZoC1COpGhenx6Go1SXmHkkRSXZfIG0TIKNHsBAn7mvdEBcA7FU6w6R84LuAG DNlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :reply-to:message-id:subject:cc:to:from:dkim-signature:date; bh=kpiCCk9hem9chMhoI6WCv3SzDtFQ1bka8iHIXf0EBIs=; b=KiJJ7CQuXeKQxKe6YN3RSFs9Y5Mae0zO/SHooVTsSwV+gYDer4/kferIm4r2H+RDIp b+/nxt3F6fWKiSgF+RQ6D8DFBm8J1i5ZlEVcRWJEp4FaGO0vxGPtDQdJmDucxVNjEa8P 21NPdgf5ogwFdhkPHkUwJAjHIK7VE2Ml61zvt8zlVMHwmXu5O+a0TLCsd0XW6QSUukP/ zP/XzFfPquWqHUpjfXQyWTLjymStExvbzg+0RVL08x9FfN8KTVn31yNyWucadS80AYxm 4pSIW5lc8qvxnZ2wOQxc9Lb1ym0N7HKBRU0UAXV91RVF4OaNmSJDT5DpRkrH/jkLG3S1 A9Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YskyC6KT; 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 dt10si2611518ejc.145.2020.12.04.16.42.38; Fri, 04 Dec 2020 16:43:01 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YskyC6KT; 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 S1726567AbgLEAlD (ORCPT + 99 others); Fri, 4 Dec 2020 19:41:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:48678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725300AbgLEAlC (ORCPT ); Fri, 4 Dec 2020 19:41:02 -0500 Date: Fri, 4 Dec 2020 16:40:22 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1607128822; bh=sTrddOHUARRjPrBPOmL3jLG/F+XsHep/EkJCIjlSO0M=; h=From:To:Cc:Subject:Reply-To:From; b=YskyC6KTk5Poxto+IqKhV4eBvLGw58/MhuVoRaD8iXdON0i56dDZkhBdzGN0qbVn8 QuznYc5THyRkb4pm3qTjdGwdujTP11Stc0B+pZnIpN7Y76vBviKUz+LlO2oZ6f0rXf zYbqFF/JjrPNdyO3P93LonABYae3uy6J3MiH2PI5oEa0IUPJ9bLiQ/2MpIud5ja3Tm 9+2ptiVmbi/wc3eQcyxkePcJd1IT8TMjlR6R9/QRtLB1+Y8tUYSTF1/bSTdn5ZdQ15 VaM6LR9B6SzupaVKpJHM2VRqPOLIfCc79PCpeQK70nj7z2GotKLyIx3tGSroICfbtg Bf0RiQb+/ztNA== From: "Paul E. McKenney" 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 Subject: [PATCH RFC sl-b] Export return addresses for better diagnostics Message-ID: <20201205004022.GA31166@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello! This series improves diagnostics by providing access to return addresses and stack traces collected by the sl*b allocators. If the allocator is not configured to collect this information, the diagnostics fall back to a reasonable approximation of their earlier state. One use case is the queue_rcu_work() function, which might be used by any number of kernel subsystems. If the caller does back-to-back invocations of queue_rcu_work(), this constitutes a double-free bug, and (if so configured) the debug-objects system will flag this, printing the callback function. In most cases, printing this function suffices. However, for double-free bugs involving queue_rcu_work(), the RCU callback function will always be rcu_work_rcufn(), which provides almost no help to the poor person trying to find this double-free bug. The return address from the allocator of the memory containing the rcu_work structure can provide an additional valuable clue. Another use case is the percpu_ref_switch_to_atomic_rcu() function, which detects percpu_ref reference-count underflow. Unfortunately, the only data that this function has access to doesn't have much in the way of identifying characteristics. Yes, it might be possible to gain more information from a crash dump, but it is more convenient for the needed hints to be in the console log. Unfortunately, printing the return address in this case is of little help because this object is allocated from percpu_ref_init(), regardless of what part of the kernel is responsible for the reference-count underflow. However, CONFIG_STACKTRACE=y kernels (such as those enabling ftrace) using slub with debugging enabled also collect stack traces. This series therefore also provides a way of extracting these stack traces to provide additional information to those debugging percpu_ref reference-count underflows. The patches are as follows: 1. Add kmem_last_alloc() to return last allocation for memory block. 2. Add kmem_last_alloc_errstring() to provide more kmem_last_alloc() info. 3. Make call_rcu() print allocation address of double-freed callback. 4. Create kmem_last_alloc_stack() to provide stack trace in slub. 5. percpu_ref: Print allocator upon reference-count underflow. 6. percpu_ref: Print stack trace upon reference-count underflow. Thanx, Paul ------------------------------------------------------------------------ include/linux/slab.h | 15 ++++++++ kernel/rcu/tree.c | 12 +++++- lib/percpu-refcount.c | 39 ++++++++++++++++------ mm/slab.c | 61 +++++++++++++++++++++++------------ mm/slab_common.c | 87 ++++++++++++++++++++++++++++++++++++++++++++------ mm/slob.c | 11 +++++- mm/slub.c | 44 +++++++++++++++++++++++-- 7 files changed, 222 insertions(+), 47 deletions(-)