TDX: Update the handling of <GetTdVmCallInfo> and implement <SetupEventNotifyInterrupt>
cover TDX: Update the handling of <GetTdVmCallInfo> and implement <SetupEventNotifyInterrupt>
It ends up as <GetQuote> is one of the base TDG.VP.VMCALL leaf, and it's not enumerated via bit 0 of out R11 (the bit 0 becomes reserved).[1]
So patch 1 updates the handling of tdx_handle_get_tdvmcall_info().
[1] https://cdrdv2.intel.com/v1/dl/getContent/858626
Paolo,
Patch 2-4, enables <SetupEventNotifyInterrupt> in QEMU. They based on the KVM patches you put in KVM tree master.
Xiaoyao Li (4):
i386/tdx: Remove enumeration of GetQuote in
tdx_handle_get_tdvmcall_info()
update Linux headers to KVM tree master
i386/tdx: Set value of <GetTdVmCallInfo> based on capabilities of both
KVM and QEMU
i386/tdx: handle TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT
linux-headers/asm-x86/kvm.h | 8 ++++- linux-headers/linux/kvm.h | 4 +++ target/i386/kvm/kvm.c | 3 ++ target/i386/kvm/tdx-stub.c | 4 +++ target/i386/kvm/tdx.c | 61 +++++++++++++++++++++++++++++++++++-- target/i386/kvm/tdx.h | 7 ++++- 6 files changed, 82 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 i386/tdx: Remove enumeration of GetQuote in tdx_handle_get_tdvmcall_info()
GHCI is finalized with the <GetQuote> being one of the base VMCALLs, and not enuemrated via <GetTdVmCallInfo>.
Adjust tdx_handle_get_tdvmcall_info() to match with GHCI.
Opportunistically fix the wrong indentation and explicitly set the ret to TDG_VP_VMCALL_SUCCESS (in case KVM leaves unexpected value).
--- target/i386/kvm/tdx.c | 6 ++++-- target/i386/kvm/tdx.h | 2 -- 2 files changed, 4 insertions(+), 4 deletions(-)
target/i386/kvm/tdx.c +4 -2
@@ -1259,13 +1259,15 @@ out_free:void tdx_handle_get_tdvmcall_info (X86CPU *cpu,struct kvm_run *run) {if (run->tdx.get_tdvmcall_info.leaf !=1 ) { -return ; +return ; } - run->tdx.get_tdvmcall_info.r11 =TDG_VP_VMCALL_SUBFUNC_GET_QUOTE ; + run->tdx.get_tdvmcall_info.r11 =0 ; run->tdx.get_tdvmcall_info.r12 =0 ; run->tdx.get_tdvmcall_info.r13 =0 ; run->tdx.get_tdvmcall_info.r14 =0 ; + + run->tdx.get_tdvmcall_info.ret =TDG_VP_VMCALL_SUCCESS ; } static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code,
target/i386/kvm/tdx.h +0 -2
@@ -32,8 +32,6 @@ typedef struct TdxGuestClass {#define TDG_VP_VMCALL_GPA_INUSE 0x8000000000000001ULL#define TDG_VP_VMCALL_ALIGN_ERROR 0x8000000000000002ULL -#define TDG_VP_VMCALL_SUBFUNC_GET_QUOTE 0x0000000000000001ULL -enum TdxRamType {TDX_RAM_UNACCEPTED ,TDX_RAM_ADDED ,
Signature · 1 line
2.43.0
PATCH 2/4 update Linux headers to KVM tree master
In reply to Xiaoyao LiTo fetch the update of TDX
--- linux-headers/asm-x86/kvm.h | 8 +++++++- linux-headers/linux/kvm.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-)
linux-headers/asm-x86/kvm.h +7 -1
@@ -963,7 +963,13 @@ struct kvm_tdx_cmd {struct kvm_tdx_capabilities {__u64 supported_attrs;__u64 supported_xfam; -__u64 reserved[254 ]; + +__u64 kernel_tdvmcallinfo_1_r11; +__u64 user_tdvmcallinfo_1_r11; +__u64 kernel_tdvmcallinfo_1_r12; +__u64 user_tdvmcallinfo_1_r12; + +__u64 reserved[250 ];/* Configurable CPUID bits for userspace */ struct kvm_cpuid2 cpuid;
linux-headers/linux/kvm.h +4 -0
@@ -459,6 +459,10 @@ struct kvm_run {__u64 leaf;__u64 r11, r12, r13, r14; } get_tdvmcall_info; +struct { +__u64 ret; +__u64 vector; + } setup_event_notify; }; } tdx;/* Fix the size of the union. */
Signature · 1 line
2.43.0
PATCH 3/4 i386/tdx: Set value of <GetTdVmCallInfo> based on capabilities of both KVM and QEMU
In reply to Xiaoyao LiKVM reports the supported TDVMCALL sub leafs in TDX capabilities.
one for kernel-supported
TDVMCALLs (userspace can set those blindly) and one for user-supported TDVMCALLs (userspace can set those if it knows how to handle them)
--- target/i386/kvm/tdx.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
target/i386/kvm/tdx.c +9 -2
@@ -1256,14 +1256,21 @@ out_free:g_free (task); } +#define SUPPORTED_TDVMCALLINFO_1_R11 (0) +#define SUPPORTED_TDVMCALLINFO_1_R12 (0) +void tdx_handle_get_tdvmcall_info (X86CPU *cpu,struct kvm_run *run) {if (run->tdx.get_tdvmcall_info.leaf !=1 ) {return ; } - run->tdx.get_tdvmcall_info.r11 =0 ; - run->tdx.get_tdvmcall_info.r12 =0 ; + run->tdx.get_tdvmcall_info.r11 = (tdx_caps->user_tdvmcallinfo_1_r11 & +SUPPORTED_TDVMCALLINFO_1_R11 ) | + tdx_caps->kernel_tdvmcallinfo_1_r11; + run->tdx.get_tdvmcall_info.r12 = (tdx_caps->user_tdvmcallinfo_1_r12 & +SUPPORTED_TDVMCALLINFO_1_R12 ) | + tdx_caps->kernel_tdvmcallinfo_1_r12; run->tdx.get_tdvmcall_info.r13 =0 ; run->tdx.get_tdvmcall_info.r14 =0 ;
Signature · 1 line
2.43.0
PATCH 4/4 i386/tdx: handle TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT
In reply to Xiaoyao LiRecord the interrupt vector and the apic id of the vcpu that calls TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT.
Inject the interrupt to TD guest to notify the completion of <GetQuote> when notify interrupt vector is valid.
--- target/i386/kvm/kvm.c | 3 +++ target/i386/kvm/tdx-stub.c | 4 ++++ target/i386/kvm/tdx.c | 48 +++++++++++++++++++++++++++++++++++++- target/i386/kvm/tdx.h | 7 ++++++ 4 files changed, 61 insertions(+), 1 deletion(-)
target/i386/kvm/kvm.c +3 -0
@@ -6182,6 +6182,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)case TDVMCALL_GET_TD_VM_CALL_INFO :tdx_handle_get_tdvmcall_info (cpu, run);break ; +case TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT : +tdx_handle_setup_event_notify_interrupt (cpu, run); +break ; } ret =0 ;break ;
target/i386/kvm/tdx-stub.c +4 -0
@@ -26,3 +26,7 @@ void tdx_handle_get_quote(X86CPU *cpu, struct kvm_run *run)void tdx_handle_get_tdvmcall_info (X86CPU *cpu,struct kvm_run *run) { } + +void tdx_handle_setup_event_notify_interrupt (X86CPU *cpu,struct kvm_run *run) +{ +}
target/i386/kvm/tdx.c +47 -1
88 lines not on this page · raw message
target/i386/kvm/tdx.h +7 -0
@@ -25,6 +25,7 @@ typedef struct TdxGuestClass {#define TDVMCALL_GET_TD_VM_CALL_INFO 0x10000#define TDVMCALL_GET_QUOTE 0x10002 +#define TDVMCALL_SETUP_EVENT_NOTIFY_INTERRUPT 0x10004#define TDG_VP_VMCALL_SUCCESS 0x0000000000000000ULL#define TDG_VP_VMCALL_RETRY 0x0000000000000001ULL
@@ -32,6 +33,8 @@ typedef struct TdxGuestClass {#define TDG_VP_VMCALL_GPA_INUSE 0x8000000000000001ULL#define TDG_VP_VMCALL_ALIGN_ERROR 0x8000000000000002ULL +#define TDG_VP_VMCALL_SUBFUNC_SET_EVENT_NOTIFY_INTERRUPT BIT_ULL(1) +enum TdxRamType {TDX_RAM_UNACCEPTED ,TDX_RAM_ADDED ,
@@ -64,6 +67,9 @@ typedef struct TdxGuest {/* GetQuote */ SocketAddress *qg_sock_addr;int num; + +uint32_t event_notify_vector; +uint32_t event_notify_apicid; } TdxGuest;#ifdef CONFIG_TDX
@@ -78,5 +84,6 @@ int tdx_parse_tdvf(void *flash_ptr, int size);int tdx_handle_report_fatal_error (X86CPU *cpu,struct kvm_run *run);void tdx_handle_get_quote (X86CPU *cpu,struct kvm_run *run);void tdx_handle_get_tdvmcall_info (X86CPU *cpu,struct kvm_run *run); +void tdx_handle_setup_event_notify_interrupt (X86CPU *cpu,struct kvm_run *run);#endif /* QEMU_I386_TDX_H */
Signature · 1 line
2.43.0