Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp470974pxp; Wed, 16 Mar 2022 09:21:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm0/o9r/vfPTDAdtEPvHOuNIpDjQdiLh3NJpUe7ACS2pFpFM0kbv/MBPs0Q8ctGMdZ9sru X-Received: by 2002:a17:907:94ca:b0:6da:e637:fa42 with SMTP id dn10-20020a17090794ca00b006dae637fa42mr592549ejc.347.1647447669293; Wed, 16 Mar 2022 09:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647447669; cv=none; d=google.com; s=arc-20160816; b=JPOk/lLETOOBim0mrZ6WW1ZAr4MNX38+Z348qIxAEiotFl0oMBKzm/v677BhNM5n0b s8zze5M+gBu1EEwW24iEpGg84//wPY4xOusRzKL94bgNP5uPZSD9YZ5kAlN7/xhNgRjF Mm4b41mD9HOMCAQPdqrJ1x+5PXrA5pnbSDdQ6agLMcNFJH5Qrhsfro5xpGPIFBT3f/7j xcMkP4SufH7vlhTt46JCwO0R3QjKngjuuQgfw5fIedRWqRb2uKps9N2Pudu2LA5cS8iR 4eChl4Zvum0oWClg8X2Up0N7w3Kn9X0qyAdH92a1VEKk2pv5Bt5v76jp9SPdmxVM+32U LyvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=fKwUPzANatNpDnPAPwrQ1epBnflw9F/VjDM4oAN2sDc=; b=VABv+nEaIBFl+mISQT07jZNycxhBVF0EHQWHgQUPCY6RLX/OZ8yyQtZP6aisMPUyOW AxTOxGfyaR7SypFlVrT+qze0NVj/yh+3y7gt7VFdHTGlF3ZGSDxGo6iwvYFTJOnnNFKh gUhlNk/5SiJ2C3NJUvLuwkf1iInaqEYf2mkQM7a5XrVyn9qP4o+UwfdMi0E+TxSAW5Cz hov0lKOwhUxOjqWNtceEUDqxugNd+QvIzAxZCWk/oNUlXkbsu3jpPt5UkKxinvNMm9k1 HBD19LqComy4QL3i0h2KHSNeheWqbCG0UDAMQxbntI3sFLhRYYxk+J5/+LgGrbmCC0nJ 3zkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d2-20020a50cf42000000b00410b9a8dd7dsi1566085edk.282.2022.03.16.09.20.42; Wed, 16 Mar 2022 09:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347757AbiCPPim (ORCPT + 99 others); Wed, 16 Mar 2022 11:38:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242953AbiCPPil (ORCPT ); Wed, 16 Mar 2022 11:38:41 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 502C76D1B4 for ; Wed, 16 Mar 2022 08:37:26 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 16BB51476; Wed, 16 Mar 2022 08:37:26 -0700 (PDT) Received: from e122027.arm.com (unknown [10.57.43.235]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 560793F7D7; Wed, 16 Mar 2022 08:37:24 -0700 (PDT) From: Steven Price To: Peter Zijlstra , Thomas Gleixner , Vincent Donnefort Cc: linux-kernel@vger.kernel.org, Baokun Li , Dongli Zhang , Randy Dunlap , Valentin Schneider , Yuan ZhaoXiong , YueHaibing , Steven Price , Dietmar Eggemann Subject: [PATCH v2] cpu/hotplug: Set st->cpu earlier Date: Wed, 16 Mar 2022 15:36:37 +0000 Message-Id: <20220316153637.288199-1-steven.price@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Setting the 'cpu' member of struct cpuhp_cpu_state in cpuhp_create() is too late as other callbacks can be made before that point. In particular if one of the earlier callbacks fails and triggers a rollback that rollback will be done with st->cpu==0 causing CPU0 to be erroneously set to be dying, causing the scheduler to get mightily confused and throw its toys out of the pram. Move the assignment earlier before any callbacks have a chance to run. Fixes: 2ea46c6fc945 ("cpumask/hotplug: Fix cpu_dying() state tracking") Signed-off-by: Steven Price CC: Dietmar Eggemann --- Changes since v1[1]: * Added a Fixes: tag. * Moved the assignment to just before cpuhp_set_state() which is the first place it is needed. [1]: https://lore.kernel.org/r/20220225134918.105796-1-steven.price%40arm.com kernel/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 407a2568f35e..c1324c8677cf 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -720,7 +720,6 @@ static void cpuhp_create(unsigned int cpu) init_completion(&st->done_up); init_completion(&st->done_down); - st->cpu = cpu; } static int cpuhp_should_run(unsigned int cpu) @@ -1351,6 +1350,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target) cpuhp_tasks_frozen = tasks_frozen; + st->cpu = cpu; cpuhp_set_state(st, target); /* * If the current CPU state is in the range of the AP hotplug thread, -- 2.25.1