162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
262306a36Sopenharmony_ci#ifndef _UAPI_ASM_X86_KVM_PARA_H
362306a36Sopenharmony_ci#define _UAPI_ASM_X86_KVM_PARA_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/types.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx.  It
862306a36Sopenharmony_ci * should be used to determine that a VM is running under KVM.
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci#define KVM_CPUID_SIGNATURE	0x40000000
1162306a36Sopenharmony_ci#define KVM_SIGNATURE "KVMKVMKVM\0\0\0"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* This CPUID returns two feature bitmaps in eax, edx. Before enabling
1462306a36Sopenharmony_ci * a particular paravirtualization, the appropriate feature bit should
1562306a36Sopenharmony_ci * be checked in eax. The performance hint feature bit should be checked
1662306a36Sopenharmony_ci * in edx.
1762306a36Sopenharmony_ci */
1862306a36Sopenharmony_ci#define KVM_CPUID_FEATURES	0x40000001
1962306a36Sopenharmony_ci#define KVM_FEATURE_CLOCKSOURCE		0
2062306a36Sopenharmony_ci#define KVM_FEATURE_NOP_IO_DELAY	1
2162306a36Sopenharmony_ci#define KVM_FEATURE_MMU_OP		2
2262306a36Sopenharmony_ci/* This indicates that the new set of kvmclock msrs
2362306a36Sopenharmony_ci * are available. The use of 0x11 and 0x12 is deprecated
2462306a36Sopenharmony_ci */
2562306a36Sopenharmony_ci#define KVM_FEATURE_CLOCKSOURCE2        3
2662306a36Sopenharmony_ci#define KVM_FEATURE_ASYNC_PF		4
2762306a36Sopenharmony_ci#define KVM_FEATURE_STEAL_TIME		5
2862306a36Sopenharmony_ci#define KVM_FEATURE_PV_EOI		6
2962306a36Sopenharmony_ci#define KVM_FEATURE_PV_UNHALT		7
3062306a36Sopenharmony_ci#define KVM_FEATURE_PV_TLB_FLUSH	9
3162306a36Sopenharmony_ci#define KVM_FEATURE_ASYNC_PF_VMEXIT	10
3262306a36Sopenharmony_ci#define KVM_FEATURE_PV_SEND_IPI	11
3362306a36Sopenharmony_ci#define KVM_FEATURE_POLL_CONTROL	12
3462306a36Sopenharmony_ci#define KVM_FEATURE_PV_SCHED_YIELD	13
3562306a36Sopenharmony_ci#define KVM_FEATURE_ASYNC_PF_INT	14
3662306a36Sopenharmony_ci#define KVM_FEATURE_MSI_EXT_DEST_ID	15
3762306a36Sopenharmony_ci#define KVM_FEATURE_HC_MAP_GPA_RANGE	16
3862306a36Sopenharmony_ci#define KVM_FEATURE_MIGRATION_CONTROL	17
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define KVM_HINTS_REALTIME      0
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* The last 8 bits are used to indicate how to interpret the flags field
4362306a36Sopenharmony_ci * in pvclock structure. If no bits are set, all flags are ignored.
4462306a36Sopenharmony_ci */
4562306a36Sopenharmony_ci#define KVM_FEATURE_CLOCKSOURCE_STABLE_BIT	24
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define MSR_KVM_WALL_CLOCK  0x11
4862306a36Sopenharmony_ci#define MSR_KVM_SYSTEM_TIME 0x12
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define KVM_MSR_ENABLED 1
5162306a36Sopenharmony_ci/* Custom MSRs falls in the range 0x4b564d00-0x4b564dff */
5262306a36Sopenharmony_ci#define MSR_KVM_WALL_CLOCK_NEW  0x4b564d00
5362306a36Sopenharmony_ci#define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01
5462306a36Sopenharmony_ci#define MSR_KVM_ASYNC_PF_EN 0x4b564d02
5562306a36Sopenharmony_ci#define MSR_KVM_STEAL_TIME  0x4b564d03
5662306a36Sopenharmony_ci#define MSR_KVM_PV_EOI_EN      0x4b564d04
5762306a36Sopenharmony_ci#define MSR_KVM_POLL_CONTROL	0x4b564d05
5862306a36Sopenharmony_ci#define MSR_KVM_ASYNC_PF_INT	0x4b564d06
5962306a36Sopenharmony_ci#define MSR_KVM_ASYNC_PF_ACK	0x4b564d07
6062306a36Sopenharmony_ci#define MSR_KVM_MIGRATION_CONTROL	0x4b564d08
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct kvm_steal_time {
6362306a36Sopenharmony_ci	__u64 steal;
6462306a36Sopenharmony_ci	__u32 version;
6562306a36Sopenharmony_ci	__u32 flags;
6662306a36Sopenharmony_ci	__u8  preempted;
6762306a36Sopenharmony_ci	__u8  u8_pad[3];
6862306a36Sopenharmony_ci	__u32 pad[11];
6962306a36Sopenharmony_ci};
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define KVM_VCPU_PREEMPTED          (1 << 0)
7262306a36Sopenharmony_ci#define KVM_VCPU_FLUSH_TLB          (1 << 1)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define KVM_CLOCK_PAIRING_WALLCLOCK 0
7562306a36Sopenharmony_cistruct kvm_clock_pairing {
7662306a36Sopenharmony_ci	__s64 sec;
7762306a36Sopenharmony_ci	__s64 nsec;
7862306a36Sopenharmony_ci	__u64 tsc;
7962306a36Sopenharmony_ci	__u32 flags;
8062306a36Sopenharmony_ci	__u32 pad[9];
8162306a36Sopenharmony_ci};
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define KVM_STEAL_ALIGNMENT_BITS 5
8462306a36Sopenharmony_ci#define KVM_STEAL_VALID_BITS ((-1ULL << (KVM_STEAL_ALIGNMENT_BITS + 1)))
8562306a36Sopenharmony_ci#define KVM_STEAL_RESERVED_MASK (((1 << KVM_STEAL_ALIGNMENT_BITS) - 1 ) << 1)
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define KVM_MAX_MMU_OP_BATCH           32
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci#define KVM_ASYNC_PF_ENABLED			(1 << 0)
9062306a36Sopenharmony_ci#define KVM_ASYNC_PF_SEND_ALWAYS		(1 << 1)
9162306a36Sopenharmony_ci#define KVM_ASYNC_PF_DELIVERY_AS_PF_VMEXIT	(1 << 2)
9262306a36Sopenharmony_ci#define KVM_ASYNC_PF_DELIVERY_AS_INT		(1 << 3)
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci/* MSR_KVM_ASYNC_PF_INT */
9562306a36Sopenharmony_ci#define KVM_ASYNC_PF_VEC_MASK			GENMASK(7, 0)
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/* MSR_KVM_MIGRATION_CONTROL */
9862306a36Sopenharmony_ci#define KVM_MIGRATION_READY		(1 << 0)
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci/* KVM_HC_MAP_GPA_RANGE */
10162306a36Sopenharmony_ci#define KVM_MAP_GPA_RANGE_PAGE_SZ_4K	0
10262306a36Sopenharmony_ci#define KVM_MAP_GPA_RANGE_PAGE_SZ_2M	(1 << 0)
10362306a36Sopenharmony_ci#define KVM_MAP_GPA_RANGE_PAGE_SZ_1G	(1 << 1)
10462306a36Sopenharmony_ci#define KVM_MAP_GPA_RANGE_ENC_STAT(n)	(n << 4)
10562306a36Sopenharmony_ci#define KVM_MAP_GPA_RANGE_ENCRYPTED	KVM_MAP_GPA_RANGE_ENC_STAT(1)
10662306a36Sopenharmony_ci#define KVM_MAP_GPA_RANGE_DECRYPTED	KVM_MAP_GPA_RANGE_ENC_STAT(0)
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* Operations for KVM_HC_MMU_OP */
10962306a36Sopenharmony_ci#define KVM_MMU_OP_WRITE_PTE            1
11062306a36Sopenharmony_ci#define KVM_MMU_OP_FLUSH_TLB	        2
11162306a36Sopenharmony_ci#define KVM_MMU_OP_RELEASE_PT	        3
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/* Payload for KVM_HC_MMU_OP */
11462306a36Sopenharmony_cistruct kvm_mmu_op_header {
11562306a36Sopenharmony_ci	__u32 op;
11662306a36Sopenharmony_ci	__u32 pad;
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistruct kvm_mmu_op_write_pte {
12062306a36Sopenharmony_ci	struct kvm_mmu_op_header header;
12162306a36Sopenharmony_ci	__u64 pte_phys;
12262306a36Sopenharmony_ci	__u64 pte_val;
12362306a36Sopenharmony_ci};
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_cistruct kvm_mmu_op_flush_tlb {
12662306a36Sopenharmony_ci	struct kvm_mmu_op_header header;
12762306a36Sopenharmony_ci};
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_cistruct kvm_mmu_op_release_pt {
13062306a36Sopenharmony_ci	struct kvm_mmu_op_header header;
13162306a36Sopenharmony_ci	__u64 pt_phys;
13262306a36Sopenharmony_ci};
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci#define KVM_PV_REASON_PAGE_NOT_PRESENT 1
13562306a36Sopenharmony_ci#define KVM_PV_REASON_PAGE_READY 2
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistruct kvm_vcpu_pv_apf_data {
13862306a36Sopenharmony_ci	/* Used for 'page not present' events delivered via #PF */
13962306a36Sopenharmony_ci	__u32 flags;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	/* Used for 'page ready' events delivered via interrupt notification */
14262306a36Sopenharmony_ci	__u32 token;
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci	__u8 pad[56];
14562306a36Sopenharmony_ci	__u32 enabled;
14662306a36Sopenharmony_ci};
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define KVM_PV_EOI_BIT 0
14962306a36Sopenharmony_ci#define KVM_PV_EOI_MASK (0x1 << KVM_PV_EOI_BIT)
15062306a36Sopenharmony_ci#define KVM_PV_EOI_ENABLED KVM_PV_EOI_MASK
15162306a36Sopenharmony_ci#define KVM_PV_EOI_DISABLED 0x0
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci#endif /* _UAPI_ASM_X86_KVM_PARA_H */
154