[2/2] arm64: kvm: Introduce MTE VCPU feature
diff mbox series

Message ID 20200713100102.53664-3-steven.price@arm.com
State New
Headers show
Series
  • MTE support for KVM guest
Related show

Commit Message

Steven Price July 13, 2020, 10:01 a.m. UTC
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 <steven.price@arm.com>
---
 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/mmu.c                 | 15 +++++++++++++++
 arch/arm64/kvm/reset.c               |  8 ++++++++
 arch/arm64/kvm/sys_regs.c            |  3 ++-
 6 files changed, 30 insertions(+), 2 deletions(-)

Comments

kernel test robot July 13, 2020, 11:22 p.m. UTC | #1
Hi Steven,

I love your patch! Yet something to improve:

[auto build test ERROR on v5.8-rc5]
[cannot apply to kvmarm/next arm64/for-next/core arm-perf/for-next/perf next-20200713]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use  as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Steven-Price/MTE-support-for-KVM-guest/20200713-180255
base:    11ba468877bb23f28956a35e896356252d63c983
config: arm64-allyesconfig (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   In file included from arch/arm64/kvm/arm.c:37:
   arch/arm64/include/asm/kvm_emulate.h: In function 'vcpu_reset_hcr':
>> arch/arm64/include/asm/kvm_emulate.h:84:25: error: 'HCR_ATA' undeclared (first use in this function); did you mean 'HCR_PTW'?
      84 |   vcpu->arch.hcr_el2 |= HCR_ATA;
         |                         ^~~~~~~
         |                         HCR_PTW
   arch/arm64/include/asm/kvm_emulate.h:84:25: note: each undeclared identifier is reported only once for each function it appears in
--
   In file included from arch/arm64/kvm/mmu.c:19:
   arch/arm64/include/asm/kvm_emulate.h: In function 'vcpu_reset_hcr':
>> arch/arm64/include/asm/kvm_emulate.h:84:25: error: 'HCR_ATA' undeclared (first use in this function); did you mean 'HCR_PTW'?
      84 |   vcpu->arch.hcr_el2 |= HCR_ATA;
         |                         ^~~~~~~
         |                         HCR_PTW
   arch/arm64/include/asm/kvm_emulate.h:84:25: note: each undeclared identifier is reported only once for each function it appears in
   arch/arm64/kvm/mmu.c: In function 'unmap_hyp_puds':
   arch/arm64/kvm/mmu.c:574:15: warning: variable 'start_pud' set but not used [-Wunused-but-set-variable]
     574 |  pud_t *pud, *start_pud;
         |               ^~~~~~~~~
   arch/arm64/kvm/mmu.c: In function 'unmap_hyp_p4ds':
   arch/arm64/kvm/mmu.c:591:15: warning: variable 'start_p4d' set but not used [-Wunused-but-set-variable]
     591 |  p4d_t *p4d, *start_p4d;
         |               ^~~~~~~~~
   arch/arm64/kvm/mmu.c: In function 'stage2_get_p4d':
   arch/arm64/kvm/mmu.c:1129:9: warning: variable 'p4d' set but not used [-Wunused-but-set-variable]
    1129 |  p4d_t *p4d;
         |         ^~~
   arch/arm64/kvm/mmu.c: In function 'user_mem_abort':
>> arch/arm64/kvm/mmu.c:1943:6: error: implicit declaration of function 'system_supports_mte'; did you mean 'system_supports_bti'? [-Werror=implicit-function-declaration]
    1943 |  if (system_supports_mte() && kvm->arch.vcpu_has_mte && pfn_valid(pfn)) {
         |      ^~~~~~~~~~~~~~~~~~~
         |      system_supports_bti
>> arch/arm64/kvm/mmu.c:1953:26: error: 'PG_mte_tagged' undeclared (first use in this function)
    1953 |    if (!test_and_set_bit(PG_mte_tagged, &page->flags))
         |                          ^~~~~~~~~~~~~
>> arch/arm64/kvm/mmu.c:1954:5: error: implicit declaration of function 'mte_clear_page_tags' [-Werror=implicit-function-declaration]
    1954 |     mte_clear_page_tags(page_address(page));
         |     ^~~~~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors
--
   In file included from arch/arm64/kvm/handle_exit.c:18:
   arch/arm64/include/asm/kvm_emulate.h: In function 'vcpu_reset_hcr':
>> arch/arm64/include/asm/kvm_emulate.h:84:25: error: 'HCR_ATA' undeclared (first use in this function); did you mean 'HCR_PTW'?
      84 |   vcpu->arch.hcr_el2 |= HCR_ATA;
         |                         ^~~~~~~
         |                         HCR_PTW
   arch/arm64/include/asm/kvm_emulate.h:84:25: note: each undeclared identifier is reported only once for each function it appears in
   arch/arm64/kvm/handle_exit.c: At top level:
   arch/arm64/kvm/handle_exit.c:178:21: warning: initialized field overwritten [-Woverride-init]
     178 |  [ESR_ELx_EC_WFx] = kvm_handle_wfx,
         |                     ^~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:178:21: note: (near initialization for 'arm_exit_handlers[1]')
   arch/arm64/kvm/handle_exit.c:179:25: warning: initialized field overwritten [-Woverride-init]
     179 |  [ESR_ELx_EC_CP15_32] = kvm_handle_cp15_32,
         |                         ^~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:179:25: note: (near initialization for 'arm_exit_handlers[3]')
   arch/arm64/kvm/handle_exit.c:180:25: warning: initialized field overwritten [-Woverride-init]
     180 |  [ESR_ELx_EC_CP15_64] = kvm_handle_cp15_64,
         |                         ^~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:180:25: note: (near initialization for 'arm_exit_handlers[4]')
   arch/arm64/kvm/handle_exit.c:181:25: warning: initialized field overwritten [-Woverride-init]
     181 |  [ESR_ELx_EC_CP14_MR] = kvm_handle_cp14_32,
         |                         ^~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:181:25: note: (near initialization for 'arm_exit_handlers[5]')
   arch/arm64/kvm/handle_exit.c:182:25: warning: initialized field overwritten [-Woverride-init]
     182 |  [ESR_ELx_EC_CP14_LS] = kvm_handle_cp14_load_store,
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:182:25: note: (near initialization for 'arm_exit_handlers[6]')
   arch/arm64/kvm/handle_exit.c:183:25: warning: initialized field overwritten [-Woverride-init]
     183 |  [ESR_ELx_EC_CP14_64] = kvm_handle_cp14_64,
         |                         ^~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:183:25: note: (near initialization for 'arm_exit_handlers[12]')
   arch/arm64/kvm/handle_exit.c:184:23: warning: initialized field overwritten [-Woverride-init]
     184 |  [ESR_ELx_EC_HVC32] = handle_hvc,
         |                       ^~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:184:23: note: (near initialization for 'arm_exit_handlers[18]')
   arch/arm64/kvm/handle_exit.c:185:23: warning: initialized field overwritten [-Woverride-init]
     185 |  [ESR_ELx_EC_SMC32] = handle_smc,
         |                       ^~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:185:23: note: (near initialization for 'arm_exit_handlers[19]')
   arch/arm64/kvm/handle_exit.c:186:23: warning: initialized field overwritten [-Woverride-init]
     186 |  [ESR_ELx_EC_HVC64] = handle_hvc,
         |                       ^~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:186:23: note: (near initialization for 'arm_exit_handlers[22]')
   arch/arm64/kvm/handle_exit.c:187:23: warning: initialized field overwritten [-Woverride-init]
     187 |  [ESR_ELx_EC_SMC64] = handle_smc,
         |                       ^~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:187:23: note: (near initialization for 'arm_exit_handlers[23]')
   arch/arm64/kvm/handle_exit.c:188:23: warning: initialized field overwritten [-Woverride-init]
     188 |  [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg,
         |                       ^~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:188:23: note: (near initialization for 'arm_exit_handlers[24]')
   arch/arm64/kvm/handle_exit.c:189:21: warning: initialized field overwritten [-Woverride-init]
     189 |  [ESR_ELx_EC_SVE] = handle_sve,
         |                     ^~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:189:21: note: (near initialization for 'arm_exit_handlers[25]')
   arch/arm64/kvm/handle_exit.c:190:26: warning: initialized field overwritten [-Woverride-init]
     190 |  [ESR_ELx_EC_IABT_LOW] = kvm_handle_guest_abort,
         |                          ^~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:190:26: note: (near initialization for 'arm_exit_handlers[32]')
   arch/arm64/kvm/handle_exit.c:191:26: warning: initialized field overwritten [-Woverride-init]
     191 |  [ESR_ELx_EC_DABT_LOW] = kvm_handle_guest_abort,
         |                          ^~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:191:26: note: (near initialization for 'arm_exit_handlers[36]')
   arch/arm64/kvm/handle_exit.c:192:28: warning: initialized field overwritten [-Woverride-init]
     192 |  [ESR_ELx_EC_SOFTSTP_LOW]= kvm_handle_guest_debug,
         |                            ^~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:192:28: note: (near initialization for 'arm_exit_handlers[50]')
   arch/arm64/kvm/handle_exit.c:193:28: warning: initialized field overwritten [-Woverride-init]
     193 |  [ESR_ELx_EC_WATCHPT_LOW]= kvm_handle_guest_debug,
         |                            ^~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:193:28: note: (near initialization for 'arm_exit_handlers[52]')
   arch/arm64/kvm/handle_exit.c:194:28: warning: initialized field overwritten [-Woverride-init]
     194 |  [ESR_ELx_EC_BREAKPT_LOW]= kvm_handle_guest_debug,
         |                            ^~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:194:28: note: (near initialization for 'arm_exit_handlers[48]')
   arch/arm64/kvm/handle_exit.c:195:24: warning: initialized field overwritten [-Woverride-init]
     195 |  [ESR_ELx_EC_BKPT32] = kvm_handle_guest_debug,
         |                        ^~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:195:24: note: (near initialization for 'arm_exit_handlers[56]')
   arch/arm64/kvm/handle_exit.c:196:23: warning: initialized field overwritten [-Woverride-init]
     196 |  [ESR_ELx_EC_BRK64] = kvm_handle_guest_debug,
         |                       ^~~~~~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:196:23: note: (near initialization for 'arm_exit_handlers[60]')
   arch/arm64/kvm/handle_exit.c:197:26: warning: initialized field overwritten [-Woverride-init]
     197 |  [ESR_ELx_EC_FP_ASIMD] = handle_no_fpsimd,
         |                          ^~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:197:26: note: (near initialization for 'arm_exit_handlers[7]')
   arch/arm64/kvm/handle_exit.c:198:21: warning: initialized field overwritten [-Woverride-init]
     198 |  [ESR_ELx_EC_PAC] = kvm_handle_ptrauth,
         |                     ^~~~~~~~~~~~~~~~~~
   arch/arm64/kvm/handle_exit.c:198:21: note: (near initialization for 'arm_exit_handlers[9]')
--
   In file included from arch/arm64/kvm/reset.c:29:
   arch/arm64/include/asm/kvm_emulate.h: In function 'vcpu_reset_hcr':
>> arch/arm64/include/asm/kvm_emulate.h:84:25: error: 'HCR_ATA' undeclared (first use in this function); did you mean 'HCR_PTW'?
      84 |   vcpu->arch.hcr_el2 |= HCR_ATA;
         |                         ^~~~~~~
         |                         HCR_PTW
   arch/arm64/include/asm/kvm_emulate.h:84:25: note: each undeclared identifier is reported only once for each function it appears in
   arch/arm64/kvm/reset.c: In function 'kvm_reset_vcpu':
>> arch/arm64/kvm/reset.c:279:8: error: implicit declaration of function 'system_supports_mte'; did you mean 'system_supports_bti'? [-Werror=implicit-function-declaration]
     279 |   if (!system_supports_mte()) {
         |        ^~~~~~~~~~~~~~~~~~~
         |        system_supports_bti
   cc1: some warnings being treated as errors
--
   In file included from arch/arm64/kvm/sys_regs.c:24:
   arch/arm64/include/asm/kvm_emulate.h: In function 'vcpu_reset_hcr':
>> arch/arm64/include/asm/kvm_emulate.h:84:25: error: 'HCR_ATA' undeclared (first use in this function); did you mean 'HCR_PTW'?
      84 |   vcpu->arch.hcr_el2 |= HCR_ATA;
         |                         ^~~~~~~
         |                         HCR_PTW
   arch/arm64/include/asm/kvm_emulate.h:84:25: note: each undeclared identifier is reported only once for each function it appears in
   In file included from arch/arm64/kvm/sys_regs.c:32:
   arch/arm64/kvm/sys_regs.c: At top level:
   arch/arm64/kvm/sys_regs.c:1525:13: error: 'SYS_RGSR_EL1' undeclared here (not in a function); did you mean 'SYS_DISR_EL1'?
    1525 |  { SYS_DESC(SYS_RGSR_EL1), trap_raz_wi, reset_unknown, RGSR_EL1 },
         |             ^~~~~~~~~~~~
   arch/arm64/kvm/sys_regs.h:156:25: note: in definition of macro 'Op0'
     156 | #define Op0(_x)  .Op0 = _x
         |                         ^~
   arch/arm64/kvm/sys_regs.h:164:6: note: in expansion of macro 'sys_reg_Op0'
     164 |  Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
         |      ^~~~~~~~~~~
   arch/arm64/kvm/sys_regs.c:1525:4: note: in expansion of macro 'SYS_DESC'
    1525 |  { SYS_DESC(SYS_RGSR_EL1), trap_raz_wi, reset_unknown, RGSR_EL1 },
         |    ^~~~~~~~
   arch/arm64/kvm/sys_regs.c:1526:13: error: 'SYS_GCR_EL1' undeclared here (not in a function); did you mean 'SYS_TCR_EL1'?
    1526 |  { SYS_DESC(SYS_GCR_EL1), trap_raz_wi, reset_unknown, GCR_EL1 },
         |             ^~~~~~~~~~~
   arch/arm64/kvm/sys_regs.h:156:25: note: in definition of macro 'Op0'
     156 | #define Op0(_x)  .Op0 = _x
         |                         ^~
   arch/arm64/kvm/sys_regs.h:164:6: note: in expansion of macro 'sys_reg_Op0'
     164 |  Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
         |      ^~~~~~~~~~~
   arch/arm64/kvm/sys_regs.c:1526:4: note: in expansion of macro 'SYS_DESC'
    1526 |  { SYS_DESC(SYS_GCR_EL1), trap_raz_wi, reset_unknown, GCR_EL1 },
         |    ^~~~~~~~
   arch/arm64/kvm/sys_regs.c:1551:13: error: 'SYS_TFSR_EL1' undeclared here (not in a function); did you mean 'SYS_DISR_EL1'?
    1551 |  { SYS_DESC(SYS_TFSR_EL1), trap_raz_wi, reset_unknown, TFSR_EL1 },
         |             ^~~~~~~~~~~~
   arch/arm64/kvm/sys_regs.h:156:25: note: in definition of macro 'Op0'
     156 | #define Op0(_x)  .Op0 = _x
         |                         ^~
   arch/arm64/kvm/sys_regs.h:164:6: note: in expansion of macro 'sys_reg_Op0'
     164 |  Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
         |      ^~~~~~~~~~~
   arch/arm64/kvm/sys_regs.c:1551:4: note: in expansion of macro 'SYS_DESC'
    1551 |  { SYS_DESC(SYS_TFSR_EL1), trap_raz_wi, reset_unknown, TFSR_EL1 },
         |    ^~~~~~~~
   arch/arm64/kvm/sys_regs.c:1552:13: error: 'SYS_TFSRE0_EL1' undeclared here (not in a function); did you mean 'SYS_AFSR0_EL1'?
    1552 |  { SYS_DESC(SYS_TFSRE0_EL1), trap_raz_wi, reset_unknown, TFSRE0_EL1 },
         |             ^~~~~~~~~~~~~~
   arch/arm64/kvm/sys_regs.h:156:25: note: in definition of macro 'Op0'
     156 | #define Op0(_x)  .Op0 = _x
         |                         ^~
   arch/arm64/kvm/sys_regs.h:164:6: note: in expansion of macro 'sys_reg_Op0'
     164 |  Op0(sys_reg_Op0(reg)), Op1(sys_reg_Op1(reg)), \
         |      ^~~~~~~~~~~
   arch/arm64/kvm/sys_regs.c:1552:4: note: in expansion of macro 'SYS_DESC'
    1552 |  { SYS_DESC(SYS_TFSRE0_EL1), trap_raz_wi, reset_unknown, TFSRE0_EL1 },
         |    ^~~~~~~~
--
   In file included from arch/arm64/kvm/hyp/sysreg-sr.c:12:
   arch/arm64/include/asm/kvm_emulate.h: In function 'vcpu_reset_hcr':
>> arch/arm64/include/asm/kvm_emulate.h:84:25: error: 'HCR_ATA' undeclared (first use in this function); did you mean 'HCR_PTW'?
      84 |   vcpu->arch.hcr_el2 |= HCR_ATA;
         |                         ^~~~~~~
         |                         HCR_PTW
   arch/arm64/include/asm/kvm_emulate.h:84:25: note: each undeclared identifier is reported only once for each function it appears in
   arch/arm64/kvm/hyp/sysreg-sr.c: In function '__sysreg_save_common_state':
   arch/arm64/kvm/hyp/sysreg-sr.c:30:6: error: implicit declaration of function 'system_supports_mte'; did you mean 'system_supports_bti'? [-Werror=implicit-function-declaration]
      30 |  if (system_supports_mte()) {
         |      ^~~~~~~~~~~~~~~~~~~
         |      system_supports_bti
   cc1: some warnings being treated as errors
--
   In file included from arch/arm64/kvm/hyp/switch.c:19:
   arch/arm64/include/asm/kvm_emulate.h: In function 'vcpu_reset_hcr':
>> arch/arm64/include/asm/kvm_emulate.h:84:25: error: 'HCR_ATA' undeclared (first use in this function); did you mean 'HCR_PTW'?
      84 |   vcpu->arch.hcr_el2 |= HCR_ATA;
         |                         ^~~~~~~
         |                         HCR_PTW
   arch/arm64/include/asm/kvm_emulate.h:84:25: note: each undeclared identifier is reported only once for each function it appears in
   arch/arm64/kvm/hyp/switch.c: At top level:
   arch/arm64/kvm/hyp/switch.c:924:28: warning: no previous prototype for 'hyp_panic' [-Wmissing-prototypes]
     924 | void __hyp_text __noreturn hyp_panic(struct kvm_cpu_context *host_ctxt)
         |                            ^~~~~~~~~

vim +84 arch/arm64/include/asm/kvm_emulate.h

    43	
    44	static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)
    45	{
    46		vcpu->arch.hcr_el2 = HCR_GUEST_FLAGS;
    47		if (is_kernel_in_hyp_mode())
    48			vcpu->arch.hcr_el2 |= HCR_E2H;
    49		if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN)) {
    50			/* route synchronous external abort exceptions to EL2 */
    51			vcpu->arch.hcr_el2 |= HCR_TEA;
    52			/* trap error record accesses */
    53			vcpu->arch.hcr_el2 |= HCR_TERR;
    54		}
    55	
    56		if (cpus_have_const_cap(ARM64_HAS_STAGE2_FWB)) {
    57			vcpu->arch.hcr_el2 |= HCR_FWB;
    58		} else {
    59			/*
    60			 * For non-FWB CPUs, we trap VM ops (HCR_EL2.TVM) until M+C
    61			 * get set in SCTLR_EL1 such that we can detect when the guest
    62			 * MMU gets turned on and do the necessary cache maintenance
    63			 * then.
    64			 */
    65			vcpu->arch.hcr_el2 |= HCR_TVM;
    66		}
    67	
    68		if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features))
    69			vcpu->arch.hcr_el2 &= ~HCR_RW;
    70	
    71		/*
    72		 * TID3: trap feature register accesses that we virtualise.
    73		 * For now this is conditional, since no AArch32 feature regs
    74		 * are currently virtualised.
    75		 */
    76		if (!vcpu_el1_is_32bit(vcpu))
    77			vcpu->arch.hcr_el2 |= HCR_TID3;
    78	
    79		if (cpus_have_const_cap(ARM64_MISMATCHED_CACHE_TYPE) ||
    80		    vcpu_el1_is_32bit(vcpu))
    81			vcpu->arch.hcr_el2 |= HCR_TID2;
    82	
    83		if (test_bit(KVM_ARM_VCPU_MTE, vcpu->arch.features))
  > 84			vcpu->arch.hcr_el2 |= HCR_ATA;
    85	}
    86	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Patch
