From patchwork Thu Jan 21 13:19:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12036137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9B6BC433E6 for ; Thu, 21 Jan 2021 13:19:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5531023A04 for ; Thu, 21 Jan 2021 13:19:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5531023A04 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CDBD36B000E; Thu, 21 Jan 2021 08:19:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB3186B0010; Thu, 21 Jan 2021 08:19:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA04E6B0012; Thu, 21 Jan 2021 08:19:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id A3A9C6B000E for ; Thu, 21 Jan 2021 08:19:23 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 708E01F0A for ; Thu, 21 Jan 2021 13:19:23 +0000 (UTC) X-FDA: 77729838606.19.cover69_1c166dc27563 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 2A4DA1AD1B4 for ; Thu, 21 Jan 2021 13:19:23 +0000 (UTC) X-HE-Tag: cover69_1c166dc27563 X-Filterd-Recvd-Size: 8033 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 13:19:22 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id i82so1537342qke.19 for ; Thu, 21 Jan 2021 05:19:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=i4YH3yLeIclRhhtAEf9273ZCA7Cxi6HCBtpgwrGQcZU=; b=sibTmKiLS9ajF4FE1rUs6hEKWQLhtFXelqmUugPjx/BwXAb19nRZuH5azNdMExPV8j 2bVfJ8ahp97a3Sf+oNrY6vrPivAv2ANLtKGPx8GEGoeCsqx/aDG9DNOfM7WsfczQzxdv 45VVZa9Li/fI2aLoMb2vPlCIiEw7CsMDRMlYACkZSVVZT292TOlGys0PdNDyL8/NkIkG YNYES0RZmp0BS71aOT0S23OLsNFfq23VTQL5eaAf1P/cGfztvVQSun1wDrbUMZDLuRHC elMCG1c1vNU/0rstvHTiWcFBYb1fYJiPs0r1lXdOP0odQ0H0IhvcixBrHEf7ThaCvMUw QMcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=i4YH3yLeIclRhhtAEf9273ZCA7Cxi6HCBtpgwrGQcZU=; b=FCkdAL0cUg0rZZQJ3p291ggNapcaKWEkxKiEEGm5HE42ENLzhtWFcv1KMw3g1zjXua KHBa0HBCjq94qsDpHBoW6hDNyRJfLR+jQSJ/0gu68Kcf3BnqTdwoa7EkX2U+1E2QPJCH 5jHq8t2a5THkaE7d8auVM/3eiQhHkRGh6bxsP6LzSbEbFPCuw47caTtPMwoBLaZTjvaN yl2arddZZrNCse2gvLB0cwIH3TWh7ppm7+NEM+CfCututQ5QspxtDVksuXlnsdJ5C5s+ dIP1Lzftu0pGbnwqLQPYSquAWFW43WOhFUmaDF0wXu/0dp6rBc5Rx8FIYkY43WuXbz4N RN3Q== X-Gm-Message-State: AOAM533hDXeINK1U/a1PLFqelmbYX4PIcHnLbflfCbxFw2x1FnQ+i52x qtW09thg66UnRT+2WeuDJI9b07UELUQ= X-Google-Smtp-Source: ABdhPJx7bFVBrO2SM5sg340Yp6559cJ8hXAbFop3C0sgAI2F2N9pzXbIGGX0yzZRy/LBdKjyMwx+2xX017k= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:9ff]) (user=glider job=sendgmr) by 2002:a0c:8601:: with SMTP id p1mr14110664qva.22.1611235161865; Thu, 21 Jan 2021 05:19:21 -0800 (PST) Date: Thu, 21 Jan 2021 14:19:13 +0100 In-Reply-To: <20210121131915.1331302-1-glider@google.com> Message-Id: <20210121131915.1331302-2-glider@google.com> Mime-Version: 1.0 References: <20210121131915.1331302-1-glider@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH v3 1/3] tracing: add error_report_end trace point From: Alexander Potapenko To: akpm@linux-foundation.org, glider@google.com Cc: elver@google.com, andreyknvl@google.com, dvyukov@google.com, mingo@redhat.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux-mm@kvack.org, linux-api@vger.kernel.org, vbabka@suse.cz, gregkh@linuxfoundation.org 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: Introduce error_report_end tracepoint. It can be used in debugging tools like KASAN, KFENCE, etc. to provide extensions to the error reporting mechanisms (e.g. allow tests hook into error reporting, ease error report collection from production kernels). Another benefit would be making use of ftrace for debugging or benchmarking the tools themselves. Should we need it, the tracepoint name leaves us with the possibility to introduce a complementary error_report_start tracepoint in the future. Suggested-by: Marco Elver Cc: Andrew Morton Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: Marco Elver Cc: Petr Mladek Cc: Steven Rostedt Cc: Sergey Senozhatsky Cc: linux-mm@kvack.org Cc: linux-api@vger.kernel.org Signed-off-by: Alexander Potapenko --- v3: - delete error_report_start that is unlikely to be unused in the nearest future - add missing copyright headers v2: - change error_report_start and error_report_end prototypes to accept enum error_detector instead of char* (as suggested by Steven Rostedt) --- include/trace/events/error_report.h | 74 +++++++++++++++++++++++++++++ kernel/trace/Makefile | 1 + kernel/trace/error_report-traces.c | 12 +++++ 3 files changed, 87 insertions(+) create mode 100644 include/trace/events/error_report.h create mode 100644 kernel/trace/error_report-traces.c diff --git a/include/trace/events/error_report.h b/include/trace/events/error_report.h new file mode 100644 index 000000000000..96f64bf218b2 --- /dev/null +++ b/include/trace/events/error_report.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Declarations for error reporting tracepoints. + * + * Copyright (C) 2021, Google LLC. + */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM error_report + +#if !defined(_TRACE_ERROR_REPORT_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_ERROR_REPORT_H + +#include + +#ifndef __ERROR_REPORT_DECLARE_TRACE_ENUMS_ONCE_ONLY +#define __ERROR_REPORT_DECLARE_TRACE_ENUMS_ONCE_ONLY + +enum error_detector { + ERROR_DETECTOR_KFENCE, + ERROR_DETECTOR_KASAN +}; + +#endif /* __ERROR_REPORT_DECLARE_TRACE_ENUMS_ONCE_ONLY */ + +#define error_detector_list \ + EM(ERROR_DETECTOR_KFENCE, "kfence") \ + EMe(ERROR_DETECTOR_KASAN, "kasan") +/* Always end the list with an EMe. */ + +#undef EM +#undef EMe + +#define EM(a, b) TRACE_DEFINE_ENUM(a); +#define EMe(a, b) TRACE_DEFINE_ENUM(a); + +error_detector_list + +#undef EM +#undef EMe + +#define EM(a, b) { a, b }, +#define EMe(a, b) { a, b } + +#define show_error_detector_list(val) \ + __print_symbolic(val, error_detector_list) + +DECLARE_EVENT_CLASS(error_report_template, + TP_PROTO(enum error_detector error_detector, unsigned long id), + TP_ARGS(error_detector, id), + TP_STRUCT__entry(__field(enum error_detector, error_detector) + __field(unsigned long, id)), + TP_fast_assign(__entry->error_detector = error_detector; + __entry->id = id;), + TP_printk("[%s] %lx", + show_error_detector_list(__entry->error_detector), + __entry->id)); + +/** + * error_report_end - called after printing the error report + * @error_detector: short string describing the error detection tool + * @id: pseudo-unique descriptor identifying the report + * (e.g. the memory access address) + * + * This event occurs right after a debugging tool finishes printing the error + * report. + */ +DEFINE_EVENT(error_report_template, error_report_end, + TP_PROTO(enum error_detector error_detector, unsigned long id), + TP_ARGS(error_detector, id)); + +#endif /* _TRACE_ERROR_REPORT_H */ + +/* This part must be outside protection */ +#include diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 7e44cea89fdc..b28d3e5013cd 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile @@ -81,6 +81,7 @@ obj-$(CONFIG_SYNTH_EVENTS) += trace_events_synth.o obj-$(CONFIG_HIST_TRIGGERS) += trace_events_hist.o obj-$(CONFIG_BPF_EVENTS) += bpf_trace.o obj-$(CONFIG_KPROBE_EVENTS) += trace_kprobe.o +obj-$(CONFIG_TRACEPOINTS) += error_report-traces.o obj-$(CONFIG_TRACEPOINTS) += power-traces.o ifeq ($(CONFIG_PM),y) obj-$(CONFIG_TRACEPOINTS) += rpm-traces.o diff --git a/kernel/trace/error_report-traces.c b/kernel/trace/error_report-traces.c new file mode 100644 index 000000000000..632c8c7ff079 --- /dev/null +++ b/kernel/trace/error_report-traces.c @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Error reporting trace points. + * + * Copyright (C) 2021, Google LLC. + */ + +#define CREATE_TRACE_POINTS +#include + +EXPORT_TRACEPOINT_SYMBOL_GPL(error_report_end); + From patchwork Thu Jan 21 13:19:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12036139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3B8BC433DB for ; Thu, 21 Jan 2021 13:19:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9428023A01 for ; Thu, 21 Jan 2021 13:19:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9428023A01 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 190BE6B0012; Thu, 21 Jan 2021 08:19:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16D816B0022; Thu, 21 Jan 2021 08:19:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0307C6B0023; Thu, 21 Jan 2021 08:19:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id E2E166B0012 for ; Thu, 21 Jan 2021 08:19:25 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A94371DF8 for ; Thu, 21 Jan 2021 13:19:25 +0000 (UTC) X-FDA: 77729838690.22.rail34_2e1292127563 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 787A51803AA65 for ; Thu, 21 Jan 2021 13:19:25 +0000 (UTC) X-HE-Tag: rail34_2e1292127563 X-Filterd-Recvd-Size: 4552 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 13:19:24 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id p80so2180389ybg.10 for ; Thu, 21 Jan 2021 05:19:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=EZM8uwys0tIYTV5rV7IMpiN4Wky1Ucyd+XglcRPDA0k=; b=WFun/2AwoihyT9AoddjjkcKTUjc9aI3jv7IFGHwz+lYgIMz5b4WPNxXTiyzbrd+LJk WO3FxCB1Z/havwsDuvKosLXatsLCtqTnsMN3N5jAgG74u80nWFXEmQ+mBgYjdUB//JjX Q6kAQ+pAl8XYDz2Ei2+nblI2fGGTv+uKtJHtRqlXQfEDBJAQS+jkFBswpyKA8etRcnUH OOs71Y+Fd5/i9qecUzQiepvITmFqkejQn7UN/r27rnGMC+BNYBM5HmdI/y7s1YXWGRBt lfvhUY4CVirmJMHsy+tYXnPwttmMKEyvF9fWE1SPqi/BxiZHoPg/x/SPCfVGkwMJnOka xM9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EZM8uwys0tIYTV5rV7IMpiN4Wky1Ucyd+XglcRPDA0k=; b=hwp9EKA60IORGM3H+i72YPpMOdRQbhVsFWlr69wBo6cMsGTtmc2stdO9tK6C21l3zM tN2kRKiD20TtCrY6SpbnVOtTob4MqZ7VpMYkV3fM/x/o8HwRiNGcc58v6FcNctXdw6bX WWMtifIP6c67AsysZEz4bwSFTyNJKom1Gm4SrorGCqavU9VbjvCY9YFVO5HvM52Uhlqb vano3q9BgiP5JBHqO42DJqj7mQQpVlxAl/ilFR6I0rVwerj9Iv4lBZQ39tFBRrmADHj9 74wEdONKHSYV4EzjW4bmgAE/RBvtddULT+C8o5OOMA8bf0DgJ82+1GnLeOXOkEGiPh2G CErg== X-Gm-Message-State: AOAM530i6ZewsGE+64FdUJE683mRq9Ob+YKi/b4CHi8MF7z0LWakcSlb zxaKBXHpbp/4wurRwZCSsNLH3ej6qz8= X-Google-Smtp-Source: ABdhPJwtDkTgRZRk3yc/3yCU/TR+GnrcNDSCBz+LT6IxxpACRB4tZzjHkAxKgNiuzuLPqOyxu2xUmBX1mnc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:9ff]) (user=glider job=sendgmr) by 2002:a25:3bc5:: with SMTP id i188mr20415374yba.332.1611235164118; Thu, 21 Jan 2021 05:19:24 -0800 (PST) Date: Thu, 21 Jan 2021 14:19:14 +0100 In-Reply-To: <20210121131915.1331302-1-glider@google.com> Message-Id: <20210121131915.1331302-3-glider@google.com> Mime-Version: 1.0 References: <20210121131915.1331302-1-glider@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH 2/3] kfence: use error_report_end tracepoint From: Alexander Potapenko To: akpm@linux-foundation.org, glider@google.com Cc: elver@google.com, andreyknvl@google.com, dvyukov@google.com, mingo@redhat.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux-mm@kvack.org, linux-api@vger.kernel.org, vbabka@suse.cz, gregkh@linuxfoundation.org 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: Make it possible to trace KFENCE error reporting. A good usecase is watching for trace events from the userspace to detect and process memory corruption reports from the kernel. Suggested-by: Marco Elver Cc: Andrew Morton Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: Marco Elver Cc: Petr Mladek Cc: Steven Rostedt Cc: Sergey Senozhatsky Cc: linux-mm@kvack.org Signed-off-by: Alexander Potapenko --- v3: - dropped error_report_start v2: - change error_report_start and error_report_end prototypes to accept enum error_detector instead of char* (as suggested by Steven Rostedt) --- mm/kfence/report.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/kfence/report.c b/mm/kfence/report.c index 901bd7ee83d8..f9fc93b2fe2e 100644 --- a/mm/kfence/report.c +++ b/mm/kfence/report.c @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -246,6 +247,7 @@ void kfence_report_error(unsigned long address, bool is_write, struct pt_regs *r show_regs(regs); else dump_stack_print_info(KERN_ERR); + trace_error_report_end(ERROR_DETECTOR_KFENCE, address); pr_err("==================================================================\n"); lockdep_on(); From patchwork Thu Jan 21 13:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12036141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5342AC433DB for ; Thu, 21 Jan 2021 13:19:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DF02E23A01 for ; Thu, 21 Jan 2021 13:19:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DF02E23A01 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 670AC6B0023; Thu, 21 Jan 2021 08:19:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 625A46B0024; Thu, 21 Jan 2021 08:19:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EB746B0025; Thu, 21 Jan 2021 08:19:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0174.hostedemail.com [216.40.44.174]) by kanga.kvack.org (Postfix) with ESMTP id 368DE6B0023 for ; Thu, 21 Jan 2021 08:19:29 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E88378249980 for ; Thu, 21 Jan 2021 13:19:28 +0000 (UTC) X-FDA: 77729838816.26.shake05_4e06e7b27563 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id C7A721804B667 for ; Thu, 21 Jan 2021 13:19:28 +0000 (UTC) X-HE-Tag: shake05_4e06e7b27563 X-Filterd-Recvd-Size: 5331 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 13:19:28 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id e12so986991wrx.14 for ; Thu, 21 Jan 2021 05:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=3UapMw1B/lQ8O8rK1t5yloPW20aKmQdYgqwziIYXJaY=; b=UKSOk4WzR2mtDoCBipGA36JhtfgylD1LozvLVpUwCjthtsOSGbdlWMc2q8E2pmyHdh 3ImBadYTaBj0ZhQ+OwufJlquLcifn27sJvDhP0iaz3UGUhMdgJ+ZkmZkw/tS7/zcjsdU Tgi7ErDfePAS28w8dFBLeqBfhd7QxzXchYbQqGyVwlSPXpoZfZEbQGSWasZmh6lV8Tto J68r/4NDvEugjF8vneCaHszTUtwU1yUHjFp64o+lFACtZ1m94s7NluiylwXXRR9NZYGX VlEqcWHT2m77F7gPpMAfNi1xcWxFQilRXACXBtGrekrUVW3fkZmmd86URU/K8Zy5mWUu y+WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3UapMw1B/lQ8O8rK1t5yloPW20aKmQdYgqwziIYXJaY=; b=k4Iu39gi79mtx9ZNsL8853GIpH6GLC/GdCVvtQBIe0L5V865CWHrZ2X7rOpvcH3fwm JcwlKYywICAi+641DlwH8MNRtyjJr52JaHkkkFrMBDd8nTlqMGgx/dv8w78j/zgCDGy6 9rwDJ9QEft8N9RZd/T879omMWyD3lf9emKKfbpswwYMXgiReW5/Am9guCWzgEWIkTC0f 4A9py4krvRamvMrB+VkvPOl9tqUTY7jcwTAupIHX0kERCyAowOjocPhOiIuYVAFwqr0H ZAHuIE+znBEr73Nmk8Nyxoqlair+JdzCMQBDkRlxn2q3Q/XDYi4DEf6LXiQ6NYjRHBfK 7wdw== X-Gm-Message-State: AOAM533Gk8xMRPnTSsSYGn6vwthv2+1CEQLHf5AATLJq/PicMqq+1r8H AWlpJ+ldexNGtXHacOjmzokUG0F8GmI= X-Google-Smtp-Source: ABdhPJw5JH6viWlCpNTEeENNaqAUbl0z56mqHOR+JS2XF/jIGeIsHBiubDSgHt35cRONxjNqkHPgiHd/phA= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:f693:9fff:fef4:9ff]) (user=glider job=sendgmr) by 2002:a5d:6c6b:: with SMTP id r11mr3209323wrz.38.1611235166783; Thu, 21 Jan 2021 05:19:26 -0800 (PST) Date: Thu, 21 Jan 2021 14:19:15 +0100 In-Reply-To: <20210121131915.1331302-1-glider@google.com> Message-Id: <20210121131915.1331302-4-glider@google.com> Mime-Version: 1.0 References: <20210121131915.1331302-1-glider@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH 3/3] kasan: use error_report_end tracepoint From: Alexander Potapenko To: akpm@linux-foundation.org, glider@google.com Cc: elver@google.com, andreyknvl@google.com, dvyukov@google.com, mingo@redhat.com, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, linux-mm@kvack.org, linux-api@vger.kernel.org, vbabka@suse.cz, gregkh@linuxfoundation.org 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: Make it possible to trace KASAN error reporting. A good usecase is watching for trace events from the userspace to detect and process memory corruption reports from the kernel. Suggested-by: Marco Elver Cc: Andrew Morton Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Ingo Molnar Cc: Marco Elver Cc: Petr Mladek Cc: Steven Rostedt Cc: Sergey Senozhatsky Cc: linux-mm@kvack.org Signed-off-by: Alexander Potapenko --- v3: - dropped error_report_start v2: - change error_report_start and error_report_end prototypes to accept enum error_detector instead of char* (as suggested by Steven Rostedt) --- mm/kasan/report.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 234f35a84f19..87b271206163 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -84,8 +85,9 @@ static void start_report(unsigned long *flags) pr_err("==================================================================\n"); } -static void end_report(unsigned long *flags) +static void end_report(unsigned long *flags, unsigned long addr) { + trace_error_report_end(ERROR_DETECTOR_KASAN, addr); pr_err("==================================================================\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irqrestore(&report_lock, *flags); @@ -355,7 +357,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) print_address_description(object, tag); pr_err("\n"); print_memory_metadata(object); - end_report(&flags); + end_report(&flags, (unsigned long)object); } static void __kasan_report(unsigned long addr, size_t size, bool is_write, @@ -401,7 +403,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, dump_stack(); } - end_report(&flags); + end_report(&flags, addr); } bool kasan_report(unsigned long addr, size_t size, bool is_write,