1 | /* $Id: VMMRZ.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM - Virtual Machine Monitor, Raw-mode and ring-0 context code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #define LOG_GROUP LOG_GROUP_VMM
|
---|
33 | #include <VBox/vmm/vmm.h>
|
---|
34 | #include "VMMInternal.h"
|
---|
35 | #include <VBox/vmm/vmcc.h>
|
---|
36 |
|
---|
37 | #include <iprt/assert.h>
|
---|
38 | #include <iprt/asm-amd64-x86.h>
|
---|
39 | #include <iprt/errcore.h>
|
---|
40 | #include <iprt/string.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Disables all host calls, except certain fatal ones.
|
---|
45 | *
|
---|
46 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
47 | * @thread EMT.
|
---|
48 | */
|
---|
49 | VMMRZDECL(void) VMMRZCallRing3Disable(PVMCPUCC pVCpu)
|
---|
50 | {
|
---|
51 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
52 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
53 | RTCCUINTREG fFlags = ASMIntDisableFlags(); /* preemption consistency. */
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | Assert(pVCpu->vmmr0.s.cCallRing3Disabled < 16);
|
---|
57 | if (ASMAtomicUoIncU32(&pVCpu->vmmr0.s.cCallRing3Disabled) == 1)
|
---|
58 | {
|
---|
59 | #ifdef IN_RC
|
---|
60 | pVCpu->pVMRC->vmm.s.fRCLoggerFlushingDisabled = true;
|
---|
61 | #else
|
---|
62 | pVCpu->vmmr0.s.fLogFlushingDisabled = true;
|
---|
63 | #endif
|
---|
64 | }
|
---|
65 |
|
---|
66 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
67 | ASMSetFlags(fFlags);
|
---|
68 | #endif
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Counters VMMRZCallRing3Disable() and re-enables host calls.
|
---|
74 | *
|
---|
75 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
76 | * @thread EMT.
|
---|
77 | */
|
---|
78 | VMMRZDECL(void) VMMRZCallRing3Enable(PVMCPUCC pVCpu)
|
---|
79 | {
|
---|
80 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
81 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
82 | RTCCUINTREG fFlags = ASMIntDisableFlags(); /* preemption consistency. */
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | Assert(pVCpu->vmmr0.s.cCallRing3Disabled > 0);
|
---|
86 | if (ASMAtomicUoDecU32(&pVCpu->vmmr0.s.cCallRing3Disabled) == 0)
|
---|
87 | {
|
---|
88 | #ifdef IN_RC
|
---|
89 | pVCpu->pVMRC->vmm.s.fRCLoggerFlushingDisabled = false;
|
---|
90 | #else
|
---|
91 | pVCpu->vmmr0.s.fLogFlushingDisabled = false;
|
---|
92 | #endif
|
---|
93 | }
|
---|
94 |
|
---|
95 | #if defined(LOG_ENABLED) && defined(IN_RING0)
|
---|
96 | ASMSetFlags(fFlags);
|
---|
97 | #endif
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Checks whether its possible to call host context or not.
|
---|
103 | *
|
---|
104 | * @returns true if it's safe, false if it isn't.
|
---|
105 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
106 | */
|
---|
107 | VMMRZDECL(bool) VMMRZCallRing3IsEnabled(PVMCPUCC pVCpu)
|
---|
108 | {
|
---|
109 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
110 | Assert(pVCpu->vmmr0.s.cCallRing3Disabled <= 16);
|
---|
111 | return pVCpu->vmmr0.s.cCallRing3Disabled == 0;
|
---|
112 | }
|
---|
113 |
|
---|