From patchwork Wed Mar 23 15:32:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12789846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBB55C433F5 for ; Wed, 23 Mar 2022 15:33:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19F326B007B; Wed, 23 Mar 2022 11:33:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FD358D0002; Wed, 23 Mar 2022 11:33:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF7996B007E; Wed, 23 Mar 2022 11:33:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CDE036B007B for ; Wed, 23 Mar 2022 11:33:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8D2B5A3EEC for ; Wed, 23 Mar 2022 15:33:09 +0000 (UTC) X-FDA: 79276044498.27.D37A658 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf29.hostedemail.com (Postfix) with ESMTP id 9B0B312002F for ; Wed, 23 Mar 2022 15:33:03 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1648049581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=aF3Mslkri/nAJdWJHWopR/qwkkYDeoi5D+QsOOTejFE=; b=nNAzpZbKSwmLx4A2amh2xH45n/jkeaQtW9aDxERhBqdxXr0WWfhl/Px1TE/xZY0Xkbi6Cq K9yC5jBZIQ5+7PE8DIQinb4t2A03pyiAVjcmTRtiHfOzC2EaxLrC2XbgByndT7rP7lWvKR VFe3EK68JHwPi7qycD8mUFa0N2Tj/DE= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko , Catalin Marinas , Will Deacon , Andrew Morton Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Mark Rutland , Vincenzo Frascino , Sami Tolvanen , Peter Collingbourne , Evgenii Stepanov , Florian Mayer , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 0/4] kasan, arm64, scs, stacktrace: collect stack traces from Shadow Call Stack Date: Wed, 23 Mar 2022 16:32:51 +0100 Message-Id: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Stat-Signature: gqjbqutb91919zu7qr3r7xfcnex6orpf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9B0B312002F Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nNAzpZbK; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf29.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev X-Rspam-User: X-HE-Tag: 1648049583-629222 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: From: Andrey Konovalov kasan, arm64, scs, stacktrace: collect stack traces from Shadow Call Stack Currently, KASAN always uses the normal stack trace collection routines, which rely on the unwinder, when saving alloc and free stack traces. Instead of invoking the unwinder, collect the stack trace by copying frames from the Shadow Call Stack whenever it is enabled. This reduces boot time by 30% for all KASAN modes when Shadow Call Stack is enabled. Stack staces are collected from the Shadow Call Stack via a new stack_trace_save_shadow() interface. Note that the frame of the interrupted function is not included into the stack trace, as it is not yet saved on the SCS when an interrupt happens. --- To deal with this last thing, we could save the interrupted frame address in another per-CPU variable. I'll look into implementing this for v3. I decided to postpone the changes to stack depot that avoid copying frames twice until a planned upcoming update for stack depot. Changes v1->v2: - Provide a kernel-wide stack_trace_save_shadow() interface for collecting stack traces from shadow stack. - Use ptrauth_strip_insn_pac() and READ_ONCE_NOCHECK, see the comments. - Get SCS pointer from x18, as per-task value is meant to save the SCS value on CPU switches. - Collect stack frames from SDEI and IRQ contexts. Andrey Konovalov (4): stacktrace: add interface based on shadow call stack arm64, scs: save scs_sp values per-cpu when switching stacks arm64: implement stack_trace_save_shadow kasan: use stack_trace_save_shadow arch/Kconfig | 6 +++ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/assembler.h | 12 +++++ arch/arm64/include/asm/scs.h | 13 ++++- arch/arm64/kernel/entry.S | 28 ++++++++-- arch/arm64/kernel/irq.c | 4 +- arch/arm64/kernel/sdei.c | 5 +- arch/arm64/kernel/stacktrace.c | 83 ++++++++++++++++++++++++++++++ include/linux/stacktrace.h | 15 ++++++ kernel/stacktrace.c | 21 ++++++++ mm/kasan/common.c | 9 ++-- 11 files changed, 183 insertions(+), 14 deletions(-)