vmcs.c (262352) | vmcs.c (266339) |
---|---|
1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: stable/10/sys/amd64/vmm/intel/vmcs.c 262352 2014-02-23 01:34:40Z jhb $ | 26 * $FreeBSD: stable/10/sys/amd64/vmm/intel/vmcs.c 266339 2014-05-17 19:11:08Z jhb $ |
27 */ 28 29#include "opt_ddb.h" 30 31#include <sys/cdefs.h> | 27 */ 28 29#include "opt_ddb.h" 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: stable/10/sys/amd64/vmm/intel/vmcs.c 262352 2014-02-23 01:34:40Z jhb $"); | 32__FBSDID("$FreeBSD: stable/10/sys/amd64/vmm/intel/vmcs.c 266339 2014-05-17 19:11:08Z jhb $"); |
33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/pcpu.h> 37 38#include <vm/vm.h> 39#include <vm/pmap.h> 40 --- 269 unchanged lines hidden (view full) --- 310 311 error = 0; 312done: 313 VMCLEAR(vmcs); 314 return (error); 315} 316 317int | 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/pcpu.h> 37 38#include <vm/vm.h> 39#include <vm/pmap.h> 40 --- 269 unchanged lines hidden (view full) --- 310 311 error = 0; 312done: 313 VMCLEAR(vmcs); 314 return (error); 315} 316 317int |
318vmcs_set_defaults(struct vmcs *vmcs, 319 u_long host_rip, u_long host_rsp, uint64_t eptp, 320 uint32_t pinbased_ctls, uint32_t procbased_ctls, 321 uint32_t procbased_ctls2, uint32_t exit_ctls, 322 uint32_t entry_ctls, u_long msr_bitmap, uint16_t vpid) | 318vmcs_init(struct vmcs *vmcs) |
323{ 324 int error, codesel, datasel, tsssel; 325 u_long cr0, cr4, efer; 326 uint64_t pat, fsbase, idtrbase; 327 uint32_t exc_bitmap; 328 329 codesel = vmm_get_host_codesel(); 330 datasel = vmm_get_host_datasel(); 331 tsssel = vmm_get_host_tsssel(); 332 333 /* 334 * Make sure we have a "current" VMCS to work with. 335 */ 336 VMPTRLD(vmcs); 337 | 319{ 320 int error, codesel, datasel, tsssel; 321 u_long cr0, cr4, efer; 322 uint64_t pat, fsbase, idtrbase; 323 uint32_t exc_bitmap; 324 325 codesel = vmm_get_host_codesel(); 326 datasel = vmm_get_host_datasel(); 327 tsssel = vmm_get_host_tsssel(); 328 329 /* 330 * Make sure we have a "current" VMCS to work with. 331 */ 332 VMPTRLD(vmcs); 333 |
338 /* 339 * Load the VMX controls 340 */ 341 if ((error = vmwrite(VMCS_PIN_BASED_CTLS, pinbased_ctls)) != 0) 342 goto done; 343 if ((error = vmwrite(VMCS_PRI_PROC_BASED_CTLS, procbased_ctls)) != 0) 344 goto done; 345 if ((error = vmwrite(VMCS_SEC_PROC_BASED_CTLS, procbased_ctls2)) != 0) 346 goto done; 347 if ((error = vmwrite(VMCS_EXIT_CTLS, exit_ctls)) != 0) 348 goto done; 349 if ((error = vmwrite(VMCS_ENTRY_CTLS, entry_ctls)) != 0) 350 goto done; 351 352 /* Guest state */ 353 | |
354 /* Initialize guest IA32_PAT MSR with the default value */ 355 pat = PAT_VALUE(0, PAT_WRITE_BACK) | 356 PAT_VALUE(1, PAT_WRITE_THROUGH) | 357 PAT_VALUE(2, PAT_UNCACHED) | 358 PAT_VALUE(3, PAT_UNCACHEABLE) | 359 PAT_VALUE(4, PAT_WRITE_BACK) | 360 PAT_VALUE(5, PAT_WRITE_THROUGH) | 361 PAT_VALUE(6, PAT_UNCACHED) | --- 55 unchanged lines hidden (view full) --- 417 if ((error = vmwrite(VMCS_HOST_FS_BASE, fsbase)) != 0) 418 goto done; 419 420 idtrbase = vmm_get_host_idtrbase(); 421 if ((error = vmwrite(VMCS_HOST_IDTR_BASE, idtrbase)) != 0) 422 goto done; 423 424 /* instruction pointer */ | 334 /* Initialize guest IA32_PAT MSR with the default value */ 335 pat = PAT_VALUE(0, PAT_WRITE_BACK) | 336 PAT_VALUE(1, PAT_WRITE_THROUGH) | 337 PAT_VALUE(2, PAT_UNCACHED) | 338 PAT_VALUE(3, PAT_UNCACHEABLE) | 339 PAT_VALUE(4, PAT_WRITE_BACK) | 340 PAT_VALUE(5, PAT_WRITE_THROUGH) | 341 PAT_VALUE(6, PAT_UNCACHED) | --- 55 unchanged lines hidden (view full) --- 397 if ((error = vmwrite(VMCS_HOST_FS_BASE, fsbase)) != 0) 398 goto done; 399 400 idtrbase = vmm_get_host_idtrbase(); 401 if ((error = vmwrite(VMCS_HOST_IDTR_BASE, idtrbase)) != 0) 402 goto done; 403 404 /* instruction pointer */ |
425 if ((error = vmwrite(VMCS_HOST_RIP, host_rip)) != 0) | 405 if ((error = vmwrite(VMCS_HOST_RIP, (u_long)vmx_exit_guest)) != 0) |
426 goto done; 427 | 406 goto done; 407 |
428 /* stack pointer */ 429 if ((error = vmwrite(VMCS_HOST_RSP, host_rsp)) != 0) 430 goto done; 431 432 /* eptp */ 433 if ((error = vmwrite(VMCS_EPTP, eptp)) != 0) 434 goto done; 435 436 /* vpid */ 437 if ((error = vmwrite(VMCS_VPID, vpid)) != 0) 438 goto done; 439 440 /* msr bitmap */ 441 if ((error = vmwrite(VMCS_MSR_BITMAP, msr_bitmap)) != 0) 442 goto done; 443 | |
444 /* exception bitmap */ 445 exc_bitmap = 1 << IDT_MC; 446 if ((error = vmwrite(VMCS_EXCEPTION_BITMAP, exc_bitmap)) != 0) 447 goto done; 448 449 /* link pointer */ 450 if ((error = vmwrite(VMCS_LINK_POINTER, ~0)) != 0) 451 goto done; --- 52 unchanged lines hidden (view full) --- 504 else 505 db_printf("Exit Reason: %u\n", exit & 0xffff); 506 db_printf("Qualification: %#lx\n", vmcs_exit_qualification()); 507 db_printf("Guest Linear Address: %#lx\n", 508 vmcs_read(VMCS_GUEST_LINEAR_ADDRESS)); 509 switch (exit & 0x8000ffff) { 510 case EXIT_REASON_EXCEPTION: 511 case EXIT_REASON_EXT_INTR: | 408 /* exception bitmap */ 409 exc_bitmap = 1 << IDT_MC; 410 if ((error = vmwrite(VMCS_EXCEPTION_BITMAP, exc_bitmap)) != 0) 411 goto done; 412 413 /* link pointer */ 414 if ((error = vmwrite(VMCS_LINK_POINTER, ~0)) != 0) 415 goto done; --- 52 unchanged lines hidden (view full) --- 468 else 469 db_printf("Exit Reason: %u\n", exit & 0xffff); 470 db_printf("Qualification: %#lx\n", vmcs_exit_qualification()); 471 db_printf("Guest Linear Address: %#lx\n", 472 vmcs_read(VMCS_GUEST_LINEAR_ADDRESS)); 473 switch (exit & 0x8000ffff) { 474 case EXIT_REASON_EXCEPTION: 475 case EXIT_REASON_EXT_INTR: |
512 val = vmcs_read(VMCS_EXIT_INTERRUPTION_INFO); | 476 val = vmcs_read(VMCS_EXIT_INTR_INFO); |
513 db_printf("Interrupt Type: "); 514 switch (val >> 8 & 0x7) { 515 case 0: 516 db_printf("external"); 517 break; 518 case 2: 519 db_printf("NMI"); 520 break; --- 5 unchanged lines hidden (view full) --- 526 break; 527 default: 528 db_printf("?? %lu", val >> 8 & 0x7); 529 break; 530 } 531 db_printf(" Vector: %lu", val & 0xff); 532 if (val & 0x800) 533 db_printf(" Error Code: %lx", | 477 db_printf("Interrupt Type: "); 478 switch (val >> 8 & 0x7) { 479 case 0: 480 db_printf("external"); 481 break; 482 case 2: 483 db_printf("NMI"); 484 break; --- 5 unchanged lines hidden (view full) --- 490 break; 491 default: 492 db_printf("?? %lu", val >> 8 & 0x7); 493 break; 494 } 495 db_printf(" Vector: %lu", val & 0xff); 496 if (val & 0x800) 497 db_printf(" Error Code: %lx", |
534 vmcs_read(VMCS_EXIT_INTERRUPTION_ERROR)); | 498 vmcs_read(VMCS_EXIT_INTR_ERRCODE)); |
535 db_printf("\n"); 536 break; 537 case EXIT_REASON_EPT_FAULT: 538 case EXIT_REASON_EPT_MISCONFIG: 539 db_printf("Guest Physical Address: %#lx\n", 540 vmcs_read(VMCS_GUEST_PHYSICAL_ADDRESS)); 541 break; 542 } 543 db_printf("VM-instruction error: %#lx\n", vmcs_instruction_error()); 544} 545#endif | 499 db_printf("\n"); 500 break; 501 case EXIT_REASON_EPT_FAULT: 502 case EXIT_REASON_EPT_MISCONFIG: 503 db_printf("Guest Physical Address: %#lx\n", 504 vmcs_read(VMCS_GUEST_PHYSICAL_ADDRESS)); 505 break; 506 } 507 db_printf("VM-instruction error: %#lx\n", vmcs_instruction_error()); 508} 509#endif |