[Qemu-devel] [PATCH v2 08/17] kvm: x86: Remove redundant mp_state initialization

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

kvm_arch_reset_vcpu initializes mp_state, and that function is invoked
right after kvm_arch_init_vcpu.

Signed-off-by: Jan Kiszka 
---
 target-i386/kvm.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 30aa51c..1403327 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -321,8 +321,6 @@ int kvm_arch_init_vcpu(CPUState *env)
 uint32_t signature[3];
 #endif
 
-env->mp_state = KVM_MP_STATE_RUNNABLE;
-
 env->cpuid_features &= kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX);
 
 i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR;
-- 
1.7.1




[Qemu-devel] [PATCH v2 05/17] x86: Optionally dump code bytes on cpu_dump_state

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

Introduce the cpu_dump_state flag CPU_DUMP_CODE and implement it for
x86. This writes out the code bytes around the current instruction
pointer. Make use of this feature in KVM to help debugging fatal vm
exits.

Signed-off-by: Jan Kiszka 
---
 cpu-all.h|2 ++
 kvm-all.c|4 ++--
 target-i386/helper.c |   21 +
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index 4ce4e83..ffbd6a4 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -765,6 +765,8 @@ int page_check_range(target_ulong start, target_ulong len, 
int flags);
 CPUState *cpu_copy(CPUState *env);
 CPUState *qemu_get_cpu(int cpu);
 
+#define CPU_DUMP_CODE 0x0001
+
 void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
 int flags);
 void cpu_dump_statistics(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
diff --git a/kvm-all.c b/kvm-all.c
index ad1d0a8..ef2ca3b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -791,7 +791,7 @@ static int kvm_handle_internal_error(CPUState *env, struct 
kvm_run *run)
 if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) {
 fprintf(stderr, "emulation failure\n");
 if (!kvm_arch_stop_on_emulation_error(env)) {
-cpu_dump_state(env, stderr, fprintf, 0);
+cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE);
 return 0;
 }
 }
@@ -953,7 +953,7 @@ void kvm_cpu_exec(CPUState *env)
 } while (ret > 0);
 
 if (ret < 0) {
-cpu_dump_state(env, stderr, fprintf, 0);
+cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE);
 vm_stop(0);
 env->exit_request = 1;
 }
diff --git a/target-i386/helper.c b/target-i386/helper.c
index adf9542..1ab42c3 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -249,6 +249,9 @@ done:
 cpu_fprintf(f, "\n");
 }
 
+#define DUMP_CODE_BYTES_TOTAL50
+#define DUMP_CODE_BYTES_BACKWARD 20
+
 void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
 int flags)
 {
@@ -434,6 +437,24 @@ void cpu_dump_state(CPUState *env, FILE *f, 
fprintf_function cpu_fprintf,
 cpu_fprintf(f, " ");
 }
 }
+if (flags & CPU_DUMP_CODE) {
+target_phys_addr_t base = env->segs[R_CS].base + env->eip;
+target_phys_addr_t offs = MIN(env->eip, DUMP_CODE_BYTES_BACKWARD);
+uint8_t code;
+char codestr[3];
+
+cpu_fprintf(f, "Code=");
+for (i = 0; i < DUMP_CODE_BYTES_TOTAL; i++) {
+if (cpu_memory_rw_debug(env, base - offs + i, &code, 1, 0) == 0) {
+snprintf(codestr, sizeof(codestr), "%02x", code);
+} else {
+snprintf(codestr, sizeof(codestr), "??");
+}
+cpu_fprintf(f, "%s%s%s%s", i > 0 ? " ": "",
+i == offs ? "<" : "", codestr, i == offs ? ">" : "");
+}
+cpu_fprintf(f, "\n");
+}
 }
 
 /***/
-- 
1.7.1




[Qemu-devel] [PATCH v2 01/17] kvm: Fix coding style violations

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

No functional changes.

Signed-off-by: Jan Kiszka 
---
 kvm-all.c |  139 ++--
 1 files changed, 79 insertions(+), 60 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 35fc73c..2538283 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -82,10 +82,12 @@ static KVMSlot *kvm_alloc_slot(KVMState *s)
 
 for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
 /* KVM private memory slots */
-if (i >= 8 && i < 12)
+if (i >= 8 && i < 12) {
 continue;
-if (s->slots[i].memory_size == 0)
+}
+if (s->slots[i].memory_size == 0) {
 return &s->slots[i];
+}
 }
 
 fprintf(stderr, "%s: no free slot available\n", __func__);
@@ -220,9 +222,10 @@ int kvm_init_vcpu(CPUState *env)
 }
 
 #ifdef KVM_CAP_COALESCED_MMIO
-if (s->coalesced_mmio && !s->coalesced_mmio_ring)
-s->coalesced_mmio_ring = (void *) env->kvm_run +
-   s->coalesced_mmio * PAGE_SIZE;
+if (s->coalesced_mmio && !s->coalesced_mmio_ring) {
+s->coalesced_mmio_ring =
+(void *)env->kvm_run + s->coalesced_mmio * PAGE_SIZE;
+}
 #endif
 
 ret = kvm_arch_init_vcpu(env);
@@ -269,16 +272,14 @@ static int kvm_dirty_pages_log_change(target_phys_addr_t 
phys_addr,
 
 int kvm_log_start(target_phys_addr_t phys_addr, ram_addr_t size)
 {
-return kvm_dirty_pages_log_change(phys_addr, size,
-  KVM_MEM_LOG_DIRTY_PAGES,
-  KVM_MEM_LOG_DIRTY_PAGES);
+return kvm_dirty_pages_log_change(phys_addr, size, KVM_MEM_LOG_DIRTY_PAGES,
+  KVM_MEM_LOG_DIRTY_PAGES);
 }
 
 int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size)
 {
-return kvm_dirty_pages_log_change(phys_addr, size,
-  0,
-  KVM_MEM_LOG_DIRTY_PAGES);
+return kvm_dirty_pages_log_change(phys_addr, size, 0,
+  KVM_MEM_LOG_DIRTY_PAGES);
 }
 
 static int kvm_set_migration_log(int enable)
@@ -350,7 +351,7 @@ static int kvm_get_dirty_pages_log_range(unsigned long 
start_addr,
  * @end_addr: end of logged region.
  */
 static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
- target_phys_addr_t end_addr)
+  target_phys_addr_t end_addr)
 {
 KVMState *s = kvm_state;
 unsigned long size, allocated_size = 0;
@@ -441,9 +442,8 @@ int kvm_check_extension(KVMState *s, unsigned int extension)
 return ret;
 }
 
-static void kvm_set_phys_mem(target_phys_addr_t start_addr,
-ram_addr_t size,
-ram_addr_t phys_offset)
+static void kvm_set_phys_mem(target_phys_addr_t start_addr, ram_addr_t size,
+ ram_addr_t phys_offset)
 {
 KVMState *s = kvm_state;
 ram_addr_t flags = phys_offset & ~TARGET_PAGE_MASK;
@@ -550,13 +550,13 @@ static void kvm_set_phys_mem(target_phys_addr_t 
start_addr,
 }
 
 /* in case the KVM bug workaround already "consumed" the new slot */
-if (!size)
+if (!size) {
 return;
-
+}
 /* KVM does not need to know about this memory */
-if (flags >= IO_MEM_UNASSIGNED)
+if (flags >= IO_MEM_UNASSIGNED) {
 return;
-
+}
 mem = kvm_alloc_slot(s);
 mem->memory_size = size;
 mem->start_addr = start_addr;
@@ -572,30 +572,29 @@ static void kvm_set_phys_mem(target_phys_addr_t 
start_addr,
 }
 
 static void kvm_client_set_memory(struct CPUPhysMemoryClient *client,
- target_phys_addr_t start_addr,
- ram_addr_t size,
- ram_addr_t phys_offset)
+  target_phys_addr_t start_addr,
+  ram_addr_t size, ram_addr_t phys_offset)
 {
-   kvm_set_phys_mem(start_addr, size, phys_offset);
+kvm_set_phys_mem(start_addr, size, phys_offset);
 }
 
 static int kvm_client_sync_dirty_bitmap(struct CPUPhysMemoryClient *client,
-   target_phys_addr_t start_addr,
-   target_phys_addr_t end_addr)
+target_phys_addr_t start_addr,
+target_phys_addr_t end_addr)
 {
-   return kvm_physical_sync_dirty_bitmap(start_addr, end_addr);
+return kvm_physical_sync_dirty_bitmap(start_addr, end_addr);
 }
 
 static int kvm_client_migration_log(struct CPUPhysMemoryClient *client,
-   int enable)
+int enable)
 {
-   return kvm_set_migration_log(enable);
+return kvm_set_migration_log(enable);
 }
 
 static CPUPhysMemoryClient kvm_cpu_phys_memory_client = {
-   .set_memory = kvm_client_

[Qemu-devel] [PATCH v2 09/17] kvm: x86: Fix xcr0 reset mismerge

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

For unknown reasons, xcr0 reset ended up in kvm_arch_update_guest_debug
on upstream merge. Fix this and also remove the misleading comment (1 is
THE reset value).

Signed-off-by: Jan Kiszka 
---
 target-i386/kvm.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 1403327..e46b901 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -450,6 +450,7 @@ void kvm_arch_reset_vcpu(CPUState *env)
 env->interrupt_injected = -1;
 env->nmi_injected = 0;
 env->nmi_pending = 0;
+env->xcr0 = 1;
 if (kvm_irqchip_in_kernel()) {
 env->mp_state = cpu_is_bsp(env) ? KVM_MP_STATE_RUNNABLE :
   KVM_MP_STATE_UNINITIALIZED;
@@ -1756,8 +1757,6 @@ void kvm_arch_update_guest_debug(CPUState *env, struct 
kvm_guest_debug *dbg)
 ((uint32_t)len_code[hw_breakpoint[n].len] << (18 + n*4));
 }
 }
-/* Legal xcr0 for loading */
-env->xcr0 = 1;
 }
 #endif /* KVM_CAP_SET_GUEST_DEBUG */
 
-- 
1.7.1




[Qemu-devel] [PATCH v2 15/17] kvm: Drop smp_cpus argument from init functions

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

No longer used.

Signed-off-by: Jan Kiszka 
---
 kvm-all.c  |4 ++--
 kvm-stub.c |2 +-
 kvm.h  |4 ++--
 target-i386/kvm.c  |2 +-
 target-ppc/kvm.c   |2 +-
 target-s390x/kvm.c |2 +-
 vl.c   |2 +-
 7 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index d8820c7..190fcdf 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -584,7 +584,7 @@ static CPUPhysMemoryClient kvm_cpu_phys_memory_client = {
 .migration_log = kvm_client_migration_log,
 };
 
-int kvm_init(int smp_cpus)
+int kvm_init(void)
 {
 static const char upgrade_note[] =
 "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
@@ -687,7 +687,7 @@ int kvm_init(int smp_cpus)
 kvm_state.xcrs = kvm_check_extension(KVM_CAP_XCRS);
 #endif
 
-ret = kvm_arch_init(smp_cpus);
+ret = kvm_arch_init();
 if (ret < 0) {
 goto err;
 }
diff --git a/kvm-stub.c b/kvm-stub.c
index 3a058ad..e00d7df 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -58,7 +58,7 @@ int kvm_check_extension(unsigned int extension)
 return 0;
 }
 
-int kvm_init(int smp_cpus)
+int kvm_init(void)
 {
 return -ENOSYS;
 }
diff --git a/kvm.h b/kvm.h
index 26ca8c1..31d9f21 100644
--- a/kvm.h
+++ b/kvm.h
@@ -34,7 +34,7 @@ struct kvm_run;
 
 /* external API */
 
-int kvm_init(int smp_cpus);
+int kvm_init(void);
 
 int kvm_has_sync_mmu(void);
 int kvm_has_vcpu_events(void);
@@ -101,7 +101,7 @@ int kvm_arch_get_registers(CPUState *env);
 
 int kvm_arch_put_registers(CPUState *env, int level);
 
-int kvm_arch_init(int smp_cpus);
+int kvm_arch_init(void);
 
 int kvm_arch_init_vcpu(CPUState *env);
 
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index c4b6813..6d31dde 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -594,7 +594,7 @@ static int kvm_init_identity_map_page(void)
 return 0;
 }
 
-int kvm_arch_init(int smp_cpus)
+int kvm_arch_init(void)
 {
 int ret;
 struct utsname utsname;
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 56d30cc..72f2f94 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -56,7 +56,7 @@ static void kvm_kick_env(void *env)
 qemu_cpu_kick(env);
 }
 
-int kvm_arch_init(int smp_cpus)
+int kvm_arch_init(void)
 {
 #ifdef KVM_CAP_PPC_UNSET_IRQ
 cap_interrupt_unset = kvm_check_extension(KVM_CAP_PPC_UNSET_IRQ);
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 927a37e..4f9075c 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -70,7 +70,7 @@
 #define SCLP_CMDW_READ_SCP_INFO 0x00020001
 #define SCLP_CMDW_READ_SCP_INFO_FORCED  0x00120001
 
-int kvm_arch_init(int smp_cpus)
+int kvm_arch_init(void)
 {
 return 0;
 }
diff --git a/vl.c b/vl.c
index 768dbf4..abe4af8 100644
--- a/vl.c
+++ b/vl.c
@@ -2834,7 +2834,7 @@ int main(int argc, char **argv, char **envp)
 }
 
 if (kvm_allowed) {
-int ret = kvm_init(smp_cpus);
+int ret = kvm_init();
 if (ret < 0) {
 if (!kvm_available()) {
 printf("KVM not supported for this target\n");
-- 
1.7.1




[Qemu-devel] [PATCH v2 14/17] kvm: x86: Introduce kvmclock device to save/restore its state

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

If kvmclock is used, which implies the kernel supports it, register a
kvmclock device with the sysbus. Its main purpose is to save and restore
the kernel state on migration, but this will also allow to visualize it
one day.

Signed-off-by: Jan Kiszka 
CC: Glauber Costa 
---
 target-i386/kvm.c |   71 -
 1 files changed, 70 insertions(+), 1 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 26f459c..c4b6813 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -29,6 +29,7 @@
 #include "hw/apic.h"
 #include "ioport.h"
 #include "kvm_x86.h"
+#include "hw/sysbus.h"
 
 #ifdef CONFIG_KVM_PARA
 #include 
@@ -309,6 +310,64 @@ void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t 
status,
 #endif
 }
 
+#ifdef KVM_CAP_ADJUST_CLOCK
+typedef struct KVMClockState {
+SysBusDevice busdev;
+uint64_t clock;
+struct kvm_clock_data data;
+} KVMClockState;
+
+static void kvmclock_pre_save(void *opaque)
+{
+KVMClockState *s = opaque;
+struct kvm_clock_data data;
+int ret;
+
+ret = kvm_vm_ioctl(KVM_GET_CLOCK, &data);
+if (ret < 0) {
+fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));
+data.clock = 0;
+}
+s->clock = data.clock;
+}
+
+static int kvmclock_post_load(void *opaque, int version_id)
+{
+KVMClockState *s = opaque;
+struct kvm_clock_data data;
+
+data.clock = s->clock;
+data.flags = 0;
+return kvm_vm_ioctl(KVM_SET_CLOCK, &data);
+}
+
+static int kvmclock_init(SysBusDevice *dev)
+{
+return 0;
+}
+
+static const VMStateDescription kvmclock_vmsd= {
+.name = "kvmclock",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.pre_save = kvmclock_pre_save,
+.post_load = kvmclock_post_load,
+.fields = (VMStateField []) {
+VMSTATE_UINT64(clock, KVMClockState),
+VMSTATE_END_OF_LIST()
+}
+};
+
+static SysBusDeviceInfo kvmclock_info = {
+.qdev.name = "kvmclock",
+.qdev.size = sizeof(KVMClockState),
+.qdev.vmsd = &kvmclock_vmsd,
+.qdev.no_user = 1,
+.init = kvmclock_init,
+};
+#endif /* KVM_CAP_ADJUST_CLOCK */
+
 int kvm_arch_init_vcpu(CPUState *env)
 {
 struct {
@@ -335,7 +394,6 @@ int kvm_arch_init_vcpu(CPUState *env)
 env->cpuid_svm_features  &= kvm_x86_get_supported_cpuid(0x800A,
 0, R_EDX);
 
-
 cpuid_i = 0;
 
 #ifdef CONFIG_KVM_PARA
@@ -442,6 +500,13 @@ int kvm_arch_init_vcpu(CPUState *env)
 }
 #endif
 
+#ifdef KVM_CAP_ADJUST_CLOCK
+if (cpu_is_bsp(env) &&
+(env->cpuid_kvm_features & (1ULL << KVM_FEATURE_CLOCKSOURCE))) {
+sysbus_create_simple("kvmclock", -1, NULL);
+}
+#endif
+
 return kvm_vcpu_ioctl(env, KVM_SET_CPUID2, &cpuid_data);
 }
 
@@ -534,6 +599,10 @@ int kvm_arch_init(int smp_cpus)
 int ret;
 struct utsname utsname;
 
+#ifdef KVM_CAP_ADJUST_CLOCK
+sysbus_register_withprop(&kvmclock_info);
+#endif
+
 ret = kvm_get_supported_msrs();
 if (ret < 0) {
 return ret;
-- 
1.7.1




[Qemu-devel] [PATCH v2 07/17] kvm: x86: Prepare kvm_get_mp_state for in-kernel irqchip

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

This code path will not yet be taken as we still lack in-kernel irqchip
support. But qemu-kvm can already make use of it and drop its own
mp_state access services.

Signed-off-by: Jan Kiszka 
---
 target-i386/kvm.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 684430f..30aa51c 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1198,6 +1198,9 @@ static int kvm_get_mp_state(CPUState *env)
 return ret;
 }
 env->mp_state = mp_state.mp_state;
+if (kvm_irqchip_in_kernel()) {
+env->halted = (mp_state.mp_state == KVM_MP_STATE_HALTED);
+}
 return 0;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH v2 16/17] kvm: x86: Rework identity map and TSS setup for larger BIOS sizes

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

First of all, we only need this EPT identity and TSS reservation on
Intel CPUs. Then, in order to support loading BIOSes > 256K, reorder the
code, adjusting the base if the kernel supports moving the identity map.
We can drop the check for KVM_CAP_SET_TSS_ADDR as we already depend on
much newer features.

Signed-off-by: Jan Kiszka 
---
 target-i386/kvm.c |   91 
 1 files changed, 42 insertions(+), 49 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 6d31dde..caca407 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -575,23 +575,12 @@ static int kvm_get_supported_msrs(void)
 return ret;
 }
 
-static int kvm_init_identity_map_page(void)
+static bool host_supports_vmx(void)
 {
-#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR
-int ret;
-uint64_t addr = 0xfffbc000;
-
-if (!kvm_check_extension(KVM_CAP_SET_IDENTITY_MAP_ADDR)) {
-return 0;
-}
+uint32_t ecx, unused;
 
-ret = kvm_vm_ioctl(KVM_SET_IDENTITY_MAP_ADDR, &addr);
-if (ret < 0) {
-fprintf(stderr, "kvm_set_identity_map_addr: %s\n", strerror(ret));
-return ret;
-}
-#endif
-return 0;
+host_cpuid(1, 0, &unused, &unused, &ecx, &unused);
+return ecx & CPUID_EXT_VMX;
 }
 
 int kvm_arch_init(void)
@@ -611,35 +600,47 @@ int kvm_arch_init(void)
 uname(&utsname);
 lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0;
 
-/* create vm86 tss.  KVM uses vm86 mode to emulate 16-bit code
- * directly.  In order to use vm86 mode, a TSS is needed.  Since this
- * must be part of guest physical memory, we need to allocate it.  Older
- * versions of KVM just assumed that it would be at the end of physical
- * memory but that doesn't work with more than 4GB of memory.  We simply
- * refuse to work with those older versions of KVM. */
-ret = kvm_check_extension(KVM_CAP_SET_TSS_ADDR);
-if (ret <= 0) {
-fprintf(stderr, "kvm does not support KVM_CAP_SET_TSS_ADDR\n");
-return ret;
-}
+if (host_supports_vmx()) {
+/*
+ * On older Intel CPUs, KVM uses vm86 mode to emulate 16-bit code
+ * directly. In order to use vm86 mode, an EPT identity map and a TSS
+ * are needed. Since these must be part of guest physical memory, we
+ * need to allocate them, both by setting their start addresses in the
+ * kernel and by creating a corresponding e820 entry. We need 4 pages
+ * before the BIOS.
+ *
+ * Older KVM versions may not support setting the identity map base.
+ * In that case we need to stick with the default, i.e. a 256K maximum
+ * BIOS size.
+ */
+uint64_t identity_base = 0xfffbc000;
 
-/* this address is 3 pages before the bios, and the bios should present
- * as unavaible memory.  FIXME, need to ensure the e820 map deals with
- * this?
- */
-/*
- * Tell fw_cfg to notify the BIOS to reserve the range.
- */
-if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED) < 0) {
-perror("e820_add_entry() table is full");
-exit(1);
-}
-ret = kvm_vm_ioctl(KVM_SET_TSS_ADDR, 0xfffbd000);
-if (ret < 0) {
-return ret;
+#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR
+if (kvm_check_extension(KVM_CAP_SET_IDENTITY_MAP_ADDR)) {
+/* Allows up to 16M BIOSes. */
+identity_base = 0xfeffc000;
+
+ret = kvm_vm_ioctl(KVM_SET_IDENTITY_MAP_ADDR, &identity_base);
+if (ret < 0) {
+return ret;
+}
+}
+#endif
+/* Set TSS base one page after EPT identity map. */
+ret = kvm_vm_ioctl(KVM_SET_TSS_ADDR, identity_base + 0x1000);
+if (ret < 0) {
+return ret;
+}
+
+/* Tell fw_cfg to notify the BIOS to reserve the range. */
+ret = e820_add_entry(identity_base, 0x4000, E820_RESERVED);
+if (ret < 0) {
+fprintf(stderr, "e820_add_entry() table is full\n");
+return ret;
+}
 }
 
-return kvm_init_identity_map_page();
+return 0;
 }
 
 static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
@@ -1592,14 +1593,6 @@ static int kvm_handle_halt(CPUState *env)
 return 1;
 }
 
-static bool host_supports_vmx(void)
-{
-uint32_t ecx, unused;
-
-host_cpuid(1, 0, &unused, &unused, &ecx, &unused);
-return ecx & CPUID_EXT_VMX;
-}
-
 #define VMX_INVALID_GUEST_STATE 0x8021
 
 int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
-- 
1.7.1




[Qemu-devel] [PATCH v2 00/17] [uq/master] Prepare for more qemu-kvm merging

2011-01-03 Thread Jan Kiszka
All previously sent patches against current uq combined, some smaller
tweaks applied, and 4 new patches added. Major news is support for
using up to 16M BIOSes and optional code dump for cpu_dump_state. Those
features are already present qemu-kvm but were reworked to provide
cleaner upstream versions.

Based on this series, I've an experimental tree here where I eliminated
another 1500 LOC from qemu-kvm code. Specifically, that tree sets an end
to duplicate KVM and VCPU initialization functions, KVMState copies, and
redundant state saving/loading functions. Will be rolled out after some
more review and testing.

Jan Kiszka (17):
  kvm: Fix coding style violations
  kvm: Drop return value of kvm_cpu_exec
  kvm: Stop on all fatal exit reasons
  kvm: Improve reporting of fatal errors
  x86: Optionally dump code bytes on cpu_dump_state
  kvm: x86: Align kvm_arch_put_registers code with comment
  kvm: x86: Prepare kvm_get_mp_state for in-kernel irqchip
  kvm: x86: Remove redundant mp_state initialization
  kvm: x86: Fix xcr0 reset mismerge
  kvm: x86: Refactor msr_star/hsave_pa setup and checks
  kvm: x86: Reset paravirtual MSRs
  kvm: x86: Drop MCE MSRs write back restrictions
  kvm: Eliminate KVMState arguments
  kvm: x86: Introduce kvmclock device to save/restore its state
  kvm: Drop smp_cpus argument from init functions
  kvm: x86: Rework identity map and TSS setup for larger BIOS sizes
  kvm: Drop dependencies on very old capabilities

 cpu-all.h |2 +
 cpu-defs.h|2 -
 kvm-all.c |  404 +++--
 kvm-stub.c|8 +-
 kvm.h |   19 +--
 target-i386/cpu.h |2 +
 target-i386/cpuid.c   |   14 +-
 target-i386/helper.c  |   21 +++
 target-i386/kvm.c |  331 
 target-i386/kvm_x86.h |3 +
 target-ppc/kvm.c  |   16 ++-
 target-s390x/kvm.c|8 +-
 vl.c  |2 +-
 13 files changed, 448 insertions(+), 384 deletions(-)




[Qemu-devel] [PATCH v2 02/17] kvm: Drop return value of kvm_cpu_exec

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

It is not used, it is not needed, so let's remove it.

Signed-off-by: Jan Kiszka 
---
 kvm-all.c  |6 ++
 kvm-stub.c |4 ++--
 kvm.h  |2 +-
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 2538283..7518f2c 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -850,7 +850,7 @@ void kvm_cpu_synchronize_post_init(CPUState *env)
 env->kvm_vcpu_dirty = 0;
 }
 
-int kvm_cpu_exec(CPUState *env)
+void kvm_cpu_exec(CPUState *env)
 {
 struct kvm_run *run = env->kvm_run;
 int ret;
@@ -943,7 +943,7 @@ int kvm_cpu_exec(CPUState *env)
 #ifdef KVM_CAP_SET_GUEST_DEBUG
 if (kvm_arch_debug(&run->debug.arch)) {
 env->exception_index = EXCP_DEBUG;
-return 0;
+return;
 }
 /* re-enter, this exception was guest-internal */
 ret = 1;
@@ -960,8 +960,6 @@ int kvm_cpu_exec(CPUState *env)
 env->exit_request = 0;
 env->exception_index = EXCP_INTERRUPT;
 }
-
-return ret;
 }
 
 int kvm_ioctl(KVMState *s, int type, ...)
diff --git a/kvm-stub.c b/kvm-stub.c
index 5384a4b..352c6a6 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -79,9 +79,9 @@ void kvm_cpu_synchronize_post_init(CPUState *env)
 {
 }
 
-int kvm_cpu_exec(CPUState *env)
+void kvm_cpu_exec(CPUState *env)
 {
-abort ();
+abort();
 }
 
 int kvm_has_sync_mmu(void)
diff --git a/kvm.h b/kvm.h
index 60a9b42..51ad56f 100644
--- a/kvm.h
+++ b/kvm.h
@@ -46,7 +46,7 @@ int kvm_has_xcrs(void);
 #ifdef NEED_CPU_H
 int kvm_init_vcpu(CPUState *env);
 
