From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: citrix.com, ip: 216.71.155.175, mailfrom: roger.pau@citrix.com) Received: from esa6.hc3370-68.iphmx.com (esa6.hc3370-68.iphmx.com [216.71.155.175]) by groups.io with SMTP; Wed, 07 Aug 2019 08:34:39 -0700 Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=roger.pau@citrix.com; spf=Pass smtp.mailfrom=roger.pau@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of roger.pau@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of roger.pau@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="roger.pau@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="roger.pau@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: od+hwtk2bGqvR/jbXEgbthUpPHgKWjrQ6ZumkTK34nxlLSzhfeAAEOxHHHUgVhY7xv7gZOyqvh 3YVeNeQIWktJlCM70NuWrXvDv93flr/RvU4kXyFL4GIDaL7ffP5+lsaZMFJ3Td+R1DMmd/Clm4 7scQ0z+bl3JAyCbXoJqevL8Bx2m8fF+PKwHA5975skDAVHuHVipf+hxfmhIGqIq5exsV18NCeZ tZbG6Afjd2BNRryOouqF4aPeO8Cr1XwxSQO4ZaJcOK4lEYeaLEocIOUPlhr/vx95jBOKzVsPQe YlI= X-SBRS: 2.7 X-MesageID: 4144387 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,357,1559534400"; d="scan'208";a="4144387" Date: Wed, 7 Aug 2019 17:34:32 +0200 From: =?UTF-8?B?Um9nZXIgUGF1IE1vbm7DqQ==?= To: Anthony PERARD CC: , Julien Grall , , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Andrew Cooper Subject: Re: [PATCH v4 23/35] OvmfPkg/XenPlatformPei: Rework memory detection Message-ID: <20190807152852.e47kogsxubbjkue5@Air-de-Roger> References: <20190729153944.24239-1-anthony.perard@citrix.com> <20190729153944.24239-24-anthony.perard@citrix.com> MIME-Version: 1.0 In-Reply-To: <20190729153944.24239-24-anthony.perard@citrix.com> User-Agent: NeoMutt/20180716 Return-Path: roger.pau@citrix.com X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL02.citrite.net (10.69.22.126) Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline On Mon, Jul 29, 2019 at 04:39:32PM +0100, Anthony PERARD wrote: > When running as a Xen PVH guest, there is no CMOS to read the memory > size from. Rework GetSystemMemorySize(Below|Above)4gb() so they can > work without CMOS by reading the e820 table. > > Rework XenPublishRamRegions to also care for the reserved and ACPI > entry in the e820 table. The region that was added by InitializeXen() > isn't needed as that same entry is in the e820 table provided by > hvmloader. > > MTRR settings aren't modified anymore, on HVM it's already done by > hvmloader, on PVH it is supposed to have sane default. MTRR will need > to be done properly but keeping what's already been done by programmes ^ firmware > that has runned before OVMF will do for now. ^ ran > diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c > index a21d657357..182e96cc5b 100644 > --- a/OvmfPkg/XenPlatformPei/Xen.c > +++ b/OvmfPkg/XenPlatformPei/Xen.c > @@ -276,9 +276,12 @@ XenPublishRamRegions ( > VOID > ) > { > - EFI_E820_ENTRY64 *E820Map; > - UINT32 E820EntriesCount; > - EFI_STATUS Status; > + EFI_E820_ENTRY64 *E820Map; > + UINT32 E820EntriesCount; > + EFI_STATUS Status; > + EFI_E820_ENTRY64 *Entry; > + UINTN Index; > + EFI_PHYSICAL_ADDRESS LocalApic; > > DEBUG ((DEBUG_INFO, "Using memory map provided by Xen\n")); > > @@ -287,26 +290,47 @@ XenPublishRamRegions ( > // > E820EntriesCount = 0; > Status = XenGetE820Map (&E820Map, &E820EntriesCount); > - > ASSERT_EFI_ERROR (Status); > > - if (E820EntriesCount > 0) { > - EFI_E820_ENTRY64 *Entry; > - UINT32 Loop; > - > - for (Loop = 0; Loop < E820EntriesCount; Loop++) { > - Entry = E820Map + Loop; > - > - // > - // Only care about RAM > - // > - if (Entry->Type != EfiAcpiAddressRangeMemory) { > - continue; > + LocalApic = PcdGet32(PcdCpuLocalApicBaseAddress); > + AddIoMemoryBaseSizeHob (LocalApic, SIZE_1MB); > + > + for (Index = 0; Index < E820EntriesCount; Index++) { > + UINT64 Base; > + UINT64 End; > + > + Entry = &E820Map[Index]; > + > + // > + // Round up the start address, and round down the end address. > + // > + Base = ALIGN_VALUE (Entry->BaseAddr, (UINT64)EFI_PAGE_SIZE); > + End = (Entry->BaseAddr + Entry->Length) & ~(UINT64)EFI_PAGE_MASK; > + > + switch (Entry->Type) { > + case EfiAcpiAddressRangeMemory: > + AddMemoryRangeHob (Base, End); > + break; > + case EfiAcpiAddressRangeACPI: > + AddReservedMemoryRangeHob (Base, End, FALSE); > + break; > + case EfiAcpiAddressRangeReserved: > + if (Base < LocalApic && LocalApic < End) { Don't you also need to check for equality? In case such region starts at Base == LocalApic? I guess it doesn't matter that much since this is to workaround a specific issue with hvmloader, but I would like to see this sorted out in hvmloader so that there's no clash anymore. Thanks, Roger.