From: Anthony Liguori <[EMAIL PROTECTED]>

The vmport code is very broken for SMP guests.  It uses a global CPUState
that's initialized multiple times?  At any rate, since it needs to know CPU
registers for the current CPU in a PIO handler, it needs to use cpu_single_env.

This patch makes vmmouse when using -smp > 1

Signed-off-by: Anthony Liguori <[EMAIL PROTECTED]>
Signed-off-by: Avi Kivity <[EMAIL PROTECTED]>

diff --git a/qemu/hw/pc.c b/qemu/hw/pc.c
index 97b108a..859d7db 100644
--- a/qemu/hw/pc.c
+++ b/qemu/hw/pc.c
@@ -755,7 +755,7 @@ CPUState *pc_new_cpu(int cpu, const char *cpu_model, int 
pci_enabled)
         if (pci_enabled) {
             apic_init(env);
         }
-        vmport_init(env);
+        vmport_init();
        return env;
 }
 
diff --git a/qemu/hw/pc.h b/qemu/hw/pc.h
index fb6c07d..f26fcb6 100644
--- a/qemu/hw/pc.h
+++ b/qemu/hw/pc.h
@@ -63,7 +63,7 @@ int pit_get_out(PITState *pit, int channel, int64_t 
current_time);
 PITState *kvm_pit_init(int base, qemu_irq irq);
 
 /* vmport.c */
-void vmport_init(CPUState *env);
+void vmport_init(void);
 void vmport_register(unsigned char command, IOPortReadFunc *func, void 
*opaque);
 
 /* vmmouse.c */
diff --git a/qemu/hw/vmport.c b/qemu/hw/vmport.c
index c09227d..83fcbcb 100644
--- a/qemu/hw/vmport.c
+++ b/qemu/hw/vmport.c
@@ -36,7 +36,6 @@
 
 typedef struct _VMPortState
 {
-    CPUState *env;
     IOPortReadFunc *func[VMPORT_ENTRIES];
     void *opaque[VMPORT_ENTRIES];
 } VMPortState;
@@ -55,18 +54,19 @@ void vmport_register(unsigned char command, IOPortReadFunc 
*func, void *opaque)
 static uint32_t vmport_ioport_read(void *opaque, uint32_t addr)
 {
     VMPortState *s = opaque;
+    CPUState *env = cpu_single_env;
     unsigned char command;
     uint32_t eax;
     uint32_t ret;
 
     if (kvm_enabled())
-       kvm_save_registers(s->env);
+       kvm_save_registers(env);
 
-    eax = s->env->regs[R_EAX];
+    eax = env->regs[R_EAX];
     if (eax != VMPORT_MAGIC)
         return eax;
 
-    command = s->env->regs[R_ECX];
+    command = env->regs[R_ECX];
     if (command >= VMPORT_ENTRIES)
         return eax;
     if (!s->func[command])
@@ -78,32 +78,30 @@ static uint32_t vmport_ioport_read(void *opaque, uint32_t 
addr)
     ret = s->func[command](s->opaque[command], addr);
 
     if (kvm_enabled())
-       kvm_load_registers(s->env);
+       kvm_load_registers(env);
 
     return ret;
 }
 
 static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
 {
-    CPUState *env = opaque;
+    CPUState *env = cpu_single_env;
     env->regs[R_EBX] = VMPORT_MAGIC;
     return 6;
 }
 
 static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
 {
-    CPUState *env = opaque;
+    CPUState *env = cpu_single_env;
     env->regs[R_EBX] = 0x1177;
     return ram_size;
 }
 
-void vmport_init(CPUState *env)
+void vmport_init(void)
 {
-    port_state.env = env;
-
     register_ioport_read(0x5658, 1, 4, vmport_ioport_read, &port_state);
 
     /* Register some generic port commands */
-    vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, env);
-    vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, env);
+    vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
+    vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
 }

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Register now and save $200. Hurry, offer ends at 11:59 p.m., 
Monday, April 7! Use priority code J8TLD2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
kvm-commits mailing list
kvm-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-commits

Reply via email to