VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/GIMR0Kvm.cpp@ 81916

Last change on this file since 81916 was 80333, checked in by vboxsync, 5 years ago

VMM: Eliminating the VBOX_BUGREF_9217_PART_I preprocessor macro. bugref:9217

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: GIMR0Kvm.cpp 80333 2019-08-16 20:28:38Z vboxsync $ */
2/** @file
3 * Guest Interface Manager (GIM), KVM - Host Context Ring-0.
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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_GIM
23#include <VBox/vmm/gim.h>
24#include <VBox/vmm/tm.h>
25#include "GIMInternal.h"
26#include "GIMKvmInternal.h"
27#include <VBox/vmm/vmcc.h>
28
29#include <VBox/err.h>
30
31#include <iprt/spinlock.h>
32
33
34/**
35 * Updates KVM's system time information globally for all VCPUs.
36 *
37 * @returns VBox status code.
38 * @param pVM The cross context VM structure.
39 * @param pVCpu The cross context virtual CPU structure.
40 * @thread EMT.
41 * @remarks Can be called with preemption disabled!
42 */
43VMM_INT_DECL(int) gimR0KvmUpdateSystemTime(PVMCC pVM, PVMCPUCC pVCpu)
44{
45 /*
46 * Validate.
47 */
48 Assert(GIMIsEnabled(pVM));
49 PGIMKVM pKvm = &pVM->gim.s.u.Kvm;
50 AssertReturn(pKvm->hSpinlockR0 != NIL_RTSPINLOCK, VERR_GIM_IPE_3);
51
52 /*
53 * Record the TSC and virtual NanoTS pairs.
54 */
55 uint64_t uTsc;
56 uint64_t uVirtNanoTS;
57 RTCCUINTREG fEFlags = ASMIntDisableFlags();
58 uTsc = TMCpuTickGetNoCheck(pVCpu) | UINT64_C(1);
59 uVirtNanoTS = TMVirtualGetNoCheck(pVM) | UINT64_C(1);
60 ASMSetFlags(fEFlags);
61
62 /*
63 * Update VCPUs with this information. The first VCPU's values
64 * will be applied to the remaining.
65 */
66 RTSpinlockAcquire(pKvm->hSpinlockR0);
67 for (VMCPUID idCpu = 0; idCpu < pVM->cCpus; idCpu++)
68 {
69 PGIMKVMCPU pKvmCpu = &VMCC_GET_CPU(pVM, idCpu)->gim.s.u.KvmCpu;
70 if ( !pKvmCpu->uTsc
71 && !pKvmCpu->uVirtNanoTS)
72 {
73 pKvmCpu->uTsc = uTsc;
74 pKvmCpu->uVirtNanoTS = uVirtNanoTS;
75 }
76 }
77 RTSpinlockRelease(pKvm->hSpinlockR0);
78
79 return VINF_SUCCESS;
80}
81
82
83/**
84 * Does ring-0 per-VM GIM KVM initialization.
85 *
86 * @returns VBox status code.
87 * @param pVM The cross context VM structure.
88 */
89VMMR0_INT_DECL(int) gimR0KvmInitVM(PVMCC pVM)
90{
91 AssertPtr(pVM);
92 Assert(GIMIsEnabled(pVM));
93
94 PGIMKVM pKvm = &pVM->gim.s.u.Kvm;
95 Assert(pKvm->hSpinlockR0 == NIL_RTSPINLOCK);
96
97 int rc = RTSpinlockCreate(&pKvm->hSpinlockR0, RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, "KVM");
98 return rc;
99}
100
101
102/**
103 * Does ring-0 per-VM GIM KVM termination.
104 *
105 * @returns VBox status code.
106 * @param pVM The cross context VM structure.
107 */
108VMMR0_INT_DECL(int) gimR0KvmTermVM(PVMCC pVM)
109{
110 AssertPtr(pVM);
111 Assert(GIMIsEnabled(pVM));
112
113 PGIMKVM pKvm = &pVM->gim.s.u.Kvm;
114 RTSpinlockDestroy(pKvm->hSpinlockR0);
115 pKvm->hSpinlockR0 = NIL_RTSPINLOCK;
116
117 return VINF_SUCCESS;
118}
119
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