Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp281163pxm; Fri, 25 Feb 2022 07:55:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoe2pjQczC3i1Bsm83qgoakWW86uvzONwpnV+mHeSX6IYBGqOMwpaw2F2wiX3zZL+GmL3V X-Received: by 2002:a63:904a:0:b0:340:87e0:f640 with SMTP id a71-20020a63904a000000b0034087e0f640mr6534801pge.171.1645804553721; Fri, 25 Feb 2022 07:55:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645804553; cv=none; d=google.com; s=arc-20160816; b=YysB66obbkWpzn23WUxYTqt+mWfUNUv8z7zYBT+BohbVT7+wOFoFtzYxu1dJD8hbHs ctujLIdpc/3Kg565fNFCT1d1dNI4FImBpZhvQXCnKVJPmG5xzJPjCtyWZfh/hWr15MQl 2ljy+U89CHpVVdT8bh2nxSfULiz+xzpWHosnkDowexXkGgFgzDCePgO40o2UCkVkQT+J 6QHLklI1zeJjNwoyKi2Wb1k1qYG6UI8nqeCQLqikgksI1zAu8EBHWn2kE64Irp8rojzD JnkmLhZyVhFQwnk52Lxhi94vT1WpEoXmOWdP4EfbPiKnKCyFadhvaivIL2WU1Oy4e3sd /33Q== 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=0pLHQoiPpTRjS6lhhtSEgL3ZnqyV4TuoLPE+5Mqyt28=; b=pt+j6qLrkPj1nHuTNz1577QpVCihhL4yvBzUUDv2AwUu/GRQJfa++glTJ40gZVhrrQ Ozq+gsFLXpZSlKn4oqnLbbxVILQfbmCR9dLwXfQKNoDTElpXCbjzffjp8m28Mz5S6jf5 TrewQlpVtCq+M8bee+bt3Mcx7wkabBx/wOru6PLXI0oMroH5eSLlJ88ThohK1JYikltS rQRstfIusxRxrEG8nNOm2rMjusKhqgove6Ahak8rPk7b5CSa3j1OvNlMBpuRyGtF4Ydl obXC7Bk6sFwtHR2wTeU3Hs5EFDKNSLouD6HFH3FaF7EiyaC4NBXKaoMOsi87fgQqNnNn uPIA== 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 q21-20020a62ae15000000b004f0f9696574si1952726pff.175.2022.02.25.07.55.37; Fri, 25 Feb 2022 07:55:53 -0800 (PST) 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 S232117AbiBYNuC (ORCPT + 99 others); Fri, 25 Feb 2022 08:50:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231828AbiBYNt7 (ORCPT ); Fri, 25 Feb 2022 08:49:59 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02A441DDFC3 for ; Fri, 25 Feb 2022 05:49:28 -0800 (PST) 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 C1E0712FC; Fri, 25 Feb 2022 05:49:27 -0800 (PST) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.1.32.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A7F093F5A1; Fri, 25 Feb 2022 05:49:25 -0800 (PST) From: Steven Price To: Peter Zijlstra , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Baokun Li , Ingo Molnar , Mark Rutland , Randy Dunlap , Valentin Schneider , Vincent Donnefort , YueHaibing , Steven Price , Dietmar Eggemann Subject: [PATCH] cpu/hotplug: Set st->cpu earlier Date: Fri, 25 Feb 2022 13:49:18 +0000 Message-Id: <20220225134918.105796-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. Signed-off-by: Steven Price CC: Dietmar Eggemann --- This was initially triggered by a VM which didn't have enough memory for its VCPUs, but an easier way of triggering it is to make a change like below in __smpboot_create_thread (as suggested by Dietmar Eggemann) to pretend the memory allocation fails for a particular CPU: td = kzalloc_node(sizeof(*td), GFP_KERNEL, cpu_to_node(cpu)); - if (!td) + if (!td || cpu == 1) return -ENOMEM; I'm not entirely sure quite where the best place to set st->cpu is, so please do let me know if there's a better place to do the assignment. --- kernel/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/cpu.c b/kernel/cpu.c index 407a2568f35e..49c3ef6067e5 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) @@ -1333,6 +1332,8 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target) goto out; } + st->cpu = cpu; + /* * The caller of cpu_up() might have raced with another * caller. Nothing to do. -- 2.25.1