Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2078922lqa; Tue, 30 Apr 2024 07:40:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVt3UkkdaEFxC3nwpchRCoSIBNgK4/wNfZUquITRdnGMGeqP1grzmRP283vSE9awXjfFRwa1y3SKxfZ/XLDOI62PPLBoaQejO3Qz5bj+g== X-Google-Smtp-Source: AGHT+IH2oxctoxRTdEpPE5raEhQUW+RWV0WWWn9vM123v5nxqShk42Gu/Iip+OK3vPko2BPhMvzA X-Received: by 2002:a05:6830:22e6:b0:6ed:e4fc:b78e with SMTP id t6-20020a05683022e600b006ede4fcb78emr11469139otc.26.1714488044567; Tue, 30 Apr 2024 07:40:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714488044; cv=pass; d=google.com; s=arc-20160816; b=zalaHEvG9Hw8aHtBFLdbDzwuTaP/W9uw6X1GTzte+V3OTryNY9M8xE2IHRIXjz1NfC cjF2r+2E5qv4V2fJQyKJcjQxfejBJ68hc/AtQhFuc6MQeu3RvK0SQwfnaFwdbRHOmlZe 7ZNnTZtnCqCJsoEfxg15o57PksBJ2so9/sI5VKUxWc+sunGe66xbdUPMzkH7UU+1X1Gl a9stY2FW/v4mINHCpnI1PSLoN6m+z0wm8dpSaNgJW3WfjHoSZ9KQijrcb6V+IWRP0FF9 PqDwTZvPqAqPWGnr6aMcNnDw5pdUSmcmfD2g5useuUwpihsT0v0yB3dj70NBlRq0GxGn DqVw== 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=VhrLUi0irwobryjkmFvwmhdhk6uj/gfythaQZQDsdvI=; fh=25IklNjpQtm3+ZI4w1ifckV22BkO2b6a/wyTwiBBJrk=; b=Nqti4fkiURWonkNzfx3aiojSKS6h7w5MsRQ67hJyjn4yc12bPL5xftdgY+cVSIvBM4 kM9vF2W//cm/lt1wVCq5MTThXtJGKIlaYiBIuSS9kUZaH/sAwQ0YL+71AkB1nfklzUsN UXPtKRU0riCc3a0eN4Bq6M6HrFVkL70QM5GJNdOPuByQw99UKZlL7iRQEnxQ+pUYP+1z pqzZzdLw22rAwOS7rgfPBJZS1CnbK273gamJsCqdeVac9F7nR+HFyHeLx96Ap9rRdWZ8 ybhfWJJWoG/rg30s4QXIiISGkRdFQ0bSI03vdYbMtOwwwXBgoSTPCgD2L9OlAhZH/5WH DAJw==; 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-164170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164170-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v11-20020a05620a0f0b00b0078f0ff5b917si31749424qkl.307.2024.04.30.07.40.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:40:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-164170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164170-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3A7391C23026 for ; Tue, 30 Apr 2024 14:40:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA75C17F39C; Tue, 30 Apr 2024 14:32:54 +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 D52EF17F392; Tue, 30 Apr 2024 14:32:51 +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=1714487574; cv=none; b=DG1BHtLFjMpkMBJl5g5u03igCdTQ5BHVEdH5pxqa0WnYD2F5EgmLU/hxM8TI+wDlzNnROqTOnc6/52RsG6TbpkrTBoQbiaOZNKcEFutEtMvlOTbeJAwpTBqkSXTCrJxSqEDumzqC0zaEE283nwdOORfIBCJn2Q7ULUxCVRG50fw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714487574; c=relaxed/simple; bh=svjcxzg91WgRmCQMi8vliHnXPWnljftkUS44mTk2PVI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pdF6ZQyBqcjj9RcE2DCHbneMpeYBRqCyng/5FvYkljWcd556ZpxSMHH8CrqwUnc39M1t5IvFvkQfE0UtYLr0RXKTJ5O/CNuDQZt4pSJpvS44qLTvaXZY60sX3R5Iz+AuIxZPuW1DsCucHQZpu65VSwy4/8/nmyU4vWQvejbaRk4= 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.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VTMzh6GDvz6J7Qn; Tue, 30 Apr 2024 22:30:08 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id AE7311400DC; Tue, 30 Apr 2024 22:32:49 +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; Tue, 30 Apr 2024 15:32:48 +0100 From: Jonathan Cameron To: Thomas Gleixner , Peter Zijlstra , , , , , , , , , Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , Marc Zyngier , Hanjun Guo , Gavin Shan CC: Ingo Molnar , Borislav Petkov , Dave Hansen , , , Subject: [PATCH v9 16/19] arm64: arch_register_cpu() variant to check if an ACPI handle is now available. Date: Tue, 30 Apr 2024 15:24:31 +0100 Message-ID: <20240430142434.10471-17-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430142434.10471-1-Jonathan.Cameron@huawei.com> References: <20240430142434.10471-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: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500005.china.huawei.com (7.191.163.240) The ARM64 architecture does not support physical CPU HP today. To avoid any possibility of a bug against such an architecture if defined in future, check for the physical CPU HP case (not present) and return an error on any such attempt. On ARM64 virtual CPU Hotplug relies on the status value that can be queried via the AML method _STA for the CPU object. There are two conditions in which the CPU can be registered. 1) ACPI disabled. 2) ACPI enabled and the acpi_handle is available. _STA evaluates to the CPU is both enabled and present. (Note that in absence of the _STA method they are always in this state). If neither of these conditions is met the CPU is not 'yet' ready to be used and -EPROBE_DEFER is returned. Success occurs in the early attempt to register the CPUs if we are booting with DT (no concept yet of vCPU HP) if not it succeeds for already enabled CPUs when the ACPI Processor driver attaches to them. Finally it may succeed via the CPU Hotplug code indicating that the CPU is now enabled. For ACPI if CONFIG_ACPI_PROCESSOR the only path to get to arch_register_cpu() with that handle set is via acpi_processor_hot_add_init() which is only called from an ACPI bus scan in which _STA has already been queried there is no need to repeat it here. Add a comment to remind us of this in the future. Suggested-by: Rafael J. Wysocki Tested-by: Miguel Luis Reviewed-by: Gavin Shan Signed-off-by: Jonathan Cameron --- V9: No change. (tags collected only) --- arch/arm64/kernel/smp.c | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index b4b3f832520c..7ed1f70ace0b 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -504,6 +504,59 @@ static int __init smp_cpu_setup(int cpu) static bool bootcpu_valid __initdata; static unsigned int cpu_count = 1; +int arch_register_cpu(int cpu) +{ + acpi_handle acpi_handle = acpi_get_processor_handle(cpu); + struct cpu *c = &per_cpu(cpu_devices, cpu); + + if (!acpi_disabled && !acpi_handle && + IS_ENABLED(CONFIG_ACPI_HOTPLUG_CPU)) + return -EPROBE_DEFER; + +#ifdef CONFIG_ACPI_HOTPLUG_CPU + /* For now block anything that looks like physical CPU Hotplug */ + if (invalid_logical_cpuid(cpu) || !cpu_present(cpu)) { + pr_err_once("Changing CPU present bit is not supported\n"); + return -ENODEV; + } +#endif + + /* + * Availability of the acpi handle is sufficient to establish + * that _STA has aleady been checked. No need to recheck here. + */ + c->hotpluggable = arch_cpu_is_hotpluggable(cpu); + + return register_cpu(c, cpu); +} + +#ifdef CONFIG_ACPI_HOTPLUG_CPU +void arch_unregister_cpu(int cpu) +{ + acpi_handle acpi_handle = acpi_get_processor_handle(cpu); + struct cpu *c = &per_cpu(cpu_devices, cpu); + acpi_status status; + unsigned long long sta; + + if (!acpi_handle) { + pr_err_once("Removing a CPU without associated ACPI handle\n"); + return; + } + + status = acpi_evaluate_integer(acpi_handle, "_STA", NULL, &sta); + if (ACPI_FAILURE(status)) + return; + + /* For now do not allow anything that looks like physical CPU HP */ + if (cpu_present(cpu) && !(sta & ACPI_STA_DEVICE_PRESENT)) { + pr_err_once("Changing CPU present bit is not supported\n"); + return; + } + + unregister_cpu(c); +} +#endif /* CONFIG_ACPI_HOTPLUG_CPU */ + #ifdef CONFIG_ACPI static struct acpi_madt_generic_interrupt cpu_madt_gicc[NR_CPUS]; -- 2.39.2