<p>
The TPM device enables a QEMU guest to have access to TPM
functionality. The TPM device may either be a TPM 1.2 or
- a TPM 2.
+ a TPM 2.0.
</p>
<p>
The TPM passthrough device type provides access to the host's TPM
...
<devices>
<tpm model='tpm-tis'>
- <backend type='emulator'>
+ <backend type='emulator' version='2.0'>
</backend>
</tpm>
</devices>
<code>tpm-tis</code> will automatically be chosen.
<span class="since">Since 4.4.0</span>, another available choice
is the <code>tpm-crb</code>, which should only be used when the
- backend device is a TPM 2.
+ backend device is a TPM 2.0.
</p>
</dd>
<dt><code>backend</code></dt>
</dd>
</dl>
</dd>
+ <dt><code>version</code></dt>
+ <dd>
+ <p>
+ The <code>version</code> attribute indicates the version
+ of the TPM. By default a TPM 1.2 is created. This attribute
+ only works with the <code>emulator</code> backend. The following
+ versions are supported:
+ </p>
+ <ul>
+ <li>'1.2' : creates a TPM 1.2</li>
+ <li>'2.0' : creates a TPM 2.0</li>
+ </ul>
+ </dd>
</dl>
<h4><a id="elementsNVRAM">NVRAM device</a></h4>
</attribute>
</group>
</choice>
+ <choice>
+ <group>
+ <optional>
+ <attribute name="version">
+ <choice>
+ <value>1.2</value>
+ <value>2.0</value>
+ </choice>
+ </attribute>
+ </optional>
+ </group>
+ </choice>
</element>
</define>
"passthrough",
"emulator")
+VIR_ENUM_IMPL(virDomainTPMVersion, VIR_DOMAIN_TPM_VERSION_LAST,
+ "default",
+ "1.2",
+ "2.0")
+
VIR_ENUM_IMPL(virDomainIOMMUModel, VIR_DOMAIN_IOMMU_MODEL_LAST,
"intel")
* or like this:
*
* <tpm model='tpm-tis'>
- * <backend type='emulator'/>
+ * <backend type='emulator' version='2'/>
* </tpm>
*/
static virDomainTPMDefPtr
char *path = NULL;
char *model = NULL;
char *backend = NULL;
+ char *version = NULL;
virDomainTPMDefPtr def;
xmlNodePtr save = ctxt->node;
xmlNodePtr *backends = NULL;
goto error;
}
+ version = virXMLPropString(backends[0], "version");
+ if (!version) {
+ def->version = VIR_DOMAIN_TPM_VERSION_DEFAULT;
+ } else {
+ if ((def->version = virDomainTPMVersionTypeFromString(version)) < 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported TPM version '%s'"),
+ version);
+ goto error;
+ }
+ }
+
switch (def->type) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
path = virXPathString("string(./backend/device/@path)", ctxt);
VIR_FREE(model);
VIR_FREE(backend);
VIR_FREE(backends);
+ VIR_FREE(version);
ctxt->node = save;
return def;
return false;
}
+ if (src->version != dst->version) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Target TPM version doesn't match source"));
+ return false;
+ }
+
return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info);
}
virBufferAddLit(buf, "</backend>\n");
break;
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
- virBufferAddLit(buf, "/>\n");
+ virBufferAsprintf(buf, " version='%s'/>\n",
+ virDomainTPMVersionTypeToString(def->version));
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
VIR_DOMAIN_TPM_TYPE_LAST
} virDomainTPMBackendType;
+typedef enum {
+ VIR_DOMAIN_TPM_VERSION_DEFAULT,
+ VIR_DOMAIN_TPM_VERSION_1_2,
+ VIR_DOMAIN_TPM_VERSION_2_0,
+
+ VIR_DOMAIN_TPM_VERSION_LAST
+} virDomainTPMVersion;
+
# define VIR_DOMAIN_TPM_DEFAULT_DEVICE "/dev/tpm0"
struct _virDomainTPMDef {
virDomainTPMBackendType type;
virDomainDeviceInfo info;
virDomainTPMModel model;
+ virDomainTPMVersion version;
union {
struct {
virDomainChrSourceDef source;
VIR_ENUM_DECL(virDomainRNGBackend)
VIR_ENUM_DECL(virDomainTPMModel)
VIR_ENUM_DECL(virDomainTPMBackend)
+VIR_ENUM_DECL(virDomainTPMVersion)
VIR_ENUM_DECL(virDomainMemoryModel)
VIR_ENUM_DECL(virDomainMemoryBackingModel)
VIR_ENUM_DECL(virDomainMemorySource)
"with this QEMU binary"));
return -1;
}
+ return 0;
+}
+
+static int
+qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
+ const virDomainDef *def ATTRIBUTE_UNUSED)
+{
+ /* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
+ if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT)
+ tpm->version = VIR_DOMAIN_TPM_VERSION_1_2;
+
+ switch (tpm->version) {
+ case VIR_DOMAIN_TPM_VERSION_1_2:
+ /* only TIS available for emulator */
+ if (tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR &&
+ tpm->model != VIR_DOMAIN_TPM_MODEL_TIS) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported interface %s for TPM 1.2"),
+ virDomainTPMModelTypeToString(tpm->model));
+ return -1;
+ }
+ break;
+ case VIR_DOMAIN_TPM_VERSION_2_0:
+ case VIR_DOMAIN_TPM_VERSION_DEFAULT:
+ case VIR_DOMAIN_TPM_VERSION_LAST:
+ break;
+ }
return 0;
}
ret = qemuDomainDeviceDefValidateVsock(dev->data.vsock, qemuCaps);
break;
+ case VIR_DOMAIN_DEVICE_TPM:
+ ret = qemuDomainDeviceDefValidateTPM(dev->data.tpm, def);
+ break;
+
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
case VIR_DOMAIN_DEVICE_SHMEM:
- case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_IOMMU:
case VIR_DOMAIN_DEVICE_NONE:
*
* @swtpmStorageDir: directory for swtpm persistent state
* @uuid: The UUID of the VM for which to create the storage
+ * @tpmversion: version of the TPM
*
* Create the swtpm's storage path
*/
static char *
qemuTPMCreateEmulatorStoragePath(const char *swtpmStorageDir,
- const char *uuidstr)
+ const char *uuidstr,
+ virDomainTPMVersion tpmversion)
{
char *path = NULL;
+ const char *dir = "";
- ignore_value(virAsprintf(&path, "%s/%s/tpm1.2", swtpmStorageDir, uuidstr));
+ switch (tpmversion) {
+ case VIR_DOMAIN_TPM_VERSION_1_2:
+ dir = "tpm1.2";
+ break;
+ case VIR_DOMAIN_TPM_VERSION_2_0:
+ dir = "tpm2";
+ break;
+ case VIR_DOMAIN_TPM_VERSION_DEFAULT:
+ case VIR_DOMAIN_TPM_VERSION_LAST:
+ return NULL;
+ }
+
+ ignore_value(virAsprintf(&path, "%s/%s/%s", swtpmStorageDir, uuidstr,
+ dir));
return path;
}
if (!tpm->data.emulator.storagepath &&
!(tpm->data.emulator.storagepath =
- qemuTPMCreateEmulatorStoragePath(swtpmStorageDir, uuidstr)))
+ qemuTPMCreateEmulatorStoragePath(swtpmStorageDir, uuidstr,
+ tpm->version)))
return -1;
return 0;
* @swtpm_group: The group id to switch to
* @logfile: The file to write the log into; it must be writable
* for the user given by userid or 'tss'
+ * @tpmversion: The version of the TPM, either a TPM 1.2 or TPM 2
*
* Setup the external swtpm by creating endorsement key and
* certificates for it.
bool privileged,
uid_t swtpm_user,
gid_t swtpm_group,
- const char *logfile)
+ const char *logfile,
+ const virDomainTPMVersion tpmversion)
{
virCommandPtr cmd = NULL;
int exitstatus;
virCommandSetUID(cmd, swtpm_user);
virCommandSetGID(cmd, swtpm_group);
+ switch (tpmversion) {
+ case VIR_DOMAIN_TPM_VERSION_1_2:
+ break;
+ case VIR_DOMAIN_TPM_VERSION_2_0:
+ virCommandAddArgList(cmd, "--tpm2", NULL);
+ break;
+ case VIR_DOMAIN_TPM_VERSION_DEFAULT:
+ case VIR_DOMAIN_TPM_VERSION_LAST:
+ break;
+ }
+
+
virCommandAddArgList(cmd,
"--tpm-state", storagepath,
"--vmid", vmid,
if (created &&
qemuTPMEmulatorRunSetup(tpm->data.emulator.storagepath, vmname, vmuuid,
privileged, swtpm_user, swtpm_group,
- tpm->data.emulator.logfile) < 0)
+ tpm->data.emulator.logfile, tpm->version) < 0)
goto error;
unlink(tpm->data.emulator.source.data.nix.path);
virCommandSetUID(cmd, swtpm_user);
virCommandSetGID(cmd, swtpm_group);
+ switch (tpm->version) {
+ case VIR_DOMAIN_TPM_VERSION_1_2:
+ break;
+ case VIR_DOMAIN_TPM_VERSION_2_0:
+ virCommandAddArg(cmd, "--tpm2");
+ break;
+ case VIR_DOMAIN_TPM_VERSION_DEFAULT:
+ case VIR_DOMAIN_TPM_VERSION_LAST:
+ break;
+ }
+
return cmd;
error:
--- /dev/null
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=TPM-VM,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-TPM-VM/master-key.aes \
+-machine pc-i440fx-2.12,accel=tcg,usb=off,dump-guest-core=off \
+-m 2048 \
+-realtime mlock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 11d7cd22-da89-3094-6212-079a48a309a1 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot menu=on,strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
+-chardev socket,id=chrtpm,path=/dev/test \
+-device tpm-tis,tpmdev=tpm-tpm0,id=tpm0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
--- /dev/null
+<domain type='qemu'>
+ <name>TPM-VM</name>
+ <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid>
+ <memory unit='KiB'>2097152</memory>
+ <currentMemory unit='KiB'>512288</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>
+ <boot dev='hd'/>
+ <bootmenu enable='yes'/>
+ </os>
+ <features>
+ <acpi/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'/>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <tpm model='tpm-tis'>
+ <backend type='emulator' version='2.0'/>
+ </tpm>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>
DO_TEST_PARSE_ERROR("tpm-no-backend-invalid",
QEMU_CAPS_DEVICE_TPM_PASSTHROUGH, QEMU_CAPS_DEVICE_TPM_TIS);
DO_TEST_CAPS_LATEST("tpm-emulator");
+ DO_TEST_CAPS_LATEST("tpm-emulator-tpm2");
DO_TEST_PARSE_ERROR("pci-domain-invalid", NONE);
DO_TEST_PARSE_ERROR("pci-bus-invalid", NONE);
--- /dev/null
+<domain type='qemu'>
+ <name>TPM-VM</name>
+ <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid>
+ <memory unit='KiB'>2097152</memory>
+ <currentMemory unit='KiB'>512288</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type>
+ <boot dev='hd'/>
+ <bootmenu enable='yes'/>
+ </os>
+ <features>
+ <acpi/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <tpm model='tpm-tis'>
+ <backend type='emulator' version='2.0'/>
+ </tpm>
+ <memballoon model='virtio'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </memballoon>
+ </devices>
+</domain>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<tpm model='tpm-tis'>
- <backend type='emulator'/>
+ <backend type='emulator' version='1.2'/>
</tpm>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>