Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1963694rda; Tue, 24 Oct 2023 08:22:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFYv9j3dDC+q34Q4ye1UXSigvcTIodkjbKtDiqeyU3yZI5HqeEpXbF+WvLwtWgjAc8tWV5 X-Received: by 2002:a17:903:110d:b0:1ca:d778:a9ce with SMTP id n13-20020a170903110d00b001cad778a9cemr8927317plh.38.1698160942510; Tue, 24 Oct 2023 08:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698160942; cv=none; d=google.com; s=arc-20160816; b=JgJhZBcs4L5T50ZQTH7mpJe6P6sGkkSRJHsKhbMKwRHh8QPY1FqC1FYnLWLiiRmygt iM3Kz1qUxuGwCblJAUsBzos0K7pg31xJgLi64iEq3PWq7DMzsHn+iCSvPXrCtxhrRLmT PwQI9gL4kakaLqQr05pdT/7P7b1wf67pCV6a/yAjmEoUMFyVxw5zFeUMgW4rVWQGWIgJ l1FfrT0eC3VHPG9rJa1y+KnTsTV02TLuSJALiUu+HS9aD1PjRM2Fl3nLZ3f8cQNp2zoi CkYpX033QgvDRwu76jEGUcSxDRbOUZXjwuHJwUIIA691Mgcs8lDSkB4oZFAhSlqTC52b raKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:sender:message-id:content-transfer-encoding :content-disposition:mime-version:subject:cc:to:from:references :in-reply-to:dkim-signature; bh=cGFxOS/yrCMC4X61kSxMueH/3TYdjD0lVNG7rD4LQi8=; fh=SkTV5xOrq7hxTIOggvbIOXu+48dqXijvMNKji0VGfy8=; b=PPcYtQ6/n6gSqMbimbltqhMGHCgI2YDEin1cR5HVjLqFWZr2YRfKpEgZRN6Zg07rem lAoeQjHIwwyryZWb+sUV6Z9LwaLvl1NDL5g7jLdZweBF2ek3iuMkQa/gdKj3WOUg/eLy BzsnJsigMmhFa7+mGMEpQt8nWzpvqd/x+stpqdx54GyebI1sCpN01+71pWds9wHFmppq yVYr84CfP+YXDpB/Avkg5xMMLzhb15Afbz5LlASP1blMi+UNyWVLm6uwEMusJvIxkRFD Jsk3clrDbNyijNClnct8b5usVDOYz2gNi+dGp9yqCkD6vLpZDhBOlINvlwOvm1aWTIZ/ pwVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=mM5DM85o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b2-20020a170902d50200b001c3b4eb2135si8691696plg.463.2023.10.24.08.22.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 08:22:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=mM5DM85o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1E80A802B04F; Tue, 24 Oct 2023 08:22:14 -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 S1343754AbjJXPWK (ORCPT + 99 others); Tue, 24 Oct 2023 11:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343573AbjJXPU5 (ORCPT ); Tue, 24 Oct 2023 11:20:57 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48AA1170E; Tue, 24 Oct 2023 08:18:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=cGFxOS/yrCMC4X61kSxMueH/3TYdjD0lVNG7rD4LQi8=; b=mM5DM85oML8fncS2AzDteCE+Cf twsep7g+E6E1YioCuTcHxWIPKAQfomgIR1bfKW+7KRY269ZjFix+j2YziC9bHMpL1gmuYbsLdiYt8 t0iJyRDkZ6i/vDXUT8ZZvMj0+IJAeDMje/YPxI+lYPHB+BwIbiIknET9OtEC3t6IJEt1knDyKAzMP DmqR6ZNAqHQCXY3kXZuLAB9kc14u2uxxzTL0cHEhym/+0CX8/yst1/5P+xZcTW6u5DIhrMXUWZ9zT MB5esOO2m5ge2eNsI73Q0YLjN0pX/Aj780yGTQEdC0YaOYz9rWjgrhfSzyvf6FfR8/yDcoSn8zvdQ PtapjFUQ==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:53108 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qvJAo-0004Ty-2Q; Tue, 24 Oct 2023 16:18:26 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1qvJAq-00AqRS-7i; Tue, 24 Oct 2023 16:18:28 +0100 In-Reply-To: References: From: Russell King (Oracle) 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, x86@kernel.org, linux-csky@vger.kernel.org, linux-doc@vger.kernel.org, linux-ia64@vger.kernel.org, linux-parisc@vger.kernel.org Cc: Salil Mehta , Jean-Philippe Brucker , jianyong.wu@arm.com, justin.he@arm.com, James Morse , "Rafael J. Wysocki" , Len Brown Subject: [PATCH 27/39] ACPI: Check _STA present bit before making CPUs not present MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Tue, 24 Oct 2023 16:18:28 +0100 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 08:22:14 -0700 (PDT) From: James Morse When called acpi_processor_post_eject() unconditionally make a CPU not-present and unregisters it. To add support for AML events where the CPU has become disabled, but remains present, the _STA method should be checked before calling acpi_processor_remove(). Rename acpi_processor_post_eject() acpi_processor_remove_possible(), and check the _STA before calling. Adding the function prototype for arch_unregister_cpu() allows the preprocessor guards to be removed. After this change CPUs will remain registered and visible to user-space as offline if buggy firmware triggers an eject-request, but doesn't clear the corresponding _STA bits after _EJ0 has been called. Signed-off-by: James Morse --- drivers/acpi/acpi_processor.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c index b6f5005985c3..19fceb3ec4e2 100644 --- a/drivers/acpi/acpi_processor.c +++ b/drivers/acpi/acpi_processor.c @@ -457,13 +457,12 @@ static int acpi_processor_add(struct acpi_device *device, return result; } -#ifdef CONFIG_ACPI_HOTPLUG_PRESENT_CPU /* Removal */ -static void acpi_processor_post_eject(struct acpi_device *device) +static void acpi_processor_make_not_present(struct acpi_device *device) { struct acpi_processor *pr; - if (!device || !acpi_driver_data(device)) + if (!IS_ENABLED(CONFIG_ACPI_HOTPLUG_PRESENT_CPU)) return; pr = acpi_driver_data(device); @@ -501,7 +500,29 @@ static void acpi_processor_post_eject(struct acpi_device *device) free_cpumask_var(pr->throttling.shared_cpu_map); kfree(pr); } -#endif /* CONFIG_ACPI_HOTPLUG_PRESENT_CPU */ + +static void acpi_processor_post_eject(struct acpi_device *device) +{ + struct acpi_processor *pr; + unsigned long long sta; + acpi_status status; + + if (!device) + return; + + pr = acpi_driver_data(device); + if (!pr || pr->id >= nr_cpu_ids || invalid_phys_cpuid(pr->phys_id)) + return; + + status = acpi_evaluate_integer(pr->handle, "_STA", NULL, &sta); + if (ACPI_FAILURE(status)) + return; + + if (cpu_present(pr->id) && !(sta & ACPI_STA_DEVICE_PRESENT)) { + acpi_processor_make_not_present(device); + return; + } +} #ifdef CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC bool __init processor_physically_present(acpi_handle handle) @@ -626,9 +647,7 @@ static const struct acpi_device_id processor_device_ids[] = { static struct acpi_scan_handler processor_handler = { .ids = processor_device_ids, .attach = acpi_processor_add, -#ifdef CONFIG_ACPI_HOTPLUG_PRESENT_CPU .post_eject = acpi_processor_post_eject, -#endif .hotplug = { .enabled = true, }, -- 2.30.2