From nobody Sat Feb 7 09:35:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1639053324; cv=none; d=zohomail.com; s=zohoarc; b=KMoKoQD7VzJ/WeT+qdD2irMFyTmJV/tgi4RjraBOBKrcACvaqnYlXv/VIrpSJdMeuUSqrV11HZHC3Xe3UM0l0JyzQ4mH02ndqch/tYfa90B5k2eRiqBAdtNvThUVIOCDE2kkCo/uHtyPHpTlXdmlL7REgcXNjsvur270P95kXb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639053324; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GECxPGjOIWEKG3lzui47iQOvSSLngj0dc6uFZ9dI2dA=; b=PhNLPIUZkIytVzLx3k0U/IkrWDAqW0spdJo/iHRiyj7ZA4QtPl4e8LBuIhgaGYSLosVlNsLtquy95TY7DAS0v3krABplF6NgYlDzGYCDpMoTv/Ni+QDs2flxY4I/JSH0GDTiF/9+mIWskpWRxkbqjBb9TizHqs+703R99Vuyods= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1639053324584223.2159067197839; Thu, 9 Dec 2021 04:35:24 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-UGOb0SC6Ps-cSzBqKqg2aw-1; Thu, 09 Dec 2021 07:34:13 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 26BE6192CC62; Thu, 9 Dec 2021 12:34:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 04BB35D6CF; Thu, 9 Dec 2021 12:34:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id C295D4A70B; Thu, 9 Dec 2021 12:34:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B9CVRP1018041 for ; Thu, 9 Dec 2021 07:31:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5E6B34ABB5; Thu, 9 Dec 2021 12:31:27 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id B42B41B472 for ; Thu, 9 Dec 2021 12:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639053323; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GECxPGjOIWEKG3lzui47iQOvSSLngj0dc6uFZ9dI2dA=; b=fFA+eCwgMilOJlbmrO5H1bBHSULKSynLv/MKb7NRMT8f46XFvmW1VZ2ym9F6zGcIrfejbG Yh4YfC1IKJ3gmZfrb8CNI3Q6xf+mz1zGkKZktBf7G6haoCXVMsp0lHfnXfx9xTjD2Bi3pj 48aII5LxKmkvhhAisv6ADOw3wK3yPJs= X-MC-Unique: UGOb0SC6Ps-cSzBqKqg2aw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 24/24] qemu: command: Use 'qemuBuildChrChardevCommand' to build TPM backend Date: Thu, 9 Dec 2021 13:30:59 +0100 Message-Id: <4c9eb8d57461cd35718068bdfd35c81b5ababb82.1639052639.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1639053326328100001 Content-Type: text/plain; charset="utf-8" Since the backend of the TPM is a chardev we can use the common helper to instantiate it. This commit also ensures proper ordering so that the backend chardev is formatted before it's being referenced. Signed-off-by: Peter Krempa --- src/qemu/qemu_command.c | 25 +++++++------------ .../aarch64-tpm.aarch64-latest.args | 2 +- .../ppc64-tpmproxy-with-tpm.ppc64-latest.args | 2 +- .../tpm-emulator-spapr.ppc64-latest.args | 2 +- .../tpm-emulator-tpm2-enc.x86_64-latest.args | 2 +- ...pm-emulator-tpm2-pstate.x86_64-latest.args | 2 +- .../tpm-emulator-tpm2.x86_64-latest.args | 2 +- .../tpm-emulator.x86_64-latest.args | 2 +- 8 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3ca7da9d5d..613f7a5d2a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9734,8 +9734,7 @@ static char * qemuBuildTPMBackendStr(virCommand *cmd, virDomainTPMDef *tpm, int *tpmfd, - int *cancelfd, - char **chardev) + int *cancelfd) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *cancel_path =3D NULL; @@ -9774,10 +9773,6 @@ qemuBuildTPMBackendStr(virCommand *cmd, break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: virBufferAddLit(&buf, ",chardev=3Dchrtpm"); - - *chardev =3D g_strdup_printf("socket,id=3Dchrtpm,path=3D%s", - tpm->data.emulator.source->data.nix.pat= h); - break; case VIR_DOMAIN_TPM_TYPE_LAST: return NULL; @@ -9793,22 +9788,20 @@ qemuBuildTPMCommandLine(virCommand *cmd, virDomainTPMDef *tpm, virQEMUCaps *qemuCaps) { - char *optstr; - g_autofree char *chardev =3D NULL; + g_autofree char *tpmdevstr =3D NULL; int tpmfd =3D -1; int cancelfd =3D -1; char *fdset; - if (!(optstr =3D qemuBuildTPMBackendStr(cmd, tpm, - &tpmfd, &cancelfd, - &chardev))) - return -1; + if (tpm->type =3D=3D VIR_DOMAIN_TPM_TYPE_EMULATOR) { + if (qemuBuildChardevCommand(cmd, tpm->data.emulator.source, "chrtp= m", qemuCaps) < 0) + return -1; + } - virCommandAddArgList(cmd, "-tpmdev", optstr, NULL); - VIR_FREE(optstr); + if (!(tpmdevstr =3D qemuBuildTPMBackendStr(cmd, tpm, &tpmfd, &cancelfd= ))) + return -1; - if (chardev) - virCommandAddArgList(cmd, "-chardev", chardev, NULL); + virCommandAddArgList(cmd, "-tpmdev", tpmdevstr, NULL); if (tpmfd >=3D 0) { fdset =3D qemuVirCommandGetFDSet(cmd, tpmfd); diff --git a/tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args b/tests= /qemuxml2argvdata/aarch64-tpm.aarch64-latest.args index 77687b1d05..3125460a95 100644 --- a/tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args +++ b/tests/qemuxml2argvdata/aarch64-tpm.aarch64-latest.args @@ -27,8 +27,8 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-aarch64test/.config \ -no-shutdown \ -no-acpi \ -boot strict=3Don \ --tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -chardev socket,id=3Dchrtpm,path=3D/dev/test \ +-tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -device '{"driver":"tpm-tis-device","tpmdev":"tpm-tpm0","id":"tpm0"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ diff --git a/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.ar= gs b/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args index 104a5ef28c..90a27ca1a8 100644 --- a/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args +++ b/tests/qemuxml2argvdata/ppc64-tpmproxy-with-tpm.ppc64-latest.args @@ -28,8 +28,8 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ -boot strict=3Don \ -device '{"driver":"pci-ohci","id":"usb","bus":"pci.0","addr":"0x1"}' \ -device '{"driver":"spapr-tpm-proxy","id":"tpm0","host-path":"/dev/tpmrm0"= }' \ --tpmdev emulator,id=3Dtpm-tpm1,chardev=3Dchrtpm \ -chardev socket,id=3Dchrtpm,path=3D/dev/test \ +-tpmdev emulator,id=3Dtpm-tpm1,chardev=3Dchrtpm \ -device '{"driver":"tpm-spapr","tpmdev":"tpm-tpm1","id":"tpm1","reg":16384= }' \ -audiodev '{"id":"audio1","driver":"none"}' \ -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x6"}' \ diff --git a/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args b/= tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args index 90c207d544..97d310d8dc 100644 --- a/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args +++ b/tests/qemuxml2argvdata/tpm-emulator-spapr.ppc64-latest.args @@ -36,8 +36,8 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-TPM-VM/.config \ -device '{"driver":"spapr-vty","chardev":"charserial0","id":"serial0","reg= ":805306368}' \ -chardev pty,id=3Dcharserial1 \ -device '{"driver":"spapr-vty","chardev":"charserial1","id":"serial1","reg= ":805310464}' \ --tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -chardev socket,id=3Dchrtpm,path=3D/dev/test \ +-tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -device '{"driver":"tpm-spapr","tpmdev":"tpm-tpm0","id":"tpm0","reg":20480= }' \ -audiodev '{"id":"audio1","driver":"none"}' \ -global spapr-nvram.reg=3D0x4000 \ diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.arg= s b/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args index 89a577d657..3b418917f3 100644 --- a/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args +++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.x86_64-latest.args @@ -27,8 +27,8 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-TPM-VM/.config \ -no-shutdown \ -boot menu=3Don,strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ --tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -chardev socket,id=3Dchrtpm,path=3D/dev/test \ +-tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x2"}' \ diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.= args b/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args index 89a577d657..3b418917f3 100644 --- a/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args +++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.x86_64-latest.args @@ -27,8 +27,8 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-TPM-VM/.config \ -no-shutdown \ -boot menu=3Don,strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ --tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -chardev socket,id=3Dchrtpm,path=3D/dev/test \ +-tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x2"}' \ diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args b/= tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args index 89a577d657..3b418917f3 100644 --- a/tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args +++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.args @@ -27,8 +27,8 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-TPM-VM/.config \ -no-shutdown \ -boot menu=3Don,strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ --tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -chardev socket,id=3Dchrtpm,path=3D/dev/test \ +-tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x2"}' \ diff --git a/tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args b/tests= /qemuxml2argvdata/tpm-emulator.x86_64-latest.args index 89a577d657..3b418917f3 100644 --- a/tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args +++ b/tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.args @@ -27,8 +27,8 @@ XDG_CONFIG_HOME=3D/tmp/lib/domain--1-TPM-VM/.config \ -no-shutdown \ -boot menu=3Don,strict=3Don \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ --tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -chardev socket,id=3Dchrtpm,path=3D/dev/test \ +-tpmdev emulator,id=3Dtpm-tpm0,chardev=3Dchrtpm \ -device '{"driver":"tpm-tis","tpmdev":"tpm-tpm0","id":"tpm0"}' \ -audiodev '{"id":"audio1","driver":"none"}' \ -device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x2"}' \ --=20 2.31.1