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=-8.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,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 EA83AC2BBD1 for ; Thu, 17 Sep 2020 16:59:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 726EB206A4 for ; Thu, 17 Sep 2020 16:59:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 726EB206A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DC7F06B005A; Thu, 17 Sep 2020 12:59:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D4F1B6B005C; Thu, 17 Sep 2020 12:59:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C3DC68E0001; Thu, 17 Sep 2020 12:59:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id A89626B005A for ; Thu, 17 Sep 2020 12:59:02 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 640C9485C for ; Thu, 17 Sep 2020 16:59:02 +0000 (UTC) X-FDA: 77273163324.21.hate71_0e0802227124 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 338EF180442C4 for ; Thu, 17 Sep 2020 16:59:02 +0000 (UTC) X-HE-Tag: hate71_0e0802227124 X-Filterd-Recvd-Size: 3474 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Thu, 17 Sep 2020 16:59:01 +0000 (UTC) Received: from gaia (unknown [31.124.44.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5906E2064B; Thu, 17 Sep 2020 16:58:58 +0000 (UTC) Date: Thu, 17 Sep 2020 17:58:55 +0100 From: Catalin Marinas To: Andrey Konovalov Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Elena Petrova , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Subject: Re: [PATCH v2 27/37] arm64: mte: Switch GCR_EL1 in kernel entry and exit Message-ID: <20200917165855.GH10662@gaia> References: <20200917165221.GF10662@gaia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200917165221.GF10662@gaia> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Sep 17, 2020 at 05:52:21PM +0100, Catalin Marinas wrote: > On Tue, Sep 15, 2020 at 11:16:09PM +0200, Andrey Konovalov wrote: > > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S > > index ff34461524d4..79a6848840bd 100644 > > --- a/arch/arm64/kernel/entry.S > > +++ b/arch/arm64/kernel/entry.S > > @@ -175,6 +175,28 @@ alternative_else_nop_endif > > #endif > > .endm > > > > + .macro mte_restore_gcr, el, tsk, tmp, tmp2 > > +#ifdef CONFIG_ARM64_MTE > > +alternative_if_not ARM64_MTE > > + b 1f > > +alternative_else_nop_endif > > + .if \el == 0 > > + ldr \tmp, [\tsk, #THREAD_GCR_EL1_USER] > > + .else > > + ldr_l \tmp, gcr_kernel_excl > > + .endif > > + /* > > + * Calculate and set the exclude mask preserving > > + * the RRND (bit[16]) setting. > > + */ > > + mrs_s \tmp2, SYS_GCR_EL1 > > + bfi \tmp2, \tmp, #0, #16 > > + msr_s SYS_GCR_EL1, \tmp2 > > + isb > > +1: > > +#endif > > + .endm > > + > > .macro kernel_entry, el, regsize = 64 > > .if \regsize == 32 > > mov w0, w0 // zero upper 32 bits of x0 > > @@ -214,6 +236,8 @@ alternative_else_nop_endif > > > > ptrauth_keys_install_kernel tsk, x20, x22, x23 > > > > + mte_restore_gcr 1, tsk, x22, x23 > > + > > scs_load tsk, x20 > > .else > > add x21, sp, #S_FRAME_SIZE > > @@ -332,6 +356,8 @@ alternative_else_nop_endif > > /* No kernel C function calls after this as user keys are set. */ > > ptrauth_keys_install_user tsk, x0, x1, x2 > > > > + mte_restore_gcr 0, tsk, x0, x1 > > Some nitpicks on these macros to match the ptrauth_keys_* above. Define > separate mte_set_{user,kernel}_gcr macros with a common mte_set_gcr that > is used by both. One more thing - the new mte_set_kernel_gcr should probably skip the GCR_EL1 update if KASAN_HW_TAGS is disabled. -- Catalin