Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2356886ybl; Thu, 9 Jan 2020 11:17:07 -0800 (PST) X-Google-Smtp-Source: APXvYqyDJ/S0YWfkAxanab+RruT7zdT/ddWzBsqGY7Y5uKdhzdAh0JZioaFJocTxYo2EEg6go5VV X-Received: by 2002:aca:4dd6:: with SMTP id a205mr4252886oib.43.1578597427258; Thu, 09 Jan 2020 11:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578597427; cv=none; d=google.com; s=arc-20160816; b=ia8YH7rIEwl0xlS2e6d+HTp1pz1r0DJEPAPqoCgr8/+zZ9dnoD9faha5G+Pf202CKk 4KUhLy8DgAcE4oP0S3dbyPtZBfcDLVkdNU5IrhoBanApk4Q5OujsbOOWQ4At8gkR4uMn 3frKcCNLnwnjGr556AzDKJl68aNYf7k9B+o2BsHtNQWeEZOSme+Z/xgbuQuOf2eqmrDc zZVtAhC+gJhCHNSVEeflPBC51KCfO8cvrH9JTmyIpvbORZXZxjskRtJF+8+jshFG+pi8 tVxplxAkP1QEFgx6wDEvQh660yabK6vLB+/PrH0AW4qqeyYI2VCRVHshPzHv7ykkziFr KgsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=jq0KfymqHCwAzpI6yM9iLGY3LYJxpSimWAtJZq35DB8=; b=kYde5HWEa5q/+LzpIxdgwT8OI9b/QUd2Hb029xerJX/16xPeIac6QQF02gMZokDAO4 fT+V/v9UuI0tWaIr8D9J9EFaWSZ0G+X+eQGgYiJkfnxuTKXZHWIWOigX4NX7jmpPpeML w5Fj9Ttc5IG2mbdDo89A5U1K3H169h4SQw/eHbFxF1g0UQLAS21K0sPlKlP71Ss9PIKT BHvxge/tXm0dpdZ5x4cmG89y4U+a6ee65GkdxO/BLIjYQIr560bAxRsMJQbtiEDo/Sjr no/RCbLRAreSKgRYu/2cfn9MX4NFY+lpbjOZOIpGtA6bfU3CLOI1PKj+Njabzjmfwetd L5Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YFVOVJQJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m4si4142913otn.281.2020.01.09.11.16.54; Thu, 09 Jan 2020 11:17:07 -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=@google.com header.s=20161025 header.b=YFVOVJQJ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732377AbgAIPXk (ORCPT + 99 others); Thu, 9 Jan 2020 10:23:40 -0500 Received: from mail-wr1-f73.google.com ([209.85.221.73]:36922 "EHLO mail-wr1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732359AbgAIPXk (ORCPT ); Thu, 9 Jan 2020 10:23:40 -0500 Received: by mail-wr1-f73.google.com with SMTP id z14so3030565wrs.4 for ; Thu, 09 Jan 2020 07:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=jq0KfymqHCwAzpI6yM9iLGY3LYJxpSimWAtJZq35DB8=; b=YFVOVJQJP7CmAnMj0nn4DvcX4+cZslPAELQzpObx7LA5SBjxFDEKYoXdEzpMGIkss+ T6xL7TtuA1AlQukiKQH5UiuvhCDfhIFTWyMa2Jkxtu/mhl+Ig7aoKxIAeIO3MT2Omy1s sXRCYvQzlg6HFsrBBmYlgRrGCFiBfwsTls0Qosuc9O1gtG8/5RMSIoEyZ7tknwFbbvSP 6WUJQHizLoh9/Vxg0hBtVru27cw0VWwycDDqDtPQjQkzMl2KC9HXyQHCRr7uYDKlB9wU fN52/INesG6BHD8S0070AWfZbMQfE43M8i9K5my8R00v0rR2V0zzfoWt7z7GcLyFWGDd Q/kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=jq0KfymqHCwAzpI6yM9iLGY3LYJxpSimWAtJZq35DB8=; b=QiXC4GxL7oNJCxJoB/jFwWO85ACmqMTP7slywzzMVB1eBfMvcciFSMqXdDv+hR1IcZ X7rpWIS0ufcj1vxiqQvBkrhHlxU31I+mACJxXRUNZu0oRIEfVHYPaBcMYVKAg2MVtIgy 8FlfVVIqH6Y1kM9oDpf37v5yw6IOKXYuGhkiibo6NL18XWw7a82smoHn6xTB9JiAEq8m U+aepAuh99LUYIZXgAVquGTfd8AsjY/6O8RVKGxh1ywapQizXNRz5BFXSmoWL9WKXiRt Zi5AYM40NFTTipcBBUimdzVgFyyyZC2CcYpmGBqPhwpsBMeYYXTwDtXlLm9WH8ZvZbQH orsQ== X-Gm-Message-State: APjAAAUKWNBAyOsGf0vImsoqhOrIPKcl4V/AXsqx/Hhbu4M1JWv5vCMk H7FV06pnOlK9V91x0dJcAe1tcStkhA== X-Received: by 2002:a5d:5704:: with SMTP id a4mr11552160wrv.198.1578583417361; Thu, 09 Jan 2020 07:23:37 -0800 (PST) Date: Thu, 9 Jan 2020 16:23:21 +0100 In-Reply-To: <20200109152322.104466-1-elver@google.com> Message-Id: <20200109152322.104466-2-elver@google.com> Mime-Version: 1.0 References: <20200109152322.104466-1-elver@google.com> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog Subject: [PATCH -rcu 1/2] kcsan: Show full access type in report From: Marco Elver To: elver@google.com Cc: paulmck@kernel.org, andreyknvl@google.com, glider@google.com, dvyukov@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This change adds support for showing the complete access type in the report. Currently the following access types can be shown: "read", "read (marked)", "write", "write (marked)". Suggested-by: Paul E. McKenney Signed-off-by: Marco Elver --- kernel/kcsan/core.c | 15 ++++++++------- kernel/kcsan/kcsan.h | 2 +- kernel/kcsan/report.c | 43 ++++++++++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c index 4d4ab5c5dc53..87bf857c8893 100644 --- a/kernel/kcsan/core.c +++ b/kernel/kcsan/core.c @@ -255,7 +255,7 @@ static inline unsigned int get_delay(void) static noinline void kcsan_found_watchpoint(const volatile void *ptr, size_t size, - bool is_write, + int type, atomic_long_t *watchpoint, long encoded_watchpoint) { @@ -276,7 +276,7 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr, flags = user_access_save(); if (consumed) { - kcsan_report(ptr, size, is_write, true, raw_smp_processor_id(), + kcsan_report(ptr, size, type, true, raw_smp_processor_id(), KCSAN_REPORT_CONSUMED_WATCHPOINT); } else { /* @@ -292,8 +292,9 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr, } static noinline void -kcsan_setup_watchpoint(const volatile void *ptr, size_t size, bool is_write) +kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) { + const bool is_write = (type & KCSAN_ACCESS_WRITE) != 0; atomic_long_t *watchpoint; union { u8 _1; @@ -415,13 +416,13 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, bool is_write) * No need to increment 'data_races' counter, as the racing * thread already did. */ - kcsan_report(ptr, size, is_write, size > 8 || value_change, + kcsan_report(ptr, size, type, size > 8 || value_change, smp_processor_id(), KCSAN_REPORT_RACE_SIGNAL); } else if (value_change) { /* Inferring a race, since the value should not have changed. */ kcsan_counter_inc(KCSAN_COUNTER_RACES_UNKNOWN_ORIGIN); if (IS_ENABLED(CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN)) - kcsan_report(ptr, size, is_write, true, + kcsan_report(ptr, size, type, true, smp_processor_id(), KCSAN_REPORT_RACE_UNKNOWN_ORIGIN); } @@ -455,10 +456,10 @@ static __always_inline void check_access(const volatile void *ptr, size_t size, */ if (unlikely(watchpoint != NULL)) - kcsan_found_watchpoint(ptr, size, is_write, watchpoint, + kcsan_found_watchpoint(ptr, size, type, watchpoint, encoded_watchpoint); else if (unlikely(should_watch(ptr, type))) - kcsan_setup_watchpoint(ptr, size, is_write); + kcsan_setup_watchpoint(ptr, size, type); } /* === Public interface ===================================================== */ diff --git a/kernel/kcsan/kcsan.h b/kernel/kcsan/kcsan.h index d3b9a96ac8a4..8492da45494b 100644 --- a/kernel/kcsan/kcsan.h +++ b/kernel/kcsan/kcsan.h @@ -103,7 +103,7 @@ enum kcsan_report_type { /* * Print a race report from thread that encountered the race. */ -extern void kcsan_report(const volatile void *ptr, size_t size, bool is_write, +extern void kcsan_report(const volatile void *ptr, size_t size, int access_type, bool value_change, int cpu_id, enum kcsan_report_type type); #endif /* _KERNEL_KCSAN_KCSAN_H */ diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c index 0eea05a3135b..9f503ca2ff7a 100644 --- a/kernel/kcsan/report.c +++ b/kernel/kcsan/report.c @@ -24,7 +24,7 @@ static struct { const volatile void *ptr; size_t size; - bool is_write; + int access_type; int task_pid; int cpu_id; unsigned long stack_entries[NUM_STACK_ENTRIES]; @@ -41,8 +41,10 @@ static DEFINE_SPINLOCK(report_lock); * Special rules to skip reporting. */ static bool -skip_report(bool is_write, bool value_change, unsigned long top_frame) +skip_report(int access_type, bool value_change, unsigned long top_frame) { + const bool is_write = (access_type & KCSAN_ACCESS_WRITE) != 0; + if (IS_ENABLED(CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY) && is_write && !value_change) { /* @@ -63,9 +65,20 @@ skip_report(bool is_write, bool value_change, unsigned long top_frame) return kcsan_skip_report_debugfs(top_frame); } -static inline const char *get_access_type(bool is_write) +static const char *get_access_type(int type) { - return is_write ? "write" : "read"; + switch (type) { + case 0: + return "read"; + case KCSAN_ACCESS_ATOMIC: + return "read (marked)"; + case KCSAN_ACCESS_WRITE: + return "write"; + case KCSAN_ACCESS_WRITE | KCSAN_ACCESS_ATOMIC: + return "write (marked)"; + default: + BUG(); + } } /* Return thread description: in task or interrupt. */ @@ -112,7 +125,7 @@ static int sym_strcmp(void *addr1, void *addr2) /* * Returns true if a report was generated, false otherwise. */ -static bool print_report(const volatile void *ptr, size_t size, bool is_write, +static bool print_report(const volatile void *ptr, size_t size, int access_type, bool value_change, int cpu_id, enum kcsan_report_type type) { @@ -124,7 +137,7 @@ static bool print_report(const volatile void *ptr, size_t size, bool is_write, /* * Must check report filter rules before starting to print. */ - if (skip_report(is_write, true, stack_entries[skipnr])) + if (skip_report(access_type, true, stack_entries[skipnr])) return false; if (type == KCSAN_REPORT_RACE_SIGNAL) { @@ -132,7 +145,7 @@ static bool print_report(const volatile void *ptr, size_t size, bool is_write, other_info.num_stack_entries); /* @value_change is only known for the other thread */ - if (skip_report(other_info.is_write, value_change, + if (skip_report(other_info.access_type, value_change, other_info.stack_entries[other_skipnr])) return false; } @@ -170,7 +183,7 @@ static bool print_report(const volatile void *ptr, size_t size, bool is_write, switch (type) { case KCSAN_REPORT_RACE_SIGNAL: pr_err("%s to 0x%px of %zu bytes by %s on cpu %i:\n", - get_access_type(other_info.is_write), other_info.ptr, + get_access_type(other_info.access_type), other_info.ptr, other_info.size, get_thread_desc(other_info.task_pid), other_info.cpu_id); @@ -181,14 +194,14 @@ static bool print_report(const volatile void *ptr, size_t size, bool is_write, pr_err("\n"); pr_err("%s to 0x%px of %zu bytes by %s on cpu %i:\n", - get_access_type(is_write), ptr, size, + get_access_type(access_type), ptr, size, get_thread_desc(in_task() ? task_pid_nr(current) : -1), cpu_id); break; case KCSAN_REPORT_RACE_UNKNOWN_ORIGIN: pr_err("race at unknown origin, with %s to 0x%px of %zu bytes by %s on cpu %i:\n", - get_access_type(is_write), ptr, size, + get_access_type(access_type), ptr, size, get_thread_desc(in_task() ? task_pid_nr(current) : -1), cpu_id); break; @@ -223,7 +236,7 @@ static void release_report(unsigned long *flags, enum kcsan_report_type type) * required for the report type, simply acquires report_lock and returns true. */ static bool prepare_report(unsigned long *flags, const volatile void *ptr, - size_t size, bool is_write, int cpu_id, + size_t size, int access_type, int cpu_id, enum kcsan_report_type type) { if (type != KCSAN_REPORT_CONSUMED_WATCHPOINT && @@ -243,7 +256,7 @@ static bool prepare_report(unsigned long *flags, const volatile void *ptr, other_info.ptr = ptr; other_info.size = size; - other_info.is_write = is_write; + other_info.access_type = access_type; other_info.task_pid = in_task() ? task_pid_nr(current) : -1; other_info.cpu_id = cpu_id; other_info.num_stack_entries = stack_trace_save(other_info.stack_entries, NUM_STACK_ENTRIES, 1); @@ -302,14 +315,14 @@ static bool prepare_report(unsigned long *flags, const volatile void *ptr, goto retry; } -void kcsan_report(const volatile void *ptr, size_t size, bool is_write, +void kcsan_report(const volatile void *ptr, size_t size, int access_type, bool value_change, int cpu_id, enum kcsan_report_type type) { unsigned long flags = 0; kcsan_disable_current(); - if (prepare_report(&flags, ptr, size, is_write, cpu_id, type)) { - if (print_report(ptr, size, is_write, value_change, cpu_id, type) && panic_on_warn) + if (prepare_report(&flags, ptr, size, access_type, cpu_id, type)) { + if (print_report(ptr, size, access_type, value_change, cpu_id, type) && panic_on_warn) panic("panic_on_warn set ...\n"); release_report(&flags, type); -- 2.25.0.rc1.283.g88dfdc4193-goog