Skip to content

Commit baffc30

Browse files
author
Jinrong Liang
committed
KVM: x86/PVM: Add pvm.h and pvm_para.h header files to tools
Add the pvm.h and pvm_para.h header files to the tools to provide the necessary header files for tools that require PVM support, such as perf. The change should not have any negative impact on the existing tools or the kernel itself, as it simply makes the header files available for use by the tools that need them. Signed-off-by: Jinrong Liang <cloudliang@tencent.com>
1 parent 6ea81b8 commit baffc30

3 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef UAPI_KVM_X86_PVM_H
3+
#define UAPI_KVM_X86_PVM_H
4+
5+
#include <linux/bitops.h>
6+
#include <uapi/asm/pvm_para.h>
7+
8+
#define NMI_VECTOR 0x02
9+
#define SWITCH_EXIT_REASONS_SYSCALL 1024
10+
#define SWITCH_EXIT_REASONS_FAILED_VMETNRY 1025
11+
12+
#define PVM_SYSCALL_VECTOR SWITCH_EXIT_REASONS_SYSCALL
13+
#define PVM_FAILED_VMENTRY_VECTOR SWITCH_EXIT_REASONS_FAILED_VMETNRY
14+
15+
#define PVM_EXIT_REASONS_SHIFT 16
16+
#define PVM_EXIT_REASONS_SYSCALL BIT(PVM_EXIT_REASONS_SHIFT)
17+
#define PVM_EXIT_REASONS_HYPERCALL (2UL << PVM_EXIT_REASONS_SHIFT)
18+
#define PVM_EXIT_REASONS_ERETU (3UL << PVM_EXIT_REASONS_SHIFT)
19+
#define PVM_EXIT_REASONS_ERETS (4UL << PVM_EXIT_REASONS_SHIFT)
20+
#define PVM_EXIT_REASONS_INTERRUPT (5UL << PVM_EXIT_REASONS_SHIFT)
21+
#define PVM_EXIT_REASONS_INT80 (6UL << PVM_EXIT_REASONS_SHIFT)
22+
23+
#define PVM_EXIT_REASONS \
24+
{ DE_VECTOR, "DE excp" }, \
25+
{ DB_VECTOR, "DB excp" }, \
26+
{ NMI_VECTOR, "NMI excp" }, \
27+
{ BP_VECTOR, "BP excp" }, \
28+
{ OF_VECTOR, "OF excp" }, \
29+
{ BR_VECTOR, "BR excp" }, \
30+
{ UD_VECTOR, "UD excp" }, \
31+
{ NM_VECTOR, "NM excp" }, \
32+
{ DF_VECTOR, "DF excp" }, \
33+
{ TS_VECTOR, "TS excp" }, \
34+
{ SS_VECTOR, "SS excp" }, \
35+
{ GP_VECTOR, "GP excp" }, \
36+
{ PF_VECTOR, "PF excp" }, \
37+
{ MF_VECTOR, "MF excp" }, \
38+
{ AC_VECTOR, "AC excp" }, \
39+
{ MC_VECTOR, "MC excp" }, \
40+
{ XM_VECTOR, "XM excp" }, \
41+
{ VE_VECTOR, "VE excp" }, \
42+
{ PVM_EXIT_REASONS_SYSCALL, "SYSCALL" }, \
43+
{ PVM_EXIT_REASONS_HYPERCALL, "HYPERCALL" }, \
44+
{ PVM_EXIT_REASONS_ERETU, "ERETU" }, \
45+
{ PVM_EXIT_REASONS_ERETS, "ERETS" }, \
46+
{ PVM_EXIT_REASONS_INTERRUPT, "INTERRUPT" }, \
47+
{ PVM_EXIT_REASONS_INT80, "INT80" }, \
48+
{ PVM_HC_LOAD_PGTBL, "HC_LOAD_PGTBL" }, \
49+
{ PVM_HC_IRQ_WIN, "HC_IRQ_WIN" }, \
50+
{ PVM_HC_IRQ_HALT, "HC_IRQ_HALT" }, \
51+
{ PVM_HC_TLB_FLUSH, "HC_TLB_FLUSH" }, \
52+
{ PVM_HC_TLB_FLUSH_CURRENT, "HC_TLB_FLUSH_CURRENT" }, \
53+
{ PVM_HC_TLB_INVLPG, "HC_TLB_INVLPG" }, \
54+
{ PVM_HC_LOAD_GS, "HC_LOAD_GS" }, \
55+
{ PVM_HC_RDMSR, "HC_RDMSR" }, \
56+
{ PVM_HC_WRMSR, "HC_WRMSR" }, \
57+
{ PVM_HC_LOAD_TLS, "HC_LOAD_TLS" }, \
58+
{ PVM_FAILED_VMENTRY_VECTOR, "FAILED_VMENTRY" }
59+
60+
#endif /* UAPI_KVM_X86_PVM_H */
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef _UAPI_ASM_X86_PVM_PARA_H
3+
#define _UAPI_ASM_X86_PVM_PARA_H
4+
5+
#include <linux/const.h>
6+
#include <linux/types.h>
7+
8+
/*
9+
* The CPUID instruction in PVM guest can't be trapped and emulated,
10+
* so PVM guest should use the following two instructions instead:
11+
* "invlpg 0xffffffffff4d5650; cpuid;"
12+
*
13+
* PVM_SYNTHETIC_CPUID is supposed to not trigger any trap in the real or
14+
* virtual x86 kernel mode and is also guaranteed to trigger a trap in the
15+
* underlying hardware user mode for the hypervisor emulating it. The
16+
* hypervisor emulates both of the basic instructions, while the INVLPG is
17+
* often emulated as an NOP since 0xffffffffff4d5650 is normally out of the
18+
* allowed linear address ranges.
19+
*/
20+
#define PVM_SYNTHETIC_CPUID 0x0f,0x01,0x3c,0x25,0x50, \
21+
0x56,0x4d,0xff,0x0f,0xa2
22+
#define PVM_SYNTHETIC_CPUID_ADDRESS 0xffffffffff4d5650
23+
24+
/*
25+
* The vendor signature 'PVM' is returned in ebx. It should be used to
26+
* determine that a VM is running under PVM.
27+
*/
28+
#define PVM_CPUID_SIGNATURE 0x4d5650
29+
30+
/*
31+
* PVM virtual MSRS falls in the range 0x4b564df0-0x4b564dff, and it should not
32+
* conflict with KVM, see arch/x86/include/uapi/asm/kvm_para.h
33+
*/
34+
#define PVM_VIRTUAL_MSR_MAX_NR 15
35+
#define PVM_VIRTUAL_MSR_BASE 0x4b564df0
36+
#define PVM_VIRTUAL_MSR_MAX (PVM_VIRTUAL_MSR_BASE+PVM_VIRTUAL_MSR_MAX_NR)
37+
38+
#define MSR_PVM_LINEAR_ADDRESS_RANGE 0x4b564df0
39+
#define MSR_PVM_VCPU_STRUCT 0x4b564df1
40+
#define MSR_PVM_SUPERVISOR_RSP 0x4b564df2
41+
#define MSR_PVM_SUPERVISOR_REDZONE 0x4b564df3
42+
#define MSR_PVM_EVENT_ENTRY 0x4b564df4
43+
#define MSR_PVM_RETU_RIP 0x4b564df5
44+
#define MSR_PVM_RETS_RIP 0x4b564df6
45+
#define MSR_PVM_SWITCH_CR3 0x4b564df7
46+
47+
#define PVM_HC_SPECIAL_MAX_NR (256)
48+
#define PVM_HC_SPECIAL_BASE (0x17088200)
49+
#define PVM_HC_SPECIAL_MAX (PVM_HC_SPECIAL_BASE+PVM_HC_SPECIAL_MAX_NR)
50+
51+
#define PVM_HC_LOAD_PGTBL (PVM_HC_SPECIAL_BASE+0)
52+
#define PVM_HC_IRQ_WIN (PVM_HC_SPECIAL_BASE+1)
53+
#define PVM_HC_IRQ_HALT (PVM_HC_SPECIAL_BASE+2)
54+
#define PVM_HC_TLB_FLUSH (PVM_HC_SPECIAL_BASE+3)
55+
#define PVM_HC_TLB_FLUSH_CURRENT (PVM_HC_SPECIAL_BASE+4)
56+
#define PVM_HC_TLB_INVLPG (PVM_HC_SPECIAL_BASE+5)
57+
#define PVM_HC_LOAD_GS (PVM_HC_SPECIAL_BASE+6)
58+
#define PVM_HC_RDMSR (PVM_HC_SPECIAL_BASE+7)
59+
#define PVM_HC_WRMSR (PVM_HC_SPECIAL_BASE+8)
60+
#define PVM_HC_LOAD_TLS (PVM_HC_SPECIAL_BASE+9)
61+
62+
/*
63+
* PVM_EVENT_FLAGS_IF
64+
* - Interrupt enable flag. The flag is set to respond to maskable
65+
* external interrupts; and cleared to inhibit maskable external
66+
* interrupts.
67+
*
68+
* PVM_EVENT_FLAGS_IP
69+
* - interrupt pending flag. The hypervisor sets it if it fails to inject
70+
* a maskable event to the VCPU due to the interrupt-enable flag being
71+
* cleared in supervisor mode.
72+
*/
73+
#define PVM_EVENT_FLAGS_IP_BIT 8
74+
#define PVM_EVENT_FLAGS_IP _BITUL(PVM_EVENT_FLAGS_IP_BIT)
75+
#define PVM_EVENT_FLAGS_IF_BIT 9
76+
#define PVM_EVENT_FLAGS_IF _BITUL(PVM_EVENT_FLAGS_IF_BIT)
77+
78+
#define PVM_LOAD_PGTBL_FLAGS_TLB _BITUL(0)
79+
#define PVM_LOAD_PGTBL_FLAGS_LA57 _BITUL(1)
80+
81+
#ifndef __ASSEMBLY__
82+
83+
/*
84+
* PVM event delivery saves the information about the event and the old context
85+
* into the PVCS structure if the event is from user mode or from supervisor
86+
* mode with vector >=32. And ERETU synthetic instruction reads the return
87+
* state from the PVCS structure to restore the old context.
88+
*/
89+
struct pvm_vcpu_struct {
90+
/*
91+
* This flag is only used in supervisor mode, with only bit 8 and
92+
* bit 9 being valid. The other bits are reserved.
93+
*/
94+
__u64 event_flags;
95+
__u32 event_errcode;
96+
__u32 event_vector;
97+
__u64 cr2;
98+
__u64 reserved0[5];
99+
100+
/*
101+
* For the event from supervisor mode with vector >=32, only eflags,
102+
* rip, rsp, rcx and r11 are saved, and others keep untouched.
103+
*/
104+
__u16 user_cs, user_ss;
105+
__u32 reserved1;
106+
__u64 reserved2;
107+
__u64 user_gsbase;
108+
__u32 eflags;
109+
__u32 pkru;
110+
__u64 rip;
111+
__u64 rsp;
112+
__u64 rcx;
113+
__u64 r11;
114+
};
115+
116+
/*
117+
* PVM event delivery saves the information about the event and the old context
118+
* on the stack with the following frame format if the event is from supervisor
119+
* mode with vector <32. And ERETS synthetic instruction reads the return state
120+
* with the following frame format from the stack to restore the old context.
121+
*/
122+
struct pvm_supervisor_event {
123+
/* vector in high32 */
124+
unsigned long errcode;
125+
unsigned long rip;
126+
unsigned long cs;
127+
unsigned long rflags;
128+
unsigned long rsp;
129+
unsigned long ss;
130+
unsigned long rcx;
131+
unsigned long r11;
132+
};
133+
134+
#endif /* __ASSEMBLY__ */
135+
136+
#endif /* _UAPI_ASM_X86_PVM_PARA_H */

tools/perf/check-headers.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ FILES=(
5555
"arch/x86/include/uapi/asm/svm.h"
5656
"arch/x86/include/uapi/asm/unistd.h"
5757
"arch/x86/include/uapi/asm/vmx.h"
58+
"arch/x86/include/uapi/asm/pvm.h"
59+
"arch/x86/include/uapi/asm/pvm_para.h"
5860
"arch/powerpc/include/uapi/asm/kvm.h"
5961
"arch/s390/include/uapi/asm/kvm.h"
6062
"arch/s390/include/uapi/asm/kvm_perf.h"

0 commit comments

Comments
 (0)