From nobody Thu Mar 28 20:50:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498698738409401.1135542521549; Wed, 28 Jun 2017 18:12:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA70474846; Thu, 29 Jun 2017 01:12:14 +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 F3AF795BA9; Thu, 29 Jun 2017 01:12:12 +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 4FF5D1800C8A; Thu, 29 Jun 2017 01:12:11 +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 v5T1CAwl014850 for ; Wed, 28 Jun 2017 21:12:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2C5ED95BA5; Thu, 29 Jun 2017 01:12:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2455B95BA0 for ; Thu, 29 Jun 2017 01:12:08 +0000 (UTC) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 585EA4E4CB for ; Thu, 29 Jun 2017 01:12:06 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 5230D20AC9; Wed, 28 Jun 2017 21:12:05 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Wed, 28 Jun 2017 21:12:05 -0400 Received: from devel-3rdparty.localdomain (89-70-103-23.dynamic.chello.pl [89.70.103.23]) by mail.messagingengine.com (Postfix) with ESMTPA id 951412436B; Wed, 28 Jun 2017 21:12:04 -0400 (EDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CA70474846 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CA70474846 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EBa34e1S" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 585EA4E4CB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=marmarek@invisiblethingslab.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 585EA4E4CB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:in-reply-to :message-id:references:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=7iAo6fJkRfYHEJ0KPB Y6W1F+vMGK0x0pWLYz/rVCCKY=; b=EBa34e1SC5uvJOMtHwo1rcbvjJbcnHVQCI xh4wjbxDx/15JjLDqrnl6YWZQpY2/4aTxW3c2LBK9JzkgkmC9z06OfVvVDGeE7LL nmt7oIvsGjPPCKNZeUe303TFlCtzEkEhQHbtfDqszEkLLWPRD9DoZss9+1puYbXu 48yj32ZUIKPBTvEtiJ4J48Q4Rs95bW+lkiNDdeMcFTHzqkrhLmbloQQOCEAZ6K1J V7hZKUIcoBFaHWLdsxGRRTOPlJs+l/+rwHbS3QONvNGR3J1VKlFhXPBBuWMTbZup GmjsxhEqz3zeCIhx1a7jv3xl+1KJFJagluxfWe7cwmklTk4jh+wA== X-ME-Sender: X-Sasl-enc: AGn/l+n+5hFYq3VErtH5h/q9hSPAVCbjWzB56oZjIRUb 1498698724 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: libvir-list@redhat.com Date: Thu, 29 Jun 2017 03:11:41 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 29 Jun 2017 01:12:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 29 Jun 2017 01:12:06 +0000 (UTC) for IP:'66.111.4.29' DOMAIN:'out5-smtp.messagingengine.com' HELO:'out5-smtp.messagingengine.com' FROM:'marmarek@invisiblethingslab.com' RCPT:'' X-RedHat-Spam-Score: -0.3 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW) 66.111.4.29 out5-smtp.messagingengine.com 66.111.4.29 out5-smtp.messagingengine.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] cpu: define sub-leaf 0 for leaf 7 in cpu_map.xml 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 29 Jun 2017 01:12:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" CPUID leaf 7 is sub-leaf aware. Add missing attribute. --- src/cpu/cpu_map.xml | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/cpu/cpu_map.xml b/src/cpu/cpu_map.xml index 29b5b59..037a057 100644 --- a/src/cpu/cpu_map.xml +++ b/src/cpu/cpu_map.xml @@ -195,93 +195,93 @@ =20 - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + =20 - + - + - + =20 - + - + =20 --=20 git-series 0.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:50:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498698737408824.2483075627016; Wed, 28 Jun 2017 18:12:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B5BDC057FA4; Thu, 29 Jun 2017 01:12:14 +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 AEF908138B; Thu, 29 Jun 2017 01:12:12 +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 62D644A492; Thu, 29 Jun 2017 01:12:11 +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 v5T1CAWB014849 for ; Wed, 28 Jun 2017 21:12:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B25895BA8; Thu, 29 Jun 2017 01:12:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24B6395BA5 for ; Thu, 29 Jun 2017 01:12:08 +0000 (UTC) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7B4F7CE0A for ; Thu, 29 Jun 2017 01:12:06 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 452F820AF5; Wed, 28 Jun 2017 21:12:06 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Wed, 28 Jun 2017 21:12:06 -0400 Received: from devel-3rdparty.localdomain (89-70-103-23.dynamic.chello.pl [89.70.103.23]) by mail.messagingengine.com (Postfix) with ESMTPA id 63BD82424E; Wed, 28 Jun 2017 21:12:05 -0400 (EDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7B5BDC057FA4 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7B5BDC057FA4 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mUHbSMcD" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D7B4F7CE0A Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=marmarek@invisiblethingslab.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D7B4F7CE0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:in-reply-to :message-id:references:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=VILYDz+oN1H2uTtRuV bHIwyv1T1XvT1NbNQdA7LttrQ=; b=mUHbSMcDttMtZQjrcq3gpVgp87u8ziVBJs 14liGd3QqHeP2zue19cneOR1HZhlxDOVi86eZGv7BjKd79oJEk69U1bvwHl8nhiS +Dt60xMy/mibwyC9YLXPLfnlRHUof0OWnyyNohcKrinW2almAiGvf7kP/sI1wNoV 3xTt3uD3lRD0wQLlYMSYl/LGFJjevN3VDOT6niztZqmwSEPy9oGVw6BO5fZiePoa dqOs86XXVQGmPpGtwaFYAGPECRd0rZYvVYiihCMDqL77jTdQJNJFo1/a8dpzANmK iAtIJ+x1c8s7ut5QNnRPuIbdze+v1PrPfJKEs0el2DFsc9grK79Q== X-ME-Sender: X-Sasl-enc: wx/NwEPRyyPnbI+ZhI9F1KDDxRW69L+b7yKT0M3GrEet 1498698725 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: libvir-list@redhat.com Date: Thu, 29 Jun 2017 03:11:42 +0200 Message-Id: <4ce7927e2d0de905ee1ead436f6eef8f2651c6a1.1498698613.git-series.marmarek@invisiblethingslab.com> In-Reply-To: References: In-Reply-To: References: X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 29 Jun 2017 01:12:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 29 Jun 2017 01:12:07 +0000 (UTC) for IP:'66.111.4.29' DOMAIN:'out5-smtp.messagingengine.com' HELO:'out5-smtp.messagingengine.com' FROM:'marmarek@invisiblethingslab.com' RCPT:'' X-RedHat-Spam-Score: -0.3 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW) 66.111.4.29 out5-smtp.messagingengine.com 66.111.4.29 out5-smtp.messagingengine.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] libxl: add support for CPUID features policy 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 29 Jun 2017 01:12:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Set CPU features in appropriate libxl structure. Use old "xend" syntax, because it allow control over any bit and libvirt already have API for translating features to appropriate cpuid bits. And also features naming in libxl do not match the one of libvirt in multiple cases. Side effect is that all the bits derived from CPU (which is required anyway) are also set as "required". Libxl do not have distinction between "force" and "required" policy (there is only "force") and also between "forbid" and "disable" (there is only "disable"). So, merge them appropriately. If anything, "require" and "forbid" should be enforced outside of specific driver. --- src/libxl/libxl_conf.c | 139 ++++++++++++++++++++++++++++++++++-------- src/libxl/libxl_conf.h | 1 +- 2 files changed, 116 insertions(+), 24 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 938e09d..4c400f4 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -291,6 +291,93 @@ libxlMakeChrdevStr(virDomainChrDefPtr def, char **buf) return 0; } =20 +static int libxlMakeCPUID(virArch arch, + const virCPUDef *cpu, + libxl_cpuid_policy_list *cpuid) +{ + virCPUDataPtr cpu_policy[4]; + /* forced, required, disabled, forbidden */ + char libxl_policy_char[4] =3D { '1', '1', '0', '0' }; + int leaf, subleaf, reg; + size_t i, j; + char leaf_text[48]; + char *reg_text; + int policy_index =3D 0; + uint32_t reg_value; + int ret =3D -1; + int cpuid_bit; + /* supported values, based on libxl_cpuid.c */ + int leafs[] =3D { 1, 6, 7, 0x80000001 }; + int subleafs[] =3D { -1, -1, 0, -1 }; + + if (cpuEncode(arch, + cpu, + &cpu_policy[0], + &cpu_policy[1], + NULL, + &cpu_policy[2], + &cpu_policy[3], + NULL)) + return -1; + + for (i =3D 0; i < sizeof(leafs)/sizeof(*leafs); i++) { + leaf =3D leafs[i]; + subleaf =3D subleafs[i]; + + for (reg =3D 0; reg < 4; reg++) { + if (subleaf !=3D -1) + snprintf(leaf_text, sizeof(leaf_text), + "%#x,%d:e%cx=3D" LIBXL_DEFAULT_CPUID_REG_CONFIG, + leaf, subleaf, 'a'+reg); + else + snprintf(leaf_text, sizeof(leaf_text), + "%#x:e%cx=3D" LIBXL_DEFAULT_CPUID_REG_CONFIG, + leaf, 'a'+reg); + + reg_text =3D strstr(leaf_text, "=3D") + 1; + + for (policy_index =3D 0; policy_index < 4; policy_index++) { + /* search for this leaf in CPUData structure */ + for (j =3D 0; j < cpu_policy[policy_index]->data.x86.len; = j++) { + virCPUx86CPUID *cpuid_policy =3D + &cpu_policy[policy_index]->data.x86.data[j]; + + if (cpuid_policy->eax_in =3D=3D leaf && + (subleaf =3D=3D -1 || cpuid_policy->ecx_in =3D= =3D subleaf)) { + + switch (reg) { + case 0: reg_value =3D cpuid_policy->eax; break; + case 1: reg_value =3D cpuid_policy->ebx; break; + case 2: reg_value =3D cpuid_policy->ecx; break; + case 3: reg_value =3D cpuid_policy->edx; break; + } + + for (cpuid_bit =3D 0; cpuid_bit < 32; cpuid_bit++)= { + if (reg_value & (1<features[VIR_DOMAIN_FEATURE_ACPI] =3D=3D VIR_TRISTATE_SWITCH_ON); =20 - if (caps && - def->cpu && def->cpu->mode =3D=3D (VIR_CPU_MODE_HOST_PASSTHROU= GH)) { - bool hasHwVirt =3D false; - bool svm =3D false, vmx =3D false; + if (caps && def->cpu) { + if (def->cpu->mode =3D=3D (VIR_CPU_MODE_HOST_PASSTHROUGH)) { + bool hasHwVirt =3D false; + bool svm =3D false, vmx =3D false; =20 - if (ARCH_IS_X86(def->os.arch)) { - vmx =3D virCPUCheckFeature(caps->host.arch, caps->host.cpu= , "vmx"); - svm =3D virCPUCheckFeature(caps->host.arch, caps->host.cpu= , "svm"); - hasHwVirt =3D vmx | svm; - } + if (ARCH_IS_X86(def->os.arch)) { + vmx =3D virCPUCheckFeature(caps->host.arch, caps->host= .cpu, "vmx"); + svm =3D virCPUCheckFeature(caps->host.arch, caps->host= .cpu, "svm"); + hasHwVirt =3D vmx | svm; + } =20 - if (def->cpu->nfeatures) { - for (i =3D 0; i < def->cpu->nfeatures; i++) { + if (def->cpu->nfeatures) { + for (i =3D 0; i < def->cpu->nfeatures; i++) { =20 - switch (def->cpu->features[i].policy) { + switch (def->cpu->features[i].policy) { =20 - case VIR_CPU_FEATURE_DISABLE: - case VIR_CPU_FEATURE_FORBID: - if ((vmx && STREQ(def->cpu->features[i].name, = "vmx")) || - (svm && STREQ(def->cpu->features[i].name, = "svm"))) - hasHwVirt =3D false; - break; + case VIR_CPU_FEATURE_DISABLE: + case VIR_CPU_FEATURE_FORBID: + if ((vmx && STREQ(def->cpu->features[i].na= me, "vmx")) || + (svm && STREQ(def->cpu->features[i].na= me, "svm"))) + hasHwVirt =3D false; + break; =20 - case VIR_CPU_FEATURE_FORCE: - case VIR_CPU_FEATURE_REQUIRE: - case VIR_CPU_FEATURE_OPTIONAL: - case VIR_CPU_FEATURE_LAST: - break; + case VIR_CPU_FEATURE_FORCE: + case VIR_CPU_FEATURE_REQUIRE: + case VIR_CPU_FEATURE_OPTIONAL: + case VIR_CPU_FEATURE_LAST: + break; + } } } + libxl_defbool_set(&b_info->u.hvm.nested_hvm, hasHwVirt); } - libxl_defbool_set(&b_info->u.hvm.nested_hvm, hasHwVirt); + + if (libxlMakeCPUID(def->os.arch, def->cpu, &b_info->cpuid)) + return -1; } =20 if (def->nsounds > 0) { diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 264df11..8d89ccd 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -60,6 +60,7 @@ # define LIBXL_DUMP_DIR LIBXL_LIB_DIR "/dump" # define LIBXL_CHANNEL_DIR LIBXL_LIB_DIR "/channel/target" # define LIBXL_BOOTLOADER_PATH "pygrub" +# define LIBXL_DEFAULT_CPUID_REG_CONFIG "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" =20 =20 typedef struct _libxlDriverPrivate libxlDriverPrivate; --=20 git-series 0.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Mar 28 20:50:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 14986987502591.5003142919716765; Wed, 28 Jun 2017 18:12:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 3457B81127; Thu, 29 Jun 2017 01:12:28 +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 CD4D5757AF; Thu, 29 Jun 2017 01:12:27 +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 06CD71853E2F; Thu, 29 Jun 2017 01:12:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5T1CHjd014881 for ; Wed, 28 Jun 2017 21:12:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id F28CE8189A; Thu, 29 Jun 2017 01:12:16 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E78788138B for ; Thu, 29 Jun 2017 01:12:15 +0000 (UTC) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B60140F1B for ; Thu, 29 Jun 2017 01:12:08 +0000 (UTC) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 137FE20B20; Wed, 28 Jun 2017 21:12:07 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Wed, 28 Jun 2017 21:12:07 -0400 Received: from devel-3rdparty.localdomain (89-70-103-23.dynamic.chello.pl [89.70.103.23]) by mail.messagingengine.com (Postfix) with ESMTPA id 5E5D72424E; Wed, 28 Jun 2017 21:12:06 -0400 (EDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3457B81127 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3457B81127 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="RT5wUea/" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0B60140F1B Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=marmarek@invisiblethingslab.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0B60140F1B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:in-reply-to:message-id:mime-version :references:references:subject:to:x-me-sender:x-me-sender :x-sasl-enc:x-sasl-enc; s=fm1; bh=gvSyzLkXCdgVVBPeW+vDrNoxaNaqHf SIvc+4JZUWjz8=; b=RT5wUea/o7xqlZeUgA6gDrjn9BUj9v+AEg5AU984YLcJTh NV34J7MMh0hVl469/5xeS7cmmNg6XGRTLy8m9rShTytcRSC/AGJhbIERCkkIxDk0 4nhEAeQrqhvILBfOD97QoT28ox/C6o8DBq2gpFjUkMP2aWK/931BTshx7YCojv3N uQq4F8WYIzQ/geE+5ozYOidsNwCbhgTAiKZ3TgUr6tmWFbxrBIpOQ2fPRW0WSDOH CPBtKlv3frhKVOF2r3n6G2nKb/JYS4fBi1Lw9OjdrAEhVVaX8K/d2EpDXfj4DCjP 7gtIyUciObNJ40fDXMgCn9ie4rJukfvbKjY7Tlkg== X-ME-Sender: X-Sasl-enc: //36ZNv00y1WoOmADJUalj311WTlc8geaokxlLYHB8bW 1498698726 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: libvir-list@redhat.com Date: Thu, 29 Jun 2017 03:11:43 +0200 Message-Id: <867ed30d1527ee7b07da9ec2f181399f1f28466e.1498698613.git-series.marmarek@invisiblethingslab.com> In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Jun 2017 01:12:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 29 Jun 2017 01:12:08 +0000 (UTC) for IP:'66.111.4.29' DOMAIN:'out5-smtp.messagingengine.com' HELO:'out5-smtp.messagingengine.com' FROM:'marmarek@invisiblethingslab.com' RCPT:'' X-RedHat-Spam-Score: -0.3 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW) 66.111.4.29 out5-smtp.messagingengine.com 66.111.4.29 out5-smtp.messagingengine.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] tests: check domain XML to libxl structures conversion 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 29 Jun 2017 01:12:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 libxl contains a method to dump libxl_domain_config in json format, which is really convenient for tests. Unfortunately it require libxl_ctx, which can be only created when running on Xen (wither in dom0 or domU). Because of this, skip the test in other cases. For now, have just two tests, including just-introduced CPUID handling, but this commit introduces a framework for further tests of src/libxl/libxl_conf.c file. --- tests/Makefile.am | 8 +- tests/libxlxmltest.c | 232 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 tests/libxlxmltest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 19986dc..06c5c73 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -274,7 +274,7 @@ test_programs +=3D xml2sexprtest sexpr2xmltest \ endif WITH_XEN =20 if WITH_LIBXL -test_programs +=3D xlconfigtest +test_programs +=3D xlconfigtest libxlxmltest endif WITH_LIBXL =20 if WITH_QEMU @@ -528,9 +528,13 @@ libxl_LDADDS +=3D $(LDADDS) xlconfigtest_SOURCES =3D \ xlconfigtest.c testutilsxen.c testutilsxen.h \ testutils.c testutils.h +libxlxmltest_SOURCES =3D \ + libxlxmltest.c testutilsxen.c testutilsxen.h \ + testutils.c testutils.h xlconfigtest_LDADD =3D$(libxl_LDADDS) +libxlxmltest_LDADD =3D$(libxl_LDADDS) else ! WITH_LIBXL -EXTRA_DIST +=3D xlconfigtest.c +EXTRA_DIST +=3D xlconfigtest.c libxlxmltest.c endif ! WITH_LIBXL =20 QEMUMONITORTESTUTILS_SOURCES =3D \ diff --git a/tests/libxlxmltest.c b/tests/libxlxmltest.c new file mode 100644 index 0000000..7e11af4 --- /dev/null +++ b/tests/libxlxmltest.c @@ -0,0 +1,232 @@ +/* + * libxlxmltest.c: Test xl.cfg(5) <-> libxl_domain_config conversion + * + * Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc. + * Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Author: Daniel P. Berrange + * Author: Kiarie Kahurani + * Author: Marek Marczykowski-G=C3=B3recki + * + */ + +#include + +#include +#include +#include +#ifdef WITH_YAJL2 +# define HAVE_YAJL_V2 1 +#endif +#include +#include + +#include "internal.h" +#include "datatypes.h" +#include "viralloc.h" +#include "virstring.h" +#include "testutils.h" +#include "testutilsxen.h" +#include "libxl/libxl_conf.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +static virCapsPtr caps; +static virDomainXMLOptionPtr xmlopt; +xentoollog_logger_stdiostream *logger; +libxl_ctx *ctx; + + +/* + * This function provides a mechanism to replace variables in test + * data files whose values are discovered at built time. + */ +static char * +testReplaceVarsXML(const char *xml) +{ + char *xmlcfgData; + char *replacedXML; + + if (virTestLoadFile(xml, &xmlcfgData) < 0) + return NULL; + + replacedXML =3D virStringReplace(xmlcfgData, "/LIBXL_FIRMWARE_DIR", + LIBXL_FIRMWARE_DIR); + + /* libxl driver checks for emulator existence */ + replacedXML =3D virStringReplace(xmlcfgData, "/usr/lib/xen/bin/qemu-sy= stem-i386", + "/bin/true"); + + VIR_FREE(xmlcfgData); + return replacedXML; +} + +/* + * Parses domXML to virDomainDef object, which is then converted to json + * config and compared with expected config. + */ +static int +testCompareParseXML(const char *json, const char *xml, bool replaceVars) +{ + char *gotjsonData =3D NULL; + virConfPtr conf =3D NULL; + virConnectPtr conn =3D NULL; + size_t wrote =3D 0; + int ret =3D -1; + virDomainDefPtr def =3D NULL; + char *replacedXML =3D NULL; + virPortAllocatorPtr reservedGraphicsPorts =3D NULL; + libxl_domain_config d_config; + yajl_gen gen =3D NULL; + + conn =3D virGetConnect(); + if (!conn) goto fail; + + if (replaceVars) { + if (!(replacedXML =3D testReplaceVarsXML(xml))) + goto fail; + if (!(def =3D virDomainDefParseString(replacedXML, caps, xmlopt, + NULL, VIR_DOMAIN_XML_INACTIVE)= )) + goto fail; + } else { + if (!(def =3D virDomainDefParseFile(xml, caps, xmlopt, + NULL, VIR_DOMAIN_XML_INACTIVE))) + goto fail; + } + + if (!(reservedGraphicsPorts =3D virPortAllocatorNew("VNC", + LIBXL_VNC_PORT_MIN, + LIBXL_VNC_PORT_MAX, + 0))) + goto fail; + + if (libxlBuildDomainConfig(reservedGraphicsPorts, + def, + NULL, /* channelDir, unused in current version */ + ctx, + caps, + &d_config)) + goto fail; + + if (!(gen =3D libxl_yajl_gen_alloc(NULL))) + goto fail; + + if (libxl_domain_config_gen_json(gen, &d_config) !=3D yajl_gen_status_= ok) + goto fail; + + if (yajl_gen_get_buf(gen, + (const unsigned char **)&gotjsonData, + &wrote) !=3D yajl_gen_status_ok) + goto fail; + + if (virTestCompareToFile(gotjsonData, json) < 0) + goto fail; + + ret =3D 0; + + fail: + VIR_FREE(replacedXML); + // yajl_gen_free handle also gotjsonData + if (gen) + yajl_gen_free(gen); + if (conf) + virConfFree(conf); + virObjectUnref(reservedGraphicsPorts); + virDomainDefFree(def); + virObjectUnref(conn); + + return ret; +} + +struct testInfo { + const char *name; + bool replaceVars; +}; + +static int +testCompareHelper(const void *data) +{ + int result =3D -1; + const struct testInfo *info =3D data; + char *xml =3D NULL; + char *json =3D NULL; + + if (virAsprintf(&xml, "%s/xlconfigdata/test-%s.xml", + abs_srcdir, info->name) < 0 || + virAsprintf(&json, "%s/xlconfigdata/test-%s.json", + abs_srcdir, info->name) < 0) + goto cleanup; + + result =3D testCompareParseXML(json, xml, info->replaceVars); + + cleanup: + VIR_FREE(xml); + VIR_FREE(json); + + return result; +} + + +static int +mymain(void) +{ + int ret =3D 0; + + logger =3D xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); + if (!logger) + return EXIT_FAILURE; + + if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0, (xentoollog_logger*)logger= )) + return EXIT_AM_SKIP; + + if (!(caps =3D testXLInitCaps())) + return EXIT_FAILURE; + + if (!(xmlopt =3D libxlCreateXMLConf())) + return EXIT_FAILURE; + +#define DO_TEST_PARSE(name, replace) \ + do { \ + struct testInfo info0 =3D { name, replace }; \ + if (virTestRun("Xen XML-2-json Parse " name, \ + testCompareHelper, &info0) < 0) \ + ret =3D -1; \ + } while (0) + +#define DO_TEST(name) \ + do { \ + DO_TEST_PARSE(name, false); \ + } while (0) + +#define DO_TEST_REPLACE_VARS(name) \ + do { \ + DO_TEST_PARSE(name, true); \ + } while (0) + + DO_TEST_REPLACE_VARS("fullvirt-ovmf"); + + DO_TEST("fullvirt-cpuid"); + + virObjectUnref(caps); + virObjectUnref(xmlopt); + libxl_ctx_free(ctx); + xtl_logger_destroy((xentoollog_logger*)logger); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) --=20 git-series 0.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list