Re: [Qemu-devel] [PATCH 0/2] virtio-s390: Convert to realize()

2015-03-02 Thread Christian Borntraeger
Am 27.02.2015 um 14:55 schrieb Markus Armbruster:
> Markus Armbruster (2):
>   virtio-s390: s390_virtio_device_init() can't fail, simplify
>   virtio-s390: Convert to realize()
> 
>  hw/s390x/s390-virtio-bus.c | 97 
> ++
>  hw/s390x/s390-virtio-bus.h |  2 +-
>  2 files changed, 56 insertions(+), 43 deletions(-)
> 

Applied. Thanks.





Re: [Qemu-devel] [PATCH] Make sysbus EHCI devices ARM only by default

2015-03-02 Thread David Gibson
On Mon, Mar 02, 2015 at 12:45:16PM +0530, Amit Shah wrote:
> On (Wed) 18 Feb 2015 [16:01:01], David Gibson wrote:
> > A number of ARM embedded boards include EHCI USB host controllers which
> > appear as directly mapped devices, rather than sitting on a PCI bus.
> > 
> > At present code to emulate such devices is included whenever EHCI support
> > is included.  This patch adjusts teh config options to only include them
> > in builds targetting ARM by default.
> > 
> > Signed-off-by: David Gibson 
> 
> After this commit, the 'pc' machine type lost a few devices, as
> noticed by the vmstate checker nightly run.  Is this expected?
> 
>Section "xlnx,ps7-usb" does not exist in dest
>Section "fusbh200-ehci-usb" does not exist in dest
>Section "tegra2-ehci-usb" does not exist in dest
>Section "sysbus-ehci-usb" does not exist in dest
>Section "exynos4210-ehci-usb" does not exist in dest

Yes, that's expected.  Those are all sysbus EHCI interfaces that AFAIK
are only actually used on certain ARM platforms.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


pgpNT5b1fjK5z.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH] Make sysbus EHCI devices ARM only by default

2015-03-02 Thread Amit Shah
On (Mon) 02 Mar 2015 [18:28:12], David Gibson wrote:
> On Mon, Mar 02, 2015 at 12:45:16PM +0530, Amit Shah wrote:
> > On (Wed) 18 Feb 2015 [16:01:01], David Gibson wrote:
> > > A number of ARM embedded boards include EHCI USB host controllers which
> > > appear as directly mapped devices, rather than sitting on a PCI bus.
> > > 
> > > At present code to emulate such devices is included whenever EHCI support
> > > is included.  This patch adjusts teh config options to only include them
> > > in builds targetting ARM by default.
> > > 
> > > Signed-off-by: David Gibson 
> > 
> > After this commit, the 'pc' machine type lost a few devices, as
> > noticed by the vmstate checker nightly run.  Is this expected?
> > 
> >Section "xlnx,ps7-usb" does not exist in dest
> >Section "fusbh200-ehci-usb" does not exist in dest
> >Section "tegra2-ehci-usb" does not exist in dest
> >Section "sysbus-ehci-usb" does not exist in dest
> >Section "exynos4210-ehci-usb" does not exist in dest
> 
> Yes, that's expected.  Those are all sysbus EHCI interfaces that AFAIK
> are only actually used on certain ARM platforms.

OK, thanks.


Amit



Re: [Qemu-devel] [PATCH 1/1] scsi-hd: fix property unset case

2015-03-02 Thread Markus Armbruster
Ekaterina Tumanova  writes:

> check conf.blk before calling blkconf_blocksizes
>
> Signed-off-by: Ekaterina Tumanova 
> ---
>  hw/scsi/scsi-disk.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index 2921728..df5140e 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -2291,7 +2291,9 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
>  static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
>  {
>  SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
> -blkconf_blocksizes(&s->qdev.conf);
> +if (s->qdev.conf.blk) {
> +blkconf_blocksizes(&s->qdev.conf);
> +}

Looks suspicious on first glance, because block device model realize()
methods are supposed to fail when the backend is missing.  But...

>  s->qdev.blocksize = s->qdev.conf.logical_block_size;
>  s->qdev.type = TYPE_DISK;
>  if (!s->product) {
   s->product = g_strdup("QEMU HARDDISK");
   }
   scsi_realize(&s->qdev, errp);

... scsi_realize() errors out then.  Worth a comment.  Or maybe call
blkconf_blocksizes() only after scsi_realize().  Your choice.



Re: [Qemu-devel] [PATCH 3/3] migrate_incoming: Cleanup/clarify error messages

2015-03-02 Thread Dr. David Alan Gilbert
* Amit Shah (amit.s...@redhat.com) wrote:
> On (Thu) 26 Feb 2015 [14:54:41], Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" 
> > 
> > Create a separate error for the case where migrate_incoming is
> > used after a succesful migrate_incoming.
> > 
> > Reword the error in the case where '-incoming defer' is missing
> > to omit the command name so it's right for both hmp and qmp.
> > 
> > Signed-off-by: Dr. David Alan Gilbert 
> > ---
> >  migration/migration.c | 8 ++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/migration/migration.c b/migration/migration.c
> > index 2c805f1..e6ac3de 100644
> > --- a/migration/migration.c
> > +++ b/migration/migration.c
> > @@ -435,11 +435,15 @@ void migrate_del_blocker(Error *reason)
> >  void qmp_migrate_incoming(const char *uri, Error **errp)
> >  {
> >  Error *local_err = NULL;
> > +static bool once = true;
> >  
> >  if (!deferred_incoming) {
> > -error_setg(errp, "'-incoming defer' is required for 
> > migrate_incoming");
> > +error_setg(errp, "For use with '-incoming defer'");
> >  return;
> >  }
> > +if (!once) {
> > +error_setg(errp, "The incoming migration has already been 
> > started");
> 
> Let me apologise in advance for picking on another error message...
> 
> This reads like we already have an incoming migration, when we mean we
> just have a URI for one.

No, if you hit this error you have at least started listening on the connection.

Dave

> 
>   Amit
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [PATCH V13 3/4] pc: add a Virtual Machine Generation ID device

2015-03-02 Thread Michael S. Tsirkin
On Wed, Feb 25, 2015 at 05:08:52PM +, Igor Mammedov wrote:
> diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> index 1f678b4..a09cb3f 100644
> --- a/include/hw/acpi/acpi.h
> +++ b/include/hw/acpi/acpi.h
> @@ -25,6 +25,7 @@
>  #include "qemu/option.h"
>  #include "exec/memory.h"
>  #include "hw/irq.h"
> +#include "hw/acpi/acpi_dev_interface.h"
>  
>  /*
>   * current device naming scheme supports up to 256 memory devices

BTW why is this here?

-- 
MST



Re: [Qemu-devel] [PATCH V2 06/11] virtio-s390: switch to bus specific queue limit

2015-03-02 Thread Cornelia Huck
On Sat, 28 Feb 2015 11:31:21 +0800
Jason Wang  wrote:

> 
> 
> On Fri, Feb 27, 2015 at 5:49 PM, Cornelia Huck 
>  wrote:
> > On Fri, 27 Feb 2015 06:42:57 +0008
> > Jason Wang  wrote:
> > 
> >>  On Thu, Feb 26, 2015 at 9:05 PM, Cornelia Huck 
> >>   wrote:
> >>  > On Thu, 26 Feb 2015 15:04:41 +0800
> >>  > Jason Wang  wrote:
> >>  > 
> > 
> >>  >>   typedef struct AdapterRoutes {
> >>  >>   AdapterInfo adapter;
> >>  >>   int num_routes;
> >>  >>  -int gsi[VIRTIO_PCI_QUEUE_MAX];
> >>  >>  +int gsi[VIRTIO_S390_QUEUE_MAX];
> >>  > 
> >>  > Adapter routes are only applicable for the ccw transport, not for 
> >> the
> >>  > old s390 transport.
> >>  
> >>  Sure, will fix this.
> >>  
> >>  > 
> >>  > 
> >>  > (I'm also wondering whether this should be the generic limit 
> >> instead.)
> >>  
> >>  As you pointed out in V1, there will be more issues if we just 
> >> increase 
> >>  the generic limit. So I switch to use per transport limit. Since 
> >> the 
> >>  limit was not changed for both s390 and ccw, it should be ok.
> > 
> > I'm just wondering how many gsis we want to support for adapter 
> > routes.
> > They were introduced for virtio-ccw, but recently s390 pci has started
> > to use them as well, so a virtio limit seems silly here. I'll switch
> > them to some kind of generic limit instead, I think.
> 
> Get your point. My understanding is you can do this on top of this 
> series.

Yup, that will work.




Re: [Qemu-devel] Announcement: Patchew server is online now

2015-03-02 Thread Markus Armbruster
Fam Zheng  writes:

> Hello, everyone
>
> I'm glad to announce the fresh Patchew server deployment:
>
> http://qemu.patchew.org/

Looks slick!

Could the authors be made links, so I could click on myself and see all
my submissions?



Re: [Qemu-devel] [PATCH 1/1] scsi-hd: fix property unset case

2015-03-02 Thread Ekaterina Tumanova

On 03/02/2015 11:46 AM, Markus Armbruster wrote:

Ekaterina Tumanova  writes:


check conf.blk before calling blkconf_blocksizes

Signed-off-by: Ekaterina Tumanova 
---
  hw/scsi/scsi-disk.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 2921728..df5140e 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2291,7 +2291,9 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
  static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
  {
  SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
-blkconf_blocksizes(&s->qdev.conf);
+if (s->qdev.conf.blk) {
+blkconf_blocksizes(&s->qdev.conf);
+}


Looks suspicious on first glance, because block device model realize()
methods are supposed to fail when the backend is missing.  But...



it will properly fail in scsi_realize


  s->qdev.blocksize = s->qdev.conf.logical_block_size;
  s->qdev.type = TYPE_DISK;
  if (!s->product) {

s->product = g_strdup("QEMU HARDDISK");
}
scsi_realize(&s->qdev, errp);

... scsi_realize() errors out then.  Worth a comment.  Or maybe call
blkconf_blocksizes() only after scsi_realize().  Your choice.


can't call it later. conf.logical_block_size, which blkconf_blocksizes
sets it used earlier.




Re: [Qemu-devel] [PATCH V13 3/4] pc: add a Virtual Machine Generation ID device

2015-03-02 Thread Igor Mammedov
On Mon, 2 Mar 2015 09:50:39 +0100
"Michael S. Tsirkin"  wrote:

> On Wed, Feb 25, 2015 at 05:08:52PM +, Igor Mammedov wrote:
> > diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> > index 1f678b4..a09cb3f 100644
> > --- a/include/hw/acpi/acpi.h
> > +++ b/include/hw/acpi/acpi.h
> > @@ -25,6 +25,7 @@
> >  #include "qemu/option.h"
> >  #include "exec/memory.h"
> >  #include "hw/irq.h"
> > +#include "hw/acpi/acpi_dev_interface.h"
> >  
> >  /*
> >   * current device naming scheme supports up to 256 memory devices
> 
> BTW why is this here?
> 

Yep, looks like it should have been in:
include/hw/acpi/pc-hotplug.h

I'll post patch.



Re: [Qemu-devel] Announcement: Patchew server is online now

2015-03-02 Thread Fam Zheng
On Mon, 03/02 10:03, Markus Armbruster wrote:
> Fam Zheng  writes:
> 
> > Hello, everyone
> >
> > I'm glad to announce the fresh Patchew server deployment:
> >
> > http://qemu.patchew.org/
> 
> Looks slick!
> 
> Could the authors be made links, so I could click on myself and see all
> my submissions?
> 

Sure, I'm adding to the wishlist, but FWIW you can bookmark a
"from:arm...@redhat.com" search result page:

http://patchew.org/?search=from%3Aarmbru%40redhat.com

Fam



Re: [Qemu-devel] [PATCH v4 00/11] block: Rework bdrv_close_all()

2015-03-02 Thread Kevin Wolf
Am 27.02.2015 um 17:43 hat Max Reitz geschrieben:
> Currently, bdrv_close_all() force-closes all BDSs with a BlockBackend,
> which can lead to data corruption (see the iotest added in the final
> patch of this series) and is most certainly very ugly.
> 
> This series reworks bdrv_close_all() to instead eject the BDS trees from
> all BlockBackends and then close the monitor-owned BDS trees, which are
> the only BDSs without a BB. In effect, all BDSs are closed just by
> getting closed automatically due to their reference count becoming 0.
> 
> The benefit over the approach taken in v1 and v2 is that in device
> models we often cannot simply drop the reference to a BB because there
> may be some user which we forgot about. By ejecting the BDS trees from
> the BB, the BB itself becomes unusable, but in a clean way (it will
> return errors when accessed, but nothing will crash). Also, it is much
> simpler (no reference tracking necessary).
> 
> The only disadvantage (I can see) is that the BBs are leaked; but this
> does not matter because the qemu process is about to exit anyway.

I haven't looked at the actual patches yet, but just from this
description and the diffstat: We need to make sure that the refcount
really drops to 0. That is, if there are NBD servers, block jobs, etc.
that hold an additional reference, we must make sure to stop them. It
doesn't look like this series takes care of this, does it?

Hm... Perhaps we could even install an atexit handler that asserts that
all BDSes are really gone in the end?

Kevin



Re: [Qemu-devel] Fedora FC21 - Bug: 100% CPU and hangs in gettimeofday(&tp, NULL); forever

2015-03-02 Thread Paolo Bonzini


On 01/03/2015 11:36, Gerhard Wiesinger wrote:
> So far it happened only the PostgreSQL database VM. Kernel is alive
> (ping works well). ssh is not working.
> console window: after entering one character at login prompt, then crashed:
> [1438.384864] Out of memory: Kill process 10115 (pg_dump) score 112 or
> sacrifice child
> [1438.384990] Killed process 10115 (pg_dump) total-vm: 340548kB,
> anon-rss: 162712kB, file-rss: 220kB

Can you get a vmcore or at least sysrq-t output?

Paolo

> VM uptime is ~1 day, 2 cores 100%CPU.
> VM is very stripped down, nevertheless is should have enough memory (and
> also swap). Looks like it crashed at the nighlty backup (pg_dumpall),
> command is: ssh -x ${REMOTE_USER}@${REMOTE_HOST} "pg_dumpall" | bzip2 -9
>> ${DEST_SQL}
> free
>   totalusedfree  shared buff/cache  
> available
> Mem: 372264   28536  214780   20884 128948  303360
> Swap:   1081340   0 1081340
> 
> Ciao,
> Gerhard
> 
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/lib64/libthread_db.so.1".
> 0x7feee62412c1 in ppoll () from /lib64/libc.so.6
> 
> Thread 4 (Thread 0x7feed3fff700 (LWP 4636)):
> #0  0x7feee6242977 in ioctl () at /lib64/libc.so.6
> #1  0x7feef11d1c35 in kvm_vcpu_ioctl ()
> #2  0x7feef11d1cec in kvm_cpu_exec ()
> #3  0x7feef11bfb02 in qemu_kvm_cpu_thread_fn ()
> #4  0x7feeefcb352a in start_thread () at /lib64/libpthread.so.0
> #5  0x7feee624c79d in clone () at /lib64/libc.so.6
> 
> Thread 3 (Thread 0x7feed37fe700 (LWP 4637)):
> #0  0x7feee6242977 in ioctl () at /lib64/libc.so.6
> #1  0x7feef11d1c35 in kvm_vcpu_ioctl ()
> #2  0x7feef11d1cec in kvm_cpu_exec ()
> #3  0x7feef11bfb02 in qemu_kvm_cpu_thread_fn ()
> #4  0x7feeefcb352a in start_thread () at /lib64/libpthread.so.0
> #5  0x7feee624c79d in clone () at /lib64/libc.so.6
> 
> Thread 2 (Thread 0x7feed1bff700 (LWP 4653)):
> #0  0x7feeefcb8590 in pthread_cond_wait@@GLIBC_2.3.2 () at
> /lib64/libpthread.so.0
> #1  0x7feef1466d79 in qemu_cond_wait ()
> #2  0x7feef13eadd3 in vnc_worker_thread_loop ()
> #3  0x7feef13eb1b8 in vnc_worker_thread ()
> #4  0x7feeefcb352a in start_thread () at /lib64/libpthread.so.0
> #5  0x7feee624c79d in clone () at /lib64/libc.so.6
> 
> Thread 1 (Thread 0x7feef103fa80 (LWP 4563)):
> #0  0x7feee62412c1 in ppoll () at /lib64/libc.so.6
> #1  0x7feef13fc89c in qemu_poll_ns ()
> #2  0x7feef13fc034 in main_loop_wait ()
> #3  0x7feef1197cdd in main ()
> 
> 
> 



Re: [Qemu-devel] [PATCH v3 03/10] acpi, mem-hotplug: Add acpi_send_gpe_event() to rise sci for memory hotplug.

2015-03-02 Thread Igor Mammedov
On Sun, 1 Mar 2015 18:29:39 +0100
"Michael S. Tsirkin"  wrote:

> On Thu, Feb 26, 2015 at 09:16:45AM +0800, Zhu Guihua wrote:
> > From: Tang Chen 
> > 
> > Add a new API named acpi_send_gpe_event() to send memory hotplug SCI.
> > Doing this is because this procedure will be used by other functions in the
> > next coming patches.
> > 
> > Signed-off-by: Tang Chen 
> > Signed-off-by: Zhu Guihua 
> > ---
> >  hw/acpi/core.c   | 7 +++
> >  hw/acpi/memory_hotplug.c | 6 ++
> >  include/hw/acpi/acpi.h   | 3 +++
> >  3 files changed, 12 insertions(+), 4 deletions(-)
> > 
> > diff --git a/hw/acpi/core.c b/hw/acpi/core.c
> > index 51913d6..98ca994 100644
> > --- a/hw/acpi/core.c
> > +++ b/hw/acpi/core.c
> > @@ -666,6 +666,13 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t 
> > addr)
> >  return val;
> >  }
> >  
> > +void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
> > + unsigned int hotplug_status)
> > +{
> > +ar->gpe.sts[0] |= hotplug_status;
> > +acpi_update_sci(ar, irq);
> > +}
> > +
> >  void acpi_update_sci(ACPIREGS *regs, qemu_irq irq)
> >  {
> >  int sci_level, pm1a_sts;
> > diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
> > index 6d91a0d..5b13baa 100644
> > --- a/hw/acpi/memory_hotplug.c
> > +++ b/hw/acpi/memory_hotplug.c
> > @@ -202,10 +202,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
> > MemHotplugState *mem_st,
> >  mdev->is_enabled = true;
> >  mdev->is_inserting = true;
> >  
> > -/* do ACPI magic */
> > -ar->gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
> > -acpi_update_sci(ar, irq);
> > -return;
> > +/* Do ACPI magic */
> > +acpi_send_gpe_event(ar, irq, ACPI_MEMORY_HOTPLUG_STATUS);
> >  }
> >  
> >  static const VMStateDescription vmstate_memhp_sts = {
> 
> This is hardly the only place where we change sts[0].
> 
> If you are doing this kind of API work, you need
> to fix it all up.
I've looked it /i.e. API change/, but it turned out to be rather big
refactoring hence it's too late for 2.3
I'll look at it later when 2.4 cycle opens.

> 
> > diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> > index 1f678b4..7a0a209 100644
> > --- a/include/hw/acpi/acpi.h
> > +++ b/include/hw/acpi/acpi.h
> > @@ -172,6 +172,9 @@ void acpi_gpe_reset(ACPIREGS *ar);
> >  void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
> >  uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
> >  
> > +void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
> > + unsigned int hotplug_status);
> > +
> 
> need to define legal values for hotplug_status.
> 
> >  void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
> >  
> >  /* acpi.c */
> > -- 
> > 1.9.3




Re: [Qemu-devel] [PATCH 0/1]

2015-03-02 Thread Kevin Wolf
Am 27.02.2015 um 19:26 hat Ekaterina Tumanova geschrieben:
> for Max Reitz:
> 
> Can you please apply this patch and re-test?
> 
> Thanks!
> Kate
> 
> p.s. This is supposed to be merged with patch 5/5 of
> "Geometry and blocksize detection for backing devices"
> 
> Ekaterina Tumanova (1):
>   scsi-hd: fix property unset case

Can someone please add a qemu-iotests case somewhere to check the
failing command line?

Kevin



Re: [Qemu-devel] [PATCH] qerror.h: Swap definitions that were not in alphabetical order

2015-03-02 Thread Markus Armbruster
Michael Tokarev  writes:

> Applied to -trivial, thank you!
>
> Markus, should I add your Reviewed-By (or Acked-By)?

I'm working towards getting rid of the whole thing.  But until then,
keeping it sorted is good.

Reviewed-by: Markus Armbruster 



Re: [Qemu-devel] [PATCH 0/2] cpus: fix deadlock and segfault

2015-03-02 Thread Leon Alrae
On 27/02/2015 19:05, Paolo Bonzini wrote:
> Reported by Leon Alrae on the mailing list, and by
> Andreas Gustafsson as Launchpad bug 1426472.
> 
> Paolo Bonzini (2):
>   cpus: fix deadlock and segfault in qemu_mutex_lock_iothread
>   cpus: be more paranoid in avoiding deadlocks

I don't know this part well enough to put Rev-by, but these fixes work
for me:

Tested-by: Leon Alrae 

Thanks,
Leon




Re: [Qemu-devel] [PATCH] nbd: Fix overflow return value

2015-03-02 Thread Markus Armbruster
"Fangyi (C)"  writes:

> PING

Please drop this line, it doesn't belong to the commit message.

You copied a bunch of people, but forgot the maintainer:

$ scripts/get_maintainer.pl -f nbd.c 
Paolo Bonzini  (odd fixer:Network Block Dev...)

I fixed that for you.

> The value of reply.error should be the type unsigned int.
>
> Signed-off-by: Yik Fang 
> ---
>  nbd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/nbd.c b/nbd.c
> index e56afbc1..30e2f3b 100644
> --- a/nbd.c
> +++ b/nbd.c
> @@ -1295,7 +1295,7 @@ static void nbd_trip(void *opaque)
>  default:
>  LOG("invalid request type (%u) received", request.type);
>  invalid_request:
> -reply.error = -EINVAL;
> +reply.error = EINVAL;
>  error_reply:
>  if (nbd_co_send_reply(req, &reply, 0) < 0) {
>  goto out;
> -- 1.8.5



Re: [Qemu-devel] [PATCH 0/2] RFC: Rolling statistics

2015-03-02 Thread Markus Armbruster
Copying qemu-block, because it could be of interest for block I/O
accounting.

"Dr. David Alan Gilbert (git)"  writes:

> From: "Dr. David Alan Gilbert" 
>
> Hi,
>   This is an attempt at a generic rolling statistics utility to
> allow data (e.g. bandwidth usage, times etc) to be collected
> easily.  They hold some basic values (min/max/mean/weighted mean)
> and the last 'n' raw values.I'd like to use this
> maybe in fault-tolerance code.
>
>   This is a first cut, and I think I probably need to rework it
> as a qapi type somehow, but I'm interested in thoughts.
>
> Dave
>
>
> Dr. David Alan Gilbert (2):
>   Rolling statistics utilities
>   Tests for rolling statistics code
>
>  include/qemu/rolling-stats.h | 101 +++
>  include/qemu/typedefs.h  |   1 +
>  tests/Makefile   |   3 +
>  tests/test-rolling-stats.c   | 161 ++
>  util/Makefile.objs   |   1 +
>  util/rolling-stats.c | 393 
> +++
>  6 files changed, 660 insertions(+)
>  create mode 100644 include/qemu/rolling-stats.h
>  create mode 100644 tests/test-rolling-stats.c
>  create mode 100644 util/rolling-stats.c



Re: [Qemu-devel] [PATCH v3 03/10] acpi, mem-hotplug: Add acpi_send_gpe_event() to rise sci for memory hotplug.

2015-03-02 Thread Michael S. Tsirkin
On Mon, Mar 02, 2015 at 10:27:29AM +0100, Igor Mammedov wrote:
> On Sun, 1 Mar 2015 18:29:39 +0100
> "Michael S. Tsirkin"  wrote:
> 
> > On Thu, Feb 26, 2015 at 09:16:45AM +0800, Zhu Guihua wrote:
> > > From: Tang Chen 
> > > 
> > > Add a new API named acpi_send_gpe_event() to send memory hotplug SCI.
> > > Doing this is because this procedure will be used by other functions in 
> > > the
> > > next coming patches.
> > > 
> > > Signed-off-by: Tang Chen 
> > > Signed-off-by: Zhu Guihua 
> > > ---
> > >  hw/acpi/core.c   | 7 +++
> > >  hw/acpi/memory_hotplug.c | 6 ++
> > >  include/hw/acpi/acpi.h   | 3 +++
> > >  3 files changed, 12 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/hw/acpi/core.c b/hw/acpi/core.c
> > > index 51913d6..98ca994 100644
> > > --- a/hw/acpi/core.c
> > > +++ b/hw/acpi/core.c
> > > @@ -666,6 +666,13 @@ uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, 
> > > uint32_t addr)
> > >  return val;
> > >  }
> > >  
> > > +void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
> > > + unsigned int hotplug_status)
> > > +{
> > > +ar->gpe.sts[0] |= hotplug_status;
> > > +acpi_update_sci(ar, irq);
> > > +}
> > > +
> > >  void acpi_update_sci(ACPIREGS *regs, qemu_irq irq)
> > >  {
> > >  int sci_level, pm1a_sts;
> > > diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
> > > index 6d91a0d..5b13baa 100644
> > > --- a/hw/acpi/memory_hotplug.c
> > > +++ b/hw/acpi/memory_hotplug.c
> > > @@ -202,10 +202,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
> > > MemHotplugState *mem_st,
> > >  mdev->is_enabled = true;
> > >  mdev->is_inserting = true;
> > >  
> > > -/* do ACPI magic */
> > > -ar->gpe.sts[0] |= ACPI_MEMORY_HOTPLUG_STATUS;
> > > -acpi_update_sci(ar, irq);
> > > -return;
> > > +/* Do ACPI magic */
> > > +acpi_send_gpe_event(ar, irq, ACPI_MEMORY_HOTPLUG_STATUS);
> > >  }
> > >  
> > >  static const VMStateDescription vmstate_memhp_sts = {
> > 
> > This is hardly the only place where we change sts[0].
> > 
> > If you are doing this kind of API work, you need
> > to fix it all up.
> I've looked it /i.e. API change/, but it turned out to be rather big
> refactoring hence it's too late for 2.3
> I'll look at it later when 2.4 cycle opens.

I don't mind who does it but it's a good idea
to sync with Zhu Guihua here to avoid duplicating work.

> > 
> > > diff --git a/include/hw/acpi/acpi.h b/include/hw/acpi/acpi.h
> > > index 1f678b4..7a0a209 100644
> > > --- a/include/hw/acpi/acpi.h
> > > +++ b/include/hw/acpi/acpi.h
> > > @@ -172,6 +172,9 @@ void acpi_gpe_reset(ACPIREGS *ar);
> > >  void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
> > >  uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
> > >  
> > > +void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
> > > + unsigned int hotplug_status);
> > > +
> > 
> > need to define legal values for hotplug_status.
> > 
> > >  void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
> > >  
> > >  /* acpi.c */
> > > -- 
> > > 1.9.3



Re: [Qemu-devel] [PATCH 2/2] docs: add memory-hotplug.txt

2015-03-02 Thread Paulo Ricardo Paz Vital
In addition to Eric's review.

On Thu, 2015-02-26 at 14:49 -0500, Luiz Capitulino wrote:
> This document describes how to use memory hotplug in QEMU.
> 
> Signed-off-by: Luiz Capitulino 
> ---
>  docs/memory-hotplug.txt | 77 
> +
>  1 file changed, 77 insertions(+)
>  create mode 100644 docs/memory-hotplug.txt
> 
> diff --git a/docs/memory-hotplug.txt b/docs/memory-hotplug.txt
> new file mode 100644
> index 000..e821449
> --- /dev/null
> +++ b/docs/memory-hotplug.txt
> @@ -0,0 +1,77 @@
> +QEMU memory hotplug

Not sure, but I guess the correct term is "hot plug" or "hot-plug". The
same approach should be used to "hot unplug" or "hot-unplug" and in the
first patch. Someone with better knowledge in English grammar than me
certainly can correct this. :-D

> +===
> +
> +This document explains how to use the memory hotplug feature in QEMU,
> +which is present since v2.1.0.
> +
> +Please, note that memory hot unplug is not supported yet. This means
> +that you're able to add memory, but you're not able to remove it.
> +Also, proper proper guest support is required for memory hotplug

There are two "proper" words here.

> +to work.
> +
> +Basic RAM hotplug
> +-
> +
> +In order to be able to hotplug memory, QEMU has to be told how many
> +hotpluggable memory slots to create and what is the maximum amount of

Following the grammar question above, this should be "hot pluggable" or
"hot-pluggable".

> +memory the guest can grow. This is done at startup time by means of
> +the -m command-line option, which has the following format:
> +
> + -m [size=]megs[,slots=n,maxmem=size]
> +
> +Where,
> +
> + - "megs" is the startup RAM. It is the RAM the guest will boot with
> + - "slots" is the number of hotpluggable memory slots
> + - "maxmem" is the maximum RAM size the guest can grow
> +
> +For example, the following command-line:
> +
> + qemu [...] 1G,slots=3,maxmem=4G
> +
> +Creates a guest with 1GB of memory and three hotpluggable memory slots.
> +The hotpluggable memory slots are empty when the guest is booted, so all
> +memory the guest will see after boot is 1GB. The maximum memory the
> +guest can reach is 4GB. This means that three additional gigas can be
> +hotplugged by using any combination of the available memory slots.
> +
> +Two monitor commands are used to hotplug memory:
> +
> + - "object_add": creates a memory backend object
> + - "device_add": creates the front-end pc-dimm device and inserts it
> + into an empty slot

s/the front-end/a front-end

> +
> +For example, the following commands add another 1GB to the guest
> +discussed earlier:
> +
> +  (qemu) object_add memory-backend-ram,id=mem1,size=1G
> +  (qemu) device_add pc-dimm,id=dimm1,memdev=mem1
> +
> +Using the file backend
> +--
> +
> +Besides basic RAM hotplug, QEMU also supports using files as a memory
> +backend. This is useful for using hugetlbfs in Linux, which provides
> +access to bigger page sizes.
> +
> +For example, assuming that the host has 1GB hugepages available in
> +the /mnt/hugepages-1GB directory, a 1GB hugepage could be hotplugged
> +into the guest from the previous section with the following commnands:
> +
> +  (qemu) object_add 
> memory-backend-file,id=mem1,size=1G,mem-path=/mnt/hugepages-1GB
> +  (qemu) device_add pc-dimm,id=dimm1,memdev=mem1
> +
> +It's also possible to start a guest with memory plugged into the
> +hotpluggable memory slots. This might seem counterintuitive at first,
> +but this allows for a lot of flexibility when using the file backend.
> +
> +In the following command-line example, a 8GB guest is created where 6GB
> +comes from regular RAM, 1GB is a 1GB hugepage page and 256MB is from
> +2MB pages. Also, the guest has additional memory slots to hotplug more
> +2GB if needed:
> +
> + qemu [...] -m 6GB,slots=4,maxmem=10G \
> +   -object memory-backend-file,id=mem1,size=1G,mem-path=/mnt/hugepages-1G \
> +   -device pc-dimm,id=dimm1,memdev=mem1 \
> +   -object memory-backend-file,id=mem2,size=256M,mem-path=/mnt/hugepages-2MB 
> \
> +   -device pc-dimm,id=dimm2,memdev=mem2

-- 
Paulo Ricardo Paz Vital 
ProfitBricks GmbH




Re: [Qemu-devel] [PATCH 1/2] Rolling statistics utilities

2015-03-02 Thread Dr. David Alan Gilbert
* Eric Blake (ebl...@redhat.com) wrote:
> On 02/27/2015 12:06 PM, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" 
> > 
> > There are various places where it's useful to hold a series
> > of values that change over time and get summaries about them.
> > 
> > This provides:
> > 
> >- a count of the number of items
> >- min/max
> >- mean
> >- a weighted mean (where you can set the weight to determine
> >   whether it changes quickly or slowly)
> >- the last 'n' values
> > 
> > Signed-off-by: Dr. David Alan Gilbert 
> > ---
> >  include/qemu/rolling-stats.h | 101 +++
> 
> > +
> > +/**
> > + * Return a string representing the RStats data, intended for JSON parsing
> > + *
> > + * Returns: An allocated string the caller must free
> > + *  or NULL on error
> > + *
> > + * e.g.
> > + *{ "min": -3.57, "max": 126.3, "mean": 7.83, "weighted_mean": 8.56,
> > + *  "count": 5678,
> > + *  "values": [ 4.3, 5.8, 1.2, 7.9, 10.3 ],
> > + *  "tags": [ 458, 783, 950, 951, 952 ] }
> 
> Looks useful at first glance.  Maybe s/weighted_mean/weighted-mean/
> since we favor - in new QMP.
> 
> 
> > +
> > +qemu_mutex_lock(&r->mutex);
> > +space  = 60 /* for text */ +
> > + /* 4 double values (min/max/mean/weighted) + the stored
> > +  * values, plus a normal guess for the size of them printed
> > +  * with %g and some padding.  I'm not sure of the worst case.
> > +  */
> > + (4 + r->allocated) * 13 +
> > + /* and the count and tags as 64bit ints and some padding */
> > + (1 + r->allocated) * 23;
> > +space_left = space - 1;
> > +
> > +result = g_try_malloc(space);
> > +
> > +if (!result) {
> > +qemu_mutex_unlock(&r->mutex);
> > +return NULL;
> > +}
> > +
> > +current = result;
> > +tmp = snprintf(current, space_left, "Min/Max: %.8g, %.8g Mean: %.8g "
> > +"(Weighted: %.8g) Count: %" PRIu64
> > +" Values: ",
> 
> Eww. Why pre-compute things for a possibly not-wide-enough snprintf,
> when you can instead use glib's g_string_printf that allocates the
> perfect size as it goes?

Ah, because I didn't know about that; useful.

>  For that matter, your cover letter comment
> about putting the struct in QAPI and letting the generated visitor
> automatically produce the JSON might make this simpler than building it
> by hand.

Right; I'd got this far, tried to glue it into the 'info' commands
and realised it needed to return soemthing more QAPI friendly;
but thought it best to see if people liked the general idea before attacking
that.

I'm not sure; but I think the approach would be to have a QAPI
type to hold the same data (Lets say a RollingStats type)
and then have a rstats_copy_to_rolling_stats function
that, under lock, copied the data out, that way the QAPI
type doesn't need to worry about the lock and neither does
anything outside this code.

Dave

> 
> -- 
> Eric Blake   eblake redhat com+1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 


--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [PATCH RFC 0/5] Another patchset try to clean up around qerror_report_err()

2015-03-02 Thread Markus Armbruster
zhanghailiang  writes:

> Hi,
>
> I have noticed Markus's previous patchset 
> "Clean up around error_get_pretty(), qerror_report_err()".
>
> This is another patch series trying to do the same thing.
> I'm not sure if he has missed this places or these modifies are false.
>
> So, please review... 
>
> Thanks.

Help with qerror elimination is of course appreciated!  However, there's
overlap with related patches in flight.  Easy to miss, because there are
so many of them.  I'll elaborate in replies to your patches.



Re: [Qemu-devel] [PATCH RFC 1/5] serial-pci: Avoid qerror_report_err() outside QMP command handlers

2015-03-02 Thread Markus Armbruster
zhanghailiang  writes:

> qerror_report_err() is a transitional interface to help with
> converting existing monitor commands to QMP.  It should not be used
> elsewhere.  Replace by error_report_err() in serial_pci_init() and
> multi_serial_pci_init().
>
> Signed-off-by: zhanghailiang 
> ---
>  hw/char/serial-pci.c | 7 ++-
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/hw/char/serial-pci.c b/hw/char/serial-pci.c
> index f05c9b4..2b0bf54 100644
> --- a/hw/char/serial-pci.c
> +++ b/hw/char/serial-pci.c
> @@ -27,7 +27,6 @@
>  
>  #include "hw/char/serial.h"
>  #include "hw/pci/pci.h"
> -#include "qapi/qmp/qerror.h"
>  
>  #define PCI_SERIAL_MAX_PORTS 4
>  
> @@ -57,8 +56,7 @@ static int serial_pci_init(PCIDevice *dev)
>  s->baudbase = 115200;
>  serial_realize_core(s, &err);
>  if (err != NULL) {
> -qerror_report_err(err);
> -error_free(err);
> +error_report_err(err);
>  return -1;
>  }
>  
> @@ -116,8 +114,7 @@ static int multi_serial_pci_init(PCIDevice *dev)
>  s->baudbase = 115200;
>  serial_realize_core(s, &err);
>  if (err != NULL) {
> -qerror_report_err(err);
> -error_free(err);
> +error_report_err(err);
>  return -1;
>  }
>  s->irq = pci->irqs[i];

This breaks the error reply when you hot plug the devices via QMP
device_add.

The correct solution is my "[PATCH 06/10] serial-pci: Convert to
realize".



Re: [Qemu-devel] [PATCH RFC v4 06/13] qapi: add dirty-bitmaps migration capability

2015-03-02 Thread Vladimir Sementsov-Ogievskiy

On 27.02.2015 21:29, Eric Blake wrote:

On 02/27/2015 10:24 AM, Vladimir Sementsov-Ogievskiy wrote:

Reviewed-by: John Snow 
Signed-off-by: Vladimir Sementsov-Ogievskiy 
---
  include/migration/migration.h | 1 +
  migration/migration.c | 9 +
  qapi-schema.json  | 5 -
  3 files changed, 14 insertions(+), 1 deletion(-)

Reviewed-by: Eric Blake 



  #
+# @dirty-bitmaps: If enabled, QEMU will migrate named dirty bitmaps. (since 
2.3)

Just to make sure, this only affects the source side, and does not have
to be set on the destination (that is, the destination will
automatically handle incoming dirty bitmaps correctly without having to
tweak the knob first)?  Of course, libvirt will check that the
destination advertises the feature before enabling the knob on the
source (to avoid the case of the source sending something the
destination won't understand).

Yes, live migration in the destination will call load_state iff such 
block is found in the migration stream.


--
Best regards,
Vladimir




[Qemu-devel] [PULL 00/15] Misc changes for 2015-03-02

2015-03-02 Thread Paolo Bonzini
The following changes since commit 041ccc922ee474693a2869d4e3b59e920c739bc0:

  Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging 
(2015-02-26 12:16:46 +)

are available in the git repository at:

  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to 21618b3e55ad2c6fede0bffcaea466091811ce59:

  cpus: be more paranoid in avoiding deadlocks (2015-03-02 10:57:07 +0100)


- more config options
- bootdevice, iscsi, virtio-scsi fixes
- build system patches for MinGW and config-devices.mak
- qemu_mutex_lock_iothread deadlock fixes
- another tiny patch from the record/replay series


David Gibson (3):
  Add specific config options for PCI-E bridges
  Create specific config option for "platform-bus"
  Give ivshmem its own config option

Fam Zheng (3):
  block: Forbid bdrv_set_aio_context outside BQL
  virtio-scsi-dataplane: Call blk_set_aio_context within BQL
  iscsi: Handle write protected case in reopen

Gonglei (1):
  bootdevice: fix segment fault when booting guest with '-kernel' and 
'-initrd'

Max Reitz (1):
  virtio-scsi: Allocate op blocker reason before blocking

Michael S. Tsirkin (2):
  Makefile: don't silence mak file test with V=1
  Makefile.target: binary depends on config-devices

Paolo Bonzini (3):
  scsi: give device a parent before setting properties
  cpus: fix deadlock and segfault in qemu_mutex_lock_iothread
  cpus: be more paranoid in avoiding deadlocks

Pavel Dovgalyuk (1):
  timer: replace time() with QEMU_CLOCK_HOST

Vasily Efimov (1):
  Makefile: fix up parallel building under MSYS+MinGW

 Makefile   | 10 +-
 Makefile.target|  4 +++-
 block/iscsi.c  | 20 +++-
 bootdevice.c   | 13 +
 cpus.c | 12 
 default-configs/arm-softmmu.mak|  5 +
 default-configs/i386-softmmu.mak   |  3 +++
 default-configs/pci.mak|  1 +
 default-configs/ppc-softmmu.mak|  1 +
 default-configs/ppc64-softmmu.mak  |  1 +
 default-configs/x86_64-softmmu.mak |  3 +++
 hw/core/Makefile.objs  |  2 +-
 hw/misc/Makefile.objs  |  4 +---
 hw/pci-bridge/Makefile.objs|  5 +++--
 hw/scsi/scsi-bus.c |  5 +
 hw/scsi/virtio-scsi-dataplane.c|  4 
 hw/scsi/virtio-scsi.c  | 19 +++
 include/block/block.h  |  3 +--
 scripts/make_device_config.sh  |  2 +-
 vl.c   | 12 
 20 files changed, 81 insertions(+), 48 deletions(-)
-- 
2.3.0




[Qemu-devel] [PULL 03/15] virtio-scsi-dataplane: Call blk_set_aio_context within BQL

2015-03-02 Thread Paolo Bonzini
From: Fam Zheng 

It's not safe to call blk_set_aio_context from outside BQL because of
the bdrv_drain_all there. Let's put it in the hotplug callback which
will be called by qdev device realization for each scsi device attached
to the bus.

Signed-off-by: Fam Zheng 
Message-Id: <1423969591-23646-3-git-send-email-f...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 hw/scsi/virtio-scsi.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 9e2c718..8c437dd 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -254,10 +254,8 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq 
*req)
 int target;
 int ret = 0;
 
-if (s->dataplane_started && blk_get_aio_context(d->conf.blk) != s->ctx) {
-aio_context_acquire(s->ctx);
-blk_set_aio_context(d->conf.blk, s->ctx);
-aio_context_release(s->ctx);
+if (s->dataplane_started) {
+assert(blk_get_aio_context(d->conf.blk) == s->ctx);
 }
 /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE".  */
 req->resp.tmf.response = VIRTIO_SCSI_S_OK;
@@ -540,10 +538,8 @@ bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, 
VirtIOSCSIReq *req)
 virtio_scsi_complete_cmd_req(req);
 return false;
 }
-if (s->dataplane_started && blk_get_aio_context(d->conf.blk) != s->ctx) {
-aio_context_acquire(s->ctx);
-blk_set_aio_context(d->conf.blk, s->ctx);
-aio_context_release(s->ctx);
+if (s->dataplane_started) {
+assert(blk_get_aio_context(d->conf.blk) == s->ctx);
 }
 req->sreq = scsi_req_new(d, req->req.cmd.tag,
  virtio_scsi_get_lun(req->req.cmd.lun),
@@ -767,6 +763,9 @@ static void virtio_scsi_hotplug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 return;
 }
 blk_op_block_all(sd->conf.blk, s->blocker);
+aio_context_acquire(s->ctx);
+blk_set_aio_context(sd->conf.blk, s->ctx);
+aio_context_release(s->ctx);
 }
 
 if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) {
-- 
2.3.0





[Qemu-devel] [PULL 02/15] block: Forbid bdrv_set_aio_context outside BQL

2015-03-02 Thread Paolo Bonzini
From: Fam Zheng 

Even if the caller has both the old and the new AioContext's, there can
be a deadlock, due to the leading bdrv_drain_all.

Suppose there are four io threads (A, B, A0, B0) with A and B owning a
BDS for each (bs_a, bs_b); Now A wants to move bs_a to iothread A0, and
B wants to move bs_b to B0, at the same time:

  iothread A   iothread B
--
  aio_context_acquire(A0) /* OK */ aio_context_acquire(B0) /* OK */
  bdrv_set_aio_context(bs_a, A0)   bdrv_set_aio_context(bs_b, B0)
  -> bdrv_drain_all()  -> bdrv_drain_all()
 -> acquire A /* OK */   -> acquire A /* blocked */
 -> acquire B /* blocked */  -> acquire B
 ... ...

Deadlock happens because A is waiting for B, and B is waiting for A.

Signed-off-by: Fam Zheng 
Reviewed-by: Paolo Bonzini 
Message-Id: <1423969591-23646-2-git-send-email-f...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 include/block/block.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index 471d11d..649c269 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -547,8 +547,7 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs);
  * Changes the #AioContext used for fd handlers, timers, and BHs by this
  * BlockDriverState and all its children.
  *
