From nobody Sun Feb 8 15:41:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+84715+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84715+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1639400272; cv=none; d=zohomail.com; s=zohoarc; b=cVlmeNWV47wtc/6IulMx6CGbv0ZRVXNMEE0aDgoG9bH9VzHIj7DTE4Gs13G2jcuoK/wPRfbkDzpHsy8VLuPNpOT4wzJ2BiKX1SJxXb62nmEc0BZMkFgrhv4iUAyu382lvkJk0qhFu+7sJBFVGYKforNK9IsOo48215QCH6fu3AI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639400272; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=IYWj2yswSrcQf/oy4pAc6bm58lxA64OCJiLR9HcoDUc=; b=jEByb8N3F4wt8Th7BjHKJj8G+0vxIizLdbMgH0fFImRaFEs3WN7yekM860KAPJ2NGTPq6KiE/PxJ4o3iQwbKpgjbQSDus5WtXxh5Zkx4mm4BnzVCq+KEGYq7SPcqHm6jEt6DvxBs22PXNMyPBBbOerX2b9SdeDFkC2n/fmNepbQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+84715+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1639400272071576.1166110044561; Mon, 13 Dec 2021 04:57:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Yg1JYY1788612x9Sw7jc3DxR; Mon, 13 Dec 2021 04:57:51 -0800 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web10.10693.1639400242692099801 for ; Mon, 13 Dec 2021 04:57:51 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10196"; a="238669332" X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="238669332" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2021 04:57:50 -0800 X-IronPort-AV: E=Sophos;i="5.88,202,1635231600"; d="scan'208";a="517738345" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.173.142]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2021 04:57:46 -0800 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Michael D Kinney , Liming Gao , Zhiguang Liu , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [edk2-devel] [PATCH V4 08/31] MdePkg: Support mmio for Tdx guest in BaseIoLibIntrinsic Date: Mon, 13 Dec 2021 20:56:39 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,min.m.xu@intel.com X-Gm-Message-State: kMiQ4tO14lkpnyM0eUfhQkN0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1639400271; bh=LL42hx0zsz+Qizfa85z/n4z+01xU6a67ln2SgtU7GRE=; h=Cc:Date:From:Reply-To:Subject:To; b=KpyfF90zZIT1vm3j+kBrJxzaTnC6ddvR8cHGsOszV0pYjTHJvHe0h7N37QscECBqAew SerO2HatToyY1ZAm/hI6/0SqS4doTsyplh0gyS5aBVxvjHdNTx9xHS09XPfxFzpBxorZa HdwBv0D5+pyFo+Yr+82MRhE0seYt6xoqceA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1639400274245100003 Content-Type: text/plain; charset="utf-8" RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3429 TDVF access MMIO with TDG.VP.VMCALL to invoke VMM provided emulation functions. If the access to MMIO fails, it fall backs to the direct access. BaseIoLibIntrinsic.inf is the IoLib used by other packages. It will not support I/O in Td guest. But some files are shared between BaseIoLibIntrinsic and BaseIoLibIntrinsicSev (IoLib.c is the example). So IoLibInternalTdxNull.c (which holds the null stub of the Td I/O routines) is included in BaseIoLibIntrinsic.inf. BaseIoLibIntrinsic.inf doesn't import TdxLib so that the Pkgs which include BaseIoLibIntrinsic.inf need not include TdxLib. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu Acked-by: Gerd Hoffmann --- .../BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf | 2 + .../BaseIoLibIntrinsicSev.inf | 3 + MdePkg/Library/BaseIoLibIntrinsic/IoLib.c | 81 +++++++++++++++++-- 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf b/Mde= Pkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf index 97eeada0656e..27b15d9ae256 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf @@ -34,6 +34,8 @@ IoLibMmioBuffer.c BaseIoLibIntrinsicInternal.h IoHighLevel.c + IoLibInternalTdxNull.c + IoLibTdx.h =20 [Sources.IA32] IoLibGcc.c | GCC diff --git a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf b/= MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf index 336d79736d9a..a74e54bee8b5 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf +++ b/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf @@ -30,17 +30,20 @@ IoLibMmioBuffer.c BaseIoLibIntrinsicInternal.h IoHighLevel.c + IoLibTdx.h =20 [Sources.IA32] IoLibGcc.c | GCC IoLibMsc.c | MSFT IoLib.c + IoLibInternalTdxNull.c Ia32/IoFifoSev.nasm =20 [Sources.X64] IoLibGcc.c | GCC IoLibMsc.c | MSFT IoLib.c + IoLibInternalTdx.c X64/IoFifoSev.nasm =20 [Packages] diff --git a/MdePkg/Library/BaseIoLibIntrinsic/IoLib.c b/MdePkg/Library/Bas= eIoLibIntrinsic/IoLib.c index 9d42e21a691c..5bd02b56a1fa 100644 --- a/MdePkg/Library/BaseIoLibIntrinsic/IoLib.c +++ b/MdePkg/Library/BaseIoLibIntrinsic/IoLib.c @@ -7,6 +7,7 @@ **/ =20 #include "BaseIoLibIntrinsicInternal.h" +#include "IoLibTdx.h" =20 /** Reads a 64-bit I/O port. @@ -69,6 +70,8 @@ IoWrite64 ( =20 If 8-bit MMIO register operations are not supported, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to read MMIO registers. + @param Address The MMIO register to read. =20 @return The value read. @@ -86,7 +89,13 @@ MmioRead8 ( Flag =3D FilterBeforeMmIoRead (FilterWidth8, Address, &Value); if (Flag) { MemoryFence (); - Value =3D *(volatile UINT8 *)Address; + + if (IsTdxGuest ()) { + Value =3D TdMmioRead8 (Address); + } else { + Value =3D *(volatile UINT8 *)Address; + } + MemoryFence (); } =20 @@ -104,6 +113,8 @@ MmioRead8 ( =20 If 8-bit MMIO register operations are not supported, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to write MMIO registers. + @param Address The MMIO register to write. @param Value The value to write to the MMIO register. =20 @@ -122,7 +133,13 @@ MmioWrite8 ( Flag =3D FilterBeforeMmIoWrite (FilterWidth8, Address, &Value); if (Flag) { MemoryFence (); - *(volatile UINT8 *)Address =3D Value; + + if (IsTdxGuest ()) { + TdMmioWrite8 (Address, Value); + } else { + *(volatile UINT8 *)Address =3D Value; + } + MemoryFence (); } =20 @@ -141,6 +158,8 @@ MmioWrite8 ( If 16-bit MMIO register operations are not supported, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to read MMIO registers. + @param Address The MMIO register to read. =20 @return The value read. @@ -159,7 +178,13 @@ MmioRead16 ( Flag =3D FilterBeforeMmIoRead (FilterWidth16, Address, &Value); if (Flag) { MemoryFence (); - Value =3D *(volatile UINT16 *)Address; + + if (IsTdxGuest ()) { + Value =3D TdMmioRead16 (Address); + } else { + Value =3D *(volatile UINT16 *)Address; + } + MemoryFence (); } =20 @@ -178,6 +203,8 @@ MmioRead16 ( If 16-bit MMIO register operations are not supported, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to write MMIO registers. + @param Address The MMIO register to write. @param Value The value to write to the MMIO register. =20 @@ -198,7 +225,13 @@ MmioWrite16 ( Flag =3D FilterBeforeMmIoWrite (FilterWidth16, Address, &Value); if (Flag) { MemoryFence (); - *(volatile UINT16 *)Address =3D Value; + + if (IsTdxGuest ()) { + TdMmioWrite16 (Address, Value); + } else { + *(volatile UINT16 *)Address =3D Value; + } + MemoryFence (); } =20 @@ -217,6 +250,8 @@ MmioWrite16 ( If 32-bit MMIO register operations are not supported, then ASSERT(). If Address is not aligned on a 32-bit boundary, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to read MMIO registers. + @param Address The MMIO register to read. =20 @return The value read. @@ -236,7 +271,13 @@ MmioRead32 ( Flag =3D FilterBeforeMmIoRead (FilterWidth32, Address, &Value); if (Flag) { MemoryFence (); - Value =3D *(volatile UINT32 *)Address; + + if (IsTdxGuest ()) { + Value =3D TdMmioRead32 (Address); + } else { + Value =3D *(volatile UINT32 *)Address; + } + MemoryFence (); } =20 @@ -255,6 +296,8 @@ MmioRead32 ( If 32-bit MMIO register operations are not supported, then ASSERT(). If Address is not aligned on a 32-bit boundary, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to write MMIO registers. + @param Address The MMIO register to write. @param Value The value to write to the MMIO register. =20 @@ -275,7 +318,13 @@ MmioWrite32 ( Flag =3D FilterBeforeMmIoWrite (FilterWidth32, Address, &Value); if (Flag) { MemoryFence (); - *(volatile UINT32 *)Address =3D Value; + + if (IsTdxGuest ()) { + TdMmioWrite32 (Address, Value); + } else { + *(volatile UINT32 *)Address =3D Value; + } + MemoryFence (); } =20 @@ -294,6 +343,8 @@ MmioWrite32 ( If 64-bit MMIO register operations are not supported, then ASSERT(). If Address is not aligned on a 64-bit boundary, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to read MMIO registers. + @param Address The MMIO register to read. =20 @return The value read. @@ -313,7 +364,13 @@ MmioRead64 ( Flag =3D FilterBeforeMmIoRead (FilterWidth64, Address, &Value); if (Flag) { MemoryFence (); - Value =3D *(volatile UINT64 *)Address; + + if (IsTdxGuest ()) { + Value =3D TdMmioRead64 (Address); + } else { + Value =3D *(volatile UINT64 *)Address; + } + MemoryFence (); } =20 @@ -332,6 +389,8 @@ MmioRead64 ( If 64-bit MMIO register operations are not supported, then ASSERT(). If Address is not aligned on a 64-bit boundary, then ASSERT(). =20 + For Td guest TDVMCALL_MMIO is invoked to write MMIO registers. + @param Address The MMIO register to write. @param Value The value to write to the MMIO register. =20 @@ -350,7 +409,13 @@ MmioWrite64 ( Flag =3D FilterBeforeMmIoWrite (FilterWidth64, Address, &Value); if (Flag) { MemoryFence (); - *(volatile UINT64 *)Address =3D Value; + + if (IsTdxGuest ()) { + TdMmioWrite64 (Address, Value); + } else { + *(volatile UINT64 *)Address =3D Value; + } + MemoryFence (); } =20 --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#84715): https://edk2.groups.io/g/devel/message/84715 Mute This Topic: https://groups.io/mt/87696564/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-