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=-9.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 50F75C433F5 for ; Thu, 9 Sep 2021 17:41:51 +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 16284610C7 for ; Thu, 9 Sep 2021 17:41:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 16284610C7 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=q5WUDecmUf0loQiwLeJiwpCOg8vvwt4bkprG2SuGGrs=; b=uYUE/3HFGdJbAJ gCj0+SClfz7VOby2zLvLsf8QDsjBCksBk6yR27dnosZG5VIofUaWMgO5MaqNVIuPadKCBT1mHOXjO I0eoqpiOXO4miccj5TQ4vRU6QKTVXeTpLJdBGWX4ygrA1s4KK9qw9qf3DehQ5PF2UYKtpoHCzPuNv 0+2ee6lzNcHQmpQmn52FHJQByLIz58qbLebpYUySprXwP3Mq3lioQgr2BS0URUJU7FOILeCMyYQ4J 5TSGmOVcxuaPF+d5JDwnIh7870Unv4TutZJ6d0ygjOfhy4l7srqZmo9ePJpCCcYhed6p+7Qo2yxEj 5yiR4E/5DYdo4D6Cr2+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mOO1p-00AXLn-2b; Thu, 09 Sep 2021 17:40:01 +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 1mOO1l-00AXLI-0D for linux-arm-kernel@lists.infradead.org; Thu, 09 Sep 2021 17:39:58 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id D624D6103E; Thu, 9 Sep 2021 17:39:54 +0000 (UTC) Date: Thu, 9 Sep 2021 18:39:51 +0100 From: Catalin Marinas To: Peter Collingbourne Cc: Vincenzo Frascino , Will Deacon , Andrey Konovalov , Evgenii Stepanov , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] arm64: kasan: mte: move GCR_EL1 switch to task switch when KASAN disabled Message-ID: References: <20210827030748.587710-1-pcc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210827030748.587710-1-pcc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210909_103957_104624_935BDE2B X-CRM114-Status: GOOD ( 18.20 ) 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 Thu, Aug 26, 2021 at 08:07:48PM -0700, Peter Collingbourne wrote: > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S > index 923ee2ac85fd..e12ed892cde8 100644 > --- a/arch/arm64/kernel/entry.S > +++ b/arch/arm64/kernel/entry.S > @@ -178,9 +178,9 @@ alternative_else_nop_endif > > .macro mte_set_kernel_gcr, tmp, tmp2 > #ifdef CONFIG_KASAN_HW_TAGS > -alternative_if_not ARM64_MTE > +alternative_cb kasan_hw_tags_enable > b 1f > -alternative_else_nop_endif > +alternative_cb_end > mov \tmp, KERNEL_GCR_EL1 > msr_s SYS_GCR_EL1, \tmp > 1: > @@ -188,10 +188,10 @@ alternative_else_nop_endif > .endm > > .macro mte_set_user_gcr, tsk, tmp, tmp2 > -#ifdef CONFIG_ARM64_MTE > -alternative_if_not ARM64_MTE > +#ifdef CONFIG_KASAN_HW_TAGS > +alternative_cb kasan_hw_tags_enable > b 1f > -alternative_else_nop_endif > +alternative_cb_end > ldr \tmp, [\tsk, #THREAD_MTE_CTRL] > > mte_set_gcr \tmp, \tmp2 > diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c > index 9d314a3bad3b..0e8edb5d5861 100644 > --- a/arch/arm64/kernel/mte.c > +++ b/arch/arm64/kernel/mte.c > @@ -162,7 +162,7 @@ void mte_check_tfsr_el1(void) > } > #endif > > -static void mte_update_sctlr_user(struct task_struct *task) > +static void mte_update_sctlr_user_and_gcr_excl(struct task_struct *task) > { > /* > * This must be called with preemption disabled and can only be called > @@ -182,6 +182,24 @@ static void mte_update_sctlr_user(struct task_struct *task) > else if (resolved_mte_tcf & MTE_CTRL_TCF_SYNC) > sctlr |= SCTLR_EL1_TCF0_SYNC; > task->thread.sctlr_user = sctlr; > + > + /* > + * SYS_GCR_EL1 will be set to current->thread.mte_ctrl value by > + * mte_set_user_gcr() in kernel_exit, but only if KASAN is enabled. > + */ > + if (!kasan_hw_tags_enabled()) > + write_sysreg_s(((mte_ctrl >> MTE_CTRL_GCR_USER_EXCL_SHIFT) & > + SYS_GCR_EL1_EXCL_MASK) | SYS_GCR_EL1_RRND, > + SYS_GCR_EL1); > +} > + > +void __init kasan_hw_tags_enable(struct alt_instr *alt, __le32 *origptr, > + __le32 *updptr, int nr_inst) > +{ > + BUG_ON(nr_inst != 1); /* Branch -> NOP */ > + > + if (kasan_hw_tags_enabled()) > + *updptr = cpu_to_le32(aarch64_insn_gen_nop()); > } A bit confusing: kasan_hw_tags_enabled() checks the kasan_flag_enabled static label. This is initialised via kasan_init_hw_tags() which is called from smp_prepare_boot_cpu() _after_ apply_boot_alternatives(). Does this work when kasan is indeed enabled? Maybe I miss something. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel