From nobody Thu Mar 28 09:46:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96304+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96304+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1668180447; cv=none; d=zohomail.com; s=zohoarc; b=n7DZ6nwnKdPIe4uhvvj72EYFtyU8JQj5HPmG+6C+UYLJTDMtOeCU4rfjaoUvuO8zyQa2yrq6O8Xs57njxvD933LxZ+YoxKzhvyrHgm/N85400GzKITJRlG0htNqZZXXnZUwhUV0F/pWGnxFGD8Jf0eeFw3KCp/9YtZfCzNuDzjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668180447; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ECJnzV9MyRnXxJh7IjyeI4I4UDFiFrd0XoU0KoCLPmY=; b=Oz0sHq8jmDc8gE4waKts8xtmRzVBpUsMypJ63eqNs42DBxFv0C6h/JH+1j1lnRJsPFLosfLGcIKXwfi/xgcoca0eJJ5npX/UCG6ErbOYjUkfrj6y8032EA2RqA9+Y4GJeTlINNsCZ9UOJ840BlUGaVrTtCdDgOAG4KUEosK3tdY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96304+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1668180447844196.0783166211803; Fri, 11 Nov 2022 07:27:27 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id e3z4YY1788612x651BNG9b0c; Fri, 11 Nov 2022 07:27:26 -0800 X-Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by mx.groups.io with SMTP id smtpd.web09.6694.1668180445341896668 for ; Fri, 11 Nov 2022 07:27:25 -0800 X-SBRS: None X-MesageID: 87190448 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:CrUDUaPQIGCpTjPvrR2fl8FynXyQoLVcMsEvi/4bfWQNrUpz0mBSz TcfDT/XOPeMNjD3KdokbY219U9S6J7Sn4QwTAto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQA+KmU4YoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvzrRC9H5qyo4mpB5wVmPJingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0vR7B15Xs sYSFGgmNx2mgs7r3JyHaPY506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEN3w/N3wsYDUWUrsTIJs4gOevgGi5azBCoUiZjaE2/3LS3Ep6172F3N/9KoPTFJ0JwhbwS mTu/n2jBBECZY2l8XmgyVH9ndHzxin5YddHfFG/3qEz2wDCroAJMzUfT1ex4uW4g0i5UNVFJ mQX9zAooKx081akJvH+RRSorXqspBMQW9NMVeY97WmlyK3O7w+fQGxCTCNadNEgnM4wWTEuk FSOmrvBCTFxvbm9RH6erPGbtzSvITNTLGhqTS0FQBQI5Z/yqYYbjxTTQ9IlG6mw5vX3BDXxz jaivCU4wbIJgqY2O76TpA6dxWj2/96QE1Bztl6/sn+ZAh1RdoKjWJXv01Lntd0ZIaOcYgSdk kQmhJ3LhAwRNq2lmCuISeQLObim4feZLTHR6WJS84kdGyeFoCD6I90JiN1qDAIwa5tfJ2e1C KPGkVkJjKK/KkdGekOej2iZL80xhZbtGt3+Phw/RoofO8MhHONrEcwHWKJx44wPuBJy+U3cE c3BGSpJMZr9IfUP8dZOb71BuYLHPwhnrY4TLLiip/hd7ZKQZWSOVZAOO0aUY+Yy4cus+VuLo 48HapDSkUUECIUShxU7FqZKczg3wYUTX8iq+6S7iMbfSuaZJI3RI6CImu5wE2CUt69Uiv3J7 hmAtrxwkTLCaLyuAVviV02Pn5u/B8oh9ihqYHBE0JTB8yFLXLtDJZw3L/MfFYTLPsQ5pRKoZ 5Hpo/m9P8k= IronPort-HdrOrdr: A9a23:nqbeaaE1xT3xJudVpLqE7seALOsnbusQ8zAXP0AYc3Nom6uj5q eTdZUgpGbJYVkqOU3I9ersBEDEewK/yXcX2/h0AV7BZmnbUQKTRekIh7cKgQeQfhEWntQts5 uIGJIRNDSfNzRHZL7BkWqFL+o= X-IronPort-AV: E=Sophos;i="5.96,156,1665460800"; d="scan'208";a="87190448" From: "Anthony PERARD via groups.io" To: CC: Jiewen Yao , Julien Grall , Jordan Justen , Ard Biesheuvel , Gerd Hoffmann , Anthony PERARD Subject: [edk2-devel] [PATCH 1/3] OvmfPkg: Introduce runtime XenHypercallLib Date: Fri, 11 Nov 2022 15:27:12 +0000 Message-ID: <20221111152714.61331-2-anthony.perard@citrix.com> In-Reply-To: <20221111152714.61331-1-anthony.perard@citrix.com> References: <20221111152714.61331-1-anthony.perard@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,anthony.perard@citrix.com X-Gm-Message-State: AtKTlpM3CetIW2xT9K2L4CHVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1668180446; bh=ECJnzV9MyRnXxJh7IjyeI4I4UDFiFrd0XoU0KoCLPmY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=QhClhqIVMOAW5jqkfrzBjzv7PMUArv3DVq8sar8Cdp7oewMjKbU5Ja2Y0T6NP0oIyr6 paiPEhfpHU4PfaYaHnRLZI3q5DjF804dyLznUesElx4SPW+EvCLDHW7qZnx0Y3P1BVLKK RAPsx0YClS3w5toSccPZQl3ZllKyp7Mm0S0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1668180448973100003 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD We need a way to execute instruction "generated" at runtime from the runtime library. This patch introduce XenHypercallRuntimeLib, which is mostly a copy of XenHypercallLib with a few changes. We reserved some code space with "XenHypercallPage", which we will overwrite to put the xen hypercall code. Then we ask Xen to overwrite the reserved space with the hypercall page via `wrmsr`. Allocation doesn't work, because the memory allocated at run time is always considered to be data instead of code, so once Linux takes over, we can't execute from it. Signed-off-by: Anthony PERARD --- Notes: I've been told that we don't need to ask Xen on how to make hypercall on x86, and that was just an helper to not have to figure out which instruction to use. That would mean that instead of doing write_msr, we would need a way to distinguish between AMD and Intel in order to find out which instruction to use. So if this patch is too weird, that another way to have hypercall in a runtime service. OvmfPkg/OvmfXen.dsc | 1 + .../XenHypercallRuntimeLib.inf | 46 ++++ .../XenHypercallLib/X86RuntimeXenHypercall.c | 210 ++++++++++++++++++ .../X64/RuntimeHypercallPage.nasm | 24 ++ 4 files changed, 281 insertions(+) create mode 100644 OvmfPkg/Library/XenHypercallLib/XenHypercallRuntimeLib.= inf create mode 100644 OvmfPkg/Library/XenHypercallLib/X86RuntimeXenHypercall.c create mode 100644 OvmfPkg/Library/XenHypercallLib/X64/RuntimeHypercallPag= e.nasm diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 58a7c97cddf7..8df173a0ee84 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -312,6 +312,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyL= ibRuntimeDxe.inf + XenHypercallLib|OvmfPkg/Library/XenHypercallLib/XenHypercallRuntimeLib.i= nf =20 [LibraryClasses.common.UEFI_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallRuntimeLib.inf b/O= vmfPkg/Library/XenHypercallLib/XenHypercallRuntimeLib.inf new file mode 100644 index 000000000000..07fdeb612760 --- /dev/null +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallRuntimeLib.inf @@ -0,0 +1,46 @@ +## @file +# Xen Hypercall abstraction lib for Intel for runtime services +# +# Copyright (c) 2014, Linaro Ltd. All rights reserved.
+# Copyright (c) 2022, Citrix Systems, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D XenHypercallRuntimeLib + FILE_GUID =3D f657a395-1d2c-40b5-bd34-eedc203899ab + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + CONSTRUCTOR =3D XenHypercallRuntimeLibConstruct + +[Defines.IA32, Defines.X64] + LIBRARY_CLASS =3D XenHypercallLib|DXE_RUNTIME_DRIVER + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D X64 +# + +[Sources.X64] + X86RuntimeXenHypercall.c + X64/hypercall.nasm + X64/RuntimeHypercallPage.nasm + +[Sources] + XenHypercall.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + UefiRuntimeLib + +[Guids.X64] + gEfiEventVirtualAddressChangeGuid # ALWAYS_CONSUMED diff --git a/OvmfPkg/Library/XenHypercallLib/X86RuntimeXenHypercall.c b/Ovm= fPkg/Library/XenHypercallLib/X86RuntimeXenHypercall.c new file mode 100644 index 000000000000..d1c097e00f3a --- /dev/null +++ b/OvmfPkg/Library/XenHypercallLib/X86RuntimeXenHypercall.c @@ -0,0 +1,210 @@ +/** @file + Xen Hypercall Library implementation for Intel architecture + + Copyright (c) 2014, Linaro Ltd. All rights reserved.
+ Copyright (c) 2022, Citrix Systems, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +STATIC VOID *mHyperPage; + +// +// Pointer to reserved page for Xen's hypercall page. +// +extern VOID *XenHypercallPage; + +// +// Virtual Address Change Event +// +// This is needed for runtime variable access. +// +EFI_EVENT mXenHypercallLibAddrChangeEvent =3D NULL; + +RETURN_STATUS +EFIAPI +XenHypercallRuntimeLibConstruct ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + XenHypercallLibInit (); + + // + // We don't fail library construction, since that has catastrophic + // consequences for client modules (whereas those modules may easily be + // running on a non-Xen platform). Instead, XenHypercallIsAvailable() + // will return FALSE. + // + return RETURN_SUCCESS; +} + +/** + Check if the Xen Hypercall library is able to make calls to the Xen + hypervisor. + + Client code should call further functions in this library only if, and a= fter, + this function returns TRUE. + + @retval TRUE Hypercalls are available. + @retval FALSE Hypercalls are not available. +**/ +BOOLEAN +EFIAPI +XenHypercallIsAvailable ( + VOID + ) +{ + return mHyperPage !=3D NULL; +} + +// +// Interface exposed by the ASM implementation of the core hypercall +// +INTN +EFIAPI +__XenHypercall2 ( + IN VOID *HypercallAddr, + IN OUT INTN Arg1, + IN OUT INTN Arg2 + ); + +/** + Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE. + + This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS= _CHANGE event. + It converts pointer to new virtual address. + + @param Event Event whose notification function is being invoked. + @param Context Pointer to the notification function's context. + +**/ +STATIC +VOID +EFIAPI +XenHypercallLibAddrChangeEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + Status =3D EfiConvertFunctionPointer (0, &mHyperPage); + ASSERT_EFI_ERROR (Status); +} + +STATIC +UINT32 +XenCpuidLeaf ( + VOID + ) +{ + UINT8 Signature[13]; + UINT32 XenLeaf; + + Signature[12] =3D '\0'; + for (XenLeaf =3D 0x40000000; XenLeaf < 0x40010000; XenLeaf +=3D 0x100) { + AsmCpuid ( + XenLeaf, + NULL, + (UINT32 *)&Signature[0], + (UINT32 *)&Signature[4], + (UINT32 *)&Signature[8] + ); + + if (!AsciiStrCmp ((CHAR8 *)Signature, "XenVMMXenVMM")) { + return XenLeaf; + } + } + + return 0; +} + +/** + Library constructor: populate hypercall page. +**/ +RETURN_STATUS +EFIAPI +XenHypercallLibInit ( + VOID + ) +{ + EFI_STATUS Status; + UINT32 TransferReg; + UINT32 TransferPages; + UINT32 XenLeaf; + + XenLeaf =3D XenCpuidLeaf (); + + if (XenLeaf =3D=3D 0) { + return RETURN_UNSUPPORTED; + } + + AsmCpuid (XenLeaf + 2, &TransferPages, &TransferReg, NULL, NULL); + + // + // Only populate the first page of the hypercall even if there's more + // than one, that is even if TransferPages > 1. + // We don't use hypercall id > 127. + // + AsmWriteMsr64 (TransferReg, (UINTN)&XenHypercallPage); + + mHyperPage =3D &XenHypercallPage; + + // + // Register for the virtual address change event + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + XenHypercallLibAddrChangeEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mXenHypercallLibAddrChangeEvent + ); + ASSERT_EFI_ERROR (Status); + + return RETURN_SUCCESS; +} + +/** + This function will put the two arguments in the right place (registers) = and + invoke the hypercall identified by HypercallID. + + @param HypercallID The symbolic ID of the hypercall to be invoked + @param Arg1 First argument. + @param Arg2 Second argument. + + @return Return 0 if success otherwise it return an errno. +**/ +INTN +EFIAPI +XenHypercall2 ( + IN UINTN HypercallID, + IN OUT INTN Arg1, + IN OUT INTN Arg2 + ) +{ + ASSERT (mHyperPage !=3D NULL); + // + // Hypercall must not use code beyong the first hypercall page. + // Only the first page is populated by XenHypercallLibInit () + // + ASSERT (HypercallID < EFI_PAGE_SIZE / 32); + if (HypercallID >=3D EFI_PAGE_SIZE / 32) { + return -38; // -ENOSYS + } + + return __XenHypercall2 ((UINT8 *)mHyperPage + HypercallID * 32, Arg1, Ar= g2); +} diff --git a/OvmfPkg/Library/XenHypercallLib/X64/RuntimeHypercallPage.nasm = b/OvmfPkg/Library/XenHypercallLib/X64/RuntimeHypercallPage.nasm new file mode 100644 index 000000000000..f0897c51b31c --- /dev/null +++ b/OvmfPkg/Library/XenHypercallLib/X64/RuntimeHypercallPage.nasm @@ -0,0 +1,24 @@ +;; @file +; Provide one page of code space to be overwritten at boot and to be used= by +; runtime drivers to make Xen hypercall on x86. +; +; Copyright (c) 2022, Citrix Systems, Inc. +; +; SPDX-License-Identifier: BSD-2-Clause-Patent +;; + +DEFAULT REL +SECTION .text + +; +; Align at page boundary as we need a pointer on a page without offset. +; +ALIGN EFI_PAGE_SIZE + +; +; reserve some .text space to put-in Xen's hypercall instructions in at ru= ntime. +; Poisoned with `ret` +; +global ASM_PFX(XenHypercallPage) +ASM_PFX(XenHypercallPage): + times EFI_PAGE_SIZE ret --=20 Anthony PERARD -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96304): https://edk2.groups.io/g/devel/message/96304 Mute This Topic: https://groups.io/mt/94960818/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Mar 28 09:46:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96303+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96303+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1668180446; cv=none; d=zohomail.com; s=zohoarc; b=Vd4eqo+DdZ6Daw5EmrLCMEZFeNjix6Rr9+xwln4W9S6gFvruNBtRbPIzOXNUgVV+qO9f5DMcT4mqH7X7YrP2/Ieh6Il93ua1QEZfPzaZHOGOEBsHSrHWflR0LsAH7TFQKrfpdZF1ahlg2CHwH/9UAyHFSpiiBcBxrToVidy19aE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668180446; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=55FL/qMShujF+HOzQ8Bl2TceVUHh9qfqzWHcns4hObc=; b=BMO1zZ1vIziE7cjrSMEOIlP+bqz+ReMhu1orsE1FVCMYbEuMSjiDEu/PY0Tyh9V+UY5RCxwW8BmarlnxOYF2sKroJoYwf/QnOXmGME08Ob5EQGKLurMLL8FmP28VtSFESuxBwk3QoJgRhjBq+yIyZBpzL7WKNa0TWRVGxR2vfvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96303+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1668180446606922.0108231275601; Fri, 11 Nov 2022 07:27:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id YF3DYY1788612xMvgwKvfxEP; Fri, 11 Nov 2022 07:27:26 -0800 X-Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by mx.groups.io with SMTP id smtpd.web09.6694.1668180445341896668 for ; Fri, 11 Nov 2022 07:27:25 -0800 X-SBRS: None X-MesageID: 87190449 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:bq3xxKOAST8VDOzvrR2fl8FynXyQoLVcMsEvi/4bfWQNrUokhTNRy mEfXjzXPPuJYDSnetx2b4Xkp0gO7MLXy4NnTAto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQA+KmU4YoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvzrRC9H5qyo4mpB5wVmPJingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0vR7B15Xs sYSFGgmNx2mgs7r3JyHaPY506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEN3w/N3wsYDUWUrsTIJs4gOevgGi5azBCoUiZjaE2/3LS3Ep6172F3N/9KoPTFJ0JwhfwS mTu+nX9DkBGLtWj4jff/Hiz3M3xgjinR9dHfFG/3qEz2wDCroAJMzUUUkG3qP//jgi8RslDJ ko8+ywyoKx0/0uuJvH0RRGy42KFtxgbUN1KHsU55RuLx66S5ByWbkAHVDdRZdgOrsI6RTU2k FSOmrvBCTFxvbm9RH6erPGbtzSvITNTLGhqTS0FQBQI5Z/yqYYbjxTTQ9IlG6mw5vX3BDXxz jaivCU4wbIJgqY2O76TpA6dxWj2/96QE1Bztl6/sn+ZAh1RdoKjWJXv01Lntd0ZIaOcYgSdk kQmhJ3LhAwRNq2lmCuISeQLObim4feZLTHR6WJS84kdGyeFoCD6I90JiN1qDAIwa5tfJ2e1C KPGkVkJjKK/KkdGekOej2iZL80xhZbtGt3+Phw/RoofO8MhHONrEcwHWKJx44wPuBJy+U3cE c3BGSpJMZr9IfUP8dZOb71BuYLHPwhnrY4TLLiip/hd7ZKQZWSOVZAOO0aUY+Yy4cus+VuLo 48HapDSkUUECIUShxU7FqZKczg3wYUTX8iq+6S7iMbfSuaZJI3RI6CImu5wE2CUt69Uiv3J7 hmAtrxwkTLCaLyuAVviV02Pn5u/B8oh9ihqYHBE0JTB8yFLXLtDJZw3L/MfFYTLPsQ5pRKoZ 5Hpo/m9P8k= IronPort-HdrOrdr: A9a23:79GREK/8ckFJJgyBcfZuk+DgI+orL9Y04lQ7vn2YSXRuHPBw8P re+sjztCWE8Ar5N0tBpTntAsW9qDbnhPtICOoqTNCftWvdyQiVxehZhOOIqVDd8m/Fh4pgPM 9bAtFD4bbLbGSS4/yU3ODBKadD/OW6 X-IronPort-AV: E=Sophos;i="5.96,156,1665460800"; d="scan'208";a="87190449" From: "Anthony PERARD via groups.io" To: CC: Jiewen Yao , Julien Grall , "Jordan Justen" , Ard Biesheuvel , Gerd Hoffmann , "Anthony PERARD" Subject: [edk2-devel] [PATCH 2/3] OvmfPkg/XenHypercallLib: Add SchedOp hypercall Date: Fri, 11 Nov 2022 15:27:13 +0000 Message-ID: <20221111152714.61331-3-anthony.perard@citrix.com> In-Reply-To: <20221111152714.61331-1-anthony.perard@citrix.com> References: <20221111152714.61331-1-anthony.perard@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,anthony.perard@citrix.com X-Gm-Message-State: RGgxT6DNIeqfVv4WC8wbIpVWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1668180446; bh=55FL/qMShujF+HOzQ8Bl2TceVUHh9qfqzWHcns4hObc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ops8WTJ8bbWBqN4oeogeH7ox4gXn0It7vRydertymGwqfYYXKoVTEds4JiD7aDyS/MC WZL0Ndt30wnYAp8du1l3wij189pSdkk5v3DB+hz0LfKK67jbWcYLe0GXJXzJbvkTyQiSY Isjh7Holy/w3k+v2RTtT+0Q5lUqRbisHe14= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1668180448955100001 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD Add a new function to allow to make an hypercall to shutdown the machine. This import "sched.h" public header from Xen Project's repo. Some changes have been made to be closer to EDK2's coding style. Signed-off-by: Anthony PERARD --- OvmfPkg/Include/IndustryStandard/Xen/sched.h | 50 +++++++++++++++++++ OvmfPkg/Include/Library/XenHypercallLib.h | 7 +++ .../Library/XenHypercallLib/XenHypercall.c | 14 ++++++ 3 files changed, 71 insertions(+) create mode 100644 OvmfPkg/Include/IndustryStandard/Xen/sched.h diff --git a/OvmfPkg/Include/IndustryStandard/Xen/sched.h b/OvmfPkg/Include= /IndustryStandard/Xen/sched.h new file mode 100644 index 000000000000..b050354efe8d --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/Xen/sched.h @@ -0,0 +1,50 @@ +/*************************************************************************= ***** + * sched.h + * + * Scheduler state interactions + * + * SPDX-License-Identifier: MIT + * + * Copyright (c) 2005, Keir Fraser + */ + +#ifndef __XEN_PUBLIC_SCHED_H__ +#define __XEN_PUBLIC_SCHED_H__ + +#include "event_channel.h" + +/* + * Halt execution of this domain (all VCPUs) and notify the system control= ler. + * @arg =3D=3D pointer to sched_shutdown_t structure. + * + * If the sched_shutdown_t reason is SHUTDOWN_suspend then + * x86 PV guests must also set RDX (EDX for 32-bit guests) to the MFN + * of the guest's start info page. RDX/EDX is the third hypercall + * argument. + * + * In addition, which reason is SHUTDOWN_suspend this hypercall + * returns 1 if suspend was cancelled or the domain was merely + * checkpointed, and 0 if it is resuming in a new domain. + */ +#define XEN_SCHEDOP_SHUTDOWN 2 + +struct _XEN_SCHED_SHUTDOWN { + unsigned int Reason; /* SHUTDOWN_* =3D> enum sched_shutdown_reason */ +}; + +typedef struct _XEN_SCHED_SHUTDOWN XEN_SCHED_SHUTDOWN; +DEFINE_XEN_GUEST_HANDLE (XEN_SCHED_SHUTDOWN); + +/* + * Reason codes for SCHEDOP_shutdown. These may be interpreted by control + * software to determine the appropriate action. For the most part, Xen do= es + * not care about the shutdown code. + */ +/* ` enum sched_shutdown_reason { */ +#define XEN_SHED_SHUTDOWN_POWEROFF 0 /* Domain exited normally. Clean up= and kill. */ +#define XEN_SHED_SHUTDOWN_REBOOT 1 /* Clean up, kill, and then restart= . */ +#define XEN_SHED_SHUTDOWN_SUSPEND 2 /* Clean up, save suspend info, kil= l. */ +#define XEN_SHED_SHUTDOWN_CRASH 3 /* Tell controller we've crashed. = */ +#define XEN_SHED_SHUTDOWN_WATCHDOG 4 /* Restart because watchdog time ex= pired. */ + +#endif /* __XEN_PUBLIC_SCHED_H__ */ diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h b/OvmfPkg/Include/Li= brary/XenHypercallLib.h index 28eee8ccac85..d7cf2c0c505b 100644 --- a/OvmfPkg/Include/Library/XenHypercallLib.h +++ b/OvmfPkg/Include/Library/XenHypercallLib.h @@ -101,4 +101,11 @@ XenHypercallEventChannelOp ( IN OUT VOID *Arguments ); =20 +INTN +EFIAPI +XenHypercallSchedOp ( + IN INTN Operation, + IN OUT VOID *Arguments + ); + #endif diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c b/OvmfPkg/Libra= ry/XenHypercallLib/XenHypercall.c index 65b14a11f402..b1a129998fdc 100644 --- a/OvmfPkg/Library/XenHypercallLib/XenHypercall.c +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercall.c @@ -87,3 +87,17 @@ XenHypercallEventChannelOp ( (INTN)Arguments ); } + +INTN +EFIAPI +XenHypercallSchedOp ( + IN INTN Operation, + IN OUT VOID *Arguments + ) +{ + return XenHypercall2 ( + __HYPERVISOR_sched_op, + Operation, + (INTN)Arguments + ); +} --=20 Anthony PERARD -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96303): https://edk2.groups.io/g/devel/message/96303 Mute This Topic: https://groups.io/mt/94960817/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu Mar 28 09:46:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+96305+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96305+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1668180449; cv=none; d=zohomail.com; s=zohoarc; b=UNVeoTprEzTV1Z+or4AXGnkDXdsS++m8nSkFAnMVzZZ4ZQfV1fi+CxUDW5ZcBj+Vc9A+V7aydG/abroHd1ijgAvB48fBkaxMRBA1hVtcg3ZuB6t3kjejlLhGtTyPl2NLrbsDazdotcRdDlSjoduQM3iPT2uIveutPeL/Jw2pYWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668180449; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gnhTY7nswY9Ov4u0+PV10XGl1J57rBhVNkqRfyLTw/g=; b=L7ZNoIbAqDKa2YszWoYsTPCY6wZe6hnNk8gk7zoOh1ovnmooWDjMF0SrHu1d0mt+CUYTqFN+ksU1adWlfJPeOmSjOsThyFlUoEJCI8WOoNwH5zLGhFhBUREHDPAOti1rQGLqriNPM44WC5ZWf1KkY6v3Pyv/hLb7yVEn3qLFB08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+96305+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1668180449811869.0367613693724; Fri, 11 Nov 2022 07:27:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4gQJYY1788612xf6msUP9Qy3; Fri, 11 Nov 2022 07:27:29 -0800 X-Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by mx.groups.io with SMTP id smtpd.web09.6694.1668180445341896668 for ; Fri, 11 Nov 2022 07:27:28 -0800 X-SBRS: None X-MesageID: 87190452 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.83 X-Policy: $RELAYED IronPort-Data: A9a23:VqKAO6oGWVQiAzgaNGXECQeoWxNeBmIiZRIvgKrLsJaIsI4StFCzt garIBnUOPaCY2T1fN1zYN+290sPuJKHxtZmSFFr/C5gQilE8JuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpAFc+E0/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKm06W1wUmAWP6gR5gaHziBNVfrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXADAXSwukuODs+5iqTOhTt94oCfS6FapK7xmMzRmBZRonaZXKQqGM7t5ExjYgwMtJGJ4yZ eJAN2ApNk6ZJUQSZBFHU/rSn8/x7pX7WzRetFKSo7tx+2XJxRZ9+LPsLMDUapqBQsA9ckOw9 j2frjylX0ty2Nq3kjuB73+gtuv0pCLhVawiG7yX7e9RuQjGroAUIEJPDgbqyRWjsWa3Qd5Va FAV8ywppq8o+WSoQ8P7Uhn+p2SL1jYfQdNAHukS8gyByqPIpQ2eAwAsTDlbZNUg8stwRyExy lKPt9LvGTFr9raSTBq1+rqKoDeaNCQWdykNfygZVRBD4t6LiIMygw3CSJByGamdj9vpFDW2y DePxAA8mrESgMgjx6i9u1fdjFqRSoPhF1BvoF+NByT8s10/NNXNi5GUBUbz7exlN6GmTAO6l mkCmvev9usrMMCkvXnYKAkSJ42B6/GAOTzapFdgGZg96jigk0KekZBsDCJWfxkwbJtdEdP9S AqK4F4KuscPVJe/RfUvC79dHfjG2kQJ+T7NcvnPJuRDbZFqHONs1HE/PBXAt4wBfaVFrE3eB Xt5WZzyZZr5If49pNZTewv6+e5D+8zG7TmPLa0XNjz+uVdeDVbMIVv/DHOAb/oi8ISPqxjP/ tBUOqOikksBALSmP3KPq95IdTjmyETX4riv9aRqmhOreFI6SAnN9deNqV/eR2CVt/sMzbqZl p1MckRZ1ED+lRX6xfaiMxhehXKGdcgXkE/XygR8Zwr2gCJyPNrHAWV2X8JfQITLPddLlZZcJ 8Tpse3aahiTYlwrIwggUKQ= IronPort-HdrOrdr: A9a23:ApqLOKH5R1LlMQPSpLqE7seALOsnbusQ8zAXP0AYc3Nom6uj5q eTdZUgpGbJYVkqOU3I9ersBEDEewK/yXcX2/h0AV7BZmnbUQKTRekIh7cKgQeQfhEWntQts5 uIGJIRNDSfNzRHZL7BkWqFL+o= X-IronPort-AV: E=Sophos;i="5.96,156,1665460800"; d="scan'208";a="87190452" From: "Anthony PERARD via groups.io" To: CC: Jiewen Yao , Julien Grall , Jordan Justen , Ard Biesheuvel , Gerd Hoffmann , Anthony PERARD Subject: [edk2-devel] [PATCH 3/3] OvmfPkg/OvmfXen: Introduce Xen's ResetSystemLib, to use xen hypercall Date: Fri, 11 Nov 2022 15:27:14 +0000 Message-ID: <20221111152714.61331-4-anthony.perard@citrix.com> In-Reply-To: <20221111152714.61331-1-anthony.perard@citrix.com> References: <20221111152714.61331-1-anthony.perard@citrix.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,anthony.perard@citrix.com X-Gm-Message-State: yUX7JxP3X1uw1wRnudX3Ga9nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1668180449; bh=gnhTY7nswY9Ov4u0+PV10XGl1J57rBhVNkqRfyLTw/g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=NmcwGzhZ8Ch70YlKhYomqNAm1jEqQParGYGdRqF1fFnqIGs7pqH682yT4PP4iJaadMY QMJfUaWvfbYvZoi5haqXFhns/RpLTyPw3l2c7cTIzISyVAcTlfaQBzQ3Sb9j+kT5w7s8K q9RtOx0rhqfqe0kdw2rqQn3mPKh65ysGtK0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1668180450813100010 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD When booting OvmfXen, the ACPI interface for shutdown/reset might not be available, instead use the hypercall interface. While it's probably possible to use the hypercall in all cases, we keep using the same interface while it still possible. That is ACPI on HVM guest, and fallback to hypercall on PVH guest. Signed-off-by: Anthony PERARD --- OvmfPkg/OvmfXen.dsc | 10 +++---- ...ystemLib.inf =3D> BaseResetSystemLibXen.inf} | 9 ++++--- ...SystemLib.inf =3D> DxeResetSystemLibXen.inf} | 11 +++++--- ...ResetShutdown.c =3D> BaseResetShutdownXen.c} | 19 +++++++++++--- ...eResetShutdown.c =3D> DxeResetShutdownXen.c} | 26 ++++++++++++------- 5 files changed, 49 insertions(+), 26 deletions(-) copy OvmfPkg/Library/ResetSystemLib/{BaseResetSystemLib.inf =3D> BaseReset= SystemLibXen.inf} (73%) copy OvmfPkg/Library/ResetSystemLib/{DxeResetSystemLib.inf =3D> DxeResetSy= stemLibXen.inf} (73%) copy OvmfPkg/Library/ResetSystemLib/{BaseResetShutdown.c =3D> BaseResetShu= tdownXen.c} (72%) copy OvmfPkg/Library/ResetSystemLib/{DxeResetShutdown.c =3D> DxeResetShutd= ownXen.c} (72%) diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 8df173a0ee84..18f7c0d76643 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -118,7 +118,7 @@ [SkuIds] [LibraryClasses] PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf @@ -302,7 +302,7 @@ [LibraryClasses.common.DXE_CORE] =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf @@ -316,7 +316,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] =20 [LibraryClasses.common.UEFI_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf @@ -326,7 +326,7 @@ [LibraryClasses.common.UEFI_DRIVER] =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf @@ -345,7 +345,7 @@ [LibraryClasses.common.DXE_DRIVER] =20 [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf - ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf b/OvmfPk= g/Library/ResetSystemLib/BaseResetSystemLibXen.inf similarity index 73% copy from OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf copy to OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf index 35d317f1e0b3..8d75dd565365 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibXen.inf @@ -1,7 +1,9 @@ ## @file -# Base library instance for ResetSystem library class for OVMF +# Base library instance for ResetSystem library class for Xen # # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2022, Citrix Systems, Inc. +# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -9,7 +11,7 @@ [Defines] INF_VERSION =3D 0x00010005 BASE_NAME =3D BaseResetSystemLib - FILE_GUID =3D 66564872-21d4-4d2a-a68b-1e844f980820 + FILE_GUID =3D 9ef32aa1-9e82-4fb1-9c49-0eff538601f8 MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D ResetSystemLib|SEC PEI_CORE PEIM DXE_= CORE @@ -22,7 +24,7 @@ [Defines] # =20 [Sources] - BaseResetShutdown.c + BaseResetShutdownXen.c ResetSystemLib.c =20 [Packages] @@ -36,3 +38,4 @@ [LibraryClasses] IoLib PciLib TimerLib + XenHypercallLib diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf b/OvmfPkg= /Library/ResetSystemLib/DxeResetSystemLibXen.inf similarity index 73% copy from OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf copy to OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf index a9b4ce90000a..ccee69e6e1fa 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibXen.inf @@ -1,16 +1,18 @@ ## @file -# DXE library instance for ResetSystem library class for OVMF +# DXE library instance for ResetSystem library class for Xen # # Copyright (C) 2020, Red Hat, Inc. # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2022, Citrix Systems, Inc. +# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## =20 [Defines] INF_VERSION =3D 1.29 - BASE_NAME =3D DxeResetSystemLib - FILE_GUID =3D bc7835ea-4094-41fe-b770-bad9e6c479b2 + BASE_NAME =3D DxeResetSystemLibXen + FILE_GUID =3D a5ac25e6-4dc5-4fd9-92cd-74e46bd2e72a MODULE_TYPE =3D DXE_DRIVER VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D ResetSystemLib|DXE_DRIVER DXE_RUNTIME= _DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION @@ -24,7 +26,7 @@ [Defines] # =20 [Sources] - DxeResetShutdown.c + DxeResetShutdownXen.c ResetSystemLib.c =20 [Packages] @@ -38,6 +40,7 @@ [LibraryClasses] IoLib PcdLib TimerLib + XenHypercallLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c b/OvmfPkg/L= ibrary/ResetSystemLib/BaseResetShutdownXen.c similarity index 72% copy from OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c copy to OvmfPkg/Library/ResetSystemLib/BaseResetShutdownXen.c index c21d3c89cf95..f45d9125feb4 100644 --- a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetShutdownXen.c @@ -3,6 +3,8 @@ =20 Copyright (C) 2020, Red Hat, Inc. Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2022, Citrix Systems, Inc. + SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 @@ -13,6 +15,7 @@ #include // IoOr16() #include // PciRead16() #include // ResetShutdown() +#include #include // OVMF_HOSTBRIDGE_DID =20 /** @@ -40,12 +43,20 @@ ResetShutdown ( case INTEL_Q35_MCH_DEVICE_ID: AcpiPmBaseAddress =3D ICH9_PMBASE_VALUE; break; - case CLOUDHV_DEVICE_ID: - IoWrite8 (CLOUDHV_ACPI_SHUTDOWN_IO_ADDRESS, 5 << 2 | 1 << 5); - CpuDeadLoop (); default: - ASSERT (FALSE); + { + // + // Fallback to using hypercall. + // Necessary for PVH guest, but should work for HVM guest. + // + INTN ReturnCode; + XEN_SCHED_SHUTDOWN ShutdownOp =3D { + .Reason =3D XEN_SHED_SHUTDOWN_POWEROFF, + }; + ReturnCode =3D XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, ShutdownOp= ); + ASSERT (ReturnCode =3D=3D 0); CpuDeadLoop (); + } } =20 IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, 0); diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c b/OvmfPkg/Li= brary/ResetSystemLib/DxeResetShutdownXen.c similarity index 72% copy from OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c copy to OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c index 31f01b82e4ee..f7f32765cfc9 100644 --- a/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c @@ -8,15 +8,16 @@ =20 #include // BIT13 =20 +#include #include // CpuDeadLoop() #include // ASSERT() #include // IoOr16() #include // PcdGet16() #include // ResetShutdown() +#include #include // PIIX4_PMBA_VALUE =20 STATIC UINT16 mAcpiPmBaseAddress; -STATIC UINT16 mAcpiHwReducedSleepCtl; =20 EFI_STATUS EFIAPI @@ -35,13 +36,13 @@ DxeResetInit ( case INTEL_Q35_MCH_DEVICE_ID: mAcpiPmBaseAddress =3D ICH9_PMBASE_VALUE; break; - case CLOUDHV_DEVICE_ID: - mAcpiHwReducedSleepCtl =3D CLOUDHV_ACPI_SHUTDOWN_IO_ADDRESS; - break; default: - ASSERT (FALSE); - CpuDeadLoop (); - return EFI_UNSUPPORTED; + // + // Fallback to using hypercall. + // Necessary for PVH guest, but should work for HVM guest. + // + mAcpiPmBaseAddress =3D 0xffff; + break; } =20 return EFI_SUCCESS; @@ -60,11 +61,16 @@ ResetShutdown ( VOID ) { - if (mAcpiHwReducedSleepCtl) { - IoWrite8 (mAcpiHwReducedSleepCtl, 5 << 2 | 1 << 5); - } else { + if (mAcpiPmBaseAddress !=3D 0xffff) { IoBitFieldWrite16 (mAcpiPmBaseAddress + 4, 10, 13, 0); IoOr16 (mAcpiPmBaseAddress + 4, BIT13); + } else { + INTN ReturnCode; + XEN_SCHED_SHUTDOWN ShutdownOp =3D { + .Reason =3D XEN_SHED_SHUTDOWN_POWEROFF, + }; + ReturnCode =3D XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, &ShutdownOp); + ASSERT (ReturnCode =3D=3D 0); } =20 CpuDeadLoop (); --=20 Anthony PERARD -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#96305): https://edk2.groups.io/g/devel/message/96305 Mute This Topic: https://groups.io/mt/94960819/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-