From patchwork Mon Jun 20 09:23:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 896512 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5K9Om5t004949 for ; Mon, 20 Jun 2011 09:24:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753110Ab1FTJYq (ORCPT ); Mon, 20 Jun 2011 05:24:46 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:48353 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752659Ab1FTJYp (ORCPT ); Mon, 20 Jun 2011 05:24:45 -0400 Received: from dbdp20.itg.ti.com ([172.24.170.38]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id p5K9O9pC008522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 20 Jun 2011 04:24:12 -0500 Received: from dbde71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id p5K9O7uZ015770; Mon, 20 Jun 2011 14:54:08 +0530 (IST) Received: from dbdp31.itg.ti.com (172.24.170.98) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 8.3.106.1; Mon, 20 Jun 2011 14:54:07 +0530 Received: from linfarm476.india.ti.com (linfarm476.india.ti.com [10.24.132.205]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with ESMTP id p5K9O1VE010019; Mon, 20 Jun 2011 14:54:02 +0530 (IST) Received: (from a0393909@localhost) by linfarm476.india.ti.com (8.12.11/8.13.8/Submit) id p5K9NxKS018432; Mon, 20 Jun 2011 14:53:59 +0530 From: Santosh Shilimkar To: CC: linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, Santosh Shilimkar , Thomas Gleixner , Peter Zijlstra , Russell King Subject: [RFC PATCH] ARM: smp: Fix the CPU hotplug race with scheduler. Date: Mon, 20 Jun 2011 14:53:59 +0530 Message-ID: <1308561839-18407-1-git-send-email-santosh.shilimkar@ti.com> X-Mailer: git-send-email 1.5.6.6 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 20 Jun 2011 09:24:48 +0000 (UTC) The current ARM CPU hotplug code suffers from couple of race conditions in CPU online path with scheduler. The ARM CPU hotplug code doesn't wait for hot-plugged CPU to be marked active as part of cpu_notify() by the CPU which brought it up before enabling interrupts. So we end up in with couple of race conditions, 1) Interrupts are enabled even before CPU is marked as active. 2) Newly plugged CPU is marked as active but it is not marked online yet. When an interrupt happens before the cpu_active bit is set, the scheduler can't schedule the woken thread which is bound to that newly onlined cpu and and selects a fallback runqueue. Secondly marking CPU active before it is online also not desirable behaviour. Fix this race conditions. Signed-off-by: Santosh Shilimkar Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Russell King --- On v3.0 kernel I started seeing lock-up and random crashes when CPU online/offline was attempted aggressively. With git bisect I could reach to Peter's commit e4a52bcb9a18142d79e231b6733cabdbf2e67c1f[sched: Remove rq->lock from the first half of ttwu()] which was also reported by Marc Zyngier. But even after using the follow up fix from Peter d6aa8f85f163[sched: Fix ttwu() for __ARCH_WANT_INTERRUPTS_ON_CTXSW], I was still seeing issues with hotplug path. So as a experiment I just pushed down the interrupt enabling on newly plugged CPU after it's marked as online. This made things better and much stable but occasionally I was still seeing lock-up. With above as background I looked at arch/x86/ code and got convinced myself that the experimental hack could be the right fix. While doing this I came across a commit from Thomas fd8a7de177b [x86: cpu-hotplug: Prevent softirq wakeup on wrong CPU] which fixed the race 2) on x86 architecture. In this patch I have folded possible fixes for both race conditions for ARM hotplug code as mentioned in change log. Hopefully I am not introducing any new race with this patch and hence the RFC. arch/arm/kernel/smp.c | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c index 344e52b..84373a9 100644 --- a/arch/arm/kernel/smp.c +++ b/arch/arm/kernel/smp.c @@ -302,13 +302,6 @@ asmlinkage void __cpuinit secondary_start_kernel(void) platform_secondary_init(cpu); /* - * Enable local interrupts. - */ - notify_cpu_starting(cpu); - local_irq_enable(); - local_fiq_enable(); - - /* * Setup the percpu timer for this CPU. */ percpu_timer_setup(); @@ -322,6 +315,17 @@ asmlinkage void __cpuinit secondary_start_kernel(void) */ set_cpu_online(cpu, true); + + while (!cpumask_test_cpu(smp_processor_id(), cpu_active_mask)) + cpu_relax(); + + /* + * Enable local interrupts. + */ + notify_cpu_starting(cpu); + local_irq_enable(); + local_fiq_enable(); + /* * OK, it's off to the idle thread for us */