Re: [Qemu-devel] [PATCH] CODING_STYLE: explicitly allow braceless 'else if'

2011-07-26 Thread Stefan Hajnoczi
On Mon, Jul 25, 2011 at 6:00 PM, Blue Swirl blauwir...@gmail.com wrote:
 On Mon, Jul 25, 2011 at 6:55 PM, Avi Kivity a...@redhat.com wrote:
 It's already allowed by the example; there are about 1800 instances in the
 tree; and disallowing it would lead to

    if (a) {
        ...
    } else {
        if (b) {
            ...
        } else {
            if (c) {
                ...
            } else {
                if (d) {
                    ...
                } else {
                    ...
                }
            }
        }
    }

 instead of

    if (a) {
        ...
    } else if (b) {
        ...
    } else if (c) {
        ...
    } else if (d) {
        ...
    } else {
        ...
    }

 which is more readable.

 Signed-off-by: Avi Kivity a...@redhat.com

 Acked-by: Blue Swirl blauwir...@gmail.com

Yes please, I use this too.

Stefan



Re: [Qemu-devel] idea: non-ethernet paravirtual network device

2011-07-26 Thread Stefan Hajnoczi
On Mon, Jul 25, 2011 at 4:53 PM, Sassan Panahinejad sas...@sassan.me.uk wrote:
 Here's a thought, could we improve network performance by creating a
 paravirtual network device which doesn't emulate ethernet? It shouldn't be
 too hard to just whack IP packets pretty much directly over a virtio link.
 This should improve performance when using a user host connection and we
 could introduce a tun host connection instead of tap for this setup.

 Does anyone have any thoughts on how worthwhile this would be? Would the
 performance improvement justify the effort involved?

My guess is no noticable impact (if you ignore ARP requests).

The Ethernet header is only 14 bytes or so.  We don't calculate any
checksums at that level.  There's probably not much of a win.

Stefan



Re: [Qemu-devel] [PATCH 5/6] scsi-disk: Remove 'drive_kind'

2011-07-26 Thread Hannes Reinecke

On 07/25/2011 05:59 PM, Markus Armbruster wrote:

Hannes Reineckeh...@suse.de  writes:


Instead of using its own definitions scsi-disk should
be using the device type of the parent device.

Signed-off-by: Hannes Reineckeh...@suse.de
---
  hw/scsi-defs.h |6 +-
  hw/scsi-disk.c |   48 
  2 files changed, 29 insertions(+), 25 deletions(-)


[ .. ]

@@ -1217,44 +1214,47 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind 
kind)
  return -1;
  }

-if (kind == SCSI_CD) {
+if (scsi_type == TYPE_ROM) {
  s-qdev.blocksize = 2048;
-} else {
+} else if (scsi_type == TYPE_DISK) {
  s-qdev.blocksize = s-qdev.conf.logical_block_size;
+} else {
+error_report(scsi-disk: Unhandled SCSI type %02x, scsi_type);
+return -1;
  }
  s-cluster_size = s-qdev.blocksize / 512;
  s-bs-buffer_alignment = s-qdev.blocksize;

-s-qdev.type = TYPE_DISK;
+s-qdev.type = scsi_type;


Is this a bug fix?


No, proper initialisation.
s-qdev.type is the SCSI type we're told to emulate. So we have to 
set it to the correct value otherwise the emulation will return 
wrong values.



  qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
-bdrv_set_removable(s-bs, kind == SCSI_CD);
+bdrv_set_removable(s-bs, scsi_type == TYPE_ROM);
  add_boot_device_path(s-qdev.conf.bootindex,dev-qdev, ,0);
  return 0;
  }

  static int scsi_hd_initfn(SCSIDevice *dev)
  {
-return scsi_initfn(dev, SCSI_HD);
+return scsi_initfn(dev, TYPE_DISK);
  }

  static int scsi_cd_initfn(SCSIDevice *dev)
  {
-return scsi_initfn(dev, SCSI_CD);
+return scsi_initfn(dev, TYPE_ROM);
  }

  static int scsi_disk_initfn(SCSIDevice *dev)
  {
-SCSIDriveKind kind;
  DriveInfo *dinfo;
+uint8_t scsi_type = TYPE_DISK;

-if (!dev-conf.bs) {
-kind = SCSI_HD; /* will die in scsi_initfn() */


The comment explains why we don't explicitly fail when !dev-conf.bs,
like all the other block device models.  I'd rather keep it.


Ah. The magic of block devices. By all means, keep it.

Cheers,

Hannes
--
Dr. Hannes Reinecke   zSeries  Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)



Re: [Qemu-devel] [PATCH 5/6] scsi-disk: Remove 'drive_kind'

2011-07-26 Thread Markus Armbruster
Hannes Reinecke h...@suse.de writes:

 On 07/25/2011 05:59 PM, Markus Armbruster wrote:
 Hannes Reineckeh...@suse.de  writes:

 Instead of using its own definitions scsi-disk should
 be using the device type of the parent device.

 Signed-off-by: Hannes Reineckeh...@suse.de
 ---
   hw/scsi-defs.h |6 +-
   hw/scsi-disk.c |   48 
   2 files changed, 29 insertions(+), 25 deletions(-)

 [ .. ]
 @@ -1217,44 +1214,47 @@ static int scsi_initfn(SCSIDevice *dev, 
 SCSIDriveKind kind)
   return -1;
   }

 -if (kind == SCSI_CD) {
 +if (scsi_type == TYPE_ROM) {
   s-qdev.blocksize = 2048;
 -} else {
 +} else if (scsi_type == TYPE_DISK) {
   s-qdev.blocksize = s-qdev.conf.logical_block_size;
 +} else {
 +error_report(scsi-disk: Unhandled SCSI type %02x, scsi_type);
 +return -1;
   }
   s-cluster_size = s-qdev.blocksize / 512;
   s-bs-buffer_alignment = s-qdev.blocksize;

 -s-qdev.type = TYPE_DISK;
 +s-qdev.type = scsi_type;

 Is this a bug fix?

 No, proper initialisation.
 s-qdev.type is the SCSI type we're told to emulate. So we have to set
 it to the correct value otherwise the emulation will return wrong
 values.

Well, it changes .type from TYPE_DISK to TYPE_ROM for scsi-cd.  I
understand how that is required for your patch to work.  I wonder
whether it has an impact beyond that, given that the old value is
plainly wrong.

   qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
 -bdrv_set_removable(s-bs, kind == SCSI_CD);
 +bdrv_set_removable(s-bs, scsi_type == TYPE_ROM);
   add_boot_device_path(s-qdev.conf.bootindex,dev-qdev, ,0);
   return 0;
   }

   static int scsi_hd_initfn(SCSIDevice *dev)
   {
 -return scsi_initfn(dev, SCSI_HD);
 +return scsi_initfn(dev, TYPE_DISK);
   }

   static int scsi_cd_initfn(SCSIDevice *dev)
   {
 -return scsi_initfn(dev, SCSI_CD);
 +return scsi_initfn(dev, TYPE_ROM);
   }

   static int scsi_disk_initfn(SCSIDevice *dev)
   {
 -SCSIDriveKind kind;
   DriveInfo *dinfo;
 +uint8_t scsi_type = TYPE_DISK;

 -if (!dev-conf.bs) {
 -kind = SCSI_HD; /* will die in scsi_initfn() */

 The comment explains why we don't explicitly fail when !dev-conf.bs,
 like all the other block device models.  I'd rather keep it.

 Ah. The magic of block devices. By all means, keep it.

Like this?

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index f42a5d1..0925944 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1251,17 +1251,17 @@ static int scsi_cd_initfn(SCSIDevice *dev)
 
 static int scsi_disk_initfn(SCSIDevice *dev)
 {
-SCSIDriveKind kind;
+uint8_t scsi_type;
 DriveInfo *dinfo;
 
 if (!dev-conf.bs) {
-kind = SCSI_HD; /* will die in scsi_initfn() */
+scsi_type = TYPE_DISK;  /* will die in scsi_initfn() */
 } else {
 dinfo = drive_get_by_blockdev(dev-conf.bs);
-kind = dinfo-media_cd ? SCSI_CD : SCSI_HD;
+scsi_type = dinfo-media_cd ? TYPE_ROM : TYPE_DISK;
 }
 
-return scsi_initfn(dev, kind);
+return scsi_initfn(dev, scsi_type);
 }
 
 #define DEFINE_SCSI_DISK_PROPERTIES()   \

By the way, I'm afraid you forgot to remove typedef SCSIDriveKind.  Care
to respin this one?



Re: [Qemu-devel] [PATCH 5/6] scsi-disk: Remove 'drive_kind'

2011-07-26 Thread Hannes Reinecke

On 07/26/2011 08:38 AM, Markus Armbruster wrote:

Hannes Reineckeh...@suse.de  writes:


On 07/25/2011 05:59 PM, Markus Armbruster wrote:

Hannes Reineckeh...@suse.de   writes:


Instead of using its own definitions scsi-disk should
be using the device type of the parent device.

Signed-off-by: Hannes Reineckeh...@suse.de
---
   hw/scsi-defs.h |6 +-
   hw/scsi-disk.c |   48 
   2 files changed, 29 insertions(+), 25 deletions(-)


[ .. ]

@@ -1217,44 +1214,47 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind 
kind)
   return -1;
   }

-if (kind == SCSI_CD) {
+if (scsi_type == TYPE_ROM) {
   s-qdev.blocksize = 2048;
-} else {
+} else if (scsi_type == TYPE_DISK) {
   s-qdev.blocksize = s-qdev.conf.logical_block_size;
+} else {
+error_report(scsi-disk: Unhandled SCSI type %02x, scsi_type);
+return -1;
   }
   s-cluster_size = s-qdev.blocksize / 512;
   s-bs-buffer_alignment = s-qdev.blocksize;

-s-qdev.type = TYPE_DISK;
+s-qdev.type = scsi_type;


Is this a bug fix?


No, proper initialisation.
s-qdev.type is the SCSI type we're told to emulate. So we have to set
it to the correct value otherwise the emulation will return wrong
values.


Well, it changes .type from TYPE_DISK to TYPE_ROM for scsi-cd.  I
understand how that is required for your patch to work.  I wonder
whether it has an impact beyond that, given that the old value is
plainly wrong.


   qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
-bdrv_set_removable(s-bs, kind == SCSI_CD);
+bdrv_set_removable(s-bs, scsi_type == TYPE_ROM);
   add_boot_device_path(s-qdev.conf.bootindex,dev-qdev, ,0);
   return 0;
   }

   static int scsi_hd_initfn(SCSIDevice *dev)
   {
-return scsi_initfn(dev, SCSI_HD);
+return scsi_initfn(dev, TYPE_DISK);
   }

   static int scsi_cd_initfn(SCSIDevice *dev)
   {
-return scsi_initfn(dev, SCSI_CD);
+return scsi_initfn(dev, TYPE_ROM);
   }

   static int scsi_disk_initfn(SCSIDevice *dev)
   {
-SCSIDriveKind kind;
   DriveInfo *dinfo;
+uint8_t scsi_type = TYPE_DISK;

-if (!dev-conf.bs) {
-kind = SCSI_HD; /* will die in scsi_initfn() */


The comment explains why we don't explicitly fail when !dev-conf.bs,
like all the other block device models.  I'd rather keep it.


Ah. The magic of block devices. By all means, keep it.


Like this?

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index f42a5d1..0925944 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1251,17 +1251,17 @@ static int scsi_cd_initfn(SCSIDevice *dev)

  static int scsi_disk_initfn(SCSIDevice *dev)
  {
-SCSIDriveKind kind;
+uint8_t scsi_type;
  DriveInfo *dinfo;

  if (!dev-conf.bs) {
-kind = SCSI_HD; /* will die in scsi_initfn() */
+scsi_type = TYPE_DISK;  /* will die in scsi_initfn() */
  } else {
  dinfo = drive_get_by_blockdev(dev-conf.bs);
-kind = dinfo-media_cd ? SCSI_CD : SCSI_HD;
+scsi_type = dinfo-media_cd ? TYPE_ROM : TYPE_DISK;
  }

-return scsi_initfn(dev, kind);
+return scsi_initfn(dev, scsi_type);
  }

  #define DEFINE_SCSI_DISK_PROPERTIES()   \

By the way, I'm afraid you forgot to remove typedef SCSIDriveKind.  Care
to respin this one?

Here you go.

Cheers,

Hannes

--
Dr. Hannes Reinecke   zSeries  Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
From f6e40a484dbcfdd4f8434ae3427c75a56581d659 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke h...@suse.de
Date: Fri, 22 Jul 2011 16:44:46 +0200
Subject: [PATCH] scsi-disk: Remove 'drive_kind'

Instead of using its own definitions scsi-disk should
be using the device type of the parent device.

Signed-off-by: Hannes Reinecke h...@suse.de

diff --git a/hw/scsi-defs.h b/hw/scsi-defs.h
index f644860..27010b7 100644
--- a/hw/scsi-defs.h
+++ b/hw/scsi-defs.h
@@ -164,6 +164,7 @@
 
 #define TYPE_DISK   0x00
 #define TYPE_TAPE   0x01
+#define TYPE_PRINTER0x02
 #define TYPE_PROCESSOR  0x03/* HP scanners use this */
 #define TYPE_WORM   0x04/* Treated as ROM by our system */
 #define TYPE_ROM0x05
@@ -171,6 +172,9 @@
 #define TYPE_MOD0x07/* Magneto-optical disk -
  * - treated as TYPE_DISK */
 #define TYPE_MEDIUM_CHANGER 0x08
-#define TYPE_ENCLOSURE	0x0d/* Enclosure Services Device */
+#define TYPE_STORAGE_ARRAY  0x0c/* Storage array device */
+#define TYPE_ENCLOSURE  0x0d/* Enclosure Services Device */
+#define TYPE_RBC0x0e/* Simplified Direct-Access Device */
+#define TYPE_OSD0x11/* Object-storage Device */
 #define TYPE_NO_LUN 0x7f
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 535fa11..f2511d0 100644

Re: [Qemu-devel] [PATCH 1/2] Makefile: distclean should clean all possible targets

2011-07-26 Thread Markus Armbruster
Alexandre Raymond cerb...@gmail.com writes:

 At the moment, make distclean relies on the TARGET_DIRS variable, set by
 configure. The problem is that this variable does not always contain all
 possible targets.

 For example, the following will leave build data in the tree:

 ./configure  make  ./configure --target-list=i386-softmmu \
  make distclean

 as it will only remove the i386-softmmu build directory, although the
 first build created additional directories.

Why is that a problem?

 Solution : pass the full list of targets from configure to make via
 the DEFAULT_TARGET_LIST variable.

Well, I'd expect distclean to remove exactly what *this* makefile can
build, and leave everything else alone.

Your patch adds a special case to that simple rule: also remove
not-configured target directories.  Other not-configured stuff is still
left behind.

Special cases need special justification, hence my question above.



Re: [Qemu-devel] [PULL] libcacard AFE support and bug fixes

2011-07-26 Thread Alon Levy
On Fri, Jul 22, 2011 at 06:08:40PM +0300, Alon Levy wrote:
 Hi,
 

Hi Anthony,

 Forgot to mention I would like this to be pulled for 0.15.0.

Alon

  Please pull fixes for AFE smart cards, cleanup and missing frees
  by Robert Relyea and Christophe Fergeau. Thanks.
 
 The following changes since commit d1afc48b7cfdb4490f322d5d82a2aae6d545ec06:
 
   SPARC64: implement addtional MMU faults related to nonfaulting load 
 (2011-07-21 20:02:22 +)
 
 are available in the git repository at:
   git://anongit.freedesktop.org/~alon/qemu pull-libcacard.afe
 
 Christophe Fergeau (5):
   libcacard: don't leak vcard_emul_alloc_arrays mem
   libcacard: s/strip(args++)/strip(args+1)
   libcacard: fix soft=... parsing in vcard_emul_options
   libcacard: introduce NEXT_TOKEN macro
   libcacard: replace copy_string with strndup
 
 Robert Relyea (1):
   libcacard/vcard_emul_nss: support cards lying about CKM_RSA_X_509 
 support
 
  libcacard/vcard_emul_nss.c |  257 
 +++-
  1 files changed, 182 insertions(+), 75 deletions(-)
 
 Alon
 



[Qemu-devel] Professional Web Design and Web Development Agency

2011-07-26 Thread Deepak
 

 

Hi,

 

 

As many as 90% websites do not deliver business to their potential because
they do not appeal to the target audience. And the reason most visitors
leave a website is because of a poor design and navigation.

 

So is your website really customer-ready? Not really, if we go by the
analysis of our experts. We are a New Delhi (India) based Web Designing
Company having more than 500 clients from: UK, USA, Australia, Canada.

 

With an experience of successfully developing more than 2500 websites, we
could help you generate more business from your website, if you are ready to
change the website.  Most of our clients have benefited from our expertise,
and we believe you could too, by getting an attractive website as follows.

 

http://osc4.template-help.com/wt_32369/index.html

http://osc4.template-help.com/wt_32420/index.html 

http://osc4.template-help.com/wt_32127/index.html 

http://osc4.template-help.com/wt_32155/index.html 

http://osc4.template-help.com/wt_31960/index.html

 

You could get a professional looking website as per your expectations

 

Getting started is easy. Just mail us beck and we will help you get started.


 

 

Regards,

 

Name: Deepak Chaudhary

 

 

Disclaimer: The CAN-SPAM Act of 2003 (Controlling the Assault of
Non-Solicited Pornography and Marketing Act) establishes requirements for
those who send commercial email, spells out penalties for spammers and
companies whose products are advertised in spam if they violate the law, and
gives consumers the right to ask e-mailers to stop spamming them. The above
mail  rrwebservi...@gmail.com and we ensure you will not receive any mails
in future

 

 

 

 



Re: [Qemu-devel] [PULL] libcacard AFE support and bug fixes

2011-07-26 Thread Alon Levy
On Tue, Jul 26, 2011 at 10:02:52AM +0300, Alon Levy wrote:
 On Fri, Jul 22, 2011 at 06:08:40PM +0300, Alon Levy wrote:
  Hi,
  
 
 Hi Anthony,
 
  Forgot to mention I would like this to be pulled for 0.15.0.
 
 Alon

Also, I've added a revised patch for libcacard.pc. The original is
 http://lists.gnu.org/archive/html/qemu-devel/2011-06/msg02733.html
The revised patch is:

commit 0f94d6da357954857f95d5be69817d8551a5526f
Author: Alon Levy al...@redhat.com
Date:   Mon Jun 27 11:58:20 2011 +0200

libcacard: add pc file, install it + includes

Additionally:
 + add --includedir configure parameters
 + make install-libcacard install vscclient as well

diff --git a/configure b/configure
index e57efb1..1cc3767 100755
--- a/configure
+++ b/configure
@@ -146,6 +146,7 @@ datadir=\${prefix}/share/qemu
 docdir=\${prefix}/share/doc/qemu
 bindir=\${prefix}/bin
 libdir=\${prefix}/lib
+includedir=\${prefix}/include
 sysconfdir=\${prefix}/etc
 confsuffix=/qemu
 slirp=yes
@@ -539,6 +540,8 @@ for opt do
   ;;
   --libdir=*) libdir=$optarg
   ;;
+  --includedir=*) includedir=$optarg
+  ;;
   --datadir=*) datadir=$optarg
   ;;
   --docdir=*) docdir=$optarg
@@ -2542,6 +2545,7 @@ echo Install prefix$prefix
 echo BIOS directory`eval echo $datadir`
 echo binary directory  `eval echo $bindir`
 echo library directory `eval echo $libdir`
+echo include directory `eval echo $includedir`
 echo config directory  `eval echo $sysconfdir`
 if test $mingw32 = no ; then
 echo Manual directory  `eval echo $mandir`
@@ -2635,6 +2639,7 @@ echo all:  $config_host_mak
 echo prefix=$prefix  $config_host_mak
 echo bindir=$bindir  $config_host_mak
 echo libdir=$libdir  $config_host_mak
+echo includedir=$includedir  $config_host_mak
 echo mandir=$mandir  $config_host_mak
 echo datadir=$datadir  $config_host_mak
 echo sysconfdir=$sysconfdir  $config_host_mak
diff --git a/libcacard/Makefile b/libcacard/Makefile
index 9802c37..bc34bf2 100644
--- a/libcacard/Makefile
+++ b/libcacard/Makefile
@@ -2,7 +2,10 @@
 -include $(SRC_PATH)/Makefile.objs
 -include $(SRC_PATH)/rules.mak
 
-$(call set-vpath, $(SRC_PATH):$(SRC_PATH)/libcacard)
+libcacard_srcpath=$(SRC_PATH)/libcacard
+libcacard_includedir=$(includedir)/cacard
+
+$(call set-vpath, $(SRC_PATH):$(libcacard_srcpath))
 
 # objects linked against normal qemu binaries, not compiled with libtool
 QEMU_OBJS=$(addprefix ../,$(oslib-obj-y) qemu-malloc.o qemu-timer-common.o 
$(trace-obj-y))
@@ -18,7 +21,7 @@ vscclient: $(libcacard-y) $(QEMU_OBJS) vscclient.o
$(call quiet-command,$(CC) $(libcacard_libs) -lrt -o $@ $^,  LINK  $@)
 
 clean:
