[Qemu-devel] [PATCH] Fix page_check_range() wrap-around check when len=0.

2010-03-27 Thread takasi-y
Fix page_check_range() wrap-around check when len=0.

write(1,"",0) on linux-user emulation should be OK, but fails.
This is a regression brought by 376a7909.

This patch fixes it at the last of the calling path shown below,
  do_syscall:write -> access_ok() -> page_check_range(),
as linux-kernel does. For example, x86 does it at follows,
  sys_write() -> access_ok() -> __range_not_ok().
This implies calling page_check_range() with len=0 is valid.

Signed-off-by: Takashi YOSHII 
---
 exec.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/exec.c b/exec.c
index 14767b7..26cd8b9 100644
--- a/exec.c
+++ b/exec.c
@@ -2410,7 +2410,7 @@ int page_check_range(target_ulong start, target_ulong 
len, int flags)
 assert(start < ((abi_ulong)1 << L1_MAP_ADDR_SPACE_BITS));
 #endif
 
-if (start + len - 1 < start) {
+if (len > 0 && start + len -1 < start) {
 /* We've wrapped around.  */
 return -1;
 }
-- 
1.6.5





Re: [Qemu-devel] Significant performance regression in qemu-system-mips.

2010-03-27 Thread Rob Landley
On Saturday 27 March 2010 07:32:41 Aurelien Jarno wrote:
> On Fri, Mar 26, 2010 at 04:47:51PM -0500, Rob Landley wrote:
> > On Friday 26 March 2010 14:00:00 Aurelien Jarno wrote:
> > > I am pretty fine applying a correct patch if you send a new one.
> >
> > By which you mean rip out the whole #ifdef block?
>
> Yes.
>
> > Here you go:
>
> This looks much better. Can you please resend it with the changes below
> and a Signed-off-by: ?

If you want the code actually cleaned up instead of minimally changed,
here's a stab at that.  (Unfortunately I haven't got a ppc64 setup to test it
with yet, but ppc32 still works.)

Signed-off-by: Rob Landley 

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 682a813..3c3ef21 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -517,31 +517,12 @@ do {  
  \
 
 static inline void init_thread(struct target_pt_regs *_regs, struct image_info 
*infop)
 {
-abi_ulong pos = infop->start_stack;
-abi_ulong tmp;
-#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-abi_ulong entry, toc;
-#endif
-
 _regs->gpr[1] = infop->start_stack;
 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
-entry = ldq_raw(infop->entry) + infop->load_addr;
-toc = ldq_raw(infop->entry + 8) + infop->load_addr;
-_regs->gpr[2] = toc;
-infop->entry = entry;
+_regs->gpr[2] = ldq_raw(infop->entry + 8) + infop->load_addr;
+infop->entry = ldq_raw(infop->entry) + infop->load_addr;
 #endif
 _regs->nip = infop->entry;
-/* Note that isn't exactly what regular kernel does
- * but this is what the ABI wants and is needed to allow
- * execution of PPC BSD programs.
- */
-/* FIXME - what to for failure of get_user()? */
-get_user_ual(_regs->gpr[3], pos);
-pos += sizeof(abi_ulong);
-_regs->gpr[4] = pos;
-for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong))
-tmp = ldl(pos);
-_regs->gpr[5] = pos;
 }
 
 #define ELF_EXEC_PAGESIZE  4096

> > Ok, I agree I was a bit harsh.  (He's the one who introduced his employer
> > into the discussion, but I suspect I read more into that than he meant by
> > it.)
>
> I think you misunderstood him. You were talking about Super-Hitachi
> which is a train [1] from Hitachi (not his employer), while he was talking
> about Super-H which is a CPU [2] from Renesas (his employer).

So essentially he's insisting he works for Freescale, not Motorola, because
Motorola stopped being interested in the m68k and divested itself of its
processor manufacturing operations.  And I'm confusing his product with
something _else_ Motorola used to do.

Only transliterated to Japan.

*shrug*  The "SuperH" chipset was developed by Hitachi.  I thought the H stood
for "Hitachi".  I hadn't actually noticed that Hitachi had divested itself of
its chip design operations, and was trying to avoid referring to it as "sh4"
because that's an architecture generation, not a chip family.  (There used to
be sh3 and similar, and I thought there might be an sh5 someday but now that
I've looked into it I can understand why they don't seem too worried about
that happening.)

My project is trying to get all the architectures Linux and QEMU support to
behave the same way.  Thus I'm no more an sh4 expert than I am a ppc expert, I
just poke at it and look stuff up when it doesn't work (which is frequently).

Speaking of which, qemu-system-ppc in 0.12.3 segfaults accessing /dev/hdc, and
the one in current -git has the missed IRQ issue when accessing /dev/hda.  Is
there any chance of 0.12.4 in the near future?  (I hate to point people
interested in PPC at a random non-current git snapshot.)

> He has the right to not care about trains ;-)

It was more the "I can build it, I don't care if you still can" issue, when
the commit in question was a primarily cosmetic change to code that was only
theoretically broken.  (Not only did it work for me, but it was so broken
nobody actually noticed the issue in question for years.)

I got the impression that the reason he didn't care about my use case was
because I was not a customer of his company.  That he was acting on behalf
of his employer, not in an impartial purely technical capacity.  I have
no commercial interest in sh4, and never did, so I stopped bothering him.

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds




[Qemu-devel] [PATCH 6/7] Refactor CPUState handling out of vl.c

2010-03-27 Thread Blue Swirl
Signed-off-by: Blue Swirl 
---
 Makefile.target |2 +-
 cpus.c  |  773 +++
 cpus.h  |   18 ++
 vl.c|  749 +-
 4 files changed, 795 insertions(+), 747 deletions(-)
 create mode 100644 cpus.c
 create mode 100644 cpus.h

diff --git a/Makefile.target b/Makefile.target
index 16ea443..a89158a 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER
 # System emulator target
 ifdef CONFIG_SOFTMMU

-obj-y = vl.o monitor.o machine.o gdbstub.o
+obj-y = vl.o cpus.o monitor.o machine.o gdbstub.o
 obj-y += qemu-timer.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
diff --git a/cpus.c b/cpus.c
new file mode 100644
index 000..9a8c2f7
--- /dev/null
+++ b/cpus.c
@@ -0,0 +1,773 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * 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.
+ */
+
+/* Needed early for CONFIG_BSD etc. */
+#include "config-host.h"
+
+#include "monitor.h"
+#include "sysemu.h"
+#include "gdbstub.h"
+#include "dma.h"
+#include "kvm.h"
+
+#include "cpus.h"
+
+static CPUState *cur_cpu;
+static CPUState *next_cpu;
+
+/***/
+void hw_error(const char *fmt, ...)
+{
+va_list ap;
+CPUState *env;
+
+va_start(ap, fmt);
+fprintf(stderr, "qemu: hardware error: ");
+vfprintf(stderr, fmt, ap);
+fprintf(stderr, "\n");
+for(env = first_cpu; env != NULL; env = env->next_cpu) {
+fprintf(stderr, "CPU #%d:\n", env->cpu_index);
+#ifdef TARGET_I386
+cpu_dump_state(env, stderr, fprintf, X86_DUMP_FPU);
+#else
+cpu_dump_state(env, stderr, fprintf, 0);
+#endif
+}
+va_end(ap);
+abort();
+}
+
+void cpu_synchronize_all_states(void)
+{
+CPUState *cpu;
+
+for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
+cpu_synchronize_state(cpu);
+}
+}
+
+void cpu_synchronize_all_post_reset(void)
+{
+CPUState *cpu;
+
+for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
+cpu_synchronize_post_reset(cpu);
+}
+}
+
+void cpu_synchronize_all_post_init(void)
+{
+CPUState *cpu;
+
+for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
+cpu_synchronize_post_init(cpu);
+}
+}
+
+static void do_vm_stop(int reason)
+{
+if (vm_running) {
+cpu_disable_ticks();
+vm_running = 0;
+pause_all_vcpus();
+vm_state_notify(0, reason);
+monitor_protocol_event(QEVENT_STOP, NULL);
+}
+}
+
+static int cpu_can_run(CPUState *env)
+{
+if (env->stop)
+return 0;
+if (env->stopped)
+return 0;
+if (!vm_running)
+return 0;
+return 1;
+}
+
+static int cpu_has_work(CPUState *env)
+{
+if (env->stop)
+return 1;
+if (env->stopped)
+return 0;
+if (!env->halted)
+return 1;
+if (qemu_cpu_has_work(env))
+return 1;
+return 0;
+}
+
+static int tcg_has_work(void)
+{
+CPUState *env;
+
+for (env = first_cpu; env != NULL; env = env->next_cpu)
+if (cpu_has_work(env))
+return 1;
+return 0;
+}
+
+#ifndef _WIN32
+static int io_thread_fd = -1;
+
+static void qemu_event_increment(void)
+{
+/* Write 8 bytes to be compatible with eventfd.  */
+static uint64_t val = 1;
+ssize_t ret;
+
+if (io_thread_fd == -1)
+return;
+
+do {
+ret = write(io_thread_fd, &val, sizeof(val));
+} while (ret < 0 && errno == EINTR);
+
+/* EAGAIN is fine, a read must be pending.  */
+if (ret < 0 && errno != EAGAIN) {
+fprintf(stderr, "qemu_event_increment: write() filed: %s\n",
+strerror(errno));
+exit (1);
+}
+}
+
+static void qemu_event_read(void *opaque)
+{
+int fd = (unsigned long)opaque;
+ssize_t len;
+char buffer[512

[Qemu-devel] [PATCH 5/7] Refactor a few architecture dependent pieces in vl.c

2010-03-27 Thread Blue Swirl
These will be moved later.

Signed-off-by: Blue Swirl 
---
 vl.c |   72 +++--
 1 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/vl.c b/vl.c
index d9fc0cc..a1bb6e1 100644
--- a/vl.c
+++ b/vl.c
@@ -2945,6 +2945,22 @@ static void set_numa_modes(void)
 }
 }

+static void set_cpu_log(const char *optarg)
+{
+int mask;
+const CPULogItem *item;
+
+mask = cpu_str_to_log_mask(optarg);
+if (!mask) {
+printf("Log items (comma separated):\n");
+for (item = cpu_log_items; item->mask != 0; item++) {
+printf("%-10s %s\n", item->name, item->help);
+}
+exit(1);
+}
+cpu_set_log(mask);
+}
+
 static int vm_can_run(void)
 {
 if (powerdown_requested)
@@ -3308,6 +3324,33 @@ int qemu_uuid_parse(const char *str, uint8_t *uuid)
 return 0;
 }

+#ifdef TARGET_I386
+static void do_acpitable_option(const char *optarg)
+{
+if (acpi_table_add(optarg) < 0) {
+fprintf(stderr, "Wrong acpi table provided\n");
+exit(1);
+}
+}
+#endif
+
+#ifdef TARGET_I386
+static void do_smbios_option(const char *optarg)
+{
+if (smbios_entry_add(optarg) < 0) {
+fprintf(stderr, "Wrong smbios provided\n");
+exit(1);
+}
+}
+#endif
+
+static void cpudef_init(void)
+{
+#if defined(cpudef_setup)
+cpudef_setup(); /* parse cpu definitions in target config file */
+#endif
+}
+
 #ifndef _WIN32

 static void termsig_handler(int signal)
@@ -3856,9 +3899,7 @@ int main(int argc, char **argv, char **envp)
 fclose(fp);
 }
 }
-#if defined(cpudef_setup)
-cpudef_setup(); /* parse cpu definitions in target config file */
-#endif
+cpudef_init();

 /* second pass of option parsing */
 optind = 1;
@@ -4164,20 +4205,7 @@ int main(int argc, char **argv, char **envp)
 break;
 #endif
 case QEMU_OPTION_d:
-{
-int mask;
-const CPULogItem *item;
-
-mask = cpu_str_to_log_mask(optarg);
-if (!mask) {
-printf("Log items (comma separated):\n");
-for(item = cpu_log_items; item->mask != 0; item++) {
-printf("%-10s %s\n", item->name, item->help);
-}
-exit(1);
-}
-cpu_set_log(mask);
-}
+set_cpu_log(optarg);
 break;
 case QEMU_OPTION_s:
 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
@@ -4345,16 +4373,10 @@ int main(int argc, char **argv, char **envp)
 rtc_td_hack = 1;
 break;
 case QEMU_OPTION_acpitable:
-if(acpi_table_add(optarg) < 0) {
-fprintf(stderr, "Wrong acpi table provided\n");
-exit(1);
-}
+do_acpitable_option(optarg);
 break;
 case QEMU_OPTION_smbios:
-if(smbios_entry_add(optarg) < 0) {
-fprintf(stderr, "Wrong smbios provided\n");
-exit(1);
-}
+do_smbios_option(optarg);
 break;
 #endif
 #ifdef CONFIG_KVM
-- 
1.6.2.4




[Qemu-devel] [PATCH 4/7] Move KVM and Xen global flags to vl.c

2010-03-27 Thread Blue Swirl
Signed-off-by: Blue Swirl 
---
 hw/xen_machine_pv.c |3 ---
 kvm-all.c   |2 --
 vl.c|4 
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/xen_machine_pv.c b/hw/xen_machine_pv.c
index 162f88d..586214d 100644
--- a/hw/xen_machine_pv.c
+++ b/hw/xen_machine_pv.c
@@ -29,9 +29,6 @@
 #include "xen_backend.h"
 #include "xen_domainbuild.h"

-uint32_t xen_domid;
-enum xen_mode xen_mode = XEN_EMULATE;
-
 static void xen_init_pv(ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename,
diff --git a/kvm-all.c b/kvm-all.c
index 534ead0..40b5a51 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -51,8 +51,6 @@ typedef struct KVMSlot

 typedef struct kvm_dirty_log KVMDirtyLog;

-int kvm_allowed = 0;
-
 struct KVMState
 {
 KVMSlot slots[32];
diff --git a/vl.c b/vl.c
index a2869b8..d9fc0cc 100644
--- a/vl.c
+++ b/vl.c
@@ -258,6 +258,10 @@ uint8_t qemu_uuid[16];
 static QEMUBootSetHandler *boot_set_handler;
 static void *boot_set_opaque;

+int kvm_allowed = 0;
+uint32_t xen_domid;
+enum xen_mode xen_mode = XEN_EMULATE;
+
 #ifdef SIGRTMIN
 #define SIG_IPI (SIGRTMIN+4)
 #else
-- 
1.6.2.4




[Qemu-devel] [PATCH 3/7] Move cpu_exec_init_all() declaration to qemu-common.h

2010-03-27 Thread Blue Swirl
Let cpu_exec_init_all() be called from non-CPU code.

Signed-off-by: Blue Swirl 
---
 cpu-all.h |1 -
 qemu-common.h |2 ++
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index f281a91..9942d49 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -756,7 +756,6 @@ void page_set_flags(target_ulong start,
target_ulong end, int flags);
 int page_check_range(target_ulong start, target_ulong len, int flags);
 #endif

-void cpu_exec_init_all(unsigned long tb_size);
 CPUState *cpu_copy(CPUState *env);
 CPUState *qemu_get_cpu(int cpu);

diff --git a/qemu-common.h b/qemu-common.h
index 087c034..d881a39 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -231,6 +231,8 @@ typedef struct SSIBus SSIBus;

 typedef uint64_t pcibus_t;

+void cpu_exec_init_all(unsigned long tb_size);
+
 /* CPU save/load.  */
 void cpu_save(QEMUFile *f, void *opaque);
 int cpu_load(QEMUFile *f, void *opaque, int version_id);
-- 
1.6.2.4




[Qemu-devel] [PATCH 2/7] Allow various header files to be included from non-CPU code

2010-03-27 Thread Blue Swirl
Allow balloon.h, gdbstub.h and kvm.h to be included from
non-CPU code.

Signed-off-by: Blue Swirl 
---
 balloon.h |2 --
 gdbstub.h |   12 +---
 kvm.h |7 ---
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/balloon.h b/balloon.h
index c3a1ad3..8c019eb 100644
--- a/balloon.h
+++ b/balloon.h
@@ -14,8 +14,6 @@
 #ifndef _QEMU_BALLOON_H
 #define _QEMU_BALLOON_H

-#include "cpu-defs.h"
-
 typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target,
 MonitorCompletion cb, void *cb_data);

diff --git a/gdbstub.h b/gdbstub.h
index 5740041..54d753c 100644
--- a/gdbstub.h
+++ b/gdbstub.h
@@ -10,6 +10,7 @@
 #define GDB_WATCHPOINT_READ  3
 #define GDB_WATCHPOINT_ACCESS4

+#ifdef NEED_CPU_H
 typedef void (*gdb_syscall_complete_cb)(CPUState *env,
 target_ulong ret, target_ulong err);

@@ -21,10 +22,7 @@ int gdb_queuesig (void);
 int gdb_handlesig (CPUState *, int);
 void gdb_exit(CPUState *, int);
 void gdb_signalled(CPUState *, int);
-int gdbserver_start(int);
 void gdbserver_fork(CPUState *);
-#else
-int gdbserver_start(const char *port);
 #endif
 /* Get or set a register.  Returns the size of the register.  */
 typedef int (*gdb_reg_cb)(CPUState *env, uint8_t *buf, int reg);
@@ -33,3 +31,11 @@ void gdb_register_coprocessor(CPUState *env,
   int num_regs, const char *xml, int g_pos);

 #endif
+
+#ifdef CONFIG_USER_ONLY
+int gdbserver_start(int);
+#else
+int gdbserver_start(const char *port);
+#endif
+
+#endif
diff --git a/kvm.h b/kvm.h
index fd8d0c1..4f77188 100644
--- a/kvm.h
+++ b/kvm.h
@@ -14,12 +14,12 @@
 #ifndef QEMU_KVM_H
 #define QEMU_KVM_H

-#include "config.h"
+#include "config-host.h"
 #include "qemu-queue.h"

-#ifdef CONFIG_KVM
 extern int kvm_allowed;

+#ifdef CONFIG_KVM
 #define kvm_enabled() (kvm_allowed)
 #else
 #define kvm_enabled() (0)
@@ -31,6 +31,7 @@ struct kvm_run;

 int kvm_init(int smp_cpus);

+#ifdef NEED_CPU_H
 int kvm_init_vcpu(CPUState *env);

 int kvm_cpu_exec(CPUState *env);
@@ -160,5 +161,5 @@ static inline void cpu_synchronize_post_init(CPUState *env)
 kvm_cpu_synchronize_post_init(env);
 }
 }
-
+#endif
 #endif
-- 
1.6.2.4




[Qemu-devel] [PATCH 0/7] Compile vl.c only once

2010-03-27 Thread Blue Swirl
With this set of patches against HEAD, I'm finally able to compile vl.c
only once.

Comments? Objections?

The patches can be found in:
git://repo.or.cz/qemu/blueswirl.git
http://repo.or.cz/r/qemu/blueswirl.git

Blue Swirl (7):
  Adjust debug handling
  Allow various header files to be included from non-CPU code
  Move cpu_exec_init_all() declaration to qemu-common.h
  Move KVM and Xen global flags to vl.c
  Refactor a few architecture dependent pieces in vl.c
  Refactor CPUState handling out of vl.c
  Refactor target specific handling, compile vl.c only once

 Makefile.objs   |   12 +-
 Makefile.target |   13 +-
 arch_init.c |  509 +
 arch_init.h |   33 ++
 balloon.h   |2 -
 cpu-all.h   |1 -
 cpus.c  |  773 
 cpus.h  |   18 +
 gdbstub.h   |   12 +-
 hw/xen_machine_pv.c |3 -
 kvm-all.c   |2 -
 kvm.h   |7 +-
 qemu-common.h   |2 +
 qemu-options.hx |  309 +++---
 sysemu.h|4 -
 vl.c| 1219 +++
 16 files changed, 1570 insertions(+), 1349 deletions(-)
 create mode 100644 arch_init.c
 create mode 100644 arch_init.h
 create mode 100644 cpus.c
 create mode 100644 cpus.h




[Qemu-devel] [PATCH 1/7] Adjust debug handling

2010-03-27 Thread Blue Swirl
Signed-off-by: Blue Swirl 
---
 vl.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/vl.c b/vl.c
index 8a73235..a2869b8 100644
--- a/vl.c
+++ b/vl.c
@@ -2920,7 +2920,7 @@ static bool tcg_cpu_exec(void)

 if (ret == EXCP_DEBUG) {
 gdb_set_stop_cpu(env);
-debug_requested = 1;
+debug_requested = EXCP_DEBUG;
 break;
 }
 }
@@ -2983,8 +2983,8 @@ static void main_loop(void)
 #endif
 } while (vm_can_run());

-if (qemu_debug_requested()) {
-vm_stop(EXCP_DEBUG);
+if ((r = qemu_debug_requested())) {
+vm_stop(r);
 }
 if (qemu_shutdown_requested()) {
 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
-- 
1.6.2.4




Re: [Qemu-devel] [PATCH 2/2] Added monitor commands: 'keyboard_set' and 'info keybaord'

2010-03-27 Thread Shahar Havivi
Fix to Markus comments. 

---
 console.h   |6 +++
 input.c |  119 ++
 monitor.c   |8 
 qemu-monitor.hx |   17 
 4 files changed, 141 insertions(+), 9 deletions(-)

diff --git a/console.h b/console.h
index 7d19407..c2af79c 100644
--- a/console.h
+++ b/console.h
@@ -45,6 +45,8 @@ typedef struct QEMUPutKbdEntry {
 char *qemu_put_kbd_name;
 QEMUPutKBDEvent *qemu_put_kbd_event;
 void *qemu_put_kbd_event_opaque;
+int index;
+
 QTAILQ_ENTRY(QEMUPutKbdEntry) entry;
 } QEMUPutKbdEntry;
 
@@ -85,6 +87,10 @@ void do_info_mice_print(Monitor *mon, const QObject *data);
 void do_info_mice(Monitor *mon, QObject **ret_data);
 void do_mouse_set(Monitor *mon, const QDict *qdict);
 
+void do_info_keyboard_print(Monitor *mon, const QObject *data);
+void do_info_keyboard(Monitor *mon, QObject **ret_data);
+int do_keyboard_set(Monitor *mon, const QDict *qdict, QObject **ret_data);
+
 /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
constants) */
 #define QEMU_KEY_ESC1(c) ((c) | 0xe100)
diff --git a/input.c b/input.c
index c27a600..2af6e9d 100644
--- a/input.c
+++ b/input.c
@@ -30,7 +30,6 @@
 
 static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers =
 QTAILQ_HEAD_INITIALIZER(kbd_handlers);
-static QEMUPutKbdEntry *kbd_current;
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = 
QTAILQ_HEAD_INITIALIZER(led_handlers);
 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
 QTAILQ_HEAD_INITIALIZER(mouse_handlers);
@@ -59,12 +58,12 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 void *opaque,
 const char *name)
 {
+static int mouse_index = 0;
 QEMUPutKbdEntry *s, *cursor;
 
 QTAILQ_FOREACH(cursor, &kbd_handlers, entry) {
 if (cursor->qemu_put_kbd_event == func &&
 cursor->qemu_put_kbd_event_opaque == opaque) {
-kbd_current = cursor;
 return cursor;
 }
 }
@@ -74,9 +73,9 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 s->qemu_put_kbd_event_opaque = opaque;
 s->qemu_put_kbd_event = func;
 s->qemu_put_kbd_name = qemu_strdup(name);
+s->index = mouse_index++;
 
 QTAILQ_INSERT_TAIL(&kbd_handlers, s, entry);
-kbd_current = s;
 
 return s;
 }
@@ -84,9 +83,6 @@ QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent 
*func,
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
 {
 QTAILQ_REMOVE(&kbd_handlers, entry, entry);
-if (kbd_current == entry) {
-kbd_current = QTAILQ_FIRST(&kbd_handlers);
-}
 qemu_free(entry);
 }
 
@@ -153,10 +149,14 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode)
 {
-if (kbd_current) {
-kbd_current->qemu_put_kbd_event(
-kbd_current->qemu_put_kbd_event_opaque, keycode);
+QEMUPutKbdEntry *entry;
+
+if (QTAILQ_EMPTY(&kbd_handlers)) {
+return;
 }
+
+entry = QTAILQ_FIRST(&kbd_handlers);
+entry->qemu_put_kbd_event(entry->qemu_put_kbd_event_opaque, keycode);
 }
 
 void kbd_put_ledstate(int ledstate)
@@ -329,3 +329,104 @@ void qemu_remove_mouse_mode_change_notifier(Notifier 
*notify)
 {
 notifier_list_remove(&mouse_mode_notifiers, notify);
 }
+
+static void info_keyboard_iter(QObject *data, void *opaque)
+{
+QDict *kbd;
+Monitor *mon = opaque;
+
+kbd = qobject_to_qdict(data);
+monitor_printf(mon, "%c Keyboard #%" PRId64 ": %s\n",
+  (qdict_get_bool(kbd, "current") ? '*' : ' '),
+  qdict_get_int(kbd, "index"), qdict_get_str(kbd, "name"));
+}
+
+void do_info_keyboard_print(Monitor *mon, const QObject *data)
+{
+QList *kbd_list;
+
+kbd_list = qobject_to_qlist(data);
+if (qlist_empty(kbd_list)) {
+monitor_printf(mon, "No keyboard devices connected\n");
+return;
+}
+
+qlist_iter(kbd_list, info_keyboard_iter, mon);
+}
+
+/*
+ * do_info_keyboard(): Show VM keyboard information
+ *
+ * Each keyboard is represented by a QDict, the returned QObject is
+ * a QList of all keyboards.
+ *
+ * The keyboard QDict contains the following:
+ *
+ * - "name": keyboard's name
+ * - "index": keyboard's index
+ * - "current": true if this keyboard is receiving events, false otherwise
+ *
+ * Example:
+ *
+ * [ { "name": "QEMU USB Keyboard", "index": 0, "current": false },
+ *   { "name": "QEMU PS/2 Keyboard", "index": 1, "current": true } ]
+ */
+void do_info_keyboard(Monitor *mon, QObject **ret_data)
+{
+QEMUPutKbdEntry *cursor;
+QList *kbd_list;
+int current;
+
+kbd_list = qlist_new();
+
+if (QTAILQ_EMPTY(&kbd_handlers)) {
+goto out;
+}
+
+current = QTAILQ_FIRST(&kbd_handlers)->index;
+QTAILQ_FOREACH(cursor, &kbd_handlers, entry) {
+QObject *obj;
+obj = qobject_from_jsonf("{ 'name': %s,"
+   

[Qemu-devel] Re: [PATCH v3 1/1] Shared memory uio_pci driver

2010-03-27 Thread Avi Kivity

On 03/26/2010 07:14 PM, Cam Macdonell wrote:



I'm not familiar with the uio internals, but for the interface, an ioctl()
on the fd to assign an eventfd to an MSI vector.  Similar to ioeventfd, but
instead of mapping a doorbell to an eventfd, it maps a real MSI to an
eventfd.
 

uio will never support ioctls.


Why not?


Maybe irqcontrol could be extended?
   


What's irqcontrol?

--
Do not meddle in the internals of kernels, for they are subtle and quick to 
panic.





[Qemu-devel] my email

2010-03-27 Thread Pushparaj Motamari
pushpara...@gmail.com


Re: [Qemu-devel] [PATCH 1/2] Support for multiple keyboard devices

2010-03-27 Thread Shahar Havivi
On Fri, Mar 26, 2010 at 10:46:14AM +0100, Markus Armbruster wrote:
> > +QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
> > +void *opaque,
> > +const char *name)
> > +{
> > +QEMUPutKbdEntry *s, *cursor;
> > +
> > +cursor = qemu_put_kbd_event_head;
> > +while (cursor) {
> > +if (cursor->qemu_put_kbd_event == func &&
> > +cursor->qemu_put_kbd_event_opaque == opaque) {
> > +
> > +qemu_put_kbd_event_current = cursor;
> > +return cursor;
> > +}
> > +cursor = cursor->next;
> > +}
> 
> You're chasing list pointers.  Why not use a suitable list type from
> qemu-queue.h?
> 
Change keyboard list to qemu tail queue.

---
 console.h|   12 ++-
 hw/adb.c |2 +-
 hw/escc.c|3 +-
 hw/musicpal.c|2 +-
 hw/nseries.c |4 +-
 hw/palm.c|2 +-
 hw/ps2.c |2 +-
 hw/pxa2xx_keypad.c   |2 +-
 hw/spitz.c   |2 +-
 hw/stellaris_input.c |2 +-
 hw/syborg_keyboard.c |2 +-
 hw/usb-hid.c |   10 ++--
 hw/xenfb.c   |4 +-
 input.c  |   51 -
 14 files changed, 73 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 6def115..7d19407 100644
--- a/console.h
+++ b/console.h
@@ -41,7 +41,17 @@ typedef struct QEMUPutLEDEntry {
 QTAILQ_ENTRY(QEMUPutLEDEntry) next;
 } QEMUPutLEDEntry;
 
-void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque);
+typedef struct QEMUPutKbdEntry {
+char *qemu_put_kbd_name;
+QEMUPutKBDEvent *qemu_put_kbd_event;
+void *qemu_put_kbd_event_opaque;
+QTAILQ_ENTRY(QEMUPutKbdEntry) entry;
+} QEMUPutKbdEntry;
+
+QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func,
+void *opaque,
+const char *name);
+void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry);
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 void *opaque, int absolute,
 const char *name);
diff --git a/hw/adb.c b/hw/adb.c
index 4fb7a62..09afcf9 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -304,7 +304,7 @@ void adb_kbd_init(ADBBusState *bus)
 s = qemu_mallocz(sizeof(KBDState));
 d = adb_register_device(bus, ADB_KEYBOARD, adb_kbd_request,
 adb_kbd_reset, s);
-qemu_add_kbd_event_handler(adb_kbd_put_keycode, d);
+qemu_add_kbd_event_handler(adb_kbd_put_keycode, d, "adb");
 register_savevm("adb_kbd", -1, 1, adb_kbd_save,
 adb_kbd_load, s);
 }
diff --git a/hw/escc.c b/hw/escc.c
index 6d2fd36..2b21d98 100644
--- a/hw/escc.c
+++ b/hw/escc.c
@@ -919,7 +919,8 @@ static int escc_init1(SysBusDevice *dev)
  "QEMU Sun Mouse");
 }
 if (s->chn[1].type == kbd) {
-qemu_add_kbd_event_handler(sunkbd_event, &s->chn[1]);
+qemu_add_kbd_event_handler(sunkbd_event, &s->chn[1],
+   "QEMU Sun Keyboard");
 }
 
 return 0;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 7fc9fb3..aca8a88 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -1447,7 +1447,7 @@ static int musicpal_key_init(SysBusDevice *dev)
 
 qdev_init_gpio_out(&dev->qdev, s->out, ARRAY_SIZE(s->out));
 
-qemu_add_kbd_event_handler(musicpal_key_event, s);
+qemu_add_kbd_event_handler(musicpal_key_event, s, "Musicpal");
 
 return 0;
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 0273eee..abfcec3 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -262,7 +262,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)
 if (n800_keys[i] >= 0)
 s->keymap[n800_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n800_key_event, s);
+qemu_add_kbd_event_handler(n800_key_event, s, "Nokia n800");
 
 tsc210x_set_transform(s->ts.chip, &n800_pointercal);
 }
@@ -371,7 +371,7 @@ static void n810_kbd_setup(struct n800_s *s)
 if (n810_keys[i] > 0)
 s->keymap[n810_keys[i]] = i;
 
-qemu_add_kbd_event_handler(n810_key_event, s);
+qemu_add_kbd_event_handler(n810_key_event, s, "Nokia n810");
 
 /* Attach the LM8322 keyboard to the I2C bus,
  * should happen in n8x0_i2c_setup and s->kbd be initialised here.  */
diff --git a/hw/palm.c b/hw/palm.c
index 6d19167..1b405d4 100644
--- a/hw/palm.c
+++ b/hw/palm.c
@@ -228,7 +228,7 @@ static void palmte_init(ram_addr_t ram_size,
 
 palmte_microwire_setup(cpu);
 
-qemu_add_kbd_event_handler(palmte_button_event, cpu);
+qemu_add_kbd_event_handler(palmte_button_event, cpu, "Palm Keyboard");
 
 palmte_gpio_setup(cpu);
 
diff --git a/hw/ps2.c b/hw/ps2.c
index f0b206a..886da37 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -596,7 +

Re: [Qemu-devel] [PATCH v2 0/6] error: Clean up after recent changes

2010-03-27 Thread Aurelien Jarno
On Mon, Mar 22, 2010 at 10:28:59AM +0100, Markus Armbruster wrote:
> Cleaner integration of location tracking with qemu-tool.c.  Move
> qerror_report() where it belongs.
> 
> v2: Remove an assertion that unreachable code can't be reached, at
> Blue Swirl's request.  Rebased.
> 
> Markus Armbruster (6):
>   error: Trim includes after "Move qemu_error & friends..."
>   error: Trim includes in qerror.c
>   error: Trim includes after "Infrastructure to track locations..."
>   error: Make use of error_set_progname() optional
>   error: Link qemu-img, qemu-nbd, qemu-io with qemu-error.o
>   error: Move qerror_report() from qemu-error.[ch] to qerror.[ch]

Thanks, applied.

>  Makefile |6 +++---
>  hw/qdev-properties.c |1 +
>  monitor.c|2 --
>  monitor.h|1 -
>  qemu-error.c |   20 +---
>  qemu-error.h |6 --
>  qemu-tool.c  |   49 +++--
>  qerror.c |   22 --
>  qerror.h |5 +
>  sysemu.h |2 --
>  10 files changed, 45 insertions(+), 69 deletions(-)
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] Add a missing #include for FreeBSD hosts

2010-03-27 Thread Aurelien Jarno
On Thu, Mar 25, 2010 at 10:35:03PM +0100, Juergen Lock wrote:
> Signed-off-by: Juergen Lock 

Thanks applied.

> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -35,6 +35,9 @@
>  #include 
>  #include 
>  #include 
> +#ifdef __FreeBSD__
> +#include 
> +#endif
>  
>  #ifdef __linux__
>  #include 
> 
> 
> 

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





Re: [Qemu-devel] [trivial one-liner] be more specific in -mem-path error messages

2010-03-27 Thread Michael Tokarev
Aurelien Jarno wrote:
> On Tue, Mar 16, 2010 at 11:01:46AM +0300, Michael Tokarev wrote:
>> The error message qemu gives when hugetlbfs is not
>> accessible is cryptic at best:
>>
>>   mkstemp: Permission denied
>>
>> Make it a bit more specific instead:
>>
>>  unable to create backing store for hugepages: Permission denied
>>
>> Thanks!
> 
> It looks good, but needs a Signed-off-by: line.

Are we now requiring such S-o-b lines even for such trivial stuff?
Oh well.  Ok, here we go, with another perror() case converted
to be a bit less cryptic.  Thanks!

Signed-Off-By: Michael Tokarev 

diff --git a/exec.c b/exec.c
index fcffb0f..90032a5 100644
--- a/exec.c
+++ b/exec.c
@@ -2438,7 +2438,7 @@ static long gethugepagesize(const char *path)
 } while (ret != 0 && errno == EINTR);

 if (ret != 0) {
-   perror("statfs");
+   perror(path);
return 0;
 }

@@ -2483,7 +2483,7 @@ static void *file_ram_alloc(ram_addr_t memory, const char 
*path)

 fd = mkstemp(filename);
 if (fd < 0) {
-   perror("mkstemp");
+   perror("unable to create backing store for hugepages");
free(filename);
return NULL;
 }






Re: [Qemu-devel] [PATCH 12/48] cocoa frontend changes

2010-03-27 Thread Andreas Färber
Hello,

Am 26.03.2010 um 17:06 schrieb Riku Voipio:

> From: Juha Riihimäki 
> 
> remove help menu, fix fullscreen mode mouse handling, add confirmation
> dialog to quit menu command, add support for undocumented alt-grab and
> ctrl-grab options, add qemu version printout in about panel.
> - fix build on os x versions prior to 10.6
> - cocoa window handling fixes
> - show shutting down status in window caption
> - add display close handler support
> - add support for multitouch in cocoa frontend
> - cocoa keymap changes

I would appreciate if you could untangle these for review by splitting this 
patch up.
Last time I built on 10.5/ppc there were no build issues in Cocoa, for instance.

Further comment inline.

> 
> Signed-Off-By: Riku Voipio 
> Signed-off-by: Juha Riihimäki 
> ---
> cocoa.m |  313 +++---
> 1 files changed, 217 insertions(+), 96 deletions(-)
> 
> diff --git a/cocoa.m b/cocoa.m
> index 56c789a..524617f 100644
> --- a/cocoa.m
> +++ b/cocoa.m
> @@ -47,10 +47,25 @@
> #define cgrect(nsrect) (*(CGRect *)&(nsrect))
> #define COCOA_MOUSE_EVENT \

Since this macro is growing large, could you consider turning it into a static 
inline function please?

Regards,
Andreas

> if (isTabletEnabled) { \
> -kbd_mouse_event((int)(p.x * 0x7FFF / (screen.width - 1)), 
> (int)((screen.height - p.y) * 0x7FFF / (screen.height - 1)), 0, buttons); \
> +if (isFullscreen) { \
> +NSSize fs = [[NSScreen mainScreen] frame].size; \
> +kbd_mouse_event((int)(p.x * 0x7FFF / (fs.width - 1)), \
> +(int)((fs.height - p.y) * 0x7FFF / 
> (fs.height - 1)), \
> +0, buttons); \
> +} else { \
> +kbd_mouse_event((int)(p.x * 0x7FFF / (screen.width - 1)), \
> +(int)((screen.height - p.y) * 0x7FFF / 
> (screen.height - 1)), \
> +0, buttons); \
> +} \
> } else if (isMouseGrabed) { \
> kbd_mouse_event((int)[event deltaX], (int)[event deltaY], 0, 
> buttons); \
> } else { \
> +if (isFullscreen) { \
> +NSSize fs = [[NSScreen mainScreen] frame].size; \
> +kbd_mouse_event((int)(p.x * 0x7FFF / (fs.width - 1)), \
> +(int)((fs.height - p.y) * 0x7FFF / 
> (fs.height - 1)), \
> +0, buttons); \
> +} \
> [NSApp sendEvent:event]; \
> }
> 
> @@ -65,6 +80,7 @@ int qemu_main(int argc, char **argv); // main defined in 
> qemu/vl.c
> NSWindow *normalWindow;
> id cocoaView;
> static DisplayChangeListener *dcl;
> +static int last_vm_running;
> 
> int gArgc;
> char **gArgv;
> @@ -83,7 +99,7 @@ int keymap[] =
> 45, //  7   0x070x2dX   QZ_x
> 46, //  8   0x080x2eC   QZ_c
> 47, //  9   0x090x2fV   QZ_v
> -0,  //  10  0x0AUndefined
> +0,  //  10  0x0AUndefined   (paragraph)
> 48, //  11  0x0B0x30B   QZ_b
> 16, //  12  0x0C0x10Q   QZ_q
> 17, //  13  0x0D0x11W   QZ_w
> @@ -127,8 +143,8 @@ int keymap[] =
> 14, //  51  0x330x0eBKSPQZ_BACKSPACE
> 0,  //  52  0x34Undefined
> 1,  //  53  0x350x01ESC QZ_ESCAPE
> -0,  //  54  0x36QZ_RMETA
> -0,  //  55  0x37QZ_LMETA
> +220,//  54  0xdce0,5c   R GUI   QZ_RMETA
> +219,//  55  0xdbe0,5b   L GUI   QZ_LMETA
> 42, //  56  0x380x2aL SHFT  QZ_LSHIFT
> 58, //  57  0x390x3aCAPSQZ_CAPSLOCK
> 56, //  58  0x3A0x38L ALT   QZ_LALT
> @@ -136,9 +152,9 @@ int keymap[] =
> 54, //  60  0x3C0x36R SHFT  QZ_RSHIFT
> 184,//  61  0x3D0xb8E0,38   R ALT   QZ_RALT
> 157,//  62  0x3E0x9dE0,1D   R CTRL  QZ_RCTRL
> -0,  //  63  0x3FUndefined
> -0,  //  64  0x40Undefined
> -0,  //  65  0x41Undefined
> +0,  //  63  0x3FUndefined   (fn)
> +0,  //  64  0x40Undefined   (f17)
> +83, //  65  0x530x53KP .
> 0,  //  66  0x42Undefined
> 55, //  67  0x430x37KP *QZ_KP_MULTIPLY
> 0,  //  68  0x44Undefined
> @@ -152,9 +168,9 @@ int keymap[] =
> 152,//  76  0x4C0x9cE0,1C   KP EN   QZ_KP_ENTER
> 0,  //  77  0x4Dundefined
> 74, //  78  0x4E0x4aKP -QZ_KP_MINUS
> -0,  //  79  0x4FUndefined
> -0,  //  80  0x50Undefined
> -0,  //  81  0x51QZ_KP_EQUALS
> +0,  //  79

Re: [Qemu-devel] [PATCH] linux-user: Use RLIMIT_STACK for default stack size.

2010-03-27 Thread Aurelien Jarno
On Fri, Mar 19, 2010 at 02:21:13PM -0700, Richard Henderson wrote:
> The current default stack limit of 512kB is far too small; a fair
> number of gcc testsuite failures (for all guests) are directly
> attributable to this.  Using the -s option in every invocation of
> the emulator is annoying to say the least.
> 
> A reasonable compromise seems to be to honor the system rlimit.
> At least on two Linux distributions, this is set to 8MB and 10MB
> respectively.  If the system does not limit the stack, then we're
> no worse off than before.
> 
> At the same time, rename the variable from x86_stack_size and
> change the ultimate fallback size from 512kB to 8MB.

Thanks, applied.

> Signed-off-by: Richard Henderson 
> ---
>  linux-user/elfload.c |2 +-
>  linux-user/main.c|   23 +--
>  linux-user/qemu.h|2 +-
>  3 files changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 91eea62..b721b10 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -1004,7 +1004,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct 
> linux_binprm *bprm,
>  /* Create enough stack to hold everything.  If we don't use
>   * it for args, we'll use it for something else...
>   */
> -size = x86_stack_size;
> +size = guest_stack_size;
>  if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
>  size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
>  error = target_mmap(0,
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 4614e3c..e5ff8a9 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -24,6 +24,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include "qemu.h"
>  #include "qemu-common.h"
> @@ -51,7 +52,7 @@ const char *qemu_uname_release = CONFIG_UNAME_RELEASE;
>  /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
> we allocate a bigger stack. Need a better solution, for example
> by remapping the process stack directly at the right place */
> -unsigned long x86_stack_size = 512 * 1024;
> +unsigned long guest_stack_size = 8 * 1024 * 1024UL;
>  
>  void gemu_log(const char *fmt, ...)
>  {
> @@ -2560,7 +2561,7 @@ static void usage(void)
> ,
> TARGET_ARCH,
> interp_prefix,
> -   x86_stack_size,
> +   guest_stack_size,
> DEBUG_LOGFILE);
>  exit(1);
>  }
> @@ -2639,6 +2640,16 @@ int main(int argc, char **argv, char **envp)
>  (void) envlist_setenv(envlist, *wrk);
>  }
>  
> +/* Read the stack limit from the kernel.  If it's "unlimited",
> +   then we can do little else besides use the default.  */
> +{
> +struct rlimit lim;
> +if (getrlimit(RLIMIT_STACK, &lim) == 0
> +&& lim.rlim_cur != RLIM_INFINITY) {
> +guest_stack_size = lim.rlim_cur;
> +}
> +}
> +
>  cpu_model = NULL;
>  #if defined(cpudef_setup)
>  cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
> @@ -2687,13 +2698,13 @@ int main(int argc, char **argv, char **envp)
>  if (optind >= argc)
>  break;
>  r = argv[optind++];
> -x86_stack_size = strtol(r, (char **)&r, 0);
> -if (x86_stack_size <= 0)
> +guest_stack_size = strtoul(r, (char **)&r, 0);
> +if (guest_stack_size == 0)
>  usage();
>  if (*r == 'M')
> -x86_stack_size *= 1024 * 1024;
> +guest_stack_size *= 1024 * 1024;
>  else if (*r == 'k' || *r == 'K')
> -x86_stack_size *= 1024;
> +guest_stack_size *= 1024;
>  } else if (!strcmp(r, "L")) {
>  interp_prefix = argv[optind++];
>  } else if (!strcmp(r, "p")) {
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index 6ab9517..47fc686 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -246,7 +246,7 @@ void mmap_fork_end(int child);
>  #endif
>  
>  /* main.c */
> -extern unsigned long x86_stack_size;
> +extern unsigned long guest_stack_size;
>  
>  /* user access */
>  
> -- 
> 1.6.6.1
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] target-arm: disable PAGE_EXEC for XN pages

2010-03-27 Thread Aurelien Jarno
On Sat, Mar 20, 2010 at 02:28:03AM +0530, Rabin Vincent wrote:
> Don't set PAGE_EXEC for XN pages, to avoid a bypass of XN protection
> checking if the page is already in the TLB.

Thanks, applied.

