All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm
@ 2022-01-24 14:39 Nicholas Piggin
  2022-01-24 14:39 ` [PATCH 2/3] powerpc/time: Fix KVM host re-arming a timer beyond decrementer range Nicholas Piggin
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Nicholas Piggin @ 2022-01-24 14:39 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Alexey Kardashevskiy, Nicholas Piggin

The decrementer exception can fail to be cleared when the interrupt
returns in the case where the decrementer wraps with the next timer
still beyond decrementer_max. This results in a decrementer interrupt
storm. This is triggerable with small decrementer system with hard
and soft watchdogs disabled.

Fix this by always programming the decrementer if there was no timer.

Fixes: 0faf20a1ad16 ("powerpc/64s/interrupt: Don't enable MSR[EE] in irq handlers unless perf is in use")
Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/time.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 62361cc7281c..cd0b8b71ecdd 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -649,8 +649,9 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(timer_interrupt)
 		__this_cpu_inc(irq_stat.timer_irqs_event);
 	} else {
 		now = *next_tb - now;
-		if (now <= decrementer_max)
-			set_dec_or_work(now);
+		if (now > decrementer_max)
+			now = decrementer_max;
+		set_dec_or_work(now);
 		__this_cpu_inc(irq_stat.timer_irqs_others);
 	}
 
-- 
2.23.0


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

* [PATCH 2/3] powerpc/time: Fix KVM host re-arming a timer beyond decrementer range
  2022-01-24 14:39 [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Nicholas Piggin
@ 2022-01-24 14:39 ` Nicholas Piggin
  2022-01-24 14:39 ` [PATCH 3/3] powerpc/time: improve decrementer clockevent processing Nicholas Piggin
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Nicholas Piggin @ 2022-01-24 14:39 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Alexey Kardashevskiy, Nicholas Piggin

If the next host timer is beyond decrementer range, timer_rearm_host_dec
will leave decrementer not programmed. This will not cause a problem for
the host it will just set the decrementer correctly when the decrementer
interrupt hits, it seems safer not to leave the next host decrementer
interrupt timing able to be influenced by a guest.

This code is only used in the P9 KVM paths so it's unlikely to be hit
practically unless large decrementer is force disabled in the host.

Fixes: 25aa145856cd ("powerpc/time: add API for KVM to re-arm the host timer/decrementer")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/time.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index cd0b8b71ecdd..384f58a3f373 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -582,8 +582,9 @@ void timer_rearm_host_dec(u64 now)
 		local_paca->irq_happened |= PACA_IRQ_DEC;
 	} else {
 		now = *next_tb - now;
-		if (now <= decrementer_max)
-			set_dec_or_work(now);
+		if (now > decrementer_max)
+			now = decrementer_max;
+		set_dec_or_work(now);
 	}
 }
 EXPORT_SYMBOL_GPL(timer_rearm_host_dec);
-- 
2.23.0


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

* [PATCH 3/3] powerpc/time: improve decrementer clockevent processing
  2022-01-24 14:39 [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Nicholas Piggin
  2022-01-24 14:39 ` [PATCH 2/3] powerpc/time: Fix KVM host re-arming a timer beyond decrementer range Nicholas Piggin
