Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp459868ybt; Wed, 17 Jun 2020 05:43:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlvT1jeddsqWWvc1yxCkK06vAtkFzv0OJCyy45wguSDQQEI+PnQG+Vwjg7HSikxR3lpKCh X-Received: by 2002:a17:906:1c8e:: with SMTP id g14mr7358736ejh.136.1592397838908; Wed, 17 Jun 2020 05:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592397838; cv=none; d=google.com; s=arc-20160816; b=KAh2rTQwy8avq7x6eJaPgl64UIiYwQUdE6hEzRRub6t+bfysKfGh8IhO42624GTNmP L8MeCzOm/0oUlphC+cYjMroSRxNbsZl21mV5uFhw6S4AfPPIXcN7syayxH36mMbsqxqD SM2aKwSKFQ+gy/kf6hbb0MkcBuV2/tczW0yEXz9klDKsFryi/rTrXq3EQ1RsEAH144B3 DjgAnoUyLacsEyWDoyWW1IaCPGeo7z+ajJGVH55UD+5N33jWlhwHNhOTJSbzprag2QaI 6qDL63ODFzVQVCaYWITReNQJurkBk3dYa/xqaYkml6V+FG2QyaKCwbOv/ViHuRUuljHU PiDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Txaf+VKJu8VyTIdz2GpaIKYNRYEteCR6b62g31rAxbM=; b=gosVW6fDLJuow8+MqlgfpeeM0ZqHS7B3QUdFHQIfBCAsOs3/yRnR6OeZap85GIf8se HGbJJncacDJNvU75byIuHXfB3Rp3twRb07s5QCuFhqHts8mOuS86ieBUvqlhPWz2Eja/ 0BfdP5o63X7VifWgi8j3RkytusdaA3wOOcKA2QkKZe2ShTWn2s+FUQygnJiGqqdlMbDw 1Hz3/PumgAAXeHNyxWJ3ilMMnJhCk6oPOEKFGdPQOrsAjJWZXTbEOiwKF/d7f3+Kj5H3 DgyDUDBVf/m0aLjF3NRqxiAm7HcPINGuiS5qmE4YVJPJVLB6XwY+gm9WJfAUIluG8SLs xp6g== 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 t13si12516704ejr.37.2020.06.17.05.43.36; Wed, 17 Jun 2020 05:43:58 -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 S1726780AbgFQMj1 (ORCPT + 99 others); Wed, 17 Jun 2020 08:39:27 -0400 Received: from foss.arm.com ([217.140.110.172]:57174 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726701AbgFQMjZ (ORCPT ); Wed, 17 Jun 2020 08:39:25 -0400 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 D033512FC; Wed, 17 Jun 2020 05:39:24 -0700 (PDT) Received: from e112269-lin.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 100DB3F71F; Wed, 17 Jun 2020 05:39:22 -0700 (PDT) From: Steven Price To: Catalin Marinas , Marc Zyngier , Will Deacon Cc: Steven Price , James Morse , Julien Thierry , Suzuki K Poulose , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Martin , Mark Rutland , Thomas Gleixner Subject: [RFC PATCH 2/2] arm64: kvm: Introduce MTE VCPU feature Date: Wed, 17 Jun 2020 13:38:44 +0100 Message-Id: <20200617123844.29960-3-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200617123844.29960-1-steven.price@arm.com> References: <20200617123844.29960-1-steven.price@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new VCPU features 'KVM_ARM_VCPU_MTE' which enables memory tagging on a VCPU. When enabled on any VCPU in the virtual machine this causes all pages that are faulted into the VM to have the PG_mte_tagged flag set (and the tag storage cleared if this is the first use). Signed-off-by: Steven Price --- arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/reset.c | 8 ++++++++ arch/arm64/kvm/sys_regs.c | 3 ++- virt/kvm/arm/mmu.c | 11 +++++++++++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index a30b4eec7cb4..b118f466a40b 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -79,6 +79,9 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) if (cpus_have_const_cap(ARM64_MISMATCHED_CACHE_TYPE) || vcpu_el1_is_32bit(vcpu)) vcpu->arch.hcr_el2 |= HCR_TID2; + + if (test_bit(KVM_ARM_VCPU_MTE, vcpu->arch.features)) + vcpu->arch.hcr_el2 |= HCR_ATA; } static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 1f10e9dee2e0..3461639bb08a 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -37,7 +37,7 @@ #define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS -#define KVM_VCPU_MAX_FEATURES 7 +#define KVM_VCPU_MAX_FEATURES 8 #define KVM_REQ_SLEEP \ KVM_ARCH_REQ_FLAGS(0, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index ba85bb23f060..2677e1ab8c16 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -106,6 +106,7 @@ struct kvm_regs { #define KVM_ARM_VCPU_SVE 4 /* enable SVE for this CPU */ #define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5 /* VCPU uses address authentication */ #define KVM_ARM_VCPU_PTRAUTH_GENERIC 6 /* VCPU uses generic authentication */ +#define KVM_ARM_VCPU_MTE 7 /* VCPU supports Memory Tagging */ struct kvm_vcpu_init { __u32 target; diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index ab76728e2742..f87a434c0849 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -287,6 +287,14 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) } } + if (test_bit(KVM_ARM_VCPU_MTE, vcpu->arch.features)) { + if (!system_supports_mte()) { + ret = -EINVAL; + goto out; + } + vcpu->kvm->arch.vcpu_has_mte = true; + } + switch (vcpu->arch.target) { default: if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) { diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 3ae008a9b0bd..a6a9552d1233 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1096,7 +1096,8 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu, val &= ~(0xfUL << ID_AA64PFR0_SVE_SHIFT); val &= ~(0xfUL << ID_AA64PFR0_AMU_SHIFT); } else if (id == SYS_ID_AA64PFR1_EL1) { - val &= ~(0xfUL << ID_AA64PFR1_MTE_SHIFT); + if (!test_bit(KVM_ARM_VCPU_MTE, vcpu->arch.features)) + val &= ~(0xfUL << ID_AA64PFR1_MTE_SHIFT); } else if (id == SYS_ID_AA64ISAR1_EL1 && !vcpu_has_ptrauth(vcpu)) { val &= ~((0xfUL << ID_AA64ISAR1_APA_SHIFT) | (0xfUL << ID_AA64ISAR1_API_SHIFT) | diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index e3b9ee268823..040a7fffaa93 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1783,6 +1783,17 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, vma_pagesize = PMD_SIZE; } + if (system_supports_mte() && kvm->arch.vcpu_has_mte) { + /* + * VM will be able to see the page's tags, so we must ensure + * they have been initialised. + */ + struct page *page = pfn_to_page(pfn); + + if (!test_and_set_bit(PG_mte_tagged, &page->flags)) + mte_clear_page_tags(page_address(page), page_size(page)); + } + if (writable) kvm_set_pfn_dirty(pfn); -- 2.20.1