> Signed-off-by: Rabin Vincent 
> ---
>  target-arm/helper.c |   10 +++---
>  1 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/target-arm/helper.c b/target-arm/helper.c
> index 18e22b1..e092b21 100644
> --- a/target-arm/helper.c
> +++ b/target-arm/helper.c
> @@ -979,6 +979,7 @@ static int get_phys_addr_v5(CPUState *env, uint32_t 
> address, int access_type,
>  /* Access permission fault.  */
>  goto do_fault;
>  }
> +*prot |= PAGE_EXEC;
>  *phys_ptr = phys_addr;
>  return 0;
>  do_fault:
> @@ -1075,6 +1076,9 @@ static int get_phys_addr_v6(CPUState *env, uint32_t 
> address, int access_type,
>  /* Access permission fault.  */
>  goto do_fault;
>  }
> +if (!xn) {
> +*prot |= PAGE_EXEC;
> +}
>  *phys_ptr = phys_addr;
>  return 0;
>  do_fault:
> @@ -1137,6 +1141,7 @@ static int get_phys_addr_mpu(CPUState *env, uint32_t 
> address, int access_type,
>   /* Bad permission.  */
>   return 1;
>  }
> +*prot |= PAGE_EXEC;
>  return 0;
>  }
>  
> @@ -1152,7 +1157,7 @@ static inline int get_phys_addr(CPUState *env, uint32_t 
> address,
>  if ((env->cp15.c1_sys & 1) == 0) {
>  /* MMU/MPU disabled.  */
>  *phys_ptr = address;
> -*prot = PAGE_READ | PAGE_WRITE;
> +*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
>  *page_size = TARGET_PAGE_SIZE;
>  return 0;
>  } else if (arm_feature(env, ARM_FEATURE_MPU)) {
> @@ -1183,8 +1188,7 @@ int cpu_arm_handle_mmu_fault (CPUState *env, 
> target_ulong address,
>  /* Map a single [sub]page.  */
>  phys_addr &= ~(uint32_t)0x3ff;
>  address &= ~(uint32_t)0x3ff;
> -tlb_set_page (env, address, phys_addr, prot | PAGE_EXEC, mmu_idx,
> -  page_size);
> +tlb_set_page (env, address, phys_addr, prot, mmu_idx, page_size);
>  return 0;
>  }
>  
> -- 
> 1.7.0
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] fix race between timer firing vs. alarm_timer->pending = 0

2010-03-27 Thread Aurelien Jarno
On Fri, Mar 19, 2010 at 11:30:35AM +0100, Paolo Bonzini wrote:
> The period for Win32 timers is very short and always the same
> independent of dynticks, so it's possible that the timer fires
> before qemu_run_all_timers has reset alarm_timer->pending to zero.
> Reset alarm_timer->pending before rearming.

Thanks, applied.

> Signed-off-by: Paolo Bonzini 
> 
> Signed-off-by: Paolo Bonzini 
> ---
>  qemu-timer.c |4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-timer.c b/qemu-timer.c
> index 329d3a4..49eac86 100644
> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -706,14 +706,14 @@ void configure_icount(const char *option)
>  
>  void qemu_run_all_timers(void)
>  {
> +alarm_timer->pending = 0;
> +
>  /* rearm timer, if not periodic */
>  if (alarm_timer->expired) {
>  alarm_timer->expired = 0;
>  qemu_rearm_alarm_timer(alarm_timer);
>  }
>  
> -alarm_timer->pending = 0;
> -
>  /* vm time timers */
>  if (vm_running) {
>  qemu_run_timers(vm_clock);
> -- 
> 1.6.6.1
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH 2/3] qemu-nbd: Fix invalid usage of the first argument of errx

2010-03-27 Thread Aurelien Jarno
On Sat, Mar 20, 2010 at 03:23:23PM +0900, Ryota Ozaki wrote:
> errx takes the exit status of a process as the first
> argument. Passing errno to it is wrong. Instead the
> patch lets errx take EXIT_FAILURE.

Thanks, applied.
 
> Signed-off-by: Ryota Ozaki 
> ---
>  qemu-nbd.c |   34 +-
>  1 files changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index b89c361..6d854d3 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -114,7 +114,7 @@ static int find_partition(BlockDriverState *bs, int 
> partition,
>  int ext_partnum = 4;
>  
>  if (bdrv_read(bs, 0, data, 1))
> -errx(EINVAL, "error while reading");
> +errx(EXIT_FAILURE, "error while reading");
>  
>  if (data[510] != 0x55 || data[511] != 0xaa) {
>  errno = -EINVAL;
> @@ -133,7 +133,7 @@ static int find_partition(BlockDriverState *bs, int 
> partition,
>  int j;
>  
>  if (bdrv_read(bs, mbr[i].start_sector_abs, data1, 1))
> -errx(EINVAL, "error while reading");
> +errx(EXIT_FAILURE, "error while reading");
>  
>  for (j = 0; j < 4; j++) {
>  read_partition(&data1[446 + 16 * j], &ext[j]);
> @@ -240,20 +240,20 @@ int main(int argc, char **argv)
>  case 'p':
>  li = strtol(optarg, &end, 0);
>  if (*end) {
> -errx(EINVAL, "Invalid port `%s'", optarg);
> +errx(EXIT_FAILURE, "Invalid port `%s'", optarg);
>  }
>  if (li < 1 || li > 65535) {
> -errx(EINVAL, "Port out of range `%s'", optarg);
> +errx(EXIT_FAILURE, "Port out of range `%s'", optarg);
>  }
>  port = (uint16_t)li;
>  break;
>  case 'o':
>  dev_offset = strtoll (optarg, &end, 0);
>  if (*end) {
> -errx(EINVAL, "Invalid offset `%s'", optarg);
> +errx(EXIT_FAILURE, "Invalid offset `%s'", optarg);
>  }
>  if (dev_offset < 0) {
> -errx(EINVAL, "Offset must be positive `%s'", optarg);
> +errx(EXIT_FAILURE, "Offset must be positive `%s'", optarg);
>  }
>  break;
>  case 'r':
> @@ -263,14 +263,14 @@ int main(int argc, char **argv)
>  case 'P':
>  partition = strtol(optarg, &end, 0);
>  if (*end)
> -errx(EINVAL, "Invalid partition `%s'", optarg);
> +errx(EXIT_FAILURE, "Invalid partition `%s'", optarg);
>  if (partition < 1 || partition > 8)
> -errx(EINVAL, "Invalid partition %d", partition);
> +errx(EXIT_FAILURE, "Invalid partition %d", partition);
>  break;
>  case 'k':
>  socket = optarg;
>  if (socket[0] != '/')
> -errx(EINVAL, "socket path must be absolute\n");
> +errx(EXIT_FAILURE, "socket path must be absolute\n");
>  break;
>  case 'd':
>  disconnect = true;
> @@ -281,10 +281,10 @@ int main(int argc, char **argv)
>  case 'e':
>  shared = strtol(optarg, &end, 0);
>  if (*end) {
> -errx(EINVAL, "Invalid shared device number '%s'", optarg);
> +errx(EXIT_FAILURE, "Invalid shared device number '%s'", 
> optarg);
>  }
>  if (shared < 1) {
> -errx(EINVAL, "Shared device number must be greater than 
> 0\n");
> +errx(EXIT_FAILURE, "Shared device number must be greater 
> than 0\n");
>  }
>  break;
>   case 't':
> @@ -302,13 +302,13 @@ int main(int argc, char **argv)
>  exit(0);
>  break;
>  case '?':
> -errx(EINVAL, "Try `%s --help' for more information.",
> +errx(EXIT_FAILURE, "Try `%s --help' for more information.",
>   argv[0]);
>  }
>  }
>  
>  if ((argc - optind) != 1) {
> -errx(EINVAL, "Invalid number of argument.\n"
> +errx(EXIT_FAILURE, "Invalid number of argument.\n"
>   "Try `%s --help' for more information.",
>   argv[0]);
>  }
> @@ -316,7 +316,7 @@ int main(int argc, char **argv)
>  if (disconnect) {
>  fd = open(argv[optind], O_RDWR);
>  if (fd == -1)
> -errx(errno, "Cannot open %s", argv[optind]);
> +errx(EXIT_FAILURE, "Cannot open %s", argv[optind]);
>  
>  nbd_disconnect(fd);
>  
> @@ -340,7 +340,7 @@ int main(int argc, char **argv)
>  
>  if (partition != -1 &&
>  find_partition(bs, partition, &dev_offset, &fd_size))
> -errx(errno, "Could not find partition %d", partition);
> +errx(EXIT_FAILURE, "Could not find partition %d", partition);
>  
>  if (device) {
>  pid_t pid;
> @@ -349,7 +349,7 @@ int main(int argc, char **argv)
>   

Re: [Qemu-devel] [PATCH 1/3] qemu-nbd: Fix return value handling of bdrv_open

2010-03-27 Thread Aurelien Jarno
On Sat, Mar 20, 2010 at 03:23:22PM +0900, Ryota Ozaki wrote:
> bdrv_open may return -errno so we have to check
> if the return value is '< 0', not '== -1'.

Thanks, applied.

> Signed-off-by: Ryota Ozaki 
> ---
>  qemu-nbd.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index a393583..b89c361 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -333,7 +333,7 @@ int main(int argc, char **argv)
>  if (bs == NULL)
>  return 1;
>  
> -if (bdrv_open(bs, argv[optind], flags) == -1)
> +if (bdrv_open(bs, argv[optind], flags) < 0)
>  return 1;
>  
>  fd_size = bs->total_sectors * 512;
> -- 
> 1.6.5.2
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH 3/3] qemu-nbd: Improve error reporting

2010-03-27 Thread Aurelien Jarno
On Sat, Mar 20, 2010 at 03:23:24PM +0900, Ryota Ozaki wrote:
> - use err(3) instead of errx(3) if errno is available
>   to report why failed
> - let fail prior to daemon(3) if opening a nbd file
>   is likely to fail after daemonizing to avoid silent
>   failure exit
> 
> Signed-off-by: Ryota Ozaki 
> ---
>  qemu-nbd.c |   16 +++-
>  1 files changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 6d854d3..8fb8cc3 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -316,7 +316,7 @@ int main(int argc, char **argv)
>  if (disconnect) {
>  fd = open(argv[optind], O_RDWR);
>  if (fd == -1)
> -errx(EXIT_FAILURE, "Cannot open %s", argv[optind]);
> +err(EXIT_FAILURE, "Cannot open %s", argv[optind]);
>  
>  nbd_disconnect(fd);
>  
> @@ -333,23 +333,29 @@ int main(int argc, char **argv)
>  if (bs == NULL)
>  return 1;
>  
> -if (bdrv_open(bs, argv[optind], flags) < 0)
> -return 1;
> +if ((ret = bdrv_open(bs, argv[optind], flags)) < 0) {
> +errno = -ret;
> +err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]);
> +} 
>  
>  fd_size = bs->total_sectors * 512;
>  
>  if (partition != -1 &&
>  find_partition(bs, partition, &dev_offset, &fd_size))
> -errx(EXIT_FAILURE, "Could not find partition %d", partition);
> +err(EXIT_FAILURE, "Could not find partition %d", partition);
>  
>  if (device) {
>  pid_t pid;
>  int sock;
>  
> +/* want to fail before daemonizing */
> +if (access(device, R_OK|W_OK) == -1)
> +err(EXIT_FAILURE, "Could not access '%s'", device);
> +

First of all you need to put this line between curly braces. Secondly,
qemu-nbd as a read-only option to export a block device as read-only.
The test has to be improved to also take care of that.

>  if (!verbose) {
>  /* detach client and server */
>  if (daemon(0, 0) == -1) {
> -errx(EXIT_FAILURE, "Failed to daemonize");
> +err(EXIT_FAILURE, "Failed to daemonize");
>  }
>  }
>  
> -- 
> 1.6.5.2
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] qemu-io: Fix return value handling of bdrv_open

2010-03-27 Thread Aurelien Jarno
On Sat, Mar 20, 2010 at 04:08:38PM +0900, Ryota Ozaki wrote:
> bdrv_open may return -errno so we have to check
> if the return value is '< 0', not '== -1'.

Thanks, applied.

> Signed-off-by: Ryota Ozaki 
> ---
>  qemu-io.c |2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/qemu-io.c b/qemu-io.c
> index b2f2f5a..2f195bf 100644
> --- a/qemu-io.c
> +++ b/qemu-io.c
> @@ -1284,7 +1284,7 @@ static int openfile(char *name, int flags, int growable)
>   flags |= BDRV_O_FILE;
>   }
>  
> - if (bdrv_open(bs, name, flags) == -1) {
> + if (bdrv_open(bs, name, flags) < 0) {
>   fprintf(stderr, "%s: can't open device %s\n", progname, name);
>   bs = NULL;
>   return 1;
> -- 
> 1.6.5.2
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] balloon: Fix overflow when reporting actual memory size

2010-03-27 Thread Aurelien Jarno
On Thu, Mar 25, 2010 at 08:58:17AM -0500, Adam Litke wrote:
> Beginning with its introduction, the virtio balloon has had an overflow error
> that causes 'info balloon' to misreport the actual memory size when the 
> balloon
> itself becomes larger than 4G.  Use a cast when converting dev->actual from
> pages to kB to prevent overflows.
>
> Before:
> (qemu) info balloon
> balloon: actual=5120
> (qemu) balloon 1025
> (qemu) info balloon
> balloon: actual=1025
> (qemu) balloon 1024
> (qemu) info balloon
> balloon: actual=5120
>
> After:
> (qemu) info balloon
> balloon: actual=5120
> (qemu) balloon 1025
> (qemu) info balloon
> balloon: actual=1025
> (qemu) balloon 1024
> (qemu) info balloon
> balloon: actual=1024

Thanks, applied.

> Signed-off-by: Adam Litke 
> ---
> hw/virtio-balloon.c |3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
> index 086d9d1..6eedab1 100644
> --- a/hw/virtio-balloon.c
> +++ b/hw/virtio-balloon.c
> @@ -78,7 +78,8 @@ static void stat_put(QDict *dict, const char *label, 
> uint64_t val)
> static QObject *get_stats_qobject(VirtIOBalloon *dev)
> {
> QDict *dict = qdict_new();
> -uint32_t actual = ram_size - (dev->actual << VIRTIO_BALLOON_PFN_SHIFT);
> +uint64_t actual = ram_size - ((uint64_t) dev->actual <<
> +  VIRTIO_BALLOON_PFN_SHIFT);
>
> stat_put(dict, "actual", actual);
> stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
> -- 
> 1.6.3.3
>
>
>
>
>

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




Re: [Qemu-devel] [PATCH] qemu: jaso-parser: Output the content of invalid keyword

2010-03-27 Thread Aurelien Jarno
On Wed, Mar 24, 2010 at 11:12:05PM +0800, Amos Kong wrote:
> 
> When input some invialid word 'unknowcmd' through QMP port, qemu outputs this
> error message:
> "parse error: invalid keyword `%s'"
> This patch makes qemu output the content of invalid keyword, like:
> "parse error: invalid keyword `unknowcmd'"

Thanks, applied.

> Signed-off-by: Amos Kong 
> ---
>  json-parser.c |8 +++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/json-parser.c b/json-parser.c
> index 579928f..b55d763 100644
> --- a/json-parser.c
> +++ b/json-parser.c
> @@ -12,6 +12,7 @@
>   */
>  
>  #include 
> +#include 
>  
>  #include "qemu-common.h"
>  #include "qstring.h"
> @@ -93,7 +94,12 @@ static int token_is_escape(QObject *obj, const char *value)
>   */
>  static void parse_error(JSONParserContext *ctxt, QObject *token, const char 
> *msg, ...)
>  {
> -fprintf(stderr, "parse error: %s\n", msg);
> +va_list ap;
> +va_start(ap, msg);
> +fprintf(stderr, "parse error: ");
> +vfprintf(stderr, msg, ap);
> +fprintf(stderr, "\n");
> +va_end(ap);
>  }
>  
>  /**
> -- 
> 1.6.3.3
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] usb-bus: fix no params

2010-03-27 Thread Aurelien Jarno
On Fri, Mar 19, 2010 at 12:59:24PM +0800, TeLeMan wrote:
> The "params" is never NULL and the usb hid devices have no params.

This looks plainly wrong. With your patch, usb devices which don't
accept parameters, will accept and ignore them.

What are you trying to fix here?

> Signed-off-by: TeLeMan 
> ---
>  hw/usb-bus.c |4 
>  1 files changed, 0 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/usb-bus.c b/hw/usb-bus.c
> index ce8a694..f3f1ed6 100644
> --- a/hw/usb-bus.c
> +++ b/hw/usb-bus.c
> @@ -299,10 +299,6 @@ USBDevice *usbdevice_create(const char *cmdline)
>  }
> 
>  if (!usb->usbdevice_init) {
> -if (params) {
> -error_report("usbdevice %s accepts no params", driver);
> -return NULL;
> -}
>  return usb_create_simple(bus, usb->qdev.name);
>  }
>  return usb->usbdevice_init(params);
> -- 
> 1.6.5.1.1367.gcd48
> --
> SUN OF A BEACH
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] raw-posix: Better error return values for hdev_create

2010-03-27 Thread Aurelien Jarno
On Fri, Mar 12, 2010 at 01:52:31PM +0100, Kevin Wolf wrote:
> Now that we output an error message according to the returned error code in
> qemu-img, let's return the real error codes. "Input/output error" for
> everything isn't helpful.
> 
> Signed-off-by: Kevin Wolf 

Thanks, applied.

> ---
>  block/raw-posix.c |6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index 716c15c..f07d730 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1009,12 +1009,12 @@ static int hdev_create(const char *filename, 
> QEMUOptionParameter *options)
>  
>  fd = open(filename, O_WRONLY | O_BINARY);
>  if (fd < 0)
> -return -EIO;
> +return -errno;
>  
>  if (fstat(fd, &stat_buf) < 0)
> -ret = -EIO;
> +ret = -errno;
>  else if (!S_ISBLK(stat_buf.st_mode) && !S_ISCHR(stat_buf.st_mode))
> -ret = -EIO;
> +ret = -ENODEV;
>  else if (lseek(fd, 0, SEEK_END) < total_size * 512)
>  ret = -ENOSPC;
>  
> -- 
> 1.6.6.1
> 
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] qemu-io: fix aio help texts

2010-03-27 Thread Aurelien Jarno
On Tue, Mar 16, 2010 at 07:12:58PM +0100, Christoph Hellwig wrote:
> Fix a few typos in the helptexts for the various aio commands.

This is clearly an improvement, but it introduces a typo (see below).

> Signed-off-by: Christoph Hellwig 
> 
> Index: qemu/qemu-io.c
> ===
> --- qemu.orig/qemu-io.c   2010-03-16 19:07:43.089009269 +0100
> +++ qemu/qemu-io.c2010-03-16 19:08:36.597005148 +0100
> @@ -904,8 +904,8 @@ aio_read_help(void)
>  "\n"
>  " Reads a segment of the currently open file, optionally dumping it to the\n"
>  " standard output stream (with -v option) for subsequent inspection.\n"
> -" The read is performed asynchronously and should the aio_flush command \n"
> -" should be used to ensure all outstanding aio requests have been 
> completed\n"
> +" The read is performed asynchronously and the aio_flush command must be\n"

"used" is missing here.

> +" to ensure all outstanding aio requests have been completed\n"
>  " -C, -- report statistics in a machine parsable format\n"
>  " -P, -- use a pattern to verify read data\n"
>  " -v, -- dump buffer to standard output\n"
> @@ -1003,8 +1003,8 @@ aio_write_help(void)
>  "\n"
>  " Writes into a segment of the currently open file, using a buffer\n"
>  " filled with a set pattern (0xcdcdcdcd).\n"
> -" The write is performed asynchronously and should the aio_flush command \n"
> -" should be used to ensure all outstanding aio requests have been 
> completed\n"
> +" The write is performed asynchronously and the aio_flush command must be\n"
> +" used to ensure all outstanding aio requests have been completed\n"
>  " -P, -- use different pattern to fill file\n"
>  " -C, -- report statistics in a machine parsable format\n"
>  " -q, -- quite mode, do not show I/O statistics\n"
> @@ -1095,7 +1095,7 @@ aio_flush_f(int argc, char **argv)
>  static const cmdinfo_t aio_flush_cmd = {
>   .name   = "aio_flush",
>   .cfunc  = aio_flush_f,
> - .oneline= "completes all outstanding aio requets"
> + .oneline= "completes all outstanding aio requests"
>  };
>  
>  static int
> 
> 
> 

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




Re: [Qemu-devel] [trivial one-liner] be more specific in -mem-path error messages

2010-03-27 Thread Aurelien Jarno
On Tue, Mar 16, 2010 at 11:01:46AM +0300, Michael Tokarev wrote:
> The error message qemu gives when hugetlbfs is not
> accessible is cryptic at best:
> 
>   mkstemp: Permission denied
> 
> Make it a bit more specific instead:
> 
>  unable to create backing store for hugepages: Permission denied
> 
> Thanks!

It looks good, but needs a Signed-off-by: line.

> /mjt
> 
> diff --git a/exec.c b/exec.c
> index 891e0ee..985bdde 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2569,5 +2569,5 @@ static void *file_ram_alloc(ram_addr_t memory, const 
> char *path)
>  fd = mkstemp(filename);
>  if (fd < 0) {
> - perror("mkstemp");
> + perror("unable to create backing store for hugepages");
>   free(filename);
>   return NULL;
> 
> 
> 

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




Re: [Qemu-devel] [PATCH] qemu-kvm: avoid strlen of NULL pointer

2010-03-27 Thread Aurelien Jarno
On Wed, Mar 03, 2010 at 03:32:43PM +0100, Jens Osterkamp wrote:
> If the user wants to create a chardev of type socket but forgets to give a
> host= option, qemu_opt_get returns NULL. This NULL pointer is then fed into
> strlen a few lines below without a check which results in a segfault.
> This fixes it.

While this correctly fixes the segfault, it doesn't output any error
message. The best would probably be to fold that with the test of
"port", as the error message already mentions "host and/or port".

> Signed-off-by: Jens Osterkamp 
> ---
>  qemu-sockets.c |3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/qemu-sockets.c b/qemu-sockets.c
> index 23c3def..a191304 100644
> --- a/qemu-sockets.c
> +++ b/qemu-sockets.c
> @@ -137,6 +137,9 @@ int inet_listen_opts(QemuOpts *opts, int port_offset)
>  pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
>  addr = qemu_opt_get(opts, "host");
>  
> +if (!addr)
> + return -1;
> +
>  to = qemu_opt_get_number(opts, "to", 0);
>  if (qemu_opt_get_bool(opts, "ipv4", 0))
>  ai.ai_family = PF_INET;
> -- 
> 1.5.6.3
> 
> 
> -- 
> Best regards, 
> 
> Jens Osterkamp
> 
> IBM Deutschland Research & Development GmbH
> Vorsitzender des Aufsichtsrats: Martin Jetter
> Geschäftsführung: Dirk Wittkopp
> Sitz der Gesellschaft: Böblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294
> 
> 
> 
> 

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




Re: [Qemu-devel] Significant performance regression in qemu-system-mips.

2010-03-27 Thread Aurelien Jarno
On Fri, Mar 26, 2010 at 04:47:51PM -0500, Rob Landley wrote:
> On Friday 26 March 2010 14:00:00 Aurelien Jarno wrote:
> > > I'm not asking anyone to care about me personally, I'm asking them to
> > > care about specific technical issues.  If those issues don't interest
> > > you, they don't interest you.
> > >
> > > Speaking of ppc, last month I sent this patch:
> > >
> > >   http://lists.gnu.org/archive/html/qemu-devel/2010-02/msg00917.html
> > >
> > > And I was under the impression people agreed with it:
> > >
> > >   http://lists.gnu.org/archive/html/qemu-devel/2010-02/msg01044.html
> > >   http://lists.gnu.org/archive/html/qemu-devel/2010-02/msg01714.html
> > >
> > > But today's -git is still having that same issue, and the same patch
> > > still applies cleanly and fixes it for me.
> >
> > Re-read the last link you quoted, and especially this part:
> > | The
> > | same way using CONFIG_BSD in linux-user/elfload.c doesn't make sense,
> > | as this code will never been compiled.
> 
> I didn't know the BSD comments werer addressed at me.  (I haven't got a BSD
> test system.)
> 
> > While your patch goes in the good direction, it doesn't mean it is
> > correct. Conditionally compiling code on CONFIG_BSD in a Linux specific
> > file doesn't make sense.
> 
> Ok.
> 
> > I am pretty fine applying a correct patch if you send a new one.
> 
> By which you mean rip out the whole #ifdef block?

Yes.

> Here you go:

This looks much better. Can you please resend it with the changes below
and a Signed-off-by: ?

> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 682a813..44405dd 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -518,12 +518,11 @@ do {
> \
>  static inline void init_thread(struct target_pt_regs *_regs, struct 
> image_info *infop)
>  {
>  abi_ulong pos = infop->start_stack;

This line should probably be removed...

> -abi_ulong tmp;
>  #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
>  abi_ulong entry, toc;
>  #endif
>  
> -_regs->gpr[1] = infop->start_stack;
> +_regs->gpr[1] = pos;

...instead of doing the change here.

>  #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
>  entry = ldq_raw(infop->entry) + infop->load_addr;
>  toc = ldq_raw(infop->entry + 8) + infop->load_addr;
> @@ -531,17 +530,6 @@ static inline void init_thread(struct target_pt_regs 
> *_regs, struct image_info *
>  infop->entry = entry;
>  #endif
>  _regs->nip = infop->entry;
> -/* Note that isn't exactly what regular kernel does
> - * but this is what the ABI wants and is needed to allow
> - * execution of PPC BSD programs.
> - */
> -/* FIXME - what to for failure of get_user()? */
> -get_user_ual(_regs->gpr[3], pos);
> -pos += sizeof(abi_ulong);
> -_regs->gpr[4] = pos;
> -for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong))
> -tmp = ldl(pos);
> -_regs->gpr[5] = pos;
>  }
>  
>  #define ELF_EXEC_PAGESIZE4096
> 
> Re-tested and it works fine for me.
> 
> > I have no problem with you having no interest in sh4, a lot of people
> > are in you case. I don't think it gives you the right to describe the
> > sh4 kernel maintainer as "sh4 linux-kernel maintainer officially doesn't
> > care about anybody who isn't employed by his company", or later "It's
> > not real hardware, it's a one-company toy". This is not something
> > reflected in link you quoted. Paul Mundt has been nicely answering your
> > question on this thread.
> 
> Ok, I agree I was a bit harsh.  (He's the one who introduced his employer into
> the discussion, but I suspect I read more into that than he meant by it.)
> 

I think you misunderstood him. You were talking about Super-Hitachi
which is a train [1] from Hitachi (not his employer), while he was talking
about Super-H which is a CPU [2] from Renesas (his employer).

He has the right to not care about trains ;-)

[1] http://en.wikipedia.org/wiki/Hitachi_(Japanese_train)
[2] http://en.wikipedia.org/wiki/SuperH

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




[Qemu-devel] [PATCH, RFC] Refactor target specific handling out of vl.c

2010-03-27 Thread Blue Swirl
This is very much work in progress, it does not compile yet. However,
the only target dependencies remaining are QEMU_OPTION_xxx enums and
the target specific option handling in the option parsing loop. I
haven't got a good plan for that, except maybe QEMUOption structure
could have a field that specifies for which targets the option is
valid. Any ideas?

There also are some pieces (set_cpu_log, debug_requested, gdbstub.h
and kvm.h cleanup, allow balloon options to all targets) that deserve
separate patches.

RAM handling could go to a new file, perhaps in hw/ram.c instead of arch_init.c.

Comments?

This depends on the various previous patches I sent. I set up a public git tree:
http://repo.or.cz/w/qemu/blueswirl.git
git://repo.or.cz/qemu/blueswirl.git

Not-quite-signed-off-by-yet: Blue Swirl 
---
 Makefile.objs   |2 +-
 Makefile.target |2 +-
 arch_init.c |  461 +
 arch_init.h |   20 +++
 balloon.h   |2 -
 cpu-all.h   |1 -
 cpus.c  |   18 ++-
 cpus.h  |1 +
 gdbstub.h   |   11 +-
 hw/smbios.c |1 +
 kvm.h   |4 +-
 qemu-common.h   |2 +
 qemu-options.hx |2 -
 vl.c|  475 ---
 14 files changed, 543 insertions(+), 459 deletions(-)
 create mode 100644 arch_init.c
 create mode 100644 arch_init.h

diff --git a/Makefile.objs b/Makefile.objs
index 1c360a6..4ff3214 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -127,7 +127,7 @@ user-obj-y += cutils.o cache-utils.o
 # libhw

 hw-obj-y =
-hw-obj-y += loader.o
+hw-obj-y += vl.o loader.o
 hw-obj-y += virtio.o virtio-console.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o
diff --git a/Makefile.target b/Makefile.target
index 156b4bd..98cf52c 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER
 # System emulator target
 ifdef CONFIG_SOFTMMU

-obj-y = vl.o cpus.o monitor.o machine.o gdbstub.o
+obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o
 obj-y += qemu-timer.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
diff --git a/arch_init.c b/arch_init.c
new file mode 100644
index 000..eb4dc07
--- /dev/null
+++ b/arch_init.c
@@ -0,0 +1,461 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * 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 
+#include 
+#include 
+#include "config.h"
+#include "monitor.h"
+#include "sysemu.h"
+#include "arch_init.h"
+#include "audio/audio.h"
+#include "hw/pc.h"
+#include "hw/pci.h"
+#include "hw/audiodev.h"
+#include "kvm.h"
+#include "migration.h"
+#include "net.h"
+#include "gdbstub.h"
+
+#ifdef TARGET_SPARC
+int graphic_width = 1024;
+int graphic_height = 768;
+int graphic_depth = 8;
+#else
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 15;
+#endif
+
+#ifdef TARGET_I386
+int rtc_td_hack = 0;
+#endif
+
+#ifdef TARGET_ARM
+int old_param = 0;
+#endif
+
+#if defined(TARGET_SPARC) || defined(TARGET_PPC)
+unsigned int nb_prom_envs = 0;
+const char *prom_envs[MAX_PROM_ENVS];
+#endif
+
+const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-"
TARGET_ARCH ".conf";
+
+/***/
+/* ram save/restore */
+
+#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
+#define RAM_SAVE_FLAG_COMPRESS 0x02
+#define RAM_SAVE_FLAG_MEM_SIZE 0x04
+#define RAM_SAVE_FLAG_PAGE 0x08
+#define RAM_SAVE_FLAG_EOS  0x10
+
+static int is_dup_page(uint8_t *page, uint8_t ch)
+{
+uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
+uint32_t *array = (uint32_t *)page;
+int i;
+
+for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) {
+if (array[i] != val)
+return 0;
+}
+
+return 1;
+}
+
+static int ram_save_block(QEMUFile *

Re: [Qemu-devel] Question about memory micro operations in Qemu 0.12.x

2010-03-27 Thread Stuart Brady
On Sat, Mar 27, 2010 at 09:20:51AM +0300, coo...@gmail.com wrote:
> My question is : how memory access microoperations are now
> implemented in qemu 0.12.x ?

We heard you the first time. :-)

Cheers,
-- 
Stuart Brady




Re: [Qemu-devel] Question about memory micro operations in Qemu 0.12.x]

2010-03-27 Thread Stuart Brady
[ Sorry for sending twice, forgot to reply to the list ]

On Fri, Mar 26, 2010 at 11:23:30PM +0300, coo...@gmail.com wrote:
> Hello.
> in qemu 0.9.x there was a special file with micro-operations, which
> implemented access to memory. For example for arm architecture it
> was op_mem.h file. I was able to add some printfs to this functions
> and get information about memory accesses.
> 
> My question is : how memory access microoperations are now
> implemented in qemu 0.12.x ?
> 
> Thanks for you answers.

To generate load and store operations, tcg_gen_qemu_{ld,st}*() are now
used.  See tcg/README for more information on TCG ops.

In tcg/*/tcg-target.c, you'll find tcg_out_qemu_{ld,st}().  The easiest
way to do this would probably be to place your printfs in __ld_mmu() and
__st_mmu() (which are defined via softmmu_template.h), and remove the
TLB lookups from tcg_out_qemu_{ld,st}() so that your tracing code is
always called.

Instead of modifying tcg_out_qemu_{ld,st}(), you might also be able to
bypass it entirely, by using having tcg_gen_qemu_{ld,st}*() generate
calls to a helper function.

Cheers,
-- 
Stuart Brady




[Qemu-devel] QEMU 0.12.3 and SCSI boot

2010-03-27 Thread Gerhard Wiesinger

Hello,

I'm having trouble booting from SCSI adapter 53C895a and e.g. INT13h OS 
like MS-DOS 6.22.


I downloaded and installed the option ROM with -option-rom 8xx_64.rom:
http://www.lsi.com/DistributionSystem/AssetDocument/files/support/ssp/sdms/Bios/lsi_bios.zip

I'm seeing that Harddisks are installed well and that also "PCI boot ROM 
succesfully installed" message appears. So that part looks good as DDIM 
(Device Driver Initialization Model) has been implemented.


Also booting (sometimes) and sometimes access works until nearly 
immediatly the following problems occour (repeated messages with different 
Tags):

lsi_scsi: error: Reselect with pending DMA
scsi-disk: Tag 0x0 already in use
paio_remove: aio request not found!

So it seems to me that there is some incompatibility with the ROM and the 
SCSI emulation (busmaster DMA?) and INT 13h.


BTW: Booting Knoppix 6.2 Live CD without any option ROM and even with 
option ROM works well with SCSI disks (at least reading from them without 
any errors on the console, i guess because of own drivers and not INT13h 
access).


Any ideas to fix that issue and to bugfix it?

Thanx.

Ciao,
Gerhard

--
http://www.wiesinger.com/




Re: [Qemu-devel] [PATCH] Fix busted driftfix option

2010-03-27 Thread Blue Swirl
On 3/26/10, Zachary Amsden  wrote:
> For some reason, this uses CONFIG_TARGET_I386 instead of TARGET_I386, so
>  the code is dead.

The code is also broken: it references undefined variable 'buf'
instead of 'value'.




[Qemu-devel] Keyboard problems - Alt-GR QEMU 0.12.3 with VNC and german keyboard doesn't work

2010-03-27 Thread Gerhard Wiesinger

Hello,

I'm having problems with QEMU 0.12.3 (and even older versions) that Alt-GR 
doesn't work: e.g. Alt-GR q should be @ but is still q.


Tested with e.g. Knoppix Live CD 6.2 and MS-DOS 6.22.

In general I'm having also keyboard problems with 
upper/lowercase/Shift state under MS-DOS 6.22 (KEYB GR loaded): Sometimes 
it is upper when it should be lowercase, so something with the keyboard 
emulation or VNC might be wrong.


own build:
qemu-0.12.3/x86_64-softmmu/qemu-system-x86_64 -k ...

VNC Client: UltraVNC 1.0.8.2

I found a fix which seems to be integrated but it doesn't work yet.
http://qemu-forum.ipi.fi/viewtopic.php?f=2&t=4690

Also some links I've found already to the topic, but sill no solution yet:
https://bugs.launchpad.net/debian/+source/qemu/+bug/238684
http://qemu-forum.ipi.fi/viewtopic.php?f=4&t=3978
http://patches.ubuntu.com/by-release/ubuntu/k/kvm/kvm_1:84+dfsg-0ubuntu10.slipped-patch
http://old.nabble.com/-PATCH-0-of-2--Fix-keymap-handling-for-vnc-console-td20505033.html

If you need some help to track down the problem let me know.

Any ideas or plans to fix?

Thanx.

Ciao,
Gerhard

--
http://www.wiesinger.com/




Re: [Qemu-devel] Re: [PATCH 10/15] virtio-serial: Add QMP events for failed port/device add

2010-03-27 Thread Amit Shah
On (Fri) Mar 26 2010 [14:52:36], Luiz Capitulino wrote:
> > >  My suggestion for the immediate term is to do what we have been doing so
> > > far, ie. call it VIRTIO_SERIAL_ADD. Worst case here is: we add a new way
> > > to group events which requires a new VIRTIO_SERIAL event, in this case we
> > > could emit both, the new VIRTIO_SERIAL and the old VIRTIO_SERIAL_ADD. The
> > > latter would be deprecated too.
> > 
> > I've no problem doing it either way - whatever you prefer is fine.
> > 
> > BTW these are two distinct events already - failure in initialising a
> > device and failure in initialising a port. Do you think these should be
> > separate as well?
> 
>  That depends on what you want clients to know/do about it.
> 
>  Can ports and devices be added and work independently of each other?
> Why is it relevant for a client to know that a _device_ has failed to
> initialize?

I'm not sure what you mean by a client, but let's say libvirt handles
the qemu session. A single device can have multiple ports. If a device
fails to register *in the guest*, all the ports associated with that
device could be hot-unplugged on the host to reduce host resource usage.

If just a single port fails to register *in the guest*, libvirt may just
want to hot-unplug it to free up resources.

So yes, I think both are necessary.

Anyway, I guess the answer is to split both these events.

>  If clients connect to a port and all they need to know is "Sorry, but
> that port won't be available", then you don't even need to have a port/device
> distinction in the event.
> 
>  Also note that events can be improved to include more information later,
> if needed. So, the best approach is to include as less information as
> possible (given that it satisfies current client needs, of course).

Right; that's the reason only the failing port number is given right
now.

> > >  Or, if you can wait I can _try_ to solve this problem next week, although
> > > I have no idea how hard this is going to be.
> > 
> > I think it's cleaner to club everything; but basically I'll go with
> > whatever you say. I've no problem waiting.
> 
>  It's definitely needed to group events some way, we just have to
> find a good way to do it. Having each subsystem doing it its own way
> is not what we want because of protocol consistency and related
> problems.

Yes, that's exactly why I think waiting till you iron it out would help.

Amit




Re: [Qemu-devel] [PATCH 1/3] Compile some MIPS devices only once

2010-03-27 Thread Blue Swirl
On 3/27/10, Aurelien Jarno  wrote:
> On Fri, Mar 26, 2010 at 11:37:08PM +0200, Blue Swirl wrote:
>  > On 3/26/10, Aurelien Jarno  wrote:
>  > > On Thu, Mar 25, 2010 at 10:24:12PM +0200, Blue Swirl wrote:
>  > >  > Move CPU specific declarations to a separate file.
>  > >
>  > >
>  > > This basically looks ok, but I haven't been able to test it as the patch
>  > >  doesn't apply anymore.
>  >
>  > You need to apply the earlier ide/core patch first, then it should apply.
>  >
>
>
> I confirm it works fine.

Thanks, I applied the patch then.