Re: [Qemu-devel] [PATCH 06/11] Add support for S390x system emulation

2009-12-02 Thread Aurelien Jarno
On Mon, Nov 30, 2009 at 11:19:06PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
  On Thu, Nov 26, 2009 at 02:23:15PM +0100, Alexander Graf wrote:
  Let's enable the basics for system emulation so we can run virtual machines
  with KVM!
  
  I don't really understand while this whole patch is not merged in patch
  number 1. Otherwise, please find the comments below.
 
 Historical reasons. To keep Uli's stripped down version separate from my code.
 
  
  Signed-off-by: Alexander Graf ag...@suse.de
  ---
  target-s390x/cpu.h|  153 
  -
  target-s390x/exec.h   |5 +
  target-s390x/helper.c |   22 +
  target-s390x/machine.c|   30 +++
  4 files changed, 208 insertions(+), 2 deletions(-)
  create mode 100644 default-configs/s390x-softmmu.mak
  create mode 100644 target-s390x/machine.c
  
  diff --git a/default-configs/s390x-softmmu.mak 
  b/default-configs/s390x-softmmu.mak
  new file mode 100644
  index 000..e69de29
  diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
  index f45b00c..a74745c 100644
  --- a/target-s390x/cpu.h
  +++ b/target-s390x/cpu.h
  @@ -30,8 +30,7 @@
  
  #include softfloat.h
  
  -#define NB_MMU_MODES 2 // guess
  -#define MMU_USER_IDX 0 // guess
  +#define NB_MMU_MODES 2
  
  typedef union FPReg {
  struct {
  @@ -77,6 +76,15 @@ static inline void cpu_clone_regs(CPUState *env, 
  target_ulong newsp)
  }
  #endif
  
  +#define MMU_MODE0_SUFFIX _kernel
  +#define MMU_MODE1_SUFFIX _user
  +#define MMU_USER_IDX 1
  +static inline int cpu_mmu_index (CPUState *env)
  +{
  +/* XXX: Currently we don't implement virtual memory */
  +return 0;
  
  Is it correct? It means that memory access will aways be kernel memory
  accesses. IIRC, even with KVM enabled, softmmu accesses are possible in
  some cases (devices ?).
 
 I can't imagine any hardware using the CPU's MMU to write to RAM. That's what 
 IOMMUs are for.
 
 The only 2 consumers are:
 
 1) tcg
 2) gdb / monitor
 
 With 2) being broken, because we can't resolve virtual addresses to physical 
 addresses. But that won't change until someone implements the softmmu 
 emulation target for real.

If it is sure it is never used, I would prefer to see an abort().
Otherwise it's fine.

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




Re: [Qemu-devel] [PATCH 04/11] Add KVM support for S390x

2009-12-02 Thread Aurelien Jarno
On Mon, Nov 30, 2009 at 11:25:03PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
  On Thu, Nov 26, 2009 at 02:23:13PM +0100, Alexander Graf wrote:
  S390x was one of the first platforms that received support for KVM back in 
  the
  day. Unfortunately until now there hasn't been a qemu implementation that 
  would
  enable users to actually run guests.
  
  So let's include support for KVM S390x in qemu!
  
  Please find the comments below.
  
  Signed-off-by: Alexander Graf ag...@suse.de
  ---
  configure  |4 +-
  target-s390x/kvm.c |  463 
  
  2 files changed, 466 insertions(+), 1 deletions(-)
  create mode 100644 target-s390x/kvm.c
  
  diff --git a/configure b/configure
  index b616e1a..cf466ec 100755
  --- a/configure
  +++ b/configure
  @@ -1348,6 +1348,8 @@ EOF
  kvm_cflags=$kvm_cflags -I$kerneldir/arch/x86/include
 elif test $cpu = ppc -a -d $kerneldir/arch/powerpc/include ; then
 kvm_cflags=$kvm_cflags -I$kerneldir/arch/powerpc/include
  +  elif test $cpu = s390x -a -d $kerneldir/arch/s390/include ; then
  +  kvm_cflags=$kvm_cflags -I$kerneldir/arch/s390/include
  elif test -d $kerneldir/arch/$cpu/include ; then
  kvm_cflags=$kvm_cflags -I$kerneldir/arch/$cpu/include
fi
  @@ -2360,7 +2362,7 @@ case $target_arch2 in
  fi
  esac
  case $target_arch2 in
  -  i386|x86_64|ppcemb|ppc|ppc64)
  +  i386|x86_64|ppcemb|ppc|ppc64|s390x)
  # Make sure the target and host cpus are compatible
  if test $kvm = yes -a $target_softmmu = yes -a \
\( $target_arch2 = $cpu -o \
  diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
  new file mode 100644
  index 000..d477664
  --- /dev/null
  +++ b/target-s390x/kvm.c
  @@ -0,0 +1,463 @@
  +/*
  + * QEMU S390x KVM implementation
  + *
  + * Copyright (c) 2009 Alexander Graf ag...@suse.de
  + *
  + * This library is free software; you can redistribute it and/or
  + * modify it under the terms of the GNU Lesser General Public
  + * License as published by the Free Software Foundation; either
  + * version 2 of the License, or (at your option) any later version.
  + *
  + * This library is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this library; if not, see 
  http://www.gnu.org/licenses/.
  + */
  +
  +#include sys/types.h
  +#include sys/ioctl.h
  +#include sys/mman.h
  +
  +#include linux/kvm.h
  +#include asm/ptrace.h
  +
  +#include qemu-common.h
  +#include qemu-timer.h
  +#include sysemu.h
  +#include kvm.h
  +#include cpu.h
  +#include device_tree.h
  +
  +/* #define DEBUG_KVM */
  +
  +#ifdef DEBUG_KVM
  +#define dprintf(fmt, ...) \
  +do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
  +#else
  +#define dprintf(fmt, ...) \
  +do { } while (0)
  +#endif
  +
  +#define IPA0_DIAG   0x8300
  +#define IPA0_SIGP   0xae00
  +#define IPA0_PRIV   0xb200
  +
  +#define PRIV_SCLP_CALL  0x20
  +#define DIAG_KVM_HYPERCALL  0x500
  +#define DIAG_KVM_BREAKPOINT 0x501
  +
  +#define SCP_LENGTH  0x00
  +#define SCP_FUNCTION_CODE   0x02
  +#define SCP_CONTROL_MASK0x03
  +#define SCP_RESPONSE_CODE   0x06
  +#define SCP_MEM_CODE0x08
  +#define SCP_INCREMENT   0x0a
  +
  +#define ICPT_INSTRUCTION0x04
  +#define ICPT_WAITPSW0x1c
  +#define ICPT_SOFT_INTERCEPT 0x24
  +#define ICPT_CPU_STOP   0x28
  +#define ICPT_IO 0x40
  +
  +#define SIGP_RESTART0x06
  +#define SIGP_INITIAL_CPU_RESET  0x0b
  +#define SIGP_STORE_STATUS_ADDR  0x0e
  +#define SIGP_SET_ARCH   0x12
  +
  +
  +int kvm_arch_init(KVMState *s, int smp_cpus)
  +{
  +return 0;
  +}
  +
  +int kvm_arch_init_vcpu(CPUState *env)
  +{
  +int ret = 0;
  +
  +if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL)  0)
  +perror(cannot init reset vcpu);
  
  coding style.
  
  +
  +return ret;
  +}
  +
  +void kvm_arch_reset_vcpu(CPUState *env)
  +{
  +}
  
  Is there really nothing to do? If some code has to be added later, it
  may be worth adding a comment.
 
 As you have probably realized by now, all reset code is missing. In fact, we 
 don't even ever call the qemu reset functions to actually do a reset.

Can you make it clean with an abort?

  +
  +static void _kvm_s390_interrupt(CPUState *env, int type, uint32_t parm, 
  uint64_t parm64, int vm)
  +{
  
  Why such a name starting with an underscore?
 
 Because that's the internal function that gets used by the exported, properly 
 named ones. Are there any conventions on how to declare private functions?


Re: [Qemu-devel] [PATCH 03/11] S/390 fake TCG implementation

2009-12-02 Thread Aurelien Jarno
On Mon, Nov 30, 2009 at 11:27:53PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
  On Thu, Nov 26, 2009 at 02:23:12PM +0100, Alexander Graf wrote:
  Qemu won't let us run a KVM target without having host TCG support. Well, 
  for
  now we don't have any so let's implement a fake target that only stubs out
  everything.
  
  I tried to keep the patch as close to Uli's source as possible, so whenever
  he feels like it he can easily diff his version against this one.
  
  Please find the comments below.
  
  Signed-off-by: Alexander Graf ag...@suse.de
  ---
  dyngen-exec.h |2 +-
  target-s390x/helper.c |5 ++
  tcg/s390/tcg-target.c |  103 
  +
  tcg/s390/tcg-target.h |   48 +++
  4 files changed, 157 insertions(+), 1 deletions(-)
  create mode 100644 tcg/s390/tcg-target.c
  create mode 100644 tcg/s390/tcg-target.h
  
  diff --git a/dyngen-exec.h b/dyngen-exec.h
  index 86e61c3..0353f36 100644
  --- a/dyngen-exec.h
  +++ b/dyngen-exec.h
  @@ -117,7 +117,7 @@ extern int printf(const char *, ...);
  
  /* The return address may point to the start of the next instruction.
 Subtracting one gets us the call instruction itself.  */
  -#if defined(__s390__)
  +#if defined(__s390__)  !defined(__s390x__)
  # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0)  
  0x7fffUL) - 1))
  #elif defined(__arm__)
  /* Thumb return addresses have the low bit set, so we need to subtract two.
  diff --git a/target-s390x/helper.c b/target-s390x/helper.c
  index 4e23b4a..0e222e3 100644
  --- a/target-s390x/helper.c
  +++ b/target-s390x/helper.c
  @@ -44,6 +44,11 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)
  return env;
  }
  
  +target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong 
  addr)
  +{
  +return addr;
  +}
  +
  
  Why does it appear in this patch? It has nothing to do with TCG support.
 
 I don't remember. What is this used for anyways?

If it is not used, maybe it's better to remove it.

  void cpu_reset(CPUS390XState *env)
  {
  if (qemu_loglevel_mask(CPU_LOG_RESET)) {
  diff --git a/tcg/s390/tcg-target.c b/tcg/s390/tcg-target.c
  new file mode 100644
  index 000..53bbf69
  --- /dev/null
  +++ b/tcg/s390/tcg-target.c
  @@ -0,0 +1,103 @@
  +/*
  + * Tiny Code Generator for QEMU
  + *
  + * Copyright (c) 2009 Ulrich Hecht u...@suse.de
  + *
  + * 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.
  + */
  +
  +static const int tcg_target_reg_alloc_order[] = {
  +};
  +
  +static const int tcg_target_call_iarg_regs[] = {
  +};
  +
  +static const int tcg_target_call_oarg_regs[] = {
  +};
  +
  +static void patch_reloc(uint8_t *code_ptr, int type,
  +tcg_target_long value, tcg_target_long addend)
  +{
  +tcg_abort();
  +}
  +
  +static inline int tcg_target_get_call_iarg_regs_count(int flags)
  +{
  +tcg_abort();
  +return 0;
  +}
  +
  +/* parse target specific constraints */
  +static int target_parse_constraint(TCGArgConstraint *ct, const char 
  **pct_str)
  +{
  +tcg_abort();
  +return 0;
  +}
  +
  +/* Test if a constant matches the constraint. */
  +static inline int tcg_target_const_match(tcg_target_long val,
  +const TCGArgConstraint *arg_ct)
  +{
  +tcg_abort();
  +return 0;
  +}
  +
  +/* load a register with an immediate value */
  +static inline void tcg_out_movi(TCGContext *s, TCGType type,
  +int ret, tcg_target_long arg)
  +{
  +tcg_abort();
  +}
  +
  +/* load data without address translation or endianness conversion */
  +static inline void tcg_out_ld(TCGContext *s, TCGType type, int arg,
  +int arg1, tcg_target_long arg2)
  +{
  +tcg_abort();
  +}
  +
  +static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
  +

Re: [Qemu-devel] [PATCH 01/11] S/390 CPU fake emulation

2009-12-02 Thread Aurelien Jarno
On Mon, Nov 30, 2009 at 11:30:04PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
  On Thu, Nov 26, 2009 at 02:23:10PM +0100, Alexander Graf wrote:
  Because Qemu currently requires a TCG target to exist and there are quite 
  some
  useful helpers here to lay the groundwork for out KVM target, let's create 
  a
  stub TCG emulation target for S390X CPUs.
  
  This is required to make tcg happy. The emulation target itself won't work
  though.
  
  Please find the comments below.
  
  Signed-off-by: Alexander Graf ag...@suse.de
  ---
  cpu-exec.c   |2 +
  target-s390x/cpu.h   |  119 
  ++
  target-s390x/exec.h  |   51 
  target-s390x/helper.c|   57 ++
  target-s390x/op_helper.c |   74 
  target-s390x/translate.c |   57 ++
  6 files changed, 360 insertions(+), 0 deletions(-)
  create mode 100644 target-s390x/cpu.h
  create mode 100644 target-s390x/exec.h
  create mode 100644 target-s390x/helper.c
  create mode 100644 target-s390x/op_helper.c
  create mode 100644 target-s390x/translate.c
  
  diff --git a/cpu-exec.c b/cpu-exec.c
  index 2c0765c..af4595b 100644
  --- a/cpu-exec.c
  +++ b/cpu-exec.c
  @@ -249,6 +249,7 @@ int cpu_exec(CPUState *env1)
  #elif defined(TARGET_MIPS)
  #elif defined(TARGET_SH4)
  #elif defined(TARGET_CRIS)
  +#elif defined(TARGET_S390X)
  /* X */
  #else
  #error unsupported target CPU
  @@ -673,6 +674,7 @@ int cpu_exec(CPUState *env1)
  #elif defined(TARGET_SH4)
  #elif defined(TARGET_ALPHA)
  #elif defined(TARGET_CRIS)
  +#elif defined(TARGET_S390X)
  /* X */
  #else
  #error unsupported target CPU
  diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
  new file mode 100644
  index 000..f45b00c
  --- /dev/null
  +++ b/target-s390x/cpu.h
  @@ -0,0 +1,119 @@
  +/*
  + * S/390 virtual CPU header
  + *
  + *  Copyright (c) 2009 Ulrich Hecht
  + *
  + * This library is free software; you can redistribute it and/or
  + * modify it under the terms of the GNU Lesser General Public
  + * License as published by the Free Software Foundation; either
  + * version 2 of the License, or (at your option) any later version.
  + *
  + * This library is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this library; if not, write to the Free Software
  + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  
  02110-1301 USA
  + */
  +#ifndef CPU_S390X_H
  +#define CPU_S390X_H
  +
  +#define TARGET_LONG_BITS 64
  +
  +#define ELF_MACHINE   EM_S390
  +
  +#define CPUState struct CPUS390XState
  +
  +#include cpu-defs.h
  +
  +#include softfloat.h
  +
  +#define NB_MMU_MODES 2 // guess
  +#define MMU_USER_IDX 0 // guess
  +
  +typedef union FPReg {
  +struct {
  +#ifdef WORDS_BIGENDIAN
  +float32 e;
  +int32_t __pad;
  +#else
  +int32_t __pad;
  +float32 e;
  +#endif
  +};
  +float64 d;
  +uint64_t i;
  +} FPReg;
  +
  +typedef struct CPUS390XState {
  +uint64_t regs[16];/* GP registers */
  +
  +uint32_t aregs[16];   /* access registers */
  +
  +uint32_t fpc; /* floating-point control register */
  +FPReg fregs[16]; /* FP registers */
  +float_status fpu_status; /* passed to softfloat lib */
  +
  +struct {
  +uint64_t mask;
  +uint64_t addr;
  +} psw;
  +
  +int cc; /* condition code (0-3) */
  +
  +uint64_t __excp_addr;
  +
  +CPU_COMMON
  +} CPUS390XState;
  +
  +#if defined(CONFIG_USER_ONLY)
  +static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
  +{
  +if (newsp)
  +env-regs[15] = newsp;
  
  Coding style.
  
  +env-regs[0] = 0;
  +}
  +#endif
  +
  +CPUS390XState *cpu_s390x_init(const char *cpu_model);
  +int cpu_s390x_exec(CPUS390XState *s);
  +void cpu_s390x_close(CPUS390XState *s);
  +
  +/* you can call this signal handler from your SIGBUS and SIGSEGV
  +   signal handlers to inform the virtual CPU of exceptions. non zero
  +   is returned if the signal was handled by the virtual CPU.  */
  +int cpu_s390x_signal_handler(int host_signum, void *pinfo,
  +   void *puc);
  +int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, 
  int rw,
  +  int mmu_idx, int is_softmuu);
  +#define cpu_handle_mmu_fault cpu_s390x_handle_mmu_fault
  +
  +#define TARGET_PAGE_BITS 12
  +
  +#define cpu_init cpu_s390x_init
  +#define cpu_exec cpu_s390x_exec
  +#define cpu_gen_code cpu_s390x_gen_code
  +
  +#include cpu-all.h
  +#include exec-all.h
  +
  +#define 

Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread Aurelien Jarno
On Tue, Dec 01, 2009 at 12:47:36PM +0100, Alexander Graf wrote:
 Hi,

 Could someone with commit rights please stand up to feel responsible for 
 PPC?

 Usually, when I send a patch to qemu-devel, I know who to address to  
 increase chances of it getting committed. For kvm/vnc/block I just CC  
 Anthony, for Audio I just CC malc, etc.

 There are some subsystems where nobody feels responsible though,  
 apparently hoping 'someone else' will tske on it. Well, turns out it  
 doesn't work that way.

 So could we please assign a committer for every subsystem around? Even  
 if the committer doesn't know the architecture inside out, it's still  
 valuable to have soneone feel responsible at all. Committer and  
 maintainer also don't have to be the same person. I'll gladly maintain  
 S390 without having commit rights - as long as I have someone to CC and 
 know the patches will get merged.


I also try to follow the ppc architecture, though less than mips and
also depending on my free time. I know that Blue Swirl and Malc also
care about it.

It's not impossible that I miss patches given the current patches rate
on the mailing list, so don't hesitate to Cc: me. On the other hand, I
don't really feel comfortable with KVM related patches, I would prefer
to see them committed by Anthony.

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




Re: [Qemu-devel] [PATCH 06/11] Add support for S390x system emulation

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:09, Aurelien Jarno wrote:

 On Mon, Nov 30, 2009 at 11:19:06PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
 On Thu, Nov 26, 2009 at 02:23:15PM +0100, Alexander Graf wrote:
 Let's enable the basics for system emulation so we can run virtual machines
 with KVM!
 
 I don't really understand while this whole patch is not merged in patch
 number 1. Otherwise, please find the comments below.
 
 Historical reasons. To keep Uli's stripped down version separate from my 
 code.
 
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 target-s390x/cpu.h|  153 
 -
 target-s390x/exec.h   |5 +
 target-s390x/helper.c |   22 +
 target-s390x/machine.c|   30 +++
 4 files changed, 208 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/s390x-softmmu.mak
 create mode 100644 target-s390x/machine.c
 
 diff --git a/default-configs/s390x-softmmu.mak 
 b/default-configs/s390x-softmmu.mak
 new file mode 100644
 index 000..e69de29
 diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
 index f45b00c..a74745c 100644
 --- a/target-s390x/cpu.h
 +++ b/target-s390x/cpu.h
 @@ -30,8 +30,7 @@
 
 #include softfloat.h
 
 -#define NB_MMU_MODES 2 // guess
 -#define MMU_USER_IDX 0 // guess
 +#define NB_MMU_MODES 2
 
 typedef union FPReg {
struct {
 @@ -77,6 +76,15 @@ static inline void cpu_clone_regs(CPUState *env, 
 target_ulong newsp)
 }
 #endif
 
 +#define MMU_MODE0_SUFFIX _kernel
 +#define MMU_MODE1_SUFFIX _user
 +#define MMU_USER_IDX 1
 +static inline int cpu_mmu_index (CPUState *env)
 +{
 +/* XXX: Currently we don't implement virtual memory */
 +return 0;
 
 Is it correct? It means that memory access will aways be kernel memory
 accesses. IIRC, even with KVM enabled, softmmu accesses are possible in
 some cases (devices ?).
 
 I can't imagine any hardware using the CPU's MMU to write to RAM. That's 
 what IOMMUs are for.
 
 The only 2 consumers are:
 
 1) tcg
 2) gdb / monitor
 
 With 2) being broken, because we can't resolve virtual addresses to physical 
 addresses. But that won't change until someone implements the softmmu 
 emulation target for real.
 
 If it is sure it is never used, I would prefer to see an abort().
 Otherwise it's fine.

I don't think I understand where you want to put the abort().

Alex



Re: [Qemu-devel] [PATCH 04/11] Add KVM support for S390x

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:12, Aurelien Jarno wrote:

 On Mon, Nov 30, 2009 at 11:25:03PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
 On Thu, Nov 26, 2009 at 02:23:13PM +0100, Alexander Graf wrote:
 S390x was one of the first platforms that received support for KVM back in 
 the
 day. Unfortunately until now there hasn't been a qemu implementation that 
 would
 enable users to actually run guests.
 
 So let's include support for KVM S390x in qemu!
 
 Please find the comments below.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 configure  |4 +-
 target-s390x/kvm.c |  463 
 
 2 files changed, 466 insertions(+), 1 deletions(-)
 create mode 100644 target-s390x/kvm.c
 
 diff --git a/configure b/configure
 index b616e1a..cf466ec 100755
 --- a/configure
 +++ b/configure
 @@ -1348,6 +1348,8 @@ EOF
kvm_cflags=$kvm_cflags -I$kerneldir/arch/x86/include
elif test $cpu = ppc -a -d $kerneldir/arch/powerpc/include ; then
kvm_cflags=$kvm_cflags -I$kerneldir/arch/powerpc/include
 +  elif test $cpu = s390x -a -d $kerneldir/arch/s390/include ; then
 +  kvm_cflags=$kvm_cflags -I$kerneldir/arch/s390/include
elif test -d $kerneldir/arch/$cpu/include ; then
kvm_cflags=$kvm_cflags -I$kerneldir/arch/$cpu/include
  fi
 @@ -2360,7 +2362,7 @@ case $target_arch2 in
fi
 esac
 case $target_arch2 in
 -  i386|x86_64|ppcemb|ppc|ppc64)
 +  i386|x86_64|ppcemb|ppc|ppc64|s390x)
# Make sure the target and host cpus are compatible
if test $kvm = yes -a $target_softmmu = yes -a \
  \( $target_arch2 = $cpu -o \
 diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
 new file mode 100644
 index 000..d477664
 --- /dev/null
 +++ b/target-s390x/kvm.c
 @@ -0,0 +1,463 @@
 +/*
 + * QEMU S390x KVM implementation
 + *
 + * Copyright (c) 2009 Alexander Graf ag...@suse.de
 + *
 + * This library is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2 of the License, or (at your option) any later version.
 + *
 + * This library is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with this library; if not, see 
 http://www.gnu.org/licenses/.
 + */
 +
 +#include sys/types.h
 +#include sys/ioctl.h
 +#include sys/mman.h
 +
 +#include linux/kvm.h
 +#include asm/ptrace.h
 +
 +#include qemu-common.h
 +#include qemu-timer.h
 +#include sysemu.h
 +#include kvm.h
 +#include cpu.h
 +#include device_tree.h
 +
 +/* #define DEBUG_KVM */
 +
 +#ifdef DEBUG_KVM
 +#define dprintf(fmt, ...) \
 +do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
 +#else
 +#define dprintf(fmt, ...) \
 +do { } while (0)
 +#endif
 +
 +#define IPA0_DIAG   0x8300
 +#define IPA0_SIGP   0xae00
 +#define IPA0_PRIV   0xb200
 +
 +#define PRIV_SCLP_CALL  0x20
 +#define DIAG_KVM_HYPERCALL  0x500
 +#define DIAG_KVM_BREAKPOINT 0x501
 +
 +#define SCP_LENGTH  0x00
 +#define SCP_FUNCTION_CODE   0x02
 +#define SCP_CONTROL_MASK0x03
 +#define SCP_RESPONSE_CODE   0x06
 +#define SCP_MEM_CODE0x08
 +#define SCP_INCREMENT   0x0a
 +
 +#define ICPT_INSTRUCTION0x04
 +#define ICPT_WAITPSW0x1c
 +#define ICPT_SOFT_INTERCEPT 0x24
 +#define ICPT_CPU_STOP   0x28
 +#define ICPT_IO 0x40
 +
 +#define SIGP_RESTART0x06
 +#define SIGP_INITIAL_CPU_RESET  0x0b
 +#define SIGP_STORE_STATUS_ADDR  0x0e
 +#define SIGP_SET_ARCH   0x12
 +
 +
 +int kvm_arch_init(KVMState *s, int smp_cpus)
 +{
 +return 0;
 +}
 +
 +int kvm_arch_init_vcpu(CPUState *env)
 +{
 +int ret = 0;
 +
 +if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL)  0)
 +perror(cannot init reset vcpu);
 
 coding style.
 
 +
 +return ret;
 +}
 +
 +void kvm_arch_reset_vcpu(CPUState *env)
 +{
 +}
 
 Is there really nothing to do? If some code has to be added later, it
 may be worth adding a comment.
 
 As you have probably realized by now, all reset code is missing. In fact, we 
 don't even ever call the qemu reset functions to actually do a reset.
 
 Can you make it clean with an abort?
 
 +
 +static void _kvm_s390_interrupt(CPUState *env, int type, uint32_t parm, 
 uint64_t parm64, int vm)
 +{
 
 Why such a name starting with an underscore?
 
 Because that's the internal function that gets used by the exported, 
 properly named ones. Are there any conventions on how to declare private 
 functions?
 
 I don't think there is any convention, but I know malc always complains
 about not introducing 

Re: [Qemu-devel] [PATCH 03/11] S/390 fake TCG implementation

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:16, Aurelien Jarno wrote:

 On Mon, Nov 30, 2009 at 11:27:53PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
 On Thu, Nov 26, 2009 at 02:23:12PM +0100, Alexander Graf wrote:
 Qemu won't let us run a KVM target without having host TCG support. Well, 
 for
 now we don't have any so let's implement a fake target that only stubs out
 everything.
 
 I tried to keep the patch as close to Uli's source as possible, so whenever
 he feels like it he can easily diff his version against this one.
 
 Please find the comments below.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 dyngen-exec.h |2 +-
 target-s390x/helper.c |5 ++
 tcg/s390/tcg-target.c |  103 
 +
 tcg/s390/tcg-target.h |   48 +++
 4 files changed, 157 insertions(+), 1 deletions(-)
 create mode 100644 tcg/s390/tcg-target.c
 create mode 100644 tcg/s390/tcg-target.h
 
 diff --git a/dyngen-exec.h b/dyngen-exec.h
 index 86e61c3..0353f36 100644
 --- a/dyngen-exec.h
 +++ b/dyngen-exec.h
 @@ -117,7 +117,7 @@ extern int printf(const char *, ...);
 
 /* The return address may point to the start of the next instruction.
   Subtracting one gets us the call instruction itself.  */
 -#if defined(__s390__)
 +#if defined(__s390__)  !defined(__s390x__)
 # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0)  
 0x7fffUL) - 1))
 #elif defined(__arm__)
 /* Thumb return addresses have the low bit set, so we need to subtract two.
 diff --git a/target-s390x/helper.c b/target-s390x/helper.c
 index 4e23b4a..0e222e3 100644
 --- a/target-s390x/helper.c
 +++ b/target-s390x/helper.c
 @@ -44,6 +44,11 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)
return env;
 }
 
 +target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong 
 addr)
 +{
 +return addr;
 +}
 +
 
 Why does it appear in this patch? It has nothing to do with TCG support.
 
 I don't remember. What is this used for anyways?
 
 If it is not used, maybe it's better to remove it.

It's called from exec.c.

 
 void cpu_reset(CPUS390XState *env)
 {
if (qemu_loglevel_mask(CPU_LOG_RESET)) {
 diff --git a/tcg/s390/tcg-target.c b/tcg/s390/tcg-target.c
 new file mode 100644
 index 000..53bbf69
 --- /dev/null
 +++ b/tcg/s390/tcg-target.c
 @@ -0,0 +1,103 @@
 +/*
 + * Tiny Code Generator for QEMU
 + *
 + * Copyright (c) 2009 Ulrich Hecht u...@suse.de
 + *
 + * 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.
 + */
 +
 +static const int tcg_target_reg_alloc_order[] = {
 +};
 +
 +static const int tcg_target_call_iarg_regs[] = {
 +};
 +
 +static const int tcg_target_call_oarg_regs[] = {
 +};
 +
 +static void patch_reloc(uint8_t *code_ptr, int type,
 +tcg_target_long value, tcg_target_long addend)
 +{
 +tcg_abort();
 +}
 +
 +static inline int tcg_target_get_call_iarg_regs_count(int flags)
 +{
 +tcg_abort();
 +return 0;
 +}
 +
 +/* parse target specific constraints */
 +static int target_parse_constraint(TCGArgConstraint *ct, const char 
 **pct_str)
 +{
 +tcg_abort();
 +return 0;
 +}
 +
 +/* Test if a constant matches the constraint. */
 +static inline int tcg_target_const_match(tcg_target_long val,
 +const TCGArgConstraint *arg_ct)
 +{
 +tcg_abort();
 +return 0;
 +}
 +
 +/* load a register with an immediate value */
 +static inline void tcg_out_movi(TCGContext *s, TCGType type,
 +int ret, tcg_target_long arg)
 +{
 +tcg_abort();
 +}
 +
 +/* load data without address translation or endianness conversion */
 +static inline void tcg_out_ld(TCGContext *s, TCGType type, int arg,
 +int arg1, tcg_target_long arg2)
 +{
 +tcg_abort();
 +}
 +
 +static inline void tcg_out_st(TCGContext *s, TCGType type, int arg,
 +  int arg1, tcg_target_long arg2)
 +{
 +tcg_abort();
 +}
 +
 

