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 63E52C433DF for ; Wed, 26 Aug 2020 15:24:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2DCF02078D for ; Wed, 26 Aug 2020 15:24:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DCF02078D 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 BBF606B0031; Wed, 26 Aug 2020 11:24:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B70196B0033; Wed, 26 Aug 2020 11:24:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A85326B0037; Wed, 26 Aug 2020 11:24:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0246.hostedemail.com [216.40.44.246]) by kanga.kvack.org (Postfix) with ESMTP id 8F0306B0031 for ; Wed, 26 Aug 2020 11:24:18 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 42025181AEF15 for ; Wed, 26 Aug 2020 15:24:18 +0000 (UTC) X-FDA: 77193090996.07.flame25_5d03ec727065 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 083171803F9AA for ; Wed, 26 Aug 2020 15:24:18 +0000 (UTC) X-HE-Tag: flame25_5d03ec727065 X-Filterd-Recvd-Size: 4203 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 26 Aug 2020 15:24:17 +0000 (UTC) Received: from gaia (unknown [46.69.195.127]) (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 8A3D82075E; Wed, 26 Aug 2020 15:24:14 +0000 (UTC) Date: Wed, 26 Aug 2020 16:24:12 +0100 From: Catalin Marinas To: Marc Zyngier Cc: Vincenzo Frascino , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, Will Deacon , Dave P Martin , Szabolcs Nagy , Kevin Brodsky , Andrey Konovalov , Peter Collingbourne , Andrew Morton , Suzuki K Poulose Subject: Re: [PATCH v8 03/28] arm64: mte: CPU feature detection and initial sysreg configuration Message-ID: <20200826152411.GA24545@gaia> References: <20200824182758.27267-1-catalin.marinas@arm.com> <20200824182758.27267-4-catalin.marinas@arm.com> <61bba3c1948651a5221b87f2dfa2872f@kernel.org> <20200825105450.GA22233@C02TF0J2HF1T.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200825105450.GA22233@C02TF0J2HF1T.local> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 083171803F9AA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 Tue, Aug 25, 2020 at 11:54:50AM +0100, Catalin Marinas wrote: > On Tue, Aug 25, 2020 at 09:53:16AM +0100, Marc Zyngier wrote: > > On 2020-08-24 19:27, Catalin Marinas wrote: > > > diff --git a/arch/arm64/include/asm/kvm_arm.h > > > b/arch/arm64/include/asm/kvm_arm.h > > > index 8a1cbfd544d6..6c3b2fc922bb 100644 > > > --- a/arch/arm64/include/asm/kvm_arm.h > > > +++ b/arch/arm64/include/asm/kvm_arm.h > > > @@ -78,7 +78,7 @@ > > > HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW | HCR_TLOR | \ > > > HCR_FMO | HCR_IMO) > > > #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF) > > > -#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK) > > > +#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK | HCR_ATA) > > > #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) > > > > Why is HCR_ATA only set for nVHE? HCR_EL2.ATA seems to apply to both, > > doesn't it? > > We need HCR_EL2.ATA to be set when !VHE so that the host kernel can use > MTE. That said, I think we need to turn it off when running a guest. > Even if we hide the ID register, the guest may still attempt to enable > tags on some memory that doesn't support it, leading to unpredictable > behaviour (well, only if we expose device memory to guests directly; > Steve's patches will deal with this but for now we just disable MTE in > guests). So if we want to properly disable MTE for guests when !VHE (not just the ID reg), I came up with the diff below. However, given that Steven is already working on KVM support, I wonder whether we could just make MTE depend on !VHE temporarily, remove it once we get the full MTE KVM support. It's up to you (either way, I still need to solve the undef injection since that affects both VHE and !VHE; patch to follow). diff --git a/arch/arm64/kvm/hyp/nvhe/tlb.c b/arch/arm64/kvm/hyp/nvhe/tlb.c index 69eae608d670..51204ac30154 100644 --- a/arch/arm64/kvm/hyp/nvhe/tlb.c +++ b/arch/arm64/kvm/hyp/nvhe/tlb.c @@ -32,10 +32,23 @@ static void __tlb_switch_to_guest(struct kvm_s2_mmu *mmu, } __load_guest_stage2(mmu); + + /* MTE is not supported in guests yet, disable access to tags */ + if (system_supports_mte()) { + u64 val = read_sysreg(hcr_el2); + val &= ~HCR_ATA; + write_sysreg(val, hcr_el2); + } } static void __tlb_switch_to_host(struct tlb_inv_context *cxt) { + /* Re-enable MTE for the host kernel */ + if (system_supports_mte()) { + u64 val = read_sysreg(hcr_el2); + write_sysreg(val | HCR_ATA, hcr_el2); + } + write_sysreg(0, vttbr_el2); if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) { -- Catalin