* [edk2-devel] [PATCH] OvmfPkg/BaseMemEncryptTdxLib: Make SetOrClearSharedBit() handle retry error
@ 2023-08-02 21:09 Isaku Yamahata
2023-08-04 6:29 ` Min Xu
0 siblings, 1 reply; 2+ messages in thread
From: Isaku Yamahata @ 2023-08-02 21:09 UTC (permalink / raw)
To: devel; +Cc: isaku.yamahata, isaku.yamahata, Jiewen Yao, Min Xu
From: Isaku Yamahata <isaku.yamahata@intel.com>
TDG.VP.VMCALL<MAPGPA> can return TDG.VP.VMCALL_RETRY when the length is too
large so that VMM can avoid too long processing time. The caller should
retry with the updated starting GPA on the error. Add check
TDG.VP.VMCALL_RETRY check.
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
MdePkg/Include/IndustryStandard/Tdx.h | 4 ++++
MdePkg/Library/BaseLib/X64/TdVmcall.nasm | 4 +---
.../Library/BaseMemEncryptTdxLib/MemoryEncryption.c | 10 ++++++++--
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/MdePkg/Include/IndustryStandard/Tdx.h b/MdePkg/Include/IndustryStandard/Tdx.h
index 81df1361842b..4ea2960a70f9 100644
--- a/MdePkg/Include/IndustryStandard/Tdx.h
+++ b/MdePkg/Include/IndustryStandard/Tdx.h
@@ -103,6 +103,10 @@
#define TDVMCALL_REPORT_FATAL_ERR 0x10003
#define TDVMCALL_SETUP_EVENT_NOTIFY 0x10004
+// TDVMCALL API sub-function Completion Status Codes
+#define TDG_VP_VMCALL_SUCCESS 0x0000000000000000
+#define TDG_VP_VMCALL_RETRY 0x0000000000000001
+
#pragma pack(1)
typedef struct {
UINT64 Data[6];
diff --git a/MdePkg/Library/BaseLib/X64/TdVmcall.nasm b/MdePkg/Library/BaseLib/X64/TdVmcall.nasm
index 5ecc10b17193..8dd9bfcbfa14 100644
--- a/MdePkg/Library/BaseLib/X64/TdVmcall.nasm
+++ b/MdePkg/Library/BaseLib/X64/TdVmcall.nasm
@@ -133,9 +133,7 @@ ASM_PFX(TdVmCall):
test r9, r9
jz .no_return_data
- ; On success, propagate TDVMCALL output value to output param
- test rax, rax
- jnz .no_return_data
+ ; Propagate TDVMCALL output value to output param
mov [r9], r11
.no_return_data:
tdcall_regs_postamble
diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
index a01dc98852b8..d55c2a34a44e 100644
--- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
+++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
@@ -526,6 +526,8 @@ SetOrClearSharedBit (
UINT64 TdStatus;
EFI_STATUS Status;
EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;
+ PHYSICAL_ADDRESS TmpPhysicalAddress;
+ UINT64 TmpLength;
AddressEncMask = GetMemEncryptionAddressMask ();
@@ -540,8 +542,12 @@ SetOrClearSharedBit (
PhysicalAddress &= ~AddressEncMask;
}
- TdStatus = TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, 0, NULL);
- if (TdStatus != 0) {
+ TmpPhysicalAddress = PhysicalAddress;
+ do {
+ TmpLength = PhysicalAddress + Length - TmpPhysicalAddress;
+ TdStatus = TdVmCall (TDVMCALL_MAPGPA, TmpPhysicalAddress, TmpLength, 0, 0, &TmpPhysicalAddress);
+ } while (TdStatus == TDG_VP_VMCALL_RETRY);
+ if (TdStatus != TDG_VP_VMCALL_SUCCESS) {
DEBUG ((DEBUG_ERROR, "%a: TdVmcall(MAPGPA) failed with %llx\n", __func__, TdStatus));
ASSERT (FALSE);
return EFI_DEVICE_ERROR;
base-commit: 677f2c6f1509da21258e02957b869b71b008fc61
--
2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107477): https://edk2.groups.io/g/devel/message/107477
Mute This Topic: https://groups.io/mt/100514591/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [edk2-devel] [PATCH] OvmfPkg/BaseMemEncryptTdxLib: Make SetOrClearSharedBit() handle retry error
2023-08-02 21:09 [edk2-devel] [PATCH] OvmfPkg/BaseMemEncryptTdxLib: Make SetOrClearSharedBit() handle retry error Isaku Yamahata
@ 2023-08-04 6:29 ` Min Xu
0 siblings, 0 replies; 2+ messages in thread
From: Min Xu @ 2023-08-04 6:29 UTC (permalink / raw)
To: Yamahata, Isaku, devel@edk2.groups.io
Cc: isaku.yamahata@gmail.com, Yao, Jiewen
Reviewed-by: Min Xu <min.m.xu@intel.com>
> -----Original Message-----
> From: Yamahata, Isaku <isaku.yamahata@intel.com>
> Sent: Thursday, August 3, 2023 5:09 AM
> To: devel@edk2.groups.io
> Cc: isaku.yamahata@gmail.com; Yamahata, Isaku
> <isaku.yamahata@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Xu, Min
> M <min.m.xu@intel.com>
> Subject: [PATCH] OvmfPkg/BaseMemEncryptTdxLib: Make
> SetOrClearSharedBit() handle retry error
>
> From: Isaku Yamahata <isaku.yamahata@intel.com>
>
> TDG.VP.VMCALL<MAPGPA> can return TDG.VP.VMCALL_RETRY when the
> length is too large so that VMM can avoid too long processing time. The
> caller should retry with the updated starting GPA on the error. Add check
> TDG.VP.VMCALL_RETRY check.
>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
> ---
> MdePkg/Include/IndustryStandard/Tdx.h | 4 ++++
> MdePkg/Library/BaseLib/X64/TdVmcall.nasm | 4 +---
> .../Library/BaseMemEncryptTdxLib/MemoryEncryption.c | 10 ++++++++--
> 3 files changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/MdePkg/Include/IndustryStandard/Tdx.h
> b/MdePkg/Include/IndustryStandard/Tdx.h
> index 81df1361842b..4ea2960a70f9 100644
> --- a/MdePkg/Include/IndustryStandard/Tdx.h
> +++ b/MdePkg/Include/IndustryStandard/Tdx.h
> @@ -103,6 +103,10 @@
> #define TDVMCALL_REPORT_FATAL_ERR 0x10003 #define
> TDVMCALL_SETUP_EVENT_NOTIFY 0x10004 +// TDVMCALL API sub-function
> Completion Status Codes+#define TDG_VP_VMCALL_SUCCESS
> 0x0000000000000000+#define TDG_VP_VMCALL_RETRY
> 0x0000000000000001+ #pragma pack(1) typedef struct { UINT64
> Data[6];diff --git a/MdePkg/Library/BaseLib/X64/TdVmcall.nasm
> b/MdePkg/Library/BaseLib/X64/TdVmcall.nasm
> index 5ecc10b17193..8dd9bfcbfa14 100644
> --- a/MdePkg/Library/BaseLib/X64/TdVmcall.nasm
> +++ b/MdePkg/Library/BaseLib/X64/TdVmcall.nasm
> @@ -133,9 +133,7 @@ ASM_PFX(TdVmCall):
> test r9, r9 jz .no_return_data - ; On success, propagate
> TDVMCALL output value to output param- test rax, rax-
> jnz .no_return_data+ ; Propagate TDVMCALL output value to output
> param mov [r9], r11 .no_return_data: tdcall_regs_postamblediff --git
> a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
> b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
> index a01dc98852b8..d55c2a34a44e 100644
> --- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
> +++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
> @@ -526,6 +526,8 @@ SetOrClearSharedBit (
> UINT64 TdStatus; EFI_STATUS Status;
> EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;+
> PHYSICAL_ADDRESS TmpPhysicalAddress;+ UINT64
> TmpLength; AddressEncMask = GetMemEncryptionAddressMask (); @@ -
> 540,8 +542,12 @@ SetOrClearSharedBit (
> PhysicalAddress &= ~AddressEncMask; } - TdStatus = TdVmCall
> (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, 0, NULL);- if (TdStatus !=
> 0) {+ TmpPhysicalAddress = PhysicalAddress;+ do {+ TmpLength =
> PhysicalAddress + Length - TmpPhysicalAddress;+ TdStatus = TdVmCall
> (TDVMCALL_MAPGPA, TmpPhysicalAddress, TmpLength, 0, 0,
> &TmpPhysicalAddress);+ } while (TdStatus == TDG_VP_VMCALL_RETRY);+ if
> (TdStatus != TDG_VP_VMCALL_SUCCESS) { DEBUG ((DEBUG_ERROR, "%a:
> TdVmcall(MAPGPA) failed with %llx\n", __func__, TdStatus)); ASSERT
> (FALSE); return EFI_DEVICE_ERROR;
> base-commit: 677f2c6f1509da21258e02957b869b71b008fc61
> --
> 2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107562): https://edk2.groups.io/g/devel/message/107562
Mute This Topic: https://groups.io/mt/100514591/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-04 6:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-02 21:09 [edk2-devel] [PATCH] OvmfPkg/BaseMemEncryptTdxLib: Make SetOrClearSharedBit() handle retry error Isaku Yamahata
2023-08-04 6:29 ` Min Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox