From patchwork Fri Aug 24 12:40:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 10575309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCEA0921 for ; Fri, 24 Aug 2018 12:40:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC3F12C1E2 for ; Fri, 24 Aug 2018 12:40:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B03332C1EB; Fri, 24 Aug 2018 12:40:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6E372C1E2 for ; Fri, 24 Aug 2018 12:40:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A991B6B2F90; Fri, 24 Aug 2018 08:40:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A48206B2F91; Fri, 24 Aug 2018 08:40:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 960106B2F9B; Fri, 24 Aug 2018 08:40:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by kanga.kvack.org (Postfix) with ESMTP id 238106B2F90 for ; Fri, 24 Aug 2018 08:40:39 -0400 (EDT) Received: by mail-lf1-f69.google.com with SMTP id p19-v6so2039671lfg.14 for ; Fri, 24 Aug 2018 05:40:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=tlewZZj00wKKEDREfp/J1yVllfPap3nKUUZ8zA0MX78=; b=PxjyTA1BFkPx84f8+blzzHPSPuABmDSuMsYgiFHGkahxBXBYgAschJN12HoLrWeXk+ L0OKoMtWA4ZIinSN0yzzuFrA6g/NG+hhiEVvYEQhzgWxr6nsrnjwXEZPySG5IVRU66gr aplxXEWfkVBTlhfCuhogF0WcfSKzqHcqkBZVPjGfwG86U3LLgFVArCFul+8QPvqT6n23 elWOYMfvelE9M+bSXgwEbhySjJxcruOXzJ2YxOy08V905OdrBKrIvE692kHVTQD7xr7V UZM892VNvmUQ2FTvdEiIXiM7c3VuoW/xrTpKiLt9HlUdW9zievn4+uQ1ALwYzBNUX7xH KjjA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) smtp.mailfrom=vincent.whitchurch@axis.com X-Gm-Message-State: APzg51Ase5o9qVkh/45p2sbaqYnnPYy3AEPTse9iTdX+EG/yy0XEkZoo zqEZ2qZ8kdY8MCxKsRE+AImPUbmVlcxoNpX0j7bP2Kh0COi0j6p4jVgrtSsPURB7jiLpiEW/13b Qn8Qi7msyopN7xsXxyZK/E6SSaBiv7JFZnnEWZFJWFLfmv8SSV5WLX1zKo7bJRoavZw== X-Received: by 2002:a2e:5f93:: with SMTP id x19-v6mr1281891lje.60.1535114438382; Fri, 24 Aug 2018 05:40:38 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda5gNCUYuFgTXrJFA87kGCc7YPqikQIa/ICvjHS6U91066T8xg33XGfF6fH358Et2Pbc66P X-Received: by 2002:a2e:5f93:: with SMTP id x19-v6mr1281848lje.60.1535114437424; Fri, 24 Aug 2018 05:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535114437; cv=none; d=google.com; s=arc-20160816; b=WgRLfU7nmlCBjMO3e3EtRGRdppQwyckqfkhIrOJOOCMh/cUHVaza4CDEZV6XIwJnu5 NxX0nyxFXENF/a2eLStuAaa5ZjulDYnfo04Nj5h3bJXtRRjXWdKle4knu9zeLfDk9md8 LYuE/XGNhORDI7EJHyGBBQcO66ZhXzuanrNjxmM8hhQ6ViZekgwf+JHuCgs/w23sfDOW /sCv9vFaLla8Iwm21OCnx1g11zMjxVM/+lbAKZF4dj1PZ/UaleviB9lzdQSTtzGH9n8K FpuN9/aD82W+S2p8QbAt1+l/+GimT9xtII12OPTb4TjkxJ/NtYGs0fgM9NC6HzKIjf0v VINg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=tlewZZj00wKKEDREfp/J1yVllfPap3nKUUZ8zA0MX78=; b=TQvdGF6U3dMjz7Kjb+m3zDZqvTic1z26irM0h8Nv3B6/8dQMsKXJFoo3TeoSrGNTer ta1aRfh2A5La1OPWI4cDrPYvlnXSIfZuUQRJ6cvvl9/HMz/oO/l/+m/qaDEK8rFGfQ6c zdH332gSj4nJhGakH48l659Qfsk+wAmnko/A3imNmtGEIwvEXGLn2oZuGe7K1ZmQOmKd 5twEGj2prNPanfeZeQwQFY+20N/fiXstTy6XYZHAZIiqFwa31hvTRyCVkFX3tWt5ZEOz eHKmxi5xKsz498Zgf8WWVIKnPMLBYcT0qYmOt9/MHVJfX2E5/85RmN99gdEazFIYTsWs ZthQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) smtp.mailfrom=vincent.whitchurch@axis.com Received: from bastet.se.axis.com (bastet.se.axis.com. [195.60.68.11]) by mx.google.com with ESMTPS id f141-v6si2361248lfg.137.2018.08.24.05.40.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Aug 2018 05:40:37 -0700 (PDT) Received-SPF: pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) client-ip=195.60.68.11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of vincent.whitchurch@axis.com designates 195.60.68.11 as permitted sender) smtp.mailfrom=vincent.whitchurch@axis.com Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id E4AAD184CD; Fri, 24 Aug 2018 14:40:36 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id j8J-Yr8PnoKx; Fri, 24 Aug 2018 14:40:36 +0200 (CEST) Received: from boulder03.se.axis.com (boulder03.se.axis.com [10.0.8.17]) by bastet.se.axis.com (Postfix) with ESMTPS id 06A76184B7; Fri, 24 Aug 2018 14:40:35 +0200 (CEST) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D3D8E1E06C; Fri, 24 Aug 2018 14:40:35 +0200 (CEST) Received: from boulder03.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C6B501E068; Fri, 24 Aug 2018 14:40:35 +0200 (CEST) Received: from seth.se.axis.com (unknown [10.0.2.172]) by boulder03.se.axis.com (Postfix) with ESMTP; Fri, 24 Aug 2018 14:40:35 +0200 (CEST) Received: from lnxartpec.se.axis.com (lnxartpec.se.axis.com [10.88.4.9]) by seth.se.axis.com (Postfix) with ESMTP id B94F23118; Fri, 24 Aug 2018 14:40:35 +0200 (CEST) Received: by lnxartpec.se.axis.com (Postfix, from userid 10564) id B27198016F; Fri, 24 Aug 2018 14:40:35 +0200 (CEST) From: Vincent Whitchurch To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vincent Whitchurch Subject: [PATCH] kmemleak: Add option to print warnings to dmesg Date: Fri, 24 Aug 2018 14:40:11 +0200 Message-Id: <20180824124011.22879-1-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.11.0 X-TM-AS-GCONF: 00 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Currently, kmemleak only prints the number of suspected leaks to dmesg but requires the user to read a debugfs file to get the actual stack traces of the objects' allocation points. Add an option to print the stack trace information (except the hex dumps) to dmesg too. This allows easier integration of kmemleak into automated test systems since those kind of systems presumably already save kernel logs. Signed-off-by: Vincent Whitchurch --- lib/Kconfig.debug | 9 +++++++++ mm/kmemleak.c | 21 +++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ab1b599202bc..9a3fc905b8bd 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -593,6 +593,15 @@ config DEBUG_KMEMLEAK_DEFAULT_OFF Say Y here to disable kmemleak by default. It can then be enabled on the command line via kmemleak=on. +config DEBUG_KMEMLEAK_WARN + bool "Print kmemleak object warnings to log buffer" + depends on DEBUG_KMEMLEAK + help + Say Y here to make kmemleak print information about unreferenced + objects (including stacktraces) as warnings to the kernel log buffer. + Otherwise this information is only available by reading the kmemleak + debugfs file. + config DEBUG_STACK_USAGE bool "Stack utilization instrumentation" depends on DEBUG_KERNEL && !IA64 diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 9a085d525bbc..61ba47a357fc 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -311,6 +311,9 @@ static void hex_dump_object(struct seq_file *seq, const u8 *ptr = (const u8 *)object->pointer; size_t len; + if (!seq) + return; + /* limit the number of lines to HEX_MAX_LINES */ len = min_t(size_t, object->size, HEX_MAX_LINES * HEX_ROW_SIZE); @@ -355,6 +358,13 @@ static bool unreferenced_object(struct kmemleak_object *object) jiffies_last_scan); } +#define warn_or_seq_printf(seq, fmt, ...) do { \ + if (seq) \ + seq_printf(seq, fmt, ##__VA_ARGS__); \ + else \ + pr_warn(fmt, ##__VA_ARGS__); \ +} while (0) + /* * Printing of the unreferenced objects information to the seq file. The * print_unreferenced function must be called with the object->lock held. @@ -365,17 +375,17 @@ static void print_unreferenced(struct seq_file *seq, int i; unsigned int msecs_age = jiffies_to_msecs(jiffies - object->jiffies); - seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\n", + warn_or_seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\n", object->pointer, object->size); - seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu (age %d.%03ds)\n", + warn_or_seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu (age %d.%03ds)\n", object->comm, object->pid, object->jiffies, msecs_age / 1000, msecs_age % 1000); hex_dump_object(seq, object); - seq_printf(seq, " backtrace:\n"); + warn_or_seq_printf(seq, " backtrace:\n"); for (i = 0; i < object->trace_len; i++) { void *ptr = (void *)object->trace[i]; - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr); + warn_or_seq_printf(seq, " [<%p>] %pS\n", ptr, ptr); } } @@ -1598,6 +1608,9 @@ static void kmemleak_scan(void) if (unreferenced_object(object) && !(object->flags & OBJECT_REPORTED)) { object->flags |= OBJECT_REPORTED; +#ifdef CONFIG_DEBUG_KMEMLEAK_WARN + print_unreferenced(NULL, object); +#endif new_leaks++; } spin_unlock_irqrestore(&object->lock, flags);