Re: [Qemu-devel] [PATCH 01/11] S/390 CPU fake emulation

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:17, Aurelien Jarno wrote:

 On Mon, Nov 30, 2009 at 11:30:04PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
 On Thu, Nov 26, 2009 at 02:23:10PM +0100, Alexander Graf wrote:
 Because Qemu currently requires a TCG target to exist and there are quite 
 some
 useful helpers here to lay the groundwork for out KVM target, let's create 
 a
 stub TCG emulation target for S390X CPUs.
 
 This is required to make tcg happy. The emulation target itself won't work
 though.
 
 Please find the comments below.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 cpu-exec.c   |2 +
 target-s390x/cpu.h   |  119 
 ++
 target-s390x/exec.h  |   51 
 target-s390x/helper.c|   57 ++
 target-s390x/op_helper.c |   74 
 target-s390x/translate.c |   57 ++
 6 files changed, 360 insertions(+), 0 deletions(-)
 create mode 100644 target-s390x/cpu.h
 create mode 100644 target-s390x/exec.h
 create mode 100644 target-s390x/helper.c
 create mode 100644 target-s390x/op_helper.c
 create mode 100644 target-s390x/translate.c
 
 diff --git a/cpu-exec.c b/cpu-exec.c
 index 2c0765c..af4595b 100644
 --- a/cpu-exec.c
 +++ b/cpu-exec.c
 @@ -249,6 +249,7 @@ int cpu_exec(CPUState *env1)
 #elif defined(TARGET_MIPS)
 #elif defined(TARGET_SH4)
 #elif defined(TARGET_CRIS)
 +#elif defined(TARGET_S390X)
/* X */
 #else
 #error unsupported target CPU
 @@ -673,6 +674,7 @@ int cpu_exec(CPUState *env1)
 #elif defined(TARGET_SH4)
 #elif defined(TARGET_ALPHA)
 #elif defined(TARGET_CRIS)
 +#elif defined(TARGET_S390X)
/* X */
 #else
 #error unsupported target CPU
 diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
 new file mode 100644
 index 000..f45b00c
 --- /dev/null
 +++ b/target-s390x/cpu.h
 @@ -0,0 +1,119 @@
 +/*
 + * S/390 virtual CPU header
 + *
 + *  Copyright (c) 2009 Ulrich Hecht
 + *
 + * This library is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2 of the License, or (at your option) any later version.
 + *
 + * This library is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with this library; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  
 02110-1301 USA
 + */
 +#ifndef CPU_S390X_H
 +#define CPU_S390X_H
 +
 +#define TARGET_LONG_BITS 64
 +
 +#define ELF_MACHINE   EM_S390
 +
 +#define CPUState struct CPUS390XState
 +
 +#include cpu-defs.h
 +
 +#include softfloat.h
 +
 +#define NB_MMU_MODES 2 // guess
 +#define MMU_USER_IDX 0 // guess
 +
 +typedef union FPReg {
 +struct {
 +#ifdef WORDS_BIGENDIAN
 +float32 e;
 +int32_t __pad;
 +#else
 +int32_t __pad;
 +float32 e;
 +#endif
 +};
 +float64 d;
 +uint64_t i;
 +} FPReg;
 +
 +typedef struct CPUS390XState {
 +uint64_t regs[16];/* GP registers */
 +
 +uint32_t aregs[16];   /* access registers */
 +
 +uint32_t fpc; /* floating-point control register */
 +FPReg fregs[16]; /* FP registers */
 +float_status fpu_status; /* passed to softfloat lib */
 +
 +struct {
 +uint64_t mask;
 +uint64_t addr;
 +} psw;
 +
 +int cc; /* condition code (0-3) */
 +
 +uint64_t __excp_addr;
 +
 +CPU_COMMON
 +} CPUS390XState;
 +
 +#if defined(CONFIG_USER_ONLY)
 +static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
 +{
 +if (newsp)
 +env-regs[15] = newsp;
 
 Coding style.
 
 +env-regs[0] = 0;
 +}
 +#endif
 +
 +CPUS390XState *cpu_s390x_init(const char *cpu_model);
 +int cpu_s390x_exec(CPUS390XState *s);
 +void cpu_s390x_close(CPUS390XState *s);
 +
 +/* you can call this signal handler from your SIGBUS and SIGSEGV
 +   signal handlers to inform the virtual CPU of exceptions. non zero
 +   is returned if the signal was handled by the virtual CPU.  */
 +int cpu_s390x_signal_handler(int host_signum, void *pinfo,
 +   void *puc);
 +int cpu_s390x_handle_mmu_fault (CPUS390XState *env, target_ulong address, 
 int rw,
 +  int mmu_idx, int is_softmuu);
 +#define cpu_handle_mmu_fault cpu_s390x_handle_mmu_fault
 +
 +#define TARGET_PAGE_BITS 12
 +
 +#define cpu_init cpu_s390x_init
 +#define cpu_exec cpu_s390x_exec
 +#define cpu_gen_code cpu_s390x_gen_code
 +
 +#include cpu-all.h
 +#include exec-all.h
 +
 +#define EXCP_OPEX 1 /* operation exception (sigill) */
 +#define EXCP_SVC 2 /* supervisor call (syscall) */
 +#define 

Re: [Qemu-devel] [PATCH] experimental sh4 host support V2

2009-12-02 Thread Aurelien Jarno
On Sun, Nov 15, 2009 at 08:53:55PM +0900, Magnus Damm wrote:
 From: Magnus Damm d...@opensource.se
 
 This is V2 of the QEMU sh4 host support patch.
 
 The code is of a somewhat experimental nature, which means that
 only the bare essentials are in place. The sh4 host support has
 been tested with the sh4 target inside the QEMU sh4 user space
 emulator. Only tiny assembly snippets has been tested so far, but
 at least syscalls and some branches seem ok at this point. Both
 big and little endian hosts are supported, but 64-bit targets and
 softmmu are still on the TODO list. The icache handling needs more
 work as well.

Hi,

I have started to review this patch, but I don't know when I'll have
time to finish the review. I'll try to do it before the end of the week.

Cheers,
Aurelien

 Signed-off-by: Magnus Damm d...@opensource.se
 ---
 
  Changes since V2:
   Renamed __function_name() - tcg_sh4_function_name()
 
  configure|   11 
  cpu-exec.c   |   15 
  dyngen-exec.h|4 
  exec-all.h   |9 
  tcg/sh4/tcg-target.c |  868 
 ++
  tcg/sh4/tcg-target.h |   65 +++
  6 files changed, 970 insertions(+), 2 deletions(-)
 
 --- 0001/configure
 +++ work/configure2009-11-15 20:19:22.0 +0900
 @@ -134,13 +134,19 @@ elif check_define _ARCH_PPC ; then
else
  cpu=ppc
fi
 +elif check_define __SH4__ ; then
 +  if check_define __BIG_ENDIAN__ ; then
 +cpu=sh4eb
 +  else
 +cpu=sh4
 +  fi
  else
cpu=`uname -m`
  fi
  
  target_list=
  case $cpu in
 -  alpha|cris|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|sparc64)
 +  alpha|cris|ia64|m68k|microblaze|mips|mips64|ppc|ppc64|sh4|sh4eb|sparc64)
  cpu=$cpu
;;
i386|i486|i586|i686|i86pc|BePC)
 @@ -1878,6 +1884,9 @@ case $cpu in
armv4b|armv4l)
  ARCH=arm
;;
 +  sh4|sh4eb)
 +ARCH=sh4
 +  ;;
*)
  echo Unsupported CPU = $cpu
  exit 1
 --- 0001/cpu-exec.c
 +++ work/cpu-exec.c   2009-11-15 20:19:22.0 +0900
 @@ -1190,6 +1190,21 @@ int cpu_signal_handler(int host_signum, 
   uc-uc_sigmask, puc);
  }
  
 +#elif defined(__SH4__)
 +
 +int cpu_signal_handler(int host_signum, void *pinfo,
 +   void *puc)
 +{
 +siginfo_t *info = pinfo;
 +struct ucontext *uc = puc;
 +greg_t pc = uc-uc_mcontext.pc;
 +int is_write;
 +
 +/* XXX: compute is_write */
 +is_write = 0;
 +return handle_cpu_signal(pc, (unsigned long)info-si_addr,
 + is_write, uc-uc_sigmask, puc);
 +}
  #else
  
  #error host CPU specific signal handler needed
 --- 0001/dyngen-exec.h
 +++ work/dyngen-exec.h2009-11-15 20:19:22.0 +0900
 @@ -106,6 +106,10 @@ extern int printf(const char *, ...);
  #define AREG0 r7
  #define AREG1 r4
  #define AREG2 r5
 +#elif defined(__SH4__)
 +#define AREG0 r11
 +#define AREG1 r12
 +#define AREG2 r13
  #else
  #error unsupported CPU
  #endif
 --- 0001/exec-all.h
 +++ work/exec-all.h   2009-11-15 20:19:22.0 +0900
 @@ -114,7 +114,7 @@ static inline int tlb_set_page(CPUState 
  #define CODE_GEN_AVG_BLOCK_SIZE 64
  #endif
  
 -#if defined(_ARCH_PPC) || defined(__x86_64__) || defined(__arm__) || 
 defined(__i386__)
 +#if defined(_ARCH_PPC) || defined(__x86_64__) || defined(__arm__) || 
 defined(__i386__) || defined(__SH4__)
  #define USE_DIRECT_JUMP
  #endif
  
 @@ -189,6 +189,13 @@ extern int code_gen_max_blocks;
  #if defined(_ARCH_PPC)
  extern void ppc_tb_set_jmp_target(unsigned long jmp_addr, unsigned long 
 addr);
  #define tb_set_jmp_target1 ppc_tb_set_jmp_target
 +#elif defined(__SH4__)
 +static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long 
 addr)
 +{
 +/* patch the branch destination */
 +*(uint32_t *)jmp_addr = addr;
 +/* FIXME: need to handle caches */
 +}
  #elif defined(__i386__) || defined(__x86_64__)
  static inline void tb_set_jmp_target1(unsigned long jmp_addr, unsigned long 
 addr)
  {
 --- /dev/null
 +++ work/tcg/sh4/tcg-target.c 2009-11-15 20:33:01.0 +0900
 @@ -0,0 +1,868 @@
 +/*
 + * Tiny Code Generator for QEMU
 + *
 + * Copyright (c) 2008 Fabrice Bellard
 + * Copyright (c) 2009 Magnus Damm
 + *
 + * 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,
 + * 

Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:26, Aurelien Jarno wrote:

 On Tue, Dec 01, 2009 at 12:47:36PM +0100, Alexander Graf wrote:
 Hi,
 
 Could someone with commit rights please stand up to feel responsible for 
 PPC?
 
 Usually, when I send a patch to qemu-devel, I know who to address to  
 increase chances of it getting committed. For kvm/vnc/block I just CC  
 Anthony, for Audio I just CC malc, etc.
 
 There are some subsystems where nobody feels responsible though,  
 apparently hoping 'someone else' will tske on it. Well, turns out it  
 doesn't work that way.
 
 So could we please assign a committer for every subsystem around? Even  
 if the committer doesn't know the architecture inside out, it's still  
 valuable to have soneone feel responsible at all. Committer and  
 maintainer also don't have to be the same person. I'll gladly maintain  
 S390 without having commit rights - as long as I have someone to CC and 
 know the patches will get merged.
 
 
 I also try to follow the ppc architecture, though less than mips and
 also depending on my free time. I know that Blue Swirl and Malc also
 care about it.

Right - which makes it pretty hard. IMHO it's always best to have a single 
person to talk to when it comes to committing and others who comment on patches.

In fact, I even believe that the person committing stuff doesn't have to know 
the stuff he commits. If I make a patch that breaks S390 and someone commits 
it, it's my fault breaking it - not the committer's. If I do a patch breaking 
PPC KVM, it's my fault breaking it, not the committer's. And with fault I also 
mean responsibility to fix.

 It's not impossible that I miss patches given the current patches rate
 on the mailing list, so don't hesitate to Cc: me. On the other hand, I
 don't really feel comfortable with KVM related patches, I would prefer
 to see them committed by Anthony.

Avi, can I get PPC KVM patches in through you then? I guess you're the closest 
person to the code in question.

Alex



Re: [Qemu-devel] [PATCH 06/11] Add support for S390x system emulation

2009-12-02 Thread Aurelien Jarno
On Wed, Dec 02, 2009 at 09:27:21AM +0100, Alexander Graf wrote:
 
 On 02.12.2009, at 09:09, Aurelien Jarno wrote:
 
  On Mon, Nov 30, 2009 at 11:19:06PM +0100, Alexander Graf wrote:
  
  On 30.11.2009, at 19:18, Aurelien Jarno wrote:
  
  On Thu, Nov 26, 2009 at 02:23:15PM +0100, Alexander Graf wrote:
  Let's enable the basics for system emulation so we can run virtual 
  machines
  with KVM!
  
  I don't really understand while this whole patch is not merged in patch
  number 1. Otherwise, please find the comments below.
  
  Historical reasons. To keep Uli's stripped down version separate from my 
  code.
  
  
  Signed-off-by: Alexander Graf ag...@suse.de
  ---
  target-s390x/cpu.h|  153 
  -
  target-s390x/exec.h   |5 +
  target-s390x/helper.c |   22 +
  target-s390x/machine.c|   30 +++
  4 files changed, 208 insertions(+), 2 deletions(-)
  create mode 100644 default-configs/s390x-softmmu.mak
  create mode 100644 target-s390x/machine.c
  
  diff --git a/default-configs/s390x-softmmu.mak 
  b/default-configs/s390x-softmmu.mak
  new file mode 100644
  index 000..e69de29
  diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
  index f45b00c..a74745c 100644
  --- a/target-s390x/cpu.h
  +++ b/target-s390x/cpu.h
  @@ -30,8 +30,7 @@
  
  #include softfloat.h
  
  -#define NB_MMU_MODES 2 // guess
  -#define MMU_USER_IDX 0 // guess
  +#define NB_MMU_MODES 2
  
  typedef union FPReg {
 struct {
  @@ -77,6 +76,15 @@ static inline void cpu_clone_regs(CPUState *env, 
  target_ulong newsp)
  }
  #endif
  
  +#define MMU_MODE0_SUFFIX _kernel
  +#define MMU_MODE1_SUFFIX _user
  +#define MMU_USER_IDX 1
  +static inline int cpu_mmu_index (CPUState *env)
  +{
  +/* XXX: Currently we don't implement virtual memory */
  +return 0;
  
  Is it correct? It means that memory access will aways be kernel memory
  accesses. IIRC, even with KVM enabled, softmmu accesses are possible in
  some cases (devices ?).
  
  I can't imagine any hardware using the CPU's MMU to write to RAM. That's 
  what IOMMUs are for.
  
  The only 2 consumers are:
  
  1) tcg
  2) gdb / monitor
  
  With 2) being broken, because we can't resolve virtual addresses to 
  physical addresses. But that won't change until someone implements the 
  softmmu emulation target for real.
  
  If it is sure it is never used, I would prefer to see an abort().
  Otherwise it's fine.
 
 I don't think I understand where you want to put the abort().
 

In inline cpu_mmu_index(), just before the return, to make sure this
function is never called, as it is clearly wrong.

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




Re: [Qemu-devel] [PATCH 06/11] Add support for S390x system emulation

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:37, Aurelien Jarno wrote:

 On Wed, Dec 02, 2009 at 09:27:21AM +0100, Alexander Graf wrote:
 
 On 02.12.2009, at 09:09, Aurelien Jarno wrote:
 
 On Mon, Nov 30, 2009 at 11:19:06PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
 On Thu, Nov 26, 2009 at 02:23:15PM +0100, Alexander Graf wrote:
 Let's enable the basics for system emulation so we can run virtual 
 machines
 with KVM!
 
 I don't really understand while this whole patch is not merged in patch
 number 1. Otherwise, please find the comments below.
 
 Historical reasons. To keep Uli's stripped down version separate from my 
 code.
 
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 target-s390x/cpu.h|  153 
 -
 target-s390x/exec.h   |5 +
 target-s390x/helper.c |   22 +
 target-s390x/machine.c|   30 +++
 4 files changed, 208 insertions(+), 2 deletions(-)
 create mode 100644 default-configs/s390x-softmmu.mak
 create mode 100644 target-s390x/machine.c
 
 diff --git a/default-configs/s390x-softmmu.mak 
 b/default-configs/s390x-softmmu.mak
 new file mode 100644
 index 000..e69de29
 diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
 index f45b00c..a74745c 100644
 --- a/target-s390x/cpu.h
 +++ b/target-s390x/cpu.h
 @@ -30,8 +30,7 @@
 
 #include softfloat.h
 
 -#define NB_MMU_MODES 2 // guess
 -#define MMU_USER_IDX 0 // guess
 +#define NB_MMU_MODES 2
 
 typedef union FPReg {
   struct {
 @@ -77,6 +76,15 @@ static inline void cpu_clone_regs(CPUState *env, 
 target_ulong newsp)
 }
 #endif
 
 +#define MMU_MODE0_SUFFIX _kernel
 +#define MMU_MODE1_SUFFIX _user
 +#define MMU_USER_IDX 1
 +static inline int cpu_mmu_index (CPUState *env)
 +{
 +/* XXX: Currently we don't implement virtual memory */
 +return 0;
 
 Is it correct? It means that memory access will aways be kernel memory
 accesses. IIRC, even with KVM enabled, softmmu accesses are possible in
 some cases (devices ?).
 
 I can't imagine any hardware using the CPU's MMU to write to RAM. That's 
 what IOMMUs are for.
 
 The only 2 consumers are:
 
 1) tcg
 2) gdb / monitor
 
 With 2) being broken, because we can't resolve virtual addresses to 
 physical addresses. But that won't change until someone implements the 
 softmmu emulation target for real.
 
 If it is sure it is never used, I would prefer to see an abort().
 Otherwise it's fine.
 
 I don't think I understand where you want to put the abort().
 
 
 In inline cpu_mmu_index(), just before the return, to make sure this
 function is never called, as it is clearly wrong.

It's just always saying we're in kernel mode. I don't see where that's wrong. 
There's no logic to implement modes, so that's the only reasonable thing to do.

Also, it does get called. That's what I mean with the target 2). When you're in 
the monitor and do x /i $pc, you end up calling that function. While it's not 
great to only have linear mapped memory here, it's a lot better than having no 
reply or, even worse, killing the VM.

Alex



Re: [Qemu-devel] [PATCH 03/11] S/390 fake TCG implementation

