• Kai Huang's avatar
    x86/virt/tdx: Add placeholder to construct TDMRs to cover all TDX memory regions · 5173d3c5
    Kai Huang authored
    After the kernel selects all TDX-usable memory regions, the kernel needs
    to pass those regions to the TDX module via data structure "TD Memory
    Region" (TDMR).
    
    Add a placeholder to construct a list of TDMRs (in multiple steps) to
    cover all TDX-usable memory regions.
    
    === Long Version ===
    
    TDX provides increased levels of memory confidentiality and integrity.
    This requires special hardware support for features like memory
    encryption and storage of memory integrity checksums.  Not all memory
    satisfies these requirements.
    
    As a result, TDX introduced the concept of a "Convertible Memory Region"
    (CMR).  During boot, the firmware builds a list of all of the memory
    ranges which can provide the TDX security guarantees.  The list of these
    ranges is available to the kernel by querying the TDX module.
    
    The TDX architecture needs additional metadata to record things like
    which TD guest "owns" a given page of memory.  This metadata essentially
    serves as the 'struct page' for the TDX module.  The space for this
    metadata is not reserved by the hardware up front and must be allocated
    by the kernel and given to the TDX module.
    
    Since this metadata consumes space, the VMM can choose whether or not to
    allocate it for a given area of convertible memory.  If it chooses not
    to, the memory cannot receive TDX protections and can not be used by TDX
    guests as private memory.
    
    For every memory region that the VMM wants to use as TDX memory, it sets
    up a "TD Memory Region" (TDMR).  Each TDMR represents a physically
    contiguous convertible range and must also have its own physically
    contiguous metadata table, referred to as a Physical Address Metadata
    Table (PAMT), to track status for each page in the TDMR range.
    
    Unlike a CMR, each TDMR requires 1G granularity and alignment.  To
    support physical RAM areas that don't meet those strict requirements,
    each TDMR permits a number of internal "reserved areas" which can be
    placed over memory holes.  If PAMT metadata is placed within a TDMR it
    must be covered by one of these reserved areas.
    
    Let's summarize the concepts:
    
     CMR - Firmware-enumerated physical ranges that support TDX.  CMRs are
           4K aligned.
    TDMR - Physical address range which is chosen by the kernel to support
           TDX.  1G granularity and alignment required.  Each TDMR has
           reserved areas where TDX memory holes and overlapping PAMTs can
           be represented.
    PAMT - Physically contiguous TDX metadata.  One table for each page size
           per TDMR.  Roughly 1/256th of TDMR in size.  256G TDMR = ~1G
           PAMT.
    
    As one step of initializing the TDX module, the kernel configures
    TDX-usable memory regions by passing a list of TDMRs to the TDX module.
    
    Constructing the list of TDMRs consists below steps:
    
    1) Fill out TDMRs to cover all memory regions that the TDX module will
       use for TD memory.
    2) Allocate and set up PAMT for each TDMR.
    3) Designate reserved areas for each TDMR.
    
    Add a placeholder to construct TDMRs to do the above steps.  To keep
    things simple, just allocate enough space to hold maximum number of
    TDMRs up front.
    Signed-off-by: default avatarKai Huang <kai.huang@intel.com>
    Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
    Reviewed-by: default avatarIsaku Yamahata <isaku.yamahata@intel.com>
    Reviewed-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
    Reviewed-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
    Link: https://lore.kernel.org/all/20231208170740.53979-9-dave.hansen%40intel.com
    5173d3c5
tdx.c 15.2 KB