From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E492C433F5 for ; Mon, 23 May 2022 11:34:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234971AbiEWLeE (ORCPT ); Mon, 23 May 2022 07:34:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234951AbiEWLd5 (ORCPT ); Mon, 23 May 2022 07:33:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6EBE24F9EE for ; Mon, 23 May 2022 04:33:55 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2DA6311FB; Mon, 23 May 2022 04:33:55 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.9.63]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C661C3F73D; Mon, 23 May 2022 04:33:52 -0700 (PDT) Date: Mon, 23 May 2022 12:33:48 +0100 From: Mark Rutland To: andrey.konovalov@linux.dev Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Catalin Marinas , Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: Re: [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c Message-ID: References: <697e015e22ea78b021c2546f390ad5d773f3af86.1653177005.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <697e015e22ea78b021c2546f390ad5d773f3af86.1653177005.git.andreyknvl@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, May 22, 2022 at 01:50:58AM +0200, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov > > Disable KASAN instrumentation of arch/arm64/kernel/stacktrace.c. > > This speeds up Generic KASAN by 5-20%. > > As a side-effect, KASAN is now unable to detect bugs in the stack trace > collection code. This is taken as an acceptable downside. > > Also replace READ_ONCE_NOCHECK() with READ_ONCE() in stacktrace.c. > As the file is now not instrumented, there is no need to use the > NOCHECK version of READ_ONCE(). > > Suggested-by: Mark Rutland > Signed-off-by: Andrey Konovalov > --- > arch/arm64/kernel/Makefile | 3 +++ > arch/arm64/kernel/stacktrace.c | 4 ++-- > 2 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile > index fa7981d0d917..da8cf6905c76 100644 > --- a/arch/arm64/kernel/Makefile > +++ b/arch/arm64/kernel/Makefile > @@ -14,6 +14,9 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE) > CFLAGS_REMOVE_syscall.o = -fstack-protector -fstack-protector-strong > CFLAGS_syscall.o += -fno-stack-protector > > +# Do not instrument to improve performance. > +KASAN_SANITIZE_stacktrace.o := n Can we make that a little more descriptive? e.g. # When KASAN is enabled, a stacktrace is recorded for every alloc/free, which # can significantly impact performance. Avoid instrumenting the stacktrace code # to minimize this impact. KASAN_SANITIZE_stacktrace.o := n With that: Acked-by: Mark Rutland Mark. > + > # It's not safe to invoke KCOV when portions of the kernel environment aren't > # available or are out-of-sync with HW state. Since `noinstr` doesn't always > # inhibit KCOV instrumentation, disable it for the entire compilation unit. > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index e4103e085681..33e96ae4b15f 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -110,8 +110,8 @@ static int notrace unwind_frame(struct task_struct *tsk, > * Record this frame record's values and location. The prev_fp and > * prev_type are only meaningful to the next unwind_frame() invocation. > */ > - frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp)); > - frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8)); > + frame->fp = READ_ONCE(*(unsigned long *)(fp)); > + frame->pc = READ_ONCE(*(unsigned long *)(fp + 8)); > frame->prev_fp = fp; > frame->prev_type = info.type; > > -- > 2.25.1 > From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC51EC433F5 for ; Mon, 23 May 2022 12:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2rHHw23OB2uIBhsMr2wRzCcSFvOvLIbxdGNo0Vxs8NI=; b=eHAQg0HjjiRKfh tYdzpByDZ2sj2UH3E+IQM90ifAMmaAi8wtkYMsRHC9biSXQLXFBUOZQGYFGAt4SYjOJkXvxOmXkVg ko8qbrepyNpeRmxMr8/LsAjHc/DzFpa9/VG3k3LJ2ylatqeR913HJnkOMDiTxm0Rak3DBJUXRLb4/ KitM5CEsgw4r4/Wu5ixgSkSP+mSISvWa74CCowasZVSZGNWFtCUugid44HFO2dQo14YIdak4bMPhE krvfZGzP7ayG6nvh14uCBkKdAynz1sSUTCMTNVwATSD5KyKiUU8oVHqLwFxtCSXQbp6Zb6dSuqYeD HTOwHiATKrGV/lvgGeGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nt6r1-003zOY-Du; Mon, 23 May 2022 12:08:08 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nt6Jw-003k6s-Vf for linux-arm-kernel@lists.infradead.org; Mon, 23 May 2022 11:33:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2DA6311FB; Mon, 23 May 2022 04:33:55 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.9.63]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C661C3F73D; Mon, 23 May 2022 04:33:52 -0700 (PDT) Date: Mon, 23 May 2022 12:33:48 +0100 From: Mark Rutland To: andrey.konovalov@linux.dev Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Catalin Marinas , Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: Re: [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c Message-ID: References: <697e015e22ea78b021c2546f390ad5d773f3af86.1653177005.git.andreyknvl@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <697e015e22ea78b021c2546f390ad5d773f3af86.1653177005.git.andreyknvl@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220523_043357_141240_CAA838A8 X-CRM114-Status: GOOD ( 21.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sun, May 22, 2022 at 01:50:58AM +0200, andrey.konovalov@linux.dev wrote: > From: Andrey Konovalov > > Disable KASAN instrumentation of arch/arm64/kernel/stacktrace.c. > > This speeds up Generic KASAN by 5-20%. > > As a side-effect, KASAN is now unable to detect bugs in the stack trace > collection code. This is taken as an acceptable downside. > > Also replace READ_ONCE_NOCHECK() with READ_ONCE() in stacktrace.c. > As the file is now not instrumented, there is no need to use the > NOCHECK version of READ_ONCE(). > > Suggested-by: Mark Rutland > Signed-off-by: Andrey Konovalov > --- > arch/arm64/kernel/Makefile | 3 +++ > arch/arm64/kernel/stacktrace.c | 4 ++-- > 2 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile > index fa7981d0d917..da8cf6905c76 100644 > --- a/arch/arm64/kernel/Makefile > +++ b/arch/arm64/kernel/Makefile > @@ -14,6 +14,9 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE) > CFLAGS_REMOVE_syscall.o = -fstack-protector -fstack-protector-strong > CFLAGS_syscall.o += -fno-stack-protector > > +# Do not instrument to improve performance. > +KASAN_SANITIZE_stacktrace.o := n Can we make that a little more descriptive? e.g. # When KASAN is enabled, a stacktrace is recorded for every alloc/free, which # can significantly impact performance. Avoid instrumenting the stacktrace code # to minimize this impact. KASAN_SANITIZE_stacktrace.o := n With that: Acked-by: Mark Rutland Mark. > + > # It's not safe to invoke KCOV when portions of the kernel environment aren't > # available or are out-of-sync with HW state. Since `noinstr` doesn't always > # inhibit KCOV instrumentation, disable it for the entire compilation unit. > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index e4103e085681..33e96ae4b15f 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -110,8 +110,8 @@ static int notrace unwind_frame(struct task_struct *tsk, > * Record this frame record's values and location. The prev_fp and > * prev_type are only meaningful to the next unwind_frame() invocation. > */ > - frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp)); > - frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8)); > + frame->fp = READ_ONCE(*(unsigned long *)(fp)); > + frame->pc = READ_ONCE(*(unsigned long *)(fp + 8)); > frame->prev_fp = fp; > frame->prev_type = info.type; > > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel