Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3366790rdb; Wed, 13 Sep 2023 09:50:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIA8ycA150VFJ1q4ykrDH68HFrbB5YpPrm1rhkp+oxh9Q6kKL3M81lHUiqZMqDe28wO7vO X-Received: by 2002:a17:902:9884:b0:1bb:b855:db3c with SMTP id s4-20020a170902988400b001bbb855db3cmr2637982plp.41.1694623807750; Wed, 13 Sep 2023 09:50:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694623807; cv=none; d=google.com; s=arc-20160816; b=WHjmmVknT7pHCfjqcvg+c7ULT84Gmuwt4em0bJWRT9SQOATtgsifl1LzVv+kn5PMAL DHslBQUR90qmnSfAo2NNvZ5IzIb9noZJ3hWC0CxMFZ4d6OrH6xFEXam8rM1ehFGt/+sR wxHJ8EF1T8HSoy1f/mLh27Zjx697bcx/6RurpLsV7DwZ35AGTaMgTiMakHjX335xY2Nl 5zDDTwVTvaaDSfji7L3wimNjQ9BUhGL49DOHIelfb/QxzzUwkuaENVvKNcvPE0UdWfyg f44TuZpmDgSJm0GMPsMNylXuOQPukov52P6m9KCKLe4jWJoMph4FEiuItFJaQZJJ4s16 ObAg== 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=D7Fwj9qY3mLo8YgU5ROdUqQwH6WDt9GRbLRoKtLliQ8=; fh=2nhVWB0fZ+8YH0lLFpnF/Mo8eq+n1VMLe+b+IpvS0g0=; b=zOuw0mB9v9hgwud0WtK3AYofCv0jSj32a1JCB79BqvrgBXSMdEmpbU2DSC5OaOvXzd sysJzuHc2Mmusvv1KcrlGEfiajC3kDRSKhIg5SeH54WpDE7xVoR9vxDGi88d4sufa3IN csWvi0cEQJmdXXKmyMgGzsaAho+M+53vXRsTg3Jt/ormpRDG1xRyf/yitgpm5FSCdhuu P2RO2urmmuARY8GGxEnP5MmMeoSx7iuhz0VzYe5xp5IA+y2hpWiPzOzavXyPwehaEIof iGhO3QAXOJMKN49jiXcAAxgqk9Y6uDMQVX4hhsS2g/5GWP/K2mfALTYLPRZZtM9tIbl2 7sZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id y15-20020a17090264cf00b001bdf47701f4si10281971pli.197.2023.09.13.09.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 09:50:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 96589835A6BE; Wed, 13 Sep 2023 09:41:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbjIMQlH (ORCPT + 99 others); Wed, 13 Sep 2023 12:41:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231127AbjIMQj7 (ORCPT ); Wed, 13 Sep 2023 12:39:59 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 657731BEC; Wed, 13 Sep 2023 09:39:37 -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 5B6AA1FB; Wed, 13 Sep 2023 09:40:14 -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 60F763F5A1; Wed, 13 Sep 2023 09:39:35 -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 22/35] ACPI: Check _STA present bit before making CPUs not present Date: Wed, 13 Sep 2023 16:38:10 +0000 Message-Id: <20230913163823.7880-23-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 (pete.vger.email [0.0.0.0]); Wed, 13 Sep 2023 09:41:31 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email 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 +++++++++++++++++++++++++------ include/linux/cpu.h | 1 + 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c index 00dcc23d49a8..2cafea1edc24 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, }, diff --git a/include/linux/cpu.h b/include/linux/cpu.h index a71691d7c2ca..e117c06e0c6b 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -81,6 +81,7 @@ struct device *cpu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups, const char *fmt, ...); extern int arch_register_cpu(int cpu); +extern void arch_unregister_cpu(int cpu); #ifdef CONFIG_HOTPLUG_CPU extern void unregister_cpu(struct cpu *cpu); extern ssize_t arch_cpu_probe(const char *, size_t); -- 2.39.2