Skip to content

Commit fcae3a3

Browse files
yamahatabonzini
authored andcommitted
KVM: TDX: Define TDX architectural definitions
Define architectural definitions for KVM to issue the TDX SEAMCALLs. Structures and values that are architecturally defined in the TDX module specifications the chapter of ABI Reference. Co-developed-by: Tony Lindgren <tony.lindgren@linux.intel.com> Signed-off-by: Tony Lindgren <tony.lindgren@linux.intel.com> Co-developed-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> --- - Drop old duplicate defines, the x86 core exports what's needed (Kai) Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 09b3d3c commit fcae3a3

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

arch/x86/kvm/vmx/tdx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#ifndef __KVM_X86_VMX_TDX_H
33
#define __KVM_X86_VMX_TDX_H
44

5+
#include "tdx_arch.h"
6+
57
#ifdef CONFIG_KVM_INTEL_TDX
68
int tdx_bringup(void);
79
void tdx_cleanup(void);

arch/x86/kvm/vmx/tdx_arch.h

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/* architectural constants/data definitions for TDX SEAMCALLs */
3+
4+
#ifndef __KVM_X86_TDX_ARCH_H
5+
#define __KVM_X86_TDX_ARCH_H
6+
7+
#include <linux/types.h>
8+
9+
/* TDX control structure (TDR/TDCS/TDVPS) field access codes */
10+
#define TDX_NON_ARCH BIT_ULL(63)
11+
#define TDX_CLASS_SHIFT 56
12+
#define TDX_FIELD_MASK GENMASK_ULL(31, 0)
13+
14+
#define __BUILD_TDX_FIELD(non_arch, class, field) \
15+
(((non_arch) ? TDX_NON_ARCH : 0) | \
16+
((u64)(class) << TDX_CLASS_SHIFT) | \
17+
((u64)(field) & TDX_FIELD_MASK))
18+
19+
#define BUILD_TDX_FIELD(class, field) \
20+
__BUILD_TDX_FIELD(false, (class), (field))
21+
22+
#define BUILD_TDX_FIELD_NON_ARCH(class, field) \
23+
__BUILD_TDX_FIELD(true, (class), (field))
24+
25+
26+
/* Class code for TD */
27+
#define TD_CLASS_EXECUTION_CONTROLS 17ULL
28+
29+
/* Class code for TDVPS */
30+
#define TDVPS_CLASS_VMCS 0ULL
31+
#define TDVPS_CLASS_GUEST_GPR 16ULL
32+
#define TDVPS_CLASS_OTHER_GUEST 17ULL
33+
#define TDVPS_CLASS_MANAGEMENT 32ULL
34+
35+
enum tdx_tdcs_execution_control {
36+
TD_TDCS_EXEC_TSC_OFFSET = 10,
37+
TD_TDCS_EXEC_TSC_MULTIPLIER = 11,
38+
};
39+
40+
/* @field is any of enum tdx_tdcs_execution_control */
41+
#define TDCS_EXEC(field) BUILD_TDX_FIELD(TD_CLASS_EXECUTION_CONTROLS, (field))
42+
43+
/* @field is the VMCS field encoding */
44+
#define TDVPS_VMCS(field) BUILD_TDX_FIELD(TDVPS_CLASS_VMCS, (field))
45+
46+
/* @field is any of enum tdx_guest_other_state */
47+
#define TDVPS_STATE(field) BUILD_TDX_FIELD(TDVPS_CLASS_OTHER_GUEST, (field))
48+
#define TDVPS_STATE_NON_ARCH(field) BUILD_TDX_FIELD_NON_ARCH(TDVPS_CLASS_OTHER_GUEST, (field))
49+
50+
/* Management class fields */
51+
enum tdx_vcpu_guest_management {
52+
TD_VCPU_PEND_NMI = 11,
53+
};
54+
55+
/* @field is any of enum tdx_vcpu_guest_management */
56+
#define TDVPS_MANAGEMENT(field) BUILD_TDX_FIELD(TDVPS_CLASS_MANAGEMENT, (field))
57+
58+
#define TDX_EXTENDMR_CHUNKSIZE 256
59+
60+
struct tdx_cpuid_value {
61+
u32 eax;
62+
u32 ebx;
63+
u32 ecx;
64+
u32 edx;
65+
} __packed;
66+
67+
#define TDX_TD_ATTR_DEBUG BIT_ULL(0)
68+
#define TDX_TD_ATTR_SEPT_VE_DISABLE BIT_ULL(28)
69+
#define TDX_TD_ATTR_PKS BIT_ULL(30)
70+
#define TDX_TD_ATTR_KL BIT_ULL(31)
71+
#define TDX_TD_ATTR_PERFMON BIT_ULL(63)
72+
73+
/*
74+
* TD_PARAMS is provided as an input to TDH_MNG_INIT, the size of which is 1024B.
75+
*/
76+
struct td_params {
77+
u64 attributes;
78+
u64 xfam;
79+
u16 max_vcpus;
80+
u8 reserved0[6];
81+
82+
u64 eptp_controls;
83+
u64 config_flags;
84+
u16 tsc_frequency;
85+
u8 reserved1[38];
86+
87+
u64 mrconfigid[6];
88+
u64 mrowner[6];
89+
u64 mrownerconfig[6];
90+
u64 reserved2[4];
91+
92+
union {
93+
DECLARE_FLEX_ARRAY(struct tdx_cpuid_value, cpuid_values);
94+
u8 reserved3[768];
95+
};
96+
} __packed __aligned(1024);
97+
98+
/*
99+
* Guest uses MAX_PA for GPAW when set.
100+
* 0: GPA.SHARED bit is GPA[47]
101+
* 1: GPA.SHARED bit is GPA[51]
102+
*/
103+
#define TDX_CONFIG_FLAGS_MAX_GPAW BIT_ULL(0)
104+
105+
/*
106+
* TDH.VP.ENTER, TDG.VP.VMCALL preserves RBP
107+
* 0: RBP can be used for TDG.VP.VMCALL input. RBP is clobbered.
108+
* 1: RBP can't be used for TDG.VP.VMCALL input. RBP is preserved.
109+
*/
110+
#define TDX_CONFIG_FLAGS_NO_RBP_MOD BIT_ULL(2)
111+
112+
113+
/*
114+
* TDX requires the frequency to be defined in units of 25MHz, which is the
115+
* frequency of the core crystal clock on TDX-capable platforms, i.e. the TDX
116+
* module can only program frequencies that are multiples of 25MHz. The
117+
* frequency must be between 100mhz and 10ghz (inclusive).
118+
*/
119+
#define TDX_TSC_KHZ_TO_25MHZ(tsc_in_khz) ((tsc_in_khz) / (25 * 1000))
120+
#define TDX_TSC_25MHZ_TO_KHZ(tsc_in_25mhz) ((tsc_in_25mhz) * (25 * 1000))
121+
#define TDX_MIN_TSC_FREQUENCY_KHZ (100 * 1000)
122+
#define TDX_MAX_TSC_FREQUENCY_KHZ (10 * 1000 * 1000)
123+
124+
#endif /* __KVM_X86_TDX_ARCH_H */

0 commit comments

Comments
 (0)