From nobody Fri May 16 12:59:30 2025 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