From patchwork Wed Jun 14 13:22:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 105516 Delivered-To: patch@linaro.org Received: by 10.140.91.77 with SMTP id y71csp290134qgd; Wed, 14 Jun 2017 06:22:53 -0700 (PDT) X-Received: by 10.84.217.154 with SMTP id p26mr10528pli.295.1497446573103; Wed, 14 Jun 2017 06:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497446573; cv=none; d=google.com; s=arc-20160816; b=0UTO/d/XNk5d6vrYUQ2FFuU88LtDUAT3+R1nHhZrawcGArbkI2dmQQzECo1hFcEvzk Wct39TcAYB4nlALDUx5O8kZpoq7bhOEN8MJHMOxJfyoawM3zt0SPTLjHZXGaC1XiCLMS QN5uxBpdx8oB86uALVZb6iAzS5VQ1G1d8a1zpOISSXzCZaee/gTRbfzVpBxNVRLQ6dW2 uhX0cg5jIoJYFIHLZzw0WfLqpBq1OPZJdkpUkzWcJ2SuycI5YbWe93hlKp49ErB8uQyP YoabTZgPuCM2vglDeMgjBFpO4XTOhkuVy2vkyPSlbj1hW3eJ9DuXjS2wPpBA8IQ3jVmp QTVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=NACeZWPH1wU5LM+D0Ahr+qQt+T6nDX+KJ2gmz38pnKk=; b=HfHb5dI97JuFAk+V6V9S81xrGffSBrLvOq4DOJkRite3ktSQYtS1L/5Z8YSqncxuuN n2rpIEMWXE4YyOVOMqsaEUgaoSQ5wzzX0s3rbCo+joDY/m8NcTimsz49MiXB38DyeGnw WJnVZnu42iEsByFjPiNqp6/CTeshWqW0w9wlWk+d9iHAcGjN994GCXQg1/AKNFuZDP0w S/CAHG+1VPoougoRYmR46aqR8HGDrG9Cq22u4ihBiCexLj1nGzdP3RHHmgzTE7pTsx0i bZxWsIrQ1txC4zwbc9WaujFUjo5A6mu+gqzVC8YCRJ/OYLpPOnWuW1I4HwoNSAbR4RxB zoGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=e8XCvfRe; spf=pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-rt-users-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11si18345pgc.137.2017.06.14.06.22.52; Wed, 14 Jun 2017 06:22:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.b=e8XCvfRe; spf=pass (google.com: best guess record for domain of linux-rt-users-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-rt-users-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752310AbdFNNWw (ORCPT + 4 others); Wed, 14 Jun 2017 09:22:52 -0400 Received: from mail-pg0-f50.google.com ([74.125.83.50]:35534 "EHLO mail-pg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751726AbdFNNWv (ORCPT ); Wed, 14 Jun 2017 09:22:51 -0400 Received: by mail-pg0-f50.google.com with SMTP id k71so198339pgd.2 for ; Wed, 14 Jun 2017 06:22:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Y1CfuspO8gHW26ipNFXJDMtlBLfzcPCP+gStQ9481Q4=; b=e8XCvfRe7iNaQPMH5FGylrmvcT6dQosE2bYrCowLs/DpCkDEQW8PWX3BzEdRMC/2Ww kFxVHwsKzaYJW6CxIX0zt6DHqUj/DTou+19JvyaN0kr2b+xDYvqXQsCopHgqIX5UOsaj wJ0V1C/R3zGrODQhe3OY/XluOGgoLSn4p2OVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Y1CfuspO8gHW26ipNFXJDMtlBLfzcPCP+gStQ9481Q4=; b=RQU+xQyvoVWGPvNouRb/agpJBy4TxtujlQ7WGTrSSI6vfYBET4JhSsxPf4BOQktD6i uqWD7uW3R3qg9ZQVrp/xP4oq4EBeYiHttAkzYcepTCiobK8vj98GjXDjIN5+OV9mqcOw SKOI3C6H/zYnbFZCF228IawcNEs5P2LPIQaomRZCZnwvRYRSSP+vTjiTSik2wr2uXLQg Qpdf6HQoNB9tYKnUH5h02aqmqs1n5TZhUU3AaFyixVr4zB72T4avWP6lFuGBUKvUBwPA oHtfT+av0b0iT+ysnmr4SPiwSVXsxoNBrSBv7gvn3sEAPGnTFQKihNt+1HrJFcAhkhy6 MP5Q== X-Gm-Message-State: AKS2vOxfBv5ze2xb9RfM7S6KGQhyo2HOl1su5kmtcHVmbXxC3aCoT+uE hwtniEupUbiKL24N X-Received: by 10.84.225.146 with SMTP id u18mr58820plj.264.1497446570350; Wed, 14 Jun 2017 06:22:50 -0700 (PDT) Received: from localhost.localdomain ([104.237.95.134]) by smtp.gmail.com with ESMTPSA id i186sm78431pgc.4.2017.06.14.06.22.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 06:22:49 -0700 (PDT) From: Alex Shi To: linux-kernel@vger.kernel.org (open list) Cc: Alex Shi , Sebastian Andrzej Siewior , Thomas Gleixner , Anders Roxell , Daniel Lezcano , linux-rt-users Subject: [RFC PATCH] cpu_pm/rt: replace rt rwlock with raw spinlock Date: Wed, 14 Jun 2017 21:22:19 +0800 Message-Id: <1497446539-6378-1-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-rt-users-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rt-users@vger.kernel.org This is a quick fix for a bug as 'scheduling while atomic' or 'scheduling from the idle thread' on arm/arm64. On arm/arm64, rwlock cpu_pm_notifier_lock in cpu_pm cause a potential schedule after irq disable in idle call chain: cpu_startup_entry cpu_idle_loop local_irq_disable() cpuidle_idle_call call_cpuidle cpuidle_enter cpuidle_enter_state ->enter :arm_enter_idle_state cpu_pm_enter/exit CPU_PM_CPU_IDLE_ENTER read_lock(&cpu_pm_notifier_lock); <-- sleep in idle __rt_spin_lock(); schedule(); The kernel panic is here: [ 4.609601] BUG: scheduling while atomic: swapper/1/0/0x00000002 [ 4.609608] [] arm_enter_idle_state+0x18/0x70 [ 4.609614] Modules linked in: [ 4.609615] [] cpuidle_enter_state+0xf0/0x218 [ 4.609620] [] cpuidle_enter+0x18/0x20 [ 4.609626] Preemption disabled at: [ 4.609627] [] call_cpuidle+0x24/0x40 [ 4.609635] [] schedule_preempt_disabled+0x1c/0x28 [ 4.609639] [] cpu_startup_entry+0x154/0x1f8 [ 4.609645] [] secondary_start_kernel+0x15c/0x1a0 Daniel Lezcano said this notification is needed on arm/arm64 platforms. I also tried use local_lock_irq to replace local_irq_disable, but my 2 boards just die without any output. So maybe it's only quick way to make rt kernel work on arm/arm64. Since this is quick fix, instead of split out the raw rwlock, to use raw_spin_lock is simple and don't cost much. Signed-off-by: Alex Shi Cc: Sebastian Andrzej Siewior Cc: Thomas Gleixner Cc: Anders Roxell Cc: Daniel Lezcano Cc: linux-rt-users --- kernel/cpu_pm.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/kernel/cpu_pm.c b/kernel/cpu_pm.c index 009cc9a..8ffa13e3 100644 --- a/kernel/cpu_pm.c +++ b/kernel/cpu_pm.c @@ -22,7 +22,7 @@ #include #include -static DEFINE_RWLOCK(cpu_pm_notifier_lock); +static DEFINE_RAW_SPINLOCK(cpu_pm_notifier_lock); static RAW_NOTIFIER_HEAD(cpu_pm_notifier_chain); static int cpu_pm_notify(enum cpu_pm_event event, int nr_to_call, int *nr_calls) @@ -50,9 +50,9 @@ int cpu_pm_register_notifier(struct notifier_block *nb) unsigned long flags; int ret; - write_lock_irqsave(&cpu_pm_notifier_lock, flags); + raw_spin_lock_irqsave(&cpu_pm_notifier_lock, flags); ret = raw_notifier_chain_register(&cpu_pm_notifier_chain, nb); - write_unlock_irqrestore(&cpu_pm_notifier_lock, flags); + raw_spin_unlock_irqrestore(&cpu_pm_notifier_lock, flags); return ret; } @@ -72,9 +72,9 @@ int cpu_pm_unregister_notifier(struct notifier_block *nb) unsigned long flags; int ret; - write_lock_irqsave(&cpu_pm_notifier_lock, flags); + raw_spin_lock_irqsave(&cpu_pm_notifier_lock, flags); ret = raw_notifier_chain_unregister(&cpu_pm_notifier_chain, nb); - write_unlock_irqrestore(&cpu_pm_notifier_lock, flags); + raw_spin_unlock_irqrestore(&cpu_pm_notifier_lock, flags); return ret; } @@ -100,7 +100,7 @@ int cpu_pm_enter(void) int nr_calls; int ret = 0; - read_lock(&cpu_pm_notifier_lock); + raw_spin_lock(&cpu_pm_notifier_lock); ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls); if (ret) /* @@ -108,7 +108,7 @@ int cpu_pm_enter(void) * PM entry who are notified earlier to prepare for it. */ cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL); - read_unlock(&cpu_pm_notifier_lock); + raw_spin_unlock(&cpu_pm_notifier_lock); return ret; } @@ -130,9 +130,9 @@ int cpu_pm_exit(void) { int ret; - read_lock(&cpu_pm_notifier_lock); + raw_spin_lock(&cpu_pm_notifier_lock); ret = cpu_pm_notify(CPU_PM_EXIT, -1, NULL); - read_unlock(&cpu_pm_notifier_lock); + raw_spin_unlock(&cpu_pm_notifier_lock); return ret; } @@ -159,7 +159,7 @@ int cpu_cluster_pm_enter(void) int nr_calls; int ret = 0; - read_lock(&cpu_pm_notifier_lock); + raw_spin_lock(&cpu_pm_notifier_lock); ret = cpu_pm_notify(CPU_CLUSTER_PM_ENTER, -1, &nr_calls); if (ret) /* @@ -167,7 +167,7 @@ int cpu_cluster_pm_enter(void) * PM entry who are notified earlier to prepare for it. */ cpu_pm_notify(CPU_CLUSTER_PM_ENTER_FAILED, nr_calls - 1, NULL); - read_unlock(&cpu_pm_notifier_lock); + raw_spin_unlock(&cpu_pm_notifier_lock); return ret; } @@ -192,9 +192,9 @@ int cpu_cluster_pm_exit(void) { int ret; - read_lock(&cpu_pm_notifier_lock); + raw_spin_lock(&cpu_pm_notifier_lock); ret = cpu_pm_notify(CPU_CLUSTER_PM_EXIT, -1, NULL); - read_unlock(&cpu_pm_notifier_lock); + raw_spin_unlock(&cpu_pm_notifier_lock); return ret; }