-   rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ vscclient *.lo .libs/* *.la
+   rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ vscclient *.lo .libs/* *.la 
*.pc
rm -Rf .libs
 
 all: vscclient
@@ -36,7 +39,25 @@ else
 libcacard.la: $(libcacard.lib-y) $(QEMU_OBJS_LIB)
$(call quiet-command,libtool --mode=link --quiet --tag=CC $(CC) 
$(libcacard_libs) -lrt -rpath $(libdir) -o $@ $^,  lt LINK $@)
 
-install-libcacard: libcacard.la
+libcacard.pc: $(libcacard_srcpath)/libcacard.pc.in
+   sed -e 's|@LIBDIR@|$(libdir)|' \
+   -e 's|@INCLUDEDIR@|$(libcacard_includedir)|' \
+   -e 's|@VERSION@|$(shell cat $(SRC_PATH)/VERSION)|' \
+   -e 's|@PREFIX@|$(prefix)|' \
+$(libcacard_srcpath)/libcacard.pc.in  libcacard.pc
+
+.PHONY: install-libcacard
+
+install-libcacard: libcacard.pc libcacard.la vscclient
$(INSTALL_DIR) $(DESTDIR)$(libdir)
+   $(INSTALL_DIR) $(DESTDIR)$(libdir)/pkgconfig
+   $(INSTALL_DIR) $(DESTDIR)$(libcacard_includedir)
+   $(INSTALL_DIR) $(DESTDIR)$(bindir)
+   libtool --mode=install $(INSTALL_PROG) vscclient $(DESTDIR)$(bindir)
libtool --mode=install $(INSTALL_PROG) libcacard.la 
$(DESTDIR)$(libdir)
+   libtool --mode=install $(INSTALL_PROG) libcacard.pc 
$(DESTDIR)$(libdir)/pkgconfig
+   for inc in *.h; do \
+   libtool --mode=install $(INSTALL_PROG) 
$(libcacard_srcpath)/$$inc $(DESTDIR)$(libcacard_includedir); \
+   done
+
 endif
diff --git a/libcacard/libcacard.pc.in b/libcacard/libcacard.pc.in
new file mode 100644
index 000..b6859b0
--- /dev/null
+++ b/libcacard/libcacard.pc.in
@@ -0,0 +1,13 @@
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: cacard
+Description: CA Card library
+Version: @VERSION@
+
+Requires:  nss
+Libs: -L${libdir} -lcacard
+Libs.private:
+Cflags: -I${includedir}



Re: [Qemu-devel] [RFC v5 86/86] 440fx: fix PAM, PCI holes

2011-07-26 Thread Avi Kivity

On 07/26/2011 12:34 AM, Eric Northup wrote:

On Wed, Jul 20, 2011 at 9:50 AM, Avi Kivitya...@redhat.com  wrote:
[...]
  @@ -130,7 +137,13 @@ static void pc_init1(MemoryRegion *system_memory,

   if (pci_enabled) {
   pci_bus = i440fx_init(i440fx_state,piix3_devfn, isa_irq,
  -  system_memory, system_io, ram_size);
  +  system_memory, system_io, ram_size,
  +  0xe000, 0x1fe0,
  +  0x1 + above_4g_mem_size,
  +  (sizeof(target_phys_addr_t) == 32

sizeof(target_phys_addr_t) == 8 ?


Good catch.  Fixed

(== 4).

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




[Qemu-devel] [PATCH v7] showing a splash picture when start

2011-07-26 Thread Wayne Xia
From: wayne xiawenc@Wayne-Libvirt-cim-VM.(none)

Added options to let qemu transfer two configuration files to bios:
bootsplash.bmp and etc/boot-menu-wait, which could be specified by command
-boot splash=P,splash-time=T
P is jpg/bmp file name or an absolute path, T have a max value of 0x, unit
is ms. With these two options, if user invoke qemu with menu=on option, then
a splash picture would be showed in a given time. For example:
qemu -boot menu=on,splash=/root/boot.bmp,splash-time=5000
would make boot.bmp shown as a brand with 5 seconds in the booting up process.
This feature need the new seabios's support, which could be got from git.

Signed-off-by: Wayne Xia xiaw...@linux.vnet.ibm.com
---
 hw/fw_cfg.c |  140 ++-
 qemu-config.c   |   27 +++
 qemu-options.hx |   16 ++-
 sysemu.h|3 +
 vl.c|   17 ++-
 5 files changed, 199 insertions(+), 4 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 34e7526..a29db90 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include isa.h
 #include fw_cfg.h
 #include sysbus.h
+#include qemu-error.h
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,143 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, rb);
+if (fp == NULL) {
+error_report(failed to open file '%s'., filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size  2) {
+error_report(file size is less than 2 bytes '%s'., filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1]  8))  0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type  0) {
+error_report('%s' not jpg/bmp file,head:0x%x.,
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1]  8))  0x;
+if (bmp_bpp != 24) {
+error_report(only 24bpp bmp file is supported.);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = -1;
+const char *boot_splash_filename = NULL;
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+const char *temp;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts(boot-opts);
+QemuOpts *opts = QTAILQ_FIRST(plist-head);
+if (opts != NULL) {
+temp = qemu_opt_get(opts, splash);
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+temp = qemu_opt_get(opts, splash-time);
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)p, 10);
+}
+}
+
+/* insert splash time if user configurated */
+if (boot_splash_time = 0) {
+/* validate the input */
+if (boot_splash_time  0x) {
+error_report(splash time is big than 65535, force it to 65535.);
+boot_splash_time = 0x;
+}
+/* use little endian format */
+qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time  0xff);
+qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time  8)  0xff);
+fw_cfg_add_file(s, etc/boot-menu-wait, qemu_extra_params_fw, 2);
+}
+
+/* insert splash file if user configurated */
+if (boot_splash_filename != NULL) {
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report(failed to find file '%s'., boot_splash_filename);
+return;
+}
+/* probing the file */
+fp = probe_splashfile(filename, file_size, file_type);
+if (fp == NULL) {
+qemu_free(filename);
+return;
+}
+/* loading file data */
+if (boot_splash_filedata != NULL) {
+qemu_free(boot_splash_filedata);
+}
+boot_splash_filedata = qemu_malloc(file_size);
+   

Re: [Qemu-devel] qemu crashes on Mac OS X

2011-07-26 Thread Paolo Bonzini
On 07/26/2011 06:58 AM, Alexandre Raymond wrote:
 +#ifdef __APPLE__
 +if (sig == 0) continue;
 +#endif

From looking at the code this should not happen:

http://fxr.watson.org/fxr/source/bsd/kern/kern_sig.c?v=xnu-792#L986

 1046 sigw = (ut-uu_sigwait  siglist);
...
 1053 signum = ffs((unsigned int)sigw);
 1054 if (!signum)
 1055 panic(sigwait with no signal wakeup);
 1056 ut-uu_siglist = ~(sigmask(signum));
 1057 if (uap-sig != USER_ADDR_NULL)
 1058 error = copyout(signum, uap-sig, 
sizeof(int));

??

Paolo



Re: [Qemu-devel] [PATCH 1/1] block/vpc.c: Detect too-large vpc file

2011-07-26 Thread Kevin Wolf
Am 25.07.2011 20:34, schrieb Serge E. Hallyn:
 VHD files technically can be up to 2Tb, but virtual pc is limited
 to 127G.  Currently qemu-img refused to create vpc files  127G,
 but it is failing to return error when converting from a non-vpc
 VHD file which is 127G.  It returns success, but creates a truncated
 converted image.  Also, qemu-img info claims the vpc file is 127G
 (and clean).
 
 This patch detects a too-large vpc file and returns -EFBIG.  Without
 this patch,
 
 =
 root@ip-10-38-123-242:~/qemu-fixed# qemu-img info /mnt/140g-dynamic.vhd 
 image: /mnt/140g-dynamic.vhd
 file format: vpc
 virtual size: 127G (13683600 bytes)
 disk size: 284K
 root@ip-10-38-123-242:~/qemu-fixed# qemu-img convert -f vpc -O raw 
 /mnt/140g-dynamic.vhd /mnt/y
 root@ip-10-38-123-242:~/qemu-fixed# echo $?
 0
 root@ip-10-38-123-242:~/qemu-fixed# qemu-img info /mnt/y
 image: /mnt/y
 file format: raw
 virtual size: 127G (13683600 bytes)
 disk size: 0
 =
 
 (The 140G image was truncated with no warning or error.)
 
 With the patch, I get:
 
 =
 root@ip-10-38-123-242:~/qemu-fixed# ./qemu-img info /mnt/140g-dynamic.vhd 
 qemu-img: Could not open '/mnt/140g-dynamic.vhd': File too large
 root@ip-10-38-123-242:~/qemu-fixed# ./qemu-img convert -f vpc -O raw 
 /mnt/140g-dynamic.vhd /mnt/y
 qemu-img: Could not open '/mnt/140g-dynamic.vhd': File too large
 qemu-img: Could not open '/mnt/140g-dynamic.vhd'
 =
 
 See https://bugs.launchpad.net/qemu/+bug/814222 for details.
 
 Signed-off-by: Serge Hallyn serge.hal...@canonical.com
 ---
  block/vpc.c |8 +++-
  1 files changed, 7 insertions(+), 1 deletions(-)
 
 diff --git a/block/vpc.c b/block/vpc.c
 index 56865da..fdd5236 100644
 --- a/block/vpc.c
 +++ b/block/vpc.c
 @@ -156,6 +156,7 @@ static int vpc_open(BlockDriverState *bs, int flags)
  struct vhd_dyndisk_header* dyndisk_header;
  uint8_t buf[HEADER_SIZE];
  uint32_t checksum;
 +int err = -1;
  
  if (bdrv_pread(bs-file, 0, s-footer_buf, HEADER_SIZE) != HEADER_SIZE)
  goto fail;
 @@ -176,6 +177,11 @@ static int vpc_open(BlockDriverState *bs, int flags)
  bs-total_sectors = (int64_t)
  be16_to_cpu(footer-cyls) * footer-heads * footer-secs_per_cyl;
  
 +if (bs-total_sectors = 65535 * 16 * 255) {
 +err = -EFBIG;
 +goto fail;
 +}

I wonder why this works. If bs-total_sectors was right, shouldn't it
have converted the full 140 GB? I can't see where else we would limit it
to 127 GB, so what I had expected is that the CHS geometry stored in the
image header is already too small.

What is the CHS geometry of this 140 GB image?

Kevin



[Qemu-devel] [PATCH 0/1] The intro for QEMU disk I/O limits

2011-07-26 Thread Zhi Yong Wu
The main goal of the patch is to effectively cap the disk I/O speed or counts 
of one single VM.It is only one draft, so it unavoidably has some drawbacks, if 
you catch them, please let me know.

The patch will mainly introduce one block I/O throttling algorithm, one global 
timer and one block queue for each I/O limits enabled drive.

When a block request is coming in, the throttling algorithm will check if its 
I/O rate or counts exceed the limits; if yes, then it will enqueue to the block 
queue; The timer will periodically handle the I/O requests in it.

Some available features follow as below:
(1) global bps limit.
-drive bps=xxxin bytes/s
(2) only read bps limit
-drive bps_rd=xxx in bytes/s
(3) only write bps limit
-drive bps_wr=xxx in bytes/s
(4) global iops limit
-drive iops=xxx   in ios/s
(5) only read iops limit
-drive iops_rd=xxxin ios/s
(6) only write iops limit
-drive iops_wr=xxxin ios/s
(7) the combination of some limits.
-drive bps=xxx,iops=xxx

Known Limitations:
(1) #1 can not coexist with #2, #3
(2) #4 can not coexist with #5, #6


Zhi Yong Wu (1):
  v2: The codes V2 for QEMU disk I/O limits.
  Modified the codes mainly based on stefan's comments.

  v1: Submit the codes for QEMU disk I/O limits.
  Only a code draft.

 Makefile.objs |2 +-
 block.c   |  288 +++--
 block.h   |1 -
 block/blk-queue.c |  116 +
 block/blk-queue.h |   70 +
 block_int.h   |   28 +
 blockdev.c|   21 
 qemu-config.c |   24 +
 qemu-option.c |   17 +++
 qemu-option.h |1 +
 qemu-options.hx   |1 +
 11 files changed, 559 insertions(+), 10 deletions(-)
 create mode 100644 block/blk-queue.c
 create mode 100644 block/blk-queue.h

-- 
1.7.2.3




[Qemu-devel] [PATCH 1/1] The codes V2 for QEMU disk I/O limits.

2011-07-26 Thread Zhi Yong Wu
Welcome to give me your comments, thanks.

Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 Makefile.objs |2 +-
 block.c   |  288 +++--
 block.h   |1 -
 block/blk-queue.c |  116 +
 block/blk-queue.h |   70 +
 block_int.h   |   28 +
 blockdev.c|   21 
 qemu-config.c |   24 +
 qemu-option.c |   17 +++
 qemu-option.h |1 +
 qemu-options.hx   |1 +
 11 files changed, 559 insertions(+), 10 deletions(-)
 create mode 100644 block/blk-queue.c
 create mode 100644 block/blk-queue.h

diff --git a/Makefile.objs b/Makefile.objs
index 9f99ed4..06f2033 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -23,7 +23,7 @@ block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o 
dmg.o bochs.o vpc.o vv
 block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-nested-y += qed-check.o
-block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
+block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o 
blk-queue.o
 block-nested-$(CONFIG_WIN32) += raw-win32.o
 block-nested-$(CONFIG_POSIX) += raw-posix.o
 block-nested-$(CONFIG_CURL) += curl.o
diff --git a/block.c b/block.c
index 24a25d5..e54e59c 100644
--- a/block.c
+++ b/block.c
@@ -29,6 +29,9 @@
 #include module.h
 #include qemu-objects.h
 
+#include qemu-timer.h
+#include block/blk-queue.h
+
 #ifdef CONFIG_BSD
 #include sys/types.h
 #include sys/stat.h
@@ -58,6 +61,13 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t 
sector_num,
 static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
  const uint8_t *buf, int nb_sectors);
 
+static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors,
+bool is_write, double elapsed_time, uint64_t *wait);
+static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,
+double elapsed_time, uint64_t *wait);
+static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors,
+bool is_write, uint64_t *wait);
+
 static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
 QTAILQ_HEAD_INITIALIZER(bdrv_states);
 
@@ -90,6 +100,20 @@ int is_windows_drive(const char *filename)
 }
 #endif
 
+static int bdrv_io_limits_enable(BlockIOLimit *io_limits)
+{
+if ((io_limits-bps[0] == 0)
+  (io_limits-bps[1] == 0)
+  (io_limits-bps[2] == 0)
+  (io_limits-iops[0] == 0)
+  (io_limits-iops[1] == 0)
+  (io_limits-iops[2] == 0)) {
+return 0;
+}
+
+return 1;
+}
+
 /* check if the path starts with protocol: */
 static int path_has_protocol(const char *path)
 {
@@ -167,6 +191,28 @@ void path_combine(char *dest, int dest_size,
 }
 }
 
+static void bdrv_block_timer(void *opaque)
+{
+BlockDriverState *bs = opaque;
+BlockQueue *queue = bs-block_queue;
+
+while (!QTAILQ_EMPTY(queue-requests)) {
+BlockIORequest *request;
+int ret;
+
+request = QTAILQ_FIRST(queue-requests);
+QTAILQ_REMOVE(queue-requests, request, entry);
+
+ret = qemu_block_queue_handler(request);
+if (ret == 0) {
+QTAILQ_INSERT_HEAD(queue-requests, request, entry);
+break;
+}
+
+qemu_free(request);
+}
+}
+
 void bdrv_register(BlockDriver *bdrv)
 {
 if (!bdrv-bdrv_aio_readv) {
@@ -642,6 +688,15 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
int flags,
 bs-change_cb(bs-change_opaque, CHANGE_MEDIA);
 }
 
+/* throttling disk I/O limits */
+if (bdrv_io_limits_enable(bs-io_limits)) {
+bs-block_queue = qemu_new_block_queue();
+bs-block_timer = qemu_new_timer_ns(vm_clock, bdrv_block_timer, bs);
+
+bs-slice_start[0] = qemu_get_clock_ns(vm_clock);
+bs-slice_start[1] = qemu_get_clock_ns(vm_clock);
+}
+
 return 0;
 
 unlink_and_fail:
@@ -680,6 +735,16 @@ void bdrv_close(BlockDriverState *bs)
 if (bs-change_cb)
 bs-change_cb(bs-change_opaque, CHANGE_MEDIA);
 }
+
+/* throttling disk I/O limits */
+if (bs-block_queue) {
+qemu_del_block_queue(bs-block_queue);
+}
+
+if (bs-block_timer) {
+qemu_del_timer(bs-block_timer);
+qemu_free_timer(bs-block_timer);
+}
 }
 
 void bdrv_close_all(void)
@@ -1312,6 +1377,14 @@ void bdrv_get_geometry_hint(BlockDriverState *bs,
 *psecs = bs-secs;
 }
 
+/* throttling disk io limits */
+void bdrv_set_io_limits(BlockDriverState *bs,
+   BlockIOLimit *io_limits)
+{
+memset(bs-io_limits, 0, sizeof(BlockIOLimit));
+bs-io_limits = *io_limits;
+}
+
 /* Recognize floppy formats */
 typedef struct FDFormat {
 FDriveType drive;
@@ -2111,6 +2184,155 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, 
QEMUSnapshotInfo *sn)
 return buf;
 }
 
+static bool 

[Qemu-devel] [PATCH v2 1/1] The codes V2 for QEMU disk I/O limits.

2011-07-26 Thread Zhi Yong Wu
Welcome to give me your comments, thanks.

Signed-off-by: Zhi Yong Wu wu...@linux.vnet.ibm.com
---
 Makefile.objs |2 +-
 block.c   |  288 +++--
 block.h   |1 -
 block/blk-queue.c |  116 +
 block/blk-queue.h |   70 +
 block_int.h   |   28 +
 blockdev.c|   21 
 qemu-config.c |   24 +
 qemu-option.c |   17 +++
 qemu-option.h |1 +
 qemu-options.hx   |1 +
 11 files changed, 559 insertions(+), 10 deletions(-)
 create mode 100644 block/blk-queue.c
 create mode 100644 block/blk-queue.h

diff --git a/Makefile.objs b/Makefile.objs
index 9f99ed4..06f2033 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -23,7 +23,7 @@ block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o 
dmg.o bochs.o vpc.o vv
 block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o 
qcow2-cache.o
 block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-nested-y += qed-check.o
-block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
+block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o 
blk-queue.o
 block-nested-$(CONFIG_WIN32) += raw-win32.o
 block-nested-$(CONFIG_POSIX) += raw-posix.o
 block-nested-$(CONFIG_CURL) += curl.o
diff --git a/block.c b/block.c
index 24a25d5..e54e59c 100644
--- a/block.c
+++ b/block.c
@@ -29,6 +29,9 @@
 #include module.h
 #include qemu-objects.h
 
+#include qemu-timer.h
+#include block/blk-queue.h
+
 #ifdef CONFIG_BSD
 #include sys/types.h
 #include sys/stat.h
@@ -58,6 +61,13 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t 
sector_num,
 static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
  const uint8_t *buf, int nb_sectors);
 
+static bool bdrv_exceed_bps_limits(BlockDriverState *bs, int nb_sectors,
+bool is_write, double elapsed_time, uint64_t *wait);
+static bool bdrv_exceed_iops_limits(BlockDriverState *bs, bool is_write,
+double elapsed_time, uint64_t *wait);
+static bool bdrv_exceed_io_limits(BlockDriverState *bs, int nb_sectors,
+bool is_write, uint64_t *wait);
+
 static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
 QTAILQ_HEAD_INITIALIZER(bdrv_states);
 
@@ -90,6 +100,20 @@ int is_windows_drive(const char *filename)
 }
 #endif
 
+static int bdrv_io_limits_enable(BlockIOLimit *io_limits)
+{
+if ((io_limits-bps[0] == 0)
+  (io_limits-bps[1] == 0)
+  (io_limits-bps[2] == 0)
+  (io_limits-iops[0] == 0)
+  (io_limits-iops[1] == 0)
+  (io_limits-iops[2] == 0)) {
+return 0;
+}
+
+return 1;
+}
+
 /* check if the path starts with protocol: */
 static int path_has_protocol(const char *path)
 {
@@ -167,6 +191,28 @@ void path_combine(char *dest, int dest_size,
 }
 }
 
+static void bdrv_block_timer(void *opaque)
+{
+BlockDriverState *bs = opaque;
+BlockQueue *queue = bs-block_queue;
+
+while (!QTAILQ_EMPTY(queue-requests)) {
+BlockIORequest *request;
+int ret;
+
+request = QTAILQ_FIRST(queue-requests);
+QTAILQ_REMOVE(queue-requests, request, entry);
+
+ret = qemu_block_queue_handler(request);
+if (ret == 0) {
+QTAILQ_INSERT_HEAD(queue-requests, request, entry);
+break;
+}
+
+qemu_free(request);
+}
+}
+
 void bdrv_register(BlockDriver *bdrv)
 {
 if (!bdrv-bdrv_aio_readv) {
@@ -642,6 +688,15 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
int flags,
 bs-change_cb(bs-change_opaque, CHANGE_MEDIA);
 }
 
+/* throttling disk I/O limits */
+if (bdrv_io_limits_enable(bs-io_limits)) {
+bs-block_queue = qemu_new_block_queue();
+bs-block_timer = qemu_new_timer_ns(vm_clock, bdrv_block_timer, bs);
+
+bs-slice_start[0] = qemu_get_clock_ns(vm_clock);
+bs-slice_start[1] = qemu_get_clock_ns(vm_clock);
+}
+
 return 0;
 
 unlink_and_fail:
@@ -680,6 +735,16 @@ void bdrv_close(BlockDriverState *bs)
 if (bs-change_cb)
 bs-change_cb(bs-change_opaque, CHANGE_MEDIA);
 }
+
+/* throttling disk I/O limits */
+if (bs-block_queue) {
+qemu_del_block_queue(bs-block_queue);
+}
+
+if (bs-block_timer) {
+qemu_del_timer(bs-block_timer);
+qemu_free_timer(bs-block_timer);
+}
 }
 
 void bdrv_close_all(void)
@@ -1312,6 +1377,14 @@ void bdrv_get_geometry_hint(BlockDriverState *bs,
 *psecs = bs-secs;
 }
 
+/* throttling disk io limits */
+void bdrv_set_io_limits(BlockDriverState *bs,
+   BlockIOLimit *io_limits)
+{
+memset(bs-io_limits, 0, sizeof(BlockIOLimit));
+bs-io_limits = *io_limits;
+}
+
 /* Recognize floppy formats */
 typedef struct FDFormat {
 FDriveType drive;
@@ -2111,6 +2184,155 @@ char *bdrv_snapshot_dump(char *buf, int buf_size, 
QEMUSnapshotInfo *sn)
 return buf;
 }
 
+static bool 

[Qemu-devel] [PATCH v2 0/1] The intro for QEMU disk I/O limits

2011-07-26 Thread Zhi Yong Wu
The main goal of the patch is to effectively cap the disk I/O speed or counts 
of one single VM.It is only one draft, so it unavoidably has some drawbacks, if 
you catch them, please let me know.

The patch will mainly introduce one block I/O throttling algorithm, one global 
timer and one block queue for each I/O limits enabled drive.

When a block request is coming in, the throttling algorithm will check if its 
I/O rate or counts exceed the limits; if yes, then it will enqueue to the block 
queue; The timer will periodically handle the I/O requests in it.

Some available features follow as below:
(1) global bps limit.
-drive bps=xxxin bytes/s
(2) only read bps limit
-drive bps_rd=xxx in bytes/s
(3) only write bps limit
-drive bps_wr=xxx in bytes/s
(4) global iops limit
-drive iops=xxx   in ios/s
(5) only read iops limit
-drive iops_rd=xxxin ios/s
(6) only write iops limit
-drive iops_wr=xxxin ios/s
(7) the combination of some limits.
-drive bps=xxx,iops=xxx

Known Limitations:
(1) #1 can not coexist with #2, #3
(2) #4 can not coexist with #5, #6


Zhi Yong Wu (1):
  v2: The codes V2 for QEMU disk I/O limits.
  Modified the codes mainly based on stefan's comments.

  v1: Submit the codes for QEMU disk I/O limits.
  Only a code draft.

 Makefile.objs |2 +-
 block.c   |  288 +++--
 block.h   |1 -
 block/blk-queue.c |  116 +
 block/blk-queue.h |   70 +
 block_int.h   |   28 +
 blockdev.c|   21 
 qemu-config.c |   24 +
 qemu-option.c |   17 +++
 qemu-option.h |1 +
 qemu-options.hx   |1 +
 11 files changed, 559 insertions(+), 10 deletions(-)
 create mode 100644 block/blk-queue.c
 create mode 100644 block/blk-queue.h

-- 
1.7.2.3




[Qemu-devel] Join my network on LinkedIn

2011-07-26 Thread Gioacchino Mendola via LinkedIn
LinkedIn





Gioacchino Mendola requested to add you as a connection on LinkedIn:
  
--

I'd like to add you to my professional network on LinkedIn.

Accept invitation from Gioacchino Mendola
http://www.linkedin.com/e/-kkb1ec-gqkn51g3-5g/qTMmi8QEI_f3FNXUkL1mvZgy00BGYniwg3/blk/I161618307_11/1BpC5vrmRLoRZcjkkZt5YCpnlOt3RApnhMpmdzgmhxrSNBszYNclYTc3cUcjoNdz59bRtWblxqokhHbP0NdPoQczgRdzcLrCBxbOYWrSlI/EML_comm_afe/

View invitation from Gioacchino Mendola
http://www.linkedin.com/e/-kkb1ec-gqkn51g3-5g/qTMmi8QEI_f3FNXUkL1mvZgy00BGYniwg3/blk/I161618307_11/34NnPsMcPwNdz4SckALqnpPbOYWrSlI/svi/
 
--

