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.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,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 1D7C3C433E7 for ; Fri, 9 Oct 2020 09:54:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 95DFE22258 for ; Fri, 9 Oct 2020 09:54:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="i9YOP2P5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95DFE22258 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JCFIlFYcZalC8gSAeMH5cHHUbgh6y0W6PpsjT8W+8wg=; b=i9YOP2P5PzJTHBwB57PMRzpxw Lk8hIGSRCbW7TI0hB3QuzQYbfqhL3N7JoJ0Ca0QUAhrTPnrMH4UJvMEImsmuyUfltVDFeHvjG4fvk heYcA1RAteZPvurQWPFUBDqOCvZF5Hc+g83MC0n1744KgOTY6cjmqnqE24Ip7oVCKZrTP9o0Z7P0F fA/eyiQHFxA3h/vIRjehdSBXoOstUtfWcPmGMWM4h021zdGNYIIW3H4+6tcXho8IePP9ppCYY4LXn ZXdMwy47Ic2NGeUvxCJ5F8beptTWqxASwsjOBheVyTKSF5Rli9vXkWUWdWeCfkhGkrC2JJVyvZ/Tk KroNwb13g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQp5c-0005ft-TY; Fri, 09 Oct 2020 09:53:28 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQp5a-0005eR-1B for linux-arm-kernel@lists.infradead.org; Fri, 09 Oct 2020 09:53:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A9CB7D6E; Fri, 9 Oct 2020 02:53:24 -0700 (PDT) Received: from [10.37.12.22] (unknown [10.37.12.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 45DAD3F66B; Fri, 9 Oct 2020 02:53:21 -0700 (PDT) Subject: Re: [PATCH v4 29/39] arm64: mte: Switch GCR_EL1 in kernel entry and exit To: Catalin Marinas References: <1f2681fdff1aa1096df949cb8634a9be6bf4acc4.1601593784.git.andreyknvl@google.com> <20201002140652.GG7034@gaia> <1b2327ee-5f30-e412-7359-32a7a38b4c8d@arm.com> <20201009081111.GA23638@gaia> From: Vincenzo Frascino Message-ID: <106f8670-3dd0-70ad-91ac-4f419585df50@arm.com> Date: Fri, 9 Oct 2020 10:56:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201009081111.GA23638@gaia> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_055326_121677_E755D9BA X-CRM114-Status: GOOD ( 22.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Elena Petrova , Andrey Konovalov , 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 , Dmitry Vyukov 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 10/9/20 9:11 AM, Catalin Marinas wrote: > 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). > Agree, but still think we should use FIELD_GET here since it is common language in the kernel. How about we get rid of MTE_TAG_MAX and we do something like: GENMASK(FIELD_GET(MTE_TAG_MASK >> MTE_TAG_SHIFT, max_tag), 0); Obviously with a comment ;) -- Regards, Vincenzo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel