From nobody Fri May 17 02:03:09 2024 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=1658136669; cv=none; d=zohomail.com; s=zohoarc; b=I7j9ELYkLC9CR0HJu3gdOcv+KmtnixalU5HOFGq5NF/E6N5w8K+I5W0J+JQG21I+dyOAx9nlxj7WQC+jmhaecIyzrVRYPnXdNd6lb2aOkabuqEm8fcQ7z4snnBCc7fUYzCGi4P6ZNxV+IZgHMcJR3lf+zw/8dRgs/fUqermxh5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136669; 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=N7ta73u3b6MyXPV3yLyI3U2r63ctswWTeNh1I2zWocY=; b=PYw+F9A8tA92YeUO605G4zn0ApVPLFWZsmEv3wdKZSjaa8XqrF5OuO0KeeJr16EBwRNiCTLIKgX6FXL3gkM9uvr8v0UwhAjTOo47gLNHcb/6iSM0DQ788HpAHYgxmklIfZgY2IBAvPfxQyTSjjM5OptAi4xjg1Hsf/fzaY8h1FQ= 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 16581366692271012.1649379678274; Mon, 18 Jul 2022 02:31:09 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-588-H3ijfjzbOAaRrGeoqPPVDA-1; Mon, 18 Jul 2022 05:30:56 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A94628039AD; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F289C35979; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 166A9194706F; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2DB4D1947054 for ; Mon, 18 Jul 2022 09:30:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F09F02166B2A; Mon, 18 Jul 2022 09:30:52 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C7F22166B26 for ; Mon, 18 Jul 2022 09:30:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136668; 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=N7ta73u3b6MyXPV3yLyI3U2r63ctswWTeNh1I2zWocY=; b=H34p8SZCJgMdMe4ClnkNix21jqQOexv/TTNiJsp+xLLHEXMWQ4U/eZ5K4/HmZww77jlOh4 7jUX0++Ygk6YTUROYGiXMhfxJ7dP46rGrmPYPl5rxUwUV9Lm41qooqO9UD5Gnkrn/48YE6 QPsS17JuXkNKTHDqLIrG/yuyKP2V+4E= X-MC-Unique: H3ijfjzbOAaRrGeoqPPVDA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/8] conf: Report an error when default TPM model is provided Date: Mon, 18 Jul 2022 11:30:43 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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: 1658136670153100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When "default" model of a TPM was provided, our parses accepts it happily even though the value is forbidden by our RNG and not documented as accepted value. This is because of < 0 vs <=3D 0 comparison of virDomainTPMModelTypeFromString() retval. Make the parser error out explicitly in this case. Users can always chose to not specify the attribute in which case we pick a sane default (in qemuDomainTPMDefPostParse()). Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4c7a5a044c..b7147945da 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10360,7 +10360,7 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, =20 model =3D virXMLPropString(node, "model"); if (model !=3D NULL && - (def->model =3D virDomainTPMModelTypeFromString(model)) < 0) { + (def->model =3D virDomainTPMModelTypeFromString(model)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown TPM frontend model '%s'"), model); goto error; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 90de50c12f..5a057c36b8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1400,7 +1400,7 @@ struct _virDomainHubDef { }; =20 typedef enum { - VIR_DOMAIN_TPM_MODEL_DEFAULT, + VIR_DOMAIN_TPM_MODEL_DEFAULT =3D 0, VIR_DOMAIN_TPM_MODEL_TIS, VIR_DOMAIN_TPM_MODEL_CRB, VIR_DOMAIN_TPM_MODEL_SPAPR, --=20 2.35.1 From nobody Fri May 17 02:03:09 2024 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=1658136855; cv=none; d=zohomail.com; s=zohoarc; b=dRFRMvyICuw1a3y0oWx3+YNh0+hAQcDRQx318Dxpd8tiWpIwR+Pu4NkaSvY+xdzjDGqgGCQq1r17slQAXUDJLFkng3paDbHCdfqnkLgV7oHd3d+8y8A44kzG+be32h0HUneym3T28Q/ufIGpB2aaN8wM+R3N3kNq3nrJIOhPvuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136855; 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=2Vpmzt8qUar+ZbkrmRW6w3OxrjTzQV3/kVn94fvsiWk=; b=QWaLz0hE+qFr9Tc8Q6vkvIvHxNcH8EE+nKTXWPLvfw4x9Pm0c9qTyLKgUZ/Csw0iIUwuAlAp6bOAYthAFzrIqgXx4k4g9Bh7puYn4ZmTg7AOisyQ4YjBuPoos1n8LjL/Ehb+GEBhrqqu9DuvgQSODce37nuSkrbfh4xusWI+RCc= 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 16581368551351014.5333100769631; Mon, 18 Jul 2022 02:34:15 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-133-lfiM6qEyN5Kas28VRhhv9g-1; Mon, 18 Jul 2022 05:31:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3C3DE811E75; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22BC21121314; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E776C1947056; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AB7A2194704C for ; Mon, 18 Jul 2022 09:30:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 875CB2166B2A; Mon, 18 Jul 2022 09:30:53 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 334692166B26 for ; Mon, 18 Jul 2022 09:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136854; 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=2Vpmzt8qUar+ZbkrmRW6w3OxrjTzQV3/kVn94fvsiWk=; b=czvQusLH4BNO5OC7LPLfyQAj8Q3BPIqoampEYEbBFLghNMS3m2DiHEossf6Y3U3hHI/H57 gdFAqpTojUcNoJ9foUJEq+ZsOueiNr3LJ5Lkl+MAkjC4i71bZgW0NMMztCmLSSLJCao2wa QOCNo1PpOEcC/gp4lXSBlK+aFC/wL48= X-MC-Unique: lfiM6qEyN5Kas28VRhhv9g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/8] conf: Report error when default TPM version is provided Date: Mon, 18 Jul 2022 11:30:44 +0200 Message-Id: <838c8127f28cdf75364d8e5e16b25c0b3c46cca0.1658136603.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 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: 1658136855401100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When "default" version of TPM was provided, our parses accepts it happily even though the value is forbidden by our RNG and not documented as accepted value. This is because of < 0 vs <=3D 0 comparison of virDomainTPMModelTypeFromString() retval. Make the parser error out explicitly in this case. Users can always chose to not specify the attribute in which case we pick a sane default (in qemuDomainDefTPMsPostParse()). Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 2 +- src/conf/domain_conf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b7147945da..6c178783af 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10400,7 +10400,7 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, if (!version) { def->version =3D VIR_DOMAIN_TPM_VERSION_DEFAULT; } else { - if ((def->version =3D virDomainTPMVersionTypeFromString(version)) = < 0) { + if ((def->version =3D virDomainTPMVersionTypeFromString(version)) = <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported TPM version '%s'"), version); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5a057c36b8..7139b91aca 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1417,7 +1417,7 @@ typedef enum { } virDomainTPMBackendType; =20 typedef enum { - VIR_DOMAIN_TPM_VERSION_DEFAULT, + VIR_DOMAIN_TPM_VERSION_DEFAULT =3D 0, VIR_DOMAIN_TPM_VERSION_1_2, VIR_DOMAIN_TPM_VERSION_2_0, =20 --=20 2.35.1 From nobody Fri May 17 02:03:09 2024 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=1658136903; cv=none; d=zohomail.com; s=zohoarc; b=T5bMr4dKNdWbf1k9/K159c366HZeYw+rZsJnQuJR17LKm0ZpnD/so8gTROaCHyspEpC/XICZQEfR9kvs9eas8Oa9OAn2KeWtNj0Iyx1P0fyU72qI1MHZ5tu531zT16WO3rPnVA5bdvvSt06JdKxL1smiX6Wc3vJYMYCLxGtYOeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136903; 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=xfm1EqnFRlhy0GW1ZFtvMiLrzAdKqRcR0ecPBvmSD6U=; b=bzMJPiSFG1UF3NFn5aIK1QxvkXrFstNOnCSV4hID+nn8A8ut4kb32VDsqHwsiiJQ+PTnFitSO9MG7ZoZlNtHg44EbeiJJIOKWgFCTImMwAIarM497KstOmAcDoSpngihg5v8Hrh7wbt4VnQptj+pnEI3WZN305bUfh/H+/uXaBc= 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 1658136903341686.8792379173501; Mon, 18 Jul 2022 02:35:03 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-13-QrffpiUHOJ6LXYygMahmaQ-1; Mon, 18 Jul 2022 05:30:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 187BE80418F; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A080DC3598D; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 514FF194705E; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 32E821947075 for ; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1DD262166B29; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE0602166B26 for ; Mon, 18 Jul 2022 09:30:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136902; 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=xfm1EqnFRlhy0GW1ZFtvMiLrzAdKqRcR0ecPBvmSD6U=; b=NJp/PtYbQ5lECiuIUamCah/B9rHpPfe2dqxE78gnvIsShBaJ8hRKYexmcAeK7yBA//HuhK pnGL8kuPnCcxTenTNA1BQMQuS4FIjjFLC0fhMup26cIoxzJZhRuuyAB6n+NGKfllpGHSee k7eucHsD7/H/PRwITTLGKLfHIhojOww= X-MC-Unique: QrffpiUHOJ6LXYygMahmaQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/8] conf: Drop needless setting of VIR_DOMAIN_TPM_VERSION_DEFAULT Date: Mon, 18 Jul 2022 11:30:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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: 1658136903605100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In previous commit the VIR_DOMAIN_TPM_VERSION_DEFAULT value was made just an alias to value of 0. And since all newly allocated memory is zeroed out (due to use of g_new0()), the def->version inside of virDomainTPMDefParseXML() is also 0 and thus there is no need to set it explicitly. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6c178783af..2d8989e4ff 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10397,15 +10397,12 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, } =20 version =3D virXMLPropString(backends[0], "version"); - if (!version) { - def->version =3D VIR_DOMAIN_TPM_VERSION_DEFAULT; - } else { - if ((def->version =3D virDomainTPMVersionTypeFromString(version)) = <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported TPM version '%s'"), - version); - goto error; - } + if (version && + (def->version =3D virDomainTPMVersionTypeFromString(version)) <=3D= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported TPM version '%s'"), + version); + goto error; } =20 switch (def->type) { --=20 2.35.1 From nobody Fri May 17 02:03:09 2024 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=1658136845; cv=none; d=zohomail.com; s=zohoarc; b=eq6CuLE2e897V2Ly32EMST2bxQ2EimH/Mbfcs6Ten5nxf35Q4hdkDVFteZOj4Ko5oMQOm3adIm5XdtJqqadsDIQOUGKkUacZqlCo1GrOuQxyL/U/fCKIzSeYN0UFfHRjbe5iSm66Nkt9/I6pvnEmnaDDPDKDaosfdBc3SF6i3FM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136845; 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=gFTMPhcfoB1DVsqoeLhpII5Xw3BomzHSUTO6q7ybPb8=; b=V+qiVQaGcAZ5C97CO/q2viQs4J/nG8kdD+D0EBub6p+VQPjKyKOxzpIsqcGkwEN7AulEB+qMWAJZHV2IZts82m2Ei11Dwx5E6EaP7aNvIEsGg8w50pOSCeuKKBWuARUg373ODWDaVJu+uHtPAVPao7+m4Wa7kpqvV9PC6Us+0Mk= 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 1658136845969732.373300681233; Mon, 18 Jul 2022 02:34:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-413-6WQdWDxoN4SLWH_i7srh3w-1; Mon, 18 Jul 2022 05:31:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A51B858290; Mon, 18 Jul 2022 09:31:00 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1659F2166B26; Mon, 18 Jul 2022 09:31:00 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CDDD31947056; Mon, 18 Jul 2022 09:30:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BFEDA1947056 for ; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A91522166B29; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 547CA2166B26 for ; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136844; 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=gFTMPhcfoB1DVsqoeLhpII5Xw3BomzHSUTO6q7ybPb8=; b=f0dMurTsiBsQvCPVkXNXpvXANEugqRa046h+JAfOv87BKyUwVYnlh4mlzHiUKnEOrWqZUC gYIhjvElsyVKo0xgX4OhLoMMA7LnXmq+1z+vNRnPzTEjIcfwFCy0f/8WKyEtVsxs4q9fkT TP1azDk7wWlMjytHELAwfMc47vVlOXI= X-MC-Unique: 6WQdWDxoN4SLWH_i7srh3w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/8] conf: Move _virDomainTPMDef::version into _virDomainTPMDef::data::emulator Date: Mon, 18 Jul 2022 11:30:46 +0200 Message-Id: <4007b6d873957cec66becb6be627f160ac676160.1658136603.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: 1658136847323100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The _virDomainTPMDef structure has 'version' member, which is a bit misplaced. It's only emulator type of TPM that can have a version, even our documentation says so: ``version`` The ``version`` attribute indicates the version of the TPM. This attribu= te only works with the ``emulator`` backend. The following versions are supported: Therefore, move the member into that part of union that's covering emulated TPM devices. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 34 +++++++++++----------- src/conf/domain_conf.h | 2 +- src/qemu/qemu_domain.c | 7 +++-- src/qemu/qemu_tpm.c | 10 ++++--- src/qemu/qemu_validate.c | 53 ++++++++++++++++++----------------- src/security/virt-aa-helper.c | 2 +- 6 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2d8989e4ff..28f0e75e60 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10396,15 +10396,6 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, goto error; } =20 - version =3D virXMLPropString(backends[0], "version"); - if (version && - (def->version =3D virDomainTPMVersionTypeFromString(version)) <=3D= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported TPM version '%s'"), - version); - goto error; - } - switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: if (!(def->data.passthrough.source =3D virDomainChrSourceDefNew(xm= lopt))) @@ -10416,6 +10407,15 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, def->data.passthrough.source->data.file.path =3D g_steal_pointer(&= path); break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: + version =3D virXMLPropString(backends[0], "version"); + if (version && + (def->data.emulator.version =3D virDomainTPMVersionTypeFromStr= ing(version)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported TPM version '%s'"), + version); + goto error; + } + if (!(def->data.emulator.source =3D virDomainChrSourceDefNew(xmlop= t))) goto error; secretuuid =3D virXPathString("string(./backend/encryption/@secret= )", ctxt); @@ -10437,7 +10437,7 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, goto error; } } - if (def->version =3D=3D VIR_DOMAIN_TPM_VERSION_2_0) { + if (def->data.emulator.version =3D=3D VIR_DOMAIN_TPM_VERSION_2_0) { if ((nnodes =3D virXPathNodeSet("./backend/active_pcr_banks/*"= , ctxt, &nodes)) < 0) break; for (i =3D 0; i < nnodes; i++) { @@ -20658,14 +20658,14 @@ virDomainTPMDefCheckABIStability(virDomainTPMDef = *src, return false; } =20 - if (src->version !=3D dst->version) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Target TPM version doesn't match source")); - return false; - } - switch (src->type) { case VIR_DOMAIN_TPM_TYPE_EMULATOR: + if (src->data.emulator.version !=3D dst->data.emulator.version) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Target TPM version doesn't match source")); + return false; + } + if (src->data.emulator.activePcrBanks !=3D dst->data.emulator.acti= vePcrBanks) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Target active PCR banks doesn't match source= ")); @@ -24219,7 +24219,7 @@ virDomainTPMDefFormat(virBuffer *buf, break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: virBufferAsprintf(&backendAttrBuf, " version=3D'%s'", - virDomainTPMVersionTypeToString(def->version)); + virDomainTPMVersionTypeToString(def->data.emulat= or.version)); if (def->data.emulator.persistent_state) virBufferAddLit(&backendAttrBuf, " persistent_state=3D'yes'"); if (def->data.emulator.hassecretuuid) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7139b91aca..3362042db5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1439,12 +1439,12 @@ struct _virDomainTPMDef { int type; /* virDomainTPMBackendType */ virDomainDeviceInfo info; int model; /* virDomainTPMModel */ - int version; /* virDomainTPMVersion */ union { struct { virDomainChrSourceDef *source; } passthrough; struct { + int version; /* virDomainTPMVersion */ virDomainChrSourceDef *source; char *storagepath; char *logfile; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 94b2e3118c..0343fd3597 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4594,13 +4594,14 @@ qemuDomainDefTPMsPostParse(virDomainDef *def) virDomainTPMDef *tpm =3D def->tpms[i]; =20 /* TPM 1.2 and 2 are not compatible, so we choose a specific versi= on here */ - if (tpm->version =3D=3D VIR_DOMAIN_TPM_VERSION_DEFAULT) { + if (tpm->type =3D=3D VIR_DOMAIN_TPM_TYPE_EMULATOR && + tpm->data.emulator.version =3D=3D VIR_DOMAIN_TPM_VERSION_DEFAU= LT) { if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR || tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_CRB || qemuDomainIsARMVirt(def)) - tpm->version =3D VIR_DOMAIN_TPM_VERSION_2_0; + tpm->data.emulator.version =3D VIR_DOMAIN_TPM_VERSION_2_0; else - tpm->version =3D VIR_DOMAIN_TPM_VERSION_1_2; + tpm->data.emulator.version =3D VIR_DOMAIN_TPM_VERSION_1_2; } =20 if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) { diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c index 03829775b8..f28dd2e1e9 100644 --- a/src/qemu/qemu_tpm.c +++ b/src/qemu/qemu_tpm.c @@ -575,7 +575,8 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, if (created && qemuTPMEmulatorRunSetup(tpm->data.emulator.storagepath, vmname, vm= uuid, privileged, swtpm_user, swtpm_group, - tpm->data.emulator.logfile, tpm->version, + tpm->data.emulator.logfile, + tpm->data.emulator.version, secretuuid, incomingMigration) < 0) goto error; =20 @@ -583,7 +584,8 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, qemuTPMEmulatorReconfigure(tpm->data.emulator.storagepath, swtpm_user, swtpm_group, tpm->data.emulator.activePcrBanks, - tpm->data.emulator.logfile, tpm->versio= n, + tpm->data.emulator.logfile, + tpm->data.emulator.version, secretuuid) < 0) goto error; =20 @@ -611,7 +613,7 @@ qemuTPMEmulatorBuildCommand(virDomainTPMDef *tpm, virCommandSetUID(cmd, swtpm_user); virCommandSetGID(cmd, swtpm_group); =20 - switch (tpm->version) { + switch (tpm->data.emulator.version) { case VIR_DOMAIN_TPM_VERSION_1_2: break; case VIR_DOMAIN_TPM_VERSION_2_0: @@ -684,7 +686,7 @@ qemuTPMEmulatorInitPaths(virDomainTPMDef *tpm, if (!tpm->data.emulator.storagepath && !(tpm->data.emulator.storagepath =3D qemuTPMEmulatorStorageBuildPath(swtpmStorageDir, uuidstr, - tpm->version))) + tpm->data.emulator.version))) return -1; =20 if (!tpm->data.emulator.logfile) { diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 764d5b029e..ff164118b7 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4760,33 +4760,34 @@ qemuValidateDomainDeviceDefTPM(virDomainTPMDef *tpm, { virDomainCapsDeviceTPM tpmCaps =3D { 0 }; =20 - switch (tpm->version) { - case VIR_DOMAIN_TPM_VERSION_1_2: - /* TPM 1.2 + CRB do not work */ - if (tpm->type =3D=3D VIR_DOMAIN_TPM_TYPE_EMULATOR && - tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_CRB) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported interface %s for TPM 1.2"), - virDomainTPMModelTypeToString(tpm->model)); - return -1; + if (tpm->type =3D=3D VIR_DOMAIN_TPM_TYPE_EMULATOR) { + switch (tpm->data.emulator.version) { + case VIR_DOMAIN_TPM_VERSION_1_2: + /* TPM 1.2 + CRB do not work */ + if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_CRB) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported interface %s for TPM 1.2"), + virDomainTPMModelTypeToString(tpm->model)); + return -1; + } + /* TPM 1.2 + SPAPR do not work with any 'type' (backend) */ + if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("TPM 1.2 is not supported with the SPAPR = device model")); + return -1; + } + /* TPM 1.2 + ARM does not work */ + if (qemuDomainIsARMVirt(def)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("TPM 1.2 is not supported on ARM")); + return -1; + } + break; + case VIR_DOMAIN_TPM_VERSION_2_0: + case VIR_DOMAIN_TPM_VERSION_DEFAULT: + case VIR_DOMAIN_TPM_VERSION_LAST: + break; } - /* TPM 1.2 + SPAPR do not work with any 'type' (backend) */ - if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("TPM 1.2 is not supported with the SPAPR devi= ce model")); - return -1; - } - /* TPM 1.2 + ARM does not work */ - if (qemuDomainIsARMVirt(def)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("TPM 1.2 is not supported on ARM")); - return -1; - } - break; - case VIR_DOMAIN_TPM_VERSION_2_0: - case VIR_DOMAIN_TPM_VERSION_DEFAULT: - case VIR_DOMAIN_TPM_VERSION_LAST: - break; } =20 virQEMUCapsFillDomainDeviceTPMCaps(qemuCaps, &tpmCaps); diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 8629503e11..2d0bc99c73 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1212,7 +1212,7 @@ get_files(vahControl * ctl) =20 shortName =3D virDomainDefGetShortName(ctl->def); =20 - switch (ctl->def->tpms[i]->version) { + switch (ctl->def->tpms[i]->data.emulator.version) { case VIR_DOMAIN_TPM_VERSION_1_2: tpmpath =3D "tpm1.2"; break; --=20 2.35.1 From nobody Fri May 17 02:03:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1658136745; cv=none; d=zohomail.com; s=zohoarc; b=cklUsPqbrL1W0bVW+3yZanuBh2lGdXRlyCmKmJm6r3n/0fva0QplWM1RWvSzGokn3AXofZhjmTItUG+HWjkIuaUlReKBrCzHPIHn3AT0dZkC7jf58eei0ENc/swx6ukzwKJeIPP8nLZjPDOCfx+R2y+Kaz5sRuM+Nk+r/06xCGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136745; 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=7b+WiEFf9fxAlmMwB4QRhYC+vOY+4sdVbaUtaFZE4fE=; b=gl6LTh1kvPzs86f1YsnuZwVxGZ4jbE0DAgaMu6ZbMUM+M4diYpqhsGoQq8UFskFWDDfNvterBx/F56JN6/E9/mfOczam4HsqLrLvg6+PZazniB048tNzSVGxKIvne2zRlpFHz96Ad98htCXpap0DMRkxFjN4S+kTSs8TP4gs+Ts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 165813674500351.661232289986174; Mon, 18 Jul 2022 02:32:25 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-377-eHlR6z-vPt6xkKhRXRQyrw-1; Mon, 18 Jul 2022 05:30:59 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E323529DD9AC; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C85AE492C3B; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 800121947065; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6649C1947075 for ; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3FD812166B2A; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id E04092166B26 for ; Mon, 18 Jul 2022 09:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136744; 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=7b+WiEFf9fxAlmMwB4QRhYC+vOY+4sdVbaUtaFZE4fE=; b=T+8OXpxK7Ece7uNGVm3tX9tdJWGYjoTzIgv/zLdIQH5j2+jRg9ml0Yw4WlI+BYB8byVQhq 0dACBwrT/Ro7p4BeUA/YG3jEShu9S9ZNk8awt7Wvbym+WD2de5kvV9pBcKhzlE8XAfvnp2 r0E1J5Vsqhlnyh4fbUkSRdQSRUXFHeo= X-MC-Unique: eHlR6z-vPt6xkKhRXRQyrw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/8] conf: Use virXMLPropEnum more when parsing TPM Date: Mon, 18 Jul 2022 11:30:47 +0200 Message-Id: <44ef366882685c1520480244acc4d0202f2735cd.1658136603.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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: 1658136746502100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When parsing a TPM device plenty of virXMLPropString() + enum2int() combos are used. These can be replaced with virXMLPropEnum(). Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 39 ++++++++++++--------------------------- src/conf/domain_conf.h | 6 +++--- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 2 +- 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 28f0e75e60..6263d90fdb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10347,9 +10347,6 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, int nnodes; size_t i; g_autofree char *path =3D NULL; - g_autofree char *model =3D NULL; - g_autofree char *backend =3D NULL; - g_autofree char *version =3D NULL; g_autofree char *secretuuid =3D NULL; g_autofree char *persistent_state =3D NULL; g_autofree xmlNodePtr *backends =3D NULL; @@ -10358,13 +10355,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, =20 def =3D g_new0(virDomainTPMDef, 1); =20 - model =3D virXMLPropString(node, "model"); - if (model !=3D NULL && - (def->model =3D virDomainTPMModelTypeFromString(model)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown TPM frontend model '%s'"), model); + if (virXMLPropEnum(node, "model", + virDomainTPMModelTypeFromString, + VIR_XML_PROP_NONZERO, + &def->model) < 0) goto error; - } =20 ctxt->node =3D node; =20 @@ -10383,18 +10378,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, goto error; } =20 - if (!(backend =3D virXMLPropString(backends[0], "type"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing TPM device backend type")); + if (virXMLPropEnum(backends[0], "type", + virDomainTPMBackendTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->type) < 0) goto error; - } - - if ((def->type =3D virDomainTPMBackendTypeFromString(backend)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown TPM backend type '%s'"), - backend); - goto error; - } =20 switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: @@ -10407,14 +10395,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, def->data.passthrough.source->data.file.path =3D g_steal_pointer(&= path); break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: - version =3D virXMLPropString(backends[0], "version"); - if (version && - (def->data.emulator.version =3D virDomainTPMVersionTypeFromStr= ing(version)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported TPM version '%s'"), - version); + if (virXMLPropEnum(backends[0], "version", + virDomainTPMVersionTypeFromString, + VIR_XML_PROP_NONZERO, + &def->data.emulator.version) < 0) goto error; - } =20 if (!(def->data.emulator.source =3D virDomainChrSourceDefNew(xmlop= t))) goto error; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3362042db5..bab667d026 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1436,15 +1436,15 @@ typedef enum { #define VIR_DOMAIN_TPM_DEFAULT_DEVICE "/dev/tpm0" =20 struct _virDomainTPMDef { - int type; /* virDomainTPMBackendType */ + virDomainTPMModel model; + virDomainTPMBackendType type; virDomainDeviceInfo info; - int model; /* virDomainTPMModel */ union { struct { virDomainChrSourceDef *source; } passthrough; struct { - int version; /* virDomainTPMVersion */ + virDomainTPMVersion version; virDomainChrSourceDef *source; char *storagepath; char *logfile; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 262fffe5fe..93ea8748c7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9840,7 +9840,7 @@ qemuBuildTPMCommandLine(virCommand *cmd, g_autoptr(qemuFDPass) passtpm =3D NULL; g_autoptr(qemuFDPass) passcancel =3D NULL; =20 - switch ((virDomainTPMBackendType) tpm->type) { + switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: { VIR_AUTOCLOSE fdtpm =3D -1; VIR_AUTOCLOSE fdcancel =3D -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0343fd3597..09fc88e7fa 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11752,7 +11752,7 @@ qemuDomainDeviceBackendChardevForeachOne(virDomainD= eviceDef *dev, return cb(dev, dev->data.rng->source.chardev, opaque); =20 case VIR_DOMAIN_DEVICE_TPM: - switch ((virDomainTPMBackendType) dev->data.tpm->type) { + switch (dev->data.tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: return cb(dev, dev->data.tpm->data.passthrough.source, opaque); =20 --=20 2.35.1 From nobody Fri May 17 02:03:09 2024 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=1658136664; cv=none; d=zohomail.com; s=zohoarc; b=adkz50m+PDwUlxlFkIWSuIvhOh9SsdHMIWGFuUk63FvFpMwarvEPduRoyKoimepG1EJmRiHP8lI148yIZasoUk0NRNjARmuMWgUoK0fSPucFhExxqrAEdluJAJ1PNwnl5ZQLRbu1qeO/okHdm9Kum5pT8kRVX30BQHUEsE/eK3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136664; 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=l6NFFll1080zIZn4/O85SiEDuxuvn1RfLH6k603bJM8=; b=U44olgfs5EDw6P6KQb2K2fEjtnoJIc4nJxwOP0/sa1Fwk72b1fYNfVfla0Bk0fV/UVHHzowX7wiLDsu4YfJwENfqAXQUT6v5OqTNkGi7+nMCpiAFM9bSoQ87NZze4ZcxmZGZUHDj8k6WChP5Feg2gODhxl6/t52XhX732tyfrbg= 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 1658136664698637.1726376340443; Mon, 18 Jul 2022 02:31:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-642-C7DBV_jzNHukSMUO02EK6g-1; Mon, 18 Jul 2022 05:30:58 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 550071C06EC5; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43063141511F; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2D42C1947056; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D6F3E194705C for ; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CB4262166B29; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 770EB2166B26 for ; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136663; 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=l6NFFll1080zIZn4/O85SiEDuxuvn1RfLH6k603bJM8=; b=ac5p8LS8Kr87Tpn6dlNU4fpO6aSYQTqtNI1fwxJgKJM4pWE5CCjTI5CZEqoV1cre8ZWCZk bSO7OX8wlcg/+jYpTnj9HqBFv5sFxAM4/kVvXpV8pPE9je6jat45NcrGE6bSDWJLoLXBb5 yQrDq2FneD3zp5HvxthrgP+oytdY/Ug= X-MC-Unique: C7DBV_jzNHukSMUO02EK6g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/8] qemu_domain: Move TPM post parse code into qemuDomainTPMDefPostParse() Date: Mon, 18 Jul 2022 11:30:48 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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: 1658136666097100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In the qemuDomainDefPostParse() we aim to fill in top level values, which require overall view of domain, or those parts of configuration that are not a device in domain XML (e.g. vCPUs). However, inside of qemuDomainDefTPMsPostParse(), which is called from aforementioned function, we do two tings: 1) fill in missing info (TPM version), and 2) validate TPM definition. Now, if 1) is moved into qemuDomainTPMDefPostParse() (the device post parse callback), then 2) can be moved into validation step. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 09fc88e7fa..bcee4d2602 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4593,17 +4593,6 @@ qemuDomainDefTPMsPostParse(virDomainDef *def) for (i =3D 0; i < def->ntpms; i++) { virDomainTPMDef *tpm =3D def->tpms[i]; =20 - /* TPM 1.2 and 2 are not compatible, so we choose a specific versi= on here */ - if (tpm->type =3D=3D VIR_DOMAIN_TPM_TYPE_EMULATOR && - tpm->data.emulator.version =3D=3D VIR_DOMAIN_TPM_VERSION_DEFAU= LT) { - if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR || - tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_CRB || - qemuDomainIsARMVirt(def)) - tpm->data.emulator.version =3D VIR_DOMAIN_TPM_VERSION_2_0; - else - tpm->data.emulator.version =3D VIR_DOMAIN_TPM_VERSION_1_2; - } - if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) { if (proxyTPM) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -5806,15 +5795,26 @@ qemuDomainHostdevDefPostParse(virDomainHostdevDef *= hostdev, =20 static int qemuDomainTPMDefPostParse(virDomainTPMDef *tpm, - virArch arch) + const virDomainDef *def) { if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_DEFAULT) { - if (ARCH_IS_PPC64(arch)) + if (ARCH_IS_PPC64(def->os.arch)) tpm->model =3D VIR_DOMAIN_TPM_MODEL_SPAPR; else tpm->model =3D VIR_DOMAIN_TPM_MODEL_TIS; } =20 + /* TPM 1.2 and 2 are not compatible, so we choose a specific version h= ere */ + if (tpm->type =3D=3D VIR_DOMAIN_TPM_TYPE_EMULATOR && + tpm->data.emulator.version =3D=3D VIR_DOMAIN_TPM_VERSION_DEFAULT) { + if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR || + tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_CRB || + qemuDomainIsARMVirt(def)) + tpm->data.emulator.version =3D VIR_DOMAIN_TPM_VERSION_2_0; + else + tpm->data.emulator.version =3D VIR_DOMAIN_TPM_VERSION_1_2; + } + return 0; } =20 @@ -5941,7 +5941,7 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDef *dev, break; =20 case VIR_DOMAIN_DEVICE_TPM: - ret =3D qemuDomainTPMDefPostParse(dev->data.tpm, def->os.arch); + ret =3D qemuDomainTPMDefPostParse(dev->data.tpm, def); break; =20 case VIR_DOMAIN_DEVICE_MEMORY: --=20 2.35.1 From nobody Fri May 17 02:03:09 2024 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=1658136726; cv=none; d=zohomail.com; s=zohoarc; b=Kuq2zKQEuI96nbq4azfeoBO3K96C9wHe8KTEn8F1/c5NaQjZJTeLQsEV8bbwVucgwvOYo+Yz/67l2gN7+bTaDZisQp5VtYu9udtCUfY/4mJ9/qEcS5qR6UvCs8EBiIZrp79dSsfyPjCFvFv+Ds9cLKdlBdbQOGLvcQf4+b9qhMw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136726; 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=H/GwXXEx9omzhlOhGeBxiuvlQTjdXNCr8YE1HUc2Rew=; b=C6PkJ/cBOQlc4UDOxZtRM4xtiP4tsnJKJBYVVFSgdK0Y9rhdFeBNVR8bat15FSgU/2UZFRGT16A7aArvKMOuK6lNg6X1BOGmlaSduWG48wqguaNyf5aRhYDartVXzYVFMeklPWQiNYkUcnXauxZ/KYp+CdSbnIA/UWI2sAJTfz4= 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 1658136726346569.5393441322857; Mon, 18 Jul 2022 02:32:06 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-610-2ZrPmfC8P32JrM9T-ib73Q-1; Mon, 18 Jul 2022 05:31:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 56B6A296A602; Mon, 18 Jul 2022 09:30:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4248D2166B29; Mon, 18 Jul 2022 09:30:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 09D491947054; Mon, 18 Jul 2022 09:30:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7DA461947063 for ; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 61E7C2166B29; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DD5E2166B26 for ; Mon, 18 Jul 2022 09:30:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136725; 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=H/GwXXEx9omzhlOhGeBxiuvlQTjdXNCr8YE1HUc2Rew=; b=AKNLa3MCE2Ok3fRnn/DjygNAu17iYfjCMXnBOqX7MlxCBMF/O9M8uFycbhEu3yqoLfk02v 3WAqOTDWzOU9yecZsT8kqyRKbOlo0yzJXqDrbQci5HdYEP1ZNzkS+cFZyz+3WqBV7H4jd6 JvI1Ei0cZVUeGxdjex/FBO5yvkuUNJY= X-MC-Unique: 2ZrPmfC8P32JrM9T-ib73Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 7/8] qemu: Move TPMs validation out of PostParse Date: Mon, 18 Jul 2022 11:30:49 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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: 1658136728376100001 Content-Type: text/plain; charset="utf-8"; x-default="true" After previous cleanup, the qemuDomainDefTPMsPostParse() function does nothing more than validates TPM devices. Therefore, it should live in qemu_validate.c instead of qemu_domain.c. Move it there and rename to reflect the fact that the function is doing validation instead of PostParsing. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 34 ---------------------------------- src/qemu/qemu_validate.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index bcee4d2602..e3d1bb548f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4583,37 +4583,6 @@ qemuDomainDefNumaCPUsPostParse(virDomainDef *def, } =20 =20 -static int -qemuDomainDefTPMsPostParse(virDomainDef *def) -{ - virDomainTPMDef *proxyTPM =3D NULL; - virDomainTPMDef *regularTPM =3D NULL; - size_t i; - - for (i =3D 0; i < def->ntpms; i++) { - virDomainTPMDef *tpm =3D def->tpms[i]; - - if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) { - if (proxyTPM) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("only a single TPM Proxy device is suppor= ted")); - return -1; - } else { - proxyTPM =3D tpm; - } - } else if (regularTPM) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("only a single TPM non-proxy device is suppor= ted")); - return -1; - } else { - regularTPM =3D tpm; - } - } - - return 0; -} - - static int qemuDomainDefPostParseBasic(virDomainDef *def, void *opaque G_GNUC_UNUSED) @@ -4709,9 +4678,6 @@ qemuDomainDefPostParse(virDomainDef *def, if (qemuDomainDefNumaCPUsPostParse(def, qemuCaps) < 0) return -1; =20 - if (qemuDomainDefTPMsPostParse(def) < 0) - return -1; - return 0; } =20 diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index ff164118b7..ce8f92f301 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1113,6 +1113,37 @@ qemuValidateDomainDefPanic(const virDomainDef *def, } =20 =20 +static int +qemuValidateDomainDefTPMs(const virDomainDef *def) +{ + const virDomainTPMDef *proxyTPM =3D NULL; + const virDomainTPMDef *regularTPM =3D NULL; + size_t i; + + for (i =3D 0; i < def->ntpms; i++) { + virDomainTPMDef *tpm =3D def->tpms[i]; + + if (tpm->model =3D=3D VIR_DOMAIN_TPM_MODEL_SPAPR_PROXY) { + if (proxyTPM) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only a single TPM Proxy device is suppor= ted")); + return -1; + } else { + proxyTPM =3D tpm; + } + } else if (regularTPM) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only a single TPM non-proxy device is suppor= ted")); + return -1; + } else { + regularTPM =3D tpm; + } + } + + return 0; +} + + int qemuValidateLifecycleAction(virDomainLifecycleAction onPoweroff, virDomainLifecycleAction onReboot, @@ -1310,6 +1341,9 @@ qemuValidateDomainDef(const virDomainDef *def, if (qemuValidateDomainDefPanic(def, qemuCaps) < 0) return -1; =20 + if (qemuValidateDomainDefTPMs(def) < 0) + return -1; + if (def->sec) { switch ((virDomainLaunchSecurity) def->sec->sectype) { case VIR_DOMAIN_LAUNCH_SECURITY_SEV: --=20 2.35.1 From nobody Fri May 17 02:03:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1658136748; cv=none; d=zohomail.com; s=zohoarc; b=e5Sg8ZJVWmL9JG4SO9q6MPyyLDQbCMDxWI8Xt5ht5OliRSgBLuSK5jNENH5A6692kVSKSg9IzINQy2xZRoW1WrHHCUSMVR1Jk25kUNLfv9Qs1LsSm5mXSp88mXWTMKz9N/CDovLS9iX2uaKuMPoS6U54rIsyncxnZiMr2EzXlDs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658136748; 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=AYDJv017N1g0pO/RxrTarGOr6W/XFbH0zhFqNXtuiZ4=; b=OZhwh8D8uPlS22Nftr/OLFXxetNfta+pIvNibnVEps9vRshMmZEO3M3joq3hPcLE/br95UjbSSMoFBwXSHPFj8Ad8DITvJA5FMrVGQTS80x/VwJYoePyE3U8H5NOkVSGQVQe+03VuClo3dc9M7xapfxC2+nv4uU7anLFGMLz92c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1658136748137198.9127312556575; Mon, 18 Jul 2022 02:32:28 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-169-ypuFyG6qMGO6TueCwxOUvg-1; Mon, 18 Jul 2022 05:31:01 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E8C1E8527A2; Mon, 18 Jul 2022 09:30:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D065E403162; Mon, 18 Jul 2022 09:30:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6DA3F1947062; Mon, 18 Jul 2022 09:30:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0604C1947065 for ; Mon, 18 Jul 2022 09:30:57 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id ED8622166B29; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98B5A2166B26 for ; Mon, 18 Jul 2022 09:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658136746; 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=AYDJv017N1g0pO/RxrTarGOr6W/XFbH0zhFqNXtuiZ4=; b=DlnnNlQaQWOcRbz1vwCVNcsDZK81iXoGPWQsrQFns+4cHH2Pm//ImQYar7fk1tNjDM4lNw +vEvhnjT5Pz/IREMB2IfYspU1xrXht8qL0yfL7yE69RK4KZqnmnYk6dg4AdJkaHmyPpDog qqltblf8KH8rSfs/kb4pRb9+t3xYPmY= X-MC-Unique: ypuFyG6qMGO6TueCwxOUvg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 8/8] conf: Don't lose when no TPM version is provided Date: Mon, 18 Jul 2022 11:30:50 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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: 1658136748511100003 Content-Type: text/plain; charset="utf-8"; x-default="true" When no TPM version is provided in the input XML we may default to version 2.0 (see qemuDomainTPMDefPostParse()). However, are parsed iff a version 2.0 was specified. This means that this piece of information might be lost. It's better to parse everything we've been given and then validate that the configuration is valid. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2084046 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 21 ++++++++++----------- src/conf/domain_validate.c | 28 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6263d90fdb..610fa5262b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10422,18 +10422,17 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlop= t, goto error; } } - if (def->data.emulator.version =3D=3D VIR_DOMAIN_TPM_VERSION_2_0) { - if ((nnodes =3D virXPathNodeSet("./backend/active_pcr_banks/*"= , ctxt, &nodes)) < 0) - break; - for (i =3D 0; i < nnodes; i++) { - if ((bank =3D virDomainTPMPcrBankTypeFromString((const cha= r *)nodes[i]->name)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported PCR banks '%s'"), - nodes[i]->name); - goto error; - } - def->data.emulator.activePcrBanks |=3D (1 << bank); + + if ((nnodes =3D virXPathNodeSet("./backend/active_pcr_banks/*", ct= xt, &nodes)) < 0) + break; + for (i =3D 0; i < nnodes; i++) { + if ((bank =3D virDomainTPMPcrBankTypeFromString((const char *)= nodes[i]->name)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Unsupported PCR banks '%s'"), + nodes[i]->name); + goto error; } + def->data.emulator.activePcrBanks |=3D (1 << bank); } break; case VIR_DOMAIN_TPM_TYPE_LAST: diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 814922cd46..8d4a69f127 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2611,6 +2611,30 @@ virDomainIOMMUDefValidate(const virDomainIOMMUDef *i= ommu) return 0; } =20 + +static int +virDomainTPMDevValidate(const virDomainTPMDef *tpm) +{ + switch (tpm->type) { + case VIR_DOMAIN_TPM_TYPE_EMULATOR: + if (tpm->data.emulator.activePcrBanks && + tpm->data.emulator.version !=3D VIR_DOMAIN_TPM_VERSION_2_0) { + virReportError(VIR_ERR_XML_ERROR, + _(" requires TPM version '%s= '"), + virDomainTPMVersionTypeToString(VIR_DOMAIN_TPM_= VERSION_2_0)); + return -1; + } + break; + + case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: + case VIR_DOMAIN_TPM_TYPE_LAST: + break; + } + + return 0; +} + + static int virDomainDeviceInfoValidate(const virDomainDeviceDef *dev) { @@ -2715,12 +2739,14 @@ virDomainDeviceDefValidateInternal(const virDomainD= eviceDef *dev, case VIR_DOMAIN_DEVICE_IOMMU: return virDomainIOMMUDefValidate(dev->data.iommu); =20 + case VIR_DOMAIN_DEVICE_TPM: + return virDomainTPMDevValidate(dev->data.tpm); + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_WATCHDOG: case VIR_DOMAIN_DEVICE_HUB: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: - case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: --=20 2.35.1