Index | Thread | Search

From:
Hans-Jörg Höxer <hshoexer@genua.de>
Subject:
vmd(8): Log psp(4) firmware version
To:
<tech@openbsd.org>
Date:
Mon, 4 Nov 2024 16:00:48 +0100

Download raw body.

Thread
  • Hans-Jörg Höxer:

    vmd(8): Log psp(4) firmware version

Hi,

as we now automatically load the SEV PSP firmware, let vmd(8) log the
firmware version.  In dmesg we get the firmware ROM version, vmd(8)
then shows the firmware version actually in use.

Take care,
HJ.

--------------------------------------------------------------------------
commit caf777510259b6640594a9190ae950d68c69a282
Author: Hans-Joerg Hoexer <hshoexer@genua.de>
Date:   Tue Oct 1 19:00:52 2024 +0200

    vmd(8): Log psp(4) firmware version
    
    On vmd(8) startup, log the psp(4) firmware version.

diff --git a/usr.sbin/vmd/psp.c b/usr.sbin/vmd/psp.c
index e0f93a0ee77..adc53e73310 100644
--- a/usr.sbin/vmd/psp.c
+++ b/usr.sbin/vmd/psp.c
@@ -43,7 +43,8 @@ extern struct vmd_vm	*current_vm;
  * Retrieve platform state.
  */
 int
-psp_get_pstate(uint16_t *state)
+psp_get_pstate(uint16_t *state, uint8_t *major, uint8_t *minor,
+    uint8_t *build, uint8_t *seves)
 {
 	struct psp_platform_status pst;
 
@@ -54,6 +55,14 @@ psp_get_pstate(uint16_t *state)
 
 	if (state)
 		*state = pst.state;
+	if (major)
+		*major = pst.api_major;
+	if (minor)
+		*minor = pst.api_minor;
+	if (build)
+		*build = (pst.cfges_build >> 24) & 0xff;
+	if (seves)
+		*seves = pst.cfges_build & 0x1;
 
 	return (0);
 }
@@ -322,6 +331,8 @@ psp_reset(void)
 void
 psp_setup(void)
 {
+	uint8_t	major, minor, build;
+
 	env->vmd_psp_fd = open(PSP_NODE, O_RDWR);
 	if (env->vmd_psp_fd == -1) {
 		if (errno != ENXIO)
@@ -331,4 +342,8 @@ psp_setup(void)
 
 	if (psp_reset() < 0)
 		fatalx("%s: failed to reset PSP", __func__);
+	if (psp_get_pstate(NULL, &major, &minor, &build, NULL) < 0)
+		fatalx("%s: failed to get platform state", __func__);
+	log_info("PSP version: major %hhd minor %hhd build %hhd",
+	    major, minor, build);
 }
diff --git a/usr.sbin/vmd/sev.c b/usr.sbin/vmd/sev.c
index 89272c8b3ad..0924054bed9 100644
--- a/usr.sbin/vmd/sev.c
+++ b/usr.sbin/vmd/sev.c
@@ -49,7 +49,7 @@ sev_init(struct vmd_vm *vm)
 	if (!vcp->vcp_sev)
 		return (0);
 
-	if (psp_get_pstate(&pstate)) {
+	if (psp_get_pstate(&pstate, NULL, NULL, NULL, NULL)) {
 		log_warnx("%s: failed to get platform state", __func__);
 		return (-1);
 	}
diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h
index d39248aa654..9b8d1497f0e 100644
--- a/usr.sbin/vmd/vmd.h
+++ b/usr.sbin/vmd/vmd.h
@@ -582,7 +582,7 @@ __dead void vionet_main(int, int);
 __dead void vioblk_main(int, int);
 
 /* psp.c */
-int	 psp_get_pstate(uint16_t *);
+int	 psp_get_pstate(uint16_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *);
 int	 psp_df_flush(void);
 int	 psp_get_gstate(uint32_t, uint32_t *, uint32_t *, uint8_t *);
 int	 psp_launch_start(uint32_t *);