qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, ehabkost@redhat.com, jan.kiszka@siemens.com,
	Don@CloudSwitch.com, mdroth@linux.vnet.ibm.com,
	blauwirbel@gmail.com, stefanha@redhat.com, pbonzini@redhat.com,
	afaerber@suse.de
Subject: [Qemu-devel] [PATCH 23/37] target-i386: convert 'check' and 'enforce' to static properties
Date: Mon, 22 Oct 2012 17:03:09 +0200	[thread overview]
Message-ID: <1350918203-25198-24-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1350918203-25198-1-git-send-email-imammedo@redhat.com>

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
  * restore original behavior, check features against host before
    they might be filtered out by TCG masks. spotted-by: Eduardo Habkost
v3:
  * use static properties instead of feature name arrays
  * since "check" is becoming regular boolean property it would be
    possible to turn it off while "enforce=on", set check_cpuid=true
    if "enforce=on" after all properties set at realize time.
---
 target-i386/cpu.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 73 insertions(+), 12 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 44cbf9c..061ee01 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -237,6 +237,62 @@ PropertyInfo qdev_prop_hv_vapic = {
 #define DEFINE_PROP_HV_VAPIC(_n)                                               \
     DEFINE_ABSTRACT_PROP(_n, qdev_prop_hv_vapic)
 
+static bool check_cpuid;
+
+static void x86_cpuid_get_check(Object *obj, Visitor *v, void *opaque,
+                                         const char *name, Error **errp)
+{
+    visit_type_bool(v, &check_cpuid, name, errp);
+}
+
+static void x86_cpuid_set_check(Object *obj, Visitor *v, void *opaque,
+                                         const char *name, Error **errp)
+{
+    bool value;
+
+    visit_type_bool(v, &value, name, errp);
+    if (error_is_set(errp)) {
+        return;
+    }
+    check_cpuid = value;
+}
+
+PropertyInfo qdev_prop_check = {
+    .name  = "bool",
+    .get   = x86_cpuid_get_check,
+    .set   = x86_cpuid_set_check,
+};
+#define DEFINE_PROP_CHECK(_n) \
+    DEFINE_ABSTRACT_PROP(_n, qdev_prop_check)
+
+static bool enforce_cpuid;
+
+static void x86_cpuid_get_enforce(Object *obj, Visitor *v, void *opaque,
+                                         const char *name, Error **errp)
+{
+    visit_type_bool(v, &enforce_cpuid, name, errp);
+}
+
+static void x86_cpuid_set_enforce(Object *obj, Visitor *v, void *opaque,
+                                         const char *name, Error **errp)
+{
+    bool value;
+
+    visit_type_bool(v, &value, name, errp);
+    if (error_is_set(errp)) {
+        return;
+    }
+    enforce_cpuid = value;
+}
+
+PropertyInfo qdev_prop_enforce = {
+    .name  = "boolean",
+    .get   = x86_cpuid_get_enforce,
+    .set   = x86_cpuid_set_enforce,
+};
+#define DEFINE_PROP_ENFORCE(_n)                                                \
+    DEFINE_ABSTRACT_PROP(_n, qdev_prop_enforce)
+
 static Property cpu_x86_properties[] = {
     DEFINE_PROP_BIT("f-fpu", X86CPU, env.cpuid_features,  0, false),
     DEFINE_PROP_BIT("f-vme", X86CPU, env.cpuid_features,  1, false),
@@ -354,6 +410,8 @@ static Property cpu_x86_properties[] = {
     DEFINE_PROP_HV_SPINLOCKS("hv_spinlocks"),
     DEFINE_PROP_HV_RELAXED("hv_relaxed"),
     DEFINE_PROP_HV_VAPIC("hv_vapic"),
+    DEFINE_PROP_CHECK("check"),
+    DEFINE_PROP_ENFORCE("enforce"),
     DEFINE_PROP_END_OF_LIST(),
  };
 
@@ -367,9 +425,6 @@ typedef struct model_features_t {
     uint32_t cpuid;
     } model_features_t;
 
-int check_cpuid = 0;
-int enforce_cpuid = 0;
-
 void host_cpuid(uint32_t function, uint32_t count,
                 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 {
@@ -1064,19 +1119,20 @@ static int unavailable_host_feature(struct model_features_t *f, uint32_t mask)
  * their way to the guest.  Note: ft[].check_feat ideally should be
  * specified via a guest_def field to suppress report of extraneous flags.
  */
-static int check_features_against_host(x86_def_t *guest_def)
+static int check_features_against_host(X86CPU *cpu)
 {
+    CPUX86State *env = &cpu->env;
     x86_def_t host_def;
     uint32_t mask;
     int rv, i;
     struct model_features_t ft[] = {
-        {&guest_def->features, &host_def.features,
+        {&env->cpuid_features, &host_def.features,
             ~0, feature_name, 0x00000000},
-        {&guest_def->ext_features, &host_def.ext_features,
+        {&env->cpuid_ext_features, &host_def.ext_features,
             ~CPUID_EXT_HYPERVISOR, ext_feature_name, 0x00000001},
-        {&guest_def->ext2_features, &host_def.ext2_features,
+        {&env->cpuid_ext2_features, &host_def.ext2_features,
             ~PPRO_FEATURES, ext2_feature_name, 0x80000000},
-        {&guest_def->ext3_features, &host_def.ext3_features,
+        {&env->cpuid_ext3_features, &host_def.ext3_features,
             ~CPUID_EXT3_SVM, ext3_feature_name, 0x80000001}};
 
     cpu_x86_fill_host(&host_def);
@@ -1594,10 +1650,6 @@ static int cpu_x86_find_by_name(X86CPU *cpu, x86_def_t *x86_cpu_def,
     x86_cpu_def->kvm_features &= ~minus_kvm_features;
     x86_cpu_def->svm_features &= ~minus_svm_features;
     x86_cpu_def->cpuid_7_0_ebx_features &= ~minus_7_0_ebx_features;
-    if (check_cpuid) {
-        if (check_features_against_host(x86_cpu_def) && enforce_cpuid)
-            goto error;
-    }
     g_free(s);
     return 0;
 
@@ -2159,6 +2211,15 @@ void x86_cpu_realize(Object *obj, Error **errp)
         env->cpuid_level = 7;
     }
 
+    if (enforce_cpuid) {
+        check_cpuid = true;
+    }
+    if (check_cpuid && check_features_against_host(cpu)
+        && enforce_cpuid) {
+        error_set(errp, QERR_PERMISSION_DENIED);
+        return;
+    }
+
     if (!kvm_enabled()) {
         env->cpuid_features &= TCG_FEATURES;
         env->cpuid_ext_features &= TCG_EXT_FEATURES;
-- 
1.7.11.7

  parent reply	other threads:[~2012-10-22 15:05 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-22 15:02 [Qemu-devel] [PATCH 00/37 v5] target-i386: convert CPU features into properties Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 01/37] target-i386: return Error from cpu_x86_find_by_name() Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 02/37] target-i386: cpu_x86_register(): report error from property setter Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 03/37] target-i386: if x86_cpu_realize() failed report error and do cleanup Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 04/37] target-i386: filter out not TCG features if running without kvm at realize time Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 05/37] target-i386: move out CPU features initialization in separate func Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 06/37] add visitor for parsing hz[KMG] input string Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 07/37] target-i386: use visit_type_hz to parse tsc_freq property value Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 08/37] target-i386: define static properties for cpuid features Igor Mammedov
2012-10-22 23:19   ` Don Slutz
     [not found]     ` <20121023122954.2db05627@thinkpad.mammed.net>
2012-10-23 18:17       ` Don Slutz
2012-10-22 15:02 ` [Qemu-devel] [PATCH 09/37] qdev: export qdev_prop_find() and allow it to be used with DeviceClass instead of Object Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 10/37] target-i386: parse cpu_model string into set of stringified properties Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 11/37] target-i386: introduce vendor-override static property Igor Mammedov
2012-10-22 15:02 ` [Qemu-devel] [PATCH 12/37] target-i386: convert "xlevel" to " Igor Mammedov
2012-10-23 21:38   ` Don Slutz
2012-10-22 15:02 ` [Qemu-devel] [PATCH 13/37] target-i386: convert "level" " Igor Mammedov
2012-10-23 21:38   ` Don Slutz
2012-10-22 15:03 ` [Qemu-devel] [PATCH 14/37] target-i386: postpone cpuid_level update to realize time Igor Mammedov
2012-12-05 16:18   ` Andreas Färber
2012-10-22 15:03 ` [Qemu-devel] [PATCH 15/37] target-i386: set default value of "hypervisor" feature using static property Igor Mammedov
2012-10-23 21:39   ` Don Slutz
2012-11-09 15:48   ` Eduardo Habkost
2012-11-29 14:56     ` Igor Mammedov
2012-11-29 15:47       ` Eduardo Habkost
2012-11-29 18:30         ` Igor Mammedov
2012-11-29 19:14           ` Eduardo Habkost
2012-10-22 15:03 ` [Qemu-devel] [PATCH 16/37] target-i386: set kvm CPUID default feature values using static properties Igor Mammedov
2012-10-22 23:20   ` Don Slutz
2012-10-23 10:40     ` Igor Mammedov
2012-10-23 10:55       ` Andreas Färber
2012-10-23 12:47         ` Igor Mammedov
2012-11-09 15:55   ` Eduardo Habkost
2012-10-22 15:03 ` [Qemu-devel] [PATCH 17/37] target-i386: make 'f-kvmclock' compatible with legacy behaviour Igor Mammedov
2012-10-23 21:41   ` Don Slutz
2012-10-22 15:03 ` [Qemu-devel] [PATCH 18/37] target-i386: add stubs for hyperv_(vapic_recommended|relaxed_timing_enabled|get_spinlock_retries)() Igor Mammedov
2012-10-25 21:44   ` Don Slutz
2012-10-22 15:03 ` [Qemu-devel] [PATCH 19/37] qdev: add DEFINE_ABSTRACT_PROP() helper Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 20/37] target-i386: convert 'hv_spinlocks' to static property Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 21/37] target-i386: convert 'hv_relaxed' " Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 22/37] target-i386: convert 'hv_vapic' " Igor Mammedov
2012-10-22 15:03 ` Igor Mammedov [this message]
2012-10-22 15:03 ` [Qemu-devel] [PATCH 24/37] target-i386: use define for cpuid vendor string size Igor Mammedov
2012-12-05 16:08   ` Andreas Färber
2012-10-22 15:03 ` [Qemu-devel] [PATCH 25/37] target-i386: replace uint32_t vendor fields by vendor string in x86_def_t Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 26/37] target-i386: convert "vendor" property to static property Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 27/37] target-i386: convert "tsc-frequency" " Igor Mammedov
2012-10-25 21:40   ` Don Slutz
2012-10-22 15:03 ` [Qemu-devel] [PATCH 28/37] target-i386: convert "model-id" " Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 29/37] target-i386: convert "stepping" " Igor Mammedov
2012-10-25 21:26   ` Don Slutz
2012-10-22 15:03 ` [Qemu-devel] [PATCH 30/37] target-i386: convert "model" " Igor Mammedov
2012-10-25 21:21   ` Don Slutz
2012-10-22 15:03 ` [Qemu-devel] [PATCH 31/37] target-i386: convert "family" " Igor Mammedov
2012-10-25 21:24   ` Don Slutz
2012-10-22 15:03 ` [Qemu-devel] [PATCH 32/37] target-i386: use static properties for setting cpuid features Igor Mammedov
2012-10-23 15:29   ` Don Slutz
2012-10-23 15:50     ` Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 33/37] qdev: QDEV_PROP_FOREACH and QDEV_CLASS_FOREACH Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 34/37] qdev: introduce QDEV_FIND_PROP_FROM_BIT and qdev_prop_find_bit() Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 35/37] target-i386: use static properties in check_features_against_host() to print CPUID feature names Igor Mammedov
2012-10-23 13:17   ` Igor Mammedov
2012-10-23 13:25   ` [Qemu-devel] [PATCH v2] " Igor Mammedov
2012-10-22 15:03 ` [Qemu-devel] [PATCH 36/37] target-i386: use static properties to list CPUID features Igor Mammedov
2012-10-23 13:26   ` [Qemu-devel] [PATCH v2] " Igor Mammedov
2012-10-23 13:51     ` Eduardo Habkost
2012-10-23 16:18       ` Igor Mammedov
2012-10-23 17:23   ` [Qemu-devel] [PATCH 36/37] " Don Slutz
2012-10-24 14:00     ` Eduardo Habkost
2012-10-22 15:03 ` [Qemu-devel] [PATCH 37/37] target-i386: cleanup cpu_x86_find_by_name(), only fill x86_def_t in it Igor Mammedov
2012-10-23 13:32 ` [Qemu-devel] [PATCH 00/37 v5] target-i386: convert CPU features into properties Don Slutz
2012-10-23 13:56   ` Igor Mammedov
2012-10-24 13:55     ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350918203-25198-24-git-send-email-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=Don@CloudSwitch.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=blauwirbel@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).