All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tick: Fix hang caused by hrtimer in broadcast mode
@ 2015-04-24 13:06 Andreas Sandberg
  2015-04-25  2:34 ` Preeti U Murthy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andreas Sandberg @ 2015-04-24 13:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andreas Sandberg, Thomas Gleixner, Preeti U Murthy, stable,
	Catalin Marinas, Mark Rutland

The hrtimer callback in the hrtimer's tick broadcast code sometimes
incorrectly ends up scheduling events at the current tick causing the
kernel to hang servicing the same hrtimer forever. This typically
happens when a device is swapped out by
tick_install_broadcast_device(), which replaces the event handler with
clock_events_handle_noop() and sets the device mode to
CLOCK_EVT_MODE_UNUSED. If the timer is scheduled when this happens,
the next_event field will not be updated and the hrtimer ends up being
restarted at the current tick. To prevent this from happening, only
try to restart the hrtimer if the broadcast clock event device is in
one of the active modes and try to cancel the timer when entering the
CLOCK_EVT_MODE_UNUSED mode.

Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Catalin Marinas <catalin.marinas@arm.com>
---
 kernel/time/tick-broadcast-hrtimer.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/kernel/time/tick-broadcast-hrtimer.c b/kernel/time/tick-broadcast-hrtimer.c
index 6aac4be..a20c605 100644
--- a/kernel/time/tick-broadcast-hrtimer.c
+++ b/kernel/time/tick-broadcast-hrtimer.c
@@ -22,6 +22,7 @@ static void bc_set_mode(enum clock_event_mode mode,
 			struct clock_event_device *bc)
 {
 	switch (mode) {
+	case CLOCK_EVT_MODE_UNUSED:
 	case CLOCK_EVT_MODE_SHUTDOWN:
 		/*
 		 * Note, we cannot cancel the timer here as we might
@@ -99,10 +100,14 @@ static enum hrtimer_restart bc_handler(struct hrtimer *t)
 {
 	ce_broadcast_hrtimer.event_handler(&ce_broadcast_hrtimer);
 
-	if (ce_broadcast_hrtimer.next_event.tv64 == KTIME_MAX)
+	switch (ce_broadcast_hrtimer.mode) {
+	case CLOCK_EVT_MODE_PERIODIC:
+	case CLOCK_EVT_MODE_ONESHOT:
+		if (ce_broadcast_hrtimer.next_event.tv64 != KTIME_MAX)
+			return HRTIMER_RESTART;
+	default:
 		return HRTIMER_NORESTART;
-
-	return HRTIMER_RESTART;
+	}
 }
 
 void tick_setup_hrtimer_broadcast(void)
-- 
2.1.4


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

* Re: [PATCH] tick: Fix hang caused by hrtimer in broadcast mode
  2015-04-24 13:06 [PATCH] tick: Fix hang caused by hrtimer in broadcast mode Andreas Sandberg
@ 2015-04-25  2:34 ` Preeti U Murthy
  2015-05-05 13:23 ` Thomas Gleixner
  2015-05-05 13:36 ` [tip:timers/core] tick: hrtimer-broadcast: Prevent endless restarting when broadcast device is unused tip-bot for Andreas Sandberg
  2 siblings, 0 replies; 4+ messages in thread
From: Preeti U Murthy @ 2015-04-25  2:34 UTC (permalink / raw)
  To: Andreas Sandberg, linux-kernel
  Cc: Thomas Gleixner, stable, Catalin Marinas, Mark Rutland

