VirtualBox

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

Last change on this file since 78359 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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