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.2 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 08077C433E7 for ; Fri, 9 Oct 2020 08:11:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7696F22227 for ; Fri, 9 Oct 2020 08:11:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7696F22227 Authentication-Results: mail.kernel.org; dmarc=fail (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 9BA186B0074; Fri, 9 Oct 2020 04:11:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 969C26B0096; Fri, 9 Oct 2020 04:11:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 881338E0001; Fri, 9 Oct 2020 04:11:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id 56AF16B0074 for ; Fri, 9 Oct 2020 04:11:34 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D669A181AE868 for ; Fri, 9 Oct 2020 08:11:33 +0000 (UTC) X-FDA: 77351667666.28.cats75_260f99e271df Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 39F626D66 for ; Fri, 9 Oct 2020 08:11:20 +0000 (UTC) X-HE-Tag: cats75_260f99e271df X-Filterd-Recvd-Size: 3383 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 08:11:19 +0000 (UTC) Received: from gaia (unknown [95.149.105.49]) (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 2E2B221789; Fri, 9 Oct 2020 08:11:16 +0000 (UTC) Date: Fri, 9 Oct 2020 09:11:13 +0100 From: Catalin Marinas To: Vincenzo Frascino Cc: Andrey Konovalov , Dmitry Vyukov , kasan-dev@googlegroups.com, Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 29/39] arm64: mte: Switch GCR_EL1 in kernel entry and exit Message-ID: <20201009081111.GA23638@gaia> References: <1f2681fdff1aa1096df949cb8634a9be6bf4acc4.1601593784.git.andreyknvl@google.com> <20201002140652.GG7034@gaia> <1b2327ee-5f30-e412-7359-32a7a38b4c8d@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1b2327ee-5f30-e412-7359-32a7a38b4c8d@arm.com> 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, Oct 08, 2020 at 07:24:12PM +0100, Vincenzo Frascino wrote: > On 10/2/20 3:06 PM, Catalin Marinas wrote: > > On Fri, Oct 02, 2020 at 01:10:30AM +0200, Andrey Konovalov wrote: > >> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c > >> index 7c67ac6f08df..d1847f29f59b 100644 > >> --- a/arch/arm64/kernel/mte.c > >> +++ b/arch/arm64/kernel/mte.c > >> @@ -23,6 +23,8 @@ > >> #include > >> #include > >> > >> +u64 gcr_kernel_excl __ro_after_init; > >> + > >> static void mte_sync_page_tags(struct page *page, pte_t *ptep, bool check_swap) > >> { > >> pte_t old_pte = READ_ONCE(*ptep); > >> @@ -120,6 +122,13 @@ void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) > >> return ptr; > >> } > >> > >> +void mte_init_tags(u64 max_tag) > >> +{ > >> + u64 incl = GENMASK(max_tag & MTE_TAG_MAX, 0); > > > > Nitpick: it's not obvious that MTE_TAG_MAX is a mask, so better write > > this as GENMASK(min(max_tag, MTE_TAG_MAX), 0). > > The two things do not seem equivalent because the format of the tags in KASAN is > 0xFF and in MTE is 0xF, hence if extract the minimum whatever is the tag passed > by KASAN it will always be MTE_TAG_MAX. > > To make it cleaner I propose: GENMASK(FIELD_GET(MTE_TAG_MAX, max_tag), 0); I don't think that's any clearer since FIELD_GET still assumes that MTE_TAG_MAX is a mask. I think it's better to add a comment on why this is needed, as you explained above that the KASAN tags go to 0xff. If you want to get rid of MTE_TAG_MAX altogether, just do a max_tag &= (1 << MAX_TAG_SIZE) - 1; before setting incl (a comment is still useful). -- Catalin