2009-12-02 Thread Aurelien Jarno
On Wed, Dec 02, 2009 at 09:29:59AM +0100, Alexander Graf wrote:
 
 On 02.12.2009, at 09:16, Aurelien Jarno wrote:
 
  On Mon, Nov 30, 2009 at 11:27:53PM +0100, Alexander Graf wrote:
  
  On 30.11.2009, at 19:18, Aurelien Jarno wrote:
  
  On Thu, Nov 26, 2009 at 02:23:12PM +0100, Alexander Graf wrote:
  Qemu won't let us run a KVM target without having host TCG support. 
  Well, for
  now we don't have any so let's implement a fake target that only stubs 
  out
  everything.
  
  I tried to keep the patch as close to Uli's source as possible, so 
  whenever
  he feels like it he can easily diff his version against this one.
  
  Please find the comments below.
  
  Signed-off-by: Alexander Graf ag...@suse.de
  ---
  dyngen-exec.h |2 +-
  target-s390x/helper.c |5 ++
  tcg/s390/tcg-target.c |  103 
  +
  tcg/s390/tcg-target.h |   48 +++
  4 files changed, 157 insertions(+), 1 deletions(-)
  create mode 100644 tcg/s390/tcg-target.c
  create mode 100644 tcg/s390/tcg-target.h
  
  diff --git a/dyngen-exec.h b/dyngen-exec.h
  index 86e61c3..0353f36 100644
  --- a/dyngen-exec.h
  +++ b/dyngen-exec.h
  @@ -117,7 +117,7 @@ extern int printf(const char *, ...);
  
  /* The return address may point to the start of the next instruction.
Subtracting one gets us the call instruction itself.  */
  -#if defined(__s390__)
  +#if defined(__s390__)  !defined(__s390x__)
  # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0)  
  0x7fffUL) - 1))
  #elif defined(__arm__)
  /* Thumb return addresses have the low bit set, so we need to subtract 
  two.
  diff --git a/target-s390x/helper.c b/target-s390x/helper.c
  index 4e23b4a..0e222e3 100644
  --- a/target-s390x/helper.c
  +++ b/target-s390x/helper.c
  @@ -44,6 +44,11 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)
 return env;
  }
  
  +target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong 
  addr)
  +{
  +return addr;
  +}
  +
  
  Why does it appear in this patch? It has nothing to do with TCG support.
  
  I don't remember. What is this used for anyways?
  
  If it is not used, maybe it's better to remove it.
 
 It's called from exec.c.

Then it's clearly not part of this patch, it should probably be part of
patch 1 or 6 instead.

  
  void cpu_reset(CPUS390XState *env)
  {
 if (qemu_loglevel_mask(CPU_LOG_RESET)) {
  diff --git a/tcg/s390/tcg-target.c b/tcg/s390/tcg-target.c
  new file mode 100644
  index 000..53bbf69
  --- /dev/null
  +++ b/tcg/s390/tcg-target.c
  @@ -0,0 +1,103 @@
  +/*
  + * Tiny Code Generator for QEMU
  + *
  + * Copyright (c) 2009 Ulrich Hecht u...@suse.de
  + *
  + * 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.
  + */
  +
  +static const int tcg_target_reg_alloc_order[] = {
  +};
  +
  +static const int tcg_target_call_iarg_regs[] = {
  +};
  +
  +static const int tcg_target_call_oarg_regs[] = {
  +};
  +
  +static void patch_reloc(uint8_t *code_ptr, int type,
  +tcg_target_long value, tcg_target_long addend)
  +{
  +tcg_abort();
  +}
  +
  +static inline int tcg_target_get_call_iarg_regs_count(int flags)
  +{
  +tcg_abort();
  +return 0;
  +}
  +
  +/* parse target specific constraints */
  +static int target_parse_constraint(TCGArgConstraint *ct, const char 
  **pct_str)
  +{
  +tcg_abort();
  +return 0;
  +}
  +
  +/* Test if a constant matches the constraint. */
  +static inline int tcg_target_const_match(tcg_target_long val,
  +const TCGArgConstraint *arg_ct)
  +{
  +tcg_abort();
  +return 0;
  +}
  +
  +/* load a register with an immediate value */
  +static inline void tcg_out_movi(TCGContext *s, TCGType type,
  +int ret, tcg_target_long arg)
  +{
  +tcg_abort();
  +}
  +
  +/* load data without address translation or endianness 

Re: [Qemu-devel] [PATCH 04/11] Add KVM support for S390x

2009-12-02 Thread malc
On Wed, 2 Dec 2009, Alexander Graf wrote:

 
 On 02.12.2009, at 09:12, Aurelien Jarno wrote:
 
  On Mon, Nov 30, 2009 at 11:25:03PM +0100, Alexander Graf wrote:
  
  On 30.11.2009, at 19:18, Aurelien Jarno wrote:
  
  On Thu, Nov 26, 2009 at 02:23:13PM +0100, Alexander Graf wrote:
  S390x was one of the first platforms that received support for KVM back 
  in the
  day. Unfortunately until now there hasn't been a qemu implementation 
  that would
  enable users to actually run guests.
  
  So let's include support for KVM S390x in qemu!
  
  Please find the comments below.
  
  Signed-off-by: Alexander Graf ag...@suse.de
  ---
  configure  |4 +-
  target-s390x/kvm.c |  463 
  
  2 files changed, 466 insertions(+), 1 deletions(-)
  create mode 100644 target-s390x/kvm.c
  
  diff --git a/configure b/configure
  index b616e1a..cf466ec 100755
  --- a/configure
  +++ b/configure
  @@ -1348,6 +1348,8 @@ EOF
 kvm_cflags=$kvm_cflags -I$kerneldir/arch/x86/include
   elif test $cpu = ppc -a -d $kerneldir/arch/powerpc/include ; then
   kvm_cflags=$kvm_cflags -I$kerneldir/arch/powerpc/include
  +elif test $cpu = s390x -a -d $kerneldir/arch/s390/include 
  ; then
  +kvm_cflags=$kvm_cflags -I$kerneldir/arch/s390/include
 elif test -d $kerneldir/arch/$cpu/include ; then
 kvm_cflags=$kvm_cflags -I$kerneldir/arch/$cpu/include
   fi
  @@ -2360,7 +2362,7 @@ case $target_arch2 in
 fi
  esac
  case $target_arch2 in
  -  i386|x86_64|ppcemb|ppc|ppc64)
  +  i386|x86_64|ppcemb|ppc|ppc64|s390x)
 # Make sure the target and host cpus are compatible
 if test $kvm = yes -a $target_softmmu = yes -a \
   \( $target_arch2 = $cpu -o \
  diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
  new file mode 100644
  index 000..d477664
  --- /dev/null
  +++ b/target-s390x/kvm.c
  @@ -0,0 +1,463 @@
  +/*
  + * QEMU S390x KVM implementation
  + *
  + * Copyright (c) 2009 Alexander Graf ag...@suse.de
  + *
  + * This library is free software; you can redistribute it and/or
  + * modify it under the terms of the GNU Lesser General Public
  + * License as published by the Free Software Foundation; either
  + * version 2 of the License, or (at your option) any later version.
  + *
  + * This library is distributed in the hope that it will be useful,
  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  + * Lesser General Public License for more details.
  + *
  + * You should have received a copy of the GNU Lesser General Public
  + * License along with this library; if not, see 
  http://www.gnu.org/licenses/.
  + */
  +
  +#include sys/types.h
  +#include sys/ioctl.h
  +#include sys/mman.h
  +
  +#include linux/kvm.h
  +#include asm/ptrace.h
  +
  +#include qemu-common.h
  +#include qemu-timer.h
  +#include sysemu.h
  +#include kvm.h
  +#include cpu.h
  +#include device_tree.h
  +
  +/* #define DEBUG_KVM */
  +
  +#ifdef DEBUG_KVM
  +#define dprintf(fmt, ...) \
  +do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
  +#else
  +#define dprintf(fmt, ...) \
  +do { } while (0)
  +#endif
  +
  +#define IPA0_DIAG   0x8300
  +#define IPA0_SIGP   0xae00
  +#define IPA0_PRIV   0xb200
  +
  +#define PRIV_SCLP_CALL  0x20
  +#define DIAG_KVM_HYPERCALL  0x500
  +#define DIAG_KVM_BREAKPOINT 0x501
  +
  +#define SCP_LENGTH  0x00
  +#define SCP_FUNCTION_CODE   0x02
  +#define SCP_CONTROL_MASK0x03
  +#define SCP_RESPONSE_CODE   0x06
  +#define SCP_MEM_CODE0x08
  +#define SCP_INCREMENT   0x0a
  +
  +#define ICPT_INSTRUCTION0x04
  +#define ICPT_WAITPSW0x1c
  +#define ICPT_SOFT_INTERCEPT 0x24
  +#define ICPT_CPU_STOP   0x28
  +#define ICPT_IO 0x40
  +
  +#define SIGP_RESTART0x06
  +#define SIGP_INITIAL_CPU_RESET  0x0b
  +#define SIGP_STORE_STATUS_ADDR  0x0e
  +#define SIGP_SET_ARCH   0x12
  +
  +
  +int kvm_arch_init(KVMState *s, int smp_cpus)
  +{
  +return 0;
  +}
  +
  +int kvm_arch_init_vcpu(CPUState *env)
  +{
  +int ret = 0;
  +
  +if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL)  0)
  +perror(cannot init reset vcpu);
  
  coding style.
  
  +
  +return ret;
  +}
  +
  +void kvm_arch_reset_vcpu(CPUState *env)
  +{
  +}
  
  Is there really nothing to do? If some code has to be added later, it
  may be worth adding a comment.
  
  As you have probably realized by now, all reset code is missing. In fact, 
  we don't even ever call the qemu reset functions to actually do a reset.
  
  Can you make it clean with an abort?
  
  +
  +static void _kvm_s390_interrupt(CPUState *env, int type, uint32_t parm, 
  uint64_t parm64, int vm)
  +{
  
  Why such a name starting with an underscore?
  
  Because that's the internal function that 

Re: [Qemu-devel] [PATCH 03/11] S/390 fake TCG implementation

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:41, Aurelien Jarno wrote:

 On Wed, Dec 02, 2009 at 09:29:59AM +0100, Alexander Graf wrote:
 
 On 02.12.2009, at 09:16, Aurelien Jarno wrote:
 
 On Mon, Nov 30, 2009 at 11:27:53PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
 On Thu, Nov 26, 2009 at 02:23:12PM +0100, Alexander Graf wrote:
 Qemu won't let us run a KVM target without having host TCG support. 
 Well, for
 now we don't have any so let's implement a fake target that only stubs 
 out
 everything.
 
 I tried to keep the patch as close to Uli's source as possible, so 
 whenever
 he feels like it he can easily diff his version against this one.
 
 Please find the comments below.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 dyngen-exec.h |2 +-
 target-s390x/helper.c |5 ++
 tcg/s390/tcg-target.c |  103 
 +
 tcg/s390/tcg-target.h |   48 +++
 4 files changed, 157 insertions(+), 1 deletions(-)
 create mode 100644 tcg/s390/tcg-target.c
 create mode 100644 tcg/s390/tcg-target.h
 
 diff --git a/dyngen-exec.h b/dyngen-exec.h
 index 86e61c3..0353f36 100644
 --- a/dyngen-exec.h
 +++ b/dyngen-exec.h
 @@ -117,7 +117,7 @@ extern int printf(const char *, ...);
 
 /* The return address may point to the start of the next instruction.
  Subtracting one gets us the call instruction itself.  */
 -#if defined(__s390__)
 +#if defined(__s390__)  !defined(__s390x__)
 # define GETPC() ((void*)(((unsigned long)__builtin_return_address(0)  
 0x7fffUL) - 1))
 #elif defined(__arm__)
 /* Thumb return addresses have the low bit set, so we need to subtract 
 two.
 diff --git a/target-s390x/helper.c b/target-s390x/helper.c
 index 4e23b4a..0e222e3 100644
 --- a/target-s390x/helper.c
 +++ b/target-s390x/helper.c
 @@ -44,6 +44,11 @@ CPUS390XState *cpu_s390x_init(const char *cpu_model)
   return env;
 }
 
 +target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong 
 addr)
 +{
 +return addr;
 +}
 +
 
 Why does it appear in this patch? It has nothing to do with TCG support.
 
 I don't remember. What is this used for anyways?
 
 If it is not used, maybe it's better to remove it.
 
 It's called from exec.c.
 
 Then it's clearly not part of this patch, it should probably be part of
 patch 1 or 6 instead.

Yes, moved it already.

Alex



Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread malc
On Wed, 2 Dec 2009, Aurelien Jarno wrote:

 On Tue, Dec 01, 2009 at 12:47:36PM +0100, Alexander Graf wrote:
  Hi,
 
  Could someone with commit rights please stand up to feel responsible for 
  PPC?
 
  Usually, when I send a patch to qemu-devel, I know who to address to  
  increase chances of it getting committed. For kvm/vnc/block I just CC  
  Anthony, for Audio I just CC malc, etc.
 
  There are some subsystems where nobody feels responsible though,  
  apparently hoping 'someone else' will tske on it. Well, turns out it  
  doesn't work that way.
 
  So could we please assign a committer for every subsystem around? Even  
  if the committer doesn't know the architecture inside out, it's still  
  valuable to have soneone feel responsible at all. Committer and  
  maintainer also don't have to be the same person. I'll gladly maintain  
  S390 without having commit rights - as long as I have someone to CC and 
  know the patches will get merged.
 
 
 I also try to follow the ppc architecture, though less than mips and
 also depending on my free time. I know that Blue Swirl and Malc also
 care about it.

Just to clarify esp. taking into consideration first paragraph of 
Alexander's message, i do not care one bit about PPC target (not
until Alexander does something magical with PPC64 and i can continue
trying to resolve an old Linux's hard lockup issue). I do care about
PPC the host though.

 
 It's not impossible that I miss patches given the current patches rate
 on the mailing list, so don't hesitate to Cc: me. On the other hand, I
 don't really feel comfortable with KVM related patches, I would prefer
 to see them committed by Anthony.
 
 

-- 
mailto:av1...@comtv.ru




Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread Aurelien Jarno
On Wed, Dec 02, 2009 at 09:37:16AM +0100, Alexander Graf wrote:
 
 On 02.12.2009, at 09:26, Aurelien Jarno wrote:
 
  On Tue, Dec 01, 2009 at 12:47:36PM +0100, Alexander Graf wrote:
  Hi,
  
  Could someone with commit rights please stand up to feel responsible for 
  PPC?
  
  Usually, when I send a patch to qemu-devel, I know who to address to  
  increase chances of it getting committed. For kvm/vnc/block I just CC  
  Anthony, for Audio I just CC malc, etc.
  
  There are some subsystems where nobody feels responsible though,  
  apparently hoping 'someone else' will tske on it. Well, turns out it  
  doesn't work that way.
  
  So could we please assign a committer for every subsystem around? Even  
  if the committer doesn't know the architecture inside out, it's still  
  valuable to have soneone feel responsible at all. Committer and  
  maintainer also don't have to be the same person. I'll gladly maintain  
  S390 without having commit rights - as long as I have someone to CC and 
  know the patches will get merged.
  
  
  I also try to follow the ppc architecture, though less than mips and
  also depending on my free time. I know that Blue Swirl and Malc also
  care about it.
 
 Right - which makes it pretty hard. IMHO it's always best to have a single 
 person to talk to when it comes to committing and others who comment on 
 patches.

Some committers are not available for a long period of time. It also
happens to me.

 In fact, I even believe that the person committing stuff doesn't have to know 
 the stuff he commits. If I make a patch that breaks S390 and someone commits 
 it, it's my fault breaking it - not the committer's. If I do a patch breaking 
 PPC KVM, it's my fault breaking it, not the committer's. And with fault I 
 also mean responsibility to fix.

Experience has shown that it doesn't work like that. It happens the
person writing the patches never provides a fix, and the committer
receives the complains, and in fine fixes the commit.

  It's not impossible that I miss patches given the current patches rate
  on the mailing list, so don't hesitate to Cc: me. On the other hand, I
  don't really feel comfortable with KVM related patches, I would prefer
  to see them committed by Anthony.
 
 Avi, can I get PPC KVM patches in through you then? I guess you're the 
 closest person to the code in question.
 

If you an get your patches acked-by Avi, I am fine merging them.

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




Re: [Qemu-devel] [PATCH 04/11] Add KVM support for S390x

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:42, malc wrote:

 On Wed, 2 Dec 2009, Alexander Graf wrote:
 
 
 On 02.12.2009, at 09:12, Aurelien Jarno wrote:
 
 On Mon, Nov 30, 2009 at 11:25:03PM +0100, Alexander Graf wrote:
 
 On 30.11.2009, at 19:18, Aurelien Jarno wrote:
 
 On Thu, Nov 26, 2009 at 02:23:13PM +0100, Alexander Graf wrote:
 S390x was one of the first platforms that received support for KVM back 
 in the
 day. Unfortunately until now there hasn't been a qemu implementation 
 that would
 enable users to actually run guests.
 
 So let's include support for KVM S390x in qemu!
 
 Please find the comments below.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 configure  |4 +-
 target-s390x/kvm.c |  463 
 
 2 files changed, 466 insertions(+), 1 deletions(-)
 create mode 100644 target-s390x/kvm.c
 
 diff --git a/configure b/configure
 index b616e1a..cf466ec 100755
 --- a/configure
 +++ b/configure
 @@ -1348,6 +1348,8 @@ EOF
   kvm_cflags=$kvm_cflags -I$kerneldir/arch/x86/include
  elif test $cpu = ppc -a -d $kerneldir/arch/powerpc/include ; then
  kvm_cflags=$kvm_cflags -I$kerneldir/arch/powerpc/include
 +elif test $cpu = s390x -a -d $kerneldir/arch/s390/include 
 ; then
 +kvm_cflags=$kvm_cflags -I$kerneldir/arch/s390/include
   elif test -d $kerneldir/arch/$cpu/include ; then
   kvm_cflags=$kvm_cflags -I$kerneldir/arch/$cpu/include
 fi
 @@ -2360,7 +2362,7 @@ case $target_arch2 in
   fi
 esac
 case $target_arch2 in
 -  i386|x86_64|ppcemb|ppc|ppc64)
 +  i386|x86_64|ppcemb|ppc|ppc64|s390x)
   # Make sure the target and host cpus are compatible
   if test $kvm = yes -a $target_softmmu = yes -a \
 \( $target_arch2 = $cpu -o \
 diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
 new file mode 100644
 index 000..d477664
 --- /dev/null
 +++ b/target-s390x/kvm.c
 @@ -0,0 +1,463 @@
 +/*
 + * QEMU S390x KVM implementation
 + *
 + * Copyright (c) 2009 Alexander Graf ag...@suse.de
 + *
 + * This library is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU Lesser General Public
 + * License as published by the Free Software Foundation; either
 + * version 2 of the License, or (at your option) any later version.
 + *
 + * This library is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 + * Lesser General Public License for more details.
 + *
 + * You should have received a copy of the GNU Lesser General Public
 + * License along with this library; if not, see 
 http://www.gnu.org/licenses/.
 + */
 +
 +#include sys/types.h
 +#include sys/ioctl.h
 +#include sys/mman.h
 +
 +#include linux/kvm.h
 +#include asm/ptrace.h
 +
 +#include qemu-common.h
 +#include qemu-timer.h
 +#include sysemu.h
 +#include kvm.h
 +#include cpu.h
 +#include device_tree.h
 +
 +/* #define DEBUG_KVM */
 +
 +#ifdef DEBUG_KVM
 +#define dprintf(fmt, ...) \
 +do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
 +#else
 +#define dprintf(fmt, ...) \
 +do { } while (0)
 +#endif
 +
 +#define IPA0_DIAG   0x8300
 +#define IPA0_SIGP   0xae00
 +#define IPA0_PRIV   0xb200
 +
 +#define PRIV_SCLP_CALL  0x20
 +#define DIAG_KVM_HYPERCALL  0x500
 +#define DIAG_KVM_BREAKPOINT 0x501
 +
 +#define SCP_LENGTH  0x00
 +#define SCP_FUNCTION_CODE   0x02
 +#define SCP_CONTROL_MASK0x03
 +#define SCP_RESPONSE_CODE   0x06
 +#define SCP_MEM_CODE0x08
 +#define SCP_INCREMENT   0x0a
 +
 +#define ICPT_INSTRUCTION0x04
 +#define ICPT_WAITPSW0x1c
 +#define ICPT_SOFT_INTERCEPT 0x24
 +#define ICPT_CPU_STOP   0x28
 +#define ICPT_IO 0x40
 +
 +#define SIGP_RESTART0x06
 +#define SIGP_INITIAL_CPU_RESET  0x0b
 +#define SIGP_STORE_STATUS_ADDR  0x0e
 +#define SIGP_SET_ARCH   0x12
 +
 +
 +int kvm_arch_init(KVMState *s, int smp_cpus)
 +{
 +return 0;
 +}
 +
 +int kvm_arch_init_vcpu(CPUState *env)
 +{
 +int ret = 0;
 +
 +if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL)  0)
 +perror(cannot init reset vcpu);
 
 coding style.
 
 +
 +return ret;
 +}
 +
 +void kvm_arch_reset_vcpu(CPUState *env)
 +{
 +}
 
 Is there really nothing to do? If some code has to be added later, it
 may be worth adding a comment.
 
 As you have probably realized by now, all reset code is missing. In fact, 
 we don't even ever call the qemu reset functions to actually do a reset.
 
 Can you make it clean with an abort?
 
 +
 +static void _kvm_s390_interrupt(CPUState *env, int type, uint32_t parm, 
 uint64_t parm64, int vm)
 +{
 
 Why such a name starting with an underscore?
 
 Because that's the internal function that gets used by the exported, 
 properly named ones. Are there any conventions on how to declare private 
 functions?
 
 I don't 

Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread Alexander Graf

On 02.12.2009, at 09:46, Aurelien Jarno wrote:

 On Wed, Dec 02, 2009 at 09:37:16AM +0100, Alexander Graf wrote:
 
 On 02.12.2009, at 09:26, Aurelien Jarno wrote:
 
 On Tue, Dec 01, 2009 at 12:47:36PM +0100, Alexander Graf wrote:
 Hi,
 
 Could someone with commit rights please stand up to feel responsible for 
 PPC?
 
 Usually, when I send a patch to qemu-devel, I know who to address to  
 increase chances of it getting committed. For kvm/vnc/block I just CC  
 Anthony, for Audio I just CC malc, etc.
 
 There are some subsystems where nobody feels responsible though,  
 apparently hoping 'someone else' will tske on it. Well, turns out it  
 doesn't work that way.
 
 So could we please assign a committer for every subsystem around? Even  
 if the committer doesn't know the architecture inside out, it's still  
 valuable to have soneone feel responsible at all. Committer and  
 maintainer also don't have to be the same person. I'll gladly maintain  
 S390 without having commit rights - as long as I have someone to CC and 
 know the patches will get merged.
 
 
 I also try to follow the ppc architecture, though less than mips and
 also depending on my free time. I know that Blue Swirl and Malc also
 care about it.
 
 Right - which makes it pretty hard. IMHO it's always best to have a single 
 person to talk to when it comes to committing and others who comment on 
 patches.
 
 Some committers are not available for a long period of time. It also
 happens to me.

So we need a clear backup strategy. Something like that when you know you're 
not available for  4 days, you assign someone else to be your replacement for 
that timeframe.

 In fact, I even believe that the person committing stuff doesn't have to 
 know the stuff he commits. If I make a patch that breaks S390 and someone 
 commits it, it's my fault breaking it - not the committer's. If I do a patch 
 breaking PPC KVM, it's my fault breaking it, not the committer's. And with 
 fault I also mean responsibility to fix.
 
 Experience has shown that it doesn't work like that. It happens the
 person writing the patches never provides a fix, and the committer
 receives the complains, and in fine fixes the commit.

Then revert the patch. I also think we need to distinguish subsystems here.

So when you have something really core-y - like the main loop - then of course 
you go through a lot of review and try to get a lot of people involved, so it 
doesn't break.

On the other hand if you have a subsystem that is completely separate - like 
cris - you don't care if it's broken. If it is for  24 hours, exclude it from 
the default build list. If you see that one person breaks stuff all along, 
tighten the restrictions for that person. But that doesn't mean all subsystems 
need a review as thorough as the core code.

In fact, it is a _lot_ easier to get code into Linux than it is to get it into 
Qemu. That's just plain wrong.

 It's not impossible that I miss patches given the current patches rate
 on the mailing list, so don't hesitate to Cc: me. On the other hand, I
 don't really feel comfortable with KVM related patches, I would prefer
 to see them committed by Anthony.
 
 Avi, can I get PPC KVM patches in through you then? I guess you're the 
 closest person to the code in question.
 
 
 If you an get your patches acked-by Avi, I am fine merging them.

Cool, thanks!

Alex



Re: [Qemu-devel] [PATCH 04/11] Add KVM support for S390x

2009-12-02 Thread malc
On Wed, 2 Dec 2009, Alexander Graf wrote:

 
 On 02.12.2009, at 09:42, malc wrote:
 
  On Wed, 2 Dec 2009, Alexander Graf wrote:

[..snip..]

  
  Why such a name starting with an underscore?
  
  Because that's the internal function that gets used by the exported, 
  properly named ones. Are there any conventions on how to declare private 
  functions?
  
  I don't think there is any convention, but I know malc always complains
  about not introducing names starting with an underscore.
  
  Yeah he does.
  
  
  Hm - I just wanted to clearly show that this is an internal API, nobody 
  should really have to call directly. But I'm open for other naming 
  suggestions.
  
  Thing is, in 7.1.3#1 standard says (after explicitly reserving __ _[A-Z]
  for any use):
  -- All  identifiers  that  begin  with  an  underscore are
 always reserved for use as identifiers with file  scope
 in both the ordinary and tag name spaces.
  
  And i could never really understand (or recall/comprehend when asked
  and being given an answer) what this entails. (Anyone?)
 
 I don't get the second part, but the first one clearly says If you
 use a function beginning underscore, only use it within the file
 you're declaring it at.

6.2.3 describes name spaces.

FWIW here's my interpretation: those names are reserved by implementation
for use in oridnary and tag name spaces, so keep out, feel free to use them
in other name spaces.

Perhaps Mans Rullgard, if he still reads this that is, can enlighten
us.  Unfortuantelly i do not have write access to Usenet anymore so
can not ask this on comp.std.c on my own.

 
  So i would go with something imaginative like internal_do_not_use_kvm*,
  but that's just me. You can go wild here, leading underscore doesn't look
  attractive though.
 
 Well I could have gone with kvm_s390_interrupt_generic or
 kvm_s390_interrupt_internal. But I wanted to have a function name
 that doesn't exceed the 80 character limit all by itself ;-).

Oh c'mon those are less than 30 chars :)

-- 
mailto:av1...@comtv.ru




Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread Avi Kivity

On 12/02/2009 10:37 AM, Alexander Graf wrote:

On 02.12.2009, at 09:26, Aurelien Jarno wrote:

   

On Tue, Dec 01, 2009 at 12:47:36PM +0100, Alexander Graf wrote:
 

Hi,

Could someone with commit rights please stand up to feel responsible for
PPC?

Usually, when I send a patch to qemu-devel, I know who to address to
increase chances of it getting committed. For kvm/vnc/block I just CC
Anthony, for Audio I just CC malc, etc.

There are some subsystems where nobody feels responsible though,
apparently hoping 'someone else' will tske on it. Well, turns out it
doesn't work that way.

So could we please assign a committer for every subsystem around? Even
if the committer doesn't know the architecture inside out, it's still
valuable to have soneone feel responsible at all. Committer and
maintainer also don't have to be the same person. I'll gladly maintain
S390 without having commit rights - as long as I have someone to CC and
know the patches will get merged.

   

I also try to follow the ppc architecture, though less than mips and
also depending on my free time. I know that Blue Swirl and Malc also
care about it.
 

Right - which makes it pretty hard. IMHO it's always best to have a single 
person to talk to when it comes to committing and others who comment on patches.

In fact, I even believe that the person committing stuff doesn't have to know the stuff 
he commits. If I make a patch that breaks S390 and someone commits it, it's my fault 
breaking it - not the committer's. If I do a patch breaking PPC KVM, it's my fault 
breaking it, not the committer's. And with fault I also mean responsibility to 
fix.
   


Breakage is simple.  This difficult stuff is keeping the code maintainable.

   

It's not impossible that I miss patches given the current patches rate
on the mailing list, so don't hesitate to Cc: me. On the other hand, I
don't really feel comfortable with KVM related patches, I would prefer
to see them committed by Anthony.
 

Avi, can I get PPC KVM patches in through you then? I guess you're the closest 
person to the code in question.
   


Sure.

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





Re: [Qemu-devel] [PATCH 04/11] Add KVM support for S390x

2009-12-02 Thread Markus Armbruster
malc av1...@comtv.ru writes:

 On Wed, 2 Dec 2009, Alexander Graf wrote:

 
 On 02.12.2009, at 09:12, Aurelien Jarno wrote:
 
  On Mon, Nov 30, 2009 at 11:25:03PM +0100, Alexander Graf wrote:
  
  On 30.11.2009, at 19:18, Aurelien Jarno wrote:
  
  On Thu, Nov 26, 2009 at 02:23:13PM +0100, Alexander Graf wrote:
[...]
  +
  +static void _kvm_s390_interrupt(CPUState *env, int type, uint32_t 
  parm, uint64_t parm64, int vm)
  +{
  
  Why such a name starting with an underscore?
  
  Because that's the internal function that gets used by the exported, 
  properly named ones. Are there any conventions on how to declare private 
  functions?
  
  I don't think there is any convention, but I know malc always complains
  about not introducing names starting with an underscore.

 Yeah he does.

 
 Hm - I just wanted to clearly show that this is an internal API, nobody 
 should really have to call directly. But I'm open for other naming 
 suggestions.

 Thing is, in 7.1.3#1 standard says (after explicitly reserving __ _[A-Z]
 for any use):
  -- All  identifiers  that  begin  with  an  underscore are
 always reserved for use as identifiers with file  scope
 in both the ordinary and tag name spaces.

 And i could never really understand (or recall/comprehend when asked
 and being given an answer) what this entails. (Anyone?)

Later in 7.1.3:

If the program declares or defines an identifier in a context in
which it is reserved (other than as allowed by 7.1.4), or defines a
reserved identifier as a macro name, the behavior is undefined.

This gives implementations of the standard (compiler + libc) license to
use reserved identifiers for their own purposes.  If they clash with the
user's identifiers, and things break, the user gets to keep the pieces.

Now, it's quite unlikely that _kvm_s390_interrupt() clashes with
anything in practice.  It does, however, set a bad example.

 So i would go with something imaginative like internal_do_not_use_kvm*,
 but that's just me. You can go wild here, leading underscore doesn't look
 attractive though.

Why not kvm_s390_interrupt_internal(), or even kvm_s390_interrupt_()?




Re: [Qemu-devel] [PATCH 04/11] Add KVM support for S390x

2009-12-02 Thread malc
On Wed, 2 Dec 2009, Markus Armbruster wrote:

 malc av1...@comtv.ru writes:
 
  On Wed, 2 Dec 2009, Alexander Graf wrote:
 
  
  On 02.12.2009, at 09:12, Aurelien Jarno wrote:
  
   On Mon, Nov 30, 2009 at 11:25:03PM +0100, Alexander Graf wrote:
   
   On 30.11.2009, at 19:18, Aurelien Jarno wrote:
   
   On Thu, Nov 26, 2009 at 02:23:13PM +0100, Alexander Graf wrote:
 [...]
   +
   +static void _kvm_s390_interrupt(CPUState *env, int type, uint32_t 
   parm, uint64_t parm64, int vm)
   +{
   
   Why such a name starting with an underscore?
   
   Because that's the internal function that gets used by the exported, 
   properly named ones. Are there any conventions on how to declare 
   private functions?
   
   I don't think there is any convention, but I know malc always complains
   about not introducing names starting with an underscore.
 
  Yeah he does.
 
  
  Hm - I just wanted to clearly show that this is an internal API, nobody 
  should really have to call directly. But I'm open for other naming 
  suggestions.
 
  Thing is, in 7.1.3#1 standard says (after explicitly reserving __ _[A-Z]
  for any use):
   -- All  identifiers  that  begin  with  an  underscore are
  always reserved for use as identifiers with file  scope
  in both the ordinary and tag name spaces.
 
  And i could never really understand (or recall/comprehend when asked
  and being given an answer) what this entails. (Anyone?)
 
 Later in 7.1.3:
 
 If the program declares or defines an identifier in a context in
 which it is reserved (other than as allowed by 7.1.4), or defines a
 reserved identifier as a macro name, the behavior is undefined.
 
 This gives implementations of the standard (compiler + libc) license to
 use reserved identifiers for their own purposes.  If they clash with the
 user's identifiers, and things break, the user gets to keep the pieces.

Yes, that's how i would interpret it too (as stated in another message)

 
 Now, it's quite unlikely that _kvm_s390_interrupt() clashes with
 anything in practice.  It does, however, set a bad example.

Indeed.

 
  So i would go with something imaginative like internal_do_not_use_kvm*,
  but that's just me. You can go wild here, leading underscore doesn't look
  attractive though.
 
 Why not kvm_s390_interrupt_internal(), or even kvm_s390_interrupt_()?
 

-- 
mailto:av1...@comtv.ru




[Qemu-devel] Re: [PATCH] vmstate: Avoid seeking

2009-12-02 Thread Juan Quintela
Jan Kiszka jan.kis...@web.de wrote:
 Seeking on vmstate save/load does not work if the underlying file is a
 stream. We could try to make all QEMUFile* forward-seek-aware, but first
 attempts in this direction indicated that it's saner to convert the few
 qemu_fseek-on-vmstates users to plain reads/writes.

 This fixes various subtle vmstate corruptions where unused fields were
 involved.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com

Something changed lately.  This used to work, and I also waste^spend
yesterday trying to understand why it was failing to me.

I am splitting the patch in virtio-net and savevm parts.  (In my tree
virtio-net don't use fseek anymore).

Thanks for finding the bug.

Later, Juan.




[Qemu-devel] [PATCH] ram migration: Properly reset statistics

2009-12-02 Thread Jan Kiszka
As we may do more than one migration (cancellation, live backup), reset
bytes_transferred on stage 1.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---

 vl.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index dbf1180..dc62c68 100644
--- a/vl.c
+++ b/vl.c
@@ -2896,7 +2896,7 @@ static int ram_save_block(QEMUFile *f)
 return found;
 }
 
