From nobody Mon Feb 9 11:07:21 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+87056+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+87056+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1646032908; cv=none; d=zohomail.com; s=zohoarc; b=BThaG3bS/+kfClgbfWTcpPuzw0i8dCzMw//ul57jr+sZ9UW61kj7ST69wF/FC+gIQo4XlaadkCLA6NU4TeyDI5C0Trz3bl6l4L/fw4LJaVLGkd5ooTMdLeFqcMWhphFwNYsGcXtnW9doK6tfqol9A6PD4ipfSXVPgb4i+878y58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646032908; 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=3HYl6X6K+4tTnVufbRtfueQqOaQXo/HYAe7Y0602jsE=; b=gMNv+hKZbGQPR/E1LlPUh48j7ZwukjKgmD6Lev+j1PkAfkDPOTtKJOpkvj3JL7SQswPaaoRJUdMCfGRbEWu3iym45V4biqjvtMtQkWH+GwrkJBlYkWQ2t40Lrmyojqg1xACmy6ND4WJ0O9AfrOEprS+o75foJI5epPdcbaAuK+0= 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+87056+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 164603290845165.54500405876206; Sun, 27 Feb 2022 23:21:48 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id lidSYY1788612x8Myl6XL4bK; Sun, 27 Feb 2022 23:21:48 -0800 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.17699.1646032885667369347 for ; Sun, 27 Feb 2022 23:21:47 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10271"; a="252552727" X-IronPort-AV: E=Sophos;i="5.90,142,1643702400"; d="scan'208";a="252552727" X-Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2022 23:21:47 -0800 X-IronPort-AV: E=Sophos;i="5.90,142,1643702400"; d="scan'208";a="534340841" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.238.2.184]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2022 23:21:44 -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 V7 08/37] MdePkg: Support mmio for Tdx guest in BaseIoLibIntrinsic Date: Mon, 28 Feb 2022 15:20:40 +0800 Message-Id: <023708b8078c4fad0a3d8563a3f87887495b2850.1646031164.git.min.m.xu@intel.com> 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: 5fAJynDOLb5pxnC9FDVbNBntx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1646032908; bh=vL9LZD6kBVx0UDbMRcaoBrCGq442DoMz0CmVN+H/e/w=; h=Cc:Date:From:Reply-To:Subject:To; b=OxEnC99/ZjIDQKO2CL2qqIXSNW11/wYhS6vGd68BVGMsns3w52tkJ1k7KwnpNHGvy27 SeHnTAGq04emxX0ch8HZ6Qkda/lAwjLhPU1Cl2ErPS2Sp+SWLBzUve4cZFTY0zCN72jiM B60afeKOucOoPQbe1iRahX3t7cHzJumvYiA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1646032910398100002 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 Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- .../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 (#87056): https://edk2.groups.io/g/devel/message/87056 Mute This Topic: https://groups.io/mt/89446155/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-