DID YOU KNOW that LinkedIn can find the answers to your most difficult 
questions? Post those vexing questions on LinkedIn Answers to tap into the 
knowledge of the world's foremost business experts: 
http://www.linkedin.com/e/-kkb1ec-gqkn51g3-5g/ask/inv-23/
 
-- 
(c) 2011, LinkedIn Corporation

[Qemu-devel] [PULL 0/7] virtio-balloon: cleanups, fix segfault from use-after-free

2011-07-26 Thread Amit Shah
Hello,

This same as the last week's patchset, with Markus's analysis included
in 5/7's commit log.

I think this should go to 0.15 as well.

This series cleans up the virtio-balloon driver and fixes a
use-after-free segfault when 'balloon 0' is issued in the monitor.

The following changes since commit c886edfb851c0c590d4e77f058f2ec8ed95ad1b5:

  Let users select their pythons (2011-07-25 16:50:12 +)

are available in the git repository at:
  git://git.kernel.org/pub/scm/virt/qemu/amit/misc.git for-anthony


Amit Shah (7):
  balloon: Make functions, local vars static
  balloon: Add braces around if statements
  balloon: Simplify code flow
  virtio-balloon: Separate status handling into separate function
  balloon: Separate out stat and balloon handling
  balloon: Fix header comment; add Copyright
  virtio-balloon: Fix header comment; add Copyright

 balloon.c   |   47 +--
 balloon.h   |   12 --
 hw/virtio-balloon.c |   60 +-
 3 files changed, 65 insertions(+), 54 deletions(-)

-- 
1.7.6




[Qemu-devel] [PATCH 1/7] balloon: Make functions, local vars static

2011-07-26 Thread Amit Shah
balloon.h had function declarations for a couple of functions that are
local to balloon.c.  Make them static.

Drop the 'qemu_' prefix for balloon.c-local variables, and make them
static.

Signed-off-by: Amit Shah amit.s...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 balloon.c |   22 +++---
 balloon.h |4 
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/balloon.c b/balloon.c
index 248c1b5..f9bcf07 100644
--- a/balloon.c
+++ b/balloon.c
@@ -31,30 +31,30 @@
 #include trace.h
 
 
-static QEMUBalloonEvent *qemu_balloon_event;
-void *qemu_balloon_event_opaque;
+static QEMUBalloonEvent *balloon_event_fn;
+static void *balloon_opaque;
 
 void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)
 {
-qemu_balloon_event = func;
-qemu_balloon_event_opaque = opaque;
+balloon_event_fn = func;
+balloon_opaque = opaque;
 }
 
-int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
+static int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
 {
-if (qemu_balloon_event) {
-trace_balloon_event(qemu_balloon_event_opaque, target);
-qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque);
+if (balloon_event_fn) {
+trace_balloon_event(balloon_opaque, target);
+balloon_event_fn(balloon_opaque, target, cb, opaque);
 return 1;
 } else {
 return 0;
 }
 }
 
-int qemu_balloon_status(MonitorCompletion cb, void *opaque)
+static int qemu_balloon_status(MonitorCompletion cb, void *opaque)
 {
-if (qemu_balloon_event) {
-qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque);
+if (balloon_event_fn) {
+balloon_event_fn(balloon_opaque, 0, cb, opaque);
 return 1;
 } else {
 return 0;
diff --git a/balloon.h b/balloon.h
index d478e28..06a8a46 100644
--- a/balloon.h
+++ b/balloon.h
@@ -21,10 +21,6 @@ typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t 
target,
 
 void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque);
 
-int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque);
-
-int qemu_balloon_status(MonitorCompletion cb, void *opaque);
-
 void monitor_print_balloon(Monitor *mon, const QObject *data);
 int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque);
 int do_balloon(Monitor *mon, const QDict *params,
-- 
1.7.6




[Qemu-devel] [PATCH 2/7] balloon: Add braces around if statements

2011-07-26 Thread Amit Shah
Signed-off-by: Amit Shah amit.s...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 balloon.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/balloon.c b/balloon.c
index f9bcf07..86f629e 100644
--- a/balloon.c
+++ b/balloon.c
@@ -65,9 +65,10 @@ static void print_balloon_stat(const char *key, QObject 
*obj, void *opaque)
 {
 Monitor *mon = opaque;
 
-if (strcmp(key, actual))
+if (strcmp(key, actual)) {
 monitor_printf(mon, ,%s=% PRId64, key,
qint_get_int(qobject_to_qint(obj)));
+}
 }
 
 void monitor_print_balloon(Monitor *mon, const QObject *data)
@@ -75,9 +76,9 @@ void monitor_print_balloon(Monitor *mon, const QObject *data)
 QDict *qdict;
 
 qdict = qobject_to_qdict(data);
-if (!qdict_haskey(qdict, actual))
+if (!qdict_haskey(qdict, actual)) {
 return;
-
+}
 monitor_printf(mon, balloon: actual=% PRId64,
qdict_get_int(qdict, actual)  20);
 qdict_iter(qdict, print_balloon_stat, mon);
-- 
1.7.6




[Qemu-devel] [PATCH 7/7] virtio-balloon: Fix header comment; add Copyright

2011-07-26 Thread Amit Shah
Signed-off-by: Amit Shah amit.s...@redhat.com
---
 hw/virtio-balloon.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 40b43b0..2ba7e95 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -1,7 +1,9 @@
 /*
- * Virtio Block Device
+ * Virtio Balloon Device
  *
  * Copyright IBM, Corp. 2008
+ * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011 Amit Shah amit.s...@redhat.com
  *
  * Authors:
  *  Anthony Liguori   aligu...@us.ibm.com
-- 
1.7.6




[Qemu-devel] [PATCH 3/7] balloon: Simplify code flow

2011-07-26 Thread Amit Shah
Replace:
  if (foo) {
...
  } else {
return 0;
  }

by

  if (!foo) {
return 0;
  }
  ...

Signed-off-by: Amit Shah amit.s...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 balloon.c |   16 +++-
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/balloon.c b/balloon.c
index 86f629e..d40be39 100644
--- a/balloon.c
+++ b/balloon.c
@@ -42,23 +42,21 @@ void qemu_add_balloon_handler(QEMUBalloonEvent *func, void 
*opaque)
 
 static int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
 {
-if (balloon_event_fn) {
-trace_balloon_event(balloon_opaque, target);
-balloon_event_fn(balloon_opaque, target, cb, opaque);
-return 1;
-} else {
+if (!balloon_event_fn) {
 return 0;
 }
+trace_balloon_event(balloon_opaque, target);
+balloon_event_fn(balloon_opaque, target, cb, opaque);
+return 1;
 }
 
 static int qemu_balloon_status(MonitorCompletion cb, void *opaque)
 {
-if (balloon_event_fn) {
-balloon_event_fn(balloon_opaque, 0, cb, opaque);
-return 1;
-} else {
+if (!balloon_event_fn) {
 return 0;
 }
+balloon_event_fn(balloon_opaque, 0, cb, opaque);
+return 1;
 }
 
 static void print_balloon_stat(const char *key, QObject *obj, void *opaque)
-- 
1.7.6




[Qemu-devel] [PATCH 4/7] virtio-balloon: Separate status handling into separate function

2011-07-26 Thread Amit Shah
Separate out the code to retrieve balloon info from the code that sets
balloon values.

This will be used to separate the two callbacks from balloon.c and help
cope with 'balloon 0' on the monitor.  Currently, 'balloon 0' causes a
segfault in monitor_resume().

Signed-off-by: Amit Shah amit.s...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 hw/virtio-balloon.c |   51 +++
 1 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 70a8710..2f371f2 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -199,36 +199,47 @@ static uint32_t virtio_balloon_get_features(VirtIODevice 
*vdev, uint32_t f)
 return f;
 }
 
+static void virtio_balloon_stat(void *opaque, MonitorCompletion cb,
+void *cb_data)
+{
+VirtIOBalloon *dev = opaque;
+
+/* For now, only allow one request at a time.  This restriction can be
+ * removed later by queueing callback and data pairs.
+ */
+if (dev-stats_callback != NULL) {
+return;
+}
+dev-stats_callback = cb;
+dev-stats_opaque_callback_data = cb_data;
+
+if (ENABLE_GUEST_STATS
+ (dev-vdev.guest_features  (1  VIRTIO_BALLOON_F_STATS_VQ))) {
+virtqueue_push(dev-svq, dev-stats_vq_elem, dev-stats_vq_offset);
+virtio_notify(dev-vdev, dev-svq);
+return;
+}
+
+/* Stats are not supported.  Clear out any stale values that might
+ * have been set by a more featureful guest kernel.
+ */
+reset_stats(dev);
+complete_stats_request(dev);
+}
+
 static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
  MonitorCompletion cb, void *cb_data)
 {
 VirtIOBalloon *dev = opaque;
 
-if (target  ram_size)
+if (target  ram_size) {
 target = ram_size;
-
+}
 if (target) {
 dev-num_pages = (ram_size - target)  VIRTIO_BALLOON_PFN_SHIFT;
 virtio_notify_config(dev-vdev);
 } else {
-/* For now, only allow one request at a time.  This restriction can be
- * removed later by queueing callback and data pairs.
- */
-if (dev-stats_callback != NULL) {
-return;
-}
-dev-stats_callback = cb;
-dev-stats_opaque_callback_data = cb_data; 
-if (ENABLE_GUEST_STATS  (dev-vdev.guest_features  (1  
VIRTIO_BALLOON_F_STATS_VQ))) {
-virtqueue_push(dev-svq, dev-stats_vq_elem, 
dev-stats_vq_offset);
-virtio_notify(dev-vdev, dev-svq);
-} else {
-/* Stats are not supported.  Clear out any stale values that might
- * have been set by a more featureful guest kernel.
- */
-reset_stats(dev);
-complete_stats_request(dev);
-}
+virtio_balloon_stat(opaque, cb, cb_data);
 }
 }
 
-- 
1.7.6




[Qemu-devel] [PATCH v8 1/5] coroutine: add gthread dependency

2011-07-26 Thread Stefan Hajnoczi
Commit 1fc7bd4a86a2bfeafcec29445871eb97469a2699 removed the gthread and
gio dependency since qemu-ga did not require it.  Coroutines require
gthread, so add it back in.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 configure |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 600da9b..5150372 100755
--- a/configure
+++ b/configure
@@ -1811,9 +1811,9 @@ fi
 
 ##
 # glib support probe
-if $pkg_config --modversion glib-2.0  /dev/null 21 ; then
-glib_cflags=`$pkg_config --cflags glib-2.0 2/dev/null`
-glib_libs=`$pkg_config --libs glib-2.0 2/dev/null`
+if $pkg_config --modversion gthread-2.0  /dev/null 21 ; then
+glib_cflags=`$pkg_config --cflags gthread-2.0 2/dev/null`
+glib_libs=`$pkg_config --libs gthread-2.0 2/dev/null`
 libs_softmmu=$glib_libs $libs_softmmu
 libs_tools=$glib_libs $libs_tools
 else
-- 
1.7.5.4




[Qemu-devel] [PATCH v8 0/5] Coroutines for better asynchronous programming

2011-07-26 Thread Stefan Hajnoczi
QEMU is event-driven and suffers when blocking operations are performed because
VM execution may be stopped until the operation completes.  Therefore many
operations that could block are performed asynchronously and a callback is
invoked when the operation has completed.  This allows QEMU to continue
executing while the operation is pending.

The downside to callbacks is that they split up code into many smaller
functions, each of which is a single step in a state machine that quickly
becomes complex and hard to understand.  Callback functions also result in lots
of noise as variables are packed and unpacked into temporary structs that pass
state to the callback function.

This patch series introduces coroutines as a solution for writing asynchronous
code while still having a nice sequential control flow.  The semantics are
explained in the second patch.  The fourth patch adds automated tests.

A nice feature of coroutines is that it is relatively easy to take synchronous
code and lift it into a coroutine to make it asynchronous.  Work has been done
to move qcow2 request processing into coroutines and thereby make it
asynchronous (today qcow2 will perform synchronous metadata accesses).  This
qcow2 work is still ongoing and not quite ready for mainline yet.

v8:
 * Bisectability: introduce gthread implementation before ucontext/fibers

v7:
 * Reduce ucontext and win32 fiber stack size to 1 MB
 * Add qemu-timer-common.o to test-coroutine dependencies for OpenBSD build

v6:
 * Use GThread on Mac OS X, fix from Andreas Färber andreas.faer...@web.de
 * abort(3) if coroutine-ucontext.c fails to create a coroutine

v5:
 * GThread-based implementation for platforms without makecontext(3) (Aneesh 
Kumar K.V aneesh.ku...@linux.vnet.ibm.com)
 * Switch to gtester test framework

v4:
 * Windows Fibers support (Paolo Bonzini pbonz...@redhat.com)
 * Return-after-setjmp() fix (Aneesh Kumar K.V 
aneesh.ku...@linux.vnet.ibm.com)
 * Re-entrancy for multi-threaded coroutines support
 * qemu-coroutine.h cleanup and documentation

v3:
 * Updated LGPL v2 license header to use web link
 * Removed atexit(3) pool freeing
 * Removed thread-local current/leader
 * Documented thread-safety limitation
 * Disabled trace events

v2:
 * Added ./check-coroutine --lifecycle-benchmark for performance measurement
 * Split pooling into a separate patch with performance justification
 * Set maximum pool size to prevent holding onto too many free coroutines
 * Added atexit(3) handler to free pool
 * Coding style cleanups

Kevin Wolf (1):
  coroutine: add ucontext and win32 implementations

Stefan Hajnoczi (4):
  coroutine: add gthread dependency
  coroutine: introduce coroutines API
  coroutine: add test-coroutine automated tests
  coroutine: add test-coroutine --benchmark-lifecycle

 .gitignore   |1 +
 Makefile |3 +-
 Makefile.objs|   11 +++
 configure|   24 +-
 coroutine-gthread.c  |  131 
 coroutine-ucontext.c |  230 ++
 coroutine-win32.c|   91 
 qemu-coroutine-int.h |   48 +++
 qemu-coroutine.c |   75 
 qemu-coroutine.h |   95 +
 test-coroutine.c |  192 +
 trace-events |5 +
 12 files changed, 902 insertions(+), 4 deletions(-)
 create mode 100644 coroutine-gthread.c
 create mode 100644 coroutine-ucontext.c
 create mode 100644 coroutine-win32.c
 create mode 100644 qemu-coroutine-int.h
 create mode 100644 qemu-coroutine.c
 create mode 100644 qemu-coroutine.h
 create mode 100644 test-coroutine.c

-- 
1.7.5.4




[Qemu-devel] [PATCH v8 5/5] coroutine: add test-coroutine --benchmark-lifecycle

2011-07-26 Thread Stefan Hajnoczi
Add a microbenchmark for coroutine create, enter, and return (aka
lifecycle).  This is a useful benchmark because users are expected to
create many coroutines, one per I/O request for example, and we
therefore need to provide good performance in that scenario.

To run:

  make test-coroutine
  ./test-coroutine --benchmark-lifecycle 2000

This will do 20,000,000 coroutine create, enter, return iterations and
print the resulting time.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 test-coroutine.c |   30 ++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/test-coroutine.c b/test-coroutine.c
index 9e9d3c9..bf9f3e9 100644
--- a/test-coroutine.c
+++ b/test-coroutine.c
@@ -150,6 +150,33 @@ static void test_lifecycle(void)
 g_assert(done); /* expect done to be true (second time) */
 }
 
+/*
+ * Lifecycle benchmark
+ */
+
+static void coroutine_fn empty_coroutine(void *opaque)
+{
+/* Do nothing */
+}
+
+static void perf_lifecycle(void)
+{
+Coroutine *coroutine;
+unsigned int i, max;
+double duration;
+
+max = 100;
+
+g_test_timer_start();
+for (i = 0; i  max; i++) {
+coroutine = qemu_coroutine_create(empty_coroutine);
+qemu_coroutine_enter(coroutine, NULL);
+}
+duration = g_test_timer_elapsed();
+
+g_test_message(Lifecycle %u iterations: %f s\n, max, duration);
+}
+
 int main(int argc, char **argv)
 {
 g_test_init(argc, argv, NULL);
@@ -158,5 +185,8 @@ int main(int argc, char **argv)
 g_test_add_func(/basic/nesting, test_nesting);
 g_test_add_func(/basic/self, test_self);
 g_test_add_func(/basic/in_coroutine, test_in_coroutine);
+if (g_test_perf()) {
+g_test_add_func(/perf/lifecycle, perf_lifecycle);
+}
 return g_test_run();
 }
-- 
1.7.5.4




[Qemu-devel] [PATCH v8 3/5] coroutine: add ucontext and win32 implementations

2011-07-26 Thread Stefan Hajnoczi
From: Kevin Wolf kw...@redhat.com

This coroutines implementation is based on the gtk-vnc implementation written
by Anthony Liguori anth...@codemonkey.ws but it has been significantly
rewritten by Kevin Wolf kw...@redhat.com to use setjmp()/longjmp() instead of
the more expensive swapcontext() and by Paolo Bonzini pbonz...@redhat.com for
Windows Fibers support.

Darwin has makecontext(3) but getcontext(3) is stubbed out to return
ENOTSUP.  Andreas Färber andreas.faer...@web.de debugged this and
contributed the ./configure test which solves the issue for Darwin/ppc64
(and ppc) v10.5.

Signed-off-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 Makefile.objs|8 ++-
 configure|   18 
 coroutine-ucontext.c |  230 ++
 coroutine-win32.c|   91 
 4 files changed, 346 insertions(+), 1 deletions(-)
 create mode 100644 coroutine-ucontext.c
 create mode 100644 coroutine-win32.c

diff --git a/Makefile.objs b/Makefile.objs
index db907c4..5679e1f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -12,7 +12,13 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o 
qemu-thread-posix.o
 
 ###
 # coroutines
-coroutine-obj-y = qemu-coroutine.o coroutine-gthread.o
+coroutine-obj-y = qemu-coroutine.o
+ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
+coroutine-obj-$(CONFIG_POSIX) += coroutine-ucontext.o
+else
+coroutine-obj-$(CONFIG_POSIX) += coroutine-gthread.o
+endif
+coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o
 
 ###
 # block-obj-y is code used by both qemu system emulation and qemu-img
diff --git a/configure b/configure
index 5150372..a4d7921 100755
--- a/configure
+++ b/configure
@@ -2499,6 +2499,20 @@ if test $trace_backend = dtrace; then
 fi
 
 ##
+# check if we have makecontext
+
+ucontext_coroutine=no
+if test $darwin != yes; then
+  cat  $TMPC  EOF
+#include ucontext.h
+int main(void) { makecontext(0, 0, 0); }
+EOF
+  if compile_prog   ; then
+  ucontext_coroutine=yes
+  fi
+fi
+
+##
 # End of CC checks
 # After here, no more $cc or $ld runs
 
@@ -2970,6 +2984,10 @@ if test $rbd = yes ; then
   echo CONFIG_RBD=y  $config_host_mak
 fi
 
+if test $ucontext_coroutine = yes ; then
+  echo CONFIG_UCONTEXT_COROUTINE=y  $config_host_mak
+fi
+
 # USB host support
 case $usb in
 linux)
