Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177686419
D61376.1795031836.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
D61376.1795031836.diff
View Options
diff --git a/usr.sbin/bhyve/aarch64/vmexit.c b/usr.sbin/bhyve/aarch64/vmexit.c
--- a/usr.sbin/bhyve/aarch64/vmexit.c
+++ b/usr.sbin/bhyve/aarch64/vmexit.c
@@ -81,6 +81,7 @@
return (VMEXIT_CONTINUE);
fail:
+ vm_check_destroyed(vcpu);
fprintf(stderr, "Failed to emulate instruction ");
FPRINTLN(stderr, "at 0x%lx", vme->pc);
return (VMEXIT_ABORT);
diff --git a/usr.sbin/bhyve/amd64/inout.c b/usr.sbin/bhyve/amd64/inout.c
--- a/usr.sbin/bhyve/amd64/inout.c
+++ b/usr.sbin/bhyve/amd64/inout.c
@@ -199,6 +199,8 @@
/* Update index register */
error = vie_update_register(vcpu, idxreg, index, addrsize);
+ if (error != 0)
+ vm_check_destroyed(vcpu);
assert(error == 0);
/*
@@ -208,12 +210,16 @@
if (rep) {
error = vie_update_register(vcpu, VM_REG_GUEST_RCX,
count, addrsize);
+ if (error != 0)
+ vm_check_destroyed(vcpu);
assert(error == 0);
}
/* Restart the instruction if more iterations remain */
if (retval == 0 && count != 0) {
error = vm_restart_instruction(vcpu);
+ if (error != 0)
+ vm_check_destroyed(vcpu);
assert(error == 0);
}
} else {
@@ -225,6 +231,8 @@
eax |= val & vie_size2mask(bytes);
error = vm_set_register(vcpu, VM_REG_GUEST_RAX,
eax);
+ if (error != 0)
+ vm_check_destroyed(vcpu);
assert(error == 0);
}
}
diff --git a/usr.sbin/bhyve/amd64/vmexit.c b/usr.sbin/bhyve/amd64/vmexit.c
--- a/usr.sbin/bhyve/amd64/vmexit.c
+++ b/usr.sbin/bhyve/amd64/vmexit.c
@@ -66,6 +66,8 @@
error = vm_inject_exception(vcpu, vector, errcode_valid, errcode,
restart_instruction);
+ if (error != 0)
+ vm_check_destroyed(vcpu);
assert(error == 0);
}
@@ -83,6 +85,7 @@
error = emulate_inout(ctx, vcpu, vme);
if (error) {
+ vm_check_destroyed(vcpu);
EPRINTLN("Unhandled %s%c 0x%04x at 0x%lx",
in ? "in" : "out",
bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'),
@@ -120,10 +123,14 @@
eax = val;
error = vm_set_register(vcpu, VM_REG_GUEST_RAX, eax);
+ if (error != 0)
+ vm_check_destroyed(vcpu);
assert(error == 0);
edx = val >> 32;
error = vm_set_register(vcpu, VM_REG_GUEST_RDX, edx);
+ if (error != 0)
+ vm_check_destroyed(vcpu);
assert(error == 0);
return (VMEXIT_CONTINUE);
@@ -387,6 +394,7 @@
return (VMEXIT_CONTINUE);
fail:
+ vm_check_destroyed(vcpu);
fprintf(stderr, "Failed to emulate instruction sequence [ ");
for (i = 0; i < vie->num_valid; i++)
fprintf(stderr, "%02x", vie->inst[i]);
diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h
--- a/usr.sbin/bhyve/bhyverun.h
+++ b/usr.sbin/bhyve/bhyverun.h
@@ -87,6 +87,7 @@
void bhyve_cfg_warn(const char *old, const char *new);
void bhyve_init_vcpu(struct vcpu *vcpu);
+void vm_check_destroyed(struct vcpu *vcpu);
void bhyve_start_vcpu(struct vcpu *vcpu, bool bsp);
int bhyve_init_platform(struct vmctx *ctx, struct vcpu *bsp);
int bhyve_init_platform_late(struct vmctx *ctx, struct vcpu *bsp);
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -724,6 +724,24 @@
EPRINTLN("vm_run error %d, errno %d", error, errno);
}
+/*
+ * A vCPU thread handling an exit finds that a call on the VM failed. If the
+ * VM was destroyed under it (bhyvectl --destroy), every call fails: ENXIO
+ * while the destroy waits for the vCPU threads, ENOTTY once the device is
+ * gone. End as vm_loop() does when vm_run() finds the VM destroyed, instead
+ * of asserting or reporting an emulation failure and aborting. On a VM that
+ * still exists this returns and the caller handles the failure as before.
+ */
+void
+vm_check_destroyed(struct vcpu *vcpu)
+{
+ int tmp;
+
+ if (vm_get_capability(vcpu, VM_CAP_UNRESTRICTED_GUEST, &tmp) != 0 &&
+ (errno == ENXIO || errno == ENOTTY))
+ exit(BHYVE_EXIT_ERROR);
+}
+
static int
num_vcpus_allowed(struct vmctx *ctx, struct vcpu *vcpu)
{
diff --git a/usr.sbin/bhyve/riscv/vmexit.c b/usr.sbin/bhyve/riscv/vmexit.c
--- a/usr.sbin/bhyve/riscv/vmexit.c
+++ b/usr.sbin/bhyve/riscv/vmexit.c
@@ -95,6 +95,7 @@
return (VMEXIT_CONTINUE);
fail:
+ vm_check_destroyed(vcpu);
fprintf(stderr, "Failed to emulate instruction ");
FPRINTLN(stderr, "at 0x%lx", vme->pc);
return (VMEXIT_ABORT);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 18, 7:57 PM (1 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41821487
Default Alt Text
D61376.1795031836.diff (4 KB)
Attached To
Mode
D61376: bhyve: Do not abort when the VM is destroyed during an exit
Attached
Detach File
Event Timeline