lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <E1rVDnP-0027ZZ-BN@rmk-PC.armlinux.org.uk>
Date: Wed, 31 Jan 2024 16:50:43 +0000
From: Russell King (Oracle) <rmk+kernel@...linux.org.uk>
To: linux-pm@...r.kernel.org,
	 loongarch@...ts.linux.dev,
	 linux-acpi@...r.kernel.org,
	 linux-arch@...r.kernel.org,
	 linux-kernel@...r.kernel.org,
	 linux-arm-kernel@...ts.infradead.org,
	 linux-riscv@...ts.infradead.org,
	 kvmarm@...ts.linux.dev,
	 x86@...nel.org,
	 acpica-devel@...ts.linuxfoundation.org,
	 linux-csky@...r.kernel.org,
	 linux-doc@...r.kernel.org,
	 linux-ia64@...r.kernel.org,
	 linux-parisc@...r.kernel.org
Cc: Salil Mehta <salil.mehta@...wei.com>,
	 Jean-Philippe Brucker <jean-philippe@...aro.org>,
	 jianyong.wu@....com,
	 justin.he@....com,
	 James Morse <james.morse@....com>,
	 Jonathan Cameron <Jonathan.Cameron@...wei.com>,
	 "Rafael J. Wysocki" <rafael@...nel.org>
Subject: [PATCH RFC v4 13/15] ACPI: add support to (un)register CPUs based on
 the _STA enabled bit

From: James Morse <james.morse@....com>

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.

Signed-off-by: James Morse <james.morse@....com>
Tested-by: Miguel Luis <miguel.luis@...cle.com>
Tested-by: Vishnu Pajjuri <vishnu@...amperecomputing.com>
Tested-by: Jianyong Wu <jianyong.wu@....com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@...linux.org.uk>
---
Changes since RFC v3 (smaller series):
 * Squash "ACPI: processor: Only call arch_unregister_cpu() if
   HOTPLUG_CPU is selected" into this patch.
---
 drivers/acpi/acpi_processor.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c
index d1d33e74216c..5e641180c45a 100644
--- a/drivers/acpi/acpi_processor.c
+++ b/drivers/acpi/acpi_processor.c
@@ -228,6 +228,32 @@ static int acpi_processor_make_present(struct acpi_processor *pr)
 	return ret;
 }
 
+static int acpi_processor_make_enabled(struct acpi_processor *pr)
+{
+	unsigned long long sta;
+	acpi_status status;
+	bool present, enabled;
+
+	if (!acpi_has_method(pr->handle, "_STA"))
+		return arch_register_cpu(pr->id);
+
+	status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	present = sta & ACPI_STA_DEVICE_PRESENT;
+	enabled = sta & ACPI_STA_DEVICE_ENABLED;
+
+	if (cpu_online(pr->id) && (!present || !enabled)) {
+		pr_err_once(FW_BUG "CPU %u is online, but described as not present or disabled!\n", pr->id);
+		add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
+	} else if (!present || !enabled) {
+		return -ENODEV;
+	}
+
+	return arch_register_cpu(pr->id);
+}
+
 static int acpi_processor_get_info(struct acpi_device *device)
 {
 	union acpi_object object = { 0 };
@@ -318,7 +344,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;
@@ -511,7 +537,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);
@@ -526,6 +552,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))
+		arch_unregister_cpu(pr->id);
 }
 
 #ifdef CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC
-- 
2.30.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