VirtualBox

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

最後變更 在這個檔案從83372是 83372,由 vboxsync 提交於 5 年 前

GIM/KVM: Update system-time struct on demand. Fixes guests that rely on the struct being frequently updated, e.g. SLES 10 SP4 (see bugref:7270).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.3 KB
 
1/* $Id: GIMR0Kvm.cpp 83372 2020-03-23 14:52:24Z vboxsync $ */
2/** @file
3 * Guest Interface Manager (GIM), KVM - Host Context Ring-0.
4 */
5
6/*
7 * Copyright (C) 2015-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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);
59 uVirtNanoTS = TMVirtualGetNoCheck(pVM);
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 pKvmCpu->uTsc = uTsc;
71 pKvmCpu->uVirtNanoTS = uVirtNanoTS;
72 }
73 RTSpinlockRelease(pKvm->hSpinlockR0);
74
75 return VINF_SUCCESS;
76}
77
78
79/**
80 * Does ring-0 per-VM GIM KVM initialization.
81 *
82 * @returns VBox status code.
83 * @param pVM The cross context VM structure.
84 */
85VMMR0_INT_DECL(int) gimR0KvmInitVM(PVMCC pVM)
86{
87 AssertPtr(pVM);
88 Assert(GIMIsEnabled(pVM));
89
90 PGIMKVM pKvm = &pVM->gim.s.u.Kvm;
91 Assert(pKvm->hSpinlockR0 == NIL_RTSPINLOCK);
92
93 int rc = RTSpinlockCreate(&pKvm->hSpinlockR0, RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, "KVM");
94 return rc;
95}
96
97
98/**
99 * Does ring-0 per-VM GIM KVM termination.
100 *
101 * @returns VBox status code.
102 * @param pVM The cross context VM structure.
103 */
104VMMR0_INT_DECL(int) gimR0KvmTermVM(PVMCC pVM)
105{
106 AssertPtr(pVM);
107 Assert(GIMIsEnabled(pVM));
108
109 PGIMKVM pKvm = &pVM->gim.s.u.Kvm;
110 RTSpinlockDestroy(pKvm->hSpinlockR0);
111 pKvm->hSpinlockR0 = NIL_RTSPINLOCK;
112
113 return VINF_SUCCESS;
114}
115
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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