Re: [edk2-devel] [PATCH V1 1/1] OvmfPkg/QemuBootOrderLib: Measure the etc/boot-menu-wait

2024-03-22 Thread sunceping
On Thursday, March 21, 2024 8:25 PM Gerd Hoffmann wrote:
> Well, just try to read them.  If present they can just be measured.
> If not present we can either skip them, or measure with an empty data 
> field to indicate it is not present.
My understanding :
If the fw_cfg is present,  it must be measured and consumed later.
Is this correct?

> > > > We propose below solution :
> > > >
> > > > Add a new API in QemuFwCfgLib,
> > > > RETURN_STATUS QemuFwCfgGetData(fw_cfg_name, *size, *value,
> > > FW_CFG_GET_DATA_FLAG flag).
> > >
> > > I'd suggest to *not* touch the existing interfaces for reading entries.
> > > Instead change the existing functions to first check the cache, in 
> > > case there is no cache entry go read from fw_cfg.
> > Actually we don't touch the existing interface for reading entries.
> > The API is newly added.
> 
> But then you have to find and update all callsites (or at least the 
> ones where we care about measurement).
In your solution,  if we cache all items that need to be measured,
we would have to add a new API (example: QemuFwCfgGetDataFromCache ())  to get 
the data from cache.

Then we also have to find and update all callsites.

Thanks
Ceping



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117028): https://edk2.groups.io/g/devel/message/117028
Mute This Topic: https://groups.io/mt/104880546/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [RFC PATCH] OvmfPkg/SecurityPkg: Add build option for coexistance of vTPM and RTMR.

2024-03-22 Thread Gerd Hoffmann
On Fri, Mar 22, 2024 at 02:39:20AM +, Yao, Jiewen wrote:
> Please aware that this option will cause potential security risk.
> 
> In case that any the guest component only knows one of vTPM or RTMR,
> and only extends one of vTPM or RTMR, but the other one only verifies
> the other, then the chain of trust is broken.  This solution is secure
> if and only if all guest components aware of coexistence, and can
> ensure all measurements are extended to both vTPM and RTMR.  But I am
> not sure if all guest components are ready today.

As far I know (it's been a while I looked at those patches) shim.efi and
grub.efi have support for EFI_CC_MEASUREMENT_PROTOCOL, but use the same
logic we have in DxeTpm2MeasureBootLib, i.e. they will not measure to
both RTMR and vTPM.

Looking at systemd-boot I see it will likewise not measure to both RTMR
and vTPM, but with reversed priority (use vTPM not RTMR in case both are
present).

Linux kernel appears to not have EFI_CC_MEASUREMENT_PROTOCOL support.

> Since this option caused a potential risk / misuse breaking the chain
> of trust, I recommend we have at least one more company to endorse the
> runtime co-existence of vTPM and RTMR.  Also, I would like to hear the
> opinions from other companies.

Rumors say intel is working on coconut-svsm support for tdx.  That will
most likely allow to use a vTPM with tdx even without depending on the
virtualization host or cloud hyperscaler providing one.  We will see VMs
with both RTMR and vTPM and surely need a strategy how guests should
deal with that situation, consistent across the whole boot stack and
not every component doing something different.

Given that the vTPM might be provided by the hypervisor and thus not be
part of the TCB I can see that guests might want use both vTPM and RTMR.
So, yes, for that case coexistance makes sense.  I'm not convinced it is
a good idea to make that a compile time option though.  That will not
help to promote a consistent story ...

take care,
  Gerd



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117029): https://edk2.groups.io/g/devel/message/117029
Mute This Topic: https://groups.io/mt/105070442/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-redfish-client][PATCH V2 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Set SettingsObject URI in @Redfish.Settings resource as the config
language which is the same as the config language of parent URI
that mandates @Redfish.Settings.
With this, we can find the config language of the properties in
SettingsObject URI.

Signed-off-by: Abner Chang 
Cc: Igor Kulchytskyy 
Co-authored-by: Nickle Wang 
---
 .../Library/RedfishFeatureUtilityLib.h| 17 
 .../RedfishFeatureUtilityLib.c| 86 ---
 .../RedfishConfigLangMapDxe.c | 15 +++-
 3 files changed, 101 insertions(+), 17 deletions(-)

diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h 
b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
index ba9ea01501..3c5f248eb7 100644
--- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
+++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
@@ -369,6 +369,23 @@ RedfishSetRedfishUri (
   INEFI_STRING  Uri
   );
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
+  @retval  EFI_SUCCESSRedfish uri is saved
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  );
+
 /**
 
   Get the property name by given Configure Language.
diff --git 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
index cc2b37b796..c37bf85310 100644
--- 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
+++ 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
@@ -2082,7 +2082,6 @@ GetConfigureLang (
   EFI_STRING  ResultStr;
   EFI_STRING  UnicodeUri;
   EFI_STATUS  Status;
-  EFI_STRING  StrFound;
 
   if (IS_EMPTY_STRING (Uri)) {
 return NULL;
@@ -2101,18 +2100,6 @@ GetConfigureLang (
   }
 
   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-  if (ConfigLang == NULL) {
-//
-// @Redfish.Settings share the same schema as its parent.
-// Remove "Settings" and try again.
-//
-StrFound = StrStr (UnicodeUri, L"/Settings");
-if (StrFound != NULL) {
-  StrFound[0] = L'\0';
-  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI, try: %s\n", 
__func__, UnicodeUri));
-  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-}
-  }
 
   FreePool (UnicodeUri);
 
@@ -2172,6 +2159,61 @@ RedfishSetRedfishUri (
   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol, ConfigLang, Uri);
 }
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  ParentUri or SettingObjectUri is NULL.
+  @retval  EFI_NOT_FOUND  Config language for ParentUri is not found.
+  @retval  EFI_SUCCESSRedfish URI is saved with corresponding
+  config language.
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  )
+{
+  EFI_STATUS  Status;
+  EFI_STRING  ConfigLang;
+
+  if ((ParentUri == NULL) || (SettingObjectUri == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check if the SettingsObject URI already in the database.
+  //
+  ConfigLang = RedfishGetConfigLanguage (SettingObjectUri);
+  if (ConfigLang == NULL) {
+//
+// No config language of SettingsObject URI is found.
+// Get the config language of parent URI because the data model of
+// SettingsObject URI resource is the same as the data model of parent URI.
+//
+ConfigLang = RedfishGetConfigLanguage (ParentUri);
+if (ConfigLang == NULL) {
+  DEBUG ((DEBUG_ERROR, "%a: Failed to get the config language of parent 
URI that mandates SettingsObject - %s.\n", __func__, ParentUri));
+  return EFI_NOT_FOUND;
+}
+
+// Set the config language of settings URI using parent's URI config 
language.
+Status = RedfishSetRedfishUri (ConfigLang, SettingObjectUri);
+if (EFI_ERROR (Status)) {
+  DEBUG ((DEBUG_ERROR, "%a: Fails to set the config language of 
SettingsObject - %s.\n", __func__, SettingObjectUri));
+  return Status;
+}
+
+DEBUG ((DEBUG_INFO, "%a: Set the config language of SettingsObject - %s: 
SUCCESS.\n", __func__, SettingObjectUri));
+  }
+
+  return EFI_SUCCESS;
+}
+
 /**
 
   Get @odata.id from give HTTP payload. It's call responsibility to release 
returned buffer.
@@ -3532,6 +3574,7 @@ CompareRedfishBooleanArrayValues (
   payload and URI to pending settings. Caller has to release "SettingPayload" 
and
   "SettingUri".
 
+  @param[in]  RedfishService  Ins

[edk2-devel] [edk2-redfish-client][PATCH V2 2/2] RedfishClientPkg/FeatureDriver: Use SetRedfishSettingsObjectsUri

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Use SetRedfishSettingsObjectsUri to set the config language
for SettingsObject URI.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c  | 1 +
 RedfishClientPkg/Features/Bios/v1_1_0/Dxe/BiosDxe.c  | 1 +
 RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c  | 1 +
 .../Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c  | 1 +
 .../Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c   | 1 +
 RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c  | 1 +
 6 files changed, 6 insertions(+)

diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c 
b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
index 1ca920640a..bb64ef8625 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
@@ -141,6 +141,7 @@ RedfishResourceConsumeResource (
 );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/Bios/v1_1_0/Dxe/BiosDxe.c 
b/RedfishClientPkg/Features/Bios/v1_1_0/Dxe/BiosDxe.c
index b2b9a0e2de..2a77b3475a 100644
--- a/RedfishClientPkg/Features/Bios/v1_1_0/Dxe/BiosDxe.c
+++ b/RedfishClientPkg/Features/Bios/v1_1_0/Dxe/BiosDxe.c
@@ -140,6 +140,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((DEBUG_MANAGEABILITY, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c 
b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
index 7501c1a975..5a66fe59e0 100644
--- a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
@@ -130,6 +130,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: @Redfish.Settings found: 
%s\n", __func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
index 1235760a18..a0c71212b3 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
@@ -133,6 +133,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
index 5207362dac..494bf59dfc 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c 
b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
index c4a363cdf5..f2c0a7735b 100644
--- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
+++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117031): https://edk2.groups.io/g/devel/message/117031
Mute This Topic: h

Re: [edk2-devel] [PATCH V1 1/1] OvmfPkg/QemuBootOrderLib: Measure the etc/boot-menu-wait

2024-03-22 Thread Gerd Hoffmann
On Fri, Mar 22, 2024 at 08:29:28AM +, Sun, CepingX wrote:
> On Thursday, March 21, 2024 8:25 PM Gerd Hoffmann wrote:
> > Well, just try to read them.  If present they can just be measured.
> > If not present we can either skip them, or measure with an empty data 
> > field to indicate it is not present.
> My understanding :
> If the fw_cfg is present,  it must be measured and consumed later.
> Is this correct?

I think that would be the best strategy.  In SEC or early PEI read the
items, cache them in HOBs, optionally measure them.

When consumed just fetch them from the cache.  For entries we are
measuring caching is mandatory (to make sure we are actually using
the same data we have measured).

> > But then you have to find and update all callsites (or at least the 
> > ones where we care about measurement).
> In your solution,  if we cache all items that need to be measured,
> we would have to add a new API (example: QemuFwCfgGetDataFromCache ())  to 
> get the data from cache.

No, we only need to update QemuFwCfgSelectItem + QemuFwCfgReadBytes to
support reading from the cache.

QemuFwCfgGetDataFromCache() can be added as additional API, and
callsites have the option to either switch over, or continue to
use the existing API.

take care,
  Gerd



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117032): https://edk2.groups.io/g/devel/message/117032
Mute This Topic: https://groups.io/mt/104880546/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-redfish-client][PATCH V3 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Set SettingsObject URI in @Redfish.Settings resource as the config
language which is the same as the config language of parent URI
that mandates @Redfish.Settings.
With this, we can find the config language of the properties in
SettingsObject URI.

Signed-off-by: Abner Chang 
Cc: Igor Kulchytskyy 
Co-authored-by: Nickle Wang 
---
 .../Library/RedfishFeatureUtilityLib.h| 17 
 .../RedfishFeatureUtilityLib.c| 86 ---
 .../RedfishConfigLangMapDxe.c | 15 +++-
 3 files changed, 101 insertions(+), 17 deletions(-)

diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h 
b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
index ba9ea01501..3c5f248eb7 100644
--- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
+++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
@@ -369,6 +369,23 @@ RedfishSetRedfishUri (
   INEFI_STRING  Uri
   );
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
+  @retval  EFI_SUCCESSRedfish uri is saved
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  );
+
 /**
 
   Get the property name by given Configure Language.
diff --git 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
index cc2b37b796..c37bf85310 100644
--- 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
+++ 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
@@ -2082,7 +2082,6 @@ GetConfigureLang (
   EFI_STRING  ResultStr;
   EFI_STRING  UnicodeUri;
   EFI_STATUS  Status;
-  EFI_STRING  StrFound;
 
   if (IS_EMPTY_STRING (Uri)) {
 return NULL;
@@ -2101,18 +2100,6 @@ GetConfigureLang (
   }
 
   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-  if (ConfigLang == NULL) {
-//
-// @Redfish.Settings share the same schema as its parent.
-// Remove "Settings" and try again.
-//
-StrFound = StrStr (UnicodeUri, L"/Settings");
-if (StrFound != NULL) {
-  StrFound[0] = L'\0';
-  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI, try: %s\n", 
__func__, UnicodeUri));
-  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-}
-  }
 
   FreePool (UnicodeUri);
 
@@ -2172,6 +2159,61 @@ RedfishSetRedfishUri (
   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol, ConfigLang, Uri);
 }
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  ParentUri or SettingObjectUri is NULL.
+  @retval  EFI_NOT_FOUND  Config language for ParentUri is not found.
+  @retval  EFI_SUCCESSRedfish URI is saved with corresponding
+  config language.
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  )
+{
+  EFI_STATUS  Status;
+  EFI_STRING  ConfigLang;
+
+  if ((ParentUri == NULL) || (SettingObjectUri == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check if the SettingsObject URI already in the database.
+  //
+  ConfigLang = RedfishGetConfigLanguage (SettingObjectUri);
+  if (ConfigLang == NULL) {
+//
+// No config language of SettingsObject URI is found.
+// Get the config language of parent URI because the data model of
+// SettingsObject URI resource is the same as the data model of parent URI.
+//
+ConfigLang = RedfishGetConfigLanguage (ParentUri);
+if (ConfigLang == NULL) {
+  DEBUG ((DEBUG_ERROR, "%a: Failed to get the config language of parent 
URI that mandates SettingsObject - %s.\n", __func__, ParentUri));
+  return EFI_NOT_FOUND;
+}
+
+// Set the config language of settings URI using parent's URI config 
language.
+Status = RedfishSetRedfishUri (ConfigLang, SettingObjectUri);
+if (EFI_ERROR (Status)) {
+  DEBUG ((DEBUG_ERROR, "%a: Fails to set the config language of 
SettingsObject - %s.\n", __func__, SettingObjectUri));
+  return Status;
+}
+
+DEBUG ((DEBUG_INFO, "%a: Set the config language of SettingsObject - %s: 
SUCCESS.\n", __func__, SettingObjectUri));
+  }
+
+  return EFI_SUCCESS;
+}
+
 /**
 
   Get @odata.id from give HTTP payload. It's call responsibility to release 
returned buffer.
@@ -3532,6 +3574,7 @@ CompareRedfishBooleanArrayValues (
   payload and URI to pending settings. Caller has to release "SettingPayload" 
and
   "SettingUri".
 
+  @param[in]  RedfishService  Ins

[edk2-devel] [edk2-redfish-client][PATCH V3 2/2] RedfishClientPkg/FeatureDriver: Use SetRedfishSettingsObjectsUri

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Use SetRedfishSettingsObjectsUri to set the config language
for SettingsObject URI.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c  | 1 +
 RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c  | 1 +
 .../Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c  | 1 +
 .../Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c   | 1 +
 RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c  | 1 +
 5 files changed, 5 insertions(+)

diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c 
b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
index 1ca920640a..bb64ef8625 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
@@ -141,6 +141,7 @@ RedfishResourceConsumeResource (
 );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c 
b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
index 7501c1a975..5a66fe59e0 100644
--- a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
@@ -130,6 +130,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: @Redfish.Settings found: 
%s\n", __func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
index 1235760a18..a0c71212b3 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
@@ -133,6 +133,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
index 5207362dac..494bf59dfc 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c 
b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
index c4a363cdf5..f2c0a7735b 100644
--- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
+++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117034): https://edk2.groups.io/g/devel/message/117034
Mute This Topic: https://groups.io/mt/105081873/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Mike Maslenkin
Hi Abner,

> On 22. 3. 2024., at 12:09, Chang, Abner via groups.io 
>  wrote:
> 
> From: Abner Chang 
> 
> Set SettingsObject URI in @Redfish.Settings resource as the config
> language which is the same as the config language of parent URI
> that mandates @Redfish.Settings.
> With this, we can find the config language of the properties in
> SettingsObject URI.
> 
> Signed-off-by: Abner Chang 
> Cc: Igor Kulchytskyy 
> Co-authored-by: Nickle Wang 
> ---
> .../Library/RedfishFeatureUtilityLib.h| 17 
> .../RedfishFeatureUtilityLib.c| 86 ---
> .../RedfishConfigLangMapDxe.c | 15 +++-
> 3 files changed, 101 insertions(+), 17 deletions(-)
> 
> diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h 
> b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> index ba9ea01501..3c5f248eb7 100644
> --- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> +++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> @@ -369,6 +369,23 @@ RedfishSetRedfishUri (
>   INEFI_STRING  Uri
>   );
> 
> +/**
> +
> +  Save Redfish SettingsObject URI in database for further use.
> +
> +  @param[in]ParentUri Parent URI of @Redfish.Settings property.
> +  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
> +
> +  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
> +  @retval  EFI_SUCCESSRedfish uri is saved
> +
> +**/
> +EFI_STATUS
> +SetRedfishSettingsObjectsUri (
> +  IN EFI_STRING  ParentUri,
> +  IN EFI_STRING  SettingObjectUri
> +  );
> +
> /**
> 
>   Get the property name by given Configure Language.
> diff --git 
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
>  
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
> index cc2b37b796..c37bf85310 100644
> --- 
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
> +++ 
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
> @@ -2082,7 +2082,6 @@ GetConfigureLang (
>   EFI_STRING  ResultStr;
>   EFI_STRING  UnicodeUri;
>   EFI_STATUS  Status;
> -  EFI_STRING  StrFound;
> 
>   if (IS_EMPTY_STRING (Uri)) {
> return NULL;
> @@ -2101,18 +2100,6 @@ GetConfigureLang (
>   }
> 
>   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> -  if (ConfigLang == NULL) {
> -//
> -// @Redfish.Settings share the same schema as its parent.
> -// Remove "Settings" and try again.
> -//
> -StrFound = StrStr (UnicodeUri, L"/Settings");
> -if (StrFound != NULL) {
> -  StrFound[0] = L'\0';
> -  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI, try: 
> %s\n", __func__, UnicodeUri));
> -  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> -}
> -  }
> 
>   FreePool (UnicodeUri);
> 
> @@ -2172,6 +2159,61 @@ RedfishSetRedfishUri (
>   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol, ConfigLang, 
> Uri);
> }
> 
> +/**
> +
> +  Save Redfish SettingsObject URI in database for further use.
> +
> +  @param[in]ParentUri Parent URI of @Redfish.Settings property.
> +  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
> +
> +  @retval  EFI_INVALID_PARAMETER  ParentUri or SettingObjectUri is NULL.
> +  @retval  EFI_NOT_FOUND  Config language for ParentUri is not found.
> +  @retval  EFI_SUCCESSRedfish URI is saved with corresponding
> +  config language.
> +
> +**/
> +EFI_STATUS
> +SetRedfishSettingsObjectsUri (
> +  IN EFI_STRING  ParentUri,
> +  IN EFI_STRING  SettingObjectUri
> +  )
> +{
> +  EFI_STATUS  Status;
> +  EFI_STRING  ConfigLang;
> +
> +  if ((ParentUri == NULL) || (SettingObjectUri == NULL)) {
> +return EFI_INVALID_PARAMETER;
> +  }
> +
> +  //
> +  // Check if the SettingsObject URI already in the database.
> +  //
> +  ConfigLang = RedfishGetConfigLanguage (SettingObjectUri);
> +  if (ConfigLang == NULL) {
> +//
> +// No config language of SettingsObject URI is found.
> +// Get the config language of parent URI because the data model of
> +// SettingsObject URI resource is the same as the data model of parent 
> URI.
> +//
> +ConfigLang = RedfishGetConfigLanguage (ParentUri);
> +if (ConfigLang == NULL) {
> +  DEBUG ((DEBUG_ERROR, "%a: Failed to get the config language of parent 
> URI that mandates SettingsObject - %s.\n", __func__, ParentUri));
> +  return EFI_NOT_FOUND;
> +}
> +
> +// Set the config language of settings URI using parent's URI config 
> language.
> +Status = RedfishSetRedfishUri (ConfigLang, SettingObjectUri);
> +if (EFI_ERROR (Status)) {
> +  DEBUG ((DEBUG_ERROR, "%a: Fails to set the config language of 
> SettingsObject - %s.\n", __func__, SettingObjectUri));

looks like there is ConfigLang leak in this function.

> +  return Status;
> +}
> +
> +DEBUG ((DEBUG_INFO, "%a: Set the config language 

[edk2-devel] [PATCH 0/5] [PATCH 0/5] Config language searching algorithm enhancement and the bug fixes

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

PR # 5491

In this patch set,
1 We enhance the config language searching algorithm.
  As the performance of searching config language using HII GetString is
  pretty slow. For the example, 1800 HII BIOS options takes over 30 mins
  to build up the metadata required for Redfish BIOS resource. With this
  improvement, it only takes 4 seconds.

2.Introduce the Redfish debug framework, there are three edk2 Redfish
  debug scopes.
  a. PcdDebugPrintErrorLevel, DEBUG_MANAGEABILITY to enable debug message
 for edk2 Redfish.
  b. PcdRedfishDebugCategory, enablement of individule edk2 Redfish
 component. Currently we only support RedfishPlatformConfigDxe
 module.
  c. PcdRedfishPlatformConfigDebugProperty, edk2 Redfish module debug
 scope. This PCD is used by RedfishPlatformConfigDxe debug enablement.

3 This patch set also fixes an issue that deletes HII string unexpectedly.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 

Abner Chang (4):
  RedfishPkg/RedfishDebugLib: Introduce Redfish DEBUG macro
  RedfishPkg/RedfishPlatformConfigDxe:Add RefishDebugLib support
  RedfishPkg/RedfishPlatformConfigDxe: HII string is deleted
unexpectedly
  EmulatorPkg/Redfish: Use edk2 Redfish debug PCDs

abnchang (1):
  RedfishPkg/RedfishPlatformConfigDxe: Config language searching
optimization

 RedfishPkg/RedfishPkg.dec |  24 +
 EmulatorPkg/EmulatorPkg.dsc   |  21 +
 .../RedfishDebugLib/RedfishDebugLib.inf   |   4 +
 .../RedfishPlatformConfigDxe.inf  |   8 +
 RedfishPkg/Include/Library/RedfishDebugLib.h  |  43 +-
 .../RedfishPlatformConfigDxe.h|  46 +-
 .../RedfishPlatformConfigImpl.h   | 131 ++-
 .../Library/RedfishDebugLib/RedfishDebugLib.c |  55 +-
 .../RedfishPlatformConfigCapability.c |  52 +
 .../RedfishPlatformConfigDxe.c|  89 +-
 .../RedfishPlatformConfigImpl.c   | 894 --
 11 files changed, 1196 insertions(+), 171 deletions(-)
 create mode 100644 
RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigCapability.c

-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117036): https://edk2.groups.io/g/devel/message/117036
Mute This Topic: https://groups.io/mt/105082172/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 2/5] RedfishPkg/RedfishDebugLib: Introduce Redfish DEBUG macro

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Introduce DEBUG_REDFISH macro for the debug message
of edk2 Redfish components.
DEBUG_REDFISH can be used in any edk2 Redfish component
with Redfish DebugCatagory as the first parameter.
Whether the debug message is output or not depends on
the platform setting of PcdRedfishDebugCatagory.

Signed-off-by: Abner Chang 
Cc: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 RedfishPkg/RedfishPkg.dec |  9 +++
 .../RedfishDebugLib/RedfishDebugLib.inf   |  4 ++
 RedfishPkg/Include/Library/RedfishDebugLib.h  | 43 +++
 .../Library/RedfishDebugLib/RedfishDebugLib.c | 55 ---
 4 files changed, 57 insertions(+), 54 deletions(-)

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 1a9c9ed7bc5..a9665ff68ef 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -5,6 +5,7 @@
 # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
 # Copyright (c) 2023, American Megatrends International LLC.
 # Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
@@ -184,3 +185,11 @@
   gEfiRedfishPkgTokenSpaceGuid.PcdHttpRetryWaitInSecond|1|UINT16|0x1010
   ## This is used to disable Redfish HTTP cache function and every request 
will be sent to Redfish service.
   gEfiRedfishPkgTokenSpaceGuid.PcdHttpCacheDisabled|FALSE|BOOLEAN|0x1011
+  #
+  # Redfish debug catagories
+  # To enable the debug message for the entire edk2 Redfish implementation, 
below PCDs must be set.
+  # DEBUG_MANAGEABILITY must be set PcdDebugPrintErrorLevel.
+  #
+  #   0x0001  RedfishPlatformConfigDxe driver debug enabled.
+  #
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory|0|UINT64|0x1012
diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf 
b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
index d468bb213b6..42ff321b48e 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
@@ -2,6 +2,7 @@
 #  INF file for Redfish debug library.
 #
 #  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -35,5 +36,8 @@
   RedfishHttpLib
   UefiLib
 
+[FixedPcd]
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory
+
 [Depex]
   TRUE
diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h 
b/RedfishPkg/Include/Library/RedfishDebugLib.h
index ad7a6975867..19e5a895cc8 100644
--- a/RedfishPkg/Include/Library/RedfishDebugLib.h
+++ b/RedfishPkg/Include/Library/RedfishDebugLib.h
@@ -2,6 +2,7 @@
   This file defines the Redfish debug library interface.
 
   Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -11,28 +12,48 @@
 #define REDFISH_DEBUG_LIB_H_
 
 #include 
+#include 
 #include 
 #include 
 #include 
 
 #include 
 
-#define DEBUG_REDFISH_NETWORK DEBUG_MANAGEABILITY   ///< Debug error 
level for Redfish networking function
-#define DEBUG_REDFISH_HOST_INTERFACE  DEBUG_MANAGEABILITY   ///< Debug error 
level for Redfish networking function
+// Used with MdePKg DEBUG macro.
+#define DEBUG_REDFISH_NETWORK  DEBUG_MANAGEABILITY  ///< Debug 
error level for Redfish networking function
+#define DEBUG_REDFISH_HOST_INTERFACE   DEBUG_MANAGEABILITY  ///< Debug 
error level for Redfish Host INterface
+#define DEBUG_REDFISH_PLATFORM_CONFIG  DEBUG_MANAGEABILITY  ///< Debug 
error level for Redfish Platform Configure Driver
+
+//
+// Definitions of Redfish debug capability in Redfish component scope, used 
with DEBUG_REDFISH macro
+// For example, Redfish Platform Config Driver
+//   DEBUG_REDFISH(DEBUG_REDFISH_PLATFORM_CONFIG_DXE, ...)
+//
+#define DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE  0x0001
+
+#define DEBUG_REDFISH(DebugCategory, ...) \
+do {\
+  if (!DebugPrintEnabled()) {   \
+break;  \
+  } \
+  if (!DebugRedfishComponentEnabled (DebugCategory)) { \
+break; \
+  }\
+  DEBUG ((DEBUG_MANAGEABILITY, ##__VA_ARGS__));   \
+} while (FALSE)
 
 /**
-  Debug print the value of StatementValue.
+  Determine whether the Redfish debug category is enabled in
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory.
 
-  @param[in]  ErrorLevel DEBUG macro error level.
-  @param[in]  StatementValue The statement value to print.
+  @param[in]  DebugCategory  Redfi

[edk2-devel] [PATCH 4/5] RedfishPkg/RedfishPlatformConfigDxe: HII string is deleted unexpectedly

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Add the condition check when delete HII string.
Only when the HiiStatement operand equal to "EFI_IFR_STRING_OP"
and the statement value type = EFI_IFR_TYPE_STRING.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 .../RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c| 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c 
b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
index 8a02c839035..d165799f9a1 100644
--- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
+++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
@@ -1873,8 +1873,11 @@ RedfishPlatformConfigSetStatementCommon (
 DEBUG ((DEBUG_ERROR, "%a: failed to save question value: %r\n", __func__, 
Status));
   }
 
-  if (StatementValue->Value.string != 0) {
-HiiDeleteString (StatementValue->Value.string, 
TargetStatement->ParentForm->ParentFormset->HiiHandle);
+  if ((TargetStatement->HiiStatement->Operand == EFI_IFR_STRING_OP) && 
(StatementValue->Type == EFI_IFR_TYPE_STRING)) {
+if (StatementValue->Value.string != 0) {
+  // Delete HII string which was created for HII statement operand = 
EFI_IFR_STRING_OP and Type = EFI_IFR_TYPE_STRING.
+  HiiDeleteString (StatementValue->Value.string, 
TargetStatement->ParentForm->ParentFormset->HiiHandle);
+}
   }
 
   return Status;
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117040): https://edk2.groups.io/g/devel/message/117040
Mute This Topic: https://groups.io/mt/105082178/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 1/5] RedfishPkg/RedfishPlatformConfigDxe: Config language searching optimization

2024-03-22 Thread Chang, Abner via groups.io
From: abnchang 

Build up the x-uefi-redfish string database for the Redfish confg
language searching, instead of using HII String protocol.
This can improve the time consumption lot on searching strings.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 .../RedfishPlatformConfigImpl.h   | 107 ++-
 .../RedfishPlatformConfigDxe.c|  23 +-
 .../RedfishPlatformConfigImpl.c   | 820 +-
 3 files changed, 878 insertions(+), 72 deletions(-)

diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h 
b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h
index 9f4312decf5..6e6c7fdb8a9 100644
--- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h
+++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigImpl.h
@@ -2,7 +2,8 @@
   This file defines the EDKII Redfish Platform Config Protocol private 
structure.
 
   (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
-  Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+  Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -30,6 +31,10 @@
 #define ENGLISH_LANGUAGE_CODE  "en-US"
 #define X_UEFI_SCHEMA_PREFIX   "x-uefi-redfish-"
 
+#define MAX_X_UEFI_REDFISH_STRING_SIZE  (128 * 2)// 128 character in UCS.
+
+typedef struct _REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE 
REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE;
+
 //
 // Definition of REDFISH_PLATFORM_CONFIG_PRIVATE.
 //
@@ -46,17 +51,49 @@ typedef struct {
   CHAR8**SchemaList;// Schema list
 } REDFISH_PLATFORM_CONFIG_SCHEMA;
 
+// Defines the number of elements in array
+#define X_UEFI_REDFISH_STRING_ARRAY_ENTRY_NUMBER  1024
+
+//
+// Definition of x-uefi-redfish string element.
+//
+typedef struct {
+  EFI_STRING_IDStringId;
+  CHAR16   *UcsString;
+} REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT;
+
+//
+// Discrete string array buffer, each has X_UEFI_REDFISH_STRING_ARRAY_NUMBER 
element.
+//
+typedef struct {
+  LIST_ENTRY  NextArray;
+  REDFISH_X_UEFI_STRINGS_ARRAY_ELEMENT*ArrayEntryAddress;
+} REDFISH_X_UEFI_STRINGS_ARRAY;
+
+//
+// x-uefi-redfish string database, x-uefi-redfish language based.
+//
+typedef struct {
+  LIST_ENTRYNextXuefiRedfishLanguage; 
// Link to the next suppoted x-uefi-Redfish language.
+  CHAR8 *XuefiRedfishLanguage;
// x-uefi-redfish language.
+  UINTN StringsArrayBlocks;   
// Number of the array blocks that accommodate 
X_UEFI_REDFISH_STRING_ARRAY_NUMBER
+  
// elements in each.
+  LIST_ENTRYXuefiRedfishStringArrays; 
// Link entry of x-uefi-redfish string array.
+} REDFISH_X_UEFI_STRING_DATABASE;
+
 //
 // Definition of REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE
 //
 typedef struct {
   LIST_ENTRYLink;
-  HII_FORMSET   *HiiFormSet; // Pointer to HII formset 
data.
-  EFI_GUID  Guid;// Formset GUID.
-  EFI_HII_HANDLEHiiHandle;   // Hii Handle of this 
formset.
-  LIST_ENTRYHiiFormList; // Form list that keep 
form data under this formset.
-  CHAR16*DevicePathStr;  // Device path of this 
formset.
-  REDFISH_PLATFORM_CONFIG_SCHEMASupportedSchema; // Schema that is 
supported in this formset.
+  HII_FORMSET   *HiiFormSet;// Pointer to 
HII formset data.
+  EFI_GUID  Guid;   // Formset 
GUID.
+  EFI_HII_HANDLEHiiHandle;  // Hii Handle 
of this formset.
+  EFI_HII_PACKAGE_LIST_HEADER   *HiiPackageListHeader;  // Hii Package 
list header.
+  LIST_ENTRYHiiFormList;// Form list 
that keep form data under this formset.
+  CHAR16*DevicePathStr; // Device path 
of this formset.
+  REDFISH_PLATFORM_CONFIG_SCHEMASupportedSchema;// Schema that 
is supported in this formset.
+  LIST_ENTRYXuefiRedfishStringDatabase; // 
x-uefi-redfish string/Id data base;
 } REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE;
 
 #define REDFISH_PLATFORM_CONFIG_FORMSET_FROM_LINK(a)  BASE_CR (a, 
REDFISH_PLATFORM_CONFIG_FORM_SET_PRIVATE, Link)
@@ -90,19 +127,19 @@ typedef struct {
 //
 // Definition of REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE
 //
-typedef struct {
+struct _REDFISH_PLATFORM_CONFIG_STATEMENT_PRIVATE {
   LIST_ENTRYLink;
   REDFISH_PLATFORM_CONFI

[edk2-devel] [PATCH 5/5] EmulatorPkg/Redfish: Use edk2 Redfish debug PCDs

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Signed-off-by: Abner Chang 
Cc: Nickle Wang 
---
 EmulatorPkg/EmulatorPkg.dsc | 21 +
 1 file changed, 21 insertions(+)

diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 85134b07816..5fa1ed345a3 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -278,6 +278,27 @@
   
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExServiceDevicePath.DevicePath|{DEVICE_PATH("MAC(,0x1)")}
   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExServiceAccessModeInBand|False
   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDiscoverAccessModeInBand|False
+
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServiceStopIfSecureBootDisabled|False
+  gEmulatorPkgTokenSpaceGuid.PcdRedfishServiceStopIfExitbootService|False
+
+  gEfiRedfishClientPkgTokenSpaceGuid.PcdRedfishServiceEtagSupported|False
+
+  #
+  # Redfish Debug enablement
+  #
+  # 0x0001  RedfishPlatformConfigDxe driver debug enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory|0
+  #   0x0001  x-uefi-redfish string database message enabled
+  #   0x0002  Debug Message for dumping formset
+  #   0x0004  Debug Message for x-uefi-redfish searching result
+  #   0x0008  Debug Message for x-uefi-redfish Regular Expression 
searching result
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigDebugProperty|0
+
+  # Redfish Platform Configure DXE driver feature enablement
+  #   0x0001  Enable building Redfish Attribute Registry menu path.
+  #   0x0002  Allow supressed HII option to be exposed on Redfish.
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigFeatureProperty|0
 !endif
 
 [PcdsDynamicDefault.common.DEFAULT]
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117041): https://edk2.groups.io/g/devel/message/117041
Mute This Topic: https://groups.io/mt/105082179/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 3/5] RedfishPkg/RedfishPlatformConfigDxe:Add RefishDebugLib support

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Add RedfishPlatformConfigDxe debug capability that aligns
with edk2 Redfish debug mechanism.

- PcdRedfishPlatformConfigDebugProperty, add PCD to control
  RedfishPlatformConfigDxe subordinate of Redfish debug
  capabilities.
- PcdRedfishPlatformConfigFeatureProperty, add PCD to
  manage RedfishPlatformConfigDxe features.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 RedfishPkg/RedfishPkg.dec |  15 +++
 .../RedfishPlatformConfigDxe.inf  |   8 ++
 .../RedfishPlatformConfigDxe.h|  46 +++-
 .../RedfishPlatformConfigImpl.h   |  24 +
 .../RedfishPlatformConfigCapability.c |  52 +
 .../RedfishPlatformConfigDxe.c|  59 +++
 .../RedfishPlatformConfigImpl.c   | 100 +++---
 7 files changed, 248 insertions(+), 56 deletions(-)
 create mode 100644 
RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigCapability.c

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index a9665ff68ef..c048e43f53b 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -193,3 +193,18 @@
   #   0x0001  RedfishPlatformConfigDxe driver debug enabled.
   #
   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory|0|UINT64|0x1012
+  #
+  # Redfish RedfishPlatformConfigDxe Debug Properties
+  #   0x0001  x-uefi-redfish string database message enabled
+  #   0x0002  Debug Message for dumping formset
+  #   0x0004  Debug Message for x-uefi-redfish searching result
+  #   0x0008  Debug Message for x-uefi-redfish Regular Expression 
searching result
+  #
+  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigDebugProperty|0|UINT32|0x1013
+  #
+  # RedfishPlatformConfigDxe feature enablement
+  #   0x0001  Enable building Redfish Attribute Registry menu path.
+  #   0x0002  Allow supressed HII option to be exposed on Redfish.
+  #
+  # Redfish RedfishPlatformConfigDxe feature Properties
+  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigFeatureProperty|0|UINT32|0x1014
diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf 
b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
index 5a249c8c3bc..2db47c2cffc 100644
--- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
+++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
@@ -3,6 +3,7 @@
 #
 #  (C) Copyright 2021 Hewlett Packard Enterprise Development LP
 #  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -23,6 +24,7 @@
   RedfishPkg/RedfishPkg.dec
 
 [Sources]
+  RedfishPlatformConfigCapability.c
   RedfishPlatformConfigDxe.h
   RedfishPlatformConfigDxe.c
   RedfishPlatformConfigImpl.h
@@ -36,7 +38,9 @@
   HiiLib
   HiiUtilityLib
   MemoryAllocationLib
+  PcdLib
   PrintLib
+  RedfishDebugLib
   UefiLib
   UefiBootServicesTableLib
   UefiRuntimeServicesTableLib
@@ -51,5 +55,9 @@
 [Guids]
   gEfiRegexSyntaxTypePerlGuid ## CONSUMED
 
+[FixedPcd]
+ gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigFeatureProperty
+ gEfiRedfishPkgTokenSpaceGuid.PcdRedfishPlatformConfigDebugProperty
+
 [Depex]
   TRUE
diff --git a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.h 
b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.h
index 38adea04c5b..688f2067bff 100644
--- a/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.h
+++ b/RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.h
@@ -3,6 +3,7 @@
 
   (C) Copyright 2021 Hewlett Packard Enterprise Development LP
   Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+  Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -20,7 +21,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -37,6 +40,41 @@
 //
 #include 
 
+//
+// Debug message in DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE scope.
+// To enable the debug message for this module, below PCDs must be set.
+//
+// 1. DEBUG_MANAGEABILITY must be set PcdDebugPrintErrorLevel.
+//
+// 2  RedfishPlatformConfigDxe debug enablement must be set in
+//PcdRedfishDebugCategory (defined in RedfishPkg.dec)
+//
+// 3. The suborinate debug enablement for RedfishPlatformConfigDxe
+//must be set in PcdRedfishPlatformConfigDebugPropert (defined
+//in RedfishPkg.dec).
+//
+#define DEBUG_REDFISH_THIS_MODULE(DebugSubordinate, ...) \
+  while (RedfishPlatformConfigDebugProp (DebugSubordinate)) { \
+DEBUG_REDFISH(DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE, ##__VA_ARGS__); 
\
+break; \
+  }
+
+#define DEBUG_REDFISH_THIS_MODULE_CODE_BEGIN(DebugSubordinate) \
+  if (RedfishPlatformConfigDebugProp (DebugSubordin

[edk2-devel] [edk2-redfish-client][PATCH V4 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Set SettingsObject URI in @Redfish.Settings resource as the config
language which is the same as the config language of parent URI
that mandates @Redfish.Settings.
With this, we can find the config language of the properties in
SettingsObject URI.

Signed-off-by: Abner Chang 
Cc: Igor Kulchytskyy 
Co-authored-by: Nickle Wang 
---
 .../Library/RedfishFeatureUtilityLib.h| 17 
 .../RedfishFeatureUtilityLib.c| 87 ---
 .../RedfishConfigLangMapDxe.c | 15 +++-
 3 files changed, 102 insertions(+), 17 deletions(-)

diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h 
b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
index ba9ea01501..3c5f248eb7 100644
--- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
+++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
@@ -369,6 +369,23 @@ RedfishSetRedfishUri (
   INEFI_STRING  Uri
   );
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
+  @retval  EFI_SUCCESSRedfish uri is saved
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  );
+
 /**
 
   Get the property name by given Configure Language.
diff --git 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
index cc2b37b796..02dee89b36 100644
--- 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
+++ 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
@@ -2082,7 +2082,6 @@ GetConfigureLang (
   EFI_STRING  ResultStr;
   EFI_STRING  UnicodeUri;
   EFI_STATUS  Status;
-  EFI_STRING  StrFound;
 
   if (IS_EMPTY_STRING (Uri)) {
 return NULL;
@@ -2101,18 +2100,6 @@ GetConfigureLang (
   }
 
   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-  if (ConfigLang == NULL) {
-//
-// @Redfish.Settings share the same schema as its parent.
-// Remove "Settings" and try again.
-//
-StrFound = StrStr (UnicodeUri, L"/Settings");
-if (StrFound != NULL) {
-  StrFound[0] = L'\0';
-  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI, try: %s\n", 
__func__, UnicodeUri));
-  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-}
-  }
 
   FreePool (UnicodeUri);
 
@@ -2172,6 +2159,62 @@ RedfishSetRedfishUri (
   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol, ConfigLang, Uri);
 }
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  ParentUri or SettingObjectUri is NULL.
+  @retval  EFI_NOT_FOUND  Config language for ParentUri is not found.
+  @retval  EFI_SUCCESSRedfish URI is saved with corresponding
+  config language.
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  )
+{
+  EFI_STATUS  Status;
+  EFI_STRING  ConfigLang;
+
+  if ((ParentUri == NULL) || (SettingObjectUri == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check if the SettingsObject URI already in the database.
+  //
+  ConfigLang = RedfishGetConfigLanguage (SettingObjectUri);
+  if (ConfigLang == NULL) {
+//
+// No config language of SettingsObject URI is found.
+// Get the config language of parent URI because the data model of
+// SettingsObject URI resource is the same as the data model of parent URI.
+//
+ConfigLang = RedfishGetConfigLanguage (ParentUri);
+if (ConfigLang == NULL) {
+  DEBUG ((DEBUG_ERROR, "%a: Failed to get the config language of parent 
URI that mandates SettingsObject - %s.\n", __func__, ParentUri));
+  return EFI_NOT_FOUND;
+}
+
+// Set the config language of settings URI using parent's URI config 
language.
+Status = RedfishSetRedfishUri (ConfigLang, SettingObjectUri);
+if (EFI_ERROR (Status)) {
+  FreePool (ConfigLang);
+  DEBUG ((DEBUG_ERROR, "%a: Fails to set the config language of 
SettingsObject - %s.\n", __func__, SettingObjectUri));
+  return Status;
+}
+
+DEBUG ((DEBUG_INFO, "%a: Set the config language of SettingsObject - %s: 
SUCCESS.\n", __func__, SettingObjectUri));
+  }
+
+  return EFI_SUCCESS;
+}
+
 /**
 
   Get @odata.id from give HTTP payload. It's call responsibility to release 
returned buffer.
@@ -3532,6 +3575,7 @@ CompareRedfishBooleanArrayValues (
   payload and URI to pending settings. Caller has to release "SettingPayload" 
and
   "SettingUri".
 
+  @

[edk2-devel] [edk2-redfish-client][PATCH V4 2/2] RedfishClientPkg/FeatureDriver: Use SetRedfishSettingsObjectsUri

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Use SetRedfishSettingsObjectsUri to set the config language
for SettingsObject URI.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c  | 1 +
 RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c  | 1 +
 .../Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c  | 1 +
 .../Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c   | 1 +
 RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c  | 1 +
 5 files changed, 5 insertions(+)

diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c 
b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
index 1ca920640a..bb64ef8625 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
@@ -141,6 +141,7 @@ RedfishResourceConsumeResource (
 );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c 
b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
index 7501c1a975..5a66fe59e0 100644
--- a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
@@ -130,6 +130,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: @Redfish.Settings found: 
%s\n", __func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
index 1235760a18..a0c71212b3 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
@@ -133,6 +133,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
index 5207362dac..494bf59dfc 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c 
b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
index c4a363cdf5..f2c0a7735b 100644
--- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
+++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117043): https://edk2.groups.io/g/devel/message/117043
Mute This Topic: https://groups.io/mt/105082317/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Hi Mike,
Thanks for catching this, V4 sent.

Abner

> -Original Message-
> From: M M 
> Sent: Friday, March 22, 2024 5:20 PM
> To: devel@edk2.groups.io; Chang, Abner 
> Cc: Igor Kulchytskyy ; Nickle Wang 
> Subject: Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2]
> RedfishClientPkg: Set SettingsObject URI as the config language
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Hi Abner,
>
> > On 22. 3. 2024., at 12:09, Chang, Abner via groups.io
>  wrote:
> >
> > From: Abner Chang 
> >
> > Set SettingsObject URI in @Redfish.Settings resource as the config
> > language which is the same as the config language of parent URI
> > that mandates @Redfish.Settings.
> > With this, we can find the config language of the properties in
> > SettingsObject URI.
> >
> > Signed-off-by: Abner Chang 
> > Cc: Igor Kulchytskyy 
> > Co-authored-by: Nickle Wang 
> > ---
> > .../Library/RedfishFeatureUtilityLib.h| 17 
> > .../RedfishFeatureUtilityLib.c| 86 ---
> > .../RedfishConfigLangMapDxe.c | 15 +++-
> > 3 files changed, 101 insertions(+), 17 deletions(-)
> >
> > diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > index ba9ea01501..3c5f248eb7 100644
> > --- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > +++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > @@ -369,6 +369,23 @@ RedfishSetRedfishUri (
> >   INEFI_STRING  Uri
> >   );
> >
> > +/**
> > +
> > +  Save Redfish SettingsObject URI in database for further use.
> > +
> > +  @param[in]ParentUri Parent URI of @Redfish.Settings property.
> > +  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
> > +
> > +  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
> > +  @retval  EFI_SUCCESSRedfish uri is saved
> > +
> > +**/
> > +EFI_STATUS
> > +SetRedfishSettingsObjectsUri (
> > +  IN EFI_STRING  ParentUri,
> > +  IN EFI_STRING  SettingObjectUri
> > +  );
> > +
> > /**
> >
> >   Get the property name by given Configure Language.
> > diff --git
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> c
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> c
> > index cc2b37b796..c37bf85310 100644
> > ---
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> c
> > +++
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> c
> > @@ -2082,7 +2082,6 @@ GetConfigureLang (
> >   EFI_STRING  ResultStr;
> >   EFI_STRING  UnicodeUri;
> >   EFI_STATUS  Status;
> > -  EFI_STRING  StrFound;
> >
> >   if (IS_EMPTY_STRING (Uri)) {
> > return NULL;
> > @@ -2101,18 +2100,6 @@ GetConfigureLang (
> >   }
> >
> >   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> > -  if (ConfigLang == NULL) {
> > -//
> > -// @Redfish.Settings share the same schema as its parent.
> > -// Remove "Settings" and try again.
> > -//
> > -StrFound = StrStr (UnicodeUri, L"/Settings");
> > -if (StrFound != NULL) {
> > -  StrFound[0] = L'\0';
> > -  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI, try:
> %s\n", __func__, UnicodeUri));
> > -  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> > -}
> > -  }
> >
> >   FreePool (UnicodeUri);
> >
> > @@ -2172,6 +2159,61 @@ RedfishSetRedfishUri (
> >   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol,
> ConfigLang, Uri);
> > }
> >
> > +/**
> > +
> > +  Save Redfish SettingsObject URI in database for further use.
> > +
> > +  @param[in]ParentUri Parent URI of @Redfish.Settings property.
> > +  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
> > +
> > +  @retval  EFI_INVALID_PARAMETER  ParentUri or SettingObjectUri is NULL.
> > +  @retval  EFI_NOT_FOUND  Config language for ParentUri is not 
> > found.
> > +  @retval  EFI_SUCCESSRedfish URI is saved with corresponding
> > +  config language.
> > +
> > +**/
> > +EFI_STATUS
> > +SetRedfishSettingsObjectsUri (
> > +  IN EFI_STRING  ParentUri,
> > +  IN EFI_STRING  SettingObjectUri
> > +  )
> > +{
> > +  EFI_STATUS  Status;
> > +  EFI_STRING  ConfigLang;
> > +
> > +  if ((ParentUri == NULL) || (SettingObjectUri == NULL)) {
> > +return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  //
> > +  // Check if the SettingsObject URI already in the database.
> > +  //
> > +  ConfigLang = RedfishGetConfigLanguage (SettingObjectUri);
> > +  if (ConfigLang == NULL) {
> > +//
> > +// No config language of SettingsObject URI is found.
> > +// Get the config language of parent URI because the data model of
> > +// SettingsObject URI resource is the same as the data model of parent
> URI.
> > +

Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Mike Maslenkin
 Hi Abner,

Sorry if I wasn't clear.
I meant in this function including the success path.
RedfishSetRedfishUri->..->NewConfigLangMapRecord() creates a copy of
this string, so it should be freed in this function.

Regards,
Mike.


On Fri, Mar 22, 2024 at 12:58 PM Chang, Abner  wrote:
>
> [AMD Official Use Only - General]
>
> Hi Mike,
> Thanks for catching this, V4 sent.
>
> Abner
>
> > -Original Message-
> > From: M M 
> > Sent: Friday, March 22, 2024 5:20 PM
> > To: devel@edk2.groups.io; Chang, Abner 
> > Cc: Igor Kulchytskyy ; Nickle Wang 
> > Subject: Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2]
> > RedfishClientPkg: Set SettingsObject URI as the config language
> >
> > Caution: This message originated from an External Source. Use proper caution
> > when opening attachments, clicking links, or responding.
> >
> >
> > Hi Abner,
> >
> > > On 22. 3. 2024., at 12:09, Chang, Abner via groups.io
> >  wrote:
> > >
> > > From: Abner Chang 
> > >
> > > Set SettingsObject URI in @Redfish.Settings resource as the config
> > > language which is the same as the config language of parent URI
> > > that mandates @Redfish.Settings.
> > > With this, we can find the config language of the properties in
> > > SettingsObject URI.
> > >
> > > Signed-off-by: Abner Chang 
> > > Cc: Igor Kulchytskyy 
> > > Co-authored-by: Nickle Wang 
> > > ---
> > > .../Library/RedfishFeatureUtilityLib.h| 17 
> > > .../RedfishFeatureUtilityLib.c| 86 ---
> > > .../RedfishConfigLangMapDxe.c | 15 +++-
> > > 3 files changed, 101 insertions(+), 17 deletions(-)
> > >
> > > diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > > index ba9ea01501..3c5f248eb7 100644
> > > --- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > > +++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > > @@ -369,6 +369,23 @@ RedfishSetRedfishUri (
> > >   INEFI_STRING  Uri
> > >   );
> > >
> > > +/**
> > > +
> > > +  Save Redfish SettingsObject URI in database for further use.
> > > +
> > > +  @param[in]ParentUri Parent URI of @Redfish.Settings 
> > > property.
> > > +  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
> > > +
> > > +  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
> > > +  @retval  EFI_SUCCESSRedfish uri is saved
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +SetRedfishSettingsObjectsUri (
> > > +  IN EFI_STRING  ParentUri,
> > > +  IN EFI_STRING  SettingObjectUri
> > > +  );
> > > +
> > > /**
> > >
> > >   Get the property name by given Configure Language.
> > > diff --git
> > a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > c
> > b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > c
> > > index cc2b37b796..c37bf85310 100644
> > > ---
> > a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > c
> > > +++
> > b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > c
> > > @@ -2082,7 +2082,6 @@ GetConfigureLang (
> > >   EFI_STRING  ResultStr;
> > >   EFI_STRING  UnicodeUri;
> > >   EFI_STATUS  Status;
> > > -  EFI_STRING  StrFound;
> > >
> > >   if (IS_EMPTY_STRING (Uri)) {
> > > return NULL;
> > > @@ -2101,18 +2100,6 @@ GetConfigureLang (
> > >   }
> > >
> > >   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> > > -  if (ConfigLang == NULL) {
> > > -//
> > > -// @Redfish.Settings share the same schema as its parent.
> > > -// Remove "Settings" and try again.
> > > -//
> > > -StrFound = StrStr (UnicodeUri, L"/Settings");
> > > -if (StrFound != NULL) {
> > > -  StrFound[0] = L'\0';
> > > -  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI, try:
> > %s\n", __func__, UnicodeUri));
> > > -  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> > > -}
> > > -  }
> > >
> > >   FreePool (UnicodeUri);
> > >
> > > @@ -2172,6 +2159,61 @@ RedfishSetRedfishUri (
> > >   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol,
> > ConfigLang, Uri);
> > > }
> > >
> > > +/**
> > > +
> > > +  Save Redfish SettingsObject URI in database for further use.
> > > +
> > > +  @param[in]ParentUri Parent URI of @Redfish.Settings 
> > > property.
> > > +  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
> > > +
> > > +  @retval  EFI_INVALID_PARAMETER  ParentUri or SettingObjectUri is NULL.
> > > +  @retval  EFI_NOT_FOUND  Config language for ParentUri is not 
> > > found.
> > > +  @retval  EFI_SUCCESSRedfish URI is saved with corresponding
> > > +  config language.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +SetRedfishSettingsObjectsUri (
> > > +  IN EFI_STRING  ParentUri,
> > > +  IN EFI_STRING  SettingObjectUri
> > > +  )
> > > +{
> > > +  EFI_STATUS  Status;
> > > +  EFI_STRIN

Re: [edk2-devel] [PATCH v2 00/13] Part 2 patch set to add LoongArch support into UefiCpuPkg

2024-03-22 Thread Gerd Hoffmann
On Wed, Mar 20, 2024 at 04:41:52PM +0800, Chao Li wrote:
> This patch set adjusted some order in UefiCpuPig alphabetically, added
> LoongArch libraries and drivers into UefiCpuPkg, it is a continuation of
> the first patch series v8 submitted at
> https://edk2.groups.io/g/devel/message/114526.
> 
> And also separated from https://edk2.groups.io/g/devel/message/116583.
> 
> This series only contents the changes for UefiCpuPkg.
> 
> Patch1-Patch4: Reorder some INF files located in UefiCpuPkg
> alphabetically.
> 
> Patch5-Patch13: Added Timer, CpuMmuLib, CpuMmuInitLib, MpInitLib, CpuDxe
> for LoongArch, and added some PCD and header files requested by the
> above libraries and drivers.
> 
> Modfied modules: UefiCpuPkg
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4726
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4734
> 
> PR: https://github.com/tianocore/edk2/pull/5483
> 
> V1 -> V2:
> 1. Removed PcdCpuMmuIsEnabled.
> 2. Removed API GetMemoryRegionAttributes API as it is no longer needed.
> 3. Patch3, added two empty line in DXE and PEI INF files.
> 4. Patch5, added the Status check in GetTimeInnanoSecond function.
> 5. Separated into two series, this is series one, and the second one is
> OvmfPkg.

While I can't comment on the loongarch architecture details the code
and the integration into build system looks overall sane to me.

Series:
Acked-by: Gerd Hoffmann 

take care,
  Gerd



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117046): https://edk2.groups.io/g/devel/message/117046
Mute This Topic: https://groups.io/mt/105041080/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 1/4] OvmfPkg: Add VirtHstiDxe driver

2024-03-22 Thread Gerd Hoffmann
From: Konstantin Kostiuk 

The driver supports qemu machine types 'pc' and 'q35'.

This patch adds some helper functions to manage the bitmasks.
The implemented features depend on both OVMF build configuration
and qemu VM configuration.

For q35 a single security feature is supported and checked: In
SMM-enabled builds the driver will verify smram is properly locked.
That test should never fail.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Konstantin Kostiuk 
Initial-patch-by: Konstantin Kostiuk 
Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf |  50 
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.h   |  67 +++
 OvmfPkg/VirtHstiDxe/QemuPC.c|  38 +++
 OvmfPkg/VirtHstiDxe/QemuQ35.c   |  58 ++
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.c   | 169 
 5 files changed, 382 insertions(+)
 create mode 100644 OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 create mode 100644 OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
 create mode 100644 OvmfPkg/VirtHstiDxe/QemuPC.c
 create mode 100644 OvmfPkg/VirtHstiDxe/QemuQ35.c
 create mode 100644 OvmfPkg/VirtHstiDxe/VirtHstiDxe.c

diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf 
b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
new file mode 100644
index ..8c63ff6a8953
--- /dev/null
+++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
@@ -0,0 +1,50 @@
+## @file
+#  Component description file for Virt Hsti Driver
+#
+# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# Copyright (c) Microsoft Corporation.
+# Copyright (c) 2024, Red Hat. Inc
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = VirtHstiDxe
+  FILE_GUID  = 60740CF3-D428-4500-80E6-04A5798241ED
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  ENTRY_POINT= VirtHstiDxeEntrypoint
+
+[Sources]
+  VirtHstiDxe.h
+  VirtHstiDxe.c
+  QemuPC.c
+  QemuQ35.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+  UefiDriverEntryPoint
+  UefiLib
+  BaseLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  DebugLib
+  HobLib
+  HstiLib
+  PcdLib
+  PciLib
+  UefiBootServicesTableLib
+
+[Guids]
+  gUefiOvmfPkgPlatformInfoGuid
+
+[FeaturePcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
+
+[Depex]
+  TRUE
diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h 
b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
new file mode 100644
index ..26109bf322e9
--- /dev/null
+++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
@@ -0,0 +1,67 @@
+/** @file
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#define VIRT_HSTI_SECURITY_FEATURE_SIZE  2
+
+#define VIRT_HSTI_BYTE0_Q35_SMM_SMRAM_LOCK  BIT0
+
+typedef struct {
+  // ADAPTER_INFO_PLATFORM_SECURITY
+  UINT32Version;
+  UINT32Role;
+  CHAR16ImplementationID[256];
+  UINT32SecurityFeaturesSize;
+  // bitfields
+  UINT8 SecurityFeaturesRequired[VIRT_HSTI_SECURITY_FEATURE_SIZE];
+  UINT8 SecurityFeaturesImplemented[VIRT_HSTI_SECURITY_FEATURE_SIZE];
+  UINT8 SecurityFeaturesVerified[VIRT_HSTI_SECURITY_FEATURE_SIZE];
+  CHAR16ErrorString[1];
+} VIRT_ADAPTER_INFO_PLATFORM_SECURITY;
+
+VOID
+VirtHstiSetSupported (
+  VIRT_ADAPTER_INFO_PLATFORM_SECURITY  *VirtHsti,
+  IN UINT32ByteIndex,
+  IN UINT8 BitMask
+  );
+
+BOOLEAN
+VirtHstiIsSupported (
+  VIRT_ADAPTER_INFO_PLATFORM_SECURITY  *VirtHsti,
+  IN UINT32ByteIndex,
+  IN UINT8 BitMask
+  );
+
+VOID
+VirtHstiTestResult (
+  CHAR16 *ErrorMsg,
+  IN UINT32  ByteIndex,
+  IN UINT8   BitMask
+  );
+
+/* QemuQ35.c */
+
+VIRT_ADAPTER_INFO_PLATFORM_SECURITY *
+VirtHstiQemuQ35Init (
+  VOID
+  );
+
+VOID
+VirtHstiQemuQ35Verify (
+  VOID
+  );
+
+/* QemuPC.c */
+
+VIRT_ADAPTER_INFO_PLATFORM_SECURITY *
+VirtHstiQemuPCInit (
+  VOID
+  );
+
+VOID
+VirtHstiQemuPCVerify (
+  VOID
+  );
diff --git a/OvmfPkg/VirtHstiDxe/QemuPC.c b/OvmfPkg/VirtHstiDxe/QemuPC.c
new file mode 100644
index ..aa0459e8b6c6
--- /dev/null
+++ b/OvmfPkg/VirtHstiDxe/QemuPC.c
@@ -0,0 +1,38 @@
+/** @file
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "VirtHstiDxe.h"
+
+STATIC VIRT_ADAPTER_INFO_PLATFORM_SECURITY  mHstiPC = {
+  PLATFORM_SECURITY_VERSION_VNEXTCS,
+  PLATFORM_SECURITY_ROLE_PLATFORM_REFERENCE,
+  { L"OVMF (Qemu PC)" },
+  VIRT_HSTI_SECURITY_FEATURE_SIZE,
+};
+
+VIRT_ADAPTER_INFO_PLATFORM_SECURITY *
+VirtHstiQemuPCInit (
+  VOID
+  )
+{
+  return &mHstiPC;
+}
+
+VOID
+VirtHstiQemuPCVerify (
+  VOID
+  )
+{
+}
diff --git a/OvmfPkg/VirtHstiDxe/QemuQ35.c b/OvmfPkg/VirtHstiDxe/QemuQ35.c
new file mode 100644
index ..75e9731b4a52
--- /dev/null
+++ b/OvmfPkg/VirtHstiDxe/QemuQ35.c
@@ -0,0 +1,58 @@
+/** @file
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#in

[edk2-devel] [PATCH 2/4] OvmfPkg: Add VirtHstiDxe to OVMF firmware build

2024-03-22 Thread Gerd Hoffmann
From: Konstantin Kostiuk 

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Signed-off-by: Konstantin Kostiuk 
Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/OvmfPkgIa32.dsc| 2 ++
 OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++
 OvmfPkg/OvmfPkgX64.dsc | 2 ++
 OvmfPkg/OvmfPkgIa32.fdf| 1 +
 OvmfPkg/OvmfPkgIa32X64.fdf | 1 +
 OvmfPkg/OvmfPkgX64.fdf | 1 +
 6 files changed, 9 insertions(+)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 713f08764b07..52b05cb373fb 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -188,6 +188,7 @@ [LibraryClasses]
   PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf
   DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
+  HstiLib|MdePkg/Library/DxeHstiLib/DxeHstiLib.inf
 !if $(SMM_REQUIRE) == FALSE
   LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf
 !endif
@@ -828,6 +829,7 @@ [Components]
   OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
   OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf
   OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
+  OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 
   #
   # ISA Support
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 90b15dc27097..be386914b047 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -193,6 +193,7 @@ [LibraryClasses]
   PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf
   DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
+  HstiLib|MdePkg/Library/DxeHstiLib/DxeHstiLib.inf
 !if $(SMM_REQUIRE) == FALSE
   LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf
 !endif
@@ -842,6 +843,7 @@ [Components.X64]
   OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
   OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf
   OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
+  OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 
   #
   # ISA Support
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 56c920168d25..ae8c7e2fbdcb 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -205,6 +205,7 @@ [LibraryClasses]
   PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf
   DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
+  HstiLib|MdePkg/Library/DxeHstiLib/DxeHstiLib.inf
 
 !if $(SMM_REQUIRE) == FALSE
   LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf
@@ -910,6 +911,7 @@ [Components]
   OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
   OvmfPkg/QemuRamfbDxe/QemuRamfbDxe.inf
   OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
+  OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 
   #
   # ISA Support
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 6c56c5e53f21..6eb26f7d4613 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -316,6 +316,7 @@ [FV.DXEFV]
 INF  OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
 INF  OvmfPkg/PlatformDxe/Platform.inf
 INF  OvmfPkg/IoMmuDxe/IoMmuDxe.inf
+INF  OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 
 !if $(SMM_REQUIRE) == TRUE
 INF  OvmfPkg/SmmAccess/SmmAccess2Dxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index ee8068ad55dc..080784f722a7 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -323,6 +323,7 @@ [FV.DXEFV]
 INF  OvmfPkg/PlatformDxe/Platform.inf
 INF  OvmfPkg/AmdSevDxe/AmdSevDxe.inf
 INF  OvmfPkg/IoMmuDxe/IoMmuDxe.inf
+INF  OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 
 !if $(SMM_REQUIRE) == TRUE
 INF  OvmfPkg/SmmAccess/SmmAccess2Dxe.inf
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index eb3fb90cb8b6..5bc979bc91b7 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -350,6 +350,7 @@ [FV.DXEFV]
 INF  OvmfPkg/PlatformDxe/Platform.inf
 INF  OvmfPkg/AmdSevDxe/AmdSevDxe.inf
 INF  OvmfPkg/IoMmuDxe/IoMmuDxe.inf
+INF  OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 
 !if $(SMM_REQUIRE) == TRUE
 INF  OvmfPkg/SmmAccess/SmmAccess2Dxe.inf
-- 
2.44.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117048): https://edk2.groups.io/g/devel/message/117048
Mute This Topic: https://groups.io/mt/105086166/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 3/4] OvmfPkg/VirtHstiDxe: add varstore flash check

2024-03-22 Thread Gerd Hoffmann
Detects qemu config issue: vars pflash is not in secure mode (write
access restricted to smm).  Applies to Q35 with SMM only.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Konstantin Kostiuk 
Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf |  4 ++
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.h   | 16 -
 OvmfPkg/VirtHstiDxe/Flash.c | 90 +
 OvmfPkg/VirtHstiDxe/QemuQ35.c   | 13 +
 4 files changed, 122 insertions(+), 1 deletion(-)
 create mode 100644 OvmfPkg/VirtHstiDxe/Flash.c

diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf 
b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
index 8c63ff6a8953..9cb2ed1f0c64 100644
--- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
+++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
@@ -22,6 +22,7 @@ [Sources]
   VirtHstiDxe.c
   QemuPC.c
   QemuQ35.c
+  Flash.c
 
 [Packages]
   MdePkg/MdePkg.dec
@@ -46,5 +47,8 @@ [Guids]
 [FeaturePcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
 
+[Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
+
 [Depex]
   TRUE
diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h 
b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
index 26109bf322e9..ca4e376582ad 100644
--- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
+++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
@@ -6,7 +6,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #define VIRT_HSTI_SECURITY_FEATURE_SIZE  2
 
-#define VIRT_HSTI_BYTE0_Q35_SMM_SMRAM_LOCK  BIT0
+#define VIRT_HSTI_BYTE0_Q35_SMM_SMRAM_LOCK BIT0
+#define VIRT_HSTI_BYTE0_Q35_SMM_SECURE_VARS_FLASH  BIT1
 
 typedef struct {
   // ADAPTER_INFO_PLATFORM_SECURITY
@@ -65,3 +66,16 @@ VOID
 VirtHstiQemuPCVerify (
   VOID
   );
+
+/* Flash.c */
+
+#define QEMU_FIRMWARE_FLASH_UNKNOWN0
+#define QEMU_FIRMWARE_FLASH_IS_ROM 1
+#define QEMU_FIRMWARE_FLASH_IS_RAM 2
+#define QEMU_FIRMWARE_FLASH_READ_ONLY  3
+#define QEMU_FIRMWARE_FLASH_WRITABLE   4
+
+UINT32
+VirtHstiQemuFirmwareFlashCheck (
+  UINT32  Address
+  );
diff --git a/OvmfPkg/VirtHstiDxe/Flash.c b/OvmfPkg/VirtHstiDxe/Flash.c
new file mode 100644
index ..e93356793f8c
--- /dev/null
+++ b/OvmfPkg/VirtHstiDxe/Flash.c
@@ -0,0 +1,90 @@
+/** @file
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+
+#include "VirtHstiDxe.h"
+
+#define WRITE_BYTE_CMD   0x10
+#define BLOCK_ERASE_CMD  0x20
+#define CLEAR_STATUS_CMD 0x50
+#define READ_STATUS_CMD  0x70
+#define READ_DEVID_CMD   0x90
+#define BLOCK_ERASE_CONFIRM_CMD  0xd0
+#define READ_ARRAY_CMD   0xff
+#define CLEARED_ARRAY_STATUS 0x00
+
+/* based on QemuFlashDetected (QemuFlashFvbServicesRuntimeDxe) */
+UINT32
+VirtHstiQemuFirmwareFlashCheck (
+  UINT32  Address
+  )
+{
+  volatile UINT8  *Ptr;
+
+  UINTN  Offset;
+  UINT8  OriginalUint8;
+  UINT8  ProbeUint8;
+
+  for (Offset = 0; Offset < EFI_PAGE_SIZE; Offset++) {
+Ptr= (UINT8 *)(UINTN)(Address + Offset);
+ProbeUint8 = *Ptr;
+if ((ProbeUint8 != CLEAR_STATUS_CMD) &&
+(ProbeUint8 != READ_STATUS_CMD) &&
+(ProbeUint8 != CLEARED_ARRAY_STATUS))
+{
+  break;
+}
+  }
+
+  if (Offset >= EFI_PAGE_SIZE) {
+DEBUG ((DEBUG_INFO, "%a: check failed\n", __func__));
+return QEMU_FIRMWARE_FLASH_UNKNOWN;
+  }
+
+  OriginalUint8 = *Ptr;
+  *Ptr  = CLEAR_STATUS_CMD;
+  ProbeUint8= *Ptr;
+  if ((OriginalUint8 != CLEAR_STATUS_CMD) &&
+  (ProbeUint8 == CLEAR_STATUS_CMD))
+  {
+*Ptr = OriginalUint8;
+DEBUG ((DEBUG_INFO, "%a: %p behaves as RAM\n", __func__, Ptr));
+return QEMU_FIRMWARE_FLASH_IS_RAM;
+  }
+
+  *Ptr   = READ_STATUS_CMD;
+  ProbeUint8 = *Ptr;
+  if (ProbeUint8 == OriginalUint8) {
+DEBUG ((DEBUG_INFO, "%a: %p behaves as ROM\n", __func__, Ptr));
+return QEMU_FIRMWARE_FLASH_IS_ROM;
+  }
+
+  if (ProbeUint8 == READ_STATUS_CMD) {
+*Ptr = OriginalUint8;
+DEBUG ((DEBUG_INFO, "%a: %p behaves as RAM\n", __func__, Ptr));
+return QEMU_FIRMWARE_FLASH_IS_RAM;
+  }
+
+  if (ProbeUint8 == CLEARED_ARRAY_STATUS) {
+*Ptr   = WRITE_BYTE_CMD;
+*Ptr   = OriginalUint8;
+*Ptr   = READ_STATUS_CMD;
+ProbeUint8 = *Ptr;
+*Ptr   = READ_ARRAY_CMD;
+if (ProbeUint8 & 0x10 /* programming error */) {
+  DEBUG ((DEBUG_INFO, "%a: %p behaves as FLASH, write-protected\n", 
__func__, Ptr));
+  return QEMU_FIRMWARE_FLASH_READ_ONLY;
+} else {
+  DEBUG ((DEBUG_INFO, "%a: %p behaves as FLASH, writable\n", __func__, 
Ptr));
+  return QEMU_FIRMWARE_FLASH_WRITABLE;
+}
+  }
+
+  DEBUG ((DEBUG_INFO, "%a: check failed\n", __func__));
+  return QEMU_FIRMWARE_FLASH_UNKNOWN;
+}
diff --git a/OvmfPkg/VirtHstiDxe/QemuQ35.c b/OvmfPkg/VirtHstiDxe/QemuQ35.c
index 75e9731b4a52..203122627d2d 100644
--- a/OvmfPkg/VirtHstiDxe/QemuQ35.c
+++ b/OvmfPkg/VirtHstiDxe/QemuQ35.c
@@ -29,6 +29,7 @@ VirtHstiQemuQ35Init (
 {
   if (FeaturePcdGet (PcdSmmSmramRequire)) {
 VirtHstiSetSupported (&mHstiQ35, 0, VIRT_HSTI_BYTE0_Q35_SMM_SMRAM_LOCK);
+VirtHstiSetSupported (&mHstiQ35, 0, 
VIRT_HSTI_BYTE0_

[edk2-devel] [PATCH 0/4] OvmfPkg: Add VirtHstiDxe driver

2024-03-22 Thread Gerd Hoffmann



Gerd Hoffmann (2):
  OvmfPkg/VirtHstiDxe: add varstore flash check
  OvmfPkg/VirtHstiDxe: add code flash check

Konstantin Kostiuk (2):
  OvmfPkg: Add VirtHstiDxe driver
  OvmfPkg: Add VirtHstiDxe to OVMF firmware build

 OvmfPkg/OvmfPkgIa32.dsc |   2 +
 OvmfPkg/OvmfPkgIa32X64.dsc  |   2 +
 OvmfPkg/OvmfPkgX64.dsc  |   2 +
 OvmfPkg/OvmfPkgIa32.fdf |   1 +
 OvmfPkg/OvmfPkgIa32X64.fdf  |   1 +
 OvmfPkg/OvmfPkgX64.fdf  |   1 +
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf |  56 +
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.h   |  94 +++
 OvmfPkg/VirtHstiDxe/Flash.c |  90 +++
 OvmfPkg/VirtHstiDxe/QemuCommon.c|  36 ++
 OvmfPkg/VirtHstiDxe/QemuPC.c|  38 ++
 OvmfPkg/VirtHstiDxe/QemuQ35.c   |  71 
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.c   | 173 
 13 files changed, 567 insertions(+)
 create mode 100644 OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
 create mode 100644 OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
 create mode 100644 OvmfPkg/VirtHstiDxe/Flash.c
 create mode 100644 OvmfPkg/VirtHstiDxe/QemuCommon.c
 create mode 100644 OvmfPkg/VirtHstiDxe/QemuPC.c
 create mode 100644 OvmfPkg/VirtHstiDxe/QemuQ35.c
 create mode 100644 OvmfPkg/VirtHstiDxe/VirtHstiDxe.c

-- 
2.44.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117050): https://edk2.groups.io/g/devel/message/117050
Mute This Topic: https://groups.io/mt/105086174/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 4/4] OvmfPkg/VirtHstiDxe: add code flash check

2024-03-22 Thread Gerd Hoffmann
Detects qemu config issue: code pflash is writable.
Checked for both PC and Q35.

Cc: Ard Biesheuvel 
Cc: Jiewen Yao 
Cc: Konstantin Kostiuk 
Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf |  2 ++
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.h   | 13 +++
 OvmfPkg/VirtHstiDxe/QemuCommon.c| 36 +
 OvmfPkg/VirtHstiDxe/VirtHstiDxe.c   |  4 
 4 files changed, 55 insertions(+)
 create mode 100644 OvmfPkg/VirtHstiDxe/QemuCommon.c

diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf 
b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
index 9cb2ed1f0c64..376cd28aeb7e 100644
--- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
+++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.inf
@@ -22,6 +22,7 @@ [Sources]
   VirtHstiDxe.c
   QemuPC.c
   QemuQ35.c
+  QemuCommon.c
   Flash.c
 
 [Packages]
@@ -49,6 +50,7 @@ [FeaturePcd]
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
+  gUefiOvmfPkgTokenSpaceGuid.PcdBfvBase
 
 [Depex]
   TRUE
diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h 
b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
index ca4e376582ad..b915f5cdf5ac 100644
--- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
+++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.h
@@ -8,6 +8,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 
 #define VIRT_HSTI_BYTE0_Q35_SMM_SMRAM_LOCK BIT0
 #define VIRT_HSTI_BYTE0_Q35_SMM_SECURE_VARS_FLASH  BIT1
+#define VIRT_HSTI_BYTE0_READONLY_CODE_FLASHBIT2
 
 typedef struct {
   // ADAPTER_INFO_PLATFORM_SECURITY
@@ -67,6 +68,18 @@ VirtHstiQemuPCVerify (
   VOID
   );
 
+/* QemuCommon.c */
+
+VOID
+VirtHstiQemuCommonInit (
+  VIRT_ADAPTER_INFO_PLATFORM_SECURITY  *VirtHsti
+  );
+
+VOID
+VirtHstiQemuCommonVerify (
+  VOID
+  );
+
 /* Flash.c */
 
 #define QEMU_FIRMWARE_FLASH_UNKNOWN0
diff --git a/OvmfPkg/VirtHstiDxe/QemuCommon.c b/OvmfPkg/VirtHstiDxe/QemuCommon.c
new file mode 100644
index ..4ab3fe2d6e63
--- /dev/null
+++ b/OvmfPkg/VirtHstiDxe/QemuCommon.c
@@ -0,0 +1,36 @@
+/** @file
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+
+#include "VirtHstiDxe.h"
+
+VOID
+VirtHstiQemuCommonInit (
+  VIRT_ADAPTER_INFO_PLATFORM_SECURITY  *VirtHsti
+  )
+{
+  VirtHstiSetSupported (VirtHsti, 0, VIRT_HSTI_BYTE0_READONLY_CODE_FLASH);
+}
+
+VOID
+VirtHstiQemuCommonVerify (
+  VOID
+  )
+{
+  CHAR16  *ErrorMsg;
+
+  switch (VirtHstiQemuFirmwareFlashCheck (PcdGet32 (PcdBfvBase))) {
+case QEMU_FIRMWARE_FLASH_WRITABLE:
+  ErrorMsg = L"qemu code pflash is writable";
+  break;
+default:
+  ErrorMsg = NULL;
+  }
+
+  VirtHstiTestResult (ErrorMsg, 0, VIRT_HSTI_BYTE0_READONLY_CODE_FLASH);
+}
diff --git a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c 
b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c
index 74e5e6bd9d4f..b6e53a1219d1 100644
--- a/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c
+++ b/OvmfPkg/VirtHstiDxe/VirtHstiDxe.c
@@ -104,9 +104,11 @@ VirtHstiOnReadyToBoot (
   switch (VirtHstiGetHostBridgeDevId ()) {
 case INTEL_82441_DEVICE_ID:
   VirtHstiQemuPCVerify ();
+  VirtHstiQemuCommonVerify ();
   break;
 case INTEL_Q35_MCH_DEVICE_ID:
   VirtHstiQemuQ35Verify ();
+  VirtHstiQemuCommonVerify ();
   break;
 default:
   ASSERT (FALSE);
@@ -142,9 +144,11 @@ VirtHstiDxeEntrypoint (
   switch (DevId) {
 case INTEL_82441_DEVICE_ID:
   VirtHsti = VirtHstiQemuPCInit ();
+  VirtHstiQemuCommonInit (VirtHsti);
   break;
 case INTEL_Q35_MCH_DEVICE_ID:
   VirtHsti = VirtHstiQemuQ35Init ();
+  VirtHstiQemuCommonInit (VirtHsti);
   break;
 default:
   DEBUG ((DEBUG_INFO, "%a: unknown platform (0x%x)\n", __func__, DevId));
-- 
2.44.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117051): https://edk2.groups.io/g/devel/message/117051
Mute This Topic: https://groups.io/mt/105086175/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-redfish-client][PATCH V5 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Set SettingsObject URI in @Redfish.Settings resource as the config
language which is the same as the config language of parent URI
that mandates @Redfish.Settings.
With this, we can find the config language of the properties in
SettingsObject URI.

Signed-off-by: Abner Chang 
Cc: Igor Kulchytskyy 
Co-authored-by: Nickle Wang 
---
 .../Library/RedfishFeatureUtilityLib.h| 17 
 .../RedfishFeatureUtilityLib.c| 89 ---
 .../RedfishConfigLangMapDxe.c | 15 +++-
 3 files changed, 104 insertions(+), 17 deletions(-)

diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h 
b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
index ba9ea01501..3c5f248eb7 100644
--- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
+++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
@@ -369,6 +369,23 @@ RedfishSetRedfishUri (
   INEFI_STRING  Uri
   );
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
+  @retval  EFI_SUCCESSRedfish uri is saved
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  );
+
 /**
 
   Get the property name by given Configure Language.
diff --git 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
index cc2b37b796..dda80c4608 100644
--- 
a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
+++ 
b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.c
@@ -2082,7 +2082,6 @@ GetConfigureLang (
   EFI_STRING  ResultStr;
   EFI_STRING  UnicodeUri;
   EFI_STATUS  Status;
-  EFI_STRING  StrFound;
 
   if (IS_EMPTY_STRING (Uri)) {
 return NULL;
@@ -2101,18 +2100,6 @@ GetConfigureLang (
   }
 
   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-  if (ConfigLang == NULL) {
-//
-// @Redfish.Settings share the same schema as its parent.
-// Remove "Settings" and try again.
-//
-StrFound = StrStr (UnicodeUri, L"/Settings");
-if (StrFound != NULL) {
-  StrFound[0] = L'\0';
-  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI, try: %s\n", 
__func__, UnicodeUri));
-  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
-}
-  }
 
   FreePool (UnicodeUri);
 
@@ -2172,6 +2159,64 @@ RedfishSetRedfishUri (
   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol, ConfigLang, Uri);
 }
 
+/**
+
+  Save Redfish SettingsObject URI in database for further use.
+
+  @param[in]ParentUri Parent URI of @Redfish.Settings property.
+  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
+
+  @retval  EFI_INVALID_PARAMETER  ParentUri or SettingObjectUri is NULL.
+  @retval  EFI_NOT_FOUND  Config language for ParentUri is not found.
+  @retval  EFI_SUCCESSRedfish URI is saved with corresponding
+  config language.
+
+**/
+EFI_STATUS
+SetRedfishSettingsObjectsUri (
+  IN EFI_STRING  ParentUri,
+  IN EFI_STRING  SettingObjectUri
+  )
+{
+  EFI_STATUS  Status;
+  EFI_STRING  ConfigLang;
+
+  if ((ParentUri == NULL) || (SettingObjectUri == NULL)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Check if the SettingsObject URI already in the database.
+  //
+  Status = EFI_SUCCESS;
+  ConfigLang = RedfishGetConfigLanguage (SettingObjectUri);
+  if (ConfigLang == NULL) {
+//
+// No config language of SettingsObject URI is found.
+// Get the config language of parent URI because the data model of
+// SettingsObject URI resource is the same as the data model of parent URI.
+//
+ConfigLang = RedfishGetConfigLanguage (ParentUri);
+if (ConfigLang == NULL) {
+  DEBUG ((DEBUG_ERROR, "%a: Failed to get the config language of parent 
URI that mandates SettingsObject - %s.\n", __func__, ParentUri));
+  Status = EFI_NOT_FOUND;
+} else {
+
+  // Set the config language of settings URI using parent's URI config 
language.
+  Status = RedfishSetRedfishUri (ConfigLang, SettingObjectUri);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a: Fails to set the config language of 
SettingsObject - %s.\n", __func__, SettingObjectUri));
+  } else {
+DEBUG ((DEBUG_INFO, "%a: Set the config language of SettingsObject - 
%s: SUCCESS.\n", __func__, SettingObjectUri));
+  }
+  FreePool (ConfigLang); // Free the ConfigLang of parent URI.
+}
+  } else {
+FreePool (ConfigLang); // Free the ConfigLang of SettingObject URI.
+  }
+  return Status;
+}
+
 /**
 
   Get @odata.id from give HTTP payload. It's call responsibility to release 
returned buffe

[edk2-devel] [edk2-redfish-client][PATCH V5 2/2] RedfishClientPkg/FeatureDriver: Use SetRedfishSettingsObjectsUri

2024-03-22 Thread Chang, Abner via groups.io
From: Abner Chang 

Use SetRedfishSettingsObjectsUri to set the config language
for SettingsObject URI.

Signed-off-by: Abner Chang 
Co-authored-by: Nickle Wang 
Cc: Igor Kulchytskyy 
---
 RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c  | 1 +
 RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c  | 1 +
 .../Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c  | 1 +
 .../Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c   | 1 +
 RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c  | 1 +
 5 files changed, 5 insertions(+)

diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c 
b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
index 1ca920640a..bb64ef8625 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
@@ -141,6 +141,7 @@ RedfishResourceConsumeResource (
 );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c 
b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
index 7501c1a975..5a66fe59e0 100644
--- a/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
+++ b/RedfishClientPkg/Features/BootOption/v1_0_4/Dxe/BootOptionDxe.c
@@ -130,6 +130,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_BOOT_OPTION_DEBUG_TRACE, "%a: @Redfish.Settings found: 
%s\n", __func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
index 1235760a18..a0c71212b3 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_13_0/Dxe/ComputerSystemDxe.c
@@ -133,6 +133,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git 
a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c 
b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
index 5207362dac..494bf59dfc 100644
--- a/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
+++ b/RedfishClientPkg/Features/ComputerSystem/v1_5_0/Dxe/ComputerSystemDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
diff --git a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c 
b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
index c4a363cdf5..f2c0a7735b 100644
--- a/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
+++ b/RedfishClientPkg/Features/Memory/V1_7_1/Dxe/MemoryDxe.c
@@ -134,6 +134,7 @@ RedfishResourceConsumeResource (
  );
   if (!EFI_ERROR (Status)) {
 DEBUG ((REDFISH_DEBUG_TRACE, "%a: @Redfish.Settings found: %s\n", 
__func__, PendingSettingUri));
+SetRedfishSettingsObjectsUri (Private->Uri, PendingSettingUri);
 Private->Uri = PendingSettingUri;
 ExpectedResponse = &PendingSettingResponse;
   } else {
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117053): https://edk2.groups.io/g/devel/message/117053
Mute This Topic: https://groups.io/mt/105086470/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2] RedfishClientPkg: Set SettingsObject URI as the config language

2024-03-22 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Ah I got your point. I reviewed that function and sent the V5.
Thanks
Abner


> -Original Message-
> From: Mike Maslenkin 
> Sent: Friday, March 22, 2024 6:08 PM
> To: Chang, Abner 
> Cc: devel@edk2.groups.io; Igor Kulchytskyy ; Nickle Wang
> 
> Subject: Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2]
> RedfishClientPkg: Set SettingsObject URI as the config language
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
>  Hi Abner,
>
> Sorry if I wasn't clear.
> I meant in this function including the success path.
> RedfishSetRedfishUri->..->NewConfigLangMapRecord() creates a copy of
> this string, so it should be freed in this function.
>
> Regards,
> Mike.
>
>
> On Fri, Mar 22, 2024 at 12:58 PM Chang, Abner 
> wrote:
> >
> > [AMD Official Use Only - General]
> >
> > Hi Mike,
> > Thanks for catching this, V4 sent.
> >
> > Abner
> >
> > > -Original Message-
> > > From: M M 
> > > Sent: Friday, March 22, 2024 5:20 PM
> > > To: devel@edk2.groups.io; Chang, Abner 
> > > Cc: Igor Kulchytskyy ; Nickle Wang
> 
> > > Subject: Re: [edk2-devel] [edk2-redfish-client][PATCH V3 1/2]
> > > RedfishClientPkg: Set SettingsObject URI as the config language
> > >
> > > Caution: This message originated from an External Source. Use proper
> caution
> > > when opening attachments, clicking links, or responding.
> > >
> > >
> > > Hi Abner,
> > >
> > > > On 22. 3. 2024., at 12:09, Chang, Abner via groups.io
> > >  wrote:
> > > >
> > > > From: Abner Chang 
> > > >
> > > > Set SettingsObject URI in @Redfish.Settings resource as the config
> > > > language which is the same as the config language of parent URI
> > > > that mandates @Redfish.Settings.
> > > > With this, we can find the config language of the properties in
> > > > SettingsObject URI.
> > > >
> > > > Signed-off-by: Abner Chang 
> > > > Cc: Igor Kulchytskyy 
> > > > Co-authored-by: Nickle Wang 
> > > > ---
> > > > .../Library/RedfishFeatureUtilityLib.h| 17 
> > > > .../RedfishFeatureUtilityLib.c| 86 ---
> > > > .../RedfishConfigLangMapDxe.c | 15 +++-
> > > > 3 files changed, 101 insertions(+), 17 deletions(-)
> > > >
> > > > diff --git a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > > b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > > > index ba9ea01501..3c5f248eb7 100644
> > > > --- a/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > > > +++ b/RedfishClientPkg/Include/Library/RedfishFeatureUtilityLib.h
> > > > @@ -369,6 +369,23 @@ RedfishSetRedfishUri (
> > > >   INEFI_STRING  Uri
> > > >   );
> > > >
> > > > +/**
> > > > +
> > > > +  Save Redfish SettingsObject URI in database for further use.
> > > > +
> > > > +  @param[in]ParentUri Parent URI of @Redfish.Settings 
> > > > property.
> > > > +  @param[in]SettingObjectUri  Redfish SettingsObject Uri to save.
> > > > +
> > > > +  @retval  EFI_INVALID_PARAMETER  SystemId is NULL or EMPTY
> > > > +  @retval  EFI_SUCCESSRedfish uri is saved
> > > > +
> > > > +**/
> > > > +EFI_STATUS
> > > > +SetRedfishSettingsObjectsUri (
> > > > +  IN EFI_STRING  ParentUri,
> > > > +  IN EFI_STRING  SettingObjectUri
> > > > +  );
> > > > +
> > > > /**
> > > >
> > > >   Get the property name by given Configure Language.
> > > > diff --git
> > >
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > > c
> > >
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > > c
> > > > index cc2b37b796..c37bf85310 100644
> > > > ---
> > >
> a/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > > c
> > > > +++
> > >
> b/RedfishClientPkg/Library/RedfishFeatureUtilityLib/RedfishFeatureUtilityLib.
> > > c
> > > > @@ -2082,7 +2082,6 @@ GetConfigureLang (
> > > >   EFI_STRING  ResultStr;
> > > >   EFI_STRING  UnicodeUri;
> > > >   EFI_STATUS  Status;
> > > > -  EFI_STRING  StrFound;
> > > >
> > > >   if (IS_EMPTY_STRING (Uri)) {
> > > > return NULL;
> > > > @@ -2101,18 +2100,6 @@ GetConfigureLang (
> > > >   }
> > > >
> > > >   ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> > > > -  if (ConfigLang == NULL) {
> > > > -//
> > > > -// @Redfish.Settings share the same schema as its parent.
> > > > -// Remove "Settings" and try again.
> > > > -//
> > > > -StrFound = StrStr (UnicodeUri, L"/Settings");
> > > > -if (StrFound != NULL) {
> > > > -  StrFound[0] = L'\0';
> > > > -  DEBUG ((REDFISH_DEBUG_TRACE, "%a: \"Settings\" found in URI,
> try:
> > > %s\n", __func__, UnicodeUri));
> > > > -  ConfigLang = RedfishGetConfigLanguage (UnicodeUri);
> > > > -}
> > > > -  }
> > > >
> > > >   FreePool (UnicodeUri);
> > > >
> > > > @@ -2172,6 +2159,61 @@ RedfishSetRedfishUri (
> > > >   return mConfigLangMapProtocol->Set (mConfigLangMapProtocol,
> > > Config

Re: [edk2-devel] [RFC PATCH] OvmfPkg/SecurityPkg: Add build option for coexistance of vTPM and RTMR.

2024-03-22 Thread Dionna Glaze via groups.io
On Fri, Mar 22, 2024 at 1:52 AM Gerd Hoffmann  wrote:
>
> On Fri, Mar 22, 2024 at 02:39:20AM +, Yao, Jiewen wrote:
> > Please aware that this option will cause potential security risk.
> >
> > In case that any the guest component only knows one of vTPM or RTMR,
> > and only extends one of vTPM or RTMR, but the other one only verifies
> > the other, then the chain of trust is broken.  This solution is secure
> > if and only if all guest components aware of coexistence, and can
> > ensure all measurements are extended to both vTPM and RTMR.  But I am
> > not sure if all guest components are ready today.
>
> As far I know (it's been a while I looked at those patches) shim.efi and
> grub.efi have support for EFI_CC_MEASUREMENT_PROTOCOL, but use the same
> logic we have in DxeTpm2MeasureBootLib, i.e. they will not measure to
> both RTMR and vTPM.

Shim will measure into CC and then continue to measure into TPM
https://github.com/rhboot/shim/blob/126a07ebc30bbd203b6966465b058da741b2654b/tpm.c#L164

GRUB2 has the same behavior. We can at least get coexistence
supporting the current boot integrity strategy that Confidential Space
is using, which is to depend on a dmverity initramfs whose root hash
is in the kernel_cmdline, and a Linux kernel built with LOADPIN. The
changes to Linux are proposed but not accepted precisely due to this
conversation we're having now.
I recall describing this to another CSP engineer at an IETF meeting
and they claimed they used the same approach, but I can't remember if
that was Oracle or another company.

>
> Looking at systemd-boot I see it will likewise not measure to both RTMR
> and vTPM, but with reversed priority (use vTPM not RTMR in case both are
> present).
>

Interesting. Thanks for this report. We'll push for the changed
semantics here if the spec is indeed changed, and request partner
distros in the CCC to include the updated systemd-boot.
I think that since the current boot integrity story stops at PCR9, we
have time to update this component before the attestation method
evolves to support a less special-purpose system composition.

> Linux kernel appears to not have EFI_CC_MEASUREMENT_PROTOCOL support.
>
> > Since this option caused a potential risk / misuse breaking the chain
> > of trust, I recommend we have at least one more company to endorse the
> > runtime co-existence of vTPM and RTMR.  Also, I would like to hear the
> > opinions from other companies.
>
> Rumors say intel is working on coconut-svsm support for tdx.  That will
> most likely allow to use a vTPM with tdx even without depending on the
> virtualization host or cloud hyperscaler providing one.  We will see VMs
> with both RTMR and vTPM and surely need a strategy how guests should
> deal with that situation, consistent across the whole boot stack and
> not every component doing something different.
>

An ephemeral TPM that Coconut-svsm offers is qualitatively different
than the persistent TPMs in CSPs today. Users of Confidential VMs all
have different threat models that allow for trusting a CSP-managed
vTPM for sealing keys but not for trusting unencrypted data in use.
The boot stack attestation story will not be fully resolved for a long
while, and a smooth transition is better than a jarring one.

> Given that the vTPM might be provided by the hypervisor and thus not be
> part of the TCB I can see that guests might want use both vTPM and RTMR.
> So, yes, for that case coexistance makes sense.  I'm not convinced it is
> a good idea to make that a compile time option though.  That will not
> help to promote a consistent story ...
>

I agree, but it does mean we have to change the event log composition
to describe the configured measurement services like described above.
I think a static Pcd is okay to begin with. The idea for tracking
these qualities is through software supply chain endorsements.
Eventually that would look like the proposed in-toto's SCAI [1] but
until then we'd have a bespoke format that we document and integrate
with in an attestation verification service.

[1] https://arxiv.org/pdf/2210.05813.pdf

-- 
-Dionna Glaze, PhD (she/her)


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117055): https://edk2.groups.io/g/devel/message/117055
Mute This Topic: https://groups.io/mt/105070442/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2-platforms v9 0/4] get rid of DeviceTree from SbsaQemu

2024-03-22 Thread Marcin Juszkiewicz
We want to stop parsing DeviceTree to gather hardware information.

Instead we ask TF-A for those details using SMC calls. On real hardware
platform it could be asking on-board Embedded Controller.

Hardware information (CPU, Memory) is now in SbsaQemuHardwareInfoLib
together with new code for handling SMC stuff. There is no DT parsing
anywhere.

TF-A part is merged already (and we have it in edk2-non-osi):
https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/25707

Patch 4 needs work to pass MemInfo as reference.

Signed-off-by: Marcin Juszkiewicz 
---
Changes in v9:
- recreated 3rd patch to drop all traces of Device Tree use
- Link to v8: 
https://openfw.io/edk2-devel/20240320-no-dt-for-cpu-v8-0-599ba9986...@linaro.org

Changes in v8:
- added HardwareInfoLib library class
- created SbsaQemuHardwareInfoLib as HardwareInfoLib
- dropped SbsaQemu from functions (to keep HardwareInfoLib class generic)
- Link to v7: 
https://openfw.io/edk2-devel/20240319-no-dt-for-cpu-v7-0-ac0a57a23...@linaro.org

Changes in v7:
- dropped CoreCount Pcd - code calls SbsaQemuGetCpuCount() instead
- dropped DT fallbacks - we have up-to-date TF-A in edk2-non-osi
- system shutdowns when there is no cpu or memory information
- SbsaQemuHardwareInfoLib debug calls show function names
- Link to v6: 
https://openfw.io/edk2-devel/20240306-no-dt-for-cpu-v6-0-acd8727a1...@linaro.org

Changes in v6 (Marcin Juszkiewicz):
- patch 5 now shutdowns system in case of no CPU information

Changes in v5 (Xiong Yining):
- added missing patch
- Link to v5: 
https://openfw.io/edk2-devel/20240131132400.3022662-1-xiongyining1...@phytium.com.cn/

Changes in v4 (Xiong Yining):
- patch 6 add the support for getting the hardware information of memory via 
SMC calls.
- patch 7 add the callback of DeviceTree when SMC calls defined on patch 6 
failled.
- replace FdtHelperGetMpidr() with SbsaQemuGetMpidr() on patch 4 to compile 
successfully.
- Link to v4: 
https://openfw.io/edk2-devel/20240131100027.2538549-1-xiongyining1...@phytium.com.cn/

Changes in v3:
- added SMC_SIP_CALL_SUCCESS
- on SMC call fail tell that SMC call failed instead of blaming TF-A
- hang when there is no cpu information (TODO: shutdown instead)
- Link to v3: 
https://openfw.io/edk2-devel/20240124-no-dt-for-cpu-v3-0-5375fcf09...@linaro.org/

---
Marcin Juszkiewicz (3):
  Platform/SbsaQemu: add SbsaQemuHardwareInfoLib
  Platform/SbsaQemu: use SbsaQemuHardwareInfoLib for cpu information
  Platform/SbsaQemu: drop use of DeviceTree

Xiong Yining (1):
  Platform/SbsaQemu: get the information of memory via SMC calls

 Silicon/Qemu/SbsaQemu/SbsaQemu.dec  |   3 +-
 Platform/Qemu/SbsaQemu/SbsaQemu.dsc |   9 +-
 Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf|   6 +-
 .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf |   5 +-
 .../SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf  |  33 -
 .../SbsaQemuHardwareInfoLib.inf |  29 
 .../SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf|   5 +-
 .../SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h |  19 ++-
 .../Qemu/SbsaQemu/Include/Library/FdtHelperLib.h|  36 -
 .../Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h |  73 ++
 Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.c  |  11 +-
 .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c   |  21 +--
 .../SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c   |   2 -
 .../SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c|  98 -
 .../SbsaQemuHardwareInfoLib.c   | 146 
 .../Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c |  54 ++--
 16 files changed, 298 insertions(+), 252 deletions(-)
---
base-commit: 80ee8b861edb6a8b02a100f63bbb435499f8741a
change-id: 20240115-no-dt-for-cpu-2c511393df93

Best regards,
-- 
Marcin Juszkiewicz 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117056): https://edk2.groups.io/g/devel/message/117056
Mute This Topic: https://groups.io/mt/105088434/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH edk2-platforms v9 1/4] Platform/SbsaQemu: add SbsaQemuHardwareInfoLib

2024-03-22 Thread Marcin Juszkiewicz
This library provides functions to check for hardware information.
For now it covers CPU ones:

- amount of cpu cores
- MPIDR value for cpu core
- NUMA node id for cpu core

Values are read from TF-A using platform specific SMC calls.

Signed-off-by: Marcin Juszkiewicz 
---
 Silicon/Qemu/SbsaQemu/SbsaQemu.dec   |  2 +
 Platform/Qemu/SbsaQemu/SbsaQemu.dsc  |  3 +-
 .../SbsaQemuHardwareInfoLib.inf  | 29 ++
 .../SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h  | 17 +++-
 .../Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h  | 45 +
 .../SbsaQemuHardwareInfoLib.c| 96 
 6 files changed, 187 insertions(+), 5 deletions(-)

diff --git a/Silicon/Qemu/SbsaQemu/SbsaQemu.dec 
b/Silicon/Qemu/SbsaQemu/SbsaQemu.dec
index 913d1d75ef29..427ff8b31aac 100644
--- a/Silicon/Qemu/SbsaQemu/SbsaQemu.dec
+++ b/Silicon/Qemu/SbsaQemu/SbsaQemu.dec
@@ -12,6 +12,8 @@ [Defines]
   PACKAGE_GUID   = 8db32c5a-2821-43e2-b4ac-bc148e2b0b05
   PACKAGE_VERSION= 0.1
 
+[LibraryClasses]
+HardwareInfoLib|Include/Library/HardwareInfoLib.h
 

 #
 # Include Section - list of Include Paths that are provided by this package.
diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc 
b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc
index 378600050df9..3c3d2449bff4 100644
--- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc
+++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc
@@ -1,6 +1,6 @@
 #
 #  Copyright (c) 2021, NUVIA Inc. All rights reserved.
-#  Copyright (c) 2019, Linaro Limited. All rights reserved.
+#  Copyright (c) 2019-2024, Linaro Ltd. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -128,6 +128,7 @@ [LibraryClasses.common]
 
   FdtHelperLib|Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf
   OemMiscLib|Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf
+  
HardwareInfoLib|Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
 
   # Debug Support
   
PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf
diff --git 
a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
new file mode 100644
index ..2acb2a1e7c76
--- /dev/null
+++ 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
@@ -0,0 +1,29 @@
+#/* @file
+#
+#  Copyright (c) 2024, Linaro Ltd. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#*/
+
+[Defines]
+  INF_VERSION= 0x0001001c
+  BASE_NAME  = SbsaQemuHardwareInfoLib
+  FILE_GUID  = 6454006f-6502-46e2-9be4-4bba8d4b29fb
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = HardwareInfoLib
+
+[Sources]
+  SbsaQemuHardwareInfoLib.c
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  Silicon/Qemu/SbsaQemu/SbsaQemu.dec
+
+[LibraryClasses]
+  ArmSmcLib
+  ResetSystemLib
diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h 
b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h
index 7934875e4aba..2317c1f0ae69 100644
--- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h
+++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h
@@ -1,6 +1,6 @@
 /** @file
 *
-*  Copyright (c) 2023, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2023-2024, Linaro Ltd. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -11,8 +11,17 @@
 
 #include 
 
-#define SIP_SVC_VERSION  SMC_SIP_FUNCTION_ID(1)
-#define SIP_SVC_GET_GIC  SMC_SIP_FUNCTION_ID(100)
-#define SIP_SVC_GET_GIC_ITS  SMC_SIP_FUNCTION_ID(101)
+#define SIP_SVC_VERSIONSMC_SIP_FUNCTION_ID(1)
+#define SIP_SVC_GET_GICSMC_SIP_FUNCTION_ID(100)
+#define SIP_SVC_GET_GIC_ITSSMC_SIP_FUNCTION_ID(101)
+#define SIP_SVC_GET_CPU_COUNT  SMC_SIP_FUNCTION_ID(200)
+#define SIP_SVC_GET_CPU_NODE   SMC_SIP_FUNCTION_ID(201)
+
+/*
+ *  SMCC does not define return codes for SiP functions.
+ *  We use Architecture ones then.
+ */
+
+#define SMC_SIP_CALL_SUCCESS  SMC_ARCH_CALL_SUCCESS
 
 #endif /* SBSA_QEMU_SMC_H_ */
diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h 
b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
new file mode 100644
index ..9c7281f123d2
--- /dev/null
+++ b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
@@ -0,0 +1,45 @@
+/** @file
+*
+*  Copyright (c) 2024, Linaro Ltd. All rights reserved.
+*
+*  SPDX-License-Identifier: BSD-2-Clause-Patent
+*
+**/
+
+#ifndef HARDWARE_INFO_LIB
+#define HARDWARE_INFO_LIB
+
+/**
+  Get CPU count from information passed by Qemu.
+
+**/
+UINT32
+GetCpuCount (
+  VOID
+  );
+
+/**
+

[edk2-devel] [PATCH edk2-platforms v9 2/4] Platform/SbsaQemu: use SbsaQemuHardwareInfoLib for cpu information

2024-03-22 Thread Marcin Juszkiewicz
We have SbsaQemuHardwareInfoLib to ask for hardware details. No need to
parse DeviceTree anymore.

Signed-off-by: Marcin Juszkiewicz 
---
 Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf |  6 ++
 .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf  |  5 ++---
 .../SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf |  4 ++--
 Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.c   | 11 +-
 .../Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c| 21 +++-
 5 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf 
b/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf
index a34f54d431d4..f959d8e0e4ee 100644
--- a/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf
+++ b/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf
@@ -3,7 +3,7 @@
 #
 #Copyright (c) 2021, NUVIA Inc. All rights reserved.
 #Copyright (c) 2018, Hisilicon Limited. All rights reserved.
-#Copyright (c) 2018, Linaro Limited. All rights reserved.
+#Copyright (c) 2018-2024, Linaro Ltd. All rights reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -29,8 +29,7 @@ [Packages]
 
 [LibraryClasses]
   BaseMemoryLib
-  FdtLib
-  FdtHelperLib
+  HardwareInfoLib
   IoLib
   PcdLib
 
@@ -40,7 +39,6 @@ [Guids]
 [Pcd]
   gArmTokenSpaceGuid.PcdEmbeddedControllerFirmwareRelease
   gArmTokenSpaceGuid.PcdSystemBiosRelease
-  gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress
 
   gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdSystemManufacturer
   gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdSystemSerialNumber
diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf 
b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf
index 291743b19115..727c8e82d16e 100644
--- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf
+++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.inf
@@ -1,7 +1,7 @@
 ## @file
 #  This driver modifies ACPI tables for the Qemu SBSA platform
 #
-#  Copyright (c) 2020, Linaro Ltd. All rights reserved.
+#  Copyright (c) 2020-2024, Linaro Ltd. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -35,7 +35,7 @@ [LibraryClasses]
   BaseLib
   DebugLib
   DxeServicesLib
-  FdtHelperLib
+  HardwareInfoLib
   PcdLib
   PrintLib
   UefiDriverEntryPoint
@@ -44,7 +44,6 @@ [LibraryClasses]
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile
-  gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdCoreCount
   gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdClusterCount
 
   gArmTokenSpaceGuid.PcdGicDistributorBase
diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf
index c067a80cc715..07e6bc4e9b11 100644
--- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf
+++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf
@@ -1,6 +1,6 @@
 #/* @file
 #
-#  Copyright (c) 2019, Linaro Limited. All rights reserved.
+#  Copyright (c) 2019-2024, Linaro Limited. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -32,9 +32,9 @@ [LibraryClasses]
   ArmLib
   BaseMemoryLib
   DebugLib
-  FdtLib
   MemoryAllocationLib
   PcdLib
+  SbsaQemuHardwareInfoLib
 
 [Pcd]
   gArmTokenSpaceGuid.PcdSystemMemoryBase
diff --git a/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.c 
b/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.c
index c38f2851904f..854f6f4072d5 100644
--- a/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.c
+++ b/Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.c
@@ -2,7 +2,7 @@
 *  OemMiscLib.c
 *
 *  Copyright (c) 2021, NUVIA Inc. All rights reserved.
-*  Copyright (c) 2020, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2020-2024, Linaro Ltd. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -12,14 +12,13 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
-#include 
 
 /** Returns whether the specified processor is present or not.
 
@@ -33,7 +32,7 @@ OemIsProcessorPresent (
   UINTN ProcessorIndex
   )
 {
-  if (ProcessorIndex < FdtHelperCountCpus ()) {
+  if (ProcessorIndex < GetCpuCount ()) {
 return TRUE;
   }
 
@@ -76,7 +75,7 @@ OemGetProcessorInformation (
 {
   UINT16 ProcessorCount;
 
-  ProcessorCount = FdtHelperCountCpus ();
+  ProcessorCount = GetCpuCount ();
 
   if (ProcessorIndex < ProcessorCount) {
 ProcessorStatus->Bits.CpuStatus   = 1; // CPU enabled
@@ -121,7 +120,7 @@ OemGetMaxProcessors (
   VOID
   )
 {
-  return FdtHelperCountCpus ();
+  return GetCpuCount ();
 }
 
 /** Gets information about the cache at the specified cache level.
diff --git a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c 
b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c
index 9fb17151d7b8..4ebe2a445344 100644
--- a/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuAcpiDxe/SbsaQemuAcpiDxe.c
+++ b/Silicon/Qemu/SbsaQemu/Drivers/SbsaQemu

[edk2-devel] [PATCH edk2-platforms v9 3/4] Platform/SbsaQemu: drop use of DeviceTree

2024-03-22 Thread Marcin Juszkiewicz
There is no need for EDK2 to know that there is DeviceTree around.
All hardware information is read using functions from
SbsaQemuHardwareInfoLib library.

Signed-off-by: Marcin Juszkiewicz 
---
 Silicon/Qemu/SbsaQemu/SbsaQemu.dec   |  1 -
 Platform/Qemu/SbsaQemu/SbsaQemu.dsc  |  6 --
 .../SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf   | 33 ---
 Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h | 36 ---
 .../SbsaQemuPlatformDxe/SbsaQemuPlatformDxe.c|  2 -
 .../SbsaQemu/Library/FdtHelperLib/FdtHelperLib.c | 98 
 6 files changed, 176 deletions(-)

diff --git a/Silicon/Qemu/SbsaQemu/SbsaQemu.dec 
b/Silicon/Qemu/SbsaQemu/SbsaQemu.dec
index 427ff8b31aac..8f3533800767 100644
--- a/Silicon/Qemu/SbsaQemu/SbsaQemu.dec
+++ b/Silicon/Qemu/SbsaQemu/SbsaQemu.dec
@@ -36,7 +36,6 @@ [PcdsFixedAtBuild.common]
   
gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdPlatformAhciSize|0x1|UINT32|0x0002
   
gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdPlatformXhciBase|0|UINT64|0x0003
   
gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdPlatformXhciSize|0x1|UINT32|0x0004
-  
gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x100|UINT64|0x0005
 
   # PCDs complementing PCIe layout pulled into ACPI tables
   # Limit = Base + Size - 1
diff --git a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc 
b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc
index 3c3d2449bff4..3d748e289b51 100644
--- a/Platform/Qemu/SbsaQemu/SbsaQemu.dsc
+++ b/Platform/Qemu/SbsaQemu/SbsaQemu.dsc
@@ -80,7 +80,6 @@ [LibraryClasses.common]
   FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
   
ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/ImagePropertiesRecordLib.inf
 
-  FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
 
@@ -126,7 +125,6 @@ [LibraryClasses.common]
   # ARM PL011 UART Driver
   PL011UartLib|ArmPlatformPkg/Library/PL011UartLib/PL011UartLib.inf
 
-  FdtHelperLib|Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf
   OemMiscLib|Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.inf
   
HardwareInfoLib|Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.inf
 
@@ -430,9 +428,6 @@ [PcdsFixedAtBuild.common]
   #
   gEmbeddedTokenSpaceGuid.PcdPrePiCpuIoSize|16
 
-  # Initial Device Tree Location
-  gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress|0x100
-
   # Non discoverable devices (AHCI,XHCI)
   gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdPlatformAhciBase|0x6010
   gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdPlatformAhciSize|0x0001
@@ -731,7 +726,6 @@ [Components.common]
   #
   ArmPkg/Universal/Smbios/ProcessorSubClassDxe/ProcessorSubClassDxe.inf
   ArmPkg/Universal/Smbios/SmbiosMiscDxe/SmbiosMiscDxe.inf
-  EmbeddedPkg/Library/FdtLib/FdtLib.inf
   MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
   Silicon/Qemu/SbsaQemu/Drivers/SbsaQemuSmbiosDxe/SbsaQemuSmbiosDxe.inf
 
diff --git a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf 
b/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf
deleted file mode 100644
index 9c059f3e5851..
--- a/Silicon/Qemu/SbsaQemu/Library/FdtHelperLib/FdtHelperLib.inf
+++ /dev/null
@@ -1,33 +0,0 @@
-#/** @file
-#
-#  Component description file for FdtHelperLib module
-#
-#  Copyright (c) 2021, NUVIA Inc. All rights reserved.
-#
-#  SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-#**/
-
-[Defines]
-  INF_VERSION= 1.29
-  BASE_NAME  = FdtHelperLib
-  FILE_GUID  = 34e4396f-c2fc-4f9e-ad58-0f98e99e3875
-  MODULE_TYPE= BASE
-  VERSION_STRING = 1.0
-  LIBRARY_CLASS  = FdtHelperLib
-
-[Sources.common]
-  FdtHelperLib.c
-
-[Packages]
-  EmbeddedPkg/EmbeddedPkg.dec
-  MdePkg/MdePkg.dec
-  Silicon/Qemu/SbsaQemu/SbsaQemu.dec
-
-[LibraryClasses]
-  DebugLib
-  FdtLib
-  PcdLib
-
-[FixedPcd]
-  gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress
diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h 
b/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h
deleted file mode 100644
index ea9159857215..
--- a/Silicon/Qemu/SbsaQemu/Include/Library/FdtHelperLib.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/** @file
-*  FdtHelperLib.h
-*
-*  Copyright (c) 2021, NUVIA Inc. All rights reserved.
-*
-*  SPDX-License-Identifier: BSD-2-Clause-Patent
-*
-**/
-
-#ifndef FDT_HELPER_LIB_
-#define FDT_HELPER_LIB_
-
-/**
-  Get MPIDR for a given cpu from device tree passed by Qemu.
-
-  @param [in]   CpuIdIndex of cpu to retrieve MPIDR value for.
-
-  @retvalMPIDR value of CPU at index 
-**/
-UINT64
-FdtHelperGetMpidr (
-  IN UINTN   CpuId
-  );
-
-/** Walks through the Device Tree created by Qemu and counts the number
- 

[edk2-devel] [PATCH edk2-platforms v9 4/4] Platform/SbsaQemu: get the information of memory via SMC calls

2024-03-22 Thread Marcin Juszkiewicz
From: Xiong Yining 

Provide functions to check for memory information:

- amount of memory nodes
- memory address
- NUMA node id for memory

Values are read from TF-A using platform specific SMC calls.

Signed-off-by: Xiong Yining 
Signed-off-by: Chen Baozi 
Signed-off-by: Marcin Juszkiewicz 
---
 .../SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf |  3 +-
 .../SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h  |  2 +
 .../Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h  | 28 ++
 .../SbsaQemuHardwareInfoLib.c| 50 ++
 .../Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuMem.c  | 54 +---
 5 files changed, 94 insertions(+), 43 deletions(-)

diff --git a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf
index 07e6bc4e9b11..384cbb349200 100644
--- a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf
+++ b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuLib/SbsaQemuLib.inf
@@ -32,14 +32,13 @@ [LibraryClasses]
   ArmLib
   BaseMemoryLib
   DebugLib
+  HardwareInfoLib
   MemoryAllocationLib
   PcdLib
-  SbsaQemuHardwareInfoLib
 
 [Pcd]
   gArmTokenSpaceGuid.PcdSystemMemoryBase
   gArmTokenSpaceGuid.PcdSystemMemorySize
-  gArmVirtSbsaQemuPlatformTokenSpaceGuid.PcdDeviceTreeBaseAddress
 
 [FixedPcd]
   gArmTokenSpaceGuid.PcdFdBaseAddress
diff --git a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h 
b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h
index 2317c1f0ae69..e3092007d27d 100644
--- a/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h
+++ b/Silicon/Qemu/SbsaQemu/Include/IndustryStandard/SbsaQemuSmc.h
@@ -16,6 +16,8 @@
 #define SIP_SVC_GET_GIC_ITSSMC_SIP_FUNCTION_ID(101)
 #define SIP_SVC_GET_CPU_COUNT  SMC_SIP_FUNCTION_ID(200)
 #define SIP_SVC_GET_CPU_NODE   SMC_SIP_FUNCTION_ID(201)
+#define SIP_SVC_GET_MEMORY_NODE_COUNT SMC_SIP_FUNCTION_ID(300)
+#define SIP_SVC_GET_MEMORY_NODE SMC_SIP_FUNCTION_ID(301)
 
 /*
  *  SMCC does not define return codes for SiP functions.
diff --git a/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h 
b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
index 9c7281f123d2..c7d397c590a8 100644
--- a/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
+++ b/Silicon/Qemu/SbsaQemu/Include/Library/HardwareInfoLib.h
@@ -9,6 +9,12 @@
 #ifndef HARDWARE_INFO_LIB
 #define HARDWARE_INFO_LIB
 
+typedef struct{
+  UINT32  NodeId;
+  UINT64  AddressBase;
+  UINT64  AddressSize;
+} MemoryInfo;
+
 /**
   Get CPU count from information passed by Qemu.
 
@@ -42,4 +48,26 @@ GetCpuNumaNode (
   IN UINTN  CpuId
   );
 
+/**
+  Get the number of memory node from device tree passed by Qemu.
+
+  @retval   the number of memory nodes.
+**/
+UINT32
+GetMemNodeCount (
+  VOID
+  );
+
+/**
+  Get memory infomation(node-id, addressbase, addresssize) for a given memory 
node from device tree passed by Qemu.
+
+  @param [in]   MemoryIdIndex of memory to retrieve memory information.
+
+  @retval   memory infomation for given memory node.
+**/
+MemoryInfo
+GetMemInfo (
+  IN UINTN   MemoryId
+  );
+
 #endif /* HARDWARE_INFO_LIB */
diff --git 
a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
index e96328978a55..4f49ae7e1862 100644
--- 
a/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
+++ 
b/Silicon/Qemu/SbsaQemu/Library/SbsaQemuHardwareInfoLib/SbsaQemuHardwareInfoLib.c
@@ -94,3 +94,53 @@ GetCpuNumaNode (
 
   return Arg0;
 }
+
+UINT32
+GetMemNodeCount (
+  VOID
+  )
+{
+  UINTNSmcResult;
+  UINTNArg0;
+
+  SmcResult = ArmCallSmc0 (SIP_SVC_GET_MEMORY_NODE_COUNT, &Arg0, NULL, NULL);
+  if (SmcResult != SMC_SIP_CALL_SUCCESS) {
+DEBUG ((DEBUG_ERROR, "%a: SIP_SVC_GET_MEMORY_NODE_COUNT call failed. We 
have no memory information.\n", __FUNCTION__));
+ResetShutdown ();
+  }
+
+  DEBUG (( DEBUG_INFO, "%a: The number of the memory nodes is %ld\n", 
__FUNCTION__, Arg0));
+  return (UINT32)Arg0;
+}
+
+MemoryInfo
+GetMemInfo (
+  IN UINTN   MemoryId
+  )
+{
+  UINTN   SmcResult;
+  UINTN   Arg0;
+  UINTN   Arg1;
+  UINTN   Arg2;
+  MemoryInfo  MemInfo;
+
+  Arg0 = MemoryId;
+
+  SmcResult = ArmCallSmc1 (SIP_SVC_GET_MEMORY_NODE, &Arg0, &Arg1, &Arg2);
+  if (SmcResult != SMC_SIP_CALL_SUCCESS) {
+DEBUG ((DEBUG_ERROR, "%a: SIP_SVC_GET_MEMORY_NODE call failed. We have no 
memory information.\n", __FUNCTION__));
+ResetShutdown ();
+  } else {
+MemInfo.NodeId = Arg0;
+MemInfo.AddressBase = Arg1;
+MemInfo.AddressSize = Arg2;
+  }
+
+  DEBUG(( DEBUG_INFO, "%a: NUMA node for System RAM:%d = 0x%lx - 0x%lx\n",
+  __FUNCTION__,
+  MemInfo.NodeId,
+  MemInfo.AddressBase,
+  MemInfo.AddressBase + MemInfo.AddressSize -1 ));
+
+  return MemInfo;
+}
diff --git a/Silicon/Qemu/SbsaQemu/Li

[edk2-devel] [PATCH v2 0/2] Update BaseTools NULL Include and Library Matching

2024-03-22 Thread Taylor Beebe
v1:
  - Initial patch series
v2:
  - Simplified the check for if the currently evaluated inf is a module or 
library.
  - Added a commit to use stronger matching of NULL includes (check for pattern 
"NULL")

Cc: Rebecca Cran 
Cc: Liming Gao 
Cc: Bob Feng 
Cc: Yuwei Chen 

Taylor Beebe (2):
  BaseTools: Don't Recurse NULL Includes Not Linked to Module
  BaseTools: Use Stronger Matching for NULL Linked Libraries

 BaseTools/Source/Python/GenFds/FfsInfStatement.py| 4 ++--
 BaseTools/Source/Python/Workspace/WorkspaceCommon.py | 8 +---
 2 files changed, 7 insertions(+), 5 deletions(-)

-- 
2.40.1.vfs.0.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117061): https://edk2.groups.io/g/devel/message/117061
Mute This Topic: https://groups.io/mt/105092033/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 1/2] BaseTools: Don't Recurse NULL Includes Not Linked to Module

2024-03-22 Thread Taylor Beebe
When collecting the required library instances for modules and
libraries, included libraries will be recursed to ensure the module is
built with all the libraries directly linked to it and indirectly
linked to it via included libraries.

Using the following scenario as an example:

[LibraryClasses.common.DXE_CORE]
NULL|Path/To/Library1.inf // Includes DebugLib

[LibraryClasses.common.DXE_DRIVER]
NULL|Path/To/Library2.inf // Includes DebugLib

[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_DRIVER]
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf

[Components]
MdeModulePkg/Core/Dxe/DxeMain.inf // Includes DebugLib

The DXE_CORE NULL library will be assigned a fake library class like
NULL1 and the DXE_DRIVER will be assigned NULL2. The recursion logic
will see NULL1 as a directly linked and will add an instance of it to
the list of libraries which need to be included in the module. When
DebugLib is evaluated, the recursion logic will add the libraries
DebugLib depends on to the queue which includes both NULL1 and NULL2.
When NULL2 is unqueued, an instance of it will also be added to the
list of libraries needed to build DxeMain which now means that both
NULL1 and NULL2 have been linked.

NULL includes outside of module overrides are not supported according
to the spec, but we do it anyways so this seems like a case which
should be fixed. This change updates the recursion logic to skip
evaluating NULL libraries unless they are linked directly to the
module/library being evaluated.

Signed-off-by: Taylor Beebe 
Cc: Rebecca Cran 
Cc: Liming Gao 
Cc: Bob Feng 
Cc: Yuwei Chen 
---
 BaseTools/Source/Python/Workspace/WorkspaceCommon.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py 
b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
index 9e506fc646..8bb6553c6f 100644
--- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
+++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
@@ -123,6 +123,8 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, 
Arch, Target, Toolcha
 while len(LibraryConsumerList) > 0:
 M = LibraryConsumerList.pop()
 for LibraryClassName in M.LibraryClasses:
+if LibraryClassName.startswith("NULL") and bool(M.LibraryClass):
+continue
 if LibraryClassName not in LibraryInstance:
 # override library instance for this module
 LibraryPath = 
Platform.Modules[str(Module)].LibraryClasses.get(LibraryClassName,Platform.LibraryClasses[LibraryClassName,
 ModuleType])
-- 
2.40.1.vfs.0.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117062): https://edk2.groups.io/g/devel/message/117062
Mute This Topic: https://groups.io/mt/105092034/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 2/2] BaseTools: Use Stronger Matching for NULL Linked Libraries

2024-03-22 Thread Taylor Beebe
To prevent the possibility that a library with a name like
NULLTestLib is interpreted as a NULL linked library, use
more explicit pattern matching to ensure that the library
name follows the pattern NULL%d.

Signed-off-by: Taylor Beebe 
Cc: Rebecca Cran 
Cc: Liming Gao 
Cc: Bob Feng 
Cc: Yuwei Chen 
---
 BaseTools/Source/Python/GenFds/FfsInfStatement.py| 4 ++--
 BaseTools/Source/Python/Workspace/WorkspaceCommon.py | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py 
b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 6550d939d4..ec9713484e 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -93,7 +93,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
 
 if ModuleType != SUP_MODULE_USER_DEFINED and ModuleType != 
SUP_MODULE_HOST_APPLICATION:
 for LibraryClass in 
PlatformDataBase.LibraryClasses.GetKeys():
-if LibraryClass.startswith("NULL") and 
PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]:
+if LibraryClass.startswith("NULL") and 
LibraryClass[4:].isdigit() and PlatformDataBase.LibraryClasses[LibraryClass, 
ModuleType]:
 self.InfModule.LibraryClasses[LibraryClass] = 
PlatformDataBase.LibraryClasses[LibraryClass, ModuleType]
 
 StrModule = str(self.InfModule)
@@ -101,7 +101,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
 if StrModule in PlatformDataBase.Modules:
 PlatformModule = PlatformDataBase.Modules[StrModule]
 for LibraryClass in PlatformModule.LibraryClasses:
-if LibraryClass.startswith("NULL"):
+if LibraryClass.startswith("NULL") and 
LibraryClass[4:].isdigit():
 self.InfModule.LibraryClasses[LibraryClass] = 
PlatformModule.LibraryClasses[LibraryClass]
 
 DependencyList = [self.InfModule]
diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py 
b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
index 8bb6553c6f..c3b26b370a 100644
--- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
+++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
@@ -102,12 +102,12 @@ def GetModuleLibInstances(Module, Platform, 
BuildDatabase, Arch, Target, Toolcha
 #
 if Module.ModuleType != SUP_MODULE_USER_DEFINED:
 for LibraryClass in Platform.LibraryClasses.GetKeys():
-if LibraryClass.startswith("NULL") and 
Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
+if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit() 
and Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
 Module.LibraryClasses[LibraryClass] = 
Platform.LibraryClasses[LibraryClass, Module.ModuleType]
 
 # add forced library instances (specified in module overrides)
 for LibraryClass in Platform.Modules[str(Module)].LibraryClasses:
-if LibraryClass.startswith("NULL"):
+if LibraryClass.startswith("NULL") and LibraryClass[4:].isdigit():
 Module.LibraryClasses[LibraryClass] = 
Platform.Modules[str(Module)].LibraryClasses[LibraryClass]
 
 # EdkII module
@@ -123,7 +123,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, 
Arch, Target, Toolcha
 while len(LibraryConsumerList) > 0:
 M = LibraryConsumerList.pop()
 for LibraryClassName in M.LibraryClasses:
-if LibraryClassName.startswith("NULL") and bool(M.LibraryClass):
+if LibraryClassName.startswith("NULL") and 
LibraryClass[4:].isdigit() and bool(M.LibraryClass):
 continue
 if LibraryClassName not in LibraryInstance:
 # override library instance for this module
@@ -141,7 +141,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, 
Arch, Target, Toolcha
 
 LibraryModule = BuildDatabase[LibraryPath, Arch, Target, 
Toolchain]
 # for those forced library instance (NULL library), add a fake 
library class
-if LibraryClassName.startswith("NULL"):
+if LibraryClassName.startswith("NULL") and 
LibraryClass[4:].isdigit():
 
LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, 
[ModuleType]))
 elif LibraryModule.LibraryClass is None \
  or len(LibraryModule.LibraryClass) == 0 \
-- 
2.40.1.vfs.0.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#117063): https://edk2.groups.io/g/devel/message/117063
Mute This Topic: https://groups.io/mt/105092035/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] NetworkPkg:Resolved Consecutive Pxe-Http Boot Issue

2024-03-22 Thread Saloni Kasbekar
Hi Siva,

Have you looked into getting this fixed in grub as Laszlo suggested? What's the 
expected timeline for this workaround?

Thanks,
Saloni

-Original Message-
From: Sivaraman Nainar  
Sent: Tuesday, March 19, 2024 4:32 AM
To: devel@edk2.groups.io; Laszlo Ersek ; Santhosh Kumar V 
; Kasbekar, Saloni ; 
Clark-williams, Zachary 
Cc: Raj V Akilan ; Soundharia R 
Subject: RE: [EXTERNAL] Re: [edk2-devel] [PATCH] NetworkPkg:Resolved 
Consecutive Pxe-Http Boot Issue

@Saloni Kasbekar,

Can you please comment on the changes?

Thanks
Siva
-Original Message-
From: Sivaraman Nainar
Sent: Monday, February 26, 2024 4:01 PM
To: devel@edk2.groups.io; Sivaraman Nainar ; Laszlo Ersek 
; Santhosh Kumar V ; Saloni Kasbekar 
; Zachary Clark-williams 

Cc: Raj V Akilan ; Soundharia R 
Subject: RE: [EXTERNAL] Re: [edk2-devel] [PATCH] NetworkPkg:Resolved 
Consecutive Pxe-Http Boot Issue

@Saloni Kasbekar, @Zachary Clark-williams,

Could you please add your feedback on the changes proposed?

Thanks
Siva
-Original Message-
From: devel@edk2.groups.io  On Behalf Of Sivaraman Nainar 
via groups.io
Sent: Thursday, February 22, 2024 7:33 AM
To: Laszlo Ersek ; devel@edk2.groups.io; Santhosh Kumar V 
; Saloni Kasbekar ; Zachary 
Clark-williams 
Cc: Raj V Akilan ; Soundharia R 
Subject: [EXTERNAL] Re: [edk2-devel] [PATCH] NetworkPkg:Resolved Consecutive 
Pxe-Http Boot Issue


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

Laszlo:

Thanks for the detailed feedback on the changes for this issue. Since we are 
not sure if this change are valid / violate some purpose of SNP driver, it 
mentioned as Workaround.

@Saloni Kasbekar and @Clark-williams, Zachary can add more on these changes.

As you recommended, we can have PCD which controls these changes till the 
changes are addressed in grub.

@Santhosh Kumar V is this issue can be seen only in SLES 15 or it can be found 
in any OS having Grub 2.x?

Thanks
Siva
-Original Message-
From: Laszlo Ersek 
Sent: Thursday, February 22, 2024 5:15 AM
To: devel@edk2.groups.io; Santhosh Kumar V 
Cc: Sivaraman Nainar ; Raj V Akilan ; 
Soundharia R ; Saloni Kasbekar 
; Zachary Clark-williams 

Subject: [EXTERNAL] Re: [edk2-devel] [PATCH] NetworkPkg:Resolved Consecutive 
Pxe-Http Boot Issue


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

On 2/21/24 18:15, Santhosh Kumar V via groups.io wrote:
> The customer has a server environment where PXE and HTTP service run in same 
> Linux Server. In this environment a SUT trying to boot to SLES 15 OS via PXE 
> from the Boot Menu. After PXE Boot file downloaded and grub Loaded without 
> continuing for installation Exit is pressed and control back to Setup.
> Now the HTTP boot to SLES 15 OS tried in the same environment and failed to 
> download the file. If there is a reconnect -r performed before this HTTP Boot 
> then boot file download and installation is getting success.
> Root cause of the issue is, when Exit from grub performed, boot Loader Stops 
> the SNP Driver and starts the same.

This sentence feels like the key one.

Are you saying that grub calls Snp->Start() just before it exits?

If so, am I right to suspect that that's a grub bug? It sounds like a resource 
leak, after all.

Can you perhaps include a grub source code location / pointer in the commit 
message?

> During this process SNP is in Initialized State. When HTTP boot is performed 
> immediately after PXE Failure, the MNP configure method initiates the SNP 
> Start again. Since the SNP already started by grub it returns 
> EFI_ALREADY_STARTED and none of the upper Layer drivers are getting started.
> As a work around in MNPConfigure(), if the SNP Start failed with Already 
> Started and in Initialized state we can return success so that rest of the 
> drivers can be loaded and HTTP boot can work.
>
>
> Cc: Saloni Kasbekar 
> Cc: Zachary Clark-williams 
>
> Signed-off-by: SanthoshKumar 
> ---
>  NetworkPkg/MnpDxe/MnpConfig.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/NetworkPkg/MnpDxe/MnpConfig.c 
> b/NetworkPkg/MnpDxe/MnpConfig.c index 93587d53aa..0f2df28d73 100644
> --- a/NetworkPkg/MnpDxe/MnpConfig.c
> +++ b/NetworkPkg/MnpDxe/MnpConfig.c
> @@ -1120,7 +1120,9 @@ MnpStartSnp (
>// Start the simple network.
>
>//
>
>Status = Snp->Start (Snp);
>
> -
>
> +  if ((Status == EFI_ALREADY_STARTED ) && (Snp->Mode->State ==
> + EfiSimpleNetworkInitialized)) {
>
> +  return EFI_SUCCESS;
>
> +  }
>
>if (!EFI_ERROR (Status)) {
>
>  //
>
>  // Initialize the simple network.
>

The commit message does say this is a workaround, and I don't immediately any 
see why this workaround (in the code) would be problematic in practice, but it 
still leaves a bad taste in my mouth.

Consider: the call path is the fol