Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmm: Correctly suspend and resume the vmm driver. #1419

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sys/amd64/acpica/acpi_wakeup.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)

intr_suspend();

if (vmm_suspend_p != NULL)
vmm_suspend_p();

pcb = &susppcbs[0]->sp_pcb;
if (savectx(pcb)) {
fpususpend(susppcbs[0]->sp_fpususpend);
Expand Down
1 change: 1 addition & 0 deletions sys/amd64/amd64/machdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ struct mem_range_softc mem_range_softc;

struct mtx dt_lock; /* lock for GDT and LDT */

void (*vmm_suspend_p)(void);
void (*vmm_resume_p)(void);

bool efi_boot;
Expand Down
3 changes: 2 additions & 1 deletion sys/amd64/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ extern char btext[];
extern char _end[];
extern char etext[];

/* Resume hook for VMM. */
/* Suspend and resume hook for VMM. */
extern void (*vmm_suspend_p)(void);
extern void (*vmm_resume_p)(void);

void cpu_halt(void);
Expand Down
2 changes: 2 additions & 0 deletions sys/amd64/include/vmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ struct vm_eventinfo {

typedef int (*vmm_init_func_t)(int ipinum);
typedef int (*vmm_cleanup_func_t)(void);
typedef void (*vmm_suspend_func_t)(void);
typedef void (*vmm_resume_func_t)(void);
typedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap);
typedef int (*vmi_run_func_t)(void *vcpui, register_t rip,
Expand All @@ -194,6 +195,7 @@ typedef int (*vmi_restore_tsc_t)(void *vcpui, uint64_t now);
struct vmm_ops {
vmm_init_func_t modinit; /* module wide initialization */
vmm_cleanup_func_t modcleanup;
vmm_resume_func_t modsuspend;
vmm_resume_func_t modresume;

vmi_init_func_t init; /* vm-specific initialization */
Expand Down
9 changes: 8 additions & 1 deletion sys/amd64/vmm/amd/svm.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,19 @@ svm_modinit(int ipinum)
return (0);
}

static void
svm_modsuspend(void)
{

return;
}

static void
svm_modresume(void)
{

svm_enable(NULL);
}
}

#ifdef BHYVE_SNAPSHOT
void
Expand Down
11 changes: 10 additions & 1 deletion sys/amd64/vmm/intel/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,20 @@ vmx_enable(void *arg __unused)
vmxon_enabled[curcpu] = 1;
}

static void
vmx_modsuspend(void)
{

if (vmxon_enabled[curcpu])
vmx_disable(NULL);
}

static void
vmx_modresume(void)
{

if (vmxon_enabled[curcpu])
vmxon(&vmxon_region[curcpu * PAGE_SIZE]);
vmx_enable(NULL);
}

static int
Expand Down Expand Up @@ -4270,6 +4278,7 @@ vmx_restore_tsc(void *vcpui, uint64_t offset)
const struct vmm_ops vmm_ops_intel = {
.modinit = vmx_modinit,
.modcleanup = vmx_modcleanup,
.modsuspend = vmx_modsuspend,
.modresume = vmx_modresume,
.init = vmx_init,
.run = vmx_run,
Expand Down
1 change: 1 addition & 0 deletions sys/amd64/vmm/vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ vmmops_panic(void)

DEFINE_VMMOPS_IFUNC(int, modinit, (int ipinum))
DEFINE_VMMOPS_IFUNC(int, modcleanup, (void))
DEFINE_VMMOPS_IFUNC(void, modsuspend, (void))
DEFINE_VMMOPS_IFUNC(void, modresume, (void))
DEFINE_VMMOPS_IFUNC(void *, init, (struct vm *vm, struct pmap *pmap))
DEFINE_VMMOPS_IFUNC(int, run, (void *vcpui, register_t rip, struct pmap *pmap,
Expand Down
5 changes: 5 additions & 0 deletions sys/x86/x86/mp_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,11 @@ cpususpend_handler(void)

mtx_assert(&smp_ipi_mtx, MA_NOTOWNED);

#ifdef __amd64__
if (vmm_suspend_p)
vmm_suspend_p();
#endif

cpu = PCPU_GET(cpuid);

#ifdef XENHVM
Expand Down
Loading