From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754286AbbF0LBM (ORCPT ); Sat, 27 Jun 2015 07:01:12 -0400 Received: from mail.skyhub.de ([78.46.96.112]:33851 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752633AbbF0LBE (ORCPT ); Sat, 27 Jun 2015 07:01:04 -0400 Date: Sat, 27 Jun 2015 13:00:46 +0200 From: Borislav Petkov To: Jan Kiszka Cc: Thomas Gleixner , LKML , Ingo Molnar , Peter Zijlstra , Paul McKenney , Frederic Weisbecker , Eric Dumazet , Viresh Kumar , John Stultz , Joonwoo Park , Wenbo Wang , Steven Rostedt , Badhri Jagan Sridharan Subject: Re: [PATCH] timer: Fix unsafe cpu variable access in migrate_timers Message-ID: <20150627110046.GC27131@pd.tnic> References: <20150526210723.245729529@linutronix.de> <20150526224511.950084301@linutronix.de> <558E7325.70505@web.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <558E7325.70505@web.de> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 27, 2015 at 11:55:49AM +0200, Jan Kiszka wrote: > From: Jan Kiszka > > migrate_timers is invoked with preemption enabled. Therefore we have to > get/put the cpu-local variable tvec_bases like before commit 0eeda71bc3. > > This fixes > > BUG: using smp_processor_id() in preemptible [00000000] code: bash/4917 > caller is debug_smp_processor_id+0x17/0x19 > CPU: 0 PID: 4917 Comm: bash Not tainted 4.1.0-dbg+ #97 > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.8.1-0-g4adadbd-20150316_085822-nilsson.home.kraxel.org 04/01/2014 > ffff880038674040 ffff880002e6fb98 ffffffff815356a0 0000000000000002 > 0000000000000000 ffff880002e6fbc8 ffffffff8130c16f ffff88003fd8d500 > 000000000000d500 0000000000000000 0000000000000003 ffff880002e6fbd8 > Call Trace: > [] dump_stack+0x4f/0x7b > [] check_preemption_disabled+0xdd/0xef > [] debug_smp_processor_id+0x17/0x19 > [] timer_cpu_notify+0x4f/0x112 > [] notifier_call_chain+0x4c/0x71 > [] __raw_notifier_call_chain+0xe/0x10 > [] __cpu_notify+0x20/0x37 > [] cpu_notify+0x13/0x15 > [] cpu_notify_nofail+0xe/0x16 > [] _cpu_down+0x178/0x268 > [] ? trace_hardirqs_on+0xd/0xf > [] cpu_down+0x28/0x3c > [] cpu_subsys_offline+0x14/0x16 > [] device_offline+0x7d/0xb1 > [] online_store+0x48/0x68 > [] dev_attr_store+0x18/0x22 > [] sysfs_kf_write+0x49/0x51 > [] kernfs_fop_write+0x105/0x158 > [] __vfs_write+0x28/0xbd > [] ? security_file_permission+0x23/0x90 > [] vfs_write+0xb2/0x169 > [] SyS_write+0x4a/0x91 > [] entry_SYSCALL_64_fastpath+0x12/0x76 > > triggered when offlining a CPU, e.g. via sysfs. > > Signed-off-by: Jan Kiszka > --- > kernel/time/timer.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/time/timer.c b/kernel/time/timer.c > index 520499d..c826178 100644 > --- a/kernel/time/timer.c > +++ b/kernel/time/timer.c > @@ -1566,7 +1566,7 @@ static void migrate_timers(int cpu) > > BUG_ON(cpu_online(cpu)); > old_base = per_cpu_ptr(&tvec_bases, cpu); > - new_base = this_cpu_ptr(&tvec_bases); > + new_base = &get_cpu_var(tvec_bases); Hmm, tglx's version doesn't disable preemtion around it: http://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=timers/urgent&id=24bfcb100959c8641a627b5604d967243f8f240c -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --