The Section A2.1.3 Realm attributes, RMM Specification, version A-bet0 introduces the concept of REMs as described below: DGRFCS - A Realm Extensible Measurement (REM) is a measurement value which can be extended during the lifetime of a Realm. IFMPYL - Attributes of a Realm include an array of measurement values. The first entry in this array is a RIM. The remaining entries in this array are REMs.
The Realm Service Interface commands defined in section B4.3.7 RSI_MEASUREMENT_READ and B4.3.6 RSI_MEASUREMENT_EXTEND specify the interfaces to read and extend measurements to REMs. Therefore, update ArmCcaRsiLib to add interfaces to get and extend REMs. Signed-off-by: Sami Mujawar <sami.muja...@arm.com> --- ArmVirtPkg/Include/Library/ArmCcaRsiLib.h | 53 ++++++++++++ ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h | 2 + ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c | 91 ++++++++++++++++++++ 3 files changed, 146 insertions(+) diff --git a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h index fe176d83c4b11d3f7bb35c97ec8ef00a4f47f981..51527071ab87aa82efa9ddc3064bb88803d5ba13 100644 --- a/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h +++ b/ArmVirtPkg/Include/Library/ArmCcaRsiLib.h @@ -7,6 +7,8 @@ - Rsi or RSI - Realm Service Interface - IPA - Intermediate Physical Address - RIPAS - Realm IPA state + - RIM - Realm Initial Measurement + - REM - Realm Extensible Measurement @par Reference(s): - Realm Management Monitor (RMM) Specification, version A-bet0 @@ -44,6 +46,21 @@ */ #define MIN_CHALLENGE_DATA_SIZE_BITS 256 +/* Maximum measurement data size in bytes. + See Section C1.11 RmmRealmMeasurement type, RMM Specification, version A-bet0 + The width of the RmmRealmMeasurement type is 512 bits. +*/ +#define MAX_MEASUREMENT_DATA_SIZE_BYTES 64 + +/* Minimum and Maximum indices for REMs + See Section A2.1.3 Realm attributes, RMM Specification, version A-bet0 + IFMPYL - Attributes of a Realm include an array of measurement values. The + first entry in this array is a RIM. The remaining entries in this array are + REMs. +*/ +#define MIN_REM_INDEX 1 +#define MAX_REM_INDEX 4 + /** An enum describing the RSI RIPAS. See Section A5.2.2 Realm IPA state, RMM Specification, version A-bet0 */ @@ -127,6 +144,42 @@ RsiSetIpaState ( IN RIPAS State ); +/** + Extends a measurement to a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [in] Measurement Pointer to the measurement buffer. + @param [in] MeasurementSize Size of the measurement data. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiExtendMeasurement ( + IN UINTN MeasurementIndex, + IN CONST UINT8 *CONST Measurement, + IN UINTN MeasurementSize + ); + +/** + Read the measurement value from a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [out] MeasurementBuffer Pointer to store the measurement data. + @param [in] MeasurementBufferSize Size of the measurement buffer. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiReadMeasurement ( + IN UINTN MeasurementIndex, + OUT UINT8 *CONST MeasurementBuffer, + IN UINTN MeasurementBufferSize + ); + /** Read the Realm Configuration. diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h index 325234d06695befc840dcf37e951130dfe0550c3..6f0ee3061ade5a4a99b717a52d5a241e0e446270 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsi.h @@ -22,6 +22,8 @@ #define FID_RSI_ATTESTATION_TOKEN_INIT 0xC4000194 #define FID_RSI_IPA_STATE_GET 0xC4000198 #define FID_RSI_IPA_STATE_SET 0xC4000197 +#define FID_RSI_MEASUREMENT_EXTEND 0xC4000193 +#define FID_RSI_MEASUREMENT_READ 0xC4000192 #define FID_RSI_REALM_CONFIG 0xC4000196 #define FID_RSI_VERSION 0xC4000190 diff --git a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c index 01ecee3a6798c0e5cefd9fb4f48788d3063c94cd..fd29fc61caf880bcaf96d982f3a4d973e7ebb70f 100644 --- a/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c +++ b/ArmVirtPkg/Library/ArmCcaRsiLib/ArmCcaRsiLib.c @@ -8,6 +8,7 @@ - Rsi or RSI - Realm Service Interface - IPA - Intermediate Physical Address - RIPAS - Realm IPA state + - REM - Realm Extensible Measurement @par Reference(s): - Realm Management Monitor (RMM) Specification, version A-bet0 @@ -366,6 +367,96 @@ RsiSetIpaState ( return Status; } +/** + Extends a measurement to a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [in] Measurement Pointer to the measurement buffer. + @param [in] MeasurementSize Size of the measurement data. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiExtendMeasurement ( + IN UINTN MeasurementIndex, + IN CONST UINT8 *CONST Measurement, + IN UINTN MeasurementSize + ) +{ + ARM_SMC_ARGS SmcCmd; + UINT64 *Data64; + + if ((MeasurementIndex < MIN_REM_INDEX) || + (MeasurementIndex > MAX_REM_INDEX) || + (Measurement == NULL) || + (MeasurementSize == 0) || + (MeasurementSize > MAX_MEASUREMENT_DATA_SIZE_BYTES)) + { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + + SmcCmd.Arg0 = FID_RSI_MEASUREMENT_EXTEND; + SmcCmd.Arg1 = MeasurementIndex; + SmcCmd.Arg2 = MeasurementSize; + + Data64 = &SmcCmd.Arg3; + CopyMem (Data64, Measurement, MeasurementSize); + + ArmCallSmc (&SmcCmd); + return RsiCmdStatusToEfiStatus (SmcCmd.Arg0); +} + +/** + Read the measurement value from a REM. + + @param [in] MeasurementIndex Index of the REM. + @param [out] MeasurementBuffer Pointer to store the measurement data. + @param [in] MeasurementBufferSize Size of the measurement buffer. + + @retval RETURN_SUCCESS Success. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. +**/ +RETURN_STATUS +EFIAPI +RsiReadMeasurement ( + IN UINTN MeasurementIndex, + OUT UINT8 *CONST MeasurementBuffer, + IN UINTN MeasurementBufferSize + ) +{ + RETURN_STATUS Status; + ARM_SMC_ARGS SmcCmd; + UINT64 *Data64; + + if ((MeasurementIndex < MIN_REM_INDEX) || + (MeasurementIndex > MAX_REM_INDEX) || + (MeasurementBuffer == NULL)) + { + return RETURN_INVALID_PARAMETER; + } + + if (MeasurementBufferSize < MAX_MEASUREMENT_DATA_SIZE_BYTES) { + return RETURN_BUFFER_TOO_SMALL; + } + + ZeroMem (&SmcCmd, sizeof (SmcCmd)); + SmcCmd.Arg0 = FID_RSI_MEASUREMENT_READ; + SmcCmd.Arg1 = MeasurementIndex; + + ArmCallSmc (&SmcCmd); + Status = RsiCmdStatusToEfiStatus (SmcCmd.Arg0); + if (!RETURN_ERROR (Status)) { + Data64 = &SmcCmd.Arg1; + CopyMem (MeasurementBuffer, Data64, MAX_MEASUREMENT_DATA_SIZE_BYTES); + } + + return Status; +} + /** Read the Realm Configuration. -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#103557): https://edk2.groups.io/g/devel/message/103557 Mute This Topic: https://groups.io/mt/98495961/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-