Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp22861pxb; Wed, 14 Apr 2021 08:33:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHlb7VbjuHPXNJ2BzCmqMwiKQa85Qpguf0LhOlxWQMAbWTFcNi1jllVB066OdNadJohmUK X-Received: by 2002:aa7:d5da:: with SMTP id d26mr5908579eds.379.1618414418582; Wed, 14 Apr 2021 08:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618414418; cv=none; d=google.com; s=arc-20160816; b=BpK0AP/IwrhOEMuM+6fZnQdqGAs2sFqLcFQXe3knt1JqumKIl0jj0GgvHDfzowBugg UUOnM6y4h/P+4JBUw94OVHVQ+zJmv/GD3wrMmZGfu8IwCSZAUSfRLbY0wcUGURrUqu5Z yINfxFs2spbuRc7pwzZrC757e0rk3glb02+5GfOp6CO186P2xve9JgJ3s1Uc3krteBuI s42B4PZy6pwfp/IeXxA956B5nbyxtE27C4spCoWCmRfWQnnzTHaFczfYqLamfqXRBJzH ocfPPJVEelB5M61bZ8iBVvcIq5KZ0jp3gcIkeCygPtaJ+avKAAsWo6MIF0RTTkoHo8/j 75eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=mMtpkoi7Dg1KI2BVOCvCvQkqmnY+V0ww8kwlTHqSHyQ=; b=kP+VYcDQ1+kRY1vRvF21d5+N3u+tvBq6xD06N5vSwkkZjvyCXongn+/s5hSCGFJIwd olw3jBsiaC3OrxgB/GPWbwP9rWCHDOD2BpOa4ttASMYOwKuF5xXgAKJGTvtN6+ynUfSP o3LfMkGnMBgYD3PiSMENhnFfDehyFAYjvtlpwxrgdJzb0aiuXS454FAPyVIj7M3AFz85 nUSWE/3m5azs8OfzkWMGn7ZJlWkg0/mdABSmdSxCDxH3d/xVnbOzLyJWMxaDzm1GNWCW 3J4HxNjI2Uo5KHrJe+a7bk5gtiFMWEzUvBYZNZtTditU4PQNSBGojLlSP2oNJWQZ5FGb fZyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZaPyMeCk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h16si13079005ejt.695.2021.04.14.08.33.15; Wed, 14 Apr 2021 08:33:38 -0700 (PDT) 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=@google.com header.s=20161025 header.b=ZaPyMeCk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350537AbhDNL3q (ORCPT + 99 others); Wed, 14 Apr 2021 07:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350543AbhDNL3L (ORCPT ); Wed, 14 Apr 2021 07:29:11 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F6F3C061756 for ; Wed, 14 Apr 2021 04:28:48 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id p5so823912qvr.4 for ; Wed, 14 Apr 2021 04:28:48 -0700 (PDT) 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=mMtpkoi7Dg1KI2BVOCvCvQkqmnY+V0ww8kwlTHqSHyQ=; b=ZaPyMeCkuGUrEuXfuFpHu0vuIW42WqZyOyAqTAZad0QEZt52MwoQNefncM5i6DdEhY wofZZj79o7BVkE06wj1dn80ne2ciLKmKAOrEBBIl2y56QTF+SWk5M+jEbegVVn6AiGix 4ccfQVtHnxgJSyWsapinxg6VBgRE+fXzCudwxGaQGOCx/ENcKRuxEzdYRK9DSDTJ1bnN CCCqZKC4iDAPORo+lS/3pvFByAlSMmwaTHnEkjVmeOVB3vrKOTp/HX/H3q1XjJ2k2c4D mSdzK4bZ1LBFlBlpeDx5mkg9QpB/hyqRevdMnCbAVviJgdSQb8y5gOGpHui3GR+6Qxae wZOg== 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=mMtpkoi7Dg1KI2BVOCvCvQkqmnY+V0ww8kwlTHqSHyQ=; b=kf0FiQ4GZuPbxA0ZTwnNS8umWyuVKtvwla7bPoYkJwFuFM8jmr2aw6lfPWIfHTdSe2 UDusXFnu+raKpqz1V1TNPflgIRY1lgyjhHYa3ZguUwYEe1PvKcGrd6WeuIGxMt9DCuVn RoTlntNgxkKLT6MoOEA2AXB/rzE77qPtBUaqYEZupALVoGHbVY1TErJyjn7gp/Pfnbid loU0ZeQVvnUT33+hFlNBwW2KxAAUxSPV7sCtFJB/WxvSeZStQiU5dqmoixdteZQSAqv5 Vy9fCQr+wkbmvz1oXJclHrxGo3yIFe7OmAfGFA8JYEQ+dpoDad4PHHXE/QW5J/jQihGT BpTg== X-Gm-Message-State: AOAM531k5Ysp7mlqW/LZv0LZfQmtNu4E9eAf8TsXwiKIPnTVd8uooklz lgQFe7hL1/3CbJIunUCwi0PQ263P6w== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:4051:8ddb:9de4:c1bb]) (user=elver job=sendgmr) by 2002:a05:6214:248f:: with SMTP id gi15mr37426775qvb.40.1618399727735; Wed, 14 Apr 2021 04:28:47 -0700 (PDT) Date: Wed, 14 Apr 2021 13:28:18 +0200 In-Reply-To: <20210414112825.3008667-1-elver@google.com> Message-Id: <20210414112825.3008667-3-elver@google.com> Mime-Version: 1.0 References: <20210414112825.3008667-1-elver@google.com> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog Subject: [PATCH 2/9] kcsan: Distinguish kcsan_report() calls From: Marco Elver To: elver@google.com, paulmck@kernel.org Cc: mark.rutland@arm.com, will@kernel.org, dvyukov@google.com, glider@google.com, boqun.feng@gmail.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland Currently kcsan_report() is used to handle three distinct cases: * The caller hit a watchpoint when attempting an access. Some information regarding the caller and access are recorded, but no output is produced. * A caller which previously setup a watchpoint detected that the watchpoint has been hit, and possibly detected a change to the location in memory being watched. This may result in output reporting the interaction between this caller and the caller which hit the watchpoint. * A caller detected a change to a modification to a memory location which wasn't detected by a watchpoint, for which there is no information on the other thread. This may result in output reporting the unexpected change. ... depending on the specific case the caller has distinct pieces of information available, but the prototype of kcsan_report() has to handle all three cases. This means that in some cases we pass redundant information, and in others we don't pass all the information we could pass. This also means that the report code has to demux these three cases. So that we can pass some additional information while also simplifying the callers and report code, add separate kcsan_report_*() functions for the distinct cases, updating callers accordingly. As the watchpoint_idx is unused in the case of kcsan_report_unknown_origin(), this passes a dummy value into kcsan_report(). Subsequent patches will refactor the report code to avoid this. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland [ elver@google.com: try to make kcsan_report_*() names more descriptive ] Signed-off-by: Marco Elver --- kernel/kcsan/core.c | 12 ++++-------- kernel/kcsan/kcsan.h | 10 ++++++---- kernel/kcsan/report.c | 26 +++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c index d360183002d6..6fe1513e1e6a 100644 --- a/kernel/kcsan/core.c +++ b/kernel/kcsan/core.c @@ -380,9 +380,7 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr, if (consumed) { kcsan_save_irqtrace(current); - kcsan_report(ptr, size, type, KCSAN_VALUE_CHANGE_MAYBE, - KCSAN_REPORT_CONSUMED_WATCHPOINT, - watchpoint - watchpoints); + kcsan_report_set_info(ptr, size, type, watchpoint - watchpoints); kcsan_restore_irqtrace(current); } else { /* @@ -558,8 +556,8 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) if (is_assert && value_change == KCSAN_VALUE_CHANGE_TRUE) atomic_long_inc(&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES]); - kcsan_report(ptr, size, type, value_change, KCSAN_REPORT_RACE_SIGNAL, - watchpoint - watchpoints); + kcsan_report_known_origin(ptr, size, type, value_change, + watchpoint - watchpoints); } else if (value_change == KCSAN_VALUE_CHANGE_TRUE) { /* Inferring a race, since the value should not have changed. */ @@ -568,9 +566,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) atomic_long_inc(&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES]); if (IS_ENABLED(CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN) || is_assert) - kcsan_report(ptr, size, type, KCSAN_VALUE_CHANGE_TRUE, - KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, - watchpoint - watchpoints); + kcsan_report_unknown_origin(ptr, size, type); } /* diff --git a/kernel/kcsan/kcsan.h b/kernel/kcsan/kcsan.h index 9881099d4179..2ee43fd5d6a4 100644 --- a/kernel/kcsan/kcsan.h +++ b/kernel/kcsan/kcsan.h @@ -136,10 +136,12 @@ enum kcsan_report_type { }; /* - * Print a race report from thread that encountered the race. + * Notify the report code that a race occurred. */ -extern void kcsan_report(const volatile void *ptr, size_t size, int access_type, - enum kcsan_value_change value_change, - enum kcsan_report_type type, int watchpoint_idx); +void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type, + int watchpoint_idx); +void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type, + enum kcsan_value_change value_change, int watchpoint_idx); +void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type); #endif /* _KERNEL_KCSAN_KCSAN_H */ diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c index 13dce3c664d6..5232bf218ea7 100644 --- a/kernel/kcsan/report.c +++ b/kernel/kcsan/report.c @@ -598,9 +598,9 @@ static noinline bool prepare_report(unsigned long *flags, } } -void kcsan_report(const volatile void *ptr, size_t size, int access_type, - enum kcsan_value_change value_change, - enum kcsan_report_type type, int watchpoint_idx) +static void kcsan_report(const volatile void *ptr, size_t size, int access_type, + enum kcsan_value_change value_change, + enum kcsan_report_type type, int watchpoint_idx) { unsigned long flags = 0; const struct access_info ai = { @@ -645,3 +645,23 @@ void kcsan_report(const volatile void *ptr, size_t size, int access_type, out: kcsan_enable_current(); } + +void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type, + int watchpoint_idx) +{ + kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_MAYBE, + KCSAN_REPORT_CONSUMED_WATCHPOINT, watchpoint_idx); +} + +void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type, + enum kcsan_value_change value_change, int watchpoint_idx) +{ + kcsan_report(ptr, size, access_type, value_change, + KCSAN_REPORT_RACE_SIGNAL, watchpoint_idx); +} + +void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type) +{ + kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_TRUE, + KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, 0); +} -- 2.31.1.295.g9ea45b61b8-goog