On 04/24/2015 06:36 PM, Andreas Sandberg wrote:
> The hrtimer callback in the hrtimer's tick broadcast code sometimes
> incorrectly ends up scheduling events at the current tick causing the
> kernel to hang servicing the same hrtimer forever. This typically
> happens when a device is swapped out by
> tick_install_broadcast_device(), which replaces the event handler with
> clock_events_handle_noop() and sets the device mode to
> CLOCK_EVT_MODE_UNUSED. If the timer is scheduled when this happens,
> the next_event field will not be updated and the hrtimer ends up being
> restarted at the current tick. To prevent this from happening, only
> try to restart the hrtimer if the broadcast clock event device is in
> one of the active modes and try to cancel the timer when entering the
> CLOCK_EVT_MODE_UNUSED mode.
> 
> Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> Tested-by: Catalin Marinas <catalin.marinas@arm.com>
> ---
>  kernel/time/tick-broadcast-hrtimer.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/time/tick-broadcast-hrtimer.c b/kernel/time/tick-broadcast-hrtimer.c
> index 6aac4be..a20c605 100644
> --- a/kernel/time/tick-broadcast-hrtimer.c
> +++ b/kernel/time/tick-broadcast-hrtimer.c
> @@ -22,6 +22,7 @@ static void bc_set_mode(enum clock_event_mode mode,
>  			struct clock_event_device *bc)
>  {
>  	switch (mode) {
> +	case CLOCK_EVT_MODE_UNUSED:
>  	case CLOCK_EVT_MODE_SHUTDOWN:
>  		/*
>  		 * Note, we cannot cancel the timer here as we might
> @@ -99,10 +100,14 @@ static enum hrtimer_restart bc_handler(struct hrtimer *t)
>  {
>  	ce_broadcast_hrtimer.event_handler(&ce_broadcast_hrtimer);
>  
> -	if (ce_broadcast_hrtimer.next_event.tv64 == KTIME_MAX)
> +	switch (ce_broadcast_hrtimer.mode) {
> +	case CLOCK_EVT_MODE_PERIODIC:
> +	case CLOCK_EVT_MODE_ONESHOT:
> +		if (ce_broadcast_hrtimer.next_event.tv64 != KTIME_MAX)
> +			return HRTIMER_RESTART;
> +	default:
>  		return HRTIMER_NORESTART;
> -
> -	return HRTIMER_RESTART;
> +	}
>  }
>  
>  void tick_setup_hrtimer_broadcast(void)
> 
Looks good.

Reviewed-by: Preeti U. Murthy <preeti@linux.vnet.ibm.com>


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

* Re: [PATCH] tick: Fix hang caused by hrtimer in broadcast mode
  2015-04-24 13:06 [PATCH] tick: Fix hang caused by hrtimer in broadcast mode Andreas Sandberg
  2015-04-25  2:34 ` Preeti U Murthy
@ 2015-05-05 13:23 ` Thomas Gleixner
  2015-05-05 13:36 ` [tip:timers/core] tick: hrtimer-broadcast: Prevent endless restarting when broadcast device is unused tip-bot for Andreas Sandberg
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Gleixner @ 2015-05-05 13:23 UTC (permalink / raw)
  To: Andreas Sandberg
  Cc: linux-kernel, Preeti U Murthy, stable, Catalin Marinas, Mark Rutland

On Fri, 24 Apr 2015, Andreas Sandberg wrote:

> The hrtimer callback in the hrtimer's tick broadcast code sometimes
> incorrectly ends up scheduling events at the current tick causing the
> kernel to hang servicing the same hrtimer forever. This typically
> happens when a device is swapped out by
> tick_install_broadcast_device(), which replaces the event handler with
> clock_events_handle_noop() and sets the device mode to
> CLOCK_EVT_MODE_UNUSED. If the timer is scheduled when this happens,
> the next_event field will not be updated and the hrtimer ends up being
> restarted at the current tick. To prevent this from happening, only
> try to restart the hrtimer if the broadcast clock event device is in
> one of the active modes and try to cancel the timer when entering the
> CLOCK_EVT_MODE_UNUSED mode.
> 
> Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> Tested-by: Catalin Marinas <catalin.marinas@arm.com>
> ---
>  kernel/time/tick-broadcast-hrtimer.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/time/tick-broadcast-hrtimer.c b/kernel/time/tick-broadcast-hrtimer.c
> index 6aac4be..a20c605 100644
> --- a/kernel/time/tick-broadcast-hrtimer.c
> +++ b/kernel/time/tick-broadcast-hrtimer.c
> @@ -22,6 +22,7 @@ static void bc_set_mode(enum clock_event_mode mode,
>  			struct clock_event_device *bc)
>  {
>  	switch (mode) {
> +	case CLOCK_EVT_MODE_UNUSED:
>  	case CLOCK_EVT_MODE_SHUTDOWN:
>  		/*
>  		 * Note, we cannot cancel the timer here as we might
> @@ -99,10 +100,14 @@ static enum hrtimer_restart bc_handler(struct hrtimer *t)
>  {
>  	ce_broadcast_hrtimer.event_handler(&ce_broadcast_hrtimer);
>  
> -	if (ce_broadcast_hrtimer.next_event.tv64 == KTIME_MAX)
> +	switch (ce_broadcast_hrtimer.mode) {
> +	case CLOCK_EVT_MODE_PERIODIC:

That case is pointless. The mode cannot be periodic simply because
.features lacks the periodic flag.

Thanks,

	tglx

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

* [tip:timers/core] tick: hrtimer-broadcast: Prevent endless restarting when broadcast device is unused
  2015-04-24 13:06 [PATCH] tick: Fix hang caused by hrtimer in broadcast mode Andreas Sandberg
  2015-04-25  2:34 ` Preeti U Murthy
  2015-05-05 13:23 ` Thomas Gleixner
@ 2015-05-05 13:36 ` tip-bot for Andreas Sandberg
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Andreas Sandberg @ 2015-05-05 13:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mark.rutland, andreas.sandberg, tglx, linux-kernel, preeti, hpa,
	catalin.marinas, mingo

Commit-ID:  38d23a6cc16c02f7b0c920266053f340b5601735
Gitweb:     http://git.kernel.org/tip/38d23a6cc16c02f7b0c920266053f340b5601735
Author:     Andreas Sandberg <andreas.sandberg@arm.com>
AuthorDate: Fri, 24 Apr 2015 13:06:05 +0000
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 5 May 2015 15:34:21 +0200

tick: hrtimer-broadcast: Prevent endless restarting when broadcast device is unused

The hrtimer callback in the hrtimer's tick broadcast code sometimes
incorrectly ends up scheduling events at the current tick causing the
kernel to hang servicing the same hrtimer forever. This typically
happens when a device is swapped out by
tick_install_broadcast_device(), which replaces the event handler with
clock_events_handle_noop() and sets the device mode to
CLOCK_EVT_MODE_UNUSED. If the timer is scheduled when this happens,
the next_event field will not be updated and the hrtimer ends up being
restarted at the current tick. To prevent this from happening, only
try to restart the hrtimer if the broadcast clock event device is in
one of the active modes and try to cancel the timer when entering the
CLOCK_EVT_MODE_UNUSED mode.

Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1429880765-5558-1-git-send-email-andreas.sandberg@arm.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/time/tick-broadcast-hrtimer.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/kernel/time/tick-broadcast-hrtimer.c b/kernel/time/tick-broadcast-hrtimer.c
index 96428d7..3e7db49 100644
--- a/kernel/time/tick-broadcast-hrtimer.c
+++ b/kernel/time/tick-broadcast-hrtimer.c
@@ -22,6 +22,7 @@ static void bc_set_mode(enum clock_event_mode mode,
 			struct clock_event_device *bc)
 {
 	switch (mode) {
+	case CLOCK_EVT_MODE_UNUSED:
 	case CLOCK_EVT_MODE_SHUTDOWN:
 		/*
 		 * Note, we cannot cancel the timer here as we might
@@ -101,10 +102,13 @@ static enum hrtimer_restart bc_handler(struct hrtimer *t)
 {
 	ce_broadcast_hrtimer.event_handler(&ce_broadcast_hrtimer);
 
-	if (ce_broadcast_hrtimer.next_event.tv64 == KTIME_MAX)
+	switch (ce_broadcast_hrtimer.mode) {
+	case CLOCK_EVT_MODE_ONESHOT:
+		if (ce_broadcast_hrtimer.next_event.tv64 != KTIME_MAX)
+			return HRTIMER_RESTART;
+	default:
 		return HRTIMER_NORESTART;
-
-	return HRTIMER_RESTART;
+	}
 }
 
 void tick_setup_hrtimer_broadcast(void)

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

end of thread, other threads:[~2015-05-05 13:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-24 13:06 [PATCH] tick: Fix hang caused by hrtimer in broadcast mode Andreas Sandberg
2015-04-25  2:34 ` Preeti U Murthy
2015-05-05 13:23 ` Thomas Gleixner
2015-05-05 13:36 ` [tip:timers/core] tick: hrtimer-broadcast: Prevent endless restarting when broadcast device is unused tip-bot for Andreas Sandberg

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.