lkml.org 
[lkml]   [2021]   [Dec]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 18/26] x86/tdx: Exclude shared bit from __PHYSICAL_MASK
    Date
    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>
    Reviewed-by: Andi Kleen <ak@linux.intel.com>
    Reviewed-by: Tony Luck <tony.luck@intel.com>
    Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
    ---
    arch/x86/Kconfig | 1 +
    arch/x86/kernel/tdx.c | 8 ++++++++
    2 files changed, 9 insertions(+)

    diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
    index fc4771a07fc0..fe0382f20445 100644
    --- a/arch/x86/Kconfig
    +++ b/arch/x86/Kconfig
    @@ -879,6 +879,7 @@ config INTEL_TDX_GUEST
    depends on X86_X2APIC
    select ARCH_HAS_CC_PLATFORM
    select X86_MCE
    + select DYNAMIC_PHYSICAL_MASK
    help
    Support running as a guest under Intel TDX. Without this support,
    the guest kernel can not boot or run under TDX.
    diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c
    index b55bc1879d1e..cbfacc2af8bb 100644
    --- a/arch/x86/kernel/tdx.c
    +++ b/arch/x86/kernel/tdx.c
    @@ -479,5 +479,13 @@ void __init tdx_early_init(void)

    tdx_get_info();

    + /*
    + * All bits above GPA width are reserved and kernel treats shared bit
    + * as flag, not as part of physical address.
    + *
    + * Adjust physical mask to only cover valid GPA bits.
    + */
    + physical_mask &= GENMASK_ULL(td_info.gpa_width - 2, 0);
    +
    pr_info("Guest detected\n");
    }
    --
    2.32.0
    \
     
     \ /
      Last update: 2021-12-14 16:05    [W:4.476 / U:0.060 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site