Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3367863rdb; Wed, 13 Sep 2023 09:51:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3nopB75lQ95xhjab3BrOxGCbTZHqwkymdnwueIJpawu3LVfzjDz6A1tHzEGsIP4FHLwtb X-Received: by 2002:a05:6a00:2e87:b0:68f:f38d:f758 with SMTP id fd7-20020a056a002e8700b0068ff38df758mr3121043pfb.34.1694623911861; Wed, 13 Sep 2023 09:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694623911; cv=none; d=google.com; s=arc-20160816; b=MDKPoC+I5pDkG3CqcLmMHesg8RmfrgAbxhQqJbj0sHbvcV19W6+z6hV53own4c+Vjp Nn/rlI2iGfbQENEgDLJGYD4v8UckASjkrIPLtJyktM7Vatbg+lmRnnSMwMxEN2kfKIFK cZA6gr9esV2GiZajoitmw4ODeeweFNFxmEzCVOGhhRDSdldCwwkRsoudGSQbU3cvQNa5 QQDuiMBv+88C0rIFi989wpSXWcxPt89rEWgix0Fz8OteIWLxQq+uhEspYwRLJJtjg0S0 ReZgFrGB4+InE1ZN9cHJqnRfZ/V4mOQ2aYNPC4LpxnBvwEr6r3GQcLWGNSzGHiFiFREs 5DaA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4nts9Z5V79ffHKEfbTuPKMkI7gmykrCBAlzYIqy0Ih0=; fh=2nhVWB0fZ+8YH0lLFpnF/Mo8eq+n1VMLe+b+IpvS0g0=; b=E1Vdb9OzDbMfRpIoSogSyYYHgo+bcOGWkwCAllgUrePeB1JF3UfZo6yeP1cU/SWb3y T0wDlKx36gIzaiGVZq7jxxuST/dRulpcnuuYz7bZDi8izX4uY10VrT2KHyi6h/gy6pB3 sqTLVafxMHJF1kmrev/zH69p8e9Umh8ukqb3b9Jr+oFXkMhOdDoTyNUSzZN/DOMu9Tm8 9teOxqQC0cWBvoqoOKb/6XO7DSx+VG9FLUB+cKxyJN73f/ovDjbxGiZgQO9OH0jyZkqQ 2S4zbbVuV0v+Vgw+oGANizPbPzUWYwDggcFjlTie7trulp352qvOA1Ftn9z2fytv/Zp9 UVCA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ct9-20020a056a000f8900b0068780155ddbsi10449045pfb.131.2023.09.13.09.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 09:51:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 41EBF80C0557; Wed, 13 Sep 2023 09:42:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231488AbjIMQmN (ORCPT + 99 others); Wed, 13 Sep 2023 12:42:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjIMQlR (ORCPT ); Wed, 13 Sep 2023 12:41:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4D7FE2D41; Wed, 13 Sep 2023 09:39:57 -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 4B8EB13D5; Wed, 13 Sep 2023 09:40:34 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 50C7C3F5A1; Wed, 13 Sep 2023 09:39:55 -0700 (PDT) From: James Morse To: linux-pm@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, kvmarm@lists.linux.dev Cc: x86@kernel.org, Salil Mehta , Russell King , Jean-Philippe Brucker , jianyong.wu@arm.com, justin.he@arm.com Subject: [RFC PATCH v2 32/35] ACPI: add support to register CPUs based on the _STA enabled bit Date: Wed, 13 Sep 2023 16:38:20 +0000 Message-Id: <20230913163823.7880-33-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230913163823.7880-1-james.morse@arm.com> References: <20230913163823.7880-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 09:42:13 -0700 (PDT) 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. Signed-off-by: James Morse --- drivers/acpi/acpi_processor.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c index b67616079751..b49859eab01a 100644 --- a/drivers/acpi/acpi_processor.c +++ b/drivers/acpi/acpi_processor.c @@ -227,6 +227,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; @@ -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.39.2