diff --git a/coroutine-ucontext.c b/coroutine-ucontext.c
new file mode 100644
index 000..41c2379
--- /dev/null
+++ b/coroutine-ucontext.c
@@ -0,0 +1,230 @@
+/*
+ * ucontext coroutine initialization code
+ *
+ * Copyright (C) 2006  Anthony Liguori anth...@codemonkey.ws
+ * Copyright (C) 2011  Kevin Wolf kw...@redhat.com
+ *
+ * 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.0 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/.
+ */
+
+/* XXX Is there a nicer way to disable glibc's stack check for longjmp? */
+#ifdef _FORTIFY_SOURCE
+#undef _FORTIFY_SOURCE
+#endif
+#include stdlib.h
+#include setjmp.h
+#include stdint.h
+#include pthread.h
+#include ucontext.h
+#include qemu-common.h
+#include qemu-coroutine-int.h
+
+enum {
+/* Maximum free pool size prevents holding too many freed coroutines */
+POOL_MAX_SIZE = 64,
+};
+
+typedef struct {
+Coroutine base;
+void *stack;
+jmp_buf env;
+} CoroutineUContext;
+
+/**
+ * Per-thread coroutine bookkeeping
+ */
+typedef struct {
+/** Currently executing coroutine */
+Coroutine *current;
+
+/** Free list to speed up creation */
+QLIST_HEAD(, Coroutine) pool;
+unsigned int pool_size;
+
+/** The default coroutine */
+CoroutineUContext leader;
+} CoroutineThreadState;
+
+static pthread_key_t thread_state_key;
+
+/*
+ * va_args to makecontext() must be type 'int', so passing
+ * the pointer we need may require several int args. This
+ * union is a quick hack to let us do that
+ */
+union cc_arg {
+void *p;
+int i[2];
+};
+
+static CoroutineThreadState *coroutine_get_thread_state(void)
+{
+CoroutineThreadState *s = pthread_getspecific(thread_state_key);
+
+if (!s) {
+s = qemu_mallocz(sizeof(*s));
+s-current = s-leader.base;
+QLIST_INIT(s-pool);
+pthread_setspecific(thread_state_key, s);
+}
+

Re: [Qemu-devel] [PATCH v8 0/5] Coroutines for better asynchronous programming

2011-07-26 Thread Stefan Hajnoczi
On Tue, Jul 26, 2011 at 10:21 AM, Stefan Hajnoczi
stefa...@linux.vnet.ibm.com wrote:
 QEMU is event-driven and suffers when blocking operations are performed 
 because
 VM execution may be stopped until the operation completes.  Therefore many
 operations that could block are performed asynchronously and a callback is
 invoked when the operation has completed.  This allows QEMU to continue
 executing while the operation is pending.

 The downside to callbacks is that they split up code into many smaller
 functions, each of which is a single step in a state machine that quickly
 becomes complex and hard to understand.  Callback functions also result in 
 lots
 of noise as variables are packed and unpacked into temporary structs that pass
 state to the callback function.

 This patch series introduces coroutines as a solution for writing asynchronous
 code while still having a nice sequential control flow.  The semantics are
 explained in the second patch.  The fourth patch adds automated tests.

 A nice feature of coroutines is that it is relatively easy to take synchronous
 code and lift it into a coroutine to make it asynchronous.  Work has been done
 to move qcow2 request processing into coroutines and thereby make it
 asynchronous (today qcow2 will perform synchronous metadata accesses).  This
 qcow2 work is still ongoing and not quite ready for mainline yet.

 v8:
  * Bisectability: introduce gthread implementation before ucontext/fibers

Forgot to mention:
 * Depend on gthread, not just glib, for multithreaded programming

Stefan



[Qemu-devel] [PATCH v8 4/5] coroutine: add test-coroutine automated tests

2011-07-26 Thread Stefan Hajnoczi
To run automated tests for coroutines:

  make test-coroutine
  ./test-coroutine

On success the program terminates with exit status 0.  On failure an
error message is written to stderr and the program exits with exit
status 1.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 .gitignore   |1 +
 Makefile |3 +-
 test-coroutine.c |  162 ++
 3 files changed, 165 insertions(+), 1 deletions(-)
 create mode 100644 test-coroutine.c

diff --git a/.gitignore b/.gitignore
index 54835bc..59c343c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,7 @@ qemu-io
 qemu-ga
 qemu-monitor.texi
 QMP/qmp-commands.txt
+test-coroutine
 .gdbinit
 *.a
 *.aux
diff --git a/Makefile b/Makefile
index f3a03ad..ea8c0ac 100644
--- a/Makefile
+++ b/Makefile
@@ -151,7 +151,7 @@ qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o 
$(oslib-obj-y) $(trac
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h  $  $@,  GEN  
 $@)
 
-check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o 
check-qjson.o: $(GENERATED_HEADERS)
+check-qint.o check-qstring.o check-qdict.o check-qlist.o check-qfloat.o 
check-qjson.o test-coroutine.o: $(GENERATED_HEADERS)
 
 CHECK_PROG_DEPS = qemu-malloc.o $(oslib-obj-y) $(trace-obj-y) qemu-tool.o
 
@@ -161,6 +161,7 @@ check-qdict: check-qdict.o qdict.o qfloat.o qint.o 
qstring.o qbool.o qlist.o $(C
 check-qlist: check-qlist.o qlist.o qint.o $(CHECK_PROG_DEPS)
 check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS)
 check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o 
qjson.o json-streamer.o json-lexer.o json-parser.o error.o qerror.o 
qemu-error.o $(CHECK_PROG_DEPS)
+test-coroutine: test-coroutine.o qemu-timer-common.o $(coroutine-obj-y) 
$(CHECK_PROG_DEPS)
 
 $(qapi-obj-y): $(GENERATED_HEADERS)
 qapi-dir := qapi-generated
diff --git a/test-coroutine.c b/test-coroutine.c
new file mode 100644
index 000..9e9d3c9
--- /dev/null
+++ b/test-coroutine.c
@@ -0,0 +1,162 @@
+/*
+ * Coroutine tests
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Stefan Hajnoczistefa...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include glib.h
+#include qemu-coroutine.h
+
+/*
+ * Check that qemu_in_coroutine() works
+ */
+
+static void coroutine_fn verify_in_coroutine(void *opaque)
+{
+g_assert(qemu_in_coroutine());
+}
+
+static void test_in_coroutine(void)
+{
+Coroutine *coroutine;
+
+g_assert(!qemu_in_coroutine());
+
+coroutine = qemu_coroutine_create(verify_in_coroutine);
+qemu_coroutine_enter(coroutine, NULL);
+}
+
+/*
+ * Check that qemu_coroutine_self() works
+ */
+
+static void coroutine_fn verify_self(void *opaque)
+{
+g_assert(qemu_coroutine_self() == opaque);
+}
+
+static void test_self(void)
+{
+Coroutine *coroutine;
+
+coroutine = qemu_coroutine_create(verify_self);
+qemu_coroutine_enter(coroutine, coroutine);
+}
+
+/*
+ * Check that coroutines may nest multiple levels
+ */
+
+typedef struct {
+unsigned int n_enter;   /* num coroutines entered */
+unsigned int n_return;  /* num coroutines returned */
+unsigned int max;   /* maximum level of nesting */
+} NestData;
+
+static void coroutine_fn nest(void *opaque)
+{
+NestData *nd = opaque;
+
+nd-n_enter++;
+
+if (nd-n_enter  nd-max) {
+Coroutine *child;
+
+child = qemu_coroutine_create(nest);
+qemu_coroutine_enter(child, nd);
+}
+
+nd-n_return++;
+}
+
+static void test_nesting(void)
+{
+Coroutine *root;
+NestData nd = {
+.n_enter  = 0,
+.n_return = 0,
+.max  = 128,
+};
+
+root = qemu_coroutine_create(nest);
+qemu_coroutine_enter(root, nd);
+
+/* Must enter and return from max nesting level */
+g_assert_cmpint(nd.n_enter, ==, nd.max);
+g_assert_cmpint(nd.n_return, ==, nd.max);
+}
+
+/*
+ * Check that yield/enter transfer control correctly
+ */
+
+static void coroutine_fn yield_5_times(void *opaque)
+{
+bool *done = opaque;
+int i;
+
+for (i = 0; i  5; i++) {
+qemu_coroutine_yield();
+}
+*done = true;
+}
+
+static void test_yield(void)
+{
+Coroutine *coroutine;
+bool done = false;
+int i = -1; /* one extra time to return from coroutine */
+
+coroutine = qemu_coroutine_create(yield_5_times);
+while (!done) {
+qemu_coroutine_enter(coroutine, done);
+i++;
+}
+g_assert_cmpint(i, ==, 5); /* coroutine must yield 5 times */
+}
+
+/*
+ * Check that creation, enter, and return work
+ */
+
+static void coroutine_fn set_and_exit(void *opaque)
+{
+bool *done = opaque;
+
+*done = true;
+}
+
+static void test_lifecycle(void)
+{
+Coroutine *coroutine;
+bool done = false;
+
+/* Create, enter, and return from coroutine */
+

[Qemu-devel] [PATCH] configure: add --disable-zlib-test

2011-07-26 Thread Alon Levy
This is required for building libcacard which doesn't itself require
zlib without bringing in this requirement to the build environment.

Signed-off-by: Alon Levy al...@redhat.com
---
I'd like this to go into 0.15.0 too, it makes building libcacard possible
without zlib-devel being installed.
---
 configure |   23 ++-
 1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/configure b/configure
index 88159ac..5fc0f82 100755
--- a/configure
+++ b/configure
@@ -178,6 +178,7 @@ rbd=
 smartcard=
 smartcard_nss=
 opengl=
+zlib=yes
 
 # parse CC options first
 for opt do
@@ -743,6 +744,8 @@ for opt do
   ;;
   --enable-smartcard-nss) smartcard_nss=yes
   ;;
+  --disable-zlib-test) zlib=no
+  ;;
   *) echo ERROR: unknown option $opt; show_help=yes
   ;;
   esac
@@ -1172,18 +1175,20 @@ fi
 ##
 # zlib check
 
-cat  $TMPC  EOF
+if test $zlib != no ; then
+cat  $TMPC  EOF
 #include zlib.h
 int main(void) { zlibVersion(); return 0; }
 EOF
-if compile_prog  -lz ; then
-:
-else
-echo
-echo Error: zlib check failed
-echo Make sure to have the zlib libs and headers installed.
-echo
-exit 1
+if compile_prog  -lz ; then
+:
+else
+echo
+echo Error: zlib check failed
+echo Make sure to have the zlib libs and headers installed.
+echo
+exit 1
+fi
 fi
 
 ##
-- 
1.7.6




[Qemu-devel] mips-linux-user and POSIX IPC

2011-07-26 Thread Holger Freyther
Hi All,

I have no idea about the MIPS ABI (or which one I am actually
using). I try to run Qt/Embedded using the linux-user target and
have some issues with the code.

For semctl qemu enters through the do_ipc method, it appears
to be that the 'variable' ptr is really a ptr (to the stack) and
needs to be dereferenced. The below snippet seems to fix that
issue for me.

My next problem is with do_shmctl, somehow third is NULL but it
should point to the out parameter (and the application is doing
this correctly as well). While trying to understand the issue it
looks like target_to_host_shmid_ds will not properly unlock the
struct on all paths.

Is the IPC emulation supposed to work? Is this an 'obvious' API
issue for MIPS?



@@ -2873,7 +2886,13 @@ static abi_long do_ipc(
 break;
 
 case IPCOP_semctl:
-ret = do_semctl(first, second, third, (union \n
target_semun)(abi_ulong) ptr);
+if (!lock_user_struct(VERIFY_READ, semun, ptr, 1))
+   ret = -TARGET_EFAULT;
+   else {
+   __get_user(t_semun.buf, semun-buf);
+   ret = do_semctl(first, second, third, t_semun);
+   unlock_user_struct(semun, ptr, 0);
+   }
 break;
 





[Qemu-devel] [PATCH 5/7] balloon: Separate out stat and balloon handling

2011-07-26 Thread Amit Shah
Passing on '0' as ballooning target to indicate retrieval of stats is
bad API.  It also makes 'balloon 0' in the monitor cause a segfault.
Have two different functions handle the different functionality instead.

Detailed explanation from Markus's review:

1. do_info_balloon() is an info_async() method.  It receives a callback
   with argument, to be called exactly once (callback frees the
   argument).  It passes the callback via qemu_balloon_status() and
   indirectly through qemu_balloon_event to virtio_balloon_to_target().

   virtio_balloon_to_target() executes its balloon stats half.  It
   stores the callback in the device state.

   If it can't send a stats request, it resets stats and calls the
   callback right away.

   Else, it sends a stats request.  The device model runs the callback
   when it receives the answer.

   Works.

2. do_balloon() is a cmd_async() method.  It receives a callback with
   argument, to be called when the command completes.  do_balloon()
   calls it right before it succeeds.  Odd, but should work.

   Nevertheless, it passes the callback on via qemu_ballon() and
   indirectly through qemu_balloon_event to virtio_balloon_to_target().

   a. If the argument is non-zero, virtio_balloon_to_target() executes
  its balloon half, which doesn't use the callback in any way.

  Odd, but works.

   b. If the argument is zero, virtio_balloon_to_target() executes its
  balloon stats half, just like in 1.  It either calls the callback
  right away, or arranges for it to be called later.

  Thus, the callback runs twice: use after free and double free.

Test case: start with -S -device virtio-balloon, execute balloon 0 in
human monitor.  Runs the callback first from virtio_balloon_to_target(),
then again from do_balloon().

Reported-by: Mike Cao b...@redhat.com
Signed-off-by: Amit Shah amit.s...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
---
 balloon.c   |   17 ++---
 balloon.h   |8 +---
 hw/virtio-balloon.c |7 ++-
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/balloon.c b/balloon.c
index d40be39..8be3812 100644
--- a/balloon.c
+++ b/balloon.c
@@ -32,30 +32,33 @@
 
 
 static QEMUBalloonEvent *balloon_event_fn;
+static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
 
-void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)
+void qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
+  QEMUBalloonStatus *stat_func, void *opaque)
 {
-balloon_event_fn = func;
+balloon_event_fn = event_func;
+balloon_stat_fn = stat_func;
 balloon_opaque = opaque;
 }
 
-static int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)
+static int qemu_balloon(ram_addr_t target)
 {
 if (!balloon_event_fn) {
 return 0;
 }
 trace_balloon_event(balloon_opaque, target);
-balloon_event_fn(balloon_opaque, target, cb, opaque);
+balloon_event_fn(balloon_opaque, target);
 return 1;
 }
 
 static int qemu_balloon_status(MonitorCompletion cb, void *opaque)
 {
-if (!balloon_event_fn) {
+if (!balloon_stat_fn) {
 return 0;
 }
-balloon_event_fn(balloon_opaque, 0, cb, opaque);
+balloon_stat_fn(balloon_opaque, cb, opaque);
 return 1;
 }
 
@@ -135,7 +138,7 @@ int do_balloon(Monitor *mon, const QDict *params,
 return -1;
 }
 
-ret = qemu_balloon(qdict_get_int(params, value), cb, opaque);
+ret = qemu_balloon(qdict_get_int(params, value));
 if (ret == 0) {
 qerror_report(QERR_DEVICE_NOT_ACTIVE, balloon);
 return -1;
diff --git a/balloon.h b/balloon.h
index 06a8a46..a6c31d5 100644
--- a/balloon.h
+++ b/balloon.h
@@ -16,10 +16,12 @@
 
 #include monitor.h
 
-typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target,
-MonitorCompletion cb, void *cb_data);
+typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target);
+typedef void (QEMUBalloonStatus)(void *opaque, MonitorCompletion cb,
+ void *cb_data);
 
-void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque);
+void qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
+  QEMUBalloonStatus *stat_func, void *opaque);
 
 void monitor_print_balloon(Monitor *mon, const QObject *data);
 int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque);
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 2f371f2..40b43b0 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -227,8 +227,7 @@ static void virtio_balloon_stat(void *opaque, 
MonitorCompletion cb,
 complete_stats_request(dev);
 }
 
-static void virtio_balloon_to_target(void *opaque, ram_addr_t target,
- MonitorCompletion cb, void *cb_data)
+static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
 {
 VirtIOBalloon *dev = opaque;
 
@@ -238,8 +237,6 

Re: [Qemu-devel] [RFC PATCH 0/4] Fix subsection ambiguity in the migration format

2011-07-26 Thread Daniel P. Berrange
On Mon, Jul 25, 2011 at 06:23:17PM -0500, Anthony Liguori wrote:
 We also need a way to future proof ourselves.
 
 == What we can do ==
 
 1) Add migration capabilities to future proof ourselves.  I think
 the simplest way this would work is to have a
 'query-migration-capabilities' command that returned a bitmask of
 supported migration features.  I think we also introduce a
 'set-migration-capabilities' command that can mask some of the
 supported features.
 
 A management tool would query-migration features on the source and
 destination, take the intersection of the two masks, and set that
 mask on both the source and destination.
 
 Lack of support for these commands indicates a mask of zero which is
 the protocol we offer today.

This sounds like a very good idea to me.

 5)  We could support 50 formats if we wanted to.  As long as the
 transport is distinct from the serialization and compat routines, it
 really doesn't matter.

Lets not get too carried away :-) Even just dealing with the different
ways libvirt can invoke  manage the migration process gives me ~100
test scenarios to run through for each release of libvirt. The fewer
QEMU testing combinations we need to worry about the better, because
it quickly explodes with migration as you throw different versions
into the mix.


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



[Qemu-devel] [PATCH v8 2/5] coroutine: introduce coroutines API

2011-07-26 Thread Stefan Hajnoczi
Asynchronous code is becoming very complex.  At the same time
synchronous code is growing because it is convenient to write.
Sometimes duplicate code paths are even added, one synchronous and the
other asynchronous.  This patch introduces coroutines which allow code
that looks synchronous but is asynchronous under the covers.

A coroutine has its own stack and is therefore able to preserve state
across blocking operations, which traditionally require callback
functions and manual marshalling of parameters.

Creating and starting a coroutine is easy:

coroutine = qemu_coroutine_create(my_coroutine);
qemu_coroutine_enter(coroutine, my_data);

The coroutine then executes until it returns or yields:

void coroutine_fn my_coroutine(void *opaque) {
MyData *my_data = opaque;

/* do some work */

qemu_coroutine_yield();

/* do some more work */
}

Yielding switches control back to the caller of qemu_coroutine_enter().
This is typically used to switch back to the main thread's event loop
after issuing an asynchronous I/O request.  The request callback will
then invoke qemu_coroutine_enter() once more to switch back to the
coroutine.

Note that if coroutines are used only from threads which hold the global
mutex they will never execute concurrently.  This makes programming with
coroutines easier than with threads.  Race conditions cannot occur since
only one coroutine may be active at any time.  Other coroutines can only
run across yield.

This patch includes a gthread-based coroutines implementation which
should work on all platforms.

[Original gthread patch by Aneesh, made consistent with
coroutine-ucontext.c and switched to GStaticPrivate by Stefan.  Tested
on Linux and OpenBSD.]

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 Makefile.objs|5 ++
 coroutine-gthread.c  |  131 ++
 qemu-coroutine-int.h |   48 ++
 qemu-coroutine.c |   75 
 qemu-coroutine.h |   95 
 trace-events |5 ++
 6 files changed, 359 insertions(+), 0 deletions(-)
 create mode 100644 coroutine-gthread.c
 create mode 100644 qemu-coroutine-int.h
 create mode 100644 qemu-coroutine.c
 create mode 100644 qemu-coroutine.h

diff --git a/Makefile.objs b/Makefile.objs
index 6991a9f..db907c4 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -11,6 +11,10 @@ oslib-obj-$(CONFIG_WIN32) += oslib-win32.o 
qemu-thread-win32.o
 oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
 
 ###
+# coroutines
+coroutine-obj-y = qemu-coroutine.o coroutine-gthread.o
+
+###
 # block-obj-y is code used by both qemu system emulation and qemu-img
 
 block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o 
async.o
@@ -69,6 +73,7 @@ common-obj-y += readline.o console.o cursor.o qemu-error.o
 common-obj-y += $(oslib-obj-y)
 common-obj-$(CONFIG_WIN32) += os-win32.o
 common-obj-$(CONFIG_POSIX) += os-posix.o
+common-obj-y += $(coroutine-obj-y)
 
 common-obj-y += tcg-runtime.o host-utils.o
 common-obj-y += irq.o ioport.o input.o
diff --git a/coroutine-gthread.c b/coroutine-gthread.c
new file mode 100644
index 000..f09877e
--- /dev/null
+++ b/coroutine-gthread.c
@@ -0,0 +1,131 @@
+/*
+ * GThread coroutine initialization code
+ *
+ * Copyright (C) 2006  Anthony Liguori anth...@codemonkey.ws
+ * Copyright (C) 2011  Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
+ *
+ * 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.0 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 glib.h
+#include qemu-common.h
+#include qemu-coroutine-int.h
+
+typedef struct {
+Coroutine base;
+GThread *thread;
+bool runnable;
+CoroutineAction action;
+} CoroutineGThread;
+
+static GCond *coroutine_cond;
+static GStaticMutex coroutine_lock = G_STATIC_MUTEX_INIT;
+static GStaticPrivate coroutine_key = G_STATIC_PRIVATE_INIT;
+
+static void __attribute__((constructor)) coroutine_init(void)
+{
+if (!g_thread_supported()) {
+g_thread_init(NULL);
+}
+
+coroutine_cond = g_cond_new();
+}
+
+static void coroutine_wait_runnable_locked(CoroutineGThread *co)
+{
+while (!co-runnable) {
+  

Re: [Qemu-devel] [RFC PATCH 0/4] Fix subsection ambiguity in the migration format

2011-07-26 Thread Stefan Hajnoczi
On Mon, Jul 25, 2011 at 06:23:17PM -0500, Anthony Liguori wrote:
 On 07/25/2011 04:10 PM, Paolo Bonzini wrote:
 On Thu, Jun 30, 2011 at 17:46, Paolo Bonzinipbonz...@redhat.com  wrote:
 With the current migration format, VMS_STRUCTs with subsections
 are ambiguous.  The protocol cannot tell whether a 0x5 byte after
 the VMS_STRUCT is a subsection or part of the parent data stream.
 In the past QEMU assumed it was always a part of a subsection; after
 commit eb60260 (savevm: fix corruption in vmstate_subsection_load(),
 2011-02-03) the choice depends on whether the VMS_STRUCT has subsections
 defined.
 
 Unfortunately, this means that if a destination has no subsections
 defined for the struct, it will happily read subsection data into
 its own fields.  And if you are lucky enough to stumble on a
 zero byte at the right time, it will be interpreted as QEMU_VM_EOF
 and migration will be interrupted with half-loaded state.
 
 There is no way out of this except defining an incompatible
 migration protocol.  Not-so-long-term we should really try to define
 one that is not a joke, but the bug is serious so we need a solution
 for 0.15.  A sentinel at the end of embedded structs does remove the
 ambiguity.
 
 Of course, this can be restricted to new machine models, and this
 is what the patch series does.  (And note that only patch 3 is specific
 to the short-term solution, everything else is entirely generic).
 
 Untested beyond compilation.
 
 I have now tested this series (exactly as sent) both by examining
 manually the differences between the two formats on the same guest
 state, and by a mix of saves/restores (new on new, 0.14 on new
 pc-0.14, new pc-0.14 on 0.14; also the same combinations on RHEL).  It
 always does what is expected.
 
 Michael Tsirkin objected that the format should be passed as a
 parameter in the migrate command.  I kind of agree, however since this
 is a real bug you would need to bump the default for new machine
 types, and this default would still go in the QEMUMachine struct like
 I am doing.  So I consider the two settings to be orthogonal.  Also,
 the alternative requires changes to the whole management stack and if
 the default is not changed it imposes a broken format unless you
 update the management tools.  Clearly much less bang for the buck.
 
 I think this is ready to go into 0.15.
 
 I'll take a look for 0.15.
 
 The bug happens when migrating
 to 0.14 a pc-0.14 machine created with QEMU 0.15 and which has a
 floppy.  The media changed subsection is almost always included, and
 this causes problems when migrating to 0.14 which didn't have any
 subsection for the floppy device.  While QEMU support for migration to
 old version admittedly depends on luck, this isn't true of certain
 downstreams :) which would like to have an unambiguous migration
 format.
 
 So this got me thinking about where we're at with migration and
 where we need to go.
 
 I actually think there might be a reasonable path forward if we
 attack the problem differently than we have so far.
 
 == Today ==
 
 Today we only support generating the latest serialization of
 devices. To increase the probability of the latest version working
 on older versions of QEMU, we strategically omit fields that we know
 can safely be omitted with older versions (subsections).  More than
 likely, migrating new to old won't work.
 
 Migrating old to new is more likely to work.  We version each
 section in order to be able to identify when we're dealing with old.
 
 But all of this logic lives in one of two forms.  Either as a
 savevm/loadvm callback that takes a QEMUFile and writes byte
 serialization to the stream in an open way (usually big endian) or
 encoded declaratively in a VMState section.
 
 == What we need ==
 
 We need to decompose migration into three different problems: 1)
 serializing device state 2) transforming the device model in order
 to satisfy forwards and backwards compatibility 3) encoding the
 serialized device model on the wire.
 
 We also need a way to future proof ourselves.
 
 == What we can do ==
 
 1) Add migration capabilities to future proof ourselves.  I think
 the simplest way this would work is to have a
 'query-migration-capabilities' command that returned a bitmask of
 supported migration features.  I think we also introduce a
 'set-migration-capabilities' command that can mask some of the
 supported features.
 
 A management tool would query-migration features on the source and
 destination, take the intersection of the two masks, and set that
 mask on both the source and destination.
 
 Lack of support for these commands indicates a mask of zero which is
 the protocol we offer today.

When the management tool drives negotiation it is possible to do nice
error reporting (each capability bit has a meaning and detailed
incompatibility errors can be generated).

However, doing so imposes extra work on management tools - they need to
understand and drive negotiation.  If QEMU adds a new 

Re: [Qemu-devel] [PATCH v7 2/4] coroutine: implement coroutines using gthread

2011-07-26 Thread Stefan Hajnoczi
On Mon, Jul 25, 2011 at 9:38 PM, Anthony Liguori anth...@codemonkey.ws wrote:
 On 07/25/2011 03:04 PM, Stefan Hajnoczi wrote:

 From: Aneesh Kumar K.Vaneesh.ku...@linux.vnet.ibm.com

 On platforms that don't support makecontext(3) use gthread based
 coroutine implementation.

 Darwin has makecontext(3) but getcontext(3) is stubbed out to return
 ENOTSUP.  Andreas Färberandreas.faer...@web.de  debugged this and
 contributed the ./configure test which solves the issue for Darwin/ppc64
 (and ppc) v10.5.

 [Original patch by Aneesh, made consistent with coroutine-ucontext.c and
 switched to GStaticPrivate by Stefan.  Tested on Linux and OpenBSD.]

 Signed-off-by: Aneesh Kumar K.Vaneesh.ku...@linux.vnet.ibm.com
 Signed-off-by: Stefan Hajnoczistefa...@linux.vnet.ibm.com
 ---
  Makefile.objs       |    4 ++
  configure           |   18 +++
  coroutine-gthread.c |  131
 +++
  3 files changed, 153 insertions(+), 0 deletions(-)
  create mode 100644 coroutine-gthread.c

 diff --git a/Makefile.objs b/Makefile.objs
 index 28e1762..5679e1f 100644
 --- a/Makefile.objs
 +++ b/Makefile.objs
 @@ -13,7 +13,11 @@ oslib-obj-$(CONFIG_POSIX) += oslib-posix.o
 qemu-thread-posix.o
  ###
  # coroutines
  coroutine-obj-y = qemu-coroutine.o
 +ifeq ($(CONFIG_UCONTEXT_COROUTINE),y)
  coroutine-obj-$(CONFIG_POSIX) += coroutine-ucontext.o
 +else
 +coroutine-obj-$(CONFIG_POSIX) += coroutine-gthread.o
 +endif
  coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o

  ###
 diff --git a/configure b/configure
 index 600da9b..1b6ad87 100755
 --- a/configure
 +++ b/configure
 @@ -2499,6 +2499,20 @@ if test $trace_backend = dtrace; then
  fi

  ##
 +# check if we have makecontext
 +
 +ucontext_coroutine=no
 +if test $darwin != yes; then
 +  cat  $TMPC  EOF
 +#includeucontext.h
 +int main(void) { makecontext(0, 0, 0); }
 +EOF
 +  if compile_prog   ; then
 +      ucontext_coroutine=yes
 +  fi
 +fi
 +

 Doesn't this make the build non-bisectable on platforms that don't have
 makecontext?  I think the gthread patch needs to come first and then the
 ucontext version can be used on platforms that we detect it's there.

You are correct.  I have sent a new version that first introduces
gthread, and then ucontext and fibers.

Stefan



Re: [Qemu-devel] [PATCH 03/23] memory: merge adjacent segments of a single memory region

2011-07-26 Thread Avi Kivity

On 07/25/2011 09:48 PM, Anthony Liguori wrote:

+/* Attempt to simplify a view by merging ajacent ranges */
+static void flatview_simplify(FlatView *view)
+{
+unsigned i;
+FlatRange *r1, *r2;
+
+for (i = 0; i + 1  view-nr; ++i) {
+r1 =view-ranges[i];
+r2 =view-ranges[i+1];
+if (addrrange_end(r1-addr) == r2-addr.start
+  r1-mr == r2-mr
+  r1-offset_in_region + r1-addr.size == r2-offset_in_region
+  r1-dirty_log_mask == r2-dirty_log_mask) {
+r1-addr.size += r2-addr.size;
+memmove(r2, r2 + 1, (view-nr - (i + 2)) * sizeof(*r2));
+--view-nr;
+--i;
+}



The --i is pretty subtle.  Moving the index variable backwards in a 
conditional in a for loop is pretty evil :-)  I started writing up why 
this was wrong until I noticed that.


I think the following would be more straight forward:

i = 0;
while (i + 1  view-nr) {
   int begin = i, end = i + 1;

   while (matches(view-ranges[begin], view-ranges[end])) {
  end++;
   }

   memmove(...)
}



Right; updated to something along these lines.

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




[Qemu-devel] [PATCH 6/7] balloon: Fix header comment; add Copyright

2011-07-26 Thread Amit Shah
Signed-off-by: Amit Shah amit.s...@redhat.com
---
 balloon.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/balloon.c b/balloon.c
index 8be3812..a938475 100644
--- a/balloon.c
+++ b/balloon.c
@@ -1,7 +1,9 @@
 /*
- * QEMU System Emulator
+ * Generic Balloon handlers and management
  *
  * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011 Amit Shah amit.s...@redhat.com
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the Software), to 
deal
@@ -30,7 +32,6 @@
 #include balloon.h
 #include trace.h
 
-
 static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonStatus *balloon_stat_fn;
 static void *balloon_opaque;
-- 
1.7.6




Re: [Qemu-devel] [PATCH 06/23] memory: rename MemoryRegion::has_ram_addr to ::terminates

2011-07-26 Thread Avi Kivity

On 07/25/2011 09:56 PM, Anthony Liguori wrote:

On 07/25/2011 09:02 AM, Avi Kivity wrote:

I/O regions will not have ram_addrs, so this is a better name.

Signed-off-by: Avi Kivitya...@redhat.com


Reviewed-by: Anthony Liguori aligu...@us.ibm.com

Although it seems squashable.


Yeah, I'm loath to squash across a conflicting commit though.

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




Re: [Qemu-devel] [PATCH 11/23] memory: add ioeventfd support

2011-07-26 Thread Avi Kivity

On 07/25/2011 10:08 PM, Anthony Liguori wrote:


+static void as_memory_ioeventfd_add(AddressSpace *as, 
MemoryRegionIoeventfd *fd)

+{
+int r;
+
+if (!fd-match_data || fd-addr.size != 4) {
+abort();
+}
+
+r = kvm_set_ioeventfd_mmio_long(fd-fd, fd-addr.start, 
fd-data, true);

+if (r  0) {
+abort();
+}



asserts would be friendlier.


I thought asserts were disabled by default.  But I see it isn't so; will 
update.




I really dislike baking ioeventfd into this API.  There is only one 
user of ioeventfd in the tree.


Two: virtio-pci and ivshmem.



I worry that by having things like ioeventfd the API, we're making it 
too difficult to side-step the API which prevents future optimizations.


I'd prefer virtio-pci to have ugliness in it where it circumvented the 
layering vs. having such a device specific thing in generic code.


It's impossible (or at least, impossible without further information 
from the API) to do this and retain correctness.  Currently virtio-pci 
is broken wrt bridges and overlapping BARs; it's probably also broken on 
targets that bridge the I/O address space to MMIO.


With the memory API, this is fixed in a natural way by making the I/O 
address space a subregion of the bridge which does the conversion; the 
code will automatically add the needed offset and use MMIO ioeventfd 
instead of portio.


On a more general note, I don't want this to be a lean and mean API that 
throws any complexity to the users; instead I want to make writing 
devices as simple as possible and own all the smarts.


(an example - undecoded address bits can be specified to the API which 
then takes care of replication or shifting).


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




Re: [Qemu-devel] [PATCH 0/3] Add PL111, implement PL110 BGR mode

2011-07-26 Thread Peter Maydell
On 22 July 2011 16:59, Peter Maydell peter.mayd...@linaro.org wrote:
 This patch series improves the emulation of the PL11x CLCD
 controllers used by the various ARM dev boards.

 versatilepb has a PL110 but it also has an external mux controlled
 by a system register which allows the OS to select whether the
 16 bit graphics format should be 5551, RGB565 or BGR565.

 In particular, Linux kernels 2.6.39 and above default to programming
 the versatilepb for BGR565, so we need to support the mux control
 rather than always assuming RGB565.

This issue was originally reported on IRC by Francis Moreau,
who has now kindly tested these patches and tells me that they
do indeed fix the issues he was seeing.

-- PMM



Re: [Qemu-devel] External COW format for raw images

2011-07-26 Thread Stefan Hajnoczi
On Wed, Jul 20, 2011 at 4:57 PM, Marcelo Tosatti mtosa...@redhat.com wrote:
 On Wed, Jul 20, 2011 at 09:35:05AM +0100, Stefan Hajnoczi wrote:
 2011/7/19 Anthony Liguori anth...@codemonkey.ws:
  On 07/19/2011 04:25 AM, Robert Wang wrote:
  As you known, raw image is very popular,but the raw image format does
  NOT support Copy-On-Write,a raw image file can NOT be used as a copy
  destination, then image streaming/Live Block Copy will NOT work.
 
  To fix this, we need to add a new block driver raw-cow to QEMU. If
  finished, we can use qemu-img like this:
  qemu-img create -f raw-cow -o backing_file=ubuntu.img,raw_file=my_vm.img
  my_vm.raw-cow
 
  1) ubuntu.img is the backing file, my_vm.img is a raw file,
  my_vm.raw-cow stores a COW bitmap related to my_vm.img.
 
  2) If the entire COW bitmap is set to dirty flag then we can get all
  information from my_vm.img and can ignore ubuntu.img and my_vm.raw-cow
  from now.
 
  To implement this, I think I can follow these steps:
  1) Add a new member to BlockDriverState struct:
  char raw_file[1024];
  This member will track raw_file parameter related to raw-cow file from
  command line.
 
  2)    * Create a new file block/raw-cow.c. It will be much more like the
  mixture of block/cow.c and block/raw.c.
 
  So I will change some functions in cow.c and raw.c to none-static, then
  raw-cow.c can re-use them. When read operation occurs, determine whether
  dirty flag in raw-cow image is set. If true, read directly from the raw
  file. After write operation, set related dirty flag in raw-cow image.
  And other functions might also be modified.
 
        * Of course, format_name member of BlockDriver struct will be 
  raw-cow.
  And in order to keep relationship with raw file( like my_vm.img) ,
  raw_cow_header struct should be
  struct raw_cow_header {
  uint32_t magic;
  uint32_t version;
  char backing_file[1024];
  char raw_file[1024];/* added*/
  int32_t mtime;
  uint64_t size;
  uint32_t sectorsize;
  };
 
  I'd suggest that doing an image format is the wrong approach here.  Why
  not just have a image format where you can pass it the location of a
  bitmap?  That let's you compose arbitrarily complex backing file chains
  and avoids the introduce of a new bitmap.

 Its possible to implement backing file chains in any case, no need for
 separate bitmap on-disk.

  The bitmap format is also useful for implementing things like dirty
  tracking.

 Are you describing something like -drive
 file=bitmap:raw.img:backing.img:dirty.bmap?

 Stefan

 The bitmap (whether its separate or part of the image) is intimately
 related to the raw file, and the relation is specific indicating
 allocated status.

 Perhaps what Anthony is suggesting is an interface for on-disk bitmap
 access, with caching?

Anthony, could you elaborate what you meant?

Stefan



Re: [Qemu-devel] idea: non-ethernet paravirtual network device

2011-07-26 Thread Hannes Reinecke

On 07/26/2011 08:04 AM, Stefan Hajnoczi wrote:

On Mon, Jul 25, 2011 at 4:53 PM, Sassan Panahinejadsas...@sassan.me.uk  wrote:

Here's a thought, could we improve network performance by creating a
paravirtual network device which doesn't emulate ethernet? It shouldn't be
too hard to just whack IP packets pretty much directly over a virtio link.
This should improve performance when using a user host connection and we
could introduce a tun host connection instead of tap for this setup.

Does anyone have any thoughts on how worthwhile this would be? Would the
performance improvement justify the effort involved?


My guess is no noticable impact (if you ignore ARP requests).

The Ethernet header is only 14 bytes or so.  We don't calculate any
checksums at that level.  There's probably not much of a win.


Only lots of pain to be had.
Mainframe used to do this. But abandoned it not, thankfully.

Problem is that you need to patch each and every tool looking at the 
packets to _not_ expecting an Ethernet header.

And patching up DHCP is _not_ trivial.

Cheers,

Hannes
--
Dr. Hannes Reinecke   zSeries  Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)



Re: [Qemu-devel] [PATCH 12/23] memory: separate building the final memory map into two steps

2011-07-26 Thread Avi Kivity

On 07/25/2011 10:12 PM, Anthony Liguori wrote:

On 07/25/2011 09:02 AM, Avi Kivity wrote:

Instead of adding and deleting regions in one pass, do a delete
pass followed by an add pass.  This fixes the following case:

from:
   0x-0x0fff ram  (a1)
   0x1000-0x1fff mmio (a2)
   0x2000-0x2fff ram  (a3)

to:
   0x-0x2fff ram  (b1)

The single pass algorithm removed a1, added b2, then removed a2 and a2,


You mean a2 and a3 I suppose?


Yes; fixed.

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




Re: [Qemu-devel] [PATCH 13/23] memory: document the memory API

2011-07-26 Thread Avi Kivity

On 07/25/2011 10:15 PM, Anthony Liguori wrote:

+Region names
+
+
+Regions are assigned names by the constructor.  For most regions 
these are
+only used for debugging purposes, but RAM regions also use the name 
to identify
+live migration sections.  This means that RAM region names need to 
have ABI

+stability.

+

I don't think this needs to change for this series, but long term, 
this is something that we need to better think through.


Device ROM is part of the device.  It shouldn't be migrated as RAM, it 
should be included in the device state.


Agreed; however I tries to limit the amount of functional change, 
especially with anything resembling an ABI.




Would be nice to make this patch #1 in the series.


Done.

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




Re: [Qemu-devel] [PATCH 14/23] memory: transaction API

2011-07-26 Thread Avi Kivity

On 07/25/2011 10:16 PM, Anthony Liguori wrote:

On 07/25/2011 09:02 AM, Avi Kivity wrote:

Allow changes to the memory hierarchy to be accumulated and
made visible all at once.  This reduces computational effort,
especially when an accelerator (e.g. kvm) is involved.

Useful when a single register update causes multiple changes
to an address space.

Signed-off-by: Avi Kivitya...@redhat.com


What's the motivation for this?  Was this just because it seemed neat 
to do or did you run into a performance issue you were trying to solve?


Both cirrus and 440fx need this; look at i440fx_update_memory_mappings() 
for example, it blindly updates mappings even for PAMs which haven't 
changed.


These issues can be also solved by more care on the caller's side, or by 
making the API richer, but it's good to have a no-thought-required 
solution, particularly as it's so easy to do.


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




Re: [Qemu-devel] [PATCH 15/23] exec.c: initialize memory map

2011-07-26 Thread Avi Kivity

On 07/25/2011 10:17 PM, Anthony Liguori wrote:

+static void memory_map_init(void)
+{
+system_memory = qemu_malloc(sizeof(*system_memory));
+memory_region_init(system_memory, system, UINT64_MAX);



Would be nice to #define MEM_REG_SIZE_ALL UINT64_MAX

Without reading the docs, it seems like an odd bit of code otherwise.


It's really temporary.  It should come from the machine description and 
specify the processor's system bus width.


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




Re: [Qemu-devel] [PATCH 16/23] ioport: register ranges by byte aligned addresses always

2011-07-26 Thread Avi Kivity

On 07/25/2011 10:20 PM, Anthony Liguori wrote:

On 07/25/2011 09:02 AM, Avi Kivity wrote:

The I/O port space is byte addressable, even for word and long accesses.

An example is the VMware svga card, which has long ports on offsets 0,
1, and 2.

Signed-off-by: Avi Kivitya...@redhat.com


I've always thought this was odd but didn't know of a specific 
circumstance where it broke a device.


This was a big problem with the old API.  Devices don't register their 
interest in specific sizes.  They may ignore certain size accesses but 
that's a device specific behavior.


In fact there's on counterexample - 440FX consumes dword accesses on 
port cf8 but forwards byte and word accesses to the PCI bus.  This 
cannot be implemented with the current API (it requires the opaque to be 
equal for all word sizes).  The new API doesn't support it either; if we 
need to, we can re-issue the access but using the PCI address space 
instead of the root I/O address space.


(of course this is purely theoretical)

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




Re: [Qemu-devel] [PATCH 19/23] pc: move global memory map out of pc_init1() and into its callers

2011-07-26 Thread Avi Kivity

On 07/25/2011 11:02 PM, Anthony Liguori wrote:

On 07/25/2011 09:03 AM, Avi Kivity wrote:

Signed-off-by: Avi Kivitya...@redhat.com


What's the rationale here?


Removing globals and making dependencies explicit.

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




Re: [Qemu-devel] [PATCH 21/23] pci: add MemoryRegion based BAR management API

2011-07-26 Thread Avi Kivity

On 07/25/2011 11:20 PM, Anthony Liguori wrote:

On 07/25/2011 09:03 AM, Avi Kivity wrote:
Allow registering a BAR using a MemoryRegion.  Once all users are 
converted,

pci_register_bar() and pci_register_bar_simple() will be removed.

Signed-off-by: Avi Kivitya...@redhat.com



diff --git a/hw/pci.h b/hw/pci.h
index cfeb042..c51156d 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -94,6 +94,7 @@ typedef struct PCIIORegion {
  uint8_t type;
  PCIMapIORegionFunc *map_func;
  ram_addr_t ram_addr;
+MemoryRegion *memory;
  } PCIIORegion;

  #define PCI_ROM_SLOT 6
@@ -204,6 +205,8 @@ void pci_register_bar(PCIDevice *pci_dev, int 
region_num,

  PCIMapIORegionFunc *map_func);
  void pci_register_bar_simple(PCIDevice *pci_dev, int region_num,
   pcibus_t size, uint8_t attr, 
ram_addr_t ram_addr);

+void pci_register_bar_region(PCIDevice *pci_dev, int region_num,
+ uint8_t attr, MemoryRegion *memory);


This ends up being a very nice API.  I had always thought this should 
be a PCI specific set of callbacks but I do see the benefits of having 
the callbacks be generic.


Reviewed-by: Anthony Liguori aligu...@us.ibm.com

One thing I'm curious about, what's the symmetric view of this API?

Would you see a device doing something like:

memory_region_read(dev-pci_bus-memory, addr, data, sizeof(data))



I haven't really considered this, but it makes sense to consider the 
initiating point for DMA.  This allows us to do IOMMU transformations 
naturally.


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




Re: [Qemu-devel] KVM call agenda for July 26

2011-07-26 Thread Stefan Hajnoczi
On Tue, Jul 26, 2011 at 12:30 AM, Juan Quintela quint...@redhat.com wrote:
 Please send in any agenda items you are interested in covering.

0.15.0 release candidate testing
 * http://wiki.qemu.org/Planning/0.15/Testing
 * Please test hosts, targets, subsystems, or features you care about!
 * May just include running the test suite (KVM-Autotest, qemu-iotests, etc)

Stefan



Re: [Qemu-devel] [RFC PATCH 2/2] separate thread for VM migration

2011-07-26 Thread Paolo Bonzini

On 07/22/2011 09:58 PM, Umesh Deshapnde wrote:

-qemu_mod_timer(s-timer, qemu_get_clock_ms(rt_clock) + 100);
+qemu_mod_timer(s-timer, qemu_get_clock_ms(migration_clock) + 100);

  if (s-freeze_output)
  return;
@@ -246,8 +246,10 @@ static void buffered_rate_tick(void *opaque)

  buffered_flush(s);

-/* Add some checks around this */
  s-put_ready(s-opaque);
+qemu_mutex_unlock_iothread();
+usleep(qemu_timer_difference(s-timer, migration_clock) * 1000);
+qemu_mutex_lock_iothread();
  }


Do you really need a timer?  The timer will only run in the migration 
thread, where you should have full control on when to wait.


The BufferedFile code is more general, but you can create one thread per 
BufferedFile (you will only have one).  Then, since you only have one 
timer, calling buffered_rate_tick repeatedly is really all that is done 
in the body of the thread:


while (s-state == MIG_STATE_ACTIVE)
start_time = qemu_get_clock_ms(rt_clock);
buffered_rate_tick (s-file);

qemu_mutex_unlock_iothread();
usleep ((qemu_get_clock_ms(rt_clock) + 100 - start_time) * 1000);
qemu_mutex_lock_iothread();
}


Perhaps the whole QEMUFile abstraction should be abandoned as the basis 
of QEMUBufferedFile.  It is simply too heavy when you're working in a 
separate thread and you can afford blocking operation.


I also am not sure about the correctness.  Here you removed the delayed 
call to migrate_fd_put_notify, which is what resets freeze_output to 0:



@@ -327,9 +320,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void 
*data, size_t size)
  if (ret == -1)
  ret = -(s-get_error(s));

-if (ret == -EAGAIN) {
-qemu_set_fd_handler2(s-fd, NULL, NULL, migrate_fd_put_notify, s);
-} else if (ret  0) {
+if (ret  0  ret != -EAGAIN) {
  if (s-mon) {
  monitor_resume(s-mon);
  }


The call to migrate_fd_put_notify is here:


@@ -396,6 +401,9 @@ void migrate_fd_put_ready(void *opaque)
 }
 s-state = state;
 notifier_list_notify(migration_state_notifiers);
+} else {
+migrate_fd_wait_for_unfreeze(s);
+qemu_file_put_notify(s-file);
 }
 }



But it is not clear to me what calls migrate_fd_put_ready when the 
output file is frozen.


Finally, here you are busy waiting:


@@ -340,10 +331,34 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void 
*data, size_t size)
  return ret;
  }

-void migrate_fd_connect(FdMigrationState *s)
+void *migrate_run_timers(void *arg)
  {
+FdMigrationState *s = arg;
  int ret;

+qemu_mutex_lock_iothread();
+ret = qemu_savevm_state_begin(s-mon, s-file, s-mig_state.blk,
+s-mig_state.shared);
+if (ret  0) {
+DPRINTF(failed, %d\n, ret);
+migrate_fd_error(s);
+return NULL;
+}
+
+migrate_fd_put_ready(s);
+
+while (s-state == MIG_STATE_ACTIVE) {
+qemu_run_timers(migration_clock);
+}


which also convinces me that if you make rate limiting the main purpose 
of the migration thread's main loop, most problems will go away.  You 
can also use select() instead of usleep, so that you fix the problem 
with qemu_file_put_notify.


Paolo



[Qemu-devel] [PATCH v2 04/23] memory: merge adjacent segments of a single memory region

2011-07-26 Thread Avi Kivity
Simple implementations of memory routers, for example the Cirrus VGA memory 
banks
or the 440FX PAM registers can generate adjacent memory regions which are 
contiguous.
Detect these and merge them; this saves kvm memory slots and shortens lookup 
times.

Signed-off-by: Avi Kivity a...@redhat.com
---
 memory.c |   29 +
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/memory.c b/memory.c
index d858b47..121f9e1 100644
--- a/memory.c
+++ b/memory.c
@@ -122,6 +122,34 @@ static void flatview_destroy(FlatView *view)
 qemu_free(view-ranges);
 }
 
+static bool can_merge(FlatRange *r1, FlatRange *r2)
+{
+return addrrange_end(r1-addr) == r2-addr.start
+ r1-mr == r2-mr
+ r1-offset_in_region + r1-addr.size == r2-offset_in_region
+ r1-dirty_log_mask == r2-dirty_log_mask;
+}
+
+/* Attempt to simplify a view by merging ajacent ranges */
+static void flatview_simplify(FlatView *view)
+{
+unsigned i, j;
+
+i = 0;
+while (i  view-nr) {
+j = i + 1;
+while (j  view-nr
+can_merge(view-ranges[j-1], view-ranges[j])) {
+view-ranges[i].addr.size += view-ranges[j].addr.size;
+++j;
+}
+++i;
+memmove(view-ranges[i], view-ranges[j],
+(view-nr - j) * sizeof(view-ranges[j]));
+view-nr -= j - i;
+}
+}
+
 /* Render a memory region into the global view.  Ranges in @view obscure
  * ranges in @mr.
  */
@@ -209,6 +237,7 @@ static FlatView generate_memory_topology(MemoryRegion *mr)
 flatview_init(view);
 
 render_memory_region(view, mr, 0, addrrange_make(0, UINT64_MAX));
+flatview_simplify(view);
 
 return view;
 }
-- 
1.7.5.3




Re: [Qemu-devel] [PATCH 00/23] Memory API, batch 1

2011-07-26 Thread Avi Kivity

On 07/25/2011 11:23 PM, Anthony Liguori wrote:


Very nice series.

Despite my lack of exciting over ioeventfd and coalescing, if you fix 
the few minor comments, this should be a no brainer to merge.


Thanks; v2 posted.

Note that this patchset has a logical dependency on my [PATCH] 
CODING_STYLE: explicitly allow braceless 'else if' patch.


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




[Qemu-devel] [Bug 816370] [NEW] compile error in QEMU 0.15.0-rc0

2011-07-26 Thread rowa
Public bug reported:

