Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp194432lql; Fri, 12 Apr 2024 07:45:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6T5sQMvWLHNV4w/ebao2n8i5X+riSXOIO7envjAKIQULZ09UxxxCq+xZqBoCzMWHNO46LDVAuBlegu0bG8XReQD3q8rADf5CSaHlzhA== X-Google-Smtp-Source: AGHT+IGeZDtQSvK6E3S9vqYYsbA/9U/7Jzr2iZis2zg8iXMyWLMhKk8iHF2RoWZS9Jc6EpxiBshl X-Received: by 2002:a17:903:1209:b0:1e0:b862:5330 with SMTP id l9-20020a170903120900b001e0b8625330mr3134140plh.54.1712933143395; Fri, 12 Apr 2024 07:45:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712933143; cv=pass; d=google.com; s=arc-20160816; b=zsS7ET/FbCxO6EkINIotd0doVinig/eZUSD1zhaj6Ocw7gvXL//NSHDI/2aj36+esH eH8T21G5F2ebiIBY/AC3H1ThDeC7pwEa3hAvW57Ec5jaKQzbXb9OBMgzSDzPihZqdDLv 3lyQBcBw2UaPgh52TLTAu1vKBPCNQzjzVNFShE6jk7fa19UHOqbl2Bm9VbK+q3B1/AXH fKIlGjNstss8H1heerW5h+Dspp+CzwSmEDzd6IVpsNSqZf9GO5yDQ1VOuZumlws6g3Uv 7mccoSDoMFVnLHvPYF3YMhRiFpTX10klf/T1Ped98desDcrx2G+pH3PKXM16RE3/ay7V 5qpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=bKW4Zb1cTw1YuZcukRUPUj3Ub3CDsRflfDCOkQF1q4o=; fh=8XQHdFtte3XOHSEIytMgmfctfSZlTmw2q6RqB5HTTCI=; b=e/qxUFPOiNBFbSlRfM673HkpYH9gOIttGd3m9QLurnj1Q3lLxCDQcDk3nUHaSsMgar xYAbyjSXd3ZZN9lV/cz7rcJkF41K9FDjJfl29URx5CVYm3O9HE8JmII2271lp9ZHxidt UT5ujQkbsXpdEJnB32BMQiSYmj9qBey1FPQindx5qUMGHWkrwq9FKQn7JdgmTtiD2IEt vvVoN3JW3bPy4vMEbITPYQYXv6Du3/4X1EmT1UpTb297WG/3wtbI8Lmvfcp4SbJJVC/I JQ5HEujRAdhCWUysYKsmV4IAVEueFL2wuVUCrHfFdZhpBopBc0G+uSpmMSlUuZe0XobO sDVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-142870-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f17-20020a170902ce9100b001e3f248a8a4si3270436plg.589.2024.04.12.07.45.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 07:45:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142870-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-142870-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 123362822F8 for ; Fri, 12 Apr 2024 14:45:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67885144D34; Fri, 12 Apr 2024 14:45:32 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92FCB8614D; Fri, 12 Apr 2024 14:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712933131; cv=none; b=g4ZMM/QDr22nvfBeRrPgjQ8n+/xcthaUvEpa9Nx+DgmzHba7JIx7GaTx9LXl+GQ9XX2o0Bsww82fj8Uskhqk5FT7xu+B3K/tJWewuddEpWANL3em6/qz8SMlCZo+SaiGh22kWMrZzCj86D1zJSnwph/AZD2dziLfExtQFQNZPPA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712933131; c=relaxed/simple; bh=Zh2SqBQq28G/7th8Ws/9M8NeB0ZeAz1H/E9UJ16xcjU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eU7XxUiUpns0Nm+7IT4Afh2V37iwpKX4hYbFPgxsCd4i1/kn2YKZH63KypCilWwzD3RBu2MqYk5Y8pfvdnHc6Zw3Ej+CczmUk6ZksBmY4UI8Rcnv/Zre7SAXhomV3ewKy1+DSKPGAB+B8yRi9jgXFOhMMNBhNd8uSB/dZk+P6QU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VGK7g2hZzz6J6WZ; Fri, 12 Apr 2024 22:43:43 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id A8CC41402CD; Fri, 12 Apr 2024 22:45:27 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 12 Apr 2024 15:45:27 +0100 From: Jonathan Cameron To: , , , , , , , , Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon CC: , , Subject: [PATCH v5 16/18] ACPI: add support to (un)register CPUs based on the _STA enabled bit Date: Fri, 12 Apr 2024 15:37:17 +0100 Message-ID: <20240412143719.11398-17-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412143719.11398-1-Jonathan.Cameron@huawei.com> References: <20240412143719.11398-1-Jonathan.Cameron@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500005.china.huawei.com (7.191.163.240) From: James Morse acpi_processor_get_info() registers all present CPUs. Registering a CPU is what creates the sysfs entries and triggers the udev notifications. arm64 virtual machines that support 'virtual cpu hotplug' use the enabled bit to indicate whether the CPU can be brought online, as the existing ACPI tables require all hardware to be described and present. If firmware describes a CPU as present, but disabled, skip the registration. Such CPUs are present, but can't be brought online for whatever reason. (e.g. firmware/hypervisor policy). Once firmware sets the enabled bit, the CPU can be registered and brought online by user-space. Online CPUs, or CPUs that are missing an _STA method must always be registered. When firmware clears the enabled bit, we need to unregister the CPU for symetry. As this is dependent on hotplug CPU being support, and arch_unregister_cpu() only exists when hotplug CPU is supported, we need to add a check for that configuration symbol. Note that some elements in the *make_present() and *make_not_present() paths are not appropriate for the *enabled() paths beause they are related to elements such as interrupt controller setup that are done for all present (but not enabled) CPUs at boot. Signed-off-by: James Morse Tested-by: Miguel Luis Tested-by: Vishnu Pajjuri Tested-by: Jianyong Wu Signed-off-by: Russell King (Oracle) Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron --- v5: Make the enable and present paths look much more like each other. Whilst similar, I think combining the two paths any more will lead to less readable code by implying they are more similar than they actually should be. --- drivers/acpi/acpi_processor.c | 46 +++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c index 3fb167ee9807..ffa2bc63da40 100644 --- a/drivers/acpi/acpi_processor.c +++ b/drivers/acpi/acpi_processor.c @@ -226,6 +226,24 @@ static int acpi_processor_make_present(struct acpi_processor *pr) return ret; } +static int acpi_processor_make_enabled(struct acpi_processor *pr) +{ + int ret; + + if (invalid_phys_cpuid(pr->phys_id)) + return -ENODEV; + + cpus_write_lock(); + ret = arch_register_cpu(pr->id); + cpus_write_unlock(); + + if (ret) + return ret; + + pr_info("CPU%d has been hot-added (onlined)\n", pr->id); + return 0; +} + static int acpi_processor_get_info(struct acpi_device *device) { union acpi_object object = { 0 }; @@ -319,7 +337,7 @@ static int acpi_processor_get_info(struct acpi_device *device) */ if (!invalid_logical_cpuid(pr->id) && cpu_present(pr->id) && !get_cpu_device(pr->id)) { - int ret = arch_register_cpu(pr->id); + int ret = acpi_processor_make_enabled(pr); if (ret) return ret; @@ -463,6 +481,27 @@ static int acpi_processor_add(struct acpi_device *device, return result; } +static void acpi_processor_make_not_enabled(struct acpi_device *device) +{ + struct acpi_processor *pr; + + pr = acpi_driver_data(device); + if (pr->id >= nr_cpu_ids) + goto out; + + device_release_driver(pr->dev); + per_cpu(processor_device_array, pr->id) = NULL; + per_cpu(processors, pr->id) = NULL; + cpus_write_lock(); + arch_unregister_cpu(pr->id); + cpus_write_unlock(); + + try_offline_node(cpu_to_node(pr->id)); +out: + free_cpumask_var(pr->throttling.shared_cpu_map); + kfree(pr); +} + /* Removal */ static void acpi_processor_make_not_present(struct acpi_device *device) { @@ -515,7 +554,7 @@ static void acpi_processor_post_eject(struct acpi_device *device) unsigned long long sta; acpi_status status; - if (!device) + if (!IS_ENABLED(CONFIG_HOTPLUG_CPU) || !device) return; pr = acpi_driver_data(device); @@ -530,6 +569,9 @@ static void acpi_processor_post_eject(struct acpi_device *device) acpi_processor_make_not_present(device); return; } + + if (cpu_present(pr->id) && !(sta & ACPI_STA_DEVICE_ENABLED)) + acpi_processor_make_not_enabled(device); } #ifdef CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC -- 2.39.2