diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2024-11-05 23:16:47 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2024-11-05 23:16:47 +0000 |
commit | dcb0d603d612effa3a293dc06a5535e2a46b7736 (patch) | |
tree | 67368659a5005e9e23cae8b8dc9b5bd215db740d /usr.sbin | |
parent | ed14024405c2dd9ccb9d3f95fa4a01ae2f5904f6 (diff) |
vmd(8) resets psp(4)
Use shutdown and init to reset psp(4) on vmd(8) startup. This helps
when hacking on vmd(8) and crashing it. The psp(4) reset cleans
up all remnants of dead VMs from psp(4). Otherwise one would have
to reboot the machine.
from hshoexer@; OK mlarkin@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/vmd/psp.c | 63 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.c | 9 | ||||
-rw-r--r-- | usr.sbin/vmd/vmd.h | 3 |
3 files changed, 67 insertions, 8 deletions
diff --git a/usr.sbin/vmd/psp.c b/usr.sbin/vmd/psp.c index 5705e1bb0e9..2de8cf4ac0b 100644 --- a/usr.sbin/vmd/psp.c +++ b/usr.sbin/vmd/psp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: psp.c,v 1.2 2024/09/26 01:45:13 jsg Exp $ */ +/* $OpenBSD: psp.c,v 1.3 2024/11/05 23:16:46 bluhm Exp $ */ /* * Copyright (c) 2023, 2024 Hans-Joerg Hoexer <hshoexer@genua.de> @@ -21,6 +21,8 @@ #include <dev/ic/pspvar.h> +#include <errno.h> +#include <fcntl.h> #include <string.h> #include "vmd.h" @@ -267,3 +269,62 @@ psp_guest_shutdown(uint32_t handle) return (0); } + +/* + * Initialize PSP. + */ +static int +psp_init(void) +{ + if (ioctl(env->vmd_psp_fd, PSP_IOC_INIT) < 0) { + log_warn("%s: ioctl", __func__); + return (-1); + } + + return (0); +} + +/* + * Shutdown PSP. + */ +static int +psp_shutdown(void) +{ + if (ioctl(env->vmd_psp_fd, PSP_IOC_SHUTDOWN) < 0) { + log_warn("%s: ioctl", __func__); + return (-1); + } + + return (0); +} + +/* + * Reset PSP. + * + * Shut PSP down, then re-initialize it. This clears and resets + * all active contexts. + */ +static int +psp_reset(void) +{ + int ret; + + if ((ret = psp_shutdown()) < 0 || (ret = psp_init()) < 0) + return (ret); + + return (0); +} + +void +psp_setup(void) +{ + env->vmd_psp_fd = open(PSP_NODE, O_RDWR); + if (env->vmd_psp_fd == -1) { + if (errno != ENXIO) + log_debug("%s: failed to open %s", __func__, PSP_NODE); + return; + } + + if (psp_reset() < 0) + fatalx("%s: failed to reset PSP", __func__); +} diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index 91ac69e6c0d..5ea0ad48dc1 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.161 2024/09/26 01:45:13 jsg Exp $ */ +/* $OpenBSD: vmd.c,v 1.162 2024/11/05 23:16:46 bluhm Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -842,11 +842,8 @@ main(int argc, char **argv) if (!env->vmd_noaction) proc_connect(ps); - if (env->vmd_noaction == 0 && proc_id == PROC_PARENT) { - env->vmd_psp_fd = open(PSP_NODE, O_RDWR); - if (env->vmd_psp_fd == -1) - log_debug("%s: failed to open %s", __func__, PSP_NODE); - } + if (env->vmd_noaction == 0 && proc_id == PROC_PARENT) + psp_setup(); if (vmd_configure() == -1) fatalx("configuration failed"); diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h index 8d53530198f..fee378b5d49 100644 --- a/usr.sbin/vmd/vmd.h +++ b/usr.sbin/vmd/vmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.h,v 1.128 2024/09/11 15:42:52 bluhm Exp $ */ +/* $OpenBSD: vmd.h,v 1.129 2024/11/05 23:16:46 bluhm Exp $ */ /* * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> @@ -595,6 +595,7 @@ int psp_launch_measure(uint32_t); int psp_launch_finish(uint32_t); int psp_activate(uint32_t, uint32_t); int psp_guest_shutdown(uint32_t); +void psp_setup(void); /* sev.c */ int sev_init(struct vmd_vm *); |