Changeset 27023 in vbox for trunk/src/VBox
- Timestamp:
- Mar 4, 2010 1:32:45 PM (15 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest.cpp
r26999 r27023 558 558 559 559 #ifdef VBOX_WITH_MANAGEMENT 560 static int VBoxGuestSetBalloonSize(PVBOXGUESTDEVEXT pDevExt, uint32_t u32BalloonSize)560 static int VBoxGuestSetBalloonSize(PVBOXGUESTDEVEXT pDevExt, uint32_t cBalloonChunks) 561 561 { 562 562 VMMDevChangeMemBalloon *req = NULL; … … 564 564 uint32_t i; 565 565 566 if ( u32BalloonSize > pDevExt->MemBalloon.cMaxBalloons)567 { 568 AssertMsgFailed(("VBoxGuestSetBalloonSize illegal balloon size %d (max=%d)\n", u32BalloonSize, pDevExt->MemBalloon.cMaxBalloons));566 if (cBalloonChunks > pDevExt->MemBalloon.cMaxBalloonChunks) 567 { 568 AssertMsgFailed(("VBoxGuestSetBalloonSize illegal balloon size %d (max=%d)\n", cBalloonChunks, pDevExt->MemBalloon.cMaxBalloonChunks)); 569 569 return VERR_INVALID_PARAMETER; 570 570 } 571 571 572 if ( u32BalloonSize == pDevExt->MemBalloon.cBalloons)572 if (cBalloonChunks == pDevExt->MemBalloon.cBalloonChunks) 573 573 return VINF_SUCCESS; /* nothing to do */ 574 574 … … 578 578 return rc; 579 579 580 if ( u32BalloonSize > pDevExt->MemBalloon.cBalloons)580 if (cBalloonChunks > pDevExt->MemBalloon.cBalloonChunks) 581 581 { 582 582 /* inflate */ 583 for (i = pDevExt->MemBalloon.cBalloon s; i < u32BalloonSize; i++)583 for (i = pDevExt->MemBalloon.cBalloonChunks; i < cBalloonChunks; i++) 584 584 { 585 585 #ifndef TARGET_NT4 … … 669 669 #endif 670 670 pDevExt->MemBalloon.paMdlMemBalloon[i] = pMdl; 671 pDevExt->MemBalloon.cBalloon s++;671 pDevExt->MemBalloon.cBalloonChunks++; 672 672 } 673 673 } … … 676 676 { 677 677 /* deflate */ 678 for (i = pDevExt->MemBalloon.cBalloon s; i > u32BalloonSize; i--)678 for (i = pDevExt->MemBalloon.cBalloonChunks; i > cBalloonChunks; i--) 679 679 { 680 680 uint32_t index = i - 1; … … 718 718 719 719 pDevExt->MemBalloon.paMdlMemBalloon[index] = NULL; 720 pDevExt->MemBalloon.cBalloon s--;721 } 722 } 723 } 724 Assert(pDevExt->MemBalloon.cBalloon s <= pDevExt->MemBalloon.cMaxBalloons);720 pDevExt->MemBalloon.cBalloonChunks--; 721 } 722 } 723 } 724 Assert(pDevExt->MemBalloon.cBalloonChunks <= pDevExt->MemBalloon.cMaxBalloonChunks); 725 725 726 726 end: … … 752 752 if (!pDevExt->MemBalloon.paMdlMemBalloon) 753 753 { 754 pDevExt->MemBalloon.cMaxBalloon s = req->u32PhysMemSize;755 pDevExt->MemBalloon.paMdlMemBalloon = (PMDL *)ExAllocatePool(PagedPool, req-> u32PhysMemSize* sizeof(PMDL));754 pDevExt->MemBalloon.cMaxBalloonChunks = req->cPhysMemChunks; 755 pDevExt->MemBalloon.paMdlMemBalloon = (PMDL *)ExAllocatePool(PagedPool, req->cPhysMemChunks * sizeof(PMDL)); 756 756 Assert(pDevExt->MemBalloon.paMdlMemBalloon); 757 757 if (!pDevExt->MemBalloon.paMdlMemBalloon) 758 758 return VERR_NO_MEMORY; 759 759 } 760 Assert(pDevExt->MemBalloon.cMaxBalloon s == req->u32PhysMemSize);761 762 rc = VBoxGuestSetBalloonSize(pDevExt, req-> u32BalloonSize);760 Assert(pDevExt->MemBalloon.cMaxBalloonChunks == req->cPhysMemChunks); 761 762 rc = VBoxGuestSetBalloonSize(pDevExt, req->cBalloonChunks); 763 763 /* ignore out of memory failures */ 764 764 if (rc == VERR_NO_MEMORY) … … 766 766 767 767 if (pMemBalloonSize) 768 *pMemBalloonSize = pDevExt->MemBalloon.cBalloon s;768 *pMemBalloonSize = pDevExt->MemBalloon.cBalloonChunks; 769 769 } 770 770 … … 780 780 ULONG dummy; 781 781 782 pDevExt->MemBalloon.cBalloon s= 0;783 pDevExt->MemBalloon.cMaxBalloon s= 0;782 pDevExt->MemBalloon.cBalloonChunks = 0; 783 pDevExt->MemBalloon.cMaxBalloonChunks = 0; 784 784 pDevExt->MemBalloon.paMdlMemBalloon = NULL; 785 785 … … 798 798 pDevExt->MemBalloon.paMdlMemBalloon = NULL; 799 799 } 800 Assert(pDevExt->MemBalloon.cBalloon s == 0);800 Assert(pDevExt->MemBalloon.cBalloonChunks == 0); 801 801 #endif 802 802 } … … 1382 1382 case VBOXGUEST_IOCTL_CHECK_BALLOON: 1383 1383 { 1384 ULONG *pMemBalloonSize = (ULONG *)pBuf;1384 VBoxGuestCheckBalloonInfo *pInfo = (VBoxGuestCheckBalloonInfo *)pBuf; 1385 1385 1386 1386 if (pStack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG)) … … 1392 1392 } 1393 1393 1394 int rc = VBoxGuestQueryMemoryBalloon(pDevExt, pMemBalloonSize); 1394 ULONG cMemoryBalloonChunks; 1395 int rc = VBoxGuestQueryMemoryBalloon(pDevExt, &cMemoryBalloonChunks); 1395 1396 if (RT_FAILURE(rc)) 1396 1397 { … … 1401 1402 { 1402 1403 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength; 1404 pInfo->cBalloonChunks = cMemoryBalloonChunks; 1405 pInfo->fHandleInR3 = false; 1403 1406 } 1404 1407 break; -
trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest_Internal.h
r25022 r27023 216 216 struct 217 217 { 218 uint32_t cBalloon s;219 uint32_t cMaxBalloon s;218 uint32_t cBalloonChunks; 219 uint32_t cMaxBalloonChunks; 220 220 PMDL *paMdlMemBalloon; 221 221 } MemBalloon; -
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp
r26999 r27023 48 48 #endif 49 49 50 const size_t cbChangeMemBalloonReq = RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[VMMDEV_MEMORY_BALLOON_CHUNK_PAGES]); 50 51 51 52 … … 259 260 { 260 261 VMMDevReportGuestInfo *pReq; 261 int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, sizeof(*pReq), VMMDevReq_ReportGuestInfo); 262 int rc; 263 rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, sizeof(*pReq), VMMDevReq_ReportGuestInfo); 262 264 if (RT_SUCCESS(rc)) 263 265 { … … 274 276 } 275 277 278 /** 279 * Inflate the balloon by one chunk represented by an R0 memory object. 280 * 281 * @returns IPRT status code. 282 * @param pMemObj Pointer to the R0 memory object. 283 * @param pReq The pre-allocated request for performing the VMMDev call. 284 */ 285 static int vboxGuestBalloonInflate(PRTR0MEMOBJ pMemObj, VMMDevChangeMemBalloon *pReq) 286 { 287 uint32_t iPage; 288 int rc; 289 290 for (iPage = 0; iPage < VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; iPage++) 291 { 292 RTHCPHYS phys = RTR0MemObjGetPagePhysAddr(*pMemObj, iPage); 293 pReq->aPhysPage[iPage] = phys; 294 } 295 296 /* Protect this memory from being accessed. Doesn't work on every platform and probably 297 * doesn't work for R3-provided memory, therefore ignore the return value. Unprotect 298 * done when object is freed. */ 299 rc = RTR0MemObjProtect(*pMemObj, 0, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, RTMEM_PROT_NONE); 300 NOREF(rc); 301 302 pReq->fInflate = true; 303 pReq->header.size = cbChangeMemBalloonReq; 304 pReq->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 305 306 return VbglGRPerform(&pReq->header); 307 } 308 309 /** 310 * Deflate the balloon by one chunk represented by an R0 memory object. 311 * 312 * @returns IPRT status code. 313 * @param pMemObj Pointer to the R0 memory object. 314 * The memory object will be freed afterwards. 315 * @param pReq The pre-allocated request for performing the VMMDev call. 316 */ 317 static int vboxGuestBalloonDeflate(PRTR0MEMOBJ pMemObj, VMMDevChangeMemBalloon *pReq) 318 { 319 uint32_t iPage; 320 int rc; 321 322 for (iPage = 0; iPage < VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; iPage++) 323 { 324 RTHCPHYS phys = RTR0MemObjGetPagePhysAddr(*pMemObj, iPage); 325 pReq->aPhysPage[iPage] = phys; 326 } 327 328 pReq->fInflate = false; 329 pReq->header.size = cbChangeMemBalloonReq; 330 pReq->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 331 332 rc = VbglGRPerform(&pReq->header); 333 if (RT_FAILURE(rc)) 334 return rc; 335 336 rc = RTR0MemObjFree(*pMemObj, true); 337 if (RT_FAILURE(rc)) 338 return rc; 339 340 *pMemObj = NIL_RTR0MEMOBJ; 341 return VINF_SUCCESS; 342 } 343 276 344 277 345 /** … … 279 347 * 280 348 * @returns VBox status code. 281 * @param pDevExt The device extension282 * @param u32BalloonSizeThe new size of the balloon in chunks of 1MB.283 */ 284 static int vboxGuestSetBalloonSizeKernel(PVBOXGUESTDEVEXT pDevExt, uint32_t u32BalloonSize)349 * @param pDevExt The device extension 350 * @param cBalloonChunks The new size of the balloon in chunks of 1MB. 351 */ 352 static int vboxGuestSetBalloonSizeKernel(PVBOXGUESTDEVEXT pDevExt, uint32_t cBalloonChunks) 285 353 { 286 354 int rc = VINF_SUCCESS; … … 289 357 { 290 358 VMMDevChangeMemBalloon *pReq; 291 uint32_t i, j; 292 const size_t cbReq = RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[VMMDEV_MEMORY_BALLOON_CHUNK_PAGES]); 293 294 if (u32BalloonSize > pDevExt->MemBalloon.cMaxChunks) 359 uint32_t i; 360 361 if (cBalloonChunks > pDevExt->MemBalloon.cMaxChunks) 295 362 { 296 363 AssertMsgFailed(("vboxGuestSetBalloonSize illegal balloon size %d (max=%d)\n", 297 u32BalloonSize, pDevExt->MemBalloon.cMaxChunks));364 cBalloonChunks, pDevExt->MemBalloon.cMaxChunks)); 298 365 return VERR_INVALID_PARAMETER; 299 366 } 300 367 301 if ( u32BalloonSize== pDevExt->MemBalloon.cMaxChunks)368 if (cBalloonChunks == pDevExt->MemBalloon.cMaxChunks) 302 369 return VINF_SUCCESS; /* nothing to do */ 303 370 304 rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, cbReq, VMMDevReq_ChangeMemBalloon); 371 if ( cBalloonChunks > pDevExt->MemBalloon.cChunks 372 && !pDevExt->MemBalloon.paMemObj) 373 { 374 pDevExt->MemBalloon.paMemObj = (RTR0MEMOBJ*)RTMemAllocZ(sizeof(RTR0MEMOBJ) * pDevExt->MemBalloon.cMaxChunks); 375 if (!pDevExt->MemBalloon.paMemObj) 376 { 377 LogRel(("VBoxGuestSetBalloonSizeKernel: no memory for paMemObj!\n")); 378 return VERR_NO_MEMORY; 379 } 380 } 381 382 rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, cbChangeMemBalloonReq, VMMDevReq_ChangeMemBalloon); 305 383 if (RT_FAILURE(rc)) 306 384 return rc; 307 385 308 if ( u32BalloonSize> pDevExt->MemBalloon.cChunks)386 if (cBalloonChunks > pDevExt->MemBalloon.cChunks) 309 387 { 310 388 /* inflate */ 311 for (i = pDevExt->MemBalloon.cChunks; i < u32BalloonSize; i++)389 for (i = pDevExt->MemBalloon.cChunks; i < cBalloonChunks; i++) 312 390 { 313 391 rc = RTR0MemObjAllocPhysNC(&pDevExt->MemBalloon.paMemObj[i], 314 VMMDEV_MEMORY_BALLOON_CHUNK_ PAGES * PAGE_SIZE, NIL_RTHCPHYS);392 VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, NIL_RTHCPHYS); 315 393 if (RT_UNLIKELY(rc == VERR_NOT_SUPPORTED)) 316 394 { 395 /* not supported -- fall back to the R3-allocated memory */ 317 396 pDevExt->MemBalloon.fUseKernelAPI = false; 318 397 break; … … 329 408 } 330 409 331 RTR0MEMOBJ MemObj = pDevExt->MemBalloon.paMemObj[i]; 332 for (j = 0; j < VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; j++) 333 { 334 RTHCPHYS phys = RTR0MemObjGetPagePhysAddr(MemObj, j); 335 pReq->aPhysPage[j] = phys; 336 } 337 338 pReq->header.size = cbReq; 339 pReq->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 340 pReq->fInflate = true; 341 342 rc = VbglGRPerform(&pReq->header); 410 rc = vboxGuestBalloonInflate(&pDevExt->MemBalloon.paMemObj[i], pReq); 343 411 if (RT_FAILURE(rc)) 344 412 { 345 Log(("vboxGuestSetBalloonSize(inflate): VbglGRPerformfailed, rc=%Rrc!\n", rc));413 Log(("vboxGuestSetBalloonSize(inflate): failed, rc=%Rrc!\n", rc)); 346 414 break; 347 415 } … … 352 420 { 353 421 /* deflate */ 354 for (i = pDevExt->MemBalloon.cChunks; i > u32BalloonSize; i--)422 for (i = pDevExt->MemBalloon.cChunks; i-- > cBalloonChunks;) 355 423 { 356 RTR0MEMOBJ MemObj = pDevExt->MemBalloon.paMemObj[i]; 357 for (j = 0; j < VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; j++) 358 { 359 RTHCPHYS phys = RTR0MemObjGetPagePhysAddr(MemObj, j); 360 pReq->aPhysPage[j] = phys; 361 } 362 363 pReq->header.size = cbReq; 364 pReq->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 365 pReq->fInflate = false; 366 367 rc = VbglGRPerform(&pReq->header); 424 rc = vboxGuestBalloonDeflate(&pDevExt->MemBalloon.paMemObj[i], pReq); 368 425 if (RT_FAILURE(rc)) 369 426 { 370 Log(("vboxGuestSetBalloonSize(deflate): VbglGRPerformfailed, rc=%Rrc!\n", rc));427 Log(("vboxGuestSetBalloonSize(deflate): failed, rc=%Rrc!\n", rc)); 371 428 break; 372 429 } 373 374 rc = RTR0MemObjFree(pDevExt->MemBalloon.paMemObj[i], true);375 if (RT_FAILURE(rc))376 {377 Log(("vboxGuestSetBalloonSize(deflate): RTR0MemObjFree() failed, rc=%Rrc!\n", rc));378 break;379 }380 pDevExt->MemBalloon.paMemObj[i] = NIL_RTR0MEMOBJ;381 430 pDevExt->MemBalloon.cChunks--; 382 431 } … … 405 454 VMMDevChangeMemBalloon *pReq; 406 455 int rc = VINF_SUCCESS; 407 uint32_t i, j; 408 const size_t cbReq = RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[VMMDEV_MEMORY_BALLOON_CHUNK_PAGES]); 456 uint32_t i; 409 457 PRTR0MEMOBJ pMemObj = NULL; 410 458 411 if ( fInflate 412 && pSession->MemBalloon.cChunks > pSession->MemBalloon.cMaxChunks - 1) 413 { 414 AssertMsgFailed(("vboxGuestSetBalloonSize: cannot inflate balloon, already have (max=%d)\n", 415 pSession->MemBalloon.cChunks, pSession->MemBalloon.cMaxChunks)); 416 return VERR_INVALID_PARAMETER; 417 } 418 else if ( !fInflate 419 && pSession->MemBalloon.cChunks == 0) 420 { 421 AssertMsgFailed(("vboxGuestSetBalloonSize: cannot decrease balloon, already at size 0\n")); 422 return VERR_INVALID_PARAMETER; 459 if (fInflate) 460 { 461 if (pSession->MemBalloon.cChunks > pDevExt->MemBalloon.cMaxChunks - 1) 462 { 463 AssertMsgFailed(("vboxGuestSetBalloonSize: cannot inflate balloon, already have (max=%d)\n", 464 pSession->MemBalloon.cChunks, pDevExt->MemBalloon.cMaxChunks)); 465 return VERR_INVALID_PARAMETER; 466 } 467 468 if (!pSession->MemBalloon.paMemObj) 469 { 470 pSession->MemBalloon.paMemObj = (RTR0MEMOBJ*)RTMemAllocZ(sizeof(RTR0MEMOBJ) * pDevExt->MemBalloon.cMaxChunks); 471 if (!pSession->MemBalloon.paMemObj) 472 { 473 LogRel(("VBoxGuestSetBalloonSizeFromUser: no memory for paMemObj!\n")); 474 return VERR_NO_MEMORY; 475 } 476 for (i = 0; i < pDevExt->MemBalloon.cMaxChunks; i++) 477 pSession->MemBalloon.paMemObj[i] = NIL_RTR0MEMOBJ; 478 } 479 } 480 else 481 { 482 if (pSession->MemBalloon.cChunks == 0) 483 { 484 AssertMsgFailed(("vboxGuestSetBalloonSize: cannot decrease balloon, already at size 0\n")); 485 return VERR_INVALID_PARAMETER; 486 } 423 487 } 424 488 … … 426 490 * Enumerate all memory objects and check if the object is already registered. 427 491 */ 428 for (i = 0; i < p Session->MemBalloon.cMaxChunks; i++)492 for (i = 0; i < pDevExt->MemBalloon.cMaxChunks; i++) 429 493 { 430 494 if ( fInflate 431 && !p Session->MemBalloon.paMemObj[i] == NIL_RTR0MEMOBJ432 && !pMemObj)495 && !pMemObj 496 && pSession->MemBalloon.paMemObj[i] == NIL_RTR0MEMOBJ) 433 497 pMemObj = &pSession->MemBalloon.paMemObj[i]; /* found free object pointer */ 434 498 if (RTR0MemObjAddressR3(pSession->MemBalloon.paMemObj[i]) == u64ChunkAddr) … … 448 512 } 449 513 450 rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, cb Req, VMMDevReq_ChangeMemBalloon);514 rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, cbChangeMemBalloonReq, VMMDevReq_ChangeMemBalloon); 451 515 if (RT_FAILURE(rc)) 452 516 return rc; … … 456 520 if (fInflate) 457 521 { 458 rc = RTR0MemObjLockUser(pMemObj, u64ChunkAddr, VMMDEV_MEMORY_BALLOON_CHUNK_ PAGES * PAGE_SIZE,522 rc = RTR0MemObjLockUser(pMemObj, u64ChunkAddr, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, 459 523 RTMEM_PROT_READ | RTMEM_PROT_WRITE, NIL_RTR0PROCESS); 460 524 if (RT_SUCCESS(rc)) 461 525 { 462 RTR0MEMOBJ MemObj = pDevExt->MemBalloon.paMemObj[i]; 463 for (j = 0; j < VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; j++) 464 { 465 RTHCPHYS phys = RTR0MemObjGetPagePhysAddr(MemObj, j); 466 pReq->aPhysPage[j] = phys; 467 } 468 469 pReq->header.size = cbReq; 470 pReq->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 471 pReq->fInflate = true; 472 473 rc = VbglGRPerform(&pReq->header); 526 rc = vboxGuestBalloonInflate(pMemObj, pReq); 474 527 if (RT_FAILURE(rc)) 475 528 { 476 Log(("vboxGuestSetBalloonSize(inflate): VbglGRPerformfailed, rc=%Rrc!\n", rc));529 Log(("vboxGuestSetBalloonSize(inflate): failed, rc=%Rrc!\n", rc)); 477 530 break; 478 531 } … … 482 535 else 483 536 { 484 /* deflate */ 485 for (j = 0; j < VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; j++) 486 { 487 RTHCPHYS phys = RTR0MemObjGetPagePhysAddr(*pMemObj, j); 488 pReq->aPhysPage[j] = phys; 489 } 490 491 pReq->header.size = cbReq; 492 pReq->cPages = VMMDEV_MEMORY_BALLOON_CHUNK_PAGES; 493 pReq->fInflate = false; 494 495 rc = VbglGRPerform(&pReq->header); 537 rc = vboxGuestBalloonDeflate(pMemObj, pReq); 496 538 if (RT_FAILURE(rc)) 497 539 { 498 Log(("vboxGuestSetBalloonSize(deflate): VbglGRPerformfailed, rc=%Rrc!\n", rc));540 Log(("vboxGuestSetBalloonSize(deflate): failed, rc=%Rrc!\n", rc)); 499 541 break; 500 542 } 501 502 rc = RTR0MemObjFree(*pMemObj, true);503 if (RT_FAILURE(rc))504 {505 Log(("vboxGuestSetBalloonSize(deflate): RTR0MemObjFree() failed, rc=%Rrc!\n", rc));506 break;507 }508 *pMemObj = NIL_RTR0MEMOBJ;509 543 pSession->MemBalloon.cChunks--; 510 544 } … … 517 551 518 552 /** 553 * Cleanup the memory balloon of a session. 554 */ 555 static void vboxGuestCloseSessionMemBalloon(PVBOXGUESTSESSION pSession) 556 { 557 if (pSession->MemBalloon.paMemObj) 558 { 559 VMMDevChangeMemBalloon *pReq; 560 int rc = VbglGRAlloc((VMMDevRequestHeader **)&pReq, cbChangeMemBalloonReq, VMMDevReq_ChangeMemBalloon); 561 if (RT_SUCCESS(rc)) 562 { 563 uint32_t i; 564 for (i = pSession->MemBalloon.cChunks; i-- > 0;) 565 { 566 rc = vboxGuestBalloonDeflate(&pSession->MemBalloon.paMemObj[i], pReq); 567 if (RT_FAILURE(rc)) 568 { 569 Log(("vboxGuestSetBalloonSize(deflate): failed, rc=%Rrc!\n", rc)); 570 break; 571 } 572 pSession->MemBalloon.paMemObj[i] = NIL_RTR0MEMOBJ; 573 pSession->MemBalloon.cChunks--; 574 } 575 VbglGRFree(&pReq->header); 576 } 577 RTMemFree(pSession->MemBalloon.paMemObj); 578 pSession->MemBalloon.paMemObj = NULL; 579 } 580 } 581 582 583 /** 519 584 * Init the variables for memory ballooning 520 585 * … … 525 590 pDevExt->MemBalloon.cChunks = 0; 526 591 pDevExt->MemBalloon.cMaxChunks = 0; 527 //#ifdef RT_OS_LINUX528 //pDevExt->MemBalloon.fUseKernelAPI = true;529 //#else592 #ifdef RT_OS_LINUX 593 pDevExt->MemBalloon.fUseKernelAPI = true; 594 #else 530 595 pDevExt->MemBalloon.fUseKernelAPI = false; 531 //#endif596 #endif 532 597 pDevExt->MemBalloon.paMemObj = NULL; 533 598 } … … 775 840 int VBoxGuestCreateUserSession(PVBOXGUESTDEVEXT pDevExt, PVBOXGUESTSESSION *ppSession) 776 841 { 777 unsigned i;778 842 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)RTMemAllocZ(sizeof(*pSession)); 779 843 if (RT_UNLIKELY(!pSession)) … … 856 920 pSession->Process = NIL_RTPROCESS; 857 921 pSession->R0Process = NIL_RTR0PROCESS; 922 vboxGuestCloseSessionMemBalloon(pSession); 858 923 RTMemFree(pSession); 859 924 } … … 1047 1112 Log(("VBoxGuestCommonIOCtlFast: iFunction=%#x pDevExt=%p pSession=%p\n", iFunction, pDevExt, pSession)); 1048 1113 1114 NOREF(iFunction); 1115 NOREF(pDevExt); 1116 NOREF(pSession); 1049 1117 return VERR_NOT_SUPPORTED; 1050 1118 } 1051 1119 1052 1120 1053 1121 /** 1122 * Return the VMM device port. 1123 * 1124 * returns IPRT status code. 1125 * @param pDevExt The device extension. 1126 * @param pInfo The request info. 1127 * @param pcbDataReturned (out) contains the number of bytes to return. 1128 */ 1054 1129 static int VBoxGuestCommonIOCtl_GetVMMDevPort(PVBOXGUESTDEVEXT pDevExt, VBoxGuestPortInfo *pInfo, size_t *pcbDataReturned) 1055 1130 { … … 1746 1821 */ 1747 1822 static int VBoxGuestCommonIOCtl_QueryMemoryBalloon(PVBOXGUESTDEVEXT pDevExt, 1748 uint32_t *memBalloonSize, size_t *pcbDataReturned)1823 VBoxGuestCheckBalloonInfo *pInfo, size_t *pcbDataReturned) 1749 1824 { 1750 1825 VMMDevGetMemBalloonChangeRequest *pReq; … … 1764 1839 } 1765 1840 1766 if ( pReq->u32BalloonSize != 0 1767 && !pDevExt->MemBalloon.paMemObj) 1768 { 1769 pDevExt->MemBalloon.cMaxChunks = pReq->u32PhysMemSize; 1770 pDevExt->MemBalloon.paMemObj = (RTR0MEMOBJ*)RTMemAllocZ(sizeof(RTR0MEMOBJ) * pReq->u32PhysMemSize); 1771 } 1772 1773 rc = vboxGuestSetBalloonSizeKernel(pDevExt, pReq->u32BalloonSize); 1774 /* ignore out of memory failures */ 1841 pDevExt->MemBalloon.cMaxChunks = pReq->cPhysMemChunks; 1842 1843 rc = vboxGuestSetBalloonSizeKernel(pDevExt, pReq->cBalloonChunks); 1844 /* Ignore out of memory failures */ 1775 1845 if (rc == VERR_NO_MEMORY) 1776 1846 rc = VINF_SUCCESS; 1777 1847 1778 /* Balloon size in MB */ 1779 *memBalloonSize = pReq->u32BalloonSize; 1848 /* Return values */ 1849 pInfo->cBalloonChunks = pReq->cBalloonChunks; 1850 pInfo->fHandleInR3 = false; 1851 if (rc == VERR_NO_PHYS_MEMORY) 1852 { 1853 pInfo->fHandleInR3 = true; 1854 rc = VINF_SUCCESS; 1855 } 1856 1780 1857 if (pcbDataReturned) 1781 *pcbDataReturned = sizeof( *memBalloonSize);1858 *pcbDataReturned = sizeof(VBoxGuestCheckBalloonInfo); 1782 1859 1783 1860 return rc; … … 1809 1886 static int VBoxGuestCommonIOCtl_Log(const char *pch, size_t cbData, size_t *pcbDataReturned) 1810 1887 { 1888 NOREF(pch); 1889 NOREF(cbData); 1811 1890 Log(("%.*s", cbData, pch)); 1812 1891 if (pcbDataReturned) … … 1977 2056 1978 2057 case VBOXGUEST_IOCTL_CHECK_BALLOON: 1979 CHECKRET_MIN_SIZE("CHECK_MEMORY_BALLOON", sizeof( uint32_t));1980 rc = VBoxGuestCommonIOCtl_QueryMemoryBalloon(pDevExt, ( uint32_t*)pvData, pcbDataReturned);2058 CHECKRET_MIN_SIZE("CHECK_MEMORY_BALLOON", sizeof(VBoxGuestCheckBalloonInfo)); 2059 rc = VBoxGuestCommonIOCtl_QueryMemoryBalloon(pDevExt, (VBoxGuestCheckBalloonInfo *)pvData, pcbDataReturned); 1981 2060 break; 1982 2061 -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibMisc.cpp
r26999 r27023 237 237 * @returns IPRT status code 238 238 * @param pu32Size Memory balloon size in MBs (out) 239 */ 240 VBGLR3DECL(int) VbglR3MemBalloonRefresh(uint32_t *pu32Size) 241 { 242 return vbglR3DoIOCtl(VBOXGUEST_IOCTL_CHECK_BALLOON, pu32Size, sizeof(*pu32Size)); 243 } 244 245 246 /** 247 * 239 * @param pfHandleInR3 Allocating of memory in R3 required (out) 240 */ 241 VBGLR3DECL(int) VbglR3MemBalloonRefresh(uint32_t *pcChunks, bool *pfHandleInR3) 242 { 243 VBoxGuestCheckBalloonInfo Info; 244 int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_CHECK_BALLOON, &Info, sizeof(Info)); 245 *pcChunks = Info.cBalloonChunks; 246 *pfHandleInR3 = Info.fHandleInR3; 247 return rc; 248 } 249 250 251 /** 252 * Change the memory by granting/reclaiming memory to/from R0. 253 * 254 * @returns IPRT status code 255 * @param pv Memory chunk (1MB) 256 * @param fInflate true = inflate balloon (grant memory) 257 * false = deflate balloon (reclaim memory) 248 258 */ 249 259 VBGLR3DECL(int) VbglR3MemBalloonChange(void *pv, bool fInflate) 250 260 { 251 261 VBoxGuestChangeBalloonInfo Info; 252 Info.u64ChunkAddr = (uint64_t) pv;262 Info.u64ChunkAddr = (uint64_t)((uintptr_t)pv); 253 263 Info.fInflate = fInflate; 254 264 return vbglR3DoIOCtl(VBOXGUEST_IOCTL_CHANGE_BALLOON, &Info, sizeof(Info)); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceBalloon.cpp
r26999 r27023 36 36 * Global Variables * 37 37 *******************************************************************************/ 38 static uint32_t g_ MemBalloonSize= 0;38 static uint32_t g_cMemBalloonChunks = 0; 39 39 40 40 /** The semaphore we're blocking on. */ 41 41 static RTSEMEVENTMULTI g_MemBalloonEvent = NIL_RTSEMEVENTMULTI; 42 42 43 /** The array holding the R3 pointers of the balloon */ 43 44 static void **g_pavBalloon = NULL; 44 45 45 46 46 static void VBoxServiceBalloonSetUser(uint32_t OldSize, uint32_t NewSize) 47 { 48 if (NewSize == OldSize) 49 return; 47 /** 48 * Adapt the R0 memory balloon by granting/reclaiming 1MB chunks to/from R0. 49 * 50 * returns IPRT status code. 51 * @param cNewChunks the number of 1MB chunks in the balloon 52 */ 53 static int VBoxServiceBalloonSetUser(uint32_t cNewChunks) 54 { 55 if (cNewChunks == g_cMemBalloonChunks) 56 return VINF_SUCCESS; 50 57 51 58 int rc = VINF_SUCCESS; 52 if ( NewSize > OldSize)59 if (cNewChunks > g_cMemBalloonChunks) 53 60 { 54 61 /* inflate */ 55 62 uint32_t i; 56 g_pavBalloon = (void**)RTMemRealloc(g_pavBalloon, NewSize * sizeof(void*)); 57 RTPrintf("allocated %d bytes\n", g_pavBalloon, NewSize * sizeof(void*)); 58 for (i = OldSize; i < NewSize; i++) 59 { 60 void *pv = RTMemAlloc(VMMDEV_MEMORY_BALLOON_CHUNK_PAGES * PAGE_SIZE); 61 VBoxServiceVerbose(3, "Alloc %p\n", pv); 63 g_pavBalloon = (void**)RTMemRealloc(g_pavBalloon, cNewChunks * sizeof(void*)); 64 for (i = g_cMemBalloonChunks; i < cNewChunks; i++) 65 { 66 void *pv = RTMemPageAlloc(VMMDEV_MEMORY_BALLOON_CHUNK_SIZE); 62 67 rc = VbglR3MemBalloonChange(pv, /* inflate=*/ true); 63 68 if (RT_SUCCESS(rc)) 64 69 { 65 VBoxServiceVerbose(3, " => %Rrc\n", rc);66 70 g_pavBalloon[i] = pv; 67 OldSize++; 71 /* protect against access by dangling pointers */ 72 RTMemProtect(pv, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, RTMEM_PROT_NONE); 73 g_cMemBalloonChunks++; 68 74 } 69 75 else … … 75 81 /* deflate */ 76 82 uint32_t i; 77 for (i = OldSize; i > NewSize; i--)78 { 79 void *pv = g_pavBalloon[i -1];83 for (i = g_cMemBalloonChunks; i-- > cNewChunks;) 84 { 85 void *pv = g_pavBalloon[i]; 80 86 rc = VbglR3MemBalloonChange(pv, /* inflate=*/ false); 81 87 if (RT_SUCCESS(rc)) 82 88 { 83 VBoxServiceVerbose(3, "Free %p\n", g_pavBalloon[i-1]); 84 RTMemFree(g_pavBalloon[i-1]); 85 g_pavBalloon[i-1] = NULL; 86 OldSize--; 89 /* unprotect */ 90 RTMemProtect(pv, VMMDEV_MEMORY_BALLOON_CHUNK_SIZE, RTMEM_PROT_READ | RTMEM_PROT_WRITE); 91 RTMemPageFree(g_pavBalloon[i]); 92 g_pavBalloon[i] = NULL; 93 g_cMemBalloonChunks--; 87 94 } 88 95 else … … 91 98 } 92 99 93 if (RT_FAILURE(rc)) 94 g_MemBalloonSize = OldSize; 100 return VINF_SUCCESS; 95 101 } 96 102 … … 106 112 static DECLCALLBACK(int) VBoxServiceBalloonOption(const char **ppszShort, int argc, char **argv, int *pi) 107 113 { 114 NOREF(ppszShort); 115 NOREF(argc); 116 NOREF(argv); 117 NOREF(pi); 108 118 return VINF_SUCCESS; 109 119 } … … 118 128 AssertRCReturn(rc, rc); 119 129 120 g_MemBalloonSize = 0; 130 g_cMemBalloonChunks = 0; 131 uint32_t cNewChunks = 0; 132 bool fHandleInR3; 121 133 122 134 /* Check balloon size */ 123 rc = VbglR3MemBalloonRefresh(& g_MemBalloonSize);135 rc = VbglR3MemBalloonRefresh(&cNewChunks, &fHandleInR3); 124 136 if (RT_SUCCESS(rc)) 125 VBoxServiceVerbose(3, "VBoxMemBalloonInit: new balloon size %d MB\n", g_MemBalloonSize); 126 else if (rc == VERR_NO_PHYS_MEMORY) 127 VBoxServiceBalloonSetUser(0, g_MemBalloonSize); 137 { 138 VBoxServiceVerbose(3, "VBoxMemBalloonInit: new balloon size %d MB (%s memory)\n", 139 cNewChunks, fHandleInR3 ? "R3" : "R0"); 140 if (fHandleInR3) 141 rc = VBoxServiceBalloonSetUser(cNewChunks); 142 else 143 g_cMemBalloonChunks = cNewChunks; 144 } 128 145 else 129 VBoxServiceVerbose(3, "VBoxMemBalloonInit: VbglR3MemBalloonRefresh failed with % d\n", rc);146 VBoxServiceVerbose(3, "VBoxMemBalloonInit: VbglR3MemBalloonRefresh failed with %Rrc\n", rc); 130 147 131 148 /* We shouldn't fail here if ballooning isn't available. This can have several reasons, … … 135 152 136 153 137 uint32_t VBoxServiceBalloonQuery Size()138 { 139 return g_ MemBalloonSize;154 uint32_t VBoxServiceBalloonQueryChunks() 155 { 156 return g_cMemBalloonChunks; 140 157 } 141 158 … … 149 166 if (RT_FAILURE(rc)) 150 167 { 151 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with % d\n", rc);168 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with %Rrc\n", rc); 152 169 return rc; 153 170 } … … 171 188 && (fEvents & VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)) 172 189 { 173 uint32_t OldMemBalloonSize = g_MemBalloonSize; 174 rc = VbglR3MemBalloonRefresh(&g_MemBalloonSize); 190 uint32_t cNewChunks; 191 bool fHandleInR3; 192 rc = VbglR3MemBalloonRefresh(&cNewChunks, &fHandleInR3); 175 193 if (RT_SUCCESS(rc)) 176 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: new balloon size %d MB\n", g_MemBalloonSize); 177 else if (rc == VERR_NO_PHYS_MEMORY) 178 VBoxServiceBalloonSetUser(OldMemBalloonSize, g_MemBalloonSize); 194 { 195 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: new balloon size %d MB (%s memory)\n", 196 cNewChunks, fHandleInR3 ? "R3" : "R0"); 197 if (fHandleInR3) 198 rc = VBoxServiceBalloonSetUser(cNewChunks); 199 else 200 g_cMemBalloonChunks = cNewChunks; 201 } 179 202 else 180 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3MemBalloonRefresh failed with % d\n", rc);203 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3MemBalloonRefresh failed with %Rrc\n", rc); 181 204 } 182 205 … … 203 226 rc = VbglR3CtlFilterMask(0, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST); 204 227 if (RT_FAILURE(rc)) 205 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with % d\n", rc);228 VBoxServiceVerbose(3, "VBoxServiceBalloonWorker: VbglR3CtlFilterMask failed with %Rrc\n", rc); 206 229 207 230 RTSemEventMultiDestroy(g_MemBalloonEvent); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceCpuHotPlug.cpp
r26611 r27023 133 133 static DECLCALLBACK(int) VBoxServiceCpuHotPlugOption(const char **ppszShort, int argc, char **argv, int *pi) 134 134 { 135 NOREF(ppszShort); 136 NOREF(argc); 137 NOREF(argv); 138 NOREF(pi); 135 139 return VINF_SUCCESS; 136 140 } -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
r26326 r27023 168 168 169 169 #ifdef VBOXSERVICE_MANAGEMENT 170 extern uint32_t VBoxServiceBalloonQuery Size();170 extern uint32_t VBoxServiceBalloonQueryChunks(); 171 171 #endif 172 172 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp
r26901 r27023 75 75 static DECLCALLBACK(int) VBoxServiceVMStatsOption(const char **ppszShort, int argc, char **argv, int *pi) 76 76 { 77 NOREF(ppszShort); 78 NOREF(argc); 79 NOREF(argv); 80 NOREF(pi); 77 81 return VINF_SUCCESS; 78 82 } … … 169 173 req.guestStats.u32PageFileSize = (uint32_t)(memStatus.ullTotalPageFile / systemInfo.dwPageSize) - req.guestStats.u32PhysMemTotal; 170 174 req.guestStats.u32MemoryLoad = memStatus.dwMemoryLoad; 171 req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQuery Size() * (_1M/systemInfo.dwPageSize); /* was in megabytes */175 req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryChunks() * (_1M/systemInfo.dwPageSize); /* was in megabytes */ 172 176 req.guestStats.u32StatCaps = VBOX_GUEST_STAT_PHYS_MEM_TOTAL | VBOX_GUEST_STAT_PHYS_MEM_AVAIL | VBOX_GUEST_STAT_PAGE_FILE_SIZE | VBOX_GUEST_STAT_MEMORY_LOAD | VBOX_GUEST_STAT_PHYS_MEM_BALLOON; 173 177 -
trunk/src/VBox/Devices/VMMDev/VMMDev.cpp
r26350 r27023 1359 1359 /* just pass on the information */ 1360 1360 Log(("VMMDev: returning memory balloon size =%d\n", pThis->u32MemoryBalloonSize)); 1361 memBalloonChangeRequest-> u32BalloonSize= pThis->u32MemoryBalloonSize;1362 memBalloonChangeRequest-> u32PhysMemSize= pThis->cbGuestRAM / (uint64_t)_1M;1361 memBalloonChangeRequest->cBalloonChunks = pThis->u32MemoryBalloonSize; 1362 memBalloonChangeRequest->cPhysMemChunks = pThis->cbGuestRAM / (uint64_t)_1M; 1363 1363 1364 1364 if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
Note:
See TracChangeset
for help on using the changeset viewer.