-int kvm_cpu_exec(CPUState *env);
+void kvm_cpu_exec(CPUState *env);
 
 #if !defined(CONFIG_USER_ONLY)
 int kvm_log_start(target_phys_addr_t phys_addr, ram_addr_t size);
-- 
1.7.1




[Qemu-devel] [PATCH v2 11/17] kvm: x86: Reset paravirtual MSRs

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

Make sure to clear MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK, and
MSR_KVM_ASYNC_PF_EN so that a freshly booted guest cannot be disturbed
by old values.

Signed-off-by: Jan Kiszka 
CC: Glauber Costa 
---
 target-i386/kvm.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index d8f26bf..664a4a0 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -453,6 +453,9 @@ void kvm_arch_reset_vcpu(CPUState *env)
 env->nmi_injected = 0;
 env->nmi_pending = 0;
 env->xcr0 = 1;
+env->system_time_msr = 0;
+env->wall_clock_msr = 0;
+env->async_pf_en_msr = 0;
 if (kvm_irqchip_in_kernel()) {
 env->mp_state = cpu_is_bsp(env) ? KVM_MP_STATE_RUNNABLE :
   KVM_MP_STATE_UNINITIALIZED;
@@ -845,6 +848,13 @@ static int kvm_put_msrs(CPUState *env, int level)
 if (smp_cpus == 1 || env->tsc != 0) {
 kvm_msr_entry_set(&msrs[n++], MSR_IA32_TSC, env->tsc);
 }
+}
+/*
+ * The following paravirtual MSRs have side effects on the guest or are
+ * too heavy for normal writeback. Limit them to reset or full state
+ * updates.
+ */
+if (level >= KVM_PUT_RESET_STATE) {
 kvm_msr_entry_set(&msrs[n++], MSR_KVM_SYSTEM_TIME,
   env->system_time_msr);
 kvm_msr_entry_set(&msrs[n++], MSR_KVM_WALL_CLOCK, env->wall_clock_msr);
-- 
1.7.1




[Qemu-devel] [PATCH v2 13/17] kvm: Eliminate KVMState arguments

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

QEMU supports only one VM, so there is only one kvm_state per process,
and we gain nothing passing a reference to it around. Eliminate any need
to refer to it outside of kvm-all.c.

Signed-off-by: Jan Kiszka 
CC: Alexander Graf 
---
 cpu-defs.h|2 -
 kvm-all.c |  232 +
 kvm-stub.c|2 +-
 kvm.h |   15 +--
 target-i386/cpuid.c   |9 +-
 target-i386/kvm.c |   77 
 target-i386/kvm_x86.h |3 +
 target-ppc/kvm.c  |   12 ++--
 target-s390x/kvm.c|8 +--
 9 files changed, 160 insertions(+), 200 deletions(-)

diff --git a/cpu-defs.h b/cpu-defs.h
index eaed43e..ada6629 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -131,7 +131,6 @@ typedef struct icount_decr_u16 {
 #endif
 
 struct kvm_run;
-struct KVMState;
 struct qemu_work_item;
 
 typedef struct CPUBreakpoint {
@@ -208,7 +207,6 @@ typedef struct CPUWatchpoint {
 struct QemuCond *halt_cond; \
 struct qemu_work_item *queued_work_first, *queued_work_last;\
 const char *cpu_model_str;  \
-struct KVMState *kvm_state; \
 struct kvm_run *kvm_run;\
 int kvm_fd; \
 int kvm_vcpu_dirty;
diff --git a/kvm-all.c b/kvm-all.c
index ef2ca3b..d8820c7 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -52,8 +52,7 @@ typedef struct KVMSlot
 
 typedef struct kvm_dirty_log KVMDirtyLog;
 
-struct KVMState
-{
+static struct KVMState {
 KVMSlot slots[32];
 int fd;
 int vmfd;
@@ -72,21 +71,19 @@ struct KVMState
 int irqchip_in_kernel;
 int pit_in_kernel;
 int xsave, xcrs;
-};
-
-static KVMState *kvm_state;
+} kvm_state;
 
-static KVMSlot *kvm_alloc_slot(KVMState *s)
+static KVMSlot *kvm_alloc_slot(void)
 {
 int i;
 
-for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
+for (i = 0; i < ARRAY_SIZE(kvm_state.slots); i++) {
 /* KVM private memory slots */
 if (i >= 8 && i < 12) {
 continue;
 }
-if (s->slots[i].memory_size == 0) {
-return &s->slots[i];
+if (kvm_state.slots[i].memory_size == 0) {
+return &kvm_state.slots[i];
 }
 }
 
@@ -94,14 +91,13 @@ static KVMSlot *kvm_alloc_slot(KVMState *s)
 abort();
 }
 
-static KVMSlot *kvm_lookup_matching_slot(KVMState *s,
- target_phys_addr_t start_addr,
+static KVMSlot *kvm_lookup_matching_slot(target_phys_addr_t start_addr,
  target_phys_addr_t end_addr)
 {
 int i;
 
-for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
-KVMSlot *mem = &s->slots[i];
+for (i = 0; i < ARRAY_SIZE(kvm_state.slots); i++) {
+KVMSlot *mem = &kvm_state.slots[i];
 
 if (start_addr == mem->start_addr &&
 end_addr == mem->start_addr + mem->memory_size) {
@@ -115,15 +111,14 @@ static KVMSlot *kvm_lookup_matching_slot(KVMState *s,
 /*
  * Find overlapping slot with lowest start address
  */
-static KVMSlot *kvm_lookup_overlapping_slot(KVMState *s,
-target_phys_addr_t start_addr,
+static KVMSlot *kvm_lookup_overlapping_slot(target_phys_addr_t start_addr,
 target_phys_addr_t end_addr)
 {
 KVMSlot *found = NULL;
 int i;
 
-for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
-KVMSlot *mem = &s->slots[i];
+for (i = 0; i < ARRAY_SIZE(kvm_state.slots); i++) {
+KVMSlot *mem = &kvm_state.slots[i];
 
 if (mem->memory_size == 0 ||
 (found && found->start_addr < mem->start_addr)) {
@@ -139,13 +134,13 @@ static KVMSlot *kvm_lookup_overlapping_slot(KVMState *s,
 return found;
 }
 
-int kvm_physical_memory_addr_from_ram(KVMState *s, ram_addr_t ram_addr,
+int kvm_physical_memory_addr_from_ram(ram_addr_t ram_addr,
   target_phys_addr_t *phys_addr)
 {
 int i;
 
-for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
-KVMSlot *mem = &s->slots[i];
+for (i = 0; i < ARRAY_SIZE(kvm_state.slots); i++) {
+KVMSlot *mem = &kvm_state.slots[i];
 
 if (ram_addr >= mem->phys_offset &&
 ram_addr < mem->phys_offset + mem->memory_size) {
@@ -157,7 +152,7 @@ int kvm_physical_memory_addr_from_ram(KVMState *s, 
ram_addr_t ram_addr,
 return 0;
 }
 
-static int kvm_set_user_memory_region(KVMState *s, KVMSlot *slot)
+static int kvm_set_user_memory_region(KVMSlot *slot)
 {
 struct kvm_userspace_memory_region mem;
 
@@ -166,10 +161,10 @@ static int kvm_set_user_memory_region(KVMState *s, 
KVMSlot *slot)
 mem.memory_size = slot->memory_size;
 mem.userspace_addr = (unsigned long)qemu_safe_ram_ptr(slot->phys_offset);
 mem.flags = slot->flags;
-if (s->migratio

[Qemu-devel] [PATCH v2 10/17] kvm: x86: Refactor msr_star/hsave_pa setup and checks

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

Simplify kvm_has_msr_star/hsave_pa to booleans and push their one-time
initialization into kvm_arch_init. Also handle potential errors of that
setup procedure.

Signed-off-by: Jan Kiszka 
---
 target-i386/kvm.c |   47 +++
 1 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index e46b901..d8f26bf 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -54,6 +54,8 @@
 #define BUS_MCEERR_AO 5
 #endif
 
+static bool has_msr_star;
+static bool has_msr_hsave_pa;
 static int lm_capable_kernel;
 
 #ifdef KVM_CAP_EXT_CPUID
@@ -459,13 +461,10 @@ void kvm_arch_reset_vcpu(CPUState *env)
 }
 }
 
-int has_msr_star;
-int has_msr_hsave_pa;
-
-static void kvm_supported_msrs(CPUState *env)
+static int kvm_get_supported_msrs(KVMState *s)
 {
 static int kvm_supported_msrs;
-int ret;
+int ret = 0;
 
 /* first time */
 if (kvm_supported_msrs == 0) {
@@ -476,9 +475,9 @@ static void kvm_supported_msrs(CPUState *env)
 /* Obtain MSR list from KVM.  These are the MSRs that we must
  * save/restore */
 msr_list.nmsrs = 0;
-ret = kvm_ioctl(env->kvm_state, KVM_GET_MSR_INDEX_LIST, &msr_list);
+ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, &msr_list);
 if (ret < 0 && ret != -E2BIG) {
-return;
+return ret;
 }
 /* Old kernel modules had a bug and could write beyond the provided
memory. Allocate at least a safe amount of 1K. */
@@ -487,17 +486,17 @@ static void kvm_supported_msrs(CPUState *env)
   sizeof(msr_list.indices[0])));
 
 kvm_msr_list->nmsrs = msr_list.nmsrs;
-ret = kvm_ioctl(env->kvm_state, KVM_GET_MSR_INDEX_LIST, kvm_msr_list);
+ret = kvm_ioctl(s, KVM_GET_MSR_INDEX_LIST, kvm_msr_list);
 if (ret >= 0) {
 int i;
 
 for (i = 0; i < kvm_msr_list->nmsrs; i++) {
 if (kvm_msr_list->indices[i] == MSR_STAR) {
-has_msr_star = 1;
+has_msr_star = true;
 continue;
 }
 if (kvm_msr_list->indices[i] == MSR_VM_HSAVE_PA) {
-has_msr_hsave_pa = 1;
+has_msr_hsave_pa = true;
 continue;
 }
 }
@@ -506,19 +505,7 @@ static void kvm_supported_msrs(CPUState *env)
 free(kvm_msr_list);
 }
 
-return;
-}
-
-static int kvm_has_msr_hsave_pa(CPUState *env)
-{
-kvm_supported_msrs(env);
-return has_msr_hsave_pa;
-}
-
-static int kvm_has_msr_star(CPUState *env)
-{
-kvm_supported_msrs(env);
-return has_msr_star;
+return ret;
 }
 
 static int kvm_init_identity_map_page(KVMState *s)
@@ -543,9 +530,13 @@ static int kvm_init_identity_map_page(KVMState *s)
 int kvm_arch_init(KVMState *s, int smp_cpus)
 {
 int ret;
-
 struct utsname utsname;
 
+ret = kvm_get_supported_msrs(s);
+if (ret < 0) {
+return ret;
+}
+
 uname(&utsname);
 lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0;
 
@@ -830,10 +821,10 @@ static int kvm_put_msrs(CPUState *env, int level)
 kvm_msr_entry_set(&msrs[n++], MSR_IA32_SYSENTER_CS, env->sysenter_cs);
 kvm_msr_entry_set(&msrs[n++], MSR_IA32_SYSENTER_ESP, env->sysenter_esp);
 kvm_msr_entry_set(&msrs[n++], MSR_IA32_SYSENTER_EIP, env->sysenter_eip);
-if (kvm_has_msr_star(env)) {
+if (has_msr_star) {
 kvm_msr_entry_set(&msrs[n++], MSR_STAR, env->star);
 }
-if (kvm_has_msr_hsave_pa(env)) {
+if (has_msr_hsave_pa) {
 kvm_msr_entry_set(&msrs[n++], MSR_VM_HSAVE_PA, env->vm_hsave);
 }
 #ifdef TARGET_X86_64
@@ -1076,10 +1067,10 @@ static int kvm_get_msrs(CPUState *env)
 msrs[n++].index = MSR_IA32_SYSENTER_CS;
 msrs[n++].index = MSR_IA32_SYSENTER_ESP;
 msrs[n++].index = MSR_IA32_SYSENTER_EIP;
-if (kvm_has_msr_star(env)) {
+if (has_msr_star) {
 msrs[n++].index = MSR_STAR;
 }
-if (kvm_has_msr_hsave_pa(env)) {
+if (has_msr_hsave_pa) {
 msrs[n++].index = MSR_VM_HSAVE_PA;
 }
 msrs[n++].index = MSR_IA32_TSC;
-- 
1.7.1




[Qemu-devel] [PATCH v2 06/17] kvm: x86: Align kvm_arch_put_registers code with comment

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

The ordering doesn't matter in this case, but better keep it consistent.

Signed-off-by: Jan Kiszka 
---
 target-i386/kvm.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index d4f253e..684430f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1388,12 +1388,12 @@ int kvm_arch_put_registers(CPUState *env, int level)
 if (ret < 0) {
 return ret;
 }
-/* must be last */
-ret = kvm_guest_debug_workarounds(env);
+ret = kvm_put_debugregs(env);
 if (ret < 0) {
 return ret;
 }
-ret = kvm_put_debugregs(env);
+/* must be last */
+ret = kvm_guest_debug_workarounds(env);
 if (ret < 0) {
 return ret;
 }
-- 
1.7.1




[Qemu-devel] [PATCH v2 17/17] kvm: Drop dependencies on very old capabilities

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

COALESCED_MMIO, SYNC_MMU, EXT_CPUID, CLOCKSOURCE, NOP_IO_DELAY, PV_MMU -
all these caps predate features on which we already depend at build
time. Moreover, the check for KVM_CAP_EXT_CPUID is unneeded as we
already test & fail is a more recent feature is missing.

Signed-off-by: Jan Kiszka 
---
 kvm-all.c |   16 
 target-i386/kvm.c |   22 --
 2 files changed, 0 insertions(+), 38 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 190fcdf..15d5f32 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -57,9 +57,7 @@ static struct KVMState {
 int fd;
 int vmfd;
 int coalesced_mmio;
-#ifdef KVM_CAP_COALESCED_MMIO
 struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
-#endif
 int broken_set_mem_region;
 int migration_log;
 int vcpu_events;
@@ -214,12 +212,10 @@ int kvm_init_vcpu(CPUState *env)
 goto err;
 }
 
-#ifdef KVM_CAP_COALESCED_MMIO
 if (kvm_state.coalesced_mmio && !kvm_state.coalesced_mmio_ring) {
 kvm_state.coalesced_mmio_ring =
 (void *)env->kvm_run + kvm_state.coalesced_mmio * PAGE_SIZE;
 }
-#endif
 
 ret = kvm_arch_init_vcpu(env);
 if (ret == 0) {
@@ -386,7 +382,6 @@ int kvm_coalesce_mmio_region(target_phys_addr_t start, 
ram_addr_t size)
 {
 int ret = -ENOSYS;
 
-#ifdef KVM_CAP_COALESCED_MMIO
 if (kvm_state.coalesced_mmio) {
 struct kvm_coalesced_mmio_zone zone;
 
@@ -395,7 +390,6 @@ int kvm_coalesce_mmio_region(target_phys_addr_t start, 
ram_addr_t size)
 
 ret = kvm_vm_ioctl(KVM_REGISTER_COALESCED_MMIO, &zone);
 }
-#endif
 
 return ret;
 }
@@ -404,7 +398,6 @@ int kvm_uncoalesce_mmio_region(target_phys_addr_t start, 
ram_addr_t size)
 {
 int ret = -ENOSYS;
 
-#ifdef KVM_CAP_COALESCED_MMIO
 if (kvm_state.coalesced_mmio) {
 struct kvm_coalesced_mmio_zone zone;
 
@@ -413,7 +406,6 @@ int kvm_uncoalesce_mmio_region(target_phys_addr_t start, 
ram_addr_t size)
 
 ret = kvm_vm_ioctl(KVM_UNREGISTER_COALESCED_MMIO, &zone);
 }
-#endif
 
 return ret;
 }
@@ -654,9 +646,7 @@ int kvm_init(void)
 goto err;
 }
 
-#ifdef KVM_CAP_COALESCED_MMIO
 kvm_state.coalesced_mmio = kvm_check_extension(KVM_CAP_COALESCED_MMIO);
-#endif
 
 kvm_state.broken_set_mem_region = 1;
 #ifdef KVM_CAP_JOIN_MEMORY_REGIONS_WORKS
@@ -777,7 +767,6 @@ static int kvm_handle_internal_error(CPUState *env, struct 
kvm_run *run)
 
 void kvm_flush_coalesced_mmio_buffer(void)
 {
-#ifdef KVM_CAP_COALESCED_MMIO
 if (kvm_state.coalesced_mmio_ring) {
 struct kvm_coalesced_mmio_ring *ring = kvm_state.coalesced_mmio_ring;
 while (ring->first != ring->last) {
@@ -790,7 +779,6 @@ void kvm_flush_coalesced_mmio_buffer(void)
 ring->first = (ring->first + 1) % KVM_COALESCED_MMIO_MAX;
 }
 }
-#endif
 }
 
 static void do_kvm_cpu_synchronize_state(void *_env)
@@ -988,11 +976,7 @@ int kvm_vcpu_ioctl(CPUState *env, int type, ...)
 
 int kvm_has_sync_mmu(void)
 {
-#ifdef KVM_CAP_SYNC_MMU
 return kvm_check_extension(KVM_CAP_SYNC_MMU);
-#else
-return 0;
-#endif
 }
 
 int kvm_has_vcpu_events(void)
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index caca407..b4a3463 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -59,8 +59,6 @@ static bool has_msr_star;
 static bool has_msr_hsave_pa;
 static int lm_capable_kernel;
 
-#ifdef KVM_CAP_EXT_CPUID
-
 static struct kvm_cpuid2 *try_get_cpuid(int max)
 {
 struct kvm_cpuid2 *cpuid;
@@ -94,10 +92,6 @@ uint32_t kvm_x86_get_supported_cpuid(uint32_t function, 
uint32_t index,
 uint32_t ret = 0;
 uint32_t cpuid_1_edx;
 
-if (!kvm_check_extension(KVM_CAP_EXT_CPUID)) {
-return -1U;
-}
-
 max = 1;
 while ((cpuid = try_get_cpuid(max)) == NULL) {
 max *= 2;
@@ -141,30 +135,14 @@ uint32_t kvm_x86_get_supported_cpuid(uint32_t function, 
uint32_t index,
 return ret;
 }
 
-#else
-
-uint32_t kvm_x86_get_supported_cpuid(uint32_t function, uint32_t index,
- int reg)
-{
-return -1U;
-}
-
-#endif
-
 #ifdef CONFIG_KVM_PARA
 struct kvm_para_features {
 int cap;
 int feature;
 } para_features[] = {
-#ifdef KVM_CAP_CLOCKSOURCE
 { KVM_CAP_CLOCKSOURCE, KVM_FEATURE_CLOCKSOURCE },
-#endif
-#ifdef KVM_CAP_NOP_IO_DELAY
 { KVM_CAP_NOP_IO_DELAY, KVM_FEATURE_NOP_IO_DELAY },
-#endif
-#ifdef KVM_CAP_PV_MMU
 { KVM_CAP_PV_MMU, KVM_FEATURE_MMU_OP },
-#endif
 #ifdef KVM_CAP_ASYNC_PF
 { KVM_CAP_ASYNC_PF, KVM_FEATURE_ASYNC_PF },
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH v2 04/17] kvm: Improve reporting of fatal errors

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

Report KVM_EXIT_UNKNOWN, KVM_EXIT_FAIL_ENTRY, and KVM_EXIT_EXCEPTION
with more details to stderr. The latter two are so far x86-only, so move
them into the arch-specific handler. Integrate the Intel real mode
warning on KVM_EXIT_FAIL_ENTRY that qemu-kvm carries, but actually
restrict it to Intel CPUs. Moreover, always dump the CPU state in case
we fail.

Signed-off-by: Jan Kiszka 
---
 kvm-all.c   |   22 --
 target-i386/cpu.h   |2 ++
 target-i386/cpuid.c |5 ++---
 target-i386/kvm.c   |   33 +
 4 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index a46a3b6..ad1d0a8 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -776,22 +776,22 @@ static int kvm_handle_io(uint16_t port, void *data, int 
direction, int size,
 #ifdef KVM_CAP_INTERNAL_ERROR_DATA
 static int kvm_handle_internal_error(CPUState *env, struct kvm_run *run)
 {
-
+fprintf(stderr, "KVM internal error.");
 if (kvm_check_extension(kvm_state, KVM_CAP_INTERNAL_ERROR_DATA)) {
 int i;
 
-fprintf(stderr, "KVM internal error. Suberror: %d\n",
-run->internal.suberror);
-
+fprintf(stderr, " Suberror: %d\n", run->internal.suberror);
 for (i = 0; i < run->internal.ndata; ++i) {
 fprintf(stderr, "extra data[%d]: %"PRIx64"\n",
 i, (uint64_t)run->internal.data[i]);
 }
+} else {
+fprintf(stderr, "\n");
 }
-cpu_dump_state(env, stderr, fprintf, 0);
 if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) {
 fprintf(stderr, "emulation failure\n");
 if (!kvm_arch_stop_on_emulation_error(env)) {
+cpu_dump_state(env, stderr, fprintf, 0);
 return 0;
 }
 }
@@ -925,15 +925,8 @@ void kvm_cpu_exec(CPUState *env)
 ret = 1;
 break;
 case KVM_EXIT_UNKNOWN:
-DPRINTF("kvm_exit_unknown\n");
-ret = -1;
-break;
-case KVM_EXIT_FAIL_ENTRY:
-DPRINTF("kvm_exit_fail_entry\n");
-ret = -1;
-break;
-case KVM_EXIT_EXCEPTION:
-DPRINTF("kvm_exit_exception\n");
+fprintf(stderr, "KVM: unknown exit, hardware reason %" PRIx64 "\n",
+(uint64_t)run->hw.hardware_exit_reason);
 ret = -1;
 break;
 #ifdef KVM_CAP_INTERNAL_ERROR_DATA
@@ -960,6 +953,7 @@ void kvm_cpu_exec(CPUState *env)
 } while (ret > 0);
 
 if (ret < 0) {
+cpu_dump_state(env, stderr, fprintf, 0);
 vm_stop(0);
 env->exit_request = 1;
 }
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index dddcd74..a457423 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -874,6 +874,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
uint32_t *ecx, uint32_t *edx);
 int cpu_x86_register (CPUX86State *env, const char *cpu_model);
 void cpu_clear_apic_feature(CPUX86State *env);
+void host_cpuid(uint32_t function, uint32_t count,
+uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
 
 /* helper.c */
 int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 165045e..5382a28 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -103,9 +103,8 @@ typedef struct model_features_t {
 int check_cpuid = 0;
 int enforce_cpuid = 0;
 
-static void host_cpuid(uint32_t function, uint32_t count,
-   uint32_t *eax, uint32_t *ebx,
-   uint32_t *ecx, uint32_t *edx)
+void host_cpuid(uint32_t function, uint32_t count,
+uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
 {
 #if defined(CONFIG_KVM)
 uint32_t vec[4];
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 2431a1f..d4f253e 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1525,8 +1525,19 @@ static int kvm_handle_halt(CPUState *env)
 return 1;
 }
 
+static bool host_supports_vmx(void)
+{
+uint32_t ecx, unused;
+
+host_cpuid(1, 0, &unused, &unused, &ecx, &unused);
+return ecx & CPUID_EXT_VMX;
+}
+
+#define VMX_INVALID_GUEST_STATE 0x8021
+
 int kvm_arch_handle_exit(CPUState *env, struct kvm_run *run)
 {
+uint64_t code;
 int ret = 0;
 
 switch (run->exit_reason) {
@@ -1534,6 +1545,28 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run 
*run)
 DPRINTF("handle_hlt\n");
 ret = kvm_handle_halt(env);
 break;
+case KVM_EXIT_FAIL_ENTRY:
+code = run->fail_entry.hardware_entry_failure_reason;
+fprintf(stderr, "KVM: entry failed, hardware error 0x%" PRIx64 "\n",
+code);
+if (host_supports_vmx() && code == VMX_INVALID_GUEST_STATE) {
+fprintf(stderr,
+"\nIf you're runnning a guest on an Intel machine without "
+"unrestricted mode\n"

[Qemu-devel] [PATCH v2 12/17] kvm: x86: Drop MCE MSRs write back restrictions

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

There is no need to restrict writing back MCE MSRs to reset or full
state updates as setting their values has no side effects.

Signed-off-by: Jan Kiszka 
CC: Huang Ying 
---
 target-i386/kvm.c |   12 
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 664a4a0..ef8f6e6 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -866,14 +866,10 @@ static int kvm_put_msrs(CPUState *env, int level)
 if (env->mcg_cap) {
 int i;
 
-if (level == KVM_PUT_RESET_STATE) {
-kvm_msr_entry_set(&msrs[n++], MSR_MCG_STATUS, env->mcg_status);
-} else if (level == KVM_PUT_FULL_STATE) {
-kvm_msr_entry_set(&msrs[n++], MSR_MCG_STATUS, env->mcg_status);
-kvm_msr_entry_set(&msrs[n++], MSR_MCG_CTL, env->mcg_ctl);
-for (i = 0; i < (env->mcg_cap & 0xff) * 4; i++) {
-kvm_msr_entry_set(&msrs[n++], MSR_MC0_CTL + i, 
env->mce_banks[i]);
-}
+kvm_msr_entry_set(&msrs[n++], MSR_MCG_STATUS, env->mcg_status);
+kvm_msr_entry_set(&msrs[n++], MSR_MCG_CTL, env->mcg_ctl);
+for (i = 0; i < (env->mcg_cap & 0xff) * 4; i++) {
+kvm_msr_entry_set(&msrs[n++], MSR_MC0_CTL + i, env->mce_banks[i]);
 }
 }
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH v2 03/17] kvm: Stop on all fatal exit reasons

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

Ensure that we stop the guest whenever we face a fatal or unknown exit
reason. If we stop, we also have to enforce a cpu loop exit.

Signed-off-by: Jan Kiszka 
---
 kvm-all.c |   15 +++
 target-i386/kvm.c |4 
 target-ppc/kvm.c  |4 
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 7518f2c..a46a3b6 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -774,7 +774,7 @@ static int kvm_handle_io(uint16_t port, void *data, int 
direction, int size,
 }
 
 #ifdef KVM_CAP_INTERNAL_ERROR_DATA
-static void kvm_handle_internal_error(CPUState *env, struct kvm_run *run)
+static int kvm_handle_internal_error(CPUState *env, struct kvm_run *run)
 {
 
 if (kvm_check_extension(kvm_state, KVM_CAP_INTERNAL_ERROR_DATA)) {
@@ -792,13 +792,13 @@ static void kvm_handle_internal_error(CPUState *env, 
struct kvm_run *run)
 if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) {
 fprintf(stderr, "emulation failure\n");
 if (!kvm_arch_stop_on_emulation_error(env)) {
-return;
+return 0;
 }
 }
 /* FIXME: Should trigger a qmp message to let management know
  * something went wrong.
  */
-vm_stop(0);
+return -1;
 }
 #endif
 
@@ -926,16 +926,19 @@ void kvm_cpu_exec(CPUState *env)
 break;
 case KVM_EXIT_UNKNOWN:
 DPRINTF("kvm_exit_unknown\n");
+ret = -1;
 break;
 case KVM_EXIT_FAIL_ENTRY:
 DPRINTF("kvm_exit_fail_entry\n");
+ret = -1;
 break;
 case KVM_EXIT_EXCEPTION:
 DPRINTF("kvm_exit_exception\n");
+ret = -1;
 break;
 #ifdef KVM_CAP_INTERNAL_ERROR_DATA
 case KVM_EXIT_INTERNAL_ERROR:
-kvm_handle_internal_error(env, run);
+ret = kvm_handle_internal_error(env, run);
 break;
 #endif
 case KVM_EXIT_DEBUG:
@@ -956,6 +959,10 @@ void kvm_cpu_exec(CPUState *env)
 }
 } while (ret > 0);
 
+if (ret < 0) {
+vm_stop(0);
+env->exit_request = 1;
+}
 if (env->exit_request) {
 env->exit_request = 0;
 env->exception_index = EXCP_INTERRUPT;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index fda07d2..2431a1f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1534,6 +1534,10 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run 
*run)
 DPRINTF("handle_hlt\n");
 ret = kvm_handle_halt(env);
 break;
+default:
+fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
+ret = -1;
+break;
 }
 
 return ret;
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 5caa07c..849b404 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -307,6 +307,10 @@ int kvm_arch_handle_exit(CPUState *env, struct kvm_run 
*run)
 dprintf("handle halt\n");
 ret = kvmppc_handle_halt(env);
 break;
+default:
+fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
+ret = -1;
+break;
 }
 
 return ret;
-- 
1.7.1




[Qemu-devel] Role of qemu_fair_mutex

2011-01-03 Thread Jan Kiszka
Hi,

at least in kvm mode, the qemu_fair_mutex seems to have lost its
function of balancing qemu_global_mutex access between the io-thread and
vcpus. It's now only taken by the latter, isn't it?

This and the fact that qemu-kvm does not use this kind of lock made me
wonder what its role is and if it is still relevant in practice. I'd
like to unify the execution models of qemu-kvm and qemu, and this lock
is the most obvious difference (there are surely more subtle ones as
well...).

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [Bug 513273] Re: kvm with -vga std is broken since karmic

2011-01-03 Thread Theo Nolte
Building vgabios from source as described above added the missing modes
for me too.  But still the vga driver does not work properly - it builds
the screen very slowly line by line and takes 20 seconds or more just
for the login-screen.

After some hours I gave up on vga and switched to the vmware-driver -
now everything works great.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/513273

Title:
  kvm with -vga std is broken since karmic

Status in QEMU:
  Invalid
Status in “qemu-kvm” package in Ubuntu:
  Invalid
Status in “seabios” package in Ubuntu:
  Invalid
Status in “vgabios” package in Ubuntu:
  Fix Released
Status in “qemu-kvm” source package in Lucid:
  Invalid
Status in “seabios” source package in Lucid:
  Invalid
Status in “vgabios” source package in Lucid:
  Fix Released

Bug description:
  Binary package hint: qemu-kvm

it works with -vga cirrus, with -vga std I got:

BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters


And driver do not work properly (I can not set screen resolution) ...
virtual machine almost works, only screen problem in winxp guest

ProblemType: Bug
Architecture: amd64
Date: Wed Jan 27 15:15:49 2010
DistroRelease: Ubuntu 10.04
KvmCmdLine: Error: command ['ps', '-C', 'kvm', '-F'] failed with exit code 1: 
UIDPID  PPID  CSZ   RSS PSR STIME TTY  TIME CMD
MachineType: Acer Aspire 9300
NonfreeKernelModules: nvidia
Pack

[Qemu-devel] Re: Role of qemu_fair_mutex

2011-01-03 Thread Avi Kivity

On 01/03/2011 11:46 AM, Jan Kiszka wrote:

Hi,

at least in kvm mode, the qemu_fair_mutex seems to have lost its
function of balancing qemu_global_mutex access between the io-thread and
vcpus. It's now only taken by the latter, isn't it?

This and the fact that qemu-kvm does not use this kind of lock made me
wonder what its role is and if it is still relevant in practice. I'd
like to unify the execution models of qemu-kvm and qemu, and this lock
is the most obvious difference (there are surely more subtle ones as
well...).



IIRC it was used for tcg, which has a problem that kvm doesn't have: a 
tcg vcpu needs to hold qemu_mutex when it runs, which means there will 
always be contention on qemu_mutex.  In the absence of fairness, the tcg 
thread could dominate qemu_mutex and starve the iothread.


This doesn't happen with kvm since kvm vcpus drop qemu_mutex when running.

--
error compiling committee.c: too many arguments to function




[Qemu-devel] Re: Role of qemu_fair_mutex

2011-01-03 Thread Jan Kiszka
Am 03.01.2011 11:01, Avi Kivity wrote:
> On 01/03/2011 11:46 AM, Jan Kiszka wrote:
>> Hi,
>>
>> at least in kvm mode, the qemu_fair_mutex seems to have lost its
>> function of balancing qemu_global_mutex access between the io-thread and
>> vcpus. It's now only taken by the latter, isn't it?
>>
>> This and the fact that qemu-kvm does not use this kind of lock made me
>> wonder what its role is and if it is still relevant in practice. I'd
>> like to unify the execution models of qemu-kvm and qemu, and this lock
>> is the most obvious difference (there are surely more subtle ones as
>> well...).
>>
> 
> IIRC it was used for tcg, which has a problem that kvm doesn't have: a
> tcg vcpu needs to hold qemu_mutex when it runs, which means there will
> always be contention on qemu_mutex.  In the absence of fairness, the tcg
> thread could dominate qemu_mutex and starve the iothread.
> 
> This doesn't happen with kvm since kvm vcpus drop qemu_mutex when running.
> 

I see. Then I guess we should do this:

diff --git a/cpus.c b/cpus.c
index 9bf5224..0de8552 100644
--- a/cpus.c
+++ b/cpus.c
@@ -734,9 +734,7 @@ static sigset_t block_io_signals(void)
 void qemu_mutex_lock_iothread(void)
 {
 if (kvm_enabled()) {
-qemu_mutex_lock(&qemu_fair_mutex);
 qemu_mutex_lock(&qemu_global_mutex);
-qemu_mutex_unlock(&qemu_fair_mutex);
 } else {
 qemu_mutex_lock(&qemu_fair_mutex);
 if (qemu_mutex_trylock(&qemu_global_mutex)) {

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] Re: Role of qemu_fair_mutex

2011-01-03 Thread Avi Kivity

On 01/03/2011 12:03 PM, Jan Kiszka wrote:

Am 03.01.2011 11:01, Avi Kivity wrote:
>  On 01/03/2011 11:46 AM, Jan Kiszka wrote:
>>  Hi,
>>
>>  at least in kvm mode, the qemu_fair_mutex seems to have lost its
>>  function of balancing qemu_global_mutex access between the io-thread and
>>  vcpus. It's now only taken by the latter, isn't it?
>>
>>  This and the fact that qemu-kvm does not use this kind of lock made me
>>  wonder what its role is and if it is still relevant in practice. I'd
>>  like to unify the execution models of qemu-kvm and qemu, and this lock
>>  is the most obvious difference (there are surely more subtle ones as
>>  well...).
>>
>
>  IIRC it was used for tcg, which has a problem that kvm doesn't have: a
>  tcg vcpu needs to hold qemu_mutex when it runs, which means there will
>  always be contention on qemu_mutex.  In the absence of fairness, the tcg
>  thread could dominate qemu_mutex and starve the iothread.
>
>  This doesn't happen with kvm since kvm vcpus drop qemu_mutex when running.
>

I see. Then I guess we should do this:

diff --git a/cpus.c b/cpus.c
index 9bf5224..0de8552 100644
--- a/cpus.c
+++ b/cpus.c
@@ -734,9 +734,7 @@ static sigset_t block_io_signals(void)
  void qemu_mutex_lock_iothread(void)
  {
  if (kvm_enabled()) {
-qemu_mutex_lock(&qemu_fair_mutex);
  qemu_mutex_lock(&qemu_global_mutex);
-qemu_mutex_unlock(&qemu_fair_mutex);
  } else {
  qemu_mutex_lock(&qemu_fair_mutex);
  if (qemu_mutex_trylock(&qemu_global_mutex)) {


I think so, though Anthony or Marcelo should confirm my interpretation 
first.


--
error compiling committee.c: too many arguments to function




[Qemu-devel] Debugging a 64-bit kernel in qemu

2011-01-03 Thread Markus Duft
Hi!

I have been playing a little with this: I'm writing a kernel for both x86 and 
x86-64. While doing so, i'd like to debug the kernel using qemu (and it's gdb 
stub) and gdb. This worked very well until qemu-0.11.1 (gdb version does not 
seem to play any role...). From there on, debugging the 64 bit version no 
longer works. My sessions look like this with qemu-0.13.50 (and any version 
above 0.11.1, actually...):

md...@s01en22 /big/Privat/osdev/tachyon2 $ x86_64-pc-linux-gnu-gdb 
.build/x86_64/x86_64-tachyon
GNU gdb (GDB) 7.2.50.20110103-cvs
[snip]
Reading symbols from 
/big/Privat/osdev/tachyon2/.build/x86_64/x86_64-tachyon...done.
(gdb) target remote:1234
Remote debugging using :1234
0x in ?? ()
(gdb) b boot
Breakpoint 1 at 0x80119000: file 
/big/Privat/osdev/tachyon2/core/tachyon.boot/Entry.cc, line 25.
(gdb) c
Continuing.
Remote 'g' packet reply is too long: 
09ea1180009512b0ad2b00950095d6101180ce1011800090118046001800100010001000100010007f030
000801f
(gdb) quit

actuallly, i _can_ debug the kernel, nut only until the long mode switch 
occurs. after this point: no luck... :[

now for the questions:

1) is this a problem with qemu or was qemu "fixed" and gdb has a problem?
   (that's why i CCd the gdb list ;)).
2) is there any plan to fix this issue?
3) is there some kind of workaround i can use (i'd be happy with an 
ugly/unsupported patch too, since i build all my stuff myself ;)).

Thanks in advance!
Regards, Markus



Re: [Qemu-devel] [PATCH 0/5] usb-ccid (v11)

2011-01-03 Thread Gerd Hoffmann

On 12/17/10 20:44, Alon Levy wrote:

This patchset adds three new devices, usb-ccid, ccid-card-passthru and
ccid-card-emulated, providing a CCID bus, a simple passthru protocol
implementing card requiring a client, and a standalone emulated card.

It also introduces a new directory libcaccard with CAC card emulation,
CAC is a type of ISO 7816 smart card.


Patch series looks good to me now.  Doesn't apply cleanly to master 
though (conflicts in configure), so it needs a rebase I guess.  Also a 
git tree to pull from would be nice.


thanks,
  Gerd



Re: [Qemu-devel] Where is ehci hiding ?

2011-01-03 Thread Gerd Hoffmann

On 12/21/10 16:16, Olivier Galibert wrote:

   Hi all,

Google sees patches to hw/usb-ehci.c from time to time, in
http://www.mail-archive.com/qemu-devel@nongnu.org/msg37741.html for
instance.  Where is that code hiding, since I just can't find it in
the git tree?


I'm busy working on the qemu usb subsystem, ehci is one of the items on 
my todo list.  My latest bits are here:


http://cgit.freedesktop.org/spice/qemu/log/?h=usb.3.wip

cheers,
  Gerd




[Qemu-devel] KVM call agenda for Jan 4

2011-01-03 Thread Juan Quintela

Please send any agenda items you are interested in covering.

thanks, Juan.



Re: [Qemu-devel] [PATCH 0/5] usb-ccid (v11)

2011-01-03 Thread Alon Levy
On Mon, Jan 03, 2011 at 11:39:01AM +0100, Gerd Hoffmann wrote:
> On 12/17/10 20:44, Alon Levy wrote:
> >This patchset adds three new devices, usb-ccid, ccid-card-passthru and
> >ccid-card-emulated, providing a CCID bus, a simple passthru protocol
> >implementing card requiring a client, and a standalone emulated card.
> >
> >It also introduces a new directory libcaccard with CAC card emulation,
> >CAC is a type of ISO 7816 smart card.
> 
> Patch series looks good to me now.  Doesn't apply cleanly to master
> though (conflicts in configure), so it needs a rebase I guess.  Also
> a git tree to pull from would be nice.

rebased, pull from:
 git://anongit.freedesktop.org/~alon/qemu usb_ccid.v11

> 
> thanks,
>   Gerd



[Qemu-devel] Re: [PATCH v2 13/17] kvm: Eliminate KVMState arguments

2011-01-03 Thread Alexander Graf

On 03.01.2011, at 09:33, Jan Kiszka wrote:

> From: Jan Kiszka 
> 
> QEMU supports only one VM, so there is only one kvm_state per process,
> and we gain nothing passing a reference to it around. Eliminate any need
> to refer to it outside of kvm-all.c.

Slightly unqemu'ish, but I like the simplicity of it :).

Acked-by: Alexander Graf 


Alex




[Qemu-devel] Re: Debugging a 64-bit kernel in qemu

2011-01-03 Thread Jan Kiszka
Am 03.01.2011 11:27, Markus Duft wrote:
> Hi!
> 
> I have been playing a little with this: I'm writing a kernel for both x86 and 
> x86-64. While doing so, i'd like to debug the kernel using qemu (and it's gdb 
> stub) and gdb. This worked very well until qemu-0.11.1 (gdb version does not 
> seem to play any role...). From there on, debugging the 64 bit version no 
> longer works. My sessions look like this with qemu-0.13.50 (and any version 
> above 0.11.1, actually...):
> 
> md...@s01en22 /big/Privat/osdev/tachyon2 $ x86_64-pc-linux-gnu-gdb 
> .build/x86_64/x86_64-tachyon
> GNU gdb (GDB) 7.2.50.20110103-cvs
> [snip]
> Reading symbols from 
> /big/Privat/osdev/tachyon2/.build/x86_64/x86_64-tachyon...done.
> (gdb) target remote:1234
> Remote debugging using :1234
> 0x in ?? ()
> (gdb) b boot
> Breakpoint 1 at 0x80119000: file 
> /big/Privat/osdev/tachyon2/core/tachyon.boot/Entry.cc, line 25.
> (gdb) c
> Continuing.
> Remote 'g' packet reply is too long: 
> 09ea1180009512b0ad2b00950095d6101180ce1011800090118046001800100010001000100010007f03000
>  
> 00
> 000801f
> (gdb) quit
> 
> actuallly, i _can_ debug the kernel, nut only until the long mode switch 
> occurs. after this point: no luck... :[
> 
> now for the questions:
> 
> 1) is this a problem with qemu or was qemu "fixed" and gdb has a problem?
>(that's why i CCd the gdb list ;)).
> 2) is there any plan to fix this issue?
> 3) is there some kind of workaround i can use (i'd be happy with an 
> ugly/unsupported patch too, since i build all my stuff myself ;)).

You see the effects of a workaround in qemu for gdb shortcomings on x86.
See e.g. http://thread.gmane.org/gmane.comp.emulators.qemu/80327, there
should be some threads on the gdb list as well.

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] qemu vs. kvm: When to flush the coalesced mmio buffer?

2011-01-03 Thread Jan Kiszka
Hi again,

another subtle difference between qemu-kvm and upstream:

When we leave the guest for an IO window (KVM_RUN returns EINTR or
EAGAIN), we call kvm_flush_coalesced_mmio_buffer in qemu-kvm but not in
upstream. When version is better? I can't find any rationales in both
git logs.

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Re: Debugging a 64-bit kernel in qemu

2011-01-03 Thread Markus Duft
On 01/03/2011 12:15 PM, Jan Kiszka wrote:
[snip]
>>
>> 1) is this a problem with qemu or was qemu "fixed" and gdb has a problem?
>>(that's why i CCd the gdb list ;)).
>> 2) is there any plan to fix this issue?
>> 3) is there some kind of workaround i can use (i'd be happy with an 
>> ugly/unsupported patch too, since i build all my stuff myself ;)).
> 
> You see the effects of a workaround in qemu for gdb shortcomings on x86.
> See e.g. http://thread.gmane.org/gmane.comp.emulators.qemu/80327, there
> should be some threads on the gdb list as well.

Hmm, from the thread i read, that it should be possible to interrupt the code 
from gdb (by pressing CTRL-C), and set a 64 bit breakpoint then? In case this 
should work: it doesn't. I'm getting the very same packet too long error, as 
soon as i try to do _anything_ with the debugger. so, actually, the state this 
is in is completely unusable to debug 64 bit code. i cannot find any way to do 
it. 

actually, i find that Ted Harkington was right: in 0.11.1 i can debug 32 bit 
code with qemu-system-x86_64 well enough (which means i debugged all the 32 bit 
part of my kernel without ever seen _any_ problem/non-working 
feature/whatever). wouldn't it be better to have 64 bit debugging working in 
the 64 bit version, with 32 bit mode working mostly (with whatever small 
issues), rather than just completely dooming 64 bit debugging...?

any further ideas?

BTW, i did look around a little for this problem before (although i wasn't 
aware of the thread you pointed me to). All those threads don't propose any 
solution other than "fix gdb", which may or may not take ages.

Regards, Markus

> 
> Jan
> 




Re: [Qemu-devel] qemu vs. kvm: When to flush the coalesced mmio buffer?

2011-01-03 Thread Gleb Natapov
On Mon, Jan 03, 2011 at 01:11:32PM +0100, Jan Kiszka wrote:
> Hi again,
> 
> another subtle difference between qemu-kvm and upstream:
> 
> When we leave the guest for an IO window (KVM_RUN returns EINTR or
> EAGAIN), we call kvm_flush_coalesced_mmio_buffer in qemu-kvm but not in
> upstream. When version is better? I can't find any rationales in both
> git logs.
> 
Since coalesced mmio is used to prevent unnecessary exits to userspace
if vcpu thread is already in userspace why not flush coalesced mmio
buffer?

--
Gleb.



Re: [Qemu-devel] Re: Debugging a 64-bit kernel in qemu

2011-01-03 Thread Markus Duft
On 01/03/2011 01:15 PM, Markus Duft wrote:
> On 01/03/2011 12:15 PM, Jan Kiszka wrote:
> [snip]
[snip]
> actually, i find that Ted Harkington was right: in 0.11.1 i can debug 32 bit 
> code with qemu-system-x86_64 well enough (which means i debugged all the 32 
> bit part of my kernel without ever seen _any_ problem/non-working 
> feature/whatever). wouldn't it be better to have 64 bit debugging working in 
> the 64 bit version, with 32 bit mode working mostly (with whatever small 
> issues), rather than just completely dooming 64 bit debugging...?
> 

owh - spoke too soon. there must be more to it: i tried reverting 
5f30fa18ad043a841fe9f0c3917ac60f2519ebd1, which restores ability to debug my 64 
bit kernel just fine, but now i get the packet too long when trying to debug 32 
bit code

wouldn't it be possible to implement some kind of explicit switch with qemu in 
the meantime, so i can choose what bitness i want to debug? I know, it's a 
problem with gdb under the hood, but still - it's really uncool debugging 
doesn't work in either of the two cases.

Regards, Markus

> any further ideas?
> 
> BTW, i did look around a little for this problem before (although i wasn't 
> aware of the thread you pointed me to). All those threads don't propose any 
> solution other than "fix gdb", which may or may not take ages.
> 
> Regards, Markus
> 
>>
>> Jan
>>
> 
> 




[Qemu-devel] Re: qemu vs. kvm: When to flush the coalesced mmio buffer?

2011-01-03 Thread Avi Kivity

On 01/03/2011 02:11 PM, Jan Kiszka wrote:

Hi again,

another subtle difference between qemu-kvm and upstream:

When we leave the guest for an IO window (KVM_RUN returns EINTR or
EAGAIN), we call kvm_flush_coalesced_mmio_buffer in qemu-kvm but not in
upstream. When version is better? I can't find any rationales in both
git logs.


We must flush on EINTR, otherwise a live migration can leave some mmios 
in the source host and not replay them on the destination host.


(plus, as Gleb says, if you're in userspace you might as well flush)

--
error compiling committee.c: too many arguments to function




[Qemu-devel] Re: qemu vs. kvm: When to flush the coalesced mmio buffer?

2011-01-03 Thread Jan Kiszka
Am 03.01.2011 13:32, Avi Kivity wrote:
> On 01/03/2011 02:11 PM, Jan Kiszka wrote:
>> Hi again,
>>
>> another subtle difference between qemu-kvm and upstream:
>>
>> When we leave the guest for an IO window (KVM_RUN returns EINTR or
>> EAGAIN), we call kvm_flush_coalesced_mmio_buffer in qemu-kvm but not in
>> upstream. When version is better? I can't find any rationales in both
>> git logs.
> 
> We must flush on EINTR, otherwise a live migration can leave some mmios
> in the source host and not replay them on the destination host.
> 
> (plus, as Gleb says, if you're in userspace you might as well flush)
> 

OK, will append a fix to my series.

Thanks,
Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 18/17] kvm: Flush coalesced mmio buffer on IO window exits

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

We must flush pending mmio writes if we leave kvm_cpu_exec for an IO
window. Otherwise we risk to loose those requests when migrating to a
different host during that window.

Signed-off-by: Jan Kiszka 
---
 kvm-all.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 15d5f32..766a3a7 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -844,6 +844,8 @@ void kvm_cpu_exec(CPUState *env)
 cpu_single_env = env;
 kvm_arch_post_run(env, run);
 
+kvm_flush_coalesced_mmio_buffer();
+
 if (ret == -EINTR || ret == -EAGAIN) {
 cpu_exit(env);
 DPRINTF("io window exit\n");
@@ -856,8 +858,6 @@ void kvm_cpu_exec(CPUState *env)
 abort();
 }
 
-kvm_flush_coalesced_mmio_buffer();
-
 ret = 0; /* exit loop */
 switch (run->exit_reason) {
 case KVM_EXIT_IO:



[Qemu-devel] [Bug 524447] Re: virsh save is very slow

2011-01-03 Thread Paolo Bonzini
The patch is in 0.13.0, so changing the status.

** Changed in: qemu
   Status: Invalid => Fix Released

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/524447

Title:
  virsh save is very slow

Status in libvirt virtualization API:
  Unknown
Status in QEMU:
  Fix Released
Status in “libvirt” package in Ubuntu:
  Confirmed
Status in “qemu-kvm” package in Ubuntu:
  Confirmed

Bug description:
  As reported here: 
http://www.redhat.com/archives/libvir-list/2009-December/msg00203.html

"virsh save" is very slow - it writes the image at around 1MB/sec on my test 
system.

(I think I saw a bug report for this issue on Fedora's bugzilla, but I can't 
find it now...)

Confirmed under Karmic.





[Qemu-devel] Re: Debugging a 64-bit kernel in qemu

2011-01-03 Thread Jan Kiszka
[ please keep CCs ]

Am 03.01.2011 13:27, Markus Duft wrote:
> On 01/03/2011 01:15 PM, Markus Duft wrote:
>> On 01/03/2011 12:15 PM, Jan Kiszka wrote:
>> [snip]
> [snip]
>> actually, i find that Ted Harkington was right: in 0.11.1 i can debug 32 bit 
>> code with qemu-system-x86_64 well enough (which means i debugged all the 32 
>> bit part of my kernel without ever seen _any_ problem/non-working 
>> feature/whatever). wouldn't it be better to have 64 bit debugging working in 
>> the 64 bit version, with 32 bit mode working mostly (with whatever small 
>> issues), rather than just completely dooming 64 bit debugging...?
>>
> 
> owh - spoke too soon. there must be more to it: i tried reverting 
> 5f30fa18ad043a841fe9f0c3917ac60f2519ebd1, which restores ability to debug my 
> 64 bit kernel just fine, but now i get the packet too long when trying to 
> debug 32 bit code

Hmm, that's new. You definitely loose stack unwinding when using the
wrong mode, thus source-level debugging.

I thought that thread suggested to set the arch explicitly, maybe I
misremembered that:

set arch i386:x86_64
tar rem :1234

If that is required, you probably load a 32-bit binary into gdb that
also contains 64-bit code in some section. I guess this is even more
confusing for gdb.

> 
> wouldn't it be possible to implement some kind of explicit switch with qemu 
> in the meantime, so i can choose what bitness i want to debug? I know, it's a 
> problem with gdb under the hood, but still - it's really uncool debugging 
> doesn't work in either of the two cases.

Wasn't required so far. If you debug in either mode, "set arch" should
do the job. If you have to debug across mode switches, that knob won't
help anyway.

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Re: Debugging a 64-bit kernel in qemu

2011-01-03 Thread Markus Duft
On 01/03/2011 02:00 PM, Jan Kiszka wrote:
> [ please keep CCs ]
> 
> Am 03.01.2011 13:27, Markus Duft wrote:
>> On 01/03/2011 01:15 PM, Markus Duft wrote:
>>> On 01/03/2011 12:15 PM, Jan Kiszka wrote:
>>> [snip]
>> [snip]
>>> actually, i find that Ted Harkington was right: in 0.11.1 i can debug 32 
>>> bit code with qemu-system-x86_64 well enough (which means i debugged all 
>>> the 32 bit part of my kernel without ever seen _any_ problem/non-working 
>>> feature/whatever). wouldn't it be better to have 64 bit debugging working 
>>> in the 64 bit version, with 32 bit mode working mostly (with whatever small 
>>> issues), rather than just completely dooming 64 bit debugging...?
>>>
>>
>> owh - spoke too soon. there must be more to it: i tried reverting 
>> 5f30fa18ad043a841fe9f0c3917ac60f2519ebd1, which restores ability to debug my 
>> 64 bit kernel just fine, but now i get the packet too long when trying to 
>> debug 32 bit code
> 
> Hmm, that's new. You definitely loose stack unwinding when using the
> wrong mode, thus source-level debugging.

hmmm... ok - that could be. my "source" in that case is all assembly for the 32 
bit part ;) i didn't have such a close look at stack unwinding, as i'm all in 
one single 32 bit procedure. the next call is already a far call to 64 bit 
mode, which re-sets the stack anyway.

> 
> I thought that thread suggested to set the arch explicitly, maybe I
> misremembered that:
> 
> set arch i386:x86_64
> tar rem :1234

arch is automatically at x86_64, as i start gdb giving it my elf64 kernel to 
load (which switches gdb to x86_64). however the first few instructions are 32 
bit, switching to long mode then.

> 
> If that is required, you probably load a 32-bit binary into gdb that
> also contains 64-bit code in some section. I guess this is even more
> confusing for gdb.

the other way round: i have a elf64 binary, containing all 64 bit code, but 
with exactly _one_ section containing 32 bit bootstrap code, which switches to 
long mode.

> 
>>
>> wouldn't it be possible to implement some kind of explicit switch with qemu 
>> in the meantime, so i can choose what bitness i want to debug? I know, it's 
>> a problem with gdb under the hood, but still - it's really uncool debugging 
>> doesn't work in either of the two cases.
> 
> Wasn't required so far. If you debug in either mode, "set arch" should
> do the job. If you have to debug across mode switches, that knob won't
> help anyway.

that definitely doesn't help in either of my cases... :( behaviour stays the 
same, no matter if i'm currently breaking in 32 bit or 64 bit code, and setting 
either architecture in any of the situations.

Regards, Markus

> 
> Jan
> 




[Qemu-devel] [PATCH v3 05/17] x86: Optionally dump code bytes on cpu_dump_state

2011-01-03 Thread Jan Kiszka
From: Jan Kiszka 

Introduce the cpu_dump_state flag CPU_DUMP_CODE and implement it for
x86. This writes out the code bytes around the current instruction
pointer. Make use of this feature in KVM to help debugging fatal vm
exits.

Signed-off-by: Jan Kiszka 
---

Argh, the broken qemu-user build led me to check my own patch.

Changes in v3:
 - fix qemu-user build by using proper address type

 cpu-all.h|2 ++
 kvm-all.c|4 ++--
 target-i386/helper.c |   21 +
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index 4ce4e83..ffbd6a4 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -765,6 +765,8 @@ int page_check_range(target_ulong start, target_ulong len, 
int flags);
 CPUState *cpu_copy(CPUState *env);
 CPUState *qemu_get_cpu(int cpu);
 
+#define CPU_DUMP_CODE 0x0001
+
 void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
 int flags);
 void cpu_dump_statistics(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
diff --git a/kvm-all.c b/kvm-all.c
index ad1d0a8..ef2ca3b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -791,7 +791,7 @@ static int kvm_handle_internal_error(CPUState *env, struct 
kvm_run *run)
 if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) {
 fprintf(stderr, "emulation failure\n");
 if (!kvm_arch_stop_on_emulation_error(env)) {
-cpu_dump_state(env, stderr, fprintf, 0);
+cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE);
 return 0;
 }
 }
@@ -953,7 +953,7 @@ void kvm_cpu_exec(CPUState *env)
 } while (ret > 0);
 
 if (ret < 0) {
-cpu_dump_state(env, stderr, fprintf, 0);
+cpu_dump_state(env, stderr, fprintf, CPU_DUMP_CODE);
 vm_stop(0);
 env->exit_request = 1;
 }
diff --git a/target-i386/helper.c b/target-i386/helper.c
index adf9542..fa37da3 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -249,6 +249,9 @@ done:
 cpu_fprintf(f, "\n");
 }
 
+#define DUMP_CODE_BYTES_TOTAL50
+#define DUMP_CODE_BYTES_BACKWARD 20
+
 void cpu_dump_state(CPUState *env, FILE *f, fprintf_function cpu_fprintf,
 int flags)
 {
@@ -434,6 +437,24 @@ void cpu_dump_state(CPUState *env, FILE *f, 
fprintf_function cpu_fprintf,
 cpu_fprintf(f, " ");
 }
 }
+if (flags & CPU_DUMP_CODE) {
+target_ulong base = env->segs[R_CS].base + env->eip;
+target_ulong offs = MIN(env->eip, DUMP_CODE_BYTES_BACKWARD);
+uint8_t code;
+char codestr[3];
+
+cpu_fprintf(f, "Code=");
+for (i = 0; i < DUMP_CODE_BYTES_TOTAL; i++) {
+if (cpu_memory_rw_debug(env, base - offs + i, &code, 1, 0) == 0) {
+snprintf(codestr, sizeof(codestr), "%02x", code);
+} else {
+snprintf(codestr, sizeof(codestr), "??");
+}
+cpu_fprintf(f, "%s%s%s%s", i > 0 ? " ": "",
+i == offs ? "<" : "", codestr, i == offs ? ">" : "");
+}
+cpu_fprintf(f, "\n");
+}
 }
 
 /***/



[Qemu-devel] [Bug 524447] Re: virsh save is very slow

2011-01-03 Thread EsbenHaabendal
How should I interpret "Fix Released"?

qemu in maverick is still 0.12.5 and 0.12.3 in lucid.

Will this not be fixed in current stable LTS and non-LTS releases?

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/524447

Title:
  virsh save is very slow

Status in libvirt virtualization API:
  Unknown
Status in QEMU:
  Fix Released
Status in “libvirt” package in Ubuntu:
  Confirmed
Status in “qemu-kvm” package in Ubuntu:
  Confirmed

Bug description:
  As reported here: 
http://www.redhat.com/archives/libvir-list/2009-December/msg00203.html

"virsh save" is very slow - it writes the image at around 1MB/sec on my test 
system.

(I think I saw a bug report for this issue on Fedora's bugzilla, but I can't 
find it now...)

Confirmed under Karmic.





[Qemu-devel] [Bug 638955] Re: emulated netcards don't work with recent sunos kernel

2011-01-03 Thread daniel pecka
is this issue dead ?? can i do something for help to fix it?

regards, daniel

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/638955

Title:
  emulated netcards don't work with recent sunos kernel

Status in QEMU:
  New

Bug description:
  hi there,

i'm using qemu-kvm backend in version: # qemu-kvm -version
QEMU PC emulator version 0.12.5 (qemu-kvm-0.12.5), Copyright (c) 2003-2008 
Fabrice Bellard

and there are just *not working any of model=$type with combinations of recent 
sunos (solaris, openindiana, opensolaris, ..) ..

you can download for testing purposes iso from here: 
http://dlc-origin.openindiana.org/isos/147/ or from here: 
http://genunix.org/distributions/indiana/ << osol and oi are also bubuntu-like 
*live cds, so no need to bother with installing

behaviour is as follows:
e1000 - receiving doesn't work, transmitting works .. dladm (tool for handle 
ethers) shows that is all ok, correct mode is loaded up, it just seems like 
this driver works at 100% but ..

rtl8169|pcnet - works in 10Mbit mode with several other issues like high cpu 
utilization and so .. dladm is unable to recognize options for this kind of -nic

others - just don't work

.. i experienced this issue several times in past .. woraround was, that 
rtl8169 worked so-so .. with recent sunos kernel it doesn't.

it's easy to reproduce, this is why i'm not putting here more then launching 
script for my virtual machine:

# cat openindiana.sh
qemu-kvm -hda /home/kvm/openindiana/openindiana.img -m 2048 -localtime -cdrom 
/home/kvm/+images/oi-dev-147-x86.iso -boot d \
-vga std -vnc :9 -k en-us -monitor 
unix:/home/kvm/openindiana/instance,server,nowait \
-net nic,model=e1000,vlan=1 -net tap,ifname=oi0,script=no,vlan=1 &

sleep 2;
ip l set oi0 up;
ip a a 192.168.99.9/24 dev oi0;

regards by daniel





Re: [Qemu-devel] Re: [PATCH v3] qemu, qmp: convert do_inject_nmi() to QObject, QError

2011-01-03 Thread Luiz Capitulino
On Mon, 20 Dec 2010 14:09:05 +0800
Lai Jiangshan  wrote:

> On 12/17/2010 11:25 PM, Avi Kivity wrote:
> > On 12/17/2010 01:22 PM, Luiz Capitulino wrote:
> >> >
> >> >  I think Avi's suggest is better, and I will use
> >> >  "inject-nmi" (without cpu-index argument) to send NMI to all cpus,
> >> >  like physical GUI. If some one want to send NMI to a set of cpus,
> >> >  he can use "inject-nmi" multiple times.
> >>
> >> His suggestion is to drop _all_ arguments, right Avi?
> > 
> > Yes.
> > 
> 
> We don't need to drop the cpu-index argument,
> the upstream tools(libvirt etc.) can just issue "inject-nmi"
> command without any argument when need.
> 
> Reasons to keep this argument
> 1) Useful for kernel developer or debuger sending NMI to a special CPU.

Ok.

> 2) Share the code with nmi of hmp version. Share the way how to
>use these two commands.(hmp version and qmp version)

This is bad. As a general rule, we shouldn't tweak QMP interfaces with
the intention of sharing code with HMP or anything like that.

Anyway, I buy your first argument, although I'm not a kernel developer
so I'm just trusting your use case.



Re: [Qemu-devel] [PATCH 1/3] nmi: convert cpu_index to cpu-index

2011-01-03 Thread Luiz Capitulino
On Mon, 20 Dec 2010 18:00:34 +0100
Markus Armbruster  wrote:

> Lai Jiangshan  writes:
> 
> > "cpu-index" is better name.
> >
> > Signed-off-by:  Lai Jiangshan 
> > ---
> > diff --git a/hmp-commands.hx b/hmp-commands.hx
> > index 4befbe2..8de7aa3 100644
> > --- a/hmp-commands.hx
> > +++ b/hmp-commands.hx
> > @@ -721,7 +721,7 @@ ETEXI
> >  #if defined(TARGET_I386)
> >  {
> >  .name   = "nmi",
> > -.args_type  = "cpu_index:i",
> > +.args_type  = "cpu-index:i",
> >  .params = "cpu",
> >  .help   = "inject an NMI on the given CPU",
> >  .mhandler.cmd = do_inject_nmi,
> > diff --git a/monitor.c b/monitor.c
> > index 5d74fe3..c16b39d 100644
> > --- a/monitor.c
> > +++ b/monitor.c
> > @@ -2410,7 +2410,7 @@ static void do_wav_capture(Monitor *mon, const QDict 
> > *qdict)
> >  static void do_inject_nmi(Monitor *mon, const QDict *qdict)
> >  {
> >  CPUState *env;
> > -int cpu_index = qdict_get_int(qdict, "cpu_index");
> > +int cpu_index = qdict_get_int(qdict, "cpu-index");
> >  
> >  for (env = first_cpu; env != NULL; env = env->next_cpu)
> >  if (env->cpu_index == cpu_index) {
> 
> Fine with me, but it would be nice if we could make up our mind once and
> for all whether to use dash or underscore in monitor commands and
> arguments.

I vote for dash, although we obviously can't change existing commands.



Re: [Qemu-devel] [Bug 524447] Re: virsh save is very slow

2011-01-03 Thread Michael Tokarev
03.01.2011 16:23, EsbenHaabendal wrote:
> How should I interpret "Fix Released"?
> 
> qemu in maverick is still 0.12.5 and 0.12.3 in lucid.

Not all the world is ubuntu.  In qemu (and qemu-kvm) the
issue is fixed in 0.13, which were released quite some
time ago.

> Will this not be fixed in current stable LTS and non-LTS releases?

There's no "stable LTS" and "non-LTS" releases in qemu,
there are plain releases.

/mjt



Re: [Qemu-devel] [PATCH 0/5] usb-ccid (v11)

2011-01-03 Thread Gerd Hoffmann

On 01/03/11 12:00, Alon Levy wrote:

On Mon, Jan 03, 2011 at 11:39:01AM +0100, Gerd Hoffmann wrote:

Patch series looks good to me now.  Doesn't apply cleanly to master
though (conflicts in configure), so it needs a rebase I guess.  Also
a git tree to pull from would be nice.


rebased, pull from:
  git://anongit.freedesktop.org/~alon/qemu usb_ccid.v11


Doesn't build with separate build directory.

cheers,
  Gerd




[Qemu-devel] [PATCH v2 6/6] SPARCV8 asr17 register support.

2011-01-03 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau 
---
 target-sparc/cpu.h   |1 +
 target-sparc/helper.c|3 ++-
 target-sparc/translate.c |   10 ++
 3 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index 7795be4..fe082e3 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -266,6 +266,7 @@ typedef struct sparc_def_t {
 #define CPU_FEATURE_CMT  (1 << 12)
 #define CPU_FEATURE_GL   (1 << 13)
 #define CPU_FEATURE_TA0_SHUTDOWN (1 << 14) /* Shutdown on "ta 0x0" */
+#define CPU_FEATURE_ASR17(1 << 15)
 #ifndef TARGET_SPARC64
 #define CPU_DEFAULT_FEATURES (CPU_FEATURE_FLOAT | CPU_FEATURE_SWAP |  \
   CPU_FEATURE_MUL | CPU_FEATURE_DIV | \
diff --git a/target-sparc/helper.c b/target-sparc/helper.c
index 49bdb58..baab379 100644
--- a/target-sparc/helper.c
+++ b/target-sparc/helper.c
@@ -1302,7 +1302,8 @@ static const sparc_def_t sparc_defs[] = {
 .mmu_sfsr_mask = 0x,
 .mmu_trcr_mask = 0x,
 .nwindows = 8,
-.features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN,
+.features = CPU_DEFAULT_FEATURES | CPU_FEATURE_TA0_SHUTDOWN |
+CPU_FEATURE_ASR17,
 },
 #endif
 };
diff --git a/target-sparc/translate.c b/target-sparc/translate.c
index b0e8044..05f942f 100644
--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -2068,6 +2068,16 @@ static void disas_sparc_insn(DisasContext * dc)
 case 0x10 ... 0x1f: /* implementation-dependent in the
SPARCv8 manual, rdy on the
microSPARC II */
+if (rs1 == 0x11) { /* Read Asr17 */
+TCGv r_const;
+CHECK_IU_FEATURE(dc, ASR17);
+/* Asr17 for a Leon3 monoprocessor */
+r_const = tcg_const_tl((1 << 8)
+   | (dc->def->nwindows - 1));
+gen_movl_TN_reg(rd, r_const);
+tcg_temp_free(r_const);
+break;
+}
 #endif
 gen_movl_TN_reg(rd, cpu_y);
 break;
-- 
1.7.1




[Qemu-devel] [PATCH v2 3/6] Emulation of GRLIB APB UART as defined in GRLIB IP Core User's Manual.

2011-01-03 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau 
---
 hw/grlib_apbuart.c |  208 
 1 files changed, 208 insertions(+), 0 deletions(-)

diff --git a/hw/grlib_apbuart.c b/hw/grlib_apbuart.c
new file mode 100644
index 000..a2ff8ed
--- /dev/null
+++ b/hw/grlib_apbuart.c
@@ -0,0 +1,208 @@
+/*
+ * QEMU GRLIB APB UART Emulator
+ *
+ * Copyright (c) 2010-2011 AdaCore
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "sysbus.h"
+#include "qemu-char.h"
+
+//#define DEBUG_UART
+
+#ifdef DEBUG_UART
+#define DPRINTF(fmt, ...)   \
+do { printf("APBUART: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+#define UART_REG_SIZE 20 /* Size of memory mapped registers */
+
+/* UART status register fields */
+#define UART_DATA_READY   (1 <<  0)
+#define UART_TRANSMIT_SHIFT_EMPTY (1 <<  1)
+#define UART_TRANSMIT_FIFO_EMPTY  (1 <<  2)
+#define UART_BREAK_RECEIVED   (1 <<  3)
+#define UART_OVERRUN  (1 <<  4)
+#define UART_PARITY_ERROR (1 <<  5)
+#define UART_FRAMING_ERROR(1 <<  6)
+#define UART_TRANSMIT_FIFO_HALF   (1 <<  7)
+#define UART_RECEIVE_FIFO_HALF(1 <<  8)
+#define UART_TRANSMIT_FIFO_FULL   (1 <<  9)
+#define UART_RECEIVE_FIFO_FULL(1 << 10)
+
+/* UART control register fields */
+#define UART_RECEIVE_ENABLE  (1 <<  0)
+#define UART_TRANSMIT_ENABLE (1 <<  1)
+#define UART_RECEIVE_INTERRUPT   (1 <<  2)
+#define UART_TRANSMIT_INTERRUPT  (1 <<  3)
+#define UART_PARITY_SELECT   (1 <<  4)
+#define UART_PARITY_ENABLE   (1 <<  5)
+#define UART_FLOW_CONTROL(1 <<  6)
+#define UART_LOOPBACK(1 <<  7)
+#define UART_EXTERNAL_CLOCK  (1 <<  8)
+#define UART_RECEIVE_FIFO_INTERRUPT  (1 <<  9)
+#define UART_TRANSMIT_FIFO_INTERRUPT (1 << 10)
+#define UART_FIFO_DEBUG_MODE (1 << 11)
+#define UART_OUTPUT_ENABLE   (1 << 12)
+#define UART_FIFO_AVAILABLE  (1 << 31)
+
+/* Memory mapped register offsets */
+#define DATA_OFFSET   0x00
+#define STATUS_OFFSET 0x04
+#define CONTROL_OFFSET0x08
+#define SCALER_OFFSET 0x0C  /* not supported */
+#define FIFO_DEBUG_OFFSET 0x10  /* not supported */
+
+typedef struct UART
+{
+SysBusDevice busdev;
+
+qemu_irq irq;
+
+CharDriverState *chr;
+
+/* registers */
+uint32_t receive;
+uint32_t status;
+uint32_t control;
+} UART;
+
+static int grlib_apbuart_can_receive(void *opaque)
+{
+UART *uart = opaque;
+assert(uart != NULL);
+
+return !!(uart->status & UART_DATA_READY);
+}
+
+static void grlib_apbuart_receive(void *opaque, const uint8_t *buf, int size)
+{
+UART *uart = opaque;
+assert(uart != NULL);
+
+uart->receive  = *buf;
+uart->status  |= UART_DATA_READY;
+
+if (uart->control & UART_RECEIVE_INTERRUPT) {
+qemu_irq_pulse(uart->irq);
+}
+}
+
+static void grlib_apbuart_event(void *opaque, int event)
+{
+DPRINTF("uart: event %x\n", event);
+}
+
+static void
+grlib_apbuart_writel(void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+UART  *uart = opaque;
+unsigned char  c= 0;
+
+addr &= 0xff;
+
+assert(uart != NULL);
+
+/* Unit registers */
+switch (addr)
+{
+case DATA_OFFSET:
+c = value & 0xFF;
+qemu_chr_write(uart->chr, &c, 1);
+return;
+
+case STATUS_OFFSET:
+/* Read Only */
+return;
+
+case CONTROL_OFFSET:
+/* Not supported */
+return;
+
+case SCALER_OFFSET:
+/* Not supported */
+return;
+
+default:
+break;
+}
+
+DPRINTF("write unknown register " TARGET_FMT_plx "\n", addr);
+}
+
+static CPUReadMemoryFunc * const grlib_apbuart_read[] = {
+NULL, NULL, NULL,
+};
+
+static CPUWriteMemoryFunc * const grlib_apbuart_wr

[Qemu-devel] [PATCH v2 0/6] [RFC] New SPARC machine: Leon3

2011-01-03 Thread Fabien Chouteau
Hi everyone,
New version of the Leon3 emulation. Many modifications since v1, mostly to
follow the Qemu architecture and to implement features in a more generic way.

Again, please feel free to comment.

Regards,



This patch set introduces a new SPARC V8 machine: Leon3. It's an open-source
VHDL System-On-Chip, well known in space industry (more information on
http://www.gaisler.com).

Leon3 is made of multiple components available in the GrLib VHDL library.
Three devices are implemented: uart, timers and IRQ manager.
You can find code for these peripherals in the grlib_* files.

Modifications have been done to the SPARC cpu emulation code to handle
Leon3's specific behavior:
 - IRQ management
 - Cache control
 - Asr17 (implementation-dependent Ancillary State Registers)
 - Shutdown

Fabien Chouteau (6):
  Emulation of GRLIB GPTimer as defined in GRLIB IP Core User's Manual.
  Emulation of GRLIB IRQMP as defined in GRLIB IP Core User's Manual.
  Emulation of GRLIB APB UART as defined in GRLIB IP Core User's
Manual.
  Header file for the GRLIB components.
  Emulation of Leon3.
  SPARCV8 asr17 register support.

 Makefile.target  |5 +-
 hw/grlib.h   |  121 +
 hw/grlib_apbuart.c   |  208 ++
 hw/grlib_gptimer.c   |  427 ++
 hw/grlib_irqmp.c |  402 +++
 hw/leon3.c   |  202 ++
 target-sparc/cpu.h   |   40 +++--
 target-sparc/helper.c|8 +-
 target-sparc/helper.h|1 +
 target-sparc/op_helper.c |  151 -
 target-sparc/translate.c |   24 +++-
 11 files changed, 1567 insertions(+), 22 deletions(-)
 create mode 100644 hw/grlib.h
 create mode 100644 hw/grlib_apbuart.c
 create mode 100644 hw/grlib_gptimer.c
 create mode 100644 hw/grlib_irqmp.c
 create mode 100644 hw/leon3.c




[Qemu-devel] [PATCH v2 1/6] Emulation of GRLIB GPTimer as defined in GRLIB IP Core User's Manual.

2011-01-03 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau 
---
 hw/grlib_gptimer.c |  427 
 1 files changed, 427 insertions(+), 0 deletions(-)

diff --git a/hw/grlib_gptimer.c b/hw/grlib_gptimer.c
new file mode 100644
index 000..e33d506
--- /dev/null
+++ b/hw/grlib_gptimer.c
@@ -0,0 +1,427 @@
+/*
+ * QEMU GRLIB GPTimer Emulator
+ *
+ * Copyright (c) 2010-2011 AdaCore
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "sysbus.h"
+#include "qemu-timer.h"
+
+//#define DEBUG_TIMER
+
+#ifdef DEBUG_TIMER
+#define DPRINTF(fmt, ...)   \
+do { printf("GPTIMER: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+#define UNIT_REG_SIZE16 /* Size of memory mapped regs for the unit */
+#define GPTIMER_REG_SIZE 16 /* Size of memory mapped regs for a GPTimer */
+
+#define GPTIMER_MAX_TIMERS 8
+
+/* GPTimer Config register fields */
+#define GPTIMER_ENABLE  (1 << 0)
+#define GPTIMER_RESTART (1 << 1)
+#define GPTIMER_LOAD(1 << 2)
+#define GPTIMER_INT_ENABLE  (1 << 3)
+#define GPTIMER_INT_PENDING (1 << 4)
+#define GPTIMER_CHAIN   (1 << 5) /* Not supported */
+#define GPTIMER_DEBUG_HALT  (1 << 6) /* Not supported */
+
+/* Memory mapped register offsets */
+#define SCALER_OFFSET 0x00
+#define SCALER_RELOAD_OFFSET  0x04
+#define CONFIG_OFFSET 0x08
+#define COUNTER_OFFSET0x00
+#define COUNTER_RELOAD_OFFSET 0x04
+#define TIMER_BASE0x10
+
+typedef struct GPTimer GPTimer;
+typedef struct GPTimerUnit GPTimerUnit;
+
+struct GPTimer
+{
+QEMUBH *bh;
+struct ptimer_state *ptimer;
+
+qemu_irq irq;
+int  id;
+GPTimerUnit *unit;
+
+/* registers */
+uint32_t counter;
+uint32_t reload;
+uint32_t config;
+};
+
+struct GPTimerUnit
+{
+SysBusDevice  busdev;
+
+uint32_t nr_timers; /* Number of timers available */
+uint32_t freq_hz;   /* System frequency */
+uint32_t irq_line;  /* Base irq line */
+
+GPTimer *timers;
+
+/* registers */
+uint32_t scaler;
+uint32_t reload;
+uint32_t config;
+};
+
+static void grlib_gptimer_enable(GPTimer *timer)
+{
+assert(timer != NULL);
+
+DPRINTF("%s id:%d\n", __func__, timer->id);
+
+ptimer_stop(timer->ptimer);
+
+if (!(timer->config & GPTIMER_ENABLE)) {
+/* Timer disabled */
+DPRINTF("%s id:%d Timer disabled (config 0x%x)\n", __func__,
+timer->id, timer->config);
+return;
+}
+
+/* ptimer is triggered when the counter reach 0 but GPTimer is triggered at
+   underflow. Set count + 1 to simulate the GPTimer behavior. */
+
+DPRINTF("%s id:%d set count 0x%x and run\n",
+__func__,
+timer->id,
+timer->counter + 1);
+
+ptimer_set_count(timer->ptimer, timer->counter + 1);
+ptimer_run(timer->ptimer, 1);
+}
+
+static void grlib_gptimer_restart(GPTimer *timer)
+{
+assert(timer != NULL);
+
+DPRINTF("%s id:%d reload val: 0x%x\n", __func__, timer->id, timer->reload);
+
+timer->counter = timer->reload;
+grlib_gptimer_enable(timer);
+}
+
+static void grlib_gptimer_set_scaler(GPTimerUnit *unit, uint32_t scaler)
+{
+int i = 0;
+uint32_t value = 0;
+
+assert(unit != NULL);
+
+
+if (scaler > 0) {
+value = unit->freq_hz / (scaler + 1);
+} else {
+value = unit->freq_hz;
+}
+
+DPRINTF("%s scaler:%d freq:0x%x\n", __func__, scaler, value);
+
+for (i = 0; i < unit->nr_timers; i++) {
+ptimer_set_freq(unit->timers[i].ptimer, value);
+}
+}
+
+static void grlib_gptimer_hit(void *opaque)
+{
+GPTimer *timer = opaque;
+assert(timer != NULL);
+
+DPRINTF("%s id:%d\n", __func__, timer->id);
+
+/* Timer expired */
+
+if (timer->config & GPTIMER_INT_ENABLE) {
+/* Set the pending bit (only unset by write in the config 

[Qemu-devel] [PATCH v2 5/6] Emulation of Leon3.

2011-01-03 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau 
---
 Makefile.target  |5 +-
 hw/leon3.c   |  202 ++
 target-sparc/cpu.h   |   39 ++---
 target-sparc/helper.c|7 +-
 target-sparc/helper.h|1 +
 target-sparc/op_helper.c |  151 ++-
 target-sparc/translate.c |   14 +++-
 7 files changed, 397 insertions(+), 22 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 2800f47..f40e04f 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -290,7 +290,10 @@ obj-sparc-y += cirrus_vga.o
 else
 obj-sparc-y = sun4m.o lance.o tcx.o sun4m_iommu.o slavio_intctl.o
 obj-sparc-y += slavio_timer.o slavio_misc.o sparc32_dma.o
-obj-sparc-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o
+obj-sparc-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o leon3.o
+
+# GRLIB
+obj-sparc-y += grlib_gptimer.o grlib_irqmp.o grlib_apbuart.o
 endif
 
 obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o
diff --git a/hw/leon3.c b/hw/leon3.c
new file mode 100644
index 000..d5fe863
--- /dev/null
+++ b/hw/leon3.c
@@ -0,0 +1,202 @@
+/*
+ * QEMU Leon3 System Emulator
+ *
+ * Copyright (c) 2010-2011 AdaCore
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "hw.h"
+#include "qemu-timer.h"
+#include "qemu-char.h"
+#include "sysemu.h"
+#include "boards.h"
+#include "loader.h"
+#include "elf.h"
+
+#include "grlib.h"
+
+//#define DEBUG_LEON3
+
+#ifdef DEBUG_LEON3
+#define DPRINTF(fmt, ...)   \
+do { printf("Leon3: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+/* Default system clock.  */
+#define CPU_CLK (40 * 1000 * 1000)
+
+#define PROM_FILENAME"u-boot.bin"
+
+#define MAX_PILS 16
+
+typedef struct ResetData {
+CPUState *env;
+uint64_t  entry;/* save kernel entry in case of reset */
+} ResetData;
+
+static void main_cpu_reset(void *opaque)
+{
+ResetData *s = (ResetData *)opaque;
+assert(s != NULL);
+CPUState *env = s->env;
+assert(env != NULL);
+
+cpu_reset(env);
+
+env->halted = 0;
+env->pc = s->entry;
+env->npc= s->entry + 4;
+}
+
+static void leon3_irq_ack(void *irq_manager, int intno)
+{
+grlib_irqmp_ack((DeviceState *)irq_manager, intno);
+leon3_cache_control_int();
+}
+
+static void leon3_generic_hw_init(ram_addr_t  ram_size,
+  const char *boot_device,
+  const char *kernel_filename,
+  const char *kernel_cmdline,
+  const char *initrd_filename,
+  const char *cpu_model)
+{
+CPUState   *env;
+ram_addr_t  ram_offset, prom_offset;
+int ret;
+char   *filename;
+qemu_irq   *cpu_irqs = NULL;
+int bios_size;
+int prom_size;
+int aligned_bios_size;
+ResetData  *reset_info;
+
+/* Init CPU */
+if (!cpu_model) {
+cpu_model = "LEON3";
+}
+
+env = cpu_init(cpu_model);
+if (!env) {
+fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
+exit(1);
+}
+
+cpu_sparc_set_id(env, 0);
+
+/* Reset data */
+reset_info= qemu_mallocz(sizeof(ResetData));
+reset_info->env   = env;
+qemu_register_reset(main_cpu_reset, reset_info);
+
+/* Allocate IRQ manager */
+grlib_irqmp_create(0x8200, env, &cpu_irqs, MAX_PILS);
+
+env->qemu_irq_ack = leon3_irq_ack;
+
+/* Allocate RAM */
+if ((uint64_t)ram_size > (1UL << 30)) {
+fprintf(stderr,
+"qemu: Too much memory for this machine: %d, maximum 1G\n",
+(unsigned int)(ram_size / (1024 * 1024)));
+exit(1);
+}
+
+ram_offset = qemu_ram_alloc(NULL, "leon3.ram", ram_size);
+cpu_register_physical_memory(0x4000, ram_size, ram_offset | 

Re: [Qemu-devel] [PATCH 0/5] usb-ccid (v11)

2011-01-03 Thread Alon Levy
On Mon, Jan 03, 2011 at 02:53:02PM +0100, Gerd Hoffmann wrote:
> On 01/03/11 12:00, Alon Levy wrote:
> >On Mon, Jan 03, 2011 at 11:39:01AM +0100, Gerd Hoffmann wrote:
> >>Patch series looks good to me now.  Doesn't apply cleanly to master
> >>though (conflicts in configure), so it needs a rebase I guess.  Also
> >>a git tree to pull from would be nice.
> >
> >rebased, pull from:
> >  git://anongit.freedesktop.org/~alon/qemu usb_ccid.v11
> 
> Doesn't build with separate build directory.
> 
> cheers,
>   Gerd
> 
> 

ok, I've never tried that. Will try it now - can you remind me how it goes? 
(configure ...?)




[Qemu-devel] [PATCH v2 2/6] Emulation of GRLIB IRQMP as defined in GRLIB IP Core User's Manual.

2011-01-03 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau 
---
 hw/grlib_irqmp.c |  402 ++
 1 files changed, 402 insertions(+), 0 deletions(-)

diff --git a/hw/grlib_irqmp.c b/hw/grlib_irqmp.c
new file mode 100644
index 000..9f947d1
--- /dev/null
+++ b/hw/grlib_irqmp.c
@@ -0,0 +1,402 @@
+/*
+ * QEMU GRLIB IRQMP Emulator
+ *
+ * (Multiprocessor and extended interrupt not supported)
+ *
+ * Copyright (c) 2010-2011 AdaCore
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "sysbus.h"
+#include "cpu.h"
+
+#include "grlib.h"
+
+//#define DEBUG_IRQ
+
+#ifdef DEBUG_IRQ
+#define DPRINTF(fmt, ...)   \
+do { printf("IRQMP: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+#define IRQMP_MAX_CPU 16
+#define IRQMP_REG_SIZE 256  /* Size of memory mapped registers */
+
+/* Memory mapped register offsets */
+#define LEVEL_OFFSET 0x00
+#define PENDING_OFFSET   0x04
+#define FORCE0_OFFSET0x08
+#define CLEAR_OFFSET 0x0C
+#define MP_STATUS_OFFSET 0x10
+#define BROADCAST_OFFSET 0x14
+#define MASK_OFFSET  0x40
+#define FORCE_OFFSET 0x80
+#define EXTENDED_OFFSET  0xC0
+
+typedef struct IRQMPState IRQMPState;
+
+typedef struct IRQMP
+{
+SysBusDevice busdev;
+
+CPUSPARCState *env;
+
+IRQMPState *state;
+} IRQMP;
+
+struct IRQMPState
+{
+uint32_t level;
+uint32_t pending;
+uint32_t clear;
+uint32_t broadcast;
+
+uint32_t mask[IRQMP_MAX_CPU];
+uint32_t force[IRQMP_MAX_CPU];
+uint32_t extended[IRQMP_MAX_CPU];
+
+IRQMP*parent;
+};
+
+static void grlib_irqmp_check_irqs(IRQMPState *state)
+{
+assert(state != NULL);
+CPUState *env   = state->parent->env;
+assert(env != NULL);
+
+uint32_t pend   = 0;
+uint32_t level0 = 0;
+uint32_t level1 = 0;
+
+
+/* IRQ for CPU 0 (no SMP support) */
+pend = (state->pending | state->force[0])
+& state->mask[0];
+
+
+level0 = pend & ~state->level;
+level1 = pend &  state->level;
+
+DPRINTF("pend:0x%04x force:0x%04x mask:0x%04x lvl1:0x%04x lvl0:0x%04x\n",
+state->pending, state->force[0],
+state->mask[0], level1, level0);
+
+/* Trigger level1 interrupt first and level0 if there is no level1 */
+if (level1 != 0) {
+env->pil_in = level1;
+} else {
+env->pil_in = level0;
+}
+
+if (env->pil_in && (env->interrupt_index == 0 ||
+(env->interrupt_index & ~15) == TT_EXTINT)) {
+unsigned int i;
+
+for (i = 15; i > 0; i--) {
+if (env->pil_in & (1 << i)) {
+int old_interrupt = env->interrupt_index;
+
+env->interrupt_index = TT_EXTINT | i;
+if (old_interrupt != env->interrupt_index) {
+DPRINTF("Set CPU IRQ %d\n", i);
+cpu_interrupt(env, CPU_INTERRUPT_HARD);
+}
+break;
+}
+}
+} else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
+DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
+env->interrupt_index = 0;
+cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+}
+}
+
+void grlib_irqmp_ack(DeviceState *dev, int intno)
+{
+assert(dev != NULL);
+
+SysBusDevice *sdev = sysbus_from_qdev(dev);
+assert(sdev != NULL);
+
+IRQMP *irqmp = FROM_SYSBUS(typeof (*irqmp), sdev);
+assert(irqmp != NULL);
+
+IRQMPState *state = irqmp->state;
+assert(state != NULL);
+
+uint32_t mask;
+
+intno &= 15;
+mask = 1 << intno;
+
+DPRINTF("grlib_irqmp_ack %d\n", intno);
+
+/* Clear registers */
+state->pending  &= ~mask;
+state->force[0] &= ~mask; /* Only CPU 0 (No SMP support) */
+
+grlib_irqmp_check_irqs(state);
+}
+
+void grlib_irqmp_set_irq(void *opaque, int irq, int level)
+{
+assert(opaque != NULL);
+
+IRQMP *irqmp = 

[Qemu-devel] [PATCH v2 4/6] Header file for the GRLIB components.

2011-01-03 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau 
---
 hw/grlib.h |  121 
 1 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/hw/grlib.h b/hw/grlib.h
new file mode 100644
index 000..bb3c01e
--- /dev/null
+++ b/hw/grlib.h
@@ -0,0 +1,121 @@
+/*
+ * QEMU GRLIB Components
+ *
+ * Copyright (c) 2010-2011 AdaCore
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _GRLIB_H_
+#define _GRLIB_H_
+
+#include "qdev.h"
+#include "sysbus.h"
+
+/* Emulation of GrLib device is base on the GRLIB IP Core User's Manual:
+ * http://www.gaisler.com/products/grlib/grip.pdf
+ */
+
+/* IRQMP */
+
+void grlib_irqmp_set_irq(void *opaque, int irq, int level);
+
+void grlib_irqmp_ack(DeviceState *dev, int intno);
+
+static inline
+DeviceState *grlib_irqmp_create(target_phys_addr_t   base,
+CPUState*env,
+qemu_irq   **cpu_irqs,
+uint32_t nr_irqs)
+{
+DeviceState *dev;
+
+assert(cpu_irqs != NULL);
+
+dev = qdev_create(NULL, "grlib,irqmp");
+qdev_prop_set_ptr(dev, "cpustate", env);
+
+if (qdev_init(dev)) {
+return NULL;
+}
+
+env->irq_manager = dev;
+
+sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
+
+*cpu_irqs = qemu_allocate_irqs(grlib_irqmp_set_irq,
+   dev,
+   nr_irqs);
+
+return dev;
+}
+
+/* GPTimer */
+
+static inline
+DeviceState *grlib_gptimer_create(target_phys_addr_t  base,
+  uint32_tnr_timers,
+  uint32_tfreq,
+  qemu_irq   *cpu_irqs,
+  int base_irq)
+{
+DeviceState *dev;
+int i;
+
+dev = qdev_create(NULL, "grlib,gptimer");
+qdev_prop_set_uint32(dev, "nr-timers", nr_timers);
+qdev_prop_set_uint32(dev, "frequency", freq);
+qdev_prop_set_uint32(dev, "irq-line", base_irq);
+
+if (qdev_init(dev)) {
+return NULL;
+}
+
+sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
+
+for (i = 0; i < nr_timers; i++)
+sysbus_connect_irq(sysbus_from_qdev(dev), i, cpu_irqs[base_irq + i]);
+
+return dev;
+}
+
+/* APB UART */
+
+static inline
+DeviceState *grlib_apbuart_create(target_phys_addr_t  base,
+  CharDriverState*serial,
+  qemu_irqirq)
+{
+DeviceState *dev;
+
+dev = qdev_create(NULL, "grlib,apbuart");
+qdev_prop_set_ptr(dev, "chrdev", serial);
+
+if (qdev_init(dev)) {
+return NULL;
+}
+
+sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
+
+sysbus_connect_irq(sysbus_from_qdev(dev), 0, irq);
+
+return dev;
+}
+
+#endif /* ! _GRLIB_H_ */
-- 
1.7.1




Re: [Qemu-devel] [Bug 524447] Re: virsh save is very slow

2011-01-03 Thread EsbenHaabendal
Michael Tokarev  writes:

> 03.01.2011 16:23, EsbenHaabendal wrote:
>> How should I interpret "Fix Released"?
>> 
>> qemu in maverick is still 0.12.5 and 0.12.3 in lucid.
>
> Not all the world is ubuntu.  In qemu (and qemu-kvm) the
> issue is fixed in 0.13, which were released quite some
> time ago.
>
>> Will this not be fixed in current stable LTS and non-LTS releases?
>
> There's no "stable LTS" and "non-LTS" releases in qemu,
> there are plain releases.

Ok.  I see.

And the current importance for libvirt (Ubuntu) and qemu-kvm (Ubuntu) is
marked as "Wishlist".

So my question goes to these two components.  When can we expect to see
this fixed in current Ubuntu releases, of which I currently count at
least maverick and lucid.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/524447

Title:
  virsh save is very slow

Status in libvirt virtualization API:
  Unknown
Status in QEMU:
  Fix Released
Status in “libvirt” package in Ubuntu:
  Confirmed
Status in “qemu-kvm” package in Ubuntu:
  Confirmed

Bug description:
  As reported here: 
http://www.redhat.com/archives/libvir-list/2009-December/msg00203.html

"virsh save" is very slow - it writes the image at around 1MB/sec on my test 
system.

(I think I saw a bug report for this issue on Fedora's bugzilla, but I can't 
find it now...)

Confirmed under Karmic.





[Qemu-devel] softfloat: fix NaN propagation for MIPS and PowerPC + cleanup

2011-01-03 Thread Aurelien Jarno
This patch series start by a cleanup to remove dead HPPA code, and then
implement correct NaN propagation rules for MIPS and PowerPC, following
commit 354f211b1a49a7387929e22d6e63849fcba48f8a.




[Qemu-devel] [PATCH 1/6] softfloat: remove HPPA specific code

2011-01-03 Thread Aurelien Jarno
We don't have any HPPA target, so let's remove HPPA specific code. It
can be re-added when someone adds an HPPA target.

Signed-off-by: Aurelien Jarno 
---
 fpu/softfloat-specialize.h |6 +-
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index f8f36f3..f23bd6a 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -30,7 +30,7 @@ these four paragraphs for those parts of this code that are 
retained.
 
 =*/
 
-#if defined(TARGET_MIPS) || defined(TARGET_HPPA)
+#if defined(TARGET_MIPS)
 #define SNAN_BIT_IS_ONE1
 #else
 #define SNAN_BIT_IS_ONE0
@@ -63,8 +63,6 @@ typedef struct {
 #define float32_default_nan make_float32(0x7FFF)
 #elif defined(TARGET_POWERPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
 #define float32_default_nan make_float32(0x7FC0)
-#elif defined(TARGET_HPPA)
-#define float32_default_nan make_float32(0x7FA0)
 #elif SNAN_BIT_IS_ONE
 #define float32_default_nan make_float32(0x7FBF)
 #else
@@ -275,8 +273,6 @@ static float32 propagateFloat32NaN( float32 a, float32 b 
STATUS_PARAM)
 #define float64_default_nan make_float64(LIT64( 0x7FFF ))
 #elif defined(TARGET_POWERPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
 #define float64_default_nan make_float64(LIT64( 0x7FF8 ))
-#elif defined(TARGET_HPPA)
-#define float64_default_nan make_float64(LIT64( 0x7FF4 ))
 #elif SNAN_BIT_IS_ONE
 #define float64_default_nan make_float64(LIT64( 0x7FF7 ))
 #else
-- 
1.7.2.3




[Qemu-devel] [PATCH 2/6] softfloat: fix float{32, 64}_maybe_silence_nan() for MIPS

2011-01-03 Thread Aurelien Jarno
On targets that define sNaN with the sNaN bit as one, simply clearing
this bit may correspond to an infinite value.

Convert it to a default NaN if SNAN_BIT_IS_ONE, as it corresponds to
the MIPS implementation, the only emulated CPU with SNAN_BIT_IS_ONE.
When other CPU of this type are added, this might be updated to include
more cases.

Signed-off-by: Aurelien Jarno 
---
 fpu/softfloat-specialize.h |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index f23bd6a..31481e7 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -107,13 +107,13 @@ int float32_is_signaling_nan( float32 a_ )
 float32 float32_maybe_silence_nan( float32 a_ )
 {
 if (float32_is_signaling_nan(a_)) {
-bits32 a = float32_val(a_);
 #if SNAN_BIT_IS_ONE
-a &= ~(1 << 22);
+return float32_default_nan;
 #else
+bits32 a = float32_val(a_);
 a |= (1 << 22);
-#endif
 return make_float32(a);
+#endif
 }
 return a_;
 }
@@ -321,13 +321,13 @@ int float64_is_signaling_nan( float64 a_ )
 float64 float64_maybe_silence_nan( float64 a_ )
 {
 if (float64_is_signaling_nan(a_)) {
-bits64 a = float64_val(a_);
 #if SNAN_BIT_IS_ONE
-a &= ~LIT64( 0x0008 );
+return float64_default_nan;
 #else
+bits64 a = float64_val(a_);
 a |= LIT64( 0x0008 );
-#endif
 return make_float64(a);
+#endif
 }
 return a_;
 }
-- 
1.7.2.3




[Qemu-devel] [PATCH 4/6] softfloat: use float{32, 64, x80, 128}_maybe_silence_nan()

2011-01-03 Thread Aurelien Jarno
Use float{32,64,x80,128}_maybe_silence_nan() instead of toggling the
sNaN bit manually. This allow per target implementation of sNaN to qNaN
conversion.

Signed-off-by: Aurelien Jarno 
---
 fpu/softfloat-specialize.h |   55 +--
 1 files changed, 17 insertions(+), 38 deletions(-)

diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index 49e3cc2..4deb165 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -228,7 +228,7 @@ static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag 
bIsQNaN, flag bIsSNaN,
 static float32 propagateFloat32NaN( float32 a, float32 b STATUS_PARAM)
 {
 flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN, 
aIsLargerSignificand;
-bits32 av, bv, res;
+bits32 av, bv;
 
 if ( STATUS(default_nan_mode) )
 return float32_default_nan;
@@ -237,15 +237,11 @@ static float32 propagateFloat32NaN( float32 a, float32 b 
STATUS_PARAM)
 aIsSignalingNaN = float32_is_signaling_nan( a );
 bIsNaN = float32_is_quiet_nan( b );
 bIsSignalingNaN = float32_is_signaling_nan( b );
+a = float32_maybe_silence_nan(a);
+b = float32_maybe_silence_nan(b);
 av = float32_val(a);
 bv = float32_val(b);
-#if SNAN_BIT_IS_ONE
-av &= ~0x0040;
-bv &= ~0x0040;
-#else
-av |= 0x0040;
-bv |= 0x0040;
-#endif
+
 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid 
STATUS_VAR);
 
 if ((bits32)(av<<1) < (bits32)(bv<<1)) {
@@ -258,12 +254,10 @@ static float32 propagateFloat32NaN( float32 a, float32 b 
STATUS_PARAM)
 
 if (pickNaN(aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN,
 aIsLargerSignificand)) {
-res = bv;
+return b;
 } else {
-res = av;
+return a;
 }
-
-return make_float32(res);
 }
 
 /*
@@ -376,7 +370,7 @@ static float64 commonNaNToFloat64( commonNaNT a )
 static float64 propagateFloat64NaN( float64 a, float64 b STATUS_PARAM)
 {
 flag aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN, 
aIsLargerSignificand;
-bits64 av, bv, res;
+bits64 av, bv;
 
 if ( STATUS(default_nan_mode) )
 return float64_default_nan;
@@ -385,15 +379,10 @@ static float64 propagateFloat64NaN( float64 a, float64 b 
STATUS_PARAM)
 aIsSignalingNaN = float64_is_signaling_nan( a );
 bIsNaN = float64_is_quiet_nan( b );
 bIsSignalingNaN = float64_is_signaling_nan( b );
+a = float64_maybe_silence_nan(a);
+b = float64_maybe_silence_nan(b);
 av = float64_val(a);
 bv = float64_val(b);
-#if SNAN_BIT_IS_ONE
-av &= ~LIT64( 0x0008 );
-bv &= ~LIT64( 0x0008 );
-#else
-av |= LIT64( 0x0008 );
-bv |= LIT64( 0x0008 );
-#endif
 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid 
STATUS_VAR);
 
 if ((bits64)(av<<1) < (bits64)(bv<<1)) {
@@ -406,12 +395,10 @@ static float64 propagateFloat64NaN( float64 a, float64 b 
STATUS_PARAM)
 
 if (pickNaN(aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN,
 aIsLargerSignificand)) {
-res = bv;
+return b;
 } else {
-res = av;
+return a;
 }
-
-return make_float64(res);
 }
 
 #ifdef FLOATX80
@@ -542,13 +529,9 @@ static floatx80 propagateFloatx80NaN( floatx80 a, floatx80 
b STATUS_PARAM)
 aIsSignalingNaN = floatx80_is_signaling_nan( a );
 bIsNaN = floatx80_is_quiet_nan( b );
 bIsSignalingNaN = floatx80_is_signaling_nan( b );
-#if SNAN_BIT_IS_ONE
-a.low &= ~LIT64( 0xC000 );
-b.low &= ~LIT64( 0xC000 );
-#else
-a.low |= LIT64( 0xC000 );
-b.low |= LIT64( 0xC000 );
-#endif
+a = floatx80_maybe_silence_nan(a);
+a = floatx80_maybe_silence_nan(b);
+
 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid 
STATUS_VAR);
 
 if (a.low < b.low) {
@@ -688,13 +671,9 @@ static float128 propagateFloat128NaN( float128 a, float128 
b STATUS_PARAM)
 aIsSignalingNaN = float128_is_signaling_nan( a );
 bIsNaN = float128_is_quiet_nan( b );
 bIsSignalingNaN = float128_is_signaling_nan( b );
-#if SNAN_BIT_IS_ONE
-a.high &= ~LIT64( 0x8000 );
-b.high &= ~LIT64( 0x8000 );
-#else
-a.high |= LIT64( 0x8000 );
-b.high |= LIT64( 0x8000 );
-#endif
+a = float128_maybe_silence_nan(a);
+b = float128_maybe_silence_nan(b);
+
 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid 
STATUS_VAR);
 
 if (lt128(a.high<<1, a.low, b.high<<1, b.low)) {
-- 
1.7.2.3




[Qemu-devel] [PATCH 3/6] softfloat: add float{x80, 128}_maybe_silence_nan()

2011-01-03 Thread Aurelien Jarno
Add float{x80,128}_maybe_silence_nan() functions, they will be need by
propagateFloat{x80,128}NaN().

Signed-off-by: Aurelien Jarno 
---
 fpu/softfloat-specialize.h |   38 ++
 fpu/softfloat.h|2 ++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index 31481e7..49e3cc2 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -470,6 +470,25 @@ int floatx80_is_signaling_nan( floatx80 a )
 }
 
 /*
+| Returns a quiet NaN if the extended double-precision floating point value
+| `a' is a signaling NaN; otherwise returns `a'.
+**/
+
+floatx80 floatx80_maybe_silence_nan( floatx80 a )
+{
+if (floatx80_is_signaling_nan(a)) {
+#if SNAN_BIT_IS_ONE
+a.low = floatx80_default_nan_low;
+a.high = floatx80_default_nan_high;
+#else
+a.low |= LIT64( 0xC000 );
+return a;
+#endif
+}
+return a;
+}
+
+/*
 | Returns the result of converting the extended double-precision floating-
 | point NaN `a' to the canonical NaN format.  If `a' is a signaling NaN, the
 | invalid exception is raised.
@@ -601,6 +620,25 @@ int float128_is_signaling_nan( float128 a )
 }
 
 /*
+| Returns a quiet NaN if the quadruple-precision floating point value `a' is
+| a signaling NaN; otherwise returns `a'.
+**/
+
+float128 float128_maybe_silence_nan( float128 a )
+{
+if (float128_is_signaling_nan(a)) {
+#if SNAN_BIT_IS_ONE
+a.low = float128_default_nan_low;
+a.high = float128_default_nan_high;
+#else
+a.high |= LIT64( 0x8000 );
+return a;
+#endif
+}
+return a;
+}
+
+/*
 | Returns the result of converting the quadruple-precision floating-point NaN
 | `a' to the canonical NaN format.  If `a' is a signaling NaN, the invalid
 | exception is raised.
diff --git a/fpu/softfloat.h b/fpu/softfloat.h
index 1f37877..f2104c6 100644
--- a/fpu/softfloat.h
+++ b/fpu/softfloat.h
@@ -439,6 +439,7 @@ int floatx80_le_quiet( floatx80, floatx80 STATUS_PARAM );
 int floatx80_lt_quiet( floatx80, floatx80 STATUS_PARAM );
 int floatx80_is_quiet_nan( floatx80 );
 int floatx80_is_signaling_nan( floatx80 );
+floatx80 floatx80_maybe_silence_nan( floatx80 );
 floatx80 floatx80_scalbn( floatx80, int STATUS_PARAM );
 
 INLINE floatx80 floatx80_abs(floatx80 a)
@@ -505,6 +506,7 @@ int float128_compare( float128, float128 STATUS_PARAM );
 int float128_compare_quiet( float128, float128 STATUS_PARAM );
 int float128_is_quiet_nan( float128 );
 int float128_is_signaling_nan( float128 );
+float128 float128_maybe_silence_nan( float128 );
 float128 float128_scalbn( float128, int STATUS_PARAM );
 
 INLINE float128 float128_abs(float128 a)
-- 
1.7.2.3




[Qemu-devel] [PATCH 5/6] target-mips: Implement correct NaN propagation rules

2011-01-03 Thread Aurelien Jarno
Implement the correct NaN propagation rules for MIPS targets by
providing an appropriate pickNaN function.

Signed-off-by: Aurelien Jarno 
---
 fpu/softfloat-specialize.h |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index 4deb165..150500b 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -187,6 +187,33 @@ static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag 
bIsQNaN, flag bIsSNaN,
 return 1;
 }
 }
+#elif defined (TARGET_MIPS)
+static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
+flag aIsLargerSignificand)
+{
+/* According to MIPS specifications, if one of the two operands is
+ * a sNaN, a new qNaN has to be generated. This is done in
+ * floatXX_maybe_silence_nan(). For qNaN inputs the specifications
+ * says: "When possible, this QNaN result is one of the operand QNaN
+ * values." In practice it seems that most implementations choose
+ * the first operand if both operands are qNaN. In short this gives
+ * the following rules:
+ *  1. A if it is signaling
+ *  2. B if it is signaling
+ *  3. A (quiet)
+ *  4. B (quiet)
+ * A signaling NaN is always quietened before returning it.
+ */
+if (aIsSNaN) {
+return 0;
+} else if (bIsSNaN) {
+return 1;
+} else if (aIsQNaN) {
+return 0;
+} else {
+return 1;
+}
+}
 #else
 static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
 flag aIsLargerSignificand)
-- 
1.7.2.3




[Qemu-devel] [PATCH 6/6] target-ppc: Implement correct NaN propagation rules

2011-01-03 Thread Aurelien Jarno
Implement the correct NaN propagation rules for ARM targets by
providing an appropriate pickNaN function.

Also fix the #ifdef tests for default NaN definition, the correct name
is TARGET_PPC instead of TARGET_POWERPC.

Cc: Alexander Graf 
Signed-off-by: Aurelien Jarno 
---
 fpu/softfloat-specialize.h |   19 +--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
index 150500b..0f6dbd0 100644
--- a/fpu/softfloat-specialize.h
+++ b/fpu/softfloat-specialize.h
@@ -61,7 +61,7 @@ typedef struct {
 **/
 #if defined(TARGET_SPARC)
 #define float32_default_nan make_float32(0x7FFF)
-#elif defined(TARGET_POWERPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
+#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
 #define float32_default_nan make_float32(0x7FC0)
 #elif SNAN_BIT_IS_ONE
 #define float32_default_nan make_float32(0x7FBF)
@@ -214,6 +214,21 @@ static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag 
bIsQNaN, flag bIsSNaN,
 return 1;
 }
 }
+#elif defined(TARGET_PPC)
+static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
+   flag aIsLargerSignificand)
+{
+/* PowerPC propagation rules:
+ *  1. A if it sNaN or qNaN
+ *  2. B if it sNaN or qNaN
+ * A signaling NaN is always quietened before returning it.
+ */
+if (aIsSNaN || aIsQNaN) {
+return 0;
+} else {
+return 1;
+}
+}
 #else
 static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
 flag aIsLargerSignificand)
@@ -292,7 +307,7 @@ static float32 propagateFloat32NaN( float32 a, float32 b 
STATUS_PARAM)
 **/
 #if defined(TARGET_SPARC)
 #define float64_default_nan make_float64(LIT64( 0x7FFF ))
-#elif defined(TARGET_POWERPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
+#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
 #define float64_default_nan make_float64(LIT64( 0x7FF8 ))
 #elif SNAN_BIT_IS_ONE
 #define float64_default_nan make_float64(LIT64( 0x7FF7 ))
-- 
1.7.2.3




[Qemu-devel] [PATCH 1/3] add migration state change notifiers

2011-01-03 Thread Gerd Hoffmann
This patch adds functions to register and unregister notifiers for
migration state changes and a function to query the migration state.
The notifier is called on every state change.  Once after establishing a
new migration object (which is in active state then) and once when the
state changes from active to completed, canceled or error.

Signed-off-by: Gerd Hoffmann 
---
 migration.c |   28 
 migration.h |5 +
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/migration.c b/migration.c
index e5ba51c..3f88666 100644
--- a/migration.c
+++ b/migration.c
@@ -36,6 +36,9 @@ static int64_t max_throttle = (32 << 20);
 
 static MigrationState *current_migration;
 
+static NotifierList migration_state_notifiers =
+NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
+
 int qemu_start_incoming_migration(const char *uri)
 {
 const char *p;
@@ -117,6 +120,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 }
 
 current_migration = s;
+notifier_list_notify(&migration_state_notifiers);
 return 0;
 }
 
@@ -268,6 +272,7 @@ void migrate_fd_error(FdMigrationState *s)
 {
 DPRINTF("setting error state\n");
 s->state = MIG_STATE_ERROR;
+notifier_list_notify(&migration_state_notifiers);
 migrate_fd_cleanup(s);
 }
 
@@ -325,6 +330,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void 
*data, size_t size)
 monitor_resume(s->mon);
 }
 s->state = MIG_STATE_ERROR;
+notifier_list_notify(&migration_state_notifiers);
 }
 
 return ret;
@@ -385,6 +391,7 @@ void migrate_fd_put_ready(void *opaque)
 state = MIG_STATE_ERROR;
 }
 s->state = state;
+notifier_list_notify(&migration_state_notifiers);
 }
 }
 
@@ -404,6 +411,7 @@ void migrate_fd_cancel(MigrationState *mig_state)
 DPRINTF("cancelling migration\n");
 
 s->state = MIG_STATE_CANCELLED;
+notifier_list_notify(&migration_state_notifiers);
 qemu_savevm_state_cancel(s->mon, s->file);
 
 migrate_fd_cleanup(s);
@@ -417,6 +425,7 @@ void migrate_fd_release(MigrationState *mig_state)

 if (s->state == MIG_STATE_ACTIVE) {
 s->state = MIG_STATE_CANCELLED;
+notifier_list_notify(&migration_state_notifiers);
 migrate_fd_cleanup(s);
 }
 qemu_free(s);
@@ -448,3 +457,22 @@ int migrate_fd_close(void *opaque)
 qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
 return s->close(s);
 }
+
+void add_migration_state_change_notifier(Notifier *notify)
+{
+notifier_list_add(&migration_state_notifiers, notify);
+}
+
+void remove_migration_state_change_notifier(Notifier *notify)
+{
+notifier_list_remove(&migration_state_notifiers, notify);
+}
+
+int get_migration_state(void)
+{
+if (current_migration) {
+return migrate_fd_get_status(current_migration);
+} else {
+return MIG_STATE_ERROR;
+}
+}
diff --git a/migration.h b/migration.h
index d13ed4f..2170792 100644
--- a/migration.h
+++ b/migration.h
@@ -16,6 +16,7 @@
 
 #include "qdict.h"
 #include "qemu-common.h"
+#include "notify.h"
 
 #define MIG_STATE_ERROR-1
 #define MIG_STATE_COMPLETED0
@@ -134,4 +135,8 @@ static inline FdMigrationState 
*migrate_to_fms(MigrationState *mig_state)
 return container_of(mig_state, FdMigrationState, mig_state);
 }
 
+void add_migration_state_change_notifier(Notifier *notify);
+void remove_migration_state_change_notifier(Notifier *notify);
+int get_migration_state(void);
+
 #endif
-- 
1.7.1




[Qemu-devel] [PATCH 3/3] spice: MAINTAINERS update

2011-01-03 Thread Gerd Hoffmann

Signed-off-by: Gerd Hoffmann 
---
 MAINTAINERS |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 59effc7..25103dd 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -383,6 +383,14 @@ S: Odd Fixes
 F: gdbstub*
 F: gdb-xml/
 
+SPICE
+M: Gerd Hoffmann 
+S: Supported
+F: ui/qemu-spice.h
+F: ui/spice-*.c
+F: audio/spiceaudio.c
+F: hw/qxl*
+
 Graphics
 M: Anthony Liguori 
 S: Maintained
-- 
1.7.1




[Qemu-devel] [PATCH 0/2] migration notifiers and spice client migration

2011-01-03 Thread Gerd Hoffmann
  Hi,

This patch series adds spice client migration support to qemu, i.e.
allow the spice client to reconnect automatically to the new host after
vm migration.

It also adds a notifier for migration state changes because spice needs
to know when the migration completed and whenever it was successful or
not.

cheers,
  Gerd

The patches are also available in the git repository at:
  git://anongit.freedesktop.org/spice/qemu spice.v25.pull

Gerd Hoffmann (3):
  add migration state change notifiers
  spice: client migration.
  spice: MAINTAINERS update

 MAINTAINERS |8 
 hmp-commands.hx |   20 
 migration.c |   28 
 migration.h |5 +
 qmp-commands.hx |   35 +++
 ui/qemu-spice.h |1 +
 ui/spice-core.c |   40 
 7 files changed, 137 insertions(+), 0 deletions(-)



[Qemu-devel] [PATCH 2/3] spice: client migration.

2011-01-03 Thread Gerd Hoffmann
Handle spice client migration, i.e. inform a spice client connected
about the new host and connection parameters, so it can move over the
connection automatically.

Signed-off-by: Gerd Hoffmann 
---
 hmp-commands.hx |   20 
 qmp-commands.hx |   35 +++
 ui/qemu-spice.h |1 +
 ui/spice-core.c |   40 
 4 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index df134f8..e6d8f36 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -815,6 +815,26 @@ ETEXI
 },
 
 STEXI
+...@item spice_migrate_info @var{hostname} @var{port} @var{tls-port} 
@var{cert-subject}
+...@findex spice_migrate_info
+Set the spice connection info for the migration target.  The spice
+server will ask the spice client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished
+successfully.
+ETEXI
+
+#if defined(CONFIG_SPICE)
+{
+.name   = "spice_migrate_info",
+.args_type  = "hostname:s,port:i?,tls-port:i?,cert-subject:s?",
+.params = "hostname port tls-port cert-subject",
+.help   = "send migration info to spice client",
+.user_print = monitor_user_noop,
+.mhandler.cmd_new = mon_spice_migrate,
+},
+#endif
+
+STEXI
 @item snapshot_blkdev
 @findex snapshot_blkdev
 Snapshot device, using snapshot file as target if provided
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 56c4d8b..24ada04 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -503,6 +503,41 @@ EQMP
 },
 
 SQMP
+spice_migrate_info
+--
+
+Set the spice connection info for the migration target.  The spice
+server will ask the spice client to automatically reconnect using the
+new parameters (if specified) once the vm migration finished
+successfully.
+
+Arguments:
+
+- "hostname": migration target hostname (json-string)
+- "port": spice tcp port for plaintext channels (json-int, optional)
+- "tls-port": spice tcp port for tls-secured channels (json-int, optional)
+- "cert-subject": server certificate subject (json-string, optional)
+
+Example:
+
+-> { "execute": "spice_migrate_info",
+ "arguments": { "hostname": "virt42.lab.kraxel.org", "port": 1234 } }
+<- { "return": {} }
+
+EQMP
+
+#if defined(CONFIG_SPICE)
+{
+.name   = "spice_migrate_info",
+.args_type  = "hostname:s,port:i?,tls-port:i?,cert-subject:s?",
+.params = "hostname port tls-port cert-subject",
+.help   = "send migration info to spice client",
+.user_print = monitor_user_noop,
+.mhandler.cmd_new = mon_spice_migrate,
+},
+#endif
+
+SQMP
 migrate_set_speed
 -
 
diff --git a/ui/qemu-spice.h b/ui/qemu-spice.h
index 48239c3..13de5ad 100644
--- a/ui/qemu-spice.h
+++ b/ui/qemu-spice.h
@@ -38,6 +38,7 @@ int qemu_spice_set_pw_expire(time_t expires);
 
 void do_info_spice_print(Monitor *mon, const QObject *data);
 void do_info_spice(Monitor *mon, QObject **ret_data);
+int mon_spice_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 #else  /* CONFIG_SPICE */
 
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 27a1ced..95116cc 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -30,11 +30,15 @@
 #include "qbool.h"
 #include "qstring.h"
 #include "qjson.h"
+#include "notify.h"
+#include "migration.h"
 #include "monitor.h"
+#include "hw/hw.h"
 
 /* core bits */
 
 static SpiceServer *spice_server;
+static Notifier migration_state;
 static const char *auth = "spice";
 static char *auth_passwd;
 static time_t auth_expires = TIME_MAX;
@@ -416,6 +420,39 @@ void do_info_spice(Monitor *mon, QObject **ret_data)
 *ret_data = QOBJECT(server);
 }
 
+static void migration_state_notifier(Notifier *notifier)
+{
+int state = get_migration_state();
+
+if (state == MIG_STATE_COMPLETED) {
+#if SPICE_SERVER_VERSION >= 0x000701 /* 0.7.1 */
+spice_server_migrate_switch(spice_server);
+#endif
+}
+}
+
+int mon_spice_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+const char *hostname = qdict_get_str(qdict, "hostname");
+const char *subject  = qdict_get_try_str(qdict, "cert-subject");
+int port = qdict_get_try_int(qdict, "port", -1);
+int tls_port = qdict_get_try_int(qdict, "tls-port", -1);
+int ret;
+
+if (!spice_server) {
+qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice");
+return -1;
+}
+
+ret = spice_server_migrate_info(spice_server, hostname,
+port, tls_port, subject);
+if (ret != 0) {
+qerror_report(QERR_UNDEFINED_ERROR);
+return -1;
+}
+return 0;
+}
+
 static int add_channel(const char *name, const char *value, void *opaque)
 {
 int security = 0;
@@ -573,6 +610,9 @@ void qemu_spice_init(void)
 spice_server_init(spice_server, &core_interface);
 using_spice = 1;
 
+migratio

Re: [Qemu-devel] [Bug 670769] Re: CDROM size not updated when changing image files

2011-01-03 Thread Alex Davis

I code, therefore I am


--- On Wed, 11/10/10, agraf <670...@bugs.launchpad.net> wrote:

> From: agraf <670...@bugs.launchpad.net>
> Subject: Re: [Qemu-devel] [Bug 670769] Re: CDROM size not updated when 
> changing image files
> To: alex14...@yahoo.com
> Date: Wednesday, November 10, 2010, 8:11 AM
> 
> On 10.11.2010, at 13:55, Alex Davis wrote:
> 
> > --- On Tue, 11/9/10, agraf <670...@bugs.launchpad.net>
> wrote:
> > 
> >> From: agraf <670...@bugs.launchpad.net>
> >> Subject: Re: [Qemu-devel] [Bug 670769] Re: CDROM
> size not updated when changing image files
> >> To: alex14...@yahoo.com
> >> Date: Tuesday, November 9, 2010, 10:47 PM
> >> 
> >> On 10.11.2010, at 04:17, Alex Davis wrote:
> >> 
> >>> Please note that until this bug is fixed, one
> cannot
> >> successfully
> >>> install a guest OS from a set of CD-ROMS where
> the
> >> first disk image is
> >>> smaller than subsequent ones.
> >>> 
> >>> -- 
> >>> CDROM size not updated when changing image
> files
> >>> https://bugs.launchpad.net/bugs/670769
> >>> You received this bug notification because you
> are a
> >> member of qemu-
> >>> devel-ml, which is subscribed to QEMU.
> >>> 
> >>> Status in QEMU: New
> >>> 
> >>> Bug description:
> >>> I'm using qemu 13.0 with a plain Linux kernel
> using
> >> the ata_piix driver as the guest, and an initrd
> that starts
> >> a shell. When changing the image in the monitor
> and reading
> >> from the CDROM in the guest, the size is not
> updated. I'm
> >> using LInux 2.6.32.24
> >>> as the host and I've tested 2.6.32.24, 2.6.35,
> and
> >> 2.6.36 as guests.  Both host and guest are
> 64-bit. Here
> >> is the command used to start the guest using the
> initrd:
> >>> 
> >>> ./x86_64-softmmu/qemu-system-x86_64 -cdrom
> >> /spare2/cd1.img -kernel
> >>
> /sources/linux-2.6.32.24-test/arch/x86/boot/bzImage -initrd
> >> /spare2/initrd.img -append 'root=/dev/ram0 rw'
> -cpu
> >> core2duo
> >>> 
> >>> Additional info on this bug can be found here:
> http://marc.info/?l=kvm&m=128746013906820&w=2. Note:
> >> this is how I discovered 
> >>> the bug, using 32-bit Slackware install CDs.
> >>> 
> >>> I'm attaching the initrd I used in my tests: I
> created
> >> two different-sized fake CDROM images by dd'ing
> from
> >> /dev/zero. In my tests,
> >>> cd1.img is smaller that cd2.img. In the
> monitor I
> >> executed 'change ide1-cd0 /spare2/cd2.img' to load
> the new
> >> image. I checked 
> >>> the size by cat'ing /sys/block/sr0/size in the
> guest
> >> after reading the CDROM. Reading the CDROM was
> done by
> >> typing
> >>> 'dd if=/dev/sr0 of=/dev/null bs=512 count=3'
> >> 
> >> Just to clarify, the contents of the image do
> change, but
> >> the reported
> >> size does not?
> > Correct?
> 
> Sounds like a missing change event to the guest to me.
> 
> Kevin, are you aware of this bug?
> 
I looks like change event is being sent, but it's being eaten by the
error recovery in the guest.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/670769

Title:
  CDROM size not updated when changing image files

Status in QEMU:
  New

Bug description:
  I'm using qemu 13.0 with a plain Linux kernel using the ata_piix driver as 
the guest, and an initrd that starts a shell. When changing the image in the 
monitor and reading from the CDROM in the guest, the size is not updated. I'm 
using LInux 2.6.32.24
as the host and I've tested 2.6.32.24, 2.6.35, and 2.6.36 as guests.  Both host 
and guest are 64-bit. Here is the command used to start the guest using the 
initrd:

./x86_64-softmmu/qemu-system-x86_64 -cdrom /spare2/cd1.img -kernel 
/sources/linux-2.6.32.24-test/arch/x86/boot/bzImage -initrd /spare2/initrd.img 
-append 'root=/dev/ram0 rw' -cpu core2duo

Additional info on this bug can be found here: 
http://marc.info/?l=kvm&m=128746013906820&w=2. Note: this is how I discovered 
the bug, using 32-bit Slackware install CDs.

I'm attaching the initrd I used in my tests: I created two different-sized fake 
CDROM images by dd'ing from /dev/zero. In my tests,
cd1.img is smaller that cd2.img. In the monitor I executed 'change ide1-cd0 
/spare2/cd2.img' to load the new image. I checked 
the size by cat'ing /sys/block/sr0/size in the guest after reading the CDROM. 
Reading the CDROM was done by typing
'dd if=/dev/sr0 of=/dev/null bs=512 count=3'





Re: [Qemu-devel] [PATCH 2/6] softfloat: fix float{32, 64}_maybe_silence_nan() for MIPS

2011-01-03 Thread Peter Maydell
On 3 January 2011 14:34, Aurelien Jarno  wrote:
> On targets that define sNaN with the sNaN bit as one, simply clearing
> this bit may correspond to an infinite value.
>
> Convert it to a default NaN if SNAN_BIT_IS_ONE, as it corresponds to
> the MIPS implementation, the only emulated CPU with SNAN_BIT_IS_ONE.
> When other CPU of this type are added, this might be updated to include
> more cases.

This patch doesn't apply to master:

> Signed-off-by: Aurelien Jarno 
> ---
>  fpu/softfloat-specialize.h |   12 ++--
>  1 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
> index f23bd6a..31481e7 100644
> --- a/fpu/softfloat-specialize.h
> +++ b/fpu/softfloat-specialize.h
> @@ -107,13 +107,13 @@ int float32_is_signaling_nan( float32 a_ )
>  float32 float32_maybe_silence_nan( float32 a_ )
>  {
>     if (float32_is_signaling_nan(a_)) {
> -        bits32 a = float32_val(a_);

...on master this line is
uint32_t a = float32_val(a_);

(different type) so the patch doesn't apply.

Other than that, looks OK. I think I'd like a comment somewhere
along the lines of
/* Rules for silencing a signaling NaN are target-specific. Typically
 * targets with !SNAN_BIT_IS_ONE use the rule that the NaN
 * is silenced by setting the bit. Targets where SNAN_BIT_IS_ONE
 * must do something more complicated, because clearing the
 * bit might turn a NaN into an infinity. This code is correct for
 * MIPS but new targets might need something different.
 */

Or you could have the #ifdefs be on TARGET_whatever so
that it's clear (because it won't compile) that adding a new
TARGET_FOO means you have to check behaviour in this
area. But I don't feel very strongly about that.

-- PMM



[Qemu-devel] [Bug 696834] [NEW] FP exception reporting not working on NetBSD host

2011-01-03 Thread Paul Goyette
Public bug reported:

I recognize that NetBSD is not one of the officially supported host OS.
However, qemu 0.13.0 is available in the NetBSD pkgsrc collection, and
works quite well.  Well, with one exception (pun intended): It seems
that Floating Point exceptions don't get reported properly.

The following code-snippet demonstrates the problem:


volatile int flt_signal = 0;

static sigjmp_buf sigfpe_flt_env;
static void
sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
{
flt_signal++;
}

void trigger(void)
{   
struct sigaction sa;
double d = strtod("0", NULL);

if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigfpe_flt_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
printf("%g\n", 1 / d);
}
printf("FPE signal handler invoked %d times.\n");
}

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/696834

Title:
  FP exception reporting not working on NetBSD host

Status in QEMU:
  New

Bug description:
  I recognize that NetBSD is not one of the officially supported host OS.  
However, qemu 0.13.0 is available in the NetBSD pkgsrc collection, and works 
quite well.  Well, with one exception (pun intended): It seems that Floating 
Point exceptions don't get reported properly.

The following code-snippet demonstrates the problem:


volatile int flt_signal = 0;

static sigjmp_buf sigfpe_flt_env;
static void
sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
{
flt_signal++;
}

void trigger(void)
{   
struct sigaction sa;
double d = strtod("0", NULL);

if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigfpe_flt_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
printf("%g\n", 1 / d);
}
printf("FPE signal handler invoked %d times.\n");
}





Re: [Qemu-devel] [PATCH 1/6] softfloat: remove HPPA specific code

2011-01-03 Thread Peter Maydell
On 3 January 2011 14:34, Aurelien Jarno  wrote:
> We don't have any HPPA target, so let's remove HPPA specific code. It
> can be re-added when someone adds an HPPA target.
>
> Signed-off-by: Aurelien Jarno 

Reviewed-by: Peter Maydell 

Do we want to get rid of the one remaining TARGET_HPPA which
is in linux-user/syscall_defs.h?

-- PMM



Re: [Qemu-devel] [PATCH 2/6] softfloat: fix float{32, 64}_maybe_silence_nan() for MIPS

2011-01-03 Thread Aurelien Jarno
Peter Maydell a écrit :
> On 3 January 2011 14:34, Aurelien Jarno  wrote:
>> On targets that define sNaN with the sNaN bit as one, simply clearing
>> this bit may correspond to an infinite value.
>>
>> Convert it to a default NaN if SNAN_BIT_IS_ONE, as it corresponds to
>> the MIPS implementation, the only emulated CPU with SNAN_BIT_IS_ONE.
>> When other CPU of this type are added, this might be updated to include
>> more cases.
> 
> This patch doesn't apply to master:
> 
>> Signed-off-by: Aurelien Jarno 
>> ---
>>  fpu/softfloat-specialize.h |   12 ++--
>>  1 files changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/fpu/softfloat-specialize.h b/fpu/softfloat-specialize.h
>> index f23bd6a..31481e7 100644
>> --- a/fpu/softfloat-specialize.h
>> +++ b/fpu/softfloat-specialize.h
>> @@ -107,13 +107,13 @@ int float32_is_signaling_nan( float32 a_ )
>>  float32 float32_maybe_silence_nan( float32 a_ )
>>  {
>> if (float32_is_signaling_nan(a_)) {
>> -bits32 a = float32_val(a_);
> 
> ...on master this line is
> uint32_t a = float32_val(a_);
> 
> (different type) so the patch doesn't apply.

Oops, yes, my patch series should have started by a patch fixing types,
but i made a mistake selecting the commits to send. Will fix that in a v2.

> Other than that, looks OK. I think I'd like a comment somewhere
> along the lines of
> /* Rules for silencing a signaling NaN are target-specific. Typically
>  * targets with !SNAN_BIT_IS_ONE use the rule that the NaN
>  * is silenced by setting the bit. Targets where SNAN_BIT_IS_ONE
>  * must do something more complicated, because clearing the
>  * bit might turn a NaN into an infinity. This code is correct for
>  * MIPS but new targets might need something different.
>  */
> 
> Or you could have the #ifdefs be on TARGET_whatever so
> that it's clear (because it won't compile) that adding a new
> TARGET_FOO means you have to check behaviour in this
> area. But I don't feel very strongly about that.
> 

Ok, thanks for the review, will fix that.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH 1/6] softfloat: remove HPPA specific code

2011-01-03 Thread Aurelien Jarno
Peter Maydell a écrit :
> On 3 January 2011 14:34, Aurelien Jarno  wrote:
>> We don't have any HPPA target, so let's remove HPPA specific code. It
>> can be re-added when someone adds an HPPA target.
>>
>> Signed-off-by: Aurelien Jarno 
> 
> Reviewed-by: Peter Maydell 
> 
> Do we want to get rid of the one remaining TARGET_HPPA which
> is in linux-user/syscall_defs.h?
> 

Thanks for the review. I personnally don't have a lot of interest in
linux-user, so I will let the linux-user maintainer (Cc) to decide.


-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [Bug 696834] [NEW] FP exception reporting not working on NetBSD host

2011-01-03 Thread Paulo Cezar
On Mon, Jan 3, 2011 at 12:14 PM, Paul Goyette <696...@bugs.launchpad.net>wrote:

> Public bug reported:
>
> I recognize that NetBSD is not one of the officially supported host OS.
> However, qemu 0.13.0 is available in the NetBSD pkgsrc collection, and
> works quite well.  Well, with one exception (pun intended): It seems
> that Floating Point exceptions don't get reported properly.
>
> The following code-snippet demonstrates the problem:
>
>
> volatile int flt_signal = 0;
>
> static sigjmp_buf sigfpe_flt_env;
> static void
> sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
> {
>flt_signal++;
> }
>
> void trigger(void)
> {
>struct sigaction sa;
>double d = strtod("0", NULL);
>
>if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
>sa.sa_flags = SA_SIGINFO;
>sa.sa_sigaction = sigfpe_flt_action;
>sigemptyset(&sa.sa_mask);
>sigaction(SIGFPE, &sa, NULL);
>fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
>printf("%g\n", 1 / d);
>}
>printf("FPE signal handler invoked %d times.\n");
>

this printf() does miss an argument :-)


> }
>
> ** Affects: qemu
> Importance: Undecided
> Status: New
>
> --
> You received this bug notification because you are a member of qemu-
> devel-ml, which is subscribed to QEMU.
> https://bugs.launchpad.net/bugs/696834
>
> Title:
>  FP exception reporting not working on NetBSD host
>
> Status in QEMU:
>  New
>
> Bug description:
>  I recognize that NetBSD is not one of the officially supported host OS.
>  However, qemu 0.13.0 is available in the NetBSD pkgsrc collection, and
> works quite well.  Well, with one exception (pun intended): It seems that
> Floating Point exceptions don't get reported properly.
>
> The following code-snippet demonstrates the problem:
>
>
> volatile int flt_signal = 0;
>
> static sigjmp_buf sigfpe_flt_env;
> static void
> sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
> {
>flt_signal++;
> }
>
> void trigger(void)
> {
>struct sigaction sa;
>double d = strtod("0", NULL);
>
>if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
>sa.sa_flags = SA_SIGINFO;
>sa.sa_sigaction = sigfpe_flt_action;
>sigemptyset(&sa.sa_mask);
>sigaction(SIGFPE, &sa, NULL);
>fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
>printf("%g\n", 1 / d);
>}
>printf("FPE signal handler invoked %d times.\n");
>

this printf() does miss an argument :-)


> }
>
>
>
>


[Qemu-devel] xAPIC version register for >P4/Xeon CPUs

2011-01-03 Thread Markus Duft
Hi!

Another question: Shouldn't the APIC version be 0x14 for CPUs since P4/Xeon? At 
least according to the Intel docs, since then the xAPIC is used, which has 0x14 
as version (see intel manuals, vol 3a "10.4.8 Local APIC Version Register". 
reading the APIC version register yields 0x11 for all CPUs on qemu currently 
(so local APIC, not local xAPIC).

is this inteded? if yes, why? (it is incompatible with the specs, right?).

Regards, Markus



Re: [Qemu-devel] [PATCH 3/6] softfloat: add float{x80, 128}_maybe_silence_nan()

2011-01-03 Thread Peter Maydell
On 3 January 2011 14:34, Aurelien Jarno  wrote:
> Add float{x80,128}_maybe_silence_nan() functions, they will be need by
> propagateFloat{x80,128}NaN().
>
> Signed-off-by: Aurelien Jarno 

Reviewed-by: Peter Maydell 

-- PMM



Re: [Qemu-devel] [Bug 696834] [NEW] FP exception reporting not working on NetBSD host

2011-01-03 Thread Paul Goyette
On Mon, 3 Jan 2011, Paulo Cezar A Junior wrote:



>>printf("FPE signal handler invoked %d times.\n");
>
> this printf() does miss an argument :-)

