Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1054537pxb; Thu, 24 Mar 2022 11:54:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgn6m2aAwOztcvyTPFszQrpXlpnTsrUyrvfVYkXEFyY0GudFc1q15immx5IUMHbaNslg6X X-Received: by 2002:a17:90a:d50a:b0:1c6:aade:e4b3 with SMTP id t10-20020a17090ad50a00b001c6aadee4b3mr20364074pju.69.1648148054548; Thu, 24 Mar 2022 11:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648148054; cv=none; d=google.com; s=arc-20160816; b=L30CO23TUBm8xdMxaxa266deO5scxv+R3xSAyfrfvV+ZAwuvbm1FVtvNFzYHGnKG2T ioWiZULKVM4kQ+nfiZn24pkNpxqVJj9aTiG6800U3ZG6+n4ajxXLz6MisY7XecZBB8L9 4W33nBv/+R3hHyn0hsqUF5FhOh3x1S6YGWkwGhNNWvCDmPBBD7nb4oHp4ePOwoSNGLFn J8lOGWsszysQbdnzO0F42LV3h51h5xUEApYuLyWR1mCn9OkjxajEOUA9+IzPnJsVE5af 2qNkYOZq9vGD/X6zWVwUW+9POkasbdlEh7N8FbnERPHJ4k3DVkWB+H1MgBqP78j8rV5p v0PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=aF3Mslkri/nAJdWJHWopR/qwkkYDeoi5D+QsOOTejFE=; b=L/acuVSGe0akUdbghv/WvhTn0TFl3IaH+phnjeiOVpASwsCb9/AYro74JNmfKGP+3W O50/c7fX+wFw2ZVbY0cX5yCLJjnoCcMaXOALrhMZY/bMcj/lYKablbQTgYTet77gotAg qBiPCSJdu1glnQFtbFI7fxWN0/E8FCls1mGa4uNlJY/nNcEb/FYPa2R+1BgJH49vh5aT VDFTlcoYKMVP/boDntMDtHC+a6T8mrg/EW2L+cDJQ/96aBzVKqg39vsdfjHVOUMEMoa/ 20kiqOHgkRTVIPho5v3RctwLCcinuJB9nnixXNpCcEqrB5AwpWeWW2kY8LOxR28kJ++i KiLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nNAzpZbK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x9-20020a17090abc8900b001c70d2622bbsi416587pjr.109.2022.03.24.11.53.58; Thu, 24 Mar 2022 11:54:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nNAzpZbK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245239AbiCWPfF (ORCPT + 99 others); Wed, 23 Mar 2022 11:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245188AbiCWPeg (ORCPT ); Wed, 23 Mar 2022 11:34:36 -0400 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BBBA1C1 for ; Wed, 23 Mar 2022 08:33:03 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.25.1