@ 2022-01-24 14:39 ` Nicholas Piggin
  2022-01-29 11:14 ` (subset) [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Michael Ellerman
  2022-03-21  5:05 ` Michael Ellerman
  3 siblings, 0 replies; 5+ messages in thread
From: Nicholas Piggin @ 2022-01-24 14:39 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Alexey Kardashevskiy, Nicholas Piggin

The stop/shutdown op should not use decrementer_set_next_event because
that sets decrementers_next_tb to now + decrementer_max, which means a
decrementer interrupt that occurs after that time will call the
clockevent event handler unexpectedly. Set next_tb to ~0 here to prevent
any clock event call. Init all clockevents to stopped.

Then the decrementer clockevent device always has event_handler set and
applicable because we know the clock event device was not stopped. So
make this call unconditional to show that it is always called. next_tb
need not be set to ~0 before the event handler is called because it will
stop the clockevent device if there is no other timer.

Finally, the timer broadcast interrupt should not modify next_tb because
it is not involved with the local decrementer clockevent on this CPU.

This doesn't fix a known bug, just tidies the code.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kernel/time.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 384f58a3f373..f3845601ab6a 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -107,7 +107,12 @@ struct clock_event_device decrementer_clockevent = {
 };
 EXPORT_SYMBOL(decrementer_clockevent);
 
-DEFINE_PER_CPU(u64, decrementers_next_tb);
+/*
+ * This always puts next_tb beyond now, so the clock event will never fire
+ * with the usual comparison, no need for a separate test for stopped.
+ */
+#define DEC_CLOCKEVENT_STOPPED ~0ULL
+DEFINE_PER_CPU(u64, decrementers_next_tb) = DEC_CLOCKEVENT_STOPPED;
 EXPORT_SYMBOL_GPL(decrementers_next_tb);
 static DEFINE_PER_CPU(struct clock_event_device, decrementers);
 
@@ -644,9 +649,7 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(timer_interrupt)
 
 	now = get_tb();
 	if (now >= *next_tb) {
-		*next_tb = ~(u64)0;
-		if (evt->event_handler)
-			evt->event_handler(evt);
+		evt->event_handler(evt);
 		__this_cpu_inc(irq_stat.timer_irqs_event);
 	} else {
 		now = *next_tb - now;
@@ -665,9 +668,6 @@ EXPORT_SYMBOL(timer_interrupt);
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 void timer_broadcast_interrupt(void)
 {
-	u64 *next_tb = this_cpu_ptr(&decrementers_next_tb);
-
-	*next_tb = ~(u64)0;
 	tick_receive_broadcast();
 	__this_cpu_inc(irq_stat.broadcast_irqs_event);
 }
@@ -893,7 +893,9 @@ static int decrementer_set_next_event(unsigned long evt,
 
 static int decrementer_shutdown(struct clock_event_device *dev)
 {
-	decrementer_set_next_event(decrementer_max, dev);
+	__this_cpu_write(decrementers_next_tb, DEC_CLOCKEVENT_STOPPED);
+	set_dec_or_work(decrementer_max);
+
 	return 0;
 }
 
-- 
2.23.0


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

* Re: (subset) [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm
  2022-01-24 14:39 [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Nicholas Piggin
  2022-01-24 14:39 ` [PATCH 2/3] powerpc/time: Fix KVM host re-arming a timer beyond decrementer range Nicholas Piggin
  2022-01-24 14:39 ` [PATCH 3/3] powerpc/time: improve decrementer clockevent processing Nicholas Piggin
@ 2022-01-29 11:14 ` Michael Ellerman
  2022-03-21  5:05 ` Michael Ellerman
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2022-01-29 11:14 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev; +Cc: Alexey Kardashevskiy

On Tue, 25 Jan 2022 00:39:28 +1000, Nicholas Piggin wrote:
> The decrementer exception can fail to be cleared when the interrupt
> returns in the case where the decrementer wraps with the next timer
> still beyond decrementer_max. This results in a decrementer interrupt
> storm. This is triggerable with small decrementer system with hard
> and soft watchdogs disabled.
> 
> Fix this by always programming the decrementer if there was no timer.
> 
> [...]

Patch 1 applied to powerpc/fixes.

[1/3] powerpc/64s/interrupt: Fix decrementer storm
      https://git.kernel.org/powerpc/c/8defc2a5dd8f4c0cb19ecbaca8d3e89ab98524da

cheers

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

* Re: [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm
  2022-01-24 14:39 [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Nicholas Piggin
                   ` (2 preceding siblings ...)
  2022-01-29 11:14 ` (subset) [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Michael Ellerman
@ 2022-03-21  5:05 ` Michael Ellerman
  3 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2022-03-21  5:05 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev; +Cc: Alexey Kardashevskiy

On Tue, 25 Jan 2022 00:39:28 +1000, Nicholas Piggin wrote:
> The decrementer exception can fail to be cleared when the interrupt
> returns in the case where the decrementer wraps with the next timer
> still beyond decrementer_max. This results in a decrementer interrupt
> storm. This is triggerable with small decrementer system with hard
> and soft watchdogs disabled.
> 
> Fix this by always programming the decrementer if there was no timer.
> 
> [...]

Patch 2 & 3 applied to powerpc/next.

[2/3] powerpc/time: Fix KVM host re-arming a timer beyond decrementer range
      https://git.kernel.org/powerpc/c/cf74ff52e352112be78c4c4c3637a37ec36a6608
[3/3] powerpc/time: improve decrementer clockevent processing
      https://git.kernel.org/powerpc/c/35de589cb8793573ed56a915af9cb4b5f15ad7d7

cheers

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

end of thread, other threads:[~2022-03-21  5:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 14:39 [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Nicholas Piggin
2022-01-24 14:39 ` [PATCH 2/3] powerpc/time: Fix KVM host re-arming a timer beyond decrementer range Nicholas Piggin
2022-01-24 14:39 ` [PATCH 3/3] powerpc/time: improve decrementer clockevent processing Nicholas Piggin
2022-01-29 11:14 ` (subset) [PATCH 1/3] powerpc/64s/interrupt: Fix decrementer storm Michael Ellerman
2022-03-21  5:05 ` Michael Ellerman

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.