VirtualBox

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

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

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

© 2023 Oracle
ContactPrivacy policyTerms of Use