KVM/arm64 fixes for 5.10, take #2
Subsystems (4)
Marc Zyngier
maintainerHi Paolo,
Here's the second set of fixes for 5.10. A compilation fix for non-48bit VA builds and a live migration regressions are on the menu this time. I have another set of regression fixes brewing, but in the meantime this will fit nicely in mainline.
Please pull,
M.
The following changes since commit 22f553842b14a1289c088a79a67fb479d3fa2a4e:
KVM: arm64: Handle Asymmetric AArch32 systems (2020-10-30 16:06:22 +0000)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-5.10-2
for you to fetch changes up to c512298eed0360923d0cbc4a1f30bc0509af0d50:
KVM: arm64: Remove AA64ZFR0_EL1 accessors (2020-11-06 16:00:29 +0000)
----------------------------------------------------------------
KVM/arm64 fixes for v5.10, take #2
- Fix compilation error when PMD and PUD are folded
- Fix regresssion of the RAZ behaviour of ID_AA64ZFR0_EL1
----------------------------------------------------------------
Andrew Jones (4):
KVM: arm64: Don't hide ID registers from userspace
KVM: arm64: Consolidate REG_HIDDEN_GUEST/USER
KVM: arm64: Check RAZ visibility in ID register accessors
KVM: arm64: Remove AA64ZFR0_EL1 accessors
Gavin Shan (1):
KVM: arm64: Fix build error in user_mem_abort()
arch/arm64/kvm/mmu.c | 2 + arch/arm64/kvm/sys_regs.c | 108 ++++++++++++++-------------------------------- arch/arm64/kvm/sys_regs.h | 16 +++---- 3 files changed, 43 insertions(+), 83 deletions(-)
Marc Zyngier
maintainerPATCH 1/5 KVM: arm64: Fix build error in user_mem_abort()
From: Gavin Shan <[email protected]>
The PUD and PMD are folded into PGD when the following options are enabled. In that case, PUD_SHIFT is equal to PMD_SHIFT and we fail to build with the indicated errors:
CONFIG_ARM64_VA_BITS_42=y
CONFIG_ARM64_PAGE_SHIFT=16
CONFIG_PGTABLE_LEVELS=3
arch/arm64/kvm/mmu.c: In function ‘user_mem_abort’:
arch/arm64/kvm/mmu.c:798:2: error: duplicate case value
case PMD_SHIFT:
^~~~
arch/arm64/kvm/mmu.c:791:2: note: previously used here
case PUD_SHIFT:
^~~~This fixes the issue by skipping the check on PUD huge page when PUD and PMD are folded into PGD.
--- arch/arm64/kvm/mmu.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kvm/mmu.c +2 -0
@@ -788,10 +788,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, }switch (vma_shift) { +#ifndef __PAGETABLE_PMD_FOLDEDcase PUD_SHIFT :if (fault_supports_stage2_huge_mapping (memslot, hva,PUD_SIZE ))break ; fallthrough; +#endif case CONT_PMD_SHIFT : vma_shift =PMD_SHIFT ; fallthrough;
Signature · 1 line
2.28.0
Marc Zyngier
maintainerPATCH 2/5 KVM: arm64: Don't hide ID registers from userspace
In reply to Marc ZyngierFrom: Andrew Jones <[email protected]>
ID registers are RAZ until they've been allocated a purpose, but that doesn't mean they should be removed from the KVM_GET_REG_LIST list. So far we only have one register, SYS_ID_AA64ZFR0_EL1, that is hidden from userspace when its function, SVE, is not present.
Expose SYS_ID_AA64ZFR0_EL1 to userspace as RAZ when SVE is not implemented. Removing the userspace visibility checks is enough to reexpose it, as it will already return zero to userspace when SVE is not present. The register already behaves as RAZ for the guest when SVE is not present.
--- arch/arm64/kvm/sys_regs.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
arch/arm64/kvm/sys_regs.c +1 -17
@@ -1193,16 +1193,6 @@ static unsigned int sve_visibility(const struct kvm_vcpu *vcpu,return REG_HIDDEN_USER |REG_HIDDEN_GUEST ; } -/* Visibility overrides for SVE-specific ID registers */ -static unsigned int sve_id_visibility (const struct kvm_vcpu *vcpu, -const struct sys_reg_desc *rd) -{ -if (vcpu_has_sve (vcpu)) -return 0 ; - -return REG_HIDDEN_USER ; -} -/* Generate the emulated ID_AA64ZFR0_EL1 value exposed to the guest */ static u64 guest_id_aa64zfr0_el1 (const struct kvm_vcpu *vcpu) {
@@ -1229,9 +1219,6 @@ static int get_id_aa64zfr0_el1(struct kvm_vcpu *vcpu, {u64 val; -if (WARN_ON (!vcpu_has_sve (vcpu))) -return -ENOENT ; - val =guest_id_aa64zfr0_el1 (vcpu);return reg_to_user (uaddr, &val, reg->id); }
@@ -1244,9 +1231,6 @@ static int set_id_aa64zfr0_el1(struct kvm_vcpu *vcpu,int err;u64 val; -if (WARN_ON (!vcpu_has_sve (vcpu))) -return -ENOENT ; - err =reg_from_user (&val, uaddr, id);if (err)return err;
@@ -1509,7 +1493,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {ID_SANITISED (ID_AA64PFR1_EL1 ),ID_UNALLOCATED (4 ,2 ),ID_UNALLOCATED (4 ,3 ), - { SYS_DESC(SYS_ID_AA64ZFR0_EL1), access_id_aa64zfr0_el1, .get_user = get_id_aa64zfr0_el1, .set_user = set_id_aa64zfr0_el1, .visibility = sve_id_visibility }, + { SYS_DESC(SYS_ID_AA64ZFR0_EL1), access_id_aa64zfr0_el1, .get_user = get_id_aa64zfr0_el1, .set_user = set_id_aa64zfr0_el1, },ID_UNALLOCATED (4 ,5 ),ID_UNALLOCATED (4 ,6 ), ID_UNALLOCATED(4,7),
Signature · 1 line
2.28.0
Marc Zyngier
maintainerPATCH 3/5 KVM: arm64: Consolidate REG_HIDDEN_GUEST/USER
In reply to Marc ZyngierFrom: Andrew Jones <[email protected]>
REG_HIDDEN_GUEST and REG_HIDDEN_USER are always used together. Consolidate them into a single REG_HIDDEN flag. We can always add another flag later if some register needs to expose itself differently to the guest than it does to userspace.
No functional change intended.
--- arch/arm64/kvm/sys_regs.c | 12 ++++++------ arch/arm64/kvm/sys_regs.h | 18 ++++-------------- 2 files changed, 10 insertions(+), 20 deletions(-)
arch/arm64/kvm/sys_regs.c +6 -6
@@ -1069,7 +1069,7 @@ static bool trap_ptrauth(struct kvm_vcpu *vcpu,static unsigned int ptrauth_visibility (const struct kvm_vcpu *vcpu,const struct sys_reg_desc *rd) { -return vcpu_has_ptrauth (vcpu) ?0 :REG_HIDDEN_USER |REG_HIDDEN_GUEST ; +return vcpu_has_ptrauth (vcpu) ?0 :REG_HIDDEN ; }#define __PTRAUTH_KEY (k) \
@@ -1190,7 +1190,7 @@ static unsigned int sve_visibility(const struct kvm_vcpu *vcpu,if (vcpu_has_sve (vcpu))return 0 ; -return REG_HIDDEN_USER |REG_HIDDEN_GUEST ; +return REG_HIDDEN ; }/* Generate the emulated ID_AA64ZFR0_EL1 value exposed to the guest */
@@ -2153,7 +2153,7 @@ static void perform_access(struct kvm_vcpu *vcpu,trace_kvm_sys_access (*vcpu_pc (vcpu), params, r);/* Check for regs disabled by runtime config */ -if (sysreg_hidden_from_guest (vcpu, r)) { +if (sysreg_hidden (vcpu, r)) {kvm_inject_undefined (vcpu);return ; }
@@ -2652,7 +2652,7 @@ int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *regreturn get_invariant_sys_reg (reg->id, uaddr);/* Check for regs disabled by runtime config */ -if (sysreg_hidden_from_user (vcpu, r)) +if (sysreg_hidden (vcpu, r))return -ENOENT ;if (r->get_user)
@@ -2677,7 +2677,7 @@ int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *regreturn set_invariant_sys_reg (reg->id, uaddr);/* Check for regs disabled by runtime config */ -if (sysreg_hidden_from_user (vcpu, r)) +if (sysreg_hidden (vcpu, r))return -ENOENT ;if (r->set_user)
@@ -2748,7 +2748,7 @@ static int walk_one_sys_reg(const struct kvm_vcpu *vcpu,if (!(rd->reg || rd->get_user))return 0 ; -if (sysreg_hidden_from_user (vcpu, rd)) +if (sysreg_hidden (vcpu, rd))return 0 ;if (!copy_reg_to_user (rd, uind))
arch/arm64/kvm/sys_regs.h +4 -14
@@ -59,8 +59,7 @@ struct sys_reg_desc { const struct sys_reg_desc *rd); }; -#define REG_HIDDEN_USER (1 << 0)/* hidden from userspace ioctls */ -#define REG_HIDDEN_GUEST (1 << 1)/* hidden from guest */ +#define REG_HIDDEN (1 << 0)/* hidden from userspace and guest */ static __printf(2, 3) inline void print_sys_reg_msg(const struct sys_reg_params *p,
@@ -111,22 +110,13 @@ static inline void reset_val(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r__vcpu_sys_reg (vcpu, r->reg) = r->val; } -static inline bool sysreg_hidden_from_guest (const struct kvm_vcpu *vcpu, -const struct sys_reg_desc *r) -{ -if (likely (!r->visibility)) -return false; - -return r->visibility (vcpu, r) ®_HIDDEN_GUEST ; -} - -static inline bool sysreg_hidden_from_user (const struct kvm_vcpu *vcpu, -const struct sys_reg_desc *r) +static inline bool sysreg_hidden (const struct kvm_vcpu *vcpu, +const struct sys_reg_desc *r) {if (likely (!r->visibility))return false; -return r->visibility (vcpu, r) ®_HIDDEN_USER ; +return r->visibility (vcpu, r) ®_HIDDEN ; } static inline int cmp_sys_reg(const struct sys_reg_desc *i1,
Signature · 1 line
2.28.0
Marc Zyngier
maintainerPATCH 4/5 KVM: arm64: Check RAZ visibility in ID register accessors
In reply to Marc ZyngierFrom: Andrew Jones <[email protected]>
The instruction encodings of ID registers are preallocated. Until an encoding is assigned a purpose the register is RAZ. KVM's general ID register accessor functions already support both paths, RAZ or not. If for each ID register we can determine if it's RAZ or not, then all ID registers can build on the general functions. The register visibility function allows us to check whether a register should be completely hidden or not, extending it to also report when the register should be RAZ or not allows us to use it for ID registers as well.
Check for RAZ visibility in the ID register accessor functions, allowing the RAZ case to be handled in a generic way for all system registers.
The new REG_RAZ flag will be used in a later patch. This patch has no intended functional change.
--- arch/arm64/kvm/sys_regs.c | 19 ++++++++++++++++--- arch/arm64/kvm/sys_regs.h | 10 ++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-)
arch/arm64/kvm/sys_regs.c +16 -3
@@ -1151,6 +1151,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,return val; } +static unsigned int id_visibility (const struct kvm_vcpu *vcpu, +const struct sys_reg_desc *r) +{ +return 0 ; +} +/* cpufeature ID register access trap handlers */ static bool __access_id_reg(struct kvm_vcpu *vcpu,
@@ -1169,7 +1175,9 @@ static bool access_id_reg(struct kvm_vcpu *vcpu,struct sys_reg_params *p, const struct sys_reg_desc *r) { - return __access_id_reg(vcpu, p, r, false); + bool raz = sysreg_visible_as_raz(vcpu, r); + +return __access_id_reg (vcpu, p, r, raz); } static bool access_raz_id_reg(struct kvm_vcpu *vcpu,
@@ -1281,13 +1289,17 @@ static int __set_id_reg(const struct kvm_vcpu *vcpu,static int get_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *rd,const struct kvm_one_reg *reg,void __user *uaddr) { -return __get_id_reg (vcpu, rd, uaddr, false); +bool raz =sysreg_visible_as_raz (vcpu, rd); + +return __get_id_reg (vcpu, rd, uaddr, raz); }static int set_id_reg (struct kvm_vcpu *vcpu,const struct sys_reg_desc *rd,const struct kvm_one_reg *reg,void __user *uaddr) { -return __set_id_reg (vcpu, rd, uaddr, false); +bool raz =sysreg_visible_as_raz (vcpu, rd); + +return __set_id_reg (vcpu, rd, uaddr, raz); } static int get_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
@@ -1372,6 +1384,7 @@ static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, .access = access_id_reg, \ .get_user = get_id_reg, \ .set_user = set_id_reg, \ + .visibility = id_visibility, \ }/*
arch/arm64/kvm/sys_regs.h +10 -0
@@ -60,6 +60,7 @@ struct sys_reg_desc { };#define REG_HIDDEN (1 << 0)/* hidden from userspace and guest */ +#define REG_RAZ (1 << 1)/* RAZ from userspace and guest */ static __printf(2, 3) inline void print_sys_reg_msg(const struct sys_reg_params *p,
@@ -119,6 +120,15 @@ static inline bool sysreg_hidden(const struct kvm_vcpu *vcpu,return r->visibility (vcpu, r) ®_HIDDEN ; } +static inline bool sysreg_visible_as_raz (const struct kvm_vcpu *vcpu, +const struct sys_reg_desc *r) +{ +if (likely (!r->visibility)) +return false; + +return r->visibility (vcpu, r) ®_RAZ ; +} +static inline int cmp_sys_reg (const struct sys_reg_desc *i1,const struct sys_reg_desc *i2) {
Signature · 1 line
2.28.0
Marc Zyngier
maintainerPATCH 5/5 KVM: arm64: Remove AA64ZFR0_EL1 accessors
In reply to Marc ZyngierFrom: Andrew Jones <[email protected]>
The AA64ZFR0_EL1 accessors are just the general accessors with its visibility function open-coded. It also skips the if-else chain in read_id_reg, but there's no reason not to go there. Indeed consolidating ID register accessors and removing lines of code make it worthwhile.
Remove the AA64ZFR0_EL1 accessors, replacing them with the general accessors for sanitized ID registers.
No functional change intended.
--- arch/arm64/kvm/sys_regs.c | 61 +++++++-------------------------------- 1 file changed, 11 insertions(+), 50 deletions(-)
arch/arm64/kvm/sys_regs.c +11 -50
@@ -1154,6 +1154,16 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,static unsigned int id_visibility (const struct kvm_vcpu *vcpu,const struct sys_reg_desc *r) { +u32 id =sys_reg ((u32 )r->Op0, (u32 )r->Op1, + (u32 )r->CRn, (u32 )r->CRm, (u32 )r->Op2); + +switch (id) { +case SYS_ID_AA64ZFR0_EL1 : +if (!vcpu_has_sve (vcpu)) +return REG_RAZ ; +break ; + } +return 0 ; }
@@ -1201,55 +1211,6 @@ static unsigned int sve_visibility(const struct kvm_vcpu *vcpu,return REG_HIDDEN ; } -/* Generate the emulated ID_AA64ZFR0_EL1 value exposed to the guest */ -static u64 guest_id_aa64zfr0_el1 (const struct kvm_vcpu *vcpu) -{ -if (!vcpu_has_sve (vcpu)) -return 0 ; - -return read_sanitised_ftr_reg (SYS_ID_AA64ZFR0_EL1 ); -} - -static bool access_id_aa64zfr0_el1 (struct kvm_vcpu *vcpu, -struct sys_reg_params *p, -const struct sys_reg_desc *rd) -{ -if (p->is_write) -return write_to_read_only (vcpu, p, rd); - - p->regval =guest_id_aa64zfr0_el1 (vcpu); -return true; -} - -static int get_id_aa64zfr0_el1 (struct kvm_vcpu *vcpu, -const struct sys_reg_desc *rd, -const struct kvm_one_reg *reg,void __user *uaddr) -{ -u64 val; - - val =guest_id_aa64zfr0_el1 (vcpu); -return reg_to_user (uaddr, &val, reg->id); -} - -static int set_id_aa64zfr0_el1 (struct kvm_vcpu *vcpu, -const struct sys_reg_desc *rd, -const struct kvm_one_reg *reg,void __user *uaddr) -{ -const u64 id =sys_reg_to_index (rd); -int err; -u64 val; - - err =reg_from_user (&val, uaddr, id); -if (err) -return err; - -/* This is what we mean by invariant: you can't change it. */ -if (val !=guest_id_aa64zfr0_el1 (vcpu)) -return -EINVAL ; - -return 0 ; -} -/* * cpufeature ID register user accessors *
@@ -1506,7 +1467,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {ID_SANITISED (ID_AA64PFR1_EL1 ),ID_UNALLOCATED (4 ,2 ),ID_UNALLOCATED (4 ,3 ), - { SYS_DESC(SYS_ID_AA64ZFR0_EL1), access_id_aa64zfr0_el1, .get_user = get_id_aa64zfr0_el1, .set_user = set_id_aa64zfr0_el1, }, +ID_SANITISED (ID_AA64ZFR0_EL1 ),ID_UNALLOCATED (4 ,5 ),ID_UNALLOCATED (4 ,6 ), ID_UNALLOCATED(4,7),
Signature · 1 line
2.28.0
Paolo Bonzini
maintainerQuoted 1 line · Marc Zyngier
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.gittags/kvmarm-fixes-5.10-2
Pulled, thanks.
Paolo