Date   

[PATCH EDK2 v1 0/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test

wenyi,xie
 

Main Changes :
Adding unit test for UefiSortLib.

Wenyi Xie (1):
MdeModulePkg/UefiSortLib:Add UefiSortLib unit test

MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 +
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf | 32 ++++
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c | 188 ++++++++++++++++++++
3 files changed, 226 insertions(+)
create mode 100644 MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
create mode 100644 MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c

--
2.20.1.windows.1


[PATCH EDK2 v1 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test

wenyi,xie
 

Adding unit test for UefiSortLib.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
---
MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 +
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf | 32 ++++
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c | 188 ++++++++++++++++++++
3 files changed, 226 insertions(+)

diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
index 4da4692c8451..c9ec835df65d 100644
--- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
+++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
@@ -41,3 +41,9 @@ [Components]
<PcdsFixedAtBuild>
gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDisable|TRUE
}
+
+ MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
+ <LibraryClasses>
+ UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ }
diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
new file mode 100644
index 000000000000..d9dac307934e
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
@@ -0,0 +1,32 @@
+## @file
+# This is a unit test for the UefiSortLib.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UefiSortLibUnitTest
+ FILE_GUID = 271337A3-0D79-BA3E-BC03-714E518E3B1B
+ VERSION_STRING = 1.0
+ MODULE_TYPE = HOST_APPLICATION
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ UefiSortLibUnitTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ UnitTestLib
+ DebugLib
+ UefiSortLib
diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
new file mode 100644
index 000000000000..f2f89daef7ba
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
@@ -0,0 +1,188 @@
+/** @file
+ Unit tests of the UefiSortLib
+
+ Copyright (C) Huawei Technologies Co., Ltd. All rights reserved
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <Library/UnitTestLib.h>
+#include <Library/SortLib.h>
+
+#define UNIT_TEST_APP_NAME "UefiSortLib Unit Tests"
+#define UNIT_TEST_APP_VERSION "1.0"
+
+#define TEST_ARRAY_SIZE_9 9
+
+/**
+ The function is called by PerformQuickSort to compare int values.
+
+ @param[in] Left The pointer to first buffer.
+ @param[in] Right The pointer to second buffer.
+
+ @retval 0 Buffer1 equal to Buffer2.
+ @return <0 Buffer1 is less than Buffer2.
+ @return >0 Buffer1 is greater than Buffer2.
+
+**/
+INTN
+EFIAPI
+TestCompareFunction (
+ IN CONST VOID *Left,
+ IN CONST VOID *Right
+ )
+{
+ if (*(UINT32*)Right > *(UINT32*)Left) {
+ return 1;
+ } else if (*(UINT32*)Right < *(UINT32*)Left) {
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ Unit test for PerformQuickSort () API of the UefiSortLib.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+SortUINT32ArrayShouldSucceed (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINTN TestCount = TEST_ARRAY_SIZE_9;
+ UINT32 TestBuffer[TEST_ARRAY_SIZE_9] = {1, 2, 3, 4, 5, 6, 7 ,8, 9};
+ UINT32 TestResult[TEST_ARRAY_SIZE_9] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
+
+ PerformQuickSort (TestBuffer, TestCount, sizeof (UINT32), (SORT_COMPARE)TestCompareFunction);
+ UT_ASSERT_MEM_EQUAL (TestBuffer, TestResult, sizeof (UINT32) * TEST_ARRAY_SIZE_9);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Unit test for StringCompare () API of the UefiSortLib.
+
+ @param[in] Context [Optional] An optional parameter that enables:
+ 1) test-case reuse with varied parameters and
+ 2) test-case re-entry for Target tests that need a
+ reboot. This parameter is a VOID* and it is the
+ responsibility of the test author to ensure that the
+ contents are well understood by all test cases that may
+ consume it.
+
+ @retval UNIT_TEST_PASSED The Unit test has completed and the test
+ case was successful.
+ @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
+**/
+UNIT_TEST_STATUS
+EFIAPI
+CompareSameBufferShouldSucceed (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ INTN retval;
+ CONST CHAR16* TestBuffer[] = { L"abcdefg" };
+
+ retval = StringCompare (TestBuffer, TestBuffer);
+ UT_ASSERT_TRUE (retval == 0);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Initialze the unit test framework, suite, and unit tests for the
+ UefiSortLib and run the UefiSortLib unit test.
+
+ @retval EFI_SUCCESS All test cases were dispatched.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
+ initialize the unit tests.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+UnitTestingEntry (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ UNIT_TEST_FRAMEWORK_HANDLE Framework;
+ UNIT_TEST_SUITE_HANDLE SortTests;
+
+ Framework = NULL;
+
+ DEBUG(( DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION ));
+
+ //
+ // Start setting up the test framework for running the tests.
+ //
+ Status = InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
+ goto EXIT;
+ }
+
+ //
+ // Populate the UefiSortLib Unit Test Suite.
+ //
+ Status = CreateUnitTestSuite (&SortTests, Framework, "UefiSortLib Sort Tests", "UefiSortLib.SortLib", NULL, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for UefiSortLib API Tests\n"));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto EXIT;
+ }
+
+ //
+ // --------------Suite--------Description------------Name--------------Function----------------Pre---Post---Context-----------
+ //
+ AddTestCase (SortTests, "Sort the Array", "Sort", SortUINT32ArrayShouldSucceed, NULL, NULL, NULL);
+ AddTestCase (SortTests, "Compare the Buffer", "Compare", CompareSameBufferShouldSucceed, NULL, NULL, NULL);
+
+ //
+ // Execute the tests.
+ //
+ Status = RunAllTestSuites (Framework);
+
+EXIT:
+ if (Framework) {
+ FreeUnitTestFramework (Framework);
+ }
+
+ return Status;
+}
+
+/**
+ Standard POSIX C entry point for host based unit test execution.
+**/
+int
+main (
+ int argc,
+ char *argv[]
+ )
+{
+ return UnitTestingEntry ();
+}
--
2.20.1.windows.1


[PATCH] RedfishPkg/RefishCrtLib: Public RefishCrtLib

Abner Chang
 

Move RefishCrtLib from PrivateInclude to Include.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
---
RedfishPkg/{PrivateInclude => Include}/Library/RedfishCrtLib.h | 2 +-
.../RedfishLib/edk2libredfish/include/redfishPayload.h | 2 +-
.../RedfishLib/edk2libredfish/include/redfishService.h | 2 +-
.../PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
rename RedfishPkg/{PrivateInclude => Include}/Library/RedfishCrtLib.h (96%)

diff --git a/RedfishPkg/PrivateInclude/Library/RedfishCrtLib.h b/RedfishPkg/Include/Library/RedfishCrtLib.h
similarity index 96%
rename from RedfishPkg/PrivateInclude/Library/RedfishCrtLib.h
rename to RedfishPkg/Include/Library/RedfishCrtLib.h
index 28a493d782..5e15768938 100644
--- a/RedfishPkg/PrivateInclude/Library/RedfishCrtLib.h
+++ b/RedfishPkg/Include/Library/RedfishCrtLib.h
@@ -2,7 +2,7 @@
Redfish CRT wrapper functions.

Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
- (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+ (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h
index 03380d9394..43149f3c89 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishPayload.h
@@ -17,7 +17,7 @@
#ifndef LIBREDFISH_REDFISH_PAYLOAD_H_
#define LIBREDFISH_REDFISH_PAYLOAD_H_

-#include <PrivateInclude/Library/RedfishCrtLib.h>
+#include <Include/Library/RedfishCrtLib.h>

#include <jansson.h>
#include <redfishService.h>
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h
index 5bcb381c05..0215caccfc 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redfishService.h
@@ -30,7 +30,7 @@
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>

-#include <PrivateInclude/Library/RedfishCrtLib.h>
+#include <Include/Library/RedfishCrtLib.h>

#include <Protocol/EdkIIRedfishConfigHandler.h>
#include <Protocol/RestEx.h>
diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h
index bdec6098e5..24413a648a 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/include/redpath.h
@@ -17,7 +17,7 @@
#ifndef LIBREDFISH_REDPATH_H_
#define LIBREDFISH_REDPATH_H_

-#include <PrivateInclude/Library/RedfishCrtLib.h>
+#include <Include/Library/RedfishCrtLib.h>

#include <jansson.h>

--
2.17.1


[PATCH] RedfishPkg/JsonLib: Add more JsonLib functions

Abner Chang
 

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
---
RedfishPkg/Include/Library/JsonLib.h | 127 ++++++++++++++++++++--
RedfishPkg/Library/JsonLib/JsonLib.c | 156 ++++++++++++++++++++++++---
2 files changed, 261 insertions(+), 22 deletions(-)

diff --git a/RedfishPkg/Include/Library/JsonLib.h b/RedfishPkg/Include/Library/JsonLib.h
index 8a30c5250b..83959dd52a 100644
--- a/RedfishPkg/Include/Library/JsonLib.h
+++ b/RedfishPkg/Include/Library/JsonLib.h
@@ -2,7 +2,7 @@
APIs for JSON operations.

Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
- (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+ (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

@@ -53,6 +53,13 @@ typedef INT64 EDKII_JSON_INT_T; // #JSON_INTEGER_IS_LONG_LONG is set to 1
Index < JsonArrayCount(Array) && (Value = JsonArrayGetValue(Array, Index)); \
Index++)

+#define EDKII_JSON_OBJECT_FOREACH_SAFE(Object, N, Key, Value) \
+ for (Key = JsonObjectIteratorKey(JsonObjectIterator(Object)), \
+ N = JsonObjectIteratorNext(Object, JsonObjectKeyToIterator(Key)); \
+ Key && (Value = JsonObjectIteratorValue(JsonObjectKeyToIterator(Key))); \
+ Key = JsonObjectIteratorKey(N), \
+ N = JsonObjectIteratorNext(Object, JsonObjectKeyToIterator(Key)))
+
///
/// Map to the json_error_t in jansson.h
///
@@ -177,12 +184,12 @@ JsonValueInitUnicodeString (

@param[in] Value The integer to initialize to JSON value

- @retval The created JSON value which contains a JSON number or NULL.
+ @retval The created JSON value which contains a JSON integer or NULL.

**/
EDKII_JSON_VALUE
EFIAPI
-JsonValueInitNumber (
+JsonValueInitInteger (
IN INT64 Value
);

@@ -218,6 +225,36 @@ JsonValueInitNull (
VOID
);

+/**
+ The function is used to initialize a JSON value which contains a TRUE JSON value,
+ or NULL on error.
+
+ NULL JSON value is kept as static value, and no need to do any cleanup work.
+
+ @retval The created JSON TRUE value.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonValueInitTrue (
+ VOID
+ );
+
+/**
+ The function is used to initialize a JSON value which contains a FALSE JSON value,
+ or NULL on error.
+
+ NULL JSON value is kept as static value, and no need to do any cleanup work.
+
+ @retval The created JSON FALSE value.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonValueInitFalse (
+ VOID
+ );
+
/**
The function is used to decrease the reference count of a JSON value by one, and once
this reference count drops to zero, the value is destroyed and it can no longer be used.
@@ -313,6 +350,21 @@ JsonValueIsString (
IN EDKII_JSON_VALUE Json
);

+/**
+ The function is used to return if the provided JSON value contains a JSON integer.
+
+ @param[in] Json The provided JSON value.
+
+ @retval TRUE The JSON value is contains JSON integer.
+ @retval FALSE The JSON value doesn't contain a JSON integer.
+
+**/
+BOOLEAN
+EFIAPI
+JsonValueIsInteger (
+ IN EDKII_JSON_VALUE Json
+ );
+
/**
The function is used to return if the provided JSON value contains a JSON number.

@@ -343,6 +395,36 @@ JsonValueIsBoolean (
IN EDKII_JSON_VALUE Json
);

+/**
+ The function is used to return if the provided JSON value contains a TRUE value.
+
+ @param[in] Json The provided JSON value.
+
+ @retval TRUE The JSON value contains a TRUE value.
+ @retval FALSE The JSON value doesn't contain a TRUE value.
+
+**/
+BOOLEAN
+EFIAPI
+JsonValueIsTrue (
+ IN EDKII_JSON_VALUE Json
+ );
+
+/**
+ The function is used to return if the provided JSON value contains a FALSE value.
+
+ @param[in] Json The provided JSON value.
+
+ @retval TRUE The JSON value contains a FALSE value.
+ @retval FALSE The JSON value doesn't contain a FALSE value.
+
+**/
+BOOLEAN
+EFIAPI
+JsonValueIsFalse (
+ IN EDKII_JSON_VALUE Json
+ );
+
/**
The function is used to return if the provided JSON value contains a JSON NULL.

@@ -424,19 +506,19 @@ JsonValueGetUnicodeString (
);

/**
- The function is used to retrieve the associated integer in a number type JSON value.
+ The function is used to retrieve the associated integer in a integer type JSON value.

- The input JSON value should not be NULL or contain no JSON number, otherwise it will
+ The input JSON value should not be NULL or contain no JSON Integer, otherwise it will
ASSERT() and return 0.

@param[in] Json The provided JSON value.

- @retval Return the associated number in JSON value.
+ @retval Return the associated Integer in JSON value.

**/
INT64
EFIAPI
-JsonValueGetNumber (
+JsonValueGetInteger (
IN EDKII_JSON_VALUE Json
);

@@ -675,6 +757,8 @@ JsonDumpString (
Caller needs to cleanup the root value by calling JsonValueFree().

@param[in] String The NULL terminated CHAR8 string to convert.
+ @param[in] Flags Flags for loading JSON string.
+ @param[in] Error Returned error status.

@retval Array JSON value or object JSON value, or NULL when any error occurs.

@@ -682,7 +766,9 @@ JsonDumpString (
EDKII_JSON_VALUE
EFIAPI
JsonLoadString (
- IN CONST CHAR8* String
+ IN CONST CHAR8* String,
+ IN UINT64 Flags,
+ IN EDKII_JSON_ERROR *Error
);

/**
@@ -781,11 +867,36 @@ JsonObjectIteratorValue (
@retval Iterator pointer
**/
VOID *
+EFIAPI
JsonObjectIteratorNext (
IN EDKII_JSON_VALUE JsonValue,
IN VOID *Iterator
);

+/**
+ Returns the key of iterator pointing
+
+ @param[in] Iterator Iterator pointer
+ @retval Key
+**/
+CHAR8 *
+EFIAPI
+JsonObjectIteratorKey (
+ IN VOID *Iterator
+);
+
+/**
+ Returns the pointer of iterator by key.
+
+ @param[in] Key The key of interator pointer.
+ @retval Pointer to interator
+**/
+VOID *
+EFIAPI
+JsonObjectKeyToIterator (
+ IN CHAR8 *Key
+);
+
/**
Returns the json type of this json value

diff --git a/RedfishPkg/Library/JsonLib/JsonLib.c b/RedfishPkg/Library/JsonLib/JsonLib.c
index c305a3767f..24e78c9d44 100644
--- a/RedfishPkg/Library/JsonLib/JsonLib.c
+++ b/RedfishPkg/Library/JsonLib/JsonLib.c
@@ -5,7 +5,7 @@
https://jansson.readthedocs.io/en/2.13/apiref.html

Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
- (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
+ (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -154,12 +154,12 @@ JsonValueInitUnicodeString (

@param[in] Value The integer to initialize to JSON value

- @retval The created JSON value which contains a JSON number or NULL.
+ @retval The created JSON value which contains a JSON integer or NULL.

**/
EDKII_JSON_VALUE
EFIAPI
-JsonValueInitNumber (
+JsonValueInitInteger (
IN INT64 Value
)
{
@@ -186,6 +186,42 @@ JsonValueInitBoolean (
return (EDKII_JSON_VALUE)json_boolean (Value);
}

+/**
+ The function is used to initialize a JSON value which contains a TRUE JSON value,
+ or NULL on error.
+
+ NULL JSON value is kept as static value, and no need to do any cleanup work.
+
+ @retval The created JSON TRUE value.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonValueInitTrue (
+ VOID
+ )
+{
+ return (EDKII_JSON_VALUE)json_true();
+}
+
+/**
+ The function is used to initialize a JSON value which contains a FALSE JSON value,
+ or NULL on error.
+
+ NULL JSON value is kept as static value, and no need to do any cleanup work.
+
+ @retval The created JSON FALSE value.
+
+**/
+EDKII_JSON_VALUE
+EFIAPI
+JsonValueInitFalse (
+ VOID
+ )
+{
+ return (EDKII_JSON_VALUE)json_false();
+}
+
/**
The function is used to initialize a JSON value which contains a new JSON NULL,
or NULL on error.
@@ -314,6 +350,24 @@ JsonValueIsString (
return json_is_string ((json_t *) Json);
}

+/**
+ The function is used to return if the provided JSON value contains a JSON integer.
+
+ @param[in] Json The provided JSON value.
+
+ @retval TRUE The JSON value is contains JSON integer.
+ @retval FALSE The JSON value doesn't contain a JSON integer.
+
+**/
+BOOLEAN
+EFIAPI
+JsonValueIsInteger (
+ IN EDKII_JSON_VALUE Json
+ )
+{
+ return json_is_integer ((json_t *) Json);
+}
+
/**
The function is used to return if the provided JSON value contains a JSON number.

@@ -329,7 +383,7 @@ JsonValueIsNumber (
IN EDKII_JSON_VALUE Json
)
{
- return json_is_integer ((json_t *) Json);
+ return json_is_number ((json_t *) Json);
}

/**
@@ -350,6 +404,47 @@ JsonValueIsBoolean (
return json_is_boolean ((json_t *) Json);
}

+/**
+ The function is used to return if the provided JSON value contains a TRUE value.
+
+ @param[in] Json The provided JSON value.
+
+ @retval TRUE The JSON value contains a TRUE value.
+ @retval FALSE The JSON value doesn't contain a TRUE value.
+
+**/
+BOOLEAN
+EFIAPI
+JsonValueIsTrue (
+ IN EDKII_JSON_VALUE Json
+ )
+{
+ if (json_is_true ((json_t *)Json)) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ The function is used to return if the provided JSON value contains a FALSE value.
+
+ @param[in] Json The provided JSON value.
+
+ @retval TRUE The JSON value contains a FALSE value.
+ @retval FALSE The JSON value doesn't contain a FALSE value.
+
+**/
+BOOLEAN
+EFIAPI
+JsonValueIsFalse (
+ IN EDKII_JSON_VALUE Json
+ )
+{
+ if (json_is_false ((json_t *)Json)) {
+ return TRUE;
+ }
+ return FALSE;
+}
/**
The function is used to return if the provided JSON value contains a JSON NULL.

@@ -485,24 +580,24 @@ JsonValueGetUnicodeString (
}

/**
- The function is used to retrieve the associated integer in a number type JSON value.
+ The function is used to retrieve the associated integer in a integer type JSON value.

- The input JSON value should not be NULL or contain no JSON number, otherwise it will
+ The input JSON value should not be NULL or contain no JSON integer, otherwise it will
ASSERT() and return 0.

@param[in] Json The provided JSON value.

- @retval Return the associated number in JSON value.
+ @retval Return the associated integer in JSON value.

**/
INT64
EFIAPI
-JsonValueGetNumber (
+JsonValueGetInteger (
IN EDKII_JSON_VALUE Json
)
{
- ASSERT (Json != NULL && JsonValueIsNumber (Json));
- if (Json == NULL || !JsonValueIsNumber (Json)) {
+ ASSERT (Json != NULL && JsonValueIsInteger (Json));
+ if (Json == NULL || !JsonValueIsInteger (Json)) {
return 0;
}

@@ -830,6 +925,8 @@ JsonDumpString (
Caller needs to cleanup the root value by calling JsonValueFree().

@param[in] String The NULL terminated CHAR8 string to convert.
+ @param[in] Flags Flags for loading JSON string.
+ @param[in] Error Returned error status.

@retval Array JSON value or object JSON value, or NULL when any error occurs.

@@ -837,12 +934,12 @@ JsonDumpString (
EDKII_JSON_VALUE
EFIAPI
JsonLoadString (
- IN CONST CHAR8* String
+ IN CONST CHAR8* String,
+ IN UINT64 Flags,
+ IN EDKII_JSON_ERROR *Error
)
{
- json_error_t JsonError;
-
- return (EDKII_JSON_VALUE) json_loads ((const char *)String, 0, &JsonError);
+ return (EDKII_JSON_VALUE) json_loads ((const char *)String, Flags, (json_error_t *)Error);
}

/**
@@ -959,6 +1056,7 @@ JsonObjectIteratorValue (
@retval Iterator pointer
**/
VOID *
+EFIAPI
JsonObjectIteratorNext (
IN EDKII_JSON_VALUE JsonValue,
IN VOID *Iterator
@@ -967,6 +1065,36 @@ JsonObjectIteratorNext (
return json_object_iter_next(JsonValue, Iterator);
}

+/**
+ Returns the key of iterator pointing
+
+ @param[in] Iterator Iterator pointer
+ @retval Key
+**/
+CHAR8 *
+EFIAPI
+JsonObjectIteratorKey (
+ IN VOID *Iterator
+)
+{
+ return json_object_iter_key(Iterator);
+}
+
+/**
+ Returns the pointer of iterator by key.
+
+ @param[in] Key The key of interator pointer.
+ @retval Pointer to interator
+**/
+VOID *
+EFIAPI
+JsonObjectKeyToIterator (
+ IN CHAR8 *Key
+)
+{
+ return json_object_key_to_iter(Key);
+}
+
/**
Returns the json type of this json value.

--
2.17.1


Re: [PATCH V3 06/10] OvmfPkg: Add AmdSev.asm in ResetVector

Min Xu
 

On July 27, 2021 8:46 PM, Yao, Jiewen wrote:
HI Min
I agree with Brijesh.

The basic rule is: SEV file shall never refer to TDX data structure. TDX file
shall never refer to SEV data structure.
These code should be isolated clearly.

Do we still need that logic if we follow the new pattern?
I have replied to Brijesh's mail about the concern of the new pattern.

I have some concern in the current pattern:
====================
OneTimeCall PreMainFunctionHookSev
OneTimeCall PreMainFunctionHookTdx
MainFunction:
XXXXXX
OneTimeCall PostMainFunctionHookSev
OneTimeCall PostMainFunctionHookTdx
====================
The TEE function need implement a TEE check function (such as IsSev, or IsTdx).

Tdx call CPUID(0x21) to determine if it is tdx guest in the very beginning of ResetVector. Then 'TDXG' is set
in TDX_WORK_AREA. SEV does the similar work which call CheckSevFeatures to set SEV_ES_WORK_AREA to 1.

After that both TDX and SEV read the above WORK_AREA to check if it is TDX or SEV or legacy guest.

In Tdx the access to SEV_ES_WORK_AREA will trigger error because SEV_ES_WORK_AREA is *NOT* initialized by host VMM.
In SEV-SNP I am afraid the access to TDX_WORK_AREA will trigger error too.

I am wondering if TDX and SEV can use the same memory region (for example, TEE_WORK_AREA) as the work area?
So that this work area is guaranteed to be initialized in both TDX and SEV. Structure of the TEE_WORK_AREA may
look like this:
typedef struct {
UINT8 Flag[4]; 'TDXG' or 'SEVG' or all-0
UINT8 Others[];
} TEE_WORK_AREA;


[PATCH 1/1] OvmfPkg PlatformBootManagerLib: Move TryRunningQemuKernel()

Christoph Willing
 

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3504

This change ensures that PlatformBdsConnectSequence() is run
before TryRunningQemuKernel().

It reverses commit a34a886962561f6d8550b2a1bb193798ca456431 which aimed
to improve UEFI boot time. Unfortunately that commit now results in boot
failure when using qemu's -kernel option, therefore rendering the -initrd
& -append options useless.

Such failures are seen in all releases from edk2-stable201808 to
edk2-stable202105 as well as the master branch.

The last releases which actually work correctly are vUDK2017 and vUDK2018
as they don't contain the a34a88 commit.

This change has been tested with edk2-stable201808, edk2-stable201811,
edk2-stable202105 as well as master (at 21/7/2021). It results in correct
booting using the -kernel option in all the test cases. No measurable
change in boot times was discernible compared with the unaffected vUDK2017
& vUDK2018 releases.

Signed-off-by: Christoph Willing <chris.willing@linux.com>
---
OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg=
/Library/PlatformBootManagerLib/BdsPlatform.c
index b0e9742937..f08ace87b3 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -1517,14 +1517,14 @@ PlatformBootManagerAfterConsole (
Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
=0D
//=0D
- // Process QEMU's -kernel command line option=0D
+ // Perform some platform specific connect sequence=0D
//=0D
- TryRunningQemuKernel ();=0D
+ PlatformBdsConnectSequence ();=0D
=0D
//=0D
- // Perform some platform specific connect sequence=0D
+ // Process QEMU's -kernel command line option=0D
//=0D
- PlatformBdsConnectSequence ();=0D
+ TryRunningQemuKernel ();=0D
=0D
EfiBootManagerRefreshAllBootOption ();=0D
=0D
--=20
2.32.0


[PATCH 0/1] OvmfPkg PlatformBootManagerLib: Move TryRunningQemuKernel()

Christoph Willing
 

Use of Qemu's -kernel option (thus also -initrd & -append) is currently n=
ot
working correctly under UEFI boot. The nominated kernel is loaded and the
initrd is opened successfully but there is no access to the VM filesystem=
.
Booting without the -kernel option i.e. using the VM's internal kernel & =
intird
works as expected with UEFI.

This behaviour has been observed in all of the four Linux systems tested =
for
verification.

The commit at which this behaviour appears has been identified and the p=
atch
proposed here just reverses it i.e. we now run TryRunningQemuKernel() aft=
er
PlatformBdsConnectSequence() instead of before it. When the proposed patc=
h is
applied, all four systems are subsequently able to boot correctly under U=
EFI.

Christoph Willing (1):
OvmfPkg PlatformBootManagerLib: Move TryRunningQemuKernel()

OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

--=20
2.32.0


Event: TianoCore Bug Triage - APAC / NAMO - 07/27/2021 #cal-reminder

devel@edk2.groups.io Calendar <noreply@...>
 

Reminder: TianoCore Bug Triage - APAC / NAMO

When:
07/27/2021
6:30pm to 7:30pm
(UTC-07:00) America/Los Angeles

Where:
https://teams.microsoft.com/l/meetup-join/19%3ameeting_OTUyZTg2NjgtNDhlNS00ODVlLTllYTUtYzg1OTNjNjdiZjFh%40thread.v2/0?context=%7b%22Tid%22%3a%2246c98d88-e344-4ed4-8496-4ed7712e255d%22%2c%22Oid%22%3a%22b286b53a-1218-4db3-bfc9-3d4c5aa7669e%22%7d

Organizer: Liming Gao gaoliming@...

View Event

Description:

TianoCore Bug Triage - APAC / NAMO

Hosted by Liming Gao

 

________________________________________________________________________________

Microsoft Teams meeting

Join on your computer or mobile app

Click here to join the meeting

Join with a video conferencing device

teams@...

Video Conference ID: 116 062 094 0

Alternate VTC dialing instructions

Or call in (audio only)

+1 916-245-6934,,77463821#   United States, Sacramento

Phone Conference ID: 774 638 21#

Find a local number | Reset PIN

Learn More | Meeting options


Re: [PATCH V3 06/10] OvmfPkg: Add AmdSev.asm in ResetVector

Min Xu
 

On July 27, 2021 8:31 PM, Brijesh Singh wrote:
On 7/27/21 6:51 AM, Xu, Min M wrote:
On July 27, 2021 6:57 PM, Brijesh Singh wrote:
Hi Min,

This refactoring is already done by the SNP patch series.

https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk
2.groups.io%2Fg%2Fdevel%2Fmessage%2F77336%3Fp%3D%2C%2C%2C20%
2C0%2C0%2
C0%3A%3ACreated%2C%2Cpost&amp;data=04%7C01%7Cbrijesh.singh%40a
md.com%
7C22b61f2ff5bb48348b0608d950f4d7c5%7C3dd8961fe4884e608e11a82d994
e183d
%7C0%7C0%7C637629834792320372%7CUnknown%7CTWFpbGZsb3d8ey
JWIjoiMC4wLjA
wMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;s
data=
tMGpR4a2uZTTR%2FsciTN0oeca2mZ32GfX3K78lA5BWas%3D&amp;reserved
=0
erid%3A5969970,20,2,20,83891510

It appears that you are also pulling in some of TDX logic inside the
AMDSev.asm such as

;
+PostJump64BitAndLandHereSev:
+
+ ;
+ ; If it is Tdx guest, jump to exit point directly.
+ ; This is because following code may access the memory region which
has
+ ; not been accepted. It is not allowed in Tdx guests.
+ ;
+ mov eax, dword[TDX_WORK_AREA]
+ cmp eax, 0x47584454 ; 'TDXG'
+ jz GoodCompare

Why we are referring the TDX workarea inside the AmdSev.asm ?
See my explanation in the above comments. In Tdx guests memory region
cannot be accessed unless it is accepted by guest or initialized by
the host VMM. In PostJump64BitAndLandHereSev there is access to
dword[SEV_ES_WORK_AREA_RDRAND] which is not initialized by host
VMM.
If this code will not be executed in Tdx guest, then the above check is not
needed. I need your help to confirm it.

There are similar Tdx check in my patch of AmdSev.asm. For example in
CheckSevFeatures byte[SEV_ES_WORK_AREA] is used to record the SEV-ES
flag. This memory region is not initialized by host VMM either. So in Tdx it
will trigger error.

Another solution is that the memory region used by SEV in ResetVector
are added Into Tdx metadata so that host VMM will initialize those
memory region when It creates the Td guest. What's your opinion?
I am not full versed on TDX yet and sorry I am not able to follow you
question completely to provide any advice. With SEV and SEV-ES, a guest can
access the memory without going through the validation process, but with
the SEV-SNP, the page need to be validated (aka accepted) before the access.
TDX has the same requirement.
In SNP series, we ensure that the data pages used in the reset vector are pre-
validated during the VM creation time -- this allows us to access the pages
without going through accept process. If I follow you correctly on your
metadata comment then it is similar to saying is pre-validate these range of
pages used in the reset vector code (that include GHCB page, Page table
pages etc), right ?
That's right. Tdx metadata describes the memory region which host VMM initialized
during the VM creation time.

In the current patch-set, below memory region are described in Tdx metadata.
- TdMailbox (PcdOvmfSecGhcbBackupBase)
- TdHob(PcdOvmfSecGhcbBase)
- TdExtraPage(PcdOvmfSecGhcbPageTableBase)
- OvmfPageTable (PcdOvmfSecPageTablesBase)
These memory regions are initialized by host VMM so they can be accessed in ResetVector in Tdx guests.

In the SEV codes, I find some memory is accessed as well. CheckSevFeatures is the example.
In CheckSevFeatures byte[SEV_ES_WORK_AREA] (PcdSevEsWorkAreaBase) is used to record/check
if it is SEV. So if this function is called in Tdx guest, then error is triggered.

What I am concerned is that, in the current pattern:
====================
OneTimeCall PreMainFunctionHookSev
OneTimeCall PreMainFunctionHookTdx
MainFunction:
XXXXXX
OneTimeCall PostMainFunctionHookSev
OneTimeCall PostMainFunctionHookTdx
====================
The TEE function need implement a TEE check function (such as IsSev, or IsTdx).
Tdx call CPUID(0x21) to determine if it is tdx guest in the very beginning of ResetVector. Then 'TDXG' is set
in TDX_WORK_AREA.
SEV does the similar work which call CheckSevFeatures to set SEV_ES_WORK_AREA to 1.
After that both TDX and SEV read the above WORK_AREA to check it is TDX or SEV or legacy guest.

In Tdx the access to SEV_ES_WORK_AREA will trigger error because SEV_ES_WORK_AREA is initialized by host VMM.
In SEV-SNP I am afraid the access to TDX_WORK_AREA will trigger error too.

I am wondering if TDX and SEV can use the same memory region (for example, TEE_WORK_AREA) as the work area?
So that this work area is guaranteed to be initialized in both TDX and SEV. Structure of the TEE_WORK_AREA may
look like this:
typedef struct {
UINT8 Flag[4]; 'TDXG' or 'SEVG' or all-0
UINT8 Others[];
} TEE_WORK_AREA;


For SEV-SNP, see this patch

https://edk2.groups.io/g/devel/message/77342?p=,,,20,0,0,0::Created,,post
erid%3A5969970,20,2,20,83891520

A VMM (qemu) looks for the range of page it need to prevalidate before the
boot, the range is provided through the GUID (SevSnpBootBlock).

I will take out my refactoring patch outside of the SNP series and
submit it so that you can build on top of. This will simplify review process.
Thank you very much for the refactoring. I will refine my patch based on it.
thanks


Re: [EXTERNAL] [edk2-devel] Missing TPM 2 related call to Tpm2HierarchyChangeAuth

Stefan Berger
 


On 7/27/21 12:25 PM, Yao, Jiewen wrote:

Oops. Sorry for late response.

 

The code is NOT in EDKII, but EDKII-platform as example. https://github.com/tianocore/edk2-platforms/tree/master/Platform/Intel/MinPlatformPkg/Tcg

 

We allow a platform having its own implementation. That is why it is NOT in EDKII.


How do edk2 and edk2-platform relate? Do we need to copy code form one to the other ?

   Stefan


 

Thank you

Yao Jiewen

 

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Bret Barkelew via groups.io
Sent: Wednesday, July 28, 2021 12:11 AM
To: devel@edk2.groups.io; stefanb@...; Yao, Jiewen <jiewen.yao@...>; Jeremiah Cox <jerecox@...>; Michael Kubacki <Michael.Kubacki@...>
Cc: Marc-André Lureau <marcandre.lureau@...>
Subject: Re: [EXTERNAL] [edk2-devel] Missing TPM 2 related call to Tpm2HierarchyChangeAuth

 

Adding @Jeremiah

 

Jeremiah, weren’t you or @Michael shopping this change to MinPlatform?

 

- Bret

 

From: Stefan Berger via groups.io
Sent: Monday, July 26, 2021 7:48 AM
To: Yao, Jiewen; devel@edk2.groups.io
Cc: Marc-André Lureau
Subject: [EXTERNAL] [edk2-devel] Missing TPM 2 related call to Tpm2HierarchyChangeAuth

 

Hello!

   The TPM 2 code in EDK2 is missing an important call to
Tpm2HierarchyChangeAuth for the platform hierarchy. We have to set the
password of that hierarchy and discard the password. See also specs
section 11:
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftrustedcomputinggroup.org%2Fwp-content%2Fuploads%2FTCG_PCClient_PFP_r1p05_v22_02dec2020.pdf&amp;data=04%7C01%7Cbret.barkelew%40microsoft.com%7Cf2a2262eee2c44b3760c08d95044601a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637629077356686202%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C2000&amp;sdata=N7VQIw87rHqUAFQ54TvhNwcsPFEwJzdZQ9JZrmX1S4E%3D&amp;reserved=0

"Platform Firmware MUST protect access to the Platform Hierarchy and
prevent access to the platform hierarchy by
non-manufacturer-controlled components.  "

I was wondering where we could put that call so it's invoked after the
user has possibly interacted with the menu and before passing control to
the next stage such as boot loader.

Regards,

   Stefan





 


[PATCH v5 06/11] ArmVirtPkg: add BlobVerifierLibNull to DSC

Dov Murik
 

This prepares the ground for calling VerifyBlob() in
QemuKernelLoaderFsDxe.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
---
ArmVirtPkg/ArmVirtQemu.dsc | 5 ++++-
ArmVirtPkg/ArmVirtQemuKernel.dsc | 5 ++++-
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 7ef5e7297bc7..97539edef799 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -440,7 +440,10 @@ [Components.common]
NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf=0D
NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc=
eManagerUiLib.inf=0D
}=0D
- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf=0D
+ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf {=0D
+ <LibraryClasses>=0D
+ NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf=0D
+ }=0D
=0D
#=0D
# Networking stack=0D
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne=
l.dsc
index a542fcb157e9..28064199c8a9 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -376,7 +376,10 @@ [Components.common]
NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf=0D
NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc=
eManagerUiLib.inf=0D
}=0D
- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf=0D
+ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf {=0D
+ <LibraryClasses>=0D
+ NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf=0D
+ }=0D
=0D
#=0D
# Networking stack=0D
--=20
2.25.1


[PATCH v5 08/11] OvmfPkg/AmdSev/SecretPei: build hob for full page

Dov Murik
 

Round up the size of the SEV launch secret area to a whole page, as
required by BuildMemoryAllocationHob. This will allow the secret
area defined in the MEMFD to take less than a whole 4KB page.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
---
OvmfPkg/AmdSev/SecretPei/SecretPei.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/AmdSev/SecretPei/SecretPei.c b/OvmfPkg/AmdSev/SecretPe=
i/SecretPei.c
index ad491515dd5d..db94c26b54d1 100644
--- a/OvmfPkg/AmdSev/SecretPei/SecretPei.c
+++ b/OvmfPkg/AmdSev/SecretPei/SecretPei.c
@@ -4,6 +4,7 @@
Copyright (C) 2020 James Bottomley, IBM Corporation.=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
**/=0D
+#include <Base.h>=0D
#include <PiPei.h>=0D
#include <Library/HobLib.h>=0D
#include <Library/PcdLib.h>=0D
@@ -17,7 +18,7 @@ InitializeSecretPei (
{=0D
BuildMemoryAllocationHob (=0D
PcdGet32 (PcdSevLaunchSecretBase),=0D
- PcdGet32 (PcdSevLaunchSecretSize),=0D
+ ALIGN_VALUE (PcdGet32 (PcdSevLaunchSecretSize), EFI_PAGE_SIZE),=0D
EfiBootServicesData=0D
);=0D
=0D
--=20
2.25.1


[PATCH v5 09/11] OvmfPkg/AmdSev: reserve MEMFD space for for firmware config hashes

Dov Murik
 

From: James Bottomley <jejb@linux.ibm.com>

Split the existing 4KB page reserved for SEV launch secrets into two
parts: first 3KB for SEV launch secrets and last 1KB for firmware
config hashes.

The area of the firmware config hashes will be attested (measured) by
the PSP and thus the untrusted VMM can't pass in different files from
what the guest owner allows.

Declare this in the Reset Vector table using GUID
7255371f-3a3b-4b04-927b-1da6efa8d454 and a uint32_t table of a base
and size value (similar to the structure used to declare the launch
secret block).

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Co-developed-by: Dov Murik <dovmurik@linux.ibm.com>
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Signed-off-by: James Bottomley <jejb@linux.ibm.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
---
OvmfPkg/OvmfPkg.dec | 6 ++++++
OvmfPkg/AmdSev/AmdSevX64.fdf | 5 ++++-
OvmfPkg/ResetVector/ResetVector.inf | 2 ++
OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 20 ++++++++++++++++++++
OvmfPkg/ResetVector/ResetVector.nasmb | 2 ++
5 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index f82228d69cc2..2ab27f0c73c2 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -324,6 +324,12 @@ [PcdsFixedAtBuild]
gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase|0x0|UINT32|0x42=0D
gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize|0x0|UINT32|0x43=0D
=0D
+ ## The base address and size of a hash table confirming allowed=0D
+ # parameters to be passed in via the Qemu firmware configuration=0D
+ # device=0D
+ gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase|0x0|UINT32|0x47=0D
+ gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize|0x0|UINT32|0x48=0D
+=0D
[PcdsDynamic, PcdsDynamicEx]=0D
gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2=0D
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x1=
0=0D
diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf
index 9977b0f00a18..0a89749700c3 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.fdf
+++ b/OvmfPkg/AmdSev/AmdSevX64.fdf
@@ -59,9 +59,12 @@ [FD.MEMFD]
0x00B000|0x001000=0D
gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|gUefiCpuPkgTokenSpaceGuid.P=
cdSevEsWorkAreaSize=0D
=0D
-0x00C000|0x001000=0D
+0x00C000|0x000C00=0D
gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase|gUefiOvmfPkgTokenSpaceGu=
id.PcdSevLaunchSecretSize=0D
=0D
+0x00CC00|0x000400=0D
+gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase|gUefiOvmfPkgTokenSpaceGuid=
.PcdQemuHashTableSize=0D
+=0D
0x00D000|0x001000=0D
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase|gUefiOvmfPkgTokenSpace=
Guid.PcdOvmfSecGhcbBackupSize=0D
=0D
diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese=
tVector.inf
index dc38f68919cd..d028c92d8cfa 100644
--- a/OvmfPkg/ResetVector/ResetVector.inf
+++ b/OvmfPkg/ResetVector/ResetVector.inf
@@ -47,3 +47,5 @@ [Pcd]
[FixedPcd]=0D
gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase=0D
gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize=0D
+ gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase=0D
+ gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize=0D
diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm b/OvmfPkg/ResetVe=
ctor/Ia16/ResetVectorVtf0.asm
index 9c0b5853a46f..7ec3c6e980c3 100644
--- a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm
+++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm
@@ -47,7 +47,27 @@ TIMES (15 - ((guidedStructureEnd - guidedStructureStart =
+ 15) % 16)) DB 0
;=0D
guidedStructureStart:=0D
=0D
+; SEV Hash Table Block=0D
;=0D
+; This describes the guest ram area where the hypervisor should=0D
+; install a table describing the hashes of certain firmware configuration=
=0D
+; device files that would otherwise be passed in unchecked. The current=0D
+; use is for the kernel, initrd and command line values, but others may be=
=0D
+; added. The data format is:=0D
+;=0D
+; base physical address (32 bit word)=0D
+; table length (32 bit word)=0D
+;=0D
+; GUID (SEV FW config hash block): 7255371f-3a3b-4b04-927b-1da6efa8d454=0D
+;=0D
+sevFwHashBlockStart:=0D
+ DD SEV_FW_HASH_BLOCK_BASE=0D
+ DD SEV_FW_HASH_BLOCK_SIZE=0D
+ DW sevFwHashBlockEnd - sevFwHashBlockStart=0D
+ DB 0x1f, 0x37, 0x55, 0x72, 0x3b, 0x3a, 0x04, 0x4b=0D
+ DB 0x92, 0x7b, 0x1d, 0xa6, 0xef, 0xa8, 0xd4, 0x54=0D
+sevFwHashBlockEnd:=0D
+=0D
; SEV Secret block=0D
;=0D
; This describes the guest ram area where the hypervisor should=0D
diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re=
setVector.nasmb
index 5fbacaed5f9d..8d0bab02f8cb 100644
--- a/OvmfPkg/ResetVector/ResetVector.nasmb
+++ b/OvmfPkg/ResetVector/ResetVector.nasmb
@@ -88,5 +88,7 @@
%define SEV_ES_AP_RESET_IP FixedPcdGet32 (PcdSevEsWorkAreaBase)=0D
%define SEV_LAUNCH_SECRET_BASE FixedPcdGet32 (PcdSevLaunchSecretBase)=0D
%define SEV_LAUNCH_SECRET_SIZE FixedPcdGet32 (PcdSevLaunchSecretSize)=0D
+ %define SEV_FW_HASH_BLOCK_BASE FixedPcdGet32 (PcdQemuHashTableBase)=0D
+ %define SEV_FW_HASH_BLOCK_SIZE FixedPcdGet32 (PcdQemuHashTableSize)=0D
%include "Ia16/ResetVectorVtf0.asm"=0D
=0D
--=20
2.25.1


[PATCH v5 04/11] OvmfPkg: add library class BlobVerifierLib with null implementation

Dov Murik
 

BlobVerifierLib will be used to verify blobs fetching them from QEMU's
firmware config (fw_cfg) in platforms that enable such verification.

The null implementation BlobVerifierLibNull treats all blobs as valid.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/OvmfPkg.dec | 3 ++
OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf | 24 +++++++++=
++++
OvmfPkg/Include/Library/BlobVerifierLib.h | 38 +++++++++=
+++++++++++
OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierNull.c | 33 +++++++++=
++++++++
4 files changed, 98 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 6ae733f6e39f..f82228d69cc2 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -23,6 +23,9 @@ [LibraryClasses]
## @libraryclass Access bhyve's firmware control interface.=0D
BhyveFwCtlLib|Include/Library/BhyveFwCtlLib.h=0D
=0D
+ ## @libraryclass Verify blobs read from the VMM=0D
+ BlobVerifierLib|Include/Library/BlobVerifierLib.h=0D
+=0D
## @libraryclass Loads and boots a Linux kernel image=0D
#=0D
LoadLinuxLib|Include/Library/LoadLinuxLib.h=0D
diff --git a/OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf b/=
OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf
new file mode 100644
index 000000000000..850d398e65a4
--- /dev/null
+++ b/OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf
@@ -0,0 +1,24 @@
+## @file=0D
+#=0D
+# Null implementation of the blob verifier library.=0D
+#=0D
+# Copyright (C) 2021, IBM Corp=0D
+#=0D
+# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+#=0D
+##=0D
+=0D
+[Defines]=0D
+ INF_VERSION =3D 1.29=0D
+ BASE_NAME =3D BlobVerifierLibNull=0D
+ FILE_GUID =3D b1b5533e-e01a-43bb-9e54-414f00ca036e=
=0D
+ MODULE_TYPE =3D BASE=0D
+ VERSION_STRING =3D 1.0=0D
+ LIBRARY_CLASS =3D BlobVerifierLib=0D
+=0D
+[Sources]=0D
+ BlobVerifierNull.c=0D
+=0D
+[Packages]=0D
+ MdePkg/MdePkg.dec=0D
+ OvmfPkg/OvmfPkg.dec=0D
diff --git a/OvmfPkg/Include/Library/BlobVerifierLib.h b/OvmfPkg/Include/Li=
brary/BlobVerifierLib.h
new file mode 100644
index 000000000000..65c01af9bf18
--- /dev/null
+++ b/OvmfPkg/Include/Library/BlobVerifierLib.h
@@ -0,0 +1,38 @@
+/** @file=0D
+=0D
+ Blob verification library=0D
+=0D
+ This library class allows verifiying whether blobs from external sources=
=0D
+ (such as QEMU's firmware config) are trusted.=0D
+=0D
+ Copyright (C) 2021, IBM Corporation=0D
+=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+**/=0D
+=0D
+#ifndef BLOB_VERIFIER_LIB_H_=0D
+#define BLOB_VERIFIER_LIB_H_=0D
+=0D
+#include <Uefi/UefiBaseType.h>=0D
+#include <Base.h>=0D
+=0D
+/**=0D
+ Verify blob from an external source.=0D
+=0D
+ @param[in] BlobName The name of the blob=0D
+ @param[in] Buf The data of the blob=0D
+ @param[in] BufSize The size of the blob in bytes=0D
+=0D
+ @retval EFI_SUCCESS The blob was verified successfully.=0D
+ @retval EFI_ACCESS_DENIED The blob could not be verified, and theref=
ore=0D
+ should be considered non-secure.=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+VerifyBlob (=0D
+ IN CONST CHAR16 *BlobName,=0D
+ IN CONST VOID *Buf,=0D
+ IN UINT32 BufSize=0D
+ );=0D
+=0D
+#endif=0D
diff --git a/OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierNull.c b/OvmfP=
kg/Library/BlobVerifierLibNull/BlobVerifierNull.c
new file mode 100644
index 000000000000..975d4dd52f80
--- /dev/null
+++ b/OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierNull.c
@@ -0,0 +1,33 @@
+/** @file=0D
+=0D
+ Null implementation of the blob verifier library.=0D
+=0D
+ Copyright (C) 2021, IBM Corporation=0D
+=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+**/=0D
+=0D
+#include <Library/BaseLib.h>=0D
+#include <Library/BlobVerifierLib.h>=0D
+=0D
+/**=0D
+ Verify blob from an external source.=0D
+=0D
+ @param[in] BlobName The name of the blob=0D
+ @param[in] Buf The data of the blob=0D
+ @param[in] BufSize The size of the blob in bytes=0D
+=0D
+ @retval EFI_SUCCESS The blob was verified successfully.=0D
+ @retval EFI_ACCESS_DENIED The blob could not be verified, and theref=
ore=0D
+ should be considered non-secure.=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+VerifyBlob (=0D
+ IN CONST CHAR16 *BlobName,=0D
+ IN CONST VOID *Buf,=0D
+ IN UINT32 BufSize=0D
+ )=0D
+{=0D
+ return EFI_SUCCESS;=0D
+}=0D
--=20
2.25.1


[PATCH v5 11/11] OvmfPkg/AmdSev: Enforce hash verification of kernel blobs

Dov Murik
 

In the AmdSevX64 build, use BlobVerifierLibSevHashes to enforce
verification of hashes of the kernel/initrd/cmdline blobs fetched from
firmware config.

This allows for secure (measured) boot of SEV guests with QEMU's
-kernel/-initrd/-append switches (with the corresponding QEMU support
for injecting the hashes table into initial measured guest memory).

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/AmdSev/AmdSevX64.dsc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index db8bd59579b9..e6cd10b75922 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -173,7 +173,7 @@ [LibraryClasses]
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf=0D
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize=
dDisplayLib.inf=0D
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL=
ib.inf=0D
- BlobVerifierLib|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.=
inf=0D
+ BlobVerifierLib|OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibS=
evHashes.inf=0D
=0D
!if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE=0D
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb=
ug/PeCoffExtraActionLibDebug.inf=0D
@@ -696,7 +696,7 @@ [Components]
}=0D
OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf {=0D
<LibraryClasses>=0D
- NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf=0D
+ NULL|OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashe=
s.inf=0D
}=0D
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf=0D
OvmfPkg/Virtio10Dxe/Virtio10.inf=0D
--=20
2.25.1


[PATCH v5 01/11] OvmfPkg/AmdSev/SecretDxe: fix header comment to generic naming

Dov Murik
 

From: James Bottomley <jejb@linux.ibm.com>

Commit 96201ae7bf97 ("OvmfPkg/AmdSev/SecretDxe: make secret location
naming generic", 2020-12-15) replaced references to SEV with the generic
term Confidential Computing, but missed the file header comment. Fix
the naming in that header.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Signed-off-by: James Bottomley <jejb@linux.ibm.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
---
OvmfPkg/AmdSev/SecretDxe/SecretDxe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/AmdSev/SecretDxe/SecretDxe.c b/OvmfPkg/AmdSev/SecretDx=
e/SecretDxe.c
index 308022b5b25e..934ad207632b 100644
--- a/OvmfPkg/AmdSev/SecretDxe/SecretDxe.c
+++ b/OvmfPkg/AmdSev/SecretDxe/SecretDxe.c
@@ -1,5 +1,5 @@
/** @file=0D
- SEV Secret configuration table constructor=0D
+ Confidential Computing Secret configuration table constructor=0D
=0D
Copyright (C) 2020 James Bottomley, IBM Corporation.=0D
SPDX-License-Identifier: BSD-2-Clause-Patent=0D
--=20
2.25.1


[PATCH v5 00/11] Measured SEV boot with kernel/initrd/cmdline

Dov Murik
 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3457

Booting with SEV prevented the loading of kernel, initrd, and kernel
command-line via QEMU fw_cfg interface because they arrive from the VMM
which is untrusted in SEV.

However, in some cases the kernel, initrd, and cmdline are not secret
but should not be modified by the host. In such a case, we want to
verify inside the trusted VM that the kernel, initrd, and cmdline are
indeed the ones expected by the Guest Owner, and only if that is the
case go on and boot them up (removing the need for grub inside OVMF in
that mode).

This patch series reserves an area in MEMFD (previously the last 1KB of
the launch secret page) which will contain the hashes of these three
blobs (kernel, initrd, cmdline), each under its own GUID entry. This
tables of hashes is populated by QEMU before launch, and encrypted as
part of the initial VM memory; this makes sure these hashes are part of
the SEV measurement (which has to be approved by the Guest Owner for
secret injection, for example). Note that populating the hashes table
requires QEMU support [1].

OVMF parses the table of hashes populated by QEMU (patch 10), and as it
reads the fw_cfg blobs from QEMU, it will verify each one against the
expected hash. This is all done inside the trusted VM context. If all
the hashes are correct, boot of the kernel is allowed to continue.

Any attempt by QEMU to modify the kernel, initrd, cmdline (including
dropping one of them), or to modify the OVMF code that verifies those
hashes, will cause the initial SEV measurement to change and therefore
will be detectable by the Guest Owner during launch before secret
injection.

Relevant part of OVMF serial log during boot with AmdSevX86 build and
QEMU with -kernel/-initrd/-append:

...
BlobVerifierLibSevHashesConstructor: Found injected hashes table in secure location
Select Item: 0x17
Select Item: 0x8
FetchBlob: loading 7379328 bytes for "kernel"
Select Item: 0x18
Select Item: 0x11
VerifyBlob: Found GUID 4DE79437-ABD2-427F-B835-D5B172D2045B in table
VerifyBlob: Hash comparison succeeded for "kernel"
Select Item: 0xB
FetchBlob: loading 12483878 bytes for "initrd"
Select Item: 0x12
VerifyBlob: Found GUID 44BAF731-3A2F-4BD7-9AF1-41E29169781D in table
VerifyBlob: Hash comparison succeeded for "initrd"
Select Item: 0x14
FetchBlob: loading 86 bytes for "cmdline"
Select Item: 0x15
VerifyBlob: Found GUID 97D02DD8-BD20-4C94-AA78-E7714D36AB2A in table
VerifyBlob: Hash comparison succeeded for "cmdline"
...

The patch series is organized as follows:

1: Simple comment fix in adjacent area in the code.
2: Use GenericQemuLoadImageLib to gain one location for fw_cfg blob
fetching.
3: Allow the (previously blocked) usage of -kernel in AmdSevX64.
4-7: Add BlobVerifierLib with null implementation and use it in the correct
location in QemuKernelLoaderFsDxe.
8-9: Reserve memory for hashes table, declare this area in the reset vector.
10-11: Add the secure implementation BlobVerifierLibSevHashes and use it in
AmdSevX64 builds.

[1] https://lore.kernel.org/qemu-devel/20210624102040.2015280-1-dovmurik@linux.ibm.com/

Code is at
https://github.com/confidential-containers-demo/edk2/tree/sev-hashes-v5

v5 changes:
- rename the null implementation dir to OvmfPkg/Library/BlobVerifierLibNull
(note that I didn't remove the R-b tags on these patches; please let me
know if I should have acted otherwise)
- move the SevHashes implementation to OvmfPkg/AmdSev/BlobVerifierLibSevHashes
- BlobVerifierLib.h: fix #ifndef according to ECC warnings
- separate variable declaration and assignment in
BlobVerifierLibSevHashesConstructor (ECC warning)

v4: https://edk2.groups.io/g/devel/message/78075
v4 changes:
- BlobVerifierSevHashes (patch 10): more comprehensive overflow tests
when parsing the SEV hashes table structure

v3: https://edk2.groups.io/g/devel/message/77955
v3 changes:
- Rename to BlobVerifierLibNull, use decimal INF_VERSION, remove unused
DebugLib reference, fix doxygen comments, add missing IN attribute
- Rename to BlobVerifierLibSevHashes, use decimal INF_VERSION, fix
doxygen comments, add missing IN attribute,
calculate buffer hash only when the guid is found in hashes table
- SecretPei: use ALIGN_VALUE to round the hob size
- Coding style fixes
- Add missing 'Ref:' in patch 1 commit message
- Fix phrasing and typos in commit messages
- Remove Cc: Laszlo from series

v2: https://edk2.groups.io/g/devel/message/77505
v2 changes:
- Use the last 1KB of the existing SEV launch secret page for hashes table
(instead of reserving a whole new MEMFD page).
- Build on top of commit cf203024745f ("OvmfPkg/GenericQemuLoadImageLib: Read
cmdline from QemuKernelLoaderFs", 2021-06-28) to have a single location in
which all of kernel/initrd/cmdline are fetched from QEMU.
- Use static linking of the two BlobVerifierLib implemenatations.
- Reorganize series.

v1: https://edk2.groups.io/g/devel/message/75567

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>

Dov Murik (8):
OvmfPkg/AmdSev: use GenericQemuLoadImageLib in AmdSev builds
OvmfPkg: add library class BlobVerifierLib with null implementation
OvmfPkg: add BlobVerifierLibNull to DSC
ArmVirtPkg: add BlobVerifierLibNull to DSC
OvmfPkg/QemuKernelLoaderFsDxe: call VerifyBlob after fetch from fw_cfg
OvmfPkg/AmdSev/SecretPei: build hob for full page
OvmfPkg/AmdSev: add BlobVerifierLibSevHashes
OvmfPkg/AmdSev: Enforce hash verification of kernel blobs

James Bottomley (3):
OvmfPkg/AmdSev/SecretDxe: fix header comment to generic naming
OvmfPkg: PlatformBootManagerLibGrub: Allow executing kernel via fw_cfg
OvmfPkg/AmdSev: reserve MEMFD space for for firmware config hashes

OvmfPkg/OvmfPkg.dec | 9 +
ArmVirtPkg/ArmVirtQemu.dsc | 5 +-
ArmVirtPkg/ArmVirtQemuKernel.dsc | 5 +-
OvmfPkg/AmdSev/AmdSevX64.dsc | 9 +-
OvmfPkg/OvmfPkgIa32.dsc | 5 +-
OvmfPkg/OvmfPkgIa32X64.dsc | 5 +-
OvmfPkg/OvmfPkgX64.dsc | 5 +-
OvmfPkg/AmdSev/AmdSevX64.fdf | 5 +-
OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashes.inf | 37 ++++
OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf | 24 +++
OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManagerLibGrub.inf | 2 +
OvmfPkg/ResetVector/ResetVector.inf | 2 +
OvmfPkg/Include/Library/BlobVerifierLib.h | 38 ++++
OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.h | 11 ++
OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierSevHashes.c | 202 ++++++++++++++++++++
OvmfPkg/AmdSev/SecretDxe/SecretDxe.c | 2 +-
OvmfPkg/AmdSev/SecretPei/SecretPei.c | 3 +-
OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierNull.c | 33 ++++
OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c | 5 +
OvmfPkg/Library/{PlatformBootManagerLib => PlatformBootManagerLibGrub}/QemuKernel.c | 0
OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 9 +
OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 20 ++
OvmfPkg/ResetVector/ResetVector.nasmb | 2 +
23 files changed, 428 insertions(+), 10 deletions(-)
create mode 100644 OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashes.inf
create mode 100644 OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf
create mode 100644 OvmfPkg/Include/Library/BlobVerifierLib.h
create mode 100644 OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierSevHashes.c
create mode 100644 OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierNull.c
copy OvmfPkg/Library/{PlatformBootManagerLib => PlatformBootManagerLibGrub}/QemuKernel.c (100%)

--
2.25.1


[PATCH v5 10/11] OvmfPkg/AmdSev: add BlobVerifierLibSevHashes

Dov Murik
 

Add an implementation for BlobVerifierLib that locates the SEV hashes
table and verifies that the calculated hashes of the kernel, initrd, and
cmdline blobs indeed match the expected hashes stated in the hashes
table.

If there's a missing hash or a hash mismatch then EFI_ACCESS_DENIED is
returned which will cause a failure to load a kernel image.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Co-developed-by: James Bottomley <jejb@linux.ibm.com>
Signed-off-by: James Bottomley <jejb@linux.ibm.com>
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
---
OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashes.inf | 37=
++++
OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierSevHashes.c | 202=
++++++++++++++++++++
2 files changed, 239 insertions(+)

diff --git a/OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHash=
es.inf b/OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashes.i=
nf
new file mode 100644
index 000000000000..76ca0b8154ce
--- /dev/null
+++ b/OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierLibSevHashes.inf
@@ -0,0 +1,37 @@
+## @file=0D
+#=0D
+# Blob verifier library that uses SEV hashes table. The hashes table hol=
ds the=0D
+# allowed hashes of the kernel, initrd, and cmdline blobs.=0D
+#=0D
+# Copyright (C) 2021, IBM Corp=0D
+#=0D
+# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+#=0D
+##=0D
+=0D
+[Defines]=0D
+ INF_VERSION =3D 1.29=0D
+ BASE_NAME =3D BlobVerifierLibSevHashes=0D
+ FILE_GUID =3D 59e713b5-eff3-46a7-8d8b-46f4c004ad7b=
=0D
+ MODULE_TYPE =3D BASE=0D
+ VERSION_STRING =3D 1.0=0D
+ LIBRARY_CLASS =3D BlobVerifierLib=0D
+ CONSTRUCTOR =3D BlobVerifierLibSevHashesConstructor=0D
+=0D
+[Sources]=0D
+ BlobVerifierSevHashes.c=0D
+=0D
+[Packages]=0D
+ CryptoPkg/CryptoPkg.dec=0D
+ MdePkg/MdePkg.dec=0D
+ OvmfPkg/OvmfPkg.dec=0D
+=0D
+[LibraryClasses]=0D
+ BaseCryptLib=0D
+ BaseMemoryLib=0D
+ DebugLib=0D
+ PcdLib=0D
+=0D
+[FixedPcd]=0D
+ gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase=0D
+ gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize=0D
diff --git a/OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierSevHashes.=
c b/OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierSevHashes.c
new file mode 100644
index 000000000000..b9054879b07f
--- /dev/null
+++ b/OvmfPkg/AmdSev/BlobVerifierLibSevHashes/BlobVerifierSevHashes.c
@@ -0,0 +1,202 @@
+/** @file=0D
+=0D
+ Blob verifier library that uses SEV hashes table. The hashes table hold=
s the=0D
+ allowed hashes of the kernel, initrd, and cmdline blobs.=0D
+=0D
+ Copyright (C) 2021, IBM Corporation=0D
+=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+**/=0D
+=0D
+#include <Library/BaseCryptLib.h>=0D
+#include <Library/BaseLib.h>=0D
+#include <Library/BaseMemoryLib.h>=0D
+#include <Library/DebugLib.h>=0D
+#include <Library/BlobVerifierLib.h>=0D
+=0D
+/**=0D
+ The SEV Hashes table must be in encrypted memory and has the table=0D
+ and its entries described by=0D
+=0D
+ <GUID>|UINT16 <len>|<data>=0D
+=0D
+ With the whole table GUID being 9438d606-4f22-4cc9-b479-a793d411fd21=0D
+=0D
+ The current possible table entries are for the kernel, the initrd=0D
+ and the cmdline:=0D
+=0D
+ 4de79437-abd2-427f-b835-d5b172d2045b kernel=0D
+ 44baf731-3a2f-4bd7-9af1-41e29169781d initrd=0D
+ 97d02dd8-bd20-4c94-aa78-e7714d36ab2a cmdline=0D
+=0D
+ The size of the entry is used to identify the hash, but the=0D
+ expectation is that it will be 32 bytes of SHA-256.=0D
+**/=0D
+=0D
+#define SEV_HASH_TABLE_GUID \=0D
+ (GUID) { 0x9438d606, 0x4f22, 0x4cc9, { 0xb4, 0x79, 0xa7, 0x93, 0xd4, 0x1=
1, 0xfd, 0x21 } }=0D
+#define SEV_KERNEL_HASH_GUID \=0D
+ (GUID) { 0x4de79437, 0xabd2, 0x427f, { 0xb8, 0x35, 0xd5, 0xb1, 0x72, 0xd=
2, 0x04, 0x5b } }=0D
+#define SEV_INITRD_HASH_GUID \=0D
+ (GUID) { 0x44baf731, 0x3a2f, 0x4bd7, { 0x9a, 0xf1, 0x41, 0xe2, 0x91, 0x6=
9, 0x78, 0x1d } }=0D
+#define SEV_CMDLINE_HASH_GUID \=0D
+ (GUID) { 0x97d02dd8, 0xbd20, 0x4c94, { 0xaa, 0x78, 0xe7, 0x71, 0x4d, 0x3=
6, 0xab, 0x2a } }=0D
+=0D
+STATIC CONST EFI_GUID mSevKernelHashGuid =3D SEV_KERNEL_HASH_GUID;=0D
+STATIC CONST EFI_GUID mSevInitrdHashGuid =3D SEV_INITRD_HASH_GUID;=0D
+STATIC CONST EFI_GUID mSevCmdlineHashGuid =3D SEV_CMDLINE_HASH_GUID;=0D
+=0D
+#pragma pack (1)=0D
+typedef struct {=0D
+ GUID Guid;=0D
+ UINT16 Len;=0D
+ UINT8 Data[];=0D
+} HASH_TABLE;=0D
+#pragma pack ()=0D
+=0D
+STATIC HASH_TABLE *mHashesTable;=0D
+STATIC UINT16 mHashesTableSize;=0D
+=0D
+STATIC=0D
+CONST GUID*=0D
+FindBlobEntryGuid (=0D
+ IN CONST CHAR16 *BlobName=0D
+ )=0D
+{=0D
+ if (StrCmp (BlobName, L"kernel") =3D=3D 0) {=0D
+ return &mSevKernelHashGuid;=0D
+ } else if (StrCmp (BlobName, L"initrd") =3D=3D 0) {=0D
+ return &mSevInitrdHashGuid;=0D
+ } else if (StrCmp (BlobName, L"cmdline") =3D=3D 0) {=0D
+ return &mSevCmdlineHashGuid;=0D
+ } else {=0D
+ return NULL;=0D
+ }=0D
+}=0D
+=0D
+/**=0D
+ Verify blob from an external source.=0D
+=0D
+ @param[in] BlobName The name of the blob=0D
+ @param[in] Buf The data of the blob=0D
+ @param[in] BufSize The size of the blob in bytes=0D
+=0D
+ @retval EFI_SUCCESS The blob was verified successfully.=0D
+ @retval EFI_ACCESS_DENIED The blob could not be verified, and theref=
ore=0D
+ should be considered non-secure.=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+VerifyBlob (=0D
+ IN CONST CHAR16 *BlobName,=0D
+ IN CONST VOID *Buf,=0D
+ IN UINT32 BufSize=0D
+ )=0D
+{=0D
+ CONST GUID *Guid;=0D
+ INT32 Remaining;=0D
+ HASH_TABLE *Entry;=0D
+=0D
+ if (mHashesTable =3D=3D NULL || mHashesTableSize =3D=3D 0) {=0D
+ DEBUG ((DEBUG_ERROR,=0D
+ "%a: Verifier called but no hashes table discoverd in MEMFD\n",=0D
+ __FUNCTION__));=0D
+ return EFI_ACCESS_DENIED;=0D
+ }=0D
+=0D
+ Guid =3D FindBlobEntryGuid (BlobName);=0D
+ if (Guid =3D=3D NULL) {=0D
+ DEBUG ((DEBUG_ERROR, "%a: Unknown blob name \"%s\"\n", __FUNCTION__,=0D
+ BlobName));=0D
+ return EFI_ACCESS_DENIED;=0D
+ }=0D
+=0D
+ //=0D
+ // Remaining is INT32 to catch underflow in case Entry->Len has a=0D
+ // very high UINT16 value=0D
+ //=0D
+ for (Entry =3D mHashesTable, Remaining =3D mHashesTableSize;=0D
+ Remaining >=3D sizeof *Entry && Remaining >=3D Entry->Len;=0D
+ Remaining -=3D Entry->Len,=0D
+ Entry =3D (HASH_TABLE *)((UINT8 *)Entry + Entry->Len)) {=0D
+ UINTN EntrySize;=0D
+ EFI_STATUS Status;=0D
+ UINT8 Hash[SHA256_DIGEST_SIZE];=0D
+=0D
+ if (!CompareGuid (&Entry->Guid, Guid)) {=0D
+ continue;=0D
+ }=0D
+=0D
+ DEBUG ((DEBUG_INFO, "%a: Found GUID %g in table\n", __FUNCTION__, Guid=
));=0D
+=0D
+ EntrySize =3D Entry->Len - sizeof Entry->Guid - sizeof Entry->Len;=0D
+ if (EntrySize !=3D SHA256_DIGEST_SIZE) {=0D
+ DEBUG ((DEBUG_ERROR, "%a: Hash has the wrong size %d !=3D %d\n",=0D
+ __FUNCTION__, EntrySize, SHA256_DIGEST_SIZE));=0D
+ return EFI_ACCESS_DENIED;=0D
+ }=0D
+=0D
+ //=0D
+ // Calculate the buffer's hash and verify that it is identical to the=
=0D
+ // expected hash table entry=0D
+ //=0D
+ Sha256HashAll (Buf, BufSize, Hash);=0D
+=0D
+ if (CompareMem (Entry->Data, Hash, EntrySize) =3D=3D 0) {=0D
+ Status =3D EFI_SUCCESS;=0D
+ DEBUG ((DEBUG_INFO, "%a: Hash comparison succeeded for \"%s\"\n",=0D
+ __FUNCTION__, BlobName));=0D
+ } else {=0D
+ Status =3D EFI_ACCESS_DENIED;=0D
+ DEBUG ((DEBUG_ERROR, "%a: Hash comparison failed for \"%s\"\n",=0D
+ __FUNCTION__, BlobName));=0D
+ }=0D
+ return Status;=0D
+ }=0D
+=0D
+ DEBUG ((DEBUG_ERROR, "%a: Hash GUID %g not found in table\n", __FUNCTION=
__,=0D
+ Guid));=0D
+ return EFI_ACCESS_DENIED;=0D
+}=0D
+=0D
+/**=0D
+ Locate the SEV hashes table.=0D
+=0D
+ This function always returns success, even if the table can't be found. =
The=0D
+ subsequent VerifyBlob calls will fail if no table was found.=0D
+=0D
+ @retval RETURN_SUCCESS The hashes table is set up correctly, or there =
is no=0D
+ hashes table=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+BlobVerifierLibSevHashesConstructor (=0D
+ VOID=0D
+ )=0D
+{=0D
+ HASH_TABLE *Ptr;=0D
+ UINT32 Size;=0D
+=0D
+ mHashesTable =3D NULL;=0D
+ mHashesTableSize =3D 0;=0D
+=0D
+ Ptr =3D (void *)(UINTN)FixedPcdGet64 (PcdQemuHashTableBase);=0D
+ Size =3D FixedPcdGet32 (PcdQemuHashTableSize);=0D
+=0D
+ if (Ptr =3D=3D NULL || Size < sizeof *Ptr ||=0D
+ !CompareGuid (&Ptr->Guid, &SEV_HASH_TABLE_GUID) ||=0D
+ Ptr->Len < sizeof *Ptr || Ptr->Len > Size) {=0D
+ return RETURN_SUCCESS;=0D
+ }=0D
+=0D
+ DEBUG ((DEBUG_INFO, "%a: Found injected hashes table in secure location\=
n",=0D
+ __FUNCTION__));=0D
+=0D
+ mHashesTable =3D (HASH_TABLE *)Ptr->Data;=0D
+ mHashesTableSize =3D Ptr->Len - sizeof Ptr->Guid - sizeof Ptr->Len;=0D
+=0D
+ DEBUG ((DEBUG_VERBOSE, "%a: mHashesTable=3D0x%p, Size=3D%u\n", __FUNCTIO=
N__,=0D
+ mHashesTable, mHashesTableSize));=0D
+=0D
+ return RETURN_SUCCESS;=0D
+}=0D
--=20
2.25.1


[PATCH v5 05/11] OvmfPkg: add BlobVerifierLibNull to DSC

Dov Murik
 

This prepares the ground for calling VerifyBlob() in
QemuKernelLoaderFsDxe.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
---
OvmfPkg/AmdSev/AmdSevX64.dsc | 6 +++++-
OvmfPkg/OvmfPkgIa32.dsc | 5 ++++-
OvmfPkg/OvmfPkgIa32X64.dsc | 5 ++++-
OvmfPkg/OvmfPkgX64.dsc | 5 ++++-
4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index aefdcf881c99..db8bd59579b9 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -173,6 +173,7 @@ [LibraryClasses]
LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf=0D
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize=
dDisplayLib.inf=0D
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL=
ib.inf=0D
+ BlobVerifierLib|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.=
inf=0D
=0D
!if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE=0D
PeCoffExtraActionLib|SourceLevelDebugPkg/Library/PeCoffExtraActionLibDeb=
ug/PeCoffExtraActionLibDebug.inf=0D
@@ -693,7 +694,10 @@ [Components]
NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf=0D
NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc=
eManagerUiLib.inf=0D
}=0D
- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf=0D
+ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf {=0D
+ <LibraryClasses>=0D
+ NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf=0D
+ }=0D
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf=0D
OvmfPkg/Virtio10Dxe/Virtio10.inf=0D
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf=0D
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index f53efeae7986..799a974cf21a 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -786,7 +786,10 @@ [Components]
NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf=0D
!endif=0D
}=0D
- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf=0D
+ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf {=0D
+ <LibraryClasses>=0D
+ NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf=0D
+ }=0D
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf=0D
OvmfPkg/Virtio10Dxe/Virtio10.inf=0D
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf=0D
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index b3662e17f256..66ad5dc70cee 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -800,7 +800,10 @@ [Components.X64]
NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf=0D
!endif=0D
}=0D
- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf=0D
+ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf {=0D
+ <LibraryClasses>=0D
+ NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf=0D
+ }=0D
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf=0D
OvmfPkg/Virtio10Dxe/Virtio10.inf=0D
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf=0D
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 0a237a905866..180565a100c5 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -798,7 +798,10 @@ [Components]
NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf=0D
!endif=0D
}=0D
- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf=0D
+ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf {=0D
+ <LibraryClasses>=0D
+ NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf=0D
+ }=0D
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf=0D
OvmfPkg/Virtio10Dxe/Virtio10.inf=0D
OvmfPkg/VirtioBlkDxe/VirtioBlk.inf=0D
--=20
2.25.1


[PATCH v5 03/11] OvmfPkg: PlatformBootManagerLibGrub: Allow executing kernel via fw_cfg

Dov Murik
 

From: James Bottomley <jejb@linux.ibm.com>

Support QEMU's -kernel option.

Create a QemuKernel.c for PlatformBootManagerLibGrub
which is an exact copy of the file
PlatformBootManagerLib/QemuKernel.c .

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3457
Signed-off-by: James Bottomley <jejb@linux.ibm.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
---
OvmfPkg/AmdSev/AmdSevX64.dsc =
| 1 +
OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManagerLibGrub.inf =
| 2 ++
OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.h =
| 11 +++++++++++
OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c =
| 5 +++++
OvmfPkg/Library/{PlatformBootManagerLib =3D> PlatformBootManagerLibGrub}/Q=
emuKernel.c | 0
5 files changed, 19 insertions(+)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index a2f1324c40a6..aefdcf881c99 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -281,6 +281,7 @@ [LibraryClasses.common.PEIM]
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuE=
xceptionHandlerLib.inf=0D
MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf=0D
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf=
=0D
+ QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad=
ImageLib.inf=0D
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf=0D
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf=0D
=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManager=
LibGrub.inf b/OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManage=
rLibGrub.inf
index 9a806d17ec45..5f6f73d18470 100644
--- a/OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManagerLibGrub=
.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManagerLibGrub=
.inf
@@ -23,6 +23,7 @@ [Defines]
=0D
[Sources]=0D
BdsPlatform.c=0D
+ QemuKernel.c=0D
PlatformData.c=0D
BdsPlatform.h=0D
=0D
@@ -46,6 +47,7 @@ [LibraryClasses]
BootLogoLib=0D
DevicePathLib=0D
PciLib=0D
+ QemuLoadImageLib=0D
UefiLib=0D
PlatformBmPrintScLib=0D
Tcg2PhysicalPresenceLib=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.h b/Ovm=
fPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.h
index 748c63081920..f1d3a2906c00 100644
--- a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.h
+++ b/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.h
@@ -172,4 +172,15 @@ PlatformInitializeConsole (
IN PLATFORM_CONSOLE_CONNECT_ENTRY *PlatformConsole=0D
);=0D
=0D
+/**=0D
+ Loads and boots UEFI Linux via the FwCfg interface.=0D
+=0D
+ @retval EFI_NOT_FOUND - The Linux kernel was not found=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+TryRunningQemuKernel (=0D
+ VOID=0D
+ );=0D
+=0D
#endif // _PLATFORM_SPECIFIC_BDS_PLATFORM_H_=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c b/Ovm=
fPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
index 5c92d4fc2b09..7cceeea4879c 100644
--- a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
@@ -1315,6 +1315,11 @@ PlatformBootManagerAfterConsole (
//=0D
Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
=0D
+ //=0D
+ // Process QEMU's -kernel command line option=0D
+ //=0D
+ TryRunningQemuKernel ();=0D
+=0D
//=0D
// Perform some platform specific connect sequence=0D
//=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c b/OvmfPkg/=
Library/PlatformBootManagerLibGrub/QemuKernel.c
similarity index 100%
copy from OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c
copy to OvmfPkg/Library/PlatformBootManagerLibGrub/QemuKernel.c
--=20
2.25.1

5841 - 5860 of 84031