Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F153288908
D32961.id126028.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D32961.id126028.diff
View Options
diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8
--- a/usr.sbin/bhyve/bhyve.8
+++ b/usr.sbin/bhyve/bhyve.8
@@ -217,6 +217,8 @@
.Cm com1 , com2 , com3 ,
and
.Cm com4 ,
+the TPM module
+.Cm tpm ,
the boot ROM device
.Cm bootrom ,
the
@@ -540,6 +542,23 @@
Use the host TTY device for serial port I/O.
.El
.Pp
+TPM device backends:
+.Bl -tag -width 10n
+.It Ar type Ns \&, Ns Ar path Ns Op Cm \&, Ns Ar tpm-device-options
+Emulate a TPM device.
+.El
+.Pp
+The
+.Ar tpm-device-options
+are:
+.Bl -tag -width 10n
+.It Cm version= Ns Ar version
+Version of the TPM device according to the TCG specification.
+Defaults to
+.Cm 2.0
+.El
+.El
+.Pp
Boot ROM device backends:
.Bl -tag -width 10n
.It Ar romfile Ns Op Cm \&, Ns Ar varfile
@@ -625,6 +644,26 @@
loader variable as described in
.Xr vmm 4 .
.Pp
+TPM devices:
+.Bl -tag -width 10n
+.It Ns Ar type
+Specifies the type of the TPM device.
+.Pp
+Supported types:
+.Bl -tag -width 10n
+.It Cm passthru
+.El
+.It Cm version= Ns Ar version
+The
+.Ar version
+of the emulated TPM device according to the TCG specification.
+.Pp
+Supported versions:
+.Bl -tag -width 10n
+.It Cm 2.0
+.El
+.El
+.Pp
Virtio console device backends:
.Bl -bullet
.Sm off
diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5
--- a/usr.sbin/bhyve/bhyve_config.5
+++ b/usr.sbin/bhyve/bhyve_config.5
@@ -139,6 +139,15 @@
This value only works when loaded with UEFI mode for VNC, and
used a VNC client that don't support QEMU Extended Key Event
Message (e.g. TightVNC).
+.It Va tpm.path Ta string Ta Ta
+Path to the host TPM device.
+This is typically /dev/tpm0.
+.It Va tpm.type Ta string Ta Ta
+Type of the TPM device passed to the guest.
+Currently, only "passthru" is supported.
+.It Va tpm.version Ta string Ta 2.0 Ta
+Version of the TPM device according to the TCG specification.
+Currently, only version 2.0 is supported.
.It Va rtc.use_localtime Ta bool Ta true Ta
The real time clock uses the local time of the host.
If this is set to false, the real time clock uses UTC.
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
@@ -107,6 +107,7 @@
#ifdef BHYVE_SNAPSHOT
#include "snapshot.h"
#endif
+#include "tpm_device.h"
#include "xmsr.h"
#include "spinup_ap.h"
#include "rtc.h"
@@ -1210,6 +1211,21 @@
set_config_value("lpc.fwcfg", "bhyve");
}
+static int
+init_devices(struct vmctx *ctx) {
+ int error;
+
+ error = init_pci(ctx);
+ if (error != 0)
+ return (error);
+
+ error = init_tpm(ctx);
+ if (error != 0)
+ return (error);
+
+ return (0);
+}
+
int
main(int argc, char *argv[])
{
@@ -1474,7 +1490,7 @@
/*
* Exit if a device emulation finds an error in its initialization
*/
- if (init_pci(ctx) != 0) {
+ if (init_devices(ctx) != 0) {
perror("device emulation initialization error");
exit(4);
}
diff --git a/usr.sbin/bhyve/pci_lpc.c b/usr.sbin/bhyve/pci_lpc.c
--- a/usr.sbin/bhyve/pci_lpc.c
+++ b/usr.sbin/bhyve/pci_lpc.c
@@ -53,6 +53,7 @@
#include "pci_lpc.h"
#include "pci_passthru.h"
#include "pctestdev.h"
+#include "tpm_device.h"
#include "uart_emul.h"
#define IO_ICU1 0x20
@@ -97,7 +98,7 @@
{
int unit, error;
char *str, *cpy, *lpcdev, *node_name;
- const char *romfile, *varfile;
+ const char *romfile, *varfile, *tpm_type, *tpm_path;
error = -1;
str = cpy = strdup(opts);
@@ -128,6 +129,27 @@
error = 0;
goto done;
}
+ if (strcasecmp(lpcdev, "tpm") == 0) {
+ nvlist_t *nvl = create_config_node("tpm");
+
+ tpm_type = strsep(&str, ",");
+ if (tpm_type == NULL) {
+ errx(4, "invalid tpm type \"%s\"", opts);
+ }
+ set_config_value_node(nvl, "type", tpm_type);
+
+ tpm_path = strsep(&str, ",");
+ if (tpm_path == NULL) {
+ errx(4, "invalid tpm path \"%s\"", opts);
+ }
+ set_config_value_node(nvl, "path", tpm_path);
+
+ pci_parse_legacy_config(find_config_node("tpm"), str);
+
+ set_config_value_node_if_unset(nvl, "version", "2.0");
+ error = 0;
+ goto done;
+ }
for (unit = 0; unit < LPC_UART_NUM; unit++) {
if (strcasecmp(lpcdev, lpc_uart_names[unit]) == 0) {
asprintf(&node_name, "lpc.%s.path",
@@ -161,6 +183,7 @@
printf("bootrom\n");
for (i = 0; i < LPC_UART_NUM; i++)
printf("%s\n", lpc_uart_names[i]);
+ printf("tpm\n");
printf("%s\n", pctestdev_getname());
}
diff --git a/usr.sbin/bhyve/tpm_device.h b/usr.sbin/bhyve/tpm_device.h
--- a/usr.sbin/bhyve/tpm_device.h
+++ b/usr.sbin/bhyve/tpm_device.h
@@ -16,3 +16,5 @@
int tpm_device_create(struct tpm_device **new_dev, struct vmctx *vm_ctx,
nvlist_t *nvl);
void tpm_device_destroy(struct tpm_device *dev);
+
+int init_tpm(struct vmctx *ctx);
diff --git a/usr.sbin/bhyve/tpm_device.c b/usr.sbin/bhyve/tpm_device.c
--- a/usr.sbin/bhyve/tpm_device.c
+++ b/usr.sbin/bhyve/tpm_device.c
@@ -232,3 +232,25 @@
return (error);
}
+
+static struct tpm_device *lpc_tpm;
+
+int
+init_tpm(struct vmctx *ctx)
+{
+ nvlist_t *nvl;
+ int error;
+
+ nvl = find_config_node("tpm");
+ if (nvl == NULL)
+ return (0);
+
+ error = tpm_device_create(&lpc_tpm, ctx, nvl);
+ if (error) {
+ warnx("%s: unable to create a TPM device (%d)",
+ __func__, error);
+ return (error);
+ }
+
+ return (0);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 21, 6:48 AM (39 m, 51 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31895021
Default Alt Text
D32961.id126028.diff (5 KB)
Attached To
Mode
D32961: bhyve: enable TPM2 passthrough
Attached
Detach File
Event Timeline
Log In to Comment