On 2011-08-17 07:25, Bharata B Rao wrote: > Hi, > > I see that x86 CPU topology inside VM is not showing up as specified. > With some debugging, I found out that the root cause for this: qemu is > not enumerating the apic ids correctly for vcpus. I made the below > hackish change to get it working. Has anybody else seen this problem > ? This patch is on qemu-kvm-0.14.1. Using 2.6.39 for guest. > > *************************** > Fix apic id enumeration > > apic id returned to guest kernel in ebx for cpuid(function=1) depends on > CPUX86State->cpuid_apic_id which gets populated after the cpuid information > is cached in the host kernel. > > Fix this by setting cpuid_apic_id before cpuid information is passed to > the host kernel. > > Signed-off-by: Bharata B Rao <bharata....@gmail.com> > --- > hw/pc.c | 4 +--- > target-i386/kvm.c | 3 +++ > 2 files changed, 4 insertions(+), 3 deletions(-) > > Index: qemu-kvm-0.14.1/hw/pc.c > =================================================================== > --- qemu-kvm-0.14.1.orig/hw/pc.c > +++ qemu-kvm-0.14.1/hw/pc.c > @@ -930,10 +930,8 @@ CPUState *pc_new_cpu(const char *cpu_mod > fprintf(stderr, "Unable to find x86 CPU definition\n"); > exit(1); > } > - if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) { > - env->cpuid_apic_id = env->cpu_index; > + if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) > env->apic_state = apic_init(env, env->cpuid_apic_id); > - } > qemu_register_reset(pc_cpu_reset, env); > pc_cpu_reset(env); > return env; > Index: qemu-kvm-0.14.1/target-i386/kvm.c > =================================================================== > --- qemu-kvm-0.14.1.orig/target-i386/kvm.c > +++ qemu-kvm-0.14.1/target-i386/kvm.c > @@ -340,6 +340,9 @@ int kvm_arch_init_vcpu(CPUState *env) > > cpuid_i = 0; > > + if (env->cpuid_features & CPUID_APIC) > + env->cpuid_apic_id = env->cpu_index; > +
Moving it only here will break TCG mode. Make sure to test both. I guess it's best to move cpuid_apic_id initialization into cpu_x86_init. And you need to take care of the external APIC case (i486) as well. Jan -- Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux