Skip to content

Commit 2d06fa0

Browse files
KAGA-KOKOgregkh
authored andcommitted
hrtimers: Move SMP function call to thread context
commit 5ec2481 upstream. smp_call_function_* must not be called from softirq context. But clock_was_set() which calls on_each_cpu() is called from softirq context to implement a delayed clock_was_set() for the timer interrupt handler. Though that almost never gets invoked. A recent change in the resume code uses the softirq based delayed clock_was_set to support Xens resume mechanism. linux-next contains a new warning which warns if smp_call_function_* is called from softirq context which gets triggered by that Xen change. Fix this by moving the delayed clock_was_set() call to a work context. Reported-and-tested-by: Artem Savkov <artem.savkov@gmail.com> Reported-by: Sasha Levin <sasha.levin@oracle.com> Cc: David Vrabel <david.vrabel@citrix.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: H. Peter Anvin <hpa@zytor.com>, Cc: Konrad Wilk <konrad.wilk@oracle.com> Cc: John Stultz <john.stultz@linaro.org> Cc: xen-devel@lists.xen.org Cc: stable@vger.kernel.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c4d98e2 commit 2d06fa0

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

‎kernel/hrtimer.c‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -721,17 +721,20 @@ static int hrtimer_switch_to_hres(void)
721721
return 1;
722722
}
723723

724+
static void clock_was_set_work(struct work_struct *work)
725+
{
726+
clock_was_set();
727+
}
728+
729+
static DECLARE_WORK(hrtimer_work, clock_was_set_work);
730+
724731
/*
725-
* Called from timekeeping code to reprogramm the hrtimer interrupt
726-
* device. If called from the timer interrupt context we defer it to
727-
* softirq context.
732+
* Called from timekeeping and resume code to reprogramm the hrtimer
733+
* interrupt device on all cpus.
728734
*/
729735
void clock_was_set_delayed(void)
730736
{
731-
struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
732-
733-
cpu_base->clock_was_set = 1;
734-
__raise_softirq_irqoff(HRTIMER_SOFTIRQ);
737+
schedule_work(&hrtimer_work);
735738
}
736739

737740
#else
@@ -780,8 +783,10 @@ void hrtimers_resume(void)
780783
WARN_ONCE(!irqs_disabled(),
781784
KERN_INFO "hrtimers_resume() called with IRQs enabled!");
782785

786+
/* Retrigger on the local CPU */
783787
retrigger_next_event(NULL);
784-
timerfd_clock_was_set();
788+
/* And schedule a retrigger for all others */
789+
clock_was_set_delayed();
785790
}
786791

787792
static inline void timer_stats_hrtimer_set_start_info(struct hrtimer *timer)
@@ -1432,13 +1437,6 @@ void hrtimer_peek_ahead_timers(void)
14321437

14331438
static void run_hrtimer_softirq(struct softirq_action *h)
14341439
{
1435-
struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
1436-
1437-
if (cpu_base->clock_was_set) {
1438-
cpu_base->clock_was_set = 0;
1439-
clock_was_set();
1440-
}
1441-
14421440
hrtimer_peek_ahead_timers();
14431441
}
14441442

0 commit comments

Comments
 (0)