vmm: don't free unallocated memory

If vmx or svm is disabled in BIOS or the device isn't supported by vmm,
modinit won't allocate these state save areas. As kmem_free panics when
passing a NULL pointer to it, loading the vmm kernel module causes a
panic too.

PR:			271251
Reviewed by:		markj
Fixes:			74ac712f72 ("vmm: Dynamically allocate a couple of per-CPU state save areas")
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D39974
This commit is contained in:
Corvin Köhne 2023-05-05 08:36:20 +02:00
parent 66659955da
commit b10e100d16
No known key found for this signature in database
GPG Key ID: D854DA56315E026A
2 changed files with 7 additions and 2 deletions

View File

@ -166,7 +166,10 @@ svm_modcleanup(void)
{
smp_rendezvous(NULL, svm_disable, NULL, NULL);
kmem_free(hsave, (mp_maxid + 1) * PAGE_SIZE);
if (hsave != NULL)
kmem_free(hsave, (mp_maxid + 1) * PAGE_SIZE);
return (0);
}

View File

@ -619,7 +619,9 @@ vmx_modcleanup(void)
nmi_flush_l1d_sw = 0;
smp_rendezvous(NULL, vmx_disable, NULL, NULL);
kmem_free(vmxon_region, (mp_maxid + 1) * PAGE_SIZE);
if (vmxon_region != NULL)
kmem_free(vmxon_region, (mp_maxid + 1) * PAGE_SIZE);
return (0);
}