Commit 2dca6d9e authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging



x86 bug fix for -rc1

Fix for a bug in "-cpu max" that breaks libvirt usage of
query-cpu-model-expansion.

# gpg: Signature made Wed 26 Jul 2017 19:35:28 BST
# gpg:                using RSA key 0x2807936F984DC5A6
# gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>"
# Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF  D1AA 2807 936F 984D C5A6

* remotes/ehabkost/tags/x86-pull-request:
  target/i386: Don't use x86_cpu_load_def() on "max" CPU model
  target/i386: Define CPUID_MODEL_ID_SZ macro
  target/i386: Use host_vendor_fms() in max_x86_cpu_initfn()

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 522fd24c bd182022
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -1585,6 +1585,17 @@ static bool lmce_supported(void)
    return !!(mce_cap & MCG_LMCE_P);
}

#define CPUID_MODEL_ID_SZ 48

/**
 * cpu_x86_fill_model_id:
 * Get CPUID model ID string from host CPU.
 *
 * @str should have at least CPUID_MODEL_ID_SZ bytes
 *
 * The function does NOT add a null terminator to the string
 * automatically.
 */
static int cpu_x86_fill_model_id(char *str)
{
    uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
@@ -1633,20 +1644,21 @@ static void max_x86_cpu_initfn(Object *obj)
    cpu->max_features = true;

    if (kvm_enabled()) {
        X86CPUDefinition host_cpudef = { };
        uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0;
        char vendor[CPUID_VENDOR_SZ + 1] = { 0 };
        char model_id[CPUID_MODEL_ID_SZ + 1] = { 0 };
        int family, model, stepping;

        host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx);
        x86_cpu_vendor_words2str(host_cpudef.vendor, ebx, edx, ecx);

        host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx);
        host_cpudef.family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF);
        host_cpudef.model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12);
        host_cpudef.stepping = eax & 0x0F;
        host_vendor_fms(vendor, &family, &model, &stepping);

        cpu_x86_fill_model_id(host_cpudef.model_id);
        cpu_x86_fill_model_id(model_id);

        x86_cpu_load_def(cpu, &host_cpudef, &error_abort);
        object_property_set_str(OBJECT(cpu), vendor, "vendor", &error_abort);
        object_property_set_int(OBJECT(cpu), family, "family", &error_abort);
        object_property_set_int(OBJECT(cpu), model, "model", &error_abort);
        object_property_set_int(OBJECT(cpu), stepping, "stepping",
                                &error_abort);
        object_property_set_str(OBJECT(cpu), model_id, "model-id",
                                &error_abort);

        env->cpuid_min_level =
            kvm_arch_get_supported_cpuid(s, 0x0, 0, R_EAX);