Yes, it does.  The signal handler is also missing a line:

siglongjmp(sigfpe_flt_env, 1);

That's what I get for extracting bits&pieces of the larger test program. 
:)


The following is a complete, standalone test program:

#include 
#include 
#include 
#include 

volatile int flt_signal = 0;

static sigjmp_buf sigfpe_flt_env;
static void
sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
{

flt_signal++;
siglongjmp(sigfpe_flt_env, 1);
}
int main(int argc, void *argv[])
{
struct sigaction sa;
double d;

printf("Start\n");
if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigfpe_flt_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
d = 1.0 / strtod("0", NULL);
}
printf("FPE signal handler invoked %d times.\n");
}

Executing the program gives the following results:

# cc -o test test.c
# ./test
Start
FPE signal handler invoked 0 times.
#

On "real" hardware,

{225} cc -o test test.c
{226} ./test
Start
FPE signal handler invoked 1 times.
{227}


-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/696834

Title:
  FP exception reporting not working on NetBSD host

Status in QEMU:
  New

Bug description:
  I recognize that NetBSD is not one of the officially supported host OS.  
However, qemu 0.13.0 is available in the NetBSD pkgsrc collection, and works 
quite well.  Well, with one exception (pun intended): It seems that Floating 
Point exceptions don't get reported properly.

