From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932966AbdCJR1p (ORCPT ); Fri, 10 Mar 2017 12:27:45 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36419 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755398AbdCJR1f (ORCPT ); Fri, 10 Mar 2017 12:27:35 -0500 Date: Fri, 10 Mar 2017 09:27:28 -0800 From: "Paul E. McKenney" To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, fweisbec@gmail.com Subject: Re: [PATCH] clock: Fix smp_processor_id() in preemptible bug Reply-To: paulmck@linux.vnet.ibm.com References: <20170308215306.GA8776@linux.vnet.ibm.com> <20170309152420.GC3343@twins.programming.kicks-ass.net> <20170309153114.GU30506@linux.vnet.ibm.com> <20170309183732.GB13748@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170309183732.GB13748@linux.vnet.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 17031017-0048-0000-0000-0000011BC5B2 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006757; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00832742; UDB=6.00408706; IPR=6.00610330; BA=6.00005202; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014597; XFM=3.00000013; UTC=2017-03-10 17:27:31 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031017-0049-0000-0000-00003F8E1412 Message-Id: <20170310172728.GA11931@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-03-10_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703100138 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 09, 2017 at 10:37:32AM -0800, Paul E. McKenney wrote: > On Thu, Mar 09, 2017 at 07:31:14AM -0800, Paul E. McKenney wrote: > > On Thu, Mar 09, 2017 at 04:24:20PM +0100, Peter Zijlstra wrote: > > > On Wed, Mar 08, 2017 at 01:53:06PM -0800, Paul E. McKenney wrote: > > > > 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. > > > > > > Does this also work? > > > > Thank you! I will give it a shot after the other tests complete. > > And it does pass light testing. I will hammer it harder this evening. > > So please send a formal patch! And the diffs below passed overnight testing, so: Tested-by: Paul E. McKenney ------------------------------------------------------------------------ commit e87df240b9e6a24635a1c8674f715554f27df6cc Author: Paul E. McKenney Date: Thu Mar 9 07:51:25 2017 -0800 EXPERIMENTAL: Peter Zijlstra hotplug fix Not-signed-off-by: Paul E. McKenney diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index a08795e21628..1560d5f961ef 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c @@ -172,8 +172,8 @@ void clear_sched_clock_stable(void) smp_mb(); /* matches sched_clock_init_late() */ - if (sched_clock_running == 2) - schedule_work(&sched_clock_work); + if (sched_clock_running == 2 && sched_clock_stable()) + schedule_work_on(smp_processor_id(), &sched_clock_work); } void sched_clock_init_late(void)