I've tryed to compile QEMU 0.15.0-rc0 on Ubuntu 10.10 „Maverick Meerkat“
but I get an error (For further details please see http://qemu-
buch.de/d/Installation#Quellen_kompilieren ).

./configure --prefix=/usr --enable-spice  
--audio-card-list=ac97,es1370,sb16,adlib,gus,cs4231a
make

  GEN   config-host.h
  GEN   trace.h
  GEN   qemu-options.def
  GEN   qapi-generated/qga-qapi-types.h
  GEN   qapi-generated/qga-qapi-visit.h
  GEN   qapi-generated/qga-qmp-marshal.c
  CCqapi/qapi-visit-core.o
In file included from qapi/qapi-visit-core.c:14:
./qapi/qapi-visit-core.h:31: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:32: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:34: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:35: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:36: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:39: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:41: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:42: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:43: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:45: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:49: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:50: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:53: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:54: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:58: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:59: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:61: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:62: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:63: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:64: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:65: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:67: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:68: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:70: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:71: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:72: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:73: error: expected declaration specifiers or ‘...’ 
before ‘Error’
./qapi/qapi-visit-core.h:74: error: expected declaration specifiers or ‘...’ 
before ‘Error’
qapi/qapi-visit-core.c:17: error: expected declaration specifiers or ‘...’ 
before ‘Error’
qapi/qapi-visit-core.c: In function ‘visit_start_handle’:
qapi/qapi-visit-core.c:19: warning: implicit declaration of function 
‘error_is_set’
qapi/qapi-visit-core.c:19: warning: nested extern declaration of ‘error_is_set’
qapi/qapi-visit-core.c:19: error: ‘errp’ undeclared (first use in this function)
qapi/qapi-visit-core.c:19: error: (Each undeclared identifier is reported only 
once
qapi/qapi-visit-core.c:19: error: for each function it appears in.)
qapi/qapi-visit-core.c:20: error: too many arguments to function 
‘v-start_handle’
qapi/qapi-visit-core.c: At top level:
qapi/qapi-visit-core.c:24: error: expected declaration specifiers or ‘...’ 
before ‘Error’
qapi/qapi-visit-core.c: In function ‘visit_end_handle’:
qapi/qapi-visit-core.c:26: error: ‘errp’ undeclared (first use in this function)
qapi/qapi-visit-core.c:27: error: too many arguments to function ‘v-end_handle’
qapi/qapi-visit-core.c: At top level:
qapi/qapi-visit-core.c:32: error: expected declaration specifiers or ‘...’ 
before ‘Error’
qapi/qapi-visit-core.c: In function ‘visit_start_struct’:
qapi/qapi-visit-core.c:34: error: ‘errp’ undeclared (first use in this function)
qapi/qapi-visit-core.c:35: error: too many arguments to function 
‘v-start_struct’
qapi/qapi-visit-core.c: At top level:
qapi/qapi-visit-core.c:39: error: expected declaration specifiers or ‘...’ 
before ‘Error’
qapi/qapi-visit-core.c: In function ‘visit_end_struct’:
qapi/qapi-visit-core.c:41: error: ‘errp’ undeclared (first use in this function)
qapi/qapi-visit-core.c:42: error: too many arguments to function ‘v-end_struct’
qapi/qapi-visit-core.c: At top level:
qapi/qapi-visit-core.c:46: error: expected declaration specifiers or ‘...’ 
before ‘Error’

Re: [Qemu-devel] [PATCH v2 04/23] memory: merge adjacent segments of a single memory region

2011-07-26 Thread Paolo Bonzini

On 07/26/2011 01:26 PM, Avi Kivity wrote:

+while (i  view-nr) {
+j = i + 1;
+while (j  view-nr
+can_merge(view-ranges[j-1], view-ranges[j])) {
+view-ranges[i].addr.size += view-ranges[j].addr.size;
+++j;
+}
+++i;


if (j != i) {


+memmove(view-ranges[i], view-ranges[j],
+(view-nr - j) * sizeof(view-ranges[j]));
+view-nr -= j - i;
+}


}


Paolo



Re: [Qemu-devel] [PATCH v2 04/23] memory: merge adjacent segments of a single memory region

2011-07-26 Thread Avi Kivity

On 07/26/2011 02:36 PM, Paolo Bonzini wrote:

On 07/26/2011 01:26 PM, Avi Kivity wrote:

+while (i  view-nr) {
+j = i + 1;
+while (j  view-nr
+  can_merge(view-ranges[j-1], view-ranges[j])) {
+view-ranges[i].addr.size += view-ranges[j].addr.size;
+++j;
+}
+++i;


if (j != i) {


+memmove(view-ranges[i], view-ranges[j],
+(view-nr - j) * sizeof(view-ranges[j]));
+view-nr -= j - i;
+}


}


Seems to work both ways?

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




Re: [Qemu-devel] [PATCH 14/23] memory: transaction API

2011-07-26 Thread Avi Kivity

On 07/26/2011 01:48 PM, Avi Kivity wrote:

On 07/25/2011 10:16 PM, Anthony Liguori wrote:

On 07/25/2011 09:02 AM, Avi Kivity wrote:

Allow changes to the memory hierarchy to be accumulated and
made visible all at once.  This reduces computational effort,
especially when an accelerator (e.g. kvm) is involved.

Useful when a single register update causes multiple changes
to an address space.

Signed-off-by: Avi Kivitya...@redhat.com


What's the motivation for this?  Was this just because it seemed neat 
to do or did you run into a performance issue you were trying to solve?


Both cirrus and 440fx need this; look at 
i440fx_update_memory_mappings() for example, it blindly updates 
mappings even for PAMs which haven't changed.


These issues can be also solved by more care on the caller's side, or 
by making the API richer, but it's good to have a no-thought-required 
solution, particularly as it's so easy to do.




I should note that updating the memory map is relatively slow with kvm 
due to the need to wait for an rcu grace period; though recent kernels 
are faster.  So any saving here has a large effect.


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




[Qemu-devel] [PATCH v2 15/23] exec.c: initialize memory map

2011-07-26 Thread Avi Kivity
Allocate the root memory region and initialize it.

Signed-off-by: Avi Kivity a...@redhat.com
---
 exec.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/exec.c b/exec.c
index 2160ded..d51502f 100644
--- a/exec.c
+++ b/exec.c
@@ -33,6 +33,8 @@
 #include kvm.h
 #include hw/xen.h
 #include qemu-timer.h
+#include memory.h
+#include exec-memory.h
 #if defined(CONFIG_USER_ONLY)
 #include qemu.h
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
@@ -109,6 +111,9 @@ int phys_ram_fd;
 static int in_migration;
 
 RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER(ram_list) };
+
+static MemoryRegion *system_memory;
+
 #endif
 
 CPUState *first_cpu;
@@ -197,6 +202,7 @@ typedef struct PhysPageDesc {
 static void *l1_phys_map[P_L1_SIZE];
 
 static void io_mem_init(void);
+static void memory_map_init(void);
 
 /* io memory support */
 CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4];
@@ -571,6 +577,7 @@ void cpu_exec_init_all(unsigned long tb_size)
 code_gen_ptr = code_gen_buffer;
 page_init();
 #if !defined(CONFIG_USER_ONLY)
+memory_map_init();
 io_mem_init();
 #endif
 #if !defined(CONFIG_USER_ONLY) || !defined(CONFIG_USE_GUEST_BASE)
@@ -3807,6 +3814,18 @@ static void io_mem_init(void)
   DEVICE_NATIVE_ENDIAN);
 }
 
+static void memory_map_init(void)
+{
+system_memory = qemu_malloc(sizeof(*system_memory));
+memory_region_init(system_memory, system, UINT64_MAX);
+set_system_memory_map(system_memory);
+}
+
+MemoryRegion *get_system_memory(void)
+{
+return system_memory;
+}
+
 #endif /* !defined(CONFIG_USER_ONLY) */
 
 /* physical memory access (slow version, mainly for debug) */
-- 
1.7.5.3




[Qemu-devel] [PATCH 00/10] block: Coroutine support

2011-07-26 Thread Kevin Wolf
Depends on Stefan's latest coroutine patches. This series makes qcow and qcow2
take advantage of the new coroutine infrastructure. Both formats used
synchronous operations for accessing their metadata and blocked the guest CPU
during that time. With coroutines, the I/O will happen asynchronously in the
background and the CPU won't be blocked any more.

Kevin Wolf (10):
  block: Add bdrv_co_readv/writev
  block: Emulate AIO functions with bdrv_co_readv/writev
  block: Add bdrv_co_readv/writev emulation
  coroutines: Locks
  qcow2: Use coroutines
  qcow: Use coroutines
  async: Remove AsyncContext
  coroutines: Use one global bottom half for CoQueue
  posix-aio-compat: Allow read after EOF
  block: Use bdrv_co_* instead of synchronous versions in coroutines

 Makefile.objs |4 +-
 async.c   |   98 ++-
 block.c   |  271 ++--
 block.h   |5 +
 block/qcow.c  |  180 +++-
 block/qcow2-cluster.c |   26 ++---
 block/qcow2.c |  240 
 block/qcow2.h |5 +-
 block/qed-table.c |   14 ---
 block/qed.c   |4 -
 block_int.h   |6 +
 linux-aio.c   |   43 +---
 posix-aio-compat.c|   30 --
 qemu-common.h |4 -
 qemu-coroutine-int.h  |1 +
 qemu-coroutine-lock.c |  117 +
 qemu-coroutine.h  |   64 
 trace-events  |   11 ++
 18 files changed, 659 insertions(+), 464 deletions(-)
 create mode 100644 qemu-coroutine-lock.c

-- 
1.7.6




[Qemu-devel] [PATCH 02/10] block: Emulate AIO functions with bdrv_co_readv/writev

2011-07-26 Thread Kevin Wolf
Use the bdrv_co_readv/writev callbacks to implement bdrv_aio_readv/writev and
bdrv_read/write if a driver provides the coroutine version instead of the
synchronous or AIO version.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c |   98 ++-
 1 files changed, 97 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index e1259ee..48413ae 100644
--- a/block.c
+++ b/block.c
@@ -28,6 +28,7 @@
 #include block_int.h
 #include module.h
 #include qemu-objects.h
+#include qemu-coroutine.h
 
 #ifdef CONFIG_BSD
 #include sys/types.h
@@ -57,6 +58,12 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t 
sector_num,
 uint8_t *buf, int nb_sectors);
 static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
  const uint8_t *buf, int nb_sectors);
+static BlockDriverAIOCB *bdrv_co_aio_readv_em(BlockDriverState *bs,
+int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
+BlockDriverCompletionFunc *cb, void *opaque);
+static BlockDriverAIOCB *bdrv_co_aio_writev_em(BlockDriverState *bs,
+int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
+BlockDriverCompletionFunc *cb, void *opaque);
 
 static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
 QTAILQ_HEAD_INITIALIZER(bdrv_states);
