diff mbox

[for-1.4,qom-cpu,2/9] target-i386: kvm: Set vcpu_id to APIC ID instead of CPU index

Message ID 1358886309-26258-3-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost Jan. 22, 2013, 8:25 p.m. UTC
The CPU ID in KVM is supposed to be the APIC ID, so change the
KVM_CREATE_VCPU call to match it. The current behavior didn't break
anything yet because today the APIC ID is assumed to be equal to the CPU
index, but this won't be true in the future.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
---
Cc: kvm@vger.kernel.org
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>

Changes v2:
 - Change only i386 code (kvm_arch_vcpu_id())

Changes v3:
 - Get CPUState as argument instead of CPUArchState
---
 target-i386/kvm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Gleb Natapov Jan. 23, 2013, 10:26 a.m. UTC | #1
On Tue, Jan 22, 2013 at 06:25:02PM -0200, Eduardo Habkost wrote:
> The CPU ID in KVM is supposed to be the APIC ID, so change the
> KVM_CREATE_VCPU call to match it. The current behavior didn't break
> anything yet because today the APIC ID is assumed to be equal to the CPU
> index, but this won't be true in the future.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
Acked-by: Gleb Natapov <gleb@redhat.com>

> ---
> Cc: kvm@vger.kernel.org
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Gleb Natapov <gleb@redhat.com>
> Cc: Marcelo Tosatti <mtosatti@redhat.com>
> 
> Changes v2:
>  - Change only i386 code (kvm_arch_vcpu_id())
> 
> Changes v3:
>  - Get CPUState as argument instead of CPUArchState
> ---
>  target-i386/kvm.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 5f3f789..c440809 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -411,9 +411,10 @@ static void cpu_update_state(void *opaque, int running, RunState state)
>      }
>  }
>  
> -unsigned long kvm_arch_vcpu_id(CPUState *cpu)
> +unsigned long kvm_arch_vcpu_id(CPUState *cs)
>  {
> -    return cpu->cpu_index;
> +    X86CPU *cpu = X86_CPU(cs);
> +    return cpu->env.cpuid_apic_id;
>  }
>  
>  int kvm_arch_init_vcpu(CPUState *cs)
> -- 
> 1.8.1

--
			Gleb.
Andreas Färber Jan. 23, 2013, 4:12 p.m. UTC | #2
Am 23.01.2013 11:26, schrieb Gleb Natapov:
> On Tue, Jan 22, 2013 at 06:25:02PM -0200, Eduardo Habkost wrote:
>> The CPU ID in KVM is supposed to be the APIC ID, so change the
>> KVM_CREATE_VCPU call to match it. The current behavior didn't break
>> anything yet because today the APIC ID is assumed to be equal to the CPU
>> index, but this won't be true in the future.
>>
>> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
>> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
> Acked-by: Gleb Natapov <gleb@redhat.com>

Thanks, applied these two to qom-cpu already:
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas
diff mbox

Patch

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5f3f789..c440809 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -411,9 +411,10 @@  static void cpu_update_state(void *opaque, int running, RunState state)
     }
 }
 
-unsigned long kvm_arch_vcpu_id(CPUState *cpu)
+unsigned long kvm_arch_vcpu_id(CPUState *cs)
 {
-    return cpu->cpu_index;
+    X86CPU *cpu = X86_CPU(cs);
+    return cpu->env.cpuid_apic_id;
 }
 
 int kvm_arch_init_vcpu(CPUState *cs)