summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravg <avg@FreeBSD.org>2018-02-04 13:53:45 +0000
committeravg <avg@FreeBSD.org>2018-02-04 13:53:45 +0000
commit98ed3092864a484e3ad9044f4fb42f83745bc0d0 (patch)
tree9ced4bd8525cfdf448e796f8a767e0c32287a68f
parent3329c8415a0f819cd1472a3bfff81b28618084c4 (diff)
downloadFreeBSD-src-98ed3092864a484e3ad9044f4fb42f83745bc0d0.zip
FreeBSD-src-98ed3092864a484e3ad9044f4fb42f83745bc0d0.tar.gz
MFC r327726: vmm/svm: contigmalloc of the whole svm_softc is excessive
-rw-r--r--sys/amd64/vmm/amd/svm.c23
-rw-r--r--sys/amd64/vmm/amd/svm_softc.h6
2 files changed, 21 insertions, 8 deletions
diff --git a/sys/amd64/vmm/amd/svm.c b/sys/amd64/vmm/amd/svm.c
index 5aa17d0..fa5b579 100644
--- a/sys/amd64/vmm/amd/svm.c
+++ b/sys/amd64/vmm/amd/svm.c
@@ -517,15 +517,26 @@ svm_vminit(struct vm *vm, pmap_t pmap)
vm_paddr_t msrpm_pa, iopm_pa, pml4_pa;
int i;
- svm_sc = contigmalloc(sizeof (*svm_sc), M_SVM, M_WAITOK | M_ZERO,
- 0, ~(vm_paddr_t)0, PAGE_SIZE, 0);
+ svm_sc = malloc(sizeof (*svm_sc), M_SVM, M_WAITOK | M_ZERO);
+ if (((uintptr_t)svm_sc & PAGE_MASK) != 0)
+ panic("malloc of svm_softc not aligned on page boundary");
+
+ svm_sc->msr_bitmap = contigmalloc(SVM_MSR_BITMAP_SIZE, M_SVM,
+ M_WAITOK, 0, ~(vm_paddr_t)0, PAGE_SIZE, 0);
+ if (svm_sc->msr_bitmap == NULL)
+ panic("contigmalloc of SVM MSR bitmap failed");
+ svm_sc->iopm_bitmap = contigmalloc(SVM_IO_BITMAP_SIZE, M_SVM,
+ M_WAITOK, 0, ~(vm_paddr_t)0, PAGE_SIZE, 0);
+ if (svm_sc->iopm_bitmap == NULL)
+ panic("contigmalloc of SVM IO bitmap failed");
+
svm_sc->vm = vm;
svm_sc->nptp = (vm_offset_t)vtophys(pmap->pm_pml4);
/*
* Intercept read and write accesses to all MSRs.
*/
- memset(svm_sc->msr_bitmap, 0xFF, sizeof(svm_sc->msr_bitmap));
+ memset(svm_sc->msr_bitmap, 0xFF, SVM_MSR_BITMAP_SIZE);
/*
* Access to the following MSRs is redirected to the VMCB when the
@@ -553,7 +564,7 @@ svm_vminit(struct vm *vm, pmap_t pmap)
svm_msr_rd_ok(svm_sc->msr_bitmap, MSR_EFER);
/* Intercept access to all I/O ports. */
- memset(svm_sc->iopm_bitmap, 0xFF, sizeof(svm_sc->iopm_bitmap));
+ memset(svm_sc->iopm_bitmap, 0xFF, SVM_IO_BITMAP_SIZE);
iopm_pa = vtophys(svm_sc->iopm_bitmap);
msrpm_pa = vtophys(svm_sc->msr_bitmap);
@@ -2043,7 +2054,9 @@ svm_vmcleanup(void *arg)
{
struct svm_softc *sc = arg;
- contigfree(sc, sizeof (*sc), M_SVM);
+ contigfree(sc->iopm_bitmap, SVM_IO_BITMAP_SIZE, M_SVM);
+ contigfree(sc->msr_bitmap, SVM_MSR_BITMAP_SIZE, M_SVM);
+ free(sc, M_SVM);
}
static register_t *
diff --git a/sys/amd64/vmm/amd/svm_softc.h b/sys/amd64/vmm/amd/svm_softc.h
index de0c3f7..9377bf5 100644
--- a/sys/amd64/vmm/amd/svm_softc.h
+++ b/sys/amd64/vmm/amd/svm_softc.h
@@ -56,13 +56,13 @@ struct svm_vcpu {
* SVM softc, one per virtual machine.
*/
struct svm_softc {
- uint8_t iopm_bitmap[SVM_IO_BITMAP_SIZE]; /* shared by all vcpus */
- uint8_t msr_bitmap[SVM_MSR_BITMAP_SIZE]; /* shared by all vcpus */
uint8_t apic_page[VM_MAXCPU][PAGE_SIZE];
struct svm_vcpu vcpu[VM_MAXCPU];
vm_offset_t nptp; /* nested page table */
+ uint8_t *iopm_bitmap; /* shared by all vcpus */
+ uint8_t *msr_bitmap; /* shared by all vcpus */
struct vm *vm;
-} __aligned(PAGE_SIZE);
+};
CTASSERT((offsetof(struct svm_softc, nptp) & PAGE_MASK) == 0);
OpenPOWER on IntegriCloud