From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 145BDAC11DF for ; Wed, 2 Aug 2023 21:09:23 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=RCIyS10hd5duw0V3htAxE+cJKhfFezLeUBvJrRz9198=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1691010562; v=1; b=AoT53O7gXmD2V2q6PgGTYbqcuKt51b0DpCNnMZAhokImFxjsvqyeFQT9yAg3chZGmQPLfTsa TBkJ3aYFkEQYNeOokGNHJM0ORg6AdxIvAY/ygpOmK+4JnMET+h+eY+Nvudz3BCD4J07XG6AjR/X Q9jB+OvVfoO4AYuwZGPSHftU= X-Received: by 127.0.0.2 with SMTP id WXgiYY7687511xyTwlYnOgfz; Wed, 02 Aug 2023 14:09:22 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.8125.1691010561766581163 for ; Wed, 02 Aug 2023 14:09:22 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="369702987" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="369702987" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2023 14:09:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="764351629" X-IronPort-AV: E=Sophos;i="6.01,250,1684825200"; d="scan'208";a="764351629" X-Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2023 14:09:20 -0700 From: "Isaku Yamahata" To: devel@edk2.groups.io Cc: isaku.yamahata@gmail.com, isaku.yamahata@intel.com, Jiewen Yao , Min Xu Subject: [edk2-devel] [PATCH] OvmfPkg/BaseMemEncryptTdxLib: Make SetOrClearSharedBit() handle retry error Date: Wed, 2 Aug 2023 14:09:09 -0700 Message-Id: <448dd0fdd1ae9faa938e9b3649570ad2d30952a9.1691010366.git.isaku.yamahata@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,isaku.yamahata@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: SjNKpbNmZfmg1qurJMUGsCHux7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=AoT53O7g; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: Isaku Yamahata TDG.VP.VMCALL 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 --- 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/Industr= yStandard/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=0D #define TDVMCALL_SETUP_EVENT_NOTIFY 0x10004=0D =0D +// TDVMCALL API sub-function Completion Status Codes=0D +#define TDG_VP_VMCALL_SUCCESS 0x0000000000000000=0D +#define TDG_VP_VMCALL_RETRY 0x0000000000000001=0D +=0D #pragma pack(1)=0D typedef struct {=0D UINT64 Data[6];=0D diff --git a/MdePkg/Library/BaseLib/X64/TdVmcall.nasm b/MdePkg/Library/Base= Lib/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=0D jz .no_return_data=0D =0D - ; On success, propagate TDVMCALL output value to output param=0D - test rax, rax=0D - jnz .no_return_data=0D + ; Propagate TDVMCALL output value to output param=0D mov [r9], r11=0D .no_return_data:=0D tdcall_regs_postamble=0D diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c b/Ovmf= Pkg/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;=0D EFI_STATUS Status;=0D EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;=0D + PHYSICAL_ADDRESS TmpPhysicalAddress;=0D + UINT64 TmpLength;=0D =0D AddressEncMask =3D GetMemEncryptionAddressMask ();=0D =0D @@ -540,8 +542,12 @@ SetOrClearSharedBit ( PhysicalAddress &=3D ~AddressEncMask;=0D }=0D =0D - TdStatus =3D TdVmCall (TDVMCALL_MAPGPA, PhysicalAddress, Length, 0, 0, N= ULL);=0D - if (TdStatus !=3D 0) {=0D + TmpPhysicalAddress =3D PhysicalAddress;=0D + do {=0D + TmpLength =3D PhysicalAddress + Length - TmpPhysicalAddress;=0D + TdStatus =3D TdVmCall (TDVMCALL_MAPGPA, TmpPhysicalAddress, TmpLength,= 0, 0, &TmpPhysicalAddress);=0D + } while (TdStatus =3D=3D TDG_VP_VMCALL_RETRY);=0D + if (TdStatus !=3D TDG_VP_VMCALL_SUCCESS) {=0D DEBUG ((DEBUG_ERROR, "%a: TdVmcall(MAPGPA) failed with %llx\n", __func= __, TdStatus));=0D ASSERT (FALSE);=0D return EFI_DEVICE_ERROR;=0D base-commit: 677f2c6f1509da21258e02957b869b71b008fc61 --=20 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] -=-=-=-=-=-=-=-=-=-=-=-