MCPcopy Create free account
hub / github.com/F-Stack/f-stack / svm_init

Function svm_init

freebsd/amd64/vmm/amd/svm.c:554–625  ·  view source on GitHub ↗

* Initialize a virtual machine. */

Source from the content-addressed store, hash-verified

552 * Initialize a virtual machine.
553 */
554static void *
555svm_init(struct vm *vm, pmap_t pmap)
556{
557 struct svm_softc *svm_sc;
558 struct svm_vcpu *vcpu;
559 vm_paddr_t msrpm_pa, iopm_pa, pml4_pa;
560 int i;
561 uint16_t maxcpus;
562
563 svm_sc = malloc(sizeof (*svm_sc), M_SVM, M_WAITOK | M_ZERO);
564 if (((uintptr_t)svm_sc & PAGE_MASK) != 0)
565 panic("malloc of svm_softc not aligned on page boundary");
566
567 svm_sc->msr_bitmap = contigmalloc(SVM_MSR_BITMAP_SIZE, M_SVM,
568 M_WAITOK, 0, ~(vm_paddr_t)0, PAGE_SIZE, 0);
569 if (svm_sc->msr_bitmap == NULL)
570 panic("contigmalloc of SVM MSR bitmap failed");
571 svm_sc->iopm_bitmap = contigmalloc(SVM_IO_BITMAP_SIZE, M_SVM,
572 M_WAITOK, 0, ~(vm_paddr_t)0, PAGE_SIZE, 0);
573 if (svm_sc->iopm_bitmap == NULL)
574 panic("contigmalloc of SVM IO bitmap failed");
575
576 svm_sc->vm = vm;
577 svm_sc->nptp = (vm_offset_t)vtophys(pmap->pm_pmltop);
578
579 /*
580 * Intercept read and write accesses to all MSRs.
581 */
582 memset(svm_sc->msr_bitmap, 0xFF, SVM_MSR_BITMAP_SIZE);
583
584 /*
585 * Access to the following MSRs is redirected to the VMCB when the
586 * guest is executing. Therefore it is safe to allow the guest to
587 * read/write these MSRs directly without hypervisor involvement.
588 */
589 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_GSBASE);
590 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_FSBASE);
591 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_KGSBASE);
592
593 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_STAR);
594 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_LSTAR);
595 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_CSTAR);
596 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_SF_MASK);
597 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_SYSENTER_CS_MSR);
598 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_SYSENTER_ESP_MSR);
599 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_SYSENTER_EIP_MSR);
600 svm_msr_rw_ok(svm_sc->msr_bitmap, MSR_PAT);
601
602 svm_msr_rd_ok(svm_sc->msr_bitmap, MSR_TSC);
603
604 /*
605 * Intercept writes to make sure that the EFER_SVM bit is not cleared.
606 */
607 svm_msr_rd_ok(svm_sc->msr_bitmap, MSR_EFER);
608
609 /* Intercept access to all I/O ports. */
610 memset(svm_sc->iopm_bitmap, 0xFF, SVM_IO_BITMAP_SIZE);
611

Callers

nothing calls this directly

Calls 10

mallocFunction · 0.85
contigmallocFunction · 0.85
memsetFunction · 0.85
svm_msr_rw_okFunction · 0.85
svm_msr_rd_okFunction · 0.85
vm_get_maxcpusFunction · 0.85
svm_get_vcpuFunction · 0.85
vmcb_initFunction · 0.85
svm_msr_guest_initFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected