From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Fri, 12 Apr 2019 02:07:26 -0700 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99645C05E14C; Fri, 12 Apr 2019 09:07:15 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-65.rdu2.redhat.com [10.10.120.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id C88E55D9CD; Fri, 12 Apr 2019 09:07:10 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v2 15/31] OvmfPkg/XenHypercallLib: Enable it in PEIM To: devel@edk2.groups.io, anthony.perard@citrix.com Cc: Jordan Justen , Ard Biesheuvel , Julien Grall , xen-devel@lists.xenproject.org References: <20190409110844.14746-1-anthony.perard@citrix.com> <20190409110844.14746-16-anthony.perard@citrix.com> From: "Laszlo Ersek" Message-ID: <96ba3650-5380-fb8d-885c-f7ce5f191769@redhat.com> Date: Fri, 12 Apr 2019 11:07:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190409110844.14746-16-anthony.perard@citrix.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 12 Apr 2019 09:07:26 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 04/09/19 13:08, Anthony PERARD wrote: > Allow to use Xen hypercalls earlier, during the PEIM stage, but > XenHypercallLibReInit() must be called once the XenInfo HOB is created > with the HyperPage setup. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Anthony PERARD > --- > OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf | 2 +- > OvmfPkg/XenPlatformPei/XenPlatformPei.inf | 1 + > OvmfPkg/Include/Library/XenHypercallLib.h | 12 ++++++++++++ > OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c | 11 +++++++++++ > OvmfPkg/XenPlatformPei/Xen.c | 7 +++++++ > 5 files changed, 32 insertions(+), 1 deletion(-) > > diff --git a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf > index d268e540fe..e0a1889171 100644 > --- a/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf > +++ b/OvmfPkg/Library/XenHypercallLib/XenHypercallLib.inf > @@ -21,7 +21,7 @@ [Defines] > CONSTRUCTOR = XenHypercallLibInit > > [Defines.IA32, Defines.X64] > - LIBRARY_CLASS = XenHypercallLib|DXE_DRIVER UEFI_DRIVER > + LIBRARY_CLASS = XenHypercallLib|PEIM DXE_DRIVER UEFI_DRIVER > > [Defines.ARM, Defines.AARCH64] > LIBRARY_CLASS = XenHypercallLib > diff --git a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf > index 1870e39208..bc6065a709 100644 > --- a/OvmfPkg/XenPlatformPei/XenPlatformPei.inf > +++ b/OvmfPkg/XenPlatformPei/XenPlatformPei.inf > @@ -66,6 +66,7 @@ [LibraryClasses] > MtrrLib > MemEncryptSevLib > PcdLib > + XenHypercallLib > > [Pcd] > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase > diff --git a/OvmfPkg/Include/Library/XenHypercallLib.h b/OvmfPkg/Include/Library/XenHypercallLib.h > index 36e3344e2f..38e64ab108 100644 > --- a/OvmfPkg/Include/Library/XenHypercallLib.h > +++ b/OvmfPkg/Include/Library/XenHypercallLib.h > @@ -16,6 +16,18 @@ > #ifndef __XEN_HYPERCALL_LIB_H__ > #define __XEN_HYPERCALL_LIB_H__ > > +/** > + To call when the gEfiXenInfoGuid HOB became available after the library init > + function has already been executed. > + > + This allow to make hypercall in the PEIM stage. > +**/ > +VOID > +EFIAPI > +XenHypercallLibReInit ( > + VOID > + ); > + > /** > Check if the Xen Hypercall library is able to make calls to the Xen > hypervisor. > diff --git a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c > index 7cb7f46c9b..2ac7254759 100644 > --- a/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c > +++ b/OvmfPkg/Library/XenHypercallLib/X86XenHypercall.c > @@ -78,6 +78,17 @@ XenHypercallLibInit ( > return RETURN_SUCCESS; > } > > +VOID > +EFIAPI > +XenHypercallLibReInit ( > + VOID > + ) > +{ > + if (HyperPage == NULL) { > + XenHypercallLibInit(); > + } > +} > + > /** > This function will put the two arguments in the right place (registers) and > invoke the hypercall identified by HypercallID. > diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c > index fb01094ba9..9d9e9f8020 100644 > --- a/OvmfPkg/XenPlatformPei/Xen.c > +++ b/OvmfPkg/XenPlatformPei/Xen.c > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > > #include "Platform.h" > #include "Xen.h" > @@ -157,6 +158,12 @@ XenConnect ( > sizeof(mXenInfo) > ); > > + // > + // Initialize the XenHypercall library, now that the XenInfo HOB is > + // available > + // > + XenHypercallLibReInit (); > + > return EFI_SUCCESS; > } > > Please rework this patch as follows. We're going to need two patches. First patch: (1) In "X86XenHypercall.c", change XenHypercallLibInit() to return RETURN_NOT_FOUND, when it doesn't find the HOB. Remove the comment about constructors. (2) Add the prototype of the existing XenHypercallLibInit() function to "XenHypercallLib.h". (3) In "XenHypercall.c", introduce a new function called XenHypercallLibConstruct(). This function should have identical return type, calling convention, and parameter list, to XenHypercallLibInit(). The new function should call XenHypercallLibInit(), ignore its return value, and always return RETURN_SUCCESS. Reinstate the comment here that you removed in (1). (4) Update the CONSTRUCTOR define in the INF file to XenHypercallLibConstruct. (5) Don't touch XenPlatformPei. Second patch: (6) Make XenPlatformPei call XenHypercallLibInit(), and then assert success: RETURN_STATUS XenHypercallInitStatus; XenHypercallInitStatus = XenHypercallLibInit (); ASSERT_RETURN_ERROR (XenHypercallInitStatus); Thanks, Laszlo