MTE support for KVM guest
v6 cover MTE support for KVM guest
It's been a week, and I think the comments on v5 made it clear that enforcing PROT_MTE requirements on the VMM was probably the wrong approach. So since I've got swap working correctly without that I thought I'd post a v6 which hopefully addresses all the comments so far.
This series adds support for Arm's Memory Tagging Extension (MTE) to KVM, allowing KVM guests to make use of it. This builds on the existing user space support already in v5.10-rc4, see [1] for an overview.
[1] https://lwn.net/Articles/834289/
Changes since v5[2]:
* Revert back to not requiring the VMM to map all guest memory PROT_MTE. Instead KVM will set the PG_mte_tagged flag automatically if not present.
* Fixed swap behaviour vs v4 by always checking for saved MTE tags for user entries in set_pte_at().
[2] https://lore.kernel.org/r/20201119153901.53705-1-steven.price%40arm.com
Steven Price (2):
arm64: kvm: Save/restore MTE registers
arm64: kvm: Introduce MTE VCPU feature
arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 8 ++++++++ arch/arm64/include/asm/pgtable.h | 2 +- arch/arm64/include/asm/sysreg.h | 3 ++- arch/arm64/kernel/mte.c | 18 +++++++++++++----- arch/arm64/kvm/arm.c | 9 +++++++++ arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 14 ++++++++++++++ arch/arm64/kvm/mmu.c | 16 ++++++++++++++++ arch/arm64/kvm/sys_regs.c | 20 +++++++++++++++----- include/uapi/linux/kvm.h | 1 + 10 files changed, 82 insertions(+), 12 deletions(-)
Signature · 1 line
2.20.1
PATCH v6 1/2 arm64: kvm: Save/restore MTE registers
Define the new system registers that MTE introduces and context switch them. The MTE feature is still hidden from the ID register as it isn't supported in a VM yet.
--- arch/arm64/include/asm/kvm_host.h | 4 ++++ arch/arm64/include/asm/sysreg.h | 3 ++- arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 14 ++++++++++++++ arch/arm64/kvm/sys_regs.c | 14 ++++++++++---- 4 files changed, 30 insertions(+), 5 deletions(-)
arch/arm64/include/asm/kvm_host.h +4 -0
@@ -136,6 +136,8 @@ enum vcpu_sysreg {SCTLR_EL1 ,/* System Control Register */ ACTLR_EL1 ,/* Auxiliary Control Register */ CPACR_EL1 ,/* Coprocessor Access Control */ +RGSR_EL1 ,/* Random Allocation Tag Seed Register */ +GCR_EL1 ,/* Tag Control Register */ ZCR_EL1 ,/* SVE Control */ TTBR0_EL1 ,/* Translation Table Base Register 0 */ TTBR1_EL1, /* Translation Table Base Register 1 */
@@ -152,6 +154,8 @@ enum vcpu_sysreg {TPIDR_EL1 ,/* Thread ID, Privileged */ AMAIR_EL1 ,/* Aux Memory Attribute Indirection Register */ CNTKCTL_EL1 ,/* Timer Control Register (EL1) */ +TFSRE0_EL1 ,/* Tag Fault Status Register (EL0) */ +TFSR_EL1 ,/* Tag Fault Stauts Register (EL1) */ PAR_EL1 ,/* Physical Address Register */ MDSCR_EL1 ,/* Monitor Debug System Control Register */ MDCCINT_EL1, /* Monitor Debug Comms Channel Interrupt Enable Reg */
arch/arm64/include/asm/sysreg.h +2 -1
@@ -569,7 +569,8 @@#define SCTLR_ELx_M (BIT(0))#define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ - SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB) + SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB | \ + SCTLR_ELx_ITFSB)/* SCTLR_EL2 specific flags. */ #define SCTLR_EL2_RES1 ((BIT(4)) | (BIT(5)) | (BIT(11)) | (BIT(16)) | \
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +14 -0
@@ -18,6 +18,11 @@static inline void __sysreg_save_common_state (struct kvm_cpu_context *ctxt) {ctxt_sys_reg (ctxt,MDSCR_EL1 ) =read_sysreg (mdscr_el1); +if (system_supports_mte ()) { +ctxt_sys_reg (ctxt,RGSR_EL1 ) =read_sysreg_s (SYS_RGSR_EL1 ); +ctxt_sys_reg (ctxt,GCR_EL1 ) =read_sysreg_s (SYS_GCR_EL1 ); +ctxt_sys_reg (ctxt,TFSRE0_EL1 ) =read_sysreg_s (SYS_TFSRE0_EL1 ); + } }static inline void __sysreg_save_user_state (struct kvm_cpu_context *ctxt)
@@ -45,6 +50,8 @@ static inline void __sysreg_save_el1_state(struct kvm_cpu_context *ctxt)ctxt_sys_reg (ctxt,CNTKCTL_EL1 ) =read_sysreg_el1 (SYS_CNTKCTL );ctxt_sys_reg (ctxt,PAR_EL1 ) =read_sysreg_par ();ctxt_sys_reg (ctxt,TPIDR_EL1 ) =read_sysreg (tpidr_el1); +if (system_supports_mte ()) +ctxt_sys_reg (ctxt,TFSR_EL1 ) =read_sysreg_el1 (SYS_TFSR );ctxt_sys_reg (ctxt,SP_EL1 ) =read_sysreg (sp_el1);ctxt_sys_reg (ctxt,ELR_EL1 ) =read_sysreg_el1 (SYS_ELR );
@@ -63,6 +70,11 @@ static inline void __sysreg_save_el2_return_state(struct kvm_cpu_context *ctxt)static inline void __sysreg_restore_common_state (struct kvm_cpu_context *ctxt) {write_sysreg (ctxt_sys_reg (ctxt,MDSCR_EL1 ), mdscr_el1); +if (system_supports_mte ()) { +write_sysreg_s (ctxt_sys_reg (ctxt,RGSR_EL1 ),SYS_RGSR_EL1 ); +write_sysreg_s (ctxt_sys_reg (ctxt,GCR_EL1 ),SYS_GCR_EL1 ); +write_sysreg_s (ctxt_sys_reg (ctxt,TFSRE0_EL1 ),SYS_TFSRE0_EL1 ); + } }static inline void __sysreg_restore_user_state (struct kvm_cpu_context *ctxt)
@@ -106,6 +118,8 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt)write_sysreg_el1 (ctxt_sys_reg (ctxt,CNTKCTL_EL1 ),SYS_CNTKCTL );write_sysreg (ctxt_sys_reg (ctxt,PAR_EL1 ), par_el1);write_sysreg (ctxt_sys_reg (ctxt,TPIDR_EL1 ), tpidr_el1); +if (system_supports_mte ()) +write_sysreg_el1 (ctxt_sys_reg (ctxt,TFSR_EL1 ),SYS_TFSR ); if (!has_vhe() && cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT) &&
arch/arm64/kvm/sys_regs.c +10 -4
@@ -1366,6 +1366,12 @@ static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,return true; } +static unsigned int mte_visibility (const struct kvm_vcpu *vcpu, +const struct sys_reg_desc *rd) +{ +return REG_HIDDEN ; +} +/* sys_reg_desc initialiser for known cpufeature ID registers */ #define ID_SANITISED (name) { \ SYS_DESC(SYS_##name), \
@@ -1534,8 +1540,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_ACTLR_EL1), access_actlr, reset_actlr, ACTLR_EL1 }, { SYS_DESC(SYS_CPACR_EL1), NULL, reset_val, CPACR_EL1, 0 }, - { SYS_DESC(SYS_RGSR_EL1), undef_access }, - { SYS_DESC(SYS_GCR_EL1), undef_access }, + { SYS_DESC(SYS_RGSR_EL1), undef_access, reset_unknown, RGSR_EL1, .visibility = mte_visibility }, + { SYS_DESC(SYS_GCR_EL1), undef_access, reset_unknown, GCR_EL1, .visibility = mte_visibility }, { SYS_DESC(SYS_ZCR_EL1), NULL, reset_val, ZCR_EL1, 0, .visibility = sve_visibility }, { SYS_DESC(SYS_TTBR0_EL1), access_vm_reg, reset_unknown, TTBR0_EL1 },
@@ -1561,8 +1567,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SYS_DESC(SYS_ERXMISC0_EL1), trap_raz_wi }, { SYS_DESC(SYS_ERXMISC1_EL1), trap_raz_wi }, - { SYS_DESC(SYS_TFSR_EL1), undef_access }, - { SYS_DESC(SYS_TFSRE0_EL1), undef_access }, + { SYS_DESC(SYS_TFSR_EL1), undef_access, reset_unknown, TFSR_EL1, .visibility = mte_visibility }, + { SYS_DESC(SYS_TFSRE0_EL1), undef_access, reset_unknown, TFSRE0_EL1, .visibility = mte_visibility }, { SYS_DESC(SYS_FAR_EL1), access_vm_reg, reset_unknown, FAR_EL1 }, { SYS_DESC(SYS_PAR_EL1), NULL, reset_unknown, PAR_EL1 },
Signature · 6 lines
2.20.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerRe: [PATCH v6 1/2] arm64: kvm: Save/restore MTE registers
Quoted 22 lines
arch/arm64/include/asm/sysreg.h +2
-1@@ -569,7 +569,8 @@#define SCTLR_ELx_M (BIT(0))#define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ - SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB) + SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB | \ + SCTLR_ELx_ITFSB)/* SCTLR_EL2 specific flags. */ #define SCTLR_EL2_RES1 ((BIT(4)) | (BIT(5)) | (BIT(11)) | (BIT(16))| \
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +0
-0
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h line 22
Quoted 5 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +1
-0@@ -18,6 +18,11 @@static inline void __sysreg_save_common_state (struct kvm_cpu_context *ctxt) {ctxt_sys_reg (ctxt,MDSCR_EL1 ) =read_sysreg (mdscr_el1); +if (system_supports_mte ()) {
Please move the per-VM predicate to this patch so that it can be used not to save/restore the MTE registers if we don't need to.
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h line 25
Quoted 4 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +4
-0+ctxt_sys_reg (ctxt,RGSR_EL1 ) =read_sysreg_s (SYS_RGSR_EL1 ); +ctxt_sys_reg (ctxt,GCR_EL1 ) =read_sysreg_s (SYS_GCR_EL1 ); +ctxt_sys_reg (ctxt,TFSRE0_EL1 ) =read_sysreg_s (SYS_TFSRE0_EL1 ); + }
Overall, I still don't understand how this is going to work once we have MTE in the kernel. You mentioned having the ability to create turn off the tag checks at times, but I don't see that in this patch (and I'm not sure we want that either).
Thanks,
M.
Signature · 5 lines
Jazz is not dead. It just smells funny... _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH v6 1/2] arm64: kvm: Save/restore MTE registers
Quoted 13 lines · Marc Zyngier
Quoted 13 lines
arch/arm64/include/asm/sysreg.h +2
-1@@ -569,7 +569,8 @@ #define SCTLR_ELx_M (BIT(0)) #define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ - SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB) + SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB | \ + SCTLR_ELx_ITFSB)
Quoted 15 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h line 21
Quoted 12 lines
arch/arm64/include/asm/sysreg.h +0
-0/* SCTLR_EL2 specific flags. */ #define SCTLR_EL2_RES1 ((BIT(4)) | (BIT(5)) | (BIT(11)) | (BIT(16)) | \arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +1
-0@@ -18,6 +18,11 @@ static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, MDSCR_EL1) = read_sysreg(mdscr_el1); + if (system_supports_mte()) {Please move the per-VM predicate to this patch so that it can be used not to save/restore the MTE registers if we don't need to.
There isn't a valid struct kvm_vcpu or struct kvm here. I know there's ctx->__hyp_running_vcpu but AFAICT that is only valid with the host context.
Quoted 11 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h line 25
Quoted 6 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +4
-0+ ctxt_sys_reg(ctxt, RGSR_EL1) = read_sysreg_s(SYS_RGSR_EL1); + ctxt_sys_reg(ctxt, GCR_EL1) = read_sysreg_s(SYS_GCR_EL1); + ctxt_sys_reg(ctxt, TFSRE0_EL1) =read_sysreg_s (SYS_TFSRE0_EL1 ); + }Overall, I still don't understand how this is going to work once we have MTE in the kernel. You mentioned having the ability to create turn off the tag checks at times, but I don't see that in this patch (and I'm not sure we want that either).
Given that this is now highly unlikely to be merged for v5.11, I'll rebase onto of the KASAN MTE series and double check exactly what happens. My thought was that it should be as simple as setting TCO, but your previous comment about moving the save/restore into assembler might be wise in case the compiler starts playing with TCO itself.
Steve
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerRe: [PATCH v6 1/2] arm64: kvm: Save/restore MTE registers
Quoted 30 lines · Steven Price
Quoted 13 lines · Marc Zyngier
Quoted 13 lines
arch/arm64/include/asm/sysreg.h +2
-1@@ -569,7 +569,8 @@ #define SCTLR_ELx_M (BIT(0)) #define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ - SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB) + SCTLR_ELx_SA | SCTLR_ELx_I | SCTLR_ELx_IESB | \ + SCTLR_ELx_ITFSB)Quoted 15 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h line 21
Quoted 12 lines
arch/arm64/include/asm/sysreg.h +0
-0/* SCTLR_EL2 specific flags. */ #define SCTLR_EL2_RES1 ((BIT(4)) | (BIT(5)) | (BIT(11)) | (BIT(16)) | \arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +1
-0@@ -18,6 +18,11 @@ static inline void __sysreg_save_common_state(struct kvm_cpu_context *ctxt) { ctxt_sys_reg(ctxt, MDSCR_EL1) = read_sysreg(mdscr_el1); + if (system_supports_mte()) {Please move the per-VM predicate to this patch so that it can be used not to save/restore the MTE registers if we don't need to.
Quoted 3 lines
There isn't a valid struct
kvm_vcpuor struct kvm here. I know there'sctx->__hyp_running_vcpubut AFAICT that is only valid with the host context.
We have per-CPU variables for the host context. If ctx->__hyp_running_vcpu is non NULL, you know you're on the host.
Quoted 14 lines
Quoted 9 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h line 27
Quoted 8 lines
arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h +4
-0+ ctxt_sys_reg(ctxt, RGSR_EL1) =read_sysreg_s (SYS_RGSR_EL1 ); + ctxt_sys_reg(ctxt, GCR_EL1) = read_sysreg_s(SYS_GCR_EL1); + ctxt_sys_reg(ctxt, TFSRE0_EL1) =read_sysreg_s (SYS_TFSRE0_EL1 ); + }Quoted 4 lines
Overall, I still don't understand how this is going to work once we have MTE in the kernel. You mentioned having the ability to create turn off the tag checks at times, but I don't see that in this patch (and I'm not sure we want that either).
Quoted 5 lines
Given that this is now highly unlikely to be merged for v5.11, I'll rebase onto of the KASAN MTE series and double check exactly what happens. My thought was that it should be as simple as setting TCO, but your previous comment about moving the save/restore into assembler might be wise in case the compiler starts playing with TCO itself.
Indeed.
Thanks,
M.
Signature · 5 lines
Jazz is not dead. It just smells funny... _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v6 2/2 arm64: kvm: Introduce MTE VCPU feature
In reply to Steven PriceAdd a new VM feature 'KVM_ARM_CAP_MTE' which enables memory tagging for a VM. This exposes the feature to the guest and automatically tags memory pages touched by the VM as PG_mte_tagged (and clears the tags storage) to ensure that the guest cannot see stale tags, and so that the tags are correctly saved/restored across swap.
--- arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 4 ++++ arch/arm64/include/asm/pgtable.h | 2 +- arch/arm64/kernel/mte.c | 18 +++++++++++++----- arch/arm64/kvm/arm.c | 9 +++++++++ arch/arm64/kvm/mmu.c | 16 ++++++++++++++++ arch/arm64/kvm/sys_regs.c | 6 +++++- include/uapi/linux/kvm.h | 1 + 8 files changed, 52 insertions(+), 7 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +3 -0
@@ -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 (kvm_has_mte (vcpu->kvm)) + vcpu->arch.hcr_el2 |=HCR_ATA ; }static inline unsigned long *vcpu_hcr (struct kvm_vcpu *vcpu)
arch/arm64/include/asm/kvm_host.h +4 -0
@@ -120,6 +120,8 @@ struct kvm_arch {unsigned int pmuver;u8 pfr0_csv2; +/* Memory Tagging Extension enabled for the guest */ +bool mte_enabled; };struct kvm_vcpu_fault_info {
@@ -658,4 +660,6 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu);#define kvm_arm_vcpu_sve_finalized (vcpu) \ ((vcpu)->arch.flags & KVM_ARM64_VCPU_SVE_FINALIZED) +#define kvm_has_mte (kvm) (system_supports_mte() && (kvm)->arch.mte_enabled) +#endif /* __ARM64_KVM_HOST_H__ */
arch/arm64/include/asm/pgtable.h +1 -1
@@ -304,7 +304,7 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,__sync_icache_dcache (pte);if (system_supports_mte () && -pte_present (pte) &&pte_tagged (pte) && !pte_special (pte)) +pte_present (pte) &&pte_valid_user (pte) && !pte_special (pte))mte_sync_tags (ptep, pte);__check_racy_pte_update (mm, ptep, pte);
arch/arm64/kernel/mte.c +13 -5
@@ -20,18 +20,24 @@#include <asm/ptrace.h> #include <asm/sysreg.h> -static void mte_sync_page_tags (struct page *page,pte_t *ptep,bool check_swap) +static void mte_sync_page_tags (struct page *page,pte_t *ptep,bool check_swap, +bool pte_is_tagged) {pte_t old_pte =READ_ONCE (*ptep);if (check_swap &&is_swap_pte (old_pte)) {swp_entry_t entry =pte_to_swp_entry (old_pte); -if (!non_swap_entry (entry) &&mte_restore_tags (entry, page)) +if (!non_swap_entry (entry) &&mte_restore_tags (entry, page)) { +set_bit (PG_mte_tagged, &page->flags);return ; + } } -mte_clear_page_tags (page_address (page)); +if (pte_is_tagged) { +set_bit (PG_mte_tagged, &page->flags); +mte_clear_page_tags (page_address (page)); + } }void mte_sync_tags (pte_t *ptep,pte_t pte)
@@ -39,11 +45,13 @@ void mte_sync_tags(pte_t *ptep, pte_t pte)struct page *page =pte_page (pte);long i, nr_pages =compound_nr (page);bool check_swap = nr_pages ==1 ; +bool pte_is_tagged =pte_tagged (pte);/* 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_sync_page_tags (page, ptep, check_swap); +if (!test_bit (PG_mte_tagged, &page->flags)) +mte_sync_page_tags (page, ptep, check_swap, + pte_is_tagged); } }
arch/arm64/kvm/arm.c +9 -0
@@ -89,6 +89,12 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, r =0 ; kvm->arch.return_nisv_io_abort_to_user = true;break ; +case KVM_CAP_ARM_MTE : +if (!system_supports_mte () || kvm->created_vcpus) +return -EINVAL ; + r =0 ; + kvm->arch.mte_enabled = true; +break ;default : r = -EINVAL ;break ;
@@ -226,6 +232,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)*/ r =1 ;break ; +case KVM_CAP_ARM_MTE : + r =system_supports_mte (); +break ;case KVM_CAP_STEAL_TIME : r =kvm_arm_pvtime_supported ();break ;
arch/arm64/kvm/mmu.c +16 -0
@@ -877,6 +877,22 @@ 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 (kvm_has_mte (kvm) &&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) { prot |=KVM_PGTABLE_PROT_W ;kvm_set_pfn_dirty (pfn);
arch/arm64/kvm/sys_regs.c +5 -1
@@ -1123,7 +1123,8 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu, val &= ~(0xfUL <<ID_AA64PFR0_CSV2_SHIFT ); val |= ((u64 )vcpu->kvm->arch.pfr0_csv2 <<ID_AA64PFR0_CSV2_SHIFT ); }else if (id ==SYS_ID_AA64PFR1_EL1 ) { - val &= ~(0xfUL <<ID_AA64PFR1_MTE_SHIFT ); +if (!kvm_has_mte (vcpu->kvm)) + 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) |
@@ -1369,6 +1370,9 @@ static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,static unsigned int mte_visibility (const struct kvm_vcpu *vcpu,const struct sys_reg_desc *rd) { +if (kvm_has_mte (vcpu->kvm)) +return 0 ; +return REG_HIDDEN ; }
include/uapi/linux/kvm.h +1 -0
@@ -1053,6 +1053,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_X86_USER_SPACE_MSR 188#define KVM_CAP_X86_MSR_FILTER 189#define KVM_CAP_ENFORCE_PV_FEATURE_CPUID 190 +#define KVM_CAP_ARM_MTE 191#ifdef KVM_CAP_IRQ_ROUTING
Signature · 6 lines
2.20.1 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Mark Rutland
reviewerQuoted 9 lines · Steven Price
It's been a week, and I think the comments on v5 made it clear that enforcing
PROT_MTErequirements on the VMM was probably the wrong approach. So since I've got swap working correctly without that I thought I'd post a v6 which hopefully addresses all the comments so far.This series adds support for Arm's Memory Tagging Extension (MTE) to KVM, allowing KVM guests to make use of it. This builds on the existing user space support already in v5.10-rc4, see [1] for an overview.
Quoted 11 lines
arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 8 ++++++++ arch/arm64/include/asm/pgtable.h | 2 +- arch/arm64/include/asm/sysreg.h | 3 ++- arch/arm64/kernel/mte.c | 18 +++++++++++++----- arch/arm64/kvm/arm.c | 9 +++++++++ arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 14 ++++++++++++++ arch/arm64/kvm/mmu.c | 16 ++++++++++++++++ arch/arm64/kvm/sys_regs.c | 20 +++++++++++++++----- include/uapi/linux/kvm.h | 1 + 10 files changed, 82 insertions(+), 12 deletions(-)
I note that doesn't fixup arch/arm64/kvm/inject_fault.c, where in enter_exception64() we have:
| // TODO: TCO (if/when ARMv8.5-MemTag is exposed to guests)
... and IIUC when MTE is present, TCO should be set when delivering an exception, so I believe that needs to be updated to set TCO.
Given that MTE-capable HW does that unconditionally, this is going to be a mess for big.LITTLE. :/
Thanks,
Mark.
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 22 lines · Mark Rutland
Quoted 9 lines · Steven Price
It's been a week, and I think the comments on v5 made it clear that enforcing
PROT_MTErequirements on the VMM was probably the wrong approach. So since I've got swap working correctly without that I thought I'd post a v6 which hopefully addresses all the comments so far.This series adds support for Arm's Memory Tagging Extension (MTE) to KVM, allowing KVM guests to make use of it. This builds on the existing user space support already in v5.10-rc4, see [1] for an overview.
Quoted 11 lines
arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 8 ++++++++ arch/arm64/include/asm/pgtable.h | 2 +- arch/arm64/include/asm/sysreg.h | 3 ++- arch/arm64/kernel/mte.c | 18 +++++++++++++----- arch/arm64/kvm/arm.c | 9 +++++++++ arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 14 ++++++++++++++ arch/arm64/kvm/mmu.c | 16 ++++++++++++++++ arch/arm64/kvm/sys_regs.c | 20 +++++++++++++++----- include/uapi/linux/kvm.h | 1 + 10 files changed, 82 insertions(+), 12 deletions(-)
Quoted 7 lines
I note that doesn't fixup
arch/arm64/kvm/inject_fault.c, where inenter_exception64()we have:| // TODO: TCO (if/when ARMv8.5-MemTag is exposed to guests)
... and IIUC when MTE is present, TCO should be set when delivering an exception, so I believe that needs to be updated to set TCO.
Well spotted! As you say TCO should be set when delivering an exception, so we need the following:
- // TODO: TCO (if/when ARMv8.5-MemTag is exposed to guests)
+ if (kvm_has_mte(vcpu->kvm))
+ new |= PSR_TCO_BIT;
Quoted 2 lines
Given that MTE-capable HW does that unconditionally, this is going to be a mess for big.LITTLE. :/
I'm not sure I follow. Either all CPUs support MTE in which this isn't a problem, or the MTE feature just isn't exposed. We don't support a mix of MTE and non-MTE CPUs. There are several aspects of MTE which effective mean it's an all-or-nothing feature for the system.
Thanks,
Steve
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Mark Rutland
reviewerQuoted 34 lines · Steven Price
Quoted 22 lines · Mark Rutland
Quoted 9 lines · Steven Price
It's been a week, and I think the comments on v5 made it clear that enforcing
PROT_MTErequirements on the VMM was probably the wrong approach. So since I've got swap working correctly without that I thought I'd post a v6 which hopefully addresses all the comments so far.This series adds support for Arm's Memory Tagging Extension (MTE) to KVM, allowing KVM guests to make use of it. This builds on the existing user space support already in v5.10-rc4, see [1] for an overview.
Quoted 11 lines
arch/arm64/include/asm/kvm_emulate.h | 3 +++ arch/arm64/include/asm/kvm_host.h | 8 ++++++++ arch/arm64/include/asm/pgtable.h | 2 +- arch/arm64/include/asm/sysreg.h | 3 ++- arch/arm64/kernel/mte.c | 18 +++++++++++++----- arch/arm64/kvm/arm.c | 9 +++++++++ arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 14 ++++++++++++++ arch/arm64/kvm/mmu.c | 16 ++++++++++++++++ arch/arm64/kvm/sys_regs.c | 20 +++++++++++++++----- include/uapi/linux/kvm.h | 1 + 10 files changed, 82 insertions(+), 12 deletions(-)Quoted 7 lines
I note that doesn't fixup
arch/arm64/kvm/inject_fault.c, where inenter_exception64()we have:| // TODO: TCO (if/when ARMv8.5-MemTag is exposed to guests)
... and IIUC when MTE is present, TCO should be set when delivering an exception, so I believe that needs to be updated to set TCO.
Well spotted! As you say TCO should be set when delivering an exception, so we need the following:
Review
Quoted 3 lines
(quoted diff) +2
-1- // TODO: TCO (if/when ARMv8.5-MemTag is exposed to guests) + if (kvm_has_mte(vcpu->kvm)) + new |= PSR_TCO_BIT;
Something of that sort, yes.
It'd be worth a look for any mention of TCO or MTE in case there are other bits that need a fixup.
Quoted 7 lines
Quoted 2 lines
Given that MTE-capable HW does that unconditionally, this is going to be a mess for big.LITTLE. :/
I'm not sure I follow. Either all CPUs support MTE in which this isn't a problem, or the MTE feature just isn't exposed. We don't support a mix of MTE and non-MTE CPUs. There are several aspects of MTE which effective mean it's an all-or-nothing feature for the system.
So long as the host requires uniform MTE support, I agree that's not a problem.
The fun is that the CPUs themselves will set TCO upon a real exception regardless of whether the host is aware, and on a mismatched system some CPUs will do that while others will not. In such a case the host and guest will end up seeing the SPSR TCO bit set sometimes upon exceptions from EL1 or EL2, and I hope that MTE-unaware CPUs ignore the bit upon ERET, or we're going to have significant problems.
Thanks,
Mark.
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm