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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,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 24921C433E0 for ; Fri, 12 Mar 2021 15:24:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFE1A64FFB for ; Fri, 12 Mar 2021 15:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231907AbhCLPXy (ORCPT ); Fri, 12 Mar 2021 10:23:54 -0500 Received: from foss.arm.com ([217.140.110.172]:55642 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231789AbhCLPXs (ORCPT ); Fri, 12 Mar 2021 10:23:48 -0500 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 C1A221FB; Fri, 12 Mar 2021 07:23:47 -0800 (PST) Received: from [10.37.8.6] (unknown [10.37.8.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3C60A3F7D7; Fri, 12 Mar 2021 07:23:45 -0800 (PST) Subject: Re: [PATCH v15 5/8] arm64: mte: Enable TCO in functions that can read beyond buffer limits To: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Andrew Morton , Will Deacon , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Andrey Konovalov , Lorenzo Pieralisi References: <20210312142210.21326-1-vincenzo.frascino@arm.com> <20210312142210.21326-6-vincenzo.frascino@arm.com> <20210312151259.GB24210@arm.com> From: Vincenzo Frascino Message-ID: <31b7a388-4c57-cb25-2d30-da7c37e2b4d6@arm.com> Date: Fri, 12 Mar 2021 15:23:44 +0000 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: <20210312151259.GB24210@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/12/21 3:13 PM, Catalin Marinas wrote: > On Fri, Mar 12, 2021 at 02:22:07PM +0000, Vincenzo Frascino wrote: >> diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h >> index 9b557a457f24..8603c6636a7d 100644 >> --- a/arch/arm64/include/asm/mte.h >> +++ b/arch/arm64/include/asm/mte.h >> @@ -90,5 +90,20 @@ static inline void mte_assign_mem_tag_range(void *addr, size_t size) >> >> #endif /* CONFIG_ARM64_MTE */ >> >> +#ifdef CONFIG_KASAN_HW_TAGS >> +/* Whether the MTE asynchronous mode is enabled. */ >> +DECLARE_STATIC_KEY_FALSE(mte_async_mode); >> + >> +static inline bool system_uses_mte_async_mode(void) >> +{ >> + return static_branch_unlikely(&mte_async_mode); >> +} >> +#else >> +static inline bool system_uses_mte_async_mode(void) >> +{ >> + return false; >> +} >> +#endif /* CONFIG_KASAN_HW_TAGS */ > > You can write this with fewer lines: > > DECLARE_STATIC_KEY_FALSE(mte_async_mode); > > static inline bool system_uses_mte_async_mode(void) > { > return IS_ENABLED(CONFIG_KASAN_HW_TAGS) && > static_branch_unlikely(&mte_async_mode); > } > > The compiler will ensure that mte_async_mode is not referred when > !CONFIG_KASAN_HW_TAGS and therefore doesn't need to be defined. > Yes, I agree, but I introduce "#ifdef CONFIG_KASAN_HW_TAGS" in the successive patch anyway, according to me the overall code looks more uniform like this. But I do not have a strong opinion or preference on this. >> diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c >> index fa755cf94e01..9362928ba0d5 100644 >> --- a/arch/arm64/kernel/mte.c >> +++ b/arch/arm64/kernel/mte.c >> @@ -26,6 +26,10 @@ u64 gcr_kernel_excl __ro_after_init; >> >> static bool report_fault_once = true; >> >> +/* Whether the MTE asynchronous mode is enabled. */ >> +DEFINE_STATIC_KEY_FALSE(mte_async_mode); >> +EXPORT_SYMBOL_GPL(mte_async_mode); > > Maybe keep these bracketed by #ifdef CONFIG_KASAN_HW_TAGS. I think the > mte_enable_kernel_*() aren't needed either if KASAN_HW is disabled (you > can do it with an additional patch). > Makes sense, I will add it in the next version. > With these, you can add: > > Reviewed-by: Catalin Marinas > -- Regards, Vincenzo