Skip to content

Commit

Permalink
[minimega] Add virtual TPM support (#1510)
Browse files Browse the repository at this point in the history
* initial tpm commit

* fixing command line args

* collapse tpm args to one; get to print in vm info

---------

Co-authored-by: root <[email protected]>
Co-authored-by: jacdavi <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2023
1 parent b5055e9 commit 1964a67
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/minimega/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ type KVMConfig struct {
// Default: true
UsbUseXHCI bool

// If specified, will configure VM to use virtual Trusted Platform Module (TPM)
// socket at the path provided
TpmSocketPath string

// Add additional arguments to be passed to the QEMU instance. For example:
//
// vm config qemu-append -serial tcp:localhost:4001
Expand Down Expand Up @@ -542,6 +546,7 @@ func (vm *KVMConfig) String() string {
fmt.Fprintf(w, "Sockets:\t%v\n", vm.Sockets)
fmt.Fprintf(w, "VGA:\t%v\n", vm.Vga)
fmt.Fprintf(w, "Usb Use XHCI:\t%v\n", vm.UsbUseXHCI)
fmt.Fprintf(w, "TPM Socket: \t%v\n", vm.TpmSocketPath)
w.Flush()
fmt.Fprintln(&o)
return o.String()
Expand Down Expand Up @@ -1316,6 +1321,14 @@ func (vm VMConfig) qemuArgs(id int, vmPath string) []string {
// this allows absolute pointers in vnc, and works great on android vms
args = append(args, "-device", "usb-tablet,bus=usb-bus.0")

if vm.TpmSocketPath != "" {
args = append(args, "-chardev")
args = append(args, fmt.Sprintf("socket,id=chrtpm,path=%v,nowait", vm.TpmSocketPath))
args = append(args, "-tpmdev")
args = append(args, "emulator,id=tpm0,chardev=chrtpm")
args = append(args, "-device")
args = append(args, "tpm-tis,tpmdev=tpm0")
}
// this is non-virtio serial ports
// for virtio-serial, look below near the net code
for i := uint64(0); i < vm.SerialPorts; i++ {
Expand Down
1 change: 1 addition & 0 deletions cmd/minimega/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var vmInfo = []string{
// kvm fields
"vcpus", "disks", "snapshot", "initrd", "kernel", "cdrom", "migrate",
"append", "serial-ports", "virtio-ports", "vnc_port", "usb-use-xhci",
"tpm-socket",
// container fields
"filesystem", "hostname", "init", "preinit", "fifo", "volume",
"console_port",
Expand Down
1 change: 1 addition & 0 deletions cmd/minimega/vm_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Additional fields are available for KVM-based VMs:
- virtio-serial : number of virtio ports
- vnc_port : port for VNC shim
- usb-use-xhci : usb controller (true = xhci; false = ehci)
- tpm-socket : path of emulated tpm socket
Additional fields are available for container-based VMs:
Expand Down
34 changes: 34 additions & 0 deletions cmd/minimega/vmconfiger_cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1964a67

Please sign in to comment.