Message ID | 20250503191515.24041-13-ricardo.neri-calderon@linux.intel.com |
---|---|
State | New |
Headers | show |
Series | x86/hyperv/hv_vtl: Use a wakeup mailbox to boot secondary CPUs | expand |
From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Sent: Saturday, May 3, 2025 12:15 PM > > From: Yunhong Jiang <yunhong.jiang@linux.intel.com> > > The current code maps MMIO devices as shared (decrypted) by default in a > confidential computing VM. > > In a TDX environment, secondary CPUs are booted using the Multiprocessor > Wakeup Structure defined in the ACPI specification. The virtual firmware > and the operating system function in the guest context, without > intervention from the VMM. Map the physical memory of the mailbox as > private. Use the is_private_mmio() callback. > > Signed-off-by: Yunhong Jiang <yunhong.jiang@linux.intel.com> > Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> > --- > Changes since v2: > - Use the new helper function get_mp_wakeup_mailbox_paddr(). > - Edited the commit message for clarity. > > Changes since v1: > - Added the helper function within_page() to improve readability > - Override the is_private_mmio() callback when detecting a TDX > environment. The address of the mailbox is checked in > hv_is_private_mmio_tdx(). > --- > arch/x86/hyperv/hv_vtl.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c > index 8b497c8292d3..cd48bedd21f0 100644 > --- a/arch/x86/hyperv/hv_vtl.c > +++ b/arch/x86/hyperv/hv_vtl.c > @@ -54,6 +54,18 @@ static void __noreturn hv_vtl_restart(char __maybe_unused *cmd) > hv_vtl_emergency_restart(); > } > > +static inline bool within_page(u64 addr, u64 start) > +{ > + return addr >= start && addr < (start + PAGE_SIZE); > +} > + > +static bool hv_vtl_is_private_mmio_tdx(u64 addr) > +{ > + u64 mb_addr = get_mp_wakeup_mailbox_paddr(); > + > + return mb_addr && within_page(addr, mb_addr); > +} > + > void __init hv_vtl_init_platform(void) > { > pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); > @@ -61,6 +73,8 @@ void __init hv_vtl_init_platform(void) > /* There is no paravisor present if we are here. */ > if (hv_isolation_type_tdx()) { > x86_init.resources.realmode_limit = SZ_4G; > + x86_platform.hyper.is_private_mmio = hv_vtl_is_private_mmio_tdx; > + > } else { > x86_platform.realmode_reserve = x86_init_noop; > x86_platform.realmode_init = x86_init_noop; > -- > 2.43.0 Reviewed-by: Michael Kelley <mhklinux@outlook.com>
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 8b497c8292d3..cd48bedd21f0 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -54,6 +54,18 @@ static void __noreturn hv_vtl_restart(char __maybe_unused *cmd) hv_vtl_emergency_restart(); } +static inline bool within_page(u64 addr, u64 start) +{ + return addr >= start && addr < (start + PAGE_SIZE); +} + +static bool hv_vtl_is_private_mmio_tdx(u64 addr) +{ + u64 mb_addr = get_mp_wakeup_mailbox_paddr(); + + return mb_addr && within_page(addr, mb_addr); +} + void __init hv_vtl_init_platform(void) { pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); @@ -61,6 +73,8 @@ void __init hv_vtl_init_platform(void) /* There is no paravisor present if we are here. */ if (hv_isolation_type_tdx()) { x86_init.resources.realmode_limit = SZ_4G; + x86_platform.hyper.is_private_mmio = hv_vtl_is_private_mmio_tdx; + } else { x86_platform.realmode_reserve = x86_init_noop; x86_platform.realmode_init = x86_init_noop;