From patchwork Sun Nov 5 12:33:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 834340 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=kvm-ppc-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oSnABygu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yVFVm1nfpz9t2c for ; Sun, 5 Nov 2017 23:34:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750914AbdKEMeH (ORCPT ); Sun, 5 Nov 2017 07:34:07 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:44795 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750725AbdKEMeF (ORCPT ); Sun, 5 Nov 2017 07:34:05 -0500 Received: by mail-pf0-f195.google.com with SMTP id x7so5698266pfa.1 for ; Sun, 05 Nov 2017 04:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=sMOVy+PlYRKjvyfrAerW0PAhvx2WdeiRoa5y2pP4RGg=; b=oSnAByguMTrWjd8Zb19/qxFjabhq6YyoL1gCgjvxf5FsWwrx7utp49lmB9vRsL74tL PefxrUykkuPq++Tgm4dS4X2sN2kIkUaF/QvnxutDviqC6qJEL2eCQYomcfaJj+t3IhRK S6vFt71I5kSPPtmDgI9vbPvteKYoQrTBJFHFiH+asfOV7FDZucICpDz+hTU6HZFOwxqE 6xAv99Lh09wMClk1aP0BGvWZUvyhqNpMbOLKBFdbVcDy6UTrhBwzejp6D5vkupaG1bCF xC2krTQVoIzzH7AARzEagbDfGyadzvxzN8z+35jKNAU3jIfuOjoDi8ZHYAbP7kqc8ViR 6XNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sMOVy+PlYRKjvyfrAerW0PAhvx2WdeiRoa5y2pP4RGg=; b=XrHdfy2mBZMGfsPfZ7gvJsRzztlHY5pHaun6qab06qLAK9OTwtqemmcXQBbX4bEkAs 7ycVt7IjI1E1eoXMmwIaU1E2ubskN3axWEYLt6JFPA47NoBKVEVut42Vtu1JqBq5Z15d xNTJDmxyZV05TocqVeEnSIZ5RxBqJO0i12O+8jCpxnoFjwornvD31BpJuDitra9L99D7 GFrECY+Z7ccpTZzwGNTEr2mCm8fVagVgfuP40FigPgAAzOwatlIKUaOGoAHJDvYoUjzx C13y+6EFxsC+ztxVZ/aWfdcCy7sbIvpYMzgTQsmEGIt11HUmpAUikdH4QPGYYkozSGBg 27zg== X-Gm-Message-State: AMCzsaW+BvL8hbjh8Rpa1qhVOL1zlnqwp7WiWpfYrCPk6PgoDgXgnbW3 X2UyUf1Ku3ZShjJfOeAwRTM= X-Google-Smtp-Source: ABhQp+R34sa4FasaAk0LfIa0Kf618NIoIq6W0keoSOdKS/uDtPlmQ1raSDfAS2Oc3l9hKyKXj9ZmQg== X-Received: by 10.84.232.138 with SMTP id i10mr12262164plk.104.1509885245356; Sun, 05 Nov 2017 04:34:05 -0800 (PST) Received: from roar.au.ibm.com (38.30.218.139.dynamic.dsl.dv.iprimus.net.au. [139.218.30.38]) by smtp.gmail.com with ESMTPSA id r22sm20161296pfl.15.2017.11.05.04.34.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Nov 2017 04:34:04 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Cc: Nicholas Piggin , Paul Mackerras , kvm-ppc@vger.kernel.org Subject: [PATCH] KVM: PPC: Book3S HV: Handle host system reset in guest mode Date: Sun, 5 Nov 2017 23:33:55 +1100 Message-Id: <20171105123355.3014-1-npiggin@gmail.com> X-Mailer: git-send-email 2.15.0 Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org If the host takes a system reset interrupt while a guest is running, the CPU must exit the guest before processing the host exception handler. After this patch, taking a sysrq+x with a CPU running in a guest gives a trace like this: cpu 0x27: Vector: 100 (System Reset) at [c000000fdf5776f0] pc: c008000010158b80: kvmppc_run_core+0x16b8/0x1ad0 [kvm_hv] lr: c008000010158b80: kvmppc_run_core+0x16b8/0x1ad0 [kvm_hv] sp: c000000fdf577850 msr: 9000000002803033 current = 0xc000000fdf4b1e00 paca = 0xc00000000fd4d680 softe: 3 irq_happened: 0x01 pid = 6608, comm = qemu-system-ppc Linux version 4.14.0-rc7-01489-g47e1893a404a-dirty #26 SMP [c000000fdf577a00] c008000010159dd4 kvmppc_vcpu_run_hv+0x3dc/0x12d0 [kvm_hv] [c000000fdf577b30] c0080000100a537c kvmppc_vcpu_run+0x44/0x60 [kvm] [c000000fdf577b60] c0080000100a1ae0 kvm_arch_vcpu_ioctl_run+0x118/0x310 [kvm] [c000000fdf577c00] c008000010093e98 kvm_vcpu_ioctl+0x530/0x7c0 [kvm] [c000000fdf577d50] c000000000357bf8 do_vfs_ioctl+0xd8/0x8c0 [c000000fdf577df0] c000000000358448 SyS_ioctl+0x68/0x100 [c000000fdf577e30] c00000000000b220 system_call+0x58/0x6c --- Exception: c01 (System Call) at 00007fff76868df0 SP (7fff7069baf0) is in userspace Fixes: e36d0a2ed5 ("powerpc/powernv: Implement NMI IPI with OPAL_SIGNAL_SYSTEM_RESET") Signed-off-by: Nicholas Piggin --- It has always been possible to sreset the host with direct scom access, but the patch e36d0a2ed5 has significantly expanded this functionality so in practice this is a required as a fix for it. Since RFC: - Removed the last hunk as sugggested by Paul. - Re-tested. Thanks, Nick --- arch/powerpc/include/asm/hw_irq.h | 1 + arch/powerpc/kernel/exceptions-64s.S | 2 ++ arch/powerpc/kernel/irq.c | 3 ++- arch/powerpc/kvm/book3s_hv.c | 7 ++++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h index 92a3e9a79cb4..a8bbac425ae6 100644 --- a/arch/powerpc/include/asm/hw_irq.h +++ b/arch/powerpc/include/asm/hw_irq.h @@ -40,6 +40,7 @@ #ifndef __ASSEMBLY__ +extern void replay_system_reset(void); extern void __replay_interrupt(unsigned int vector); extern void timer_interrupt(struct pt_regs *); diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index 651e1a0114ed..bff2ed6e3c3c 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -113,6 +113,7 @@ EXC_VIRT_NONE(0x4000, 0x100) cmpwi cr3,r10,2 ; \ BRANCH_TO_C000(r10, system_reset_idle_common) ; \ 1: \ + KVMTEST_PR(n) ; \ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206) #else #define IDLETEST NOTEST @@ -129,6 +130,7 @@ EXC_REAL_BEGIN(system_reset, 0x100, 0x100) EXC_REAL_END(system_reset, 0x100, 0x100) EXC_VIRT_NONE(0x4100, 0x100) +TRAMP_KVM(PACA_EXNMI, 0x100) #ifdef CONFIG_PPC_P7_NAP EXC_COMMON_BEGIN(system_reset_idle_common) diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c index efbadcbbf694..7e8259106944 100644 --- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c @@ -437,7 +437,7 @@ static const u8 srr1_to_lazyirq[0x10] = { PACA_IRQ_HMI, 0, 0, 0, 0, 0 }; -static noinline void replay_system_reset(void) +void replay_system_reset(void) { struct pt_regs regs; @@ -447,6 +447,7 @@ static noinline void replay_system_reset(void) system_reset_exception(®s); get_paca()->in_nmi = 0; } +EXPORT_SYMBOL_GPL(replay_system_reset); void irq_set_pending_from_srr1(unsigned long srr1) { diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c index 8f34715cfbff..31a362669fea 100644 --- a/arch/powerpc/kvm/book3s_hv.c +++ b/arch/powerpc/kvm/book3s_hv.c @@ -47,6 +47,7 @@ #include #include +#include #include #include #include @@ -1089,9 +1090,10 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, vcpu->stat.ext_intr_exits++; r = RESUME_GUEST; break; - /* HMI is hypervisor interrupt and host has handled it. Resume guest.*/ + /* SR/HMI/PMI are HV interrupts that host has handled. Resume guest.*/ case BOOK3S_INTERRUPT_HMI: case BOOK3S_INTERRUPT_PERFMON: + case BOOK3S_INTERRUPT_SYSTEM_RESET: r = RESUME_GUEST; break; case BOOK3S_INTERRUPT_MACHINE_CHECK: @@ -2604,6 +2606,9 @@ static void set_irq_happened(int trap) case BOOK3S_INTERRUPT_HMI: local_paca->irq_happened |= PACA_IRQ_HMI; break; + case BOOK3S_INTERRUPT_SYSTEM_RESET: + replay_system_reset(); + break; } }