Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1995854ioo; Mon, 23 May 2022 07:52:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9L/inVWq8zVLbBOtx37JerYWRCb1naSEUr1alwPQ0r9pDCwsoET1v4xQmtdtUqoAZZGIz X-Received: by 2002:a17:90a:4209:b0:1df:b907:ed3d with SMTP id o9-20020a17090a420900b001dfb907ed3dmr26827655pjg.40.1653317538088; Mon, 23 May 2022 07:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653317538; cv=none; d=google.com; s=arc-20160816; b=JpyBfAxgAIzsbvQuh8N+BLVTXq2MMhVjD9k1BZvpcuICmEyNysCqANXhY+STxgm/Bn r1WL28zx9GTunNeo3gagXL3rmsiM1MB4GlBs2vFX2BFxped+4ArUaE5a6NTKdhRDxnMs 3ZOe81w3viXkcKPETKt/VyzWeXj1xwZLqNdv30FGiA5LwrX5Tv3f8aQ6YypdeQeizUe8 CcAUXiv5UkXot/R6D+eO7+q408275BgpbMjP4UDVgBQyI9RwoTHzY7NXP/HOWkU8KQDf soMlJyeBUceWdYbwTfQq5d5Etel25owVuxCgfKvRzByxBDowMiR58L74MRnf5AapqD2W uvXA== 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=HrBttuHNouCVJd8EaofzeEzAduf8tjD2M1BbP/WSMfw=; b=bjPfGktsW4NtoMW/4XKNEYizH5W79EMYi1j3G6LLJaX/imLppOm31KrRugVLCbePaB XfQiMzXiQYEkwIerKF6KYQp2F7fJknEkQl16CLxn7H39KKHpBIzmrPr84pLx/Puo9Yqr VqeRITb6cK8CCOJLo9wveEsxlbo0s87lnNJnSXAR/BZEUujNR2heLjcMnX5MUYojw/u7 rBxvVvD7Xb1jcMc3iHvgc0uyvdKuZxCBOQ7idO3zE4RvpnEFU/CTwGbEK/qytkPocmzE /j20O2dwZqAeuI7DtrBn4YaOc2rRgxzTOwcEKk+tT+hGhlAJH9VzgSBnkPU/j89CmcvS VblA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=RIxsqyTM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id w2-20020a170902a70200b00161573da69bsi9981468plq.223.2022.05.23.07.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 07:52:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=RIxsqyTM; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 729685AED5; Mon, 23 May 2022 07:52:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237336AbiEWOwC (ORCPT + 99 others); Mon, 23 May 2022 10:52:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237321AbiEWOv7 (ORCPT ); Mon, 23 May 2022 10:51:59 -0400 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA33275C5 for ; Mon, 23 May 2022 07:51:57 -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=1653317515; 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=HrBttuHNouCVJd8EaofzeEzAduf8tjD2M1BbP/WSMfw=; b=RIxsqyTM4Y+A03KO+NZc0lK/f6q3XGacTaQfyQJrgykPnV+6op4aGF5NG2yw0wwghNJ2Dn yBArzejl76aT0hMQe1MLUn2z31vHfPOZGzvHcxuG5G8QoebmmPk85Wkdji6bEMoFeoPh+I I2FlA5ujf6cEEBTfVqoZAxIXFnPN084= From: andrey.konovalov@linux.dev To: Will Deacon , Catalin Marinas Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Vincenzo Frascino , Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 1/2] arm64: kasan: do not instrument stacktrace.c Date: Mon, 23 May 2022 16:51:51 +0200 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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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 Acked-by: Mark Rutland Signed-off-by: Andrey Konovalov --- Changes v1->v2: - Updated the comment in Makefile as suggested by Mark. --- arch/arm64/kernel/Makefile | 5 +++++ arch/arm64/kernel/stacktrace.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index fa7981d0d917..7075a9c6a4a6 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -14,6 +14,11 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_syscall.o = -fstack-protector -fstack-protector-strong CFLAGS_syscall.o += -fno-stack-protector +# When KASAN is enabled, a stack trace is recorded for every alloc/free, which +# can significantly impact performance. Avoid instrumenting the stack trace +# collection code to minimize this impact. +KASAN_SANITIZE_stacktrace.o := n + # 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