[23] | 1 | /* $Id: VMReq.cpp 69111 2017-10-17 14:26:02Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | * VM - Virtual Machine
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[69111] | 7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
[57358] | 19 | /*********************************************************************************************************************************
|
---|
| 20 | * Header Files *
|
---|
| 21 | *********************************************************************************************************************************/
|
---|
[1] | 22 | #define LOG_GROUP LOG_GROUP_VM
|
---|
[35346] | 23 | #include <VBox/vmm/mm.h>
|
---|
| 24 | #include <VBox/vmm/vmm.h>
|
---|
[1] | 25 | #include "VMInternal.h"
|
---|
[35346] | 26 | #include <VBox/vmm/vm.h>
|
---|
| 27 | #include <VBox/vmm/uvm.h>
|
---|
[1] | 28 |
|
---|
| 29 | #include <VBox/err.h>
|
---|
| 30 | #include <VBox/param.h>
|
---|
| 31 | #include <VBox/log.h>
|
---|
| 32 | #include <iprt/assert.h>
|
---|
| 33 | #include <iprt/asm.h>
|
---|
| 34 | #include <iprt/string.h>
|
---|
| 35 | #include <iprt/time.h>
|
---|
| 36 | #include <iprt/semaphore.h>
|
---|
| 37 | #include <iprt/thread.h>
|
---|
| 38 |
|
---|
| 39 |
|
---|
[57358] | 40 | /*********************************************************************************************************************************
|
---|
| 41 | * Internal Functions *
|
---|
| 42 | *********************************************************************************************************************************/
|
---|
[62647] | 43 | static int vmR3ReqProcessOne(PVMREQ pReq);
|
---|
[1] | 44 |
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
[44340] | 47 | * Convenience wrapper for VMR3ReqCallU.
|
---|
[1] | 48 | *
|
---|
[44340] | 49 | * This assumes (1) you're calling a function that returns an VBox status code,
|
---|
| 50 | * (2) that you want it's return code on success, and (3) that you wish to wait
|
---|
| 51 | * for ever for it to return.
|
---|
[1] | 52 | *
|
---|
[44340] | 53 | * @returns VBox status code. In the unlikely event that VMR3ReqCallVU fails,
|
---|
| 54 | * its status code is return. Otherwise, the status of pfnFunction is
|
---|
| 55 | * returned.
|
---|
[1] | 56 | *
|
---|
[58122] | 57 | * @param pVM The cross context VM structure.
|
---|
[19300] | 58 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 59 | * one of the following special values:
|
---|
[20880] | 60 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
[1] | 61 | * @param pfnFunction Pointer to the function to call.
|
---|
| 62 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 63 | * @param ... Function arguments.
|
---|
[24467] | 64 | *
|
---|
| 65 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[44340] | 66 | * @internal
|
---|
[1] | 67 | */
|
---|
[44340] | 68 | VMMR3_INT_DECL(int) VMR3ReqCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
[1] | 69 | {
|
---|
[44340] | 70 | PVMREQ pReq;
|
---|
[1] | 71 | va_list va;
|
---|
| 72 | va_start(va, cArgs);
|
---|
[44340] | 73 | int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VBOX_STATUS,
|
---|
| 74 | pfnFunction, cArgs, va);
|
---|
[1] | 75 | va_end(va);
|
---|
[44340] | 76 | if (RT_SUCCESS(rc))
|
---|
| 77 | rc = pReq->iStatus;
|
---|
| 78 | VMR3ReqFree(pReq);
|
---|
[1] | 79 | return rc;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | /**
|
---|
[23010] | 84 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 85 | *
|
---|
| 86 | * This assumes (1) you're calling a function that returns an VBox status code,
|
---|
| 87 | * (2) that you want it's return code on success, and (3) that you wish to wait
|
---|
| 88 | * for ever for it to return.
|
---|
| 89 | *
|
---|
| 90 | * @returns VBox status code. In the unlikely event that VMR3ReqCallVU fails,
|
---|
| 91 | * its status code is return. Otherwise, the status of pfnFunction is
|
---|
| 92 | * returned.
|
---|
| 93 | *
|
---|
[58126] | 94 | * @param pUVM The user mode VM structure.
|
---|
[23010] | 95 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 96 | * one of the following special values:
|
---|
| 97 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 98 | * @param pfnFunction Pointer to the function to call.
|
---|
| 99 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 100 | * @param ... Function arguments.
|
---|
[24467] | 101 | *
|
---|
| 102 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[44340] | 103 | * @internal
|
---|
[23010] | 104 | */
|
---|
[44340] | 105 | VMMR3DECL(int) VMR3ReqCallWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
[23010] | 106 | {
|
---|
| 107 | PVMREQ pReq;
|
---|
| 108 | va_list va;
|
---|
| 109 | va_start(va, cArgs);
|
---|
[44340] | 110 | int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VBOX_STATUS,
|
---|
[23010] | 111 | pfnFunction, cArgs, va);
|
---|
| 112 | va_end(va);
|
---|
| 113 | if (RT_SUCCESS(rc))
|
---|
| 114 | rc = pReq->iStatus;
|
---|
| 115 | VMR3ReqFree(pReq);
|
---|
| 116 | return rc;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | /**
|
---|
| 121 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 122 | *
|
---|
| 123 | * This assumes (1) you're calling a function that returns an VBox status code
|
---|
| 124 | * and that you do not wish to wait for it to complete.
|
---|
| 125 | *
|
---|
| 126 | * @returns VBox status code returned by VMR3ReqCallVU.
|
---|
| 127 | *
|
---|
[58122] | 128 | * @param pVM The cross context VM structure.
|
---|
[23010] | 129 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 130 | * one of the following special values:
|
---|
| 131 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 132 | * @param pfnFunction Pointer to the function to call.
|
---|
| 133 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 134 | * @param ... Function arguments.
|
---|
[24467] | 135 | *
|
---|
| 136 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[44340] | 137 | * @internal
|
---|
[23010] | 138 | */
|
---|
| 139 | VMMR3DECL(int) VMR3ReqCallNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
| 140 | {
|
---|
| 141 | va_list va;
|
---|
| 142 | va_start(va, cArgs);
|
---|
| 143 | int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, NULL, 0, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_NO_WAIT,
|
---|
| 144 | pfnFunction, cArgs, va);
|
---|
| 145 | va_end(va);
|
---|
| 146 | return rc;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | /**
|
---|
| 151 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 152 | *
|
---|
[44340] | 153 | * This assumes (1) you're calling a function that returns an VBox status code
|
---|
| 154 | * and that you do not wish to wait for it to complete.
|
---|
| 155 | *
|
---|
| 156 | * @returns VBox status code returned by VMR3ReqCallVU.
|
---|
| 157 | *
|
---|
| 158 | * @param pUVM Pointer to the VM.
|
---|
| 159 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 160 | * one of the following special values:
|
---|
| 161 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 162 | * @param pfnFunction Pointer to the function to call.
|
---|
| 163 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 164 | * @param ... Function arguments.
|
---|
| 165 | *
|
---|
| 166 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
| 167 | */
|
---|
| 168 | VMMR3DECL(int) VMR3ReqCallNoWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
| 169 | {
|
---|
| 170 | va_list va;
|
---|
| 171 | va_start(va, cArgs);
|
---|
| 172 | int rc = VMR3ReqCallVU(pUVM, idDstCpu, NULL, 0, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_NO_WAIT,
|
---|
| 173 | pfnFunction, cArgs, va);
|
---|
| 174 | va_end(va);
|
---|
| 175 | return rc;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | /**
|
---|
| 180 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 181 | *
|
---|
[23010] | 182 | * This assumes (1) you're calling a function that returns void, and (2) that
|
---|
| 183 | * you wish to wait for ever for it to return.
|
---|
| 184 | *
|
---|
| 185 | * @returns VBox status code of VMR3ReqCallVU.
|
---|
| 186 | *
|
---|
[58122] | 187 | * @param pVM The cross context VM structure.
|
---|
[23010] | 188 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 189 | * one of the following special values:
|
---|
| 190 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 191 | * @param pfnFunction Pointer to the function to call.
|
---|
| 192 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 193 | * @param ... Function arguments.
|
---|
[24467] | 194 | *
|
---|
| 195 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[44340] | 196 | * @internal
|
---|
[23010] | 197 | */
|
---|
[44340] | 198 | VMMR3_INT_DECL(int) VMR3ReqCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
[23010] | 199 | {
|
---|
| 200 | PVMREQ pReq;
|
---|
| 201 | va_list va;
|
---|
| 202 | va_start(va, cArgs);
|
---|
| 203 | int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VOID,
|
---|
| 204 | pfnFunction, cArgs, va);
|
---|
| 205 | va_end(va);
|
---|
| 206 | VMR3ReqFree(pReq);
|
---|
| 207 | return rc;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 |
|
---|
| 211 | /**
|
---|
| 212 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 213 | *
|
---|
| 214 | * This assumes (1) you're calling a function that returns void, and (2) that
|
---|
[44340] | 215 | * you wish to wait for ever for it to return.
|
---|
| 216 | *
|
---|
| 217 | * @returns VBox status code of VMR3ReqCallVU.
|
---|
| 218 | *
|
---|
| 219 | * @param pUVM Pointer to the VM.
|
---|
| 220 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 221 | * one of the following special values:
|
---|
| 222 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 223 | * @param pfnFunction Pointer to the function to call.
|
---|
| 224 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 225 | * @param ... Function arguments.
|
---|
| 226 | *
|
---|
| 227 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
| 228 | */
|
---|
| 229 | VMMR3DECL(int) VMR3ReqCallVoidWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
| 230 | {
|
---|
| 231 | PVMREQ pReq;
|
---|
| 232 | va_list va;
|
---|
| 233 | va_start(va, cArgs);
|
---|
| 234 | int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VOID,
|
---|
| 235 | pfnFunction, cArgs, va);
|
---|
| 236 | va_end(va);
|
---|
| 237 | VMR3ReqFree(pReq);
|
---|
| 238 | return rc;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | /**
|
---|
| 243 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 244 | *
|
---|
| 245 | * This assumes (1) you're calling a function that returns void, and (2) that
|
---|
[38838] | 246 | * you do not wish to wait for it to complete.
|
---|
[23010] | 247 | *
|
---|
| 248 | * @returns VBox status code of VMR3ReqCallVU.
|
---|
| 249 | *
|
---|
[58122] | 250 | * @param pVM The cross context VM structure.
|
---|
[23010] | 251 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 252 | * one of the following special values:
|
---|
| 253 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 254 | * @param pfnFunction Pointer to the function to call.
|
---|
| 255 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 256 | * @param ... Function arguments.
|
---|
[24467] | 257 | *
|
---|
| 258 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[44340] | 259 | * @internal
|
---|
[23010] | 260 | */
|
---|
[38838] | 261 | VMMR3DECL(int) VMR3ReqCallVoidNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
[23010] | 262 | {
|
---|
| 263 | PVMREQ pReq;
|
---|
| 264 | va_list va;
|
---|
| 265 | va_start(va, cArgs);
|
---|
[38838] | 266 | int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VOID | VMREQFLAGS_NO_WAIT,
|
---|
[23010] | 267 | pfnFunction, cArgs, va);
|
---|
| 268 | va_end(va);
|
---|
| 269 | VMR3ReqFree(pReq);
|
---|
| 270 | return rc;
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | /**
|
---|
| 275 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 276 | *
|
---|
[38838] | 277 | * This assumes (1) you're calling a function that returns an VBox status code,
|
---|
| 278 | * (2) that you want it's return code on success, (3) that you wish to wait for
|
---|
| 279 | * ever for it to return, and (4) that it's priority request that can be safely
|
---|
[39327] | 280 | * be handled during async suspend and power off.
|
---|
[23010] | 281 | *
|
---|
[38838] | 282 | * @returns VBox status code. In the unlikely event that VMR3ReqCallVU fails,
|
---|
| 283 | * its status code is return. Otherwise, the status of pfnFunction is
|
---|
| 284 | * returned.
|
---|
[23010] | 285 | *
|
---|
[58122] | 286 | * @param pVM The cross context VM structure.
|
---|
[23010] | 287 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 288 | * one of the following special values:
|
---|
| 289 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 290 | * @param pfnFunction Pointer to the function to call.
|
---|
| 291 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 292 | * @param ... Function arguments.
|
---|
[24467] | 293 | *
|
---|
| 294 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[44340] | 295 | * @internal
|
---|
[23010] | 296 | */
|
---|
[38838] | 297 | VMMR3DECL(int) VMR3ReqPriorityCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
[23010] | 298 | {
|
---|
| 299 | PVMREQ pReq;
|
---|
| 300 | va_list va;
|
---|
| 301 | va_start(va, cArgs);
|
---|
[38838] | 302 | int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_PRIORITY,
|
---|
[23010] | 303 | pfnFunction, cArgs, va);
|
---|
| 304 | va_end(va);
|
---|
[38838] | 305 | if (RT_SUCCESS(rc))
|
---|
| 306 | rc = pReq->iStatus;
|
---|
[23010] | 307 | VMR3ReqFree(pReq);
|
---|
| 308 | return rc;
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 |
|
---|
| 312 | /**
|
---|
| 313 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 314 | *
|
---|
[44340] | 315 | * This assumes (1) you're calling a function that returns an VBox status code,
|
---|
| 316 | * (2) that you want it's return code on success, (3) that you wish to wait for
|
---|
| 317 | * ever for it to return, and (4) that it's priority request that can be safely
|
---|
| 318 | * be handled during async suspend and power off.
|
---|
| 319 | *
|
---|
| 320 | * @returns VBox status code. In the unlikely event that VMR3ReqCallVU fails,
|
---|
| 321 | * its status code is return. Otherwise, the status of pfnFunction is
|
---|
| 322 | * returned.
|
---|
| 323 | *
|
---|
| 324 | * @param pUVM The user mode VM handle.
|
---|
| 325 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 326 | * one of the following special values:
|
---|
| 327 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 328 | * @param pfnFunction Pointer to the function to call.
|
---|
| 329 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 330 | * @param ... Function arguments.
|
---|
| 331 | *
|
---|
| 332 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
| 333 | */
|
---|
| 334 | VMMR3DECL(int) VMR3ReqPriorityCallWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
| 335 | {
|
---|
| 336 | PVMREQ pReq;
|
---|
| 337 | va_list va;
|
---|
| 338 | va_start(va, cArgs);
|
---|
| 339 | int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_PRIORITY,
|
---|
| 340 | pfnFunction, cArgs, va);
|
---|
| 341 | va_end(va);
|
---|
| 342 | if (RT_SUCCESS(rc))
|
---|
| 343 | rc = pReq->iStatus;
|
---|
| 344 | VMR3ReqFree(pReq);
|
---|
| 345 | return rc;
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 | /**
|
---|
| 350 | * Convenience wrapper for VMR3ReqCallU.
|
---|
| 351 | *
|
---|
[39327] | 352 | * This assumes (1) you're calling a function that returns void, (2) that you
|
---|
| 353 | * wish to wait for ever for it to return, and (3) that it's priority request
|
---|
| 354 | * that can be safely be handled during async suspend and power off.
|
---|
[23010] | 355 | *
|
---|
| 356 | * @returns VBox status code of VMR3ReqCallVU.
|
---|
| 357 | *
|
---|
[44340] | 358 | * @param pUVM The user mode VM handle.
|
---|
[23010] | 359 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 360 | * one of the following special values:
|
---|
| 361 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
| 362 | * @param pfnFunction Pointer to the function to call.
|
---|
| 363 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 364 | * @param ... Function arguments.
|
---|
[24467] | 365 | *
|
---|
| 366 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[23010] | 367 | */
|
---|
[44340] | 368 | VMMR3DECL(int) VMR3ReqPriorityCallVoidWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
[23010] | 369 | {
|
---|
| 370 | PVMREQ pReq;
|
---|
| 371 | va_list va;
|
---|
| 372 | va_start(va, cArgs);
|
---|
[44340] | 373 | int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VOID | VMREQFLAGS_PRIORITY,
|
---|
[23010] | 374 | pfnFunction, cArgs, va);
|
---|
| 375 | va_end(va);
|
---|
| 376 | VMR3ReqFree(pReq);
|
---|
| 377 | return rc;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 |
|
---|
| 381 | /**
|
---|
[6796] | 382 | * Allocate and queue a call request to a void function.
|
---|
| 383 | *
|
---|
| 384 | * If it's desired to poll on the completion of the request set cMillies
|
---|
[33540] | 385 | * to 0 and use VMR3ReqWait() to check for completion. In the other case
|
---|
[6796] | 386 | * use RT_INDEFINITE_WAIT.
|
---|
| 387 | * The returned request packet must be freed using VMR3ReqFree().
|
---|
| 388 | *
|
---|
| 389 | * @returns VBox status code.
|
---|
| 390 | * Will not return VERR_INTERRUPTED.
|
---|
| 391 | * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
|
---|
| 392 | *
|
---|
| 393 | * @param pUVM Pointer to the user mode VM structure.
|
---|
[19300] | 394 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 395 | * one of the following special values:
|
---|
[20880] | 396 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
[6796] | 397 | * @param ppReq Where to store the pointer to the request.
|
---|
[33540] | 398 | * This will be NULL or a valid request pointer not matter what happens, unless fFlags
|
---|
[6796] | 399 | * contains VMREQFLAGS_NO_WAIT when it will be optional and always NULL.
|
---|
| 400 | * @param cMillies Number of milliseconds to wait for the request to
|
---|
| 401 | * be completed. Use RT_INDEFINITE_WAIT to only
|
---|
| 402 | * wait till it's completed.
|
---|
| 403 | * @param fFlags A combination of the VMREQFLAGS values.
|
---|
| 404 | * @param pfnFunction Pointer to the function to call.
|
---|
| 405 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 406 | * @param ... Function arguments.
|
---|
[24467] | 407 | *
|
---|
| 408 | * @remarks See remarks on VMR3ReqCallVU.
|
---|
[6796] | 409 | */
|
---|
[25728] | 410 | VMMR3DECL(int) VMR3ReqCallU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags,
|
---|
| 411 | PFNRT pfnFunction, unsigned cArgs, ...)
|
---|
[6796] | 412 | {
|
---|
| 413 | va_list va;
|
---|
| 414 | va_start(va, cArgs);
|
---|
[19300] | 415 | int rc = VMR3ReqCallVU(pUVM, idDstCpu, ppReq, cMillies, fFlags, pfnFunction, cArgs, va);
|
---|
[6796] | 416 | va_end(va);
|
---|
| 417 | return rc;
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 |
|
---|
| 421 | /**
|
---|
[1] | 422 | * Allocate and queue a call request.
|
---|
| 423 | *
|
---|
| 424 | * If it's desired to poll on the completion of the request set cMillies
|
---|
[33540] | 425 | * to 0 and use VMR3ReqWait() to check for completion. In the other case
|
---|
[1] | 426 | * use RT_INDEFINITE_WAIT.
|
---|
| 427 | * The returned request packet must be freed using VMR3ReqFree().
|
---|
| 428 | *
|
---|
| 429 | * @returns VBox status code.
|
---|
| 430 | * Will not return VERR_INTERRUPTED.
|
---|
| 431 | * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
|
---|
| 432 | *
|
---|
[6796] | 433 | * @param pUVM Pointer to the user mode VM structure.
|
---|
[19300] | 434 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 435 | * one of the following special values:
|
---|
[20880] | 436 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
[1] | 437 | * @param ppReq Where to store the pointer to the request.
|
---|
[33540] | 438 | * This will be NULL or a valid request pointer not matter what happens, unless fFlags
|
---|
[1] | 439 | * contains VMREQFLAGS_NO_WAIT when it will be optional and always NULL.
|
---|
| 440 | * @param cMillies Number of milliseconds to wait for the request to
|
---|
| 441 | * be completed. Use RT_INDEFINITE_WAIT to only
|
---|
| 442 | * wait till it's completed.
|
---|
| 443 | * @param pfnFunction Pointer to the function to call.
|
---|
| 444 | * @param fFlags A combination of the VMREQFLAGS values.
|
---|
| 445 | * @param cArgs Number of arguments following in the ellipsis.
|
---|
| 446 | * Stuff which differs in size from uintptr_t is gonna make trouble, so don't try!
|
---|
| 447 | * @param Args Argument vector.
|
---|
[24467] | 448 | *
|
---|
| 449 | * @remarks Caveats:
|
---|
| 450 | * - Do not pass anything which is larger than an uintptr_t.
|
---|
| 451 | * - 64-bit integers are larger than uintptr_t on 32-bit hosts.
|
---|
| 452 | * Pass integers > 32-bit by reference (pointers).
|
---|
| 453 | * - Don't use NULL since it should be the integer 0 in C++ and may
|
---|
| 454 | * therefore end up with garbage in the bits 63:32 on 64-bit
|
---|
| 455 | * hosts because 'int' is 32-bit.
|
---|
| 456 | * Use (void *)NULL or (uintptr_t)0 instead of NULL.
|
---|
[1] | 457 | */
|
---|
[25728] | 458 | VMMR3DECL(int) VMR3ReqCallVU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags,
|
---|
| 459 | PFNRT pfnFunction, unsigned cArgs, va_list Args)
|
---|
[1] | 460 | {
|
---|
[19395] | 461 | LogFlow(("VMR3ReqCallV: idDstCpu=%u cMillies=%d fFlags=%#x pfnFunction=%p cArgs=%d\n", idDstCpu, cMillies, fFlags, pfnFunction, cArgs));
|
---|
[1] | 462 |
|
---|
| 463 | /*
|
---|
[6796] | 464 | * Validate input.
|
---|
[1] | 465 | */
|
---|
[6796] | 466 | AssertPtrReturn(pfnFunction, VERR_INVALID_POINTER);
|
---|
[44346] | 467 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
[38838] | 468 | AssertReturn(!(fFlags & ~(VMREQFLAGS_RETURN_MASK | VMREQFLAGS_NO_WAIT | VMREQFLAGS_POKE | VMREQFLAGS_PRIORITY)), VERR_INVALID_PARAMETER);
|
---|
[1] | 469 | if (!(fFlags & VMREQFLAGS_NO_WAIT) || ppReq)
|
---|
| 470 | {
|
---|
[6796] | 471 | AssertPtrReturn(ppReq, VERR_INVALID_POINTER);
|
---|
[1] | 472 | *ppReq = NULL;
|
---|
| 473 | }
|
---|
| 474 | PVMREQ pReq = NULL;
|
---|
[6796] | 475 | AssertMsgReturn(cArgs * sizeof(uintptr_t) <= sizeof(pReq->u.Internal.aArgs),
|
---|
| 476 | ("cArg=%d\n", cArgs),
|
---|
| 477 | VERR_TOO_MUCH_DATA);
|
---|
[1] | 478 |
|
---|
| 479 | /*
|
---|
| 480 | * Allocate request
|
---|
| 481 | */
|
---|
[44340] | 482 | int rc = VMR3ReqAlloc(pUVM, &pReq, VMREQTYPE_INTERNAL, idDstCpu);
|
---|
[13816] | 483 | if (RT_FAILURE(rc))
|
---|
[1] | 484 | return rc;
|
---|
| 485 |
|
---|
| 486 | /*
|
---|
| 487 | * Initialize the request data.
|
---|
| 488 | */
|
---|
| 489 | pReq->fFlags = fFlags;
|
---|
| 490 | pReq->u.Internal.pfn = pfnFunction;
|
---|
| 491 | pReq->u.Internal.cArgs = cArgs;
|
---|
| 492 | for (unsigned iArg = 0; iArg < cArgs; iArg++)
|
---|
| 493 | pReq->u.Internal.aArgs[iArg] = va_arg(Args, uintptr_t);
|
---|
| 494 |
|
---|
| 495 | /*
|
---|
| 496 | * Queue the request and return.
|
---|
| 497 | */
|
---|
| 498 | rc = VMR3ReqQueue(pReq, cMillies);
|
---|
[13816] | 499 | if ( RT_FAILURE(rc)
|
---|
[1] | 500 | && rc != VERR_TIMEOUT)
|
---|
| 501 | {
|
---|
| 502 | VMR3ReqFree(pReq);
|
---|
| 503 | pReq = NULL;
|
---|
| 504 | }
|
---|
| 505 | if (!(fFlags & VMREQFLAGS_NO_WAIT))
|
---|
| 506 | {
|
---|
| 507 | *ppReq = pReq;
|
---|
[13818] | 508 | LogFlow(("VMR3ReqCallV: returns %Rrc *ppReq=%p\n", rc, pReq));
|
---|
[1] | 509 | }
|
---|
| 510 | else
|
---|
[13818] | 511 | LogFlow(("VMR3ReqCallV: returns %Rrc\n", rc));
|
---|
[1] | 512 | Assert(rc != VERR_INTERRUPTED);
|
---|
| 513 | return rc;
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 |
|
---|
| 517 | /**
|
---|
| 518 | * Joins the list pList with whatever is linked up at *pHead.
|
---|
| 519 | */
|
---|
| 520 | static void vmr3ReqJoinFreeSub(volatile PVMREQ *ppHead, PVMREQ pList)
|
---|
| 521 | {
|
---|
| 522 | for (unsigned cIterations = 0;; cIterations++)
|
---|
| 523 | {
|
---|
[30111] | 524 | PVMREQ pHead = ASMAtomicXchgPtrT(ppHead, pList, PVMREQ);
|
---|
[1] | 525 | if (!pHead)
|
---|
| 526 | return;
|
---|
| 527 | PVMREQ pTail = pHead;
|
---|
| 528 | while (pTail->pNext)
|
---|
| 529 | pTail = pTail->pNext;
|
---|
[30111] | 530 | ASMAtomicWritePtr(&pTail->pNext, pList);
|
---|
[20651] | 531 | ASMCompilerBarrier();
|
---|
[30111] | 532 | if (ASMAtomicCmpXchgPtr(ppHead, pHead, pList))
|
---|
[1] | 533 | return;
|
---|
[30112] | 534 | ASMAtomicWriteNullPtr(&pTail->pNext);
|
---|
[20651] | 535 | ASMCompilerBarrier();
|
---|
[30111] | 536 | if (ASMAtomicCmpXchgPtr(ppHead, pHead, NULL))
|
---|
[1] | 537 | return;
|
---|
| 538 | pList = pHead;
|
---|
| 539 | Assert(cIterations != 32);
|
---|
| 540 | Assert(cIterations != 64);
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 |
|
---|
| 545 | /**
|
---|
| 546 | * Joins the list pList with whatever is linked up at *pHead.
|
---|
| 547 | */
|
---|
[6796] | 548 | static void vmr3ReqJoinFree(PVMINTUSERPERVM pVMInt, PVMREQ pList)
|
---|
[1] | 549 | {
|
---|
| 550 | /*
|
---|
| 551 | * Split the list if it's too long.
|
---|
| 552 | */
|
---|
| 553 | unsigned cReqs = 1;
|
---|
| 554 | PVMREQ pTail = pList;
|
---|
| 555 | while (pTail->pNext)
|
---|
| 556 | {
|
---|
| 557 | if (cReqs++ > 25)
|
---|
| 558 | {
|
---|
| 559 | const uint32_t i = pVMInt->iReqFree;
|
---|
[6796] | 560 | vmr3ReqJoinFreeSub(&pVMInt->apReqFree[(i + 2) % RT_ELEMENTS(pVMInt->apReqFree)], pTail->pNext);
|
---|
[1] | 561 |
|
---|
| 562 | pTail->pNext = NULL;
|
---|
[6796] | 563 | vmr3ReqJoinFreeSub(&pVMInt->apReqFree[(i + 2 + (i == pVMInt->iReqFree)) % RT_ELEMENTS(pVMInt->apReqFree)], pTail->pNext);
|
---|
[1] | 564 | return;
|
---|
| 565 | }
|
---|
| 566 | pTail = pTail->pNext;
|
---|
| 567 | }
|
---|
[6796] | 568 | vmr3ReqJoinFreeSub(&pVMInt->apReqFree[(pVMInt->iReqFree + 2) % RT_ELEMENTS(pVMInt->apReqFree)], pList);
|
---|
[1] | 569 | }
|
---|
| 570 |
|
---|
| 571 |
|
---|
| 572 | /**
|
---|
| 573 | * Allocates a request packet.
|
---|
| 574 | *
|
---|
| 575 | * The caller allocates a request packet, fills in the request data
|
---|
| 576 | * union and queues the request.
|
---|
| 577 | *
|
---|
| 578 | * @returns VBox status code.
|
---|
| 579 | *
|
---|
[6796] | 580 | * @param pUVM Pointer to the user mode VM structure.
|
---|
| 581 | * @param ppReq Where to store the pointer to the allocated packet.
|
---|
| 582 | * @param enmType Package type.
|
---|
[19300] | 583 | * @param idDstCpu The destination CPU(s). Either a specific CPU ID or
|
---|
| 584 | * one of the following special values:
|
---|
[20880] | 585 | * VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
|
---|
[6796] | 586 | */
|
---|
[44340] | 587 | VMMR3DECL(int) VMR3ReqAlloc(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu)
|
---|
[6796] | 588 | {
|
---|
[1] | 589 | /*
|
---|
| 590 | * Validate input.
|
---|
| 591 | */
|
---|
[6796] | 592 | AssertMsgReturn(enmType > VMREQTYPE_INVALID && enmType < VMREQTYPE_MAX,
|
---|
[33595] | 593 | ("Invalid package type %d valid range %d-%d inclusively.\n",
|
---|
[6796] | 594 | enmType, VMREQTYPE_INVALID + 1, VMREQTYPE_MAX - 1),
|
---|
| 595 | VERR_VM_REQUEST_INVALID_TYPE);
|
---|
| 596 | AssertPtrReturn(ppReq, VERR_INVALID_POINTER);
|
---|
[19300] | 597 | AssertMsgReturn( idDstCpu == VMCPUID_ANY
|
---|
[20880] | 598 | || idDstCpu == VMCPUID_ANY_QUEUE
|
---|
[19300] | 599 | || idDstCpu < pUVM->cCpus
|
---|
| 600 | || idDstCpu == VMCPUID_ALL
|
---|
| 601 | || idDstCpu == VMCPUID_ALL_REVERSE,
|
---|
| 602 | ("Invalid destination %u (max=%u)\n", idDstCpu, pUVM->cCpus), VERR_INVALID_PARAMETER);
|
---|
[1] | 603 |
|
---|
| 604 | /*
|
---|
| 605 | * Try get a recycled packet.
|
---|
| 606 | * While this could all be solved with a single list with a lock, it's a sport
|
---|
| 607 | * of mine to avoid locks.
|
---|
| 608 | */
|
---|
[6796] | 609 | int cTries = RT_ELEMENTS(pUVM->vm.s.apReqFree) * 2;
|
---|
[1] | 610 | while (--cTries >= 0)
|
---|
| 611 | {
|
---|
[6796] | 612 | PVMREQ volatile *ppHead = &pUVM->vm.s.apReqFree[ASMAtomicIncU32(&pUVM->vm.s.iReqFree) % RT_ELEMENTS(pUVM->vm.s.apReqFree)];
|
---|
[1] | 613 | #if 0 /* sad, but this won't work safely because the reading of pReq->pNext. */
|
---|
| 614 | PVMREQ pNext = NULL;
|
---|
| 615 | PVMREQ pReq = *ppHead;
|
---|
| 616 | if ( pReq
|
---|
[30111] | 617 | && !ASMAtomicCmpXchgPtr(ppHead, (pNext = pReq->pNext), pReq)
|
---|
[1] | 618 | && (pReq = *ppHead)
|
---|
[30111] | 619 | && !ASMAtomicCmpXchgPtr(ppHead, (pNext = pReq->pNext), pReq))
|
---|
[1] | 620 | pReq = NULL;
|
---|
| 621 | if (pReq)
|
---|
| 622 | {
|
---|
| 623 | Assert(pReq->pNext == pNext); NOREF(pReq);
|
---|
| 624 | #else
|
---|
[30111] | 625 | PVMREQ pReq = ASMAtomicXchgPtrT(ppHead, NULL, PVMREQ);
|
---|
[1] | 626 | if (pReq)
|
---|
| 627 | {
|
---|
| 628 | PVMREQ pNext = pReq->pNext;
|
---|
| 629 | if ( pNext
|
---|
[30111] | 630 | && !ASMAtomicCmpXchgPtr(ppHead, pNext, NULL))
|
---|
[1] | 631 | {
|
---|
[6796] | 632 | STAM_COUNTER_INC(&pUVM->vm.s.StatReqAllocRaces);
|
---|
| 633 | vmr3ReqJoinFree(&pUVM->vm.s, pReq->pNext);
|
---|
[1] | 634 | }
|
---|
| 635 | #endif
|
---|
[6796] | 636 | ASMAtomicDecU32(&pUVM->vm.s.cReqFree);
|
---|
[1] | 637 |
|
---|
| 638 | /*
|
---|
| 639 | * Make sure the event sem is not signaled.
|
---|
| 640 | */
|
---|
| 641 | if (!pReq->fEventSemClear)
|
---|
| 642 | {
|
---|
| 643 | int rc = RTSemEventWait(pReq->EventSem, 0);
|
---|
| 644 | if (rc != VINF_SUCCESS && rc != VERR_TIMEOUT)
|
---|
| 645 | {
|
---|
| 646 | /*
|
---|
| 647 | * This shall not happen, but if it does we'll just destroy
|
---|
| 648 | * the semaphore and create a new one.
|
---|
| 649 | */
|
---|
[13818] | 650 | AssertMsgFailed(("rc=%Rrc from RTSemEventWait(%#x).\n", rc, pReq->EventSem));
|
---|
[1] | 651 | RTSemEventDestroy(pReq->EventSem);
|
---|
| 652 | rc = RTSemEventCreate(&pReq->EventSem);
|
---|
| 653 | AssertRC(rc);
|
---|
[13816] | 654 | if (RT_FAILURE(rc))
|
---|
[1] | 655 | return rc;
|
---|
[63560] | 656 | #if 0 /// @todo @bugref{4725} - def RT_LOCK_STRICT
|
---|
[25730] | 657 | for (VMCPUID idCpu = 0; idCpu < pUVM->cCpus; idCpu++)
|
---|
| 658 | RTSemEventAddSignaller(pReq->EventSem, pUVM->aCpus[idCpu].vm.s.ThreadEMT);
|
---|
| 659 | #endif
|
---|
[1] | 660 | }
|
---|
| 661 | pReq->fEventSemClear = true;
|
---|
| 662 | }
|
---|
| 663 | else
|
---|
| 664 | Assert(RTSemEventWait(pReq->EventSem, 0) == VERR_TIMEOUT);
|
---|
| 665 |
|
---|
| 666 | /*
|
---|
| 667 | * Initialize the packet and return it.
|
---|
| 668 | */
|
---|
| 669 | Assert(pReq->enmType == VMREQTYPE_INVALID);
|
---|
| 670 | Assert(pReq->enmState == VMREQSTATE_FREE);
|
---|
[6796] | 671 | Assert(pReq->pUVM == pUVM);
|
---|
[1] | 672 | ASMAtomicXchgSize(&pReq->pNext, NULL);
|
---|
| 673 | pReq->enmState = VMREQSTATE_ALLOCATED;
|
---|
| 674 | pReq->iStatus = VERR_VM_REQUEST_STATUS_STILL_PENDING;
|
---|
| 675 | pReq->fFlags = VMREQFLAGS_VBOX_STATUS;
|
---|
| 676 | pReq->enmType = enmType;
|
---|
[19300] | 677 | pReq->idDstCpu = idDstCpu;
|
---|
[1] | 678 |
|
---|
| 679 | *ppReq = pReq;
|
---|
[6796] | 680 | STAM_COUNTER_INC(&pUVM->vm.s.StatReqAllocRecycled);
|
---|
[1] | 681 | LogFlow(("VMR3ReqAlloc: returns VINF_SUCCESS *ppReq=%p recycled\n", pReq));
|
---|
| 682 | return VINF_SUCCESS;
|
---|
| 683 | }
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | /*
|
---|
| 687 | * Ok allocate one.
|
---|
| 688 | */
|
---|
[6796] | 689 | PVMREQ pReq = (PVMREQ)MMR3HeapAllocU(pUVM, MM_TAG_VM_REQ, sizeof(*pReq));
|
---|
[1] | 690 | if (!pReq)
|
---|
| 691 | return VERR_NO_MEMORY;
|
---|
| 692 |
|
---|
| 693 | /*
|
---|
| 694 | * Create the semaphore.
|
---|
| 695 | */
|
---|
| 696 | int rc = RTSemEventCreate(&pReq->EventSem);
|
---|
| 697 | AssertRC(rc);
|
---|
[13816] | 698 | if (RT_FAILURE(rc))
|
---|
[1] | 699 | {
|
---|
| 700 | MMR3HeapFree(pReq);
|
---|
| 701 | return rc;
|
---|
| 702 | }
|
---|
[63560] | 703 | #if 0 /// @todo @bugref{4725} - def RT_LOCK_STRICT
|
---|
[25730] | 704 | for (VMCPUID idCpu = 0; idCpu < pUVM->cCpus; idCpu++)
|
---|
| 705 | RTSemEventAddSignaller(pReq->EventSem, pUVM->aCpus[idCpu].vm.s.ThreadEMT);
|
---|
| 706 | #endif
|
---|
[1] | 707 |
|
---|
| 708 | /*
|
---|
| 709 | * Initialize the packet and return it.
|
---|
| 710 | */
|
---|
| 711 | pReq->pNext = NULL;
|
---|
[6796] | 712 | pReq->pUVM = pUVM;
|
---|
[1] | 713 | pReq->enmState = VMREQSTATE_ALLOCATED;
|
---|
| 714 | pReq->iStatus = VERR_VM_REQUEST_STATUS_STILL_PENDING;
|
---|
| 715 | pReq->fEventSemClear = true;
|
---|
| 716 | pReq->fFlags = VMREQFLAGS_VBOX_STATUS;
|
---|
| 717 | pReq->enmType = enmType;
|
---|
[19300] | 718 | pReq->idDstCpu = idDstCpu;
|
---|
[1] | 719 |
|
---|
| 720 | *ppReq = pReq;
|
---|
[6796] | 721 | STAM_COUNTER_INC(&pUVM->vm.s.StatReqAllocNew);
|
---|
[1] | 722 | LogFlow(("VMR3ReqAlloc: returns VINF_SUCCESS *ppReq=%p new\n", pReq));
|
---|
| 723 | return VINF_SUCCESS;
|
---|
| 724 | }
|
---|
| 725 |
|
---|
| 726 |
|
---|
| 727 | /**
|
---|
| 728 | * Free a request packet.
|
---|
| 729 | *
|
---|
| 730 | * @returns VBox status code.
|
---|
| 731 | *
|
---|
| 732 | * @param pReq Package to free.
|
---|
| 733 | * @remark The request packet must be in allocated or completed state!
|
---|
| 734 | */
|
---|
[12989] | 735 | VMMR3DECL(int) VMR3ReqFree(PVMREQ pReq)
|
---|
[1] | 736 | {
|
---|
| 737 | /*
|
---|
| 738 | * Ignore NULL (all free functions should do this imho).
|
---|
| 739 | */
|
---|
| 740 | if (!pReq)
|
---|
| 741 | return VINF_SUCCESS;
|
---|
| 742 |
|
---|
| 743 | /*
|
---|
| 744 | * Check packet state.
|
---|
| 745 | */
|
---|
| 746 | switch (pReq->enmState)
|
---|
| 747 | {
|
---|
| 748 | case VMREQSTATE_ALLOCATED:
|
---|
| 749 | case VMREQSTATE_COMPLETED:
|
---|
| 750 | break;
|
---|
| 751 | default:
|
---|
| 752 | AssertMsgFailed(("Invalid state %d!\n", pReq->enmState));
|
---|
| 753 | return VERR_VM_REQUEST_STATE;
|
---|
| 754 | }
|
---|
| 755 |
|
---|
| 756 | /*
|
---|
| 757 | * Make it a free packet and put it into one of the free packet lists.
|
---|
| 758 | */
|
---|
| 759 | pReq->enmState = VMREQSTATE_FREE;
|
---|
| 760 | pReq->iStatus = VERR_VM_REQUEST_STATUS_FREED;
|
---|
| 761 | pReq->enmType = VMREQTYPE_INVALID;
|
---|
| 762 |
|
---|
[6796] | 763 | PUVM pUVM = pReq->pUVM;
|
---|
| 764 | STAM_COUNTER_INC(&pUVM->vm.s.StatReqFree);
|
---|
| 765 |
|
---|
| 766 | if (pUVM->vm.s.cReqFree < 128)
|
---|
[1] | 767 | {
|
---|
[6796] | 768 | ASMAtomicIncU32(&pUVM->vm.s.cReqFree);
|
---|
| 769 | PVMREQ volatile *ppHead = &pUVM->vm.s.apReqFree[ASMAtomicIncU32(&pUVM->vm.s.iReqFree) % RT_ELEMENTS(pUVM->vm.s.apReqFree)];
|
---|
[1] | 770 | PVMREQ pNext;
|
---|
| 771 | do
|
---|
| 772 | {
|
---|
[30111] | 773 | pNext = ASMAtomicUoReadPtrT(ppHead, PVMREQ);
|
---|
| 774 | ASMAtomicWritePtr(&pReq->pNext, pNext);
|
---|
[20651] | 775 | ASMCompilerBarrier();
|
---|
[30111] | 776 | } while (!ASMAtomicCmpXchgPtr(ppHead, pReq, pNext));
|
---|
[1] | 777 | }
|
---|
| 778 | else
|
---|
| 779 | {
|
---|
[6796] | 780 | STAM_COUNTER_INC(&pReq->pUVM->vm.s.StatReqFreeOverflow);
|
---|
[1] | 781 | RTSemEventDestroy(pReq->EventSem);
|
---|
| 782 | MMR3HeapFree(pReq);
|
---|
| 783 | }
|
---|
| 784 | return VINF_SUCCESS;
|
---|
| 785 | }
|
---|
| 786 |
|
---|
| 787 |
|
---|
| 788 | /**
|
---|
| 789 | * Queue a request.
|
---|
| 790 | *
|
---|
| 791 | * The quest must be allocated using VMR3ReqAlloc() and contain
|
---|
| 792 | * all the required data.
|
---|
| 793 | * If it's desired to poll on the completion of the request set cMillies
|
---|
[33540] | 794 | * to 0 and use VMR3ReqWait() to check for completion. In the other case
|
---|
[1] | 795 | * use RT_INDEFINITE_WAIT.
|
---|
| 796 | *
|
---|
| 797 | * @returns VBox status code.
|
---|
| 798 | * Will not return VERR_INTERRUPTED.
|
---|
| 799 | * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
|
---|
| 800 | *
|
---|
| 801 | * @param pReq The request to queue.
|
---|
| 802 | * @param cMillies Number of milliseconds to wait for the request to
|
---|
| 803 | * be completed. Use RT_INDEFINITE_WAIT to only
|
---|
| 804 | * wait till it's completed.
|
---|
| 805 | */
|
---|
[25728] | 806 | VMMR3DECL(int) VMR3ReqQueue(PVMREQ pReq, RTMSINTERVAL cMillies)
|
---|
[1] | 807 | {
|
---|
| 808 | LogFlow(("VMR3ReqQueue: pReq=%p cMillies=%d\n", pReq, cMillies));
|
---|
| 809 | /*
|
---|
| 810 | * Verify the supplied package.
|
---|
| 811 | */
|
---|
[6796] | 812 | AssertMsgReturn(pReq->enmState == VMREQSTATE_ALLOCATED, ("%d\n", pReq->enmState), VERR_VM_REQUEST_STATE);
|
---|
| 813 | AssertMsgReturn( VALID_PTR(pReq->pUVM)
|
---|
| 814 | && !pReq->pNext
|
---|
| 815 | && pReq->EventSem != NIL_RTSEMEVENT,
|
---|
| 816 | ("Invalid request package! Anyone cooking their own packages???\n"),
|
---|
| 817 | VERR_VM_REQUEST_INVALID_PACKAGE);
|
---|
| 818 | AssertMsgReturn( pReq->enmType > VMREQTYPE_INVALID
|
---|
| 819 | && pReq->enmType < VMREQTYPE_MAX,
|
---|
[33595] | 820 | ("Invalid package type %d valid range %d-%d inclusively. This was verified on alloc too...\n",
|
---|
[6796] | 821 | pReq->enmType, VMREQTYPE_INVALID + 1, VMREQTYPE_MAX - 1),
|
---|
| 822 | VERR_VM_REQUEST_INVALID_TYPE);
|
---|
[38838] | 823 | Assert(!(pReq->fFlags & ~(VMREQFLAGS_RETURN_MASK | VMREQFLAGS_NO_WAIT | VMREQFLAGS_POKE | VMREQFLAGS_PRIORITY)));
|
---|
[1] | 824 |
|
---|
[6274] | 825 | /*
|
---|
| 826 | * Are we the EMT or not?
|
---|
| 827 | * Also, store pVM (and fFlags) locally since pReq may be invalid after queuing it.
|
---|
| 828 | */
|
---|
[13782] | 829 | int rc = VINF_SUCCESS;
|
---|
| 830 | PUVM pUVM = ((VMREQ volatile *)pReq)->pUVM; /* volatile paranoia */
|
---|
[19179] | 831 | PUVMCPU pUVCpu = (PUVMCPU)RTTlsGet(pUVM->vm.s.idxTLS);
|
---|
[13782] | 832 |
|
---|
[19300] | 833 | if (pReq->idDstCpu == VMCPUID_ALL)
|
---|
[1] | 834 | {
|
---|
[19299] | 835 | /* One-by-one. */
|
---|
| 836 | Assert(!(pReq->fFlags & VMREQFLAGS_NO_WAIT));
|
---|
[19267] | 837 | for (unsigned i = 0; i < pUVM->cCpus; i++)
|
---|
[13782] | 838 | {
|
---|
[19267] | 839 | /* Reinit some members. */
|
---|
| 840 | pReq->enmState = VMREQSTATE_ALLOCATED;
|
---|
[19300] | 841 | pReq->idDstCpu = i;
|
---|
[19267] | 842 | rc = VMR3ReqQueue(pReq, cMillies);
|
---|
| 843 | if (RT_FAILURE(rc))
|
---|
| 844 | break;
|
---|
| 845 | }
|
---|
[13782] | 846 | }
|
---|
[19300] | 847 | else if (pReq->idDstCpu == VMCPUID_ALL_REVERSE)
|
---|
[19267] | 848 | {
|
---|
[19299] | 849 | /* One-by-one. */
|
---|
| 850 | Assert(!(pReq->fFlags & VMREQFLAGS_NO_WAIT));
|
---|
[19267] | 851 | for (int i = pUVM->cCpus-1; i >= 0; i--)
|
---|
| 852 | {
|
---|
| 853 | /* Reinit some members. */
|
---|
| 854 | pReq->enmState = VMREQSTATE_ALLOCATED;
|
---|
[19300] | 855 | pReq->idDstCpu = i;
|
---|
[19267] | 856 | rc = VMR3ReqQueue(pReq, cMillies);
|
---|
| 857 | if (RT_FAILURE(rc))
|
---|
| 858 | break;
|
---|
| 859 | }
|
---|
| 860 | }
|
---|
[20806] | 861 | else if ( pReq->idDstCpu != VMCPUID_ANY /* for a specific VMCPU? */
|
---|
[23010] | 862 | && pReq->idDstCpu != VMCPUID_ANY_QUEUE
|
---|
[20806] | 863 | && ( !pUVCpu /* and it's not the current thread. */
|
---|
[19300] | 864 | || pUVCpu->idCpu != pReq->idDstCpu))
|
---|
[13782] | 865 | {
|
---|
[19300] | 866 | VMCPUID idTarget = pReq->idDstCpu; Assert(idTarget < pUVM->cCpus);
|
---|
[19141] | 867 | PVMCPU pVCpu = &pUVM->pVM->aCpus[idTarget];
|
---|
[13782] | 868 | unsigned fFlags = ((VMREQ volatile *)pReq)->fFlags; /* volatile paranoia */
|
---|
| 869 |
|
---|
[19217] | 870 | /* Fetch the right UVMCPU */
|
---|
| 871 | pUVCpu = &pUVM->aCpus[idTarget];
|
---|
| 872 |
|
---|
[1] | 873 | /*
|
---|
| 874 | * Insert it.
|
---|
| 875 | */
|
---|
[38838] | 876 | volatile PVMREQ *ppQueueHead = pReq->fFlags & VMREQFLAGS_PRIORITY ? &pUVCpu->vm.s.pPriorityReqs : &pUVCpu->vm.s.pNormalReqs;
|
---|
[1] | 877 | pReq->enmState = VMREQSTATE_QUEUED;
|
---|
| 878 | PVMREQ pNext;
|
---|
| 879 | do
|
---|
| 880 | {
|
---|
[38838] | 881 | pNext = ASMAtomicUoReadPtrT(ppQueueHead, PVMREQ);
|
---|
[30111] | 882 | ASMAtomicWritePtr(&pReq->pNext, pNext);
|
---|
[20651] | 883 | ASMCompilerBarrier();
|
---|
[38838] | 884 | } while (!ASMAtomicCmpXchgPtr(ppQueueHead, pReq, pNext));
|
---|
[1] | 885 |
|
---|
| 886 | /*
|
---|
| 887 | * Notify EMT.
|
---|
| 888 | */
|
---|
[6796] | 889 | if (pUVM->pVM)
|
---|
[19146] | 890 | VMCPU_FF_SET(pVCpu, VMCPU_FF_REQUEST);
|
---|
[19402] | 891 | VMR3NotifyCpuFFU(pUVCpu, fFlags & VMREQFLAGS_POKE ? VMNOTIFYFF_FLAGS_POKE : 0);
|
---|
[1] | 892 |
|
---|
| 893 | /*
|
---|
| 894 | * Wait and return.
|
---|
| 895 | */
|
---|
[6274] | 896 | if (!(fFlags & VMREQFLAGS_NO_WAIT))
|
---|
[1] | 897 | rc = VMR3ReqWait(pReq, cMillies);
|
---|
[13818] | 898 | LogFlow(("VMR3ReqQueue: returns %Rrc\n", rc));
|
---|
[1] | 899 | }
|
---|
[20805] | 900 | else if ( ( pReq->idDstCpu == VMCPUID_ANY
|
---|
| 901 | && !pUVCpu /* only EMT threads have a valid pointer stored in the TLS slot. */)
|
---|
[20880] | 902 | || pReq->idDstCpu == VMCPUID_ANY_QUEUE)
|
---|
[1] | 903 | {
|
---|
[13765] | 904 | unsigned fFlags = ((VMREQ volatile *)pReq)->fFlags; /* volatile paranoia */
|
---|
| 905 |
|
---|
[31631] | 906 | /* Note: pUVCpu may or may not be NULL in the VMCPUID_ANY_QUEUE case; we don't care. */
|
---|
[20805] | 907 |
|
---|
[1] | 908 | /*
|
---|
[13765] | 909 | * Insert it.
|
---|
| 910 | */
|
---|
[38838] | 911 | volatile PVMREQ *ppQueueHead = pReq->fFlags & VMREQFLAGS_PRIORITY ? &pUVM->vm.s.pPriorityReqs : &pUVM->vm.s.pNormalReqs;
|
---|
[13765] | 912 | pReq->enmState = VMREQSTATE_QUEUED;
|
---|
| 913 | PVMREQ pNext;
|
---|
| 914 | do
|
---|
| 915 | {
|
---|
[38838] | 916 | pNext = ASMAtomicUoReadPtrT(ppQueueHead, PVMREQ);
|
---|
[30111] | 917 | ASMAtomicWritePtr(&pReq->pNext, pNext);
|
---|
[20651] | 918 | ASMCompilerBarrier();
|
---|
[38838] | 919 | } while (!ASMAtomicCmpXchgPtr(ppQueueHead, pReq, pNext));
|
---|
[13765] | 920 |
|
---|
| 921 | /*
|
---|
| 922 | * Notify EMT.
|
---|
| 923 | */
|
---|
| 924 | if (pUVM->pVM)
|
---|
[13782] | 925 | VM_FF_SET(pUVM->pVM, VM_FF_REQUEST);
|
---|
[19402] | 926 | VMR3NotifyGlobalFFU(pUVM, fFlags & VMREQFLAGS_POKE ? VMNOTIFYFF_FLAGS_POKE : 0);
|
---|
[13765] | 927 |
|
---|
| 928 | /*
|
---|
| 929 | * Wait and return.
|
---|
| 930 | */
|
---|
| 931 | if (!(fFlags & VMREQFLAGS_NO_WAIT))
|
---|
| 932 | rc = VMR3ReqWait(pReq, cMillies);
|
---|
[13818] | 933 | LogFlow(("VMR3ReqQueue: returns %Rrc\n", rc));
|
---|
[13765] | 934 | }
|
---|
| 935 | else
|
---|
| 936 | {
|
---|
[19179] | 937 | Assert(pUVCpu);
|
---|
[13782] | 938 |
|
---|
[13765] | 939 | /*
|
---|
[19299] | 940 | * The requester was an EMT, just execute it.
|
---|
[1] | 941 | */
|
---|
| 942 | pReq->enmState = VMREQSTATE_QUEUED;
|
---|
[62647] | 943 | rc = vmR3ReqProcessOne(pReq);
|
---|
[13818] | 944 | LogFlow(("VMR3ReqQueue: returns %Rrc (processed)\n", rc));
|
---|
[1] | 945 | }
|
---|
| 946 | return rc;
|
---|
| 947 | }
|
---|
| 948 |
|
---|
| 949 |
|
---|
| 950 | /**
|
---|
| 951 | * Wait for a request to be completed.
|
---|
| 952 | *
|
---|
| 953 | * @returns VBox status code.
|
---|
| 954 | * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
|
---|
| 955 | *
|
---|
| 956 | * @param pReq The request to wait for.
|
---|
| 957 | * @param cMillies Number of milliseconds to wait.
|
---|
| 958 | * Use RT_INDEFINITE_WAIT to only wait till it's completed.
|
---|
| 959 | */
|
---|
[25728] | 960 | VMMR3DECL(int) VMR3ReqWait(PVMREQ pReq, RTMSINTERVAL cMillies)
|
---|
[1] | 961 | {
|
---|
| 962 | LogFlow(("VMR3ReqWait: pReq=%p cMillies=%d\n", pReq, cMillies));
|
---|
| 963 |
|
---|
| 964 | /*
|
---|
| 965 | * Verify the supplied package.
|
---|
| 966 | */
|
---|
[6796] | 967 | AssertMsgReturn( pReq->enmState == VMREQSTATE_QUEUED
|
---|
| 968 | || pReq->enmState == VMREQSTATE_PROCESSING
|
---|
| 969 | || pReq->enmState == VMREQSTATE_COMPLETED,
|
---|
| 970 | ("Invalid state %d\n", pReq->enmState),
|
---|
| 971 | VERR_VM_REQUEST_STATE);
|
---|
| 972 | AssertMsgReturn( VALID_PTR(pReq->pUVM)
|
---|
| 973 | && pReq->EventSem != NIL_RTSEMEVENT,
|
---|
| 974 | ("Invalid request package! Anyone cooking their own packages???\n"),
|
---|
| 975 | VERR_VM_REQUEST_INVALID_PACKAGE);
|
---|
| 976 | AssertMsgReturn( pReq->enmType > VMREQTYPE_INVALID
|
---|
| 977 | && pReq->enmType < VMREQTYPE_MAX,
|
---|
[33595] | 978 | ("Invalid package type %d valid range %d-%d inclusively. This was verified on alloc too...\n",
|
---|
[6796] | 979 | pReq->enmType, VMREQTYPE_INVALID + 1, VMREQTYPE_MAX - 1),
|
---|
| 980 | VERR_VM_REQUEST_INVALID_TYPE);
|
---|
[1] | 981 |
|
---|
| 982 | /*
|
---|
| 983 | * Check for deadlock condition
|
---|
| 984 | */
|
---|
[6796] | 985 | PUVM pUVM = pReq->pUVM;
|
---|
[7559] | 986 | NOREF(pUVM);
|
---|
[1] | 987 |
|
---|
| 988 | /*
|
---|
| 989 | * Wait on the package.
|
---|
| 990 | */
|
---|
| 991 | int rc;
|
---|
| 992 | if (cMillies != RT_INDEFINITE_WAIT)
|
---|
| 993 | rc = RTSemEventWait(pReq->EventSem, cMillies);
|
---|
| 994 | else
|
---|
| 995 | {
|
---|
| 996 | do
|
---|
| 997 | {
|
---|
| 998 | rc = RTSemEventWait(pReq->EventSem, RT_INDEFINITE_WAIT);
|
---|
| 999 | Assert(rc != VERR_TIMEOUT);
|
---|
[4943] | 1000 | } while ( pReq->enmState != VMREQSTATE_COMPLETED
|
---|
| 1001 | && pReq->enmState != VMREQSTATE_INVALID);
|
---|
[1] | 1002 | }
|
---|
[13816] | 1003 | if (RT_SUCCESS(rc))
|
---|
[1] | 1004 | ASMAtomicXchgSize(&pReq->fEventSemClear, true);
|
---|
| 1005 | if (pReq->enmState == VMREQSTATE_COMPLETED)
|
---|
| 1006 | rc = VINF_SUCCESS;
|
---|
[13818] | 1007 | LogFlow(("VMR3ReqWait: returns %Rrc\n", rc));
|
---|
[1] | 1008 | Assert(rc != VERR_INTERRUPTED);
|
---|
| 1009 | return rc;
|
---|
| 1010 | }
|
---|
| 1011 |
|
---|
| 1012 |
|
---|
| 1013 | /**
|
---|
[39327] | 1014 | * Sets the relevant FF.
|
---|
| 1015 | *
|
---|
[38838] | 1016 | * @param pUVM Pointer to the user mode VM structure.
|
---|
| 1017 | * @param idDstCpu VMCPUID_ANY or the ID of the current CPU.
|
---|
| 1018 | */
|
---|
| 1019 | DECLINLINE(void) vmR3ReqSetFF(PUVM pUVM, VMCPUID idDstCpu)
|
---|
| 1020 | {
|
---|
| 1021 | if (RT_LIKELY(pUVM->pVM))
|
---|
| 1022 | {
|
---|
| 1023 | if (idDstCpu == VMCPUID_ANY)
|
---|
| 1024 | VM_FF_SET(pUVM->pVM, VM_FF_REQUEST);
|
---|
| 1025 | else
|
---|
| 1026 | VMCPU_FF_SET(&pUVM->pVM->aCpus[idDstCpu], VMCPU_FF_REQUEST);
|
---|
| 1027 | }
|
---|
| 1028 | }
|
---|
| 1029 |
|
---|
| 1030 |
|
---|
| 1031 | /**
|
---|
[24738] | 1032 | * VMR3ReqProcessU helper that handles cases where there are more than one
|
---|
| 1033 | * pending request.
|
---|
| 1034 | *
|
---|
| 1035 | * @returns The oldest request.
|
---|
| 1036 | * @param pUVM Pointer to the user mode VM structure
|
---|
| 1037 | * @param idDstCpu VMCPUID_ANY or virtual CPU ID.
|
---|
| 1038 | * @param pReqList The list of requests.
|
---|
[30111] | 1039 | * @param ppReqs Pointer to the list head.
|
---|
[24738] | 1040 | */
|
---|
[30111] | 1041 | static PVMREQ vmR3ReqProcessUTooManyHelper(PUVM pUVM, VMCPUID idDstCpu, PVMREQ pReqList, PVMREQ volatile *ppReqs)
|
---|
[24738] | 1042 | {
|
---|
| 1043 | STAM_COUNTER_INC(&pUVM->vm.s.StatReqMoreThan1);
|
---|
[38838] | 1044 |
|
---|
[39327] | 1045 | /*
|
---|
[38838] | 1046 | * Chop off the last one (pReq).
|
---|
| 1047 | */
|
---|
[24738] | 1048 | PVMREQ pPrev;
|
---|
| 1049 | PVMREQ pReqRet = pReqList;
|
---|
| 1050 | do
|
---|
| 1051 | {
|
---|
| 1052 | pPrev = pReqRet;
|
---|
| 1053 | pReqRet = pReqRet->pNext;
|
---|
| 1054 | } while (pReqRet->pNext);
|
---|
[30112] | 1055 | ASMAtomicWriteNullPtr(&pPrev->pNext);
|
---|
[24738] | 1056 |
|
---|
[39327] | 1057 | /*
|
---|
[38838] | 1058 | * Push the others back onto the list (end of it).
|
---|
| 1059 | */
|
---|
[24738] | 1060 | Log2(("VMR3ReqProcess: Pushing back %p %p...\n", pReqList, pReqList->pNext));
|
---|
[30111] | 1061 | if (RT_UNLIKELY(!ASMAtomicCmpXchgPtr(ppReqs, pReqList, NULL)))
|
---|
[24738] | 1062 | {
|
---|
| 1063 | STAM_COUNTER_INC(&pUVM->vm.s.StatReqPushBackRaces);
|
---|
| 1064 | do
|
---|
| 1065 | {
|
---|
| 1066 | ASMNopPause();
|
---|
[30111] | 1067 | PVMREQ pReqList2 = ASMAtomicXchgPtrT(ppReqs, NULL, PVMREQ);
|
---|
[24738] | 1068 | if (pReqList2)
|
---|
| 1069 | {
|
---|
| 1070 | PVMREQ pLast = pReqList2;
|
---|
| 1071 | while (pLast->pNext)
|
---|
| 1072 | pLast = pLast->pNext;
|
---|
[30111] | 1073 | ASMAtomicWritePtr(&pLast->pNext, pReqList);
|
---|
[24738] | 1074 | pReqList = pReqList2;
|
---|
| 1075 | }
|
---|
[30111] | 1076 | } while (!ASMAtomicCmpXchgPtr(ppReqs, pReqList, NULL));
|
---|
[24738] | 1077 | }
|
---|
| 1078 |
|
---|
[38838] | 1079 | vmR3ReqSetFF(pUVM, idDstCpu);
|
---|
[24738] | 1080 | return pReqRet;
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
| 1083 |
|
---|
| 1084 | /**
|
---|
[1] | 1085 | * Process pending request(s).
|
---|
| 1086 | *
|
---|
[6796] | 1087 | * This function is called from a forced action handler in the EMT
|
---|
| 1088 | * or from one of the EMT loops.
|
---|
[1] | 1089 | *
|
---|
| 1090 | * @returns VBox status code.
|
---|
| 1091 | *
|
---|
[6796] | 1092 | * @param pUVM Pointer to the user mode VM structure.
|
---|
[19300] | 1093 | * @param idDstCpu Pass VMCPUID_ANY to process the common request queue
|
---|
| 1094 | * and the CPU ID for a CPU specific one. In the latter
|
---|
| 1095 | * case the calling thread must be the EMT of that CPU.
|
---|
[39327] | 1096 | * @param fPriorityOnly When set, only process the priority request queue.
|
---|
[19451] | 1097 | *
|
---|
| 1098 | * @note SMP safe (multiple EMTs trying to satisfy VM_FF_REQUESTs).
|
---|
[24738] | 1099 | *
|
---|
[39327] | 1100 | * @remarks This was made reentrant for async PDM handling, the debugger and
|
---|
[38838] | 1101 | * others.
|
---|
[44340] | 1102 | * @internal
|
---|
[1] | 1103 | */
|
---|
[44340] | 1104 | VMMR3_INT_DECL(int) VMR3ReqProcessU(PUVM pUVM, VMCPUID idDstCpu, bool fPriorityOnly)
|
---|
[1] | 1105 | {
|
---|
[19300] | 1106 | LogFlow(("VMR3ReqProcessU: (enmVMState=%d) idDstCpu=%d\n", pUVM->pVM ? pUVM->pVM->enmVMState : VMSTATE_CREATING, idDstCpu));
|
---|
[1] | 1107 |
|
---|
| 1108 | /*
|
---|
[38838] | 1109 | * Determine which queues to process.
|
---|
| 1110 | */
|
---|
| 1111 | PVMREQ volatile *ppNormalReqs;
|
---|
| 1112 | PVMREQ volatile *ppPriorityReqs;
|
---|
| 1113 | if (idDstCpu == VMCPUID_ANY)
|
---|
| 1114 | {
|
---|
| 1115 | ppPriorityReqs = &pUVM->vm.s.pPriorityReqs;
|
---|
| 1116 | ppNormalReqs = !fPriorityOnly ? &pUVM->vm.s.pNormalReqs : ppPriorityReqs;
|
---|
| 1117 | }
|
---|
| 1118 | else
|
---|
| 1119 | {
|
---|
| 1120 | Assert(idDstCpu < pUVM->cCpus);
|
---|
| 1121 | Assert(pUVM->aCpus[idDstCpu].vm.s.NativeThreadEMT == RTThreadNativeSelf());
|
---|
| 1122 | ppPriorityReqs = &pUVM->aCpus[idDstCpu].vm.s.pPriorityReqs;
|
---|
| 1123 | ppNormalReqs = !fPriorityOnly ? &pUVM->aCpus[idDstCpu].vm.s.pNormalReqs : ppPriorityReqs;
|
---|
| 1124 | }
|
---|
| 1125 |
|
---|
| 1126 | /*
|
---|
[1] | 1127 | * Process loop.
|
---|
| 1128 | *
|
---|
[19217] | 1129 | * We do not repeat the outer loop if we've got an informational status code
|
---|
[38613] | 1130 | * since that code needs processing by our caller (usually EM).
|
---|
[1] | 1131 | */
|
---|
| 1132 | int rc = VINF_SUCCESS;
|
---|
[38613] | 1133 | for (;;)
|
---|
[1] | 1134 | {
|
---|
| 1135 | /*
|
---|
[39327] | 1136 | * Get the pending requests.
|
---|
| 1137 | *
|
---|
[24738] | 1138 | * If there are more than one request, unlink the oldest and put the
|
---|
| 1139 | * rest back so that we're reentrant.
|
---|
[1] | 1140 | */
|
---|
[38838] | 1141 | if (RT_LIKELY(pUVM->pVM))
|
---|
[13765] | 1142 | {
|
---|
[38838] | 1143 | if (idDstCpu == VMCPUID_ANY)
|
---|
[13765] | 1144 | VM_FF_CLEAR(pUVM->pVM, VM_FF_REQUEST);
|
---|
[38838] | 1145 | else
|
---|
| 1146 | VMCPU_FF_CLEAR(&pUVM->pVM->aCpus[idDstCpu], VMCPU_FF_REQUEST);
|
---|
[13765] | 1147 | }
|
---|
[38838] | 1148 |
|
---|
| 1149 | PVMREQ pReq = ASMAtomicXchgPtrT(ppPriorityReqs, NULL, PVMREQ);
|
---|
| 1150 | if (pReq)
|
---|
| 1151 | {
|
---|
| 1152 | if (RT_UNLIKELY(pReq->pNext))
|
---|
| 1153 | pReq = vmR3ReqProcessUTooManyHelper(pUVM, idDstCpu, pReq, ppPriorityReqs);
|
---|
| 1154 | else if (ASMAtomicReadPtrT(ppNormalReqs, PVMREQ))
|
---|
| 1155 | vmR3ReqSetFF(pUVM, idDstCpu);
|
---|
| 1156 | }
|
---|
[13765] | 1157 | else
|
---|
| 1158 | {
|
---|
[38838] | 1159 | pReq = ASMAtomicXchgPtrT(ppNormalReqs, NULL, PVMREQ);
|
---|
| 1160 | if (!pReq)
|
---|
| 1161 | break;
|
---|
| 1162 | if (RT_UNLIKELY(pReq->pNext))
|
---|
| 1163 | pReq = vmR3ReqProcessUTooManyHelper(pUVM, idDstCpu, pReq, ppNormalReqs);
|
---|
[13765] | 1164 | }
|
---|
[24738] | 1165 |
|
---|
[1] | 1166 | /*
|
---|
[38613] | 1167 | * Process the request
|
---|
[1] | 1168 | */
|
---|
[24738] | 1169 | STAM_COUNTER_INC(&pUVM->vm.s.StatReqProcessed);
|
---|
[62647] | 1170 | int rc2 = vmR3ReqProcessOne(pReq);
|
---|
[24738] | 1171 | if ( rc2 >= VINF_EM_FIRST
|
---|
[38613] | 1172 | && rc2 <= VINF_EM_LAST)
|
---|
| 1173 | {
|
---|
[24738] | 1174 | rc = rc2;
|
---|
[38613] | 1175 | break;
|
---|
| 1176 | }
|
---|
[1] | 1177 | }
|
---|
| 1178 |
|
---|
[13818] | 1179 | LogFlow(("VMR3ReqProcess: returns %Rrc (enmVMState=%d)\n", rc, pUVM->pVM ? pUVM->pVM->enmVMState : VMSTATE_CREATING));
|
---|
[1] | 1180 | return rc;
|
---|
| 1181 | }
|
---|
| 1182 |
|
---|
| 1183 |
|
---|
| 1184 | /**
|
---|
| 1185 | * Process one request.
|
---|
| 1186 | *
|
---|
| 1187 | * @returns VBox status code.
|
---|
| 1188 | *
|
---|
| 1189 | * @param pReq Request packet to process.
|
---|
| 1190 | */
|
---|
[62647] | 1191 | static int vmR3ReqProcessOne(PVMREQ pReq)
|
---|
[1] | 1192 | {
|
---|
[62647] | 1193 | LogFlow(("vmR3ReqProcessOne: pReq=%p type=%d fFlags=%#x\n", pReq, pReq->enmType, pReq->fFlags));
|
---|
[1] | 1194 |
|
---|
| 1195 | /*
|
---|
| 1196 | * Process the request.
|
---|
| 1197 | */
|
---|
| 1198 | Assert(pReq->enmState == VMREQSTATE_QUEUED);
|
---|
| 1199 | pReq->enmState = VMREQSTATE_PROCESSING;
|
---|
| 1200 | int rcRet = VINF_SUCCESS; /* the return code of this function. */
|
---|
| 1201 | int rcReq = VERR_NOT_IMPLEMENTED; /* the request status. */
|
---|
| 1202 | switch (pReq->enmType)
|
---|
| 1203 | {
|
---|
| 1204 | /*
|
---|
| 1205 | * A packed down call frame.
|
---|
| 1206 | */
|
---|
| 1207 | case VMREQTYPE_INTERNAL:
|
---|
| 1208 | {
|
---|
| 1209 | uintptr_t *pauArgs = &pReq->u.Internal.aArgs[0];
|
---|
[23] | 1210 | union
|
---|
[1] | 1211 | {
|
---|
| 1212 | PFNRT pfn;
|
---|
| 1213 | DECLCALLBACKMEMBER(int, pfn00)(void);
|
---|
| 1214 | DECLCALLBACKMEMBER(int, pfn01)(uintptr_t);
|
---|
| 1215 | DECLCALLBACKMEMBER(int, pfn02)(uintptr_t, uintptr_t);
|
---|
| 1216 | DECLCALLBACKMEMBER(int, pfn03)(uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1217 | DECLCALLBACKMEMBER(int, pfn04)(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1218 | DECLCALLBACKMEMBER(int, pfn05)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1219 | DECLCALLBACKMEMBER(int, pfn06)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1220 | DECLCALLBACKMEMBER(int, pfn07)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1221 | DECLCALLBACKMEMBER(int, pfn08)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1222 | DECLCALLBACKMEMBER(int, pfn09)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1223 | DECLCALLBACKMEMBER(int, pfn10)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1224 | DECLCALLBACKMEMBER(int, pfn11)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1225 | DECLCALLBACKMEMBER(int, pfn12)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
[34790] | 1226 | DECLCALLBACKMEMBER(int, pfn13)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1227 | DECLCALLBACKMEMBER(int, pfn14)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
| 1228 | DECLCALLBACKMEMBER(int, pfn15)(uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t);
|
---|
[1] | 1229 | } u;
|
---|
| 1230 | u.pfn = pReq->u.Internal.pfn;
|
---|
[3696] | 1231 | #ifdef RT_ARCH_AMD64
|
---|
[1] | 1232 | switch (pReq->u.Internal.cArgs)
|
---|
| 1233 | {
|
---|
| 1234 | case 0: rcRet = u.pfn00(); break;
|
---|
| 1235 | case 1: rcRet = u.pfn01(pauArgs[0]); break;
|
---|
| 1236 | case 2: rcRet = u.pfn02(pauArgs[0], pauArgs[1]); break;
|
---|
| 1237 | case 3: rcRet = u.pfn03(pauArgs[0], pauArgs[1], pauArgs[2]); break;
|
---|
| 1238 | case 4: rcRet = u.pfn04(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3]); break;
|
---|
| 1239 | case 5: rcRet = u.pfn05(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4]); break;
|
---|
| 1240 | case 6: rcRet = u.pfn06(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5]); break;
|
---|
| 1241 | case 7: rcRet = u.pfn07(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6]); break;
|
---|
| 1242 | case 8: rcRet = u.pfn08(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7]); break;
|
---|
| 1243 | case 9: rcRet = u.pfn09(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7], pauArgs[8]); break;
|
---|
| 1244 | case 10: rcRet = u.pfn10(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7], pauArgs[8], pauArgs[9]); break;
|
---|
| 1245 | case 11: rcRet = u.pfn11(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7], pauArgs[8], pauArgs[9], pauArgs[10]); break;
|
---|
| 1246 | case 12: rcRet = u.pfn12(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7], pauArgs[8], pauArgs[9], pauArgs[10], pauArgs[11]); break;
|
---|
[34790] | 1247 | case 13: rcRet = u.pfn13(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7], pauArgs[8], pauArgs[9], pauArgs[10], pauArgs[11], pauArgs[12]); break;
|
---|
| 1248 | case 14: rcRet = u.pfn14(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7], pauArgs[8], pauArgs[9], pauArgs[10], pauArgs[11], pauArgs[12], pauArgs[13]); break;
|
---|
| 1249 | case 15: rcRet = u.pfn15(pauArgs[0], pauArgs[1], pauArgs[2], pauArgs[3], pauArgs[4], pauArgs[5], pauArgs[6], pauArgs[7], pauArgs[8], pauArgs[9], pauArgs[10], pauArgs[11], pauArgs[12], pauArgs[13], pauArgs[14]); break;
|
---|
[1] | 1250 | default:
|
---|
| 1251 | AssertReleaseMsgFailed(("cArgs=%d\n", pReq->u.Internal.cArgs));
|
---|
[39402] | 1252 | rcRet = rcReq = VERR_VM_REQUEST_TOO_MANY_ARGS_IPE;
|
---|
[1] | 1253 | break;
|
---|
| 1254 | }
|
---|
| 1255 | #else /* x86: */
|
---|
| 1256 | size_t cbArgs = pReq->u.Internal.cArgs * sizeof(uintptr_t);
|
---|
| 1257 | # ifdef __GNUC__
|
---|
| 1258 | __asm__ __volatile__("movl %%esp, %%edx\n\t"
|
---|
| 1259 | "subl %2, %%esp\n\t"
|
---|
| 1260 | "andl $0xfffffff0, %%esp\n\t"
|
---|
| 1261 | "shrl $2, %2\n\t"
|
---|
| 1262 | "movl %%esp, %%edi\n\t"
|
---|
| 1263 | "rep movsl\n\t"
|
---|
| 1264 | "movl %%edx, %%edi\n\t"
|
---|
| 1265 | "call *%%eax\n\t"
|
---|
| 1266 | "mov %%edi, %%esp\n\t"
|
---|
| 1267 | : "=a" (rcRet),
|
---|
| 1268 | "=S" (pauArgs),
|
---|
| 1269 | "=c" (cbArgs)
|
---|
| 1270 | : "0" (u.pfn),
|
---|
| 1271 | "1" (pauArgs),
|
---|
| 1272 | "2" (cbArgs)
|
---|
| 1273 | : "edi", "edx");
|
---|
| 1274 | # else
|
---|
| 1275 | __asm
|
---|
| 1276 | {
|
---|
| 1277 | xor edx, edx /* just mess it up. */
|
---|
| 1278 | mov eax, u.pfn
|
---|
| 1279 | mov ecx, cbArgs
|
---|
| 1280 | shr ecx, 2
|
---|
| 1281 | mov esi, pauArgs
|
---|
| 1282 | mov ebx, esp
|
---|
| 1283 | sub esp, cbArgs
|
---|
| 1284 | and esp, 0xfffffff0
|
---|
| 1285 | mov edi, esp
|
---|
| 1286 | rep movsd
|
---|
| 1287 | call eax
|
---|
| 1288 | mov esp, ebx
|
---|
| 1289 | mov rcRet, eax
|
---|
| 1290 | }
|
---|
| 1291 | # endif
|
---|
| 1292 | #endif /* x86 */
|
---|
| 1293 | if ((pReq->fFlags & (VMREQFLAGS_RETURN_MASK)) == VMREQFLAGS_VOID)
|
---|
| 1294 | rcRet = VINF_SUCCESS;
|
---|
| 1295 | rcReq = rcRet;
|
---|
| 1296 | break;
|
---|
| 1297 | }
|
---|
| 1298 |
|
---|
| 1299 | default:
|
---|
| 1300 | AssertMsgFailed(("pReq->enmType=%d\n", pReq->enmType));
|
---|
| 1301 | rcReq = VERR_NOT_IMPLEMENTED;
|
---|
| 1302 | break;
|
---|
| 1303 | }
|
---|
| 1304 |
|
---|
| 1305 | /*
|
---|
| 1306 | * Complete the request.
|
---|
| 1307 | */
|
---|
| 1308 | pReq->iStatus = rcReq;
|
---|
| 1309 | pReq->enmState = VMREQSTATE_COMPLETED;
|
---|
| 1310 | if (pReq->fFlags & VMREQFLAGS_NO_WAIT)
|
---|
| 1311 | {
|
---|
| 1312 | /* Free the packet, nobody is waiting. */
|
---|
[62647] | 1313 | LogFlow(("vmR3ReqProcessOne: Completed request %p: rcReq=%Rrc rcRet=%Rrc - freeing it\n",
|
---|
[1] | 1314 | pReq, rcReq, rcRet));
|
---|
| 1315 | VMR3ReqFree(pReq);
|
---|
| 1316 | }
|
---|
| 1317 | else
|
---|
| 1318 | {
|
---|
| 1319 | /* Notify the waiter and him free up the packet. */
|
---|
[62647] | 1320 | LogFlow(("vmR3ReqProcessOne: Completed request %p: rcReq=%Rrc rcRet=%Rrc - notifying waiting thread\n",
|
---|
[1] | 1321 | pReq, rcReq, rcRet));
|
---|
| 1322 | ASMAtomicXchgSize(&pReq->fEventSemClear, false);
|
---|
| 1323 | int rc2 = RTSemEventSignal(pReq->EventSem);
|
---|
[13816] | 1324 | if (RT_FAILURE(rc2))
|
---|
[1] | 1325 | {
|
---|
| 1326 | AssertRC(rc2);
|
---|
| 1327 | rcRet = rc2;
|
---|
| 1328 | }
|
---|
| 1329 | }
|
---|
[38838] | 1330 |
|
---|
[1] | 1331 | return rcRet;
|
---|
| 1332 | }
|
---|
| 1333 |
|
---|