@@ -169,7 +176,13 @@ void path_combine(char *dest, int dest_size,
 
 void bdrv_register(BlockDriver *bdrv)
 {
-if (!bdrv-bdrv_aio_readv) {
+if (bdrv-bdrv_co_readv) {
+/* Emulate AIO by coroutines, and sync by AIO */
+bdrv-bdrv_aio_readv = bdrv_co_aio_readv_em;
+bdrv-bdrv_aio_writev = bdrv_co_aio_writev_em;
+bdrv-bdrv_read = bdrv_read_em;
+bdrv-bdrv_write = bdrv_write_em;
+ } else if (!bdrv-bdrv_aio_readv) {
 /* add AIO emulation layer */
 bdrv-bdrv_aio_readv = bdrv_aio_readv_em;
 bdrv-bdrv_aio_writev = bdrv_aio_writev_em;
@@ -2626,6 +2639,89 @@ static BlockDriverAIOCB 
*bdrv_aio_writev_em(BlockDriverState *bs,
 return bdrv_aio_rw_vector(bs, sector_num, qiov, nb_sectors, cb, opaque, 1);
 }
 
+
+typedef struct BlockDriverAIOCBCoroutine {
+BlockDriverAIOCB common;
+BlockRequest req;
+bool is_write;
+QEMUBH* bh;
+} BlockDriverAIOCBCoroutine;
+
+static void bdrv_aio_co_cancel_em(BlockDriverAIOCB *blockacb)
+{
+qemu_aio_flush();
+}
+
+static AIOPool bdrv_em_co_aio_pool = {
+.aiocb_size = sizeof(BlockDriverAIOCBCoroutine),
+.cancel = bdrv_aio_co_cancel_em,
+};
+
+static void bdrv_co_rw_bh(void *opaque)
+{
+BlockDriverAIOCBCoroutine *acb = opaque;
+
+acb-common.cb(acb-common.opaque, acb-req.error);
+qemu_bh_delete(acb-bh);
+qemu_aio_release(acb);
+}
+
+static void coroutine_fn bdrv_co_rw(void *opaque)
+{
+BlockDriverAIOCBCoroutine *acb = opaque;
+BlockDriverState *bs = acb-common.bs;
+
+if (!acb-is_write) {
+acb-req.error = bs-drv-bdrv_co_readv(bs, acb-req.sector,
+acb-req.nb_sectors, acb-req.qiov);
+} else {
+acb-req.error = bs-drv-bdrv_co_writev(bs, acb-req.sector,
+acb-req.nb_sectors, acb-req.qiov);
+}
+
+acb-bh = qemu_bh_new(bdrv_co_rw_bh, acb);
+qemu_bh_schedule(acb-bh);
+}
+
+static BlockDriverAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs,
+   int64_t sector_num,
+   QEMUIOVector *qiov,
+   int nb_sectors,
+   BlockDriverCompletionFunc *cb,
+   void *opaque,
+   bool is_write)
+{
+Coroutine *co;
+BlockDriverAIOCBCoroutine *acb;
+
+acb = qemu_aio_get(bdrv_em_co_aio_pool, bs, cb, opaque);
+acb-req.sector = sector_num;
+acb-req.nb_sectors = nb_sectors;
+acb-req.qiov = qiov;
+acb-is_write = is_write;
+
+co = qemu_coroutine_create(bdrv_co_rw);
+qemu_coroutine_enter(co, acb);
+
+return acb-common;
+}
+
+static BlockDriverAIOCB *bdrv_co_aio_readv_em(BlockDriverState *bs,
+int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
+BlockDriverCompletionFunc *cb, void *opaque)
+{
+return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors, cb, opaque,
+ false);
+}
+
+static BlockDriverAIOCB *bdrv_co_aio_writev_em(BlockDriverState *bs,
+int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
+BlockDriverCompletionFunc *cb, void *opaque)
+{
+return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors, cb, opaque,
+ true);
+}
+
 static BlockDriverAIOCB *bdrv_aio_flush_em(BlockDriverState *bs,
 BlockDriverCompletionFunc *cb, void *opaque)
 {
-- 
1.7.6




[Qemu-devel] [PATCH 08/10] coroutines: Use one global bottom half for CoQueue

2011-07-26 Thread Kevin Wolf
Now that AsyncContexts don't exist any more, we can use one global bottom half
for restarting coroutines instead of allocating a new one every time (before
removing AsyncContexts, the problem with having a global BH was that it had to
belong to a single AsyncContexts and wouldn't be executed in a different one -
which leads to deadlocks)

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 qemu-coroutine-lock.c |   19 ++-
 1 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c
index abaa1f7..a80f437 100644
--- a/qemu-coroutine-lock.c
+++ b/qemu-coroutine-lock.c
@@ -30,14 +30,10 @@
 
 static QTAILQ_HEAD(, Coroutine) unlock_bh_queue =
 QTAILQ_HEAD_INITIALIZER(unlock_bh_queue);
-
-struct unlock_bh {
-QEMUBH *bh;
-};
+static QEMUBH* unlock_bh;
 
 static void qemu_co_queue_next_bh(void *opaque)
 {
-struct unlock_bh *unlock_bh = opaque;
 Coroutine *next;
 
 trace_qemu_co_queue_next_bh();
@@ -45,14 +41,15 @@ static void qemu_co_queue_next_bh(void *opaque)
 QTAILQ_REMOVE(unlock_bh_queue, next, co_queue_next);
 qemu_coroutine_enter(next, NULL);
 }
-
-qemu_bh_delete(unlock_bh-bh);
-qemu_free(unlock_bh);
 }
 
 void qemu_co_queue_init(CoQueue *queue)
 {
 QTAILQ_INIT(queue-entries);
+
+if (!unlock_bh) {
+unlock_bh = qemu_bh_new(qemu_co_queue_next_bh, NULL);
+}
 }
 
 void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
@@ -65,7 +62,6 @@ void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
 
 bool qemu_co_queue_next(CoQueue *queue)
 {
-struct unlock_bh *unlock_bh;
 Coroutine *next;
 
 next = QTAILQ_FIRST(queue-entries);
@@ -73,10 +69,7 @@ bool qemu_co_queue_next(CoQueue *queue)
 QTAILQ_REMOVE(queue-entries, next, co_queue_next);
 QTAILQ_INSERT_TAIL(unlock_bh_queue, next, co_queue_next);
 trace_qemu_co_queue_next(next);
-
-unlock_bh = qemu_malloc(sizeof(*unlock_bh));
-unlock_bh-bh = qemu_bh_new(qemu_co_queue_next_bh, unlock_bh);
-qemu_bh_schedule(unlock_bh-bh);
+qemu_bh_schedule(unlock_bh);
 }
 
 return (next != NULL);
-- 
1.7.6




[Qemu-devel] [PATCH 07/10] async: Remove AsyncContext

2011-07-26 Thread Kevin Wolf
The purpose of AsyncContexts was to protect qcow and qcow2 against reentrancy
during an emulated bdrv_read/write (which includes a qemu_aio_wait() call and
can run AIO callbacks of different requests if it weren't for AsyncContexts).

Now both qcow and qcow2 are protected by CoMutexes and AsyncContexts can be
removed.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 async.c|   98 
 block.c|6 ---
 block/qed-table.c  |   14 ---
 block/qed.c|4 --
 linux-aio.c|   43 ++
 posix-aio-compat.c |   11 --
 qemu-common.h  |4 --
 7 files changed, 11 insertions(+), 169 deletions(-)

diff --git a/async.c b/async.c
index fd313df..3fe70b9 100644
--- a/async.c
+++ b/async.c
@@ -25,92 +25,8 @@
 #include qemu-common.h
 #include qemu-aio.h
 
-/*
- * An AsyncContext protects the callbacks of AIO requests and Bottom Halves
- * against interfering with each other. A typical example is qcow2 that accepts
- * asynchronous requests, but relies for manipulation of its metadata on
- * synchronous bdrv_read/write that doesn't trigger any callbacks.
- *
- * However, these functions are often emulated using AIO which means that AIO
- * callbacks must be run - but at the same time we must not run callbacks of
- * other requests as they might start to modify metadata and corrupt the
- * internal state of the caller of bdrv_read/write.
- *
- * To achieve the desired semantics we switch into a new AsyncContext.
- * Callbacks must only be run if they belong to the current AsyncContext.
- * Otherwise they need to be queued until their own context is active again.
- * This is how you can make qemu_aio_wait() wait only for your own callbacks.
- *
- * The AsyncContexts form a stack. When you leave a AsyncContexts, you always
- * return to the old (parent) context.
- */
-struct AsyncContext {
-/* Consecutive number of the AsyncContext (position in the stack) */
-int id;
-
-/* Anchor of the list of Bottom Halves belonging to the context */
-struct QEMUBH *first_bh;
-
-/* Link to parent context */
-struct AsyncContext *parent;
-};
-
-/* The currently active AsyncContext */
-static struct AsyncContext *async_context = (struct AsyncContext) { 0 };
-
-/*
- * Enter a new AsyncContext. Already scheduled Bottom Halves and AIO callbacks
- * won't be called until this context is left again.
- */
-void async_context_push(void)
-{
-struct AsyncContext *new = qemu_mallocz(sizeof(*new));
-new-parent = async_context;
-new-id = async_context-id + 1;
-async_context = new;
-}
-
-/* Run queued AIO completions and destroy Bottom Half */
-static void bh_run_aio_completions(void *opaque)
-{
-QEMUBH **bh = opaque;
-qemu_bh_delete(*bh);
-qemu_free(bh);
-qemu_aio_process_queue();
-}
-/*
- * Leave the currently active AsyncContext. All Bottom Halves belonging to the
- * old context are executed before changing the context.
- */
-void async_context_pop(void)
-{
-struct AsyncContext *old = async_context;
-QEMUBH **bh;
-
-/* Flush the bottom halves, we don't want to lose them */
-while (qemu_bh_poll());
-
-/* Switch back to the parent context */
-async_context = async_context-parent;
-qemu_free(old);
-
-if (async_context == NULL) {
-abort();
-}
-
-/* Schedule BH to run any queued AIO completions as soon as possible */
-bh = qemu_malloc(sizeof(*bh));
-*bh = qemu_bh_new(bh_run_aio_completions, bh);
-qemu_bh_schedule(*bh);
-}
-
-/*
- * Returns the ID of the currently active AsyncContext
- */
-int get_async_context_id(void)
-{
-return async_context-id;
-}
+/* Anchor of the list of Bottom Halves belonging to the context */
+static struct QEMUBH *first_bh;
 
 /***/
 /* bottom halves (can be seen as timers which expire ASAP) */
@@ -130,8 +46,8 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
 bh = qemu_mallocz(sizeof(QEMUBH));
 bh-cb = cb;
 bh-opaque = opaque;
-bh-next = async_context-first_bh;
-async_context-first_bh = bh;
+bh-next = first_bh;
+first_bh = bh;
 return bh;
 }
 
@@ -141,7 +57,7 @@ int qemu_bh_poll(void)
 int ret;
 
 ret = 0;
-for (bh = async_context-first_bh; bh; bh = next) {
+for (bh = first_bh; bh; bh = next) {
 next = bh-next;
 if (!bh-deleted  bh-scheduled) {
 bh-scheduled = 0;
@@ -153,7 +69,7 @@ int qemu_bh_poll(void)
 }
 
 /* remove deleted bhs */
-bhp = async_context-first_bh;
+bhp = first_bh;
 while (*bhp) {
 bh = *bhp;
 if (bh-deleted) {
@@ -199,7 +115,7 @@ void qemu_bh_update_timeout(int *timeout)
 {
 QEMUBH *bh;
 
-for (bh = async_context-first_bh; bh; bh = bh-next) {
+for (bh = first_bh; bh; bh = bh-next) {
 if (!bh-deleted  bh-scheduled) {
 if (bh-idle) {
 /* idle bottom halves will be 

[Qemu-devel] [PATCH 01/10] block: Add bdrv_co_readv/writev

2011-07-26 Thread Kevin Wolf
Add new block driver callbacks bdrv_co_readv/writev, which work on a
QEMUIOVector like bdrv_aio_*, but don't need a callback. The function may only
be called inside a coroutine, so a block driver implementing this interface can
yield instead of blocking during I/O.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 Makefile.objs |2 +-
 block.c   |   46 ++
 block.h   |5 +
 block_int.h   |6 ++
 trace-events  |2 ++
 5 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 5679e1f..9549e2a 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -25,6 +25,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o
 
 block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o 
async.o
 block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o 
qemu-sockets.o
+block-obj-y += $(coroutine-obj-y)
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
@@ -79,7 +80,6 @@ common-obj-y += readline.o console.o cursor.o qemu-error.o
 common-obj-y += $(oslib-obj-y)
 common-obj-$(CONFIG_WIN32) += os-win32.o
 common-obj-$(CONFIG_POSIX) += os-posix.o
-common-obj-y += $(coroutine-obj-y)
 
 common-obj-y += tcg-runtime.o host-utils.o
 common-obj-y += irq.o ioport.o input.o
diff --git a/block.c b/block.c
index 9549b9e..e1259ee 100644
--- a/block.c
+++ b/block.c
@@ -1121,6 +1121,52 @@ int bdrv_write_sync(BlockDriverState *bs, int64_t 
sector_num,
 buf, BDRV_SECTOR_SIZE * nb_sectors);
 }
 
+int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
+int nb_sectors, QEMUIOVector *qiov)
+{
+BlockDriver *drv = bs-drv;
+
+trace_bdrv_co_readv(bs, sector_num, nb_sectors);
+
+if (!drv) {
+return -ENOMEDIUM;
+}
+if (bdrv_check_request(bs, sector_num, nb_sectors)) {
+return -EIO;
+}
+
+return drv-bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
+}
+
+int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
+int nb_sectors, QEMUIOVector *qiov)
+{
+BlockDriver *drv = bs-drv;
+
+trace_bdrv_co_writev(bs, sector_num, nb_sectors);
+
+if (!bs-drv) {
+return -ENOMEDIUM;
+}
+if (bs-read_only) {
+return -EACCES;
+}
+if (bdrv_check_request(bs, sector_num, nb_sectors)) {
+return -EIO;
+}
+
+if (bs-dirty_bitmap) {
+set_dirty_bitmap(bs, sector_num, nb_sectors, 1);
+}
+
+if (bs-wr_highest_sector  sector_num + nb_sectors - 1) {
+bs-wr_highest_sector = sector_num + nb_sectors - 1;
+}
+
+return drv-bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
+}
+
+
 /**
  * Truncate file to 'offset' bytes (needed only for file protocols)
  */
diff --git a/block.h b/block.h
index 59cc410..a559459 100644
--- a/block.h
+++ b/block.h
@@ -4,6 +4,7 @@
 #include qemu-aio.h
 #include qemu-common.h
 #include qemu-option.h
+#include qemu-coroutine.h
 #include qobject.h
 
 /* block.c */
@@ -87,6 +88,10 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
 const void *buf, int count);
 int bdrv_write_sync(BlockDriverState *bs, int64_t sector_num,
 const uint8_t *buf, int nb_sectors);
+int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
+int nb_sectors, QEMUIOVector *qiov);
+int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
+int nb_sectors, QEMUIOVector *qiov);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
 int64_t bdrv_getlength(BlockDriverState *bs);
 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
diff --git a/block_int.h b/block_int.h
index efb6803..c868b49 100644
--- a/block_int.h
+++ b/block_int.h
@@ -27,6 +27,7 @@
 #include block.h
 #include qemu-option.h
 #include qemu-queue.h
+#include qemu-coroutine.h
 
 #define BLOCK_FLAG_ENCRYPT 1
 #define BLOCK_FLAG_COMPAT6 4
@@ -77,6 +78,11 @@ struct BlockDriver {
 int (*bdrv_discard)(BlockDriverState *bs, int64_t sector_num,
 int nb_sectors);
 
+int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
+int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
+int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs,
+int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
+
 int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs,
 int num_reqs);
 int (*bdrv_merge_requests)(BlockDriverState *bs, BlockRequest* a,
diff --git a/trace-events b/trace-events
index 136f775..46bceca 100644
--- a/trace-events
+++ b/trace-events
@@ -66,6 +66,8 @@ disable bdrv_aio_flush(void *bs, void *opaque) bs %p opaque 
%p
 disable bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void 
*opaque) bs %p sector_num %PRId64 nb_sectors %d opaque %p
 disable bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void 
*opaque) bs %p sector_num %PRId64 nb_sectors %d opaque %p
 disable bdrv_set_locked(void *bs, int 

Re: [Qemu-devel] [PATCH v2 04/23] memory: merge adjacent segments of a single memory region

2011-07-26 Thread Paolo Bonzini

On 07/26/2011 01:38 PM, Avi Kivity wrote:


if (j != i) {


+memmove(view-ranges[i], view-ranges[j],
+(view-nr - j) * sizeof(view-ranges[j]));
+view-nr -= j - i;
+}


}


Seems to work both ways?


Sure, but you're pointlessly memmove-ing memory over itself.  I'm not 
sure how many segments a single memory region will usually have, but 
it's better to be safe.


Paolo



[Qemu-devel] [PATCH v2 14/23] memory: transaction API

2011-07-26 Thread Avi Kivity
Allow changes to the memory hierarchy to be accumulated and
made visible all at once.  This reduces computational effort,
especially when an accelerator (e.g. kvm) is involved.

Useful when a single register update causes multiple changes
to an address space.

Signed-off-by: Avi Kivity a...@redhat.com
---
 memory.c |   18 ++
 memory.h |8 
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/memory.c b/memory.c
index 7a5670e..5c6e63d 100644
--- a/memory.c
+++ b/memory.c
@@ -18,6 +18,8 @@
 #include kvm.h
 #include assert.h
 
+unsigned memory_region_transaction_depth = 0;
+
 typedef struct AddrRange AddrRange;
 
 struct AddrRange {
@@ -626,6 +628,10 @@ static void address_space_update_topology(AddressSpace *as)
 
 static void memory_region_update_topology(void)
 {
+if (memory_region_transaction_depth) {
+return;
+}
+
 if (address_space_memory.root) {
 address_space_update_topology(address_space_memory);
 }
@@ -634,6 +640,18 @@ static void memory_region_update_topology(void)
 }
 }
 
+void memory_region_transaction_begin(void)
+{
+++memory_region_transaction_depth;
+}
+
+void memory_region_transaction_commit(void)
+{
+assert(memory_region_transaction_depth);
+--memory_region_transaction_depth;
+memory_region_update_topology();
+}
+
 void memory_region_init(MemoryRegion *mr,
 const char *name,
 uint64_t size)
diff --git a/memory.h b/memory.h
index c280a39..4e518b2 100644
--- a/memory.h
+++ b/memory.h
@@ -456,6 +456,14 @@ void memory_region_add_subregion_overlap(MemoryRegion *mr,
 void memory_region_del_subregion(MemoryRegion *mr,
  MemoryRegion *subregion);
 
+/* Start a transaction; changes will be accumulated and made visible only
+ * when the transaction ends.
+ */
+void memory_region_transaction_begin(void);
+/* Commit a transaction and make changes visible to the guest.
+ */
+void memory_region_transaction_commit(void);
+
 #endif
 
 #endif
-- 
1.7.5.3




[Qemu-devel] [PATCH v2 02/23] Hierarchical memory region API

2011-07-26 Thread Avi Kivity
The memory API separates the attributes of a memory region (its size, how
reads or writes are handled, dirty logging, and coalescing) from where it
is mapped and whether it is enabled.  This allows a device to configure
a memory region once, then hand it off to its parent bus to map it according
to the bus configuration.

Hierarchical registration also allows a device to compose a region out of
a number of sub-regions with different properties; for example some may be
RAM while others may be MMIO.

Reviewed-by: Anthony Liguori aligu...@us.ibm.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 Makefile.target |1 +
 memory.c|  653 +++
 memory.h|  385 
 3 files changed, 1039 insertions(+), 0 deletions(-)
 create mode 100644 memory.c
 create mode 100644 memory.h

diff --git a/Makefile.target b/Makefile.target
index cde509b..8884a56 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -198,6 +198,7 @@ obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
 obj-y += rwhandler.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_NO_KVM) += kvm-stub.o
+obj-y += memory.o
 LIBS+=-lz
 
 QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
diff --git a/memory.c b/memory.c
new file mode 100644
index 000..a9cf317
--- /dev/null
+++ b/memory.c
@@ -0,0 +1,653 @@
+/*
+ * Physical memory management
+ *
+ * Copyright 2011 Red Hat, Inc. and/or its affiliates
+ *
+ * Authors:
+ *  Avi Kivity a...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include memory.h
+#include assert.h
+
+typedef struct AddrRange AddrRange;
+
+struct AddrRange {
+uint64_t start;
+uint64_t size;
+};
+
+static AddrRange addrrange_make(uint64_t start, uint64_t size)
+{
+return (AddrRange) { start, size };
+}
+
+static bool addrrange_equal(AddrRange r1, AddrRange r2)
+{
+return r1.start == r2.start  r1.size == r2.size;
+}
+
+static uint64_t addrrange_end(AddrRange r)
+{
+return r.start + r.size;
+}
+
+static AddrRange addrrange_shift(AddrRange range, int64_t delta)
+{
+range.start += delta;
+return range;
+}
+
+static bool addrrange_intersects(AddrRange r1, AddrRange r2)
+{
+return (r1.start = r2.start  r1.start  r2.start + r2.size)
+|| (r2.start = r1.start  r2.start  r1.start + r1.size);
+}
+
+static AddrRange addrrange_intersection(AddrRange r1, AddrRange r2)
+{
+uint64_t start = MAX(r1.start, r2.start);
+/* off-by-one arithmetic to prevent overflow */
+uint64_t end = MIN(addrrange_end(r1) - 1, addrrange_end(r2) - 1);
+return addrrange_make(start, end - start + 1);
+}
+
+struct CoalescedMemoryRange {
+AddrRange addr;
+QTAILQ_ENTRY(CoalescedMemoryRange) link;
+};
+
+typedef struct FlatRange FlatRange;
+typedef struct FlatView FlatView;
+
+/* Range of memory in the global map.  Addresses are absolute. */
+struct FlatRange {
+MemoryRegion *mr;
+target_phys_addr_t offset_in_region;
+AddrRange addr;
+};
+
+/* Flattened global view of current active memory hierarchy.  Kept in sorted
+ * order.
+ */
+struct FlatView {
+FlatRange *ranges;
+unsigned nr;
+unsigned nr_allocated;
+};
+
+#define FOR_EACH_FLAT_RANGE(var, view)  \
+for (var = (view)-ranges; var  (view)-ranges + (view)-nr; ++var)
+
+static FlatView current_memory_map;
+static MemoryRegion *root_memory_region;
+
+static bool flatrange_equal(FlatRange *a, FlatRange *b)
+{
+return a-mr == b-mr
+ addrrange_equal(a-addr, b-addr)
+ a-offset_in_region == b-offset_in_region;
+}
+
+static void flatview_init(FlatView *view)
+{
+view-ranges = NULL;
+view-nr = 0;
+view-nr_allocated = 0;
+}
+
+/* Insert a range into a given position.  Caller is responsible for maintaining
+ * sorting order.
+ */
+static void flatview_insert(FlatView *view, unsigned pos, FlatRange *range)
+{
+if (view-nr == view-nr_allocated) {
+view-nr_allocated = MAX(2 * view-nr, 10);
+view-ranges = qemu_realloc(view-ranges,
+view-nr_allocated * 
sizeof(*view-ranges));
+}
+memmove(view-ranges + pos + 1, view-ranges + pos,
+(view-nr - pos) * sizeof(FlatRange));
+view-ranges[pos] = *range;
+++view-nr;
+}
+
+static void flatview_destroy(FlatView *view)
+{
+qemu_free(view-ranges);
+}
+
+/* Render a memory region into the global view.  Ranges in @view obscure
+ * ranges in @mr.
+ */
+static void render_memory_region(FlatView *view,
+ MemoryRegion *mr,
+ target_phys_addr_t base,
+ AddrRange clip)
+{
+MemoryRegion *subregion;
+unsigned i;
+target_phys_addr_t offset_in_region;
+uint64_t remain;
+uint64_t now;
+FlatRange fr;
+AddrRange tmp;
+
+base += mr-addr;
+
+tmp = addrrange_make(base, mr-size);
+
+if 

Re: [Qemu-devel] [PATCH 12/55] ide: Fix ATA command READ to set ATAPI signature for CD-ROM

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:46PM +0200, Markus Armbruster wrote:
 Must set the ATAPI device signature, see ACS-2 7.36.6 Outputs for
 PACKET feature set devices.

Odd but true, even if it's 7.38.2 in my local copy of the ACS spec.

It defintively should be documented in a comment next to the code,
given how odd the behaviour is.




Re: [Qemu-devel] [PATCH 13/55] ide: Use a table to declare which drive kinds accept each command

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:47PM +0200, Markus Armbruster wrote:
 No functional change.
 
 It would be nice to have handler functions in the table, like commit
 e1a064f9 did for ATAPI.  Left for another day.

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 14/55] ide: Reject ATA commands specific to drive kinds

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:48PM +0200, Markus Armbruster wrote:
 ACS-2 Table B.2 explicitly prohibits ATAPI devices from implementing
 WIN_RECAL, WIN_READ_EXT, WIN_READDMA_EXT, WIN_READ_NATIVE_MAX,
 WIN_MULTREAD_EXT, WIN_WRITE, WIN_WRITE_ONCE, WIN_WRITE_EXT,
 WIN_WRITEDMA_EXT, WIN_MULTWRITE_EXT, WIN_WRITE_VERIFY, WIN_VERIFY,
 WIN_VERIFY_ONCE, WIN_VERIFY_EXT, WIN_SPECIFY, WIN_MULTREAD,
 WIN_MULTWRITE, WIN_SETMULT, WIN_READDMA, WIN_READDMA_ONCE,
 WIN_WRITEDMA, WIN_WRITEDMA_ONCE, WIN_FLUSH_CACHE_EXT.  Restrict them
 to IDE_HD and IDE_CFATA.
 
 Same for CFA_WRITE_SECT_WO_ERASE, CFA_WRITE_MULTI_WO_ERASE.  Restrict
 them to IDE_CFATA, like the other CFA_ commands.

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de



Re: [Qemu-devel] [PATCH 15/55] ide/atapi: Clean up misleading name in cmd_start_stop_unit()

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:49PM +0200, Markus Armbruster wrote:
 eject is misleading; it means eject when start is clear, but
 load when start is set.  Rename to loej, because that's how MMC-5
 calls it, in section 6.40.

Just as clear as the bdrv_eject name :)

Looks fine anyway,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 0/3] Add PL111, implement PL110 BGR mode

2011-07-26 Thread Francis Moreau
On Tue, Jul 26, 2011 at 12:12 PM, Peter Maydell
peter.mayd...@linaro.org wrote:
 On 22 July 2011 16:59, Peter Maydell peter.mayd...@linaro.org wrote:
 This patch series improves the emulation of the PL11x CLCD
 controllers used by the various ARM dev boards.

 versatilepb has a PL110 but it also has an external mux controlled
 by a system register which allows the OS to select whether the
 16 bit graphics format should be 5551, RGB565 or BGR565.

 In particular, Linux kernels 2.6.39 and above default to programming
 the versatilepb for BGR565, so we need to support the mux control
 rather than always assuming RGB565.

 This issue was originally reported on IRC by Francis Moreau,
 who has now kindly tested these patches and tells me that they
 do indeed fix the issues he was seeing.

Yes I confirm.
-- 
Francis



Re: [Qemu-devel] [PATCH 16/55] ide/atapi: Track tray open/close state

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:50PM +0200, Markus Armbruster wrote:
 We already track it in BlockDriverState since commit 4be9762a.  As
 discussed in that commit's message, we should track it in the device
 device models instead, because it's device state.

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de



Re: [Qemu-devel] [PATCH 17/55] ide/atapi: Switch from BlockDriverState's tray_open to own

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:51PM +0200, Markus Armbruster wrote:
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good, although I would have folded this patch into the previous
one.

Reviewed-by: Christoph Hellwig h...@lst.de



[Qemu-devel] [PATCH 03/10] block: Add bdrv_co_readv/writev emulation

2011-07-26 Thread Kevin Wolf
In order to be able to call bdrv_co_readv/writev for drivers that don't
implement the functions natively, add an emulation that uses the AIO functions
to implement them.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block.c  |   84 -
 trace-events |1 +
 2 files changed, 77 insertions(+), 8 deletions(-)

diff --git a/block.c b/block.c
index 48413ae..2f589ac 100644
--- a/block.c
+++ b/block.c
@@ -64,6 +64,12 @@ static BlockDriverAIOCB 
*bdrv_co_aio_readv_em(BlockDriverState *bs,
 static BlockDriverAIOCB *bdrv_co_aio_writev_em(BlockDriverState *bs,
 int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
 BlockDriverCompletionFunc *cb, void *opaque);
+static int coroutine_fn bdrv_co_readv_em(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors,
+ QEMUIOVector *iov);
+static int coroutine_fn bdrv_co_writev_em(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors,
+ QEMUIOVector *iov);
 
 static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
 QTAILQ_HEAD_INITIALIZER(bdrv_states);
@@ -182,14 +188,19 @@ void bdrv_register(BlockDriver *bdrv)
 bdrv-bdrv_aio_writev = bdrv_co_aio_writev_em;
 bdrv-bdrv_read = bdrv_read_em;
 bdrv-bdrv_write = bdrv_write_em;
- } else if (!bdrv-bdrv_aio_readv) {
-/* add AIO emulation layer */
-bdrv-bdrv_aio_readv = bdrv_aio_readv_em;
-bdrv-bdrv_aio_writev = bdrv_aio_writev_em;
-} else if (!bdrv-bdrv_read) {
-/* add synchronous IO emulation layer */
-bdrv-bdrv_read = bdrv_read_em;
-bdrv-bdrv_write = bdrv_write_em;
+ } else {
+bdrv-bdrv_co_readv = bdrv_co_readv_em;
+bdrv-bdrv_co_writev = bdrv_co_writev_em;
+
+if (!bdrv-bdrv_aio_readv) {
+/* add AIO emulation layer */
+bdrv-bdrv_aio_readv = bdrv_aio_readv_em;
+bdrv-bdrv_aio_writev = bdrv_aio_writev_em;
+} else if (!bdrv-bdrv_read) {
+/* add synchronous IO emulation layer */
+bdrv-bdrv_read = bdrv_read_em;
+bdrv-bdrv_write = bdrv_write_em;
+}
 }
 
 if (!bdrv-bdrv_aio_flush)
@@ -2868,6 +2879,63 @@ void qemu_aio_release(void *p)
 }
 
 /**/
+/* Coroutine block device emulation */
+
+typedef struct CoroutineIOCompletion {
+Coroutine *coroutine;
+int ret;
+} CoroutineIOCompletion;
+
+static void bdrv_co_io_em_complete(void *opaque, int ret)
+{
+CoroutineIOCompletion *co = opaque;
+
+co-ret = ret;
+qemu_coroutine_enter(co-coroutine, NULL);
+}
+
+static int coroutine_fn bdrv_co_io_em(BlockDriverState *bs, int64_t sector_num,
+  int nb_sectors, QEMUIOVector *iov,
+  bool is_write)
+{
+CoroutineIOCompletion co = {
+.coroutine = qemu_coroutine_self(),
+.ret = -EINPROGRESS,
+};
+BlockDriverAIOCB *acb;
+
+if (is_write) {
+acb = bdrv_aio_writev(bs, sector_num, iov, nb_sectors,
+  bdrv_co_io_em_complete, co);
+} else {
+acb = bdrv_aio_readv(bs, sector_num, iov, nb_sectors,
+ bdrv_co_io_em_complete, co);
+}
+
+trace_bdrv_co_io(is_write, acb);
+if (!acb) {
+return -EIO;
+}
+qemu_coroutine_yield();
+
+return co.ret;
+}
+
+static int coroutine_fn bdrv_co_readv_em(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors,
+ QEMUIOVector *iov)
+{
+return bdrv_co_io_em(bs, sector_num, nb_sectors, iov, false);
+}
+
+static int coroutine_fn bdrv_co_writev_em(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors,
+ QEMUIOVector *iov)
+{
+return bdrv_co_io_em(bs, sector_num, nb_sectors, iov, true);
+}
+
+/**/
 /* removable device support */
 
 /**
diff --git a/trace-events b/trace-events
index 46bceca..bc9be30 100644
--- a/trace-events
+++ b/trace-events
@@ -68,6 +68,7 @@ disable bdrv_aio_writev(void *bs, int64_t sector_num, int 
nb_sectors, void *opaq
 disable bdrv_set_locked(void *bs, int locked) bs %p locked %d
 disable bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) bs %p 
sector_num %PRId64 nb_sectors %d
 disable bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) bs %p 
sector_num %PRId64 nb_sectors %d
+disable bdrv_co_io(int is_write, void *acb) is_write %d acb %p
 
 # hw/virtio-blk.c
 disable virtio_blk_req_complete(void *req, int status) req %p status %d
-- 
1.7.6




[Qemu-devel] [PATCH v2 10/23] memory: add backward compatibility for old portio registration

2011-07-26 Thread Avi Kivity
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 memory.c |   32 
 memory.h |   17 +
 2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/memory.c b/memory.c
index df0ed0e..5f2c9ef 100644
--- a/memory.c
+++ b/memory.c
@@ -218,6 +218,21 @@ static AddressSpace address_space_memory = {
 .ops = address_space_ops_memory,
 };
 
+static const MemoryRegionPortio *find_portio(MemoryRegion *mr, uint64_t offset,
+ unsigned width, bool write)
+{
+const MemoryRegionPortio *mrp;
+
+for (mrp = mr-ops-old_portio; mrp-size; ++mrp) {
+if (offset = mrp-offset  offset  mrp-offset + mrp-len
+ width == mrp-size
+ (write ? (bool)mrp-write : (bool)mrp-read)) {
+return mrp;
+}
+}
+return NULL;
+}
+
 static void memory_region_iorange_read(IORange *iorange,
uint64_t offset,
unsigned width,
@@ -225,6 +240,15 @@ static void memory_region_iorange_read(IORange *iorange,
 {
 MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange);
 
+if (mr-ops-old_portio) {
+const MemoryRegionPortio *mrp = find_portio(mr, offset, width, false);
+
+*data = ((uint64_t)1  (width * 8)) - 1;
+if (mrp) {
+*data = mrp-read(mr-opaque, offset - mrp-offset);
+}
+return;
+}
 *data = mr-ops-read(mr-opaque, offset, width);
 }
 
@@ -235,6 +259,14 @@ static void memory_region_iorange_write(IORange *iorange,
 {
 MemoryRegion *mr = container_of(iorange, MemoryRegion, iorange);
 
+if (mr-ops-old_portio) {
+const MemoryRegionPortio *mrp = find_portio(mr, offset, width, true);
+
+if (mrp) {
+mrp-write(mr-opaque, offset - mrp-offset, data);
+}
+return;
+}
 mr-ops-write(mr-opaque, offset, data, width);
 }
 
diff --git a/memory.h b/memory.h
index 88ba428..40ab95a 100644
--- a/memory.h
+++ b/memory.h
@@ -23,9 +23,11 @@
 #include targphys.h
 #include qemu-queue.h
 #include iorange.h
+#include ioport.h
 
 typedef struct MemoryRegionOps MemoryRegionOps;
 typedef struct MemoryRegion MemoryRegion;
+typedef struct MemoryRegionPortio MemoryRegionPortio;
 
 /* Must match *_DIRTY_FLAGS in cpu-all.h.  To be replaced with dynamic
  * registration.
@@ -78,6 +80,11 @@ struct MemoryRegionOps {
  */
  bool unaligned;
 } impl;
+
+/* If .read and .write are not present, old_portio may be used for
+ * backwards compatibility with old portio registration
+ */
+const MemoryRegionPortio *old_portio;
 };
 
 typedef struct CoalescedMemoryRange CoalescedMemoryRange;
@@ -105,6 +112,16 @@ struct MemoryRegion {
 uint8_t dirty_log_mask;
 };
 
