VirtualBox

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

Last change on this file since 56874 was 56813, checked in by vboxsync, 10 years ago

VMM/GIM: Fix regression introduced in r101441 (on hosts without threadctxhooks, we need to take spinlocks)

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