Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4188215pxk; Tue, 8 Sep 2020 13:01:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPaLmvEF6tobSywX28YMzfd1Vn5M3BugBMWDYqIddf+MykFMA1kVjvM4fsiIdS1Gsiz4ap X-Received: by 2002:a17:906:35d5:: with SMTP id p21mr137783ejb.194.1599595308667; Tue, 08 Sep 2020 13:01:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599595308; cv=none; d=google.com; s=arc-20160816; b=qxvUMuDAYPk9KGcpmXDkSaGv+U7RIZmp4CRt0s0rT5gm15kexiTBI2J7f11dYflEA9 UFZPHL9E0jrcMQQ1jXiMhmhZjtjWGTbuOwFwe0eHwxorq7SGpZuUx9a15QGQV8MhP8uE 8KmkfVDBkWauzUq21sgHv05+cWevDmBCzue4bv5qaOJxfJLdrRM7pAZ6mwARX/3X+HfE mcRO46j0OfQI8/0CzkrLfJtpNnQHYH2GwB5dCq6QsBX14nT5OSE/qVP0AZfXYQ7IrX1n EfcpMrWYz/G0fG9Y4tMvFQYDUWmuyTlJmyrmtd72pcezWrcfKnvj6tqVWdNmkrvh8G5X xQLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Pq4J2NnfUd+1Pc40yb24NgBzbHzhJ0SXNWzcle1Fztw=; b=k6Oj/DpxHAt2Hw8Fz6JLQ43W8o5I4w9Nvf8WgOZkEU/8zi4oM5qV8ykviBOyDHs5AV 9TCbU6jLP0le2PeOorgr3oSKs2Kg0dND7FUlpionvb5ERv3YNvzi1ZUzq5fYLzTvLzDb RW2N92aIVphW3RU07B9HcILHEmjSzB26eBkxJXrVDwzi1vocD+jyh1z74EUQd/v23+/P lx05QrfZkz30lpi2QJ8ZdEMal658+q/yfsv1FyxaavtvNmTmS1AQsjnGXca1oVjRF0+R 74JlYCFaGXm9BZ5Kc3vwm6iMnvbHXcYVf4ITH/BfnXGfVp+sDZZBHxaHbKP1S2FZxBGh Q/8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g17si25959edw.332.2020.09.08.13.01.25; Tue, 08 Sep 2020 13:01:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732517AbgIHUAh (ORCPT + 99 others); Tue, 8 Sep 2020 16:00:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:58866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730330AbgIHPf0 (ORCPT ); Tue, 8 Sep 2020 11:35:26 -0400 Received: from gaia (unknown [46.69.195.48]) (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 E1F6221919; Tue, 8 Sep 2020 14:41:43 +0000 (UTC) Date: Tue, 8 Sep 2020 15:41:41 +0100 From: Catalin Marinas To: Andrey Konovalov Cc: Dmitry Vyukov , Vincenzo Frascino , kasan-dev , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , Linux ARM , Linux Memory Management List , LKML Subject: Re: [PATCH 26/35] kasan, arm64: Enable TBI EL1 Message-ID: <20200908144140.GG25591@gaia> References: <518da1e5169a4e343caa3c37feed5ad551b77a34.1597425745.git.andreyknvl@google.com> <20200827104033.GF29264@gaia> <20200908140620.GE25591@gaia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 08, 2020 at 04:12:49PM +0200, Andrey Konovalov wrote: > On Tue, Sep 8, 2020 at 4:06 PM Catalin Marinas wrote: > > On Tue, Sep 08, 2020 at 03:18:04PM +0200, Andrey Konovalov wrote: > > > On Thu, Aug 27, 2020 at 12:40 PM Catalin Marinas > > > wrote: > > > > On Fri, Aug 14, 2020 at 07:27:08PM +0200, Andrey Konovalov wrote: > > > > > diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S > > > > > index 152d74f2cc9c..6880ddaa5144 100644 > > > > > --- a/arch/arm64/mm/proc.S > > > > > +++ b/arch/arm64/mm/proc.S > > > > > @@ -38,7 +38,7 @@ > > > > > /* PTWs cacheable, inner/outer WBWA */ > > > > > #define TCR_CACHE_FLAGS TCR_IRGN_WBWA | TCR_ORGN_WBWA > > > > > > > > > > -#ifdef CONFIG_KASAN_SW_TAGS > > > > > +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) > > > > > #define TCR_KASAN_FLAGS TCR_TBI1 > > > > > #else > > > > > #define TCR_KASAN_FLAGS 0 > > > > > > > > I prefer to turn TBI1 on only if MTE is present. So on top of the v8 > > > > user series, just do this in __cpu_setup. > > > > > > Started working on this, but realized that I don't understand what > > > exactly is suggested here. TCR_KASAN_FLAGS are used in __cpu_setup(), > > > so this already happens in __cpu_setup(). > > > > > > Do you mean that TBI1 should be enabled when CONFIG_ARM64_MTE is > > > enabled, but CONFIG_KASAN_HW_TAGS is disabled? > > > > What I meant is that we should turn TBI1 only when the MTE is present in > > hardware (and the ARM64_MTE option is on). But I probably missed the way > > MTE is used with KASAN. > > > > So what happens if CONFIG_KASAN_HW_TAGS and CONFIG_ARM64_MTE are both on > > but the hardware does not support MTE? Does KASAN still generate tagged > > pointers? If yes, then the current patch is fine, we should always set > > TBI1. > > No, the tag is always 0xFF when MTE is not supported. > > Should we then only enable TBI1 if system_supports_mte() or something > like that? You could add it do this block in __cpu_setup: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/tree/arch/arm64/mm/proc.S?h=for-next/mte#n429 It needs a few changes to have "mov_q x10, TCR_..." before the MTE check so that you can add the TBI1 bit in there. system_supports_mte() would be called too late, you want this set before the MMU is turned on. -- Catalin