From: Mukesh R <[email protected]> Sent: Tuesday, November 10, 2026 
6:21 PM
> 
> Add a new function hv_isolation_hw_cvm() for convenient check
> if a VM is running in HW confidential mode, ie, TDX or SNP.
> 
> Signed-off-by: Mukesh R <[email protected]>
> ---
>  arch/x86/hyperv/ivm.c          | 5 +++++
>  drivers/hv/hv_common.c         | 9 +++++++--
>  include/asm-generic/mshyperv.h | 7 +++++++
>  3 files changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
> index 2ce4dfe53472..b3340be0c43a 100644
> --- a/arch/x86/hyperv/ivm.c
> +++ b/arch/x86/hyperv/ivm.c
> @@ -944,3 +944,8 @@ bool hv_isolation_type_tdx(void)
>  {
>       return static_branch_unlikely(&isolation_type_tdx);
>  }
> +
> +bool hv_isolation_hw_cvm(void)
> +{
> +     return hv_isolation_type_snp() || hv_isolation_type_tdx();
> +}
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index 27b9b79d4f4c..62b52855ae69 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -528,8 +528,7 @@ int hv_common_cpu_init(unsigned int cpu)
>                       *outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
>               }
> 
> -             if (!ms_hyperv.paravisor_present &&
> -                 (hv_isolation_type_snp() || hv_isolation_type_tdx())) {
> +             if (!ms_hyperv.paravisor_present && hv_isolation_hw_cvm()) {

Any reason not to use hv_is_isolation_supported()? Your
new function seems conceptually equivalent, though at a
detailed level it handles VBS isolation differently from
hv_is_isolation_supported(). But I don't think including
VBS isolation here is a problem since set_memory_decrypted()
is a no-op with VBS isolation.

Also, Kameron Carr has a patch set in flight that collides
on exactly this code.  See [1] for the patch and my comments.

Michael

[1] 
https://lore.kernel.org/linux-hyperv/mn2pr02mb6863aa6357c8e0d4881f5fead4...@mn2pr02mb6863.namprd02.prod.outlook.com/


>                       ret = set_memory_decrypted((unsigned long)mem, pgcount);
>                       if (ret) {
>                               /* It may be unsafe to free 'mem' */
> @@ -696,6 +695,12 @@ bool __weak hv_isolation_type_tdx(void)
>  }
>  EXPORT_SYMBOL_GPL(hv_isolation_type_tdx);
> 
> +bool __weak hv_isolation_hw_cvm(void)
> +{
> +     return false;
> +}
> +EXPORT_SYMBOL_GPL(hv_isolation_hw_cvm);
> +
>  void __weak hv_setup_vmbus_handler(void (*handler)(void))
>  {
>  }
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index a3d497d99b0b..440c599784eb 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -87,6 +87,13 @@ u64 hv_do_fast_hypercall16(u16 control, u64 input1, u64
> input2);
>  bool hv_isolation_type_snp(void);
>  bool hv_isolation_type_tdx(void);
> 
> +/* This needs to be before hv_do_rep_hypercall() below */
> +#if IS_ENABLED(CONFIG_HYPERV)
> +bool hv_isolation_hw_cvm(void);
> +#else
> +static inline bool hv_isolation_hw_cvm(void) { return false; }
> +#endif
> +
>  /*
>   * On architectures where Hyper-V doesn't support AEOI (e.g., ARM64),
>   * it doesn't provide a recommendation flag and AEOI must be disabled.
> --
> 2.51.2.vfs.0.1
> 


Reply via email to