+struct MemoryRegionPortio {
+uint32_t offset;
+uint32_t len;
+unsigned size;
+IOPortReadFunc *read;
+IOPortWriteFunc *write;
+};
+
+#define PORTIO_END { }
+
 /**
  * memory_region_init: Initialize a memory region
  *
-- 
1.7.5.3




Re: [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:52PM +0200, Markus Armbruster wrote:
 Use a table to declare which drive kinds accept each command.
 
 Limit READ_CAPACITY, READ_TOC, GET_CONFIGURATION to SCSI_CD, as per
 SPC-4.

READ CAPACITY is defined in SBC, and absolutely required for proper
operation with disks.




Re: [Qemu-devel] [PATCH 19/55] scsi-disk: Factor out scsi_disk_emulate_start_stop()

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:53PM +0200, Markus Armbruster wrote:
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,


Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 20/55] scsi-disk: Track tray open/close state

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:54PM +0200, Markus Armbruster wrote:
 We already track it in BlockDriverState since commit 4be9762a.  As
 discussed in that commit's message, we should track it in the device
 device models instead, because it's device state.

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




[Qemu-devel] [PATCH v2 08/23] memory: late initialization of ram_addr

2011-07-26 Thread Avi Kivity
For non-RAM memory regions, we cannot tell whether this is an I/O region
or an MMIO region.  Since the qemu backing registration is different for
the two, we have to defer initialization until we know which address
space we are in.

These shenanigans will be removed once the backing registration is unified
with the memory API.

Signed-off-by: Avi Kivity a...@redhat.com
---
 memory.c |   24 
 memory.h |1 +
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/memory.c b/memory.c
index 9e1a838..e839c9e 100644
--- a/memory.c
+++ b/memory.c
@@ -165,10 +165,14 @@ static void flatview_simplify(FlatView *view)
 }
 }
 
+static void memory_region_prepare_ram_addr(MemoryRegion *mr);
+
 static void as_memory_range_add(AddressSpace *as, FlatRange *fr)
 {
 ram_addr_t phys_offset, region_offset;
 
+memory_region_prepare_ram_addr(fr-mr);
+
 phys_offset = fr-mr-ram_addr;
 region_offset = fr-offset_in_region;
 /* cpu_register_physical_memory_log() wants region_offset for
@@ -519,6 +523,19 @@ static CPUWriteMemoryFunc * const 
memory_region_write_thunk[] = {
 memory_region_write_thunk_l,
 };
 
+static void memory_region_prepare_ram_addr(MemoryRegion *mr)
+{
+if (mr-backend_registered) {
+return;
+}
+
+mr-ram_addr = cpu_register_io_memory(memory_region_read_thunk,
+  memory_region_write_thunk,
+  mr,
+  mr-ops-endianness);
+mr-backend_registered = true;
+}
+
 void memory_region_init_io(MemoryRegion *mr,
const MemoryRegionOps *ops,
void *opaque,
@@ -529,10 +546,7 @@ void memory_region_init_io(MemoryRegion *mr,
 mr-ops = ops;
 mr-opaque = opaque;
 mr-terminates = true;
-mr-ram_addr = cpu_register_io_memory(memory_region_read_thunk,
-  memory_region_write_thunk,
-  mr,
-  mr-ops-endianness);
+mr-backend_registered = false;
 }
 
 void memory_region_init_ram(MemoryRegion *mr,
@@ -543,6 +557,7 @@ void memory_region_init_ram(MemoryRegion *mr,
 memory_region_init(mr, name, size);
 mr-terminates = true;
 mr-ram_addr = qemu_ram_alloc(dev, name, size);
+mr-backend_registered = true;
 }
 
 void memory_region_init_ram_ptr(MemoryRegion *mr,
@@ -554,6 +569,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr,
 memory_region_init(mr, name, size);
 mr-terminates = true;
 mr-ram_addr = qemu_ram_alloc_from_ptr(dev, name, size, ptr);
+mr-backend_registered = true;
 }
 
 void memory_region_init_alias(MemoryRegion *mr,
diff --git a/memory.h b/memory.h
index 47d6b9d..c481038 100644
--- a/memory.h
+++ b/memory.h
@@ -89,6 +89,7 @@ struct MemoryRegion {
 uint64_t size;
 target_phys_addr_t addr;
 target_phys_addr_t offset;
+bool backend_registered;
 ram_addr_t ram_addr;
 bool terminates;
 MemoryRegion *alias;
-- 
1.7.5.3




Re: [Qemu-devel] [PATCH v2 04/23] memory: merge adjacent segments of a single memory region

2011-07-26 Thread Avi Kivity

On 07/26/2011 02:51 PM, Paolo Bonzini wrote:

On 07/26/2011 01:38 PM, Avi Kivity wrote:


if (j != i) {


+memmove(view-ranges[i], view-ranges[j],
+(view-nr - j) * sizeof(view-ranges[j]));
+view-nr -= j - i;
+}


}


Seems to work both ways?


Sure, but you're pointlessly memmove-ing memory over itself.  I'm not 
sure how many segments a single memory region will usually have, but 
it's better to be safe.


This will never be an issue in practice.  We expect to have few 
FlatRanges (O(100)), simplify() will be called very rarely (never during 
normal operations; a few dozen times during boot; a few during hotplug); 
everything is in L1 cache; and the cost will be dwarfed by any calls to 
kvm (if enabled).


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




[Qemu-devel] [PATCH v2 22/23] sysbus: add MemoryRegion based memory management API

2011-07-26 Thread Avi Kivity
Allow registering sysbus device memory using a MemoryRegion.  Once all users
are converted, sysbus_init_mmio() and sysbus_init_mmio_cb() will be removed.

Reviewed-by: Anthony Liguori aligu...@us.ibm.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 hw/sysbus.c |   27 ---
 hw/sysbus.h |3 +++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/hw/sysbus.c b/hw/sysbus.c
index 2e22be7..ea442ac 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -19,6 +19,7 @@
 
 #include sysbus.h
 #include monitor.h
+#include exec-memory.h
 
 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static char *sysbus_get_fw_dev_path(DeviceState *dev);
@@ -49,11 +50,20 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, 
target_phys_addr_t addr)
 }
 if (dev-mmio[n].addr != (target_phys_addr_t)-1) {
 /* Unregister previous mapping.  */
-cpu_register_physical_memory(dev-mmio[n].addr, dev-mmio[n].size,
- IO_MEM_UNASSIGNED);
+if (dev-mmio[n].memory) {
+memory_region_del_subregion(get_system_memory(),
+dev-mmio[n].memory);
+} else {
+cpu_register_physical_memory(dev-mmio[n].addr, dev-mmio[n].size,
+ IO_MEM_UNASSIGNED);
+}
 }
 dev-mmio[n].addr = addr;
-if (dev-mmio[n].cb) {
+if (dev-mmio[n].memory) {
+memory_region_add_subregion(get_system_memory(),
+addr,
+dev-mmio[n].memory);
+} else if (dev-mmio[n].cb) {
 dev-mmio[n].cb(dev, addr);
 } else {
 cpu_register_physical_memory(addr, dev-mmio[n].size,
@@ -107,6 +117,17 @@ void sysbus_init_mmio_cb(SysBusDevice *dev, 
target_phys_addr_t size,
 dev-mmio[n].cb = cb;
 }
 
+void sysbus_init_mmio_region(SysBusDevice *dev, MemoryRegion *memory)
+{
+int n;
+
+assert(dev-num_mmio  QDEV_MAX_MMIO);
+n = dev-num_mmio++;
+dev-mmio[n].addr = -1;
+dev-mmio[n].size = memory_region_size(memory);
+dev-mmio[n].memory = memory;
+}
+
 void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size)
 {
 pio_addr_t i;
diff --git a/hw/sysbus.h b/hw/sysbus.h
index 4e8cb16..5f62e2d 100644
--- a/hw/sysbus.h
+++ b/hw/sysbus.h
@@ -4,6 +4,7 @@
 /* Devices attached directly to the main system bus.  */
 
 #include qdev.h
+#include memory.h
 
 #define QDEV_MAX_MMIO 32
 #define QDEV_MAX_PIO 32
@@ -23,6 +24,7 @@ struct SysBusDevice {
 target_phys_addr_t size;
 mmio_mapfunc cb;
 ram_addr_t iofunc;
+MemoryRegion *memory;
 } mmio[QDEV_MAX_MMIO];
 int num_pio;
 pio_addr_t pio[QDEV_MAX_PIO];
@@ -46,6 +48,7 @@ void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t 
size,
   ram_addr_t iofunc);
 void sysbus_init_mmio_cb(SysBusDevice *dev, target_phys_addr_t size,
 mmio_mapfunc cb);
+void sysbus_init_mmio_region(SysBusDevice *dev, MemoryRegion *memory);
 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
 void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t 
size);
-- 
1.7.5.3




[Qemu-devel] [PATCH v2 18/23] pc: convert pc_memory_init() to memory API

2011-07-26 Thread Avi Kivity
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 hw/pc.c |   59 ---
 hw/pc.h |1 +
 2 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 369566a..1c9d89a 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -41,6 +41,7 @@
 #include sysemu.h
 #include blockdev.h
 #include ui/qemu-spice.h
+#include memory.h
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -966,22 +967,30 @@ void pc_memory_init(MemoryRegion *system_memory,
 {
 char *filename;
 int ret, linux_boot, i;
-ram_addr_t ram_addr, bios_offset, option_rom_offset;
+MemoryRegion *ram, *bios, *isa_bios, *option_rom_mr;
+MemoryRegion *ram_below_4g, *ram_above_4g;
 int bios_size, isa_bios_size;
 void *fw_cfg;
 
 linux_boot = (kernel_filename != NULL);
 
-/* allocate RAM */
-ram_addr = qemu_ram_alloc(NULL, pc.ram,
-  below_4g_mem_size + above_4g_mem_size);
-cpu_register_physical_memory(0, 0xa, ram_addr);
-cpu_register_physical_memory(0x10,
- below_4g_mem_size - 0x10,
- ram_addr + 0x10);
+/* Allocate RAM.  We allocate it as a single memory region and use
+ * aliases to address portions of it, mostly for backwards compatiblity
+ * with older qemus that used qemu_ram_alloc().
+ */
+ram = qemu_malloc(sizeof(*ram));
+memory_region_init_ram(ram, NULL, pc.ram,
+   below_4g_mem_size + above_4g_mem_size);
+ram_below_4g = qemu_malloc(sizeof(*ram_below_4g));
+memory_region_init_alias(ram_below_4g, ram-below-4g, ram,
+ 0, below_4g_mem_size);
+memory_region_add_subregion(system_memory, 0, ram_below_4g);
 if (above_4g_mem_size  0) {
-cpu_register_physical_memory(0x1ULL, above_4g_mem_size,
- ram_addr + below_4g_mem_size);
+ram_above_4g = qemu_malloc(sizeof(*ram_above_4g));
+memory_region_init_alias(ram_above_4g, ram-above-4g, ram,
+ below_4g_mem_size, above_4g_mem_size);
+memory_region_add_subregion(system_memory, 0x1ULL,
+ram_above_4g);
 }
 
 /* BIOS load */
@@ -997,7 +1006,9 @@ void pc_memory_init(MemoryRegion *system_memory,
 (bios_size % 65536) != 0) {
 goto bios_error;
 }
-bios_offset = qemu_ram_alloc(NULL, pc.bios, bios_size);
+bios = qemu_malloc(sizeof(*bios));
+memory_region_init_ram(bios, NULL, pc.bios, bios_size);
+memory_region_set_readonly(bios, true);
 ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
 if (ret != 0) {
 bios_error:
@@ -1011,16 +1022,26 @@ void pc_memory_init(MemoryRegion *system_memory,
 isa_bios_size = bios_size;
 if (isa_bios_size  (128 * 1024))
 isa_bios_size = 128 * 1024;
-cpu_register_physical_memory(0x10 - isa_bios_size,
- isa_bios_size,
- (bios_offset + bios_size - isa_bios_size) | 
IO_MEM_ROM);
-
-option_rom_offset = qemu_ram_alloc(NULL, pc.rom, PC_ROM_SIZE);
-cpu_register_physical_memory(PC_ROM_MIN_VGA, PC_ROM_SIZE, 
option_rom_offset);
+isa_bios = qemu_malloc(sizeof(*isa_bios));
+memory_region_init_alias(isa_bios, isa-bios, bios,
+ bios_size - isa_bios_size, isa_bios_size);
+memory_region_add_subregion_overlap(system_memory,
+0x10 - isa_bios_size,
+isa_bios,
+1);
+memory_region_set_readonly(isa_bios, true);
+
+option_rom_mr = qemu_malloc(sizeof(*option_rom_mr));
+memory_region_init_ram(option_rom_mr, NULL, pc.rom, PC_ROM_SIZE);
+memory_region_add_subregion_overlap(system_memory,
+PC_ROM_MIN_VGA,
+option_rom_mr,
+1);
 
 /* map all the bios at the top of memory */
-cpu_register_physical_memory((uint32_t)(-bios_size),
- bios_size, bios_offset | IO_MEM_ROM);
+memory_region_add_subregion(system_memory,
+(uint32_t)(-bios_size),
+bios);
 
 fw_cfg = bochs_bios_init();
 rom_set_fw(fw_cfg);
diff --git a/hw/pc.h b/hw/pc.h
index fa57583..40684f4 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -2,6 +2,7 @@
 #define HW_PC_H
 
 #include qemu-common.h
+#include memory.h
 #include ioport.h
 #include isa.h
 #include fdc.h
-- 
1.7.5.3




Re: [Qemu-devel] [RFC PATCH 0/4] Fix subsection ambiguity in the migration format

2011-07-26 Thread Juan Quintela
Anthony Liguori anth...@codemonkey.ws wrote:
 On 07/25/2011 04:10 PM, Paolo Bonzini wrote:

 == Today ==

 Today we only support generating the latest serialization of
 devices. To increase the probability of the latest version working on
 older versions of QEMU, we strategically omit fields that we know can
 safely be omitted with older versions (subsections).  More than
 likely, migrating new to old won't work.

 Migrating old to new is more likely to work.  We version each section
 in order to be able to identify when we're dealing with old.

 But all of this logic lives in one of two forms.  Either as a
 savevm/loadvm callback that takes a QEMUFile and writes byte
 serialization to the stream in an open way (usually big endian) or
 encoded declaratively in a VMState section.

We have a very poor way to try to load a device without some features,
but support is very bad.

 == What we need ==

 We need to decompose migration into three different problems: 1)
 serializing device state 2) transforming the device model in order to
 satisfy forwards and backwards compatibility 3) encoding the
 serialized device model on the wire.

I will change this to:
- We need to be able to enable/disable features of a device.
  A.K.A. make -M pc-0.14 work with devices with the same features
  than 0.14.  Notice that this is _independent_ of migration.

- Be able to describe that different features/versions.  This is not the
  difficult part, it can be subsections, optional fields, whatever.
  What is the difficult part is _knowing_ what fields needs to be on
  each version.  That again depends of the device, not migration.

- Be able to to do forward/bacward compatibility (and without
  comunication both sides is basically impossible).

- Send things on the wire (really this is the easy part, we can play
  with it touching only migration functions.).

 We also need a way to future proof ourselves.

We have been very bad at this.  Automatic checking is the only way that
I can think of.

 == What we can do ==

 1) Add migration capabilities to future proof ourselves.  I think the
 simplest way this would work is to have a
 query-migration-capabilities' command that returned a bitmask of
 supported migration features.  I think we also introduce a
 set-migration-capabilities' command that can mask some of the
 supported features.

We have two things here.  Device level  protocol level.

Device level: very late to set anything.
Protocol level: we can set things here, but notice that only a few
things cane be set here.

 A management tool would query-migration features on the source and
 destination, take the intersection of the two masks, and set that mask
 on both the source and destination.

 Lack of support for these commands indicates a mask of zero which is
 the protocol we offer today.

 2) Switch to a visitor model to serialize device state.  This involves
 converting any occurance of:

 qemu_put_be32(f, port-guest_connected);

 To:

 visit_type_u32(v, guest_connected, port-guest_connected, local_err);

VMSTATE_INT32(guest_conected, FooState)

can be make to do this at any point.

 It's 100% mechanical and makes absolutely no logic change.  It works
 equally well with legacy and VMstate migration handlers.

 3) Add a Visitor class that operates on QEMUFile.

 At this state, we can migrate to data structures.  That means we can
 migrate to QEMUFile, QObjects, or JSON.  We could change the protocol
 at this stage to something that was still binary but had section sizes
 and things of that nature.

That was the whole point of vmstate.

 But we shouldn't stop here.

 4) Compatibility logic should be extracted from the savevm functions
 and VMstate functions into separate functions that take a data
 structure. Basically, we want to have something roughly equivalent to:

 QObject *e1000_migration_compatibility(QObject *src, int src_version,
 int dst_version);

 We can have lots of helpers that reuse the VMstate declarative stuff
 to do this but this should be registered independent of the main
 serialization handler.

 This moves us to a model where we always generate the latest
 serialization format, and then have specific ways to convert to older
 mechanisms.  It allows us to do very big backwards compatibility steps
 like convert the state of one device into two separate devices
 (because we're just dealing with in-memory data structures).

Paint me sceptic about this.   I don't think this is going to work
because that functions will rote very fast.

 It's this step that lets us truly support compatibility with
 migration. The good news is, it doesn't have to be all or nothing.
 Since we always already generate the latest serialization format, the
 existing code only deals with migrating older versions to the latest
 which is something that isn't all that important.

 So if we did this in 1.0, we could have a single function that
 converted the 1.0 device model to 1.1 and vice versa, and we'd be
 fine.  We wouldn't have 

Re: [Qemu-devel] [PATCH 21/55] block: Revert entanglement of bdrv_is_inserted() with tray status

2011-07-26 Thread Christoph Hellwig
 @@ -1066,20 +1066,21 @@ static const struct {
  [ 0x03 ] = { cmd_request_sense, ALLOW_UA },
  [ 0x12 ] = { cmd_inquiry,   ALLOW_UA },
  [ 0x1a ] = { cmd_mode_sense, /* (6) */  0 },
 -[ 0x1b ] = { cmd_start_stop_unit,   0 },
 +[ 0x1b ] = { cmd_start_stop_unit,   0 }, /* [1] */
  [ 0x1e ] = { cmd_prevent_allow_medium_removal,  0 },
  [ 0x25 ] = { cmd_read_cdvd_capacity,CHECK_READY },

 +/* [1] handler detects and reports not ready condition itself */

Why not comment this near the actual code?  The footnote scheme is
pretty odd and I've not seen it anywhere else in the code.

Otherwise looks fine,

Reviewed-by: Christoph Hellwig h...@lst.de



Re: [Qemu-devel] [PATCH 22/55] block: Drop tray status tracking, no longer used

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:56PM +0200, Markus Armbruster wrote:
 Commit 4be9762a is now completely redone.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,


Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 24/55] ide/atapi: Track tray locked state

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:58PM +0200, Markus Armbruster wrote:
 We already track it in BlockDriverState.  Just like tray open/close
 state, we should track it in the device models instead, because it's
 device state.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 25/55] ide/atapi: Switch from BlockDriverState's locked to own tray_locked

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:23:59PM +0200, Markus Armbruster wrote:
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/atapi.c |3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 26/55] scsi-disk: Track tray locked state

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:00PM +0200, Markus Armbruster wrote:
 We already track it in BlockDriverState.  Just like tray open/close
 state, we should track it in the device models instead, because it's
 device state.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 27/55] scsi-disk: Switch from BlockDriverState's locked to own tray_locked

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:01PM +0200, Markus Armbruster wrote:
 
 Signed-off-by: Markus Armbruster arm...@redhat.com


Looks good, although I would have merged it into the previous one.


Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 31/55] ide: Provide IDEDeviceInfo method exit()

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:05PM +0200, Markus Armbruster wrote:
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 32/55] ide/atapi: Don't fail eject when tray is already open

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:06PM +0200, Markus Armbruster wrote:
 MMC-5 6.40.2.6 specifies that START STOP UNIT succeeds when the drive
 already has the requested state.  cmd_start_stop_unit() fails when
 asked to eject while the tray is open and locked.  Fix that.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:07PM +0200, Markus Armbruster wrote:
 When ide-cd is backed by a physical drive, we want the physical tray
 match the virtual one.  To that end, we call bdrv_eject() on guest's
 load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
 But we don't set the initial state on device model init.  Fix that.
 
 While there, also unlock on device model exit.

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de

But wondering:  do you actually use the physical CDROM passthrough?



[Qemu-devel] [PATCH v2 17/23] pc: grab system_memory

2011-07-26 Thread Avi Kivity
While eventually this should come from the machine initialization function,
take a short cut to avoid converting all machines now.

Reviewed-by: Anthony Liguori aligu...@us.ibm.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 hw/pc.c  |3 ++-
 hw/pc.h  |4 +++-
 hw/pc_piix.c |8 +++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index a3e8539..369566a 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -957,7 +957,8 @@ void pc_cpus_init(const char *cpu_model)
 }
 }
 
-void pc_memory_init(const char *kernel_filename,
+void pc_memory_init(MemoryRegion *system_memory,
+const char *kernel_filename,
 const char *kernel_cmdline,
 const char *initrd_filename,
 ram_addr_t below_4g_mem_size,
diff --git a/hw/pc.h b/hw/pc.h
index 6d5730b..fa57583 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -6,6 +6,7 @@
 #include isa.h
 #include fdc.h
 #include net.h
+#include memory.h
 
 /* PC-style peripherals (also used by other machines).  */
 
@@ -129,7 +130,8 @@ void pc_cmos_set_s3_resume(void *opaque, int irq, int 
level);
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
 void pc_cpus_init(const char *cpu_model);
-void pc_memory_init(const char *kernel_filename,
+void pc_memory_init(MemoryRegion *system_memory,
+const char *kernel_filename,
 const char *kernel_cmdline,
 const char *initrd_filename,
 ram_addr_t below_4g_mem_size,
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index c5c16b4..d83854c 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -39,6 +39,8 @@
 #include blockdev.h
 #include smbus.h
 #include xen.h
+#include memory.h
+#include exec-memory.h
 #ifdef CONFIG_XEN
 #  include xen/hvm/hvm_info_table.h
 #endif
@@ -89,6 +91,9 @@ static void pc_init1(ram_addr_t ram_size,
 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
 BusState *idebus[MAX_IDE_BUS];
 ISADevice *rtc_state;
+MemoryRegion *system_memory;
+
+system_memory = get_system_memory();
 
 pc_cpus_init(cpu_model);
 
@@ -106,7 +111,8 @@ static void pc_init1(ram_addr_t ram_size,
 
 /* allocate ram and load rom/bios */
 if (!xen_enabled()) {
-pc_memory_init(kernel_filename, kernel_cmdline, initrd_filename,
+pc_memory_init(system_memory,
+   kernel_filename, kernel_cmdline, initrd_filename,
below_4g_mem_size, above_4g_mem_size);
 }
 
-- 
1.7.5.3




Re: [Qemu-devel] [PATCH 34/55] scsi-disk: Fix START_STOP to fail when it can't eject

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:08PM +0200, Markus Armbruster wrote:
 Don't fail when tray is already open.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:09PM +0200, Markus Armbruster wrote:
 When scsi-cd is backed by a physical drive, we want the physical tray
 match the virtual one.  To that end, we call bdrv_eject() on guest's
 load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
 But we don't set the initial state on device model init.  Fix that.
 
 While there, also unlock on device model exit.

Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 39/55] block/raw: Fix to forward method bdrv_media_changed()

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:13PM +0200, Markus Armbruster wrote:
 Block driver raw forwards most methods to the underlying block
 driver.  However, it doesn't implement method bdrv_media_changed().
 Makes bdrv_media_changed() always return -ENOTSUP.
 
 I believe -fda /dev/fd0 gives you raw over host_floppy, and disk
 change detection (fdc register 7 bit 7) is broken.  Testing my theory
 requires a computer museum, though.

Haha.  The patch looks fine to me anyway,

Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 40/55] block: Leave tracking media change to device models

2011-07-26 Thread Christoph Hellwig
On Wed, Jul 20, 2011 at 06:24:14PM +0200, Markus Armbruster wrote:
 hw/fdc.c is the only one that cares.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Looks good,


Reviewed-by: Christoph Hellwig h...@lst.de




Re: [Qemu-devel] [PATCH 42/55] block: Clean up bdrv_flush_all()

2011-07-26 Thread Christoph Hellwig
Looks good,

Reviewed-by: Christoph Hellwig h...@lst.de



  1   2   3   >