diff mbox series

diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 4d0f8ea600ba..1e4280f9a5ce 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 1fc306705193..586b250f683b 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/mmu.c b/arch/arm64/kvm/mmu.c
index 8c0035cab6b6..8d405701f534 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1940,6 +1940,21 @@  static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 	if (vma_pagesize == PAGE_SIZE && !force_pte)
 		vma_pagesize = transparent_hugepage_adjust(memslot, hva,
 							   &pfn, &fault_ipa);
+	if (system_supports_mte() && kvm->arch.vcpu_has_mte && pfn_valid(pfn)) {
+		/*
+		 * 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);
+		long i, nr_pages = compound_nr(page);
+
+		/* if PG_mte_tagged is set, tags have already been initialised */
+		for (i = 0; i < nr_pages; i++, page++) {
+			if (!test_and_set_bit(PG_mte_tagged, &page->flags))
+				mte_clear_page_tags(page_address(page));
+		}
+	}
+
 	if (writable)
 		kvm_set_pfn_dirty(pfn);
 
diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c
index 6ed36be51b4b..39fdd95441df 100644
--- a/arch/arm64/kvm/reset.c
+++ b/arch/arm64/kvm/reset.c
@@ -275,6 +275,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 5ca974c93bd4..0c3c577f98fe 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1105,7 +1105,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) |