All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>,
	Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH 03/14] powerpc/64s/exception: machine check fix KVM guest test
Date: Wed,  3 Jul 2019 17:54:33 +1000	[thread overview]
Message-ID: <20190703075444.19005-4-npiggin@gmail.com> (raw)
In-Reply-To: <20190703075444.19005-1-npiggin@gmail.com>

The machine_check_handle_early hypervisor guest test is skipped if
!HVMODE or MSR[HV]=0, which is wrong for PR or nested hypervisors
that could be running a guest in this state.

Test HSTATE_IN_GUEST up front and use that to branch out to the KVM
handler, then MSR[PR] alone can test for this kernel's userspace.
This matches all other interrupt handling.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/exceptions-64s.S | 33 +++++++++++-----------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index e8734a1dfdb9..5789a00691f9 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -1108,11 +1108,8 @@ EXC_COMMON_BEGIN(machine_check_handle_early)
 	bl	machine_check_early
 	std	r3,RESULT(r1)	/* Save result */
 	ld	r12,_MSR(r1)
-BEGIN_FTR_SECTION
-	b	4f
-END_FTR_SECTION_IFCLR(CPU_FTR_HVMODE)
 
-#ifdef	CONFIG_PPC_P7_NAP
+#ifdef CONFIG_PPC_P7_NAP
 	/*
 	 * Check if thread was in power saving mode. We come here when any
 	 * of the following is true:
@@ -1128,30 +1125,26 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_HVMODE | CPU_FTR_ARCH_206)
 #endif
 
-	/*
-	 * Check if we are coming from hypervisor userspace. If yes then we
-	 * continue in host kernel in V mode to deliver the MC event.
-	 */
-	rldicl.	r11,r12,4,63		/* See if MC hit while in HV mode. */
-	beq	5f
-4:	andi.	r11,r12,MSR_PR		/* See if coming from user. */
-	bne	9f			/* continue in V mode if we are. */
-
-5:
 #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
-BEGIN_FTR_SECTION
 	/*
-	 * We are coming from kernel context. Check if we are coming from
-	 * guest. if yes, then we can continue. We will fall through
-	 * do_kvm_200->kvmppc_interrupt to deliver the MC event to guest.
+	 * Check if we are coming from guest. If yes, then run the normal
+	 * exception handler which will take the do_kvm_200->kvmppc_interrupt
+	 * branch to deliver the MC event to guest.
 	 */
 	lbz	r11,HSTATE_IN_GUEST(r13)
 	cmpwi	r11,0			/* Check if coming from guest */
 	bne	9f			/* continue if we are. */
-END_FTR_SECTION_IFSET(CPU_FTR_HVMODE)
 #endif
+
+	/*
+	 * Check if we are coming from userspace. If yes, then run the normal
+	 * exception handler which will deliver the MC event to this kernel.
+	 */
+	andi.	r11,r12,MSR_PR		/* See if coming from user. */
+	bne	9f			/* continue in V mode if we are. */
+
 	/*
-	 * At this point we are not sure about what context we come from.
+	 * At this point we are coming from kernel context.
 	 * Queue up the MCE event and return from the interrupt.
 	 * But before that, check if this is an un-recoverable exception.
 	 * If yes, then stay on emergency stack and panic.
-- 
2.20.1


  parent reply	other threads:[~2019-07-03  8:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03  7:54 [PATCH 00/14] powerpc/64s/exception: machine check cleanup series Nicholas Piggin
2019-07-03  7:54 ` [PATCH 01/14] powerpc/64s/exception: machine check fwnmi remove HV case Nicholas Piggin
2019-07-03  7:54 ` [PATCH 02/14] powerpc/64s/exception: machine check remove bitrotted comment Nicholas Piggin
2019-07-03  7:54 ` Nicholas Piggin [this message]
2019-07-03  7:54 ` [PATCH 04/14] powerpc/64s/exception: machine check adjust RFI target Nicholas Piggin
2019-07-03  7:54 ` [PATCH 05/14] powerpc/64s/exception: machine check pseries should always run the early handler Nicholas Piggin
2019-07-03  7:54 ` [PATCH 06/14] powerpc/64s/exception: machine check remove machine_check_pSeries_0 branch Nicholas Piggin
2019-07-03  7:54 ` [PATCH 07/14] powerpc/64s/exception: machine check use correct cfar for late handler Nicholas Piggin
2019-07-03  7:54 ` [PATCH 08/14] powerpc/64s/exception: machine check pseries should skip the late handler for host kernel MCEs Nicholas Piggin
2019-07-03  7:54 ` [PATCH 09/14] powerpc/64s/exception: machine check restructure to reuse common macros Nicholas Piggin
2019-07-03  7:54 ` [PATCH 10/14] powerpc/64s/exception: machine check move tramp code Nicholas Piggin
2019-07-03  7:54 ` [PATCH 11/14] powerpc/64s/exception: simplify machine check early path Nicholas Piggin
2019-07-03  7:54 ` [PATCH 12/14] powerpc/64s/exception: machine check move unrecoverable handling out of line Nicholas Piggin
2019-07-03  7:54 ` [PATCH 13/14] powerpc/64s/exception: untangle early machine check handler branch Nicholas Piggin
2019-07-03  7:54 ` [PATCH 14/14] powerpc/64s/exception: machine check improve labels and comments Nicholas Piggin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190703075444.19005-4-npiggin@gmail.com \
    --to=npiggin@gmail.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mahesh@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.