Move VM-wide ID register emulation fields from struct kvm_arch into a new struct kvm_vm_id_regs. The new struct is placed in a shared region. Update the helper function and one memcopy in pkvm to use the new structure; No functional changes. Suggested-by: Nina Schoetterl-Glausch Co-developed-by: Andreas Grapentin Signed-off-by: Andreas Grapentin Signed-off-by: Steffen Eiden --- arch/arm64/include/asm/kvm_host.h | 56 +++++++++++++++++++++------------------ arch/arm64/kvm/hyp/nvhe/pkvm.c | 3 ++- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 83a6993e21cf..cfb2721053ed 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -105,6 +105,25 @@ struct vcpu_reset_state { bool reset; }; +struct kvm_vm_id_regs { + /* + * Emulated CPU ID registers per VM + * (Op0, Op1, CRn, CRm, Op2) of the ID registers to be saved in it + * is (3, 0, 0, crm, op2), where 1<=crm<8, 0<=op2<8. + * + * These emulated idregs are VM-wide, but accessed from the context of a vCPU. + * Atomic access to multiple idregs are guarded by kvm_arch.config_lock. + */ +#define IDREG_IDX(id) (((sys_reg_CRm(id) - 1) << 3) | sys_reg_Op2(id)) +#define KVM_ARM_ID_REG_NUM (IDREG_IDX(sys_reg(3, 0, 0, 7, 7)) + 1) + u64 ftr_regs[KVM_ARM_ID_REG_NUM]; + + u64 midr_el1; + u64 revidr_el1; + u64 aidr_el1; + u64 ctr_el0; +}; + #endif /* ARM64_S390_COMMON == 1 */ #define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \ @@ -478,22 +497,7 @@ struct kvm_arch { struct kvm_smccc_features smccc_feat; struct maple_tree smccc_filter; - /* - * Emulated CPU ID registers per VM - * (Op0, Op1, CRn, CRm, Op2) of the ID registers to be saved in it - * is (3, 0, 0, crm, op2), where 1<=crm<8, 0<=op2<8. - * - * These emulated idregs are VM-wide, but accessed from the context of a vCPU. - * Atomic access to multiple idregs are guarded by kvm_arch.config_lock. - */ -#define IDREG_IDX(id) (((sys_reg_CRm(id) - 1) << 3) | sys_reg_Op2(id)) -#define KVM_ARM_ID_REG_NUM (IDREG_IDX(sys_reg(3, 0, 0, 7, 7)) + 1) - u64 id_regs[KVM_ARM_ID_REG_NUM]; - - u64 midr_el1; - u64 revidr_el1; - u64 aidr_el1; - u64 ctr_el0; + struct kvm_vm_id_regs id_regs; /* Masks for VNCR-backed and general EL2 sysregs */ struct kvm_sysreg_masks *sysreg_masks; @@ -1637,24 +1641,24 @@ void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu); bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu); bool kvm_pkvm_vcpu_is_powered_off(struct kvm_vcpu *vcpu); -static inline u64 *__vm_ftr_reg_by_idx(struct kvm_arch *ka, u32 idx) +static inline u64 *__vm_ftr_reg_by_idx(struct kvm_vm_id_regs *id_regs, u32 idx) { - return &ka->id_regs[idx]; + return &id_regs->ftr_regs[idx]; } -static inline u64 *__vm_id_reg(struct kvm_arch *ka, u32 reg) +static inline u64 *__vm_id_reg(struct kvm_vm_id_regs *id_regs, u32 reg) { switch (reg) { case sys_reg(3, 0, 0, 1, 0) ... sys_reg(3, 0, 0, 7, 7): - return __vm_ftr_reg_by_idx(ka, IDREG_IDX(reg)); + return __vm_ftr_reg_by_idx(id_regs, IDREG_IDX(reg)); case SYS_CTR_EL0: - return &ka->ctr_el0; + return &id_regs->ctr_el0; case SYS_MIDR_EL1: - return &ka->midr_el1; + return &id_regs->midr_el1; case SYS_REVIDR_EL1: - return &ka->revidr_el1; + return &id_regs->revidr_el1; case SYS_AIDR_EL1: - return &ka->aidr_el1; + return &id_regs->aidr_el1; default: WARN_ON_ONCE(1); return NULL; @@ -1663,13 +1667,13 @@ static inline u64 *__vm_id_reg(struct kvm_arch *ka, u32 reg) #define kvm_get_vm_ftr_reg_by_idx(kvm, idx) \ ({ \ - u64 *__valp = __vm_ftr_reg_by_idx(&(kvm)->arch, idx); \ + u64 *__valp = __vm_ftr_reg_by_idx(&(kvm)->arch.id_regs, idx); \ __valp; \ }) #define kvm_get_vm_id_reg(kvm, reg) \ ({ \ - u64 *__valp = __vm_id_reg(&(kvm)->arch, reg); \ + u64 *__valp = __vm_id_reg(&(kvm)->arch.id_regs, reg); \ __valp; \ }) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index db51174ffbe0..471f6d82bc3e 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -591,7 +591,8 @@ static int vm_copy_id_regs(struct pkvm_hyp_vcpu *hyp_vcpu) if (test_and_set_bit(KVM_ARCH_FLAG_ID_REGS_INITIALIZED, &kvm->arch.flags)) return 0; - memcpy(kvm->arch.id_regs, host_kvm->arch.id_regs, sizeof(kvm->arch.id_regs)); + memcpy(kvm->arch.id_regs.ftr_regs, host_kvm->arch.id_regs.ftr_regs, + sizeof(kvm->arch.id_regs.ftr_regs)); return 0; } -- 2.56.1