VirtualBox

source: vbox/trunk/src/VBox/VMM/include/GIMKvmInternal.h@ 69288

Last change on this file since 69288 was 69111, checked in by vboxsync, 7 years ago

(C) year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1/* $Id: GIMKvmInternal.h 69111 2017-10-17 14:26:02Z vboxsync $ */
2/** @file
3 * GIM - KVM, Internal header file.
4 */
5
6/*
7 * Copyright (C) 2015-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___GIMKvmInternal_h
19#define ___GIMKvmInternal_h
20
21#include <VBox/vmm/gim.h>
22#include <VBox/vmm/cpum.h>
23
24
25/** @name KVM base features.
26 * @{
27 */
28/** Old, deprecated clock source available. */
29#define GIM_KVM_BASE_FEAT_CLOCK_OLD RT_BIT(0)
30/** No need for artifical delays on IO operations. */
31#define GIM_KVM_BASE_FEAT_NOP_IO_DELAY RT_BIT(1)
32/** MMU op supported (deprecated, unused). */
33#define GIM_KVM_BASE_FEAT_MMU_OP RT_BIT(2)
34/** Clock source available. */
35#define GIM_KVM_BASE_FEAT_CLOCK RT_BIT(3)
36/** Asynchronous page faults supported. */
37#define GIM_KVM_BASE_FEAT_ASYNC_PF RT_BIT(4)
38/** Steal time (VCPU not executing guest code time in ns) available. */
39#define GIM_KVM_BASE_FEAT_STEAL_TIME RT_BIT(5)
40/** Paravirtualized EOI (end-of-interrupt) supported. */
41#define GIM_KVM_BASE_FEAT_PV_EOI RT_BIT(6)
42/** Paravirtualized spinlock (unhalting VCPU) supported. */
43#define GIM_KVM_BASE_FEAT_PV_UNHALT RT_BIT(7)
44/** The TSC is stable (fixed rate, monotonic). */
45#define GIM_KVM_BASE_FEAT_TSC_STABLE RT_BIT(24)
46/** @} */
47
48
49/** @name KVM MSRs.
50 * @{
51 */
52/** Start of range 0. */
53#define MSR_GIM_KVM_RANGE0_START UINT32_C(0x11)
54/** Old, deprecated wall clock. */
55#define MSR_GIM_KVM_WALL_CLOCK_OLD UINT32_C(0x11)
56/** Old, deprecated System time. */
57#define MSR_GIM_KVM_SYSTEM_TIME_OLD UINT32_C(0x12)
58/** End of range 0. */
59#define MSR_GIM_KVM_RANGE0_END MSR_GIM_KVM_SYSTEM_TIME_OLD
60
61/** Start of range 1. */
62#define MSR_GIM_KVM_RANGE1_START UINT32_C(0x4b564d00)
63/** Wall clock. */
64#define MSR_GIM_KVM_WALL_CLOCK UINT32_C(0x4b564d00)
65/** System time. */
66#define MSR_GIM_KVM_SYSTEM_TIME UINT32_C(0x4b564d01)
67/** Asynchronous page fault. */
68#define MSR_GIM_KVM_ASYNC_PF UINT32_C(0x4b564d02)
69/** Steal time. */
70#define MSR_GIM_KVM_STEAL_TIME UINT32_C(0x4b564d03)
71/** Paravirtualized EOI (end-of-interrupt). */
72#define MSR_GIM_KVM_EOI UINT32_C(0x4b564d04)
73/** End of range 1. */
74#define MSR_GIM_KVM_RANGE1_END MSR_GIM_KVM_EOI
75
76AssertCompile(MSR_GIM_KVM_RANGE0_START <= MSR_GIM_KVM_RANGE0_END);
77AssertCompile(MSR_GIM_KVM_RANGE1_START <= MSR_GIM_KVM_RANGE1_END);
78
79/** KVM page size. */
80#define GIM_KVM_PAGE_SIZE 0x1000
81
82/**
83 * MMIO2 region indices.
84 */
85/** The system time page(s) region. */
86#define GIM_KVM_SYSTEM_TIME_PAGE_REGION_IDX UINT8_C(0)
87/** The steal time page(s) region. */
88#define GIM_KVM_STEAL_TIME_PAGE_REGION_IDX UINT8_C(1)
89/** The maximum region index (must be <= UINT8_MAX). */
90#define GIM_KVM_REGION_IDX_MAX GIM_KVM_STEAL_TIME_PAGE_REGION_IDX
91
92/**
93 * KVM system-time structure (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags.
94 * See "Documentation/virtual/kvm/api.txt".
95 */
96/** The TSC is stable (monotonic). */
97#define GIM_KVM_SYSTEM_TIME_FLAGS_TSC_STABLE RT_BIT(0)
98/** The guest VCPU has been paused by the hypervisor. */
99#define GIM_KVM_SYSTEM_TIME_FLAGS_GUEST_PAUSED RT_BIT(1)
100/** */
101
102/** @name KVM MSR - System time (MSR_GIM_KVM_SYSTEM_TIME and
103 * MSR_GIM_KVM_SYSTEM_TIME_OLD).
104 * @{
105 */
106/** The system-time enable bit. */
107#define MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT RT_BIT_64(0)
108/** Whether the system-time struct. is enabled or not. */
109#define MSR_GIM_KVM_SYSTEM_TIME_IS_ENABLED(a) RT_BOOL((a) & MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT)
110/** Guest-physical address of the system-time struct. */
111#define MSR_GIM_KVM_SYSTEM_TIME_GUEST_GPA(a) ((a) & ~MSR_GIM_KVM_SYSTEM_TIME_ENABLE_BIT)
112/** @} */
113
114/** @name KVM MSR - Wall clock (MSR_GIM_KVM_WALL_CLOCK and
115 * MSR_GIM_KVM_WALL_CLOCK_OLD).
116 * @{
117 */
118/** Guest-physical address of the wall-clock struct. */
119#define MSR_GIM_KVM_WALL_CLOCK_GUEST_GPA(a) (a)
120/** @} */
121
122
123/** @name KVM Hypercall operations.
124 * @{ */
125#define KVM_HYPERCALL_OP_VAPIC_POLL_IRQ 1
126#define KVM_HYPERCALL_OP_MMU 2
127#define KVM_HYPERCALL_OP_FEATURES 3
128#define KVM_HYPERCALL_OP_KICK_CPU 5
129/** @} */
130
131/** @name KVM Hypercall return values.
132 * @{ */
133/* Return values for hypercalls */
134#define KVM_HYPERCALL_RET_SUCCESS 0
135#define KVM_HYPERCALL_RET_ENOSYS (uint64_t)(-1000)
136#define KVM_HYPERCALL_RET_EFAULT (uint64_t)(-14)
137#define KVM_HYPERCALL_RET_E2BIG (uint64_t)(-7)
138#define KVM_HYPERCALL_RET_EPERM (uint64_t)(-1)
139/** @} */
140
141/**
142 * KVM per-VCPU system-time structure.
143 */
144typedef struct GIMKVMSYSTEMTIME
145{
146 /** Version (sequence number). */
147 uint32_t u32Version;
148 /** Alignment padding. */
149 uint32_t u32Padding0;
150 /** TSC time stamp. */
151 uint64_t u64Tsc;
152 /** System time in nanoseconds. */
153 uint64_t u64NanoTS;
154 /** TSC to system time scale factor. */
155 uint32_t u32TscScale;
156 /** TSC frequency shift. */
157 int8_t i8TscShift;
158 /** Clock source (GIM_KVM_SYSTEM_TIME_FLAGS_XXX) flags. */
159 uint8_t fFlags;
160 /** Alignment padding. */
161 uint8_t abPadding0[2];
162} GIMKVMSYSTEMTIME;
163/** Pointer to KVM system-time struct. */
164typedef GIMKVMSYSTEMTIME *PGIMKVMSYSTEMTIME;
165/** Pointer to a const KVM system-time struct. */
166typedef GIMKVMSYSTEMTIME const *PCGIMKVMSYSTEMTIME;
167AssertCompileSize(GIMKVMSYSTEMTIME, 32);
168
169
170/**
171 * KVM per-VM wall-clock structure.
172 */
173typedef struct GIMKVMWALLCLOCK
174{
175 /** Version (sequence number). */
176 uint32_t u32Version;
177 /** Number of seconds since boot. */
178 uint32_t u32Sec;
179 /** Number of nanoseconds since boot. */
180 uint32_t u32Nano;
181} GIMKVMWALLCLOCK;
182/** Pointer to KVM wall-clock struct. */
183typedef GIMKVMWALLCLOCK *PGIMKVMWALLCLOCK;
184/** Pointer to a const KVM wall-clock struct. */
185typedef GIMKVMWALLCLOCK const *PCGIMKVMWALLCLOCK;
186AssertCompileSize(GIMKVMWALLCLOCK, 12);
187
188
189/**
190 * GIM KVM VM instance data.
191 * Changes to this must checked against the padding of the gim union in VM!
192 */
193typedef struct GIMKVM
194{
195 /** Wall-clock MSR. */
196 uint64_t u64WallClockMsr;
197 /** CPUID features: Basic. */
198 uint32_t uBaseFeat;
199 /** Whether GIM needs to trap \#UD exceptions. */
200 bool fTrapXcptUD;
201 /** Disassembler opcode of hypercall instruction native for this host CPU. */
202 uint16_t uOpCodeNative;
203 /** The TSC frequency (in HZ) reported to the guest. */
204 uint64_t cTscTicksPerSecond;
205 /** Spinlock used for protecting GIMKVMCPU::uTsc and
206 * GIMKVMCPU::uVirtNanoTS. */
207 RTSPINLOCK hSpinlockR0;
208} GIMKVM;
209/** Pointer to per-VM GIM KVM instance data. */
210typedef GIMKVM *PGIMKVM;
211/** Pointer to const per-VM GIM KVM instance data. */
212typedef GIMKVM const *PCGIMKVM;
213
214/**
215 * GIM KVMV VCPU instance data.
216 * Changes to this must checked against the padding of the gim union in VMCPU!
217 */
218typedef struct GIMKVMCPU
219{
220 /** System-time MSR. */
221 uint64_t u64SystemTimeMsr;
222 /** The guest-physical address of the system-time struct. */
223 RTGCPHYS GCPhysSystemTime;
224 /** The version (sequence number) of the system-time struct. */
225 uint32_t u32SystemTimeVersion;
226 /** The guest TSC value while enabling the system-time MSR. */
227 uint64_t uTsc;
228 /** The guest virtual time while enabling the system-time MSR. */
229 uint64_t uVirtNanoTS;
230 /** The flags of the system-time struct. */
231 uint8_t fSystemTimeFlags;
232} GIMKVMCPU;
233/** Pointer to per-VCPU GIM KVM instance data. */
234typedef GIMKVMCPU *PGIMKVMCPU;
235/** Pointer to const per-VCPU GIM KVM instance data. */
236typedef GIMKVMCPU const *PCGIMKVMCPU;
237
238
239RT_C_DECLS_BEGIN
240
241#ifdef IN_RING0
242VMMR0_INT_DECL(int) gimR0KvmInitVM(PVM pVM);
243VMMR0_INT_DECL(int) gimR0KvmTermVM(PVM pVM);
244VMMR0_INT_DECL(int) gimR0KvmUpdateSystemTime(PVM pVM, PVMCPU pVCpu);
245#endif /* IN_RING0 */
246
247#ifdef IN_RING3
248VMMR3_INT_DECL(int) gimR3KvmInit(PVM pVM);
249VMMR3_INT_DECL(int) gimR3KvmInitCompleted(PVM pVM);
250VMMR3_INT_DECL(int) gimR3KvmTerm(PVM pVM);
251VMMR3_INT_DECL(void) gimR3KvmRelocate(PVM pVM, RTGCINTPTR offDelta);
252VMMR3_INT_DECL(void) gimR3KvmReset(PVM pVM);
253VMMR3_INT_DECL(int) gimR3KvmSave(PVM pVM, PSSMHANDLE pSSM);
254VMMR3_INT_DECL(int) gimR3KvmLoad(PVM pVM, PSSMHANDLE pSSM);
255
256VMMR3_INT_DECL(int) gimR3KvmDisableSystemTime(PVM pVM);
257VMMR3_INT_DECL(int) gimR3KvmEnableSystemTime(PVM pVM, PVMCPU pVCpu);
258VMMR3_INT_DECL(int) gimR3KvmEnableWallClock(PVM pVM, RTGCPHYS GCPhysSysTime);
259#endif /* IN_RING3 */
260
261VMM_INT_DECL(bool) gimKvmIsParavirtTscEnabled(PVM pVM);
262VMM_INT_DECL(bool) gimKvmAreHypercallsEnabled(PVMCPU pVCpu);
263VMM_INT_DECL(VBOXSTRICTRC) gimKvmHypercall(PVMCPU pVCpu, PCPUMCTX pCtx);
264VMM_INT_DECL(VBOXSTRICTRC) gimKvmReadMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t *puValue);
265VMM_INT_DECL(VBOXSTRICTRC) gimKvmWriteMsr(PVMCPU pVCpu, uint32_t idMsr, PCCPUMMSRRANGE pRange, uint64_t uRawValue);
266VMM_INT_DECL(bool) gimKvmShouldTrapXcptUD(PVMCPU pVCpu);
267VMM_INT_DECL(VBOXSTRICTRC) gimKvmXcptUD(PVMCPU pVCpu, PCPUMCTX pCtx, PDISCPUSTATE pDis, uint8_t *pcbInstr);
268VMM_INT_DECL(VBOXSTRICTRC) gimKvmExecHypercallInstr(PVMCPU pVCpu, PCPUMCTX pCtx, PDISCPUSTATE pDis);
269
270
271RT_C_DECLS_END
272
273#endif
274
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette