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; Thu, 15 Aug 2019 01:59:30 -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 4F49D30833A8; Thu, 15 Aug 2019 08:59:30 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-57.ams2.redhat.com [10.36.117.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 019441E0; Thu, 15 Aug 2019 08:59:28 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v5 22/35] OvmfPkg/XenPlatformPei: no hvmloader: get the E820 table via hypercall To: devel@edk2.groups.io, anthony.perard@citrix.com Cc: Jordan Justen , Julien Grall , xen-devel@lists.xenproject.org, Ard Biesheuvel References: <20190813113119.14804-1-anthony.perard@citrix.com> <20190813113119.14804-23-anthony.perard@citrix.com> From: "Laszlo Ersek" Message-ID: <4c015736-1fa1-36a2-e865-6c2f9913f8a6@redhat.com> Date: Thu, 15 Aug 2019 10:59:28 +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: <20190813113119.14804-23-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.44]); Thu, 15 Aug 2019 08:59:30 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/13/19 13:31, Anthony PERARD wrote: > When the Xen PVH entry point has been used, hvmloader hasn't run and > hasn't prepared an E820 table. The only way left to get an E820 table > is to ask Xen via an hypercall. We keep the result cached to avoid > making a second hypercall which would give the same result. > > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1689 > Signed-off-by: Anthony PERARD > Acked-by: Laszlo Ersek > --- > > Notes: > v5: > - fix commit message, the hypercall *can* be made several time, but we > still cache the result. Addresses Roger's feedback in: http://mid.mail-archive.com/20190808104558.vm6dfic5dntjsnt4@Air-de-Roger https://edk2.groups.io/g/devel/message/45160 My ACK stands. Thanks Laszlo > v3: > - fix commit message > - add 'm' prefix to the global variables > and make them static > > OvmfPkg/XenPlatformPei/Xen.c | 46 +++++++++++++++++++++++++++++++++++- > 1 file changed, 45 insertions(+), 1 deletion(-) > > diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c > index f26f0e56dd..72f6f37b46 100644 > --- a/OvmfPkg/XenPlatformPei/Xen.c > +++ b/OvmfPkg/XenPlatformPei/Xen.c > @@ -27,6 +27,7 @@ > #include > #include > #include > +#include > > #include "Platform.h" > #include "Xen.h" > @@ -40,6 +41,8 @@ EFI_XEN_INFO mXenInfo; > // Only the E820 table is used by OVMF. > // > EFI_XEN_OVMF_INFO *mXenHvmloaderInfo; > +STATIC EFI_E820_ENTRY64 mE820Entries[128]; > +STATIC UINT32 mE820EntriesCount; > > /** > Returns E820 map provided by Xen > @@ -55,6 +58,12 @@ XenGetE820Map ( > UINT32 *Count > ) > { > + INTN ReturnCode; > + xen_memory_map_t Parameters; > + UINTN LoopIndex; > + UINTN Index; > + EFI_E820_ENTRY64 TmpEntry; > + > // > // Get E820 produced by hvmloader > // > @@ -66,7 +75,42 @@ XenGetE820Map ( > return EFI_SUCCESS; > } > > - return EFI_NOT_FOUND; > + // > + // Otherwise, get the E820 table from the Xen hypervisor > + // > + > + if (mE820EntriesCount > 0) { > + *Entries = mE820Entries; > + *Count = mE820EntriesCount; > + return EFI_SUCCESS; > + } > + > + Parameters.nr_entries = 128; > + set_xen_guest_handle (Parameters.buffer, mE820Entries); > + > + // Returns a errno > + ReturnCode = XenHypercallMemoryOp (XENMEM_memory_map, &Parameters); > + ASSERT (ReturnCode == 0); > + > + mE820EntriesCount = Parameters.nr_entries; > + > + // > + // Sort E820 entries > + // > + for (LoopIndex = 1; LoopIndex < mE820EntriesCount; LoopIndex++) { > + for (Index = LoopIndex; Index < mE820EntriesCount; Index++) { > + if (mE820Entries[Index - 1].BaseAddr > mE820Entries[Index].BaseAddr) { > + TmpEntry = mE820Entries[Index]; > + mE820Entries[Index] = mE820Entries[Index - 1]; > + mE820Entries[Index - 1] = TmpEntry; > + } > + } > + } > + > + *Count = mE820EntriesCount; > + *Entries = mE820Entries; > + > + return EFI_SUCCESS; > } > > /** >