Download raw body.
AMD SEV 2/5: ccp(4): provide ioctl for guestshutdown
On Wed, Aug 28, 2024 at 03:24:18PM +0200, Hans-Jörg Höxer wrote:
>
> this diff provides a new ioctl for simplified guest shutdown. Will be
> used by vmd(8).
diff updated wrt pledge_ioctl_psp().
--------------------------------------------------------------------------
commit 35fbee6e7ab6f5a58502c51e800d149bbe8576af
Author: Hans-Joerg Hoexer <hshoexer@genua.de>
Date: Tue Aug 13 17:36:21 2024 +0200
ccp(4): provide ioctl for guestshutdown
To shutdown a SEV-enabled guest, we have first to deactivate the
guest context in ccp(4), then decommission the guest context. To
simplify guest shutdown combine these two operations in a single
ioctl. As this ioctl does not directly map to a single ccp command
use a high number for this ioctl. There will be more ioctls like
this one.
diff --git a/sys/dev/ic/ccp.c b/sys/dev/ic/ccp.c
index 17e96277c26..24f0680f03a 100644
--- a/sys/dev/ic/ccp.c
+++ b/sys/dev/ic/ccp.c
@@ -564,6 +564,29 @@ psp_deactivate(struct psp_deactivate *udeact)
return (0);
}
+int
+psp_guest_shutdown(struct psp_guest_shutdown *ugshutdown)
+{
+ struct psp_deactivate deact;
+ struct psp_decommission decom;
+ int ret;
+
+ bzero(&deact, sizeof(deact));
+ deact.handle = ugshutdown->handle;
+ if ((ret = psp_deactivate(&deact)) != 0)
+ return (ret);
+
+ if ((ret = psp_df_flush()) != 0)
+ return (ret);
+
+ bzero(&decom, sizeof(decom));
+ decom.handle = ugshutdown->handle;
+ if ((ret = psp_decommission(&decom)) != 0)
+ return (ret);
+
+ return (0);
+}
+
int
psp_snp_get_pstatus(struct psp_snp_platform_status *ustatus)
{
@@ -642,6 +665,9 @@ pspioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
case PSP_IOC_DEACTIVATE:
ret = psp_deactivate((struct psp_deactivate *)data);
break;
+ case PSP_IOC_GUEST_SHUTDOWN:
+ ret = psp_guest_shutdown((struct psp_guest_shutdown *)data);
+ break;
case PSP_IOC_SNP_GET_PSTATUS:
ret =
psp_snp_get_pstatus((struct psp_snp_platform_status *)data);
@@ -668,6 +694,7 @@ pledge_ioctl_psp(struct proc *p, long com)
case PSP_IOC_LAUNCH_MEASURE:
case PSP_IOC_LAUNCH_FINISH:
case PSP_IOC_ACTIVATE:
+ case PSP_IOC_GUEST_SHUTDOWN:
return (0);
default:
return (pledge_fail(p, EPERM, PLEDGE_VMM));
diff --git a/sys/dev/ic/ccpvar.h b/sys/dev/ic/ccpvar.h
index e8e0514610d..9ccf96febf1 100644
--- a/sys/dev/ic/ccpvar.h
+++ b/sys/dev/ic/ccpvar.h
@@ -243,6 +243,11 @@ struct psp_init {
} __packed;
+struct psp_guest_shutdown {
+ /* Input parameter for PSP_CMD_GUEST_SHUTDOWN */
+ uint32_t handle;
+} __packed;
+
/* Selection of PSP commands of the SEV-SNP ABI Version 1.55 */
#define PSP_CMD_SNP_PLATFORMSTATUS 0x81
@@ -272,6 +277,7 @@ struct psp_snp_platform_status {
#define PSP_IOC_ACTIVATE _IOW('P', 9, struct psp_activate)
#define PSP_IOC_DEACTIVATE _IOW('P', 10, struct psp_deactivate)
#define PSP_IOC_SNP_GET_PSTATUS _IOR('P', 11, struct psp_snp_platform_status)
+#define PSP_IOC_GUEST_SHUTDOWN _IOW('P', 255, struct psp_guest_shutdown)
#endif /* __amd64__ */
#ifdef _KERNEL
AMD SEV 2/5: ccp(4): provide ioctl for guestshutdown