-static uint64_t bytes_transferred = 0;
+static uint64_t bytes_transferred;
 
 static ram_addr_t ram_save_remaining(void)
 {
@@ -2944,6 +2944,8 @@ static int ram_save_live(Monitor *mon, QEMUFile *f, int 
stage, void *opaque)
 }
 
 if (stage == 1) {
+bytes_transferred = 0;
+
 /* Make sure all dirty bits are set */
 for (addr = 0; addr  last_ram_offset; addr += TARGET_PAGE_SIZE) {
 if (!cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG))




Re: [Qemu-devel] [PATCH v2] Don't leak file descriptors

2009-12-02 Thread Kevin Wolf
Am 01.12.2009 16:55, schrieb Alexander Graf:
 Kevin Wolf wrote:
 We're leaking file descriptors to child processes. Set FD_CLOEXEC on file
 descriptors that don't need to be passed to children to stop this 
 misbehaviour.

 Signed-off-by: Kevin Wolf kw...@redhat.com

 On Anthony's staging tree:
 
 cc1: warnings being treated as errors
 osdep.c: In function ‘qemu_accept’:
 osdep.c:304: error: implicit declaration of function ‘accept4’

Does this one on top work for you?

Kevin
diff --git a/configure b/configure
index dca5a43..0a1e347 100755
--- a/configure
+++ b/configure
@@ -1550,6 +1550,23 @@ if compile_prog   ; then
   pipe2=yes
 fi
 
+# check if accept4 is there
+accept4=no
+cat  $TMPC  EOF
+#define _GNU_SOURCE
+#include sys/socket.h
+#include stddef.h
+
+int main(void)
+{
+accept4(0, NULL, NULL, SOCK_CLOEXEC);
+return 0;
+}
+EOF
+if compile_prog   ; then
+  accept4=yes
+fi
+
 # check if tee/splice is there. vmsplice was added same time.
 splice=no
 cat  $TMPC  EOF
@@ -2013,6 +2030,9 @@ fi
 if test $pipe2 = yes ; then
   echo CONFIG_PIPE2=y  $config_host_mak
 fi
+if test $accept4 = yes ; then
+  echo CONFIG_ACCEPT4=y  $config_host_mak
+fi
 if test $splice = yes ; then
   echo CONFIG_SPLICE=y  $config_host_mak
 fi
diff --git a/osdep.c b/osdep.c
index 039065e..7509c5b 100644
--- a/osdep.c
+++ b/osdep.c
@@ -260,7 +260,7 @@ int qemu_pipe(int pipefd[2])
 {
 int ret;
 
-#ifdef O_CLOEXEC
+#ifdef CONFIG_PIPE2
 ret = pipe2(pipefd, O_CLOEXEC);
 #else
 ret = pipe(pipefd);
@@ -300,7 +300,7 @@ int qemu_accept(int s, struct sockaddr *addr, socklen_t 
*addrlen)
 {
 int ret;
 
-#ifdef SOCK_CLOEXEC
+#ifdef CONFIG_ACCEPT4
 ret = accept4(s, addr, addrlen, SOCK_CLOEXEC);
 #else
 ret = accept(s, addr, addrlen);


Re: [Qemu-devel] Socket reconnection.

2009-12-02 Thread Ian Molton
Anthony Liguori wrote:

 sleep() in qemu is very, very wrong.  It will pause the guest's
 execution and all sorts of badness can ensue.

Quite...

 The right thing to do is set a timer and not generate data while
 disconnected.

New patch attached, now with less crack...

  I still am not confident this is really a great thing to do.

What other option is there than to drop the ability to feed entropy to
the guest when the hosts egd link drops?

btw. Does anyone know how to get t-bird to inline patches?

-Ian
From e9d4be9cd0ef9e34c65939d4604874035c45bf34 Mon Sep 17 00:00:00 2001
From: Ian Molton ian.mol...@collabora.co.uk
Date: Tue, 1 Dec 2009 11:18:41 +
Subject: [PATCH 2/4] socket: Add a reconnect option.

	Add a reconnect option that allows sockets to reconnect (after a
specified delay) to the specified server. This makes the virtio-rng driver
useful in production environments where the EGD server may need to be restarted.

Signed-off-by: Ian Molton ian.mol...@collabora.co.uk
---
 qemu-char.c   |  177 -
 qemu-char.h   |2 +
 qemu-config.c |3 +
 vl.c  |4 +
 4 files changed, 147 insertions(+), 39 deletions(-)

diff --git a/qemu-char.c b/qemu-char.c
index e202585..714c119 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1870,8 +1870,12 @@ typedef struct {
 int max_size;
 int do_telnetopt;
 int do_nodelay;
+int reconnect;
 int is_unix;
 int msgfd;
+QemuOpts *opts;
+CharDriverState *chr;
+int (*setup)(QemuOpts *opts);
 } TCPCharDriver;
 
 static void tcp_chr_accept(void *opaque);
@@ -2011,6 +2015,69 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len)
 }
 #endif
 
+struct reconnect_list {
+TCPCharDriver *s;
+uint64_t when;
+struct reconnect_list *next;
+};
+
+static struct reconnect_list *rc_list;
+
+static int qemu_chr_sched_reconnect(TCPCharDriver *s)
+{
+struct reconnect_list *new = qemu_malloc(sizeof(*new));
+struct timeval tv;
+
+if(!new)
+return 1;
+
+gettimeofday(tv, NULL);
+new-s = s;
+new-when = (s-reconnect + tv.tv_sec) * 100 + tv.tv_usec;
+new-next = rc_list;
+rc_list = new;
+
+return 0;
+}
+
+static int qemu_chr_connect_socket(TCPCharDriver *s);
+
+void qemu_chr_reconnect(void)
+{
+struct reconnect_list *this = rc_list, *prev = NULL;
+struct timeval tv;
+uint64_t now;
+
+if(!this)
+return;
+
+gettimeofday(tv, NULL);
+now = tv.tv_sec * 100 + tv.tv_usec;
+
+while (this) {
+if (this-when = now) {
+if(qemu_chr_connect_socket(this-s)) {
+if(prev)
+prev-next = this-next;
+else
+rc_list = NULL;
+qemu_chr_event(this-s-chr, CHR_EVENT_RECONNECTED);
+free(this);
+		if(prev)
+			this = prev;
+		else
+			this = NULL;
+}
+else {
+this-when += this-s-reconnect * 100;
+}
+}
+prev = this;
+	if(this)
+this = this-next;
+}
+}
+
 static void tcp_chr_read(void *opaque)
 {
 CharDriverState *chr = opaque;
@@ -2030,10 +2097,16 @@ static void tcp_chr_read(void *opaque)
 if (s-listen_fd = 0) {
 qemu_set_fd_handler(s-listen_fd, tcp_chr_accept, NULL, chr);
 }
-qemu_set_fd_handler(s-fd, NULL, NULL, NULL);
+if (!s-reconnect)
+qemu_set_fd_handler(s-fd, NULL, NULL, NULL);
 closesocket(s-fd);
 s-fd = -1;
-qemu_chr_event(chr, CHR_EVENT_CLOSED);
+if (!s-reconnect) {
+qemu_chr_event(chr, CHR_EVENT_CLOSED);
+} else if (qemu_chr_sched_reconnect(s)) {
+printf(Unable to queue socket for reconnection.\n);
+qemu_chr_event(chr, CHR_EVENT_CLOSED);
+}
 } else if (size  0) {
 if (s-do_telnetopt)
 tcp_chr_process_IAC_bytes(chr, s, buf, size);
@@ -2137,7 +2210,6 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
 {
 CharDriverState *chr = NULL;
 TCPCharDriver *s = NULL;
-int fd = -1;
 int is_listen;
 int is_waitconnect;
 int do_nodelay;
@@ -2145,34 +2217,40 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
 int is_telnet;
 
 is_listen  = qemu_opt_get_bool(opts, server, 0);
+is_unix= qemu_opt_get(opts, path) != NULL;
+
 is_waitconnect = qemu_opt_get_bool(opts, wait, 1);
 is_telnet  = qemu_opt_get_bool(opts, telnet, 0);
 do_nodelay = !qemu_opt_get_bool(opts, delay, 1);
-is_unix= qemu_opt_get(opts, path) != NULL;
-if (!is_listen)
+
+if (!is_listen) {
 is_waitconnect = 0;
+} else {
+if (is_telnet)
+s-do_telnetopt = 1;
+}
+
 
-chr = qemu_mallocz(sizeof(CharDriverState));
 s = qemu_mallocz(sizeof(TCPCharDriver));
+chr = qemu_mallocz(sizeof(CharDriverState));
+s-opts = opts;
+
+

Re: [Qemu-devel] [PATCH v2 05/11] tell kernel about all registers instead of just mp_state

2009-12-02 Thread Gleb Natapov
On Tue, Dec 01, 2009 at 10:51:31AM -0200, Glauber Costa wrote:
 This fix a bug with -smp in kvm. Since we have updated apic_base,
 we also have to tell kernel about it. So instead of just updating
 mp_state, update every regs.
 
 It is mandatory that this happens synchronously, without waiting for
 the next vcpu run. Otherwise, if we are migrating, or initializing
 the cpu's APIC, other cpus can still see an invalid state.
 
 Since putting registers already happen in vcpu entry, we factor
 out the required code in cpu_flush_state()
 
 Signed-off-by: Glauber Costa glom...@redhat.com
 ---
  hw/apic-kvm.c |5 -
  kvm-all.c |   14 +-
  kvm.h |8 
  3 files changed, 21 insertions(+), 6 deletions(-)
 
 diff --git a/hw/apic-kvm.c b/hw/apic-kvm.c
 index e5a0bfc..9e9790f 100644
 --- a/hw/apic-kvm.c
 +++ b/hw/apic-kvm.c
 @@ -126,7 +126,10 @@ static void kvm_apic_reset(void *opaque)
  s-cpu_env-mp_state
  = bsp ? KVM_MP_STATE_RUNNABLE : KVM_MP_STATE_UNINITIALIZED;
  
 -kvm_put_mp_state(s-cpu_env);
 +/* We have to tell the kernel about mp_state, but also save sregs, since
 + * apic base was just updated
 + */
 +cpu_flush_state(s-cpu_env);
  
  if (bsp) {
  /*
 diff --git a/kvm-all.c b/kvm-all.c
 index 40203f0..318a4e6 100644
 --- a/kvm-all.c
 +++ b/kvm-all.c
 @@ -622,7 +622,6 @@ static void kvm_run_coalesced_mmio(CPUState *env, struct 
 kvm_run *run)
  }
  #endif
  }
 -
Spurious line removing.

  void kvm_cpu_synchronize_state(CPUState *env)
  {
  if (!env-kvm_state-regs_modified) {
 @@ -631,6 +630,14 @@ void kvm_cpu_synchronize_state(CPUState *env)
  }
  }
  
 +void kvm_cpu_flush_state(CPUState *env)
 +{
 +if (env-kvm_state-regs_modified) {
 +kvm_arch_put_registers(env);
 +env-kvm_state-regs_modified = 0;
 +}
 +}
 +
  int kvm_cpu_exec(CPUState *env)
  {
  struct kvm_run *run = env-kvm_run;
 @@ -645,10 +652,7 @@ int kvm_cpu_exec(CPUState *env)
  break;
  }
  
 -if (env-kvm_state-regs_modified) {
 -kvm_arch_put_registers(env);
 -env-kvm_state-regs_modified = 0;
 -}
 +kvm_cpu_flush_state(env);
  
  kvm_arch_pre_run(env, run);
  qemu_mutex_unlock_iothread();
 diff --git a/kvm.h b/kvm.h
 index a474d95..d9af176 100644
 --- a/kvm.h
 +++ b/kvm.h
 @@ -139,6 +139,7 @@ int kvm_check_extension(KVMState *s, unsigned int 
 extension);
  uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
int reg);
  void kvm_cpu_synchronize_state(CPUState *env);
 +void kvm_cpu_flush_state(CPUState *env);
  
  /* generic hooks - to be moved/refactored once there are more users */
  
 @@ -149,4 +150,11 @@ static inline void cpu_synchronize_state(CPUState *env)
  }
  }
  
 +static inline void cpu_flush_state(CPUState *env)
 +{
 +if (kvm_enabled()) {
Is this ever called or intended to be called when kvm is disabled?

 +kvm_cpu_flush_state(env);
 +}
 +}
 +
  #endif
 -- 
 1.6.5.2
 
 

--
Gleb.




[Qemu-devel] [PATCH v3 00/10] *** SUBJECT HERE ***

2009-12-02 Thread Juan Quintela
[v3]
- Fix UNUSED size to 3 for ac97.
- use %zd for sizeof() values insead of %lu.

[v2]
- rebased to top of qemu/master
- removed IO_READ/WRITE_PROTO cleanups.
- rest is the same that previous round.  malc agreed to let them it.

Later, Juan.

[v1]

THis patch series port audio to vmstate.
- fix compliation with DEBUG_PLIVE and DEBUG_AC97
- unfold IO_READ_PROTO/IO_WRITE_PROTO and remove them
- audio.c: the easiest thing to port (nothing inside)
- sb16: port to vmstate, testing shows that it didn't survive migrations
  very well (it happened before already).  Guest got this messages:
   I got lots of underruns on the guest reported by alsa
  on monitor I get lots of:
   sb16: warning: command 0x42,2 is not truly understood yet
- es1370: the best working with migration.
- adlib: I am not able to get sound out of it on any recent Fedora :(
- cs4231a: it uses irq9, and that don't fly with acpi using that irq on qemu
  I disabled dma_running before loading state.  malc can you take a look here?
  I changed it to be able to use dma_running state field for state.
- gus: no module anymore on Fedora
- ac97: from Anthony sugestion, remove the use of active array, it can be
recalculated.  All my testing (muted, not muted, ..., shows that
transmited array is the same one than the recalculated one).
  ac97 don't work always with migration.

How did I test:
- start a linux guest
- inside there play a song (ogg123 foo.ogg)
- in the middle of the song do savevm foo
- later restart qemu with -loadvm foo option

What did I expect?:
- I expected after ending the loadvm to hear the contination of the song.

Actual results:
- es1370: the one working better
- sb16: lots of underruns, very low sound quality.
- ac97: mixed results.  The 1st 5-10 seconds always sound perfect
   Then, between 10 and 30 seconds, sometimes it lots syncs and start playing at
   full speed, basiaclly no sound ouput. No sound after this is ever generated.
   If it is able to generate sound for 30-40 seconds, then sound works 
correctly.
  I tried to debug this, enabled all the audio DEBUG*, but I didn't find what is
  happening.
  Notice that this happens when I launch from the same savevm image.  Some times
  it works well, some times it stops working at 5 seconds, sometimes it stops
  working at 10 seconds, and so on.
  My theory is that we are not saving all the state that we need, but I have 
been
  unable to found anything obviosu here.  malc, do you have any suggestion?

This took a lot because the ac97 testing, I thouguht the ac97 problems were due 
to
my changes.  It just happened that the 1st time that I loaded without my changes
it just worked :(  Problem can be reproduced as easily without any of my 
changes.
More work needs to be done to be sure that ac97 migrates correctly, but that is
independent of this patch :)

Later, Juan.


Juan Quintela (10):
  audio: fix compilation of DEBUG_PLIVE
  audio: port to vmstate
  sb16: port to vmstate
  es1370: port to vmstate
  c4231a: port to vmstate
  gus: port to vmstate
  ac97: sizeof needs %zd
  ac97: recalculate active after loadvm
  ac97: up savevm version and remove active from state
  ac97: port to vmstate

 audio/audio.c  |   26 +++-
 audio/audio_template.h |6 +-
 hw/ac97.c  |  113 ++--
 hw/cs4231a.c   |   58 +
 hw/es1370.c|   77 ++
 hw/gus.c   |   47 +-
 hw/sb16.c  |  168 +--
 7 files changed, 205 insertions(+), 290 deletions(-)





[Qemu-devel] [PATCH 01/10] audio: fix compilation of DEBUG_PLIVE

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 audio/audio_template.h |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/audio/audio_template.h b/audio/audio_template.h
index 1a4707b..6b19848 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -445,9 +445,9 @@ SW *glue (AUD_open_, TYPE) (
SW_NAME (sw), sw-info.freq, sw-info.bits, sw-info.nchannels);
 dolog (New %s freq %d, bits %d, channels %d\n,
name,
-   freq,
-   (fmt == AUD_FMT_S16 || fmt == AUD_FMT_U16) ? 16 : 8,
-   nchannels);
+   as-freq,
+   (as-fmt == AUD_FMT_S16 || as-fmt == AUD_FMT_U16) ? 16 : 8,
+   as-nchannels);
 #endif

 if (live) {
-- 
1.6.5.2





[Qemu-devel] [PATCH 02/10] audio: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 audio/audio.c |   26 +-
 1 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 80a717b..a5305c4 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1784,23 +1784,15 @@ static void audio_atexit (void)
 }
 }

-static void audio_save (QEMUFile *f, void *opaque)
-{
-(void) f;
-(void) opaque;
-}
-
-static int audio_load (QEMUFile *f, void *opaque, int version_id)
-{
-(void) f;
-(void) opaque;
-
-if (version_id != 1) {
-return -EINVAL;
+static const VMStateDescription vmstate_audio = {
+.name = audio,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_END_OF_LIST()
 }
-
-return 0;
-}
+};

 static void audio_init (void)
 {
@@ -1900,7 +1892,7 @@ static void audio_init (void)
 }

 QLIST_INIT (s-card_head);
-register_savevm (audio, 0, 1, audio_save, audio_load, s);
+vmstate_register (0, vmstate_audio, s);
 }

 void AUD_register_card (const char *name, QEMUSoundCard *card)
-- 
1.6.5.2





[Qemu-devel] [PATCH 03/10] sb16: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/sb16.c |  168 ++---
 1 files changed, 61 insertions(+), 107 deletions(-)

diff --git a/hw/sb16.c b/hw/sb16.c
index 12ddad4..4c0d682 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -1244,115 +1244,10 @@ static void SB_audio_callback (void *opaque, int free)
 s-audio_free = free;
 }

