Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp828027ybv; Wed, 19 Feb 2020 10:04:00 -0800 (PST) X-Google-Smtp-Source: APXvYqzxNrwR2kvJqFinTjLrYyyrs6ASSnPa8BsxoGfrrZ45c6TL5TQp397uhT2mOFbnuTc4kj5g X-Received: by 2002:a05:6808:30d:: with SMTP id i13mr5172823oie.144.1582135440112; Wed, 19 Feb 2020 10:04:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582135440; cv=none; d=google.com; s=arc-20160816; b=flIKFSAYAgekJ0kwoaReQdOFHyr1rxo5WHP4D+W67BDn/4zizQ/fl/8Iuh2sIElrMc aZQF8fWckGuN/L/3lkC4EB5Xo9Z6xlwRkRiPCn2D8bks6bXd68sNhxElAKOXQNeNxCBi oznzpqEHeH6gNSDniw/AbDOByqpl9Dbwiqlu+4XJUWxxCyA5o4vqrVZ+SdGjZWtwBD+X VhGnSKBvloQMorjGv+YTaDBnHlhAQYidDbGe+AgAoAyQZxJIsLEvL6KAj9Oeg0PKiX3/ xyR8RSrxye334DhefxOlGLlTBH432VkJ/z8Pe/VZxPsxbsluUTaYOOsTzw0bP4k1yNQK B5Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=gnZ1F9gUnRDWBV4JdOstiTb0zYeGazVBoDuMiIXRXm8=; b=QmIPBhNNAnDTTPoHrpGdNdUO5WsTmSuDZ7RlCynEc7uRITKqsYR0qf5JcUwOZ5CHJv AEYbGoJWmqEIPVthdKOmH57DJccqeMBI5u/oQkF4Uxj0ejJvHPT8LghepF8Au0mSkc3p twwhQeR/lIUM3UQziVpCH8zSgObZ3KLqOB1w9ftfPwEIOR634lQ4J0IBrZxnmgjccNxv aKjK2JrkYqZLaEOj5mcdK21BnWazL++bvUWzLemZWMAvAtHCCSSO1ZVrDKQBmajzvdUt yFUP7Vbn0E7v2+g8j6R2kgQzXmGZ95ThWqufr4Wo68+Hx60suMV11rFADenFtlXTxGOn hLHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PC5SIEBR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id m7si234523otk.73.2020.02.19.10.03.45; Wed, 19 Feb 2020 10:04:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PC5SIEBR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726697AbgBSSB4 (ORCPT + 99 others); Wed, 19 Feb 2020 13:01:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:55376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgBSSB4 (ORCPT ); Wed, 19 Feb 2020 13:01:56 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 55DE924656; Wed, 19 Feb 2020 18:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582135315; bh=yicJpUKBY2lCa9DYQFX7OM+15TFASg4m1KjhxR4TRrg=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=PC5SIEBReGWN148eb6cKbeEnEH8xCSoQLAR4zMnI7g8CMFnTHpY5MTzTD9vvKt0u2 6Xp1txu9xJjZ60zf7UuDW7tef7+0WSiyZPUaYB9Wh/EyalgypJ97aEqhtBa7Uixhy6 GpjopJBrcLEV0y6zMVkAgpg3BKT6wavjwTCy1YXc= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 2AFF335209B0; Wed, 19 Feb 2020 10:01:55 -0800 (PST) Date: Wed, 19 Feb 2020 10:01:55 -0800 From: "Paul E. McKenney" To: Marco Elver Cc: andreyknvl@google.com, glider@google.com, dvyukov@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Qian Cai Subject: Re: [PATCH] kcsan: Add option for verbose reporting Message-ID: <20200219180155.GM2935@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200219151531.161515-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219151531.161515-1-elver@google.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 04:15:31PM +0100, Marco Elver wrote: > Adds CONFIG_KCSAN_VERBOSE to optionally enable more verbose reports. > Currently information about the reporting task's held locks and IRQ > trace events are shown, if they are enabled. > > Signed-off-by: Marco Elver > Suggested-by: Qian Cai Queued for testing and review, thank you! Thanx, Paul > --- > kernel/kcsan/report.c | 48 +++++++++++++++++++++++++++++++++++++++++++ > lib/Kconfig.kcsan | 13 ++++++++++++ > 2 files changed, 61 insertions(+) > > diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c > index 11c791b886f3c..f14becb6f1537 100644 > --- a/kernel/kcsan/report.c > +++ b/kernel/kcsan/report.c > @@ -1,10 +1,12 @@ > // SPDX-License-Identifier: GPL-2.0 > > +#include > #include > #include > #include > #include > #include > +#include > #include > #include > #include > @@ -245,6 +247,29 @@ static int sym_strcmp(void *addr1, void *addr2) > return strncmp(buf1, buf2, sizeof(buf1)); > } > > +static void print_verbose_info(struct task_struct *task) > +{ > + if (!task) > + return; > + > + if (task != current && task->state == TASK_RUNNING) > + /* > + * Showing held locks for a running task is unreliable, so just > + * skip this. The printed locks are very likely inconsistent, > + * since the stack trace was obtained when the actual race > + * occurred and the task has since continued execution. Since we > + * cannot display the below information from the racing thread, > + * but must print it all from the watcher thread, bail out. > + * Note: Even if the task is not running, there is a chance that > + * the locks held may be inconsistent. > + */ > + return; > + > + pr_err("\n"); > + debug_show_held_locks(task); > + print_irqtrace_events(task); > +} > + > /* > * Returns true if a report was generated, false otherwise. > */ > @@ -319,6 +344,26 @@ static bool print_report(const volatile void *ptr, size_t size, int access_type, > other_info.num_stack_entries - other_skipnr, > 0); > > + if (IS_ENABLED(CONFIG_KCSAN_VERBOSE) && other_info.task_pid != -1) { > + struct task_struct *other_task; > + > + /* > + * Rather than passing @current from the other task via > + * @other_info, obtain task_struct here. The problem > + * with passing @current via @other_info is that, we > + * would have to get_task_struct/put_task_struct, and if > + * we race with a task being released, we would have to > + * release it in release_report(). This may result in > + * deadlock if we want to use KCSAN on the allocators. > + * Instead, make this best-effort, and if the task was > + * already released, we just do not print anything here. > + */ > + rcu_read_lock(); > + other_task = find_task_by_pid_ns(other_info.task_pid, &init_pid_ns); > + print_verbose_info(other_task); > + rcu_read_unlock(); > + } > + > pr_err("\n"); > pr_err("%s to 0x%px of %zu bytes by %s on cpu %i:\n", > get_access_type(access_type), ptr, size, > @@ -340,6 +385,9 @@ static bool print_report(const volatile void *ptr, size_t size, int access_type, > stack_trace_print(stack_entries + skipnr, num_stack_entries - skipnr, > 0); > > + if (IS_ENABLED(CONFIG_KCSAN_VERBOSE)) > + print_verbose_info(current); > + > /* Print report footer. */ > pr_err("\n"); > pr_err("Reported by Kernel Concurrency Sanitizer on:\n"); > diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan > index f0b791143c6ab..ba9268076cfbc 100644 > --- a/lib/Kconfig.kcsan > +++ b/lib/Kconfig.kcsan > @@ -20,6 +20,19 @@ menuconfig KCSAN > > if KCSAN > > +config KCSAN_VERBOSE > + bool "Show verbose reports with more information about system state" > + depends on PROVE_LOCKING > + help > + If enabled, reports show more information about the system state that > + may help better analyze and debug races. This includes held locks and > + IRQ trace events. > + > + While this option should generally be benign, we call into more > + external functions on report generation; if a race report is > + generated from any one of them, system stability may suffer due to > + deadlocks or recursion. If in doubt, say N. > + > config KCSAN_DEBUG > bool "Debugging of KCSAN internals" > > -- > 2.25.0.265.gbab2e86ba0-goog >