The following code-snippet demonstrates the problem:


volatile int flt_signal = 0;

static sigjmp_buf sigfpe_flt_env;
static void
sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
{
flt_signal++;
}

void trigger(void)
{   
struct sigaction sa;
double d = strtod("0", NULL);

if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigfpe_flt_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
printf("%g\n", 1 / d);
}
printf("FPE signal handler invoked %d times.\n");
}





[Qemu-devel] Re: [PATCH v2 14/17] kvm: x86: Introduce kvmclock device to save/restore its state

2011-01-03 Thread Avi Kivity

On 01/03/2011 10:33 AM, Jan Kiszka wrote:

From: Jan Kiszka

If kvmclock is used, which implies the kernel supports it, register a
kvmclock device with the sysbus. Its main purpose is to save and restore
the kernel state on migration, but this will also allow to visualize it
one day.



kvmclock is a per-cpu affair.



@@ -534,6 +599,10 @@ int kvm_arch_init(int smp_cpus)
  int ret;
  struct utsname utsname;

+#ifdef KVM_CAP_ADJUST_CLOCK
+sysbus_register_withprop(&kvmclock_info);
+#endif
+


So this doesn't look right.  I think we're fine with just migrating the 
MSRs, like we migrate anything else that has to do with the cpu.


--
error compiling committee.c: too many arguments to function




