From: Steffen Eiden Manage the host interrupt mask directly in assembly. Remove the temporary raw_local_irq enable/ disable workaround from C code to prepare to eliminate entry/exit races later. Add a pointer to the current vCPU, SAE control block, and an IRQ state slot to the SAE stack frame. The vCPU pointer can be used by s390 kernel handlers to forward work to the arm on s390 module. The control block can be used for correctly handling perf events for SAE guests. The IRQ stack slot is used by the stosm/stnsm instructions to enable and disable interrupts around SAE execution like SIE does. Co-developed-by: Sven Schnelle Signed-off-by: Sven Schnelle Signed-off-by: Steffen Eiden Co-developed-by: Andreas Grapentin Signed-off-by: Andreas Grapentin Acked-by: Heiko Carstens --- arch/s390/include/asm/sae.h | 2 +- arch/s390/include/asm/stacktrace.h | 3 +++ arch/s390/kernel/asm-offsets.c | 3 +++ arch/s390/kernel/entry.S | 11 ++++++++++- arch/s390/kvm/arm64/arm.c | 18 ++++-------------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/s390/include/asm/sae.h b/arch/s390/include/asm/sae.h index d1b9af770108..fd3f042fb497 100644 --- a/arch/s390/include/asm/sae.h +++ b/arch/s390/include/asm/sae.h @@ -9,7 +9,7 @@ #ifndef __ASSEMBLER__ /* defined in arch/s390/kernel/entry.S */ -asmlinkage void sae(phys_addr_t sae_block_phys); +asmlinkage void sae(phys_addr_t sae_block_phys, void *sae_block, void *vcpu); #include #include diff --git a/arch/s390/include/asm/stacktrace.h b/arch/s390/include/asm/stacktrace.h index 2d332d7c8145..d0cc948444d6 100644 --- a/arch/s390/include/asm/stacktrace.h +++ b/arch/s390/include/asm/stacktrace.h @@ -72,6 +72,9 @@ struct stack_frame { /* SAE stack frame */ struct { unsigned long sae_bear; + unsigned long sae_block; + unsigned long sae_vcpu; + unsigned long sae_irq; }; }; unsigned long gprs[10]; diff --git a/arch/s390/kernel/asm-offsets.c b/arch/s390/kernel/asm-offsets.c index f9f9c2246074..e09158248248 100644 --- a/arch/s390/kernel/asm-offsets.c +++ b/arch/s390/kernel/asm-offsets.c @@ -71,6 +71,9 @@ int main(void) OFFSET(__SF_SIE_GUEST_ASCE, stack_frame, sie_guest_asce); OFFSET(__SF_SIE_IRQ, stack_frame, sie_irq); OFFSET(__SF_SAE_BEAR, stack_frame, sae_bear); + OFFSET(__SF_SAE_BLOCK, stack_frame, sae_block); + OFFSET(__SF_SAE_VCPU, stack_frame, sae_vcpu); + OFFSET(__SF_SAE_IRQ, stack_frame, sae_irq); DEFINE(STACK_FRAME_OVERHEAD, sizeof(struct stack_frame)); BLANK(); OFFSET(__SFUSER_BACKCHAIN, stack_frame_user, back_chain); diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S index 999dc7d0c637..14dea207b30e 100644 --- a/arch/s390/kernel/entry.S +++ b/arch/s390/kernel/entry.S @@ -248,12 +248,21 @@ EXPORT_SYMBOL(sie_exit) #if IS_ENABLED(CONFIG_KVM) /* * SAE calling convention: - * %r2 physical address of the SAE control block + * %r2 pointer to sae control block phys + * %r3 pointer to sae control block virt + * %r4 vcpu pointer */ SYM_FUNC_START(sae) stmg %r6,%r14,__SF_GPRS(%r15) # store kernel registers STBEAR __SF_SAE_BEAR(%r15) # save breaking event address register + stg %r3,__SF_SAE_BLOCK(%r15) # save sae block for perf + stg %r4,__SF_SAE_VCPU(%r15) # save vcpu ptr for interrupt handling + stosm __SF_SAE_IRQ(%r15),0x03 .insn rre,0xb9a50000,%r2,0 # Start Arm Execution +# Let the next instruction be NOP to avoid triggering a machine check +# and handling it in a guest as result of the instruction execution. + nopr 7 + stnsm __SF_SAE_IRQ(%r15),0xfc LBEAR __SF_SAE_BEAR(%r15) # restore breaking event address register lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers xgr %r0,%r0 # clear guest registers to diff --git a/arch/s390/kvm/arm64/arm.c b/arch/s390/kvm/arm64/arm.c index cd59a382a70c..547f77be7e3c 100644 --- a/arch/s390/kvm/arm64/arm.c +++ b/arch/s390/kvm/arm64/arm.c @@ -425,23 +425,13 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level, return -EINVAL; } -static noinstr void arm_vcpu_enter_exit(phys_addr_t sae_block) +static noinstr void arm_vcpu_enter_exit(struct kvm_sae_block *sae_block, + struct kvm_vcpu *vcpu) { guest_timing_enter_irqoff(); guest_state_enter_irqoff(); - /* - * External interrupts may occur while the SAE instruction is executing - * and must preempt guest execution to maintain responsiveness of the - * host. - * - * As a temporary workaround, run SAE with interrupts enabled so that any - * interrupt is taken via the normal host interrupt path rather than - * being subsumed inside the SAE window. - */ - raw_local_irq_enable(); - sae(sae_block); - raw_local_irq_disable(); + sae(virt_to_phys(sae_block), sae_block, vcpu); guest_state_exit_irqoff(); guest_timing_exit_irqoff(); @@ -522,7 +512,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) _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); - arm_vcpu_enter_exit(virt_to_phys(&vcpu->arch.sae_block)); + arm_vcpu_enter_exit(&vcpu->arch.sae_block, 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); -- 2.55.0