Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4534690imm; Mon, 17 Sep 2018 16:02:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY3iz654N12y1mC+AqxoW5kVsIkVrU15cPJPZcMW1BhGQMbDJ47d00HxGuUljYmlktXO65y X-Received: by 2002:a63:170b:: with SMTP id x11-v6mr24563011pgl.364.1537225360208; Mon, 17 Sep 2018 16:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537225360; cv=none; d=google.com; s=arc-20160816; b=FszHtLt4qSDl0znHYKiRWTlbvoLne7m2bZb8yoyATCUoKnZ1iD/kZ4pOhst6xo5x0R OeJQIWy9/niZc6BQ1/tJLADhing+N+5jXYwWK9z/K3C7JRd4JxD7Up/UN9RO2SwrMmBa 9G/gekGRLL7xebzQxyP7Zmzvzvb9f3fE3FAbt/4Rb15Hkt2n+FEOVBXNT0lEPdveZgYQ BMYjFa54o3TxwdqsXLFlh30PKHlzbwsV5pm82UanNLzEtaZW3KQbq44nSiWq62dzEYZf rwE6d1J389kyfjs7ps3kJF1YLp2Xw3ei6cXbvqWTZ4n3BBq1oBJZ5afMLLIhX6H/kXy7 DLOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=lwxeuSTOOTKFxl/ZbQAMUSFIwlchbYRb5Xyg7kooPwA=; b=wzbGq3C1ootrkK4+Td1BptO2mf9RzxqyagYwujOVOa2ogTI0SXiOJZ4lgXW/DvTUFT AmN/hONfSvzSSQwNkO9x2JtBR6zs1UcLu/r2DwmUdwuAd1ZeqY2seknDtqRohvmx/o1W 40NS5WtbF4EPxXiL92JU1AGWxx3Eah2Q00pG3RZb9mzxta/ZHnu1EsakxsRxNDG+NANR 6LaBolJle02ito3SFNMdV6+KeMjfX4oTPcAM5g5JbAr5/f6iKPIPoL4G2qt5vpiP3I6I Qn86bFs4eyVoMSxVwRPBI63wuSJHB0XhXqfsqW7axhwvQ7rAsMVTsgMJPYOqzoVH7Ws/ EwZQ== 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 u5-v6si16667964pgc.459.2018.09.17.16.02.25; Mon, 17 Sep 2018 16:02:40 -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 S1730359AbeIREbj (ORCPT + 99 others); Tue, 18 Sep 2018 00:31:39 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48412 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbeIREbj (ORCPT ); Tue, 18 Sep 2018 00:31:39 -0400 Received: from localhost (li1825-44.members.linode.com [172.104.248.44]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id F043FC03; Mon, 17 Sep 2018 23:02:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Neeraj Upadhyay , Thomas Gleixner , Geert Uytterhoeven , Sudeep Holla , josh@joshtriplett.org, peterz@infradead.org, jiangshanlai@gmail.com, dzickus@redhat.com, brendan.jackman@arm.com, malat@debian.org, sramana@codeaurora.org, linux-arm-msm@vger.kernel.org Subject: [PATCH 4.14 015/126] cpu/hotplug: Prevent state corruption on error rollback Date: Tue, 18 Sep 2018 00:41:03 +0200 Message-Id: <20180917211705.700936708@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180917211703.481236999@linuxfoundation.org> References: <20180917211703.481236999@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit 69fa6eb7d6a64801ea261025cce9723d9442d773 upstream. 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 Signed-off-by: Greg Kroah-Hartman ---- --- kernel/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -932,7 +932,8 @@ static int cpuhp_down_callbacks(unsigned 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; } } @@ -985,7 +986,7 @@ static int __ref _cpu_down(unsigned int * 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); }