linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] powerpc: misc interrupt and context tracking
@ 2022-10-14  3:07 Nicholas Piggin
  2022-10-14  3:07 ` [PATCH v2 1/2] KVM: PPC: BookS PR-KVM and BookE do not support " Nicholas Piggin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nicholas Piggin @ 2022-10-14  3:07 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Nicholas Piggin

These are several fixes for regressions and crash bugs. Since v1
I cut down the fixes to a minimum.

Thanks,
Nick

Nicholas Piggin (2):
  KVM: PPC: BookS PR-KVM and BookE do not support context tracking
  powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning

 arch/powerpc/kernel/exceptions-64e.S |  7 +++++++
 arch/powerpc/kernel/exceptions-64s.S |  7 +++++++
 arch/powerpc/kernel/interrupt.c      | 12 +++++++++---
 arch/powerpc/kvm/Kconfig             |  4 ++++
 4 files changed, 27 insertions(+), 3 deletions(-)

-- 
2.37.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] KVM: PPC: BookS PR-KVM and BookE do not support context tracking
  2022-10-14  3:07 [PATCH v2 0/2] powerpc: misc interrupt and context tracking Nicholas Piggin
@ 2022-10-14  3:07 ` Nicholas Piggin
  2022-10-14  3:07 ` [PATCH v2 2/2] powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning Nicholas Piggin
  2022-10-28 11:49 ` [PATCH v2 0/2] powerpc: misc interrupt and context tracking Michael Ellerman
  2 siblings, 0 replies; 4+ messages in thread
From: Nicholas Piggin @ 2022-10-14  3:07 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Nicholas Piggin

The context tracking code in PR-KVM and BookE implementations is not
complete, and can cause host crashes if context tracking is enabled.

Make these implementations depend on !CONTEXT_TRACKING_USER.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/Kconfig | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig
index 61cdd782d3c5..a9f57dad6d91 100644
--- a/arch/powerpc/kvm/Kconfig
+++ b/arch/powerpc/kvm/Kconfig
@@ -51,6 +51,7 @@ config KVM_BOOK3S_HV_POSSIBLE
 config KVM_BOOK3S_32
 	tristate "KVM support for PowerPC book3s_32 processors"
 	depends on PPC_BOOK3S_32 && !SMP && !PTE_64BIT
+	depends on !CONTEXT_TRACKING_USER
 	select KVM
 	select KVM_BOOK3S_32_HANDLER
 	select KVM_BOOK3S_PR_POSSIBLE
@@ -105,6 +106,7 @@ config KVM_BOOK3S_64_HV
 config KVM_BOOK3S_64_PR
 	tristate "KVM support without using hypervisor mode in host"
 	depends on KVM_BOOK3S_64
+	depends on !CONTEXT_TRACKING_USER
 	select KVM_BOOK3S_PR_POSSIBLE
 	help
 	  Support running guest kernels in virtual machines on processors
@@ -190,6 +192,7 @@ config KVM_EXIT_TIMING
 config KVM_E500V2
 	bool "KVM support for PowerPC E500v2 processors"
 	depends on PPC_E500 && !PPC_E500MC
+	depends on !CONTEXT_TRACKING_USER
 	select KVM
 	select KVM_MMIO
 	select MMU_NOTIFIER
@@ -205,6 +208,7 @@ config KVM_E500V2
 config KVM_E500MC
 	bool "KVM support for PowerPC E500MC/E5500/E6500 processors"
 	depends on PPC_E500MC
