From nobody Mon Mar 10 04:30:16 2025 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2088.outbound.protection.outlook.com [40.107.95.88]) (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 23C05204F60 for ; Thu, 6 Mar 2025 11:08:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741259333; cv=fail; b=ew2iN5o7TQL2SwqFbh8a6ZJm5Z03RZYul0UTuZ6I3MSbxh6TXQDvq9d+Ch7wCuZROYp5sOakRP1aI+lSlGH9ldr/T9nI4uqPT/FKhA4/+j5XwAPuw411HSYLRYQHubtUu9tuV2qDraHch6GCSwGjutYq44gkQHvUYeCoqqnnl6Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741259333; c=relaxed/simple; bh=38MZfpJUSshiUGK+Bz1+S9yvvH8NQVAGp5Eo75E8yI4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U95aqAAM/HBSg/hl/J5EWOXilXoO8UjQcMNS1o2uUrruwFbOYUCLox4ZB4aoNlQat9DcCyn4F0IBXGIopYoXK3qNBnozktXEKNBoUsenW+GAJHu4MaslWFJARGS16ljm1XIe4Auj2CCfqM1eHIuCbNO5OXyUq2Wt+0sNLVZPR5A= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=ld0kDCcF; arc=fail smtp.client-ip=40.107.95.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="ld0kDCcF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bx4yQKcIou+bGDBwVOXYgeK+sFSXCVyzU5qJP41LPhenpKGW++ePj9YoMuSLZVBaD5EN4N01v1hfSHr/2v/Yw4v+jc4bgLWyOmInikt45CaRe2UypDvbL4E1NqSdWNOd5yi4m+iOyyC7u5ZfioYbJymJVXc/NPNCCUZSDVru+Oi8h65L7o5y8/CB5VuK5sx5DhyOrnJIgi4pYMdx0OUL2mpnMawdZ3vUMCQYdmD2mQC+t0184iKxa7531VOtBi0liHaVW3JR8qkwhs4heR6QFm/GpHBYWxZQthOttkrEavsHwxwtlvH1aO98g95w4Gt/JNEsEtOlCF0lteD3RwUq8A== 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=umPQCB2LN+Kalqs6W3FFGVHcfPlI9C3UYolJoarzFPM=; b=WuCEKnQphRNQA44CLda2Npj1PP7ea5xqyOlsgxULfVdSgqEfDby2TbQSpijT1YDK1C4i9thuEgcl9/DbltLG2yFsxfRxM+3VvYDOjVfDuoGyQ270Se25ju6/ixaLG8d6Xp5O6ZDnqas5ApIpuapxmRD9mCJ8gGjrWJwREIh/18bhmqJ3bc/hZDLdpgDj4/+bXWCjYrGWWgMZAomgRFZUxuH1Mz1Fx/RMv9P4eGBTnXrla11dKaFL+7K6g+vFgcmKDl75rZ0CI8ZfpkGVFOcNlQuDp4Hbhimyz+FY2XoHTqSz7iLvkJQI4DqbX8bXnmxrec1Z5VMyDrPT3GU6SCPHXw== 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=umPQCB2LN+Kalqs6W3FFGVHcfPlI9C3UYolJoarzFPM=; b=ld0kDCcFSxAytTnql+O4h+lQYq3yOyDvfJ8z2J3HalvoiTB40GXb+2ZhzxEpN0/5qv0VcP5eMYvF0JhHx6LtmKOJhpIjIPyXNmoyzw/hQ+tgucFeJBsKpuOhlzCoHI/uButNh6RYm6QMPyvuX9OM5FC9QfxvHK75T33EfE66Tm8= Received: from SJ0PR13CA0158.namprd13.prod.outlook.com (2603:10b6:a03:2c7::13) by CY5PR12MB6407.namprd12.prod.outlook.com (2603:10b6:930:3c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8511.16; Thu, 6 Mar 2025 11:08:46 +0000 Received: from CO1PEPF000066EA.namprd05.prod.outlook.com (2603:10b6:a03:2c7:cafe::ea) by SJ0PR13CA0158.outlook.office365.com (2603:10b6:a03:2c7::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8534.11 via Frontend Transport; Thu, 6 Mar 2025 11:08:46 +0000 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 Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066EA.mail.protection.outlook.com (10.167.249.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8511.15 via Frontend Transport; Thu, 6 Mar 2025 11:08:45 +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; Thu, 6 Mar 2025 05:08:42 -0600 From: Penny Zheng To: , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko CC: Ray Huang , Jason Andryuk , Penny Zheng , , , Roger Pau Monne Subject: [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0 Date: Thu, 6 Mar 2025 19:08:20 +0800 Message-ID: <20250306110824.1506699-2-Penny.Zheng@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250306110824.1506699-1-Penny.Zheng@amd.com> References: <20250306110824.1506699-1-Penny.Zheng@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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: CO1PEPF000066EA:EE_|CY5PR12MB6407:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f168f34-20af-40f2-4f22-08dd5c9f4399 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?aUQzcGZDNUV6d2l2clduK0ZmcWUyOXZZTG9CMm5STUF6ZHowNURjOUw3WVd2?= =?utf-8?B?WFV3NXN3RHBHYWZoTmYzMG9xR2NIQnljcUlhTDNKTms2TUwyUGRxRFZSdWl2?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NMDJLSTdyZS9Xc1FGTzdJclpaTkZETzFISExESmhCSURBRWhZbG1h?= =?utf-8?B?cDFHbVF0Qnl0bkZtWUloS2hsZVRORytyU2RzMUlNMEhIYndmaDg1R2tOVzYz?= =?utf-8?Q?FAnZBdfBkX6SMyMa1n42pPBy7suObc=3D?= 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)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Mar 2025 11:08:45.8279 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f168f34-20af-40f2-4f22-08dd5c9f4399 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: CO1PEPF000066EA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6407 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=C3=A9 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 093ad4a08672..36fb5372cd04 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); =20 #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 =3D false; @@ -403,6 +403,7 @@ bool __init xen_processor_present(uint32_t acpi_id) =20 return online; } +EXPORT_SYMBOL_GPL(xen_processor_present); =20 void xen_sanitize_proc_cap_bits(uint32_t *cap) { diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-proces= sor.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; =20 +static bool pr_initialized; + static int push_cxx_to_hypervisor(struct acpi_processor *_pr) { struct xen_platform_op op =3D { @@ -172,8 +174,13 @@ static int xen_copy_psd_data(struct acpi_processor *_p= r, =20 /* 'acpi_processor_preregister_performance' does not parse if the * num_processors <=3D 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 <=3D 1) { + if (pdomain->num_processors <=3D 1 || + dst->shared_type =3D=3D CPUFREQ_SHARED_TYPE_NONE) { if (pdomain->coord_type =3D=3D DOMAIN_COORD_TYPE_SW_ALL) dst->shared_type =3D CPUFREQ_SHARED_TYPE_ALL; else if (pdomain->coord_type =3D=3D 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 a= lso + * the entity running the driver. + */ +static int xen_acpi_processor_evaluate_cst(acpi_handle handle, + struct acpi_processor_power *info) +{ + struct acpi_buffer buffer =3D { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *cst; + acpi_status status; + u64 count; + int last_index =3D 0; + int i, ret =3D 0; + + status =3D acpi_evaluate_object(handle, "_CST", NULL, &buffer); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(handle, "No _CST\n"); + return -ENODEV; + } + + cst =3D buffer.pointer; + + /* There must be at least 2 elements. */ + if (!cst || cst->type !=3D ACPI_TYPE_PACKAGE || cst->package.count < 2) { + acpi_handle_warn(handle, "Invalid _CST output\n"); + ret =3D -EFAULT; + goto end; + } + + count =3D cst->package.elements[0].integer.value; + + /* Validate the number of C-states. */ + if (count < 1 || count !=3D cst->package.count - 1) { + acpi_handle_warn(handle, "Inconsistent _CST data\n"); + ret =3D -EFAULT; + goto end; + } + + for (i =3D 1; i <=3D 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 >=3D 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 =3D &cst->package.elements[i]; + if (element->type !=3D 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 !=3D 4) { + acpi_handle_info(handle, "_CST C%d package count(%d) is not 4, skip...\= n", + i, element->package.count); + continue; + } + + obj =3D &element->package.elements[0]; + + if (obj->type !=3D ACPI_TYPE_BUFFER) { + acpi_handle_info(handle, "_CST C%d package element[0] type(%x) is not b= uffer, skip...\n", + i, obj->type); + continue; + } + + reg =3D (struct acpi_power_register *)obj->buffer.pointer; + + obj =3D &element->package.elements[1]; + if (obj->type !=3D 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 =3D 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 =3D=3D 1 && cx.type !=3D ACPI_STATE_C1) + last_index =3D 1; + + cx.address =3D reg->address; + cx.index =3D last_index + 1; + + switch (reg->space_id) { + case ACPI_ADR_SPACE_FIXED_HARDWARE: + cx.entry_method =3D ACPI_CSTATE_FFH; + break; + + case ACPI_ADR_SPACE_SYSTEM_IO: + cx.entry_method =3D 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 =3D=3D ACPI_STATE_C1) + cx.valid =3D 1; + + obj =3D &element->package.elements[2]; + if (obj->type !=3D ACPI_TYPE_INTEGER) { + acpi_handle_info(handle, "_CST C%d package element[2] type(%x) not inte= ger, skip...\n", + i, obj->type); + continue; + } + + cx.latency =3D obj->integer.value; + + obj =3D &element->package.elements[3]; + if (obj->type !=3D ACPI_TYPE_INTEGER) { + acpi_handle_info(handle, "_CST C%d package element[3] type(%x) not inte= ger, 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 =3D 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 !=3D 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 =3D { 0 }; struct acpi_buffer buffer =3D { sizeof(union acpi_object), &object }; + struct acpi_buffer cst_buf =3D { ACPI_ALLOCATE_BUFFER, NULL }; acpi_io_address pblk =3D 0; =20 status =3D acpi_get_type(handle, &acpi_type); @@ -354,24 +511,45 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *conte= xt, void **rv) default: return AE_OK; } - if (invalid_phys_cpuid(acpi_get_phys_id(handle, - acpi_type =3D=3D 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 >=3D 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); =20 pr_debug("ACPI CPU%u w/ PBLK:0x%lx\n", acpi_id, (unsigned long)pblk); =20 + if (!pr_initialized) { + struct acpi_processor *pr =3D 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 =3D handle; + + rc =3D acpi_processor_get_performance_info(pr); + if (rc) + pr_err("ACPI CPU%u failed to get performance data\n", + acpi_id); + rc2 =3D 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 =3D 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 =3D %llu domain =3D %llu\n", @@ -379,11 +557,13 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *conte= xt, void **rv) acpi_psd[acpi_id].domain); } =20 - status =3D acpi_evaluate_object(handle, "_CST", NULL, &buffer); + status =3D 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); =20 @@ -391,10 +571,6 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *contex= t, 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_bac= kup) =20 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= ); =20 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 =3D NULL; int i; int rc =3D 0; + bool free_perf =3D false; =20 pr_info("Uploading Xen processor PM info\n"); =20 @@ -473,12 +650,29 @@ static int xen_upload_processor_pm_data(void) if (!_pr) continue; =20 - if (!pr_backup) + if (!pr_backup) { pr_backup =3D kmemdup(_pr, sizeof(*_pr), GFP_KERNEL); + pr_initialized =3D true; + } (void)upload_pm_data(_pr); } =20 + if (!pr_backup) { + pr_backup =3D kzalloc(sizeof(struct acpi_processor), GFP_KERNEL); + if (!pr_backup) + return -ENOMEM; + pr_backup->performance =3D kzalloc(sizeof(struct acpi_processor_performa= nce), + GFP_KERNEL); + if (!pr_backup->performance) { + kfree(pr_backup); + return -ENOMEM; + } + free_perf =3D true; + } + rc =3D check_acpi_ids(pr_backup); + if (free_perf) + kfree(pr_backup->performance); kfree(pr_backup); =20 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 in= t nr_pages, #endif =20 #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) --=20 2.34.1