From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@redhat.com, peterz@infradead.org, fweisbec@gmail.com
Subject: [PATCH] clock: Fix smp_processor_id() in preemptible bug
Date: Wed, 8 Mar 2017 13:53:06 -0800 [thread overview]
Message-ID: <20170308215306.GA8776@linux.vnet.ibm.com> (raw)
The v4.11-rc1 kernel emits the following splat in some configurations:
[ 43.681891] BUG: using smp_processor_id() in preemptible [00000000] code: kworker/3:1/49
[ 43.682511] caller is debug_smp_processor_id+0x17/0x20
[ 43.682893] CPU: 0 PID: 49 Comm: kworker/3:1 Not tainted 4.11.0-rc1+ #1
[ 43.683382] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
[ 43.683497] Workqueue: events __clear_sched_clock_stable
[ 43.683497] Call Trace:
[ 43.683497] dump_stack+0x4f/0x69
[ 43.683497] check_preemption_disabled+0xd9/0xf0
[ 43.683497] debug_smp_processor_id+0x17/0x20
[ 43.683497] __clear_sched_clock_stable+0x11/0x60
[ 43.683497] process_one_work+0x146/0x430
[ 43.683497] worker_thread+0x126/0x490
[ 43.683497] kthread+0xfc/0x130
[ 43.683497] ? process_one_work+0x430/0x430
[ 43.683497] ? kthread_create_on_node+0x40/0x40
[ 43.683497] ? umh_complete+0x30/0x30
[ 43.683497] ? call_usermodehelper_exec_async+0x12a/0x130
[ 43.683497] ret_from_fork+0x29/0x40
[ 43.689244] sched_clock: Marking unstable (43688244724, 179505618)<-(43867750342, 0)
This happens because workqueue handlers run with preemption enabled
by default and the new this_scd() function accesses per-CPU variables.
This commit therefore disables preemption across this call to this_scd()
and to the uses of the pointer that it returns. Lightly tested
successfully on x86.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index a08795e21628..aa184bea1344 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -143,7 +143,7 @@ static void __set_sched_clock_stable(void)
static void __clear_sched_clock_stable(struct work_struct *work)
{
- struct sched_clock_data *scd = this_scd();
+ struct sched_clock_data *scd;
/*
* Attempt to make the stable->unstable transition continuous.
@@ -154,7 +154,10 @@ static void __clear_sched_clock_stable(struct work_struct *work)
*
* Still do what we can.
*/
+ preempt_disable();
+ scd = this_scd();
gtod_offset = (scd->tick_raw + raw_offset) - (scd->tick_gtod);
+ preempt_enable();
printk(KERN_INFO "sched_clock: Marking unstable (%lld, %lld)<-(%lld, %lld)\n",
scd->tick_gtod, gtod_offset,
next reply other threads:[~2017-03-08 21:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 21:53 Paul E. McKenney [this message]
2017-03-09 15:24 ` [PATCH] clock: Fix smp_processor_id() in preemptible bug Peter Zijlstra
2017-03-09 15:31 ` Paul E. McKenney
2017-03-09 18:37 ` Paul E. McKenney
2017-03-10 17:27 ` Paul E. McKenney
2017-03-13 12:46 ` Peter Zijlstra
2017-03-13 15:55 ` Paul E. McKenney
2017-03-14 16:24 ` Paul E. McKenney
2017-03-15 22:58 ` Paul E. McKenney
2017-03-16 15:53 ` Peter Zijlstra
2017-03-16 16:57 ` Paul E. McKenney
2017-03-16 21:00 ` Paul E. McKenney
2017-03-16 21:06 ` Paul E. McKenney
2017-03-23 9:10 ` [tip:sched/urgent] sched/clock: Fix clear_sched_clock_stable() preempt wobbly tip-bot for Peter Zijlstra
2017-03-23 16:52 ` Paul E. McKenney
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=20170308215306.GA8776@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
/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.