Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp562748imm; Thu, 6 Sep 2018 06:54:35 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb5xIrz3Lmeihsyrpbb1c8Zs+REcSezinX7VDCFPrrCrorIJLZ4sSdI34Q8qQmayPojuAmP X-Received: by 2002:a63:9409:: with SMTP id m9-v6mr2849884pge.13.1536242075397; Thu, 06 Sep 2018 06:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536242075; cv=none; d=google.com; s=arc-20160816; b=0nYZo+SKX23kjfwtkMQwjjTGOnclCFpCGlQOpgGsq2/F2s3QelnvbEjtasw/xPRsg5 MVSIzWrqtCza8PFfpsrZSQclJsDLU7NHOsYHvMln/obpNnHf8tul/PeT7bN+8nZCQNl6 QCJuU0p6GpbibbkeWs1QTvuiaYb9ellqRuExSXORIYGypsG05sprLL1f5DrD5IVthCeE g5QcMMvNgZP+AdKW0JcTA1a/14pyutQ3NKUCU8IkPW5kXBcWI+qDviyF9gt+rJWiGTws dxsmvdilxcefsxUwO0Uwf/QO2mqwcFGcQ6ZLq2XwWO01SlGfQCokuRa8VNkHRqXSiiR1 qf5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=AnpzA8sfZAfzRYMHIWiLYahsHdR7RIi7Jsas2Ez/7Rg=; b=ISPKgOSqrNU64sKXk5koXNeWvAsKYBaopwaAOxlcmGay55DHRWj/7PTN+kl2fcmFen 3kHrbHUYMsmRdUFKOKZ6tdza/cwVVf96/Wk/AwTNon82+oOQFIo1JlSX5adC0DIuP3hd 3NzM4tIhTrZ3tnTD3+5E0DxJzLf/jJeG16WO+doSYev1q5cubyBclkW8GspQzRRS7b1e zgubdD3KEqDE4wXM3Ign8VA7wBsdaxaxomZGdoqL0T/QVQ/5ETAqcnHw9fmvKP3iNLiF V7wr/ig5Ra2qHroa+AcPAjHQCWvUKoZ//2iLV2Bc4t/BUwEq47HX5erhmUAUpseclUAP cbNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2-v6si5472045pgm.236.2018.09.06.06.54.20; Thu, 06 Sep 2018 06:54:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729979AbeIFS2O (ORCPT + 99 others); Thu, 6 Sep 2018 14:28:14 -0400 Received: from terminus.zytor.com ([198.137.202.136]:43207 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729662AbeIFS2O (ORCPT ); Thu, 6 Sep 2018 14:28:14 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w86DqNNB312146 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 6 Sep 2018 06:52:23 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w86DqNBh312143; Thu, 6 Sep 2018 06:52:23 -0700 Date: Thu, 6 Sep 2018 06:52:23 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Gleixner Message-ID: Cc: tglx@linutronix.de, mingo@kernel.org, neeraju@codeaurora.org, hpa@zytor.com, linux-kernel@vger.kernel.org, geert+renesas@glider.be, sudeep.holla@arm.com Reply-To: geert+renesas@glider.be, sudeep.holla@arm.com, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, neeraju@codeaurora.org, tglx@linutronix.de In-Reply-To: References: To: linux-tip-commits@vger.kernel.org Subject: [tip:smp/urgent] cpu/hotplug: Prevent state corruption on error rollback Git-Commit-ID: 69fa6eb7d6a64801ea261025cce9723d9442d773 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 69fa6eb7d6a64801ea261025cce9723d9442d773 Gitweb: https://git.kernel.org/tip/69fa6eb7d6a64801ea261025cce9723d9442d773 Author: Thomas Gleixner AuthorDate: Thu, 6 Sep 2018 15:21:38 +0200 Committer: Thomas Gleixner CommitDate: Thu, 6 Sep 2018 15:21:38 +0200 cpu/hotplug: Prevent state corruption on error rollback When a teardown callback fails, the CPU hotplug code brings the CPU back to the previous state. The previous state becomes the new target state. The rollback happens in undo_cpu_down() which increments the state unconditionally even if the state is already the same as the target. As a consequence the next CPU hotplug operation will start at the wrong state. This is easily to observe when __cpu_disable() fails. Prevent the unconditional undo by checking the state vs. target before incrementing state and fix up the consequently wrong conditional in the unplug code which handles the failure of the final CPU take down on the control CPU side. Fixes: 4dddfb5faa61 ("smp/hotplug: Rewrite AP state machine core") Reported-by: Neeraj Upadhyay Signed-off-by: Thomas Gleixner Tested-by: Geert Uytterhoeven Tested-by: Sudeep Holla Tested-by: Neeraj Upadhyay Cc: josh@joshtriplett.org Cc: peterz@infradead.org Cc: jiangshanlai@gmail.com Cc: dzickus@redhat.com Cc: brendan.jackman@arm.com Cc: malat@debian.org Cc: sramana@codeaurora.org Cc: linux-arm-msm@vger.kernel.org Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/alpine.DEB.2.21.1809051419580.1416@nanos.tec.linutronix.de ---- --- kernel/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index eb4041f78073..0097acec1c71 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -916,7 +916,8 @@ static int cpuhp_down_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st, ret = cpuhp_invoke_callback(cpu, st->state, false, NULL, NULL); if (ret) { st->target = prev_state; - undo_cpu_down(cpu, st); + if (st->state < prev_state) + undo_cpu_down(cpu, st); break; } } @@ -969,7 +970,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen, * to do the further cleanups. */ ret = cpuhp_down_callbacks(cpu, st, target); - if (ret && st->state > CPUHP_TEARDOWN_CPU && st->state < prev_state) { + if (ret && st->state == CPUHP_TEARDOWN_CPU && st->state < prev_state) { cpuhp_reset_state(st, prev_state); __cpuhp_kick_ap(st); }