[Qemu-devel] [PATCH 0/5] usb-ccid (v12)

2011-01-03 Thread Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and
ccid-card-emulated, providing a CCID bus, a simple passthru protocol
implementing card requiring a client, and a standalone emulated card.

It also introduces a new directory libcaccard with CAC card emulation,
CAC is a type of ISO 7816 smart card.

Tree for pull: git://anongit.freedesktop.org/~alon/qemu usb_ccid.v12

v11-v12 changes:
 * fix out of tree build

v10-v11 changes:
 * fix last patch that removed one of the doc files.
 * updated flow table in docs/ccid.txt

v8-v10 changes:
 * usb-ccid:
  * add slot for future use (Gerd)
  * ifdef ENABLE_MIGRATION for migration support on account of usb
   migration not being ready in general. (Gerd)
 * verbosified commit messages. (Gerd)
 * put libcacard docs in libcacard commit. (Gerd)

v8-v9 changes:
 * Blue Swirl comments:
  * white space fixes
  * enabled by default, disabled only if missing nss
  * forgotten fix from v8 (don't build libcacard.so)
 * added a note about device being little endian
 * library renamed from libcaccard to libcacard
 * squashed both of libcacard patches, they touched different files anyway.

v7-v8 changes:
 * Blue Swirl comments:
  * usb-ccid: deannonymize some structs
  * usb-ccid: coding style change - answer_t and bulk_in_t fixed
  * usb-ccid: handle endianess conversion between guest and host
 * usb-ccid: s/ccid_bulk_in_copy_out/ccid_bulk_in_copy_to_guest/
 * ccid-card-emulated: fix segfault if backend not specified
 * ccid-card-emulated: let last reader inserted win
 * libcaccard: remove double vscard_common.h

v6->v7 changes:
 * external libcaccard became internal directory libcaccard
  * statically link object files into qemu
  * produce libcaccard.so for usage by external projects
  * applied coding style to new code (please check me)
  - did not use the qemu options parsing for libcaccard, since
   it seems to draw large amounts of qemu code (monitor for instance).

v5->v6 changes:
 * really remove static debug (I apologize for claiming to have done so before)

v4->v5 changes:
 * rebased to latest
 * remove static debug in card devices
 * fix --enable-smartcard to link
 * stall instead of assert when exceeding BULK_OUT_DATA_SIZE
 * make ccid_reserve_recv_buf for too large len discard message, not exit
 * make ccid_reserve_recv_buf return void*
 * fix typo
 * remove commented code in VMState

v3->v4:
 * remove ccid field in CCIDBus
 * remove static debug in bus
 * add back docs

v2->v3:
 * split into bus (usb-ccid.c, uses ccid.h) and card (ccid-card-passthru.c).
 * removed documentation (being revised).

v1->v2:
 * all QSIMPLEQ turned into fixed sized rings
 * all allocated buffers turned into fixed size buffers
 * added migration support
 * added a message to tell client qemu has migrated to ip:port
  * for lack of monitor commands ip:port are 0:0, which causes the updated
   vscclient to connect to one port higher on the same host. will add monitor
   commands in a separate patch. tested with current setup.


Alon Levy (4):
  usb-ccid: add CCID bus
  ccid: add passthru card device
  ccid: add ccid-card-emulated device (v2)
  ccid: add docs

Robert Relyea (1):
  libcacard: initial commit after coding style fixes

 Makefile|6 +-
 Makefile.objs   |6 +
 Makefile.target |2 +
 configure   |   31 +
 docs/ccid.txt   |  135 +
 docs/libcacard.txt  |  483 +++
 hw/ccid-card-emulated.c |  501 
 hw/ccid-card-passthru.c |  277 +
 hw/ccid.h   |   35 ++
 hw/usb-ccid.c   | 1362 +++
 libcacard/Makefile  |   15 +
 libcacard/cac.c |  411 +
 libcacard/cac.h |   20 +
 libcacard/card_7816.c   |  780 +
 libcacard/card_7816.h   |   60 ++
 libcacard/card_7816t.h  |  163 +
 libcacard/config.h  |   81 +++
 libcacard/event.c   |  112 
 libcacard/eventt.h  |   28 +
 libcacard/link_test.c   |   20 +
 libcacard/mutex.h   |   59 ++
 libcacard/passthru.c|  612 +++
 libcacard/passthru.h|   50 ++
 libcacard/vcard.c   |  350 +++
 libcacard/vcard.h   |   85 +++
 libcacard/vcard_emul.h  |   59 ++
 libcacard/vcard_emul_nss.c  | 1147 
 libcacard/vcard_emul_type.c |   60 ++
 libcacard/vcard_emul_type.h |   29 +
 libcacard/vcardt.h  |   66 +++
 libcacard/vevent.h  |   26 +
 libcacard/vreader.c |  515 
 libcacard/vreader.h |   53 ++
 libcacard/vreadert.h|   23 +
 libcacard/vscard_common.h   |  130 
 libcacard/vscclient.c   |  710 ++
 36 files changed, 8500 insertions(+), 2 deletions(-)
 create mode 100644 docs/ccid.txt
 create mode 100644 docs/libcacard.txt
 create mode 100644 hw/ccid-card-emul

[Qemu-devel] [PATCH 2/5] ccid: add passthru card device

2011-01-03 Thread Alon Levy
The passthru ccid card is a device sitting on the usb-ccid bus and
using a chardevice to communicate with a remote device using the
VSCard protocol defined in libcacard/vscard_common.h

Usage docs available in following patch in docs/ccid.txt

Signed-off-by: Alon Levy 
---
 Makefile.objs |2 +-
 hw/ccid-card-passthru.c   |  277 +
 libcacard/vscard_common.h |  130 +
 3 files changed, 408 insertions(+), 1 deletions(-)
 create mode 100644 hw/ccid-card-passthru.c
 create mode 100644 libcacard/vscard_common.h

diff --git a/Makefile.objs b/Makefile.objs
index 7da4771..274db5e 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -197,7 +197,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o
 hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 hw-obj-$(CONFIG_DMA) += dma.o
-hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o
+hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
 
 # PPC devices
 hw-obj-$(CONFIG_OPENPIC) += openpic.o
diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c
new file mode 100644
index 000..e90ba0e
--- /dev/null
+++ b/hw/ccid-card-passthru.c
@@ -0,0 +1,277 @@
+/*
+ * CCID Card Device emulation
+ *
+ * Copyright (c) 2010 Red Hat.
+ * Written by Alon Levy.
+ *
+ * This code is licenced under the LGPL.
+ */
+
+#include "qemu-char.h"
+#include "monitor.h"
+#include "hw/ccid.h"
+#include "libcacard/vscard_common.h"
+
+#define DPRINTF(card, lvl, fmt, ...) \
+do { if (lvl <= card->debug) { printf("ccid-card: " fmt , ## __VA_ARGS__); } } 
while (0)
+
+/* Passthru card */
+
+
+// TODO: do we still need this?
+uint8_t DEFAULT_ATR[] = {
+/* From some example somewhere
+ 0x3B, 0xB0, 0x18, 0x00, 0xD1, 0x81, 0x05, 0xB1, 0x40, 0x38, 0x1F, 0x03, 0x28
+ */
+
+/* From an Athena smart card */
+ 0x3B, 0xD5, 0x18, 0xFF, 0x80, 0x91, 0xFE, 0x1F, 0xC3, 0x80, 0x73, 0xC8, 0x21, 
0x13, 0x08
+
+}; /* maximum size of ATR - from 7816-3 */
+
+
+#define PASSTHRU_DEV_NAME "ccid-card-passthru"
+#define VSCARD_IN_SIZE 65536
+#define MAX_ATR_SIZE40
+
+typedef struct PassthruState PassthruState;
+
+struct PassthruState {
+CCIDCardState base;
+CharDriverState *cs;
+uint8_t  vscard_in_data[VSCARD_IN_SIZE];
+uint32_t vscard_in_pos;
+uint32_t vscard_in_hdr;
+uint8_t  atr[MAX_ATR_SIZE];
+uint8_t  atr_length;
+uint8_t debug;
+};
+
+/* VSCard protocol over chardev
+ * This code should not depend on the card type.
+ * */
+
+static void ccid_card_vscard_send_msg(
+PassthruState *s, VSCMsgType type, reader_id_t reader_id,
+const uint8_t* payload, uint32_t length)
+{
+VSCMsgHeader scr_msg_header;
+
+scr_msg_header.type = type;
+scr_msg_header.reader_id = reader_id;
+scr_msg_header.length = length;
+qemu_chr_write(s->cs, (uint8_t*)&scr_msg_header, sizeof(VSCMsgHeader));
+qemu_chr_write(s->cs, payload, length);
+}
+
+static void ccid_card_vscard_send_apdu(
+PassthruState *s, const uint8_t* apdu, uint32_t length)
+{
+ccid_card_vscard_send_msg(s, VSC_APDU, VSCARD_MINIMAL_READER_ID, apdu, 
length);
+}
+
+static void ccid_card_vscard_send_error(
+PassthruState *s, reader_id_t reader_id, VSCErrorCode code)
+{
+VSCMsgError msg = {.code=code};
+
+ccid_card_vscard_send_msg(s, VSC_Error, reader_id, (uint8_t*)&msg, 
sizeof(msg));
+}
+
+static void ccid_card_vscard_send_init(PassthruState *s)
+{
+VSCMsgInit msg = {.version=VSCARD_VERSION};
+
+ccid_card_vscard_send_msg(s, VSC_Init, VSCARD_UNDEFINED_READER_ID,
+ (uint8_t*)&msg, sizeof(msg));
+}
+
+static int ccid_card_vscard_can_read(void *opaque)
+{
+return 65535;
+}
+
+static void ccid_card_vscard_handle_message(PassthruState *card,
+VSCMsgHeader* scr_msg_header)
+{
+uint8_t *data = (uint8_t*)&scr_msg_header[1];
+
+switch (scr_msg_header->type) {
+case VSC_ATR:
+DPRINTF(card, 1, "VSC_ATR %d\n", scr_msg_header->length);
+assert(scr_msg_header->length <= MAX_ATR_SIZE);
+memcpy(card->atr, data, scr_msg_header->length);
+card->atr_length = scr_msg_header->length;
+ccid_card_card_inserted(&card->base);
+break;
+case VSC_APDU:
+ccid_card_send_apdu_to_guest(&card->base, data, 
scr_msg_header->length);
+break;
+case VSC_CardRemove:
+DPRINTF(card, 1, "VSC_CardRemove\n");
+ccid_card_card_removed(&card->base);
+break;
+case VSC_Init:
+break;
+case VSC_Error:
+ccid_card_card_error(&card->base, *(uint64_t*)data);
+break;
+case VSC_ReaderAdd:
+if (ccid_card_ccid_attach(&card->base) < 0) {
+ccid_card_vscard_send_error(card, VSCARD_UNDEFINED_READER_ID,
+  VSC_CANNOT_ADD_MORE_READERS);
+} else {
+ccid_card_vscard_send_msg(card, VSC_ReaderAddResponse,
+  

[Qemu-devel] Re: [PATCH v2 17/17] kvm: Drop dependencies on very old capabilities

2011-01-03 Thread Avi Kivity

On 01/03/2011 10:33 AM, Jan Kiszka wrote:

From: Jan Kiszka

COALESCED_MMIO, SYNC_MMU, EXT_CPUID, CLOCKSOURCE, NOP_IO_DELAY, PV_MMU -
all these caps predate features on which we already depend at build
time. Moreover, the check for KVM_CAP_EXT_CPUID is unneeded as we
already test&  fail is a more recent feature is missing.


No.  Each test documents a dependency of qemu on a kvm feature.  Even 
though something like SYNC_MMU is unlikely to go away, as long as we 
depend on it, we require the feature.


--
error compiling committee.c: too many arguments to function




[Qemu-devel] [PATCH 5/5] ccid: add docs

2011-01-03 Thread Alon Levy
Add documentation for the usb-ccid device and accompanying two card
devices, ccid-card-emulated and ccid-card-passthru.
---
 docs/ccid.txt |  135 +
 1 files changed, 135 insertions(+), 0 deletions(-)
 create mode 100644 docs/ccid.txt

diff --git a/docs/ccid.txt b/docs/ccid.txt
new file mode 100644
index 000..75605bb
--- /dev/null
+++ b/docs/ccid.txt
@@ -0,0 +1,135 @@
+Qemu CCID Device Documentation.
+
+Contents
+1. USB CCID device
+2. Building
+3. Using ccid-card-emulated with hardware
+4. Using ccid-card-emulated with certificates
+5. Using ccid-card-passthru with client side hardware
+6. Using ccid-card-passthru with client side certificates
+7. Passthrough protocol scenario
+8. libcaccard
+
+1. USB CCID device
+
+The USB CCID device is a USB device implementing the CCID specification, which
+lets one connect smart card readers that implement the same spec. For more
+information see the specification:
+
+ Universal Serial Bus
+ Device Class: Smart Card
+ CCID
+ Specification for
+ Integrated Circuit(s) Cards Interface Devices
+ Revision 1.1
+ April 22rd, 2005
+
+Smartcard are used for authentication, single sign on, decryption in
+public/private schemes and digital signatures. A smartcard reader on the client
+cannot be used on a guest with simple usb passthrough since it will then not be
+available on the client, possibly locking the computer when it is "removed". On
+the other hand this device can let you use the smartcard on both the client and
+the guest machine. It is also possible to have a completely virtual smart card
+reader and smart card (i.e. not backed by a physical device) using this device.
+
+2. Building
+
+The cryptographic functions and access to the physical card is done via NSS.
+
+Installing NSS:
+
+In redhat/fedora:
+yum install nss-devel
+In ubuntu/debian:
+apt-get install libnss3-dev
+(not tested on ubuntu)
+
+Configuring and building:
+./configure --enable-smartcard && make
+
+3. Using ccid-card-emulated with hardware
+
+Assuming you have a working smartcard on the host with the current
+user, using NSS, qemu acts as another NSS client using ccid-card-emulated:
+
+qemu -usb -device usb-ccid -device ccid-card-emualated
+
+4. Using ccid-card-emulated with certificates
+
+You must create the certificates. This is a one time process. We use NSS
+certificates:
+
+certutil -d /etc/pki/nssdb -x -t "CT,CT,CT" -S -s "CN=cert1" -n cert1
+
+Note: you must have exactly three certificates.
+
+Assuming the current user can access the certificates (use certutil -L to
+verify), you can use the emulated card type with the certificates backend:
+
+qemu -usb -device usb-ccid -device 
ccid-card-emulated,backend=certificates,cert1=cert1,cert2=cert2,cert3=cert3
+
+5. Using ccid-card-passthru with client side hardware
+
+on the host specify the ccid-card-passthru device with a suitable chardev:
+
+qemu -chardev socket,server,host=0.0.0.0,port=2001,id=ccid,nowait -usb 
-device usb-ccid -device ccid-card-passthru,chardev=ccid
+
+on the client run vscclient, built when you built the libcaccard library:
+libcaccard/vscclient  2001
+
+6. Using ccid-card-passthru with client side certificates
+
+Run qemu as per #5, and run vscclient as follows:
+(Note: vscclient command line interface is in a state of change)
+
+libcaccard/vscclient -e "db=\"/etc/pki/nssdb\" use_hw=no 
soft=(,Test,CAC,,cert1,cert2,cert3)"  2001
+
+7. Passthrough protocol scenario
+
+This is a typical interchange of messages when using the passthru card device.
+usb-ccid is a usb device. It defaults to an unattached usb device on startup.
+usb-ccid expects a chardev and expects the protocol defined in
+cac_card/vscard_common.h to be passed over that.
+The usb-ccid device can be in one of three modes:
+ * detached
+ * attached with no card
+ * attached with card
+
+A typical interchange is: (the arrow shows who started each exchange, it can 
be client
+originated or guest originated)
+
+client event  |  vscclient   |passthru| usb-ccid  
|  guest event
+--
+  |  VSC_Init||   |
+  |  VSC_ReaderAdd   || attach|
+  |  ||   
|  sees new usb device.
+card inserted ->  |  ||   |
+  |  VSC_ATR |   insert   | insert
|  see new card
+  |  ||   |
+  |  VSC_APDU|   VSC_APDU |   
| <- guest sends APDU
+client<->physical |  ||   |
+card APDU exchange|  ||   |

[Qemu-devel] [PATCH 4/5] ccid: add ccid-card-emulated device (v2)

2011-01-03 Thread Alon Levy
This devices uses libcacard (internal) to emulate a smartcard conforming
to the CAC standard. It attaches to the usb-ccid bus. Usage instructions
(example command lines) are in the following patch in docs/ccid.txt. It
uses libcacard which uses nss, so it can work with both hw cards and
certificates (files).

changes from v1:
remove stale comments, use only c-style comments
bugfix, forgot to set recv_len
change reader name to 'Virtual Reader'

Signed-off-by: Alon Levy 
---
 Makefile.objs   |2 +-
 hw/ccid-card-emulated.c |  501 +++
 2 files changed, 502 insertions(+), 1 deletions(-)
 create mode 100644 hw/ccid-card-emulated.c

diff --git a/Makefile.objs b/Makefile.objs
index 6a0030b..303b642 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -197,7 +197,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o
 hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 hw-obj-$(CONFIG_DMA) += dma.o
-hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
+hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o 
ccid-card-emulated.o
 
 # PPC devices
 hw-obj-$(CONFIG_OPENPIC) += openpic.o
diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
new file mode 100644
index 000..7ecdf75
--- /dev/null
+++ b/hw/ccid-card-emulated.c
@@ -0,0 +1,501 @@
+/*
+ * CCID Card Device. Emulated card.
+ *
+ * It can be used to provide access to the local hardware in a non exclusive
+ * way, or it can use certificates. It requires the usb-ccid bus.
+ *
+ * Usage 1: standard, mirror hardware reader+card:
+ * qemu .. -usb -device usb-ccid -device ccid-card-emulated
+ *
+ * Usage 2: use certificates, no hardware required
+ * one time: create the certificates:
+ *  for i in 1 2 3; do certutil -d /etc/pki/nssdb -x -t "CT,CT,CT" -S -s 
"CN=user$i" -n user$i; done
+ * qemu .. -usb -device usb-ccid -device 
ccid-card-emulated,cert1=user1,cert2=user2,cert3=user3
+ *
+ * If you use a non default db for the certificates you can specify it using 
the db parameter.
+ *
+ *
+ * Copyright (c) 2010 Red Hat.
+ * Written by Alon Levy.
+ *
+ * This code is licenced under the LGPL.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "qemu-char.h"
+#include "monitor.h"
+#include "hw/ccid.h"
+
+#define DPRINTF(card, lvl, fmt, ...) \
+do { if (lvl <= card->debug) { printf("ccid-card-emul: %s: " fmt , __func__, 
## __VA_ARGS__); } } while (0)
+
+#define EMULATED_DEV_NAME "ccid-card-emulated"
+
+#define BACKEND_NSS_EMULATED "nss-emulated" /* the default */
+#define BACKEND_CERTIFICATES "certificates"
+
+typedef struct EmulatedState EmulatedState;
+
+enum {
+EMUL_READER_INSERT = 0,
+EMUL_READER_REMOVE,
+EMUL_CARD_INSERT,
+EMUL_CARD_REMOVE,
+EMUL_GUEST_APDU,
+EMUL_RESPONSE_APDU,
+EMUL_ERROR,
+};
+
+static const char* emul_event_to_string(uint32_t emul_event)
+{
+switch (emul_event) {
+case EMUL_READER_INSERT: return "EMUL_READER_INSERT";
+case EMUL_READER_REMOVE: return "EMUL_READER_REMOVE";
+case EMUL_CARD_INSERT: return "EMUL_CARD_INSERT";
+case EMUL_CARD_REMOVE: return "EMUL_CARD_REMOVE";
+case EMUL_GUEST_APDU: return "EMUL_GUEST_APDU";
+case EMUL_RESPONSE_APDU: return "EMUL_RESPONSE_APDU";
+case EMUL_ERROR: return "EMUL_ERROR";
+default:
+break;
+}
+return "UNKNOWN";
+}
+
+typedef struct EmulEvent {
+QSIMPLEQ_ENTRY(EmulEvent) entry;
+union {
+struct {
+uint32_t type;
+} gen;
+struct {
+uint32_t type;
+uint64_t code;
+} error;
+struct {
+uint32_t type;
+uint32_t len;
+uint8_t data[];
+} data;
+} p;
+} EmulEvent;
+
+#define MAX_ATR_SIZE 40
+struct EmulatedState {
+CCIDCardState base;
+uint8_t  debug;
+char*backend;
+char*cert1;
+char*cert2;
+char*cert3;
+char*db;
+uint8_t  atr[MAX_ATR_SIZE];
+uint8_t  atr_length;
+QSIMPLEQ_HEAD(event_list, EmulEvent) event_list;
+pthread_mutex_t event_list_mutex;
+VReader *reader;
+QSIMPLEQ_HEAD(guest_apdu_list, EmulEvent) guest_apdu_list;
+pthread_mutex_t vreader_mutex; /* and guest_apdu_list mutex */
+pthread_mutex_t handle_apdu_mutex;
+pthread_cond_t handle_apdu_cond;
+int  pipe[2];
+int  quit_apdu_thread;
+pthread_mutex_t apdu_thread_quit_mutex;
+pthread_cond_t apdu_thread_quit_cond;
+};
+
+static void emulated_apdu_from_guest(CCIDCardState *base, const uint8_t *apdu, 
uint32_t len)
+{
+EmulatedState *card = DO_UPCAST(EmulatedState, base, base);
+EmulEvent *event = (EmulEvent*)malloc(sizeof(EmulEvent) + len);
+
+assert(event);
+event->p.data.type = EMUL_GUEST_APDU;
+event->p.data.len = len;
+memcpy(event->p.data.data, apdu, len);
+pthread_mutex_lock(&card->vreader_mutex);
+QSIMPLEQ_INSERT_TAIL(&card->guest_apdu_list, even

[Qemu-devel] Re: [PATCH v2 00/17] [uq/master] Prepare for more qemu-kvm merging

2011-01-03 Thread Avi Kivity

On 01/03/2011 10:32 AM, Jan Kiszka wrote:

All previously sent patches against current uq combined, some smaller
tweaks applied, and 4 new patches added. Major news is support for
using up to 16M BIOSes and optional code dump for cpu_dump_state. Those
features are already present qemu-kvm but were reworked to provide
cleaner upstream versions.



Looks reasonable overall.


Based on this series, I've an experimental tree here where I eliminated
another 1500 LOC from qemu-kvm code. Specifically, that tree sets an end
to duplicate KVM and VCPU initialization functions, KVMState copies, and
redundant state saving/loading functions. Will be rolled out after some
more review and testing.


Sounds really frightening... this glue code is a real breeding ground 
for subtle bugs and merge problems.


--
error compiling committee.c: too many arguments to function




[Qemu-devel] Re: [PATCH v2 16/17] kvm: x86: Rework identity map and TSS setup for larger BIOS sizes

2011-01-03 Thread Avi Kivity

On 01/03/2011 10:33 AM, Jan Kiszka wrote:

From: Jan Kiszka

First of all, we only need this EPT identity and TSS reservation on
Intel CPUs.


kvm-amd will ignore it just fine.  I'd like to keep arch differences 
away from userspace.



Then, in order to support loading BIOSes>  256K, reorder the
code, adjusting the base if the kernel supports moving the identity map.
We can drop the check for KVM_CAP_SET_TSS_ADDR as we already depend on
much newer features.


There is no ordering on kvm features.  Each can come and go as it pleases.

--
error compiling committee.c: too many arguments to function




[Qemu-devel] [PATCH 0/2] ARM: Fix VQSHL/VQSHLU immediate forms

2011-01-03 Thread Peter Maydell
This patchset fixes errors in the decoding and implementation of the
immediate forms of the VQSHL/VQSHLU ARM instructions.
Tested in the usual random-instruction-set way. This is the final part
of the maemo-qemu tree commit 03a2445a fixes (the first part being
the already-committed VQSHL-reg patchset); the patch down as authored
by me is a minor tweaking of changes in the maemo-qemu commit.

Juha Riihimäki (1):
  ARM: Fix decoding of VQSHL/VQSHLU immediate forms

Peter Maydell (1):
  ARM: add neon helpers for VQSHLU

 target-arm/helpers.h |4 +++
 target-arm/neon_helper.c |   47 ++
 target-arm/translate.c   |   51 -
 3 files changed, 87 insertions(+), 15 deletions(-)




Re: [Qemu-devel] [Bug 696834] [NEW] FP exception reporting not working on NetBSD host

2011-01-03 Thread Paul Goyette
On Mon, 3 Jan 2011, Paul Goyette wrote:

> The following is a complete, standalone test program:
>
>   #include 
>   #include 
>   #include 
>   #include 
>
>volatile int flt_signal = 0;
>
>   static sigjmp_buf sigfpe_flt_env;
>   static void
>   sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
>   {
>
>   flt_signal++;
>   siglongjmp(sigfpe_flt_env, 1);
>   }
>   int main(int argc, void *argv[])
>   {
>   struct sigaction sa;
>   double d;
>
>   printf("Start\n");
>   if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
>   sa.sa_flags = SA_SIGINFO;
>   sa.sa_sigaction = sigfpe_flt_action;
>   sigemptyset(&sa.sa_mask);
>   sigaction(SIGFPE, &sa, NULL);
>   fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
>   d = 1.0 / strtod("0", NULL);
>   }
>   printf("FPE signal handler invoked %d times.\n");

And, of course, I still missed the extra agument:

 printf("FPE signal handler invoked %d times.\n",
flt_signal);


>   }
>
> Executing the program gives the following results:
>
>   # cc -o test test.c
>   # ./test
>   Start
>   FPE signal handler invoked 0 times.
>   #
>
> On "real" hardware,
>
>   {225} cc -o test test.c
>   {226} ./test
>   Start
>   FPE signal handler invoked 1 times.
>   {227}
>
>
> -
> | Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
> | Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
> | Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
> | Kernel Developer |  | pgoyette at netbsd.org  |
> -
>
> -- 
> You received this bug notification because you are a direct subscriber
> of the bug.
> https://bugs.launchpad.net/bugs/696834
>
> Title:
>  FP exception reporting not working on NetBSD host
>
> Status in QEMU:
>  New
>
> Bug description:
>  I recognize that NetBSD is not one of the officially supported host OS.  
> However, qemu 0.13.0 is available in the NetBSD pkgsrc collection, and works 
> quite well.  Well, with one exception (pun intended): It seems that Floating 
> Point exceptions don't get reported properly.
>
> The following code-snippet demonstrates the problem:
>
>
> volatile int flt_signal = 0;
>
> static sigjmp_buf sigfpe_flt_env;
> static void
> sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
> {
>flt_signal++;
> }
>
> void trigger(void)
> {
>struct sigaction sa;
>double d = strtod("0", NULL);
>
>if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
>sa.sa_flags = SA_SIGINFO;
>sa.sa_sigaction = sigfpe_flt_action;
>sigemptyset(&sa.sa_mask);
>sigaction(SIGFPE, &sa, NULL);
>fpsetmask(FP_X_INV|FP_X_DZ|FP_X_OFL|FP_X_UFL|FP_X_IMP);
>printf("%g\n", 1 / d);
>}
>printf("FPE signal handler invoked %d times.\n");
> }
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/qemu/+bug/696834/+subscribe
>
> !DSPAM:4d21f0752341470756574!
>
>
>

-
| Paul Goyette | PGP Key fingerprint: | E-mail addresses:   |
| Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com|
| Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net |
| Kernel Developer |  | pgoyette at netbsd.org  |
-

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/696834

Title:
  FP exception reporting not working on NetBSD host

Status in QEMU:
  New

Bug description:
  I recognize that NetBSD is not one of the officially supported host OS.  
However, qemu 0.13.0 is available in the NetBSD pkgsrc collection, and works 
quite well.  Well, with one exception (pun intended): It seems that Floating 
Point exceptions don't get reported properly.

The following code-snippet demonstrates the problem:


volatile int flt_signal = 0;

static sigjmp_buf sigfpe_flt_env;
static void
sigfpe_flt_action(int signo, siginfo_t *info, void *ptr)
{
flt_signal++;
}

void trigger(void)
{   
struct sigaction sa;
double d = strtod("0", NULL);

if (sigsetjmp(sigfpe_flt_env, 0) == 0) {
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = sigfpe_flt_action;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, NULL);
fpsetmask(FP_X_IN

[Qemu-devel] [PATCH 1/2] ARM: add neon helpers for VQSHLU

2011-01-03 Thread Peter Maydell
Add neon helper functions to implement VQSHLU, which is a
signed-to-unsigned version of VQSHL available only as an
immediate form.

Signed-off-by: Juha Riihimäki 
Reviewed-by: Peter Maydell 
---
 target-arm/helpers.h |4 +++
 target-arm/neon_helper.c |   47 ++
 2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/target-arm/helpers.h b/target-arm/helpers.h
index 0d1bc47..b88ebae 100644
--- a/target-arm/helpers.h
+++ b/target-arm/helpers.h
@@ -249,6 +249,10 @@ DEF_HELPER_3(neon_qshl_u32, i32, env, i32, i32)
 DEF_HELPER_3(neon_qshl_s32, i32, env, i32, i32)
 DEF_HELPER_3(neon_qshl_u64, i64, env, i64, i64)
 DEF_HELPER_3(neon_qshl_s64, i64, env, i64, i64)
+DEF_HELPER_3(neon_qshlu_s8, i32, env, i32, i32);
+DEF_HELPER_3(neon_qshlu_s16, i32, env, i32, i32);
+DEF_HELPER_3(neon_qshlu_s32, i32, env, i32, i32);
+DEF_HELPER_3(neon_qshlu_s64, i64, env, i64, i64);
 DEF_HELPER_3(neon_qrshl_u8, i32, env, i32, i32)
 DEF_HELPER_3(neon_qrshl_s8, i32, env, i32, i32)
 DEF_HELPER_3(neon_qrshl_u16, i32, env, i32, i32)
diff --git a/target-arm/neon_helper.c b/target-arm/neon_helper.c
index dae063e..20f3c16 100644
--- a/target-arm/neon_helper.c
+++ b/target-arm/neon_helper.c
@@ -632,6 +632,53 @@ uint64_t HELPER(neon_qshl_s64)(CPUState *env, uint64_t 
valop, uint64_t shiftop)
 return val;
 }
 
+#define NEON_FN(dest, src1, src2) do { \
+if (src1 & (1 << (sizeof(src1) * 8 - 1))) { \
+SET_QC(); \
+dest = 0; \
+} else { \
+int8_t tmp; \
+tmp = (int8_t)src2; \
+if (tmp >= (ssize_t)sizeof(src1) * 8) { \
+if (src1) { \
+SET_QC(); \
+dest = ~0; \
+} else { \
+dest = 0; \
+} \
+} else if (tmp <= -(ssize_t)sizeof(src1) * 8) { \
+dest = 0; \
+} else if (tmp < 0) { \
+dest = src1 >> -tmp; \
+} else { \
+dest = src1 << tmp; \
+if ((dest >> tmp) != src1) { \
+SET_QC(); \
+dest = ~0; \
+} \
+} \
+}} while (0)
+NEON_VOP_ENV(qshlu_s8, neon_u8, 4)
+NEON_VOP_ENV(qshlu_s16, neon_u16, 2)
+#undef NEON_FN
+
+uint32_t HELPER(neon_qshlu_s32)(CPUState *env, uint32_t valop, uint32_t 
shiftop)
+{
+if ((int32_t)valop < 0) {
+SET_QC();
+return 0;
+}
+return helper_neon_qshl_u32(env, valop, shiftop);
+}
+
+uint64_t HELPER(neon_qshlu_s64)(CPUState *env, uint64_t valop, uint64_t 
shiftop)
+{
+if ((int64_t)valop < 0) {
+SET_QC();
+return 0;
+}
+return helper_neon_qshl_u64(env, valop, shiftop);
+}
 
 /* FIXME: This is wrong.  */
 #define NEON_FN(dest, src1, src2) do { \
-- 
1.6.3.3




[Qemu-devel] [PATCH 2/2] ARM: Fix decoding of VQSHL/VQSHLU immediate forms

2011-01-03 Thread Peter Maydell
From: Juha Riihimäki 

Fix errors in the decoding of ARM VQSHL/VQSHLU immediate forms,
including using the new VQSHLU helper functions where appropriate.

Signed-off-by: Peter Maydell 
---
 target-arm/translate.c |   51 +--
 1 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 2598268..1853b5c 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -4647,14 +4647,22 @@ static int disas_neon_data_insn(CPUState * env, 
DisasContext *s, uint32_t insn)
 case 5: /* VSHL, VSLI */
 gen_helper_neon_shl_u64(cpu_V0, cpu_V0, cpu_V1);
 break;
-case 6: /* VQSHL */
-if (u)
-gen_helper_neon_qshl_u64(cpu_V0, cpu_env, 
cpu_V0, cpu_V1);
-else
-gen_helper_neon_qshl_s64(cpu_V0, cpu_env, 
cpu_V0, cpu_V1);
+case 6: /* VQSHLU */
+if (u) {
+gen_helper_neon_qshlu_s64(cpu_V0, cpu_env,
+  cpu_V0, cpu_V1);
+} else {
+return 1;
+}
 break;
-case 7: /* VQSHLU */
-gen_helper_neon_qshl_u64(cpu_V0, cpu_env, cpu_V0, 
cpu_V1);
+case 7: /* VQSHL */
+if (u) {
+gen_helper_neon_qshl_u64(cpu_V0, cpu_env,
+ cpu_V0, cpu_V1);
+} else {
+gen_helper_neon_qshl_s64(cpu_V0, cpu_env,
+ cpu_V0, cpu_V1);
+}
 break;
 }
 if (op == 1 || op == 3) {
@@ -4693,17 +4701,30 @@ static int disas_neon_data_insn(CPUState * env, 
DisasContext *s, uint32_t insn)
 default: return 1;
 }
 break;
-case 6: /* VQSHL */
-GEN_NEON_INTEGER_OP_ENV(qshl);
-break;
-case 7: /* VQSHLU */
+case 6: /* VQSHLU */
+if (!u) {
+return 1;
+}
 switch (size) {
-case 0: gen_helper_neon_qshl_u8(tmp, cpu_env, tmp, 
tmp2); break;
-case 1: gen_helper_neon_qshl_u16(tmp, cpu_env, 
tmp, tmp2); break;
-case 2: gen_helper_neon_qshl_u32(tmp, cpu_env, 
tmp, tmp2); break;
-default: return 1;
+case 0:
+gen_helper_neon_qshlu_s8(tmp, cpu_env,
+ tmp, tmp2);
+break;
+case 1:
+gen_helper_neon_qshlu_s16(tmp, cpu_env,
+  tmp, tmp2);
+break;
+case 2:
+gen_helper_neon_qshlu_s32(tmp, cpu_env,
+  tmp, tmp2);
+break;
+default:
+return 1;
 }
 break;
+case 7: /* VQSHL */
+GEN_NEON_INTEGER_OP_ENV(qshl);
+break;
 }
 dead_tmp(tmp2);
 
-- 
1.6.3.3




[Qemu-devel] Re: [PATCH v2 14/17] kvm: x86: Introduce kvmclock device to save/restore its state

2011-01-03 Thread Jan Kiszka
Am 03.01.2011 17:04, Avi Kivity wrote:
> On 01/03/2011 10:33 AM, Jan Kiszka wrote:
>> From: Jan Kiszka
>>
>> If kvmclock is used, which implies the kernel supports it, register a
>> kvmclock device with the sysbus. Its main purpose is to save and restore
>> the kernel state on migration, but this will also allow to visualize it
>> one day.
>>
> 
> kvmclock is a per-cpu affair.

Nope, it's state (the one save/restored here) is per VM.

> 
>>
>> @@ -534,6 +599,10 @@ int kvm_arch_init(int smp_cpus)
>>   int ret;
>>   struct utsname utsname;
>>
>> +#ifdef KVM_CAP_ADJUST_CLOCK
>> +sysbus_register_withprop(&kvmclock_info);
>> +#endif
>> +
> 
> So this doesn't look right.  I think we're fine with just migrating the
> MSRs, like we migrate anything else that has to do with the cpu.
> 

The kvmclock state is not contained in any MSR. It's an independent
machine state that can be indirectly obtained via MSR access. Therefore,
qemu-kvm currently registers only one vmstate entry per machine, and
this patch just turns this into a clean device - because that's what
kvmclock is in the end, something like an HPET.

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] Re: [PATCH v2 14/17] kvm: x86: Introduce kvmclock device to save/restore its state

2011-01-03 Thread Glauber Costa
On Mon, 2011-01-03 at 18:04 +0200, Avi Kivity wrote:
> On 01/03/2011 10:33 AM, Jan Kiszka wrote:
> > From: Jan Kiszka
> >
> > If kvmclock is used, which implies the kernel supports it, register a
> > kvmclock device with the sysbus. Its main purpose is to save and restore
> > the kernel state on migration, but this will also allow to visualize it
> > one day.
> >
> 
> kvmclock is a per-cpu affair.
> 
> >
> > @@ -534,6 +599,10 @@ int kvm_arch_init(int smp_cpus)
> >   int ret;
> >   struct utsname utsname;
> >
> > +#ifdef KVM_CAP_ADJUST_CLOCK
> > +sysbus_register_withprop(&kvmclock_info);
> > +#endif
> > +
> 
> So this doesn't look right.  I think we're fine with just migrating the 
> MSRs, like we migrate anything else that has to do with the cpu.

The ioctl jan is handling here is a global one, that adjusts the base
offset for the clock over migration. It is okay.




[Qemu-devel] Re: [PATCH v2 11/17] kvm: x86: Reset paravirtual MSRs

2011-01-03 Thread Glauber Costa
On Mon, 2011-01-03 at 09:33 +0100, Jan Kiszka wrote:
> From: Jan Kiszka 
> 
> Make sure to clear MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK, and
> MSR_KVM_ASYNC_PF_EN so that a freshly booted guest cannot be disturbed
> by old values.
> 
> Signed-off-by: Jan Kiszka 
> CC: Glauber Costa 
> ---
>  target-i386/kvm.c |   10 ++
>  1 files changed, 10 insertions(+), 0 deletions(-)
> 
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index d8f26bf..664a4a0 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -453,6 +453,9 @@ void kvm_arch_reset_vcpu(CPUState *env)
>  env->nmi_injected = 0;
>  env->nmi_pending = 0;
>  env->xcr0 = 1;
> +env->system_time_msr = 0;
> +env->wall_clock_msr = 0;
> +env->async_pf_en_msr = 0;

Have you seen this happening? I'd expect CPUState to be zeroed out over
init. And if it is not, I guess we should...





[Qemu-devel] Re: [PATCH v2 14/17] kvm: x86: Introduce kvmclock device to save/restore its state

2011-01-03 Thread Glauber Costa
On Mon, 2011-01-03 at 09:33 +0100, Jan Kiszka wrote:
> From: Jan Kiszka 
> 
> If kvmclock is used, which implies the kernel supports it, register a
> kvmclock device with the sysbus. Its main purpose is to save and restore
> the kernel state on migration, but this will also allow to visualize it
> one day.
> 
> Signed-off-by: Jan Kiszka 
> CC: Glauber Costa 

Hi Jan.

I've just recently posted a patch (not sure what was made from it), that
fixes a bug that you reintroduce here.

The bug is: if we call KVM_GET_CLOCK ioctl in pre_save, this means that
this value will change every time we issue savevm, even if the machine
is not run in between.

Ideally, we'd like to have two consecutive savevms returning the exact
same thing in that situation.

I like the general approach of moving it to sysbus, but please move the
ioctl to change state notifiers.

Cheers!





[Qemu-devel] Re: [PATCH v2 11/17] kvm: x86: Reset paravirtual MSRs

2011-01-03 Thread Jan Kiszka
Am 03.01.2011 17:40, Glauber Costa wrote:
> On Mon, 2011-01-03 at 09:33 +0100, Jan Kiszka wrote:
>> From: Jan Kiszka 
>>
>> Make sure to clear MSR_KVM_SYSTEM_TIME, MSR_KVM_WALL_CLOCK, and
>> MSR_KVM_ASYNC_PF_EN so that a freshly booted guest cannot be disturbed
>> by old values.
>>
>> Signed-off-by: Jan Kiszka 
>> CC: Glauber Costa 
>> ---
>>  target-i386/kvm.c |   10 ++
>>  1 files changed, 10 insertions(+), 0 deletions(-)
>>
>> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
>> index d8f26bf..664a4a0 100644
>> --- a/target-i386/kvm.c
>> +++ b/target-i386/kvm.c
>> @@ -453,6 +453,9 @@ void kvm_arch_reset_vcpu(CPUState *env)
>>  env->nmi_injected = 0;
>>  env->nmi_pending = 0;
>>  env->xcr0 = 1;
>> +env->system_time_msr = 0;
>> +env->wall_clock_msr = 0;
>> +env->async_pf_en_msr = 0;
> 
> Have you seen this happening? I'd expect CPUState to be zeroed out over
> init. And if it is not, I guess we should...

Ah, true, those three are part of the section that is zeroed. Will drop
that hunk on repost.

Guess we should rather move some other variables in that region too and
avoid clearing them manually like above...

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] Re: [PATCH v2 14/17] kvm: x86: Introduce kvmclock device to save/restore its state

2011-01-03 Thread Jan Kiszka
Am 03.01.2011 17:37, Glauber Costa wrote:
> On Mon, 2011-01-03 at 09:33 +0100, Jan Kiszka wrote:
>> From: Jan Kiszka 
>>
>> If kvmclock is used, which implies the kernel supports it, register a
>> kvmclock device with the sysbus. Its main purpose is to save and restore
>> the kernel state on migration, but this will also allow to visualize it
>> one day.
>>
>> Signed-off-by: Jan Kiszka 
>> CC: Glauber Costa 
> 
> Hi Jan.
> 
> I've just recently posted a patch (not sure what was made from it), that
> fixes a bug that you reintroduce here.

Hmm, must have missed it.

> 
> The bug is: if we call KVM_GET_CLOCK ioctl in pre_save, this means that
> this value will change every time we issue savevm, even if the machine
> is not run in between.
> 
> Ideally, we'd like to have two consecutive savevms returning the exact
> same thing in that situation.
> 
> I like the general approach of moving it to sysbus, but please move the
> ioctl to change state notifiers.

OK, will look into this.

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] Re: [PATCH v2 16/17] kvm: x86: Rework identity map and TSS setup for larger BIOS sizes

2011-01-03 Thread Jan Kiszka
Am 03.01.2011 17:06, Avi Kivity wrote:
> On 01/03/2011 10:33 AM, Jan Kiszka wrote:
>> From: Jan Kiszka
>>
>> First of all, we only need this EPT identity and TSS reservation on
>> Intel CPUs.
> 
> kvm-amd will ignore it just fine.  I'd like to keep arch differences
> away from userspace.

And I would prefer to avoid needlessly cluttering the physical guest
address space where not needed. Long term, we could even give user space
a hint (unless it can test it directly) that this workaround is no
longer needed as the host Intel CPU supports true real mode.

> 
>> Then, in order to support loading BIOSes>  256K, reorder the
>> code, adjusting the base if the kernel supports moving the identity map.
>> We can drop the check for KVM_CAP_SET_TSS_ADDR as we already depend on
>> much newer features.
> 
> There is no ordering on kvm features.  Each can come and go as it pleases.
> 

Well, at least this is not how kvm upstream works so far.

Jan



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] Re: [PATCH v2 16/17] kvm: x86: Rework identity map and TSS setup for larger BIOS sizes

2011-01-03 Thread Avi Kivity

On 01/03/2011 06:52 PM, Jan Kiszka wrote:

Am 03.01.2011 17:06, Avi Kivity wrote:
>  On 01/03/2011 10:33 AM, Jan Kiszka wrote:
>>  From: Jan Kiszka
>>
>>  First of all, we only need this EPT identity and TSS reservation on
>>  Intel CPUs.
>
>  kvm-amd will ignore it just fine.  I'd like to keep arch differences
>  away from userspace.

And I would prefer to avoid needlessly cluttering the physical guest
address space where not needed. Long term, we could even give user space
a hint (unless it can test it directly) that this workaround is no
longer needed as the host Intel CPU supports true real mode.


Having different physical address spaces based on the host cpu is bad, 
even disregarding live migration.  If there's a real need, we can do it 
as an option.  I don't see such a need though.


We can definitely add a new KVM_CAP for "tss/ept identity supported but 
not needed".  If emulate_invalid_guest_state is eventually fully 
implemented and becomes the default, it will even be true across the board.



>
>>  Then, in order to support loading BIOSes>   256K, reorder the
>>  code, adjusting the base if the kernel supports moving the identity map.
>>  We can drop the check for KVM_CAP_SET_TSS_ADDR as we already depend on
>>  much newer features.
>
>  There is no ordering on kvm features.  Each can come and go as it pleases.
>

Well, at least this is not how kvm upstream works so far.


Let's change it then.

--
error compiling committee.c: too many arguments to function




[Qemu-devel] [PATCH 0/2] ARM/softfloat: support flushing denormals on input

2011-01-03 Thread Peter Maydell
On ARM, the FPSCR FZ bit (which controls whether denormals should be
flushed to zero) is supposed to cause this flushing to occur both
when the output of a calculation is a denormal (already implemented in
softfloat) and also when the input to a calculation is a denormal
(not implemented, as noted by a FIXME comment).

This patchset adds the support to softfloat for flushing denormals on
input. This is controlled using a new status flag to enable it (so that
CPUs which only flush on output continue to work). There is a new
exception status bit to indicate when input flushing has happened
(because on ARM it is reported via a different FPSCR bit to that used
when an output denormal is flushed to zero).

I have deliberately only implemented this for input float32 and
float64 values because that is what ARM requires (on ARM float16
inputs must not be flushed to zero and floatx80 and float128 are
not used) so other changes would be totally untested code.

Existing CPUs should be unaffected as there is no behaviour change
unless the mode is enabled.

(I suspect that MIPS should be able to use this to implement the
FCSR FO bit if desired.)

Tested using random instruction generation for vadd/vsub/vmul/vdiv
with the FPSCR FZ bit set.

Peter Maydell (2):
  softfloat: Implement flushing input denormals to zero
  ARM: wire up the softfloat flush_input_to_zero flag

 fpu/softfloat.c |  104 ++-
 fpu/softfloat.h |   22 ++-
 target-arm/helper.c |   10 -
 3 files changed, 131 insertions(+), 5 deletions(-)




Re: [Qemu-devel] [PATCH 0/2] ARM: Fix VQSHL/VQSHLU immediate forms

2011-01-03 Thread Peter Maydell
On 3 January 2011 16:20, Peter Maydell  wrote:
> This patchset fixes errors in the decoding and implementation of the
> immediate forms of the VQSHL/VQSHLU ARM instructions.
> Tested in the usual random-instruction-set way. This is the final part
> of the maemo-qemu tree commit 03a2445a fixes (the first part being
> the already-committed VQSHL-reg patchset); the patch down as authored
> by me is a minor tweaking of changes in the maemo-qemu commit.
>
> Juha Riihimäki (1):
>  ARM: Fix decoding of VQSHL/VQSHLU immediate forms
>
> Peter Maydell (1):
>  ARM: add neon helpers for VQSHLU

Whoops, I changed the wrong patch when I was adjusting the
authors for this patchset -- the authors should be the other way
round. I'll fix this in a v2 but since it's not a code change I'll see
if there's any review commentary first.

-- PMM



[Qemu-devel] Re: [PATCH v2 17/17] kvm: Drop dependencies on very old capabilities

2011-01-03 Thread Avi Kivity

On 01/03/2011 06:54 PM, Jan Kiszka wrote:

Am 03.01.2011 17:08, Avi Kivity wrote:
>  On 01/03/2011 10:33 AM, Jan Kiszka wrote:
>>  From: Jan Kiszka
>>
>>  COALESCED_MMIO, SYNC_MMU, EXT_CPUID, CLOCKSOURCE, NOP_IO_DELAY, PV_MMU -
>>  all these caps predate features on which we already depend at build
>>  time. Moreover, the check for KVM_CAP_EXT_CPUID is unneeded as we
>>  already test&   fail is a more recent feature is missing.
>
>  No.  Each test documents a dependency of qemu on a kvm feature.  Even
>  though something like SYNC_MMU is unlikely to go away, as long as we
>  depend on it, we require the feature.
>

Then at least move all those KVM_CAPs we need at build time into
configure.


Need a run time check as well (build on new kernel, run on old kernel, 
or run on even newer kernel that lost a feature).



I really see no value in keeping ugly conditional code
around, A) because those paths won't be tested and B) none of the CAPs
touched here are to pass away without a replacement that will require
user space adaption anyway.


I'm fine with a series of checks during init time with no fallback.  I'm 
not fine with just dropping those away.  Reducing code size is great, 
but not at the cost of undiagnosed runtime failures.


--
error compiling committee.c: too many arguments to function




  1   2   >