+	depends on !CONTEXT_TRACKING_USER
 	select KVM
 	select KVM_MMIO
 	select KVM_BOOKE_HV
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning
  2022-10-14  3:07 [PATCH v2 0/2] powerpc: misc interrupt and context tracking Nicholas Piggin
  2022-10-14  3:07 ` [PATCH v2 1/2] KVM: PPC: BookS PR-KVM and BookE do not support " Nicholas Piggin
@ 2022-10-14  3:07 ` Nicholas Piggin
  2022-10-28 11:49 ` [PATCH v2 0/2] powerpc: misc interrupt and context tracking Michael Ellerman
  2 siblings, 0 replies; 4+ messages in thread
From: Nicholas Piggin @ 2022-10-14  3:07 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Nicholas Piggin

NMI PMIs really should not return using the normal interrupt_return
function. If such a PMI hits in code returning to user with the context
switched to user mode, this warning can fire. This was enough to cause
crashes when reproducing on 64s, because another perf interrupt would
hit while reporting bug, and that would cause another bug, and so on
until smashing the stack.

Work around that particular crash for now by just disabling that context
warning for PMIs. This is a hack and not a complete fix, there could be
other such problems lurking in corners. But it does fix the known crash.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/exceptions-64e.S |  7 +++++++
 arch/powerpc/kernel/exceptions-64s.S |  7 +++++++
 arch/powerpc/kernel/interrupt.c      | 12 +++++++++---
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
index 930e36099015..2f68fb2ee4fc 100644
--- a/arch/powerpc/kernel/exceptions-64e.S
+++ b/arch/powerpc/kernel/exceptions-64e.S
@@ -813,6 +813,13 @@ kernel_dbg_exc:
 	EXCEPTION_COMMON(0x260)
 	CHECK_NAPPING()
 	addi	r3,r1,STACK_FRAME_OVERHEAD
+	/*
+	 * XXX: Returning from performance_monitor_exception taken as a
+	 * soft-NMI (Linux irqs disabled) may be risky to use interrupt_return
+	 * and could cause bugs in return or elsewhere. That case should just
+	 * restore registers and return. There is a workaround for one known
+	 * problem in interrupt_exit_kernel_prepare().
+	 */
 	bl	performance_monitor_exception
 	b	interrupt_return
 
diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
index 5381a43e50fe..7ca55ac7bb87 100644
--- a/arch/powerpc/kernel/exceptions-64s.S
+++ b/arch/powerpc/kernel/exceptions-64s.S
@@ -2357,6 +2357,13 @@ EXC_VIRT_END(performance_monitor, 0x4f00, 0x20)
 EXC_COMMON_BEGIN(performance_monitor_common)
 	GEN_COMMON performance_monitor
 	addi	r3,r1,STACK_FRAME_OVERHEAD
+	/*
+	 * XXX: Returning from performance_monitor_exception taken as a
+	 * soft-NMI (Linux irqs disabled) may be risky to use interrupt_return
+	 * and could cause bugs in return or elsewhere. That case should just
+	 * restore registers and return. There is a workaround for one known
+	 * problem in interrupt_exit_kernel_prepare().
+	 */
 	bl	performance_monitor_exception
 	b	interrupt_return_srr
 
diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index f9db0a172401..7bc93367de68 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -374,10 +374,16 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
 	if (regs_is_unrecoverable(regs))
 		unrecoverable_exception(regs);
 	/*
-	 * CT_WARN_ON comes here via program_check_exception,
-	 * so avoid recursion.
+	 * CT_WARN_ON comes here via program_check_exception, so avoid
+	 * recursion.
+	 *
+	 * Skip the assertion on PMIs to work around a problem caused by NMI
+	 * PMIs incorrectly taking this interrupt return path, it's possible
+	 * for this to hit after interrupt exit to user switches context to
+	 * user. See also the comment in the performance monitor handler in
+	 * exceptions-64e/s.S
 	 */
-	if (TRAP(regs) != INTERRUPT_PROGRAM)
+	if (TRAP(regs) != INTERRUPT_PROGRAM && TRAP(regs) != INTERRUPT_PERFMON)
 		CT_WARN_ON(ct_state() == CONTEXT_USER);
 
 	kuap = kuap_get_and_assert_locked();
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] powerpc: misc interrupt and context tracking
  2022-10-14  3:07 [PATCH v2 0/2] powerpc: misc interrupt and context tracking Nicholas Piggin
  2022-10-14  3:07 ` [PATCH v2 1/2] KVM: PPC: BookS PR-KVM and BookE do not support " Nicholas Piggin
  2022-10-14  3:07 ` [PATCH v2 2/2] powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning Nicholas Piggin
@ 2022-10-28 11:49 ` Michael Ellerman
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2022-10-28 11:49 UTC (permalink / raw)
  To: linuxppc-dev, Nicholas Piggin

On Fri, 14 Oct 2022 13:07:27 +1000, Nicholas Piggin wrote:
> These are several fixes for regressions and crash bugs. Since v1
> I cut down the fixes to a minimum.
> 
> Thanks,
> Nick
> 
> Nicholas Piggin (2):
>   KVM: PPC: BookS PR-KVM and BookE do not support context tracking
>   powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning
> 
> [...]

Applied to powerpc/fixes.

[1/2] KVM: PPC: BookS PR-KVM and BookE do not support context tracking
      https://git.kernel.org/powerpc/c/e59b3399fde5e173b026d4952b215043e77b4521
[2/2] powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning
      https://git.kernel.org/powerpc/c/a073672eb09670540e95a2a4aa1c46f5da74159f

cheers

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-28 11:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-14  3:07 [PATCH v2 0/2] powerpc: misc interrupt and context tracking Nicholas Piggin
2022-10-14  3:07 ` [PATCH v2 1/2] KVM: PPC: BookS PR-KVM and BookE do not support " Nicholas Piggin
2022-10-14  3:07 ` [PATCH v2 2/2] powerpc/64/interrupt: Prevent NMI PMI causing a dangerous warning Nicholas Piggin
2022-10-28 11:49 ` [PATCH v2 0/2] powerpc: misc interrupt and context tracking Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).