From patchwork Thu Dec 5 05:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 13894715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4DD30E77172 for ; Thu, 5 Dec 2024 05:43:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.848857.1263643 (Exim 4.92) (envelope-from ) id 1tJ4eA-0002FM-CV; Thu, 05 Dec 2024 05:43:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 848857.1263643; Thu, 05 Dec 2024 05:43:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4eA-0002FF-9i; Thu, 05 Dec 2024 05:43:30 +0000 Received: by outflank-mailman (input) for mailman id 848857; Thu, 05 Dec 2024 05:43:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4e9-0001z8-AG for xen-devel@lists.xenproject.org; Thu, 05 Dec 2024 05:43:29 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20617.outbound.protection.outlook.com [2a01:111:f403:2417::617]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d9891a44-b2cb-11ef-a0d5-8be0dac302b0; Thu, 05 Dec 2024 06:43:28 +0100 (CET) Received: from CY8P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:930:6b::6) by SJ2PR12MB8783.namprd12.prod.outlook.com (2603:10b6:a03:4d0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.18; Thu, 5 Dec 2024 05:43:21 +0000 Received: from CY4PEPF0000FCC2.namprd03.prod.outlook.com (2603:10b6:930:6b:cafe::1a) by CY8P222CA0013.outlook.office365.com (2603:10b6:930:6b::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.9 via Frontend Transport; Thu, 5 Dec 2024 05:43:21 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000FCC2.mail.protection.outlook.com (10.167.242.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Thu, 5 Dec 2024 05:43:21 +0000 Received: from penny-System-Product-Name.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 4 Dec 2024 23:43:17 -0600 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d9891a44-b2cb-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=g5IU8p+c0CjXps19m4rZ3HVlRkE3B7xnWh/wbZ3j08JApanIbPoO3VnASiufSDoN2yM7UQTCl451OPIeQqCCjCV4eyutqnl/6mh8Mcie1z85MVT+SFMs4GjhaZhyW9EZvwgh3RMdpTSJDqqzQCQgCrsBuhrH6itKaXUby27gWEAHJyfoRKpzoEwHiMqNOTGF+lSsaJN6c+Nr3bEn1pKPRROzB+H3ZlOw0QX04MpuL3rBqPYyc7oGVd0+7XCSdduCf5ADU8KM+UL8f7V7sNmzEbD6tBFZ9K+PiydqrrX3yi2p6zAS7QlCZOQftBp0zbqhOMwzbHCyYN/ALHmOSo7t5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=A2mvoo0AwSmZHRNlDBxrD1PqpsXiFjqStSx71eJmWSM=; b=UPODDh/IMdn2eJ4WYxWTFfm9Yj5p3wM4+s6sCM7RqF2V8yzGWfoysICx6fmiN+onocscblKPmQst/nTB5gLw8E3a5sZy/JDQ2tyUAS4WV70JETbG/ZRiD2D1aFkOehHzEH1H1w5cBa7nPq5VILBWEP1+surJpHTLrAHmNmcCeCNwk5T3lp89K9thK6mrbvSSAuLmN7pypNPM27ZbJ6boaRkIPKSuJMdxTTpF0ZDMYVL80jida0eSQ7WcyclZ4OwdS3i6VuS6rYM52eJ+WYrLVG3jtzHyCcVQUq0l3tusKvRQO9FYJ0LFriAwvpDdhRzCItvlqlp/W88P4CMSpQ5SYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A2mvoo0AwSmZHRNlDBxrD1PqpsXiFjqStSx71eJmWSM=; b=nsFaJIkZpjJr7/jaFfc/lmXclPq/6cWh5sJ9nqWCfb2JAydkLqmFVA9eanTrEy0J9YzUEHHsC4MnDP21WG2CoN0T1cqlW28eyelhXUS6+M6L4cuHSOFHyhZLK7OTR3hxXH0HzpJEmqZN51x2heEKLlJHH+pSxvUP8b9t2HO+uBw= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Penny Zheng To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko CC: Ray Huang , Xenia Ragiadakou , Jason Andryuk , "Penny Zheng" , , , Roger Pau Monne Subject: [PATCH v2 1/4] xen/acpi: upload power and performance related data from a PVH dom0 Date: Thu, 5 Dec 2024 13:42:49 +0800 Message-ID: <20241205054252.471761-2-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241205054252.471761-1-Penny.Zheng@amd.com> References: <20241205054252.471761-1-Penny.Zheng@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC2:EE_|SJ2PR12MB8783:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bfe8ce1-6aef-43e0-8368-08dd14efba6b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?PiarisyywluveGpWvNTRJnXUg7TGuiR?= =?utf-8?q?qCMZ3hxnhSCPIyiSQ9r4O11jHiSVv0coP8canXIz/AhBeJEL48QMdv25jnWHqkjjh?= =?utf-8?q?/j+19ti0BP/4j+Te8K46lXLAzraGfEkyHBsKTTTBo3wrmZnMMUvquZGV4x/We41hv?= =?utf-8?q?rdIHHIJJjBxqtwSziT1DvlWxww/OaBIVqFpJemIRLoXu3PpxTs+sETQIBSy0v9CCe?= =?utf-8?q?mw0MASyhfAj80d93q7gWa7s4BZGqRdpNFh75JKIiKXZFXtLjQn59CWgxjicFA8Bay?= =?utf-8?q?5uuGjY6+Qrtd4V6ZF5gLqUQSAypbHLMvIKlou6TGyzpfK7nmZmmcQxvuAzjNdqlh7?= =?utf-8?q?PVdDg0RMkuoTxG0f0YZ4xJp5SCkMOyDafwZO5sCBePr6hEuQWIUuPNhXvRuC5HIzD?= =?utf-8?q?Vl1ogv5HUBe/duhZn7GnWPhFb4Ua512SunP2wQE36/BkcwsGk/7cxq7mbKjvH+90K?= =?utf-8?q?nF9SXalrfvWxn/G/kaN00Pv5MxUhwK0399HkH65EWSWOmiT2XEiNYAdXb0bYF+q4z?= =?utf-8?q?qnRF9yNRQQ/bQUnwB8xjphgL8OYImZJ/Y/uYRyPWtjSWBw3d7f+dh3fnPku4bpzf/?= =?utf-8?q?12MXPeEMA0FOP7RHIiZkNS1+rwgPuKOOsNlDSIqseUcXWDVOqf1i9WQb/k/zP+91P?= =?utf-8?q?oLMwwiaH4dDuEzOcHlY4M83AmAXCRpNQwiAJrO9eG/QkTgxMy+AfUKKY4pmToweRu?= =?utf-8?q?+kFeRFQGRYQDhxfKdyZ58hSasS749C3U/O6077YSJmcGGRBtWEU2p+P3NqXVVU5Di?= =?utf-8?q?CHW9bqgpONX6DmxA7NSzUPJQKZBLWvcgKVfjhBgf/lvMQdViMQyBoae96zPIefj+c?= =?utf-8?q?UMIbVHb2xH5uOuvM4Lsjrs0KAOyPR4/a7fyA9xFDPcP+isB9u8lg4V1FDnP69T66P?= =?utf-8?q?rNw97kmSrJvULFhTBQZg5LFRj7uznczqvXw87i9Q98/fTNB1RidZbR0ZgVTKdByoj?= =?utf-8?q?c56ZX00BPnffFR62Pu/fxER3eKZ4OyUjKUCUiSryl8Qjz7KoUA/NhzL/+OMMANFSI?= =?utf-8?q?sxLsgp26UGz/G5zJaXf7ADZTKHWcfYKZXl/st+kWKnvsOggy0L40V8kQSdLd4mSwb?= =?utf-8?q?ufgTdJdug9W4BPQbFJt/socI+KF5EWi9HYsHH8VrkSQbJuW7NJ+9e2JuiemvkANfD?= =?utf-8?q?A6RYoszyWnH7TAfNFW459vgJZzT32rNmrJNn3cTyRq6bWoD0hgiDQwIbRa2N+cEBQ?= =?utf-8?q?lPmfh0dkDIYbmzUDbGaAuAS9lHgKBelQaYKRzAChwjVF7CMHuEoDXSRTgee+ns84I?= =?utf-8?q?Z2oDrg8SWnpFRWcnOfX+8aLvi1QEwTPXVOu+hcaLhSVsli0zCIFon7oQdoYuJOOOb?= =?utf-8?q?qqjI45OH2/lKELTfPVqQvzY6is3EpOIGdj129wc3B3uxdNLm8q/Kw/kCcpH1izTGF?= =?utf-8?q?kQuk99L89HO?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2024 05:43:21.2107 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4bfe8ce1-6aef-43e0-8368-08dd14efba6b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8783 From: Roger Pau Monne When running as a PVH dom0 the ACPI MADT is crafted by Xen in order to report the correct numbers of vCPUs that dom0 has, so the host MADT is not provided to dom0. This creates issues when parsing the power and performance related data from ACPI dynamic tables, as the ACPI Processor UIDs found on the dynamic code are likely to not match the ones crafted by Xen in the dom0 MADT. Xen would rely on Linux having filled at least the power and performance related data of the vCPUs on the system, and would clone that information in order to setup the remaining pCPUs on the system if dom0 vCPUs < pCPUs. However when running as PVH dom0 it's likely that none of dom0 CPUs will have the power and performance data filled, and hence the Xen ACPI Processor driver needs to fetch that information by itself. In order to do so correctly, introduce a new helper to fetch the _CST data without taking into account the system capabilities from the CPUID output, as the capabilities reported to dom0 in CPUID might be different from the ones on the host. Note that the newly introduced code will only fetch the _CST, _PSS, _PPC and _PCT from a single CPU, and clone that information for all the other Processors. This won't work on an heterogeneous system with Processors having different power and performance related data between them. Signed-off-by: Roger Pau MonnĂ© Signed-off-by: Jason Andryuk --- drivers/xen/pcpu.c | 3 +- drivers/xen/xen-acpi-processor.c | 232 ++++++++++++++++++++++++++++--- include/xen/xen.h | 2 +- 3 files changed, 216 insertions(+), 21 deletions(-) diff --git a/drivers/xen/pcpu.c b/drivers/xen/pcpu.c index c63f317e3df3..dc9f2c14bf62 100644 --- a/drivers/xen/pcpu.c +++ b/drivers/xen/pcpu.c @@ -388,7 +388,7 @@ static int __init xen_pcpu_init(void) arch_initcall(xen_pcpu_init); #ifdef CONFIG_ACPI -bool __init xen_processor_present(uint32_t acpi_id) +bool xen_processor_present(uint32_t acpi_id) { const struct pcpu *pcpu; bool online = false; @@ -403,6 +403,7 @@ bool __init xen_processor_present(uint32_t acpi_id) return online; } +EXPORT_SYMBOL_GPL(xen_processor_present); void xen_sanitize_proc_cap_bits(uint32_t *cap) { diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c index 296703939846..e9f38f171240 100644 --- a/drivers/xen/xen-acpi-processor.c +++ b/drivers/xen/xen-acpi-processor.c @@ -48,6 +48,8 @@ static unsigned long *acpi_id_cst_present; /* Which ACPI P-State dependencies for a enumerated processor */ static struct acpi_psd_package *acpi_psd; +static bool pr_initialized; + static int push_cxx_to_hypervisor(struct acpi_processor *_pr) { struct xen_platform_op op = { @@ -172,8 +174,13 @@ static int xen_copy_psd_data(struct acpi_processor *_pr, /* 'acpi_processor_preregister_performance' does not parse if the * num_processors <= 1, but Xen still requires it. Do it manually here. + * + * Also init the field if not set, as that's possible if the physical + * CPUs on the system doesn't match the data provided in the MADT when + * running as a PVH dom0. */ - if (pdomain->num_processors <= 1) { + if (pdomain->num_processors <= 1 || + dst->shared_type == CPUFREQ_SHARED_TYPE_NONE) { if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL) dst->shared_type = CPUFREQ_SHARED_TYPE_ALL; else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) @@ -313,6 +320,155 @@ static unsigned int __init get_max_acpi_id(void) pr_debug("Max ACPI ID: %u\n", max_acpi_id); return max_acpi_id; } + +/* + * Custom version of the native acpi_processor_evaluate_cst() function, to + * avoid some sanity checks done based on the CPUID data. When running as a + * Xen domain the CPUID data provided to dom0 is not the native one, so C + * states cannot be sanity checked. Leave it to the hypervisor which is also + * the entity running the driver. + */ +static int xen_acpi_processor_evaluate_cst(acpi_handle handle, + struct acpi_processor_power *info) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *cst; + acpi_status status; + u64 count; + int last_index = 0; + int i, ret = 0; + + status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(handle, "No _CST\n"); + return -ENODEV; + } + + cst = buffer.pointer; + + /* There must be at least 2 elements. */ + if (!cst || cst->type != ACPI_TYPE_PACKAGE || cst->package.count < 2) { + acpi_handle_warn(handle, "Invalid _CST output\n"); + ret = -EFAULT; + goto end; + } + + count = cst->package.elements[0].integer.value; + + /* Validate the number of C-states. */ + if (count < 1 || count != cst->package.count - 1) { + acpi_handle_warn(handle, "Inconsistent _CST data\n"); + ret = -EFAULT; + goto end; + } + + for (i = 1; i <= count; i++) { + union acpi_object *element; + union acpi_object *obj; + struct acpi_power_register *reg; + struct acpi_processor_cx cx; + + /* + * If there is not enough space for all C-states, skip the + * excess ones and log a warning. + */ + if (last_index >= ACPI_PROCESSOR_MAX_POWER - 1) { + acpi_handle_warn(handle, "No room for more idle states (limit: %d)\n", + ACPI_PROCESSOR_MAX_POWER - 1); + break; + } + + memset(&cx, 0, sizeof(cx)); + + element = &cst->package.elements[i]; + if (element->type != ACPI_TYPE_PACKAGE) { + acpi_handle_info(handle, "_CST C%d type(%x) is not package, skip...\n", + i, element->type); + continue; + } + + if (element->package.count != 4) { + acpi_handle_info(handle, "_CST C%d package count(%d) is not 4, skip...\n", + i, element->package.count); + continue; + } + + obj = &element->package.elements[0]; + + if (obj->type != ACPI_TYPE_BUFFER) { + acpi_handle_info(handle, "_CST C%d package element[0] type(%x) is not buffer, skip...\n", + i, obj->type); + continue; + } + + reg = (struct acpi_power_register *)obj->buffer.pointer; + + obj = &element->package.elements[1]; + if (obj->type != ACPI_TYPE_INTEGER) { + acpi_handle_info(handle, "_CST C[%d] package element[1] type(%x) is not integer, skip...\n", + i, obj->type); + continue; + } + + cx.type = obj->integer.value; + /* + * There are known cases in which the _CST output does not + * contain C1, so if the type of the first state found is not + * C1, leave an empty slot for C1 to be filled in later. + */ + if (i == 1 && cx.type != ACPI_STATE_C1) + last_index = 1; + + cx.address = reg->address; + cx.index = last_index + 1; + + switch (reg->space_id) { + case ACPI_ADR_SPACE_FIXED_HARDWARE: + cx.entry_method = ACPI_CSTATE_FFH; + break; + + case ACPI_ADR_SPACE_SYSTEM_IO: + cx.entry_method = ACPI_CSTATE_SYSTEMIO; + break; + + default: + acpi_handle_info(handle, "_CST C%d space_id(%x) neither FIXED_HARDWARE nor SYSTEM_IO, skip...\n", + i, reg->space_id); + continue; + } + + if (cx.type == ACPI_STATE_C1) + cx.valid = 1; + + obj = &element->package.elements[2]; + if (obj->type != ACPI_TYPE_INTEGER) { + acpi_handle_info(handle, "_CST C%d package element[2] type(%x) not integer, skip...\n", + i, obj->type); + continue; + } + + cx.latency = obj->integer.value; + + obj = &element->package.elements[3]; + if (obj->type != ACPI_TYPE_INTEGER) { + acpi_handle_info(handle, "_CST C%d package element[3] type(%x) not integer, skip...\n", + i, obj->type); + continue; + } + + memcpy(&info->states[++last_index], &cx, sizeof(cx)); + } + + acpi_handle_info(handle, "Found %d idle states\n", last_index); + + info->count = last_index; + +end: + kfree(buffer.pointer); + + return ret; +} + /* * The read_acpi_id and check_acpi_ids are there to support the Xen * oddity of virtual CPUs != physical CPUs in the initial domain. @@ -331,6 +487,7 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) unsigned long long tmp; union acpi_object object = { 0 }; struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; + struct acpi_buffer cst_buf = { ACPI_ALLOCATE_BUFFER, NULL }; acpi_io_address pblk = 0; status = acpi_get_type(handle, &acpi_type); @@ -354,24 +511,45 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) default: return AE_OK; } - if (invalid_phys_cpuid(acpi_get_phys_id(handle, - acpi_type == ACPI_TYPE_DEVICE, - acpi_id))) { + + if (!xen_processor_present(acpi_id)) { pr_debug("CPU with ACPI ID %u is unavailable\n", acpi_id); return AE_OK; } - /* There are more ACPI Processor objects than in x2APIC or MADT. - * This can happen with incorrect ACPI SSDT declerations. */ - if (acpi_id >= nr_acpi_bits) { - pr_debug("max acpi id %u, trying to set %u\n", - nr_acpi_bits - 1, acpi_id); - return AE_OK; - } + /* OK, There is a ACPI Processor object */ __set_bit(acpi_id, acpi_id_present); pr_debug("ACPI CPU%u w/ PBLK:0x%lx\n", acpi_id, (unsigned long)pblk); + if (!pr_initialized) { + struct acpi_processor *pr = context; + int rc, rc2; + + /* + * There's no CPU on the system that has any performance or + * power related data, initialize all the required fields by + * fetching that info here. + * + * Note such information is only fetched once, and then reused + * for all pCPUs. This won't work on heterogeneous systems + * with different Cx anb/or Px states between CPUs. + */ + + pr->handle = handle; + + rc = acpi_processor_get_performance_info(pr); + if (rc) + pr_err("ACPI CPU%u failed to get performance data\n", + acpi_id); + rc2 = xen_acpi_processor_evaluate_cst(handle, &pr->power); + if (rc2) + pr_err("ACPI CPU%u failed to get _CST data\n", acpi_id); + + if (!rc && !rc2) + pr_initialized = true; + } + /* It has P-state dependencies */ if (!acpi_processor_get_psd(handle, &acpi_psd[acpi_id])) { pr_debug("ACPI CPU%u w/ PST:coord_type = %llu domain = %llu\n", @@ -379,11 +557,13 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) acpi_psd[acpi_id].domain); } - status = acpi_evaluate_object(handle, "_CST", NULL, &buffer); + status = acpi_evaluate_object(handle, "_CST", NULL, &cst_buf); if (ACPI_FAILURE(status)) { if (!pblk) return AE_OK; } + kfree(cst_buf.pointer); + /* .. and it has a C-state */ __set_bit(acpi_id, acpi_id_cst_present); @@ -391,10 +571,6 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) } static int check_acpi_ids(struct acpi_processor *pr_backup) { - - if (!pr_backup) - return -ENODEV; - if (acpi_id_present && acpi_id_cst_present) /* OK, done this once .. skip to uploading */ goto upload; @@ -422,8 +598,8 @@ static int check_acpi_ids(struct acpi_processor *pr_backup) acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, - read_acpi_id, NULL, NULL, NULL); - acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, read_acpi_id, NULL, NULL); + read_acpi_id, NULL, pr_backup, NULL); + acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, read_acpi_id, pr_backup, NULL); upload: if (!bitmap_equal(acpi_id_present, acpi_ids_done, nr_acpi_bits)) { @@ -464,6 +640,7 @@ static int xen_upload_processor_pm_data(void) struct acpi_processor *pr_backup = NULL; int i; int rc = 0; + bool free_perf = false; pr_info("Uploading Xen processor PM info\n"); @@ -473,12 +650,29 @@ static int xen_upload_processor_pm_data(void) if (!_pr) continue; - if (!pr_backup) + if (!pr_backup) { pr_backup = kmemdup(_pr, sizeof(*_pr), GFP_KERNEL); + pr_initialized = true; + } (void)upload_pm_data(_pr); } + if (!pr_backup) { + pr_backup = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); + if (!pr_backup) + return -ENOMEM; + pr_backup->performance = kzalloc(sizeof(struct acpi_processor_performance), + GFP_KERNEL); + if (!pr_backup->performance) { + kfree(pr_backup); + return -ENOMEM; + } + free_perf = true; + } + rc = check_acpi_ids(pr_backup); + if (free_perf) + kfree(pr_backup->performance); kfree(pr_backup); return rc; diff --git a/include/xen/xen.h b/include/xen/xen.h index a1e5b3f18d69..6ff3e2f40803 100644 --- a/include/xen/xen.h +++ b/include/xen/xen.h @@ -81,7 +81,7 @@ static inline void xen_free_unpopulated_pages(unsigned int nr_pages, #endif #if defined(CONFIG_XEN_DOM0) && defined(CONFIG_ACPI) && defined(CONFIG_X86) -bool __init xen_processor_present(uint32_t acpi_id); +bool xen_processor_present(uint32_t acpi_id); #else #include static inline bool xen_processor_present(uint32_t acpi_id) From patchwork Thu Dec 5 05:42:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 13894718 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A72EE77173 for ; Thu, 5 Dec 2024 05:43:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.848858.1263653 (Exim 4.92) (envelope-from ) id 1tJ4eB-0002Uf-OF; Thu, 05 Dec 2024 05:43:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 848858.1263653; Thu, 05 Dec 2024 05:43:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4eB-0002UR-LK; Thu, 05 Dec 2024 05:43:31 +0000 Received: by outflank-mailman (input) for mailman id 848858; Thu, 05 Dec 2024 05:43:30 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4eA-0001z8-Db for xen-devel@lists.xenproject.org; Thu, 05 Dec 2024 05:43:30 +0000 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on20604.outbound.protection.outlook.com [2a01:111:f403:2418::604]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id da8d5936-b2cb-11ef-a0d5-8be0dac302b0; Thu, 05 Dec 2024 06:43:29 +0100 (CET) Received: from DM6PR12CA0029.namprd12.prod.outlook.com (2603:10b6:5:1c0::42) by DM3PR12MB9392.namprd12.prod.outlook.com (2603:10b6:0:44::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Thu, 5 Dec 2024 05:43:24 +0000 Received: from CY4PEPF0000FCC0.namprd03.prod.outlook.com (2603:10b6:5:1c0:cafe::52) by DM6PR12CA0029.outlook.office365.com (2603:10b6:5:1c0::42) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.9 via Frontend Transport; Thu, 5 Dec 2024 05:43:24 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000FCC0.mail.protection.outlook.com (10.167.242.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Thu, 5 Dec 2024 05:43:23 +0000 Received: from penny-System-Product-Name.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 4 Dec 2024 23:43:20 -0600 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: da8d5936-b2cb-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DD+ra+IFQGzH37GSSyAkDexD9EKCYoUst8aA73R00lx9ccwDC77aina1yYkqKaOeGI6Fp7SI/yVKxIrkpumG59eF/RQhlG7KaI1yPl2JgoLbRYutRYK5p2orXZbgF0awMvyHFcHMVPwWVXXWCxX4stCCV9pjfurQx4JkbYFv22W1TWYDGgWAZx2SxteVWGuPpfRSxkLovqvJ4QaUC7zS4Sp2WDqGBfsSK9Uvim0e+p402HDE7W+9aKQMY0qhnIbzyanuh+lkTDit2h2P/k1x8TfFdcAe9PwFGoKfexKvsHwZENjjT76tVNPqRcLTJq2NEpKcQh0GZRKj/5ivSl4UPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GsDTXx9VhQgMbr8Jxkh1RlqXObfZJnJqSYjRU1bKv7Q=; b=lK1paWeIxVEpdwe0oxSewu5sOfn4bb+nurvE1opka0szu7Y5CNuaZt8AxF+JkOnV9tIfiL3qqV4yCAvUKrYvMyPMkGWtCttsy36DVIU4cmAvHM4JgQ3LPdQjhx8HKhtl5KfY8vpMPLvHKedtbqR4und0poMkzYG9ajO3l7U8Q/dIzLie+Xje3KchAfMFDxm1pU0SdZM79ayCyLE4C28EpcuqUih8EclK+bE2FFP1MNCUmq7Q6zn2FzbymjMoUtqSb5hU3bMZXr3VWi+b0thi/8dkmbzwgUcB5+yrWw6xrkaYOt7zf8pQAVvS+IRQySU7d8OulLe+a3zaGE3Debvv0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GsDTXx9VhQgMbr8Jxkh1RlqXObfZJnJqSYjRU1bKv7Q=; b=DhgqZlkxnyvjmPrP40F35R3OYpBA8zkZ11e3j8kK8Ao5zMy+kshfd//LD6QepqV5SwruGl4MHXqZp2Q+EHAlXVKDS6bjbSRwR1kB9XMCWDrVtDZ+om4+DyHQhOMnXrWt6x7eLlza/PVkkJaLfxERVQdKIBAnu5r4hYLUQlsRkVM= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Penny Zheng To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko CC: Ray Huang , Xenia Ragiadakou , Jason Andryuk , "Penny Zheng" , , Subject: [PATCH v2 2/4] acpi/cppc: extract _cpc entry parsing logic Date: Thu, 5 Dec 2024 13:42:50 +0800 Message-ID: <20241205054252.471761-3-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241205054252.471761-1-Penny.Zheng@amd.com> References: <20241205054252.471761-1-Penny.Zheng@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC0:EE_|DM3PR12MB9392:EE_ X-MS-Office365-Filtering-Correlation-Id: 06c4401c-9187-43bd-f46c-08dd14efbbed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014; X-Microsoft-Antispam-Message-Info: 9APmW5t2gIPePvIuvB3zLgJsIg3fd0GPpk4OQeLwt3XqaaJoGUoCq9bswOyNvj8MkJoUlKuL/5Dm397fhI0z9gMnfYz8QBNYsYA5vnNqHs4MS/iqf+BCQ/GRbnNkilwRPvm3KW6/iOqJK+q/XKntlWcQBSX1l5fbAmpc8JqDO1yZmI3aHRUfritxH54ClqT+Oor7viCbHz3uOKrfigMxXmrbsTQMq5BX21KsvZJr45+YhiwX0vg3LkaG+1WUnf5fgnAQkO0diRl5s+b59Ic/e6ASFgK7gm3JxmHnfgkpmRuAonbb3bScy7TeOk4eBc45+3A775LPz7yIKKbCYGPYhzuawfj/yPcz7qpl8O1gD5E1zgLr8+0LWx6+gQ+cDhZFj/C90W9Fsd0fRFFiD5o1vHgegG0Y/o7cXEmKVzD4gGqSjmeYvZUM1eHCkMbaJlA6ZIx5Hjl/343qcGQ8nH5ITSouz56K/n/TT7Ds5RGloPmTTYQRm3U+pFoCRrOWp/3vEVQjDJ62dOZZH2XHLAxiRclWMsYUCS4SzGtd98hwwSsWjKXMbzdjaeyUbvSG0TPtctaNCSQdCCuqFPdIBuXNX1+PHewHscInNkBtjG81aWX2COOOFuVCQZ1ZgXNhN27Wcc9O6HI+1nwvgJwNeoZNDzSRJ6IzCeD2/h6D4rW4kHb6Nr+kT7NhXjZhcLOUJoaStZWcGd1hwUoV6XddwL8B2XkSdPxMmYTaDLuOwaCOaRPiokjRm0fzjR5un2zqMheucm0DJ0zxJCgfVG5aiMKQw9wuUHerD1vVEcWFX08bqYjEFvfh8s+u5NRi1NOavx8FE2hzFGKCkGp3Rjy7WC29Bd0QlcwILonn5EHfogvNuByBl7vNjEwErErQLmV4GX3JSTtImA3FXzvjaeSx5nAxYKCzWQTjxmU2vFFgS28ad/CD2vjyxjhG+o35QFfQw/e9Q7eVIgrvwqtx/lR8VWjzNcf9fYQTOldouxOpL4Y15aXqLYff27axsRc9HwfgYWXW/NxvF27dxiTf7JTUAMG+mq3sxe1/hcZjjNvO84Qal7dzHmNDv5m15UpursfPJ8BYL3cdpiOy1hSWgQCLbAtFrqeQbRlPTAv5EGmDo2RXpjKZDfPRlBiqZBRnFhB5+DNXbBi5QILXTrtEON/T1QSWtUaaZHVuZkoKeBsgXoNerAg289QcP87VE90mA1Sb/U2Rq4qF+2ig+j2XnqgsJ7g99myhMxd04MdeprSQ4t+kQKLOdpjjebPZRjLdswNT+SNqlpW6JVpvZGFabjB/gJ4+ys46F6KgB9kVc1X4Ng2P5ci+fNZ8xa5Pq9QqOL9oBkwVzWN2S+haprikh+DnnEYvI12yAjbsKo0sZwWqkAOPxMI+SPcWg8FQAQj+7sNk9QbgqLUsCRPKcMtqRzIX0E08H0W6rdYw8qLn4A6DBgrf/pW1KzfmujHFmEzZedLCZ1Do X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2024 05:43:23.7432 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06c4401c-9187-43bd-f46c-08dd14efbbed X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9392 When running as Xen dom0 PVH guest, MADT table is customized and may have the "wrong" UID processor number, which is inconsistent with the UID in Processor entry in native DSDT. As a result, during ACPI boot-up for dom0, linux fails to set up proper processor logical id <-> physical id map(acpi_map_cpuid). Furthermore, It leads to that some ACPI processor feature data, like per-cpu cpc_desc structure, failed to be correctly stored. In order to re-parse _CPC entry later for delivering correct data in performance hypercall, firstly, we extract parsing logic from acpi_cppc_processor_probe() and export it as a new function acpi_cppc_processor_parse(). Also, replace logical processor id with ACPI ID, to show correct print info in Xen dom0 PVH guest. Signed-off-by: Penny Zheng Reviewed-by: Jason Andryuk --- drivers/acpi/cppc_acpi.c | 93 +++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index c3fc2c05d868..13d6ff84a1e9 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -675,19 +675,11 @@ static int pcc_data_alloc(int pcc_ss_id) static inline void arch_init_invariance_cppc(void) { } #endif -/** - * acpi_cppc_processor_probe - Search for per CPU _CPC objects. - * @pr: Ptr to acpi_processor containing this CPU's logical ID. - * - * Return: 0 for success or negative value for err. - */ -int acpi_cppc_processor_probe(struct acpi_processor *pr) +static int acpi_cppc_processor_parse(struct acpi_processor *pr, struct cpc_desc *cpc_ptr) { struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; union acpi_object *out_obj, *cpc_obj; - struct cpc_desc *cpc_ptr; struct cpc_reg *gas_t; - struct device *cpu_dev; acpi_handle handle = pr->handle; unsigned int num_ent, i, cpc_rev; int pcc_subspace_id = -1; @@ -706,31 +698,24 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) status = acpi_evaluate_object_typed(handle, "_CPC", NULL, &output, ACPI_TYPE_PACKAGE); if (ACPI_FAILURE(status)) { - ret = -ENODEV; - goto out_buf_free; + return -ENODEV; } out_obj = (union acpi_object *) output.pointer; - cpc_ptr = kzalloc(sizeof(struct cpc_desc), GFP_KERNEL); - if (!cpc_ptr) { - ret = -ENOMEM; - goto out_buf_free; - } - /* First entry is NumEntries. */ cpc_obj = &out_obj->package.elements[0]; if (cpc_obj->type == ACPI_TYPE_INTEGER) { num_ent = cpc_obj->integer.value; if (num_ent <= 1) { pr_debug("Unexpected _CPC NumEntries value (%d) for CPU:%d\n", - num_ent, pr->id); - goto out_free; + num_ent, pr->acpi_id); + goto out_pointer; } } else { pr_debug("Unexpected _CPC NumEntries entry type (%d) for CPU:%d\n", - cpc_obj->type, pr->id); - goto out_free; + cpc_obj->type, pr->acpi_id); + goto out_pointer; } /* Second entry should be revision. */ @@ -739,14 +724,14 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) cpc_rev = cpc_obj->integer.value; } else { pr_debug("Unexpected _CPC Revision entry type (%d) for CPU:%d\n", - cpc_obj->type, pr->id); - goto out_free; + cpc_obj->type, pr->acpi_id); + goto out_pointer; } if (cpc_rev < CPPC_V2_REV) { pr_debug("Unsupported _CPC Revision (%d) for CPU:%d\n", cpc_rev, - pr->id); - goto out_free; + pr->acpi_id); + goto out_pointer; } /* @@ -758,8 +743,8 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) (cpc_rev == CPPC_V3_REV && num_ent != CPPC_V3_NUM_ENT) || (cpc_rev > CPPC_V3_REV && num_ent <= CPPC_V3_NUM_ENT)) { pr_debug("Unexpected number of _CPC return package entries (%d) for CPU:%d\n", - num_ent, pr->id); - goto out_free; + num_ent, pr->acpi_id); + goto out_pointer; } if (cpc_rev > CPPC_V3_REV) { num_ent = CPPC_V3_NUM_ENT; @@ -793,7 +778,7 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) goto out_free; } else if (pcc_subspace_id != gas_t->access_width) { pr_debug("Mismatched PCC ids in _CPC for CPU:%d\n", - pr->id); + pr->acpi_id); goto out_free; } } else if (gas_t->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { @@ -848,7 +833,7 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) memcpy(&cpc_ptr->cpc_regs[i-2].cpc_entry.reg, gas_t, sizeof(*gas_t)); } else { pr_debug("Invalid entry type (%d) in _CPC for CPU:%d\n", - i, pr->id); + i, pr->acpi_id); goto out_free; } } @@ -864,6 +849,45 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) cpc_ptr->cpc_regs[i].cpc_entry.int_value = 0; } + pr_debug("Parsed _CPC entry for CPU: %d\n", pr->acpi_id); + kfree(output.pointer); + return 0; + + out_free: + /* Free all the mapped sys mem areas for this CPU */ + for (i = 2; i < cpc_ptr->num_entries; i++) { + void __iomem *addr = cpc_ptr->cpc_regs[i-2].sys_mem_vaddr; + + if (addr) + iounmap(addr); + } + out_pointer: + kfree(output.pointer); + return ret; +} + +/** + * acpi_cppc_processor_probe - Search for per CPU _CPC objects. + * @pr: Ptr to acpi_processor containing this CPU's logical ID. + * + * Return: 0 for success or negative value for err. + */ +int acpi_cppc_processor_probe(struct acpi_processor *pr) +{ + acpi_handle handle = pr->handle; + struct cpc_desc *cpc_ptr; + struct device *cpu_dev; + int pcc_subspace_id = -1; + int ret = -ENODATA; + + cpc_ptr = kzalloc(sizeof(struct cpc_desc), GFP_KERNEL); + if (!cpc_ptr) + return -ENOMEM; + + ret = acpi_cppc_processor_parse(pr, cpc_ptr); + if (ret) + goto out_free; + pcc_subspace_id = per_cpu(cpu_pcc_subspace_idx, pr->id); /* Store CPU Logical ID */ cpc_ptr->cpu_id = pr->id; @@ -907,21 +931,10 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) arch_init_invariance_cppc(); - kfree(output.pointer); return 0; out_free: - /* Free all the mapped sys mem areas for this CPU */ - for (i = 2; i < cpc_ptr->num_entries; i++) { - void __iomem *addr = cpc_ptr->cpc_regs[i-2].sys_mem_vaddr; - - if (addr) - iounmap(addr); - } kfree(cpc_ptr); - -out_buf_free: - kfree(output.pointer); return ret; } EXPORT_SYMBOL_GPL(acpi_cppc_processor_probe); From patchwork Thu Dec 5 05:42:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 13894717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4B7F3E7716D for ; Thu, 5 Dec 2024 05:43:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.848860.1263663 (Exim 4.92) (envelope-from ) id 1tJ4eE-0002mh-Vf; Thu, 05 Dec 2024 05:43:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 848860.1263663; Thu, 05 Dec 2024 05:43:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4eE-0002mW-T2; Thu, 05 Dec 2024 05:43:34 +0000 Received: by outflank-mailman (input) for mailman id 848860; Thu, 05 Dec 2024 05:43:33 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4eD-0001z8-IB for xen-devel@lists.xenproject.org; Thu, 05 Dec 2024 05:43:33 +0000 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2061e.outbound.protection.outlook.com [2a01:111:f403:2415::61e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dc455609-b2cb-11ef-a0d5-8be0dac302b0; Thu, 05 Dec 2024 06:43:32 +0100 (CET) Received: from DS7P222CA0017.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::26) by PH8PR12MB7181.namprd12.prod.outlook.com (2603:10b6:510:22a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8207.15; Thu, 5 Dec 2024 05:43:27 +0000 Received: from CY4PEPF0000FCC3.namprd03.prod.outlook.com (2603:10b6:8:2e:cafe::46) by DS7P222CA0017.outlook.office365.com (2603:10b6:8:2e::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.19 via Frontend Transport; Thu, 5 Dec 2024 05:43:26 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000FCC3.mail.protection.outlook.com (10.167.242.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Thu, 5 Dec 2024 05:43:26 +0000 Received: from penny-System-Product-Name.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 4 Dec 2024 23:43:23 -0600 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dc455609-b2cb-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l2myruzZq6Lyh6/aNpzGbce9kl2lX3JhD2RiEihN+BAOD8lNlb29Hq2tRrUFWG3lEs30RVAntG+gAlS8zB9UdWczNlZmvxwADvcWibl0CmzBHt1sguY8y7xV3xX6WPbclXqjNWZlVVUfRODSRgA+pWpVfBgjumgBIDnceAeVGbU/TQzky2XVh042oLM9QU6l96oU+bkd6UlCa1B+cHgXes3G0IpWx9ndaQghprqZV/E74SvwM6vZOw0nr8waZgsaZKklfzy7YH72x2EJk97H4qUqFAZfHKZW74b6c9ev0TsARU+camC5WXdtCFWnFLoLWf0YFQO/iC+Ljv17/jtegg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iFOJrAd0KMsoZrN9Shjj1dooQzMESP1akwRRETW6xhI=; b=GMZhXYwPHmkAtCCLbxYdpUXgylFiQ+L7bGRHtGCAXvNXme6/LLJWwIqpaAMgvElOvUFMwcmGVzgjWTcTz+81stLbwI7XsXhUU+lC5cQ8QqH1r0DdfALOjN1Z45LsO6rB+GE4qtIpxsxbOKcuA94Ou99F7Q9p6Aug5V5mDMeCCjVpw9uRS11/FxHlKlVIC0rdBigqCVgBx/2Rv0a4d+fA6/V8hfqItpUBNVnsj2qLi/MzP9S9GGpR8XbghkPiApgnaOIgH6eV1ZR17sK3RsCXMj4yDcMgqIhsk5zb8g9vI/DA4FxJ57Yfku+8qMIj8ocHczHVtd1O1aYUB8UZ49EfCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iFOJrAd0KMsoZrN9Shjj1dooQzMESP1akwRRETW6xhI=; b=ens/F7esvTX9U4hlVjvFwAwKPCgacatzecxS8uSDfkrIoDq87HsSVLxonE1jtmji1hcP8EAe87VWJsZd3XTPsy+ph4PrMP5MjdLsM3y2BMf6N1sSKrkyzKwPxlw1ZckjJurNNqk37g+MiJxWDX56mwAJBPct93mJ+QlPBklxBT0= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Penny Zheng To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko CC: Ray Huang , Xenia Ragiadakou , Jason Andryuk , "Penny Zheng" , , Subject: [PATCH v2 3/4] xen/cppc: get xen-required cppc perf caps data Date: Thu, 5 Dec 2024 13:42:51 +0800 Message-ID: <20241205054252.471761-4-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241205054252.471761-1-Penny.Zheng@amd.com> References: <20241205054252.471761-1-Penny.Zheng@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCC3:EE_|PH8PR12MB7181:EE_ X-MS-Office365-Filtering-Correlation-Id: 77293042-9397-4491-4cd8-08dd14efbd82 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: hA5gdBlM4rCRgjPyC3wKnk76+FoHivFpgWQppyuuYLoJDL9I06SyhMORBdWJ/n5G63Qq+VTSOvan+vD+Sg4NCZ5qv3ebBVLgj9JDZAy7BaIbDDdfWn5D3XnKNoIfSLRVk1g4/Ivv4N41PvrbkT2B66JukXfTqHIIWmy4INqojAskb8j5wpgGIiCUXlKu+GGDs+Yr0Nee7RvB0XMR7/PqrFHWg1Czj/jqWR3NoLqrYhqWS6tLmo/ytzB68MThvAijxqWPGRshb8LhdAivZwylFl6coUptfIF+d1m3lish7KOrkFtbPS6wskZqple8Xh9GNtPjjq0aTXddeAUPg+ei2kZQiyXO9yGBA+1A8z6MLYSG8evphqQuoTx5RaAKExZBE+lX4pr21amQ78s8IklltdTR6BEUhxLN78GekVjKbBhwcl0RwMUVw1YbaQtIs7hCiV5Hki7YnAm+Q2D4tCCL/5zPLBiGP0MtrNpvv6IIXfGj5X3Jqnu1nFfYyEgpui1qj4EST311YSk8+wmNKSRD8kIOa8o0yEcZRduNrKUhqCERUCwT5saRjq1eoy3Hmsy5l2ekt9ZDj6DHnK0k7KMT78nYbPq31jzmWVtYTVjqK0UWUAvh9esurwr0lOtDdDNRbIChLsqBbhP1hJ4wqtwhMcKie1JHabCTgpNTwPuTD2SZjqRzrf97rEVVqFkYfWYuQQGexRaKYyGrETKyNzO8vkje8UOWx/So4D0erW0acVhTdSgJzExvBrFZI44H18T1TmuJSPs67nG4Q8gcZ99fiX/n7SvwNRfX3H1bdbKeDvklQFP/pVGm1BMdXQZ5DrTB/+3P+ulA4X/axEOmz7R/e+95ZApwFkhl7ETTWrgTgcK54WJPb0oAJihoTvZ3BYQ4g9GA1i+vuoMKr8TnhobFqSpv4u20ZUM+GUY6BhC/3pVG5mBeLjtU7Vvb35EDT+OCfW+HYFv08NOKUbSM6nYDx1r72tlOJL4r2Q3unYizn7n5gAnqjPQN0zsd8L636tk/olrnookcM0acO22T1YJiVHt/i61BvHzaOLri84sE3mzfcleMATWSRDBHAPA0UQkLUlQwn59hyNEECN57cKE9d52sFZWCJTk3602EwhtLM5ctY9IcEHEYiHdEUHgXdvPM/94GbPViJCscGrjBh7gn4QAHWv8ekMwhI/3tZva3Mo1KUNwaq4O47P6lmmSoz7FcqkdFH/50sVMtCfTU8yFEt0/ChsCwA7484QMquFg1NxlfYUUFa8nnQWPxYGz/4jOf//f+Vzv33EFPcAwM+fyyqqZ2e3lRKKq45/GdYy+KLV/47e6M0ff4b82nVYfF0yxp8Gjskv0I/r5e4Vq8HUkIWT7Uf0QDV7cuSNFYnFWOqWttsjjkBNsD6sug6xc7FusVBRD/Ig2os0OyWQto1q9QvRtOuk2UmmvqQe4i0eXYcb1b8+EAlImZ4xvu62LkuMLa X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2024 05:43:26.3932 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 77293042-9397-4491-4cd8-08dd14efbd82 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCC3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7181 When running as Xen dom0 PVH guest, processor logical id <-> physical id map could not be properly set up. So the original function cppc_get_perf_caps() fails to get correct cppc data for Xen ACPI processor. A new function xen_processor_get_perf_caps() is introduced to get xen-required cppc perf caps data. Also, as Xen couldn't read and process PCC-type register, this commit includes a new flag pcc_unsupported in struct acpi_processor_flags to tell whether platform supports PCC-type register. Signed-off-by: Penny Zheng Reviewed-by: Jason Andryuk --- drivers/acpi/cppc_acpi.c | 110 +++++++++++++++++++++++++++++++++++---- include/acpi/cppc_acpi.h | 5 ++ include/acpi/processor.h | 1 + 3 files changed, 105 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 13d6ff84a1e9..3a436591da07 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -772,6 +772,15 @@ static int acpi_cppc_processor_parse(struct acpi_processor *pr, struct cpc_desc * so extract it only once. */ if (gas_t->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) { + /* + * When ACPI processor represents Xen processor, PCC register type + * could not be properly read and processed right now, as logical + * processor doesn't always have 1:1 map relation to physical processor. + */ + if (pr->flags.pcc_unsupported) { + pr_debug("Unsupported PCC register type:%d\n", pr->acpi_id); + goto out_free; + } if (pcc_subspace_id < 0) { pcc_subspace_id = gas_t->access_width; if (pcc_data_alloc(pcc_subspace_id)) @@ -837,7 +846,9 @@ static int acpi_cppc_processor_parse(struct acpi_processor *pr, struct cpc_desc goto out_free; } } - per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_subspace_id; + + if (!pr->flags.pcc_unsupported) + per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_subspace_id; /* * Initialize the remaining cpc_regs as unsupported. @@ -1018,8 +1029,7 @@ int __weak cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val) static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) { void __iomem *vaddr = NULL; - int size; - int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); + int size, pcc_ss_id; struct cpc_reg *reg = ®_res->cpc_entry.reg; if (reg_res->type == ACPI_TYPE_INTEGER) { @@ -1044,14 +1054,17 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val) *val = val_u32; return 0; - } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >= 0) { - /* - * For registers in PCC space, the register size is determined - * by the bit width field; the access size is used to indicate - * the PCC subspace id. - */ - size = reg->bit_width; - vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id); + } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) { + pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); + if (pcc_ss_id >= 0) { + /* + * For registers in PCC space, the register size is determined + * by the bit width field; the access size is used to indicate + * the PCC subspace id. + */ + size = reg->bit_width; + vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id); + } } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) vaddr = reg_res->sys_mem_vaddr; @@ -1282,6 +1295,81 @@ int cppc_get_epp_perf(int cpunum, u64 *epp_perf) } EXPORT_SYMBOL_GPL(cppc_get_epp_perf); + +int xen_processor_get_perf_caps(struct acpi_processor *pr, struct cppc_perf_caps *perf_caps) +{ + struct cpc_desc *cpc_ptr; + struct cpc_register_resource *highest_reg, *lowest_reg, + *lowest_non_linear_reg, *nominal_reg, + *low_freq_reg = NULL, *nom_freq_reg = NULL; + u64 high, low, nom, min_nonlinear, low_f = 0, nom_f = 0; + int ret = 0; + + cpc_ptr = kzalloc(sizeof(struct cpc_desc), GFP_KERNEL); + if (!cpc_ptr) + return -ENOMEM; + + ret = acpi_cppc_processor_parse(pr, cpc_ptr); + if (ret) + goto err; + + highest_reg = &cpc_ptr->cpc_regs[HIGHEST_PERF]; + lowest_reg = &cpc_ptr->cpc_regs[LOWEST_PERF]; + lowest_non_linear_reg = &cpc_ptr->cpc_regs[LOW_NON_LINEAR_PERF]; + nominal_reg = &cpc_ptr->cpc_regs[NOMINAL_PERF]; + low_freq_reg = &cpc_ptr->cpc_regs[LOWEST_FREQ]; + nom_freq_reg = &cpc_ptr->cpc_regs[NOMINAL_FREQ]; + + /* Are any of the regs PCC ?*/ + if (CPC_IN_PCC(highest_reg) || CPC_IN_PCC(lowest_reg) || + CPC_IN_PCC(lowest_non_linear_reg) || CPC_IN_PCC(nominal_reg) || + CPC_IN_PCC(low_freq_reg) || CPC_IN_PCC(nom_freq_reg)) { + pr_debug("Unsupported register type read for Xen Processor %d," + "highest_reg in PCC: %s, lowest_reg in PCC: %s," + "lowest_non_linear_reg in PCC: %s, nominal_reg in PCC: %s," + "low_freq_reg in PCC: %s, nom_freq_reg in PCC: %s\n", + pr->acpi_id, CPC_IN_PCC(highest_reg) ? "true" : "false", + CPC_IN_PCC(lowest_reg) ? "true" : "false", + CPC_IN_PCC(lowest_non_linear_reg) ? "true" : "false", + CPC_IN_PCC(nominal_reg) ? "true" : "false", + CPC_IN_PCC(low_freq_reg) ? "true" : "false", + CPC_IN_PCC(nom_freq_reg) ? "true" : "false"); + goto err; + } + + cpc_read(pr->acpi_id, highest_reg, &high); + perf_caps->highest_perf = high; + + cpc_read(pr->acpi_id, lowest_reg, &low); + perf_caps->lowest_perf = low; + + cpc_read(pr->acpi_id, nominal_reg, &nom); + perf_caps->nominal_perf = nom; + + cpc_read(pr->id, lowest_non_linear_reg, &min_nonlinear); + perf_caps->lowest_nonlinear_perf = min_nonlinear; + + if (!high || !low || !nom || !min_nonlinear) + pr_warn("CPPC: read zero cpc register value for Xen Processor %d" + "highest_reg: %llu, lowest_reg: %llu" + "nominal_reg: %llu, lowest_non_linear_reg: %llu\n", + pr->acpi_id, high, low, nom, min_nonlinear); + + /* Read optional lowest and nominal frequencies if present */ + if (CPC_SUPPORTED(low_freq_reg)) + cpc_read(pr->acpi_id, low_freq_reg, &low_f); + + if (CPC_SUPPORTED(nom_freq_reg)) + cpc_read(pr->acpi_id, nom_freq_reg, &nom_f); + + perf_caps->lowest_freq = low_f; + perf_caps->nominal_freq = nom_f; + + err: + kfree(cpc_ptr); + return ret; +} +EXPORT_SYMBOL_GPL(xen_processor_get_perf_caps); /** * cppc_get_perf_caps - Get a CPU's performance capabilities. * @cpunum: CPU from which to get capabilities info. diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 76e44e102780..2281110c00b7 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -164,6 +164,7 @@ extern int cppc_set_auto_sel(int cpu, bool enable); extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf); extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator); extern int amd_detect_prefcore(bool *detected); +extern int xen_processor_get_perf_caps(struct acpi_processor *pr, struct cppc_perf_caps *perf_caps); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { @@ -249,6 +250,10 @@ static inline int amd_detect_prefcore(bool *detected) { return -ENODEV; } +static inline int xen_processor_get_perf_caps(struct acpi_processor *pr, struct cppc_perf_caps *perf_caps) +{ + return -ENOTSUPP; +} #endif /* !CONFIG_ACPI_CPPC_LIB */ #endif /* _CPPC_ACPI_H*/ diff --git a/include/acpi/processor.h b/include/acpi/processor.h index e6f6074eadbf..18499cc11366 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -214,6 +214,7 @@ struct acpi_processor_flags { u8 bm_control:1; u8 bm_check:1; u8 has_cst:1; + u8 pcc_unsupported:1; u8 has_lpi:1; u8 power_setup_done:1; u8 bm_rld_set:1; From patchwork Thu Dec 5 05:42:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Penny Zheng X-Patchwork-Id: 13894714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BE6AE7716C for ; Thu, 5 Dec 2024 05:43:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.848861.1263674 (Exim 4.92) (envelope-from ) id 1tJ4eG-00032s-Cg; Thu, 05 Dec 2024 05:43:36 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 848861.1263674; Thu, 05 Dec 2024 05:43:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4eG-00032l-9Q; Thu, 05 Dec 2024 05:43:36 +0000 Received: by outflank-mailman (input) for mailman id 848861; Thu, 05 Dec 2024 05:43:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tJ4eF-0001z8-FA for xen-devel@lists.xenproject.org; Thu, 05 Dec 2024 05:43:35 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20616.outbound.protection.outlook.com [2a01:111:f403:2417::616]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id dd62f5be-b2cb-11ef-a0d5-8be0dac302b0; Thu, 05 Dec 2024 06:43:34 +0100 (CET) Received: from MW4PR03CA0071.namprd03.prod.outlook.com (2603:10b6:303:b6::16) by CY8PR12MB7609.namprd12.prod.outlook.com (2603:10b6:930:99::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.12; Thu, 5 Dec 2024 05:43:29 +0000 Received: from CY4PEPF0000FCBE.namprd03.prod.outlook.com (2603:10b6:303:b6:cafe::bb) by MW4PR03CA0071.outlook.office365.com (2603:10b6:303:b6::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8230.9 via Frontend Transport; Thu, 5 Dec 2024 05:43:29 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000FCBE.mail.protection.outlook.com (10.167.242.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Thu, 5 Dec 2024 05:43:28 +0000 Received: from penny-System-Product-Name.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 4 Dec 2024 23:43:25 -0600 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dd62f5be-b2cb-11ef-a0d5-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bqbEarWZcyjRyCaTHu+gTf5GtU0WxNMQmKRL7pBJXmwaWS8qB5qNdfAXW6PC27o4kvZnBvxh+QZgL5QRtbcCuZKHVYZRS2sOLUfEm5nH1kyCaMWIsWc5ab3vQdSeh12x18JFSF9ZLYzJOUWJtkS29WCf+yqoEnK4iVd1qM6Wq99L38yP/76ZgRCXZJ2dRraSlLktPJ0fy3HZ9KgikOUwMTfEeCdaI0bsIhN5LMn7FkpCz9eLq24N8odQyMl01Cw9tff2OU5VYjLJ8aIuhgjULaQ7RlzFD5bXD6PXaOtaYoqPN7PO8vscqBoCa5G/yES0fq1E4WpbttXdux2w4p0Eag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f3kT6q2N35dmBYg9LrUhnFoFHFr1MmQ2XdbI9z7bg1s=; b=sbepxTvpRkMUDqCcq2jJGi3Ccib/Pa1UTQtuQ4fJT+FB9dSvksHZ32dP/iBwfx53zqos3AuouienTocZ7czrrqujHWl/0qKqvY6u7Rd5QdHjeU+jtBP+ONgOeof75AExah3r5WhwYCseuQSsRbBkn0AzoMXbNOgRsFYZRJ+Yw0+xy7YeSXizAy4pjKlakQ/8+b1SNDgc5eExoZxw1Xtd8a3RkPA99aRd6fJSecrDWZjUamPiOj7Pg9yQIVR4u+zwvD+5Av7HXRUX24dSv1fFzwi3FnB8oWy+utba817OeOkCUq+YqgzMFqwf6FEZxXRIVkBjvssykBGIkVBOuTUSKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f3kT6q2N35dmBYg9LrUhnFoFHFr1MmQ2XdbI9z7bg1s=; b=if2IhlaItK79RyYRy47iIOOgclnVXSxdIsyzv0378RQBVZbtb6Jz4itfldaRnxq+cgaT4i7Yw5twxZdenehYDSddDh00d6xkV9YOAX9oohA44M56zcibQ79Ez7W4rXHqW2hi8ZsX6WgwzIxtpTeZnIGudzm/h0ZFSvTkvEXgiTk= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Penny Zheng To: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko CC: Ray Huang , Xenia Ragiadakou , Jason Andryuk , "Penny Zheng" , , Subject: [PATCH v2 4/4] xen/cppc: introduce cppc data upload sub-hypercall Date: Thu, 5 Dec 2024 13:42:52 +0800 Message-ID: <20241205054252.471761-5-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241205054252.471761-1-Penny.Zheng@amd.com> References: <20241205054252.471761-1-Penny.Zheng@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000FCBE:EE_|CY8PR12MB7609:EE_ X-MS-Office365-Filtering-Correlation-Id: 849b106c-4aad-4ce6-36f2-08dd14efbf02 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: hUwWn9GBx1E0HpOsdtodvd6SX/W/0F/sohJNZ86YnkruvPeE4P0MOaN103TAnk2EmgyHpWzIITrhCfkVgFZ2WiHoJ4j5Eq53Hk/h+Pgf3UHlkBesoEfa6vgsNwAlEzArodqxBctDOkCWRkj5mIIglmkSoOzKOWNWCS282Kr9EML5K4mgKRTsfV9efe3Dob+gZH+VFioaDBtZqhKl2xZZcSyNSrKGTIF7HwiOuFukrP5jeplWOx1jxDdlekpPmXb6PoSnthQPNAEIHPnp/xVvlD7kwYCVAchQuLCVVFggz2v+2Y+xsPdgD2j7YZC45o6mvX0hDtizPkJcMC4WT88Dm9KYoPk7EYtwQShNST5ahM5MKHysDqO2M9PkVZKfNUBa9qBtY+3X55htgG0knLTyyyraiTWDK2IOqmxCu2nAUKV7zLkB2Io7/ghKdsAPtKt7xK6Qjf+q3q0ZidsS/aUBfxcX10Q+n4MzutiS4YUfvalhtVW7kigTlVNipJMT36OOCk0vIAAnU5A43M/6uTs6rxOAApZ/kJn96GobkQDg3KY3i1ByZopsr0Od3hQh7cdv6rSfNOiXmu9bjw+3ExjvKqehe0Nqp3bOxMDHdiXXPuUpE+orYIun1rQPAxXB0KiUtb0B8jb/WXsHkFoUcKEZGg+rHFbYSTJYIaPi6KTNVWOjmSh7CQyMbvqQzevOEufRdeVDsxKYXQZhs9iSxER5onyfc3N45izOY5x/FQsZoOqcWtA8gz0Olzqbyro19hH1tmhRF2mDKdhQ9mFqldziWElNIHV6UsBw2YgUxL0gRHfleGvSdeTkCmYyv/7wp5+1NryR9gEZZ2/oePtjHORMIdkddujEa9jqmMkMTstzj/TeMv0KYMew2PJmOVK9GXpjNKLEPkTGmyRgaEJPBnXWGDJErhcs/fMMUDg0d7LfNt+dFnEFaDuklfKOjmRKiiiPB3RgObQ4fl1XkYzbA+uRzKTuZ0elVc6X2cm4RDC1aTUHF8kUw02E76V50BAzTBhPYl8tqpYJm01pE4c8lT62c5FtRskZK1JrP1dFkBwIOL+NuHY5y92v8tfc19P8sMBph0O+XuLFnIndHlhsbPQW+fY0+NxtNBBsS3Mdu+NpzZC/DIMYhkgMD66SpmfXwgB9tOcQkDMcSvJtGDgF3Ivxjczf4I1VpqBbNCqhcp/NTgqv77sdI48BiqBgpUTCEu9T90LZ2RNEjhgxPcWzuo9D9cmpDBXsTUO76rvmVBe90H0SbAICojxysyh17BVJmUKXsJjcpNsT7OvYpudh62M2BelBXWDcwXcFcu7HiUJDkETfKDOt/PgfSZKkHTM6sBDGX6DEDbDCtft4aL1hcyVOD9M+MG02ng9if89XNOT+T4Gi6UKM0gnioMLuA+ugBodrbYVz7N+fXuV9SwsVxYGDs+QEnJ6shJ4eBwPWpbOTnYe/NYdLSdM04DOuJpNtPZBz X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2024 05:43:28.9248 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 849b106c-4aad-4ce6-36f2-08dd14efbf02 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000FCBE.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7609 As Xen is uncapable of parsing the ACPI dynamic table, this commit introduces a new sub-hypercall XEN_PM_CPPC to deliver CPPC perf caps data. Signed-off-by: Penny Zheng --- drivers/acpi/cppc_acpi.c | 1 + drivers/xen/xen-acpi-processor.c | 89 +++++++++++++++++++++++++++++++- include/acpi/processor.h | 1 + include/xen/interface/platform.h | 11 ++++ 4 files changed, 101 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 3a436591da07..3570a52a5dbd 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -860,6 +860,7 @@ static int acpi_cppc_processor_parse(struct acpi_processor *pr, struct cpc_desc cpc_ptr->cpc_regs[i].cpc_entry.int_value = 0; } + pr->flags.has_cpc = 1; pr_debug("Parsed _CPC entry for CPU: %d\n", pr->acpi_id); kfree(output.pointer); return 0; diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c index e9f38f171240..8a39e46c1ebc 100644 --- a/drivers/xen/xen-acpi-processor.c +++ b/drivers/xen/xen-acpi-processor.c @@ -25,6 +25,7 @@ #include #include #include +#include static int no_hypercall; MODULE_PARM_DESC(off, "Inhibit the hypercall."); @@ -45,8 +46,12 @@ static unsigned long *acpi_ids_done; static unsigned long *acpi_id_present; /* And if there is an _CST definition (or a PBLK) for the ACPI IDs */ static unsigned long *acpi_id_cst_present; +/* And if there is an _CPC entry for the ACPI IDs */ +static unsigned long *acpi_id_cpc_present; /* Which ACPI P-State dependencies for a enumerated processor */ static struct acpi_psd_package *acpi_psd; +/* ACPI CPPC structures for a enumerated processor */ +static struct cppc_perf_caps *acpi_cppc_data; static bool pr_initialized; @@ -208,6 +213,44 @@ static int xen_copy_pct_data(struct acpi_pct_register *pct, dst_pct->address = pct->address; return 0; } +static int push_cppc_to_hypervisor(struct acpi_processor *_pr) +{ + int ret = 0; + struct xen_platform_op op = { + .cmd = XENPF_set_processor_pminfo, + .interface_version = XENPF_INTERFACE_VERSION, + .u.set_pminfo.id = _pr->acpi_id, + .u.set_pminfo.type = XEN_PM_CPPC, + }; + struct cppc_perf_caps *cppc_perf = acpi_cppc_data + _pr->acpi_id; + + op.u.set_pminfo.cppc_data.highest_perf = cppc_perf->highest_perf; + op.u.set_pminfo.cppc_data.lowest_perf = cppc_perf->lowest_perf; + op.u.set_pminfo.cppc_data.nominal_perf = cppc_perf->nominal_perf; + op.u.set_pminfo.cppc_data.lowest_nonlinear_perf = cppc_perf->lowest_nonlinear_perf; + op.u.set_pminfo.cppc_data.lowest_freq = cppc_perf->lowest_freq; + op.u.set_pminfo.cppc_data.nominal_freq = cppc_perf->nominal_freq; + + if (!no_hypercall) + ret = HYPERVISOR_platform_op(&op); + + if (!ret) { + pr_debug("ACPI CPU%u - CPPC uploaded.\n", _pr->acpi_id); + pr_debug(" highest_perf: %d\n", cppc_perf->highest_perf); + pr_debug(" lowest_perf: %d\n", cppc_perf->lowest_perf); + pr_debug(" lowest_nonlinear_perf: %d\n", cppc_perf->lowest_nonlinear_perf); + pr_debug(" nominal_perf: %d\n", cppc_perf->nominal_perf); + pr_debug(" lowest_freq: %d Mhz\n", cppc_perf->lowest_freq); + pr_debug(" nominal_freq: %d Mhz\n", cppc_perf->nominal_freq); + } else if ((ret != -EINVAL) && (ret != -ENOSYS)) + /* EINVAL means the ACPI ID is incorrect - meaning the ACPI + * table is referencing a non-existing CPU - which can happen + * with broken ACPI tables. */ + pr_warn("(_CPC): Hypervisor error (%d) for ACPI CPU%u\n", + ret, _pr->acpi_id); + + return ret; +} static int push_pxx_to_hypervisor(struct acpi_processor *_pr) { int ret = 0; @@ -284,6 +327,9 @@ static int upload_pm_data(struct acpi_processor *_pr) if (_pr->flags.power) err = push_cxx_to_hypervisor(_pr); + if (_pr->flags.has_cpc) + err |= push_cppc_to_hypervisor(_pr); + if (_pr->performance && _pr->performance->states) err |= push_pxx_to_hypervisor(_pr); @@ -488,6 +534,7 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) union acpi_object object = { 0 }; struct acpi_buffer buffer = { sizeof(union acpi_object), &object }; struct acpi_buffer cst_buf = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer cpc_buf = { ACPI_ALLOCATE_BUFFER, NULL }; acpi_io_address pblk = 0; status = acpi_get_type(handle, &acpi_type); @@ -567,11 +614,20 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv) /* .. and it has a C-state */ __set_bit(acpi_id, acpi_id_cst_present); + status = acpi_evaluate_object(handle, "_CPC", NULL, &cpc_buf); + if (ACPI_FAILURE(status)) { + return AE_OK; + } + kfree(cpc_buf.pointer); + + /* .. and it has a _CPC entry */ + __set_bit(acpi_id, acpi_id_cpc_present); + return AE_OK; } static int check_acpi_ids(struct acpi_processor *pr_backup) { - if (acpi_id_present && acpi_id_cst_present) + if (acpi_id_present && acpi_id_cst_present && acpi_id_cpc_present) /* OK, done this once .. skip to uploading */ goto upload; @@ -588,11 +644,19 @@ static int check_acpi_ids(struct acpi_processor *pr_backup) return -ENOMEM; } + acpi_id_cpc_present = bitmap_zalloc(nr_acpi_bits, GFP_KERNEL); + if (!acpi_id_cpc_present) { + bitmap_free(acpi_id_present); + bitmap_free(acpi_id_cst_present); + return -ENOMEM; + } + acpi_psd = kcalloc(nr_acpi_bits, sizeof(struct acpi_psd_package), GFP_KERNEL); if (!acpi_psd) { bitmap_free(acpi_id_present); bitmap_free(acpi_id_cst_present); + bitmap_free(acpi_id_cpc_present); return -ENOMEM; } @@ -608,6 +672,12 @@ static int check_acpi_ids(struct acpi_processor *pr_backup) pr_backup->acpi_id = i; /* Mask out C-states if there are no _CST or PBLK */ pr_backup->flags.power = test_bit(i, acpi_id_cst_present); + /* Mask out relevant flag if there are no _CPC */ + pr_backup->flags.has_cpc = test_bit(i, acpi_id_cpc_present); + if (pr_backup->flags.has_cpc) { + if (xen_processor_get_perf_caps(pr_backup, acpi_cppc_data + i)) + return -EINVAL; + } /* num_entries is non-zero if we evaluated _PSD */ if (acpi_psd[i].num_entries) { memcpy(&pr_backup->performance->domain_info, @@ -726,6 +796,15 @@ static int __init xen_acpi_processor_init(void) bitmap_free(acpi_ids_done); return -ENOMEM; } + + acpi_cppc_data = kcalloc(nr_acpi_bits, sizeof(struct cppc_perf_caps), + GFP_KERNEL); + if (!acpi_cppc_data) { + pr_debug("Memory allocation error for acpi_cppc_data\n"); + rc = -ENOMEM; + goto err1_out; + } + for_each_possible_cpu(i) { if (!zalloc_cpumask_var_node( &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map, @@ -751,6 +830,11 @@ static int __init xen_acpi_processor_init(void) rc = acpi_processor_get_performance_info(pr); if (rc) goto err_out; + + pr->flags.pcc_unsupported = true; + rc = xen_processor_get_perf_caps(pr, acpi_cppc_data + i); + if (rc) + goto err_out; } rc = xen_upload_processor_pm_data(); @@ -766,6 +850,8 @@ static int __init xen_acpi_processor_init(void) err_out: /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */ + kfree(acpi_cppc_data); +err1_out: free_acpi_perf_data(); bitmap_free(acpi_ids_done); return rc; @@ -779,6 +865,7 @@ static void __exit xen_acpi_processor_exit(void) bitmap_free(acpi_id_present); bitmap_free(acpi_id_cst_present); kfree(acpi_psd); + kfree(acpi_cppc_data); for_each_possible_cpu(i) acpi_processor_unregister_performance(i); diff --git a/include/acpi/processor.h b/include/acpi/processor.h index 18499cc11366..66492f5d68a8 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -214,6 +214,7 @@ struct acpi_processor_flags { u8 bm_control:1; u8 bm_check:1; u8 has_cst:1; + u8 has_cpc:1; u8 pcc_unsupported:1; u8 has_lpi:1; u8 power_setup_done:1; diff --git a/include/xen/interface/platform.h b/include/xen/interface/platform.h index 79a443c65ea9..e11bb9443dc0 100644 --- a/include/xen/interface/platform.h +++ b/include/xen/interface/platform.h @@ -319,6 +319,7 @@ DEFINE_GUEST_HANDLE_STRUCT(xenpf_getidletime_t); #define XEN_PM_PX 1 #define XEN_PM_TX 2 #define XEN_PM_PDC 3 +#define XEN_PM_CPPC 4 /* Px sub info type */ #define XEN_PX_PCT 1 #define XEN_PX_PSS 2 @@ -384,6 +385,15 @@ struct xen_processor_px { }; DEFINE_GUEST_HANDLE_STRUCT(xen_processor_px); +struct xen_processor_cppc { + uint32_t highest_perf; + uint32_t nominal_perf; + uint32_t lowest_perf; + uint32_t lowest_nonlinear_perf; + uint32_t lowest_freq; + uint32_t nominal_freq; +}; + struct xen_psd_package { uint64_t num_entries; uint64_t revision; @@ -412,6 +422,7 @@ struct xenpf_set_processor_pminfo { struct xen_processor_power power;/* Cx: _CST/_CSD */ struct xen_processor_performance perf; /* Px: _PPC/_PCT/_PSS/_PSD */ GUEST_HANDLE(uint32_t) pdc; + struct xen_processor_cppc cppc_data; /* _CPC */ }; }; DEFINE_GUEST_HANDLE_STRUCT(xenpf_set_processor_pminfo);