- * This function must be called from the old #AioContext or with a lock held so
- * the old #AioContext is not executing.
+ * This function must be called with iothread lock held.
  */
 void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context);
 
-- 
2.3.0





[Qemu-devel] [PULL 06/15] Add specific config options for PCI-E bridges

2015-03-02 Thread Paolo Bonzini
From: David Gibson 

The i82801b11, ioh3420 and xio3130 PCI Express devices are currently
included in the build unconditionally.

While they could theoretically appear on any target platform with PCI-E,
they're pretty unlikely to appear on platforms that aren't Intel derived.

Therefore, to avoid presenting unlikely-to-be-relevant devices to the user,
add config options to enable these components, and enable them by default
only on x86 and arm platforms.

(Note that this patch does include these for aarch64, via its inclusion of
arm-softmmu.mak).

Signed-off-by: David Gibson 
Reviewed-by: Peter Crosthwaite 
Message-Id: <1425017077-18487-2-git-send-email-da...@gibson.dropbear.id.au>
Signed-off-by: Paolo Bonzini 
---
 default-configs/arm-softmmu.mak| 4 
 default-configs/i386-softmmu.mak   | 3 +++
 default-configs/x86_64-softmmu.mak | 3 +++
 hw/pci-bridge/Makefile.objs| 5 +++--
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index b00c2e1..6ee9b43 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -91,3 +91,7 @@ CONFIG_INTEGRATOR_DEBUG=y
 CONFIG_ALLWINNER_A10_PIT=y
 CONFIG_ALLWINNER_A10_PIC=y
 CONFIG_ALLWINNER_A10=y
+
+CONFIG_XIO3130=y
+CONFIG_IOH3420=y
+CONFIG_I82801B11=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index bd99af9..0b8ce4b 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -43,3 +43,6 @@ CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_XIO3130=y
+CONFIG_IOH3420=y
+CONFIG_I82801B11=y
diff --git a/default-configs/x86_64-softmmu.mak 
b/default-configs/x86_64-softmmu.mak
index e7c2734..6add04a 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -43,3 +43,6 @@ CONFIG_IOAPIC=y
 CONFIG_ICC_BUS=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_HOTPLUG=y
+CONFIG_XIO3130=y
+CONFIG_IOH3420=y
+CONFIG_I82801B11=y
diff --git a/hw/pci-bridge/Makefile.objs b/hw/pci-bridge/Makefile.objs
index 968b369..96c596e 100644
--- a/hw/pci-bridge/Makefile.objs
+++ b/hw/pci-bridge/Makefile.objs
@@ -1,5 +1,6 @@
 common-obj-y += pci_bridge_dev.o
-common-obj-y += ioh3420.o xio3130_upstream.o xio3130_downstream.o
-common-obj-y += i82801b11.o
+common-obj-$(CONFIG_XIO3130) += xio3130_upstream.o xio3130_downstream.o
+common-obj-$(CONFIG_IOH3420) += ioh3420.o
+common-obj-$(CONFIG_I82801B11) += i82801b11.o
 # NewWorld PowerMac
 common-obj-$(CONFIG_DEC_PCI) += dec.o
-- 
2.3.0





[Qemu-devel] [PULL 05/15] bootdevice: fix segment fault when booting guest with '-kernel' and '-initrd'

2015-03-02 Thread Paolo Bonzini
From: Gonglei 

Reproducer:

 $./qemu-system-x86_64 --enable-kvm -kernel /home/vmlinuz-2.6.32.12-0.7-default 
\
  -initrd /home/initrd-2.6.32.12-0.7-default -append \
 "root=/dev/ram rw console=ttyS0,115200" -dtb guest.dtb -vnc :10 --monitor 
stdio -smp 2
QEMU 2.2.50 monitor - type 'help' for more information
(qemu) Segmentation fault (core dumped)

Reported-by: Edivaldo de Araujo Pereira 
Signed-off-by: Gonglei 
Message-Id: <1425001784-6752-1-git-send-email-arei.gong...@huawei.com>
Signed-off-by: Paolo Bonzini 
---
 bootdevice.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/bootdevice.c b/bootdevice.c
index c3a010c..eacd8c8 100644
--- a/bootdevice.c
+++ b/bootdevice.c
@@ -221,10 +221,15 @@ char *get_boot_devices_list(size_t *size, bool 
ignore_suffixes)
 }
 
 if (!ignore_suffixes) {
-d = qdev_get_own_fw_dev_path_from_handler(i->dev->parent_bus, 
i->dev);
-if (d) {
-assert(!i->suffix);
-suffix = d;
+if (i->dev) {
+d = qdev_get_own_fw_dev_path_from_handler(i->dev->parent_bus,
+  i->dev);
+if (d) {
+assert(!i->suffix);
+suffix = d;
+} else {
+suffix = g_strdup(i->suffix);
+}
 } else {
 suffix = g_strdup(i->suffix);
 }
-- 
2.3.0





[Qemu-devel] [PULL 07/15] Create specific config option for "platform-bus"

2015-03-02 Thread Paolo Bonzini
From: David Gibson 

Currently the "platform-bus" device is included for all softmmu builds.
This bridge is intended for use on any platforms that require dynamic
creation of sysbus devices.  However, at present it is used only for the
PPC E500 target, with plans for the ARM "virt" target in the immediate
future.

To avoid a not-very-useful entry appearing in "qemu -device ?" output on
other targets, this patch makes a specific config option for platform-bus
and enables it (for now) only on ppc configurations which include E500
and on ARM (which always includes the "virt" target).

Signed-off-by: David Gibson 
Message-Id: <1425017077-18487-3-git-send-email-da...@gibson.dropbear.id.au>
Signed-off-by: Paolo Bonzini 
---
 default-configs/arm-softmmu.mak   | 1 +
 default-configs/ppc-softmmu.mak   | 1 +
 default-configs/ppc64-softmmu.mak | 1 +
 hw/core/Makefile.objs | 2 +-
 4 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 6ee9b43..149ae1b 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -34,6 +34,7 @@ CONFIG_PFLASH_CFI02=y
 CONFIG_MICRODRIVE=y
 CONFIG_USB_MUSB=y
 CONFIG_USB_EHCI_SYSBUS=y
+CONFIG_PLATFORM_BUS=y
 
 CONFIG_ARM11MPCORE=y
 CONFIG_A9MPCORE=y
diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak
index aebfab9..4b60e69 100644
--- a/default-configs/ppc-softmmu.mak
+++ b/default-configs/ppc-softmmu.mak
@@ -43,6 +43,7 @@ CONFIG_PREP=y
 CONFIG_MAC=y
 CONFIG_E500=y
 CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM))
+CONFIG_PLATFORM_BUS=y
 CONFIG_ETSEC=y
 CONFIG_LIBDECNUMBER=y
 # For PReP
diff --git a/default-configs/ppc64-softmmu.mak 
b/default-configs/ppc64-softmmu.mak
index f195a87..de71e41 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -44,6 +44,7 @@ CONFIG_PREP=y
 CONFIG_MAC=y
 CONFIG_E500=y
 CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM))
+CONFIG_PLATFORM_BUS=y
 CONFIG_ETSEC=y
 CONFIG_LIBDECNUMBER=y
 # For pSeries
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index 9dce1bc..abb3560 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -14,4 +14,4 @@ common-obj-$(CONFIG_SOFTMMU) += machine.o
 common-obj-$(CONFIG_SOFTMMU) += null-machine.o
 common-obj-$(CONFIG_SOFTMMU) += loader.o
 common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
-common-obj-$(CONFIG_SOFTMMU) += platform-bus.o
+common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o
-- 
2.3.0





[Qemu-devel] [PULL 04/15] timer: replace time() with QEMU_CLOCK_HOST

2015-03-02 Thread Paolo Bonzini
From: Pavel Dovgalyuk 

This patch replaces time() function calls with calls to
qemu_clock_get_ns(QEMU_CLOCK_HOST). It makes such requests deterministic
in record/replay mode of icount.

Reviewed-by: Paolo Bonzini 
Signed-off-by: Pavel Dovgalyuk 
Message-Id: <20150227131102.11912.89850.stgit@PASHA-ISP>
Signed-off-by: Paolo Bonzini 
---
 vl.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/vl.c b/vl.c
index e1ffd0a..9213f68 100644
--- a/vl.c
+++ b/vl.c
@@ -710,13 +710,17 @@ void vm_start(void)
 /***/
 /* real time host monotonic timer */
 
+static time_t qemu_time(void)
+{
+return qemu_clock_get_ms(QEMU_CLOCK_HOST) / 1000;
+}
+
 /***/
 /* host time/date access */
 void qemu_get_timedate(struct tm *tm, int offset)
 {
-time_t ti;
+time_t ti = qemu_time();
 
-time(&ti);
 ti += offset;
 if (rtc_date_offset == -1) {
 if (rtc_utc)
@@ -744,7 +748,7 @@ int qemu_timedate_diff(struct tm *tm)
 else
 seconds = mktimegm(tm) + rtc_date_offset;
 
-return seconds - time(NULL);
+return seconds - qemu_time();
 }
 
 static void configure_rtc_date_offset(const char *startdate, int legacy)
@@ -782,7 +786,7 @@ static void configure_rtc_date_offset(const char 
*startdate, int legacy)
 "'2006-06-17T16:01:21' or '2006-06-17'\n");
 exit(1);
 }
-rtc_date_offset = time(NULL) - rtc_start_date;
+rtc_date_offset = qemu_time() - rtc_start_date;
 }
 }
 
-- 
2.3.0





[Qemu-devel] [PULL 14/15] cpus: fix deadlock and segfault in qemu_mutex_lock_iothread

2015-03-02 Thread Paolo Bonzini
When two threads (other than the low-priority TCG VCPU thread)
are competing for the iothread lock, a deadlock can happen.  This
is because iothread_requesting_mutex is set to false by the first
thread that gets the mutex, and then the VCPU thread might never
yield from the execution loop.  If iothread_requesting_mutex is
changed from a bool to a counter, the deadlock is fixed.

However, there is another bug in qemu_mutex_lock_iothread that
can be triggered by the new call_rcu thread.  The bug happens
if qemu_mutex_lock_iothread is called before the CPUs are
created.  In that case, first_cpu is NULL and the caller
segfaults in qemu_mutex_lock_iothread.  To fix this, just
do not do the kick if first_cpu is NULL.

Reported-by: Leon Alrae 
Reported-by: Andreas Gustafsson 
Tested-by: Leon Alrae 
Signed-off-by: Paolo Bonzini 
---
 cpus.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/cpus.c b/cpus.c
index 1cd9867..83c078e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -778,7 +778,7 @@ static void qemu_tcg_init_cpu_signals(void)
 
 static QemuMutex qemu_global_mutex;
 static QemuCond qemu_io_proceeded_cond;
-static bool iothread_requesting_mutex;
+static unsigned iothread_requesting_mutex;
 
 static QemuThread io_thread;
 
@@ -1115,15 +1115,15 @@ bool qemu_in_vcpu_thread(void)
 
 void qemu_mutex_lock_iothread(void)
 {
-if (!tcg_enabled()) {
+if (!tcg_enabled() || !first_cpu) {
 qemu_mutex_lock(&qemu_global_mutex);
 } else {
-iothread_requesting_mutex = true;
+atomic_inc(&iothread_requesting_mutex);
 if (qemu_mutex_trylock(&qemu_global_mutex)) {
 qemu_cpu_kick_thread(first_cpu);
 qemu_mutex_lock(&qemu_global_mutex);
 }
-iothread_requesting_mutex = false;
+atomic_dec(&iothread_requesting_mutex);
 qemu_cond_broadcast(&qemu_io_proceeded_cond);
 }
 }
-- 
2.3.0





[Qemu-devel] [PULL 09/15] iscsi: Handle write protected case in reopen

2015-03-02 Thread Paolo Bonzini
From: Fam Zheng 

Save the write protected flag and check before reopen.

Signed-off-by: Fam Zheng 
Message-Id: <1424839208-5195-1-git-send-email-f...@redhat.com>
[Fixed typo in the name of the new field. - Paolo]
Signed-off-by: Paolo Bonzini 
---
 block/iscsi.c | 20 +++-
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 12ddbfb..1fa855a 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -65,6 +65,7 @@ typedef struct IscsiLun {
 unsigned long *allocationmap;
 int cluster_sectors;
 bool use_16_for_rw;
+bool write_protected;
 } IscsiLun;
 
 typedef struct IscsiTask {
@@ -1268,10 +1269,6 @@ out:
 /*
  * We support iscsi url's on the form
  * iscsi://[%@][:]//
- *
- * Note: flags are currently not used by iscsi_open.  If this function
- * is changed such that flags are used, please examine iscsi_reopen_prepare()
- * to see if needs to be changed as well.
  */
 static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
   Error **errp)
@@ -1385,9 +1382,10 @@ static int iscsi_open(BlockDriverState *bs, QDict 
*options, int flags,
 scsi_free_scsi_task(task);
 task = NULL;
 
+iscsilun->write_protected = iscsi_is_write_protected(iscsilun);
 /* Check the write protect flag of the LUN if we want to write */
 if (iscsilun->type == TYPE_DISK && (flags & BDRV_O_RDWR) &&
-iscsi_is_write_protected(iscsilun)) {
+iscsilun->write_protected) {
 error_setg(errp, "Cannot open a write protected LUN as read-write");
 ret = -EACCES;
 goto out;
@@ -1541,13 +1539,17 @@ static void iscsi_refresh_limits(BlockDriverState *bs, 
Error **errp)
 sector_limits_lun2qemu(iscsilun->bl.opt_xfer_len, iscsilun);
 }
 
-/* Since iscsi_open() ignores bdrv_flags, there is nothing to do here in
- * prepare.  Note that this will not re-establish a connection with an iSCSI
- * target - it is effectively a NOP.  */
+/* Note that this will not re-establish a connection with an iSCSI target - it
+ * is effectively a NOP.  */
 static int iscsi_reopen_prepare(BDRVReopenState *state,
 BlockReopenQueue *queue, Error **errp)
 {
-/* NOP */
+IscsiLun *iscsilun = state->bs->opaque;
+
+if (state->flags & BDRV_O_RDWR && iscsilun->write_protected) {
+error_setg(errp, "Cannot open a write protected LUN as read-write");
+return -EACCES;
+}
 return 0;
 }
 
-- 
2.3.0





[Qemu-devel] [PULL 13/15] virtio-scsi: Allocate op blocker reason before blocking

2015-03-02 Thread Paolo Bonzini
From: Max Reitz 

s->blocker is really only used in hw/scsi/virtio-scsi.c; the only places
where it is used in hw/scsi/virtio-scsi-dataplane.c is when it is
allocated and when it is freed. That does not make a whole lot of sense
(and is actually wrong because this leads to s->blocker potentially
being NULL when blk_op_block_all() is called in virtio-scsi.c), so move
the allocation and destruction of s->blocker to the device realization
and unrealization in virtio-scsi.c, respectively.

Case in point:

$ echo -e 'eject drv\nquit' | \
x86_64-softmmu/qemu-system-x86_64 \
-monitor stdio -machine accel=qtest -display none \
-object iothread,id=thr -device virtio-scsi-pci,iothread=thr \
-drive if=none,file=test.qcow2,format=qcow2,id=drv \
-device scsi-cd,drive=drv

Without this patch:

(qemu) eject drv
[1]10102 done
   10103 segmentation fault (core dumped)

With this patch:

(qemu) eject drv
Device 'drv' is busy: block device is in use by data plane
(qemu) quit

Signed-off-by: Max Reitz 
Message-Id: <1425057113-26940-1-git-send-email-mre...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 hw/scsi/virtio-scsi-dataplane.c | 4 
 hw/scsi/virtio-scsi.c   | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/virtio-scsi-dataplane.c b/hw/scsi/virtio-scsi-dataplane.c
index 418d73b..3f40ff0 100644
--- a/hw/scsi/virtio-scsi-dataplane.c
+++ b/hw/scsi/virtio-scsi-dataplane.c
@@ -211,8 +211,6 @@ void virtio_scsi_dataplane_start(VirtIOSCSI *s)
 
 s->dataplane_starting = true;
 
-assert(!s->blocker);
-error_setg(&s->blocker, "block device is in use by data plane");
 /* Set up guest notifier (irq) */
 rc = k->set_guest_notifiers(qbus->parent, vs->conf.num_queues + 2, true);
 if (rc != 0) {
@@ -279,8 +277,6 @@ void virtio_scsi_dataplane_stop(VirtIOSCSI *s)
 if (!s->dataplane_started || s->dataplane_stopping) {
 return;
 }
-error_free(s->blocker);
-s->blocker = NULL;
 s->dataplane_stopping = true;
 assert(s->ctx == iothread_get_aio_context(vs->conf.iothread));
 
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 8c437dd..4db3b23 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -903,6 +903,8 @@ static void virtio_scsi_device_realize(DeviceState *dev, 
Error **errp)
 virtio_scsi_save, virtio_scsi_load, s);
 s->migration_state_notifier.notify = virtio_scsi_migration_state_changed;
 add_migration_state_change_notifier(&s->migration_state_notifier);
+
+error_setg(&s->blocker, "block device is in use by data plane");
 }
 
 static void virtio_scsi_instance_init(Object *obj)
@@ -928,6 +930,8 @@ static void virtio_scsi_device_unrealize(DeviceState *dev, 
Error **errp)
 {
 VirtIOSCSI *s = VIRTIO_SCSI(dev);
 
+error_free(s->blocker);
+
 unregister_savevm(dev, "virtio-scsi", s);
 remove_migration_state_change_notifier(&s->migration_state_notifier);
 
-- 
2.3.0





[Qemu-devel] [PULL 15/15] cpus: be more paranoid in avoiding deadlocks

2015-03-02 Thread Paolo Bonzini
For good measure, ensure that the following sequence:

   thread 1 calls qemu_mutex_lock_iothread
   thread 2 calls qemu_mutex_lock_iothread
   VCPU thread are created
   VCPU thread enters execution loop

results in the VCPU threads letting the other two threads run
and obeying iothread_requesting_mutex even if the VCPUs are
not halted.  To do this, check iothread_requesting_mutex
before execution starts.

Tested-by: Leon Alrae 
Signed-off-by: Paolo Bonzini 
---
 cpus.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/cpus.c b/cpus.c
index 83c078e..0fac143 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1025,6 +1025,9 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
 }
 }
 
