From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 85BFA941DBF for ; Thu, 11 Jan 2024 19:11:12 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=jjbK6obbWH5aFJkkhylUb1/2S0NFIcfE27YebEMo1zk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1705000271; v=1; b=NOuuCY16Az4JHs2Jt2Za/Mo50e3WsUEmye6fR9DZhShxtBB0Vw3QsmlqxBDOsH0MbL47H8R4 3jdLD0IM6gVbWGq9f7yHGhfwaM2cFFT1PAxkxDAlNwA0SVNg/Xrf9fFUBanELVO1x7n0ASMExeq cJleirQI8U+emdxmycetgKLg= X-Received: by 127.0.0.2 with SMTP id WCgtYY7687511xtmbQWsjIPr; Thu, 11 Jan 2024 11:11:11 -0800 X-Received: from us-smtp-delivery-137.mimecast.com (us-smtp-delivery-137.mimecast.com [170.10.133.137]) by mx.groups.io with SMTP id smtpd.web11.1193.1705000270470509341 for ; Thu, 11 Jan 2024 11:11:10 -0800 X-Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-VXvLruHjPJWXczwZai01lg-1; Thu, 11 Jan 2024 14:11:03 -0500 X-MC-Unique: VXvLruHjPJWXczwZai01lg-1 X-Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-3bb91e121e6so5207094b6e.1 for ; Thu, 11 Jan 2024 11:11:03 -0800 (PST) X-Gm-Message-State: eS4jzQSzMju5q6sUZiByr8Fax7686176AA= X-Received: by 2002:a05:6808:14c4:b0:3bd:3fd3:50e3 with SMTP id f4-20020a05680814c400b003bd3fd350e3mr598051oiw.20.1705000262203; Thu, 11 Jan 2024 11:11:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJKfQlKcmeeGY6aDTUWsmYeZ4W9e9N1KV1dFK3ruVAOJyPNi5jHS5HZs6nzE1KPDYP+2y0Ag== X-Received: by 2002:a17:902:ec86:b0:1d5:a005:4212 with SMTP id x6-20020a170902ec8600b001d5a0054212mr479932plg.0.1704999777681; Thu, 11 Jan 2024 11:02:57 -0800 (PST) X-Received: from dev-hypervisor-01.hsd1.ca.comcast.net ([2601:645:8001:5750::6d3b]) by smtp.googlemail.com with ESMTPSA id o17-20020a170902e29100b001d05bb77b43sm1491661plc.19.2024.01.11.11.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 11:02:57 -0800 (PST) From: "Thomas Barrett" To: devel@edk2.groups.io Cc: Thomas Barrett , Anatol Belski , Ard Biesheuvel , Gerd Hoffmann , Jianyong Wu , Jiewen Yao , Laszlo Ersek , Rob Bradford Subject: [edk2-devel] [PATCH v2 1/2] OvmfPkg: Add CloudHv support to PlatformScanE820 utility function. Date: Thu, 11 Jan 2024 19:02:14 +0000 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: crusoeenergy.com Precedence: Bulk 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,tbarrett@crusoeenergy.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Type: multipart/alternative; boundary="MCBoundary=_12401111411040631" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=NOuuCY16; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=crusoeenergy.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --MCBoundary=_12401111411040631 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 The PlatformScanE820 utility function is not currently compatible with CloudHv since it relies on the prescence of the "etc/e820" QemuFwCfg file. Update the PlatformScanE820 to iterate through the PVH e820 entries when running on a CloudHv guest. Cc: Anatol Belski Cc: Ard Biesheuvel Cc: Gerd Hoffmann Cc: Jianyong Wu Cc: Jiewen Yao Cc: Laszlo Ersek Cc: Rob Bradford Signed-off-by: Thomas Barrett --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 95 +++++++++++++------- 1 file changed, 65 insertions(+), 30 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 662e7e85bb..76a9dc9211 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -248,6 +248,67 @@ PlatformReservationConflictCB ( PlatformInfoHob->PcdPciMmio64Base =3D NewBase; } =20 +/** + Returns PVH memmap + @param Entries Pointer to PVH memmap + @param Count Number of entries + @return EFI_STATUS +**/ +EFI_STATUS +GetPvhMemmapEntries ( + struct hvm_memmap_table_entry **Entries, + UINT32 *Count + ) +{ + UINT32 *PVHResetVectorData; + struct hvm_start_info *pvh_start_info; + + PVHResetVectorData =3D (VOID *)(UINTN)PcdGet32 (PcdXenPvhStartOfDayStruc= tPtr); + if (PVHResetVectorData =3D=3D 0) { + return EFI_NOT_FOUND; + } + + pvh_start_info =3D (struct hvm_start_info *)(UINTN)PVHResetVectorData[0]= ; + + *Entries =3D (struct hvm_memmap_table_entry *)(UINTN)pvh_start_info->mem= map_paddr; + *Count =3D pvh_start_info->memmap_entries; + + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +PlatformScanE820Pvh ( + IN E820_SCAN_CALLBACK Callback, + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + struct hvm_memmap_table_entry *Memmap; + UINT32 MemmapEntriesCount; + struct hvm_memmap_table_entry *Entry; + EFI_E820_ENTRY64 E820Entry; + EFI_STATUS Status; + UINT32 Loop; + + Status =3D GetPvhMemmapEntries (&Memmap, &MemmapEntriesCount); + if (EFI_ERROR (Status)) { + return Status; + } + + for (Loop =3D 0; Loop < MemmapEntriesCount; Loop++) { + Entry =3D Memmap + Loop; + + if (Entry->type =3D=3D XEN_HVM_MEMMAP_TYPE_RAM) { + E820Entry.BaseAddr =3D Entry->addr; + E820Entry.Length =3D Entry->size; + E820Entry.Type =3D Entry->type; + Callback (&E820Entry, PlatformInfoHob); + } + } + + return EFI_SUCCESS; +} + /** Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the passed callback for each entry. @@ -279,6 +340,10 @@ PlatformScanE820 ( EFI_E820_ENTRY64 E820Entry; UINTN Processed; =20 + if (PlatformInfoHob->HostBridgeDevId =3D=3D CLOUDHV_DEVICE_ID) { + return PlatformScanE820Pvh (Callback, PlatformInfoHob); + } + Status =3D QemuFwCfgFindFile ("etc/e820", &FwCfgItem, &FwCfgSize); if (EFI_ERROR (Status)) { return Status; @@ -297,36 +362,6 @@ PlatformScanE820 ( return EFI_SUCCESS; } =20 -/** - Returns PVH memmap - - @param Entries Pointer to PVH memmap - @param Count Number of entries - - @return EFI_STATUS -**/ -EFI_STATUS -GetPvhMemmapEntries ( - struct hvm_memmap_table_entry **Entries, - UINT32 *Count - ) -{ - UINT32 *PVHResetVectorData; - struct hvm_start_info *pvh_start_info; - - PVHResetVectorData =3D (VOID *)(UINTN)PcdGet32 (PcdXenPvhStartOfDayStruc= tPtr); - if (PVHResetVectorData =3D=3D 0) { - return EFI_NOT_FOUND; - } - - pvh_start_info =3D (struct hvm_start_info *)(UINTN)PVHResetVectorData[0]= ; - - *Entries =3D (struct hvm_memmap_table_entry *)(UINTN)pvh_start_info->mem= map_paddr; - *Count =3D pvh_start_info->memmap_entries; - - return EFI_SUCCESS; -} - STATIC UINT64 GetHighestSystemMemoryAddressFromPvhMemmap ( --=20 2.34.1 Disclaimer The information contained in this communication from the sender is confiden= tial. It is intended solely for use by the recipient and others authorized = to receive it. If you are not the recipient, you are hereby notified that a= ny disclosure, copying, distribution or taking action in relation of the co= ntents of this information is strictly prohibited and may be unlawful. This email has been scanned for viruses and malware, and may have been auto= matically archived by Mimecast, a leader in email security and cyber resili= ence. Mimecast integrates email defenses with brand protection, security aw= areness training, web security, compliance and other essential capabilities= . Mimecast helps protect large and small organizations from malicious activ= ity, human error and technology failure; and to lead the movement toward bu= ilding a more resilient world. To find out more, visit our website. -=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 (#113630): https://edk2.groups.io/g/devel/message/113630 Mute This Topic: https://groups.io/mt/103668748/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --MCBoundary=_12401111411040631 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 The PlatformScanE820 utility function is not curren= tly compatible
with CloudHv since it relies on the prescence of the "etc/e820" QemuFwCfg file. Update the PlatformScanE820 to iterate through the
PVH e820 entries when running on a CloudHv guest.

Cc: Anatol Belski <anbelski@linux.microsoft.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jianyong Wu <jianyong.wu@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rob Bradford <rbradford@rivosinc.com>
Signed-off-by: Thomas Barrett <tbarrett@crusoeenergy.com>
---
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 95 +++++++++++++-------
1 file changed, 65 insertions(+), 30 deletions(-)

diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c
index 662e7e85bb..76a9dc9211 100644
--- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
+++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
@@ -248,6 +248,67 @@ PlatformReservationConflictCB (
PlatformInfoHob->PcdPciMmio64Base =3D NewBase;

}



+/**

+ Returns PVH memmap

+ @param Entries Pointer to PVH memmap

+ @param Count Number of entries

+ @return EFI_STATUS

+**/

+EFI_STATUS

+GetPvhMemmapEntries (

+ struct hvm_memmap_table_entry **Entries,

+ UINT32 *Count

+ )

+{

+ UINT32 *PVHResetVectorData;

+ struct hvm_start_info *pvh_start_info;

+

+ PVHResetVectorData =3D (VOID *)(UINTN)PcdGet32 (PcdXenPvhStartOfDayStruc= tPtr);

+ if (PVHResetVectorData =3D=3D 0) {

+ return EFI_NOT_FOUND;

+ }

+

+ pvh_start_info =3D (struct hvm_start_info *)(UINTN)PVHResetVectorData[0]= ;

+

+ *Entries =3D (struct hvm_memmap_table_entry *)(UINTN)pvh_start_info->= memmap_paddr;

+ *Count =3D pvh_start_info->memmap_entries;

+

+ return EFI_SUCCESS;

+}

+

+STATIC

+EFI_STATUS

+PlatformScanE820Pvh (

+ IN E820_SCAN_CALLBACK Callback,

+ IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob

+ )

+{

+ struct hvm_memmap_table_entry *Memmap;

+ UINT32 MemmapEntriesCount;

+ struct hvm_memmap_table_entry *Entry;

+ EFI_E820_ENTRY64 E820Entry;

+ EFI_STATUS Status;

+ UINT32 Loop;

+

+ Status =3D GetPvhMemmapEntries (&Memmap, &MemmapEntriesCount);
+ if (EFI_ERROR (Status)) {

+ return Status;

+ }

+

+ for (Loop =3D 0; Loop < MemmapEntriesCount; Loop++) {

+ Entry =3D Memmap + Loop;

+

+ if (Entry->type =3D=3D XEN_HVM_MEMMAP_TYPE_RAM) {

+ E820Entry.BaseAddr =3D Entry->addr;

+ E820Entry.Length =3D Entry->size;

+ E820Entry.Type =3D Entry->type;

+ Callback (&E820Entry, PlatformInfoHob);

+ }

+ }

+

+ return EFI_SUCCESS;

+}

+

/**

Iterate over the entries in QEMU's fw_cfg E820 RAM map, call the

passed callback for each entry.

@@ -279,6 +340,10 @@ PlatformScanE820 (
EFI_E820_ENTRY64 E820Entry;

UINTN Processed;



+ if (PlatformInfoHob->HostBridgeDevId =3D=3D CLOUDHV_DEVICE_ID) {

+ return PlatformScanE820Pvh (Callback, PlatformInfoHob);

+ }

+

Status =3D QemuFwCfgFindFile ("etc/e820", &FwCfgItem, &= ;FwCfgSize);

if (EFI_ERROR (Status)) {

return Status;

@@ -297,36 +362,6 @@ PlatformScanE820 (
return EFI_SUCCESS;

}



-/**

- Returns PVH memmap

-

- @param Entries Pointer to PVH memmap

- @param Count Number of entries

-

- @return EFI_STATUS

-**/

-EFI_STATUS

-GetPvhMemmapEntries (

- struct hvm_memmap_table_entry **Entries,

- UINT32 *Count

- )

-{

- UINT32 *PVHResetVectorData;

- struct hvm_start_info *pvh_start_info;

-

- PVHResetVectorData =3D (VOID *)(UINTN)PcdGet32 (PcdXenPvhStartOfDayStruc= tPtr);

- if (PVHResetVectorData =3D=3D 0) {

- return EFI_NOT_FOUND;

- }

-

- pvh_start_info =3D (struct hvm_start_info *)(UINTN)PVHResetVectorData[0]= ;

-

- *Entries =3D (struct hvm_memmap_table_entry *)(UINTN)pvh_start_info->= memmap_paddr;

- *Count =3D pvh_start_info->memmap_entries;

-

- return EFI_SUCCESS;

-}

-

STATIC

UINT64

GetHighestSystemMemoryAddressFromPvhMemmap (

--
2.34.1


<= b>Disclaimer

The information contained in this communication from the sender i= s confidential. It is intended solely for use by the recipient and others a= uthorized to receive it. If you are not the recipient, you are hereby notif= ied that any disclosure, copying, distribution or taking action in relation= of the contents of this information is strictly prohibited and may be unla= wful.

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#113630) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--MCBoundary=_12401111411040631--