KVM: s390: arm64: SMCCC, timers and IRQ line
Steffen Eiden
reviewerPATCH 4/12 KVM: s390: arm64: Use register shadow helper
In reply to Steffen EidenTo clearly mark the intention of the save/restore around SAE and to give a single point for the shadowing process add and use hepler functions to save and restore the shadow copy of the shadowed registers. For EL 0/1 this process is symmetrical. For EL2 registers the registers only need to be restored as the EL0/1 guest could not have modified those.
--- arch/s390/kvm/arm64/arm.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
arch/s390/kvm/arm64/arm.c +17 -8
@@ -447,6 +447,21 @@ static noinstr void arm_vcpu_enter_exit(phys_addr_t sae_block)guest_timing_exit_irqoff (); } +static void kvm_arm_restore_shadowed_regs (struct kvm_vcpu *vcpu) +{ +vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcr_el2,SYS_HCR_EL2 ); +vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcrx_el2,SYS_HCRX_EL2 ); +vcpu_write_host_sys_reg (vcpu, vcpu->arch.mpidr,SYS_VMPIDR_EL2 ); +_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.elr_el1,SYS_ELR_EL1 ); +_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.spsr_el1,SYS_SPSR_EL1 ); +} + +static void kvm_arm_save_shadowed_regs (struct kvm_vcpu *vcpu) +{ + vcpu->arch.ctxt.elr_el1 =_vcpu_read_sys_reg (vcpu,SYS_ELR_EL1 ); + vcpu->arch.ctxt.spsr_el1 =_vcpu_read_sys_reg (vcpu,SYS_SPSR_EL1 ); +} +/** kvm_arch_vcpu_ioctl_run() - run arm64 vCPU * * Execute arm64 guest instructions using SAE.
@@ -516,16 +531,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)trace_kvm_entry (*vcpu_pc (vcpu));kvm_adjust_pc (vcpu); -vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcr_el2,SYS_HCR_EL2 ); -vcpu_write_host_sys_reg (vcpu, vcpu->arch.hcrx_el2,SYS_HCRX_EL2 ); -vcpu_write_host_sys_reg (vcpu, vcpu->arch.mpidr,SYS_VMPIDR_EL2 ); -_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.elr_el1,SYS_ELR_EL1 ); -_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.spsr_el1,SYS_SPSR_EL1 ); +kvm_arm_restore_shadowed_regs (vcpu);arm_vcpu_enter_exit (virt_to_phys (&vcpu->arch.sae_block)); - - vcpu->arch.ctxt.elr_el1 =_vcpu_read_sys_reg (vcpu,SYS_ELR_EL1 ); - vcpu->arch.ctxt.spsr_el1 =_vcpu_read_sys_reg (vcpu,SYS_SPSR_EL1 ); +kvm_arm_save_shadowed_regs (vcpu); vcpu->mode =OUTSIDE_GUEST_MODE ; vcpu->stat.exits++;
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 5/12 KVM: s390: arm64: Shadow the guest timer CVAL registers
In reply to Steffen EidenThe timer registers {CNTP,CNTV}_CVAL_EL0 so far live solely in the save area and are only accessible through EASR/SASR, which is valid only from the vCPU thread while it owns the guest state. The accessors assert that a loaded vCPU is the currently running one, and an EASR read issued from any other CPU returns that CPU's registers instead of the guest's.
The timer emulation added later in this series reads CVAL from a hard hrtimer callback that can fire on any CPU, concurrently with the vCPU being loaded or put elsewhere. Give both registers plain memory shadows in struct kvm_cpu_context so that guest timer state is readable from any context.
--- arch/s390/include/asm/kvm_host_arm64.h | 8 ++++++-- arch/s390/kvm/arm64/arm.c | 4 ++++ arch/s390/kvm/arm64/sys_regs.c | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-)
arch/s390/include/asm/kvm_host_arm64.h +6 -2
@@ -68,6 +68,10 @@ struct kvm_cpu_context {/* shadowed sysregs to comply with arm64 infrastructure */ u64 elr_el1;u64 spsr_el1; + +/* shadowed timer sysregs */ +u64 cntp_cval_el0; +u64 cntv_cval_el0; };struct kvm_vcpu_arch {
@@ -329,6 +333,8 @@ enum vcpu_sysreg {MPIDR_EL1 ,ELR_EL1 ,SPSR_EL1 , +CNTP_CVAL_EL0 , + CNTV_CVAL_EL0, ),/* EL 0,1 register from save area in order of appearance */
@@ -337,8 +343,6 @@ enum vcpu_sysreg {AFSR0_EL1 ,AFSR1_EL1 ,CNTFRQ_EL0 , -CNTP_CVAL_EL0 , -CNTV_CVAL_EL0 ,DISR_EL1 ,MIDR_EL1 , OSLSR_EL1,
arch/s390/kvm/arm64/arm.c +4 -0
@@ -454,12 +454,16 @@ static void kvm_arm_restore_shadowed_regs(struct kvm_vcpu *vcpu)vcpu_write_host_sys_reg (vcpu, vcpu->arch.mpidr,SYS_VMPIDR_EL2 );_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.elr_el1,SYS_ELR_EL1 );_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.spsr_el1,SYS_SPSR_EL1 ); +_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.cntp_cval_el0,SYS_CNTP_CVAL_EL0 ); +_vcpu_write_sys_reg (vcpu, vcpu->arch.ctxt.cntv_cval_el0,SYS_CNTV_CVAL_EL0 ); }static void kvm_arm_save_shadowed_regs (struct kvm_vcpu *vcpu) { vcpu->arch.ctxt.elr_el1 =_vcpu_read_sys_reg (vcpu,SYS_ELR_EL1 ); vcpu->arch.ctxt.spsr_el1 =_vcpu_read_sys_reg (vcpu,SYS_SPSR_EL1 ); + vcpu->arch.ctxt.cntp_cval_el0 =_vcpu_read_sys_reg (vcpu,SYS_CNTP_CVAL_EL0 ); + vcpu->arch.ctxt.cntv_cval_el0 =_vcpu_read_sys_reg (vcpu,SYS_CNTV_CVAL_EL0 ); }/** kvm_arch_vcpu_ioctl_run() - run arm64 vCPU
arch/s390/kvm/arm64/sys_regs.c +4 -4
@@ -77,6 +77,8 @@ static __always_inline u64 read_special_sr(const struct kvm_vcpu *vcpu,case CNTV_CTL_EL0 :return vcpu->arch.sae_block.cntv_ctl;case CONTEXTIDR_EL1 :return vcpu->arch.sae_block.contextidr_el1;case SP_EL1 :return vcpu->arch.sae_block.sp_el1; +case CNTP_CVAL_EL0 :return vcpu->arch.ctxt.cntp_cval_el0; +case CNTV_CVAL_EL0 :return vcpu->arch.ctxt.cntv_cval_el0;default :WARN (true,"%s wants to read non-special register %x" , __func__, reg);return SR_INVALID ;
@@ -91,8 +93,6 @@ static __always_inline u64 read_sr_from_vcpu(const struct kvm_vcpu *vcpu,case AFSR0_EL1 :return _vcpu_read_sys_reg (vcpu,SYS_AFSR0_EL1 );case AFSR1_EL1 :return _vcpu_read_sys_reg (vcpu,SYS_AFSR1_EL1 );case CNTFRQ_EL0 :return _vcpu_read_sys_reg (vcpu,SYS_CNTFRQ_EL0 ); -case CNTP_CVAL_EL0 :return _vcpu_read_sys_reg (vcpu,SYS_CNTP_CVAL_EL0 ); -case CNTV_CVAL_EL0 :return _vcpu_read_sys_reg (vcpu,SYS_CNTV_CVAL_EL0 );case DISR_EL1 :return _vcpu_read_sys_reg (vcpu,SYS_DISR_EL1 );case MIDR_EL1 :return _vcpu_read_sys_reg (vcpu,SYS_MIDR_EL1 );case OSLSR_EL1 :return _vcpu_read_sys_reg (vcpu,SYS_OSLSR_EL1 );
@@ -160,6 +160,8 @@ static __always_inline void write_special_sr(struct kvm_vcpu *vcpu, u64 val,case SP_EL1 : vcpu->arch.sae_block.sp_el1 = val;break ;case ELR_EL1 : vcpu->arch.ctxt.elr_el1 = val;break ;case SPSR_EL1 : vcpu->arch.ctxt.spsr_el1 = val;break ; +case CNTP_CVAL_EL0 : vcpu->arch.ctxt.cntp_cval_el0 = val;break ; +case CNTV_CVAL_EL0 : vcpu->arch.ctxt.cntv_cval_el0 = val;break ;default :WARN (true,"%s wants to write non-special register %x" , __func__, reg); }
@@ -173,8 +175,6 @@ static __always_inline void write_sr_to_vcpu(struct kvm_vcpu *vcpu, u64 val,case AFSR0_EL1 :_vcpu_write_sys_reg (vcpu, val,SYS_AFSR0_EL1 );break ;case AFSR1_EL1 :_vcpu_write_sys_reg (vcpu, val,SYS_AFSR1_EL1 );break ;case CNTFRQ_EL0 :_vcpu_write_sys_reg (vcpu, val,SYS_CNTFRQ_EL0 );break ; -case CNTP_CVAL_EL0 :_vcpu_write_sys_reg (vcpu, val,SYS_CNTP_CVAL_EL0 );break ; -case CNTV_CVAL_EL0 :_vcpu_write_sys_reg (vcpu, val,SYS_CNTV_CVAL_EL0 );break ;case DISR_EL1 :_vcpu_write_sys_reg (vcpu, val,SYS_DISR_EL1 );break ;case MIDR_EL1 :_vcpu_write_sys_reg (vcpu, val,SYS_MIDR_EL1 );break ;case PAR_EL1 :_vcpu_write_sys_reg (vcpu, val,SYS_PAR_EL1 );break ;
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 1/12 arm64: Prepare for sharing with s390
In reply to Steffen EidenAdd s390 guards for arm headers which reside in include/kvm. This allows s390 to use headers placed in its arch include/arm64/ .
Move vcpu_can_run to a more convenient location such that it can be shared without adding another shared section. Move functions in arch_timer.c to more convenient locations such that the required functionality can be shared with just two shared regions instead of seven.
--- arch/arm64/include/asm/kvm_host.h | 4 +- arch/arm64/kvm/arch_timer.c | 87 ++++++++++++++++++++------------------- arch/arm64/kvm/arm.c | 10 ++--- include/kvm/arm_hypercalls.h | 3 ++ include/kvm/arm_psci.h | 3 ++ 5 files changed, 57 insertions(+), 50 deletions(-)
arch/arm64/include/asm/kvm_host.h +2 -2
@@ -396,6 +396,8 @@ static inline u16 kvm_mpidr_index(struct kvm_mpidr_data *data, u64 mpidr)return index; } +struct kvm_vcpu *kvm_mpidr_to_vcpu (struct kvm *kvm,unsigned long mpidr); +struct kvm_sysreg_masks ;enum fgt_group_id {
@@ -1444,8 +1446,6 @@ static inline bool kvm_arm_is_pvtime_enabled(struct kvm_vcpu_arch *vcpu_arch)return (vcpu_arch->steal.base !=INVALID_GPA ); } -struct kvm_vcpu *kvm_mpidr_to_vcpu (struct kvm *kvm,unsigned long mpidr); - DECLARE_KVM_HYP_PER_CPU(struct kvm_host_data, kvm_host_data);/*
arch/arm64/kvm/arch_timer.c +44 -43
135 lines not on this page · raw message
arch/arm64/kvm/arm.c +5 -5
@@ -901,6 +901,11 @@ static bool kvm_arm_vcpu_suspended(struct kvm_vcpu *vcpu)return READ_ONCE (vcpu->arch.mp_state.mp_state) ==KVM_MP_STATE_SUSPENDED ; } +static bool vcpu_can_run (struct kvm_vcpu *vcpu) +{ +return !kvm_arm_vcpu_stopped (vcpu) && !atomic_read (&vcpu->arch.pause); +} +/* Only the guest's CPU_ON may start a vCPU EL2 holds powered off. */ bool kvm_pkvm_vcpu_is_powered_off (struct kvm_vcpu *vcpu) {
@@ -953,11 +958,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,return ret; } -static bool vcpu_can_run (struct kvm_vcpu *vcpu) -{ -return !kvm_arm_vcpu_stopped (vcpu) && !atomic_read (&vcpu->arch.pause); -} -/** * kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled * @v: The VCPU pointer
include/kvm/arm_hypercalls.h +3 -0
@@ -4,7 +4,10 @@#ifndef __KVM_ARM_HYPERCALLS_H#define __KVM_ARM_HYPERCALLS_H +/* s390 provides its own header view */ +#ifndef __s390__#include <asm/kvm_emulate.h> +#endif // !__s390__ int kvm_smccc_call_handler (struct kvm_vcpu *vcpu);
include/kvm/arm_psci.h +3 -0
@@ -10,7 +10,10 @@#include <linux/kvm_host.h> #include <uapi/linux/psci.h> +/* s390 provides its own header view */ +#ifndef __s390__#include <asm/kvm_emulate.h> +#endif // !__s390__ #define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1)#define KVM_ARM_PSCI_0_2 PSCI_VERSION(0, 2)
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 6/12 KVM: s390: arm64: Use mpstate for guests
In reply to Steffen EidenImplement the necessary plumbing to manage the mp state of an arm64 guest.
--- arch/s390/include/asm/kvm_host_arm64.h | 3 ++- arch/s390/kvm/arm64/arm.c | 37 ++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-)
arch/s390/include/asm/kvm_host_arm64.h +2 -1
@@ -37,7 +37,8 @@ bool cpus_have_final_cap(unsigned int num);#define KVM_S390_ARM64_IMPL_FEATURES ( \ BIT(KVM_ARM_VCPU_PTRAUTH_ADDRESS) | \ BIT(KVM_ARM_VCPU_PTRAUTH_GENERIC) | \ - BIT(KVM_ARM_VCPU_SVE) \ + BIT(KVM_ARM_VCPU_SVE) | \ + BIT(KVM_ARM_VCPU_POWER_OFF) \ )#define KVM_HALT_POLL_NS_DEFAULT 50000
arch/s390/kvm/arm64/arm.c +35 -2
@@ -52,6 +52,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_IOEVENTFD :case KVM_CAP_PRE_FAULT_MEMORY :case KVM_CAP_ONE_REG : +case KVM_CAP_MP_STATE : ret =1 ;break ;case KVM_CAP_ARM_SVE :
@@ -175,6 +176,7 @@ long kvm_arch_dev_ioctl(struct file *filp,void kvm_arch_destroy_vm (struct kvm *kvm) { +kvm_destroy_mpidr_data (kvm);kvm_destroy_vcpus (kvm);debug_unregister (kvm->arch.dbf); kvm->arch.gmap =gmap_put (kvm->arch.gmap);
@@ -212,6 +214,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) sae_block->save_area =virt_to_phys (save_area); sae_block->gpto = vcpu->kvm->arch.epd; +kvm_destroy_mpidr_data (vcpu->kvm); VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%p, sae block at 0x%p, satellite at 0x%p", vcpu->vcpu_id, vcpu, &vcpu->arch.sae_block,
@@ -267,7 +270,25 @@ int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,int kvm_arch_vcpu_ioctl_set_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) { -return -EINVAL ; +int ret =0 ; + + scoped_guard(spinlock, &vcpu->arch.mp_state_lock) { +switch (mp_state->mp_state) { +case KVM_MP_STATE_RUNNABLE : +WRITE_ONCE (vcpu->arch.mp_state, *mp_state); +break ; +case KVM_MP_STATE_STOPPED : +__kvm_arm_vcpu_power_off (vcpu,KVM_MP_STATE_STOPPED ); +break ; +case KVM_MP_STATE_SUSPENDED : +kvm_arm_vcpu_suspend (vcpu); +break ; +default : + ret = -EINVAL ; + } + } + +return ret; }int kvm_arch_vcpu_runnable (struct kvm_vcpu *vcpu)
@@ -309,6 +330,8 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)if (likely (READ_ONCE (vcpu->pid)))return 0 ; +kvm_init_mpidr_data (kvm); + ret =kvm_vcpu_finalize_sys_regs (vcpu);if (ret)return ret;
@@ -403,16 +426,26 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, {struct kvm_sae_save_area *save_area = &vcpu->arch.save_area;struct kvm_sae_block *sae_block = &vcpu->arch.sae_block; +bool power_off = false;int ret; sae_block->save_area =virt_to_phys (save_area); +/* Limit KVM_ARM_VCPU_POWER_OFF's scope to a single KVM_ARM_VCPU_INIT call */ +if (init->features[0 ] &BIT (KVM_ARM_VCPU_POWER_OFF )) { + init->features[0 ] &= ~BIT (KVM_ARM_VCPU_POWER_OFF ); + power_off = true; + } + ret =kvm_vcpu_set_target (vcpu, init);if (ret)return ret; scoped_guard(spinlock, &vcpu->arch.mp_state_lock) { -WRITE_ONCE (vcpu->arch.mp_state.mp_state,KVM_MP_STATE_RUNNABLE ); +if (power_off) +__kvm_arm_vcpu_power_off (vcpu,KVM_MP_STATE_STOPPED ); +else +WRITE_ONCE (vcpu->arch.mp_state.mp_state,KVM_MP_STATE_RUNNABLE ); }return 0 ;
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 9/12 KVM: s390: arm64: Provide timer infrastructure
In reply to Steffen EidenFrom: Gautam Gala <[email protected]>
Add support for the arm64 architected timers (virtual and physical) of an arm64 guest. The SAE block holds the timer control registers, and ISTATUS in CTL is set when a timer condition is met.
Build the shared arm64 arch_timer.c with s390-specific backends: CTL and CVAL are accessed through vcpu_{read,write}_sys_reg(), and the guest counter is obtained with PTFF QAGPT from the guest physical time offset (GPTO) in the SAE block.
--- arch/s390/include/arm64/kvm_emulate.h | 5 + arch/s390/include/asm/kvm_host_arm64.h | 2 + arch/s390/kvm/arm64/Makefile | 1 + arch/s390/kvm/arm64/Makefile.gen | 1 + arch/s390/kvm/arm64/arch_timer.c | 224 +++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/arm.c | 5 - 6 files changed, 233 insertions(+), 5 deletions(-)
arch/s390/include/arm64/kvm_emulate.h +5 -0
@@ -127,6 +127,11 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu)void vcpu_reset_hcrx (struct kvm_vcpu *vcpu); +static inline bool is_hyp_ctxt (const struct kvm_vcpu *vcpu) +{ +return false; +} +#include <arm64/kvm_emulate-gen.h> #endif /* __S390_ARM64_KVM_EMULATE_H__ */
arch/s390/include/asm/kvm_host_arm64.h +2 -0
@@ -135,6 +135,8 @@ struct kvm_vcpu_arch {u64 last_steal;gpa_t base; } steal; + +struct arch_timer_cpu timer_cpu; };struct kvm_vcpu_stat {
arch/s390/kvm/arm64/Makefile +1 -0
@@ -11,6 +11,7 @@ ccflags-y += -I $(src) -I $(objtree)/$(obj) -I$(srctree)/arch/$(SRCARCH)/kvm/gma kvm-arm64-local := \ arm.o \ + arch_timer.o \ exception.o \ feature.o \ guest.o \
arch/s390/kvm/arm64/Makefile.gen +1 -0
@@ -5,6 +5,7 @@ # List of ARM64 C files to extract ARM64_CFILES := \ + arch_timer.c \ arm.c \ guest.c \ hypercalls.c \
arch/s390/kvm/arm64/arch_timer.c new file +224 -0
224 lines not on this page · raw message
arch/s390/kvm/arm64/arm.c +0 -5
@@ -894,11 +894,6 @@ int kvm_set_routing_entry(struct kvm *kvm,return -EINVAL ; } -int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu) -{ -return 0 ; -} -long kvm_arch_vcpu_unlocked_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 11/12 KVM: s390: arm64: Trap WFx
In reply to Steffen EidenFrom: Gautam Gala <[email protected]>
Enable the TWI and TWE trap bits in HCR_EL2 and handle the resulting WFx exceptions in kvm_handle_wfx().
WFI halts the vCPU until it becomes runnable again, i.e. until userspace asserts an IRQ/FIQ line (KVM_IRQ_LINE) or a guest timer output level changes. WFE is treated as a directed yield to another vCPU of the same VM. WFxT carries a deadline: compare it against the guest counter obtained with PTFF QAGPT from the guest physical time offset (GPTO) in the SAE block, and complete the instruction immediately if it has already passed. Otherwise, halt as for WFI with IN_WFIT set so the timer code takes the deadline into account. WFxT with an invalid RN is executed as plain WFI/WFE.
--- arch/s390/kvm/arm64/handle_exit.c | 54 +++++++++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/reset.c | 3 ++- 2 files changed, 56 insertions(+), 1 deletion(-)
arch/s390/kvm/arm64/handle_exit.c +54 -0
@@ -6,6 +6,8 @@#include <arm64/kvm_emulate.h> #include <kvm/arm_hypercalls.h> +#include <asm/timex.h> +#include "handle_exit.h" typedef int (*exit_handle_fn )(struct kvm_vcpu *);
@@ -43,8 +45,60 @@ static int handle_smc(struct kvm_vcpu *vcpu)return kvm_smccc_call_handler (vcpu); } +/** +* kvm_handle_wfx - handle a wait-for-interrupts or wait-for-event +* instruction executed by a guest +* +* @vcpu: the vcpu pointer +* +* WFI: Virtualize the instruction by halting the vCPU until it becomes +* runnable, i.e. until userspace asserts an IRQ/FIQ line (KVM_IRQ_LINE) or +* a guest timer output level changes. +* WFE: Handled as a directed yield to another vCPU of the same VM. +* WFxT: WFI/WFE with a deadline; if the deadline has already passed, the +* instruction completes immediately. +*/ +static int kvm_handle_wfx (struct kvm_vcpu *vcpu) +{ +u64 esr =kvm_vcpu_get_esr (vcpu); +bool is_wfe = !!(esr & ESR_ELx_WFx_ISS_WFE); + +if (is_wfe) + vcpu->stat.wfe_exit_stat++; +else + vcpu->stat.wfi_exit_stat++; + +if (esr & ESR_ELx_WFx_ISS_WFxT) { +if (esr & ESR_ELx_WFx_ISS_RV) { +u64 val, now; + + now =ptff_qagpt (vcpu->arch.sae_block.gpto); + val =vcpu_get_reg (vcpu,kvm_vcpu_sys_get_rt (vcpu)); +if (now >= val) + goto out; + }else { +/* Treat WFxT as WFx if RN is invalid */ + esr &= ~ESR_ELx_WFx_ISS_WFxT; + } + } + +if (esr & ESR_ELx_WFx_ISS_WFE) { +kvm_vcpu_on_spin (vcpu,vcpu_mode_priv (vcpu)); + }else { +if (esr & ESR_ELx_WFx_ISS_WFxT) +vcpu_set_flag (vcpu,IN_WFIT ); + +kvm_vcpu_wfi (vcpu); + } +out: +kvm_incr_pc (vcpu); + +return 1 ; +} +static exit_handle_fn arm_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec, + [ESR_ELx_EC_WFx] = kvm_handle_wfx, [ESR_ELx_EC_SMC64] = handle_smc, [ESR_ELx_EC_HVC64] = handle_hvc, [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg,
arch/s390/kvm/arm64/reset.c +2 -1
@@ -30,7 +30,8 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu)/* traps */ vcpu->arch.hcr_el2 |=HCR_EL2_TSC |HCR_EL2_TID1 |HCR_EL2_TID2 |HCR_EL2_TID3 |HCR_EL2_TID4 |HCR_EL2_TID5 | -HCR_EL2_TIDCP |HCR_EL2_TLOR ; +HCR_EL2_TIDCP |HCR_EL2_TLOR | +HCR_EL2_TWI |HCR_EL2_TWE ; }void vcpu_reset_hcrx (struct kvm_vcpu *vcpu)
Signature · 1 line
2.56.1
Steffen Eiden
reviewercover KVM: s390: arm64: SMCCC, timers and IRQ line
Add SMCCC/PSCI support, the arm64 architected timers, WFx* handling and the userspace IRQ line for KVM/arm64 on s390. The arm64 SMCCC, timer and vCPU power management code is shared with s390 and wired into the s390 KVM module.
This is the third series on the way to arm64 guests on s390. The first series laid the KVM foundation (basic module, vCPU run, simple page faults) and is included in v7.4. The second series built the system register layer [1]. This series adds the guest CPU management layer on top. Power management with PSCI, full SMCCC handling, the architected timers and interrupt injection from userspace.
This series depends on the second series [1], on the vCPU kick enabling series [2], and on the vgic stubs patch [3]
PATCH 04 and 05 can be squashed into series 2 [1] and will be when I send v5. I just did not want to send a respin after a few days w/o much comments.
Changes in detail:
arm64:
Prepare headers and code for sharing with s390: guard arm64 headers that reside in include/ such that s390 can consume them, and move a few things/ The moves add a bit of churn in the diff but reduce the number of shared sections required for the timer from seven to two.
Share the SMCCC related files (hypercalls, psci, trng, pvtime) as a whole.Share the timer functionality that is architecture agnostic. As timers work differently on s390 only a subset can be reused. Share the functions for managing SMP guests.
s390:
Implement the mp_state plumbing for arm64 guests backed by the shared power-off/suspend infrastructure and the MPIDR data used for SMP guest management.
Use the shared arm64 code for handling SMCCCs and implement the final host-side plumbing, removing the primitive SYSTEM_OFF only implementation.
Add support for the arm64 architected timers (virtual and physical) of an arm64 guest. The SAE block holds the timer control registers, and ISTATUS in CTL is set when a timer condition is met. The shared arm64 arch_timer.c is built with s390-specific backends: CTL and CVAL are accessed through vcpu_{read,write}_sys_reg(), and the guest counter is obtained with PTFF QAGPT from the guest physical time offset (GPTO) in the SAE block.
Trap WFx* and handle them in kvm_handle_wfx(). A vCPU halted in WFI or WFIT is woken by a background hrtimer armed for the earliest of the enabled guest timer expiries and the WFIT deadline; on expiry the hrtimer raises KVM_REQ_UNBLOCK and wakes the vCPU.
There is no in-kernel irqchip (yet!), so timer output level changes cannot be injected. After each guest exit handled in the kernel, including a timer interception (SAE_ICPTR_TIMER), ISTATUS in CTL is compared with the level last seen by userspace and the vCPU exits with KVM_EXIT_INTR on a change. On vCPU reset both timers are disabled and unmasked.
Implement the IRQ line for the !irqchip_in_kernel case, i.e. interrupt injection from userspace.
A branch with this series at kernel.org is available [4].
Steffen
[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux.git/log/?h=sae
---
Andreas Grapentin (1):
KVM: s390: arm64: Add IRQ line
Gautam Gala (2):
KVM: s390: arm64: Provide timer infrastructure
KVM: s390: arm64: Trap WFx
Steffen Eiden (9):
arm64: Prepare for sharing with s390
arm64: Share timer and smccc functionality with s390
KVM: arm64: Share timer and smccc code with s390
KVM: s390: arm64: Use register shadow helper
KVM: s390: arm64: Shadow the guest timer CVAL registers
KVM: s390: arm64: Use mpstate for guests
KVM: s390: arm64: Enable full smccc support
KVM: s390: arm64: Report fwregs to userspace
KVM: s390: arm64: Integrate guest timer
arch/arm64/include/asm/kvm_emulate.h | 4 +- arch/arm64/include/asm/kvm_host.h | 40 +++--- arch/arm64/include/asm/kvm_mmu.h | 2 + arch/arm64/include/asm/pvclock-abi.h | 1 + arch/arm64/kvm/arch_timer.c | 95 +++++++------- arch/arm64/kvm/arm.c | 25 +++- arch/arm64/kvm/hypercalls.c | 4 + arch/arm64/kvm/psci.c | 3 + arch/arm64/kvm/pvtime.c | 2 + arch/arm64/kvm/trng.c | 2 + arch/s390/include/arm64/kvm_emulate.h | 6 + arch/s390/include/asm/kvm_host_arm64.h | 45 ++++++- arch/s390/kvm/Kconfig | 1 + arch/s390/kvm/arm64/Makefile | 7 +- arch/s390/kvm/arm64/Makefile.gen | 7 +- arch/s390/kvm/arm64/arch_timer.c | 226 ++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/arm.c | 227 ++++++++++++++++++++++++++++++--- arch/s390/kvm/arm64/guest.c | 14 ++ arch/s390/kvm/arm64/handle_exit.c | 105 ++++++++++----- arch/s390/kvm/arm64/hypercalls.c | 32 +++++ arch/s390/kvm/arm64/psci.c | 20 +++ arch/s390/kvm/arm64/pvtime.c | 15 +++ arch/s390/kvm/arm64/reset.c | 14 +- arch/s390/kvm/arm64/sys_regs.c | 8 +- arch/s390/kvm/arm64/trace.h | 45 +++++++ arch/s390/kvm/arm64/trng.c | 12 ++ arch/s390/tools/Makefile.arm64h | 2 + include/kvm/arm_hypercalls.h | 3 + include/kvm/arm_psci.h | 3 + 29 files changed, 836 insertions(+), 134 deletions(-)
base-commit: 9437ee8b6cf607e883b36e44bd755968daaebd48
change-id: 20261127-smccc-c8cb09f78ebc
prerequisite-message-id: [email protected]
prerequisite-patch-id: ed28ef94c9056cb81bb738f1b54745d012cb613f
prerequisite-change-id: 20261106-sysreg-d6adf0cd34d4:v4
prerequisite-patch-id: ed28ef94c9056cb81bb738f1b54745d012cb613f
prerequisite-patch-id: 4f6b2386967522be268f77ca6eb9487a3503dc96
prerequisite-patch-id: 539f1138a427fddb952a5f7a0691e8acd974d0fb
prerequisite-patch-id: 3e9b8384f07ff18911f48eabe625a1c0507a5e96
prerequisite-patch-id: fc58c00a1006ecffd045728020ef01308022ac03
prerequisite-patch-id: 2c22bad7059a38c4ea01ca774d0c0b49cea27fba
prerequisite-patch-id: c809f818609fed0a0f8ccb1721b96f5329505543
prerequisite-patch-id: b35581eba719557148ea84232698457adc8c8cc4
prerequisite-patch-id: 0b8792bac82c24bfac0b5912d2eec5da32413747
prerequisite-patch-id: 58fb40b78dd793ca3b24cadadad8868bc54aa20e
prerequisite-patch-id: d986b0811f1feac0678eb135ce5c44140748431b
prerequisite-patch-id: 0e3d84b8259a175fceb67b01bc37c1830805636b
prerequisite-patch-id: 53a6741f3c6ec60c798995ccbf4d2b293619ec34
prerequisite-patch-id: b71ccf22e4cb8fccf4ca9eea558af14163b256db
prerequisite-patch-id: bba91e0c077b1f308e2ec914a54399f775d9090d
prerequisite-patch-id: 9be57897346558cd0bea61d946d85d3ba9a17f2e
prerequisite-patch-id: f4ae3a54ce24b78e335eb1f019b971419d82720a
prerequisite-patch-id: cc8dfe5b2b8a3f28b3c29b1a10827d99f987694d
prerequisite-patch-id: f27d96dacb5c7dadc01f1cc72158b8b3f64d7053
prerequisite-patch-id: 1c69a0380267279633c8ba33bf1d30c13877e033
prerequisite-patch-id: 20ac948d6ec4bfd4b9c3d053bcb0fcb3fe067486
prerequisite-patch-id: db6b83091a6107dbfd9c4311af14fadf1534375f
prerequisite-patch-id: af30d541a7cabea0981dfe79276d1e9991a8c91a
prerequisite-patch-id: 5eead648d962cbdc9f45ce40538f174faedd5775
prerequisite-patch-id: 97589af6c7ac9efe15c371883511fc05d4f1c870
prerequisite-patch-id: f661ef5923e8026fab81d73e596006ac30d5cbac
prerequisite-message-id: [email protected]
prerequisite-patch-id: bd1a0c1fa7ff80d9edd5fff5258d8af1de06d7d7
prerequisite-message-id: [email protected]
prerequisite-patch-id: 90cb98820a1c6fec2085ca6830827f90c6b659ab
prerequisite-patch-id: 36feb5c5ca141ca0a94f60e8cc27e3969f3ebefd
Steffen Eiden
reviewerPATCH 8/12 KVM: s390: arm64: Report fwregs to userspace
Now that we have the firmware registers implemented provide the UAPI for managing them.
--- arch/s390/kvm/arm64/guest.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/s390/kvm/arm64/guest.c +14 -0
@@ -9,6 +9,8 @@#include "feature.h" +#include <kvm/arm_hypercalls.h> +#define SVE_VQ_MIN __SVE_VQ_MIN#define SVE_NUM_ZREGS KVM_ARM64_SVE_NUM_ZREGS#define SVE_NUM_PREGS KVM_ARM64_SVE_NUM_PREGS
@@ -306,6 +308,11 @@ int kvm_arm_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices)return ret; uindices += ret; + ret =kvm_arm_copy_fw_reg_indices (vcpu, uindices); +if (ret <0 ) +return ret; + uindices +=kvm_arm_get_fw_num_regs (vcpu); +return kvm_arm_copy_sys_reg_indices (vcpu, uindices); }
@@ -315,6 +322,7 @@ unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu) num +=num_sve_regs (vcpu); num +=kvm_arm_num_sys_reg_descs (vcpu); + num +=kvm_arm_get_fw_num_regs (vcpu);return num; }
@@ -327,6 +335,9 @@ int kvm_arm_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)switch (reg->id &KVM_REG_ARM_COPROC_MASK ) {case KVM_REG_ARM_CORE :return get_core_reg (vcpu, reg); +case KVM_REG_ARM_FW : +case KVM_REG_ARM_FW_FEAT_BMAP : +return kvm_arm_get_fw_reg (vcpu, reg);case KVM_REG_ARM64_SVE :return get_sve_reg (vcpu, reg);default :
@@ -343,6 +354,9 @@ int kvm_arm_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)switch (reg->id &KVM_REG_ARM_COPROC_MASK ) {case KVM_REG_ARM_CORE :return set_core_reg (vcpu, reg); +case KVM_REG_ARM_FW : +case KVM_REG_ARM_FW_FEAT_BMAP : +return kvm_arm_set_fw_reg (vcpu, reg);case KVM_REG_ARM64_SVE :return set_sve_reg (vcpu, reg);default :
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 2/12 arm64: Share timer and smccc functionality with s390
In reply to Steffen EidenShare functions and definitions required to implement guest timers and smccc.
--- arch/arm64/include/asm/kvm_emulate.h | 4 ++-- arch/arm64/include/asm/kvm_host.h | 36 ++++++++++++++++++++---------------- arch/arm64/include/asm/kvm_mmu.h | 2 ++ arch/arm64/include/asm/pvclock-abi.h | 1 + 4 files changed, 25 insertions(+), 18 deletions(-)
arch/arm64/include/asm/kvm_emulate.h +2 -2
@@ -546,13 +546,13 @@ static inline bool kvm_is_write_fault(struct kvm_vcpu *vcpu) return esr_abt_is_write_fault(kvm_vcpu_get_esr(vcpu)); } -#endif /* ARM64_S390_COMMON == 1 */ -static inline unsigned long kvm_vcpu_get_mpidr_aff (struct kvm_vcpu *vcpu) {return __vcpu_sys_reg (vcpu,MPIDR_EL1 ) &MPIDR_HWID_BITMASK ; } +#endif /* ARM64_S390_COMMON == 1 */ +/* In nVHE hyp code, registers are always in memory: use the raw accessors. */ #if defined(__KVM_NVHE_HYPERVISOR__)#define vcpu_read_sys_reg (v, r) __vcpu_sys_reg(v, r)
arch/arm64/include/asm/kvm_host.h +20 -16
@@ -124,6 +124,20 @@ struct kvm_vm_id_regs { u64 ctr_el0; }; +/** +* struct kvm_smccc_features: Descriptor of the hypercall services exposed to the guests +* +* @std_bmap: Bitmap of standard secure service calls +* @std_hyp_bmap: Bitmap of standard hypervisor service calls +* @vendor_hyp_bmap: Bitmap of vendor specific hypervisor service calls +*/ +struct kvm_smccc_features { +unsigned long std_bmap; +unsigned long std_hyp_bmap; +unsigned long vendor_hyp_bmap;/* Function numbers 0-63 */ +unsigned long vendor_hyp_bmap_2;/* Function numbers 64-127 */ +}; +#endif /* ARM64_S390_COMMON == 1 */ #define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
@@ -354,20 +368,6 @@ struct kvm_s2_mmu {struct kvm_arch_memory_slot { }; -/** -* struct kvm_smccc_features: Descriptor of the hypercall services exposed to the guests -* -* @std_bmap: Bitmap of standard secure service calls -* @std_hyp_bmap: Bitmap of standard hypervisor service calls -* @vendor_hyp_bmap: Bitmap of vendor specific hypervisor service calls -*/ -struct kvm_smccc_features { -unsigned long std_bmap; -unsigned long std_hyp_bmap; -unsigned long vendor_hyp_bmap;/* Function numbers 0-63 */ -unsigned long vendor_hyp_bmap_2;/* Function numbers 64-127 */ -}; -struct kvm_protected_vm {pkvm_handle_t handle;struct kvm_hyp_memcache stage2_teardown_mc;
@@ -381,6 +381,8 @@ struct kvm_protected_vm {bool is_dying; }; +#if ARM64_S390_COMMON == 1 + struct kvm_mpidr_data { u64 mpidr_mask; DECLARE_FLEX_ARRAY(u16, cmpidr_to_idx);
@@ -398,6 +400,8 @@ static inline u16 kvm_mpidr_index(struct kvm_mpidr_data *data, u64 mpidr)struct kvm_vcpu *kvm_mpidr_to_vcpu (struct kvm *kvm,unsigned long mpidr); +#endif /* ARM64_S390_COMMON == 1 */ +struct kvm_sysreg_masks ;enum fgt_group_id {
@@ -1406,8 +1410,6 @@ unsigned long kvm_mmio_read_buf(const void *buf, unsigned int len);int kvm_handle_mmio_return (struct kvm_vcpu *vcpu);int io_mem_abort (struct kvm_vcpu *vcpu,phys_addr_t fault_ipa); -#endif /* ARM64_S390_COMMON == 1 */ -/* * Returns true if a Performance Monitoring Interrupt (PMI), a.k.a. perf event, * arrived in guest context. For arm64, any event that arrives while a vCPU is
@@ -1430,6 +1432,8 @@ int kvm_arm_pvtime_get_attr(struct kvm_vcpu *vcpu,int kvm_arm_pvtime_has_attr (struct kvm_vcpu *vcpu,struct kvm_device_attr *attr); +#endif /* ARM64_S390_COMMON == 1 */ +extern unsigned int __ro_after_init kvm_arm_vmid_bits;int __init kvm_arm_vmid_alloc_init (void );void __init kvm_arm_vmid_alloc_free (void );
arch/arm64/include/asm/kvm_mmu.h +2 -0
@@ -297,6 +297,7 @@ static inline int kvm_read_guest_lock(struct kvm *kvm,return ret; } +#if ARM64_S390_COMMON ==1 static inline int kvm_write_guest_lock (struct kvm *kvm,gpa_t gpa,const void *data,unsigned long len) {
@@ -307,6 +308,7 @@ static inline int kvm_write_guest_lock(struct kvm *kvm, gpa_t gpa, return ret; } +#endif /* ARM64_S390_COMMON == 1 */ #define kvm_phys_to_vttbr (addr) phys_to_ttbr(addr)
arch/arm64/include/asm/pvclock-abi.h +1 -0
@@ -1,5 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ /* Copyright (C) 2019 Arm Ltd. */ +/* Whole file is shared with s390 */ #ifndef __ASM_PVCLOCK_ABI_H#define __ASM_PVCLOCK_ABI_H
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 10/12 KVM: s390: arm64: Integrate guest timer
In reply to Steffen EidenHook the timer into the vCPU lifecycle and, on vCPU reset, disable and unmask both timers.
--- arch/s390/kvm/arm64/arch_timer.c | 2 ++ arch/s390/kvm/arm64/arm.c | 35 +++++++++++++++++++++++++++++++++-- arch/s390/kvm/arm64/handle_exit.c | 2 ++ arch/s390/kvm/arm64/reset.c | 1 + 4 files changed, 38 insertions(+), 2 deletions(-)
arch/s390/kvm/arm64/arch_timer.c +2 -0
@@ -173,6 +173,8 @@ void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu)kvm_timer_unblocking (vcpu); + vcpu->arch.sae_block.gpto = vcpu->kvm->arch.epd; +for (int timerid =0 ; timerid <nr_timers (vcpu); timerid++) { ctxt =vcpu_get_timer (vcpu, timerid); ctxt->loaded = true;
arch/s390/kvm/arm64/arm.c +33 -2
@@ -27,6 +27,8 @@#include "handle_exit.h" #include "qaaf.h" +#include <kvm/arm_arch_timer.h> +#define CREATE_TRACE_POINTS #include "trace.h"
@@ -215,6 +217,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)/* Force users to call KVM_ARM_VCPU_INIT */ vcpu_clear_flag (vcpu,VCPU_INITIALIZED ); +kvm_timer_vcpu_init (vcpu); + vcpu->arch.mc =kvm_s390_new_mmu_cache ();if (!vcpu->arch.mc)return -ENOMEM ;
@@ -244,6 +248,7 @@ void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)void kvm_arch_vcpu_destroy (struct kvm_vcpu *vcpu) {kfree (vcpu->arch.ccsidr); +kvm_timer_vcpu_terminate (vcpu);kvm_s390_free_mmu_cache (vcpu->arch.mc);VCPU_EVENT (vcpu,3 ,"%s" ,"free cpu" );
@@ -263,6 +268,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)lasrm (&vcpu->arch.save_area); vcpu->arch.sae_block.gpto = vcpu->kvm->arch.epd; +kvm_timer_vcpu_load (vcpu);vcpu_set_pauth_traps (vcpu);
@@ -272,6 +278,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)void kvm_arch_vcpu_put (struct kvm_vcpu *vcpu) { +kvm_timer_vcpu_put (vcpu); +stiasrm (&vcpu->arch.save_area); vcpu->cpu =-1 ;
@@ -525,6 +533,26 @@ static void kvm_arm_save_shadowed_regs(struct kvm_vcpu *vcpu) vcpu->arch.ctxt.cntv_cval_el0 =_vcpu_read_sys_reg (vcpu,SYS_CNTV_CVAL_EL0 ); } +/* +* kvm_vcpu_exit_request - returns true if the VCPU should *not* enter the guest +* @vcpu: The VCPU pointer +* @ret: Exit reason to be propagated to userspace +* +*/ +static bool kvm_vcpu_exit_request (struct kvm_vcpu *vcpu,int *ret) +{ +if (unlikely (!irqchip_in_kernel (vcpu->kvm))) { +if (unlikely (kvm_timer_update_run (vcpu))) { + *ret = -EINTR ; + vcpu->run->exit_reason =KVM_EXIT_INTR ; +return true; + } + } + +return kvm_request_pending (vcpu) || +xfer_to_guest_mode_work_pending (); +} +/** kvm_arch_vcpu_ioctl_run() - run arm64 vCPU * * Execute arm64 guest instructions using SAE.
@@ -584,8 +612,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)*/ smp_store_mb (vcpu->mode,IN_GUEST_MODE ); -if (ret <=0 ||kvm_request_pending (vcpu) || -xfer_to_guest_mode_work_pending ()) { +if (ret <=0 ||kvm_vcpu_exit_request (vcpu, &ret)) { vcpu->mode =OUTSIDE_GUEST_MODE ;local_irq_enable ();continue ;
@@ -608,6 +635,10 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) ret =handle_exit (vcpu); } +/* Tell userspace about in-kernel device output levels */ +if (!irqchip_in_kernel (vcpu->kvm)) +kvm_timer_update_run (vcpu); +kvm_sigset_deactivate (vcpu); out: if (unlikely(vcpu_get_flag(vcpu, PENDING_EXCEPTION) ||
arch/s390/kvm/arm64/handle_exit.c +2 -0
@@ -97,6 +97,8 @@ int handle_exit(struct kvm_vcpu *vcpu)case SAE_ICPTR_SYNCHRONOUS_EXCEPTION : ret =handle_trap_exceptions (vcpu);break ; +case SAE_ICPTR_TIMER : +break ;default : vcpu->run->exit_reason =KVM_EXIT_FAIL_ENTRY ; ret =0 ;
arch/s390/kvm/arm64/reset.c +1 -0
@@ -101,6 +101,7 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)kvm_reset_vcpu_core (vcpu);kvm_reset_sys_regs (vcpu); +kvm_timer_vcpu_reset (vcpu);/* Reset special registers */ vcpu_reset_hcr (vcpu);
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 12/12 KVM: s390: arm64: Add IRQ line
In reply to Steffen EidenFrom: Andreas Grapentin <[email protected]>
As all relevant helper and CPU management functions are in place and behave correctly it is time to add support for non-kernel IRQ handling. Implement the IRQ line for the !irqchip_in_kernel case.
With that arm on s390 is able to run full Linux arm64 guests using the user irq chip.
--- arch/s390/include/arm64/kvm_emulate.h | 1 + arch/s390/include/asm/kvm_host_arm64.h | 1 + arch/s390/kvm/arm64/arm.c | 49 +++++++++++++++++++++++++++++++--- arch/s390/kvm/arm64/reset.c | 6 +++-- arch/s390/kvm/arm64/trace.h | 25 +++++++++++++++++ 5 files changed, 77 insertions(+), 5 deletions(-)
arch/s390/include/arm64/kvm_emulate.h +1 -0
@@ -125,6 +125,7 @@ static inline void kvm_reset_fpsimd(struct kvm_vcpu *vcpu) vcpu->arch.sae_block.fpcr =0 ; } +void vcpu_reset_hcr (struct kvm_vcpu *vcpu);void vcpu_reset_hcrx (struct kvm_vcpu *vcpu);static inline bool is_hyp_ctxt (const struct kvm_vcpu *vcpu)
arch/s390/include/asm/kvm_host_arm64.h +1 -0
@@ -39,6 +39,7 @@ bool cpus_have_final_cap(unsigned int num);/* GICv2 maximum TODO change with in-kernel gic support*/ #define KVM_MAX_VCPUS 8#define __KVM_HAVE_VCPU_RUN_PID_CHANGE +#define __KVM_HAVE_IRQ_LINE#define KVM_S390_ARM64_IMPL_FEATURES ( \ BIT(KVM_ARM_VCPU_PTRAUTH_ADDRESS) | \
arch/s390/kvm/arm64/arm.c +46 -3
73 lines not on this page · raw message
arch/s390/kvm/arm64/reset.c +4 -2
@@ -23,7 +23,7 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu)return true; } -static inline void vcpu_reset_hcr (struct kvm_vcpu *vcpu) +void vcpu_reset_hcr (struct kvm_vcpu *vcpu) { vcpu->arch.hcr_el2 =HCR_EL2_E2H |HCR_EL2_RW |HCR_EL2_AMO |HCR_EL2_IMO |HCR_EL2_FMO |HCR_EL2_PTW ;
@@ -105,12 +105,14 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)kvm_timer_vcpu_reset (vcpu);/* Reset special registers */ -vcpu_reset_hcr (vcpu);vcpu_reset_hcrx (vcpu);vcpu_reset_cptr (vcpu);vcpu_reset_cnthctl (vcpu);vcpu_reset_icc (vcpu); +/* Discard a pending SError */ + vcpu->arch.hcr_el2 &= ~HCR_EL2_VSE ; +if (reset_state.reset) {/* The guest found the shoot yourself in the foot button */ if (reset_state.be)
arch/s390/kvm/arm64/trace.h +25 -0
@@ -43,6 +43,31 @@ TRACE_EVENT(kvm_exit, __entry->vcpu_pc) ); +TRACE_EVENT (kvm_irq_line, + TP_PROTO(unsigned int type, int vcpu_idx, int irq_num, int level), +TP_ARGS (type, vcpu_idx, irq_num, level), + +TP_STRUCT__entry ( + __field( unsigned int, type ) + __field( int, vcpu_idx ) + __field( int, irq_num ) +__field ( int, level ) + ), + +TP_fast_assign ( + __entry->type = type; + __entry->vcpu_idx = vcpu_idx; + __entry->irq_num = irq_num; + __entry->level = level; + ), + +TP_printk ("Inject %s interrupt (%d), vcpu->idx: %d, num: %d, level: %d" , + (__entry->type ==KVM_ARM_IRQ_TYPE_CPU ) ?"CPU" : + (__entry->type ==KVM_ARM_IRQ_TYPE_PPI ) ?"VGIC PPI" : + (__entry->type ==KVM_ARM_IRQ_TYPE_SPI ) ?"VGIC SPI" :"UNKNOWN" , + __entry->type, __entry->vcpu_idx, __entry->irq_num, __entry->level) +); + TRACE_EVENT(kvm_mmio_nisv, TP_PROTO(unsigned long vcpu_pc, unsigned long esr, unsigned long far, unsigned long ipa),
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 3/12 KVM: arm64: Share timer and smccc code with s390
In reply to Steffen EidenShare the whole smccc related files. s390 will use the whole unmodified infrastructure. Share useful timer related functions. As timers work differntly on s390 only a subset can be reused. Share functions for managing SMP guests.
--- arch/arm64/kvm/arch_timer.c | 8 ++++++++ arch/arm64/kvm/arm.c | 15 +++++++++++++++ arch/arm64/kvm/hypercalls.c | 4 ++++ arch/arm64/kvm/psci.c | 3 +++ arch/arm64/kvm/pvtime.c | 2 ++ arch/arm64/kvm/trng.c | 2 ++ 6 files changed, 34 insertions(+)
arch/arm64/kvm/arch_timer.c +8 -0
@@ -248,6 +248,8 @@ static bool vcpu_has_wfit_active(struct kvm_vcpu *vcpu) vcpu_get_flag(vcpu, IN_WFIT)); } +#if ARM64_S390_COMMON ==1 +static int nr_timers (struct kvm_vcpu *vcpu) {if (!vcpu_has_nv (vcpu))
@@ -314,6 +316,8 @@ static u64 kvm_timer_earliest_exp(struct kvm_vcpu *vcpu) return min_delta; } +#endif /* ARM64_S390_COMMON == 1 */ +static enum hrtimer_restart kvm_bg_timer_expire (struct hrtimer *hrt) {struct arch_timer_cpu *timer;
@@ -406,6 +410,8 @@ static bool kvm_timer_pending(struct arch_timer_context *timer_ctx)return cval <= now; } +#if ARM64_S390_COMMON ==1 +int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu) {return vcpu_has_wfit_active (vcpu) &&wfit_delay_ns (vcpu) ==0 ;
@@ -451,6 +457,8 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) soft_timer_cancel(&timer->bg_timer); } +#endif /* ARM64_S390_COMMON == 1 */ +static void kvm_timer_update_status (struct arch_timer_context *ctx,bool level) {/*
arch/arm64/kvm/arm.c +15 -0
@@ -318,6 +318,7 @@ void kvm_arch_create_vm_debugfs(struct kvm *kvm)kvm_s2_ptdump_create_debugfs (kvm); } +#if ARM64_S390_COMMON ==1 static void kvm_destroy_mpidr_data (struct kvm *kvm) {struct kvm_mpidr_data *data;
@@ -334,6 +335,7 @@ static void kvm_destroy_mpidr_data(struct kvm *kvm) mutex_unlock(&kvm->arch.config_lock); } +#endif /* ARM64_S390_COMMON == 1 */ /** * kvm_arch_destroy_vm - destroy the VM data structure
@@ -865,6 +867,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) vcpu->cpu =-1 ; } +#if ARM64_S390_COMMON ==1 static void __kvm_arm_vcpu_power_off (struct kvm_vcpu *vcpu,u32 mp_state) {WRITE_ONCE (vcpu->arch.mp_state.mp_state, mp_state);
@@ -912,6 +915,8 @@ bool kvm_pkvm_vcpu_is_powered_off(struct kvm_vcpu *vcpu) return READ_ONCE(vcpu->arch.mp_state.mp_state) == KVM_MP_STATE_UNINITIALIZED; } +#endif /* ARM64_S390_COMMON == 1 */ +int kvm_arch_vcpu_ioctl_get_mpstate (struct kvm_vcpu *vcpu,struct kvm_mp_state *mp_state) {
@@ -981,6 +986,7 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)return vcpu_mode_priv (vcpu); } +#if ARM64_S390_COMMON == 1 #ifdef CONFIG_GUEST_PERF_EVENTS unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) {
@@ -1040,6 +1046,8 @@ static void kvm_init_mpidr_data(struct kvm *kvm) mutex_unlock(&kvm->arch.config_lock); } +#endif /* ARM64_S390_COMMON == 1 */ +/* * Handle both the initialisation that is being done when the vcpu is * run for the first time, as well as the updates that must be
@@ -1164,6 +1172,7 @@ void kvm_arm_resume_guest(struct kvm *kvm)kvm_resume_vcpu (vcpu); } +#if ARM64_S390_COMMON ==1 static void kvm_vcpu_sleep (struct kvm_vcpu *vcpu) {struct rcuwait *wait =kvm_arch_vcpu_get_wait (vcpu);
@@ -1249,6 +1258,7 @@ static int kvm_vcpu_suspend(struct kvm_vcpu *vcpu)*/ return 1; } +#endif /* ARM64_S390_COMMON == 1 */ /** * check_vcpu_requests - check and handle pending vCPU requests
@@ -1607,6 +1617,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)return ret; } +#if ARM64_S390_COMMON ==1 static int vcpu_interrupt_line (struct kvm_vcpu *vcpu,int number,bool level) {int bit_index;
@@ -1641,6 +1652,8 @@ static int vcpu_interrupt_line(struct kvm_vcpu *vcpu, int number, bool level) return 0; } +#endif /* ARM64_S390_COMMON == 1 */ +int kvm_vm_ioctl_irq_line (struct kvm *kvm,struct kvm_irq_level *irq_level,bool line_status) {
@@ -3157,6 +3170,7 @@ static int __init init_hyp_mode(void)return err; } +#if ARM64_S390_COMMON ==1 struct kvm_vcpu *kvm_mpidr_to_vcpu (struct kvm *kvm,unsigned long mpidr) {struct kvm_vcpu *vcpu =NULL ;
@@ -3187,6 +3201,7 @@ struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr) }return NULL ; } +#endif /* ARM64_S390_COMMON == 1 */ bool kvm_arch_irqchip_in_kernel (struct kvm *kvm) {
arch/arm64/kvm/hypercalls.c +4 -0
@@ -67,6 +67,8 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val) val[3 ] =lower_32_bits (cycles); } +#if ARM64_S390_COMMON ==1 +static bool kvm_smccc_default_allowed (u32 func_id) {switch (func_id) {
@@ -691,3 +693,5 @@ int kvm_vm_smccc_set_attr(struct kvm *kvm, struct kvm_device_attr *attr) return -ENXIO; } } + +#endif /* ARM64_S390_COMMON == 1 */
arch/arm64/kvm/psci.c +3 -0
@@ -16,6 +16,7 @@#include <kvm/arm_psci.h> #include <kvm/arm_hypercalls.h> +#if ARM64_S390_COMMON ==1 /* * This is an implementation of the Power State Coordination Interface * as described in ARM document number ARM DEN 0022A.
@@ -484,3 +485,5 @@ int kvm_psci_call(struct kvm_vcpu *vcpu) return 1; } } + +#endif /* ARM64_S390_COMMON == 1 */
arch/arm64/kvm/pvtime.c +2 -0
@@ -10,6 +10,7 @@#include <kvm/arm_hypercalls.h> +#if ARM64_S390_COMMON ==1 void kvm_update_stolen_time (struct kvm_vcpu *vcpu) {struct kvm *kvm = vcpu->kvm;
@@ -131,3 +132,4 @@ int kvm_arm_pvtime_has_attr(struct kvm_vcpu *vcpu, }return -ENXIO ; } +#endif /* ARM64_S390_COMMON == 1 */
arch/arm64/kvm/trng.c +2 -0
@@ -8,6 +8,7 @@#include <kvm/arm_hypercalls.h> +#if ARM64_S390_COMMON ==1 #define ARM_SMCCC_TRNG_VERSION_1_0 0x10000UL/* Those values are deliberately separate from the generic SMCCC definitions. */
@@ -83,3 +84,4 @@ int kvm_trng_call(struct kvm_vcpu *vcpu)smccc_set_retval (vcpu, val,0 ,0 ,0 ); return 1; } +#endif /* ARM64_S390_COMMON == 1 */
Signature · 1 line
2.56.1
Steffen Eiden
reviewerPATCH 7/12 KVM: s390: arm64: Enable full smccc support
In reply to Steffen EidenUse the shared arm64 code for handling smccc's. Implement the final plumbing for the host to process these. Remove the primitive SYSTEM_OFF implementation.
--- arch/s390/include/asm/kvm_host_arm64.h | 33 +++++++++++++++- arch/s390/kvm/Kconfig | 1 + arch/s390/kvm/arm64/Makefile | 6 ++- arch/s390/kvm/arm64/Makefile.gen | 6 ++- arch/s390/kvm/arm64/arm.c | 72 +++++++++++++++++++++++++++++++++- arch/s390/kvm/arm64/handle_exit.c | 49 ++++++++--------------- arch/s390/kvm/arm64/hypercalls.c | 32 +++++++++++++++ arch/s390/kvm/arm64/psci.c | 20 ++++++++++ arch/s390/kvm/arm64/pvtime.c | 15 +++++++ arch/s390/kvm/arm64/reset.c | 4 ++ arch/s390/kvm/arm64/trace.h | 20 ++++++++++ arch/s390/kvm/arm64/trng.c | 12 ++++++ arch/s390/tools/Makefile.arm64h | 2 + 13 files changed, 235 insertions(+), 37 deletions(-)
arch/s390/include/asm/kvm_host_arm64.h +31 -2
@@ -10,10 +10,13 @@#define vcpu_gp_regs (v) ((v)->arch.sae_block.gpr)enum vcpu_sysreg ; +struct kvm_arch ; +static inline bool __vcpu_has_feature (const struct kvm_arch *ka,int feature);#include <arm64/cputype.h> #include <arm64/kvm_host.h> #include <arm64/ptrace.h> +#include <arm64/kvm_hyp.h> #include <asm/sae.h>
@@ -30,15 +33,19 @@ enum {bool cpus_have_final_cap (unsigned int num); +#include <kvm/arm_arch_timer.h> +#define KVM_HAVE_MMU_RWLOCK -#define KVM_MAX_VCPUS 1 +/* GICv2 maximum TODO change with in-kernel gic support*/ +#define KVM_MAX_VCPUS 8#define __KVM_HAVE_VCPU_RUN_PID_CHANGE#define KVM_S390_ARM64_IMPL_FEATURES ( \ BIT(KVM_ARM_VCPU_PTRAUTH_ADDRESS) | \ BIT(KVM_ARM_VCPU_PTRAUTH_GENERIC) | \ BIT(KVM_ARM_VCPU_SVE) | \ - BIT(KVM_ARM_VCPU_POWER_OFF) \ + BIT(KVM_ARM_VCPU_POWER_OFF) | \ + BIT(KVM_ARM_VCPU_PSCI_0_2) \ )#define KVM_HALT_POLL_NS_DEFAULT 50000
@@ -122,6 +129,12 @@ struct kvm_vcpu_arch {struct kvm_s390_mmu_cache *mc;void *debugfs_state_data; + +/* Guest PV state */ +struct { +u64 last_steal; +gpa_t base; + } steal; };struct kvm_vcpu_stat {
@@ -167,6 +180,12 @@ struct kvm_arch {/* Per-VM ID register storage */ struct kvm_vm_id_regs id_regs; +/* Hypercall features firmware registers' descriptor */ +struct kvm_smccc_features smccc_feat; +struct maple_tree smccc_filter; +/* Mandated version of PSCI */ +u32 psci_version; +struct kvm_mpidr_data *mpidr_data; };
@@ -398,6 +417,16 @@ static __always_inline u64 *___ctxt_sys_reg(struct kvm_cpu_context *ctxt,void vcpu_write_host_sys_reg (struct kvm_vcpu *vcpu,u64 val,int reg);u64 vcpu_read_host_sys_reg (const struct kvm_vcpu *vcpu,int reg); +static inline void kvm_arm_pvtime_vcpu_init (struct kvm_vcpu_arch *vcpu_arch) +{ + vcpu_arch->steal.base =INVALID_GPA ; +} + +static inline bool kvm_arm_is_pvtime_enabled (struct kvm_vcpu_arch *vcpu_arch) +{ +return (vcpu_arch->steal.base !=INVALID_GPA ); +} +#define kvm_debug_handle_oslar (_v, _val)/* debug not implemented yet*/ #define kvm_vm_has_ran_once (kvm) \
arch/s390/kvm/Kconfig +1 -0
@@ -29,6 +29,7 @@ config KVM select VIRT_XFER_TO_GUEST_WORK select KVM_MMU_LOCKLESS_AGING select KVM_GENERIC_PRE_FAULT_MEMORY + select SCHED_INFO help Enable support for hosting virtualized, hardware-accelerated virtual machines via two modules: kvm and kvm_arm64.
arch/s390/kvm/arm64/Makefile +5 -1
@@ -15,13 +15,17 @@ kvm-arm64-local := \ feature.o \ guest.o \ handle_exit.o \ + hypercalls.o \ inject_fault.o \ mmio.o \ mmu.o \ + psci.o \ + pvtime.o \ qaaf.o \ reset.o \ spectre.o \ - sys_regs.o + sys_regs.o \ + trng.o kvm-arm64-obj := $(kvm-arm64-local) kvm-arm64-obj += $(patsubst %.o,%-arm64.o,$(kvm-y))
arch/s390/kvm/arm64/Makefile.gen +5 -1
@@ -7,8 +7,12 @@ ARM64_CFILES := \ arm.c \ guest.c \ + hypercalls.c \ mmio.c \ - sys_regs.c + psci.c \ + pvtime.c \ + sys_regs.c \ + trng.c quiet_cmd_extract_inc = GEN $@ cmd_extract_inc = mkdir -p $(dir $@); \
arch/s390/kvm/arm64/arm.c +71 -1
171 lines not on this page · raw message
arch/s390/kvm/arm64/handle_exit.c +17 -32
71 lines not on this page · raw message
arch/s390/kvm/arm64/hypercalls.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/arm-smccc.h> +#include <linux/kvm_host.h> + +#include <arm64/kvm_emulate.h> +#include <arm64/sysreg.h> +#include <arm64/spectre.h> + +#include <kvm/arm_hypercalls.h> +#include <kvm/arm_psci.h> + +#include "trace.h" + +/* arm on s390 KVM does not support/need PTP */ +static void kvm_ptp_get_time (struct kvm_vcpu *vcpu,u64 *val) { } + +#define KVM_S390_ARM_SMCCC_VENDOR_HYP_FEATURES \ + GENMASK(KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT, 0) + +#define KVM_ARM_SMCCC_STD_FEATURES \ + GENMASK(KVM_REG_ARM_STD_BMAP_BIT_COUNT - 1, 0) +#define KVM_ARM_SMCCC_STD_HYP_FEATURES \ + GENMASK(KVM_REG_ARM_STD_HYP_BMAP_BIT_COUNT - 1, 0) +#define KVM_ARM_SMCCC_VENDOR_HYP_FEATURES \ + KVM_S390_ARM_SMCCC_VENDOR_HYP_FEATURES +#define KVM_ARM_SMCCC_VENDOR_HYP_FEATURES_2 \ + GENMASK(KVM_REG_ARM_VENDOR_HYP_BMAP_2_BIT_COUNT - 1, 0) + +#define __INCL_GEN_ARM_FILE +#include "generated/hypercalls.inc" +#undef __INCL_GEN_ARM_FILE
arch/s390/kvm/arm64/psci.c new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/arm-smccc.h> +#include <linux/preempt.h> +#include <linux/kvm_host.h> +#include <linux/uaccess.h> +#include <linux/wait.h> + +#include <arm64/kvm_emulate.h> +#include <arm64/cputype.h> +#include <arm64/sysreg.h> + +#include <kvm/arm_psci.h> +#include <kvm/arm_hypercalls.h> + +#include "trace.h" + +#define __INCL_GEN_ARM_FILE +#include "generated/psci.inc" +#undef __INCL_GEN_ARM_FILE
arch/s390/kvm/arm64/pvtime.c new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/arm-smccc.h> +#include <linux/kvm_host.h> +#include <linux/sched/stat.h> + +#include <arm64/pvclock-abi.h> +#include <arm64/kvm_emulate.h> +#include <arm64/kvm_mmu.h> + +#include <kvm/arm_hypercalls.h> + +#define __INCL_GEN_ARM_FILE +#include "generated/pvtime.inc" +#undef __INCL_GEN_ARM_FILE
arch/s390/kvm/arm64/reset.c +4 -0
@@ -110,6 +110,10 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)vcpu_reset_icc (vcpu);if (reset_state.reset) { +/* The guest found the shoot yourself in the foot button */ +if (reset_state.be) +kvm_vm_dead (vcpu->kvm); + *vcpu_pc (vcpu) = reset_state.pc;vcpu_clear_flag (vcpu,PENDING_EXCEPTION );vcpu_clear_flag (vcpu,EXCEPT_MASK );
arch/s390/kvm/arm64/trace.h +20 -0
@@ -140,6 +140,26 @@ TRACE_EVENT(kvm_sys_access, str_write_read(__entry->is_write)) ); +TRACE_EVENT (kvm_hvc_arm64, + TP_PROTO(unsigned long vcpu_pc, unsigned long r0, unsigned long imm), +TP_ARGS (vcpu_pc, r0, imm), + +TP_STRUCT__entry ( + __field(unsigned long, vcpu_pc) + __field(unsigned long, r0) + __field(unsigned long, imm) + ), + +TP_fast_assign ( + __entry->vcpu_pc = vcpu_pc; + __entry->r0 = r0; + __entry->imm = imm; + ), + +TP_printk ("HVC at 0x%016lx (r0: 0x%016lx, imm: 0x%lx)" , + __entry->vcpu_pc, __entry->r0, __entry->imm) +); +#endif /* KVM_ARM64_TRACE_KVM_H */ #undef TRACE_INCLUDE_PATH
arch/s390/kvm/arm64/trng.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/arm-smccc.h> +#include <linux/kvm_host.h> + +#include <arm64/kvm_emulate.h> + +#include <kvm/arm_hypercalls.h> + +#define __INCL_GEN_ARM_FILE +#include "generated/trng.inc" +#undef __INCL_GEN_ARM_FILE
arch/s390/tools/Makefile.arm64h +2 -0
@@ -23,7 +23,9 @@ ARM64_SHARED_HEADERS := \ kvm_arm.h \ kvm_emulate-gen.h \ kvm_host.h \ + kvm_mmu.h \ ptrace-gen.h \ + pvclock-abi.h \ sysreg-gen.h \ spectre.h \ kvm:sys_regs-gen.h \
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH 09/12] KVM: s390: arm64: Provide timer infrastructure
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: s390: arm64: duplicate CNTFRQ_EL0 read in kvm_timer_vcpu_init() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: s390: arm64: duplicate CNTFRQ_EL0 read in kvm_timer_vcpu_init()
--
commit 3f84c2d2b67205dc8582a4940d22e1a2782707bb
Author: Gautam Gala <[email protected]>
KVM: s390: arm64: Provide timer infrastructure
This commit adds virtual and physical architected timer support for arm64 guests on s390 by building the shared arm64 arch_timer.c with s390-specific backends.
Quoted 6 lines
arch/s390/kvm/arm64/arch_timer.c new file +0
-0@@ -0,0 +1,224 @@
[ ... ]
arch/s390/kvm/arm64/arch_timer.c line 211
Quoted 10 lines
arch/s390/kvm/arm64/arch_timer.c new file +10
-0+void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu) +{ +u64 cntfrq_el0 =kvm_qaaf_read_ftr_reg (SYS_CNTFRQ_EL0 ); +struct arch_timer_cpu *timer =vcpu_timer (vcpu); + + cntfrq_el0 =kvm_qaaf_read_ftr_reg (SYS_CNTFRQ_EL0 ); +if (cntfrq_el0 !=HZ_PER_GHZ ) +pr_warn_once ( +"CNTFRQ_EL0 is %llu Hz. KVM expects 1GHz. Wakeups may arrive early or late." , + cntfrq_el0);
[Severity: Low]cntfrq_el0 is initialized from kvm_qaaf_read_ftr_reg(SYS_CNTFRQ_EL0) and immediately overwritten with a second identical call. Also, the pr_warn_once() format string is missing a trailing newline.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
[email protected]
AI reviewRe: [PATCH 10/12] KVM: s390: arm64: Integrate guest timer
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: s390: arm64: duplicate sae_block.gpto store in kvm_timer_vcpu_load() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] KVM: s390: arm64: duplicate sae_block.gpto store in kvm_timer_vcpu_load()
--
commit 2c2f682fb98375d172d67f251dc234fab2444a6f
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Integrate guest timer
This commit hooks the guest timer into the vCPU lifecycle and resets both timers on vCPU reset.
Quoted 17 lines
arch/s390/kvm/arm64/arch_timer.c +2
-0@@ -173,6 +173,8 @@ void kvm_timer_vcpu_load(struct kvm_vcpu *vcpu)kvm_timer_unblocking (vcpu); + vcpu->arch.sae_block.gpto = vcpu->kvm->arch.epd; +for (int timerid =0 ; timerid <nr_timers (vcpu); timerid++) { ctxt =vcpu_get_timer (vcpu, timerid); ctxt->loaded = true;arch/s390/kvm/arm64/arm.c +0
-0
[ ... ]
arch/s390/kvm/arm64/arm.c void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) · line 271
Quoted 5 lines
arch/s390/kvm/arm64/arm.c +1
-0@@ -263,6 +268,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)lasrm (&vcpu->arch.save_area); vcpu->arch.sae_block.gpto = vcpu->kvm->arch.epd; +kvm_timer_vcpu_load (vcpu);
[Severity: Low]
This isn't a bug, but kvm_timer_vcpu_load() sets vcpu->arch.sae_block.gpto to vcpu->kvm->arch.epd even though its only caller, kvm_arch_vcpu_load(), already does the same assignment on the line right before calling kvm_timer_vcpu_load(). Could one of the two assignments be dropped?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
[email protected]
AI reviewRe: [PATCH 07/12] KVM: s390: arm64: Enable full smccc support
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] KVM: s390: arm64: unclamped kvm->max_vcpus in kvm_arch_init_vm() - [Low] KVM: s390: arm64…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] KVM: s390: arm64: unclamped kvm->max_vcpus in kvm_arch_init_vm()
- [Low] KVM: s390: arm64: misplaced case blocks in kvm_arch_vm_ioctl() --
commit 531ac05785ece0e3573d8628fd57758de85eef37
Author: Steffen Eiden <[email protected]>
KVM: s390: arm64: Enable full smccc support
This commit enables SMCCC, PSCI, PV time, and TRNG support for arm64 guests on s390 by wiring up the shared arm64 hypercall handling code.
Quoted 11 lines
arch/s390/kvm/arm64/arm.c +1
-1@@ -44,7 +46,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_NR_VCPUS :case KVM_CAP_MAX_VCPUS :case KVM_CAP_MAX_VCPU_ID : - ret =KVM_MAX_VCPUS ; + ret =min (kvm_sae_max_vcpus (),KVM_MAX_VCPUS );break ;
[ ... ]
Quoted 18 lines
arch/s390/kvm/arm64/arm.c +3
-0@@ -154,6 +161,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm->arch.epd =ptff_qagto (0 ); +kvm_arm_init_hypercalls (kvm); +VM_EVENT (kvm,3 ,"vm created with type %lu" , type);return 0 ;@@ -180,6 +189,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)kvm_destroy_vcpus (kvm);debug_unregister (kvm->arch.dbf); kvm->arch.gmap =gmap_put (kvm->arch.gmap); +kvm_arm_teardown_hypercalls (kvm); }u32 get_kvm_ipa_limit (void )
arch/s390/kvm/arm64/arm.c u32 get_kvm_ipa_limit(void) · line 206
Quoted 8 lines
arch/s390/kvm/arm64/arm.c +3
-0@@ -189,6 +199,9 @@ u32 get_kvm_ipa_limit(void)int kvm_arch_vcpu_precreate (struct kvm *kvm,unsigned int id) { +if (id >= kvm->max_vcpus) +return -EINVAL ; +return 0 ; }
[Severity: Medium]
Should kvm_arch_init_vm() clamp kvm->max_vcpus tomin(kvm_sae_max_vcpus(), KVM_MAX_VCPUS)?
kvm_create_vm() initializes kvm->max_vcpus to KVM_MAX_VCPUS (now 8) before calling kvm_arch_init_vm(). Because kvm_arch_init_vm() never updates kvm->max_vcpus, both kvm_vm_ioctl_create_vcpu() and kvm_arch_vcpu_precreate() check against 8 instead of the hardware limit reported by kvm_sae_max_vcpus(), allowing userspace to create vCPUs past the hardware limit on systems where kvm_sae_max_vcpus() < 8.
[ ... ]
Quoted 10 lines
arch/s390/kvm/arm64/arm.c +6
-0@@ -799,6 +856,19 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)return -EFAULT ;return 0 ; +case KVM_HAS_DEVICE_ATTR : { +if (copy_from_user (&attr, argp,sizeof (attr))) +return -EFAULT ; + +return kvm_vm_has_attr (kvm, &attr); + }
arch/s390/kvm/arm64/arm.c int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) · line 874
Quoted 10 lines
arch/s390/kvm/arm64/arm.c +7
-0+case KVM_SET_DEVICE_ATTR : { +if (copy_from_user (&attr, argp,sizeof (attr))) +return -EFAULT ; + +return kvm_vm_set_attr (kvm, &attr); + } + }default :
[Severity: Low]
This isn't a bug, but case KVM_HAS_DEVICE_ATTR and case KVM_SET_DEVICE_ATTR are placed inside the compound block opened by case KVM_ARM_PREFERRED_TARGET, jumping into the scope of init rather than after the closing brace of KVM_ARM_PREFERRED_TARGET.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH 12/12] KVM: s390: arm64: Add IRQ line
In reply to Steffen EidenThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] KVM: s390: arm64: non-atomic hcr_el2 RMW races with vcpu_interrupt_line() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] KVM: s390: arm64: non-atomic hcr_el2 RMW races with vcpu_interrupt_line()
--
commit d464d208b63e74e278a80c66b1b80eba93db96f6
Author: Andreas Grapentin <[email protected]>
KVM: s390: arm64: Add IRQ line
This commit implements KVM_IRQ_LINE support for arm64 guests on s390 with a userspace interrupt controller, exposing KVM_CAP_ARM_USER_IRQ, updating kvm_arch_vcpu_runnable(), and preserving HCR_EL2 interrupt lines across vCPU resets.
Quoted 4 lines
arch/s390/kvm/arm64/reset.c +0
-0
[ ... ]
arch/s390/kvm/arm64/reset.c void kvm_reset_vcpu(struct kvm_vcpu *vcpu) · line 114
Quoted 12 lines
arch/s390/kvm/arm64/reset.c +2
-1@@ -105,12 +105,14 @@ void kvm_reset_vcpu(struct kvm_vcpu *vcpu)kvm_timer_vcpu_reset (vcpu);/* Reset special registers */ -vcpu_reset_hcr (vcpu);vcpu_reset_hcrx (vcpu);vcpu_reset_cptr (vcpu);vcpu_reset_cnthctl (vcpu);vcpu_reset_icc (vcpu); +/* Discard a pending SError */ + vcpu->arch.hcr_el2 &= ~HCR_EL2_VSE ;
[Severity: Medium]
Can this non-atomic read-modify-write on vcpu->arch.hcr_el2 race with vcpu_interrupt_line() and drop a concurrent HCR_EL2_VI or HCR_EL2_VF update?
KVM_IRQ_LINE is a VM ioctl that runs without vcpu->mutex and updates HCR_EL2_VI and HCR_EL2_VF in vcpu->arch.hcr_el2 via test_and_set_bit() and test_and_clear_bit(). Both kvm_reset_vcpu() here and kvm_arch_vcpu_load() -> vcpu_set_pauth_traps() modify vcpu->arch.hcr_el2 with plain bitwise operations:
arch/s390/kvm/arm64/arm.c:vcpu_set_pauth_traps() {
if (vcpu_has_ptrauth(vcpu))
vcpu->arch.hcr_el2 |= (HCR_EL2_API | HCR_EL2_APK);
}CPU0 CPU1kvm_arch_vcpu_load()
vcpu_set_pauth_traps()
tmp = vcpu->arch.hcr_el2
kvm_vm_ioctl_irq_line()
vcpu_interrupt_line()
test_and_set_bit(..., hcr)
vcpu->arch.hcr_el2 =
tmp | HCR_EL2_API | ... <-- overwrites HCR_EL2_VI/VFWhen CPU0 writes back the stale value during vcpu_load() or a PSCI CPU_ON reset, the guest can miss an asserted interrupt (for example when waking from WFI) or keep a deasserted line asserted. Using atomic bit operations on vcpu_hcr(vcpu) (or setting static trap bits such as HCR_EL2_API | HCR_EL2_APK in vcpu_reset_hcr()) would avoid clobbering concurrent VI/VF updates.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
[email protected]
AI reviewSashiko has finished reviewing this 12-patch series:
Sashiko has finished reviewing this 12-patch series:
- Patches 1-6, 8, and 11: no issues found.
- Patch 7 ("KVM: s390: arm64: Enable full smccc support"): 2 potential issues (1 Medium, 1 Low)
- Patch 9 ("KVM: s390: arm64: Provide timer infrastructure"): 1 potential issue (1 Low)
- Patch 10 ("KVM: s390: arm64: Integrate guest timer"): 1 potential issue (1 Low)
- Patch 12 ("KVM: s390: arm64: Add IRQ line"): 1 potential issue (1 Medium)
Detailed reviews have been sent as separate replies to patches 7, 9, 10, and 12.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]