From nobody Fri May 10 21:20:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1694024531; cv=none; d=zohomail.com; s=zohoarc; b=ENP8YEmcs1Ybr4Uhkz/7KqC5axFsRa+3NfayBgDa3zjLHVJDVn1EB15WRjQqY1rpMmo7rlDNeYZMpu0vurnIsaSDUyqgEbeF50NSMaPkqCkOLCGLSEX29YrXK16P5lUicLIxekqM6hJPofpZlKt0GRcrW2ouS67FiDUhJCay4UA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694024531; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=zklSHdsI2UWJPNn1ecr8Eo6vQMjVOJa/0zR4bl3TAqc=; b=IzneriGS/ZlCNqbgkPc6xBPvSeGP6I9uG1g1pp7WHcMfX13yzssbGXOC7U2GTxemQ/Rbl2SXWzs5G0T0/NdfeBF8VuKd5I0sOrjPuy3udIxq6HHuWsVcxBg6FjEhtxrEhQF1gMWDk98g6bjIAG4Qf+2ndJv/9+4hIlTkGkWTwUw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1694024531483154.4319070747847; Wed, 6 Sep 2023 11:22:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.596777.930811 (Exim 4.92) (envelope-from ) id 1qdx9p-0004sW-Bz; Wed, 06 Sep 2023 18:21:41 +0000 Received: by outflank-mailman (output) from mailman id 596777.930811; Wed, 06 Sep 2023 18:21:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdx9p-0004sP-9M; Wed, 06 Sep 2023 18:21:41 +0000 Received: by outflank-mailman (input) for mailman id 596777; Wed, 06 Sep 2023 18:21:39 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qdx9n-0004sJ-Hs for xen-devel@lists.xenproject.org; Wed, 06 Sep 2023 18:21:39 +0000 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [2607:f8b0:4864:20::72e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 370b9ea3-4ce2-11ee-9b0d-b553b5be7939; Wed, 06 Sep 2023 20:21:37 +0200 (CEST) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-76ef6d98d7eso9345985a.0 for ; Wed, 06 Sep 2023 11:21:37 -0700 (PDT) Received: from pm2-ws13.praxislan02.com (207-172-141-204.s8906.c3-0.slvr-cbr1.lnh-slvr.md.cable.rcncustomer.com. [207.172.141.204]) by smtp.gmail.com with ESMTPSA id f9-20020a05620a15a900b0076ee82f7726sm5090024qkk.132.2023.09.06.11.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 11:21:34 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 370b9ea3-4ce2-11ee-9b0d-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694024496; x=1694629296; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zklSHdsI2UWJPNn1ecr8Eo6vQMjVOJa/0zR4bl3TAqc=; b=aKu/OGszcXsXLXfev865o5AHWj930QG2IPNZyM2yVoXlCVgKosUZqtZ7lL2puZ8BtF d8e5l8hVLuQ9/VPvchceRUJQF91jlLTdVc7GLgle4aoKuxzjAWaV5NT/6o6TdO7YqC0J KgaMSWh53eb0jXUjT47t0D6Z+ep207dWiCrBeziOBbLCR4Yq30OgLAu/6HV9yICdKZxo EUKqNRGmqNFm9l1pQz97WgCQrPPI5pBp2ErDThAAIY/ZLnZ6PK9ViwAF6S474DtXl1iM 6BdvFOzSS6MV3c4VvhX6NvTbG710q3pzyiFpfGS2WdcLdqzHP7AmA4EixbZSAhaQLwEi KmIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694024496; x=1694629296; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zklSHdsI2UWJPNn1ecr8Eo6vQMjVOJa/0zR4bl3TAqc=; b=DcBb5/TyIozkhsfZPjN16IsV8MjxU8PkKqevNpSNfN6gRgQtMZjDtiTx+AAacAzpyF Ntqqb5Hfb7Ybi8g5dm0TCzSIt2uJQ/D+9fkhuLCRinW6X6skbTEEq5ms9IGHB5+Djhhe I/J2seyIooAzt+6+CHdMjMezi3P1XeLWBk7EwEOqtsud/94nPUvk0Y0zkY6jRKyL2o3q ddNowhlWMcnEsGWdh129zSqMAxqgXeibhSmyI2s+ZPVUXlIYgnFBLyO/1QgFAgLHlebR JSlRctT5V+6dEvySUz34moyyLEri0L+ERZfPZfjHH5dvst/HJ67V921a8+kR+vKtIBvo qe0g== X-Gm-Message-State: AOJu0YyOKOvUibew7NwZauVncD/dlVDqR4FKpYlrJkU0yA5kVkVEJT2o 680KEI6tOmVUa5y2s5yplBg= X-Google-Smtp-Source: AGHT+IGHLnABm96FdDRUcT50m1IX58j6HqwLhDE/W1lxdQtnCSL26QzqbxI+re/ZCl4UzGIAe5nrRQ== X-Received: by 2002:a05:620a:248a:b0:76e:f5c5:1bac with SMTP id i10-20020a05620a248a00b0076ef5c51bacmr19230155qkn.48.1694024495823; Wed, 06 Sep 2023 11:21:35 -0700 (PDT) From: Jason Andryuk To: Juergen Gross , Boris Ostrovsky , "Rafael J. Wysocki" , Len Brown Cc: Roger Pau Monne , stable@vger.kernel.org, Jason Andryuk , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH v2] acpi/processor: sanitize _PDC buffer bits when running as Xen dom0 Date: Wed, 6 Sep 2023 14:21:23 -0400 Message-ID: <20230906182125.48642-1-jandryuk@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1694024534041100001 From: Roger Pau Monne The Processor _PDC buffer bits notify ACPI of the OS capabilities, and so ACPI can adjust the return of other Processor methods taking the OS capabilities into account. When Linux is running as a Xen dom0, it's the hypervisor the entity in charge of processor power management, and hence Xen needs to make sure the capabilities reported in the _PDC buffer match the capabilities of the driver in Xen. Introduce a small helper to sanitize the buffer when running as Xen dom0. When Xen supports HWP, this serves as the equivalent of commit a21211672c9a ("ACPI / processor: Request native thermal interrupt handling via _OSC") to avoid SMM crashes. Xen will set bit 12 in the _PDC bits and the _PDC call will apply it. [ jandryuk: Mention Xen HWP's need. Move local variables ] Signed-off-by: Roger Pau Monn=C3=A9 Cc: stable@vger.kernel.org Signed-off-by: Jason Andryuk --- v2: Move local variables in acpi_processor_eval_pdc() to reuse in both conditio= ns. --- arch/x86/include/asm/xen/hypervisor.h | 6 ++++++ arch/x86/xen/enlighten.c | 19 +++++++++++++++++++ drivers/acpi/processor_pdc.c | 22 ++++++++++++++++------ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/xen/hypervisor.h b/arch/x86/include/asm/x= en/hypervisor.h index 5fc35f889cd1..0f88a7e450d3 100644 --- a/arch/x86/include/asm/xen/hypervisor.h +++ b/arch/x86/include/asm/xen/hypervisor.h @@ -63,4 +63,10 @@ void __init xen_pvh_init(struct boot_params *boot_params= ); void __init mem_map_via_hcall(struct boot_params *boot_params_p); #endif =20 +#ifdef CONFIG_XEN_DOM0 +void xen_sanitize_pdc(uint32_t *buf); +#else +static inline void xen_sanitize_pdc(uint32_t *buf) { BUG(); } +#endif + #endif /* _ASM_X86_XEN_HYPERVISOR_H */ diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c index b8db2148c07d..9f7fc11330a3 100644 --- a/arch/x86/xen/enlighten.c +++ b/arch/x86/xen/enlighten.c @@ -346,3 +346,22 @@ void xen_arch_unregister_cpu(int num) } EXPORT_SYMBOL(xen_arch_unregister_cpu); #endif + +#ifdef CONFIG_XEN_DOM0 +void xen_sanitize_pdc(uint32_t *buf) +{ + struct xen_platform_op op =3D { + .cmd =3D XENPF_set_processor_pminfo, + .interface_version =3D XENPF_INTERFACE_VERSION, + .u.set_pminfo.id =3D -1, + .u.set_pminfo.type =3D XEN_PM_PDC, + }; + int ret; + + set_xen_guest_handle(op.u.set_pminfo.pdc, buf); + ret =3D HYPERVISOR_platform_op(&op); + if (ret) + pr_info("sanitize of _PDC buffer bits from Xen failed: %d\n", + ret); +} +#endif diff --git a/drivers/acpi/processor_pdc.c b/drivers/acpi/processor_pdc.c index 18fb04523f93..9393dd4a3158 100644 --- a/drivers/acpi/processor_pdc.c +++ b/drivers/acpi/processor_pdc.c @@ -122,6 +122,11 @@ static acpi_status acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_i= n) { acpi_status status =3D AE_OK; + union acpi_object *obj; + u32 *buffer =3D NULL; + + obj =3D pdc_in->pointer; + buffer =3D (u32 *)(obj->buffer.pointer); =20 if (boot_option_idle_override =3D=3D IDLE_NOMWAIT) { /* @@ -129,14 +134,19 @@ acpi_processor_eval_pdc(acpi_handle handle, struct ac= pi_object_list *pdc_in) * mode will be disabled in the parameter of _PDC object. * Of course C1_FFH access mode will also be disabled. */ - union acpi_object *obj; - u32 *buffer =3D NULL; - - obj =3D pdc_in->pointer; - buffer =3D (u32 *)(obj->buffer.pointer); buffer[2] &=3D ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH); - } + + if (xen_initial_domain()) { + /* + * When Linux is running as Xen dom0, the hypervisor is the + * entity in charge of the processor power management, and so + * Xen needs to check the OS capabilities reported in the _PDC + * buffer matches what the hypervisor driver supports. + */ + xen_sanitize_pdc(buffer); + } + status =3D acpi_evaluate_object(handle, "_PDC", pdc_in, NULL); =20 if (ACPI_FAILURE(status)) --=20 2.41.0