From nobody Thu Nov 14 17:15:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565697576; cv=none; d=zoho.com; s=zohoarc; b=KD/XhaJ/DTokSLt9cb0+wswid3Op+nZxLWjaHhPfvYzp7PuEsFFAw8o+5OtZLKZUQi/fKlbtCg7ZAtDVTEz+Ic11q9dEfHlEw6klHFjmkF5LdmKv5DYaUQWX7hXSJVt6M1upOXV97hF40CqRfSOMN6G28dSxOQwXZZ/tPkigbxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565697576; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=aNJPWj1NLEEISydCOeG3WiDTStd4DRhW9jR7DqW1TcE=; b=js/2Q5TPQ2hhAJji7Mj2zfZSq0DzPG8gDx9ZCs5SmZNaUFn/FJEHw9raNfd5c6VxRWre/dszoCEXSwmBT5P3ltQXXLLksb1sMIZw/8ytCZyBQV6NbUrIFE9ukFAdMNHdCAj3MHHmi0E/+aWlTSQvczELKb+gUm5w99KJHSkN2rQ= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565697576825970.1428125517622; Tue, 13 Aug 2019 04:59:36 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxVRv-00022K-NC; Tue, 13 Aug 2019 11:58:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hxVRu-00020O-DJ for xen-devel@lists.xenproject.org; Tue, 13 Aug 2019 11:58:46 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b36b873a-bdc1-11e9-a88d-1f9cc3d11dae; Tue, 13 Aug 2019 11:58:45 +0000 (UTC) X-Inumbo-ID: b36b873a-bdc1-11e9-a88d-1f9cc3d11dae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1565697525; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LxIWAL2otNxzMxkwpzbh1CtLvNL30mSsL6IS4d0CuVk=; b=L8VTlm6zCHNnnoZvs4erBKoLmSjFJqN0NORkJM6+jd5ISwYBN9Ypll81 I0WwoUACVXSaccmAND3o+cYeQ4Sm0VWChfrcn8BjAhIl5TclQ4ixTFcll HA6hgQfK3cg1Q+pZVw9KuRHRi+jOSetc9Oi0NdDMbds3xPSGbRlO/uFd6 I=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of anthony.perard@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="anthony.perard@citrix.com"; x-sender="anthony.perard@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="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: JWz3jpstM9ApbuaHtI5wmMENGY14NAASH7i3+0Usdt4qhIxzCn+hPEU36eNaSNV+gkZwxgOgNr qeWOLd822YhtN+e8aLfXLY45bitGuMqJV5sPhUwoS+cbV82wQfv71PADC2ZFRh1n4Zdqg4hFUm 5U6/2E5NqwcXAeufn5zXXGcgCYu4eePzouTGhcL2VyL1YOZT4hUoMFdnJnO0TC3tWLw2qlCt1Q 1spFFD9J2bmX8wPmQ8AwDViPiohLeSPvkP7ls+rEvRpa8R8qAEgpLoI+LgjbcdOkICsCtjYhxO 6bo= X-SBRS: 2.7 X-MesageID: 4374849 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,381,1559534400"; d="scan'208";a="4374849" From: Anthony PERARD To: Date: Tue, 13 Aug 2019 12:31:07 +0100 Message-ID: <20190813113119.14804-24-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190813113119.14804-1-anthony.perard@citrix.com> References: <20190813113119.14804-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 23/35] OvmfPkg/XenPlatformPei: Rework memory detection X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , Jordan Justen , Julien Grall , Anthony PERARD , xen-devel@lists.xenproject.org, Laszlo Ersek Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 programs that have run before OVMF will do for now. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1689 Signed-off-by: Anthony PERARD Acked-by: Laszlo Ersek --- Notes: v5: - fix coding style - fix typo in commit message - Handle all possible cases of a E820 reserved range overlapping with t= he LAPIC range. =20 v4: - some coding style - Added AddReservedMemoryRangeHob, and using it. - this patch now replace "OvmfPkg/XenPlatformPei: Reserve hvmloader's m= emory only when it has run" from v3. hvmloader have added an entry in the e820 table, there is no need for a special case. - now, everything that is in the e820 table is added to OVMF's memory map, no more skipping ACPI entries or hvmloader's reserved entries. Instead, we look for the local APIC region and avoid it if it is present in the e820. - rework commit message OvmfPkg/XenPlatformPei/Platform.h | 13 ++++++ OvmfPkg/XenPlatformPei/MemDetect.c | 69 +++++++++++++++++++++++++++ OvmfPkg/XenPlatformPei/Platform.c | 11 +++++ OvmfPkg/XenPlatformPei/Xen.c | 75 +++++++++++++++++++++--------- 4 files changed, 147 insertions(+), 21 deletions(-) diff --git a/OvmfPkg/XenPlatformPei/Platform.h b/OvmfPkg/XenPlatformPei/Pla= tform.h index db9a62572f..7661f4a8de 100644 --- a/OvmfPkg/XenPlatformPei/Platform.h +++ b/OvmfPkg/XenPlatformPei/Platform.h @@ -44,6 +44,13 @@ AddReservedMemoryBaseSizeHob ( BOOLEAN Cacheable ); =20 +VOID +AddReservedMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit, + BOOLEAN Cacheable + ); + VOID AddressWidthInitialization ( VOID @@ -114,6 +121,12 @@ XenPublishRamRegions ( VOID ); =20 +EFI_STATUS +XenGetE820Map ( + EFI_E820_ENTRY64 **Entries, + UINT32 *Count + ); + extern EFI_BOOT_MODE mBootMode; =20 extern UINT8 mPhysMemAddressWidth; diff --git a/OvmfPkg/XenPlatformPei/MemDetect.c b/OvmfPkg/XenPlatformPei/Me= mDetect.c index cf95f9c474..1f81eee407 100644 --- a/OvmfPkg/XenPlatformPei/MemDetect.c +++ b/OvmfPkg/XenPlatformPei/MemDetect.c @@ -96,6 +96,45 @@ Q35TsegMbytesInitialization ( mQ35TsegMbytes =3D ExtendedTsegMbytes; } =20 +STATIC +UINT64 +GetHighestSystemMemoryAddress ( + BOOLEAN Below4gb + ) +{ + EFI_E820_ENTRY64 *E820Map; + UINT32 E820EntriesCount; + EFI_E820_ENTRY64 *Entry; + EFI_STATUS Status; + UINT32 Loop; + UINT64 HighestAddress; + UINT64 EntryEnd; + + HighestAddress =3D 0; + + Status =3D XenGetE820Map (&E820Map, &E820EntriesCount); + ASSERT_EFI_ERROR (Status); + + for (Loop =3D 0; Loop < E820EntriesCount; Loop++) { + Entry =3D E820Map + Loop; + EntryEnd =3D Entry->BaseAddr + Entry->Length; + + if (Entry->Type =3D=3D EfiAcpiAddressRangeMemory && + EntryEnd > HighestAddress) { + + if (Below4gb && (EntryEnd <=3D BASE_4GB)) { + HighestAddress =3D EntryEnd; + } else if (!Below4gb && (EntryEnd >=3D BASE_4GB)) { + HighestAddress =3D EntryEnd; + } + } + } + + // + // Round down the end address. + // + return HighestAddress & ~(UINT64)EFI_PAGE_MASK; +} =20 UINT32 GetSystemMemorySizeBelow4gb ( @@ -105,6 +144,19 @@ GetSystemMemorySizeBelow4gb ( UINT8 Cmos0x34; UINT8 Cmos0x35; =20 + // + // In PVH case, there is no CMOS, we have to calculate the memory size + // from parsing the E820 + // + if (XenPvhDetected ()) { + UINT64 HighestAddress; + + HighestAddress =3D GetHighestSystemMemoryAddress (TRUE); + ASSERT (HighestAddress > 0 && HighestAddress <=3D BASE_4GB); + + return HighestAddress; + } + // // CMOS 0x34/0x35 specifies the system memory above 16 MB. // * CMOS(0x35) is the high byte @@ -129,6 +181,23 @@ GetSystemMemorySizeAbove4gb ( UINT32 Size; UINTN CmosIndex; =20 + // + // In PVH case, there is no CMOS, we have to calculate the memory size + // from parsing the E820 + // + if (XenPvhDetected ()) { + UINT64 HighestAddress; + + HighestAddress =3D GetHighestSystemMemoryAddress (FALSE); + ASSERT (HighestAddress =3D=3D 0 || HighestAddress >=3D BASE_4GB); + + if (HighestAddress >=3D BASE_4GB) { + HighestAddress -=3D BASE_4GB; + } + + return HighestAddress; + } + // // CMOS 0x5b-0x5d specifies the system memory above 4GB MB. // * CMOS(0x5d) is the most significant size byte diff --git a/OvmfPkg/XenPlatformPei/Platform.c b/OvmfPkg/XenPlatformPei/Pla= tform.c index 6aaafc3ee9..2f42ca6ccd 100644 --- a/OvmfPkg/XenPlatformPei/Platform.c +++ b/OvmfPkg/XenPlatformPei/Platform.c @@ -102,6 +102,17 @@ AddReservedMemoryBaseSizeHob ( ); } =20 +VOID +AddReservedMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit, + BOOLEAN Cacheable + ) +{ + AddReservedMemoryBaseSizeHob (MemoryBase, + (UINT64)(MemoryLimit - MemoryBase), Cacheable); +} + VOID AddIoMemoryRangeHob ( EFI_PHYSICAL_ADDRESS MemoryBase, diff --git a/OvmfPkg/XenPlatformPei/Xen.c b/OvmfPkg/XenPlatformPei/Xen.c index 72f6f37b46..c4506def9a 100644 --- a/OvmfPkg/XenPlatformPei/Xen.c +++ b/OvmfPkg/XenPlatformPei/Xen.c @@ -276,9 +276,14 @@ 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; + UINT64 LapicBase; + UINT64 LapicEnd; + =20 DEBUG ((DEBUG_INFO, "Using memory map provided by Xen\n")); =20 @@ -287,26 +292,60 @@ XenPublishRamRegions ( // E820EntriesCount =3D 0; Status =3D XenGetE820Map (&E820Map, &E820EntriesCount); - ASSERT_EFI_ERROR (Status); =20 - if (E820EntriesCount > 0) { - EFI_E820_ENTRY64 *Entry; - UINT32 Loop; + LapicBase =3D PcdGet32 (PcdCpuLocalApicBaseAddress); + LapicEnd =3D LapicBase + SIZE_1MB; + AddIoMemoryRangeHob (LapicBase, LapicEnd); =20 - for (Loop =3D 0; Loop < E820EntriesCount; Loop++) { - Entry =3D E820Map + Loop; + for (Index =3D 0; Index < E820EntriesCount; Index++) { + UINT64 Base; + UINT64 End; + UINT64 ReservedBase; + UINT64 ReservedEnd; =20 + Entry =3D &E820Map[Index]; + + // + // Round up the start address, and round down the end address. + // + Base =3D ALIGN_VALUE (Entry->BaseAddr, (UINT64)EFI_PAGE_SIZE); + End =3D (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: // - // Only care about RAM + // hvmloader marks a range that overlaps with the local APIC memory + // mapped region as reserved, but CpuDxe wants it as mapped IO. We + // have already added it as mapped IO, so skip it here. // - if (Entry->Type !=3D EfiAcpiAddressRangeMemory) { - continue; - } =20 - AddMemoryBaseSizeHob (Entry->BaseAddr, Entry->Length); + // + // add LAPIC predecessor range, if any + // + ReservedBase =3D Base; + ReservedEnd =3D MIN (End, LapicBase); + if (ReservedBase < ReservedEnd) { + AddReservedMemoryRangeHob (ReservedBase, ReservedEnd, FALSE); + } =20 - MtrrSetMemoryAttribute (Entry->BaseAddr, Entry->Length, CacheWriteBa= ck); + // + // add LAPIC successor range, if any + // + ReservedBase =3D MAX (Base, LapicEnd); + ReservedEnd =3D End; + if (ReservedBase < ReservedEnd) { + AddReservedMemoryRangeHob (ReservedBase, ReservedEnd, FALSE); + } + break; + default: + break; } } } @@ -326,12 +365,6 @@ InitializeXen ( { RETURN_STATUS PcdStatus; =20 - // - // Reserve away HVMLOADER reserved memory [0xFC000000,0xFD000000). - // This needs to match HVMLOADER RESERVED_MEMBASE/RESERVED_MEMSIZE. - // - AddReservedMemoryBaseSizeHob (0xFC000000, 0x1000000, FALSE); - PcdStatus =3D PcdSetBoolS (PcdPciDisableBusEnumeration, TRUE); ASSERT_RETURN_ERROR (PcdStatus); =20 --=20 Anthony PERARD _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel