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 X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 B40CCC4338F for ; Tue, 27 Jul 2021 18:47:30 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 82ECC60F6E for ; Tue, 27 Jul 2021 18:47:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 82ECC60F6E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=DAd8a2cZ7ZH9ir5ss2ZrLRKXDra1TkZ5aOqJIEeUlCU=; b=cBkizNAhbkR2Zd SujjQyVy9g6PUjSAUnWUpLw56qURwJH/74jRVu6Y+VEv6seGoLZpHom+SPcxS0JhVkskwUJ+j78Yo vBSmYC6opmXxcrvBc7MLh+yEQATCaa39I95yWuSY6mOtw5pMRPq3f9nqOVpP/q7WJ8XPjWbvOSd62 FGNiEsgIaEbNeBS7T063TEKvhd0e5YRMsV+iadCrWB+qnEgAeSojb2oO2VURHo1PkMNxh8U3OoJbY sWMvBpvigTp6gP85Ybx8n+0HfhtWTl2fFeacLkBh8gRehaPPXByaCZDwdictBbRFLyzcwnhVzRPjs lTQGHW9N6k5v0TKHDziA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8S4i-00Fz2K-Se; Tue, 27 Jul 2021 18:45:10 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8RpW-00FsZ3-B8 for linux-arm-kernel@lists.infradead.org; Tue, 27 Jul 2021 18:29:27 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9E48060F91; Tue, 27 Jul 2021 18:29:22 +0000 (UTC) Date: Tue, 27 Jul 2021 19:29:19 +0100 From: Catalin Marinas To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, andreyknvl@gmail.com, dvyukov@google.com, glider@google.com, pcc@google.com, ryabinin.a.a@gmail.com, vincenzo.frascino@arm.com, will@kernel.org Subject: Re: [PATCH 2/3] arm64: kasan: mte: use a constant kernel GCR_EL1 value Message-ID: <20210727182919.GT13920@arm.com> References: <20210714143843.56537-1-mark.rutland@arm.com> <20210714143843.56537-3-mark.rutland@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210714143843.56537-3-mark.rutland@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210727_112926_466512_3523E79C X-CRM114-Status: GOOD ( 30.45 ) 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 Wed, Jul 14, 2021 at 03:38:42PM +0100, Mark Rutland wrote: > When KASAN_HW_TAGS is selected, KASAN is enabled at boot time, and the > hardware supports MTE, we'll initialize `kernel_gcr_excl` with a value > dependent on KASAN_TAG_MAX. While the resulting value is a constant > which depends on KASAN_TAG_MAX, we have to perform some runtime work to > generate the value, and have to read the value from memory during the > exception entry path. It would be better if we could generate this as a > constant at compile-time, and use it as such directly. > > Early in boot within __cpu_setup(), we initialize GCR_EL1 to a safe > value, and later override this with the value required by KASAN. If > CONFIG_KASAN_HW_TAGS is not selected, or if KASAN is disabeld at boot > time, the kernel will not use IRG instructions, and so the initial value > of GCR_EL1 is does not matter to the kernel. Thus, we can instead have > __cpu_setup() initialize GCR_EL1 to a value consistent with > KASAN_TAG_MAX, and avoid the need to re-initialize it during hotplug and > resume form suspend. > > This patch makes arem64 use a compile-time constant KERNEL_GCR_EL1 > value, which is compatible with KASAN_HW_TAGS when this is selected. > This removes the need to re-initialize GCR_EL1 dynamically, and acts as > an optimization to the entry assembly, which no longer needs to load > this value from memory. The redundant initialization hooks are removed. > > In order to do this, KASAN_TAG_MAX needs to be visible outside of the > core KASAN code. To do this, I've moved the KASAN_TAG_* values into > . > > There should be no functional change as a result of this patch. > > Signed-off-by: Mark Rutland > Cc: Alexander Potapenko > Cc: Andrey Konovalov > Cc: Andrey Ryabinin > Cc: Catalin Marinas > Cc: Dmitry Vyukov > Cc: Peter Collingbourne > Cc: Vincenzo Frascino > Cc: Will Deacon Reviewed-by: Catalin Marinas > diff --git a/include/linux/kasan-tags.h b/include/linux/kasan-tags.h > new file mode 100644 > index 000000000000..4f85f562512c > --- /dev/null > +++ b/include/linux/kasan-tags.h > @@ -0,0 +1,15 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _LINUX_KASAN_TAGS_H > +#define _LINUX_KASAN_TAGS_H > + > +#define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ > +#define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ > +#define KASAN_TAG_MAX 0xFD /* maximum value for random tags */ > + > +#ifdef CONFIG_KASAN_HW_TAGS > +#define KASAN_TAG_MIN 0xF0 /* minimum value for random tags */ > +#else > +#define KASAN_TAG_MIN 0x00 /* minimum value for random tags */ > +#endif > + > +#endif /* LINUX_KASAN_TAGS_H */ If the kasan folk are happy with this change, I can take the patches through the arm64 tree. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel