]>
Commit | Line | Data |
---|---|---|
3dcc8d3b WB |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Eduardo Habkost <ehabkost@redhat.com> | |
3 | Date: Wed, 12 Jul 2017 13:20:58 -0300 | |
4 | Subject: [PATCH] target/i386: Don't use x86_cpu_load_def() on "max" CPU model | |
5 | ||
6 | When commit 0bacd8b3046f ('i386: Don't set CPUClass::cpu_def on | |
7 | "max" model') removed the CPUClass::cpu_def field, we kept using | |
8 | the x86_cpu_load_def() helper directly in max_x86_cpu_initfn(), | |
9 | emulating the previous behavior when CPUClass::cpu_def was set. | |
10 | ||
11 | However, x86_cpu_load_def() is intended to help initialization of | |
12 | CPU models from the builtin_x86_defs table, and does lots of | |
13 | other steps that are not necessary for "max". | |
14 | ||
15 | One of the things x86_cpu_load_def() do is to set the properties | |
16 | listed at tcg_default_props/kvm_default_props. We must not do | |
17 | that on the "max" CPU model, otherwise under KVM we will | |
18 | incorrectly report all KVM features as always available, and the | |
19 | "svm" feature as always unavailable. The latter caused the bug | |
20 | reported at: | |
21 | ||
22 | https://bugzilla.redhat.com/show_bug.cgi?id=1467599 | |
23 | ("Unable to start domain: the CPU is incompatible with host CPU: | |
24 | Host CPU does not provide required features: svm") | |
25 | ||
26 | Replace x86_cpu_load_def() with simple object_property_set*() | |
27 | calls. In addition to fixing the above bug, this makes the KVM | |
28 | branch in max_x86_cpu_initfn() very similar to the existing TCG | |
29 | branch. | |
30 | ||
31 | For reference, the full list of steps performed by | |
32 | x86_cpu_load_def() is: | |
33 | ||
34 | * Setting min-level and min-xlevel. Already done by | |
35 | max_x86_cpu_initfn(). | |
36 | * Setting family/model/stepping/model-id. Done by the code added | |
37 | to max_x86_cpu_initfn() in this patch. | |
38 | * Copying def->features. Wrong because "-cpu max" features need to | |
39 | be calculated at realize time. This was not a problem in the | |
40 | current code because host_cpudef.features was all zeroes. | |
41 | * x86_cpu_apply_props() calls. This causes the bug above, and | |
42 | shouldn't be done. | |
43 | * Setting CPUID_EXT_HYPERVISOR. Not needed because it is already | |
44 | reported by x86_cpu_get_supported_feature_word(), and because | |
45 | "-cpu max" features need to be calculated at realize time. | |
46 | * Setting CPU vendor to host CPU vendor if on KVM mode. | |
47 | Redundant, because max_x86_cpu_initfn() already sets it to the | |
48 | host CPU vendor. | |
49 | ||
50 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | |
51 | Message-Id: <20170712162058.10538-5-ehabkost@redhat.com> | |
52 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | |
53 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | |
54 | --- | |
55 | target/i386/cpu.c | 18 ++++++++++++------ | |
56 | 1 file changed, 12 insertions(+), 6 deletions(-) | |
57 | ||
58 | diff --git a/target/i386/cpu.c b/target/i386/cpu.c | |
59 | index 54832dd591..3d53cb4c86 100644 | |
60 | --- a/target/i386/cpu.c | |
61 | +++ b/target/i386/cpu.c | |
62 | @@ -1600,15 +1600,21 @@ static void max_x86_cpu_initfn(Object *obj) | |
63 | cpu->max_features = true; | |
64 | ||
65 | if (kvm_enabled()) { | |
66 | - X86CPUDefinition host_cpudef = { }; | |
67 | - uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0; | |
68 | + char vendor[CPUID_VENDOR_SZ + 1] = { 0 }; | |
69 | + char model_id[CPUID_MODEL_ID_SZ + 1] = { 0 }; | |
70 | + int family, model, stepping; | |
71 | ||
72 | - host_vendor_fms(host_cpudef.vendor, &host_cpudef.family, | |
73 | - &host_cpudef.model, &host_cpudef.stepping); | |
74 | + host_vendor_fms(vendor, &family, &model, &stepping); | |
75 | ||
76 | - cpu_x86_fill_model_id(host_cpudef.model_id); | |
77 | + cpu_x86_fill_model_id(model_id); | |
78 | ||
79 | - x86_cpu_load_def(cpu, &host_cpudef, &error_abort); | |
80 | + object_property_set_str(OBJECT(cpu), vendor, "vendor", &error_abort); | |
81 | + object_property_set_int(OBJECT(cpu), family, "family", &error_abort); | |
82 | + object_property_set_int(OBJECT(cpu), model, "model", &error_abort); | |
83 | + object_property_set_int(OBJECT(cpu), stepping, "stepping", | |
84 | + &error_abort); | |
85 | + object_property_set_str(OBJECT(cpu), model_id, "model-id", | |
86 | + &error_abort); | |
87 | ||
88 | env->cpuid_min_level = | |
89 | kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX); | |
90 | -- | |
91 | 2.11.0 | |
92 |