Skip to content

Commit 08e9d12

Browse files
dcuiliuw
authored andcommitted
x86/hyperv: Add hv_isolation_type_tdx() to detect TDX guests
No logic change to SNP/VBS guests. hv_isolation_type_tdx() will be used to instruct a TDX guest on Hyper-V to do some TDX-specific operations, e.g. for a fully enlightened TDX guest (i.e. without the paravisor), hv_do_hypercall() should use __tdx_hypercall() and such a guest on Hyper-V should handle the Hyper-V Event/Message/Monitor pages specially. Reviewed-by: Michael Kelley <mikelley@microsoft.com> Reviewed-by: Tianyu Lan <tiala@microsoft.com> Signed-off-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Wei Liu <wei.liu@kernel.org> Link: https://lore.kernel.org/r/20230824080712.30327-2-decui@microsoft.com
1 parent 86e619c commit 08e9d12

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

arch/x86/hyperv/ivm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,12 @@ bool hv_isolation_type_en_snp(void)
562562
return static_branch_unlikely(&isolation_type_en_snp);
563563
}
564564

565+
DEFINE_STATIC_KEY_FALSE(isolation_type_tdx);
566+
/*
567+
* hv_isolation_type_tdx - Check if the system runs in an Intel TDX based
568+
* isolated VM.
569+
*/
570+
bool hv_isolation_type_tdx(void)
571+
{
572+
return static_branch_unlikely(&isolation_type_tdx);
573+
}

arch/x86/include/asm/hyperv-tlfs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@
169169
enum hv_isolation_type {
170170
HV_ISOLATION_TYPE_NONE = 0,
171171
HV_ISOLATION_TYPE_VBS = 1,
172-
HV_ISOLATION_TYPE_SNP = 2
172+
HV_ISOLATION_TYPE_SNP = 2,
173+
HV_ISOLATION_TYPE_TDX = 3
173174
};
174175

175176
/* Hyper-V specific model specific registers (MSRs) */

arch/x86/include/asm/mshyperv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ union hv_ghcb;
2727

2828
DECLARE_STATIC_KEY_FALSE(isolation_type_snp);
2929
DECLARE_STATIC_KEY_FALSE(isolation_type_en_snp);
30+
DECLARE_STATIC_KEY_FALSE(isolation_type_tdx);
3031

3132
typedef int (*hyperv_fill_flush_list_func)(
3233
struct hv_guest_mapping_flush_list *flush,
@@ -49,6 +50,8 @@ extern u64 hv_current_partition_id;
4950
extern union hv_ghcb * __percpu *hv_ghcb_pg;
5051

5152
extern bool hv_isolation_type_en_snp(void);
53+
bool hv_isolation_type_tdx(void);
54+
5255
/*
5356
* DEFAULT INIT GPAT and SEGMENT LIMIT value in struct VMSA
5457
* to start AP in enlightened SEV guest.

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ static void __init ms_hyperv_init_platform(void)
418418
static_branch_enable(&isolation_type_snp);
419419
else
420420
static_branch_enable(&isolation_type_en_snp);
421+
} else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_TDX) {
422+
static_branch_enable(&isolation_type_tdx);
421423
}
422424
}
423425

drivers/hv/hv_common.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,12 @@ bool __weak hv_isolation_type_en_snp(void)
521521
}
522522
EXPORT_SYMBOL_GPL(hv_isolation_type_en_snp);
523523

524+
bool __weak hv_isolation_type_tdx(void)
525+
{
526+
return false;
527+
}
528+
EXPORT_SYMBOL_GPL(hv_isolation_type_tdx);
529+
524530
void __weak hv_setup_vmbus_handler(void (*handler)(void))
525531
{
526532
}

include/asm-generic/mshyperv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);
6666
extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
6767
extern bool hv_isolation_type_snp(void);
6868
extern bool hv_isolation_type_en_snp(void);
69+
bool hv_isolation_type_tdx(void);
6970

7071
/* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */
7172
static inline int hv_result(u64 status)

0 commit comments

Comments
 (0)