Skip to content

Commit

Permalink
MdePkg: MMIO for Tdx shared region must have tdx share bit set
Browse files Browse the repository at this point in the history
GPA for MMIO region that VMM emulates must be shared region.
  • Loading branch information
mxu9 committed Apr 5, 2021
1 parent 72ad8f8 commit 52fe95b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions MdePkg/Library/BaseIoLibIntrinsic/IoLibTdx.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ TdMmioRead8 (
UINT64 Value;
UINT64 Status;

Address |= TdSharedPageMask ();

MemoryFence ();
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_1, TDVMCALL_ACCESS_READ, Address, 0, &Value);
if (Status != 0) {
Expand Down Expand Up @@ -242,6 +244,8 @@ TdMmioWrite8 (
UINT64 Value;
UINT64 Status;

Address |= TdSharedPageMask ();

MemoryFence ();
Value = Val;
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_1, TDVMCALL_ACCESS_WRITE, Address, Value, 0);
Expand Down Expand Up @@ -272,6 +276,8 @@ TdMmioRead16 (
UINT64 Value;
UINT64 Status;

Address |= TdSharedPageMask ();

MemoryFence ();
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_2, TDVMCALL_ACCESS_READ, Address, 0, &Value);
if (Status != 0) {
Expand Down Expand Up @@ -305,6 +311,8 @@ TdMmioWrite16 (

ASSERT ((Address & 1) == 0);

Address |= TdSharedPageMask ();

MemoryFence ();
Value = Val;
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_2, TDVMCALL_ACCESS_WRITE, Address, Value, 0);
Expand Down Expand Up @@ -335,6 +343,8 @@ TdMmioRead32 (
UINT64 Value;
UINT64 Status;

Address |= TdSharedPageMask ();

MemoryFence ();
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_4, TDVMCALL_ACCESS_READ, Address, 0, &Value);
if (Status != 0) {
Expand Down Expand Up @@ -368,6 +378,8 @@ TdMmioWrite32 (

ASSERT ((Address & 3) == 0);

Address |= TdSharedPageMask ();

MemoryFence ();
Value = Val;
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_4, TDVMCALL_ACCESS_WRITE, Address, Value, 0);
Expand Down Expand Up @@ -398,6 +410,8 @@ TdMmioRead64 (
UINT64 Value;
UINT64 Status;

Address |= TdSharedPageMask ();

MemoryFence ();
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_8, TDVMCALL_ACCESS_READ, Address, 0, &Value);
if (Status != 0) {
Expand Down Expand Up @@ -428,6 +442,8 @@ TdMmioWrite64 (

ASSERT ((Address & 7) == 0);

Address |= TdSharedPageMask ();

MemoryFence ();
Status = TdVmCall (TDVMCALL_MMIO, TDVMCALL_ACCESS_SIZE_8, TDVMCALL_ACCESS_WRITE, Address, Value, 0);
if (Status != 0) {
Expand Down

0 comments on commit 52fe95b

Please sign in to comment.