From nobody Mon Feb 9 02:57:06 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=1644422707; cv=none; d=zohomail.com; s=zohoarc; b=k1UvldjY+veZQEqzM5iKrOKa20SZpKr+ggu0dEaCw+32BgVbjlS9V1+zCfSvtIh3Fk9SrST3B3Byb5pevoyfii2PW0MFjzWHBMmxo4S9jq79WObCqVijTEWrEh3PH2A+lildkUuhusI7oVA2guUNaTnhxNxWjp1M59qzA3iVWYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644422707; 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=aICIrdZAeoGLsOMU45pkaYVZasvX9SZI86tQd35AhcQ=; b=Wq+VAj5Ys+Z2AQDd8puIxu3aVSQZYYEPGMtQ4Y/nNQBYoeRofcASilaV33Yoa1agm+b75OKUpkkBqicFWzO24EAWA/VNU9K8408eMjucBuk3OIgj3KSM4+uqOh8ZuTO/Szdwina+PaOGti7uyx1wdQdY1LtLWAsqS1IY1yC+uYk= 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 1644422706998304.9979684659687; Wed, 9 Feb 2022 08:05:06 -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-367-qrJ4_jppMHqk1EhWMpMc0g-1; Wed, 09 Feb 2022 11:03:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EF24E100F959; Wed, 9 Feb 2022 16:03:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C85F2798A5; Wed, 9 Feb 2022 16:03:19 +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 95F6F18218B6; Wed, 9 Feb 2022 16:03:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 219G329E012565 for ; Wed, 9 Feb 2022 11:03:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id D68B47DE4A; Wed, 9 Feb 2022 16:03:02 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43699838E4 for ; Wed, 9 Feb 2022 16:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644422705; 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=aICIrdZAeoGLsOMU45pkaYVZasvX9SZI86tQd35AhcQ=; b=E868g2z6hEySPeWV1dTalHdAY8/06F3YptVWYJGTN9/6NGp3yWgWL31eRDTVsioEUGCUz/ vbIyvNcbW0/N0DnxTlTiG5Vo0z/I8/pKNAP8hAl9sMiQAh9V07ubt1pdFHRdhYGCY/EerJ E488zD5HKRYYeaX31SCDNr0hGf7Zlnk= X-MC-Unique: qrJ4_jppMHqk1EhWMpMc0g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 27/27] qemuBuildTPMCommandLine: Use 'qemuPassFD' infrastructure Date: Wed, 9 Feb 2022 17:02:19 +0100 Message-Id: <2f693b177050df19b82f2f0b5dd546249f241b00.1644422239.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.14 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: 1644422708162100004 Content-Type: text/plain; charset="utf-8" Remove the last code path using hardcoded fdsets. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 140 +++++------------- .../tpm-passthrough-crb.x86_64-latest.args | 6 +- .../tpm-passthrough.x86_64-latest.args | 6 +- 3 files changed, 45 insertions(+), 107 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7169b8ff90..9649ba3701 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -301,56 +301,6 @@ qemuBuildMasterKeyCommandLine(virCommand *cmd, } -/** - * qemuVirCommandGetFDSet: - * @cmd: the command to modify - * @fd: fd to reassign to the child - * - * Get the parameters for the QEMU -add-fd command line option - * for the given file descriptor. The file descriptor must previously - * have been 'transferred' in a virCommandPassFD() call. - * This function for example returns "set=3D10,fd=3D20". - */ -static char * -qemuVirCommandGetFDSet(virCommand *cmd, int fd) -{ - int idx =3D virCommandPassFDGetFDIndex(cmd, fd); - - if (idx < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("file descriptor %d has not been transferred"), f= d); - return NULL; - } - - return g_strdup_printf("set=3D%d,fd=3D%d", idx, fd); -} - - -/** - * qemuVirCommandGetDevSet: - * @cmd: the command to modify - * @fd: fd to reassign to the child - * - * Get the parameters for the QEMU path=3D parameter where a file - * descriptor is accessed via a file descriptor set, for example - * /dev/fdset/10. The file descriptor must previously have been - * 'transferred' in a virCommandPassFD() call. - */ -static char * -qemuVirCommandGetDevSet(virCommand *cmd, int fd) -{ - int idx =3D virCommandPassFDGetFDIndex(cmd, fd); - - if (idx < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("file descriptor %d has not been transferred"), f= d); - return NULL; - } - - return g_strdup_printf("/dev/fdset/%d", idx); -} - - static char * qemuBuildDeviceAddressPCIGetBus(const virDomainDef *domainDef, const virDomainDeviceInfo *info) @@ -9764,40 +9714,22 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev, static char * -qemuBuildTPMBackendStr(virCommand *cmd, - virDomainTPMDef *tpm, - int *tpmfd, - int *cancelfd) +qemuBuildTPMBackendStr(virDomainTPMDef *tpm, + qemuFDPass *passtpm, + qemuFDPass *passcancel) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - g_autofree char *devset =3D NULL; - g_autofree char *cancelset =3D NULL; - - *tpmfd =3D -1; - *cancelfd =3D -1; virBufferAsprintf(&buf, "%s", virDomainTPMBackendTypeToString(tpm->typ= e)); virBufferAsprintf(&buf, ",id=3Dtpm-%s", tpm->info.alias); switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: - if (qemuBuildTPMOpenBackendFDs(tpm->data.passthrough.source->data.= file.path, - tpmfd, cancelfd) < 0) - return NULL; - - virCommandPassFD(cmd, *tpmfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); - virCommandPassFD(cmd, *cancelfd, VIR_COMMAND_PASS_FD_CLOSE_PARENT); - - if (!(devset =3D qemuVirCommandGetDevSet(cmd, *tpmfd)) || - !(cancelset =3D qemuVirCommandGetDevSet(cmd, *cancelfd))) - return NULL; - virBufferAddLit(&buf, ",path=3D"); - virQEMUBuildBufferEscapeComma(&buf, devset); + virQEMUBuildBufferEscapeComma(&buf, qemuFDPassGetPath(passtpm)); virBufferAddLit(&buf, ",cancel-path=3D"); - virQEMUBuildBufferEscapeComma(&buf, cancelset); - + virQEMUBuildBufferEscapeComma(&buf, qemuFDPassGetPath(passcancel)); break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: virBufferAddLit(&buf, ",chardev=3Dchrtpm"); @@ -9814,42 +9746,49 @@ static int qemuBuildTPMCommandLine(virCommand *cmd, const virDomainDef *def, virDomainTPMDef *tpm, - virQEMUCaps *qemuCaps) + qemuDomainObjPrivate *priv) { g_autofree char *tpmdevstr =3D NULL; - int tpmfd =3D -1; - int cancelfd =3D -1; - char *fdset; + g_autoptr(qemuFDPass) passtpm =3D NULL; + g_autoptr(qemuFDPass) passcancel =3D NULL; - if (tpm->type =3D=3D VIR_DOMAIN_TPM_TYPE_EMULATOR) { - if (qemuBuildChardevCommand(cmd, tpm->data.emulator.source, "chrtp= m", qemuCaps) < 0) - return -1; - } + switch ((virDomainTPMBackendType) tpm->type) { + case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: { + VIR_AUTOCLOSE fdtpm =3D -1; + VIR_AUTOCLOSE fdcancel =3D -1; - if (!(tpmdevstr =3D qemuBuildTPMBackendStr(cmd, tpm, &tpmfd, &cancelfd= ))) - return -1; + if (qemuBuildTPMOpenBackendFDs(tpm->data.passthrough.source->data.= file.path, + &fdtpm, &fdcancel) < 0) + return -1; - virCommandAddArgList(cmd, "-tpmdev", tpmdevstr, NULL); + passtpm =3D qemuFDPassNew(tpm->info.alias, priv, true); + passcancel =3D qemuFDPassNew(tpm->info.alias, priv, true); - if (tpmfd >=3D 0) { - fdset =3D qemuVirCommandGetFDSet(cmd, tpmfd); - if (!fdset) + if (qemuFDPassAddFD(passtpm, &fdtpm, "-tpm") < 0 || + qemuFDPassAddFD(passcancel, &fdcancel, "-cancel") < 0) return -1; - - virCommandAddArgList(cmd, "-add-fd", fdset, NULL); - VIR_FREE(fdset); } + break; - if (cancelfd >=3D 0) { - fdset =3D qemuVirCommandGetFDSet(cmd, cancelfd); - if (!fdset) + case VIR_DOMAIN_TPM_TYPE_EMULATOR: + if (qemuBuildChardevCommand(cmd, tpm->data.emulator.source, "chrtp= m", priv->qemuCaps) < 0) return -1; + break; - virCommandAddArgList(cmd, "-add-fd", fdset, NULL); - VIR_FREE(fdset); + case VIR_DOMAIN_TPM_TYPE_LAST: + virReportEnumRangeError(virDomainTPMBackendType, tpm->type); + return -1; } - if (qemuBuildTPMDevCmd(cmd, def, tpm, qemuCaps) < 0) + qemuFDPassTransferCommand(passtpm, cmd); + qemuFDPassTransferCommand(passcancel, cmd); + + if (!(tpmdevstr =3D qemuBuildTPMBackendStr(tpm, passtpm, passcancel))) + return -1; + + virCommandAddArgList(cmd, "-tpmdev", tpmdevstr, NULL); + + if (qemuBuildTPMDevCmd(cmd, def, tpm, priv->qemuCaps) < 0) return -1; return 0; @@ -9880,16 +9819,15 @@ qemuBuildTPMProxyCommandLine(virCommand *cmd, static int qemuBuildTPMsCommandLine(virCommand *cmd, const virDomainDef *def, - virQEMUCaps *qemuCaps) + qemuDomainObjPrivate *priv) { size_t i; for (i =3D 0; i < def->ntpms; i++) { if (def->tpms[i]->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) { - if (qemuBuildTPMProxyCommandLine(cmd, def->tpms[i], qemuCaps) = < 0) + if (qemuBuildTPMProxyCommandLine(cmd, def->tpms[i], priv->qemu= Caps) < 0) return -1; - } else if (qemuBuildTPMCommandLine(cmd, def, - def->tpms[i], qemuCaps) < 0) { + } else if (qemuBuildTPMCommandLine(cmd, def, def->tpms[i], priv) <= 0) { return -1; } } @@ -10633,7 +10571,7 @@ qemuBuildCommandLine(virQEMUDriver *driver, if (qemuBuildConsoleCommandLine(cmd, def, qemuCaps) < 0) return NULL; - if (qemuBuildTPMsCommandLine(cmd, def, qemuCaps) < 0) + if (qemuBuildTPMsCommandLine(cmd, def, priv) < 0) return NULL; if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0) diff --git a/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args = b/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args index e099cf0fa1..b9f22188c2 100644 --- a/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args +++ b/tests/qemuxml2argvdata/tpm-passthrough-crb.x86_64-latest.args @@ -27,9 +27,9 @@ 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 passthrough,id=3Dtpm-tpm0,path=3D/dev/fdset/0,cancel-path=3D/dev/f= dset/1 \ --add-fd set=3D0,fd=3D1730 \ --add-fd set=3D1,fd=3D1731 \ +-add-fd set=3D1,fd=3D1730,opaque=3Dtpm0-tpm \ +-add-fd set=3D2,fd=3D1731,opaque=3Dtpm0-cancel \ +-tpmdev passthrough,id=3Dtpm-tpm0,path=3D/dev/fdset/1,cancel-path=3D/dev/f= dset/2 \ -device '{"driver":"tpm-crb","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-passthrough.x86_64-latest.args b/te= sts/qemuxml2argvdata/tpm-passthrough.x86_64-latest.args index beb6a307cb..da042d3b2b 100644 --- a/tests/qemuxml2argvdata/tpm-passthrough.x86_64-latest.args +++ b/tests/qemuxml2argvdata/tpm-passthrough.x86_64-latest.args @@ -27,9 +27,9 @@ 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 passthrough,id=3Dtpm-tpm0,path=3D/dev/fdset/0,cancel-path=3D/dev/f= dset/1 \ --add-fd set=3D0,fd=3D1730 \ --add-fd set=3D1,fd=3D1731 \ +-add-fd set=3D1,fd=3D1730,opaque=3Dtpm0-tpm \ +-add-fd set=3D2,fd=3D1731,opaque=3Dtpm0-cancel \ +-tpmdev passthrough,id=3Dtpm-tpm0,path=3D/dev/fdset/1,cancel-path=3D/dev/f= dset/2 \ -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.34.1