-static void SB_save (QEMUFile *f, void *opaque)
+static int sb16_post_load (void *opaque, int version_id)
 {
 SB16State *s = opaque;

-qemu_put_be32 (f, s-irq);
-qemu_put_be32 (f, s-dma);
-qemu_put_be32 (f, s-hdma);
-qemu_put_be32 (f, s-port);
-qemu_put_be32 (f, s-ver);
-qemu_put_be32 (f, s-in_index);
-qemu_put_be32 (f, s-out_data_len);
-qemu_put_be32 (f, s-fmt_stereo);
-qemu_put_be32 (f, s-fmt_signed);
-qemu_put_be32 (f, s-fmt_bits);
-qemu_put_be32s (f, s-fmt);
-qemu_put_be32 (f, s-dma_auto);
-qemu_put_be32 (f, s-block_size);
-qemu_put_be32 (f, s-fifo);
-qemu_put_be32 (f, s-freq);
-qemu_put_be32 (f, s-time_const);
-qemu_put_be32 (f, s-speaker);
-qemu_put_be32 (f, s-needed_bytes);
-qemu_put_be32 (f, s-cmd);
-qemu_put_be32 (f, s-use_hdma);
-qemu_put_be32 (f, s-highspeed);
-qemu_put_be32 (f, s-can_write);
-qemu_put_be32 (f, s-v2x6);
-
-qemu_put_8s (f, s-csp_param);
-qemu_put_8s (f, s-csp_value);
-qemu_put_8s (f, s-csp_mode);
-qemu_put_8s (f, s-csp_param);
-qemu_put_buffer (f, s-csp_regs, 256);
-qemu_put_8s (f, s-csp_index);
-qemu_put_buffer (f, s-csp_reg83, 4);
-qemu_put_be32 (f, s-csp_reg83r);
-qemu_put_be32 (f, s-csp_reg83w);
-
-qemu_put_buffer (f, s-in2_data, sizeof (s-in2_data));
-qemu_put_buffer (f, s-out_data, sizeof (s-out_data));
-qemu_put_8s (f, s-test_reg);
-qemu_put_8s (f, s-last_read_byte);
-
-qemu_put_be32 (f, s-nzero);
-qemu_put_be32 (f, s-left_till_irq);
-qemu_put_be32 (f, s-dma_running);
-qemu_put_be32 (f, s-bytes_per_second);
-qemu_put_be32 (f, s-align);
-
-qemu_put_be32 (f, s-mixer_nreg);
-qemu_put_buffer (f, s-mixer_regs, 256);
-}
-
-static int SB_load (QEMUFile *f, void *opaque, int version_id)
-{
-SB16State *s = opaque;
-
-if (version_id != 1) {
-return -EINVAL;
-}
-
-s-irq=qemu_get_be32 (f);
-s-dma=qemu_get_be32 (f);
-s-hdma=qemu_get_be32 (f);
-s-port=qemu_get_be32 (f);
-s-ver=qemu_get_be32 (f);
-s-in_index=qemu_get_be32 (f);
-s-out_data_len=qemu_get_be32 (f);
-s-fmt_stereo=qemu_get_be32 (f);
-s-fmt_signed=qemu_get_be32 (f);
-s-fmt_bits=qemu_get_be32 (f);
-qemu_get_be32s (f, s-fmt);
-s-dma_auto=qemu_get_be32 (f);
-s-block_size=qemu_get_be32 (f);
-s-fifo=qemu_get_be32 (f);
-s-freq=qemu_get_be32 (f);
-s-time_const=qemu_get_be32 (f);
-s-speaker=qemu_get_be32 (f);
-s-needed_bytes=qemu_get_be32 (f);
-s-cmd=qemu_get_be32 (f);
-s-use_hdma=qemu_get_be32 (f);
-s-highspeed=qemu_get_be32 (f);
-s-can_write=qemu_get_be32 (f);
-s-v2x6=qemu_get_be32 (f);
-
-qemu_get_8s (f, s-csp_param);
-qemu_get_8s (f, s-csp_value);
-qemu_get_8s (f, s-csp_mode);
-qemu_get_8s (f, s-csp_param);
-qemu_get_buffer (f, s-csp_regs, 256);
-qemu_get_8s (f, s-csp_index);
-qemu_get_buffer (f, s-csp_reg83, 4);
-s-csp_reg83r=qemu_get_be32 (f);
-s-csp_reg83w=qemu_get_be32 (f);
-
-qemu_get_buffer (f, s-in2_data, sizeof (s-in2_data));
-qemu_get_buffer (f, s-out_data, sizeof (s-out_data));
-qemu_get_8s (f, s-test_reg);
-qemu_get_8s (f, s-last_read_byte);
-
-s-nzero=qemu_get_be32 (f);
-s-left_till_irq=qemu_get_be32 (f);
-s-dma_running=qemu_get_be32 (f);
-s-bytes_per_second=qemu_get_be32 (f);
-s-align=qemu_get_be32 (f);
-
-s-mixer_nreg=qemu_get_be32 (f);
-qemu_get_buffer (f, s-mixer_regs, 256);
-
 if (s-voice) {
 AUD_close_out (s-card, s-voice);
 s-voice = NULL;
@@ -1385,6 +1280,65 @@ static int SB_load (QEMUFile *f, void *opaque, int 
version_id)
 return 0;
 }

+static const VMStateDescription vmstate_sb16 = {
+.name = sb16,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.post_load = sb16_post_load,
+.fields  = (VMStateField []) {
+VMSTATE_UINT32(irq, SB16State),
+VMSTATE_UINT32(dma, SB16State),
+VMSTATE_UINT32(hdma, SB16State),
+VMSTATE_UINT32(port, SB16State),
+VMSTATE_UINT32(ver, SB16State),
+VMSTATE_INT32(in_index, SB16State),
+VMSTATE_INT32(out_data_len, SB16State),
+VMSTATE_INT32(fmt_stereo, SB16State),
+VMSTATE_INT32(fmt_signed, SB16State),
+VMSTATE_INT32(fmt_bits, SB16State),
+VMSTATE_UINT32(fmt, SB16State),
+VMSTATE_INT32(dma_auto, SB16State),
+VMSTATE_INT32(block_size, SB16State),
+VMSTATE_INT32(fifo, SB16State),
+VMSTATE_INT32(freq, SB16State),
+

[Qemu-devel] [PATCH 04/10] es1370: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/es1370.c |   77 +++---
 1 files changed, 36 insertions(+), 41 deletions(-)

diff --git a/hw/es1370.c b/hw/es1370.c
index 10da250..4e646dc 100644
--- a/hw/es1370.c
+++ b/hw/es1370.c
@@ -924,48 +924,28 @@ static void es1370_map (PCIDevice *pci_dev, int 
region_num,
 register_ioport_read (addr, 0x40, 4, es1370_readl, s);
 }

-static void es1370_save (QEMUFile *f, void *opaque)
-{
-ES1370State *s = opaque;
-size_t i;
-
-pci_device_save (s-dev, f);
-for (i = 0; i  NB_CHANNELS; ++i) {
-struct chan *d = s-chan[i];
-qemu_put_be32s (f, d-shift);
-qemu_put_be32s (f, d-leftover);
-qemu_put_be32s (f, d-scount);
-qemu_put_be32s (f, d-frame_addr);
-qemu_put_be32s (f, d-frame_cnt);
+static const VMStateDescription vmstate_es1370_channel = {
+.name = es1370_channel,
+.version_id = 2,
+.minimum_version_id = 2,
+.minimum_version_id_old = 2,
+.fields  = (VMStateField []) {
+VMSTATE_UINT32(shift, struct chan),
+VMSTATE_UINT32(leftover, struct chan),
+VMSTATE_UINT32(scount, struct chan),
+VMSTATE_UINT32(frame_addr, struct chan),
+VMSTATE_UINT32(frame_cnt, struct chan),
+VMSTATE_END_OF_LIST()
 }
-qemu_put_be32s (f, s-ctl);
-qemu_put_be32s (f, s-status);
-qemu_put_be32s (f, s-mempage);
-qemu_put_be32s (f, s-codec);
-qemu_put_be32s (f, s-sctl);
-}
+};

-static int es1370_load (QEMUFile *f, void *opaque, int version_id)
+static int es1370_post_load (void *opaque, int version_id)
 {
-int ret;
 uint32_t ctl, sctl;
 ES1370State *s = opaque;
 size_t i;

-if (version_id != 2)
-return -EINVAL;
-
-ret = pci_device_load (s-dev, f);
-if (ret)
-return ret;
-
 for (i = 0; i  NB_CHANNELS; ++i) {
-struct chan *d = s-chan[i];
-qemu_get_be32s (f, d-shift);
-qemu_get_be32s (f, d-leftover);
-qemu_get_be32s (f, d-scount);
-qemu_get_be32s (f, d-frame_addr);
-qemu_get_be32s (f, d-frame_cnt);
 if (i == ADC_CHANNEL) {
 if (s-adc_voice) {
 AUD_close_in (s-card, s-adc_voice);
@@ -980,18 +960,33 @@ static int es1370_load (QEMUFile *f, void *opaque, int 
version_id)
 }
 }

-qemu_get_be32s (f, ctl);
-qemu_get_be32s (f, s-status);
-qemu_get_be32s (f, s-mempage);
-qemu_get_be32s (f, s-codec);
-qemu_get_be32s (f, sctl);
-
+ctl = s-ctl;
+sctl = s-sctl;
 s-ctl = 0;
 s-sctl = 0;
 es1370_update_voices (s, ctl, sctl);
 return 0;
 }

+static const VMStateDescription vmstate_es1370 = {
+.name = es1370,
+.version_id = 2,
+.minimum_version_id = 2,
+.minimum_version_id_old = 2,
+.post_load = es1370_post_load,
+.fields  = (VMStateField []) {
+VMSTATE_PCI_DEVICE(dev, ES1370State),
+VMSTATE_STRUCT_ARRAY(chan, ES1370State, NB_CHANNELS, 2,
+ vmstate_es1370_channel, struct chan),
+VMSTATE_UINT32(ctl, ES1370State),
+VMSTATE_UINT32(status, ES1370State),
+VMSTATE_UINT32(mempage, ES1370State),
+VMSTATE_UINT32(codec, ES1370State),
+VMSTATE_UINT32(sctl, ES1370State),
+VMSTATE_END_OF_LIST()
+}
+};
+
 static void es1370_on_reset (void *opaque)
 {
 ES1370State *s = opaque;
@@ -1028,7 +1023,7 @@ static int es1370_initfn (PCIDevice *dev)
 c[0x3f] = 0x80;

 pci_register_bar (s-dev, 0, 256, PCI_BASE_ADDRESS_SPACE_IO, es1370_map);
-register_savevm (es1370, 0, 2, es1370_save, es1370_load, s);
+vmstate_register (0, vmstate_es1370, s);
 qemu_register_reset (es1370_on_reset, s);

 AUD_register_card (es1370, s-card);
-- 
1.6.5.2





[Qemu-devel] [PATCH 05/10] c4231a: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/cs4231a.c |   58 ++
 1 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index e03c5d2..7c29aa8 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -596,45 +596,47 @@ static int cs_dma_read (void *opaque, int nchan, int 
dma_pos, int dma_len)
 return dma_pos;
 }

-static void cs_save (QEMUFile *f, void *opaque)
+static int cs4231a_pre_load (void *opaque)
 {
 CSState *s = opaque;
-unsigned int i;
-uint32_t val;

-for (i = 0; i  CS_REGS; i++)
-qemu_put_be32s (f, s-regs[i]);
-
-qemu_put_buffer (f, s-dregs, CS_DREGS);
-val = s-dma_running; qemu_put_be32s (f, val);
-val = s-audio_free;  qemu_put_be32s (f, val);
-val = s-transferred; qemu_put_be32s (f, val);
-val = s-aci_counter; qemu_put_be32s (f, val);
+if (s-dma_running) {
+DMA_release_DREQ (s-dma);
+AUD_set_active_out (s-voice, 0);
+}
+s-dma_running = 0;
+return 0;
 }

-static int cs_load (QEMUFile *f, void *opaque, int version_id)
+static int cs4231a_post_load (void *opaque, int version_id)
 {
 CSState *s = opaque;
-unsigned int i;
-uint32_t val, dma_running;
-
-if (version_id  1)
-return -EINVAL;

-for (i = 0; i  CS_REGS; i++)
-qemu_get_be32s (f, s-regs[i]);
-
-qemu_get_buffer (f, s-dregs, CS_DREGS);
-
-qemu_get_be32s (f, dma_running);
-qemu_get_be32s (f, val); s-audio_free  = val;
-qemu_get_be32s (f, val); s-transferred = val;
-qemu_get_be32s (f, val); s-aci_counter = val;
-if (dma_running  (s-dregs[Interface_Configuration]  PEN))
+if (s-dma_running  (s-dregs[Interface_Configuration]  PEN)) {
+s-dma_running = 0;
 cs_reset_voices (s, s-dregs[FS_And_Playback_Data_Format]);
+}
 return 0;
 }

+static const VMStateDescription vmstate_cs4231a = {
+.name = cs4231a,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.pre_load = cs4231a_pre_load,
+.post_load = cs4231a_post_load,
+.fields  = (VMStateField []) {
+VMSTATE_UINT32_ARRAY(regs, CSState, CS_REGS),
+VMSTATE_BUFFER(dregs, CSState),
+VMSTATE_INT32(dma_running, CSState),
+VMSTATE_INT32(audio_free, CSState),
+VMSTATE_INT32(transferred, CSState),
+VMSTATE_INT32(aci_counter, CSState),
+VMSTATE_END_OF_LIST()
+}
+};
+
 static int cs4231a_initfn (ISADevice *dev)
 {
 CSState *s = DO_UPCAST (CSState, dev, dev);
@@ -649,7 +651,7 @@ static int cs4231a_initfn (ISADevice *dev)

 DMA_register_channel (s-dma, cs_dma_read, s);

-register_savevm (cs4231a, 0, 1, cs_save, cs_load, s);
+vmstate_register (0, vmstate_cs4231a, s);
 qemu_register_reset (cs_reset, s);
 cs_reset (s);

-- 
1.6.5.2





[Qemu-devel] [PATCH 07/10] ac97: sizeof needs %zd

2009-12-02 Thread Juan Quintela
This change makes DEBUG_AC97 to compile again

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/ac97.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/ac97.c b/hw/ac97.c
index f72c46d..36aab8a 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -323,7 +323,7 @@ static void reset_bm_regs (AC97LinkState *s, 
AC97BusMasterRegs *r)
 static void mixer_store (AC97LinkState *s, uint32_t i, uint16_t v)
 {
 if (i + 2  sizeof (s-mixer_data)) {
-dolog (mixer_store: index %d out of bounds %d\n,
+dolog (mixer_store: index %d out of bounds %zd\n,
i, sizeof (s-mixer_data));
 return;
 }
@@ -337,7 +337,7 @@ static uint16_t mixer_load (AC97LinkState *s, uint32_t i)
 uint16_t val = 0x;

 if (i + 2  sizeof (s-mixer_data)) {
-dolog (mixer_store: index %d out of bounds %d\n,
+dolog (mixer_store: index %d out of bounds %zd\n,
i, sizeof (s-mixer_data));
 }
 else {
-- 
1.6.5.2





[Qemu-devel] [PATCH 08/10] ac97: recalculate active after loadvm

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/ac97.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/hw/ac97.c b/hw/ac97.c
index 36aab8a..e89a56a 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -1242,6 +1242,9 @@ static int ac97_load (QEMUFile *f, void *opaque, int 
version_id)
 V_ (AC97_Line_In_Volume_Mute, AUD_MIXER_LINE_IN);
 #undef V_
 #endif
+active[PI_INDEX] = !!(s-bm_regs[PI_INDEX].cr  CR_RPBM);
+active[PO_INDEX] = !!(s-bm_regs[PO_INDEX].cr  CR_RPBM);
+active[MC_INDEX] = !!(s-bm_regs[MC_INDEX].cr  CR_RPBM);
 reset_voices (s, active);

 s-bup_flag = 0;
-- 
1.6.5.2





[Qemu-devel] [PATCH 06/10] gus: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/gus.c |   47 +--
 1 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/hw/gus.c b/hw/gus.c
index c6b98b3..d35da0a 100644
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -215,35 +215,22 @@ static int GUS_read_DMA (void *opaque, int nchan, int 
dma_pos, int dma_len)
 return dma_len;
 }

-static void GUS_save (QEMUFile *f, void *opaque)
-{
-GUSState *s = opaque;
-
-qemu_put_be32 (f, s-pos);
-qemu_put_be32 (f, s-left);
-qemu_put_be32 (f, s-shift);
-qemu_put_be32 (f, s-irqs);
-qemu_put_be32 (f, s-samples);
-qemu_put_be64 (f, s-last_ticks);
-qemu_put_buffer (f, s-himem, sizeof (s-himem));
-}
-
-static int GUS_load (QEMUFile *f, void *opaque, int version_id)
-{
-GUSState *s = opaque;
-
-if (version_id != 2)
-return -EINVAL;
-
-s-pos = qemu_get_be32 (f);
-s-left = qemu_get_be32 (f);
-s-shift = qemu_get_be32 (f);
-s-irqs = qemu_get_be32 (f);
-s-samples = qemu_get_be32 (f);
-s-last_ticks = qemu_get_be64 (f);
-qemu_get_buffer (f, s-himem, sizeof (s-himem));
-return 0;
-}
+static const VMStateDescription vmstate_gus = {
+.name = gus,
+.version_id = 2,
+.minimum_version_id = 2,
+.minimum_version_id_old = 2,
+.fields  = (VMStateField []) {
+VMSTATE_INT32(pos, GUSState),
+VMSTATE_INT32(left, GUSState),
+VMSTATE_INT32(shift, GUSState),
+VMSTATE_INT32(irqs, GUSState),
+VMSTATE_INT32(samples, GUSState),
+VMSTATE_INT64(last_ticks, GUSState),
+VMSTATE_BUFFER(himem, GUSState),
+VMSTATE_END_OF_LIST()
+}
+};

 static int gus_initfn (ISADevice *dev)
 {
@@ -300,7 +287,7 @@ static int gus_initfn (ISADevice *dev)

 AUD_set_active_out (s-voice, 1);

-register_savevm (gus, 0, 2, GUS_save, GUS_load, s);
+vmstate_register (0, vmstate_gus, s);
 return 0;
 }

-- 
1.6.5.2





[Qemu-devel] [PATCH 09/10] ac97: up savevm version and remove active from state

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/ac97.c |   13 -
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/hw/ac97.c b/hw/ac97.c
index e89a56a..cc5ec30 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -1170,7 +1170,6 @@ static void po_callback (void *opaque, int free)
 static void ac97_save (QEMUFile *f, void *opaque)
 {
 size_t i;
-uint8_t active[LAST_INDEX];
 AC97LinkState *s = opaque;

 pci_device_save (s-dev, f);
@@ -1193,11 +1192,6 @@ static void ac97_save (QEMUFile *f, void *opaque)
 qemu_put_be32s (f, r-bd.ctl_len);
 }
 qemu_put_buffer (f, s-mixer_data, sizeof (s-mixer_data));
-
-active[PI_INDEX] = AUD_is_active_in (s-voice_pi) ? 1 : 0;
-active[PO_INDEX] = AUD_is_active_out (s-voice_po) ? 1 : 0;
-active[MC_INDEX] = AUD_is_active_in (s-voice_mc) ? 1 : 0;
-qemu_put_buffer (f, active, sizeof (active));
 }

 static int ac97_load (QEMUFile *f, void *opaque, int version_id)
@@ -1207,7 +1201,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int 
version_id)
 uint8_t active[LAST_INDEX];
 AC97LinkState *s = opaque;

-if (version_id != 2)
+if (version_id  2 || version_id  3)
 return -EINVAL;

 ret = pci_device_load (s-dev, f);
@@ -1232,7 +1226,8 @@ static int ac97_load (QEMUFile *f, void *opaque, int 
version_id)
 qemu_get_be32s (f, r-bd.ctl_len);
 }
 qemu_get_buffer (f, s-mixer_data, sizeof (s-mixer_data));
-qemu_get_buffer (f, active, sizeof (active));
+if (version_id  3)
+qemu_get_buffer (f, active, sizeof (active));

 #ifdef USE_MIXER
 record_select (s, mixer_load (s, AC97_Record_Select));
@@ -1337,7 +1332,7 @@ static int ac97_initfn (PCIDevice *dev)
 pci_register_bar (s-dev, 0, 256 * 4, PCI_BASE_ADDRESS_SPACE_IO,
   ac97_map);
 pci_register_bar (s-dev, 1, 64 * 4, PCI_BASE_ADDRESS_SPACE_IO, ac97_map);
-register_savevm (ac97, 0, 2, ac97_save, ac97_load, s);
+register_savevm (ac97, 0, 3, ac97_save, ac97_load, s);
 qemu_register_reset (ac97_on_reset, s);
 AUD_register_card (ac97, s-card);
 ac97_on_reset (s);
-- 
1.6.5.2





[Qemu-devel] [PATCH 10/10] ac97: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/ac97.c |  101 ++--
 1 files changed, 44 insertions(+), 57 deletions(-)

diff --git a/hw/ac97.c b/hw/ac97.c
index cc5ec30..f2d2823 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -1167,68 +1167,31 @@ static void po_callback (void *opaque, int free)
 transfer_audio (opaque, PO_INDEX, free);
 }

-static void ac97_save (QEMUFile *f, void *opaque)
-{
-size_t i;
-AC97LinkState *s = opaque;
-
-pci_device_save (s-dev, f);
-
-qemu_put_be32s (f, s-glob_cnt);
-qemu_put_be32s (f, s-glob_sta);
-qemu_put_be32s (f, s-cas);
-
-for (i = 0; i  ARRAY_SIZE (s-bm_regs); ++i) {
-AC97BusMasterRegs *r = s-bm_regs[i];
-qemu_put_be32s (f, r-bdbar);
-qemu_put_8s (f, r-civ);
-qemu_put_8s (f, r-lvi);
-qemu_put_be16s (f, r-sr);
-qemu_put_be16s (f, r-picb);
-qemu_put_8s (f, r-piv);
-qemu_put_8s (f, r-cr);
-qemu_put_be32s (f, r-bd_valid);
-qemu_put_be32s (f, r-bd.addr);
-qemu_put_be32s (f, r-bd.ctl_len);
+static const VMStateDescription vmstate_ac97_bm_regs = {
+.name = ac97_bm_regs,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_UINT32(bdbar, AC97BusMasterRegs),
+VMSTATE_UINT8(civ, AC97BusMasterRegs),
+VMSTATE_UINT8(lvi, AC97BusMasterRegs),
+VMSTATE_UINT16(sr, AC97BusMasterRegs),
+VMSTATE_UINT16(picb, AC97BusMasterRegs),
+VMSTATE_UINT8(piv, AC97BusMasterRegs),
+VMSTATE_UINT8(cr, AC97BusMasterRegs),
+VMSTATE_UINT32(bd_valid, AC97BusMasterRegs),
+VMSTATE_UINT32(bd.addr, AC97BusMasterRegs),
+VMSTATE_UINT32(bd.ctl_len, AC97BusMasterRegs),
+VMSTATE_END_OF_LIST()
 }
-qemu_put_buffer (f, s-mixer_data, sizeof (s-mixer_data));
-}
+};

-static int ac97_load (QEMUFile *f, void *opaque, int version_id)
+static int ac97_post_load (void *opaque, int version_id)
 {
-int ret;
-size_t i;
 uint8_t active[LAST_INDEX];
 AC97LinkState *s = opaque;

-if (version_id  2 || version_id  3)
-return -EINVAL;
-
-ret = pci_device_load (s-dev, f);
-if (ret)
-return ret;
-
-qemu_get_be32s (f, s-glob_cnt);
-qemu_get_be32s (f, s-glob_sta);
-qemu_get_be32s (f, s-cas);
-
-for (i = 0; i  ARRAY_SIZE (s-bm_regs); ++i) {
-AC97BusMasterRegs *r = s-bm_regs[i];
-qemu_get_be32s (f, r-bdbar);
-qemu_get_8s (f, r-civ);
-qemu_get_8s (f, r-lvi);
-qemu_get_be16s (f, r-sr);
-qemu_get_be16s (f, r-picb);
-qemu_get_8s (f, r-piv);
-qemu_get_8s (f, r-cr);
-qemu_get_be32s (f, r-bd_valid);
-qemu_get_be32s (f, r-bd.addr);
-qemu_get_be32s (f, r-bd.ctl_len);
-}
-qemu_get_buffer (f, s-mixer_data, sizeof (s-mixer_data));
-if (version_id  3)
-qemu_get_buffer (f, active, sizeof (active));
-
 #ifdef USE_MIXER
 record_select (s, mixer_load (s, AC97_Record_Select));
 #define V_(a, b) set_volume (s, a, b, mixer_load (s, a))
@@ -1247,6 +1210,30 @@ static int ac97_load (QEMUFile *f, void *opaque, int 
version_id)
 return 0;
 }

+static bool is_version_2 (void *opaque, int version_id)
+{
+return version_id == 2;
+}
+
+static const VMStateDescription vmstate_ac97 = {
+.name = ac97,
+.version_id = 3,
+.minimum_version_id = 2,
+.minimum_version_id_old = 2,
+.post_load = ac97_post_load,
+.fields  = (VMStateField []) {
+VMSTATE_PCI_DEVICE(dev, AC97LinkState),
+VMSTATE_UINT32(glob_cnt, AC97LinkState),
+VMSTATE_UINT32(glob_sta, AC97LinkState),
+VMSTATE_UINT32(cas, AC97LinkState),
+VMSTATE_STRUCT_ARRAY(bm_regs, AC97LinkState, 3, 1,
+ vmstate_ac97_bm_regs, AC97BusMasterRegs),
+VMSTATE_BUFFER(mixer_data, AC97LinkState),
+VMSTATE_UNUSED_TEST(is_version_2, 3),
+VMSTATE_END_OF_LIST()
+}
+};
+
 static void ac97_map (PCIDevice *pci_dev, int region_num,
   pcibus_t addr, pcibus_t size, int type)
 {
@@ -1332,7 +1319,7 @@ static int ac97_initfn (PCIDevice *dev)
 pci_register_bar (s-dev, 0, 256 * 4, PCI_BASE_ADDRESS_SPACE_IO,
   ac97_map);
 pci_register_bar (s-dev, 1, 64 * 4, PCI_BASE_ADDRESS_SPACE_IO, ac97_map);
-register_savevm (ac97, 0, 3, ac97_save, ac97_load, s);
+vmstate_register (0, vmstate_ac97, s);
 qemu_register_reset (ac97_on_reset, s);
 AUD_register_card (ac97, s-card);
 ac97_on_reset (s);
-- 
1.6.5.2





Re: [Qemu-devel] [PATCH v2 0/11]

2009-12-02 Thread Gleb Natapov
On Tue, Dec 01, 2009 at 10:51:26AM -0200, Glauber Costa wrote:
 This is a repost of the -smp series. Note that it depends on 
 irqchip-in-kernel,
 that is already in staging. Also, you'll have to enable the io-thread, for 
 the time
 being.
 
 From the last version, main change is that I am not calling queue_work 
 automatically
 from vcpu ioctls. queue_work is only used currently for the gdb stub.
 
 All other uses were by-passed by the new qemu_register_vcpu_reset(), since 
 most
 of it uses (all racy) came from the reset handlers.
 
Looks good to me except one thing. I don't see how you are addressing
the problem fixed by commit b8a7857071b477b28d3055e33ff0298fc91f329a
in qemu-kvm. The problem is that mp_state can change in kernel between
call to kvm_cpu_synchronize_state() and vcpu re-entry. In this case old
mp_state will overwrite new one.

--
Gleb.




[Qemu-devel] Re: [PATCH] vmstate: Avoid seeking

2009-12-02 Thread Jan Kiszka
Juan Quintela wrote:
 Jan Kiszka jan.kis...@web.de wrote:
 Seeking on vmstate save/load does not work if the underlying file is a
 stream. We could try to make all QEMUFile* forward-seek-aware, but first
 attempts in this direction indicated that it's saner to convert the few
 qemu_fseek-on-vmstates users to plain reads/writes.

 This fixes various subtle vmstate corruptions where unused fields were
 involved.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 
 Something changed lately.  This used to work, and I also waste^spend
 yesterday trying to understand why it was failing to me.

I'm quite sure it never really worked. Maybe the bug was just papered over.

 
 I am splitting the patch in virtio-net and savevm parts.  (In my tree
 virtio-net don't use fseek anymore).

OK, then I will drop this patch from my queue. BTW, where is your tree
hosted?

 
 Thanks for finding the bug.
 
 Later, Juan.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux




[Qemu-devel] Re: [PATCH v3 00/10] mean audio: port to vmstate

2009-12-02 Thread Juan Quintela
Juan Quintela quint...@redhat.com wrote:
 [v3]

Sorry to forget to put the subject in the 1st email.

Later, Juan.




Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread andrzej zaborowski
2009/12/1 Alexander Graf ag...@suse.de:
 Maintainership for a subsystem is completely different from feeling 
 responsible for patches. You can be the person checking stuff in without 
 knowing anything about the subsystem. If it breaks, have the community fix 
 it. If it stays broken and nobody cares, remove the subsystem.

If it leads to removing the subsystem then it's not much gain for the
project and the users :)

I don't know of any succesful project that has maintainers who don't
feel responsible for the code they're comming.

Cheers




Re: [Qemu-devel] [PATCH v2 05/11] tell kernel about all registers instead of just mp_state

2009-12-02 Thread Glauber Costa
 +{
 +    if (kvm_enabled()) {
 Is this ever called or intended to be called when kvm is disabled?

 +        kvm_cpu_flush_state(env);
 +    }

I don't think so. But this is here for consistency with its synchronize brother.


-- 
Glauber  Costa.
Free as in Freedom
http://glommer.net

The less confident you are, the more serious you have to act.




[Qemu-devel] Re: [PATCH] vmstate: Avoid seeking

2009-12-02 Thread Juan Quintela
Jan Kiszka jan.kis...@siemens.com wrote:
 Juan Quintela wrote:
 Jan Kiszka jan.kis...@web.de wrote:
 Seeking on vmstate save/load does not work if the underlying file is a
 stream. We could try to make all QEMUFile* forward-seek-aware, but first
 attempts in this direction indicated that it's saner to convert the few
 qemu_fseek-on-vmstates users to plain reads/writes.

 This fixes various subtle vmstate corruptions where unused fields were
 involved.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 
 Something changed lately.  This used to work, and I also waste^spend
 yesterday trying to understand why it was failing to me.

 I'm quite sure it never really worked. Maybe the bug was just papered over.

 
 I am splitting the patch in virtio-net and savevm parts.  (In my tree
 virtio-net don't use fseek anymore).

 OK, then I will drop this patch from my queue. BTW, where is your tree
 hosted?

http://repo.or.cz/w/qemu/quintela.git/shortlog/refs/heads/vmstate/virtio

This one has not still in upstream:
- the audio changes that I have just posted
- vmstate cleanups (yours and more)
- msix/virtio port to vmstate

I am splitting vmstate/cleanups at this moment to send the two series
upstream.  I am in the point where everything compiles and run,
i.e. only need to reorder patches.

Later, Juan.

 
 Thanks for finding the bug.
 
 Later, Juan.

 Jan




[Qemu-devel] [PATCH v2] Don't leak file descriptors

2009-12-02 Thread Kevin Wolf
We're leaking file descriptors to child processes. Set FD_CLOEXEC on file
descriptors that don't need to be passed to children to stop this misbehaviour.

Signed-off-by: Kevin Wolf kw...@redhat.com
---

v2:
- The existence of SOCK_CLOEXEC doesn't mean that accept4 exists. Added a check
  for it in configure.

 block/raw-posix.c  |2 +-
 configure  |   20 ++
 gdbstub.c  |6 +++
 kvm-all.c  |2 +-
 migration-tcp.c|6 +-
 migration-unix.c   |6 +-
 net.c  |8 ++--
 osdep.c|  104 +++-
 posix-aio-compat.c |2 +-
 qemu-char.c|8 ++--
 qemu-common.h  |7 +++
 qemu-sockets.c |   10 ++--
 qemu_socket.h  |2 +
 slirp/misc.c   |4 +-
 slirp/slirp.h  |4 ++
 slirp/socket.c |2 +-
 slirp/tcp_subr.c   |2 +-
 slirp/udp.c|4 +-
 vl.c   |   11 +++--
 vnc.c  |2 +-
 20 files changed, 178 insertions(+), 34 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 266d841..0359e43 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -153,7 +153,7 @@ static int raw_open_common(BlockDriverState *bs, const char 
*filename,
 s-open_flags |= O_DSYNC;
 
 s-fd = -1;
-fd = open(filename, s-open_flags, 0644);
+fd = qemu_open(filename, s-open_flags, 0644);
 if (fd  0) {
 ret = -errno;
 if (ret == -EROFS)
diff --git a/configure b/configure
index dca5a43..0a1e347 100755
--- a/configure
+++ b/configure
@@ -1550,6 +1550,23 @@ if compile_prog   ; then
   pipe2=yes
 fi
 
+# check if accept4 is there
+accept4=no
+cat  $TMPC  EOF
+#define _GNU_SOURCE
+#include sys/socket.h
+#include stddef.h
+
+int main(void)
+{
+accept4(0, NULL, NULL, SOCK_CLOEXEC);
+return 0;
+}
+EOF
+if compile_prog   ; then
+  accept4=yes
+fi
+
 # check if tee/splice is there. vmsplice was added same time.
 splice=no
 cat  $TMPC  EOF
@@ -2013,6 +2030,9 @@ fi
 if test $pipe2 = yes ; then
   echo CONFIG_PIPE2=y  $config_host_mak
 fi
+if test $accept4 = yes ; then
+  echo CONFIG_ACCEPT4=y  $config_host_mak
+fi
 if test $splice = yes ; then
   echo CONFIG_SPLICE=y  $config_host_mak
 fi
diff --git a/gdbstub.c b/gdbstub.c
index 055093f..5a4f7d4 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2356,6 +2356,9 @@ static void gdb_accept(void)
 perror(accept);
 return;
 } else if (fd = 0) {
+#ifndef _WIN32
+fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
 break;
 }
 }
@@ -2385,6 +2388,9 @@ static int gdbserver_open(int port)
 perror(socket);
 return -1;
 }
+#ifndef _WIN32
+fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
 
 /* allow fast reuse */
 val = 1;
diff --git a/kvm-all.c b/kvm-all.c
index b605caa..b8ffe54 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -416,7 +416,7 @@ int kvm_init(int smp_cpus)
 s-slots[i].slot = i;
 
 s-vmfd = -1;
-s-fd = open(/dev/kvm, O_RDWR);
+s-fd = qemu_open(/dev/kvm, O_RDWR);
 if (s-fd == -1) {
 fprintf(stderr, Could not access KVM kernel module: %m\n);
 ret = -errno;
diff --git a/migration-tcp.c b/migration-tcp.c
index efa7c74..4bd19ed 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -104,7 +104,7 @@ MigrationState *tcp_start_outgoing_migration(const char 
*host_port,
 s-state = MIG_STATE_ACTIVE;
 s-mon_resume = NULL;
 s-bandwidth_limit = bandwidth_limit;
-s-fd = socket(PF_INET, SOCK_STREAM, 0);
+s-fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
 if (s-fd == -1) {
 qemu_free(s);
 return NULL;
@@ -144,7 +144,7 @@ static void tcp_accept_incoming_migration(void *opaque)
 int c, ret;
 
 do {
-c = accept(s, (struct sockaddr *)addr, addrlen);
+c = qemu_accept(s, (struct sockaddr *)addr, addrlen);
 } while (c == -1  socket_error() == EINTR);
 
 dprintf(accepted migration\n);
@@ -191,7 +191,7 @@ int tcp_start_incoming_migration(const char *host_port)
 return -EINVAL;
 }
 
-s = socket(PF_INET, SOCK_STREAM, 0);
+s = qemu_socket(PF_INET, SOCK_STREAM, 0);
 if (s == -1)
 return -socket_error();
 
diff --git a/migration-unix.c b/migration-unix.c
index 25cd6d3..4d03f6a 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -103,7 +103,7 @@ MigrationState *unix_start_outgoing_migration(const char 
*path,
 s-state = MIG_STATE_ACTIVE;
 s-mon_resume = NULL;
 s-bandwidth_limit = bandwidth_limit;
-s-fd = socket(PF_UNIX, SOCK_STREAM, 0);
+s-fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
 if (s-fd  0) {
 dprintf(Unable to open socket);
 goto err_after_alloc;
@@ -148,7 +148,7 @@ static void unix_accept_incoming_migration(void *opaque)
 int c, ret;
 
 do {
-c = accept(s, (struct sockaddr *)addr, addrlen);
+c = qemu_accept(s, (struct sockaddr *)addr, addrlen);
 } while (c == -1  socket_error() == EINTR);
 
 

[Qemu-devel] Re: [PATCH v2] Don't leak file descriptors

2009-12-02 Thread Kevin Wolf
Am 02.12.2009 12:24, schrieb Kevin Wolf:
 We're leaking file descriptors to child processes. Set FD_CLOEXEC on file
 descriptors that don't need to be passed to children to stop this 
 misbehaviour.
 
 Signed-off-by: Kevin Wolf kw...@redhat.com
 ---
 
 v2:
 - The existence of SOCK_CLOEXEC doesn't mean that accept4 exists. Added a 
 check
   for it in configure.

v3 even. Anthony, I hope this doesn't confuse your scripts?

Kevin




Re: [Qemu-devel] Unclear committer situation

2009-12-02 Thread Riku Voipio
On Tue, Dec 01, 2009 at 12:51:25PM -0600, Anthony Liguori wrote:
 There are some subsystems where nobody feels responsible though,  
 apparently hoping 'someone else' will tske on it. Well, turns out it  
 doesn't work that way.

 The general problem is that someone has to step up to maintain these  
 subsystems.  For some of them, there just isn't really a lot of interest.

I and Juha can take maintainence of the omap2 (and future omap3) stuff,
which obviously isn't mainted by anyone at the moment:

http://www.mail-archive.com/qemu-devel@nongnu.org/msg17487.html
http://lists.gnu.org/archive/html/qemu-devel/2009-06/msg00326.html

6 months for no action on a patch that fixes a fails to boot bug? No
wonder the android people have forked qemu so far...

 git pulls have been working really well for linux-user.  I'd like to  
 continue that for new architectures.

I can provide the patches in the same way as git pull requests.





[Qemu-devel] [PATCH 01/12] vmstate: Avoid seeking

2009-12-02 Thread Juan Quintela
From: Jan Kiszka jan.kis...@web.de

Seeking on vmstate save/load does not work if the underlying file is a
stream. We could try to make all QEMUFile* forward-seek-aware, but first
attempts in this direction indicated that it's saner to convert the few
qemu_fseek-on-vmstates users to plain reads/writes.

This fixes various subtle vmstate corruptions where unused fields were
involved.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 savevm.c |   20 +---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/savevm.c b/savevm.c
index 18c2e54..833bf3c 100644
--- a/savevm.c
+++ b/savevm.c
@@ -959,13 +959,27 @@ const VMStateInfo vmstate_info_buffer = {

 static int get_unused_buffer(QEMUFile *f, void *pv, size_t size)
 {
-qemu_fseek(f, size, SEEK_CUR);
-return 0;
+uint8_t buf[1024];
+int block_len;
+
+while (size  0) {
+block_len = MIN(sizeof(buf), size);
+size -= block_len;
+qemu_get_buffer(f, buf, block_len);
+}
+   return 0;
 }

 static void put_unused_buffer(QEMUFile *f, void *pv, size_t size)
 {
-qemu_fseek(f, size, SEEK_CUR);
+static const uint8_t buf[1024];
+int block_len;
+
+while (size  0) {
+block_len = MIN(sizeof(buf), size);
+size -= block_len;
+qemu_put_buffer(f, buf, block_len);
+}
 }

 const VMStateInfo vmstate_info_unused_buffer = {
-- 
1.6.5.2





[Qemu-devel] [PATCH 02/12] vmstate: Fix info field of VMSTATE_MACADDR

2009-12-02 Thread Juan Quintela
From: Jan Kiszka jan.kis...@siemens.com

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 7889aa3..c3c0c9f 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -545,7 +545,7 @@ extern const VMStateDescription vmstate_i2c_slave;
 #define VMSTATE_MACADDR(_field, _state) {\
 .name   = (stringify(_field)),   \
 .size   = sizeof(MACAddr),   \
-.info   = vmstate_info_uint8,   \
+.info   = vmstate_info_buffer,  \
 .flags  = VMS_BUFFER,\
 .offset = vmstate_offset_macaddr(_state, _field),\
 }
-- 
1.6.5.2





[Qemu-devel] [PATCH 03/12] vmstate: fix missing ARRAY_OF_POINTERS support on save state

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 savevm.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/savevm.c b/savevm.c
index 833bf3c..8fac502 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1206,6 +1206,9 @@ void vmstate_save_state(QEMUFile *f, const 
VMStateDescription *vmsd,
 for (i = 0; i  n_elems; i++) {
 void *addr = base_addr + field-size * i;

+if (field-flags  VMS_ARRAY_OF_POINTER) {
+addr = *(void **)addr;
+}
 if (field-flags  VMS_STRUCT) {
 vmstate_save_state(f, field-vmsd, addr);
 } else {
-- 
1.6.5.2





[Qemu-devel] [PATCH 04/12] vmstate: Add support for VBUFFERS

2009-12-02 Thread Juan Quintela
Support for buffer that are pointed by a pointer (i.e. not embedded)
where the size that we want to use is a field in the state.
We also need a new place to store where to start in the middle of the
buffer, as now it is a pointer, not the offset of the 1st field.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h  |   20 
 savevm.c |   20 ++--
 2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index c3c0c9f..47fb12b 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -294,14 +294,17 @@ enum VMStateFlags {
 VMS_BUFFER   = 0x020,  /* static sized buffer */
 VMS_ARRAY_OF_POINTER = 0x040,
 VMS_VARRAY_UINT16= 0x080,  /* Array with size in uint16_t field */
+VMS_VBUFFER  = 0x100,  /* Buffer with size in int32_t field */
 };

 typedef struct {
 const char *name;
 size_t offset;
 size_t size;
+size_t start;
 int num;
 size_t num_offset;
+size_t size_offset;
 const VMStateInfo *info;
 enum VMStateFlags flags;
 const VMStateDescription *vmsd;
@@ -490,6 +493,17 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 .offset   = vmstate_offset_buffer(_state, _field) + _start,  \
 }

+#define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) 
{ \
+.name = (stringify(_field)), \
+.version_id   = (_version),  \
+.field_exists = (_test), \
+.size_offset  = vmstate_offset_value(_state, _field_size, int32_t),\
+.info = vmstate_info_buffer,\
+.flags= VMS_VBUFFER|VMS_POINTER, \
+.offset   = offsetof(_state, _field),\
+.start= (_start),\
+}
+
 #define VMSTATE_BUFFER_UNSAFE_INFO(_field, _state, _version, _info, _size) { \
 .name   = (stringify(_field)),   \
 .version_id = (_version),\
@@ -683,6 +697,12 @@ extern const VMStateDescription vmstate_i2c_slave;
 #define VMSTATE_BUFFER_START_MIDDLE(_f, _s, _start) \
 VMSTATE_STATIC_BUFFER(_f, _s, 0, NULL, _start, sizeof(typeof_field(_s, 
_f)))

+#define VMSTATE_PARTIAL_VBUFFER(_f, _s, _size)\
+VMSTATE_VBUFFER(_f, _s, 0, NULL, 0, _size)
+
+#define VMSTATE_SUB_VBUFFER(_f, _s, _start, _size)\
+VMSTATE_VBUFFER(_f, _s, 0, NULL, _start, _size)
+
 #define VMSTATE_BUFFER_TEST(_f, _s, _test)\
 VMSTATE_STATIC_BUFFER(_f, _s, 0, _test, 0, sizeof(typeof_field(_s, _f)))

diff --git a/savevm.c b/savevm.c
index 8fac502..2715f8f 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1143,7 +1143,11 @@ int vmstate_load_state(QEMUFile *f, const 
VMStateDescription *vmsd,
  field-version_id = version_id)) {
 void *base_addr = opaque + field-offset;
 int ret, i, n_elems = 1;
+int size = field-size;

+if (field-flags  VMS_VBUFFER) {
+size = *(int32_t *)(opaque+field-size_offset);
+}
 if (field-flags  VMS_ARRAY) {
 n_elems = field-num;
 } else if (field-flags  VMS_VARRAY_INT32) {
@@ -1152,10 +1156,10 @@ int vmstate_load_state(QEMUFile *f, const 
VMStateDescription *vmsd,
 n_elems = *(uint16_t *)(opaque+field-num_offset);
 }
 if (field-flags  VMS_POINTER) {
-base_addr = *(void **)base_addr;
+base_addr = *(void **)base_addr + field-start;
 }
 for (i = 0; i  n_elems; i++) {
-void *addr = base_addr + field-size * i;
+void *addr = base_addr + size * i;

 if (field-flags  VMS_ARRAY_OF_POINTER) {
 addr = *(void **)addr;
@@ -1163,7 +1167,7 @@ int vmstate_load_state(QEMUFile *f, const 
VMStateDescription *vmsd,
 if (field-flags  VMS_STRUCT) {
 ret = vmstate_load_state(f, field-vmsd, addr, 
field-vmsd-version_id);
 } else {
-ret = field-info-get(f, addr, field-size);
+ret = field-info-get(f, addr, size);

 }
 if (ret  0) {
@@ -1192,7 +1196,11 @@ void vmstate_save_state(QEMUFile *f, const 
VMStateDescription *vmsd,
 field-field_exists(opaque, vmsd-version_id)) {
 void *base_addr = opaque + field-offset;
 int i, n_elems = 1;
+int size = field-size;

+if (field-flags  VMS_VBUFFER) {
+size = *(int32_t *)(opaque+field-size_offset);
+}
 if (field-flags  VMS_ARRAY) {
 n_elems = field-num;
 } else if (field-flags  VMS_VARRAY_INT32) {
@@ -1201,10 +1209,10 @@ void vmstate_save_state(QEMUFile 

[Qemu-devel] [PATCH 05/12] vmstate: Introduce VMSTATE_STRUCT_TEST

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h |   18 +++---
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 47fb12b..0f4442a 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -436,13 +436,14 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 .offset = offsetof(_state, _field),  \
 }

-#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) { \
-.name   = (stringify(_field)),   \
-.version_id = (_version),\
-.vmsd   = (_vmsd),  \
-.size   = sizeof(_type), \
-.flags  = VMS_STRUCT,\
-.offset = vmstate_offset_value(_state, _field, _type),   \
+#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) { \
+.name = (stringify(_field)), \
+.version_id   = (_version),  \
+.field_exists = (_test), \
+.vmsd = (_vmsd),\
+.size = sizeof(_type),   \
+.flags= VMS_STRUCT,  \
+.offset   = vmstate_offset_value(_state, _field, _type), \
 }

 #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) {   \
@@ -574,6 +575,9 @@ extern const VMStateDescription vmstate_i2c_slave;
 #define VMSTATE_SINGLE(_field, _state, _version, _info, _type)\
 VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type)

+#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)\
+VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)
+
 #define VMSTATE_INT8_V(_f, _s, _v)\
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
 #define VMSTATE_INT16_V(_f, _s, _v)   \
-- 
1.6.5.2





[Qemu-devel] [PATCH 06/12] vmstate: Introduce VMSTATE_STRUCT_POINTER_TEST

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h |   16 ++--
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 0f4442a..0a5acd4 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -446,12 +446,13 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 .offset   = vmstate_offset_value(_state, _field, _type), \
 }

-#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) {   \
-.name   = (stringify(_field)),   \
-.vmsd   = (_vmsd),  \
-.size   = sizeof(_type), \
-.flags  = VMS_STRUCT|VMS_POINTER,\
-.offset = vmstate_offset_value(_state, _field, _type),   \
+#define VMSTATE_STRUCT_POINTER_TEST(_field, _state, _test, _vmsd, _type) { \
+.name = (stringify(_field)), \
+.field_exists = (_test), \
+.vmsd = (_vmsd),\
+.size = sizeof(_type),   \
+.flags= VMS_STRUCT|VMS_POINTER,  \
+.offset   = vmstate_offset_value(_state, _field, _type), \
 }

 #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) 
{\
@@ -578,6 +579,9 @@ extern const VMStateDescription vmstate_i2c_slave;
 #define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type)\
 VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type)

+#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type)  \
+VMSTATE_STRUCT_POINTER_TEST(_field, _state, NULL, _vmsd, _type)
+
 #define VMSTATE_INT8_V(_f, _s, _v)\
 VMSTATE_SINGLE(_f, _s, _v, vmstate_info_int8, int8_t)
 #define VMSTATE_INT16_V(_f, _s, _v)   \
-- 
1.6.5.2





[Qemu-devel] [PATCH 07/12] vmstate: Introduce UINT16_TEST support

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 0a5acd4..5994d86 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -633,6 +633,9 @@ extern const VMStateDescription vmstate_i2c_slave;
 #define VMSTATE_INT32_LE(_f, _s)   \
 VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t)

+#define VMSTATE_UINT16_TEST(_f, _s, _t)   \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint16, uint16_t)
+
 #define VMSTATE_UINT32_TEST(_f, _s, _t)  \
 VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_uint32, uint32_t)

-- 
1.6.5.2





[Qemu-devel] [PATCH 08/12] vmstate: remove usused VMSTATE_STRUCT_ARRAY_SIZE_UINT8

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h |   10 --
 1 files changed, 0 insertions(+), 10 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 5994d86..41e13cc 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -475,16 +475,6 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 .offset = vmstate_offset_array(_state, _field, _type, _num), \
 }

-#define VMSTATE_STRUCT_ARRAY_SIZE_UINT8(_field, _state, _field__num, _version, 
_vmsd, _type) { \
-.name   = (stringify(_field)),   \
-.num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \
-.version_id = (_version),\
-.vmsd   = (_vmsd),  \
-.size   = sizeof(_type), \
-.flags  = VMS_STRUCT|VMS_ARRAY,  \
-.offset = vmstate_offset_array(_state, _field, _type, _num), \
-}
-
 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) 
{ \
 .name = (stringify(_field)), \
 .version_id   = (_version),  \
-- 
1.6.5.2





[Qemu-devel] [PATCH 11/12] qdev: enable vmstate_unregister() support

2009-12-02 Thread Juan Quintela
Now vmstate_unregister have the right type

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/qdev.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index d19d531..e9d76d4 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -296,10 +296,8 @@ void qdev_free(DeviceState *dev)
 bus = QLIST_FIRST(dev-child_bus);
 qbus_free(bus);
 }
-#if 0 /* FIXME: need sane vmstate_unregister function */
 if (dev-info-vmsd)
 vmstate_unregister(dev-info-vmsd, dev);
-#endif
 if (dev-info-exit)
 dev-info-exit(dev);
 if (dev-opts)
-- 
1.6.5.2





[Qemu-devel] [PATCH 09/12] vmstate: Add support for multiplying size for a constant

2009-12-02 Thread Juan Quintela
When the size that we want to transmit is in another field, but in an
unit different that bytes

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h  |   13 +
 savevm.c |6 ++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 41e13cc..5f34991 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -295,6 +295,7 @@ enum VMStateFlags {
 VMS_ARRAY_OF_POINTER = 0x040,
 VMS_VARRAY_UINT16= 0x080,  /* Array with size in uint16_t field */
 VMS_VBUFFER  = 0x100,  /* Buffer with size in int32_t field */
+VMS_MULTIPLY = 0x200,  /* multiply size field by field_size */
 };

 typedef struct {
@@ -485,6 +486,18 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 .offset   = vmstate_offset_buffer(_state, _field) + _start,  \
 }

+#define VMSTATE_BUFFER_MULTIPLY(_field, _state, _version, _test, _start, 
_field_size, _multiply) { \
+.name = (stringify(_field)), \
+.version_id   = (_version),  \
+.field_exists = (_test), \
+.size_offset  = vmstate_offset_value(_state, _field_size, uint32_t),\
+.size = (_multiply),  \
+.info = vmstate_info_buffer,\
+.flags= VMS_VBUFFER|VMS_MULTIPLY,\
+.offset   = offsetof(_state, _field),\
+.start= (_start),\
+}
+
 #define VMSTATE_VBUFFER(_field, _state, _version, _test, _start, _field_size) 
{ \
 .name = (stringify(_field)), \
 .version_id   = (_version),  \
diff --git a/savevm.c b/savevm.c
index 2715f8f..c7da4a6 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1147,6 +1147,9 @@ int vmstate_load_state(QEMUFile *f, const 
VMStateDescription *vmsd,

 if (field-flags  VMS_VBUFFER) {
 size = *(int32_t *)(opaque+field-size_offset);
+if (field-flags  VMS_MULTIPLY) {
+size *= field-size;
+}
 }
 if (field-flags  VMS_ARRAY) {
 n_elems = field-num;
@@ -1200,6 +1203,9 @@ void vmstate_save_state(QEMUFile *f, const 
VMStateDescription *vmsd,

 if (field-flags  VMS_VBUFFER) {
 size = *(int32_t *)(opaque+field-size_offset);
+if (field-flags  VMS_MULTIPLY) {
+size *= field-size;
+}
 }
 if (field-flags  VMS_ARRAY) {
 n_elems = field-num;
-- 
1.6.5.2





[Qemu-devel] [PATCH 10/12] pci: vmstate_register() already assign consecutive numbers starting at 0

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/pci.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 8cf008d..3f855b3 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -161,8 +161,6 @@ PCIBus *pci_find_root_bus(int domain)
 void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
  const char *name, int devfn_min)
 {
-static int nbus = 0;
-
 qbus_create_inplace(bus-qbus, pci_bus_info, parent, name);
 bus-devfn_min = devfn_min;

@@ -170,7 +168,7 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
 QLIST_INIT(bus-child);
 pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported */

-vmstate_register(nbus++, vmstate_pcibus, bus);
+vmstate_register(-1, vmstate_pcibus, bus);
 qemu_register_reset(pci_bus_reset, bus);
 }

-- 
1.6.5.2





[Qemu-devel] [PATCH 12/12] savevm: Port to qdev.vmsd all devices that have qdev

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/ac97.c |2 +-
 hw/cirrus_vga.c   |2 +-
 hw/cs4231a.c  |2 +-
 hw/e1000.c|4 +---
 hw/es1370.c   |2 +-
 hw/gus.c  |2 +-
 hw/lance.c|   14 --
 hw/lm832x.c   |2 +-
 hw/lsi53c895a.c   |2 +-
 hw/max7310.c  |2 +-
 hw/ne2000-isa.c   |   12 +++-
 hw/ne2000.c   |3 +--
 hw/pckbd.c|   13 -
 hw/pcnet.c|4 +---
 hw/piix_pci.c |4 ++--
 hw/rtl8139.c  |4 +---
 hw/sb16.c |2 +-
 hw/ssd0303.c  |2 +-
 hw/tmp105.c   |2 +-
 hw/twl92230.c |2 +-
 hw/usb-uhci.c |3 ++-
 hw/vga-pci.c  |2 +-
 hw/vmware_vga.c   |2 +-
 hw/wdt_i6300esb.c |3 +--
 hw/wdt_ib700.c|2 +-
 hw/wm8750.c   |2 +-
 26 files changed, 60 insertions(+), 36 deletions(-)

diff --git a/hw/ac97.c b/hw/ac97.c
index f2d2823..62e349a 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -1319,7 +1319,6 @@ static int ac97_initfn (PCIDevice *dev)
 pci_register_bar (s-dev, 0, 256 * 4, PCI_BASE_ADDRESS_SPACE_IO,
   ac97_map);
 pci_register_bar (s-dev, 1, 64 * 4, PCI_BASE_ADDRESS_SPACE_IO, ac97_map);
-vmstate_register (0, vmstate_ac97, s);
 qemu_register_reset (ac97_on_reset, s);
 AUD_register_card (ac97, s-card);
 ac97_on_reset (s);
@@ -1336,6 +1335,7 @@ static PCIDeviceInfo ac97_info = {
 .qdev.name= AC97,
 .qdev.desc= Intel 82801AA AC97 Audio,
 .qdev.size= sizeof (AC97LinkState),
+.qdev.vmsd= vmstate_ac97,
 .init = ac97_initfn,
 };

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index d76e5bb..1194b5a 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -3245,7 +3245,6 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
  pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
   PCI_BASE_ADDRESS_SPACE_MEMORY, cirrus_pci_mmio_map);
  }
- vmstate_register(0, vmstate_pci_cirrus_vga, d);

  /* ROM BIOS */
  rom_add_vga(VGABIOS_CIRRUS_FILENAME);
@@ -3260,6 +3259,7 @@ void pci_cirrus_vga_init(PCIBus *bus)
 static PCIDeviceInfo cirrus_vga_info = {
 .qdev.name= Cirrus VGA,
 .qdev.size= sizeof(PCICirrusVGAState),
+.qdev.vmsd= vmstate_pci_cirrus_vga,
 .init = pci_cirrus_vga_initfn,
 .config_write = pci_cirrus_write_config,
 };
diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index 7c29aa8..4d5ce5c 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -651,7 +651,6 @@ static int cs4231a_initfn (ISADevice *dev)

 DMA_register_channel (s-dma, cs_dma_read, s);

-vmstate_register (0, vmstate_cs4231a, s);
 qemu_register_reset (cs_reset, s);
 cs_reset (s);

@@ -669,6 +668,7 @@ static ISADeviceInfo cs4231a_info = {
 .qdev.name = cs4231a,
 .qdev.desc = Crystal Semiconductor CS4231A,
 .qdev.size = sizeof (CSState),
+.qdev.vmsd = vmstate_cs4231a,
 .init  = cs4231a_initfn,
 .qdev.props= (Property[]) {
 DEFINE_PROP_HEX32  (iobase,  CSState, port, 0x534),
diff --git a/hw/e1000.c b/hw/e1000.c
index 00f6a57..782a60b 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1051,7 +1051,6 @@ pci_e1000_uninit(PCIDevice *dev)

 cpu_unregister_io_memory(d-mmio_index);
 qemu_del_vlan_client(d-vc);
-vmstate_unregister(vmstate_e1000, d);
 return 0;
 }

@@ -1116,8 +1115,6 @@ static int pci_e1000_init(PCIDevice *pci_dev)

 qemu_format_nic_info_str(d-vc, macaddr);

-vmstate_register(-1, vmstate_e1000, d);
-
 if (!pci_dev-qdev.hotplugged) {
 static int loaded = 0;
 if (!loaded) {
@@ -1139,6 +1136,7 @@ static PCIDeviceInfo e1000_info = {
 .qdev.desc  = Intel Gigabit Ethernet,
 .qdev.size  = sizeof(E1000State),
 .qdev.reset = qdev_e1000_reset,
+.qdev.vmsd  = vmstate_e1000,
 .init   = pci_e1000_init,
 .exit   = pci_e1000_uninit,
 .qdev.props = (Property[]) {
diff --git a/hw/es1370.c b/hw/es1370.c
index 4e646dc..c358253 100644
--- a/hw/es1370.c
+++ b/hw/es1370.c
@@ -1023,7 +1023,6 @@ static int es1370_initfn (PCIDevice *dev)
 c[0x3f] = 0x80;

 pci_register_bar (s-dev, 0, 256, PCI_BASE_ADDRESS_SPACE_IO, es1370_map);
-vmstate_register (0, vmstate_es1370, s);
 qemu_register_reset (es1370_on_reset, s);

 AUD_register_card (es1370, s-card);
@@ -1041,6 +1040,7 @@ static PCIDeviceInfo es1370_info = {
 .qdev.name= ES1370,
 .qdev.desc= ENSONIQ AudioPCI ES1370,
 .qdev.size= sizeof (ES1370State),
+.qdev.vmsd= vmstate_es1370,
 .init = es1370_initfn,
 };

diff --git a/hw/gus.c b/hw/gus.c
index d35da0a..e9016d8 100644
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -287,7 +287,6 @@ static int gus_initfn (ISADevice *dev)

 AUD_set_active_out (s-voice, 1);

-vmstate_register (0, vmstate_gus, s);
 return 0;
 }

@@ -301,6 +300,7 @@ static ISADeviceInfo gus_info = {
 .qdev.name = gus,
 

Re: [Qemu-devel] [PATCH v2 0/11]

2009-12-02 Thread Glauber Costa
On Wed, Dec 2, 2009 at 8:59 AM, Gleb Natapov g...@redhat.com wrote:
 On Tue, Dec 01, 2009 at 10:51:26AM -0200, Glauber Costa wrote:
 This is a repost of the -smp series. Note that it depends on 
 irqchip-in-kernel,
 that is already in staging. Also, you'll have to enable the io-thread, for 
 the time
 being.

 From the last version, main change is that I am not calling queue_work 
 automatically
 from vcpu ioctls. queue_work is only used currently for the gdb stub.

 All other uses were by-passed by the new qemu_register_vcpu_reset(), since 
 most
 of it uses (all racy) came from the reset handlers.

 Looks good to me except one thing. I don't see how you are addressing
 the problem fixed by commit b8a7857071b477b28d3055e33ff0298fc91f329a
 in qemu-kvm. The problem is that mp_state can change in kernel between
 call to kvm_cpu_synchronize_state() and vcpu re-entry. In this case old
 mp_state will overwrite new one.

I plan to do it in a patch that already lives on my tree. It basically flushes
register state in early post_load


-- 
Glauber  Costa.
Free as in Freedom
http://glommer.net

The less confident you are, the more serious you have to act.




Re: [Qemu-devel] Re: [PATCH v2] Don't leak file descriptors

2009-12-02 Thread Scott Tsai
On Wed, Dec 2, 2009 at 7:26 PM, Kevin Wolf kw...@redhat.com wrote:
 v3 even. Anthony, I hope this doesn't confuse your scripts?

Kevin, I see use of fopen, fdopen, popen, eventfd in qemu without the
equivalent of CLOEXEC set.
Do you want to handle those in this patch series as well?




[Qemu-devel] Re: [PATCH v2 0/11]

2009-12-02 Thread Jan Kiszka
Gleb Natapov wrote:
 On Tue, Dec 01, 2009 at 10:51:26AM -0200, Glauber Costa wrote:
 This is a repost of the -smp series. Note that it depends on 
 irqchip-in-kernel,
 that is already in staging. Also, you'll have to enable the io-thread, for 
 the time
 being.

 From the last version, main change is that I am not calling queue_work 
 automatically
 from vcpu ioctls. queue_work is only used currently for the gdb stub.

 All other uses were by-passed by the new qemu_register_vcpu_reset(), since 
 most
 of it uses (all racy) came from the reset handlers.

 Looks good to me except one thing. I don't see how you are addressing
 the problem fixed by commit b8a7857071b477b28d3055e33ff0298fc91f329a
 in qemu-kvm. The problem is that mp_state can change in kernel between
 call to kvm_cpu_synchronize_state() and vcpu re-entry. In this case old
 mp_state will overwrite new one.

+ nmi_pending
+ sipi_vector

These things need to be fixed at kernel level as discussed recently:
Asynchronous changes done by in-kernel subsystems need to be queued and
replayed with a higher priority than user space changes. User space need
to stop the vm if it does not want to be overruled.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux




[Qemu-devel] [PATCH 00/41] virtio: port to vmstate

2009-12-02 Thread Juan Quintela
Hi

this patch series run on top of my previous vmstate cleanups and fixes.
It ports virtio* and msix at the same time (msix and virtio-pci are too 
entangled
to do it separately).  It contains:

- Use DO_UPCAST instead of local function for doing the casts
- virtio: add a type field (pci and syborg by now).
- strange pci bindings for virtio are gone (i.e. config and queues are handled
  explicitely for pci, the ones that used them).
- virtio-net: make vlans to use uint8_t instead of uint32_t array, that
  makes it work through big_endian/low endian migrations.  This needs testing
  from people that use the feature.
- virtio-blk: It has no hope for migration between 32/64bits hosts or
  big-endian/little-endian.  It sends a structure with memcpy that contains:
  - target_phys_addr_t (32 or 64 bits depending on host/guest)
  - void * (again it depends on host)
  - size_t (it depends on host again)
  I didn't changed it, but we should.
- virtio-blk: change the list of requests to QLIST.  I also needed a
  QLIST_COPY_HEAD to not have to break the abstraction, created it.

Later, Juan.

Juan Quintela (40):
  virtio: Teach virtio-balloon about DO_UPCAST
  virtio: Teach virtio-blk about DO_UPCAST
  virtio: Teach virtio-console about DO_UPCAST
  virtio: Teach virtio-net about DO_UPCAST
  virtio-console: Remove useless casts
  virtio: Use DO_UPCAST instead of a cast
  virtio-pci: Remove duplicate test
  msix: Store sizes that we send/receive
  msix: port to vmstate
  virtio: Introduce type field to distingish between PCI and Syborg
  virtio-pci: port pci config to vmstate
  msix: msix_load/save are not needed anymore
  virtio: remove save/load_config for virtio
  virtio: remove save/load_queue for virtio
  virtio: Add num_pci_queues field
  virtio: split virtio_post_load() from virtio_load()
  virtio: change config_len type to int32_t
  virtio: use the right types for VirtQueue elements
  virtio: abstract test for save/load values
  virtio: port to vmstate
  virtio-net: change tx_timer_active to uint32_t
  virtio-net: change mergeable_rx_bufs to uint32_t
  virtio-net: use type checking version of qemu_put/get-*
  virtio-net: MAC_TABLE_ENTRIES has never been bigger
  virtio-net: we know vlans size at compile time, make it static
  virtio-net: abstract vlans operations
  virtio-net: make vlan operations on uint8_t, not uint32_t
  virtio-net: in_use and first_multi only handle unsigned values
  virtio-net: use save/load type chek functions for has_vent_hdr
  virtio-net: we know macs size at compile time, make it static
  virtio-net: split virtio_net_post_load
  virtio-net: port to vmstate
  virtio-console: port to vmstate
  virtio-balloon: port to vmstate
  virtio-blk: change rq type to VirtIOBlockReq
  QLIST: Introduce QLIST_COPY_HEAD
  virtio-blk: use QLIST for the list of requests
  virtio-blk: add VirtIOBlokReqHead type
  virtio-blk: port to vmstate
  virtio: virtio_save/load are not used anymore

Michael S. Tsirkin (1):
  qemu/pci: document msix_entries_nr field

 hw/hw.h |   10 +++
 hw/msix.c   |   37 ++---
 hw/msix.h   |3 +-
 hw/pci.h|6 +-
 hw/syborg_virtio.c  |1 +
 hw/virtio-balloon.c |   53 +-
 hw/virtio-blk.c |  101 +++--
 hw/virtio-console.c |   43 ---
 hw/virtio-net.c |  207 +--
 hw/virtio-pci.c |   80 ++-
 hw/virtio.c |  138 ++
 hw/virtio.h |   24 --
 qemu-queue.h|4 +
 13 files changed, 390 insertions(+), 317 deletions(-)





[Qemu-devel] [PATCH 01/41] virtio: Teach virtio-balloon about DO_UPCAST

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-balloon.c |   11 +++
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index cfd3b41..2310ab0 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -32,11 +32,6 @@ typedef struct VirtIOBalloon
 uint32_t actual;
 } VirtIOBalloon;

-static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev)
-{
-return (VirtIOBalloon *)vdev;
-}
-
 static void balloon_page(void *addr, int deflate)
 {
 #if defined(__linux__)
@@ -75,7 +70,7 @@ static size_t memcpy_from_iovector(void *data, size_t offset, 
size_t size,

 static void virtio_balloon_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIOBalloon *s = to_virtio_balloon(vdev);
+VirtIOBalloon *s = DO_UPCAST(VirtIOBalloon, vdev, vdev);
 VirtQueueElement elem;

 while (virtqueue_pop(vq, elem)) {
@@ -106,7 +101,7 @@ static void virtio_balloon_handle_output(VirtIODevice 
*vdev, VirtQueue *vq)

 static void virtio_balloon_get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
-VirtIOBalloon *dev = to_virtio_balloon(vdev);
+VirtIOBalloon *dev = DO_UPCAST(VirtIOBalloon, vdev, vdev);
 struct virtio_balloon_config config;

 config.num_pages = cpu_to_le32(dev-num_pages);
@@ -118,7 +113,7 @@ static void virtio_balloon_get_config(VirtIODevice *vdev, 
uint8_t *config_data)
 static void virtio_balloon_set_config(VirtIODevice *vdev,
   const uint8_t *config_data)
 {
-VirtIOBalloon *dev = to_virtio_balloon(vdev);
+VirtIOBalloon *dev = DO_UPCAST(VirtIOBalloon, vdev, vdev);
 struct virtio_balloon_config config;
 memcpy(config, config_data, 8);
 dev-actual = config.actual;
-- 
1.6.5.2





[Qemu-devel] [PATCH 02/41] virtio: Teach virtio-blk about DO_UPCAST

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-blk.c |   11 +++
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 42b766f..39ebc37 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -30,11 +30,6 @@ typedef struct VirtIOBlock
 size_t config_size;
 } VirtIOBlock;

-static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
-{
-return (VirtIOBlock *)vdev;
-}
-
 /* store identify data in little endian format
  */
 static inline void put_le16(uint16_t *p, unsigned int v)
@@ -319,7 +314,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)

 static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = DO_UPCAST(VirtIOBlock, vdev, vdev);
 VirtIOBlockReq *req;
 BlockRequest blkreq[32];
 int num_writes = 0;
@@ -409,7 +404,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
  */
 static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = DO_UPCAST(VirtIOBlock, vdev, vdev);
 struct virtio_blk_config blkcfg;
 uint64_t capacity;
 int cylinders, heads, secs;
@@ -431,7 +426,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, 
uint8_t *config)

 static uint32_t virtio_blk_get_features(VirtIODevice *vdev)
 {
-VirtIOBlock *s = to_virtio_blk(vdev);
+VirtIOBlock *s = DO_UPCAST(VirtIOBlock, vdev, vdev);
 uint32_t features = 0;

 features |= (1  VIRTIO_BLK_F_SEG_MAX);
-- 
1.6.5.2





[Qemu-devel] [PATCH 03/41] virtio: Teach virtio-console about DO_UPCAST

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-console.c |7 +--
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 57f8f89..e0afe61 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -24,14 +24,9 @@ typedef struct VirtIOConsole
 CharDriverState *chr;
 } VirtIOConsole;

-static VirtIOConsole *to_virtio_console(VirtIODevice *vdev)
-{
-return (VirtIOConsole *)vdev;
-}
-
 static void virtio_console_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIOConsole *s = to_virtio_console(vdev);
+VirtIOConsole *s = DO_UPCAST(VirtIOConsole, vdev, vdev);
 VirtQueueElement elem;

 while (virtqueue_pop(vq, elem)) {
-- 
1.6.5.2





[Qemu-devel] [PATCH 04/41] virtio: Teach virtio-net about DO_UPCAST

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |   21 -
 1 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 2f147e5..f518d78 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -61,14 +61,9 @@ typedef struct VirtIONet
  * - we could suppress RX interrupt if we were so inclined.
  */

-static VirtIONet *to_virtio_net(VirtIODevice *vdev)
-{
-return (VirtIONet *)vdev;
-}
-
 static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
 struct virtio_net_config netcfg;

 netcfg.status = n-status;
@@ -78,7 +73,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t 
*config)

 static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
 struct virtio_net_config netcfg;

 memcpy(netcfg, config, sizeof(netcfg));
@@ -105,7 +100,7 @@ static void virtio_net_set_link_status(VLANClientState *vc)

 static void virtio_net_reset(VirtIODevice *vdev)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);

 /* Reset back to compatibility mode */
 n-promisc = 1;
@@ -149,7 +144,7 @@ static int peer_has_ufo(VirtIONet *n)

 static uint32_t virtio_net_get_features(VirtIODevice *vdev)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
 uint32_t features = (1  VIRTIO_NET_F_MAC) |
 (1  VIRTIO_NET_F_MRG_RXBUF) |
 (1  VIRTIO_NET_F_STATUS) |
@@ -197,7 +192,7 @@ static uint32_t virtio_net_bad_features(VirtIODevice *vdev)

 static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);

 n-mergeable_rx_bufs = !!(features  (1  VIRTIO_NET_F_MRG_RXBUF));

@@ -320,7 +315,7 @@ static int virtio_net_handle_vlan_table(VirtIONet *n, 
uint8_t cmd,

 static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
 struct virtio_net_ctrl_hdr ctrl;
 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
 VirtQueueElement elem;
@@ -358,7 +353,7 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, 
VirtQueue *vq)

 static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);

 qemu_flush_queued_packets(n-vc);

@@ -662,7 +657,7 @@ static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)

 static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq)
 {
-VirtIONet *n = to_virtio_net(vdev);
+VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);

 if (n-tx_timer_active) {
 virtio_queue_set_notification(vq, 1);
-- 
1.6.5.2





[Qemu-devel] [PATCH 05/41] virtio-console: Remove useless casts

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-console.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index e0afe61..9f1a602 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -53,7 +53,7 @@ static uint32_t virtio_console_get_features(VirtIODevice 
*vdev)

 static int vcon_can_read(void *opaque)
 {
-VirtIOConsole *s = (VirtIOConsole *) opaque;
+VirtIOConsole *s = opaque;

 if (!virtio_queue_ready(s-ivq) ||
 !(s-vdev.status  VIRTIO_CONFIG_S_DRIVER_OK) ||
@@ -73,7 +73,7 @@ static int vcon_can_read(void *opaque)

 static void vcon_read(void *opaque, const uint8_t *buf, int size)
 {
-VirtIOConsole *s = (VirtIOConsole *) opaque;
+VirtIOConsole *s = opaque;
 VirtQueueElement elem;
 int offset = 0;

-- 
1.6.5.2





[Qemu-devel] [PATCH 07/41] virtio-pci: Remove duplicate test

2009-12-02 Thread Juan Quintela
We already do the test for msix on the caller, just use that test

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/msix.c   |8 
 hw/virtio-pci.c |7 ---
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/hw/msix.c b/hw/msix.c
index 4bc6147..8dca9fd 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -295,10 +295,6 @@ void msix_save(PCIDevice *dev, QEMUFile *f)
 {
 unsigned n = dev-msix_entries_nr;

-if (!(dev-cap_present  QEMU_PCI_CAP_MSIX)) {
-return;
-}
-
 qemu_put_buffer(f, dev-msix_table_page, n * MSIX_ENTRY_SIZE);
 qemu_put_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8);
 }
@@ -308,10 +304,6 @@ void msix_load(PCIDevice *dev, QEMUFile *f)
 {
 unsigned n = dev-msix_entries_nr;

-if (!(dev-cap_present  QEMU_PCI_CAP_MSIX)) {
-return;
-}
-
 msix_free_irq_entries(dev);
 qemu_get_buffer(f, dev-msix_table_page, n * MSIX_ENTRY_SIZE);
 qemu_get_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index d222ce0..25b6380 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -109,9 +109,10 @@ static void virtio_pci_save_config(void * opaque, QEMUFile 
*f)
 {
 VirtIOPCIProxy *proxy = opaque;
 pci_device_save(proxy-pci_dev, f);
-msix_save(proxy-pci_dev, f);
-if (msix_present(proxy-pci_dev))
+if (msix_present(proxy-pci_dev)) {
+msix_save(proxy-pci_dev, f);
 qemu_put_be16(f, proxy-vdev-config_vector);
+}
 }

 static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
@@ -129,8 +130,8 @@ static int virtio_pci_load_config(void * opaque, QEMUFile 
*f)
 if (ret) {
 return ret;
 }
-msix_load(proxy-pci_dev, f);
 if (msix_present(proxy-pci_dev)) {
+msix_load(proxy-pci_dev, f);
 qemu_get_be16s(f, proxy-vdev-config_vector);
 } else {
 proxy-vdev-config_vector = VIRTIO_NO_VECTOR;
-- 
1.6.5.2





[Qemu-devel] [PATCH 06/41] virtio: Use DO_UPCAST instead of a cast

2009-12-02 Thread Juan Quintela
virtio_common_init() creates a struct with the right size, DO_UPCAST
is the appropiate thing here

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-balloon.c |4 ++--
 hw/virtio-blk.c |8 
 hw/virtio-console.c |3 ++-
 hw/virtio-net.c |8 
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 2310ab0..6f60fb1 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -167,11 +167,11 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, 
int version_id)
 VirtIODevice *virtio_balloon_init(DeviceState *dev)
 {
 VirtIOBalloon *s;
-
-s = (VirtIOBalloon *)virtio_common_init(virtio-balloon,
+VirtIODevice *vdev = virtio_common_init(virtio-balloon,
 VIRTIO_ID_BALLOON,
 8, sizeof(VirtIOBalloon));

+s = DO_UPCAST(VirtIOBalloon, vdev, vdev);
 s-vdev.get_config = virtio_balloon_get_config;
 s-vdev.set_config = virtio_balloon_set_config;
 s-vdev.get_features = virtio_balloon_get_features;
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 39ebc37..918be74 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -487,11 +487,11 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo 
*dinfo)
 char *ps = (char *)drive_get_serial(dinfo-bdrv);
 size_t size = strlen(ps) ? sizeof(struct virtio_blk_config) :
offsetof(struct virtio_blk_config, _blk_size);
+VirtIODevice *vdev = virtio_common_init(virtio-blk, VIRTIO_ID_BLOCK,
+size,
+sizeof(VirtIOBlock));

-s = (VirtIOBlock *)virtio_common_init(virtio-blk, VIRTIO_ID_BLOCK,
-  size,
-  sizeof(VirtIOBlock));
-
+s = DO_UPCAST(VirtIOBlock, vdev, vdev);
 s-config_size = size;
 s-vdev.get_config = virtio_blk_update_config;
 s-vdev.get_features = virtio_blk_get_features;
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 9f1a602..57f5e9d 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -121,9 +121,10 @@ static int virtio_console_load(QEMUFile *f, void *opaque, 
int version_id)
 VirtIODevice *virtio_console_init(DeviceState *dev)
 {
 VirtIOConsole *s;
-s = (VirtIOConsole *)virtio_common_init(virtio-console,
+VirtIODevice *vdev = virtio_common_init(virtio-console,
 VIRTIO_ID_CONSOLE,
 0, sizeof(VirtIOConsole));
+s = DO_UPCAST(VirtIOConsole, vdev, vdev);
 s-vdev.get_features = virtio_console_get_features;

 s-ivq = virtio_add_queue(s-vdev, 128, virtio_console_handle_input);
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index f518d78..1b8ce14 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -817,11 +817,11 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf 
*conf)
 {
 VirtIONet *n;
 static int virtio_net_id;
+VirtIODevice *vdev = virtio_common_init(virtio-net, VIRTIO_ID_NET,
+sizeof(struct virtio_net_config),
+sizeof(VirtIONet));

-n = (VirtIONet *)virtio_common_init(virtio-net, VIRTIO_ID_NET,
-sizeof(struct virtio_net_config),
-sizeof(VirtIONet));
-
+n = DO_UPCAST(VirtIONet, vdev, vdev);
 n-vdev.get_config = virtio_net_get_config;
 n-vdev.set_config = virtio_net_set_config;
 n-vdev.get_features = virtio_net_get_features;
-- 
1.6.5.2





[Qemu-devel] [PATCH 08/41] msix: Store sizes that we send/receive

2009-12-02 Thread Juan Quintela
VMstate send buffers in bytes ammonts, not bits or MSIX_ENTRY_SIZE
multiples

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/msix.c |   13 +
 hw/pci.h  |2 ++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/hw/msix.c b/hw/msix.c
index 8dca9fd..62865d0 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -294,9 +294,11 @@ int msix_uninit(PCIDevice *dev)
 void msix_save(PCIDevice *dev, QEMUFile *f)
 {
 unsigned n = dev-msix_entries_nr;
+dev-msix_entries_size = n * MSIX_ENTRY_SIZE;
+dev-msix_pending_size = (n + 7) / 8;

-qemu_put_buffer(f, dev-msix_table_page, n * MSIX_ENTRY_SIZE);
-qemu_put_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8);
+qemu_put_buffer(f, dev-msix_table_page, dev-msix_entries_size);
+qemu_put_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, 
dev-msix_pending_size);
 }

 /* Should be called after restoring the config space. */
@@ -304,9 +306,12 @@ void msix_load(PCIDevice *dev, QEMUFile *f)
 {
 unsigned n = dev-msix_entries_nr;

+dev-msix_entries_size = n * MSIX_ENTRY_SIZE;
+dev-msix_pending_size = (n + 7) / 8;
+
 msix_free_irq_entries(dev);
-qemu_get_buffer(f, dev-msix_table_page, n * MSIX_ENTRY_SIZE);
-qemu_get_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8);
+qemu_get_buffer(f, dev-msix_table_page, dev-msix_entries_size);
+qemu_get_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, 
dev-msix_pending_size);
 }

 /* Does device support MSI-X? */
diff --git a/hw/pci.h b/hw/pci.h
index 0baf69b..c67cc70 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -241,6 +241,8 @@ struct PCIDevice {
 uint32_t msix_bar_size;
 /* Version id needed for VMState */
 int32_t version_id;
+int32_t msix_entries_size;
+int32_t msix_pending_size;
 };

 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
-- 
1.6.5.2





[Qemu-devel] [PATCH 09/41] msix: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/msix.c |   39 ---
 hw/msix.h |1 +
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/hw/msix.c b/hw/msix.c
index 62865d0..f00256a 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -291,29 +291,54 @@ int msix_uninit(PCIDevice *dev)
 return 0;
 }

-void msix_save(PCIDevice *dev, QEMUFile *f)
+static void msix_pre_save(void *opaque)
 {
+PCIDevice *dev = opaque;
 unsigned n = dev-msix_entries_nr;
+
 dev-msix_entries_size = n * MSIX_ENTRY_SIZE;
 dev-msix_pending_size = (n + 7) / 8;
-
-qemu_put_buffer(f, dev-msix_table_page, dev-msix_entries_size);
-qemu_put_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, 
dev-msix_pending_size);
 }

 /* Should be called after restoring the config space. */
-void msix_load(PCIDevice *dev, QEMUFile *f)
+static int msix_pre_load(void *opaque)
 {
+PCIDevice *dev = opaque;
 unsigned n = dev-msix_entries_nr;

 dev-msix_entries_size = n * MSIX_ENTRY_SIZE;
 dev-msix_pending_size = (n + 7) / 8;

 msix_free_irq_entries(dev);
-qemu_get_buffer(f, dev-msix_table_page, dev-msix_entries_size);
-qemu_get_buffer(f, dev-msix_table_page + MSIX_PAGE_PENDING, 
dev-msix_pending_size);
+return 0;
 }

+const VMStateDescription vmstate_msix = {
+.name = msix,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.pre_load = msix_pre_load,
+.pre_save = msix_pre_save,
+.fields  = (VMStateField []) {
+VMSTATE_PARTIAL_VBUFFER(msix_table_page, PCIDevice, msix_entries_size),
+VMSTATE_SUB_VBUFFER(msix_table_page, PCIDevice, MSIX_PAGE_PENDING,
+msix_pending_size),
+VMSTATE_END_OF_LIST()
+}
+};
+
+void msix_save(PCIDevice *dev, QEMUFile *f)
+{
+vmstate_save_state(f, vmstate_msix, dev);
+}
+
+void msix_load(PCIDevice *dev, QEMUFile *f)
+{
+vmstate_load_state(f, vmstate_msix, dev, vmstate_msix.version_id);
+}
+
+
 /* Does device support MSI-X? */
 int msix_present(PCIDevice *dev)
 {
diff --git a/hw/msix.h b/hw/msix.h
index a9f7993..a921a98 100644
--- a/hw/msix.h
+++ b/hw/msix.h
@@ -15,6 +15,7 @@ void msix_mmio_map(PCIDevice *pci_dev, int region_num,

 int msix_uninit(PCIDevice *d);

+extern const VMStateDescription vmstate_msix;
 void msix_save(PCIDevice *dev, QEMUFile *f);
 void msix_load(PCIDevice *dev, QEMUFile *f);

-- 
1.6.5.2





[Qemu-devel] [PATCH 10/41] qemu/pci: document msix_entries_nr field

2009-12-02 Thread Juan Quintela
From: Michael S. Tsirkin m...@redhat.com

Document the fact that msix_entries_nr field caches
a value from config space.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/pci.h |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/pci.h b/hw/pci.h
index c67cc70..20b1b28 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -228,7 +228,9 @@ struct PCIDevice {
 /* Offset of MSI-X capability in config space */
 uint8_t msix_cap;

-/* MSI-X entries */
+/* MSI-X entries.
+ * This value is also encoded in the read-only MSI-X Table Size register
+ * in config space. */
 int msix_entries_nr;

 /* Space to store MSIX table */
-- 
1.6.5.2





[Qemu-devel] [PATCH 11/41] virtio: Introduce type field to distingish between PCI and Syborg

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/syborg_virtio.c |1 +
 hw/virtio-pci.c|2 +-
 hw/virtio.h|6 ++
 3 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/hw/syborg_virtio.c b/hw/syborg_virtio.c
index 6cf5a15..46ac192 100644
--- a/hw/syborg_virtio.c
+++ b/hw/syborg_virtio.c
@@ -275,6 +275,7 @@ static int syborg_virtio_net_init(SysBusDevice *dev)
 SyborgVirtIOProxy *proxy = FROM_SYSBUS(SyborgVirtIOProxy, dev);

 vdev = virtio_net_init(dev-qdev, proxy-nic);
+vdev-type = VIRTIO_SYBORG;
 return syborg_virtio_init(proxy, vdev);
 }

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 25b6380..a2179de 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -433,7 +433,7 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, 
VirtIODevice *vdev,

 pci_register_bar(proxy-pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO,
virtio_map);
-
+vdev-type = VIRTIO_PCI;
 virtio_bind_device(vdev, virtio_pci_bindings, proxy);
 }

diff --git a/hw/virtio.h b/hw/virtio.h
index 15ad910..ec1ff4d 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -88,6 +88,11 @@ typedef struct {

 #define VIRTIO_NO_VECTOR 0x

+typedef enum VirtIOType {
+VIRTIO_PCI,
+VIRTIO_SYBORG,
+} VirtIOType;
+
 struct VirtIODevice
 {
 const char *name;
@@ -106,6 +111,7 @@ struct VirtIODevice
 void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
 void (*reset)(VirtIODevice *vdev);
 VirtQueue *vq;
+VirtIOType type;
 const VirtIOBindings *binding;
 void *binding_opaque;
 uint16_t device_id;
-- 
1.6.5.2





[Qemu-devel] [PATCH 13/41] msix: msix_load/save are not needed anymore

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/msix.c |   11 ---
 hw/msix.h |2 --
 2 files changed, 0 insertions(+), 13 deletions(-)

diff --git a/hw/msix.c b/hw/msix.c
index f00256a..8bbae99 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -328,17 +328,6 @@ const VMStateDescription vmstate_msix = {
 }
 };

-void msix_save(PCIDevice *dev, QEMUFile *f)
-{
-vmstate_save_state(f, vmstate_msix, dev);
-}
-
-void msix_load(PCIDevice *dev, QEMUFile *f)
-{
-vmstate_load_state(f, vmstate_msix, dev, vmstate_msix.version_id);
-}
-
-
 /* Does device support MSI-X? */
 int msix_present(PCIDevice *dev)
 {
diff --git a/hw/msix.h b/hw/msix.h
index a921a98..ead6ce1 100644
--- a/hw/msix.h
+++ b/hw/msix.h
@@ -16,8 +16,6 @@ void msix_mmio_map(PCIDevice *pci_dev, int region_num,
 int msix_uninit(PCIDevice *d);

 extern const VMStateDescription vmstate_msix;
-void msix_save(PCIDevice *dev, QEMUFile *f);
-void msix_load(PCIDevice *dev, QEMUFile *f);

 int msix_enabled(PCIDevice *dev);
 int msix_present(PCIDevice *dev);
-- 
1.6.5.2





[Qemu-devel] [PATCH 12/41] virtio-pci: port pci config to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-pci.c |   72 ++
 1 files changed, 50 insertions(+), 22 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index a2179de..4fe55aa 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -105,35 +105,28 @@ static void virtio_pci_notify(void *opaque, uint16_t 
vector)
 qemu_set_irq(proxy-pci_dev.irq[0], proxy-vdev-isr  1);
 }

-static void virtio_pci_save_config(void * opaque, QEMUFile *f)
+static bool is_msix(void *opaque, int version_id)
 {
 VirtIOPCIProxy *proxy = opaque;
-pci_device_save(proxy-pci_dev, f);
-if (msix_present(proxy-pci_dev)) {
-msix_save(proxy-pci_dev, f);
-qemu_put_be16(f, proxy-vdev-config_vector);
-}
+return msix_present(proxy-pci_dev);
 }

-static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
-{
-VirtIOPCIProxy *proxy = opaque;
-if (msix_present(proxy-pci_dev))
-qemu_put_be16(f, virtio_queue_vector(proxy-vdev, n));
-}
+static const VMStateDescription vmstate_msix_vector = {
+.name = msix_vector,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_UINT16(config_vector, VirtIODevice),
+VMSTATE_END_OF_LIST()
+}
+};

-static int virtio_pci_load_config(void * opaque, QEMUFile *f)
+static int virtio_pci_post_load(void * opaque, int version_id)
 {
 VirtIOPCIProxy *proxy = opaque;
-int ret;
-ret = pci_device_load(proxy-pci_dev, f);
-if (ret) {
-return ret;
-}
-if (msix_present(proxy-pci_dev)) {
-msix_load(proxy-pci_dev, f);
-qemu_get_be16s(f, proxy-vdev-config_vector);
-} else {
+
+if (!msix_present(proxy-pci_dev)) {
 proxy-vdev-config_vector = VIRTIO_NO_VECTOR;
 }
 if (proxy-vdev-config_vector != VIRTIO_NO_VECTOR) {
@@ -142,6 +135,41 @@ static int virtio_pci_load_config(void * opaque, QEMUFile 
*f)
 return 0;
 }

+const VMStateDescription vmstate_virtio_pci_config = {
+.name = pci_config,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.post_load = virtio_pci_post_load,
+.fields  = (VMStateField []) {
+VMSTATE_PCI_DEVICE(pci_dev, VirtIOPCIProxy),
+VMSTATE_STRUCT_TEST(pci_dev, VirtIOPCIProxy, is_msix, 0,
+vmstate_msix, PCIDevice),
+VMSTATE_STRUCT_POINTER_TEST(vdev, VirtIOPCIProxy, is_msix,
+vmstate_msix_vector, VirtIODevice *),
+VMSTATE_END_OF_LIST()
+}
+};
+
+static void virtio_pci_save_config(void * opaque, QEMUFile *f)
+{
+vmstate_save_state(f, vmstate_virtio_pci_config, opaque);
+}
+
+static int virtio_pci_load_config(void * opaque, QEMUFile *f)
+{
+return vmstate_load_state(f, vmstate_virtio_pci_config, opaque,
+  vmstate_virtio_pci_config.version_id);
+}
+
+static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
+{
+VirtIOPCIProxy *proxy = opaque;
+if (msix_present(proxy-pci_dev))
+qemu_put_be16(f, virtio_queue_vector(proxy-vdev, n));
+}
+
+
 static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
 {
 VirtIOPCIProxy *proxy = opaque;
-- 
1.6.5.2





[Qemu-devel] [PATCH 14/41] virtio: remove save/load_config for virtio

2009-12-02 Thread Juan Quintela
It was used only for PCI virtio devices, state that

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-pci.c |   13 -
 hw/virtio.c |9 +
 hw/virtio.h |5 +++--
 3 files changed, 8 insertions(+), 19 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 4fe55aa..45d0adc 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -151,17 +151,6 @@ const VMStateDescription vmstate_virtio_pci_config = {
 }
 };

-static void virtio_pci_save_config(void * opaque, QEMUFile *f)
-{
-vmstate_save_state(f, vmstate_virtio_pci_config, opaque);
-}
-
-static int virtio_pci_load_config(void * opaque, QEMUFile *f)
-{
-return vmstate_load_state(f, vmstate_virtio_pci_config, opaque,
-  vmstate_virtio_pci_config.version_id);
-}
-
 static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
 {
 VirtIOPCIProxy *proxy = opaque;
@@ -413,8 +402,6 @@ static void virtio_write_config(PCIDevice *pci_dev, 
uint32_t address,

 static const VirtIOBindings virtio_pci_bindings = {
 .notify = virtio_pci_notify,
-.save_config = virtio_pci_save_config,
-.load_config = virtio_pci_load_config,
 .save_queue = virtio_pci_save_queue,
 .load_queue = virtio_pci_load_queue,
 };
diff --git a/hw/virtio.c b/hw/virtio.c
index 1f92171..c136005 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -619,8 +619,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
 int i;

-if (vdev-binding-save_config)
-vdev-binding-save_config(vdev-binding_opaque, f);
+if (vdev-type == VIRTIO_PCI)
+vmstate_save_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque);

 qemu_put_8s(f, vdev-status);
 qemu_put_8s(f, vdev-isr);
@@ -652,8 +652,9 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
 int num, i, ret;

-if (vdev-binding-load_config) {
-ret = vdev-binding-load_config(vdev-binding_opaque, f);
+if (vdev-type == VIRTIO_PCI) {
+ret = vmstate_load_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque,
+ vmstate_virtio_pci_config.version_id);
 if (ret)
 return ret;
 }
diff --git a/hw/virtio.h b/hw/virtio.h
index ec1ff4d..9d2e2cc 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -78,9 +78,7 @@ typedef struct VirtQueueElement

 typedef struct {
 void (*notify)(void * opaque, uint16_t vector);
-void (*save_config)(void * opaque, QEMUFile *f);
 void (*save_queue)(void * opaque, int n, QEMUFile *f);
-int (*load_config)(void * opaque, QEMUFile *f);
 int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;

@@ -176,4 +174,7 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev);

 void virtio_net_exit(VirtIODevice *vdev);

+/* virtio-pci. */
+extern const VMStateDescription vmstate_virtio_pci_config;
+
 #endif
-- 
1.6.5.2





[Qemu-devel] [PATCH 15/41] virtio: remove save/load_queue for virtio

2009-12-02 Thread Juan Quintela
It was used only for PCI virtio devices, state that explicitely

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-pci.c |   24 ++--
 hw/virtio.c |   22 --
 hw/virtio.h |4 ++--
 3 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 45d0adc..12f3961 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -151,28 +151,18 @@ const VMStateDescription vmstate_virtio_pci_config = {
 }
 };

-static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
+bool virtio_pci_msix_present(void *opaque)
 {
 VirtIOPCIProxy *proxy = opaque;
-if (msix_present(proxy-pci_dev))
-qemu_put_be16(f, virtio_queue_vector(proxy-vdev, n));
-}

+return msix_present(proxy-pci_dev);
+}

-static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
+int virtio_pci_msix_vector_use(void *opaque, unsigned vector)
 {
 VirtIOPCIProxy *proxy = opaque;
-uint16_t vector;
-if (msix_present(proxy-pci_dev)) {
-qemu_get_be16s(f, vector);
-} else {
-vector = VIRTIO_NO_VECTOR;
-}
-virtio_queue_set_vector(proxy-vdev, n, vector);
-if (vector != VIRTIO_NO_VECTOR) {
-return msix_vector_use(proxy-pci_dev, vector);
-}
-return 0;
+
+return msix_vector_use(proxy-pci_dev, vector);
 }

 static void virtio_pci_reset(DeviceState *d)
@@ -402,8 +392,6 @@ static void virtio_write_config(PCIDevice *pci_dev, 
uint32_t address,

 static const VirtIOBindings virtio_pci_bindings = {
 .notify = virtio_pci_notify,
-.save_queue = virtio_pci_save_queue,
-.load_queue = virtio_pci_load_queue,
 };

 static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
diff --git a/hw/virtio.c b/hw/virtio.c
index c136005..b565bf9 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -643,8 +643,10 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 qemu_put_be32(f, vdev-vq[i].vring.num);
 qemu_put_be64(f, vdev-vq[i].pa);
 qemu_put_be16s(f, vdev-vq[i].last_avail_idx);
-if (vdev-binding-save_queue)
-vdev-binding-save_queue(vdev-binding_opaque, i, f);
+if (vdev-type == VIRTIO_PCI 
+virtio_pci_msix_present(vdev-binding_opaque)) {
+qemu_put_be16s(f, vdev-vq[i].vector);
+}
 }
 }

@@ -676,10 +678,18 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 if (vdev-vq[i].pa) {
 virtqueue_init(vdev-vq[i]);
 }
-if (vdev-binding-load_queue) {
-ret = vdev-binding-load_queue(vdev-binding_opaque, i, f);
-if (ret)
-return ret;
+if (vdev-type == VIRTIO_PCI) {
+if (virtio_pci_msix_present(vdev-binding_opaque)) {
+qemu_get_be16s(f, vdev-vq[i].vector);
+} else {
+vdev-vq[i].vector = VIRTIO_NO_VECTOR;
+}
+if (vdev-vq[i].vector != VIRTIO_NO_VECTOR) {
+ret = virtio_pci_msix_vector_use(vdev-binding_opaque,
+ vdev-vq[i].vector);
+if (ret)
+return ret;
+}
 }
 }

diff --git a/hw/virtio.h b/hw/virtio.h
index 9d2e2cc..91a6c10 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -78,8 +78,6 @@ typedef struct VirtQueueElement

 typedef struct {
 void (*notify)(void * opaque, uint16_t vector);
-void (*save_queue)(void * opaque, int n, QEMUFile *f);
-int (*load_queue)(void * opaque, int n, QEMUFile *f);
 } VirtIOBindings;

 #define VIRTIO_PCI_QUEUE_MAX 16
@@ -176,5 +174,7 @@ void virtio_net_exit(VirtIODevice *vdev);

 /* virtio-pci. */
 extern const VMStateDescription vmstate_virtio_pci_config;
+bool virtio_pci_msix_present(void *opaque);
+int virtio_pci_msix_vector_use(void *opaque, unsigned vector);

 #endif
-- 
1.6.5.2





[Qemu-devel] [PATCH 16/41] virtio: Add num_pci_queues field

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio.c |   32 +++-
 hw/virtio.h |2 ++
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index b565bf9..f549543 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -615,10 +615,24 @@ void virtio_notify_config(VirtIODevice *vdev)
 virtio_notify_vector(vdev, vdev-config_vector);
 }

+static void virtio_pre_save(void *opaque)
+{
+VirtIODevice *vdev = opaque;
+int i;
+
+for (i = 0; i  VIRTIO_PCI_QUEUE_MAX; i++) {
+if (vdev-vq[i].vring.num == 0)
+break;
+}
+vdev-num_pci_queues = i;
+}
+
 void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
 int i;

+virtio_pre_save(vdev);
+
 if (vdev-type == VIRTIO_PCI)
 vmstate_save_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque);

@@ -629,17 +643,9 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 qemu_put_be32(f, vdev-config_len);
 qemu_put_buffer(f, vdev-config, vdev-config_len);

-for (i = 0; i  VIRTIO_PCI_QUEUE_MAX; i++) {
-if (vdev-vq[i].vring.num == 0)
-break;
-}
-
-qemu_put_be32(f, i);
-
-for (i = 0; i  VIRTIO_PCI_QUEUE_MAX; i++) {
-if (vdev-vq[i].vring.num == 0)
-break;
+qemu_put_sbe32s(f, vdev-num_pci_queues);

+for (i = 0; i  vdev-num_pci_queues; i++) {
 qemu_put_be32(f, vdev-vq[i].vring.num);
 qemu_put_be64(f, vdev-vq[i].pa);
 qemu_put_be16s(f, vdev-vq[i].last_avail_idx);
@@ -652,7 +658,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)

 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
-int num, i, ret;
+int i, ret;

 if (vdev-type == VIRTIO_PCI) {
 ret = vmstate_load_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque,
@@ -668,9 +674,9 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 vdev-config_len = qemu_get_be32(f);
 qemu_get_buffer(f, vdev-config, vdev-config_len);

-num = qemu_get_be32(f);
+qemu_get_sbe32s(f, vdev-num_pci_queues);

-for (i = 0; i  num; i++) {
+for (i = 0; i  vdev-num_pci_queues; i++) {
 vdev-vq[i].vring.num = qemu_get_be32(f);
 vdev-vq[i].pa = qemu_get_be64(f);
 qemu_get_be16s(f, vdev-vq[i].last_avail_idx);
diff --git a/hw/virtio.h b/hw/virtio.h
index 91a6c10..d849f44 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -111,6 +111,8 @@ struct VirtIODevice
 const VirtIOBindings *binding;
 void *binding_opaque;
 uint16_t device_id;
+/* fields used only by vmstate */
+int32_t num_pci_queues;
 };

 VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
-- 
1.6.5.2





[Qemu-devel] [PATCH 17/41] virtio: split virtio_post_load() from virtio_load()

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio.c |   45 +
 1 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index f549543..bb93e8c 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -656,6 +656,32 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 }
 }

+static int virtio_post_load(void *opaque, int version_id)
+{
+VirtIODevice *vdev = opaque;
+int i, ret;
+
+for (i = 0; i  vdev-num_pci_queues; i++) {
+if (vdev-vq[i].pa) {
+virtqueue_init(vdev-vq[i]);
+}
+if (vdev-type == VIRTIO_PCI) {
+if (!virtio_pci_msix_present(vdev-binding_opaque)) {
+vdev-vq[i].vector = VIRTIO_NO_VECTOR;
+}
+if (vdev-vq[i].vector != VIRTIO_NO_VECTOR) {
+ret = virtio_pci_msix_vector_use(vdev-binding_opaque,
+ vdev-vq[i].vector);
+if (ret)
+return ret;
+}
+}
+}
+
+virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);
+return 0;
+}
+
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
 int i, ret;
@@ -681,25 +707,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 vdev-vq[i].pa = qemu_get_be64(f);
 qemu_get_be16s(f, vdev-vq[i].last_avail_idx);

-if (vdev-vq[i].pa) {
-virtqueue_init(vdev-vq[i]);
-}
-if (vdev-type == VIRTIO_PCI) {
-if (virtio_pci_msix_present(vdev-binding_opaque)) {
+if (vdev-type == VIRTIO_PCI 
+virtio_pci_msix_present(vdev-binding_opaque)) {
 qemu_get_be16s(f, vdev-vq[i].vector);
-} else {
-vdev-vq[i].vector = VIRTIO_NO_VECTOR;
-}
-if (vdev-vq[i].vector != VIRTIO_NO_VECTOR) {
-ret = virtio_pci_msix_vector_use(vdev-binding_opaque,
- vdev-vq[i].vector);
-if (ret)
-return ret;
-}
 }
 }
-
-virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);
+virtio_post_load(vdev, 1);
 return 0;
 }

-- 
1.6.5.2





[Qemu-devel] [PATCH 18/41] virtio: change config_len type to int32_t

2009-12-02 Thread Juan Quintela
size_t changes between 32 and 64 bits, making it bad for a field
that needs to be on the 'wire'.  This value will never be near int32_t
limit.

Stored values are very small ints, it is backwards compatible

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio.c |4 ++--
 hw/virtio.h |2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index bb93e8c..fd617ff 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -640,7 +640,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 qemu_put_8s(f, vdev-isr);
 qemu_put_be16s(f, vdev-queue_sel);
 qemu_put_be32s(f, vdev-features);
-qemu_put_be32(f, vdev-config_len);
+qemu_put_sbe32s(f, vdev-config_len);
 qemu_put_buffer(f, vdev-config, vdev-config_len);

 qemu_put_sbe32s(f, vdev-num_pci_queues);
@@ -697,7 +697,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 qemu_get_8s(f, vdev-isr);
 qemu_get_be16s(f, vdev-queue_sel);
 qemu_get_be32s(f, vdev-features);
-vdev-config_len = qemu_get_be32(f);
+qemu_get_sbe32s(f, vdev-config_len);
 qemu_get_buffer(f, vdev-config, vdev-config_len);

 qemu_get_sbe32s(f, vdev-num_pci_queues);
diff --git a/hw/virtio.h b/hw/virtio.h
index d849f44..f56f672 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -96,7 +96,7 @@ struct VirtIODevice
 uint8_t isr;
 uint16_t queue_sel;
 uint32_t features;
-size_t config_len;
+int32_t config_len;
 void *config;
 uint16_t config_vector;
 int nvectors;
-- 
1.6.5.2





[Qemu-devel] [PATCH 21/41] virtio: port to vmstate

2009-12-02 Thread Juan Quintela
We need to do the virt queue msix and not msix version because we know
if there is msix at virtio level, not at queue element level

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/hw.h |   10 +
 hw/virtio.c |  121 ---
 hw/virtio.h |5 ++
 3 files changed, 81 insertions(+), 55 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 5f34991..747a311 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -476,6 +476,16 @@ extern const VMStateInfo vmstate_info_unused_buffer;
 .offset = vmstate_offset_array(_state, _field, _type, _num), \
 }

+#define VMSTATE_VARRAY_STRUCT_INT32(_field, _state, _field_num, _test, _vmsd, 
_type) {\
+.name = (stringify(_field)), \
+.field_exists = (_test), \
+.num_offset   = vmstate_offset_value(_state, _field_num, int32_t), \
+.vmsd = (_vmsd),\
+.size = sizeof(_type),   \
+.flags= VMS_VARRAY_INT32|VMS_POINTER|VMS_STRUCT, \
+.offset   = vmstate_offset_pointer(_state, _field, _type),   \
+}
+
 #define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) 
{ \
 .name = (stringify(_field)), \
 .version_id   = (_version),  \
diff --git a/hw/virtio.c b/hw/virtio.c
index 5497716..73dae7c 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -625,10 +625,19 @@ static bool is_virtio_pci(void *opaque, int version_id)
 static bool is_virtio_msix(void *opaque, int version_id)
 {
 VirtIODevice *vdev = opaque;
+
 return (vdev-type == VIRTIO_PCI) 
 virtio_pci_msix_present(vdev-binding_opaque);
 }

+static bool is_virtio_not_msix(void *opaque, int version_id)
+{
+VirtIODevice *vdev = opaque;
+
+return !((vdev-type == VIRTIO_PCI) 
+ virtio_pci_msix_present(vdev-binding_opaque));
+}
+
 static void virtio_pre_save(void *opaque)
 {
 VirtIODevice *vdev = opaque;
@@ -641,34 +650,6 @@ static void virtio_pre_save(void *opaque)
 vdev-num_pci_queues = i;
 }

-void virtio_save(VirtIODevice *vdev, QEMUFile *f)
-{
-int i;
-
-virtio_pre_save(vdev);
-
-if (is_virtio_pci(vdev, 1))
-vmstate_save_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque);
-
-qemu_put_8s(f, vdev-status);
-qemu_put_8s(f, vdev-isr);
-qemu_put_be16s(f, vdev-queue_sel);
-qemu_put_be32s(f, vdev-features);
-qemu_put_sbe32s(f, vdev-config_len);
-qemu_put_buffer(f, vdev-config, vdev-config_len);
-
-qemu_put_sbe32s(f, vdev-num_pci_queues);
-
-for (i = 0; i  vdev-num_pci_queues; i++) {
-qemu_put_be32s(f, vdev-vq[i].vring.num);
-qemu_put_be64s(f, vdev-vq[i].pa);
-qemu_put_be16s(f, vdev-vq[i].last_avail_idx);
-if (is_virtio_msix(vdev, 1)) {
-qemu_put_be16s(f, vdev-vq[i].vector);
-}
-}
-}
-
 static int virtio_post_load(void *opaque, int version_id)
 {
 VirtIODevice *vdev = opaque;
@@ -695,38 +676,68 @@ static int virtio_post_load(void *opaque, int version_id)
 return 0;
 }

-
-int virtio_load(VirtIODevice *vdev, QEMUFile *f)
-{
-int i, ret;
-
-if (is_virtio_pci(vdev, 1)) {
-ret = vmstate_load_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque,
- vmstate_virtio_pci_config.version_id);
-if (ret)
-return ret;
+static const VMStateDescription vmstate_virtio_pci_queue = {
+.name = virtio_pci_queue,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_UINT32(vring.num, VirtQueue),
+VMSTATE_UINT64(pa, VirtQueue),
+VMSTATE_UINT16(last_avail_idx, VirtQueue),
+VMSTATE_END_OF_LIST()
 }
+};

-qemu_get_8s(f, vdev-status);
-qemu_get_8s(f, vdev-isr);
-qemu_get_be16s(f, vdev-queue_sel);
-qemu_get_be32s(f, vdev-features);
-qemu_get_sbe32s(f, vdev-config_len);
-qemu_get_buffer(f, vdev-config, vdev-config_len);
+static const VMStateDescription vmstate_virtio_pci_queue_msix = {
+.name = virtio_pci_queue_msix,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_UINT32(vring.num, VirtQueue),
+VMSTATE_UINT64(pa, VirtQueue),
+VMSTATE_UINT16(last_avail_idx, VirtQueue),
+VMSTATE_UINT16(vector, VirtQueue),
+VMSTATE_END_OF_LIST()
+}
+};

-qemu_get_sbe32s(f, vdev-num_pci_queues);
+const VMStateDescription vmstate_virtio = {
+ .name = virtio,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.post_load = virtio_post_load,
+.pre_save = virtio_pre_save,
+.fields  = (VMStateField []) {
+VMSTATE_STRUCT_POINTER_TEST(binding_opaque, VirtIODevice, 

[Qemu-devel] [PATCH 19/41] virtio: use the right types for VirtQueue elements

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index fd617ff..2b36cad 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -646,8 +646,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 qemu_put_sbe32s(f, vdev-num_pci_queues);

 for (i = 0; i  vdev-num_pci_queues; i++) {
-qemu_put_be32(f, vdev-vq[i].vring.num);
-qemu_put_be64(f, vdev-vq[i].pa);
+qemu_put_be32s(f, vdev-vq[i].vring.num);
+qemu_put_be64s(f, vdev-vq[i].pa);
 qemu_put_be16s(f, vdev-vq[i].last_avail_idx);
 if (vdev-type == VIRTIO_PCI 
 virtio_pci_msix_present(vdev-binding_opaque)) {
@@ -703,8 +703,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 qemu_get_sbe32s(f, vdev-num_pci_queues);

 for (i = 0; i  vdev-num_pci_queues; i++) {
-vdev-vq[i].vring.num = qemu_get_be32(f);
-vdev-vq[i].pa = qemu_get_be64(f);
+qemu_get_be32s(f, vdev-vq[i].vring.num);
+qemu_get_be64s(f, vdev-vq[i].pa);
 qemu_get_be16s(f, vdev-vq[i].last_avail_idx);

 if (vdev-type == VIRTIO_PCI 
-- 
1.6.5.2





[Qemu-devel] [PATCH 20/41] virtio: abstract test for save/load values

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio.c |   27 ---
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index 2b36cad..5497716 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -615,6 +615,20 @@ void virtio_notify_config(VirtIODevice *vdev)
 virtio_notify_vector(vdev, vdev-config_vector);
 }

+static bool is_virtio_pci(void *opaque, int version_id)
+{
+VirtIODevice *vdev = opaque;
+
+return vdev-type == VIRTIO_PCI;
+}
+
+static bool is_virtio_msix(void *opaque, int version_id)
+{
+VirtIODevice *vdev = opaque;
+return (vdev-type == VIRTIO_PCI) 
+virtio_pci_msix_present(vdev-binding_opaque);
+}
+
 static void virtio_pre_save(void *opaque)
 {
 VirtIODevice *vdev = opaque;
@@ -633,7 +647,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)

 virtio_pre_save(vdev);

-if (vdev-type == VIRTIO_PCI)
+if (is_virtio_pci(vdev, 1))
 vmstate_save_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque);

 qemu_put_8s(f, vdev-status);
@@ -649,8 +663,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 qemu_put_be32s(f, vdev-vq[i].vring.num);
 qemu_put_be64s(f, vdev-vq[i].pa);
 qemu_put_be16s(f, vdev-vq[i].last_avail_idx);
-if (vdev-type == VIRTIO_PCI 
-virtio_pci_msix_present(vdev-binding_opaque)) {
+if (is_virtio_msix(vdev, 1)) {
 qemu_put_be16s(f, vdev-vq[i].vector);
 }
 }
@@ -682,11 +695,12 @@ static int virtio_post_load(void *opaque, int version_id)
 return 0;
 }

+
 int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 {
 int i, ret;

-if (vdev-type == VIRTIO_PCI) {
+if (is_virtio_pci(vdev, 1)) {
 ret = vmstate_load_state(f, vmstate_virtio_pci_config, 
vdev-binding_opaque,
  vmstate_virtio_pci_config.version_id);
 if (ret)
@@ -707,9 +721,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 qemu_get_be64s(f, vdev-vq[i].pa);
 qemu_get_be16s(f, vdev-vq[i].last_avail_idx);

-if (vdev-type == VIRTIO_PCI 
-virtio_pci_msix_present(vdev-binding_opaque)) {
-qemu_get_be16s(f, vdev-vq[i].vector);
+if (is_virtio_msix(vdev, 1)) {
+qemu_get_be16s(f, vdev-vq[i].vector);
 }
 }
 virtio_post_load(vdev, 1);
-- 
1.6.5.2





[Qemu-devel] [PATCH 22/41] virtio-net: change tx_timer_active to uint32_t

2009-12-02 Thread Juan Quintela
It is only used with values 0 and 1

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 1b8ce14..fda6a76 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -33,7 +33,7 @@ typedef struct VirtIONet
 VirtQueue *ctrl_vq;
 VLANClientState *vc;
 QEMUTimer *tx_timer;
-int tx_timer_active;
+uint32_t tx_timer_active;
 uint32_t has_vnet_hdr;
 uint8_t has_ufo;
 struct {
@@ -693,7 +693,7 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
 virtio_save(n-vdev, f);

 qemu_put_buffer(f, n-mac, ETH_ALEN);
-qemu_put_be32(f, n-tx_timer_active);
+qemu_put_be32s(f, n-tx_timer_active);
 qemu_put_be32(f, n-mergeable_rx_bufs);
 qemu_put_be16(f, n-status);
 qemu_put_byte(f, n-promisc);
@@ -722,7 +722,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)
 virtio_load(n-vdev, f);

 qemu_get_buffer(f, n-mac, ETH_ALEN);
-n-tx_timer_active = qemu_get_be32(f);
+qemu_get_be32s(f, n-tx_timer_active);
 n-mergeable_rx_bufs = qemu_get_be32(f);

 if (version_id = 3)
-- 
1.6.5.2





[Qemu-devel] [PATCH 23/41] virtio-net: change mergeable_rx_bufs to uint32_t

2009-12-02 Thread Juan Quintela
It only has values 1 and 0

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index fda6a76..4ad5edd 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -40,7 +40,7 @@ typedef struct VirtIONet
 VirtQueueElement elem;
 ssize_t len;
 } async_tx;
-int mergeable_rx_bufs;
+uint32_t mergeable_rx_bufs;
 uint8_t promisc;
 uint8_t allmulti;
 uint8_t alluni;
@@ -694,7 +694,7 @@ static void virtio_net_save(QEMUFile *f, void *opaque)

 qemu_put_buffer(f, n-mac, ETH_ALEN);
 qemu_put_be32s(f, n-tx_timer_active);
-qemu_put_be32(f, n-mergeable_rx_bufs);
+qemu_put_be32s(f, n-mergeable_rx_bufs);
 qemu_put_be16(f, n-status);
 qemu_put_byte(f, n-promisc);
 qemu_put_byte(f, n-allmulti);
@@ -723,7 +723,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)

 qemu_get_buffer(f, n-mac, ETH_ALEN);
 qemu_get_be32s(f, n-tx_timer_active);
-n-mergeable_rx_bufs = qemu_get_be32(f);
+qemu_get_be32s(f, n-mergeable_rx_bufs);

 if (version_id = 3)
 n-status = qemu_get_be16(f);
-- 
1.6.5.2





[Qemu-devel] [PATCH 24/41] virtio-net: use type checking version of qemu_put/get-*

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |   41 +
 1 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 4ad5edd..57ad20b 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -695,20 +695,20 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
 qemu_put_buffer(f, n-mac, ETH_ALEN);
 qemu_put_be32s(f, n-tx_timer_active);
 qemu_put_be32s(f, n-mergeable_rx_bufs);
-qemu_put_be16(f, n-status);
-qemu_put_byte(f, n-promisc);
-qemu_put_byte(f, n-allmulti);
+qemu_put_be16s(f, n-status);
+qemu_put_8s(f, n-promisc);
+qemu_put_8s(f, n-allmulti);
 qemu_put_be32(f, n-mac_table.in_use);
 qemu_put_buffer(f, n-mac_table.macs, n-mac_table.in_use * ETH_ALEN);
 qemu_put_buffer(f, (uint8_t *)n-vlans, MAX_VLAN  3);
 qemu_put_be32(f, n-has_vnet_hdr);
-qemu_put_byte(f, n-mac_table.multi_overflow);
-qemu_put_byte(f, n-mac_table.uni_overflow);
-qemu_put_byte(f, n-alluni);
-qemu_put_byte(f, n-nomulti);
-qemu_put_byte(f, n-nouni);
-qemu_put_byte(f, n-nobcast);
-qemu_put_byte(f, n-has_ufo);
+qemu_put_8s(f, n-mac_table.multi_overflow);
+qemu_put_8s(f, n-mac_table.uni_overflow);
+qemu_put_8s(f, n-alluni);
+qemu_put_8s(f, n-nomulti);
+qemu_put_8s(f, n-nouni);
+qemu_put_8s(f, n-nobcast);
+qemu_put_8s(f, n-has_ufo);
 }

 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
@@ -726,15 +726,15 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)
 qemu_get_be32s(f, n-mergeable_rx_bufs);

 if (version_id = 3)
-n-status = qemu_get_be16(f);
+qemu_get_be16s(f, n-status);

 if (version_id = 4) {
 if (version_id  8) {
 n-promisc = qemu_get_be32(f);
 n-allmulti = qemu_get_be32(f);
 } else {
-n-promisc = qemu_get_byte(f);
-n-allmulti = qemu_get_byte(f);
+qemu_get_8s(f, n-promisc);
+qemu_get_8s(f, n-allmulti);
 }
 }

@@ -772,19 +772,20 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)
 }

 if (version_id = 9) {
-n-mac_table.multi_overflow = qemu_get_byte(f);
-n-mac_table.uni_overflow = qemu_get_byte(f);
+qemu_get_8s(f, n-mac_table.multi_overflow);
+qemu_get_8s(f, n-mac_table.uni_overflow);
 }

 if (version_id = 10) {
-n-alluni = qemu_get_byte(f);
-n-nomulti = qemu_get_byte(f);
-n-nouni = qemu_get_byte(f);
-n-nobcast = qemu_get_byte(f);
+qemu_get_8s(f, n-alluni);
+qemu_get_8s(f, n-nomulti);
+qemu_get_8s(f, n-nouni);
+qemu_get_8s(f, n-nobcast);
 }

 if (version_id = 11) {
-if (qemu_get_byte(f)  !peer_has_ufo(n)) {
+qemu_get_8s(f, n-has_ufo);
+if (n-has_ufo  !peer_has_ufo(n)) {
 qemu_error(virtio-net: saved image requires TUN_F_UFO support\n);
 return -1;
 }
-- 
1.6.5.2





[Qemu-devel] [PATCH 27/41] virtio-net: abstract vlans operations

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |   21 ++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 97db0d0..cf13e94 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -63,6 +63,21 @@ typedef struct VirtIONet
  * - we could suppress RX interrupt if we were so inclined.
  */

+static void vlan_add(VirtIONet *n, int vid)
+{
+n-vlans[vid  5] |= (1U  (vid  0x1f));
+}
+
+static void vlan_del(VirtIONet *n, int vid)
+{
+n-vlans[vid  5] = ~(1U  (vid  0x1f));
+}
+
+static bool vlan_is_set(VirtIONet *n, int vid)
+{
+return n-vlans[vid  5]  ~(1U  (vid  0x1f));
+}
+
 static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
 {
 VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
@@ -306,9 +321,9 @@ static int virtio_net_handle_vlan_table(VirtIONet *n, 
uint8_t cmd,
 return VIRTIO_NET_ERR;

 if (cmd == VIRTIO_NET_CTRL_VLAN_ADD)
-n-vlans[vid  5] |= (1U  (vid  0x1f));
+vlan_add(n, vid);
 else if (cmd == VIRTIO_NET_CTRL_VLAN_DEL)
-n-vlans[vid  5] = ~(1U  (vid  0x1f));
+vlan_del(n, vid);
 else
 return VIRTIO_NET_ERR;

@@ -471,7 +486,7 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, 
int size)

 if (!memcmp(ptr[12], vlan, sizeof(vlan))) {
 int vid = be16_to_cpup((uint16_t *)(ptr + 14))  0xfff;
-if (!(n-vlans[vid  5]  (1U  (vid  0x1f
+if (!vlan_is_set(n, vid))
 return 0;
 }

-- 
1.6.5.2





[Qemu-devel] [PATCH 28/41] virtio-net: make vlan operations on uint8_t, not uint32_t

2009-12-02 Thread Juan Quintela
This fixes endianess problems.  Using ints and saving the state as bytes
break cross-endian migration.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index cf13e94..05cc67f 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -56,7 +56,7 @@ typedef struct VirtIONet
 uint8_t uni_overflow;
 uint8_t *macs;
 } mac_table;
-uint32_t vlans[MAX_VLAN  5];
+uint8_t vlans[MAX_VLAN  3];
 } VirtIONet;

 /* TODO
@@ -65,17 +65,17 @@ typedef struct VirtIONet

 static void vlan_add(VirtIONet *n, int vid)
 {
-n-vlans[vid  5] |= (1U  (vid  0x1f));
+n-vlans[vid  3] |= (1U  (vid  0x7));
 }

 static void vlan_del(VirtIONet *n, int vid)
 {
-n-vlans[vid  5] = ~(1U  (vid  0x1f));
+n-vlans[vid  3] = ~(1U  (vid  0x7));
 }

 static bool vlan_is_set(VirtIONet *n, int vid)
 {
-return n-vlans[vid  5]  ~(1U  (vid  0x1f));
+return n-vlans[vid  3]  ~(1U  (vid  0x7));
 }

 static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
@@ -717,7 +717,7 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
 qemu_put_8s(f, n-allmulti);
 qemu_put_be32(f, n-mac_table.in_use);
 qemu_put_buffer(f, n-mac_table.macs, n-mac_table.in_use * ETH_ALEN);
-qemu_put_buffer(f, (uint8_t *)n-vlans, MAX_VLAN  3);
+qemu_put_buffer(f, n-vlans, MAX_VLAN  3);
 qemu_put_be32(f, n-has_vnet_hdr);
 qemu_put_8s(f, n-mac_table.multi_overflow);
 qemu_put_8s(f, n-mac_table.uni_overflow);
@@ -762,7 +762,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)
 }
  
 if (version_id = 6)
-qemu_get_buffer(f, (uint8_t *)n-vlans, MAX_VLAN  3);
+qemu_get_buffer(f, n-vlans, MAX_VLAN  3);

 if (version_id = 7) {
 if (qemu_get_be32(f)  !peer_has_vnet_hdr(n)) {
-- 
1.6.5.2





[Qemu-devel] [PATCH 29/41] virtio-net: in_use and first_multi only handle unsigned values

2009-12-02 Thread Juan Quintela
And they were saved/loaded as unsigned already

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 05cc67f..589ea80 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -50,8 +50,8 @@ typedef struct VirtIONet
 uint8_t nouni;
 uint8_t nobcast;
 struct {
-int in_use;
-int first_multi;
+uint32_t in_use;
+uint32_t first_multi;
 uint8_t multi_overflow;
 uint8_t uni_overflow;
 uint8_t *macs;
@@ -715,7 +715,7 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
 qemu_put_be16s(f, n-status);
 qemu_put_8s(f, n-promisc);
 qemu_put_8s(f, n-allmulti);
-qemu_put_be32(f, n-mac_table.in_use);
+qemu_put_be32s(f, n-mac_table.in_use);
 qemu_put_buffer(f, n-mac_table.macs, n-mac_table.in_use * ETH_ALEN);
 qemu_put_buffer(f, n-vlans, MAX_VLAN  3);
 qemu_put_be32(f, n-has_vnet_hdr);
@@ -756,7 +756,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)
 }

 if (version_id = 5) {
-n-mac_table.in_use = qemu_get_be32(f);
+qemu_get_be32s(f, n-mac_table.in_use);
 qemu_get_buffer(f, n-mac_table.macs,
 n-mac_table.in_use * ETH_ALEN);
 }
-- 
1.6.5.2





[Qemu-devel] [PATCH 30/41] virtio-net: use save/load type chek functions for has_vent_hdr

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 589ea80..c515e0e 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -718,7 +718,7 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
 qemu_put_be32s(f, n-mac_table.in_use);
 qemu_put_buffer(f, n-mac_table.macs, n-mac_table.in_use * ETH_ALEN);
 qemu_put_buffer(f, n-vlans, MAX_VLAN  3);
-qemu_put_be32(f, n-has_vnet_hdr);
+qemu_put_be32s(f, n-has_vnet_hdr);
 qemu_put_8s(f, n-mac_table.multi_overflow);
 qemu_put_8s(f, n-mac_table.uni_overflow);
 qemu_put_8s(f, n-alluni);
@@ -765,7 +765,8 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)
 qemu_get_buffer(f, n-vlans, MAX_VLAN  3);

 if (version_id = 7) {
-if (qemu_get_be32(f)  !peer_has_vnet_hdr(n)) {
+qemu_get_be32s(f, n-has_vnet_hdr);
+if (n-has_vnet_hdr  !peer_has_vnet_hdr(n)) {
 qemu_error(virtio-net: saved image requires vnet_hdr=on\n);
 return -1;
 }
-- 
1.6.5.2





[Qemu-devel] [PATCH 31/41] virtio-net: we know macs size at compile time, make it static

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |6 +-
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index c515e0e..550a814 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -54,7 +54,7 @@ typedef struct VirtIONet
 uint32_t first_multi;
 uint8_t multi_overflow;
 uint8_t uni_overflow;
-uint8_t *macs;
+uint8_t macs[MAC_TABLE_ENTRIES * ETH_ALEN];
 } mac_table;
 uint8_t vlans[MAX_VLAN  3];
 } VirtIONet;
@@ -860,8 +860,6 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf 
*conf)
 n-mergeable_rx_bufs = 0;
 n-promisc = 1; /* for compatibility */

-n-mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN);
-
 register_savevm(virtio-net, virtio_net_id++, VIRTIO_NET_VM_VERSION,
 virtio_net_save, virtio_net_load, n);

@@ -876,8 +874,6 @@ void virtio_net_exit(VirtIODevice *vdev)

 unregister_savevm(virtio-net, n);

-qemu_free(n-mac_table.macs);
-
 qemu_del_timer(n-tx_timer);
 qemu_free_timer(n-tx_timer);

-- 
1.6.5.2





[Qemu-devel] [PATCH 32/41] virtio-net: split virtio_net_post_load

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |   79 ---
 1 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 550a814..4434827 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -703,6 +703,51 @@ static void virtio_net_tx_timer(void *opaque)
 virtio_net_flush_tx(n, n-tx_vq);
 }

+static int virtio_net_post_load(void *opaque, int version_id)
+{
+VirtIONet *n = opaque;
+int i;
+
+if (version_id = 7) {
+if (n-has_vnet_hdr  !peer_has_vnet_hdr(n)) {
+qemu_error(virtio-net: saved image requires vnet_hdr=on\n);
+return -1;
+}
+
+if (n-has_vnet_hdr) {
+tap_using_vnet_hdr(n-vc-peer, 1);
+tap_set_offload(n-vc-peer,
+(n-vdev.features  VIRTIO_NET_F_GUEST_CSUM)  1,
+(n-vdev.features  VIRTIO_NET_F_GUEST_TSO4)  1,
+(n-vdev.features  VIRTIO_NET_F_GUEST_TSO6)  1,
+(n-vdev.features  VIRTIO_NET_F_GUEST_ECN)   1,
+(n-vdev.features  VIRTIO_NET_F_GUEST_UFO)   1);
+}
+}
+
+if (version_id = 11) {
+if (n-has_ufo  !peer_has_ufo(n)) {
+qemu_error(virtio-net: saved image requires TUN_F_UFO support\n);
+return -1;
+}
+}
+
+/* Find the first multicast entry in the saved MAC filter */
+for (i = 0; i  n-mac_table.in_use; i++) {
+if (n-mac_table.macs[i * ETH_ALEN]  1) {
+break;
+}
+}
+n-mac_table.first_multi = i;
+
+if (n-tx_timer_active) {
+qemu_mod_timer(n-tx_timer,
+   qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
+}
+
+return 0;
+}
+
 static void virtio_net_save(QEMUFile *f, void *opaque)
 {
 VirtIONet *n = opaque;
@@ -731,7 +776,6 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
 {
 VirtIONet *n = opaque;
-int i;

 if (version_id  2 || version_id  VIRTIO_NET_VM_VERSION)
 return -EINVAL;
@@ -766,20 +810,6 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)

 if (version_id = 7) {
 qemu_get_be32s(f, n-has_vnet_hdr);
-if (n-has_vnet_hdr  !peer_has_vnet_hdr(n)) {
-qemu_error(virtio-net: saved image requires vnet_hdr=on\n);
-return -1;
-}
-
-if (n-has_vnet_hdr) {
-tap_using_vnet_hdr(n-vc-peer, 1);
-tap_set_offload(n-vc-peer,
-(n-vdev.features  VIRTIO_NET_F_GUEST_CSUM)  1,
-(n-vdev.features  VIRTIO_NET_F_GUEST_TSO4)  1,
-(n-vdev.features  VIRTIO_NET_F_GUEST_TSO6)  1,
-(n-vdev.features  VIRTIO_NET_F_GUEST_ECN)   1,
-(n-vdev.features  VIRTIO_NET_F_GUEST_UFO)   1);
-}
 }

 if (version_id = 9) {
@@ -796,26 +826,9 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)

 if (version_id = 11) {
 qemu_get_8s(f, n-has_ufo);
-if (n-has_ufo  !peer_has_ufo(n)) {
-qemu_error(virtio-net: saved image requires TUN_F_UFO support\n);
-return -1;
-}
 }

-/* Find the first multicast entry in the saved MAC filter */
-for (i = 0; i  n-mac_table.in_use; i++) {
-if (n-mac_table.macs[i * ETH_ALEN]  1) {
-break;
-}
-}
-n-mac_table.first_multi = i;
-
-if (n-tx_timer_active) {
-qemu_mod_timer(n-tx_timer,
-   qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
-}
-
-return 0;
+return virtio_net_post_load(n, version_id);
 }

 static void virtio_net_cleanup(VLANClientState *vc)
-- 
1.6.5.2





[Qemu-devel] [PATCH 33/41] virtio-net: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-net.c |  148 ---
 1 files changed, 64 insertions(+), 84 deletions(-)

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 4434827..3a59449 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -703,6 +703,38 @@ static void virtio_net_tx_timer(void *opaque)
 virtio_net_flush_tx(n, n-tx_vq);
 }

+/* Restore an uint8_t from an uint32_t
+   This is a Big hack, but it is how the old state did it.
+ */
+
+static int get_uint8_from_uint32(QEMUFile *f, void *pv, size_t size)
+{
+uint8_t *v = pv;
+*v = qemu_get_be32(f);
+return 0;
+}
+
+static void put_unused(QEMUFile *f, void *pv, size_t size)
+{
+fprintf(stderr, uint8_from_uint32 is used only for backwards 
compatibility.\n);
+fprintf(stderr, Never should be used to write a new state.\n);
+exit(0);
+}
+
+static const VMStateInfo vmstate_hack_uint8_from_uint32 = {
+.name = uint8_from_uint32,
+.get  = get_uint8_from_uint32,
+.put  = put_unused,
+};
+
+#define VMSTATE_UINT8_HACK_TEST(_f, _s, _t)   \
+VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_hack_uint8_from_uint32, uint8_t)
+
+static bool between_4_and_8(void *opaque, int version_id)
+{
+return version_id = 4  version_id  8;
+}
+
 static int virtio_net_post_load(void *opaque, int version_id)
 {
 VirtIONet *n = opaque;
@@ -748,88 +780,37 @@ static int virtio_net_post_load(void *opaque, int 
version_id)
 return 0;
 }

-static void virtio_net_save(QEMUFile *f, void *opaque)
-{
-VirtIONet *n = opaque;
-
-virtio_save(n-vdev, f);
-
-qemu_put_buffer(f, n-mac, ETH_ALEN);
-qemu_put_be32s(f, n-tx_timer_active);
-qemu_put_be32s(f, n-mergeable_rx_bufs);
-qemu_put_be16s(f, n-status);
-qemu_put_8s(f, n-promisc);
-qemu_put_8s(f, n-allmulti);
-qemu_put_be32s(f, n-mac_table.in_use);
-qemu_put_buffer(f, n-mac_table.macs, n-mac_table.in_use * ETH_ALEN);
-qemu_put_buffer(f, n-vlans, MAX_VLAN  3);
-qemu_put_be32s(f, n-has_vnet_hdr);
-qemu_put_8s(f, n-mac_table.multi_overflow);
-qemu_put_8s(f, n-mac_table.uni_overflow);
-qemu_put_8s(f, n-alluni);
-qemu_put_8s(f, n-nomulti);
-qemu_put_8s(f, n-nouni);
-qemu_put_8s(f, n-nobcast);
-qemu_put_8s(f, n-has_ufo);
-}
-
-static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
-{
-VirtIONet *n = opaque;
-
-if (version_id  2 || version_id  VIRTIO_NET_VM_VERSION)
-return -EINVAL;
-
-virtio_load(n-vdev, f);
-
-qemu_get_buffer(f, n-mac, ETH_ALEN);
-qemu_get_be32s(f, n-tx_timer_active);
-qemu_get_be32s(f, n-mergeable_rx_bufs);
-
-if (version_id = 3)
-qemu_get_be16s(f, n-status);
-
-if (version_id = 4) {
-if (version_id  8) {
-n-promisc = qemu_get_be32(f);
-n-allmulti = qemu_get_be32(f);
-} else {
-qemu_get_8s(f, n-promisc);
-qemu_get_8s(f, n-allmulti);
-}
-}
-
-if (version_id = 5) {
-qemu_get_be32s(f, n-mac_table.in_use);
-qemu_get_buffer(f, n-mac_table.macs,
-n-mac_table.in_use * ETH_ALEN);
-}
- 
-if (version_id = 6)
-qemu_get_buffer(f, n-vlans, MAX_VLAN  3);
-
-if (version_id = 7) {
-qemu_get_be32s(f, n-has_vnet_hdr);
-}
-
-if (version_id = 9) {
-qemu_get_8s(f, n-mac_table.multi_overflow);
-qemu_get_8s(f, n-mac_table.uni_overflow);
-}
-
-if (version_id = 10) {
-qemu_get_8s(f, n-alluni);
-qemu_get_8s(f, n-nomulti);
-qemu_get_8s(f, n-nouni);
-qemu_get_8s(f, n-nobcast);
+static const VMStateDescription vmstate_virtio_net = {
+.name = virtio-net,
+.version_id = 11,
+.minimum_version_id = 2,
+.minimum_version_id_old = 2,
+.post_load = virtio_net_post_load,
+.fields  = (VMStateField []) {
+VMSTATE_VIRTIO(vdev, VirtIONet),
+VMSTATE_BUFFER(mac, VirtIONet),
+VMSTATE_UINT32(tx_timer_active, VirtIONet),
+VMSTATE_UINT32(mergeable_rx_bufs, VirtIONet),
+VMSTATE_UINT16_V(status, VirtIONet, 3),
+VMSTATE_UINT8_HACK_TEST(promisc, VirtIONet, between_4_and_8),
+VMSTATE_UINT8_HACK_TEST(allmulti, VirtIONet, between_4_and_8),
+VMSTATE_UINT8_V(promisc, VirtIONet, 8),
+VMSTATE_UINT8_V(allmulti, VirtIONet, 8),
+VMSTATE_UINT32_V(mac_table.in_use, VirtIONet, 5),
+VMSTATE_BUFFER_MULTIPLY(mac_table.macs, VirtIONet, 5, NULL, 0,
+mac_table.in_use, ETH_ALEN),
+VMSTATE_BUFFER_V(vlans, VirtIONet, 6),
+VMSTATE_UINT32_V(has_vnet_hdr, VirtIONet, 7),
+VMSTATE_UINT8_V(mac_table.multi_overflow, VirtIONet, 9),
+VMSTATE_UINT8_V(mac_table.uni_overflow, VirtIONet, 9),
+VMSTATE_UINT8_V(alluni, VirtIONet, 10),
+VMSTATE_UINT8_V(nomulti, VirtIONet, 10),
+VMSTATE_UINT8_V(nouni, VirtIONet, 10),
+

[Qemu-devel] [PATCH 34/41] virtio-console: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-console.c |   29 +++--
 1 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index 57f5e9d..1ebb3dd 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -100,23 +100,16 @@ static void vcon_event(void *opaque, int event)
 /* we will ignore any event for the time being */
 }

-static void virtio_console_save(QEMUFile *f, void *opaque)
-{
-VirtIOConsole *s = opaque;
-
-virtio_save(s-vdev, f);
-}
-
-static int virtio_console_load(QEMUFile *f, void *opaque, int version_id)
-{
-VirtIOConsole *s = opaque;
-
-if (version_id != 1)
-return -EINVAL;
-
-virtio_load(s-vdev, f);
-return 0;
-}
+static const VMStateDescription vmstate_virtio_console = {
+.name = virtio-console,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_VIRTIO(vdev, VirtIOConsole),
+VMSTATE_END_OF_LIST()
+}
+};

 VirtIODevice *virtio_console_init(DeviceState *dev)
 {
@@ -133,7 +126,7 @@ VirtIODevice *virtio_console_init(DeviceState *dev)
 s-chr = qdev_init_chardev(dev);
 qemu_chr_add_handlers(s-chr, vcon_can_read, vcon_read, vcon_event, s);

-register_savevm(virtio-console, -1, 1, virtio_console_save, 
virtio_console_load, s);
+vmstate_register(-1, vmstate_virtio_console, s);

 return s-vdev;
 }
-- 
1.6.5.2





[Qemu-devel] [PATCH 35/41] virtio-balloon: port to vmstate

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-balloon.c |   38 +-
 1 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 6f60fb1..f461c32 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -139,30 +139,18 @@ static ram_addr_t virtio_balloon_to_target(void *opaque, 
ram_addr_t target)
 return ram_size - (dev-actual  VIRTIO_BALLOON_PFN_SHIFT);
 }

-static void virtio_balloon_save(QEMUFile *f, void *opaque)
-{
-VirtIOBalloon *s = opaque;
-
-virtio_save(s-vdev, f);
-
-qemu_put_be32(f, s-num_pages);
-qemu_put_be32(f, s-actual);
-}
-
-static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
-{
-VirtIOBalloon *s = opaque;
-
-if (version_id != 1)
-return -EINVAL;
-
-virtio_load(s-vdev, f);
-
-s-num_pages = qemu_get_be32(f);
-s-actual = qemu_get_be32(f);
-
-return 0;
-}
+static const VMStateDescription vmstate_virtio_balloon = {
+.name = virtio-balloon,
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_VIRTIO(vdev, VirtIOBalloon),
+VMSTATE_UINT32(num_pages, VirtIOBalloon),
+VMSTATE_UINT32(actual, VirtIOBalloon),
+VMSTATE_END_OF_LIST()
+}
+};

 VirtIODevice *virtio_balloon_init(DeviceState *dev)
 {
@@ -181,7 +169,7 @@ VirtIODevice *virtio_balloon_init(DeviceState *dev)

 qemu_add_balloon_handler(virtio_balloon_to_target, s);

-register_savevm(virtio-balloon, -1, 1, virtio_balloon_save, 
virtio_balloon_load, s);
+vmstate_register(-1, vmstate_virtio_balloon, s);

 return s-vdev;
 }
-- 
1.6.5.2





[Qemu-devel] [PATCH 36/41] virtio-blk: change rq type to VirtIOBlockReq

2009-12-02 Thread Juan Quintela

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/virtio-blk.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 918be74..b716a36 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -19,12 +19,14 @@
 # include scsi/sg.h
 #endif

+typedef struct VirtIOBlockReq VirtIOBlockReq;
+
 typedef struct VirtIOBlock
 {
 VirtIODevice vdev;
 BlockDriverState *bs;
 VirtQueue *vq;
-void *rq;
+VirtIOBlockReq *rq;
 char serial_str[BLOCK_SERIAL_STRLEN + 1];
 QEMUBH *bh;
 size_t config_size;
@@ -71,7 +73,7 @@ static inline void virtio_identify_template(struct 
virtio_blk_config *bc)
 put_le16(p + 103, lba_sectors  48);
 }

-typedef struct VirtIOBlockReq
+struct VirtIOBlockReq
 {
 VirtIOBlock *dev;
 VirtQueueElement elem;
@@ -80,7 +82,7 @@ typedef struct VirtIOBlockReq
 struct virtio_scsi_inhdr *scsi;
 QEMUIOVector qiov;
 struct VirtIOBlockReq *next;
-} VirtIOBlockReq;
+};

 static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
 {
-- 
1.6.5.2





[Qemu-devel] [PATCH 37/41] QLIST: Introduce QLIST_COPY_HEAD

2009-12-02 Thread Juan Quintela
This operation copies one head into other.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 qemu-queue.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/qemu-queue.h b/qemu-queue.h
index 8877efd..a59f948 100644
--- a/qemu-queue.h
+++ b/qemu-queue.h
@@ -92,6 +92,10 @@ struct { 
   \
 (head)-lh_first = NULL;\
 } while (/*CONSTCOND*/0)

+#define QLIST_COPY_HEAD(head, origin) do {  \
+(head)-lh_first = (origin)-lh_first;  \
+} while (/*CONSTCOND*/0)
+
 #define QLIST_INSERT_AFTER(listelm, elm, field) do {\
 if (((elm)-field.le_next = (listelm)-field.le_next) != NULL)  \
 (listelm)-field.le_next-field.le_prev =   \
-- 
1.6.5.2





  1   2   3   >