Skip to content

Commit 65fab5b

Browse files
kirylhansendc
authored andcommitted
x86/tdx: Exclude shared bit from __PHYSICAL_MASK
In TDX guests, by default memory is protected from host access. If a guest needs to communicate with the VMM (like the I/O use case), it uses a single bit in the physical address to communicate the protected/shared attribute of the given page. In the x86 ARCH code, __PHYSICAL_MASK macro represents the width of the physical address in the given architecture. It is used in creating physical PAGE_MASK for address bits in the kernel. Since in TDX guest, a single bit is used as metadata, it needs to be excluded from valid physical address bits to avoid using incorrect addresses bits in the kernel. Enable DYNAMIC_PHYSICAL_MASK to support updating the __PHYSICAL_MASK. Co-developed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Andi Kleen <ak@linux.intel.com> Reviewed-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20220405232939.73860-6-kirill.shutemov@linux.intel.com
1 parent 41394e3 commit 65fab5b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ config INTEL_TDX_GUEST
883883
depends on X86_64 && CPU_SUP_INTEL
884884
depends on X86_X2APIC
885885
select ARCH_HAS_CC_PLATFORM
886+
select DYNAMIC_PHYSICAL_MASK
886887
help
887888
Support running as a guest under Intel TDX. Without this support,
888889
the guest kernel can not boot or run under TDX.

arch/x86/coco/tdx/tdx.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,13 @@ void __init tdx_early_init(void)
8989
cc_mask = get_cc_mask();
9090
cc_set_mask(cc_mask);
9191

92+
/*
93+
* All bits above GPA width are reserved and kernel treats shared bit
94+
* as flag, not as part of physical address.
95+
*
96+
* Adjust physical mask to only cover valid GPA bits.
97+
*/
98+
physical_mask &= cc_mask - 1;
99+
92100
pr_info("Guest detected\n");
93101
}

0 commit comments

Comments
 (0)