+/* process any pending work */
+exit_request = 1;
+
 while (1) {
 tcg_exec_all();
 
@@ -1115,10 +1118,11 @@ bool qemu_in_vcpu_thread(void)
 
 void qemu_mutex_lock_iothread(void)
 {
+atomic_inc(&iothread_requesting_mutex);
 if (!tcg_enabled() || !first_cpu) {
 qemu_mutex_lock(&qemu_global_mutex);
+atomic_dec(&iothread_requesting_mutex);
 } else {
-atomic_inc(&iothread_requesting_mutex);
 if (qemu_mutex_trylock(&qemu_global_mutex)) {
 qemu_cpu_kick_thread(first_cpu);
 qemu_mutex_lock(&qemu_global_mutex);
-- 
2.3.0




[Qemu-devel] [PULL 08/15] Give ivshmem its own config option

2015-03-02 Thread Paolo Bonzini
From: David Gibson 

Currently the ivshmem device is built whenever both PCI and KVM support are
included.  This patch gives it its own config option to allow easier
customization of whether to include it.  It's enabled by default in the
same circumstances as now - when both PCI and KVM are available.

Signed-off-by: David Gibson 
Reviewed-by: Peter Crosthwaite 
Message-Id: <1425017077-18487-4-git-send-email-da...@gibson.dropbear.id.au>
Signed-off-by: Paolo Bonzini 
---
 default-configs/pci.mak | 1 +
 hw/misc/Makefile.objs   | 4 +---
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index bea6b01..58a2c0a 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -35,3 +35,4 @@ CONFIG_SDHCI=y
 CONFIG_EDU=y
 CONFIG_VGA=y
 CONFIG_VGA_PCI=y
+CONFIG_IVSHMEM=$(CONFIG_KVM)
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 029a56f..6c6e296 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -19,9 +19,7 @@ common-obj-$(CONFIG_PUV3) += puv3_pm.o
 
 common-obj-$(CONFIG_MACIO) += macio/
 
-ifeq ($(CONFIG_PCI), y)
-obj-$(CONFIG_KVM) += ivshmem.o
-endif
+obj-$(CONFIG_IVSHMEM) += ivshmem.o
 
 obj-$(CONFIG_REALVIEW) += arm_sysctl.o
 obj-$(CONFIG_NSERIES) += cbus.o
-- 
2.3.0





Re: [Qemu-devel] [PATCH RFC 3/5] pci-hotplug-old: Avoid qerror_report_err() outside QMP command handlers

2015-03-02 Thread Markus Armbruster
zhanghailiang  writes:

> qerror_report_err() is a transitional interface to help with
> converting existing monitor commands to QMP. It should not be used
> elsewhere.  Replace by error_report_err() in qemu_pci_hot_add_nic().
>
> Signed-off-by: zhanghailiang 
> ---
>  hw/pci/pci-hotplug-old.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
> index beea6d2..477bafc 100644
> --- a/hw/pci/pci-hotplug-old.c
> +++ b/hw/pci/pci-hotplug-old.c
> @@ -91,8 +91,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
>  
>  ret = net_client_init(opts, 0, &local_err);
>  if (local_err) {
> -qerror_report_err(local_err);
> -error_free(local_err);
> +error_report_err(local_err);
>  return NULL;
>  }
>  if (nd_table[ret].devaddr) {

Hard to see, but this is actually dead code.

[PATCH v2 0/2] pci: Bury dead legacy commands pci_add, pci_del



[Qemu-devel] [PULL 12/15] Makefile.target: binary depends on config-devices

2015-03-02 Thread Paolo Bonzini
From: "Michael S. Tsirkin" 

relink binary whenever config-devices.mak changes:
this makes sense as we are adding/removing devices,
so binary has to be relinked to be up to date.

Signed-off-by: Michael S. Tsirkin 
Message-Id: <1424332114-13440-2-git-send-email-...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile.target | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Makefile.target b/Makefile.target
index 58c6ae1..2262d89 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -175,9 +175,11 @@ all-obj-y += $(common-obj-y)
 all-obj-y += $(target-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
 
+$(QEMU_PROG_BUILD): config-devices.mak
+
 # build either PROG or PROGW
 $(QEMU_PROG_BUILD): $(all-obj-y) ../libqemuutil.a ../libqemustub.a
-   $(call LINK,$^)
+   $(call LINK, $(filter-out %.mak, $^))
 
 gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
$(call quiet-command,rm -f $@ && $(SHELL) 
$(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES),"  GEN   
$(TARGET_DIR)$@")
-- 
2.3.0





[Qemu-devel] [PULL 01/15] scsi: give device a parent before setting properties

2015-03-02 Thread Paolo Bonzini
This mimics what is done in qdev_device_add, and lets the device be
freed in case something goes wrong.  Otherwise, object_unparent returns
immediately without freeing the device, which is on the other hand left
in the parent bus's list of children.

scsi_bus_legacy_handle_cmdline then returns an error, and the HBA is
destroyed as well with object_unparent.  But the lingering device that
was not removed in scsi_bus_legacy_add_drive cannot be removed now either,
and bus_unparent gets stuck in an infinite loop trying to empty the list
of children.

The right fix of course would be to assert in bus_add_child that the
device already has a bus, and remove the "safety net" that adds the
drive to the QOM tree in device_set_realized.  I am not yet sure whether
that would entail changing all callers to qdev_create (as well as
isa_create and usb_create and the corresponding _try_create versions).

Reported-by: Markus Armbruster 
Tested-by: Markus Armbruster 
Signed-off-by: Paolo Bonzini 
---
 hw/scsi/scsi-bus.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index db39ae0..dca9576 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -221,11 +221,16 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, 
BlockBackend *blk,
   const char *serial, Error **errp)
 {
 const char *driver;
+char *name;
 DeviceState *dev;
 Error *err = NULL;
 
 driver = blk_is_sg(blk) ? "scsi-generic" : "scsi-disk";
 dev = qdev_create(&bus->qbus, driver);
+name = g_strdup_printf("legacy[%d]", unit);
+object_property_add_child(OBJECT(bus), name, OBJECT(dev), NULL);
+g_free(name);
+
 qdev_prop_set_uint32(dev, "scsi-id", unit);
 if (bootindex >= 0) {
 object_property_set_int(OBJECT(dev), bootindex, "bootindex",
-- 
2.3.0





Re: [Qemu-devel] [PATCH RFC 2/5] qdev: Avoid qerror_report_err() outside QMP command handlers

2015-03-02 Thread Markus Armbruster
zhanghailiang  writes:

> qerror_report_err() is a transitional interface to help with
> converting existing monitor commands to QMP.  It should not be used
> elsewhere.  Replace by error_report_err() in qdev_init() and
> device_post_init().
>
> Signed-off-by: zhanghailiang 
> ---
>  hw/core/qdev.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 44c6b93..9adcd27 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -181,8 +181,7 @@ int qdev_init(DeviceState *dev)
>  
>  object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
>  if (local_err != NULL) {
> -qerror_report_err(local_err);
> -error_free(local_err);
> +error_report_err(local_err);
>  object_unparent(OBJECT(dev));
>  return -1;
>  }

This breaks QMP device_add's error reply.

The patches I posted together remove all calls of qdev_init().  Once
they're all merged, the function should be simply dropped.

> @@ -1189,8 +1188,7 @@ static void device_post_init(Object *obj)
>  Error *err = NULL;
>  qdev_prop_set_globals(DEVICE(obj), &err);
>  if (err) {
> -qerror_report_err(err);
> -error_free(err);
> +error_report_err(err);
>  exit(EXIT_FAILURE);
>  }
>  }

This one is part of a wider problem I solved in

[PATCH] qdev: Don't exit when running into bad -global



[Qemu-devel] [PULL 10/15] Makefile: fix up parallel building under MSYS+MinGW

2015-03-02 Thread Paolo Bonzini
From: Vasily Efimov 

This patch enables parallel building of QEMU in MSYS+MinGW environment.
Currently an attempt to build QEMU in parallel fails on generation of
version.lo (and version.o too).

The cause of the failure is that when listing prerequisites "Makefile"
references "config-host.h" by absolute path in some rules and by relative
path in others. Make cannot figure out that these references points to the
same file which leads to the race: the generation of "version.*" which
requires "$(BUILD_DIR)/config-host.h" is launched in parallel with the
generation of "config-host.h" needed by other "Makefile" targets.

This patch removes "$(BUILD_DIR)/" prefix from corresponding prerequisite
of "version.*". There is no other prerequisites "$(BUILD_DIR)/config-host.h"
found.

Also note that not every version of MSYS is able to build QEMU in parallel,
see: "http://sourceforge.net/p/mingw/bugs/1950/";. The suggested version is
1.0.17.

Signed-off-by: Vasily Efimov 
Message-Id: <1424264377-5992-1-git-send-email-r...@ispras.ru>
Signed-off-by: Paolo Bonzini 
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 6817c6f..b0d8c07 100644
--- a/Makefile
+++ b/Makefile
@@ -197,9 +197,9 @@ ALL_SUBDIRS=$(TARGET_DIRS) $(patsubst %,pc-bios/%, $(ROMS))
 
 recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
 
-$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc $(BUILD_DIR)/config-host.h | 
$(BUILD_DIR)/version.lo
+$(BUILD_DIR)/version.o: $(SRC_PATH)/version.rc config-host.h | 
$(BUILD_DIR)/version.lo
$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"  RC
version.o")
-$(BUILD_DIR)/version.lo: $(SRC_PATH)/version.rc $(BUILD_DIR)/config-host.h
+$(BUILD_DIR)/version.lo: $(SRC_PATH)/version.rc config-host.h
$(call quiet-command,$(WINDRES) -I$(BUILD_DIR) -o $@ $<,"  RC
version.lo")
 
 Makefile: $(version-obj-y) $(version-lobj-y)
-- 
2.3.0





Re: [Qemu-devel] [PATCH RFC 4/5] pci-assign: Avoid qerror_report_err() outside QMP command handlers

2015-03-02 Thread Markus Armbruster
zhanghailiang  writes:

> qerror_report_err() is a transitional interface to help with
> converting existing monitor commands to QMP.  It should not be used
> elsewhere.  Replace by error_report_err() in assigned_initfn().
>
> Signed-off-by: zhanghailiang 
> ---
>  hw/i386/kvm/pci-assign.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
> index bd92c69..f2f4e07 100644
> --- a/hw/i386/kvm/pci-assign.c
> +++ b/hw/i386/kvm/pci-assign.c
> @@ -1831,8 +1831,7 @@ out:
>  
>  exit_with_error:
>  assert(local_err);
> -qerror_report_err(local_err);
> -error_free(local_err);
> +error_report_err(local_err);
>  return -1;
>  }

This breaks the error reply when you hot plug the devices via QMP
device_add.

A correct solution is my "[PATCH 10/10] pci-assign: Convert to realize".



[Qemu-devel] [PULL 11/15] Makefile: don't silence mak file test with V=1

2015-03-02 Thread Paolo Bonzini
From: "Michael S. Tsirkin" 

V=1 should show what's going on, it's not nice
to silence things unconditionally.

Signed-off-by: Michael S. Tsirkin 
Message-Id: <1424332114-13440-1-git-send-email-...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile  | 6 +++---
 scripts/make_device_config.sh | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index b0d8c07..d92d4cd 100644
--- a/Makefile
+++ b/Makefile
@@ -109,8 +109,8 @@ endif
 -include $(SUBDIR_DEVICES_MAK_DEP)
 
 %/config-devices.mak: default-configs/%.mak
-   $(call quiet-command,$(SHELL) $(SRC_PATH)/scripts/make_device_config.sh 
$@ $<, "  GEN   $@")
-   @if test -f $@; then \
+   $(call quiet-command,$(SHELL) $(SRC_PATH)/scripts/make_device_config.sh 
$@.tmp $<, "  GEN   $@.tmp")
+   $(call quiet-command, if test -f $@; then \
  if cmp -s $@.old $@; then \
mv $@.tmp $@; \
cp -p $@ $@.old; \
@@ -126,7 +126,7 @@ endif
 else \
  mv $@.tmp $@; \
  cp -p $@ $@.old; \
-fi
+fi, "  GEN  $@");
 
 defconfig:
rm -f config-all-devices.mak $(SUBDIR_DEVICES_MAK)
diff --git a/scripts/make_device_config.sh b/scripts/make_device_config.sh
index 7242707..7958086 100644
--- a/scripts/make_device_config.sh
+++ b/scripts/make_device_config.sh
@@ -2,7 +2,7 @@
 # Construct a target device config file from a default, pulling in any
 # files from include directives.
 
-dest=$1.tmp
+dest=$1
 dep=`dirname $1`-`basename $1`.d
 src=$2
 src_dir=`dirname $src`
-- 
2.3.0





Re: [Qemu-devel] [PATCH] Makefile.objs: add dummy rule for .dsl files

2015-03-02 Thread Paolo Bonzini


On 01/03/2015 17:50, Michael S. Tsirkin wrote:
> Hmm, it turns out while this helps sometimes,
> sometimes this results in a hard to debug error
> as we try to run preprocessor on the non-existent .dsl.
> 
> If not too late, I suggest you drop this one for now.
> If too late, probably not worth reverting.
> 

Okay, dropped.

Paolo



Re: [Qemu-devel] [PATCH RFC 5/5] savevm: Replace error_report() & error_free() with error_report_err()

2015-03-02 Thread Markus Armbruster
zhanghailiang  writes:

> Signed-off-by: zhanghailiang 
> ---
>  savevm.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/savevm.c b/savevm.c
> index ce2b6a2..c4f8c39 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -932,8 +932,7 @@ int qemu_loadvm_state(QEMUFile *f)
>  int ret;
>  
>  if (qemu_savevm_state_blocked(&local_err)) {
> -error_report("%s", error_get_pretty(local_err));
> -error_free(local_err);
> +error_report_err(local_err);
>  return -EINVAL;
>  }

This one's good.  My commit 565f65d "error: Use error_report_err() where
appropriate" cleaned up this pattern, but a few more instances have
since crept in, and this is one.

I can see another one in hw/arm/virt.c machvirt_init().



Re: [Qemu-devel] [PATCH v3] block/vdi: Add locking for parallel requests

2015-03-02 Thread Paolo Bonzini


On 27/02/2015 20:54, Max Reitz wrote:
> When allocating a new cluster, the first write to it must be the one
> doing the allocation, because that one pads its write request to the
> cluster size; if another write to that cluster is executed before it,
> that write will be overwritten due to the padding.
> 
> See https://bugs.launchpad.net/qemu/+bug/1422307 for what can go wrong
> without this patch.
> 
> Cc: qemu-stable 
> Signed-off-by: Max Reitz 

Usage of CoMutex is tricky, but well commented.  So:

Reviewed-by: Paolo Bonzini 

> ---
> v3: Hopefully finally found the real issue which causes the problems
> described in the bug report; at least it sounds very reasonable and
> I can no longer reproduce any of the issues described there.
> Thank you, Paolo and Stefan!
> ---
>  block/vdi.c | 25 +
>  1 file changed, 25 insertions(+)
> 
> diff --git a/block/vdi.c b/block/vdi.c
> index 74030c6..53bd02f 100644
> --- a/block/vdi.c
> +++ b/block/vdi.c
> @@ -53,6 +53,7 @@
>  #include "block/block_int.h"
>  #include "qemu/module.h"
>  #include "migration/migration.h"
> +#include "block/coroutine.h"
>  
>  #if defined(CONFIG_UUID)
>  #include 
> @@ -196,6 +197,8 @@ typedef struct {
>  /* VDI header (converted to host endianness). */
>  VdiHeader header;
>  
> +CoMutex write_lock;
> +
>  Error *migration_blocker;
>  } BDRVVdiState;
>  
> @@ -504,6 +507,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, 
> int flags,
>"vdi", bdrv_get_device_name(bs), "live migration");
>  migrate_add_blocker(s->migration_blocker);
>  
> +qemu_co_mutex_init(&s->write_lock);
> +
>  return 0;
>  
>   fail_free_bmap:
> @@ -639,11 +644,31 @@ static int vdi_co_write(BlockDriverState *bs,
> buf, n_sectors * SECTOR_SIZE);
>  memset(block + (sector_in_block + n_sectors) * SECTOR_SIZE, 0,
> (s->block_sectors - n_sectors - sector_in_block) * 
> SECTOR_SIZE);
> +
> +/* Note that this coroutine does not yield anywhere from reading 
> the
> + * bmap entry until here, so in regards to all the coroutines 
> trying
> + * to write to this cluster, the one doing the allocation will
> + * always be the first to try to acquire the lock.
> + * Therefore, it is also the first that will actually be able to
> + * acquire the lock and thus the padded cluster is written before
> + * the other coroutines can write to the affected area. */
> +qemu_co_mutex_lock(&s->write_lock);
>  ret = bdrv_write(bs->file, offset, block, s->block_sectors);
> +qemu_co_mutex_unlock(&s->write_lock);
>  } else {
>  uint64_t offset = s->header.offset_data / SECTOR_SIZE +
>(uint64_t)bmap_entry * s->block_sectors +
>sector_in_block;
> +qemu_co_mutex_lock(&s->write_lock);
> +/* This lock is only used to make sure the following write 
> operation
> + * is executed after the write issued by the coroutine allocating
> + * this cluster, therefore we do not need to keep it locked.
> + * As stated above, the allocating coroutine will always try to 
> lock
> + * the mutex before all the other concurrent accesses to that
> + * cluster, therefore at this point we can be absolutely certain
> + * that that write operation has returned (there may be other 
> writes
> + * in flight, but they do not concern this very operation). */
> +qemu_co_mutex_unlock(&s->write_lock);
>  ret = bdrv_write(bs->file, offset, buf, n_sectors);
>  }
>  
> 



Re: [Qemu-devel] [PATCH 2/2] virtio_blk: fix comment for virtio 1.0

2015-03-02 Thread Rusty Russell
"Michael S. Tsirkin"  writes:
> Fix up comment to match virtio 1.0 logic:
> virtio_blk_outhdr isn't the first elements anymore,
> the only requirement is that it comes first in
> the s/g list.
>
> Signed-off-by: Michael S. Tsirkin 

Thanks, both applied.

Cheers,
Rusty.



Re: [Qemu-devel] [PATCH RFC v4 00/13] Dirty bitmaps migration

2015-03-02 Thread Vladimir Sementsov-Ogievskiy

On 27.02.2015 23:13, John Snow wrote:



On 02/27/2015 12:24 PM, Vladimir Sementsov-Ogievskiy wrote:

These patches provide dirty bitmap migration feature. Only named dirty
bitmaps are to be migrated. Migration may be enabled using migration
capabilities.

v4 significant changes:
  0001: tiny bugfix: out[i] -> out[i-start], same for 'in'
  0007: set chunk size to 1kb, disable live iteration for
migrating data < 1mb size.

  tests: only one with md5 sum is here. used function event_wait
 by John Snow. (I hope, you don't mind me just adding this
 function with your 'Signed-off-by')

  rfc: This patch set is based on v13 of
   "block: incremental backup series" by John Snow, which are
   not pushed yet.

v3:
  based on v13 of "block: incremental backup series" by John Snow.

  changes from v2:
  removed patch for adding dirty parameter (migration capablities used
  instead).

  0001: printf's dropped, qapi used
  0002: part0 -> zeroes
  0003: part0 -> zeroes
  0005: dirty_dirty -> meta
add comments about meta bitmap

  0006: the format is changed, nodes used instead of devices.

  other patches are new.

  rfc: there are two tests. They are the same but using different
  interfaces: md5 checksum of the bitmap last layer in query-block or
  separate query-block-dirty-bitmap with dirty bitmap regions.
  The second form is more appropriate for debugging, the first is more
  appropriate for simple regression control. Which should go to
  upstream?

v2:
  1. bug-fixes, that are already in upstream, and renaming of function
  bdrv_reset_dirty_bitmap (which is already in Snow's series) are
  dropped
  2. bitmap store/restore: the concept renamed to serialization, added
  function hbitmap_deserialize_part0, to not transfer zero blocks
  3. migration dirty parameter: added description comment
  4. Other patches are new.

v2.rfc:
Actually, in this version of the series I'm trying not use
migration/block.c at all. Instead a separate migration unit is added
in the new file migration/dirty-bitmap.c. Now bitmaps are migrated
like blocks in block migration, they have their "dirty-dirty" bitmaps,
for tracking set/unset changes during migration.

The advantages are:
   - no complications of migration/block.c
   - separate dirty-dirty bitmaps provide handling of "unset's"
   - more effective meta-data/data ratio - no tiny bitmap-blocks.



v1:
These patches provide dirty bitmap migration feature. Only named dirty
bitmaps are to be migrated. Migration is made as a part of block
migration in block-migration.c.

Dirty bitmap migration may be enabled by "dirty" parameter for qmp 
migrate

command. If "blk" and "inc" parameters are false when "dirty" is true
block migration is actually skipped: no allocatoions, no bdrv_read's,
no bdrv_write's, only bitmaps are migrated.

The patch set includes two my previous bug fixes, which are necessary
for it. The patch set is based on Incremental backup series by John
Snow.

*** BLURB HERE ***

Vladimir Sementsov-Ogievskiy (13):
   hbitmap: serialization
   block: BdrvDirtyBitmap serialization interface
   block: tiny refactoring: minimize hbitmap_(set/reset) usage
   block: add meta bitmaps
   block: add bdrv_next_dirty_bitmap()
   qapi: add dirty-bitmaps migration capability
   migration: add migration/block-dirty-bitmap.c
   iotests: maintain several vms in test
   iotests: add add_incoming_migration to VM class
   iotests: add event_wait to VM class
   qapi: add md5 checksum of last dirty bitmap level to query-block
   iotests: add dirty bitmap migration test
   migration/qemu-file: make functions qemu_(get/put)_string public

  block.c|  98 +-
  include/block/block.h  |  22 ++
  include/migration/block.h  |   1 +
  include/migration/migration.h  |   1 +
  include/migration/qemu-file.h  |  17 +
  include/qemu/hbitmap.h |  67 
  migration/Makefile.objs|   2 +-
  migration/block-dirty-bitmap.c | 693 
+

  migration/migration.c  |   9 +
  migration/qemu-file.c  |  18 ++
  qapi-schema.json   |   5 +-
  qapi/block-core.json   |   4 +-
  tests/qemu-iotests/117 |  84 +
  tests/qemu-iotests/117.out |   5 +
  tests/qemu-iotests/group   |   1 +
  tests/qemu-iotests/iotests.py  |  19 +-
  util/hbitmap.c | 106 +++
  vl.c   |   1 +
  18 files changed, 1144 insertions(+), 9 deletions(-)
  create mode 100644 migration/block-dirty-bitmap.c
  create mode 100755 tests/qemu-iotests/117
  create mode 100644 tests/qemu-iotests/117.out



I think you forgot to CC me on the series.

Unless -- you're not trying to get rid of me, are you? :>


Ohh, I'm sorry) It's a mistake. Hm, I've forgotten this for v3 too, 
because I wanted to CC people, added by you. So, I've just copy-pasted 
the CC list, but you wasn't in it as a sender. And for v4 the same 
command line was used..


--

[Qemu-devel] [PULL v3 01/26] balloon: call qdev_alias_all_properties for proxy dev in balloon class init

2015-03-02 Thread Michael S. Tsirkin
From: "Denis V. Lunev" 

The idea is that all other virtio devices are calling this helper
to merge properties of the proxy device. This is the only difference
in between this helper and code in inside virtio_instance_init_common.
The patch should not cause any harm as property list in generic balloon
code is empty.

This also allows to avoid some dummy errors like fixed by this
commit 91ba21208839643603e7f7fa5864723c3f371ebe
Author: Gonglei 
Date:   Tue Sep 30 14:10:35 2014 +0800
virtio-balloon: fix virtio-balloon child refcount in transports

Signed-off-by: Denis V. Lunev 
Signed-off-by: Raushaniya Maksudova 
Revieved-by: Cornelia Huck 
CC: Christian Borntraeger 
CC: Anthony Liguori 
CC: Michael S. Tsirkin 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/s390x/virtio-ccw.c  | 5 ++---
 hw/virtio/virtio-pci.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 3fee4aa..ffbb9c2 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -898,9 +898,8 @@ static void balloon_ccw_stats_set_poll_interval(Object 
*obj, struct Visitor *v,
 static void virtio_ccw_balloon_instance_init(Object *obj)
 {
 VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
-object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BALLOON);
-object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
-object_unref(OBJECT(&dev->vdev));
+virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_BALLOON);
 object_property_add(obj, "guest-stats", "guest statistics",
 balloon_ccw_stats_get_all, NULL, NULL, dev, NULL);
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 6dd41b9..e7baf7b 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1274,9 +1274,8 @@ static void virtio_balloon_pci_class_init(ObjectClass 
*klass, void *data)
 static void virtio_balloon_pci_instance_init(Object *obj)
 {
 VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
-object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_BALLOON);
-object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
-object_unref(OBJECT(&dev->vdev));
+virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_BALLOON);
 object_property_add(obj, "guest-stats", "guest statistics",
 balloon_pci_stats_get_all, NULL, NULL, dev,
 NULL);
-- 
MST




[Qemu-devel] [PULL v3 00/26] pci, pc, virtio fixes and cleanups

2015-03-02 Thread Michael S. Tsirkin
Hello, Peter!

This should be the last big pull as we are entering hard freeze.

This is an update of my previous pull request from
http://mid.gmane.org/20150226165911.ga20...@redhat.com
  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream_rebased
as the tree was not rebased since, you can either do both pulls or
only this latest pull, result will be exactly the same.

Note: I only included here the extra 26 patches, on top of what was previously 
posted
http://mid.gmane.org/1424295164-4774-1-git-send-email-...@redhat.com
if you merge PULL v2 first, you will see just these 26 patches.

I hope all this helps reduce the amount of noise rather
than increase it.

Note: these patches remove some generated files that we previously
compiled. Our build system doesn't handle this well for incremental
builds, resulting in build errors. This is not new, incremental
builds aren't 100% reliable. You can find and remove the
stale .d files from the removed sources, this will fix it -
for example, if you get an error about a missing ssdt-misc.dsl,
find and remove ssdt-misc.d in output directory.

The following changes since commit 11d39a131020cc5c54ff9bc86d3259f7d32bf849:

  Merge remote-tracking branch 'remotes/borntraeger/tags/s390x-20150218' into 
staging (2015-02-26 09:08:54 +)

are available in the git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to e32dccddb0b1fa335bf251c155e907f9d47accfd:

  acpi-test-data: update after pci rewrite (2015-03-01 19:41:50 +0100)


pci, pc, virtio fixes and cleanups

Last pull for hard freeze.

A bunch of fixes all over the place.
All of ACPI refactoring has been merged.
Legacy pci commands have been dropped.

Additionally, this includes patches from soft-freeze
(which apparently haven't been merged yet):

a bunch of fixes all over the place
virtio header cleanup
initial patches from virtio-1.0 branch

Signed-off-by: Michael S. Tsirkin 


Cornelia Huck (3):
  virtio: cull virtio_bus_set_vdev_features
  virtio: feature bit manipulation helpers
  virtio: add feature checking helpers

Denis V. Lunev (1):
  balloon: call qdev_alias_all_properties for proxy dev in balloon class 
init

Igor Mammedov (59):
  acpi: move generic aml building helpers into dedictated file
  acpi: add build_append_namestring() helper
  acpi: drop min-bytes in build_package()
  pc: acpi-build: update linker on guest access
  pc: acpi-build: migrate RSDP table
  pc: acpi: use local var for accessing ACPI tables blob in acpi_build()
  acpi: introduce AML composer aml_append()
  acpi: add aml_scope() term
  pc: acpi-build: use aml_scope() for \_SB scope
  acpi: add aml_device() term
  acpi: add aml_method() term
  acpi: add aml_if() term
  acpi: add aml_name() & aml_name_decl() term
  acpi: add aml_int() term
  acpi: add aml_return() term
  acpi: add aml_arg() term
  acpi: add aml_store() term
  acpi: add aml_and() term
  acpi: add aml_notify() term
  acpi: add aml_call1(), aml_call2(), aml_call3(), aml_call4() helpers
  acpi: add aml_package() term
  pc: acpi-build: generate _S[345] packages dynamically
  acpi: add aml_buffer() term
  acpi: add aml_resource_template() helper
  acpi: add aml_io() helper
  acpi: include PkgLength size only when requested
  acpi: add aml_operation_region() term
  acpi: add aml_field() & aml_named_field() terms
  acpi: add aml_local() term
  acpi: add aml_string() term
  pc: acpi-build: generate pvpanic device description dynamically
  acpi: add aml_varpackage() term
  acpi: add aml_equal() term
  acpi: add aml_processor() term
  acpi: add aml_eisaid() term
  pc: acpi-build: drop template patching and CPU hotplug objects dynamically
  pc: acpi-build: create CPU hotplug IO region dynamically
  acpi: add aml_reserved_field() term
  pc: acpi-build: drop template patching and memory hotplug objects 
dynamically
  pc: acpi-build: create memory hotplug IO region dynamically
  acpi: add aml_word_bus_number(), aml_word_io(), aml_dword_memory(), 
aml_qword_memory() terms
  pc: pcihp: expose MMIO base and len as properties
  pc: acpi-build: reserve PCIHP MMIO resources
  pc: acpi-build: create PCI0._CRS dynamically
  pc: acpi: drop manual hole punching for PCI hotplug resources
  pc: acpi: drop manual hole punching for CPU hotplug resources
  pc: acpi: drop manual hole punching for GPE0 resources
  pc: acpi-build: drop remaining ssdt_misc template
  acpi: add acpi_irq_no_flags() term
  pc: export applesmc IO port/len
  pc: acpi-build: drop template patching and create Device(SMC) dynamically
  tests: ACPI test blobs update due to PCI0._CRS changes
  tests: 

[Qemu-devel] [PULL v3 06/26] tpm: Support for capability flags of TIS 1.3

2015-03-02 Thread Michael S. Tsirkin
From: Stefan Berger 

Provide the TIS 1.3 capability flags.
The interface now looks like a TIS 1.3 interface. It's fully
compatible with previous TIS 1.2 and drivers written for
TIS 1.2 continue to work.

Signed-off-by: Stefan Berger 
Acked-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/tpm/tpm_tis.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 61186c5..d0bb97f 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -14,7 +14,7 @@
  *
  * Implementation of the TIS interface according to specs found at
  * http://www.trustedcomputinggroup.org. This implementation currently
- * supports version 1.21, revision 1.0.
+ * supports version 1.3, 21 March 2013
  * In the developers menu choose the PC Client section then find the TIS
  * specification.
  */
@@ -103,8 +103,15 @@
 
 #endif
 
+#define TPM_TIS_CAP_INTERFACE_VERSION1_3 (2 << 28)
+#define TPM_TIS_CAP_DATA_TRANSFER_64B(3 << 9)
+#define TPM_TIS_CAP_DATA_TRANSFER_LEGACY (0 << 9)
+#define TPM_TIS_CAP_BURST_COUNT_DYNAMIC  (0 << 8)
 #define TPM_TIS_CAP_INTERRUPT_LOW_LEVEL  (1 << 4) /* support is mandatory */
 #define TPM_TIS_CAPABILITIES_SUPPORTED   (TPM_TIS_CAP_INTERRUPT_LOW_LEVEL | \
+  TPM_TIS_CAP_BURST_COUNT_DYNAMIC | \
+  TPM_TIS_CAP_DATA_TRANSFER_64B | \
+  TPM_TIS_CAP_INTERFACE_VERSION1_3 | \
   TPM_TIS_INTERRUPTS_SUPPORTED)
 
 #define TPM_TIS_TPM_DID   0x0001
-- 
MST




[Qemu-devel] [PULL v3 10/26] pc: acpi: drop manual hole punching for GPE0 resources

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Drops manual hole punching in PCI0._CRS on PIIX4 machine type
for GPE0 resources. Resources will be consumed by Device(GPE0)
that is attached to PCI namespace.
There is GPE device with HID ACPI0006 since ACPI2.0
that should be used for this purpose but none of Windows
versions support it and show it as "unknown device",
so reserve resource in old fashioned way with PNP0A06
device to make windows happy and actually reserve resources.

Along with last hole _CRS layout of PIIX4 machine becomes
the same as Q35 one, so merge them together and use the same
_CRS for both machine types.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c | 32 +---
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 0de261a..2700154 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -876,21 +876,10 @@ build_ssdt(GArray *table_data, GArray *linker,
 aml_word_io(aml_min_fixed, aml_max_fixed,
 aml_pos_decode, aml_entire_range,
 0x, 0x, 0x0CF7, 0x, 0x0CF8));
-if (ich9_lpc_find()) { /* Q35 */
-aml_append(crs,
-aml_word_io(aml_min_fixed, aml_max_fixed,
-aml_pos_decode, aml_entire_range,
-0x, 0x0D00, 0x, 0x, 0xF300));
-} else { /* piix4 */
-aml_append(crs,
-aml_word_io(aml_min_fixed, aml_max_fixed,
-aml_pos_decode, aml_entire_range,
-0x, 0x0D00, 0xAFDF, 0x, 0xA2E0));
-aml_append(crs,
-aml_word_io(aml_min_fixed, aml_max_fixed,
-aml_pos_decode, aml_entire_range,
-0x, 0xAFE4, 0x, 0x, 0x501C));
-}
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0x0D00, 0x, 0x, 0xF300));
 aml_append(crs,
 aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
  aml_cacheable, aml_ReadWrite,
@@ -909,6 +898,19 @@ build_ssdt(GArray *table_data, GArray *linker,
 }
 aml_append(scope, aml_name_decl("_CRS", crs));
 
+/* reserve GPE0 block resources */
+dev = aml_device("GPE0");
+aml_append(dev, aml_name_decl("_HID", aml_string("PNP0A06")));
+aml_append(dev, aml_name_decl("_UID", aml_string("GPE0 resources")));
+/* device present, functioning, decoding, not shown in UI */
+aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+crs = aml_resource_template();
+aml_append(crs,
+aml_io(aml_decode16, pm->gpe0_blk, pm->gpe0_blk, 1, pm->gpe0_blk_len)
+);
+aml_append(dev, aml_name_decl("_CRS", crs));
+aml_append(scope, dev);
+
 /* reserve PCIHP resources */
 if (pm->pcihp_io_len) {
 dev = aml_device("PHPR");
-- 
MST




[Qemu-devel] [PULL v3 09/26] pc: acpi: drop manual hole punching for CPU hotplug resources

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Drops manual hole punching in PCI0._CRS on PIIX4 machine type
for CPU hotplug resources.
Resources will be consumed by Device(PRES) that is attached
to PCI bus. The same way how it currently works for mem hotlpug.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 02e2597..0de261a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -885,11 +885,7 @@ build_ssdt(GArray *table_data, GArray *linker,
 aml_append(crs,
 aml_word_io(aml_min_fixed, aml_max_fixed,
 aml_pos_decode, aml_entire_range,
-0x, 0x0D00, 0xAEFF, 0x, 0xA200));
-aml_append(crs,
-aml_word_io(aml_min_fixed, aml_max_fixed,
-aml_pos_decode, aml_entire_range,
-0x, 0xAF20, 0xAFDF, 0x, 0x00C0));
+0x, 0x0D00, 0xAFDF, 0x, 0xA2E0));
 aml_append(crs,
 aml_word_io(aml_min_fixed, aml_max_fixed,
 aml_pos_decode, aml_entire_range,
-- 
MST




[Qemu-devel] [PULL v3 02/26] tpm: Extend sts register to 32 bit

2015-03-02 Thread Michael S. Tsirkin
From: Stefan Berger 

More recent TIS specs extend the STS register to 32 bit. While
we don't store the TIS interface state, yet, we can extend it
without sideeffects.

Signed-off-by: Stefan Berger 
Acked-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/tpm/tpm_tis.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h
index 1a0db23..db78d51 100644
--- a/hw/tpm/tpm_tis.h
+++ b/hw/tpm/tpm_tis.h
@@ -41,7 +41,7 @@ typedef enum {
 typedef struct TPMLocality {
 TPMTISState state;
 uint8_t access;
-uint8_t sts;
+uint32_t sts;
 uint32_t inte;
 uint32_t ints;
 
-- 
MST




[Qemu-devel] [PULL v3 08/26] pc: acpi: drop manual hole punching for PCI hotplug resources

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Drops manual hole punching in PCI0._CRS for PIIX4 machine type.
Resources will be consumed by Device(PHPR) that cwis attached
to PCI bus. The same way how it currently works for mem hotlpug.

Manual hole in PIIX4 _CRS wasn't correct anyway since it was
legacy size 0xF while current PCIHP MMIO region is of size 0x14.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 355f9b7..02e2597 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -885,11 +885,7 @@ build_ssdt(GArray *table_data, GArray *linker,
 aml_append(crs,
 aml_word_io(aml_min_fixed, aml_max_fixed,
 aml_pos_decode, aml_entire_range,
-0x, 0x0D00, 0xADFF, 0x, 0xA100));
-aml_append(crs,
-aml_word_io(aml_min_fixed, aml_max_fixed,
-aml_pos_decode, aml_entire_range,
-0x, 0xAE0F, 0xAEFF, 0x, 0x00F1));
+0x, 0x0D00, 0xAEFF, 0x, 0xA200));
 aml_append(crs,
 aml_word_io(aml_min_fixed, aml_max_fixed,
 aml_pos_decode, aml_entire_range,
-- 
MST




[Qemu-devel] [PULL v3 15/26] tests: ACPI test blobs update due to PCI0._CRS changes

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

PCI0._CRS was moved into SSDT and became the same for
PIIX4/Q35 machines.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 tests/acpi-test-data/pc/DSDT  | Bin 3415 -> 2970 bytes
 tests/acpi-test-data/pc/SSDT  | Bin 2374 -> 2480 bytes
 tests/acpi-test-data/q35/DSDT | Bin 8005 -> 7608 bytes
 tests/acpi-test-data/q35/SSDT | Bin 578 -> 685 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/tests/acpi-test-data/pc/DSDT b/tests/acpi-test-data/pc/DSDT
index 
ad12cb35d9dafc4d50002873f5c4ca04552b36df..1693c3783b34cfb5473e7ef65ba6f8deee390898
 100644
GIT binary patch
delta 45
zcmcaEHA|e!CDR}W5h(Rj?Icp+>8P~()!Ht!A|i3&YlLI!H)5pvzXs<0ss&x
B3^@P*

delta 471
zcmX|;PfG$p7{=dmA=YWu6e24^q(i4D|FOqtT^BPf21n}9Vf+XZ5qMG}P$DSt5*?zz
zt4j0%@>_JQL)Q+S^3*i1+xi}6e$Vp^54_BM{B4yMM4@_Y0g&@9?KBUUx1`8R?v_%f
zTk%9JPw7L)f)E27g$F5;37artYM(Fztsfmv*i2h$pv|X1FAUWX;2Q#+9KDYK#xwmn
zQo4AJx8pW|UkE@!sd?s;9E~_!
z*g2nDf*&XeN1j}4iUU`ga<5ci
gb5S6s6jg_UiQB}Y)G87%z#z%>UA^VYfP97j0NTcIKL7v#

diff --git a/tests/acpi-test-data/pc/SSDT b/tests/acpi-test-data/pc/SSDT
index 
d0103368a0b9e3d5410372f1f589df4baf03..dc5be2497b6c2015d7cbabb1ff0cd13e02b3e0e4
 100644
GIT binary patch
delta 200
zcmX>mv_Y6FIM^j*11AFmq_(Y5Qb-R5RY{u3HX5oqF7jo=Ho~s1TU8(Mxrd)V52Z8Q%Mk;R1pa%HWv8<
z7OCtcjh#0B1}*&$HmO{9?mVa1edc|Kmz{mtf3Jy#Zgj&90DO8Dgrk#{UD9<@L96Hn
zolxiM3*zD~11Skyh7WAwT+SuBR!8Zu^kMB!`QK*@4}RaS0mMFl0Am(;)K&^22jdRD
zjCuWuIsH}`f*VXIzdpLQlHvLrOD@)juczaO!UVTfyXp;8i6bN6$OziR)|eAG
zpf~N!`Y5q>RM>NpFKua`&Te+}aX>B|wi+^>1$0SweE}}7lgo-s6TtxoH@6P#nzM1r
G%l`r~K4Uik

diff --git a/tests/acpi-test-data/q35/SSDT b/tests/acpi-test-data/q35/SSDT
index 
f86643da45ad89a97a652233cb090516afde7b31..749f368e3034bfb491dcd8ced37936e0dcbba02a
 100644
GIT binary patch
delta 200
zcmX@avX+%AIM^j*EfWI+NY;4}o2modBDslh-

delta 117
zcmZ3>dWeN9IM^k`iHU)MaoI#J={P6W7zU02gWz}`1_p)$K$dGf&;S4X|8WEuhQ)IM
or3{1P1-ZF6fU;l!6mUfs@Ies};EvIY4|a+VaP~CV_-;QV0J~ckEdT%j

-- 
MST




[Qemu-devel] [PULL v3 07/26] pc: acpi-build: create PCI0._CRS dynamically

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Replace template patching and runtime calculation
in _CRS() method with static _CRS defined in SSDT.
No functional change except of as mentined above
and _CRS being moved from DSDT to SSDT.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c  | 88 -
 hw/i386/acpi-dsdt-pci-crs.dsl | 92 ---
 hw/i386/acpi-dsdt.dsl | 45 -
 hw/i386/q35-acpi-dsdt.dsl | 18 -
 hw/i386/ssdt-misc.dsl | 19 -
 5 files changed, 52 insertions(+), 210 deletions(-)
 delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 4d5d7e3..355f9b7 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -346,24 +346,6 @@ static void acpi_align_size(GArray *blob, unsigned align)
 g_array_set_size(blob, ROUND_UP(acpi_data_len(blob), align));
 }
 
-/* Set a value within table in a safe manner */
-#define ACPI_BUILD_SET_LE(table, size, off, bits, val) \
-do { \
-uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \
-memcpy(acpi_data_get_ptr(table, size, off, \
- (bits) / BITS_PER_BYTE), \
-   &ACPI_BUILD_SET_LE_val, \
-   (bits) / BITS_PER_BYTE); \
-} while (0)
-
-static inline void *acpi_data_get_ptr(uint8_t *table_data, unsigned table_size,
-  unsigned off, unsigned size)
-{
-assert(off + size > off);
-assert(off + size <= table_size);
-return table_data + off;
-}
-
 static inline void acpi_add_table(GArray *table_offsets, GArray *table_data)
 {
 uint32_t offset = cpu_to_le32(table_data->len);
@@ -860,22 +842,6 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
 g_free(child);
 }
 
-static void patch_pci_windows(PcPciInfo *pci, uint8_t *start, unsigned size)
-{
-ACPI_BUILD_SET_LE(start, size, acpi_pci32_start[0], 32, pci->w32.begin);
-
-ACPI_BUILD_SET_LE(start, size, acpi_pci32_end[0], 32, pci->w32.end - 1);
-
-if (pci->w64.end || pci->w64.begin) {
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_valid[0], 8, 1);
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_start[0], 64, 
pci->w64.begin);
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_end[0], 64, pci->w64.end - 
1);
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_length[0], 64, pci->w64.end 
- pci->w64.begin);
-} else {
-ACPI_BUILD_SET_LE(start, size, acpi_pci64_valid[0], 8, 0);
-}
-}
-
 static void
 build_ssdt(GArray *table_data, GArray *linker,
AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -898,9 +864,59 @@ build_ssdt(GArray *table_data, GArray *linker,
 ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
 memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
 
-patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
-
 scope = aml_scope("\\_SB.PCI0");
+/* build PCI0._CRS */
+crs = aml_resource_template();
+aml_append(crs,
+aml_word_bus_number(aml_min_fixed, aml_max_fixed, aml_pos_decode,
+0x, 0x, 0x00FF, 0x, 0x0100));
+aml_append(crs, aml_io(aml_decode16, 0x0CF8, 0x0CF8, 0x01, 0x08));
+
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0x, 0x0CF7, 0x, 0x0CF8));
+if (ich9_lpc_find()) { /* Q35 */
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0x0D00, 0x, 0x, 0xF300));
+} else { /* piix4 */
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0x0D00, 0xADFF, 0x, 0xA100));
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0xAE0F, 0xAEFF, 0x, 0x00F1));
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0xAF20, 0xAFDF, 0x, 0x00C0));
+aml_append(crs,
+aml_word_io(aml_min_fixed, aml_max_fixed,
+aml_pos_decode, aml_entire_range,
+0x, 0xAFE4, 0x, 0x, 0x501C));
+}
+aml_append(crs,
+aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+ aml_cacheable, aml_ReadWrite,
+ 0, 0x000A, 0x000B, 0, 0x0002));
+aml_append(crs,
+aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
+ aml_non_cache

[Qemu-devel] [PULL v3 04/26] tpm: Support for XFIFO register

2015-03-02 Thread Michael S. Tsirkin
From: Stefan Berger 

Support for the XFIFO register (range) of the TIS 1.3 specification.
We support a range of 64 bytes.

Signed-off-by: Stefan Berger 
Acked-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/tpm/tpm_tis.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 6170693..a37c7ce 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -51,6 +51,8 @@
 #define TPM_TIS_REG_INTF_CAPABILITY   0x14
 #define TPM_TIS_REG_STS   0x18
 #define TPM_TIS_REG_DATA_FIFO 0x24
+#define TPM_TIS_REG_DATA_XFIFO0x80
+#define TPM_TIS_REG_DATA_XFIFO_END0xbc
 #define TPM_TIS_REG_DID_VID   0xf00
 #define TPM_TIS_REG_RID   0xf04
 
@@ -476,6 +478,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
 }
 break;
 case TPM_TIS_REG_DATA_FIFO:
+case TPM_TIS_REG_DATA_XFIFO ... TPM_TIS_REG_DATA_XFIFO_END:
 if (tis->active_locty == locty) {
 if (size > 4 - (addr & 0x3)) {
 /* prevent access beyond FIFO */
@@ -762,6 +765,7 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr 
addr,
 }
 break;
 case TPM_TIS_REG_DATA_FIFO:
+case TPM_TIS_REG_DATA_XFIFO ... TPM_TIS_REG_DATA_XFIFO_END:
 /* data fifo */
 if (tis->active_locty != locty) {
 break;
-- 
MST




[Qemu-devel] [PULL v3 11/26] pc: acpi-build: drop remaining ssdt_misc template

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

It drops empty ssdt_misc templete. It also hides
from user almost all pointer arithmetic when building
SSDT which makes resulting code a bit cleaner
and concentrating only on composing ASL construct
/i.e. a task build_ssdt() should be doing/.

Also it makes one binary blob less stored in QEMU
source tree by removing need to keep and update
hw/i386/ssdt-misc.hex.generated file here in total
saving us ~430LOC.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c  |  7 ++-
 hw/i386/Makefile.objs |  1 -
 hw/i386/ssdt-misc.dsl | 21 -
 3 files changed, 2 insertions(+), 27 deletions(-)
 delete mode 100644 hw/i386/ssdt-misc.dsl

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 2700154..01d988c 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -526,7 +526,6 @@ static inline char acpi_get_hex(uint32_t val)
 #define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 #define ACPI_SSDT_HEADER_LENGTH 36
 
-#include "hw/i386/ssdt-misc.hex"
 #include "hw/i386/ssdt-pcihp.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
@@ -850,7 +849,6 @@ build_ssdt(GArray *table_data, GArray *linker,
 MachineState *machine = MACHINE(qdev_get_machine());
 uint32_t nr_mem = machine->ram_slots;
 unsigned acpi_cpus = guest_info->apic_id_limit;
-uint8_t *ssdt_ptr;
 Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;
 int i;
 
@@ -860,9 +858,8 @@ build_ssdt(GArray *table_data, GArray *linker,
 QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256);
 g_assert(acpi_cpus <= ACPI_CPU_HOTPLUG_ID_LIMIT);
 
-/* Copy header and patch values in the S3_ / S4_ / S5_ packages */
-ssdt_ptr = acpi_data_push(ssdt->buf, sizeof(ssdp_misc_aml));
-memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
+/* Reserve space for header */
+acpi_data_push(ssdt->buf, sizeof(AcpiTableHeader));
 
 scope = aml_scope("\\_SB.PCI0");
 /* build PCI0._CRS */
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 45b90a8..9b00568 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -10,7 +10,6 @@ obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c \
hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
hw/i386/ssdt-pcihp.hex \
-   hw/i386/ssdt-misc.hex \
hw/i386/ssdt-tpm.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
diff --git a/hw/i386/ssdt-misc.dsl b/hw/i386/ssdt-misc.dsl
deleted file mode 100644
index 8d61f21..000
--- a/hw/i386/ssdt-misc.dsl
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
-
- * This program 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 General Public License for more details.
-
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, see .
- */
-#include "hw/acpi/pc-hotplug.h"
-
-ACPI_EXTRACT_ALL_CODE ssdp_misc_aml
-
-DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1)
-{
-}
-- 
MST




[Qemu-devel] [PULL v3 17/26] tests: add ACPI blobs for qemu with bridge cases

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 tests/acpi-test-data/pc/SSDT.bridge  | Bin 0 -> 4352 bytes
 tests/acpi-test-data/q35/SSDT.bridge | Bin 0 -> 702 bytes
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/acpi-test-data/pc/SSDT.bridge
 create mode 100644 tests/acpi-test-data/q35/SSDT.bridge

diff --git a/tests/acpi-test-data/pc/SSDT.bridge 
b/tests/acpi-test-data/pc/SSDT.bridge
new file mode 100644
index 
..b807ac92dde72719fe3861c710b555fe3dd62583
GIT binary patch
literal 4352
zcmeH}&2HO96ov0ljLlF~Ov!ZYIC0FayGZCbaon9GlCk_ln$S=|3K`*|2&w=@6C@3a
zz#H2I)b6`4vdB7mg!U2o2-)-r3bgK~>b<0{9afL;WU`qh{+?%Kep^v1D1pfBjGC)xWFkv_>6N(=V@(T4xA7eQD>93;s^Y3q=d+zJINr?To
z_JT?hCtkzb1|#dBqWkWvXRlwpdG-0T*LYK=4YOQ~v|^gO;^W}sK5Koy#Reefqez3%ye
zeuo}m(hg-l0;}=GYb7CU-#ETo
z;`NVONnk`l+{OvhPRO4xuA>PnG^$n-wQ*FYxzasbCsB&p%|jP2Exa63>kwPXlMIKw
znA1=k|DB3;bXi=-*x698lT(d$Z-U6&bMR-rz-t}wcyMA`KQqc>D&z^y~*fJ6&kYZ
zEklO6m-x1D-N^N%Zj;7+&viG~lX{&r?qIH;=6X`kXN-H1>-Z<5
zFa1k(nlKJT&mN|aes{KF6m44I%-_$as8Au)}4*Sk5hOF&A1cMs$p(*#HbON
zrKk8$AWr4x4*o4T{D!`ZC@S#|D1ku%Bq)9Il%t@+%;m6C1eM1|f>AMTE0Jp+mE@{1
ziitTr{-zC2fzCp87OJyQorUWECRF3KB2>#KJ&H#>Ym4Nhq`=d(5EK)5UKWBf0#C$3
T%yO7={=b{U>qQO=MGpTBc|!Xx

literal 0
HcmV?d1

diff --git a/tests/acpi-test-data/q35/SSDT.bridge 
b/tests/acpi-test-data/q35/SSDT.bridge
new file mode 100644
index 
..c552782f5bcc57094a7d1375b67979b2efa48f1c
GIT binary patch
literal 702
zcmaJ<&2G~`5T12{vDO=5f)N!Le1$`C2}PVx?X`*1#?H#?q9RAy1F9%eMNvx+y^$aR
zcV2))p96RVj(HCb7a943`XL`SL@n(6Z
z5+_fJ5=W%hYj=XX=deayWhyV33!JajvpYmOc^QubG#Q#Pp)n%0XRz%XZ8mK2Jk^Hf
zqe8QKc5_vwQ_P*D&(LTY_;ybHc{^8Vf%W{F4nyOZC@I@tQ_t_|@bRUCfsgy&NZ`B$
U4=%uf02OciE4IM5l`Jaw0}NP~0RR91

literal 0
HcmV?d1

-- 
MST




[Qemu-devel] [PULL v3 13/26] pc: export applesmc IO port/len

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

IO port and length will be used in following patch
to correctly generate SMC ACPI device in SSDT.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/isa/isa.h | 11 +--
 hw/i386/acpi-build.c |  2 +-
 hw/misc/applesmc.c   |  5 ++---
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h
index cf7bd34..f21ceaa 100644
--- a/include/hw/isa/isa.h
+++ b/include/hw/isa/isa.h
@@ -21,10 +21,17 @@
 #define ISA_BUS(obj) OBJECT_CHECK(ISABus, (obj), TYPE_ISA_BUS)
 
 #define TYPE_APPLE_SMC "isa-applesmc"
+#define APPLESMC_MAX_DATA_LENGTH   32
+#define APPLESMC_PROP_IO_BASE "iobase"
 
-static inline bool applesmc_find(void)
+static inline uint16_t applesmc_port(void)
 {
-return object_resolve_path_type("", TYPE_APPLE_SMC, NULL);
+Object *obj = object_resolve_path_type("", TYPE_APPLE_SMC, NULL);
+
+if (obj) {
+return object_property_get_int(obj, APPLESMC_PROP_IO_BASE, NULL);
+}
+return 0;
 }
 
 typedef struct ISADeviceClass {
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 01d988c..badfa73 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -145,7 +145,7 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
 
 /* Patch in appropriate value for AppleSMC _STA */
 *(uint8_t *)(info->dsdt_code + *applesmc_sta) =
-applesmc_find() ? 0x0b : 0x00;
+applesmc_port() ? 0x0b : 0x00;
 }
 
 static
diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 6a56b07..6bd61e7 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -43,7 +43,6 @@
 /* command/status port used by Apple SMC */
 #define APPLESMC_CMD_PORT  0x4
 #define APPLESMC_NR_PORTS  32
-#define APPLESMC_MAX_DATA_LENGTH   32
 
 #define APPLESMC_READ_CMD  0x10
 #define APPLESMC_WRITE_CMD 0x11
@@ -249,8 +248,8 @@ static void applesmc_isa_realize(DeviceState *dev, Error 
**errp)
 }
 
 static Property applesmc_isa_properties[] = {
-DEFINE_PROP_UINT32("iobase", AppleSMCState, iobase,
-  APPLESMC_DEFAULT_IOBASE),
+DEFINE_PROP_UINT32(APPLESMC_PROP_IO_BASE, AppleSMCState, iobase,
+   APPLESMC_DEFAULT_IOBASE),
 DEFINE_PROP_STRING("osk", AppleSMCState, osk),
 DEFINE_PROP_END_OF_LIST(),
 };
-- 
MST




[Qemu-devel] [PULL v3 03/26] tpm: Allow 32 & 16 bit accesses to the registers

2015-03-02 Thread Michael S. Tsirkin
From: Stefan Berger 

Improve the access to the registers with 32 and 16 bit reads and writes.
Also enable access to a non-base register address, such as reads of the
2nd byte of a register. Map the FIFO byte access to any byte within
its 4 byte register (following specs).

Signed-off-by: Stefan Berger 
Acked-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/tpm/tpm_tis.c | 60 
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index c0e7cd7..6170693 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -427,6 +427,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
 uint32_t val = 0x;
 uint8_t locty = tpm_tis_locality_from_addr(addr);
 uint32_t avail;
+uint8_t v;
 
 if (tpm_backend_had_startup_error(s->be_driver)) {
 return val;
@@ -476,14 +477,26 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr 
addr,
 break;
 case TPM_TIS_REG_DATA_FIFO:
 if (tis->active_locty == locty) {
-switch (tis->loc[locty].state) {
-case TPM_TIS_STATE_COMPLETION:
-val = tpm_tis_data_read(s, locty);
-break;
-default:
-val = TPM_TIS_NO_DATA_BYTE;
-break;
+if (size > 4 - (addr & 0x3)) {
+/* prevent access beyond FIFO */
+size = 4 - (addr & 0x3);
+}
+val = 0;
+shift = 0;
+while (size > 0) {
+switch (tis->loc[locty].state) {
+case TPM_TIS_STATE_COMPLETION:
+v = tpm_tis_data_read(s, locty);
+break;
+default:
+v = TPM_TIS_NO_DATA_BYTE;
+break;
+}
+val |= (v << shift);
+shift += 8;
+size--;
 }
+shift = 0; /* no more adjustments */
 }
 break;
 case TPM_TIS_REG_DID_VID:
@@ -518,11 +531,13 @@ static void tpm_tis_mmio_write_intern(void *opaque, 
hwaddr addr,
 {
 TPMState *s = opaque;
 TPMTISEmuState *tis = &s->s.tis;
-uint16_t off = addr & 0xfff;
+uint16_t off = addr & 0xffc;
+uint8_t shift = (addr & 0x3) * 8;
 uint8_t locty = tpm_tis_locality_from_addr(addr);
 uint8_t active_locty, l;
 int c, set_new_locty = 1;
 uint16_t len;
+uint32_t mask = (size == 1) ? 0xff : ((size == 2) ? 0x : ~0);
 
 DPRINTF("tpm_tis: write.%u(%08x) = %08x\n", size, (int)addr, 
(uint32_t)val);
 
@@ -535,6 +550,15 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr 
addr,
 return;
 }
 
+val &= mask;
+
+if (shift) {
+val <<= shift;
+mask <<= shift;
+}
+
+mask ^= 0x;
+
 switch (off) {
 case TPM_TIS_REG_ACCESS:
 
@@ -646,9 +670,10 @@ static void tpm_tis_mmio_write_intern(void *opaque, hwaddr 
addr,
 break;
 }
 
-tis->loc[locty].inte = (val & (TPM_TIS_INT_ENABLED |
-   TPM_TIS_INT_POLARITY_MASK |
-   TPM_TIS_INTERRUPTS_SUPPORTED));
+tis->loc[locty].inte &= mask;
+tis->loc[locty].inte |= (val & (TPM_TIS_INT_ENABLED |
+TPM_TIS_INT_POLARITY_MASK |
+TPM_TIS_INTERRUPTS_SUPPORTED));
 break;
 case TPM_TIS_REG_INT_VECTOR:
 /* hard wired -- ignore */
@@ -747,16 +772,25 @@ static void tpm_tis_mmio_write_intern(void *opaque, 
hwaddr addr,
 tis->loc[locty].state == TPM_TIS_STATE_COMPLETION) {
 /* drop the byte */
 } else {
-DPRINTF("tpm_tis: Byte to send to TPM: %02x\n", (uint8_t)val);
+DPRINTF("tpm_tis: Data to send to TPM: %08x (size=%d)\n",
+val, size);
 if (tis->loc[locty].state == TPM_TIS_STATE_READY) {
 tis->loc[locty].state = TPM_TIS_STATE_RECEPTION;
 tis->loc[locty].sts = TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID;
 }
 
-if ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT)) {
+val >>= shift;
+if (size > 4 - (addr & 0x3)) {
+/* prevent access beyond FIFO */
+size = 4 - (addr & 0x3);
+}
+
+while ((tis->loc[locty].sts & TPM_TIS_STS_EXPECT) && size > 0) {
 if (tis->loc[locty].w_offset < tis->loc[locty].w_buffer.size) {
 tis->loc[locty].w_buffer.
 buffer[tis->loc[locty].w_offset++] = (uint8_t)val;
+val >>= 8;
+size--;
 } else {
 tis->loc[locty].sts = TPM_TIS_STS_VALID;
 }
-- 
MST




[Qemu-devel] [PULL v3 14/26] pc: acpi-build: drop template patching and create Device(SMC) dynamically

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

patch moves SMC device into SSDT and creates it only
when device is present, which makes ACPI tables smaller
in default case when device is not present.

Also it fixes wrong IO range in CRS if "iobase"
property is set to a non default value.

PS:
Testing with XP shows that current default "iobase"
used SMC device conflicts with floppy controller IO,
but it's topic for another patch and I'd leave it
to SMC device author for resolving conflict.

Signed-off-by: Igor Mammedov 
CC: ag...@suse.de
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c  | 29 ++---
 hw/i386/acpi-dsdt-isa.dsl | 11 ---
 hw/i386/acpi-dsdt.dsl |  1 -
 hw/i386/q35-acpi-dsdt.dsl |  1 -
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index badfa73..05eb80a 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -116,6 +116,7 @@ typedef struct AcpiMiscInfo {
 const unsigned char *dsdt_code;
 unsigned dsdt_size;
 uint16_t pvpanic_port;
+uint16_t applesmc_io_base;
 } AcpiMiscInfo;
 
 typedef struct AcpiBuildPciBusHotplugState {
@@ -127,7 +128,6 @@ typedef struct AcpiBuildPciBusHotplugState {
 
 static void acpi_get_dsdt(AcpiMiscInfo *info)
 {
-uint16_t *applesmc_sta;
 Object *piix = piix4_pm_find();
 Object *lpc = ich9_lpc_find();
 assert(!!piix != !!lpc);
@@ -135,17 +135,11 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
 if (piix) {
 info->dsdt_code = AcpiDsdtAmlCode;
 info->dsdt_size = sizeof AcpiDsdtAmlCode;
-applesmc_sta = piix_dsdt_applesmc_sta;
 }
 if (lpc) {
 info->dsdt_code = Q35AcpiDsdtAmlCode;
 info->dsdt_size = sizeof Q35AcpiDsdtAmlCode;
-applesmc_sta = q35_dsdt_applesmc_sta;
 }
-
-/* Patch in appropriate value for AppleSMC _STA */
-*(uint8_t *)(info->dsdt_code + *applesmc_sta) =
-applesmc_port() ? 0x0b : 0x00;
 }
 
 static
@@ -248,6 +242,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info)
 info->has_hpet = hpet_find();
 info->has_tpm = tpm_find();
 info->pvpanic_port = pvpanic_port();
+info->applesmc_io_base = applesmc_port();
 }
 
 static void acpi_get_pci_info(PcPciInfo *info)
@@ -955,6 +950,26 @@ build_ssdt(GArray *table_data, GArray *linker,
 aml_append(scope, aml_name_decl("_S5", pkg));
 aml_append(ssdt, scope);
 
+if (misc->applesmc_io_base) {
+scope = aml_scope("\\_SB.PCI0.ISA");
+dev = aml_device("SMC");
+
+aml_append(dev, aml_name_decl("_HID", aml_eisaid("APP0001")));
+/* device present, functioning, decoding, not shown in UI */
+aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));
+
+crs = aml_resource_template();
+aml_append(crs,
+aml_io(aml_decode16, misc->applesmc_io_base, 
misc->applesmc_io_base,
+   0x01, APPLESMC_MAX_DATA_LENGTH)
+);
+aml_append(crs, aml_irq_no_flags(6));
+aml_append(dev, aml_name_decl("_CRS", crs));
+
+aml_append(scope, dev);
+aml_append(ssdt, scope);
+}
+
 if (misc->pvpanic_port) {
 scope = aml_scope("\\_SB.PCI0.ISA");
 
diff --git a/hw/i386/acpi-dsdt-isa.dsl b/hw/i386/acpi-dsdt-isa.dsl
index deb37de..89caa16 100644
--- a/hw/i386/acpi-dsdt-isa.dsl
+++ b/hw/i386/acpi-dsdt-isa.dsl
@@ -16,17 +16,6 @@
 /* Common legacy ISA style devices. */
 Scope(\_SB.PCI0.ISA) {
 
-Device (SMC) {
-Name(_HID, EisaId("APP0001"))
-/* _STA will be patched to 0x0B if AppleSMC is present */
-ACPI_EXTRACT_NAME_BYTE_CONST DSDT_APPLESMC_STA
-Name(_STA, 0xF0)
-Name(_CRS, ResourceTemplate () {
-IO (Decode16, 0x0300, 0x0300, 0x01, 0x20)
-IRQNoFlags() { 6 }
-})
-}
-
 Device(RTC) {
 Name(_HID, EisaId("PNP0B00"))
 Name(_CRS, ResourceTemplate() {
diff --git a/hw/i386/acpi-dsdt.dsl b/hw/i386/acpi-dsdt.dsl
index 09b68f0..a2d84ec 100644
--- a/hw/i386/acpi-dsdt.dsl
+++ b/hw/i386/acpi-dsdt.dsl
@@ -85,7 +85,6 @@ DefinitionBlock (
 }
 }
 
-#define DSDT_APPLESMC_STA piix_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
diff --git a/hw/i386/q35-acpi-dsdt.dsl b/hw/i386/q35-acpi-dsdt.dsl
index 3fb4b2f..16eaca3 100644
--- a/hw/i386/q35-acpi-dsdt.dsl
+++ b/hw/i386/q35-acpi-dsdt.dsl
@@ -150,7 +150,6 @@ DefinitionBlock (
 }
 }
 
-#define DSDT_APPLESMC_STA q35_dsdt_applesmc_sta
 #include "acpi-dsdt-isa.dsl"
 
 
-- 
MST




[Qemu-devel] [PULL v3 20/26] pc: acpi-build: drop template patching and create PCI bus tree dynamically

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Replace AML template patching with direct composing
of PCI device entries in C. It allows to simplify
PCI tree generation further and saves us about 400LOC
scattered through different files, confining tree
generation to one C function which is much easier
to deal with.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c   | 235 +
 hw/i386/Makefile.objs  |   1 -
 hw/i386/ssdt-pcihp.dsl | 100 -
 3 files changed, 80 insertions(+), 256 deletions(-)
 delete mode 100644 hw/i386/ssdt-pcihp.dsl

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index ba056f0..b94e47e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -294,26 +294,6 @@ build_header(GArray *linker, GArray *table_data,
 table_data->data, h, len, &h->checksum);
 }
 
-static GArray *build_alloc_method(const char *name, uint8_t arg_count)
-{
-GArray *method = build_alloc_array();
-
-build_append_namestring(method, "%s", name);
-build_append_byte(method, arg_count); /* MethodFlags: ArgCount */
-
-return method;
-}
-
-static void build_append_and_cleanup_method(GArray *device, GArray *method)
-{
-uint8_t op = 0x14; /* MethodOp */
-
-build_package(method, op);
-
-build_append_array(device, method);
-build_free_array(method);
-}
-
 /* End here */
 #define ACPI_PORT_SMI_CMD   0x00b2 /* TODO: this is APM_CNT_IOPORT */
 
@@ -494,71 +474,12 @@ static inline char acpi_get_hex(uint32_t val)
 return (val <= 9) ? ('0' + val) : ('A' + val - 10);
 }
 
-/* 0x5B 0x82 DeviceOp PkgLength NameString */
-#define ACPI_PCIHP_OFFSET_HEX (*ssdt_pcihp_name - *ssdt_pcihp_start + 1)
-#define ACPI_PCIHP_OFFSET_ID (*ssdt_pcihp_id - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_ADR (*ssdt_pcihp_adr - *ssdt_pcihp_start)
-#define ACPI_PCIHP_OFFSET_EJ0 (*ssdt_pcihp_ej0 - *ssdt_pcihp_start)
-#define ACPI_PCIHP_SIZEOF (*ssdt_pcihp_end - *ssdt_pcihp_start)
-#define ACPI_PCIHP_AML (ssdp_pcihp_aml + *ssdt_pcihp_start)
-
-#define ACPI_PCINOHP_OFFSET_HEX (*ssdt_pcinohp_name - *ssdt_pcinohp_start + 1)
-#define ACPI_PCINOHP_OFFSET_ADR (*ssdt_pcinohp_adr - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_SIZEOF (*ssdt_pcinohp_end - *ssdt_pcinohp_start)
-#define ACPI_PCINOHP_AML (ssdp_pcihp_aml + *ssdt_pcinohp_start)
-
-#define ACPI_PCIVGA_OFFSET_HEX (*ssdt_pcivga_name - *ssdt_pcivga_start + 1)
-#define ACPI_PCIVGA_OFFSET_ADR (*ssdt_pcivga_adr - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_SIZEOF (*ssdt_pcivga_end - *ssdt_pcivga_start)
-#define ACPI_PCIVGA_AML (ssdp_pcihp_aml + *ssdt_pcivga_start)
-
-#define ACPI_PCIQXL_OFFSET_HEX (*ssdt_pciqxl_name - *ssdt_pciqxl_start + 1)
-#define ACPI_PCIQXL_OFFSET_ADR (*ssdt_pciqxl_adr - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_SIZEOF (*ssdt_pciqxl_end - *ssdt_pciqxl_start)
-#define ACPI_PCIQXL_AML (ssdp_pcihp_aml + *ssdt_pciqxl_start)
 
 #define ACPI_SSDT_SIGNATURE 0x54445353 /* SSDT */
 #define ACPI_SSDT_HEADER_LENGTH 36
 
-#include "hw/i386/ssdt-pcihp.hex"
 #include "hw/i386/ssdt-tpm.hex"
 
-static void patch_pcihp(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCIHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCIHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIHP_OFFSET_ID] = slot;
-ssdt_ptr[ACPI_PCIHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcinohp(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCINOHP_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCINOHP_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pcivga(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCIVGA_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIVGA_OFFSET_ADR + 2] = slot;
-}
-
-static void patch_pciqxl(int slot, uint8_t *ssdt_ptr)
-{
-unsigned devfn = PCI_DEVFN(slot, 0);
-
-ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX] = acpi_get_hex(devfn >> 4);
-ssdt_ptr[ACPI_PCIQXL_OFFSET_HEX + 1] = acpi_get_hex(devfn);
-ssdt_ptr[ACPI_PCIQXL_OFFSET_ADR + 2] = slot;
-}
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
@@ -590,46 +511,30 @@ static void acpi_set_pci_info(void)
 }
 }
 
-static void build_append_pcihp_notify_entry(GArray *method, int slot)
+static void build_append_pcihp_notify_entry(Aml *method, int slot)
 {
-GArray *ifctx;
-
-ifctx = build_alloc_array();
-build_append_byte(ifctx, 0x7B); /* AndOp */
-build_append_byte(ifctx, 0x68); /* Arg0Op */
-build_append_int(ifctx, 0x1U << slot);
-build_append_byte(ifctx, 0x00); /* NullName */
-build_append_byte(ifctx, 0x86); /* NotifyOp */
-build_appen

[Qemu-devel] [PULL v3 23/26] pci: Give a few helpers internal linkage

2015-03-02 Thread Michael S. Tsirkin
From: Markus Armbruster 

None of them should be used in new code.

Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/pci/pci.h |  7 ---
 hw/pci/pci.c | 14 +++---
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 3164fc3..be2d9b8 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -371,9 +371,6 @@ void pci_device_set_intx_routing_notifier(PCIDevice *dev,
   PCIINTxRoutingNotifier notifier);
 void pci_device_reset(PCIDevice *dev);
 
-PCIDevice *pci_nic_init(NICInfo *nd, PCIBus *rootbus,
-const char *default_model,
-const char *default_devaddr);
 PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
const char *default_model,
const char *default_devaddr);
@@ -403,12 +400,8 @@ PCIBus *pci_device_root_bus(const PCIDevice *d);
 const char *pci_root_bus_path(PCIDevice *dev);
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
-PCIBus *pci_get_bus_devfn(int *devfnp, PCIBus *root, const char *devaddr);
 void pci_bus_get_w64_range(PCIBus *bus, Range *range);
 
-int pci_parse_devaddr(const char *addr, int *domp, int *busp,
-  unsigned int *slotp, unsigned int *funcp);
-
 void pci_device_deassert_intx(PCIDevice *dev);
 
 typedef AddressSpace *(*PCIIOMMUFunc)(PCIBus *, void *, int);
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index b1f3cea..cc5d946 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -539,8 +539,8 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev)
  * Parse [[:]:], return -1 on error if funcp == NULL
  *   [[:]:]., return -1 on error
  */
-int pci_parse_devaddr(const char *addr, int *domp, int *busp,
-  unsigned int *slotp, unsigned int *funcp)
+static int pci_parse_devaddr(const char *addr, int *domp, int *busp,
+ unsigned int *slotp, unsigned int *funcp)
 {
 const char *p;
 char *e;
@@ -598,7 +598,8 @@ int pci_parse_devaddr(const char *addr, int *domp, int 
*busp,
 return 0;
 }
 
-PCIBus *pci_get_bus_devfn(int *devfnp, PCIBus *root, const char *devaddr)
+static PCIBus *pci_get_bus_devfn(int *devfnp, PCIBus *root,
+ const char *devaddr)
 {
 int dom, bus;
 unsigned slot;
@@ -1610,10 +1611,9 @@ static const char * const pci_nic_names[] = {
 };
 
 /* Initialize a PCI NIC.  */
-/* FIXME callers should check for failure, but don't */
-PCIDevice *pci_nic_init(NICInfo *nd, PCIBus *rootbus,
-const char *default_model,
-const char *default_devaddr)
+static PCIDevice *pci_nic_init(NICInfo *nd, PCIBus *rootbus,
+   const char *default_model,
+   const char *default_devaddr)
 {
 const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
 PCIBus *bus;
-- 
MST




[Qemu-devel] [PULL v3 05/26] tpm: Support for TIS selftest done flag

2015-03-02 Thread Michael S. Tsirkin
From: Stefan Berger 

Extend the backend to check whether the TPM_ContinueSelfTest
finished successfully and provide a flag to the TIS front-end
if it successfully finished. The TIS then sets a flag in
all localities in the STS register and keeps it until the next
reset.

Signed-off-by: Stefan Berger 
Acked-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/tpm/tpm_int.h |  1 +
 include/sysemu/tpm_backend.h |  2 +-
 hw/tpm/tpm_passthrough.c | 37 
 hw/tpm/tpm_tis.c | 58 ++--
 4 files changed, 79 insertions(+), 19 deletions(-)

diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h
index 2f582ca..2b35fe2 100644
--- a/hw/tpm/tpm_int.h
+++ b/hw/tpm/tpm_int.h
@@ -62,6 +62,7 @@ struct tpm_resp_hdr {
 
 #define TPM_FAIL  9
 
+#define TPM_ORD_ContinueSelfTest  0x53
 #define TPM_ORD_GetTicks  0xf1
 
 #endif /* TPM_TPM_INT_H */
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 825f33b..540ee25 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -56,7 +56,7 @@ struct TPMBackend {
 QLIST_ENTRY(TPMBackend) list;
 };
 
-typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty);
+typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done);
 
 typedef struct TPMSizedBuffer {
 uint32_t size;
diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
index 2bf3c6f..a94c7c5 100644
--- a/hw/tpm/tpm_passthrough.c
+++ b/hw/tpm/tpm_passthrough.c
@@ -112,14 +112,31 @@ static void tpm_write_fatal_error_response(uint8_t *out, 
uint32_t out_len)
 }
 }
 
+static bool tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len)
+{
+struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in;
+
+if (in_len >= sizeof(*hdr)) {
+return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest);
+}
+
+return false;
+}
+
 static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
 const uint8_t *in, uint32_t in_len,
-uint8_t *out, uint32_t out_len)
+uint8_t *out, uint32_t out_len,
+bool *selftest_done)
 {
 int ret;
+bool is_selftest;
+const struct tpm_resp_hdr *hdr;
 
 tpm_pt->tpm_op_canceled = false;
 tpm_pt->tpm_executing = true;
+*selftest_done = false;
+
+is_selftest = tpm_passthrough_is_selftest(in, in_len);
 
 ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len);
 if (ret != in_len) {
@@ -149,6 +166,11 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState 
*tpm_pt,
  "packet from TPM\n");
 }
 
+if (is_selftest && (ret >= sizeof(struct tpm_resp_hdr))) {
+hdr = (struct tpm_resp_hdr *)out;
+*selftest_done = (be32_to_cpu(hdr->errcode) == 0);
+}
+
 err_exit:
 if (ret < 0) {
 tpm_write_fatal_error_response(out, out_len);
@@ -160,13 +182,15 @@ err_exit:
 }
 
 static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt,
- const TPMLocality *locty_data)
+ const TPMLocality *locty_data,
+ bool *selftest_done)
 {
 return tpm_passthrough_unix_tx_bufs(tpm_pt,
 locty_data->w_buffer.buffer,
 locty_data->w_offset,
 locty_data->r_buffer.buffer,
-locty_data->r_buffer.size);
+locty_data->r_buffer.size,
+selftest_done);
 }
 
 static void tpm_passthrough_worker_thread(gpointer data,
@@ -175,16 +199,19 @@ static void tpm_passthrough_worker_thread(gpointer data,
 TPMPassthruThreadParams *thr_parms = user_data;
 TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(thr_parms->tb);
 TPMBackendCmd cmd = (TPMBackendCmd)data;
+bool selftest_done = false;
 
 DPRINTF("tpm_passthrough: processing command type %d\n", cmd);
 
 switch (cmd) {
 case TPM_BACKEND_CMD_PROCESS_CMD:
 tpm_passthrough_unix_transfer(tpm_pt,
-  thr_parms->tpm_state->locty_data);
+  thr_parms->tpm_state->locty_data,
+  &selftest_done);
 
 thr_parms->recv_data_callback(thr_parms->tpm_state,
-  thr_parms->tpm_state->locty_number);
+  thr_parms->tpm_state->locty_number,
+  selftest_done);
 break;
 case TPM_BACKEND_CMD_INIT:
 case TPM_BACKEND_CMD_END:
diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index a37c7ce..61186c5 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@

[Qemu-devel] [PULL v3 21/26] pc: acpi: remove not used anymore ssdt-[misc|pcihp].hex.generated blobs

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/ssdt-misc.hex.generated  | 139 --
 hw/i386/ssdt-pcihp.hex.generated | 251 ---
 2 files changed, 390 deletions(-)
 delete mode 100644 hw/i386/ssdt-misc.hex.generated
 delete mode 100644 hw/i386/ssdt-pcihp.hex.generated

diff --git a/hw/i386/ssdt-misc.hex.generated b/hw/i386/ssdt-misc.hex.generated
deleted file mode 100644
index 0b77ed4..000
--- a/hw/i386/ssdt-misc.hex.generated
+++ /dev/null
@@ -1,139 +0,0 @@
-static unsigned char acpi_pci64_length[] = {
-0x6f
-};
-static unsigned char acpi_pci32_start[] = {
-0x2f
-};
-static unsigned char acpi_pci64_valid[] = {
-0x43
-};
-static unsigned char ssdp_misc_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0x77,
-0x0,
-0x0,
-0x0,
-0x1,
-0x40,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x53,
-0x55,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x7,
-0x11,
-0x14,
-0x20,
-0x10,
-0x42,
-0x5,
-0x5c,
-0x0,
-0x8,
-0x50,
-0x30,
-0x53,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x30,
-0x45,
-0x5f,
-0xc,
-0x78,
-0x56,
-0x34,
-0x12,
-0x8,
-0x50,
-0x31,
-0x56,
-0x5f,
-0xa,
-0x12,
-0x8,
-0x50,
-0x31,
-0x53,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x50,
-0x31,
-0x45,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x8,
-0x50,
-0x31,
-0x4c,
-0x5f,
-0x11,
-0xb,
-0xa,
-0x8,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0,
-0x0
-};
-static unsigned char acpi_pci64_start[] = {
-0x4d
-};
-static unsigned char acpi_pci64_end[] = {
-0x5e
-};
-static unsigned char acpi_pci32_end[] = {
-0x39
-};
diff --git a/hw/i386/ssdt-pcihp.hex.generated b/hw/i386/ssdt-pcihp.hex.generated
deleted file mode 100644
index 72ffa84..000
--- a/hw/i386/ssdt-pcihp.hex.generated
+++ /dev/null
@@ -1,251 +0,0 @@
-static unsigned char ssdt_pcihp_name[] = {
-0x34
-};
-static unsigned char ssdt_pcivga_end[] = {
-0x99
-};
-static unsigned char ssdt_pcivga_name[] = {
-0x70
-};
-static unsigned char ssdt_pcihp_adr[] = {
-0x45
-};
-static unsigned char ssdt_pcinohp_end[] = {
-0x6d
-};
-static unsigned char ssdt_pcihp_end[] = {
-0x5c
-};
-static unsigned char ssdt_pciqxl_start[] = {
-0x99
-};
-static unsigned char ssdt_pcinohp_name[] = {
-0x5f
-};
-static unsigned char ssdp_pcihp_aml[] = {
-0x53,
-0x53,
-0x44,
-0x54,
-0xc6,
-0x0,
-0x0,
-0x0,
-0x1,
-0x70,
-0x42,
-0x58,
-0x50,
-0x43,
-0x0,
-0x0,
-0x42,
-0x58,
-0x53,
-0x53,
-0x44,
-0x54,
-0x50,
-0x43,
-0x1,
-0x0,
-0x0,
-0x0,
-0x49,
-0x4e,
-0x54,
-0x4c,
-0x15,
-0x11,
-0x13,
-0x20,
-0x10,
-0x41,
-0xa,
-0x5c,
-0x2e,
-0x5f,
-0x53,
-0x42,
-0x5f,
-0x50,
-0x43,
-0x49,
-0x30,
-0x5b,
-0x82,
-0x29,
-0x53,
-0x41,
-0x41,
-0x5f,
-0x8,
-0x5f,
-0x53,
-0x55,
-0x4e,
-0xa,
-0xaa,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x12,
-0x5f,
-0x45,
-0x4a,
-0x30,
-0x1,
-0x50,
-0x43,
-0x45,
-0x4a,
-0x42,
-0x53,
-0x45,
-0x4c,
-0x5f,
-0x53,
-0x55,
-0x4e,
-0x5b,
-0x82,
-0xf,
-0x53,
-0x42,
-0x42,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x5b,
-0x82,
-0x2a,
-0x53,
-0x43,
-0x43,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x31,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x32,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x33,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x5b,
-0x82,
-0x2b,
-0x53,
-0x44,
-0x44,
-0x5f,
-0x8,
-0x5f,
-0x41,
-0x44,
-0x52,
-0xc,
-0x0,
-0x0,
-0xaa,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x31,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x8,
-0x5f,
-0x53,
-0x32,
-0x44,
-0x0,
-0xa4,
-0x0,
-0x14,
-0x9,
-0x5f,
-0x53,
-0x33,
-0x44,
-0x0,
-0xa4,
-0xa,
-0x3
-};
-static unsigned char ssdt_pciqxl_adr[] = {
-0xa6
-};
-static unsigned char ssdt_pcinohp_adr[] = {
-0x69
-};
-static unsigned char ssdt_pcivga_adr[] = {
-0x7a
-};
-static unsigned char ssdt_pciqxl_name[] = {
-0x9c
-};
-static unsigned char ssdt_pcivga_start[] = {
-0x6d
-};
-static unsigned char ssdt_pciqxl_end[] = {
-0xc6
-};
-static unsigned char ssdt_pcihp_start[] = {
-0x31
-};
-static unsigned char ssdt_pcihp_id[] = {
-0x3e
-};
-static unsigned char ssdt_pcinohp_start[] = {
-0x5c
-};
-- 
MST




Re: [Qemu-devel] [PATCH] disas/microblaze: Fix warnings caused by missing 'static' attribute

2015-03-02 Thread Michael Tokarev
01.03.2015 16:18, Stefan Weil wrote:
> Warnings from the Sparse static analysis tool:
[...]
> @@ -738,7 +737,9 @@ get_field_special (long instr, struct op_code_struct * op)
> default :
>   {
> if ( instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask) & 0xE000) 
> == REG_PVR_MASK) {
> -  sprintf(tmpstr, "%spvr%d", register_prefix, (unsigned short)(((instr & 
> IMM_MASK) >> IMM_LOW) ^ op->immval_mask) ^ REG_PVR_MASK);
> +   sprintf(tmpstr, "%s%u", pvr_register_prefix,
> + (unsigned short)(((instr & IMM_MASK) >> IMM_LOW) ^
> +  op->immval_mask) ^ REG_PVR_MASK);

Is this word wrapping intentionally put into this patch or
was it supposed to be a separate patch?

Thanks,

/mjt



[Qemu-devel] [PULL v3 12/26] acpi: add acpi_irq_no_flags() term

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/acpi/aml-build.h |  1 +
 hw/acpi/aml-build.c | 21 +
 2 files changed, 22 insertions(+)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index d2b2c35..1187197 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -146,6 +146,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 uint8_t aln, uint8_t len);
 Aml *aml_operation_region(const char *name, AmlRegionSpace rs,
   uint32_t offset, uint32_t len);
+Aml *aml_irq_no_flags(uint8_t irq);
 Aml *aml_named_field(const char *name, unsigned length);
 Aml *aml_reserved_field(unsigned length);
 Aml *aml_local(int num);
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d793775..60245e7 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -514,6 +514,27 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t 
max_base,
 return var;
 }
 
+/*
+ * ACPI 1.0b: 6.4.2.1.1 ASL Macro for IRQ Descriptor
+ *
+ * More verbose description at:
+ * ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro)
+ *   6.4.2.1 IRQ Descriptor
+ */
+Aml *aml_irq_no_flags(uint8_t irq)
+{
+uint16_t irq_mask;
+Aml *var = aml_alloc();
+
+assert(irq < 16);
+build_append_byte(var->buf, 0x22); /* IRQ descriptor 2 byte form */
+
+irq_mask = 1U << irq;
+build_append_byte(var->buf, irq_mask & 0xFF); /* IRQ mask bits[7:0] */
+build_append_byte(var->buf, irq_mask >> 8); /* IRQ mask bits[15:8] */
+return var;
+}
+
 /* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */
 Aml *aml_equal(Aml *arg1, Aml *arg2)
 {
-- 
MST




[Qemu-devel] [PULL v3 24/26] pci-hotplug-old: Has been dead for five major releases, bury

2015-03-02 Thread Michael S. Tsirkin
From: Markus Armbruster 

Commit 79ca616 (v1.6.0) accidentally disabled legacy x86-only HMP
commands pci_add, pci_del: it defined CONFIG_PCI_HOTPLUG only as make
variable, not as preprocessor macro, killing the code conditional on
defined(CONFIG_PCI_HOTPLUG_OLD).

In all this time, nobody reported the loss.  I only noticed it when I
tried to test some error reporting change that forced me to touch this
old crap again.

Fun: git-log hw/pci/pci-hotplug-old.c shows our faith in the backward
compatibility god has been strong enough to sacrifice at its altar
about a dozen times, but not strong enough to even once verify the
legacy feature's still there, let alone works.

Remove the commands along with the code backing them.

Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/sysemu/blockdev.h  |   2 -
 include/sysemu/sysemu.h|   5 -
 device-hotplug.c   |   7 +-
 hw/pci/pci-hotplug-old.c   | 342 -
 stubs/pci-drive-hot-add.c  |  10 --
 default-configs/i386-softmmu.mak   |   1 -
 default-configs/x86_64-softmmu.mak |   1 -
 hmp-commands.hx|  32 
 hw/pci/Makefile.objs   |   2 -
 stubs/Makefile.objs|   1 -
 10 files changed, 3 insertions(+), 400 deletions(-)
 delete mode 100644 hw/pci/pci-hotplug-old.c
 delete mode 100644 stubs/pci-drive-hot-add.c

diff --git a/include/sysemu/blockdev.h b/include/sysemu/blockdev.h
index 0c62643..7ca59b5 100644
--- a/include/sysemu/blockdev.h
+++ b/include/sysemu/blockdev.h
@@ -63,8 +63,6 @@ DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType 
block_default_type);
 
 /* device-hotplug */
 
-DriveInfo *add_init_drive(const char *opts);
-
 void qmp_change_blockdev(const char *device, const char *filename,
  const char *format, Error **errp);
 void hmp_commit(Monitor *mon, const QDict *qdict);
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 1ab7063..e7135e1 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -174,11 +174,6 @@ extern int nb_option_roms;
 extern const char *prom_envs[MAX_PROM_ENVS];
 extern unsigned int nb_prom_envs;
 
-/* pci-hotplug */
-void hmp_pci_add(Monitor *mon, const QDict *qdict);
-int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo);
-void hmp_pci_del(Monitor *mon, const QDict *qdict);
-
 /* generic hotplug */
 void hmp_drive_add(Monitor *mon, const QDict *qdict);
 
diff --git a/device-hotplug.c b/device-hotplug.c
index 833d874..68b9496 100644
--- a/device-hotplug.c
+++ b/device-hotplug.c
@@ -30,7 +30,7 @@
 #include "sysemu/sysemu.h"
 #include "monitor/monitor.h"
 
-DriveInfo *add_init_drive(const char *optstr)
+static DriveInfo *add_init_drive(const char *optstr)
 {
 DriveInfo *dinfo;
 QemuOpts *opts;
@@ -69,9 +69,8 @@ void hmp_drive_add(Monitor *mon, const QDict *qdict)
 monitor_printf(mon, "OK\n");
 break;
 default:
-if (pci_drive_hot_add(mon, qdict, dinfo)) {
-goto err;
-}
+monitor_printf(mon, "Can't hot-add drive to type %d\n", dinfo->type);
+goto err;
 }
 return;
 
diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
deleted file mode 100644
index beea6d2..000
--- a/hw/pci/pci-hotplug-old.c
+++ /dev/null
@@ -1,342 +0,0 @@
-/*
- * Deprecated PCI hotplug interface support
- * This covers the old pci_add / pci_del command, whereas the more general
- * device_add / device_del commands are now preferred.
- *
- * Copyright (c) 2004 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "hw/hw.h"
-#include "hw/boards.h"
-#include "hw/pci/pci.h"
-#include "net/net.h"
-#include "hw/i386/pc.h"
-#include "monitor/monitor.h"
-#include "hw/scsi/scsi.h"
-#include "hw/virtio/virtio-blk.h"
-#include "qemu/config-file

[Qemu-devel] [PULL v3 16/26] tests: bios-tables-test: add support for testing bridges

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Adds alternative ACPI table blob selection for testing
non default QEMU configurations. If blob file for test
variant is not present, fallback to default blob.

With this change implement testing with a coldplugged
bridge.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 tests/bios-tables-test.c | 45 -
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
index 4d0fa84..735ac61 100644
--- a/tests/bios-tables-test.c
+++ b/tests/bios-tables-test.c
@@ -40,6 +40,7 @@ typedef struct {
 
 typedef struct {
 const char *machine;
+const char *variant;
 uint32_t rsdp_addr;
 AcpiRsdpDescriptor rsdp_table;
 AcpiRsdtDescriptorRev1 rsdt_table;
@@ -396,13 +397,14 @@ static void dump_aml_files(test_data *data, bool rebuild)
 int i;
 
 for (i = 0; i < data->tables->len; ++i) {
+const char *ext = data->variant ? data->variant : "";
 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
 g_assert(sdt->aml);
 
 if (rebuild) {
 uint32_t signature = cpu_to_le32(sdt->header.signature);
-aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine,
-   (gchar *)&signature);
+aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
+   (gchar *)&signature, ext);
 fd = g_open(aml_file, O_WRONLY|O_TRUNC|O_CREAT,
 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
 } else {
@@ -509,7 +511,7 @@ static GArray *load_expected_aml(test_data *data)
 {
 int i;
 AcpiSdtTable *sdt;
-gchar *aml_file;
+gchar *aml_file = NULL;
 GError *error = NULL;
 gboolean ret;
 
@@ -517,6 +519,7 @@ static GArray *load_expected_aml(test_data *data)
 for (i = 0; i < data->tables->len; ++i) {
 AcpiSdtTable exp_sdt;
 uint32_t signature;
+const char *ext = data->variant ? data->variant : "";
 
 sdt = &g_array_index(data->tables, AcpiSdtTable, i);
 
@@ -524,8 +527,15 @@ static GArray *load_expected_aml(test_data *data)
 exp_sdt.header.signature = sdt->header.signature;
 
 signature = cpu_to_le32(sdt->header.signature);
-aml_file = g_strdup_printf("%s/%s/%.4s", data_dir, data->machine,
-   (gchar *)&signature);
+
+try_again:
+aml_file = g_strdup_printf("%s/%s/%.4s%s", data_dir, data->machine,
+   (gchar *)&signature, ext);
+if (data->variant && !g_file_test(aml_file, G_FILE_TEST_EXISTS)) {
+g_free(aml_file);
+ext = "";
+goto try_again;
+}
 exp_sdt.aml_file = aml_file;
 g_assert(g_file_test(aml_file, G_FILE_TEST_EXISTS));
 ret = g_file_get_contents(aml_file, &exp_sdt.aml,
@@ -778,6 +788,17 @@ static void test_acpi_piix4_tcg(void)
 free_test_data(&data);
 }
 
+static void test_acpi_piix4_tcg_bridge(void)
+{
+test_data data;
+
+memset(&data, 0, sizeof(data));
+data.machine = MACHINE_PC;
+data.variant = ".bridge";
+test_acpi_one("-machine accel=tcg -device pci-bridge,chassis_nr=1", &data);
+free_test_data(&data);
+}
+
 static void test_acpi_q35_tcg(void)
 {
 test_data data;
@@ -788,6 +809,18 @@ static void test_acpi_q35_tcg(void)
 free_test_data(&data);
 }
 
+static void test_acpi_q35_tcg_bridge(void)
+{
+test_data data;
+
+memset(&data, 0, sizeof(data));
+data.machine = MACHINE_Q35;
+data.variant = ".bridge";
+test_acpi_one("-machine q35,accel=tcg -device pci-bridge,chassis_nr=1",
+  &data);
+free_test_data(&data);
+}
+
 int main(int argc, char *argv[])
 {
 const char *arch = qtest_get_arch();
@@ -805,7 +838,9 @@ int main(int argc, char *argv[])
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
 qtest_add_func("acpi/piix4/tcg", test_acpi_piix4_tcg);
+qtest_add_func("acpi/piix4/tcg/bridge", test_acpi_piix4_tcg_bridge);
 qtest_add_func("acpi/q35/tcg", test_acpi_q35_tcg);
+qtest_add_func("acpi/q35/tcg/bridge", test_acpi_q35_tcg_bridge);
 }
 ret = g_test_run();
 unlink(disk);
-- 
MST




[Qemu-devel] [PULL v3 18/26] pc: acpi-build: simplify PCI bus tree generation

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

it basicaly does the same as original approach,
* just without bus/notify tables tracking (less obscure)
  which is easier to follow.
* drops unnecessary loops and bitmaps,
  creating devices and notification method in the same loop.
* saves us ~100LOC

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/acpi-build.c | 274 ---
 1 file changed, 85 insertions(+), 189 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 05eb80a..ba056f0 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -112,7 +112,6 @@ typedef struct AcpiPmInfo {
 typedef struct AcpiMiscInfo {
 bool has_hpet;
 bool has_tpm;
-DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
 const unsigned char *dsdt_code;
 unsigned dsdt_size;
 uint16_t pvpanic_port;
@@ -591,74 +590,37 @@ static void acpi_set_pci_info(void)
 }
 }
 
-static void build_pci_bus_state_init(AcpiBuildPciBusHotplugState *state,
- AcpiBuildPciBusHotplugState *parent,
- bool pcihp_bridge_en)
+static void build_append_pcihp_notify_entry(GArray *method, int slot)
 {
-state->parent = parent;
-state->device_table = build_alloc_array();
-state->notify_table = build_alloc_array();
-state->pcihp_bridge_en = pcihp_bridge_en;
+GArray *ifctx;
+
+ifctx = build_alloc_array();
+build_append_byte(ifctx, 0x7B); /* AndOp */
+build_append_byte(ifctx, 0x68); /* Arg0Op */
+build_append_int(ifctx, 0x1U << slot);
+build_append_byte(ifctx, 0x00); /* NullName */
+build_append_byte(ifctx, 0x86); /* NotifyOp */
+build_append_namestring(ifctx, "S%.02X", PCI_DEVFN(slot, 0));
+build_append_byte(ifctx, 0x69); /* Arg1Op */
+
+/* Pack it up */
+build_package(ifctx, 0xA0 /* IfOp */);
+build_append_array(method, ifctx);
+build_free_array(ifctx);
 }
 
-static void build_pci_bus_state_cleanup(AcpiBuildPciBusHotplugState *state)
+static void build_append_pci_bus_devices(GArray *parent_scope, PCIBus *bus,
+ bool pcihp_bridge_en)
 {
-build_free_array(state->device_table);
-build_free_array(state->notify_table);
-}
-
-static void *build_pci_bus_begin(PCIBus *bus, void *parent_state)
-{
-AcpiBuildPciBusHotplugState *parent = parent_state;
-AcpiBuildPciBusHotplugState *child = g_malloc(sizeof *child);
-
-build_pci_bus_state_init(child, parent, parent->pcihp_bridge_en);
-
-return child;
-}
-
-static void build_pci_bus_end(PCIBus *bus, void *bus_state)
-{
-AcpiBuildPciBusHotplugState *child = bus_state;
-AcpiBuildPciBusHotplugState *parent = child->parent;
 GArray *bus_table = build_alloc_array();
-DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX);
-DECLARE_BITMAP(slot_device_present, PCI_SLOT_MAX);
-DECLARE_BITMAP(slot_device_system, PCI_SLOT_MAX);
-DECLARE_BITMAP(slot_device_vga, PCI_SLOT_MAX);
-DECLARE_BITMAP(slot_device_qxl, PCI_SLOT_MAX);
-uint8_t op;
-int i;
+GArray *method = NULL;
 QObject *bsel;
-GArray *method;
-bool bus_hotplug_support = false;
-
-/*
- * Skip bridge subtree creation if bridge hotplug is disabled
- * to make acpi tables compatible with legacy machine types.
- * Skip creation for hotplugged bridges as well.
- */
-if (bus->parent_dev && (!child->pcihp_bridge_en ||
-DEVICE(bus->parent_dev)->hotplugged)) {
-build_free_array(bus_table);
-build_pci_bus_state_cleanup(child);
-g_free(child);
-return;
-}
+PCIBus *sec;
+int i;
 
 if (bus->parent_dev) {
-op = 0x82; /* DeviceOp */
-build_append_namestring(bus_table, "S%.02X",
- bus->parent_dev->devfn);
-build_append_byte(bus_table, 0x08); /* NameOp */
-build_append_namestring(bus_table, "_SUN");
-build_append_int(bus_table, PCI_SLOT(bus->parent_dev->devfn));
-build_append_byte(bus_table, 0x08); /* NameOp */
-build_append_namestring(bus_table, "_ADR");
-build_append_int(bus_table, (PCI_SLOT(bus->parent_dev->devfn) << 16) |
-   PCI_FUNC(bus->parent_dev->devfn));
+build_append_namestring(bus_table, "S%.02X_", bus->parent_dev->devfn);
 } else {
-op = 0x10; /* ScopeOp */;
 build_append_namestring(bus_table, "PCI0");
 }
 
@@ -667,29 +629,28 @@ static void build_pci_bus_end(PCIBus *bus, void 
*bus_state)
 build_append_byte(bus_table, 0x08); /* NameOp */
 build_append_namestring(bus_table, "BSEL");
 build_append_int(bus_table, qint_get_int(qobject_to_qint(bsel)));
-memset(slot_hotplug_enable, 0xff, sizeof slot_hotplug_enable);
-} else {
-/* No bsel - no slots are hot-pluggable */
-memset(slot_hotplug_enable, 0x00, sizeof slot_hot

[Qemu-devel] [PULL v3 19/26] tests: ACPI: update pc/SSDT.bridge due to new alg of PCI tree creation

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 tests/acpi-test-data/pc/SSDT.bridge | Bin 4352 -> 4351 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)

diff --git a/tests/acpi-test-data/pc/SSDT.bridge 
b/tests/acpi-test-data/pc/SSDT.bridge
index 
b807ac92dde72719fe3861c710b555fe3dd62583..ca7f63cb4e48bd95418f68daf1b7e254d5bcf8c2
 100644
GIT binary patch
delta 79
zcmZor`me|p9PASEUx0yu@ybT7Xhue_&1sCDjEoMGH!yjL@dq1P#B;vA+>;M#S6CwZr

-- 
MST




[Qemu-devel] [PULL v3 22/26] acpi: make build_*() routines static to aml-build.c

2015-03-02 Thread Michael S. Tsirkin
From: Igor Mammedov 

build_*() routines were used for composing AML
structures manually in acpi-build.c but after
conversion to AML API they are not used outside
of aml-build.c anymore, so hide them from external
users.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/acpi/aml-build.h | 16 
 hw/acpi/aml-build.c | 20 ++--
 2 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h
index 1187197..f6735ea 100644
--- a/include/hw/acpi/aml-build.h
+++ b/include/hw/acpi/aml-build.h
@@ -188,20 +188,4 @@ Aml *aml_resource_template(void);
 Aml *aml_field(const char *name, AmlFieldFlags flags);
 Aml *aml_varpackage(uint32_t num_elements);
 
-/* other helpers */
-GArray *build_alloc_array(void);
-void build_free_array(GArray *array);
-void build_prepend_byte(GArray *array, uint8_t val);
-void build_append_byte(GArray *array, uint8_t val);
-void build_append_array(GArray *array, GArray *val);
-
-void GCC_FMT_ATTR(2, 3)
-build_append_namestring(GArray *array, const char *format, ...);
-
-void
-build_prepend_package_length(GArray *package, unsigned length, bool incl_self);
-void build_package(GArray *package, uint8_t op);
-void build_append_int(GArray *table, uint64_t value);
-void build_extop_package(GArray *package, uint8_t op);
-
 #endif
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 60245e7..3e5949b 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -27,27 +27,27 @@
 #include "hw/acpi/aml-build.h"
 #include "qemu/bswap.h"
 
-GArray *build_alloc_array(void)
+static GArray *build_alloc_array(void)
 {
 return g_array_new(false, true /* clear */, 1);
 }
 
-void build_free_array(GArray *array)
+static void build_free_array(GArray *array)
 {
 g_array_free(array, true);
 }
 
-void build_prepend_byte(GArray *array, uint8_t val)
+static void build_prepend_byte(GArray *array, uint8_t val)
 {
 g_array_prepend_val(array, val);
 }
 
-void build_append_byte(GArray *array, uint8_t val)
+static void build_append_byte(GArray *array, uint8_t val)
 {
 g_array_append_val(array, val);
 }
 
-void build_append_array(GArray *array, GArray *val)
+static void build_append_array(GArray *array, GArray *val)
 {
 g_array_append_vals(array, val->data, val->len);
 }
@@ -141,7 +141,7 @@ build_append_namestringv(GArray *array, const char *format, 
va_list ap)
 g_strfreev(segs);
 }
 
-void build_append_namestring(GArray *array, const char *format, ...)
+static void build_append_namestring(GArray *array, const char *format, ...)
 {
 va_list ap;
 
@@ -158,7 +158,7 @@ enum {
 PACKAGE_LENGTH_4BYTE_SHIFT = 20,
 };
 
-void
+static void
 build_prepend_package_length(GArray *package, unsigned length, bool incl_self)
 {
 uint8_t byte;
@@ -226,13 +226,13 @@ build_append_pkg_length(GArray *array, unsigned length, 
bool incl_self)
 build_free_array(tmp);
 }
 
-void build_package(GArray *package, uint8_t op)
+static void build_package(GArray *package, uint8_t op)
 {
 build_prepend_package_length(package, package->len, true);
 build_prepend_byte(package, op);
 }
 
-void build_extop_package(GArray *package, uint8_t op)
+static void build_extop_package(GArray *package, uint8_t op)
 {
 build_package(package, op);
 build_prepend_byte(package, 0x5B); /* ExtOpPrefix */
@@ -248,7 +248,7 @@ static void build_append_int_noprefix(GArray *table, 
uint64_t value, int size)
 }
 }
 
-void build_append_int(GArray *table, uint64_t value)
+static void build_append_int(GArray *table, uint64_t value)
 {
 if (value == 0x00) {
 build_append_byte(table, 0x00); /* ZeroOp */
-- 
MST




[Qemu-devel] [PULL v3 25/26] acpi, mem-hotplug: use PC_DIMM_SLOT_PROP in acpi_memory_plug_cb().

2015-03-02 Thread Michael S. Tsirkin
From: Tang Chen 

Replace string "slot" in acpi_memory_plug_cb() with macro PC_DIMM_SLOT_PROP.

Reviewed-by: Igor Mammedov 
Signed-off-by: Tang Chen 
Signed-off-by: Zhu Guihua 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/acpi/memory_hotplug.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/acpi/memory_hotplug.c b/hw/acpi/memory_hotplug.c
index ed39241..c6580da 100644
--- a/hw/acpi/memory_hotplug.c
+++ b/hw/acpi/memory_hotplug.c
@@ -168,7 +168,8 @@ void acpi_memory_plug_cb(ACPIREGS *ar, qemu_irq irq, 
MemHotplugState *mem_st,
 {
 MemStatus *mdev;
 Error *local_err = NULL;
-int slot = object_property_get_int(OBJECT(dev), "slot", &local_err);
+int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP,
+   &local_err);
 
 if (local_err) {
 error_propagate(errp, local_err);
-- 
MST




[Qemu-devel] [PULL v3 26/26] acpi-test-data: update after pci rewrite

2015-03-02 Thread Michael S. Tsirkin
more trivial changes as more code has been rewritten in C.
we also got rid of extra Scope operators.

Signed-off-by: Michael S. Tsirkin 
---
 tests/acpi-test-data/pc/SSDT | Bin 2480 -> 2476 bytes
 tests/acpi-test-data/pc/SSDT.bridge  | Bin 4351 -> 4335 bytes
 tests/acpi-test-data/q35/SSDT| Bin 685 -> 681 bytes
 tests/acpi-test-data/q35/SSDT.bridge | Bin 702 -> 698 bytes
 4 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/tests/acpi-test-data/pc/SSDT b/tests/acpi-test-data/pc/SSDT
index 
dc5be2497b6c2015d7cbabb1ff0cd13e02b3e0e4..87c3e9fc0271f2b5826877a9f931c2428838f8a7
 100644
GIT binary patch
delta 56
zcmdlWyhfNSIM^j*4JQKwBj-l0Xhuf&&1sCDj1s>20nVNV98STmJ`B-K+`$G0@f`7v
MEWdtGD<%UaP~Cda0+(yVTf+x4>mA}=ZJT7
z3F2X3V3>TIN#B@1*w6wl#LOVzT?Q5aX<&?Q(u8OT4)x<=KmywwqxGN
F3jplmASnO<

diff --git a/tests/acpi-test-data/q35/SSDT b/tests/acpi-test-data/q35/SSDT
index 
749f368e3034bfb491dcd8ced37936e0dcbba02a..6a5c0423b93dd9eda038dc4fd4af283f6bba9745
 100644
GIT binary patch
delta 49
zcmZ3>x{{SEIM^j*B@+V!g3b

delta 53
zcmZ3g3b

diff --git a/tests/acpi-test-data/q35/SSDT.bridge 
b/tests/acpi-test-data/q35/SSDT.bridge
index 
c552782f5bcc57094a7d1375b67979b2efa48f1c..5fc83a034002df64500970fa64f07b58bc15f3ea
 100644
GIT binary patch
delta 49
zcmdnTx{H-7IM^j*7ZU>mW86kAenv*e%~Fh>j6&|L0nVNV(M{aJ1_tpQ@s2J*lPj5A
E0V{qC0

delta 53
zcmdnRx{sABIM^j*9}@!uqtiw%env*u%~Fh>jAGub0nVNV(M|lp1_tpQ@s2J*JPZsB
IlS`Rg0aS_%0

-- 
MST




Re: [Qemu-devel] [PATCH] disas/microblaze: Fix warnings caused by missing 'static' attribute

2015-03-02 Thread Stefan Weil
Am 02.03.2015 um 12:04 schrieb Michael Tokarev:
> 01.03.2015 16:18, Stefan Weil wrote:
>> Warnings from the Sparse static analysis tool:
> [...]
>> @@ -738,7 +737,9 @@ get_field_special (long instr, struct op_code_struct * 
>> op)
>> default :
>>   {
>> if ( instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask) & 0xE000) 
>> == REG_PVR_MASK) {
>> - sprintf(tmpstr, "%spvr%d", register_prefix, (unsigned short)(((instr & 
>> IMM_MASK) >> IMM_LOW) ^ op->immval_mask) ^ REG_PVR_MASK);
>> +  sprintf(tmpstr, "%s%u", pvr_register_prefix,
>> + (unsigned short)(((instr & IMM_MASK) >> IMM_LOW) ^
>> +  op->immval_mask) ^ REG_PVR_MASK);
> Is this word wrapping intentionally put into this patch or
> was it supposed to be a separate patch?
>
> Thanks,
>
> /mjt

It's part of the fix ("%spvr%d", register_prefix was replaced by "%s%u",
pvr_register_prefix).

The wrapping was needed to satisfy codecheck.pl.

Stefan




[Qemu-devel] [PATCH 0/4] block: Convert bdrv_find to blk_by_name and drop it

2015-03-02 Thread Fam Zheng
This is a small step towards a more complete separation from BlockDriverState
to block backend users.

Fam Zheng (4):
  monitor: Convert bdrv_find to blk_by_name
  migration: Convert bdrv_find to blk_by_name
  blockdev: Convert bdrv_find to blk_by_name
  block: Drop bdrv_find

 block.c   |  9 -
 blockdev.c| 92 +--
 include/block/block.h |  1 -
 migration/block.c |  7 ++--
 monitor.c |  9 ++---
 5 files changed, 69 insertions(+), 49 deletions(-)

-- 
1.9.3




[Qemu-devel] [PATCH 2/4] migration: Convert bdrv_find to blk_by_name

2015-03-02 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 migration/block.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/migration/block.c b/migration/block.c
index 0c76106..085c0fa 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -23,6 +23,7 @@
 #include "migration/block.h"
 #include "migration/migration.h"
 #include "sysemu/blockdev.h"
+#include "sysemu/block-backend.h"
 #include 
 
 #define BLOCK_SIZE   (1 << 20)
@@ -783,6 +784,7 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 char device_name[256];
 int64_t addr;
 BlockDriverState *bs, *bs_prev = NULL;
+BlockBackend *blk;
 uint8_t *buf;
 int64_t total_sectors = 0;
 int nr_sectors;
@@ -800,12 +802,13 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 qemu_get_buffer(f, (uint8_t *)device_name, len);
 device_name[len] = '\0';
 
-bs = bdrv_find(device_name);
-if (!bs) {
+blk = blk_by_name(device_name);
+if (!blk) {
 fprintf(stderr, "Error unknown block device %s\n",
 device_name);
 return -EINVAL;
 }
+bs = blk_bs(blk);
 
 if (bs != bs_prev) {
 bs_prev = bs;
-- 
1.9.3




[Qemu-devel] [PATCH 1/4] monitor: Convert bdrv_find to blk_by_name

2015-03-02 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 monitor.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 41900da..6ad777d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -72,6 +72,7 @@
 #include "block/qapi.h"
 #include "qapi/qmp-event.h"
 #include "qapi-event.h"
+#include "sysemu/block-backend.h"
 
 /* for hmp_info_irq/pic */
 #if defined(TARGET_SPARC)
@@ -5413,15 +5414,15 @@ int monitor_read_block_device_key(Monitor *mon, const 
char *device,
   BlockCompletionFunc *completion_cb,
   void *opaque)
 {
-BlockDriverState *bs;
+BlockBackend *blk;
 
-bs = bdrv_find(device);
-if (!bs) {
+blk = blk_by_name(device);
+if (!blk) {
 monitor_printf(mon, "Device not found %s\n", device);
 return -1;
 }
 
-return monitor_read_bdrv_key_start(mon, bs, completion_cb, opaque);
+return monitor_read_bdrv_key_start(mon, blk_bs(blk), completion_cb, 
opaque);
 }
 
 QemuOptsList qemu_mon_opts = {
-- 
1.9.3




[Qemu-devel] [PATCH 3/4] blockdev: Convert bdrv_find to blk_by_name

2015-03-02 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 blockdev.c | 92 --
 1 file changed, 59 insertions(+), 33 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index ae73539..c70d849 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1017,18 +1017,18 @@ fail:
 void hmp_commit(Monitor *mon, const QDict *qdict)
 {
 const char *device = qdict_get_str(qdict, "device");
-BlockDriverState *bs;
+BlockBackend *blk;
 int ret;
 
 if (!strcmp(device, "all")) {
 ret = bdrv_commit_all();
 } else {
-bs = bdrv_find(device);
-if (!bs) {
+blk = blk_by_name(device);
+if (!blk) {
 monitor_printf(mon, "Device '%s' not found\n", device);
 return;
 }
-ret = bdrv_commit(bs);
+ret = bdrv_commit(blk_bs(blk));
 }
 if (ret < 0) {
 monitor_printf(mon, "'commit' error for '%s': %s\n", device,
@@ -1093,17 +1093,20 @@ SnapshotInfo 
*qmp_blockdev_snapshot_delete_internal_sync(const char *device,
  const char *name,
  Error **errp)
 {
-BlockDriverState *bs = bdrv_find(device);
+BlockDriverState *bs;
+BlockBackend *blk;
 AioContext *aio_context;
 QEMUSnapshotInfo sn;
 Error *local_err = NULL;
 SnapshotInfo *info = NULL;
 int ret;
 
-if (!bs) {
+blk = blk_by_name(device);
+if (!blk) {
 error_set(errp, QERR_DEVICE_NOT_FOUND, device);
 return NULL;
 }
+bs = blk_bs(blk);
 
 if (!has_id) {
 id = NULL;
@@ -1206,6 +1209,7 @@ static void internal_snapshot_prepare(BlkTransactionState 
*common,
 Error *local_err = NULL;
 const char *device;
 const char *name;
+BlockBackend *blk;
 BlockDriverState *bs;
 QEMUSnapshotInfo old_sn, *sn;
 bool ret;
@@ -1224,11 +1228,12 @@ static void 
internal_snapshot_prepare(BlkTransactionState *common,
 name = internal->name;
 
 /* 2. check for validation */
-bs = bdrv_find(device);
-if (!bs) {
+blk = blk_by_name(device);
+if (!blk) {
 error_set(errp, QERR_DEVICE_NOT_FOUND, device);
 return;
 }
+bs = blk_bs(blk);
 
 /* AioContext is released in .clean() */
 state->aio_context = bdrv_get_aio_context(bs);
@@ -1495,17 +1500,19 @@ static void drive_backup_prepare(BlkTransactionState 
*common, Error **errp)
 {
 DriveBackupState *state = DO_UPCAST(DriveBackupState, common, common);
 BlockDriverState *bs;
+BlockBackend *blk;
 DriveBackup *backup;
 Error *local_err = NULL;
 
 assert(common->action->kind == TRANSACTION_ACTION_KIND_DRIVE_BACKUP);
 backup = common->action->drive_backup;
 
-bs = bdrv_find(backup->device);
-if (!bs) {
+blk = blk_by_name(backup->device);
+if (!blk) {
 error_set(errp, QERR_DEVICE_NOT_FOUND, backup->device);
 return;
 }
+bs = blk_bs(blk);
 
 /* AioContext is released in .clean() */
 state->aio_context = bdrv_get_aio_context(bs);
@@ -1560,22 +1567,25 @@ static void blockdev_backup_prepare(BlkTransactionState 
*common, Error **errp)
 BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, 
common);
 BlockdevBackup *backup;
 BlockDriverState *bs, *target;
+BlockBackend *blk;
 Error *local_err = NULL;
 
 assert(common->action->kind == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP);
 backup = common->action->blockdev_backup;
 
-bs = bdrv_find(backup->device);
-if (!bs) {
+blk = blk_by_name(backup->device);
+if (!blk) {
 error_set(errp, QERR_DEVICE_NOT_FOUND, backup->device);
 return;
 }
+bs = blk_bs(blk);
 
-target = bdrv_find(backup->target);
-if (!target) {
+blk = blk_by_name(backup->target);
+if (!blk) {
 error_set(errp, QERR_DEVICE_NOT_FOUND, backup->target);
 return;
 }
+target = blk_bs(blk);
 
 /* AioContext is released in .clean() */
 state->aio_context = bdrv_get_aio_context(bs);
@@ -1882,13 +1892,15 @@ void qmp_block_set_io_throttle(const char *device, 
int64_t bps, int64_t bps_rd,
 {
 ThrottleConfig cfg;
 BlockDriverState *bs;
+BlockBackend *blk;
 AioContext *aio_context;
 
-bs = bdrv_find(device);
-if (!bs) {
+blk = blk_by_name(device);
+if (!blk) {
 error_set(errp, QERR_DEVICE_NOT_FOUND, device);
 return;
 }
+bs = blk_bs(blk);
 
 memset(&cfg, 0, sizeof(cfg));
 cfg.buckets[THROTTLE_BPS_TOTAL].avg = bps;
@@ -2092,6 +2104,7 @@ void qmp_block_stream(const char *device,
   bool has_on_error, BlockdevOnError on_error,
   Error **errp)
 {
+BlockBackend *blk;
 BlockDriverState *bs;
 BlockDriverState *base_bs = NULL;
 AioContext *aio_context;
@@ -2102,11 +2115,12 @@ void qmp_block_stream(const char *device,
 on_error = BLOCKDEV_ON_ERROR_REPORT;
 }
 
-

[Qemu-devel] [PATCH 4/4] block: Drop bdrv_find

2015-03-02 Thread Fam Zheng
All callers are converted, so drop it.

Signed-off-by: Fam Zheng 
---
 block.c   | 9 -
 include/block/block.h | 1 -
 2 files changed, 10 deletions(-)

diff --git a/block.c b/block.c
index 9b707e3..742f82c 100644
--- a/block.c
+++ b/block.c
@@ -3780,15 +3780,6 @@ void bdrv_iterate_format(void (*it)(void *opaque, const 
char *name),
 g_free(formats);
 }
 
-/* This function is to find block backend bs */
-/* TODO convert callers to blk_by_name(), then remove */
-BlockDriverState *bdrv_find(const char *name)
-{
-BlockBackend *blk = blk_by_name(name);
-
-return blk ? blk_bs(blk) : NULL;
-}
-
 /* This function is to find a node in the bs graph */
 BlockDriverState *bdrv_find_node(const char *node_name)
 {
diff --git a/include/block/block.h b/include/block/block.h
index 471d11d..2c121a5 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -370,7 +370,6 @@ int bdrv_media_changed(BlockDriverState *bs);
 void bdrv_lock_medium(BlockDriverState *bs, bool locked);
 void bdrv_eject(BlockDriverState *bs, bool eject_flag);
 const char *bdrv_get_format_name(BlockDriverState *bs);
-BlockDriverState *bdrv_find(const char *name);
 BlockDriverState *bdrv_find_node(const char *node_name);
 BlockDeviceInfoList *bdrv_named_nodes_list(void);
 BlockDriverState *bdrv_lookup_bs(const char *device,
-- 
1.9.3




[Qemu-devel] [PATCH 2/2] virtio-pci: switch to modern accessors for 1.0

2015-03-02 Thread Michael S. Tsirkin
virtio 1.0 config space is in LE format for all
devices, use modern wrappers when accessed through
the 1.0 BAR.

Reported-by: Rusty Russell 
Signed-off-by: Michael S. Tsirkin 
---
 hw/virtio/virtio-pci.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 4c9a0b8..49ea7fc 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1198,13 +1198,13 @@ static uint64_t virtio_pci_device_read(void *opaque, 
hwaddr addr,
 
 switch (size) {
 case 1:
-val = virtio_config_readb(vdev, addr);
+val = virtio_config_modern_readb(vdev, addr);
 break;
 case 2:
-val = virtio_config_readw(vdev, addr);
+val = virtio_config_modern_readw(vdev, addr);
 break;
 case 4:
-val = virtio_config_readl(vdev, addr);
+val = virtio_config_modern_readl(vdev, addr);
 break;
 }
 return val;
@@ -1216,13 +1216,13 @@ static void virtio_pci_device_write(void *opaque, 
hwaddr addr,
 VirtIODevice *vdev = opaque;
 switch (size) {
 case 1:
-virtio_config_writeb(vdev, addr, val);
+virtio_config_modern_writeb(vdev, addr, val);
 break;
 case 2:
-virtio_config_writew(vdev, addr, val);
+virtio_config_modern_writew(vdev, addr, val);
 break;
 case 4:
-virtio_config_writel(vdev, addr, val);
+virtio_config_modern_writel(vdev, addr, val);
 break;
 }
 }
-- 
MST




[Qemu-devel] [PATCH 1/2] virtio: add modern config accessors

2015-03-02 Thread Michael S. Tsirkin
virtio 1.0 defines config space as LE,
as opposed to pre-1.0 which was native endian.

Add API for transports to execute word/dword accesses in
little endian format - will be useful for mmio
and pci (byte access is also wrapped, for completeness).

For simplicity, we still keep config in host native
endian format, byteswap to LE on guest access.

Signed-off-by: Michael S. Tsirkin 
---
 include/hw/virtio/virtio.h |  6 +++
 hw/virtio/virtio.c | 93 ++
 2 files changed, 99 insertions(+)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index df09993..7a6a9d1 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -227,6 +227,12 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t 
addr);
 void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data);
 void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data);
 void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data);
+uint32_t virtio_config_modern_readb(VirtIODevice *vdev, uint32_t addr);
+uint32_t virtio_config_modern_readw(VirtIODevice *vdev, uint32_t addr);
+uint32_t virtio_config_modern_readl(VirtIODevice *vdev, uint32_t addr);
+void virtio_config_modern_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t 
data);
+void virtio_config_modern_writew(VirtIODevice *vdev, uint32_t addr, uint32_t 
data);
+void virtio_config_modern_writel(VirtIODevice *vdev, uint32_t addr, uint32_t 
data);
 void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);
 hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);
 void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 75abc1f..b098f44 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -729,6 +729,99 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t 
addr, uint32_t data)
 }
 }
 
+uint32_t virtio_config_modern_readb(VirtIODevice *vdev, uint32_t addr)
+{
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+uint8_t val;
+
+if (addr + sizeof(val) > vdev->config_len) {
+return (uint32_t)-1;
+}
+
+k->get_config(vdev, vdev->config);
+
+val = ldub_p(vdev->config + addr);
+return val;
+}
+
+uint32_t virtio_config_modern_readw(VirtIODevice *vdev, uint32_t addr)
+{
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+uint16_t val;
+
+if (addr + sizeof(val) > vdev->config_len) {
+return (uint32_t)-1;
+}
+
+k->get_config(vdev, vdev->config);
+
+val = lduw_le_p(vdev->config + addr);
+return val;
+}
+
+uint32_t virtio_config_modern_readl(VirtIODevice *vdev, uint32_t addr)
+{
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+uint32_t val;
+
+if (addr + sizeof(val) > vdev->config_len) {
+return (uint32_t)-1;
+}
+
+k->get_config(vdev, vdev->config);
+
+val = ldl_le_p(vdev->config + addr);
+return val;
+}
+
+void virtio_config_modern_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t 
data)
+{
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+uint8_t val = data;
+
+if (addr + sizeof(val) > vdev->config_len) {
+return;
+}
+
+stb_p(vdev->config + addr, val);
+
+if (k->set_config) {
+k->set_config(vdev, vdev->config);
+}
+}
+
+void virtio_config_modern_writew(VirtIODevice *vdev, uint32_t addr, uint32_t 
data)
+{
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+uint16_t val = data;
+
+if (addr + sizeof(val) > vdev->config_len) {
+return;
+}
+
+stw_le_p(vdev->config + addr, val);
+
+if (k->set_config) {
+k->set_config(vdev, vdev->config);
+}
+}
+
+void virtio_config_modern_writel(VirtIODevice *vdev, uint32_t addr, uint32_t 
data)
+{
+VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
+uint32_t val = data;
+
+if (addr + sizeof(val) > vdev->config_len) {
+return;
+}
+
+stl_le_p(vdev->config + addr, val);
+
+if (k->set_config) {
+k->set_config(vdev, vdev->config);
+}
+}
+
 void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
 {
 vdev->vq[n].vring.desc = addr;
-- 
MST




Re: [Qemu-devel] Qemu and virtio 1.0

2015-03-02 Thread Michael S. Tsirkin
On Wed, Feb 25, 2015 at 02:50:22PM +1030, Rusty Russell wrote:
> OK, I am trying to experiment with virtio 1.0 support using the
> latest kernel and MST's qemu tree:
> 
> https://git.kernel.org/cgit/virt/kvm/mst/qemu.git/?h=virtio-1.0
> 
> The first issue is that the device config endian was wrong (see
> attached patch).
> 
> I'm now setting up a BE guest on my x86 laptop, and a BE and LE guest
> on a BE powerpc machine, to check that all combinations work correctly.
> If others test too, that would be appreciated!
> 
> Cheers,
> Rusty.

Thanks a lot for finding this!
The issue is certainly there, though I think looking
at guest features is not the right thing to do:
drivers can access config before acking features.

At least for PCI, it's very simple: we have a
separate memory region for modern devices, we
should just use a different accessor, not virtio_config_readw
and friends.

Untested patch sent (sorry about the untested part, a bit busy right now).


> >From 95ac91554ed602f856a2a5fcc25eaffcad1b1c8d Mon Sep 17 00:00:00 2001
> From: Rusty Russell 
> Date: Tue, 24 Feb 2015 14:47:44 +1030
> Subject: [PATCH] virtio_config_write*/virtio_config_read*: Don't endian swap
>  for virtio 1.0.
> 
> Signed-off-by: Rusty Russell 
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 079944c..882a31b 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -662,7 +662,12 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, 
> uint32_t addr)
>  
>  k->get_config(vdev, vdev->config);
>  
> -val = lduw_p(vdev->config + addr);
> +/* Virtio 1.0 is always LE */
> +if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
> +val = lduw_le_p(vdev->config + addr);
> +} else {
> +val = lduw_p(vdev->config + addr);
> +}
>  return val;
>  }
>  
> @@ -677,7 +682,12 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, 
> uint32_t addr)
>  
>  k->get_config(vdev, vdev->config);
>  
> -val = ldl_p(vdev->config + addr);
> +/* Virtio 1.0 is always LE */
> +if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
> +val = ldl_le_p(vdev->config + addr);
> +} else {
> +val = ldl_p(vdev->config + addr);
> +}
>  return val;
>  }
>  
> @@ -706,7 +716,12 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t 
> addr, uint32_t data)
>  return;
>  }
>  
> -stw_p(vdev->config + addr, val);
> +/* Virtio 1.0 is always LE */
> +if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
> +stw_le_p(vdev->config + addr, val);
> +} else {
> +stw_p(vdev->config + addr, val);
> +}
>  
>  if (k->set_config) {
>  k->set_config(vdev, vdev->config);
> @@ -722,7 +737,12 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t 
> addr, uint32_t data)
>  return;
>  }
>  
> -stl_p(vdev->config + addr, val);
> +/* Virtio 1.0 is always LE */
> +if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) {
> +stl_le_p(vdev->config + addr, val);
> +} else {
> +stl_p(vdev->config + addr, val);
> +}
>  
>  if (k->set_config) {
>  k->set_config(vdev, vdev->config);



Re: [Qemu-devel] [PATCH 1/2] virtio: add modern config accessors

2015-03-02 Thread Cornelia Huck
On Mon, 2 Mar 2015 12:40:25 +0100
"Michael S. Tsirkin"  wrote:

> virtio 1.0 defines config space as LE,
> as opposed to pre-1.0 which was native endian.
> 
> Add API for transports to execute word/dword accesses in
> little endian format - will be useful for mmio
> and pci (byte access is also wrapped, for completeness).
> 
> For simplicity, we still keep config in host native
> endian format, byteswap to LE on guest access.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  include/hw/virtio/virtio.h |  6 +++
>  hw/virtio/virtio.c | 93 
> ++
>  2 files changed, 99 insertions(+)

One could also imagine making the accessors dependant on whether the
provided virtio device is standard compliant, but as mmio will probably
register different MemoryRegionOps for v1.0 devices as well, this
should work out nicer this way.

Reviewed-by: Cornelia Huck 




Re: [Qemu-devel] [PATCH 2/2] virtio-pci: switch to modern accessors for 1.0

2015-03-02 Thread Cornelia Huck
On Mon, 2 Mar 2015 12:40:28 +0100
"Michael S. Tsirkin"  wrote:

> virtio 1.0 config space is in LE format for all
> devices, use modern wrappers when accessed through
> the 1.0 BAR.
> 
> Reported-by: Rusty Russell 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  hw/virtio/virtio-pci.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)

Not that I'm deeply familiar with pci :), but this looks good to me.

(This is on top of your pci branch, btw?)




Re: [Qemu-devel] Qemu and virtio 1.0

2015-03-02 Thread Cornelia Huck
On Mon, 2 Mar 2015 12:43:43 +0100
"Michael S. Tsirkin"  wrote:

> On Wed, Feb 25, 2015 at 02:50:22PM +1030, Rusty Russell wrote:
> > OK, I am trying to experiment with virtio 1.0 support using the
> > latest kernel and MST's qemu tree:
> > 
> > https://git.kernel.org/cgit/virt/kvm/mst/qemu.git/?h=virtio-1.0
> > 
> > The first issue is that the device config endian was wrong (see
> > attached patch).
> > 
> > I'm now setting up a BE guest on my x86 laptop, and a BE and LE guest
> > on a BE powerpc machine, to check that all combinations work correctly.
> > If others test too, that would be appreciated!
> > 
> > Cheers,
> > Rusty.
> 
> Thanks a lot for finding this!
> The issue is certainly there, though I think looking
> at guest features is not the right thing to do:
> drivers can access config before acking features.

Ah right. I'm just wondering what the device-specific accessors (in net
and so on) will do?




Re: [Qemu-devel] [PATCH 1/1] scsi-hd: fix property unset case

2015-03-02 Thread Markus Armbruster
Ekaterina Tumanova  writes:

> On 03/02/2015 11:46 AM, Markus Armbruster wrote:
>> Ekaterina Tumanova  writes:
>>
>>> check conf.blk before calling blkconf_blocksizes
>>>
>>> Signed-off-by: Ekaterina Tumanova 
>>> ---
>>>   hw/scsi/scsi-disk.c | 4 +++-
>>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
>>> index 2921728..df5140e 100644
>>> --- a/hw/scsi/scsi-disk.c
>>> +++ b/hw/scsi/scsi-disk.c
>>> @@ -2291,7 +2291,9 @@ static void scsi_realize(SCSIDevice *dev, Error 
>>> **errp)
>>>   static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
>>>   {
>>>   SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
>>> -blkconf_blocksizes(&s->qdev.conf);
>>> +if (s->qdev.conf.blk) {
>>> +blkconf_blocksizes(&s->qdev.conf);
>>> +}
>>
>> Looks suspicious on first glance, because block device model realize()
>> methods are supposed to fail when the backend is missing.  But...
>>
>
> it will properly fail in scsi_realize
>
>>>   s->qdev.blocksize = s->qdev.conf.logical_block_size;
>>>   s->qdev.type = TYPE_DISK;
>>>   if (!s->product) {
>> s->product = g_strdup("QEMU HARDDISK");
>> }
>> scsi_realize(&s->qdev, errp);
>>
>> ... scsi_realize() errors out then.  Worth a comment.  Or maybe call
>> blkconf_blocksizes() only after scsi_realize().  Your choice.
>
> can't call it later. conf.logical_block_size, which blkconf_blocksizes
> sets it used earlier.

Okay, I recommend a comment then.



Re: [Qemu-devel] [PATCH 1/3] migration: Fix coding style (whitespace issues)

2015-03-02 Thread Michael Tokarev
28.02.2015 21:09, Stefan Weil wrote:
> * Remove trailing whitespace (fixes 9 errors from checkpatch.pl).
>   One comment line was longer than 80 characters, so wrap it
>   and fix a typo, too.
> * Replace tabs by blanks (fixes 1 error).

This hunk:

> @@ -2421,7 +2421,7 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error 
> **errp)
>  continue;
>  }
>  }
> -
> +
>  goto listen;
>  }


clashes with my earlier attemt to clean up this code, I rewrote
this loop a bit to avoid this "twisted" usage of gotos.
I'll apply this patch without this change.

Thanks,

/mjt



Re: [Qemu-devel] [PATCH 2/2] virtio-pci: switch to modern accessors for 1.0

2015-03-02 Thread Michael S. Tsirkin
On Mon, Mar 02, 2015 at 12:56:55PM +0100, Cornelia Huck wrote:
> On Mon, 2 Mar 2015 12:40:28 +0100
> "Michael S. Tsirkin"  wrote:
> 
> > virtio 1.0 config space is in LE format for all
> > devices, use modern wrappers when accessed through
> > the 1.0 BAR.
> > 
> > Reported-by: Rusty Russell 
> > Signed-off-by: Michael S. Tsirkin 
> > ---
> >  hw/virtio/virtio-pci.c | 12 ++--
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> Not that I'm deeply familiar with pci :), but this looks good to me.
> 
> (This is on top of your pci branch, btw?)

virtio 1.0 branch




Re: [Qemu-devel] [PATCH] vhost_net: Add missing 'static' attribute

2015-03-02 Thread Michael Tokarev
Applied to trivial, thank you!

/mjt



Re: [Qemu-devel] [PATCH] oslib-posix: Fix compiler warning (-Wclobbered) and simplify the code

2015-03-02 Thread Michael Tokarev
Applied to trivial, thank you!

/mjt



Re: [Qemu-devel] [PATCH] disas/cris: Fix warning caused by missing 'static' attribute

2015-03-02 Thread Michael Tokarev
Applied to -trivial, thanks!

/mjt



Re: [Qemu-devel] [PATCH] disas/arm: Fix warnings caused by missing 'static' attribute

2015-03-02 Thread Michael Tokarev
Applied to -trivial, thanks!

/mjt



Re: [Qemu-devel] [PATCH] disas/microblaze: Fix warnings caused by missing 'static' attribute

2015-03-02 Thread Michael Tokarev
Applied to -trivial, thank you!

/mjt



[Qemu-devel] [PATCH] gdbstub: avoid possible NULL pointer dereference

2015-03-02 Thread Paolo Bonzini
Coverity reports that s->chr is checked after put_packet dereferences it.
Move the check earlier, consistent with the code used for user-mode
emulation.

Signed-off-by: Paolo Bonzini 
---
 gdbstub.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index e4a1a79..8abcb8a 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1443,15 +1443,17 @@ void gdb_exit(CPUArchState *env, int code)
   if (gdbserver_fd < 0 || s->fd < 0) {
   return;
   }
+#else
+  if (!s->chr) {
+  return;
+  }
 #endif
 
   snprintf(buf, sizeof(buf), "W%02x", (uint8_t)code);
   put_packet(s, buf);
 
 #ifndef CONFIG_USER_ONLY
-  if (s->chr) {
-  qemu_chr_delete(s->chr);
-  }
+  qemu_chr_delete(s->chr);
 #endif
 }
 
-- 
2.3.0




Re: [Qemu-devel] [RFC 01/10] target-arm: protect cpu_exclusive_*.

2015-03-02 Thread Peter Maydell
On 27 February 2015 at 16:54, Mark Burton  wrote:
>
>> On 26 Feb 2015, at 23:56, Peter Maydell  wrote:
>> cpu_physical_memory_rw would bypass the TLB and so be much slower.
>> Make sure you use the functions which go via the TLB if you do
>> this in a helper (and remember that they will longjmp out on a
>> tlb miss!)
>
> At this point speed isn’t our main concern - it’s simplicity of 
> implementation - we want it to work, then we can worry about a better 
> implementation (which likely should not go this path at all - as discussed 
> above).
> Given that - isn’t it reasonable to pass through cpu_physical_memory_rw - and 
> hence not have to worry about the long jump ? Or am I missing something?

If you use cpu_physical_memory_rw you need to do the
virt-to-phys translation by hand (preferably via the TLB).
That might be something you needed to do anyway if we want
to have architecturally correct monitors that work on
physaddrs rather than vaddrs, but if not then the two
step process is a bit awkward.

>> Pretty sure we've already discussed how the current ldrex/strex
>> implementation is not architecturally correct. I think this is
>> another of those areas.
>
> We have indeed discussed this - but this is a surprise.

You're right that I didn't specifically realise this exact
part of our incorrectness earlier.

-- PMM



Re: [Qemu-devel] [RfC PATCH 03/15] virtio-pci: make pci bars configurable

2015-03-02 Thread Michael S. Tsirkin
On Mon, Feb 23, 2015 at 11:23:19AM +0100, Gerd Hoffmann wrote:
> Add msix_bar and modern_mem_bar fields to VirtIOPCIProxy.  They can be
> used to configure which pci regions are used for the virtio 1.0 memory
> bar and the msix bar.
> 
> For legacy/transitional devices the legacy bar is region 0 and the msix
> bar is region 1.  Only the modern bar can be configured, and it must be
> 2 or larger.  Default is 2.
> 
> For legacy-free devices the modern bar is region 0 by default and the
> msix bar is 2 by default.
> 
> Use case: For VirtIOPCIProxy subclasses which need additional pci bars,
> such as virtio-vga.  With the new fields they can make sure the regions
> do not conflict.
> 
> Signed-off-by: Gerd Hoffmann 

Hmm, I'd rather add an API to register a free BAR.
What's wrong with that?

> ---
>  hw/virtio/virtio-pci.c | 25 +
>  hw/virtio/virtio-pci.h |  2 ++
>  2 files changed, 23 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index cd7c777..f97baf2 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -965,8 +965,6 @@ static void virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
>  PCIDevice *dev = &proxy->pci_dev;
>  int offset;
>  
> -cap->bar = 2;
> -
>  offset = pci_add_capability(dev, PCI_CAP_ID_VNDR, 0, cap->cap_len);
>  assert(offset > 0);
>  
> @@ -1243,11 +1241,21 @@ static void virtio_pci_device_plugged(DeviceState *d)
>  pci_config_set_class(config, proxy->class_code);
>  }
>  
> +if (proxy->modern_mem_bar > 5) {
> +proxy->modern_mem_bar = 5;
> +}
> +if (proxy->msix_bar > 5) {
> +proxy->msix_bar = 5;
> +}
>  if (legacy) {
>  /* legacy and transitional */
>  pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
>   pci_get_word(config + PCI_VENDOR_ID));
>  pci_set_word(config + PCI_SUBSYSTEM_ID, virtio_bus_get_vdev_id(bus));
> +proxy->msix_bar = 1;
> +if (proxy->modern_mem_bar < 2) {
> +proxy->modern_mem_bar = 2;
> +}
>  } else {
>  /* pure virtio-1.0 */
>  pci_set_word(config + PCI_VENDOR_ID,
> @@ -1255,6 +1263,9 @@ static void virtio_pci_device_plugged(DeviceState *d)
>  pci_set_word(config + PCI_DEVICE_ID,
>   0x1040 + virtio_bus_get_vdev_id(bus));
>  pci_config_set_revision(config, 1);
> +if (proxy->msix_bar == proxy->modern_mem_bar) {
> +proxy->msix_bar = (proxy->msix_bar + 2) % 6;
> +}
>  }
>  config[PCI_INTERRUPT_PIN] = 1;
>  
> @@ -1263,24 +1274,28 @@ static void virtio_pci_device_plugged(DeviceState *d)
>  struct virtio_pci_cap common = {
>  .cfg_type = VIRTIO_PCI_CAP_COMMON_CFG,
>  .cap_len = sizeof common,
> +.bar = proxy->modern_mem_bar,
>  .offset = cpu_to_le32(0x0),
>  .length = cpu_to_le32(0x1000),
>  };
>  struct virtio_pci_cap isr = {
>  .cfg_type = VIRTIO_PCI_CAP_ISR_CFG,
>  .cap_len = sizeof isr,
> +.bar = proxy->modern_mem_bar,
>  .offset = cpu_to_le32(0x1000),
>  .length = cpu_to_le32(0x1000),
>  };
>  struct virtio_pci_cap device = {
>  .cfg_type = VIRTIO_PCI_CAP_DEVICE_CFG,
>  .cap_len = sizeof device,
> +.bar = proxy->modern_mem_bar,
>  .offset = cpu_to_le32(0x2000),
>  .length = cpu_to_le32(0x1000),
>  };
>  struct virtio_pci_notify_cap notify = {
>  .cap.cfg_type = VIRTIO_PCI_CAP_NOTIFY_CFG,
>  .cap.cap_len = sizeof notify,
> +.cap.bar = proxy->modern_mem_bar,
>  .cap.offset = cpu_to_le32(0x3000),
>  .cap.length = cpu_to_le32(QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
>VIRTIO_PCI_QUEUE_MAX),
> @@ -1359,12 +1374,14 @@ static void virtio_pci_device_plugged(DeviceState *d)
>QEMU_VIRTIO_PCI_QUEUE_MEM_MULT *
>VIRTIO_PCI_QUEUE_MAX);
>  memory_region_add_subregion(&proxy->modern_bar, 0x3000, 
> &proxy->notify);
> -pci_register_bar(&proxy->pci_dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY,
> +pci_register_bar(&proxy->pci_dev, proxy->modern_mem_bar,
> + PCI_BASE_ADDRESS_SPACE_MEMORY,
>   &proxy->modern_bar);
>  }
>  
>  if (proxy->nvectors &&
> -msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors, 1)) {
> +msix_init_exclusive_bar(&proxy->pci_dev, proxy->nvectors,
> +proxy->msix_bar)) {
>  error_report("unable to init msix vectors to %" PRIu32,
>   proxy->nvectors);
>  proxy->nvectors = 0;
> diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
> index 3068a63..a273c33 100644
> --- a/hw/virtio/virtio-pci.h
> +++ b

  1   2   3   4   >