Re: [Qemu-devel] [PATCH] net/colo-compare.c: Remove duplicated code

2019-01-15 Thread Jason Wang



On 2019/1/15 上午12:44, Philippe Mathieu-Daudé wrote:

On 1/14/19 3:30 PM, Thomas Huth wrote:

On 2019-01-14 15:05, Zhang Chen wrote:

From: Zhang Chen 

Fix duplicated code:
https://bugs.launchpad.net/qemu/+bug/1811499


Fixes: f449c9e549c


Signed-off-by: Zhang Chen 
---
  net/colo-compare.c | 8 
  1 file changed, 8 deletions(-)

diff --git a/net/colo-compare.c b/net/colo-compare.c
index 9156ab3349..fa3fd0632d 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -285,14 +285,6 @@ static bool colo_mark_tcp_pkt(Packet *ppkt, Packet *spkt,
  {
  *mark = 0;
  
-if (ppkt->tcp_seq == spkt->tcp_seq && ppkt->seq_end == spkt->seq_end) {

-if (colo_compare_packet_payload(ppkt, spkt,
-ppkt->header_size, spkt->header_size,
-ppkt->payload_size)) {
-*mark = COLO_COMPARE_FREE_SECONDARY | COLO_COMPARE_FREE_PRIMARY;
-return true;
-}
-}
  if (ppkt->tcp_seq == spkt->tcp_seq && ppkt->seq_end == spkt->seq_end) {
  if (colo_compare_packet_payload(ppkt, spkt,
  ppkt->header_size, spkt->header_size,


Reviewed-by: Thomas Huth 

Reviewed-by: Philippe Mathieu-Daudé 



Applied.

Thanks





Re: [Qemu-devel] [PATCH] vhost-user: fix qemu crash caused by failed backend

2019-01-15 Thread Marc-André Lureau
On Tue, Jan 15, 2019 at 7:59 AM Michael S. Tsirkin  wrote:
>
> On Tue, Oct 02, 2018 at 01:54:25PM +0400, Marc-André Lureau wrote:
> > Hi
> >
> > On Thu, Sep 27, 2018 at 7:37 PM Liang Li  wrote:
> > >
> > > During live migration, when stopping vhost-user device, 'vhost_dev_stop'
> > > will be called, 'vhost_dev_stop' will call a batch of 'vhost_user_read'
> > > and 'vhost_user_write'. If a previous 'vhost_user_read' or 
> > > 'vhost_user_write'
> > > failed because the vhost user backend failed, the 'CHR_EVENT_CLOSED' event
> > > will be triggerd, followed by the call chain 
> > > chr_closed_bh()->vhost_user_stop()->
> > > vhost_net_cleanup()->vhost_dev_cleanup()
> > >
> > > vhost_dev_cleanup will clear vhost_dev struct, so the later 
> > > 'vhost_user_read'
> > > or 'vhost_user_read' will reference null pointer and cause qemu crash
> >
> > Do you have a backtrace to help understand the issue?
> > thanks
>
> Marc-André, Maxime any input on this patch?

It looks like this may be reproducible today. It would be great to
have a test or an easy way to reproduce it on master. It could be
based on existing vhost-user-test migration test.

> I agree flags like break_down don't exactly look elegant ...

Indeed, and its state is somehow managed by both vhost-user and
vhost-net. I wonder if vhost_dev_cleanup() shouldn't set it, instead
of vhost_net_mark_break_down().

>
>
> > >
> > > Signed-off-by: Liang Li 
> > > ---
> > >  hw/net/vhost_net.c|  6 ++
> > >  hw/virtio/vhost-user.c| 15 +--
> > >  include/hw/virtio/vhost.h |  1 +
> > >  include/net/vhost_net.h   |  1 +
> > >  net/vhost-user.c  |  3 +++
> > >  5 files changed, 24 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > > index e037db6..77994e9 100644
> > > --- a/hw/net/vhost_net.c
> > > +++ b/hw/net/vhost_net.c
> > > @@ -113,6 +113,11 @@ uint64_t vhost_net_get_features(struct vhost_net 
> > > *net, uint64_t features)
> > >  features);
> > >  }
> > >
> > > +void vhost_net_mark_break_down(struct vhost_net *net)
> > > +{
> > > +net->dev.break_down = true;
> > > +}
> > > +
> > >  void vhost_net_ack_features(struct vhost_net *net, uint64_t features)
> > >  {
> > >  net->dev.acked_features = net->dev.backend_features;
> > > @@ -156,6 +161,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions 
> > > *options)
> > >  net->dev.max_queues = 1;
> > >  net->dev.nvqs = 2;
> > >  net->dev.vqs = net->vqs;
> > > +net->dev.break_down = false;
> > >
> > >  if (backend_kernel) {
> > >  r = vhost_net_get_fd(options->net_backend);
> > > diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> > > index b041343..1394719 100644
> > > --- a/hw/virtio/vhost-user.c
> > > +++ b/hw/virtio/vhost-user.c
> > > @@ -213,14 +213,20 @@ static bool ioeventfd_enabled(void)
> > >  static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg)
> > >  {
> > >  struct vhost_user *u = dev->opaque;
> > > -CharBackend *chr = u->user->chr;
> > > +CharBackend *chr;
> > >  uint8_t *p = (uint8_t *) msg;
> > >  int r, size = VHOST_USER_HDR_SIZE;
> > >
> > > +if (dev->break_down) {
> > > +goto fail;
> > > +}
> > > +
> > > +chr = u->user->chr;
> > >  r = qemu_chr_fe_read_all(chr, p, size);
> > >  if (r != size) {
> > >  error_report("Failed to read msg header. Read %d instead of %d."
> > >   " Original request %d.", r, size, msg->hdr.request);
> > > +dev->break_down = true;
> > >  goto fail;
> > >  }
> > >
> > > @@ -299,9 +305,12 @@ static int vhost_user_write(struct vhost_dev *dev, 
> > > VhostUserMsg *msg,
> > >  int *fds, int fd_num)
> > >  {
> > >  struct vhost_user *u = dev->opaque;
> > > -CharBackend *chr = u->user->chr;
> > > +CharBackend *chr;
> > >  int ret, size = VHOST_USER_HDR_SIZE + msg->hdr.size;
> > >
> > > +if (dev->break_down) {
> > > +return -1;
> > > +}
> > >  /*
> > >   * For non-vring specific requests, like VHOST_USER_SET_MEM_TABLE,
> > >   * we just need send it once in the first time. For later such
> > > @@ -312,6 +321,7 @@ static int vhost_user_write(struct vhost_dev *dev, 
> > > VhostUserMsg *msg,
> > >  return 0;
> > >  }
> > >
> > > +chr = u->user->chr;
> > >  if (qemu_chr_fe_set_msgfds(chr, fds, fd_num) < 0) {
> > >  error_report("Failed to set msg fds.");
> > >  return -1;
> > > @@ -319,6 +329,7 @@ static int vhost_user_write(struct vhost_dev *dev, 
> > > VhostUserMsg *msg,
> > >
> > >  ret = qemu_chr_fe_write_all(chr, (const uint8_t *) msg, size);
> > >  if (ret != size) {
> > > +dev->break_down = true;
> > >  error_report("Failed to write msg."
> > >   " Wrote %d instead of %d.", ret, size);
> > >  return -1;
> > > diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
> > 

[Qemu-devel] [Bug 1785698] Re: Solaris build error: unknown type name ‘gcry_error_t’

2019-01-15 Thread Thomas Huth
Right, we've got a separate bug for libutil already, and as far as I can
see, all the other problems here were due to using the non-POSIX
compliant shell etc., so let's close this bug here and track the libutil
problem in the other bug.

** Changed in: qemu
   Status: New => Invalid

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

Title:
  Solaris build error: unknown type name ‘gcry_error_t’

Status in QEMU:
  Invalid

Bug description:
  Building qemu 2.12.0 on a Sun Oracle Enterprise M3000 SPARC64 VII,
  Solaris 10 Update 11, opencsw toolchain and gcc 7.3.0, gmake fails
  with a bunch of related errors all in cypher-gcrypt.c:

  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:262:32: error: 
‘gcry_cipher_hd_t’ undeclared (first use in this function); did you mean 
‘gcry_cipher_info’?
   err = gcry_cipher_encrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);^~~~
  gcry_cipher_info
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:262:49: error: 
expected ‘)’ before ‘ctx’
   err = gcry_cipher_encrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length); ^~~
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:262:11: error: too few 
arguments to function ‘gcry_cipher_encrypt’
   err = gcry_cipher_encrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);   ^~~
  In file included from 
/export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:25:0,
   from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:
  /usr/include/gcrypt.h:566:5: note: declared here
   int gcry_cipher_encrypt (GcryCipherHd h,
   ^~~
  In file included from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:0:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c: In function 
‘qcrypto_gcrypt_xts_decrypt’:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:271:5: error: unknown 
type name ‘gcry_error_t’; did you mean ‘g_error’?
   gcry_error_t err;
   ^~~~
   g_error
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:272:32: error: 
‘gcry_cipher_hd_t’ undeclared (first use in this function); did you mean 
‘gcry_cipher_info’?
   err = gcry_cipher_decrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);^~~~
  gcry_cipher_info
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:272:49: error: 
expected ‘)’ before ‘ctx’
   err = gcry_cipher_decrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length); ^~~
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:272:11: error: too few 
arguments to function ‘gcry_cipher_decrypt’
   err = gcry_cipher_decrypt((gcry_cipher_hd_t)ctx, dst, length, src, 
length);   ^~~
  In file included from 
/export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:25:0,
   from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:
  /usr/include/gcrypt.h:571:5: note: declared here
   int gcry_cipher_decrypt (GcryCipherHd h,
   ^~~
  In file included from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:0:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c: In function 
‘qcrypto_gcrypt_cipher_encrypt’:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:284:5: error: unknown 
type name ‘gcry_error_t’; did you mean ‘g_error’?
   gcry_error_t err;
   ^~~~
   g_error
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:293:21: warning: 
passing argument 1 of ‘xts_encrypt’ makes pointer from integer without a cast 
[-Wint-conversion]
   xts_encrypt(ctx->handle, ctx->tweakhandle,
   ^~~
  In file included from 
/export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:22:0,
   from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:
  /export/home/denber/qemu-2.12.0/include/crypto/xts.h:73:6: note: expected 
‘const void *’ but argument is of type ‘int’
   void xts_encrypt(const void *datactx,
    ^~~
  In file included from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:0:
  /export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:293:34: warning: 
passing argument 2 of ‘xts_encrypt’ makes pointer from integer without a cast 
[-Wint-conversion]
   xts_encrypt(ctx->handle, ctx->tweakhandle,
    ^~~
  In file included from 
/export/home/denber/qemu-2.12.0/crypto/cipher-gcrypt.c:22:0,
   from /export/home/denber/qemu-2.12.0/crypto/cipher.c:153:
  /export/home/denber/qemu-2.12.0/include/crypto/xts.h:73:6: note: expected 
‘const void *’ but argument is of type ‘int’
   void xts_encrypt(const void *datactx,
    ^~~

Re: [Qemu-devel] [qemu-s390x] [PATCH 10/15] s390-bios: Support for running format-0/1 channel programs

2019-01-15 Thread Cornelia Huck
On Mon, 14 Jan 2019 13:44:12 -0500
"Jason J. Herne"  wrote:

> On 1/7/19 2:02 PM, Jason J. Herne wrote:
> >>> @@ -190,6 +247,9 @@ struct ciw {
> >>>   __u16 count;
> >>>   };
> >>> +#define CU_TYPE_VIRTIO  0x3832
> >>> +#define CU_TYPE_DASD0x3990  
> >>
> >> No other dasd types we want to support? :) (Not sure if others are out
> >> in the wild. Maybe FBA?)
> >>  
> > 
> > I have no idea. I assumed 3390 was the only thing we supported. Perhaps 
> > 3380? I'd need to 
> > find a test device, which I could probably do ... I'll look more into this. 
> >  
> 
> After a few discussions with folks in the lab we've decided that we don't see 
> a ton of 
> value in supporting anything other than 3990 at the moment. Anything else 
> would be older 
> (3380) and/or rare to see in the wild (and very difficult to test). As for 
> emulated setups 
> like z/VM, a user can just use 3390 instead of FBA. So I recommend we move 
> forward with 
> 3390/3990 support for now. We can always add in others types if/when we need 
> them.

Sounds reasonable.

What about calling the #define above CU_TYPE_DASD_3990 instead? Just to
make clear that there are other dasd types out there, but we only
support that particular one (at least at the moment).



[Qemu-devel] [Bug 1777252] Re: tests/Makefile.include trying to add linking library '-lutil' that break the build on Solaris

2019-01-15 Thread Thomas Huth
Does something like this work for you?

diff --git a/tests/Makefile.include b/tests/Makefile.include
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -777,7 +777,7 @@ tests/migration/initrd-stress.img: 
tests/migration/stress$(EXESUF)
rm $(INITRD_WORK_DIR)/init
rmdir $(INITRD_WORK_DIR)
 
-ifeq ($(CONFIG_POSIX),y)
+ifeq ($(CONFIG_POSIX)$(call lnot,$(CONFIG_SOLARIS)),yy)
 LIBS += -lutil
 endif

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

Title:
  tests/Makefile.include trying to add linking library '-lutil' that
  break the build on Solaris

Status in QEMU:
  New

Bug description:
  Building script 'tests/Makefile.include' contains following code
  ```
  ifeq ($(CONFIG_POSIX),y)
  LIBS += -lutil
  endif
  ```

  library -lutil is not available on Solaris, so the building will failed, like
  ```
  ld: fatal: library -lutil: not found
  make: *** [SOMEWHERE/src/qemu-2.12.0/rules.mak:121: qemu-nbd] Error 1
  ```

  Commenting those code out fixed the error.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1777252/+subscriptions



Re: [Qemu-devel] [qemu-s390x] [PATCH v1] s390x/pci: Send correct event on hotplug.

2019-01-15 Thread Cornelia Huck
On Mon, 14 Jan 2019 21:59:58 +0100
David Hildenbrand  wrote:

> On 14.01.19 21:00, Collin Walling wrote:
> > On 1/14/19 12:44 PM, Cornelia Huck wrote:  
> >> [restored cc:s]
> >>
> >> On Mon, 14 Jan 2019 11:06:19 +0100
> >> Pierre Morel  wrote:
> >>  
> >>> On 11/01/2019 10:38, Cornelia Huck wrote:  
>  On Fri, 11 Jan 2019 08:16:41 +0100
>  David Hildenbrand  wrote:
>  
> > On 10.01.19 22:03, David Hildenbrand wrote:
> >> Comit 2c28c490571f ("s390x/pci: let pci devices start in configured 
> >> mode")
> >> changed the initial state of zPCI devices from ZPCI_FS_STANDBY to
> >> ZPCI_FS_DISABLED (a.k.a. configured). However we still only send a
> >> HP_EVENT_RESERVED_TO_STANDBY event to the guest, indicating a wrong
> >> state.
> >>
> >> Let's send a HP_EVENT_TO_CONFIGURED event instead, to match the actual
> >> state the device is in.
> >>
> >> This fixes hotplugged devices having to be enabled explicitly in the
> >> guest e.g. via echo 1 > /sys/bus/pci/slots//power.
> >>
> >> Fixes: 2c28c490571f ("s390x/pci: let pci devices start in configured 
> >> mode")
> >> Report-by: Cornelia Huck 
> 
>  Cool, works for me as well.
> 
>  Tested-by: Cornelia Huck 
> 
>  Do we want to cc:stable? Probably not, as it's more annoying than
>  critical, and pci hotplug does not seem to be much used on s390x.
>  
> >
> > If this patch is the right thing to do, then
> >
> > 1. s/Report-by/Reported-by/
> > 2. Dropping the "." from the subject
> >
> > (yes, it was late)
> 
>  :) Can do while applying.
>  
> >
> > I wonder if we should do both events sequentially, but as I don't have
> > access to the architecture I have to rely on that this works :)
> 
>  Yep, let's wait for feedback from folks with architecture access.
>  
> >>>
> >>> Works fine on the architecture too.
> >>>
> >>> Seems the logical thing to do for me.
> >>>
> >>> Reviewed-by: Pierre Morel  
> >>
> >> Thanks for checking.
> >>
> >> I'd like to queue this, but I'd like an ack from Collin as well.
> >>  
> > 
> > Would you mind adding a comment somewhere that states something like
> > "we can safely bypass the standby state when PCI hotplugging for a guest" 
> > just to be clear that QEMU is a bit different from how we handle it on the 
> > LPAR
> > level?
> > 
> > That comment would more-or-less clarify why we set the ZPCI_FS_ 
> > directly
> > to disabled instead of to standby when hotplugging (which, AFAIU, is the 
> > order 
> > how things occur at the LPAR level)  
> 
> This patch relies on Christians patch, where the general concept was
> explained. As we changed the initial state, we have to send a
> corresponding hotplug event. But still we can add a comment to shine
> some light on the general concept.
> 
> @Conny, can you add after the first paragraph: (or let me know if you
> want a respin)
> 
> "On real HW, a PCI device always pops up in the STANDBY state. In QEMU,
> we decided to let it show up directly in the configured state (as
> configuring it is otherwise just an extra burden for the admin). We can
> safely bypass the STANDBY state when hotplugging PCI devices to a guest."

I'll just add that text.

> 
> > 
> > Otherwise,
> > 
> > Reviewed-by: Collin Walling   
> 
> Thanks!
> 

Thanks!



Re: [Qemu-devel] [PATCH v1] s390x/pci: Send correct event on hotplug.

2019-01-15 Thread Cornelia Huck
On Thu, 10 Jan 2019 22:03:58 +0100
David Hildenbrand  wrote:

> Comit 2c28c490571f ("s390x/pci: let pci devices start in configured mode")
> changed the initial state of zPCI devices from ZPCI_FS_STANDBY to
> ZPCI_FS_DISABLED (a.k.a. configured). However we still only send a
> HP_EVENT_RESERVED_TO_STANDBY event to the guest, indicating a wrong
> state.
> 
> Let's send a HP_EVENT_TO_CONFIGURED event instead, to match the actual
> state the device is in.
> 
> This fixes hotplugged devices having to be enabled explicitly in the
> guest e.g. via echo 1 > /sys/bus/pci/slots//power.
> 
> Fixes: 2c28c490571f ("s390x/pci: let pci devices start in configured mode")
> Report-by: Cornelia Huck 
> Signed-off-by: David Hildenbrand 
> ---
>  hw/s390x/s390-pci-bus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Thanks, applied.



[Qemu-devel] [Bug 1811782] [NEW] QEMU Windows fails to mount rootfs on an ISO where QEMU Linux works normally

2019-01-15 Thread Chris Ward
Public bug reported:

I have installed QEMU 3.1.0 for Microsoft Windows from 
https://qemu.weilnetz.de/w64/ . When I give the command "qemu-system-x86_64.exe 
-cdrom ..\QemuSaver\freeduc2.iso", qemu boots the ISO, but the resulting Linux 
kernel panics when trying to mount the root file system. Running the equivalent 
command under Linux (OpenSuSE Leap 15.0) results in success.
I will attach a screenshot of the command and the kernel panic message.
To reproduce the problem, download the zip file from Google Drive here 
https://drive.google.com/file/d/1bAozvGeRF7PbkOnJKzrFHxhUh2kDLz6L/view?usp=sharing,
 and unpack it under Microsoft Windows. You can either run the installer (which 
will install QEMU 3.0.0 and an ISO image in C:\QemuSaver) or you can run the 
command I gave from the directory where your QEMU is installed.

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: kernel-panic qemu rootfs windows

** Attachment added: "Screenshot of command to invoke QEMU and resulting error"
   
https://bugs.launchpad.net/bugs/1811782/+attachment/5229205/+files/qemu-fail-to-mount-root.png

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

Title:
  QEMU Windows fails to mount rootfs on an ISO where QEMU Linux works
  normally

Status in QEMU:
  New

Bug description:
  I have installed QEMU 3.1.0 for Microsoft Windows from 
https://qemu.weilnetz.de/w64/ . When I give the command "qemu-system-x86_64.exe 
-cdrom ..\QemuSaver\freeduc2.iso", qemu boots the ISO, but the resulting Linux 
kernel panics when trying to mount the root file system. Running the equivalent 
command under Linux (OpenSuSE Leap 15.0) results in success.
  I will attach a screenshot of the command and the kernel panic message.
  To reproduce the problem, download the zip file from Google Drive here 
https://drive.google.com/file/d/1bAozvGeRF7PbkOnJKzrFHxhUh2kDLz6L/view?usp=sharing,
 and unpack it under Microsoft Windows. You can either run the installer (which 
will install QEMU 3.0.0 and an ISO image in C:\QemuSaver) or you can run the 
command I gave from the directory where your QEMU is installed.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1811782/+subscriptions



Re: [Qemu-devel] [PATCH v3 04/19] nbd/server: Hoist length check to qemp_nbd_server_add

2019-01-15 Thread Vladimir Sementsov-Ogievskiy
12.01.2019 20:57, Eric Blake wrote:
> We only had two callers to nbd_export_new; qemu-nbd.c always
> passed a valid offset/length pair (because it already checked
> the file length, to ensure that offset was in bounds), while
> blockdev-nbd always passed 0/-1.  Then nbd_export_new reduces
> the size to a multiple of BDRV_SECTOR_SIZE (can only happen
> when offset is not sector-aligned, since bdrv_getlength()
> currently rounds up), which can result in offset being greater
> than the enforced length, but that's not fatal (the server
> rejects client requests that exceed the advertised length).
> 
> However, I'm finding it easier to work with the code if we are
> consistent on having both callers pass in a valid length, and
> just assert that things are sane in nbd_export_new.
> 
> Signed-off-by: Eric Blake 
> 
> ---
> v3: new patch
> ---
>   blockdev-nbd.c | 10 +-
>   nbd/server.c   |  9 ++---
>   2 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/blockdev-nbd.c b/blockdev-nbd.c
> index c76d5416b90..d73ac1b026a 100644
> --- a/blockdev-nbd.c
> +++ b/blockdev-nbd.c
> @@ -146,6 +146,7 @@ void qmp_nbd_server_add(const char *device, bool 
> has_name, const char *name,
>   BlockDriverState *bs = NULL;
>   BlockBackend *on_eject_blk;
>   NBDExport *exp;
> +int64_t len;
> 
>   if (!nbd_server) {
>   error_setg(errp, "NBD server not running");
> @@ -168,6 +169,13 @@ void qmp_nbd_server_add(const char *device, bool 
> has_name, const char *name,
>   return;
>   }
> 
> +len = bdrv_getlength(bs);
> +if (len < 0) {
> +error_setg_errno(errp, -len,
> + "Failed to determine the NBD export's length");
> +return;
> +}
> +
>   if (!has_writable) {
>   writable = false;
>   }
> @@ -175,7 +183,7 @@ void qmp_nbd_server_add(const char *device, bool 
> has_name, const char *name,
>   writable = false;
>   }
> 
> -exp = nbd_export_new(bs, 0, -1, name, NULL, bitmap,
> +exp = nbd_export_new(bs, 0, len, name, NULL, bitmap,
>writable ? 0 : NBD_FLAG_READ_ONLY,
>NULL, false, on_eject_blk, errp);
>   if (!exp) {
> diff --git a/nbd/server.c b/nbd/server.c
> index e8c56607eff..c9937ccdc2a 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -1499,13 +1499,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t 
> dev_offset, off_t size,
>   exp->name = g_strdup(name);
>   exp->description = g_strdup(description);
>   exp->nbdflags = nbdflags;
> -exp->size = size < 0 ? blk_getlength(blk) : size;
> -if (exp->size < 0) {
> -error_setg_errno(errp, -exp->size,
> - "Failed to determine the NBD export's length");
> -goto fail;
> -}
> -exp->size -= exp->size % BDRV_SECTOR_SIZE;
> +assert(dev_offset <= size);

@size is not size of the image, but size of the export, so it may be less than 
dev_offset
(qemu-nbd.c do "fd_size -= dev_offset" before "nbd_export_new(bs, dev_offset, 
fd_size, "

> +exp->size = QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE);
> 
>   if (bitmap) {
>   BdrvDirtyBitmap *bm = NULL;
> 


-- 
Best regards,
Vladimir


[Qemu-devel] [Bug 1811782] Re: QEMU Windows fails to mount rootfs on an ISO where QEMU Linux works normally

2019-01-15 Thread Chris Ward
This fails on Windows 7 and on Windows 10.
I have had success with different ISO files.

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

Title:
  QEMU Windows fails to mount rootfs on an ISO where QEMU Linux works
  normally

Status in QEMU:
  New

Bug description:
  I have installed QEMU 3.1.0 for Microsoft Windows from 
https://qemu.weilnetz.de/w64/ . When I give the command "qemu-system-x86_64.exe 
-cdrom ..\QemuSaver\freeduc2.iso", qemu boots the ISO, but the resulting Linux 
kernel panics when trying to mount the root file system. Running the equivalent 
command under Linux (OpenSuSE Leap 15.0) results in success.
  I will attach a screenshot of the command and the kernel panic message.
  To reproduce the problem, download the zip file from Google Drive here 
https://drive.google.com/file/d/1bAozvGeRF7PbkOnJKzrFHxhUh2kDLz6L/view?usp=sharing,
 and unpack it under Microsoft Windows. You can either run the installer (which 
will install QEMU 3.0.0 and an ISO image in C:\QemuSaver) or you can run the 
command I gave from the directory where your QEMU is installed.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1811782/+subscriptions



Re: [Qemu-devel] [RFC v2 0/4] QEMU changes to do PVH boot

2019-01-15 Thread Liam Merwick

Hi Stefano,

On 10/01/2019 15:12, Stefano Garzarella wrote:

On Wed, Jan 09, 2019 at 01:18:12PM -0800, Maran Wilson wrote:

On 1/9/2019 11:53 AM, Boris Ostrovsky wrote:

On 1/9/19 6:53 AM, Stefano Garzarella wrote:

Hi Liam,

On Tue, Jan 8, 2019 at 3:47 PM Liam Merwick  wrote:

QEMU sets the hvm_modlist_entry in load_linux() after the call to
load_elfboot() and then qboot loads it in boot_pvh_from_fw_cfg()

But the current PVH patches don't handle initrd (they have
start_info.nr_modules == 1).

Looking in the linux kernel (arch/x86/platform/pvh/enlighten.c) I saw:
  /* The first module is always ramdisk. */
  if (pvh_start_info.nr_modules) {
  struct hvm_modlist_entry *modaddr =
  __va(pvh_start_info.modlist_paddr);
  pvh_bootparams.hdr.ramdisk_image = modaddr->paddr;
  pvh_bootparams.hdr.ramdisk_size = modaddr->size;
  }

So, putting start_info.nr_modules = 1, means that the first
hvm_modlist_entry should have the ramdisk paddr and size. Is it
correct?


That's my understanding.

I think what's missing, is that we just need Qemu or qboot/seabios to
properly populate the pvh_start_info.modlist_paddr with the address (as
usable by the guest) of the hvm_modlist_entry which correctly defines the
details of the initrd that has already been loaded into memory that is
accessible by the guest.

-Maran



I tried and it works, I modified QEMU to load the initrd and to expose it
through fw_cfg, then qboot loads it and set correctly the hvm_modlist_entry.

You can find the patch of QEMU at the end of this email and the qboot
patch here: 
https://github.com/stefano-garzarella/qboot/commit/41e1fd765c8419e270fd79d9b3af5d53576e88a8

Do you think can be a good approach? If you want, you can add this patch
to your series.


Code looks good to me. I'll include it with v3 of my QEMU patches.

Regards,
Liam




Thanks,
Stefano


 From d5c0d51768f5a8fb214be6c2bb0cb7e86e9917b7 Mon Sep 17 00:00:00 2001
From: Stefano Garzarella 
Date: Thu, 10 Jan 2019 15:16:44 +0100
Subject: [PATCH] pvh: load initrd and expose it through fw_cfg

When initrd is specified, load and expose it to the guest firmware
through fw_cfg. The firmware will fill the hvm_start_info for the
kernel.

Signed-off-by: Stefano Garzarella 
Based-on: <1545422632-2-5-git-send-email-liam.merw...@oracle.com>
---
  hw/i386/pc.c | 38 +-
  1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 06bce6a101..f6721f51be 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -986,25 +986,45 @@ static void load_linux(PCMachineState *pcms,
   */
  if (load_elfboot(kernel_filename, kernel_size,
   header, pvh_start_addr, fw_cfg)) {
-struct hvm_modlist_entry ramdisk_mod = { 0 };
-
  fclose(f);
  
  fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,

  strlen(kernel_cmdline) + 1);
  fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
  
-assert(machine->device_memory != NULL);

-ramdisk_mod.paddr = machine->device_memory->base;
-ramdisk_mod.size =
-memory_region_size(&machine->device_memory->mr);
-
-fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, &ramdisk_mod,
- sizeof(ramdisk_mod));
  fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, sizeof(header));
  fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA,
   header, sizeof(header));
  
+/* load initrd */

+if (initrd_filename) {
+gsize initrd_size;
+gchar *initrd_data;
+GError *gerr = NULL;
+
+if (!g_file_get_contents(initrd_filename, &initrd_data,
+&initrd_size, &gerr)) {
+fprintf(stderr, "qemu: error reading initrd %s: %s\n",
+initrd_filename, gerr->message);
+exit(1);
+}
+
+initrd_max = pcms->below_4g_mem_size - pcmc->acpi_data_size - 
1;
+if (initrd_size >= initrd_max) {
+fprintf(stderr, "qemu: initrd is too large, cannot 
support."
+"(max: %"PRIu32", need %"PRId64")\n",
+initrd_max, (uint64_t)initrd_size);
+exit(1);
+}
+
+initrd_addr = (initrd_max - initrd_size) & ~4095;
+
+fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
+fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
+fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data,
+ initrd_size);
+}
+
  return;
  }
  /* This looks like a multiboot kernel. If it is, let's stop





[Qemu-devel] [PATCH v2 0/4] pvh: add new PVH option rom

2019-01-15 Thread Stefano Garzarella
This patch series is based on "[RFC v2 0/4] QEMU changes to do PVH boot" and
provides a PVH option rom that can be used with SeaBIOS to boot uncompressed
kernel using the x86/HVM direct boot ABI.

Patches 1 and 2 are to prepare the PVH option rom, moving common functions in a
new header.  Patch 3 adds the new PVH option rom and patch 4 uses it when we
are booting an uncompressed kernel using the x86/HVM direct boot ABI.

Changes in v2:
- addressed comments by Stefan and Eric:
  - Patch 2: moved inludes on top of linuxboot_dma.c and add  in
optrom.h
  - Patch 4: added check of pvh.bin in xen_load_linux()
- modified commit message of patch 2 to explain better the patch

Stefano Garzarella (4):
  linuxboot_dma: remove duplicate definitions of FW_CFG
  linuxboot_dma: move common functions in a new header
  optionrom: add new PVH option rom
  hw/i386/pc: use PVH option rom

 hw/i386/pc.c  |   5 +
 pc-bios/optionrom/Makefile|   5 +-
 pc-bios/optionrom/linuxboot_dma.c | 112 +++--
 pc-bios/optionrom/optrom.h| 110 
 pc-bios/optionrom/optrom_fw_cfg.h |  92 ++
 pc-bios/optionrom/pvh.S   | 200 ++
 pc-bios/optionrom/pvh_main.c  | 117 +
 7 files changed, 544 insertions(+), 97 deletions(-)
 create mode 100644 pc-bios/optionrom/optrom.h
 create mode 100644 pc-bios/optionrom/optrom_fw_cfg.h
 create mode 100644 pc-bios/optionrom/pvh.S
 create mode 100644 pc-bios/optionrom/pvh_main.c

-- 
2.20.1




[Qemu-devel] [PATCH v2 3/4] optionrom: add new PVH option rom

2019-01-15 Thread Stefano Garzarella
The new pvh.bin option rom can be used with SeaBIOS to boot
uncompressed kernel using the x86/HVM direct boot ABI.

pvh.S contains the entry point of the option rom. It runs
in real mode, loads the e820 table querying the BIOS, and
then it switches to 32bit protect mode and jump to the
pvh_load_kernel() written in pvh_main.c.
pvh_load_kernel() loads the cmdline and kernel entry_point
using fw_cfg, then it looks for RSDP, fills the
hvm_start_info required by x86/HVM ABI, and finally jumps
to the kernel entry_point.

Signed-off-by: Stefano Garzarella 
Reviewed-by: Stefan Hajnoczi 
---
 pc-bios/optionrom/Makefile   |   5 +-
 pc-bios/optionrom/pvh.S  | 200 +++
 pc-bios/optionrom/pvh_main.c | 117 
 3 files changed, 321 insertions(+), 1 deletion(-)
 create mode 100644 pc-bios/optionrom/pvh.S
 create mode 100644 pc-bios/optionrom/pvh_main.c

diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index a9a9e5e7eb..92c91d9949 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -37,7 +37,7 @@ Wa = -Wa,
 ASFLAGS += -32
 QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS), $(Wa)-32)
 
-build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin
+build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin
 
 # suppress auto-removal of intermediate files
 .SECONDARY:
@@ -46,6 +46,9 @@ build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin 
kvmvapic.bin
 %.o: %.S
$(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< 
| $(AS) $(ASFLAGS) -o $@,"AS","$(TARGET_DIR)$@")
 
+%.img: %.o %_main.o
+   $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -T 
$(SRC_PATH)/pc-bios/optionrom/flat.lds -s -o $@ $?,"BUILD","$(TARGET_DIR)$@")
+
 %.img: %.o
$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -T 
$(SRC_PATH)/pc-bios/optionrom/flat.lds -s -o $@ $<,"BUILD","$(TARGET_DIR)$@")
 
diff --git a/pc-bios/optionrom/pvh.S b/pc-bios/optionrom/pvh.S
new file mode 100644
index 00..e1d7f4a7a7
--- /dev/null
+++ b/pc-bios/optionrom/pvh.S
@@ -0,0 +1,200 @@
+/*
+ * PVH Option ROM
+ *
+ * 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 .
+ *
+ * Copyright Novell Inc, 2009
+ *   Authors: Alexander Graf 
+ *
+ * Copyright (c) 2019 Red Hat Inc.
+ *   Authors: Stefano Garzarella 
+ */
+
+#include "optionrom.h"
+
+#define BOOT_ROM_PRODUCT "PVH loader"
+
+#define GS_PROT_JUMP   0
+#define GS_GDT_DESC6
+
+#ifdef OPTION_ROM_START
+#undef OPTION_ROM_START
+#endif
+#ifdef OPTION_ROM_END
+#undef OPTION_ROM_END
+#endif
+
+/*
+ * Redefine OPTION_ROM_START and OPTION_ROM_END, because this rom is produced
+ * linking multiple objects.
+ * signrom.py will add padding.
+ */
+#define OPTION_ROM_START\
+.code16;   \
+.text; \
+   .global _start; \
+_start:;   \
+   .short  0xaa55; \
+   .byte   3; /* desired size in 512 units */
+
+#define OPTION_ROM_END \
+_end:
+
+BOOT_ROM_START
+
+run_pvhboot:
+
+   cli
+   cld
+
+   mov %cs, %eax
+   shl $0x4, %eax
+
+   /* set up a long jump descriptor that is PC relative */
+
+   /* move stack memory to %gs */
+   mov %ss, %ecx
+   shl $0x4, %ecx
+   mov %esp, %ebx
+   add %ebx, %ecx
+   sub $0x20, %ecx
+   sub $0x30, %esp
+   shr $0x4, %ecx
+   mov %cx, %gs
+
+   /* now push the indirect jump descriptor there */
+   mov (prot_jump), %ebx
+   add %eax, %ebx
+   movl%ebx, %gs:GS_PROT_JUMP
+   mov $8, %bx
+   movw%bx, %gs:GS_PROT_JUMP + 4
+
+   /* fix the gdt descriptor to be PC relative */
+   movw(gdt_desc), %bx
+   movw%bx, %gs:GS_GDT_DESC
+   movl(gdt_desc+2), %ebx
+   add %eax, %ebx
+   movl%ebx, %gs:GS_GDT_DESC + 2
+
+   /* initialize HVM memmap table using int 0x15(e820) */
+
+   /* ES 

[Qemu-devel] [PATCH v1] virtio: add checks for the size of the indirect table

2019-01-15 Thread Dima Stepanov
The virtqueue_pop() and virtqueue_get_avail_bytes() routines can use the
INDIRECT table to get the data. It is possible to create a packet which
will lead to the assert message like:
  include/exec/memory.h:1995: void
  address_space_read_cached(MemoryRegionCache *, hwaddr, void *, int):
  Assertion `addr < cache->len && len <= cache->len - addr' failed.
  Aborted
To do it the first descriptor should have a link to the INDIRECT table
and set the size of it to 0. It doesn't look good that the guest should
be able to trigger the assert in qemu. Add additional check for the size
of the INDIRECT table, which should not be 0.

Signed-off-by: Dima Stepanov 
---
 hw/virtio/virtio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 22bd1ac..a1ff647 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -646,7 +646,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int 
*in_bytes,
 vring_desc_read(vdev, &desc, desc_cache, i);
 
 if (desc.flags & VRING_DESC_F_INDIRECT) {
-if (desc.len % sizeof(VRingDesc)) {
+if (!desc.len || (desc.len % sizeof(VRingDesc))) {
 virtio_error(vdev, "Invalid size for indirect buffer table");
 goto err;
 }
@@ -902,7 +902,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
 desc_cache = &caches->desc;
 vring_desc_read(vdev, &desc, desc_cache, i);
 if (desc.flags & VRING_DESC_F_INDIRECT) {
-if (desc.len % sizeof(VRingDesc)) {
+if (!desc.len || (desc.len % sizeof(VRingDesc))) {
 virtio_error(vdev, "Invalid size for indirect buffer table");
 goto done;
 }
-- 
2.7.4




[Qemu-devel] [PATCH v2 2/4] linuxboot_dma: move common functions in a new header

2019-01-15 Thread Stefano Garzarella
In order to allow other option roms to use these common
useful functions and definitions, this patch put them
in two new C header files called optrom.h and
optrom_fw_cfg.h. We also add useful out*() in*()
functions for different size, and new fw_cfg functions
to use when DMA feature is not available.

Signed-off-by: Stefano Garzarella 
---
 pc-bios/optionrom/linuxboot_dma.c | 100 +--
 pc-bios/optionrom/optrom.h| 110 ++
 pc-bios/optionrom/optrom_fw_cfg.h |  92 +
 3 files changed, 218 insertions(+), 84 deletions(-)
 create mode 100644 pc-bios/optionrom/optrom.h
 create mode 100644 pc-bios/optionrom/optrom_fw_cfg.h

diff --git a/pc-bios/optionrom/linuxboot_dma.c 
b/pc-bios/optionrom/linuxboot_dma.c
index f728dc839f..bf6ee79c38 100644
--- a/pc-bios/optionrom/linuxboot_dma.c
+++ b/pc-bios/optionrom/linuxboot_dma.c
@@ -20,6 +20,10 @@
  * Richard W.M. Jones 
  */
 
+#include 
+#include "optrom.h"
+#include "optrom_fw_cfg.h"
+
 asm(
 ".text\n"
 ".global _start\n"
@@ -58,34 +62,12 @@ asm(
 "   jmp load_kernel\n"
 );
 
-#define BIOS_CFG_DMA_ADDR_HIGH 0x514
-#define BIOS_CFG_DMA_ADDR_LOW  0x518
-
-#define uint64_t unsigned long long
-#define uint32_t unsigned int
-#define uint16_t unsigned short
-
-#include "../../include/standard-headers/linux/qemu_fw_cfg.h"
-
-#define barrier() asm("" : : : "memory")
-
-static inline void outl(uint32_t value, uint16_t port)
-{
-asm("outl %0, %w1" : : "a"(value), "Nd"(port));
-}
-
 static inline void set_es(void *addr)
 {
 uint32_t seg = (uint32_t)addr >> 4;
 asm("movl %0, %%es" : : "r"(seg));
 }
 
-#ifdef __clang__
-#define ADDR32
-#else
-#define ADDR32 "addr32 "
-#endif
-
 static inline uint16_t readw_es(uint16_t offset)
 {
 uint16_t val;
@@ -108,56 +90,6 @@ static inline void writel_es(uint16_t offset, uint32_t val)
 asm(ADDR32 "movl %0, %%es:(%1)" : : "r"(val), "r"((uint32_t)offset));
 }
 
-static inline uint32_t bswap32(uint32_t x)
-{
-asm("bswapl %0" : "=r" (x) : "0" (x));
-return x;
-}
-
-static inline uint64_t bswap64(uint64_t x)
-{
-asm("bswapl %%eax; bswapl %%edx; xchg %%eax, %%edx" : "=A" (x) : "0" (x));
-return x;
-}
-
-static inline uint64_t cpu_to_be64(uint64_t x)
-{
-return bswap64(x);
-}
-
-static inline uint32_t cpu_to_be32(uint32_t x)
-{
-return bswap32(x);
-}
-
-static inline uint32_t be32_to_cpu(uint32_t x)
-{
-return bswap32(x);
-}
-
-/* clang is happy to inline this function, and bloats the
- * ROM.
- */
-static __attribute__((__noinline__))
-void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len)
-{
-struct fw_cfg_dma_access access;
-uint32_t control = (entry << 16) | FW_CFG_DMA_CTL_SELECT
-| FW_CFG_DMA_CTL_READ;
-
-access.address = cpu_to_be64((uint64_t)(uint32_t)buf);
-access.length = cpu_to_be32(len);
-access.control = cpu_to_be32(control);
-
-barrier();
-
-outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW);
-
-while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) {
-barrier();
-}
-}
-
 /* Return top of memory using BIOS function E801. */
 static uint32_t get_e801_addr(void)
 {
@@ -211,9 +143,9 @@ void load_kernel(void)
 uint32_t initrd_end_page, max_allowed_page;
 uint32_t segment_addr, stack_addr;
 
-bios_cfg_read_entry(&setup_addr, FW_CFG_SETUP_ADDR, 4);
-bios_cfg_read_entry(&setup_size, FW_CFG_SETUP_SIZE, 4);
-bios_cfg_read_entry(setup_addr, FW_CFG_SETUP_DATA, setup_size);
+bios_cfg_read_entry_dma(&setup_addr, FW_CFG_SETUP_ADDR, 4);
+bios_cfg_read_entry_dma(&setup_size, FW_CFG_SETUP_SIZE, 4);
+bios_cfg_read_entry_dma(setup_addr, FW_CFG_SETUP_DATA, setup_size);
 
 set_es(setup_addr);
 
@@ -223,8 +155,8 @@ void load_kernel(void)
 writel_es(0x22c, 0x37ff);
 }
 
-bios_cfg_read_entry(&initrd_addr, FW_CFG_INITRD_ADDR, 4);
-bios_cfg_read_entry(&initrd_size, FW_CFG_INITRD_SIZE, 4);
+bios_cfg_read_entry_dma(&initrd_addr, FW_CFG_INITRD_ADDR, 4);
+bios_cfg_read_entry_dma(&initrd_size, FW_CFG_INITRD_SIZE, 4);
 
 initrd_end_page = ((uint32_t)(initrd_addr + initrd_size) & -4096);
 max_allowed_page = (readl_es(0x22c) & -4096);
@@ -239,15 +171,15 @@ void load_kernel(void)
 
 }
 
-bios_cfg_read_entry(initrd_addr, FW_CFG_INITRD_DATA, initrd_size);
+bios_cfg_read_entry_dma(initrd_addr, FW_CFG_INITRD_DATA, initrd_size);
 
-bios_cfg_read_entry(&kernel_addr, FW_CFG_KERNEL_ADDR, 4);
-bios_cfg_read_entry(&kernel_size, FW_CFG_KERNEL_SIZE, 4);
-bios_cfg_read_entry(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size);
+bios_cfg_read_entry_dma(&kernel_addr, FW_CFG_KERNEL_ADDR, 4);
+bios_cfg_read_entry_dma(&kernel_size, FW_CFG_KERNEL_SIZE, 4);
+bios_cfg_read_entry_dma(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size);
 
-bios_cfg_read_entry(&cmdline_addr, FW_CFG_CMDLINE_ADDR, 4);
-bios_cfg_read_entry(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4);
-bios_

[Qemu-devel] [PATCH v2 4/4] hw/i386/pc: use PVH option rom

2019-01-15 Thread Stefano Garzarella
Use pvh.bin option rom when we are booting an uncompressed
kernel using the x86/HVM direct boot ABI.

Signed-off-by: Stefano Garzarella 
Based-on: <1545422632-2-5-git-send-email-liam.merw...@oracle.com>
---
 hw/i386/pc.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 06bce6a101..7564ba51d2 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1005,6 +1005,10 @@ static void load_linux(PCMachineState *pcms,
 fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA,
  header, sizeof(header));
 
+option_rom[nb_option_roms].bootindex = 0;
+option_rom[nb_option_roms].name = "pvh.bin";
+nb_option_roms++;
+
 return;
 }
 /* This looks like a multiboot kernel. If it is, let's stop
@@ -1456,6 +1460,7 @@ void xen_load_linux(PCMachineState *pcms)
 for (i = 0; i < nb_option_roms; i++) {
 assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
!strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
+   !strcmp(option_rom[i].name, "pvh.bin") ||
!strcmp(option_rom[i].name, "multiboot.bin"));
 rom_add_option(option_rom[i].name, option_rom[i].bootindex);
 }
-- 
2.20.1




[Qemu-devel] [PATCH v2 1/4] linuxboot_dma: remove duplicate definitions of FW_CFG

2019-01-15 Thread Stefano Garzarella
FW_CFG_DMA_CTL_* bits and struct fw_cfg_dma_access are
defined in the qemu_fw_cfg.h header file already included
in linuxboot_dma.c, so we can remove the definition of
BIOS_CFG_DMA_CTL_* and struct FWCfgDmaAccess.

Signed-off-by: Stefano Garzarella 
Reviewed-by: Stefan Hajnoczi 
---
 pc-bios/optionrom/linuxboot_dma.c | 20 
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/pc-bios/optionrom/linuxboot_dma.c 
b/pc-bios/optionrom/linuxboot_dma.c
index d856d41b55..f728dc839f 100644
--- a/pc-bios/optionrom/linuxboot_dma.c
+++ b/pc-bios/optionrom/linuxboot_dma.c
@@ -58,12 +58,6 @@ asm(
 "   jmp load_kernel\n"
 );
 
-/* QEMU_CFG_DMA_CONTROL bits */
-#define BIOS_CFG_DMA_CTL_ERROR   0x01
-#define BIOS_CFG_DMA_CTL_READ0x02
-#define BIOS_CFG_DMA_CTL_SKIP0x04
-#define BIOS_CFG_DMA_CTL_SELECT  0x08
-
 #define BIOS_CFG_DMA_ADDR_HIGH 0x514
 #define BIOS_CFG_DMA_ADDR_LOW  0x518
 
@@ -75,12 +69,6 @@ asm(
 
 #define barrier() asm("" : : : "memory")
 
-typedef struct FWCfgDmaAccess {
-uint32_t control;
-uint32_t length;
-uint64_t address;
-} __attribute__((packed)) FWCfgDmaAccess;
-
 static inline void outl(uint32_t value, uint16_t port)
 {
 asm("outl %0, %w1" : : "a"(value), "Nd"(port));
@@ -153,9 +141,9 @@ static inline uint32_t be32_to_cpu(uint32_t x)
 static __attribute__((__noinline__))
 void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len)
 {
-FWCfgDmaAccess access;
-uint32_t control = (entry << 16) | BIOS_CFG_DMA_CTL_SELECT
-| BIOS_CFG_DMA_CTL_READ;
+struct fw_cfg_dma_access access;
+uint32_t control = (entry << 16) | FW_CFG_DMA_CTL_SELECT
+| FW_CFG_DMA_CTL_READ;
 
 access.address = cpu_to_be64((uint64_t)(uint32_t)buf);
 access.length = cpu_to_be32(len);
@@ -165,7 +153,7 @@ void bios_cfg_read_entry(void *buf, uint16_t entry, 
uint32_t len)
 
 outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW);
 
-while (be32_to_cpu(access.control) & ~BIOS_CFG_DMA_CTL_ERROR) {
+while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) {
 barrier();
 }
 }
-- 
2.20.1




Re: [Qemu-devel] [PATCH] include/fpu/softfloat: Fix compilation with Clang on s390x

2019-01-15 Thread Peter Maydell
On Mon, 14 Jan 2019 at 22:48, Alex Bennée  wrote:
>
>
> Richard Henderson  writes:
> > But perhaps
> >
> > unsigned __int128 n = (unsigned __int128)n1 << 64 | n0;
> > *r = n % d;
> > return n / d;
> >
> > will allow the compiler to do what the assembly does for some 64-bit
> > hosts.
>
> I wonder how much cost is incurred by the jumping to the (libgcc?) div
> helper? Anyone got an s390x about so we can benchmark the two
> approaches?

The project has an s390x system available; however it's usually
running merge build tests so not so useful for benchmarking.
(I can set up accounts on it but that requires me to faff about
figuring out how to create new accounts :-))

thanks
-- PMM



[Qemu-devel] [Bug 1811720] Re: storage physical_block_size is restricted to uint16_t

2019-01-15 Thread Коренберг Марк
Yes, you are right. Thanks for the response.

** Changed in: qemu
   Status: New => Invalid

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

Title:
  storage physical_block_size is restricted to uint16_t

Status in QEMU:
  Invalid

Bug description:
  It is desirable to set -global scsi-hd.physical_block_size=4194304 for
  RBD-backed storage.

  But unfortunatelly, this values is restricted with uint16_t, i.e.
  65536 maximum.

  For example, scsi-hd.discard_granularity=4194304 is not so restricted
  (and works as expected)

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1811720/+subscriptions



Re: [Qemu-devel] [PATCH v2 2/3] migration: fix memory leak when updating tls-creds and tls-hostname

2019-01-15 Thread Dr. David Alan Gilbert
* Peter Xu (pet...@redhat.com) wrote:
> On Fri, Jan 11, 2019 at 02:37:31PM +0800, guangrong.x...@gmail.com wrote:
> > From: Xiao Guangrong 
> > 
> > If we update parameter, tls-creds and tls-hostname, these string
> > values are duplicated to local variables in migrate_params_test_apply()
> > by using g_strdup(), however these new allocated memory are missed to
> > be freed
> > 
> > Actually, they are not used to check anything, we can directly skip
> > them
> > 
> > Signed-off-by: Xiao Guangrong 
> > ---
> >  migration/migration.c | 10 --
> >  1 file changed, 10 deletions(-)
> > 
> > diff --git a/migration/migration.c b/migration/migration.c
> > index a82d594f29..fb39d7bec1 100644
> > --- a/migration/migration.c
> > +++ b/migration/migration.c
> > @@ -1145,16 +1145,6 @@ static void 
> > migrate_params_test_apply(MigrateSetParameters *params,
> >  dest->cpu_throttle_increment = params->cpu_throttle_increment;
> >  }
> >  
> > -if (params->has_tls_creds) {
> > -assert(params->tls_creds->type == QTYPE_QSTRING);
> > -dest->tls_creds = g_strdup(params->tls_creds->u.s);
> > -}
> > -
> > -if (params->has_tls_hostname) {
> > -assert(params->tls_hostname->type == QTYPE_QSTRING);
> > -dest->tls_hostname = g_strdup(params->tls_hostname->u.s);
> > -}
> > -
> 
> Hi, Guangrong,
> 
> The memleak seems to be correct here but before that I'm even a bit
> confused on why we need to copy the whole parameter list here instead
> of checking against a MigrateSetParameters* in migrate_params_check().
> Could anyone shed some light?  CC Markus too.

I think the problem is that
migrate_params_check checks a MigrationParameters

while the QMP command gives us a MigrateSetParameters; but we also use
migrate_params_check for the global check you added (8b0b29dc) which is
against migrationParameters; so that's why migrate_params_check takes
a MigrationParameters.

It's horrible we've got stuff duped so much.

However, I don't like this fix because if someone later was to add
a test for tls parameters to migrate_params_check, then they would be
confused why the hostname/creds weren't checked.
So while we have migrate_params_test_apply, it should cover all
parameters.

I think a cleaner check would be to write a MigrateParameters_free
that free'd any strings, and call that in qmp_migrate_set_parameters
on both exit paths.

Dave

> Thanks,
> 
> >  if (params->has_max_bandwidth) {
> >  dest->max_bandwidth = params->max_bandwidth;
> >  }
> > -- 
> > 2.14.5
> > 
> 
> Regards,
> 
> -- 
> Peter Xu
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK



Re: [Qemu-devel] [PATCH v3 05/19] nbd/server: Favor [u]int64_t over off_t

2019-01-15 Thread Vladimir Sementsov-Ogievskiy
12.01.2019 20:57, Eric Blake wrote:
> Although our compile-time environment is set up so that we always
> support long files with 64-bit off_t, we have no guarantee whether
> off_t is the same type as int64_t.  This requires casts when
> printing values, and prevents us from directly using qemu_strtoi64().
> Let's just flip to [u]int64_t (signed for length, because we have to
> detect failure of blk_getlength()

we have not, after previous patch

and because off_t was signed;
> unsigned for offset because it lets us simplify some math without
> having to worry about signed overflow).
> 
> Suggested-by: Vladimir Sementsov-Ogievskiy 
> Signed-off-by: Eric Blake 
> 
> ---
> v3: new patch
> ---
>   include/block/nbd.h |  4 ++--
>   nbd/server.c| 14 +++---
>   qemu-nbd.c  | 26 ++
>   3 files changed, 19 insertions(+), 25 deletions(-)
> 
> diff --git a/include/block/nbd.h b/include/block/nbd.h
> index 1971b557896..0f252829376 100644
> --- a/include/block/nbd.h
> +++ b/include/block/nbd.h
> @@ -294,8 +294,8 @@ int nbd_errno_to_system_errno(int err);
>   typedef struct NBDExport NBDExport;
>   typedef struct NBDClient NBDClient;
> 
> -NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
> -  const char *name, const char *description,
> +NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
> +  int64_t size, const char *name, const char *desc,

in previous patch you drop use of negative @size parameter, so it looks better
to use unsigned for size like for offset

> const char *bitmap, uint16_t nbdflags,
> void (*close)(NBDExport *), bool writethrough,
> BlockBackend *on_eject_blk, Error **errp);
> diff --git a/nbd/server.c b/nbd/server.c
> index c9937ccdc2a..15357d40fd7 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -77,8 +77,8 @@ struct NBDExport {
>   BlockBackend *blk;
>   char *name;
>   char *description;
> -off_t dev_offset;
> -off_t size;
> +uint64_t dev_offset;
> +int64_t size;
>   uint16_t nbdflags;
>   QTAILQ_HEAD(, NBDClient) clients;
>   QTAILQ_ENTRY(NBDExport) next;
> @@ -1455,8 +1455,8 @@ static void nbd_eject_notifier(Notifier *n, void *data)
>   nbd_export_close(exp);
>   }
> 
> -NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size,
> -  const char *name, const char *description,
> +NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
> +  int64_t size, const char *name, const char *desc,
> const char *bitmap, uint16_t nbdflags,
> void (*close)(NBDExport *), bool writethrough,
> BlockBackend *on_eject_blk, Error **errp)
> @@ -1497,7 +1497,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t 
> dev_offset, off_t size,
>   exp->blk = blk;
>   exp->dev_offset = dev_offset;
>   exp->name = g_strdup(name);
> -exp->description = g_strdup(description);
> +exp->description = g_strdup(desc);

unrelated but at least obvious, OK. However tiny note in commit message won't 
hurt.

>   exp->nbdflags = nbdflags;
>   assert(dev_offset <= size);
>   exp->size = QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE);
> @@ -2131,8 +2131,8 @@ static int nbd_co_receive_request(NBDRequestData *req, 
> NBDRequest *request,
>   if (request->from > client->exp->size ||
>   request->from + request->len > client->exp->size) {
>   error_setg(errp, "operation past EOF; From: %" PRIu64 ", Len: %" 
> PRIu32
> -   ", Size: %" PRIu64, request->from, request->len,
> -   (uint64_t)client->exp->size);
> +   ", Size: %" PRId64, request->from, request->len,
> +   client->exp->size);
>   return (request->type == NBD_CMD_WRITE ||
>   request->type == NBD_CMD_WRITE_ZEROES) ? -ENOSPC : -EINVAL;
>   }
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index ff4adb9b3eb..96c0829970c 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -176,7 +176,7 @@ static void read_partition(uint8_t *p, struct 
> partition_record *r)
>   }
> 
>   static int find_partition(BlockBackend *blk, int partition,
> -  off_t *offset, off_t *size)
> +  uint64_t *offset, int64_t *size)

function never return negative @size, so what is the reason to keep it signed?

Also, type conversion (uint64_t) should be dropped from the function code I 
think.

>   {
>   struct partition_record mbr[4];
>   uint8_t data[MBR_SIZE];
> @@ -500,14 +500,14 @@ int main(int argc, char **argv)
>   {
>   BlockBackend *blk;
>   BlockDriverState *bs;
> -off_t dev_offset = 0;
> +uint64_t dev_offset = 0;
>   uint16_t nbdflags = 0;
>   bool disconnect = false;

Re: [Qemu-devel] test-filter-mirror hangs

2019-01-15 Thread Peter Maydell
On Fri, 11 Jan 2019 at 16:15, Dr. David Alan Gilbert
 wrote:
>
> * Peter Maydell (peter.mayd...@linaro.org) wrote:
> > Recently I've noticed that test-filter-mirror has been hanging
> > intermittently, typically when run on some other TCG architecture.
> > In the instance I've just looked at, this was with s390x guest on
> > x86-64 host, though I've also seen it on other host archs and
> > perhaps with other guests.
>
> Watch out to see if you really do see it for other guests;
> it carefully avoids using virtio-net to avoid vhost; but on s390x it
> uses virtio-net-ccw - could that hit the vhost it was trying to avoid?

I've seen several hangs in the last few days, all on s390x guests.
It is intermittent though, so sometimes s390x works fine.

thanks
-- PMM



Re: [Qemu-devel] [PATCH v1] virtio: add checks for the size of the indirect table

2019-01-15 Thread Philippe Mathieu-Daudé
On 1/15/19 11:08 AM, Dima Stepanov wrote:
> The virtqueue_pop() and virtqueue_get_avail_bytes() routines can use the
> INDIRECT table to get the data. It is possible to create a packet which
> will lead to the assert message like:
>   include/exec/memory.h:1995: void
>   address_space_read_cached(MemoryRegionCache *, hwaddr, void *, int):
>   Assertion `addr < cache->len && len <= cache->len - addr' failed.
>   Aborted
> To do it the first descriptor should have a link to the INDIRECT table
> and set the size of it to 0. It doesn't look good that the guest should
> be able to trigger the assert in qemu. Add additional check for the size
> of the INDIRECT table, which should not be 0.
> 
> Signed-off-by: Dima Stepanov 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
>  hw/virtio/virtio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 22bd1ac..a1ff647 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -646,7 +646,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned 
> int *in_bytes,
>  vring_desc_read(vdev, &desc, desc_cache, i);
>  
>  if (desc.flags & VRING_DESC_F_INDIRECT) {
> -if (desc.len % sizeof(VRingDesc)) {
> +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
>  virtio_error(vdev, "Invalid size for indirect buffer table");
>  goto err;
>  }
> @@ -902,7 +902,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
>  desc_cache = &caches->desc;
>  vring_desc_read(vdev, &desc, desc_cache, i);
>  if (desc.flags & VRING_DESC_F_INDIRECT) {
> -if (desc.len % sizeof(VRingDesc)) {
> +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
>  virtio_error(vdev, "Invalid size for indirect buffer table");
>  goto done;
>  }
> 



Re: [Qemu-devel] [PATCH v1] virtio: add checks for the size of the indirect table

2019-01-15 Thread Cornelia Huck
On Tue, 15 Jan 2019 13:08:47 +0300
Dima Stepanov  wrote:

> The virtqueue_pop() and virtqueue_get_avail_bytes() routines can use the
> INDIRECT table to get the data. It is possible to create a packet which
> will lead to the assert message like:
>   include/exec/memory.h:1995: void
>   address_space_read_cached(MemoryRegionCache *, hwaddr, void *, int):
>   Assertion `addr < cache->len && len <= cache->len - addr' failed.
>   Aborted
> To do it the first descriptor should have a link to the INDIRECT table
> and set the size of it to 0. It doesn't look good that the guest should
> be able to trigger the assert in qemu. Add additional check for the size
> of the INDIRECT table, which should not be 0.

Ouch, being able to crash QEMU by a specially crafted descriptor is bad.

Looking at the virtio spec, we don't seem to explicitly disallow
indirect descriptors with a zero-length table. So, as an alternative to
marking the device broken, we could also skip over such a descriptor.
Not sure whether that makes sense, though.

> 
> Signed-off-by: Dima Stepanov 
> ---
>  hw/virtio/virtio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 22bd1ac..a1ff647 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -646,7 +646,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned 
> int *in_bytes,
>  vring_desc_read(vdev, &desc, desc_cache, i);
>  
>  if (desc.flags & VRING_DESC_F_INDIRECT) {
> -if (desc.len % sizeof(VRingDesc)) {
> +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
>  virtio_error(vdev, "Invalid size for indirect buffer table");
>  goto err;
>  }
> @@ -902,7 +902,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
>  desc_cache = &caches->desc;
>  vring_desc_read(vdev, &desc, desc_cache, i);
>  if (desc.flags & VRING_DESC_F_INDIRECT) {
> -if (desc.len % sizeof(VRingDesc)) {
> +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
>  virtio_error(vdev, "Invalid size for indirect buffer table");
>  goto done;
>  }




Re: [Qemu-devel] [PATCH v1 4/8] RISC-V: Use riscv prefix consistently on cpu helpers

2019-01-15 Thread Philippe Mathieu-Daudé
Hi Alistair,

On 1/15/19 12:58 AM, Alistair Francis wrote:
> From: Michael Clark 
> 
> * Add riscv prefix to raise_exception function
> * Add riscv prefix to CSR read/write functions
> * Add riscv prefix to signal handler function
> * Add riscv prefix to get fflags function
> * Remove redundant declaration of riscv_cpu_init
>   and rename cpu_riscv_init to riscv_cpu_init
> * rename riscv_set_mode to riscv_cpu_set_mode
> 
> Cc: Sagar Karandikar 
> Cc: Bastian Koppelmann 
> Cc: Palmer Dabbelt 
> Cc: Alistair Francis 
> Signed-off-by: Michael Clark 
> Signed-off-by: Alistair Francis 
> ---
>  linux-user/riscv/signal.c |  4 ++--
>  target/riscv/cpu.h| 21 ++---
>  target/riscv/cpu_helper.c | 10 +-
>  target/riscv/csr.c|  8 
>  target/riscv/fpu_helper.c |  6 +++---
>  target/riscv/op_helper.c  | 28 ++--
>  6 files changed, 38 insertions(+), 39 deletions(-)
> 
> diff --git a/linux-user/riscv/signal.c b/linux-user/riscv/signal.c
> index f598d41891..83ecc6f799 100644
> --- a/linux-user/riscv/signal.c
> +++ b/linux-user/riscv/signal.c
> @@ -83,7 +83,7 @@ static void setup_sigcontext(struct target_sigcontext *sc, 
> CPURISCVState *env)
>  __put_user(env->fpr[i], &sc->fpr[i]);
>  }
>  
> -uint32_t fcsr = csr_read_helper(env, CSR_FCSR); /*riscv_get_fcsr(env);*/
> +uint32_t fcsr = riscv_csr_read(env, CSR_FCSR);
>  __put_user(fcsr, &sc->fcsr);
>  }
>  
> @@ -159,7 +159,7 @@ static void restore_sigcontext(CPURISCVState *env, struct 
> target_sigcontext *sc)
>  
>  uint32_t fcsr;
>  __get_user(fcsr, &sc->fcsr);
> -csr_write_helper(env, fcsr, CSR_FCSR);
> +riscv_csr_write(env, CSR_FCSR, fcsr);
>  }
>  
>  static void restore_ucontext(CPURISCVState *env, struct target_ucontext *uc)
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 681341f5d5..a97435bd7b 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -256,7 +256,7 @@ int riscv_cpu_handle_mmu_fault(CPUState *cpu, vaddr 
> address, int size,
>  char *riscv_isa_string(RISCVCPU *cpu);
>  void riscv_cpu_list(FILE *f, fprintf_function cpu_fprintf);
>  
> -#define cpu_signal_handler cpu_riscv_signal_handler
> +#define cpu_signal_handler riscv_cpu_signal_handler
>  #define cpu_list riscv_cpu_list
>  #define cpu_mmu_index riscv_cpu_mmu_index
>  
> @@ -264,16 +264,15 @@ void riscv_cpu_list(FILE *f, fprintf_function 
> cpu_fprintf);
>  uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value);
>  #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */
>  #endif
> -void riscv_set_mode(CPURISCVState *env, target_ulong newpriv);
> +void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv);
>  
>  void riscv_translate_init(void);
> -RISCVCPU *cpu_riscv_init(const char *cpu_model);
> -int cpu_riscv_signal_handler(int host_signum, void *pinfo, void *puc);
> -void QEMU_NORETURN do_raise_exception_err(CPURISCVState *env,
> -  uint32_t exception, uintptr_t pc);
> +int riscv_cpu_signal_handler(int host_signum, void *pinfo, void *puc);
> +void QEMU_NORETURN riscv_raise_exception(CPURISCVState *env,
> + uint32_t exception, uintptr_t pc);
>  
> -target_ulong cpu_riscv_get_fflags(CPURISCVState *env);
> -void cpu_riscv_set_fflags(CPURISCVState *env, target_ulong);
> +target_ulong riscv_cpu_get_fflags(CPURISCVState *env);
> +void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong);
>  
>  #define TB_FLAGS_MMU_MASK   3
>  #define TB_FLAGS_MSTATUS_FS MSTATUS_FS
> @@ -293,13 +292,13 @@ static inline void cpu_get_tb_cpu_state(CPURISCVState 
> *env, target_ulong *pc,
>  int riscv_csrrw(CPURISCVState *env, int csrno, target_ulong *ret_value,
>  target_ulong new_value, target_ulong write_mask);
>  
> -static inline void csr_write_helper(CPURISCVState *env, target_ulong val,
> -int csrno)
> +static inline void riscv_csr_write(CPURISCVState *env, int csrno,
> +   target_ulong val)
>  {
>  riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS));
>  }
>  
> -static inline target_ulong csr_read_helper(CPURISCVState *env, int csrno)
> +static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)

Don't you need to update target/riscv/gdbstub.c (in
riscv_cpu_gdb_read_register)?

>  {
>  target_ulong val = 0;
>  riscv_csrrw(env, csrno, &val, 0, 0);
> diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
> index f257050f12..f49e98ed59 100644
> --- a/target/riscv/cpu_helper.c
> +++ b/target/riscv/cpu_helper.c
> @@ -93,7 +93,7 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, 
> uint32_t value)
>  return old;
>  }
>  
> -void riscv_set_mode(CPURISCVState *env, target_ulong newpriv)
> +void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv)
>  {
>  if (newpriv > PRV_M) {
>  g_as

[Qemu-devel] [PATCH 1/2] qcow2: include LUKS payload overhead in qemu-img measure

2019-01-15 Thread Stefan Hajnoczi
LUKS encryption reserves clusters for its own payload data.  The size of
this area must be included in the qemu-img measure calculation so that
we arrive at the correct minimum required image size.

(Ab)use the qcrypto_block_create() API to determine the payload
overhead.  We discard the payload data that qcrypto thinks will be
written to the image.

Signed-off-by: Stefan Hajnoczi 
---
 block/qcow2.c | 51 ++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 4897abae5e..7ab93a5d2f 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -4231,6 +4231,24 @@ static coroutine_fn int 
qcow2_co_flush_to_os(BlockDriverState *bs)
 return ret;
 }
 
+static ssize_t qcow2_measure_crypto_hdr_init_func(QCryptoBlock *block,
+size_t headerlen, void *opaque, Error **errp)
+{
+size_t *headerlenp = opaque;
+
+/* Stash away the payload size */
+*headerlenp = headerlen;
+return 0;
+}
+
+static ssize_t qcow2_measure_crypto_hdr_write_func(QCryptoBlock *block,
+size_t offset, const uint8_t *buf, size_t buflen,
+void *opaque, Error **errp)
+{
+/* Discard the bytes, we're not actually writing to an image */
+return buflen;
+}
+
 static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
Error **errp)
 {
@@ -4240,11 +4258,13 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, 
BlockDriverState *in_bs,
 uint64_t virtual_size; /* disk size as seen by guest */
 uint64_t refcount_bits;
 uint64_t l2_tables;
+uint64_t luks_payload_size = 0;
 size_t cluster_size;
 int version;
 char *optstr;
 PreallocMode prealloc;
 bool has_backing_file;
+bool has_luks;
 
 /* Parse image creation options */
 cluster_size = qcow2_opt_get_cluster_size_del(opts, &local_err);
@@ -4274,6 +4294,35 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, 
BlockDriverState *in_bs,
 has_backing_file = !!optstr;
 g_free(optstr);
 
+optstr = qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT_FORMAT);
+has_luks = optstr && strcmp(optstr, "luks") == 0;
+g_free(optstr);
+
+if (has_luks) {
+QCryptoBlockCreateOptions cryptoopts = {
+.format = Q_CRYPTO_BLOCK_FORMAT_LUKS,
+};
+QCryptoBlock *crypto;
+size_t headerlen;
+
+optstr = qemu_opt_get_del(opts, "encrypt.key-secret");
+cryptoopts.u.luks.has_key_secret = !!optstr;
+cryptoopts.u.luks.key_secret = optstr;
+
+crypto = qcrypto_block_create(&cryptoopts, "encrypt.",
+  qcow2_measure_crypto_hdr_init_func,
+  qcow2_measure_crypto_hdr_write_func,
+  &headerlen, &local_err);
+
+g_free(optstr);
+if (!crypto) {
+goto err;
+}
+qcrypto_block_free(crypto);
+
+luks_payload_size = ROUND_UP(headerlen, cluster_size);
+}
+
 virtual_size = qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0);
 virtual_size = ROUND_UP(virtual_size, cluster_size);
 
@@ -4344,7 +4393,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, 
BlockDriverState *in_bs,
 info = g_new(BlockMeasureInfo, 1);
 info->fully_allocated =
 qcow2_calc_prealloc_size(virtual_size, cluster_size,
- ctz32(refcount_bits));
+ ctz32(refcount_bits)) + luks_payload_size;
 
 /* Remove data clusters that are not required.  This overestimates the
  * required size because metadata needed for the fully allocated file is
-- 
2.20.1




[Qemu-devel] [PATCH 0/2] qcow2: include LUKS payload overhead in qemu-img measure

2019-01-15 Thread Stefan Hajnoczi
The LUKS payload has a significant size (>1 MB).  It must be included in the
qemu-img measure calculation so we arrive at the correct minimum image size.

Stefan Hajnoczi (2):
  qcow2: include LUKS payload overhead in qemu-img measure
  iotests: add LUKS payload overhead to 178 qemu-img measure test

 block/qcow2.c| 51 +++-
 tests/qemu-iotests/178   |  8 +
 tests/qemu-iotests/178.out.qcow2 | 24 +++
 3 files changed, 82 insertions(+), 1 deletion(-)

-- 
2.20.1




[Qemu-devel] [PATCH 2/2] iotests: add LUKS payload overhead to 178 qemu-img measure test

2019-01-15 Thread Stefan Hajnoczi
The previous patch includes the LUKS payload overhead into the qemu-img
measure calculation for qcow2.  Update qemu-iotests 178 to exercise this
new code path.

Signed-off-by: Stefan Hajnoczi 
---
 tests/qemu-iotests/178   |  8 
 tests/qemu-iotests/178.out.qcow2 | 24 
 2 files changed, 32 insertions(+)

diff --git a/tests/qemu-iotests/178 b/tests/qemu-iotests/178
index 3f4b4a4564..23eb017ea1 100755
--- a/tests/qemu-iotests/178
+++ b/tests/qemu-iotests/178
@@ -142,6 +142,14 @@ for ofmt in human json; do
 # The backing file doesn't need to exist :)
 $QEMU_IMG measure --output=$ofmt -o backing_file=x \
   -f "$fmt" -O "$IMGFMT" "$TEST_IMG"
+
+echo
+echo "== $fmt input image and LUKS encryption =="
+echo
+$QEMU_IMG measure --output=$ofmt \
+  --object secret,id=sec0,data=base \
+  -o encrypt.format=luks,encrypt.key-secret=sec0 \
+  -f "$fmt" -O "$IMGFMT" "$TEST_IMG"
 fi
 
 echo
diff --git a/tests/qemu-iotests/178.out.qcow2 b/tests/qemu-iotests/178.out.qcow2
index d42d4a4597..55a8dc926f 100644
--- a/tests/qemu-iotests/178.out.qcow2
+++ b/tests/qemu-iotests/178.out.qcow2
@@ -68,6 +68,11 @@ converted image file size in bytes: 458752
 required size: 1074135040
 fully allocated size: 1074135040
 
+== qcow2 input image and LUKS encryption ==
+
+required size: 2686976
+fully allocated size: 1076232192
+
 == qcow2 input image and preallocation (human) ==
 
 required size: 1074135040
@@ -114,6 +119,11 @@ converted image file size in bytes: 524288
 required size: 1074135040
 fully allocated size: 1074135040
 
+== raw input image and LUKS encryption ==
+
+required size: 2686976
+fully allocated size: 1076232192
+
 == raw input image and preallocation (human) ==
 
 required size: 1074135040
@@ -205,6 +215,13 @@ converted image file size in bytes: 458752
 "fully-allocated": 1074135040
 }
 
+== qcow2 input image and LUKS encryption ==
+
+{
+"required": 2686976,
+"fully-allocated": 1076232192
+}
+
 == qcow2 input image and preallocation (json) ==
 
 {
@@ -263,6 +280,13 @@ converted image file size in bytes: 524288
 "fully-allocated": 1074135040
 }
 
+== raw input image and LUKS encryption ==
+
+{
+"required": 2686976,
+"fully-allocated": 1076232192
+}
+
 == raw input image and preallocation (json) ==
 
 {
-- 
2.20.1




Re: [Qemu-devel] [PULL 00/21] misc testing fixes for Travis and docker

2019-01-15 Thread Peter Maydell
On Mon, 14 Jan 2019 at 15:01, Alex Bennée  wrote:
>
> The following changes since commit 7260438b7056469610ee166f7abe9ff8a26b8b16:
>
>   Merge remote-tracking branch 
> 'remotes/palmer/tags/riscv-for-master-3.2-part2' into staging (2019-01-14 
> 11:41:43 +)
>
> are available in the Git repository at:
>
>   https://github.com/stsquad/qemu.git tags/pull-testing-next-140119-1
>
> for you to fetch changes up to a36270a4d1589b1ed309065fc8b3fe0ac8d6869d:
>
>   Revert "tests: Disable qht-bench parallel test when using gprof" 
> (2019-01-14 14:55:32 +)
>
> 
> A bunch of fixes for testing:
>
>   - Various Travis updates
>   - "stable" SID snapshot for docker
>   - avoid :latest docker tags
>   - g_usleep fix for some tests
>

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.

-- PMM



Re: [Qemu-devel] [PATCH 0/2] qcow2: include LUKS payload overhead in qemu-img measure

2019-01-15 Thread Philippe Mathieu-Daudé
On 1/15/19 12:10 PM, Stefan Hajnoczi wrote:
> The LUKS payload has a significant size (>1 MB).  It must be included in the
> qemu-img measure calculation so we arrive at the correct minimum image size.
> 
> Stefan Hajnoczi (2):
>   qcow2: include LUKS payload overhead in qemu-img measure
>   iotests: add LUKS payload overhead to 178 qemu-img measure test
> 
>  block/qcow2.c| 51 +++-
>  tests/qemu-iotests/178   |  8 +
>  tests/qemu-iotests/178.out.qcow2 | 24 +++
>  3 files changed, 82 insertions(+), 1 deletion(-)
> 

Reviewed-by: Philippe Mathieu-Daudé 



Re: [Qemu-devel] [qemu-s390x] [PATCH v2] configure: Only build the s390-ccw bios if the compiler supports -march=z900

2019-01-15 Thread Christian Borntraeger



On 14.01.2019 13:52, Thomas Huth wrote:
> We want to build our s390-ccw bios with -march=z900 so that it also
> works with the oldest s390x CPU that we support with TCG. However,
> Clang on s390x does not support -march=z900 anymore, so we can not
> use this compiler to build the s390-ccw bios. Thus add a proper test
> to the configure script to see whether the compiler is usable.
> 
> Signed-off-by: Thomas Huth 

Acked-by: Christian Borntraeger 

> ---
>  v2: Use compile_prog as suggested by Peter
> 
>  configure | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index 05b7e85..2b9ba7d 100755
> --- a/configure
> +++ b/configure
> @@ -5905,8 +5905,12 @@ if test "$cpu" = "ppc64" -a "$targetos" != "Darwin" ; 
> then
>roms="$roms spapr-rtas"
>  fi
>  
> +# Only build s390-ccw bios if we're on s390x and the compiler has -march=z900
>  if test "$cpu" = "s390x" ; then
> -  roms="$roms s390-ccw"
> +  write_c_skeleton
> +  if compile_prog "-march=z900" ""; then
> +roms="$roms s390-ccw"
> +  fi
>  fi
>  
>  # Probe for the need for relocating the user-only binary.
> 




Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper

2019-01-15 Thread Cornelia Huck
On Fri, 11 Jan 2019 17:58:00 +0100
Eric Auger  wrote:

> The code used to attach the eventfd handler for the ERR and
> REQ irq indices can be factorized into a helper. In subsequent
> patches we will extend this helper to support other irq indices.

Looks like a nice refactoring to me.

> 
> We test the notification is allowed outside of the helper:

s/We test/We test whether/

> respectively check vdev->pci_aer and VFIO_FEATURE_ENABLE_REQ.
> Depending on the returned value we set vdev->pci_aer and
> vdev->req_enabled. An error handle is introduced for future usage
> although not strictly useful here.
> 
> Signed-off-by: Eric Auger 
> ---
>  hw/vfio/pci.c | 291 ++
>  1 file changed, 127 insertions(+), 164 deletions(-)
> 
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index c0cb1ec289..c589a4e666 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -105,6 +105,95 @@ static void vfio_intx_eoi(VFIODevice *vbasedev)
>  vfio_unmask_single_irqindex(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>  }
>  
> +/*
> + * vfio_register_event_notifier - setup/tear down eventfd
> + * notification and handling for IRQ indices that span over
> + * a single IRQ
> + *
> + * @vdev: VFIO device handle
> + * @index: IRQ index the eventfd/handler is associated to

s/to/with/ ?

> + * @target_state: true means notifier needs to be set up
> + * @handler to attach if @target_state is true
> + * @errp error handle
> + */
> +static int vfio_register_event_notifier(VFIOPCIDevice *vdev,
> +int index,
> +bool target_state,
> +void (*handler)(void *opaque),
> +Error **errp)

(...)

> @@ -3069,8 +2998,29 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
>  goto out_teardown;
>  }
>  
> -vfio_register_err_notifier(vdev);
> -vfio_register_req_notifier(vdev);
> +if (vdev->pci_aer) {
> +/*
> + * Registers error notifier for devices supporting error recovery.
> + * If we encounter a failure in this function, we report an error

s/in this function/while registering it/ ?

> + * and continue after disabling error recovery support for the
> + * device.
> + */
> +vdev->pci_aer =
> +!vfio_register_event_notifier(vdev, VFIO_PCI_ERR_IRQ_INDEX, true,
> +  vfio_err_notifier_handler, &err);
> +if (err) {
> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> +}

I think you need to reset err to NULL if you want to reuse the variable.

Alternatively, you could keep the wrappers and define a local error
variable there.

> +}
> +
> +if (vdev->features & VFIO_FEATURE_ENABLE_REQ) {
> +vdev->req_enabled =
> +!vfio_register_event_notifier(vdev, VFIO_PCI_REQ_IRQ_INDEX, true,
> +  vfio_req_notifier_handler, &err);
> +if (err) {
> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> +}
> +}
>  vfio_setup_resetfn_quirk(vdev);
>  
>  return;
> @@ -3106,9 +3056,22 @@ static void vfio_instance_finalize(Object *obj)
>  static void vfio_exitfn(PCIDevice *pdev)
>  {
>  VFIOPCIDevice *vdev = PCI_VFIO(pdev);
> +Error *err = NULL;
>  
> -vfio_unregister_req_notifier(vdev);
> -vfio_unregister_err_notifier(vdev);
> +if (vdev->req_enabled) {
> +vfio_register_event_notifier(vdev, VFIO_PCI_REQ_IRQ_INDEX,
> + false, NULL, &err);
> +if (err) {
> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> +}

Likewise.

> +}
> +if (vdev->pci_aer) {
> +vfio_register_event_notifier(vdev, VFIO_PCI_ERR_IRQ_INDEX,
> + false, NULL, &err);
> +if (err) {
> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
> +}
> +}
>  pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>  vfio_disable_interrupts(vdev);
>  if (vdev->intx.mmap_timer) {




Re: [Qemu-devel] [PATCH 2/2] vfio-pci: Use vfio_register_event_notifier in vfio_intx_enable_kvm

2019-01-15 Thread Cornelia Huck
On Fri, 11 Jan 2019 17:58:01 +0100
Eric Auger  wrote:

> We can also use vfio_register_event_notifier() helper in
> vfio_intx_enable_kvm to set the signalling associated to
> VFIO_PCI_INTX_IRQ_INDEX.
> 
> Signed-off-by: Eric Auger 
> ---
>  hw/vfio/pci.c | 38 +++---
>  1 file changed, 7 insertions(+), 31 deletions(-)
> 

>  static void vfio_intx_disable(VFIOPCIDevice *vdev)

I'm wondering why the _disable path can't use the new helper. Ordering
issues?



[Qemu-devel] Profesjonalne Strony i Sklepy internetowe.

2019-01-15 Thread Strony, sklepy internetowe.


Dzień dobry,



tworzymy nowoczesne */Stron i Sklepów WWW.
/*


Jeżeli chcieliby Państwo otrzymać propozycję w tym zakresie dla Państwa firmy 
prosimy o odpowiedź "*TAK"*.







Serdecznie Pozdrawiamy



[Qemu-devel] [PATCH v3 0/4] QEMU changes to do PVH boot

2019-01-15 Thread Liam Merwick
For certain applications it is desirable to rapidly boot a KVM virtual
machine. In cases where legacy hardware and software support within the
guest is not needed, QEMU should be able to boot directly into the
uncompressed Linux kernel binary with minimal firmware involvement.

There already exists an ABI to allow this for Xen PVH guests and the ABI
is supported by Linux and FreeBSD:

   https://xenbits.xen.org/docs/unstable/misc/pvh.html

Details on the Linux changes (in 4.21): https://lkml.org/lkml/2018/12/14/1330
qboot pull request integrated: https://github.com/bonzini/qboot/pull/17 

This patch series provides QEMU support to read the ELF header of an
uncompressed kernel binary and get the 32-bit PVH kernel entry point
from an ELF Note.  In load_linux() a call is made to load_elfboot()
so see if the header matches that of an uncompressed kernel binary (ELF)
and if so, loads the binary and determines the kernel entry address
from an ELF Note in the binary.  Then qboot does futher initialisation
of the guest (e820, etc.) and jumps to the kernel entry address and
boots the guest.

changes v1 -> v2
- Based on feedback from Stefan Hajnoczi
- The reading of the PVH entry point is now done in a single pass during
  elf_load() which results in Patch2 in v1 being split into Patches 1&2 in v2
  and considerably reworked.
- Patch1 adds a new optional function pointer to parse the ELF note type
  (the type is passed in via the existing translate_opaque arg - the
  function already had 11 args so I didn't want to add more than one new arg).
- Patch2 adds a function to elf_ops.h to find an ELF note
  matching a specific type 
- Patch3 just has a line added to the commit message to state that the Xen
  repo is the canonical location
- Patch4 (that does the PVH boot) is mainly equivalent to Patch3 in v1
  just minor load_elfboot() changes and the addition of a
  read_pvh_start_addr() helper function for load_elf()

changes v2 -> v3
- Based on feedback from Stefan Hajnoczi
- Fix formatting issues where a few tabs snuck in v2
- Moved code to use ELF Note in load_elf() from Patch1 to Patch2
- In load_elf() set data to NULL after g_free() [now in Patch2 following move]
- Added Patch5 containing changes by Stefano Garzarella to support -initrd

Usіng the method/scripts documented by the NEMU team at

   https://github.com/intel/nemu/wiki/Measuring-Boot-Latency
   https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg00200.html

below are some timings measured (vmlinux and bzImage from the same build)
Time to get to kernel start is almost halved (95ṁs -> 48ms)

QEMU + qboot + vmlinux (PVH + 4.20-rc4)
 qemu_init_end: 41.550521
 fw_start: 41.667139 (+0.116618)
 fw_do_boot: 47.448495 (+5.781356)
 linux_startup_64: 47.720785 (+0.27229)
 linux_start_kernel: 48.399541 (+0.678756)
 linux_start_user: 296.952056 (+248.552515)

QEMU + qboot + bzImage:
 qemu_init_end: 29.209276
 fw_start: 29.317342 (+0.108066)
 linux_start_boot: 36.679362 (+7.36202)
 linux_startup_64: 94.531349 (+57.851987)
 linux_start_kernel: 94.900913 (+0.369564)
 linux_start_user: 401.060971 (+306.160058)

QEMU + bzImage:
 qemu_init_end: 30.424430
 linux_startup_64: 893.770334 (+863.345904)
 linux_start_kernel: 894.17049 (+0.400156)
 linux_start_user: 1208.679768 (+314.509278)


Liam Merwick (4):
  elf: Add optional function ptr to load_elf() to parse ELF notes
  elf-ops.h: Add get_elf_note_type()
  pvh: Add x86/HVM direct boot ABI header file
  pvh: Boot uncompressed kernel using direct boot ABI

 hw/alpha/dp264.c   |   4 +-
 hw/arm/armv7m.c|   3 +-
 hw/arm/boot.c  |   2 +-
 hw/core/generic-loader.c   |   2 +-
 hw/core/loader.c   |  24 ---
 hw/cris/boot.c |   3 +-
 hw/hppa/machine.c  |   6 +-
 hw/i386/multiboot.c|   2 +-
 hw/i386/pc.c   | 135 +
 hw/lm32/lm32_boards.c  |   6 +-
 hw/lm32/milkymist.c|   3 +-
 hw/m68k/an5206.c   |   2 +-
 hw/m68k/mcf5208.c  |   2 +-
 hw/microblaze/boot.c   |   7 +-
 hw/mips/mips_fulong2e.c|   5 +-
 hw/mips/mips_malta.c   |   5 +-
 hw/mips/mips_mipssim.c |   5 +-
 hw/mips/mips_r4k.c |   5 +-
 hw/moxie/moxiesim.c|   2 +-
 hw/nios2/boot.c|   7 +-
 hw/openrisc/openrisc_sim.c |   2 +-
 hw/pci-host/prep.c |   2 +-
 hw/ppc/e500.c  |   3 +-
 hw/ppc/mac_newworld.c  |   5 +-
 hw/ppc/mac_oldworld.c  |   5 +-
 hw/ppc/ppc440_bamboo.c |   2 +-
 hw/ppc/sam460ex.c  |   3 +-
 hw/ppc/spapr.c |   7 +-
 hw/ppc/virtex_ml507.c  |   2 +-
 hw/riscv/sifive_e.c|   2 +-
 hw/riscv/sifive_u.c|   2 +-
 hw/riscv/spike.c   |   2 +-
 hw/riscv/virt.c|   2 +-
 hw/s390x/ipl.c |   9 ++-
 hw/sparc/leon3.c   |   3 +-
 hw/sparc/sun4m

[Qemu-devel] [PATCH v3 2/5] elf-ops.h: Add get_elf_note_type()

2019-01-15 Thread Liam Merwick
Introduce a routine which, given a pointer to a range of ELF Notes,
searches through them looking for a note matching the type specified
and returns a pointer to the matching ELF note.

get_elf_note_type() is used by elf_load[32|64]() to find the
specified note type required by the 'elf_note_fn' parameter
added in the previous commit.

Signed-off-by: Liam Merwick 
---
 include/hw/elf_ops.h | 75 
 1 file changed, 75 insertions(+)

diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 3438d6f69e8d..690f9238c8cc 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -265,6 +265,51 @@ fail:
 return ret;
 }
 
+/*
+ * Given 'nhdr', a pointer to a range of ELF Notes, search through them
+ * for a note matching type 'elf_note_type' and return a pointer to
+ * the matching ELF note.
+ */
+static struct elf_note *glue(get_elf_note_type, SZ)(struct elf_note *nhdr,
+elf_word note_size,
+elf_word phdr_align,
+elf_word elf_note_type)
+{
+elf_word nhdr_size = sizeof(struct elf_note);
+elf_word elf_note_entry_offset = 0;
+elf_word note_type;
+elf_word nhdr_namesz;
+elf_word nhdr_descsz;
+
+if (nhdr == NULL) {
+return NULL;
+}
+
+note_type = nhdr->n_type;
+while (note_type != elf_note_type) {
+nhdr_namesz = nhdr->n_namesz;
+nhdr_descsz = nhdr->n_descsz;
+
+elf_note_entry_offset = nhdr_size +
+QEMU_ALIGN_UP(nhdr_namesz, phdr_align) +
+QEMU_ALIGN_UP(nhdr_descsz, phdr_align);
+
+/*
+ * If the offset calculated in this iteration exceeds the
+ * supplied size, we are done and no matching note was found.
+ */
+if (elf_note_entry_offset > note_size) {
+return NULL;
+}
+
+/* skip to the next ELF Note entry */
+nhdr = (void *)nhdr + elf_note_entry_offset;
+note_type = nhdr->n_type;
+}
+
+return nhdr;
+}
+
 static int glue(load_elf, SZ)(const char *name, int fd,
   uint64_t (*elf_note_fn)(void *, void *, bool),
   uint64_t (*translate_fn)(void *, uint64_t),
@@ -497,6 +542,36 @@ static int glue(load_elf, SZ)(const char *name, int fd,
 high = addr + mem_size;
 
 data = NULL;
+
+} else if (ph->p_type == PT_NOTE && elf_note_fn) {
+struct elf_note *nhdr = NULL;
+
+file_size = ph->p_filesz; /* Size of the range of ELF notes */
+data = g_malloc0(file_size);
+if (ph->p_filesz > 0) {
+if (lseek(fd, ph->p_offset, SEEK_SET) < 0) {
+goto fail;
+}
+if (read(fd, data, file_size) != file_size) {
+goto fail;
+}
+}
+
+/*
+ * Search the ELF notes to find one with a type matching the
+ * value passed in via 'translate_opaque'
+ */
+nhdr = (struct elf_note *)data;
+assert(translate_opaque != NULL);
+nhdr = glue(get_elf_note_type, SZ)(nhdr, file_size, ph->p_align,
+   *(uint64_t *)translate_opaque);
+if (nhdr != NULL) {
+bool is64 =
+sizeof(struct elf_note) == sizeof(struct elf64_note);
+elf_note_fn((void *)nhdr, (void *)&ph->p_align, is64);
+}
+g_free(data);
+data = NULL;
 }
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 4/5] pvh: Boot uncompressed kernel using direct boot ABI

2019-01-15 Thread Liam Merwick
These changes (along with corresponding Linux kernel and qboot changes)
enable a guest to be booted using the x86/HVM direct boot ABI.

This commit adds a load_elfboot() routine to pass the size and
location of the kernel entry point to qboot (which will fill in
the start_info struct information needed to to boot the guest).
Having loaded the ELF binary, load_linux() will run qboot
which continues the boot.

The address for the kernel entry point is read from an ELF Note
in the uncompressed kernel binary by a helper routine passed
to load_elf().

Co-developed-by: George Kennedy 
Signed-off-by: George Kennedy 
Signed-off-by: Liam Merwick 
---
 hw/i386/pc.c  | 135 ++
 include/elf.h |  10 +
 2 files changed, 145 insertions(+)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 73d688f84239..6d549950a044 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -54,6 +54,7 @@
 #include "sysemu/qtest.h"
 #include "kvm_i386.h"
 #include "hw/xen/xen.h"
+#include "hw/xen/start_info.h"
 #include "ui/qemu-spice.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
@@ -110,6 +111,9 @@ static struct e820_entry *e820_table;
 static unsigned e820_entries;
 struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
 
+/* Physical Address of PVH entry point read from kernel ELF NOTE */
+static size_t pvh_start_addr;
+
 GlobalProperty pc_compat_3_1[] = {
 { "intel-iommu", "dma-drain", "off" },
 { "Opteron_G3" "-" TYPE_X86_CPU, "rdtscp", "off" },
@@ -1060,6 +1064,109 @@ struct setup_data {
 uint8_t data[0];
 } __attribute__((packed));
 
+
+/*
+ * The entry point into the kernel for PVH boot is different from
+ * the native entry point.  The PVH entry is defined by the x86/HVM
+ * direct boot ABI and is available in an ELFNOTE in the kernel binary.
+ *
+ * This function is passed to load_elf() when it is called from
+ * load_elfboot() which then additionally checks for an ELF Note of
+ * type XEN_ELFNOTE_PHYS32_ENTRY and passes it to this function to
+ * parse the PVH entry address from the ELF Note.
+ *
+ * Due to trickery in elf_opts.h, load_elf() is actually available as
+ * load_elf32() or load_elf64() and this routine needs to be able
+ * to deal with being called as 32 or 64 bit.
+ *
+ * The address of the PVH entry point is saved to the 'pvh_start_addr'
+ * global variable.  (although the entry point is 32-bit, the kernel
+ * binary can be either 32-bit or 64-bit).
+ */
+static uint64_t read_pvh_start_addr(void *arg1, void *arg2, bool is64)
+{
+size_t *elf_note_data_addr;
+
+/* Check if ELF Note header passed in is valid */
+if (arg1 == NULL) {
+return 0;
+}
+
+if (is64) {
+struct elf64_note *nhdr64 = (struct elf64_note *)arg1;
+uint64_t nhdr_size64 = sizeof(struct elf64_note);
+uint64_t phdr_align = *(uint64_t *)arg2;
+uint64_t nhdr_namesz = nhdr64->n_namesz;
+
+elf_note_data_addr =
+((void *)nhdr64) + nhdr_size64 +
+QEMU_ALIGN_UP(nhdr_namesz, phdr_align);
+} else {
+struct elf32_note *nhdr32 = (struct elf32_note *)arg1;
+uint32_t nhdr_size32 = sizeof(struct elf32_note);
+uint32_t phdr_align = *(uint32_t *)arg2;
+uint32_t nhdr_namesz = nhdr32->n_namesz;
+
+elf_note_data_addr =
+((void *)nhdr32) + nhdr_size32 +
+QEMU_ALIGN_UP(nhdr_namesz, phdr_align);
+}
+
+pvh_start_addr = *elf_note_data_addr;
+
+return pvh_start_addr;
+}
+
+static bool load_elfboot(const char *kernel_filename,
+   int kernel_file_size,
+   uint8_t *header,
+   size_t pvh_xen_start_addr,
+   FWCfgState *fw_cfg)
+{
+uint32_t flags = 0;
+uint32_t mh_load_addr = 0;
+uint32_t elf_kernel_size = 0;
+uint64_t elf_entry;
+uint64_t elf_low, elf_high;
+int kernel_size;
+
+if (ldl_p(header) != 0x464c457f) {
+return false; /* no elfboot */
+}
+
+bool elf_is64 = header[EI_CLASS] == ELFCLASS64;
+flags = elf_is64 ?
+((Elf64_Ehdr *)header)->e_flags : ((Elf32_Ehdr *)header)->e_flags;
+
+if (flags & 0x00010004) { /* LOAD_ELF_HEADER_HAS_ADDR */
+error_report("elfboot unsupported flags = %x", flags);
+exit(1);
+}
+
+uint64_t elf_note_type = XEN_ELFNOTE_PHYS32_ENTRY;
+kernel_size = load_elf(kernel_filename, read_pvh_start_addr,
+   NULL, &elf_note_type, &elf_entry,
+   &elf_low, &elf_high, 0, I386_ELF_MACHINE,
+   0, 0);
+
+if (kernel_size < 0) {
+error_report("Error while loading elf kernel");
+exit(1);
+}
+mh_load_addr = elf_low;
+elf_kernel_size = elf_high - elf_low;
+
+if (pvh_start_addr == 0) {
+error_report("Error loading uncompressed kernel without PVH ELF Note");
+exit(1);
+}
+fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ENTRY, pvh_start_addr);
+fw_cfg_add_i

[Qemu-devel] [PATCH v3 3/5] pvh: Add x86/HVM direct boot ABI header file

2019-01-15 Thread Liam Merwick
From: Liam Merwick 

The x86/HVM direct boot ABI permits Qemu to be able to boot directly
into the uncompressed Linux kernel binary with minimal firmware involvement.

https://xenbits.xen.org/docs/unstable/misc/pvh.html

This commit adds the header file that defines the start_info struct
that needs to be populated in order to use this ABI.

The canonical version of start_info.h is in the Xen codebase.
(like QEMU, the Linux kernel uses a copy as well).

Signed-off-by: Liam Merwick 
Reviewed-by: Konrad Rzeszutek Wilk 
---
 include/hw/xen/start_info.h | 146 
 1 file changed, 146 insertions(+)
 create mode 100644 include/hw/xen/start_info.h

diff --git a/include/hw/xen/start_info.h b/include/hw/xen/start_info.h
new file mode 100644
index ..348779eb10cd
--- /dev/null
+++ b/include/hw/xen/start_info.h
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ *
+ * Copyright (c) 2016, Citrix Systems, Inc.
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+
+/*
+ * Start of day structure passed to PVH guests and to HVM guests in %ebx.
+ *
+ * NOTE: nothing will be loaded at physical address 0, so a 0 value in any
+ * of the address fields should be treated as not present.
+ *
+ *  0 ++
+ *| magic  | Contains the magic value XEN_HVM_START_MAGIC_VALUE
+ *|| ("xEn3" with the 0x80 bit of the "E" set).
+ *  4 ++
+ *| version| Version of this structure. Current version is 1. New
+ *|| versions are guaranteed to be backwards-compatible.
+ *  8 ++
+ *| flags  | SIF_xxx flags.
+ * 12 ++
+ *| nr_modules | Number of modules passed to the kernel.
+ * 16 ++
+ *| modlist_paddr  | Physical address of an array of modules
+ *|| (layout of the structure below).
+ * 24 ++
+ *| cmdline_paddr  | Physical address of the command line,
+ *|| a zero-terminated ASCII string.
+ * 32 ++
+ *| rsdp_paddr | Physical address of the RSDP ACPI data structure.
+ * 40 ++
+ *| memmap_paddr   | Physical address of the (optional) memory map. Only
+ *|| present in version 1 and newer of the structure.
+ * 48 ++
+ *| memmap_entries | Number of entries in the memory map table. Only
+ *|| present in version 1 and newer of the structure.
+ *|| Zero if there is no memory map being provided.
+ * 52 ++
+ *| reserved   | Version 1 and newer only.
+ * 56 ++
+ *
+ * The layout of each entry in the module structure is the following:
+ *
+ *  0 ++
+ *| paddr  | Physical address of the module.
+ *  8 ++
+ *| size   | Size of the module in bytes.
+ * 16 ++
+ *| cmdline_paddr  | Physical address of the command line,
+ *|| a zero-terminated ASCII string.
+ * 24 ++
+ *| reserved   |
+ * 32 ++
+ *
+ * The layout of each entry in the memory map table is as follows:
+ *
+ *  0 ++
+ *| addr   | Base address
+ *  8 ++
+ *| size   | Size of mapping in bytes
+ * 16 ++
+ *| type   | Type of mapping as defined between the hypervisor
+ *|| and guest it's starting. E820_TYPE_xxx, for example.
+ * 20 +|
+ *| reserved   |
+ * 24 ++
+ *
+ * The address and sizes are always a 64bit little endian unsigned integer.
+ *
+ * NB: Xen on x86 will always try to place all the data below the 4GiB
+ * boundary.
+ *
+ * Version numbers of the hvm_start_info structure have evolved lik

[Qemu-devel] [PATCH v3 1/5] elf: Add optional function ptr to load_elf() to parse ELF notes

2019-01-15 Thread Liam Merwick
This patch adds an optional function pointer, 'elf_note_fn', to
load_elf() which causes load_elf() to additionally parse any
ELF program headers of type PT_NOTE and check to see if the ELF
Note is of the type specified by the 'translate_opaque' arg.
If a matching ELF Note is found then the specfied function pointer
is called to process the ELF note.

Passing a NULL function pointer results in ELF Notes being skipped.

The first consumer of this functionality is the PVHboot support
which needs to read the XEN_ELFNOTE_PHYS32_ENTRY ELF Note while
loading the uncompressed kernel binary in order to discover the
boot entry address for the x86/HVM direct boot ABI.

Signed-off-by: Liam Merwick 
---
 hw/alpha/dp264.c   |  4 ++--
 hw/arm/armv7m.c|  3 ++-
 hw/arm/boot.c  |  2 +-
 hw/core/generic-loader.c   |  2 +-
 hw/core/loader.c   | 24 
 hw/cris/boot.c |  3 ++-
 hw/hppa/machine.c  |  6 +++---
 hw/i386/multiboot.c|  2 +-
 hw/lm32/lm32_boards.c  |  6 --
 hw/lm32/milkymist.c|  3 ++-
 hw/m68k/an5206.c   |  2 +-
 hw/m68k/mcf5208.c  |  2 +-
 hw/microblaze/boot.c   |  7 ---
 hw/mips/mips_fulong2e.c|  5 +++--
 hw/mips/mips_malta.c   |  5 +++--
 hw/mips/mips_mipssim.c |  5 +++--
 hw/mips/mips_r4k.c |  5 +++--
 hw/moxie/moxiesim.c|  2 +-
 hw/nios2/boot.c|  7 ---
 hw/openrisc/openrisc_sim.c |  2 +-
 hw/pci-host/prep.c |  2 +-
 hw/ppc/e500.c  |  3 ++-
 hw/ppc/mac_newworld.c  |  5 +++--
 hw/ppc/mac_oldworld.c  |  5 +++--
 hw/ppc/ppc440_bamboo.c |  2 +-
 hw/ppc/sam460ex.c  |  3 ++-
 hw/ppc/spapr.c |  7 ---
 hw/ppc/virtex_ml507.c  |  2 +-
 hw/riscv/sifive_e.c|  2 +-
 hw/riscv/sifive_u.c|  2 +-
 hw/riscv/spike.c   |  2 +-
 hw/riscv/virt.c|  2 +-
 hw/s390x/ipl.c |  9 ++---
 hw/sparc/leon3.c   |  3 ++-
 hw/sparc/sun4m.c   |  6 --
 hw/sparc64/sun4u.c |  4 ++--
 hw/tricore/tricore_testboard.c |  2 +-
 hw/xtensa/sim.c| 12 
 hw/xtensa/xtfpga.c |  2 +-
 include/hw/elf_ops.h   |  2 ++
 include/hw/loader.h|  9 -
 41 files changed, 113 insertions(+), 70 deletions(-)

diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c
index dd62f2a4050c..0347eb897c8a 100644
--- a/hw/alpha/dp264.c
+++ b/hw/alpha/dp264.c
@@ -114,7 +114,7 @@ static void clipper_init(MachineState *machine)
 error_report("no palcode provided");
 exit(1);
 }
-size = load_elf(palcode_filename, cpu_alpha_superpage_to_phys,
+size = load_elf(palcode_filename, NULL, cpu_alpha_superpage_to_phys,
 NULL, &palcode_entry, &palcode_low, &palcode_high,
 0, EM_ALPHA, 0, 0);
 if (size < 0) {
@@ -133,7 +133,7 @@ static void clipper_init(MachineState *machine)
 if (kernel_filename) {
 uint64_t param_offset;
 
-size = load_elf(kernel_filename, cpu_alpha_superpage_to_phys,
+size = load_elf(kernel_filename, NULL, cpu_alpha_superpage_to_phys,
 NULL, &kernel_entry, &kernel_low, &kernel_high,
 0, EM_ALPHA, 0, 0);
 if (size < 0) {
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
index f4446528307f..ae68aadef965 100644
--- a/hw/arm/armv7m.c
+++ b/hw/arm/armv7m.c
@@ -293,7 +293,8 @@ void armv7m_load_kernel(ARMCPU *cpu, const char 
*kernel_filename, int mem_size)
 as = cpu_get_address_space(cs, asidx);
 
 if (kernel_filename) {
-image_size = load_elf_as(kernel_filename, NULL, NULL, &entry, &lowaddr,
+image_size = load_elf_as(kernel_filename, NULL, NULL, NULL,
+ &entry, &lowaddr,
  NULL, big_endian, EM_ARM, 1, 0, as);
 if (image_size < 0) {
 image_size = load_image_targphys_as(kernel_filename, 0,
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index c7a67af7a97c..9d8746f7613f 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -885,7 +885,7 @@ static int64_t arm_load_elf(struct arm_boot_info *info, 
uint64_t *pentry,
 }
 }
 
-ret = load_elf_as(info->kernel_filename, NULL, NULL,
+ret = load_elf_as(info->kernel_filename, NULL, NULL, NULL,
   pentry, lowaddr, highaddr, big_endian, elf_machine,
   1, data_swab, as);
 if (ret <= 0) {
diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index fbae05fb3b64..3695dd439cd0 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -136,7 +136,7 @@ static void generic_loader_realize(DeviceState *dev, Error 
**errp)
 AddressSpace *as = s->cpu ? s->cpu->as :  NULL;
 
 if (!s->force_raw) {
-  

[Qemu-devel] [PATCH v3 5/5] pvh: load initrd and expose it through fw_cfg

2019-01-15 Thread Liam Merwick
From: Stefano Garzarella 

When initrd is specified, load and expose it to the guest firmware
through fw_cfg. The firmware will fill the hvm_start_info for the
kernel.

Signed-off-by: Stefano Garzarella 
Based-on: <1545422632-2-5-git-send-email-liam.merw...@oracle.com>
Signed-off-by: Liam Merwick 
---
 hw/i386/pc.c | 38 +-
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 6d549950a044..9ed5063de8f8 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1213,25 +1213,45 @@ static void load_linux(PCMachineState *pcms,
  */
 if (load_elfboot(kernel_filename, kernel_size,
  header, pvh_start_addr, fw_cfg)) {
-struct hvm_modlist_entry ramdisk_mod = { 0 };
-
 fclose(f);
 
 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
 strlen(kernel_cmdline) + 1);
 fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
 
-assert(machine->device_memory != NULL);
-ramdisk_mod.paddr = machine->device_memory->base;
-ramdisk_mod.size =
-memory_region_size(&machine->device_memory->mr);
-
-fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, &ramdisk_mod,
- sizeof(ramdisk_mod));
 fw_cfg_add_i32(fw_cfg, FW_CFG_SETUP_SIZE, sizeof(header));
 fw_cfg_add_bytes(fw_cfg, FW_CFG_SETUP_DATA,
  header, sizeof(header));
 
+/* load initrd */
+if (initrd_filename) {
+gsize initrd_size;
+gchar *initrd_data;
+GError *gerr = NULL;
+
+if (!g_file_get_contents(initrd_filename, &initrd_data,
+&initrd_size, &gerr)) {
+fprintf(stderr, "qemu: error reading initrd %s: %s\n",
+initrd_filename, gerr->message);
+exit(1);
+}
+
+initrd_max = pcms->below_4g_mem_size - pcmc->acpi_data_size - 
1;
+if (initrd_size >= initrd_max) {
+fprintf(stderr, "qemu: initrd is too large, cannot 
support."
+"(max: %"PRIu32", need %"PRId64")\n",
+initrd_max, (uint64_t)initrd_size);
+exit(1);
+}
+
+initrd_addr = (initrd_max - initrd_size) & ~4095;
+
+fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
+fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
+fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, initrd_data,
+ initrd_size);
+}
+
 return;
 }
 /* This looks like a multiboot kernel. If it is, let's stop
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH 03/15] hw/ssi: Remove SSIBus from "qemu/typedefs.h"

2019-01-15 Thread Markus Armbruster
Philippe Mathieu-Daudé  writes:

> From: Philippe Mathieu-Daudé 
>
> There are only three files requiring this typedef, let them
> include "hw/ssi/ssi.h" directly to simplify "qemu/typedefs.h".
>
> To clean "qemu/typedefs.h", move the forward declaration
> to "hw/ssi/ssi.h".
>
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/arm/strongarm.h  | 1 +
>  include/hw/arm/pxa.h| 1 +
>  include/hw/ssi/pl022.h  | 1 +
>  include/hw/ssi/ssi.h| 1 +
>  include/qemu/typedefs.h | 1 -
>  5 files changed, 4 insertions(+), 1 deletion(-)

When typedefs.h changes, we recompile the world, but it pretty much only
ever changes when new typedefs are added.  Thus, *keeping* a typedef
there is therefore pretty cheap.

Nevertheless, we shouldn't keep typedefs there without a real reason.
Being able to move one away without having to add any new #include
directives is a strong sign for "no real reason".  I like patches doing
that.

What I don't like is adding #include directives just so you can move
typedefs out of typedefs.h: it slows down the build.  Granted, the four
added by this patch are a drop in the bucket.  The point I'm trying to
make is typedefs.h's purpose: it's for avoiding #include directives.
Circular ones in particular, but others, too.



Re: [Qemu-devel] [PATCH v3 06/19] qemu-nbd: Avoid strtol open-coding

2019-01-15 Thread Vladimir Sementsov-Ogievskiy
12.01.2019 20:57, Eric Blake wrote:
> Our copy-and-pasted open-coding of strtol handling forgot to
> handle overflow conditions.  Use qemu_strto*() instead.
> 
> In the case of --partition, since we insist on a user-supplied
> partition to be non-zero, we can use 0 rather than -1 for our
> initial value to distinguish when a partition is not being
> served, for slightly more optimal code.
> 
> The error messages for out-of-bounds values are less specific,
> but should not be a terrible loss in quality.
> 
> Signed-off-by: Eric Blake 
> Message-Id: <20181215135324.152629-8-ebl...@redhat.com>
> 
> ---
> v3: rebase to use int64_t rather than off_t [Vladimir]
> ---
>   qemu-nbd.c | 28 +---
>   1 file changed, 9 insertions(+), 19 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 96c0829970c..4670b659167 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -546,9 +546,8 @@ int main(int argc, char **argv)
>   };
>   int ch;
>   int opt_ind = 0;
> -char *end;
>   int flags = BDRV_O_RDWR;
> -int partition = -1;
> +int partition = 0;
>   int ret = 0;
>   bool seen_cache = false;
>   bool seen_discard = false;
> @@ -660,9 +659,8 @@ int main(int argc, char **argv)
>   port = optarg;
>   break;
>   case 'o':
> -dev_offset = strtoll (optarg, &end, 0);
> -if (*end) {
> -error_report("Invalid offset `%s'", optarg);
> +if (qemu_strtou64(optarg, NULL, 0, &dev_offset) < 0) {
> +error_report("Invalid offset '%s'", optarg);
>   exit(EXIT_FAILURE);
>   }
>   break;
> @@ -684,13 +682,9 @@ int main(int argc, char **argv)
>   flags &= ~BDRV_O_RDWR;
>   break;
>   case 'P':
> -partition = strtol(optarg, &end, 0);
> -if (*end) {
> -error_report("Invalid partition `%s'", optarg);
> -exit(EXIT_FAILURE);
> -}
> -if (partition < 1 || partition > 8) {
> -error_report("Invalid partition %d", partition);
> +if (qemu_strtoi(optarg, NULL, 0, &partition) < 0 ||

we can use unsigned conversion like for offset (and unsigned type for 
partition), but this doesn't really matter.

> +partition < 1 || partition > 8) {
> +error_report("Invalid partition '%s'", optarg);
>   exit(EXIT_FAILURE);
>   }
>   break;
> @@ -711,15 +705,11 @@ int main(int argc, char **argv)
>   device = optarg;
>   break;
>   case 'e':
> -shared = strtol(optarg, &end, 0);
> -if (*end) {
> +if (qemu_strtoi(optarg, NULL, 0, &shared) < 0 ||

and here

> +shared < 1) {
>   error_report("Invalid shared device number '%s'", optarg);
>   exit(EXIT_FAILURE);
>   }
> -if (shared < 1) {
> -error_report("Shared device number must be greater than 0");
> -exit(EXIT_FAILURE);
> -}
>   break;
>   case 'f':
>   fmt = optarg;
> @@ -1007,7 +997,7 @@ int main(int argc, char **argv)
>   }
>   fd_size -= dev_offset;
> 
> -if (partition != -1) {
> +if (partition) {
>   int64_t limit;
> 
>   if (dev_offset) {
> 

anyway,
Reviewed-by: Vladimir Sementsov-Ogievskiy 

-- 
Best regards,
Vladimir


Re: [Qemu-devel] [PULL 00/44] pci, pc, virtio: fixes, features

2019-01-15 Thread Michael S. Tsirkin
On Tue, Jan 15, 2019 at 01:38:02PM +0800, Peter Xu wrote:
> On Mon, Jan 14, 2019 at 08:35:11PM -0500, Michael S. Tsirkin wrote:
> > The following changes since commit 89bd861c2b470e3fb45596945509079c72af3ac2:
> > 
> >   Merge remote-tracking branch 
> > 'remotes/ehabkost/tags/x86-next-pull-request' into staging (2019-01-14 
> > 17:35:00 +)
> > 
> > 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 b421506a3ac2f1b2a4f18d6f423a92dfa16e2645:
> > 
> >   acpi: update expected files (2019-01-14 19:31:05 -0500)
> > 
> > 
> > pci, pc, virtio: fixes, features
> > 
> > tpm physical presence interface
> > rsc support in virtio net
> > ivshmem is removed
> > misc cleanups and fixes all over the place
> 
> Hi, Michael,
> 
> Do you want to review/queue some VT-d patches that I posted recently?
> 
> [PATCH 0/5] intel_iommu: misc fixes for error exposed after 
> error_report_once()
> (https://patchwork.kernel.org/cover/10751913/, patch 5 dropped though)
> 
> They fix some bugs that were recently exposed.  Currently only the
> first two patches got acked-by from Jason.
> 
> They don't worth to block the pull but IMHO they fix real problems so
> just to make sure they won't fall through the cracks.
> 
> Thanks!
> 
> -- 
> Peter Xu

Assuming you have arrived at a consensus with Alex, pls
post a series that either doesn't affect vfio or
has his ack.

Thanks!

-- 
MST



Re: [Qemu-devel] [PATCH v4 for-4.0 2/7] vhost-user: Support transferring inflight buffer between qemu and backend

2019-01-15 Thread Michael S. Tsirkin
On Tue, Jan 15, 2019 at 02:46:42PM +0800, Yongji Xie wrote:
> On Tue, 15 Jan 2019 at 06:25, Michael S. Tsirkin  wrote:
> >
> > On Wed, Jan 09, 2019 at 07:27:23PM +0800, elohi...@gmail.com wrote:
> > > @@ -382,6 +397,30 @@ If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol 
> > > feature is negotiated,
> > >  slave can send file descriptors (at most 8 descriptors in each message)
> > >  to master via ancillary data using this fd communication channel.
> > >
> > > +Inflight I/O tracking
> > > +-
> > > +
> > > +To support slave reconnecting, slave need to track inflight I/O in a
> > > +shared memory. VHOST_USER_GET_INFLIGHT_FD and VHOST_USER_SET_INFLIGHT_FD
> > > +are used to transfer the memory between master and slave. And to 
> > > encourage
> > > +consistency, we provide a recommended format for this memory:
> >
> > I think we should make a stronger statement and actually
> > just say what the format is. Not recommend it weakly.
> >
> 
> Okey, will do it.
> 
> > > +
> > > +offsetwidthdescription
> > > +0x0  0x400region for queue0
> > > +0x4000x400region for queue1
> > > +0x8000x400region for queue2
> > > +...  ...  ...
> > > +
> > > +For each virtqueue, we have a 1024 bytes region.
> >
> >
> > Why is the size hardcoded? Why not a function of VQ size?
> >
> 
> Sorry, I didn't get your point. Should the region's size be fixed? Do
> you mean we need to document a function for the region's size?


Well you are saying 0x0 to 0x400 is for queue0.
How do you know that's enough? And why are 0x400
bytes necessary? After all max queue size can be very small.



> >
> > > The region's format is like:
> > > +
> > > +offset   widthdescription
> > > +0x0  0x1  descriptor 0 is in use or not
> > > +0x1  0x1  descriptor 1 is in use or not
> > > +0x2  0x1  descriptor 2 is in use or not
> > > +...  ...  ...
> > > +
> > > +For each descriptor, we use one byte to specify whether it's in use or 
> > > not.
> > > +
> > >  Protocol features
> > >  -
> > >
> >
> > I think that it's a good idea to have a version in this region.
> > Otherwise how are you going to handle compatibility when
> > this needs to be extended?
> >
> 
> I have put the version into the message's payload: VhostUserInflight. Is it 
> OK?
> 
> Thanks,
> Yongji

I'm not sure I like it.  So is qemu expected to maintain it? Reset it?
Also don't you want to be able to detect that qemu has reset the buffer?
If we have version 1 at a known offset that can serve both purposes.
Given it only has value within the buffer why not store it there?

-- 
MST



Re: [Qemu-devel] [PATCH for-4.0 v9 09/16] qemu_thread: supplement error handling for pci_edu_realize

2019-01-15 Thread Markus Armbruster
Fei Li  writes:

> 在 2019/1/14 下午8:36, Markus Armbruster 写道:
>> Fei Li  writes:
>>
>>> Just to make sure about how to do the cleanup. I notice that in 
>>> device_set_realized(),
>>> the current code does not call "dc->unrealize(dev, NULL);" when 
>>> dc->realize() fails.
> Sorry that I am still uncertain.. I guess the code below I pasted was
> misleading,
> actually I want to stress the *dc->unrealize() is not called when
> dc->realize() fails*
> and the incomplete below "goto fail" does not include the dc->unrealize(),
> but instead the dc->unrealize() is included in later
> child_realize_fail: & post_realize_fail:.
>
>
> Emm, IMHO, I think when dc->realize() fails, the dc->unrealize() is
> either should be
> called in the common function: device_set_realized() in a unified way,
> that is
>
>     if (local_err != NULL) {
> +  if (dc->unrealize) {
> +  dc->unrealize(dev, local_err);
> +  }
>     goto fail;
>     }
>
> or do the unrealize() locally for each device earlier when
> dc->realize() fails.
>
> But I checked several dc->realize() function, they did not call unrealize()
> when fails. Besides, it may mean verbose code if unrealize() locally.
> Thus I think the above way is the right way to do the cleanup when
> realize() fails.

The realize() method is specified to either succeed completely or fail
completely, i.e. fail and do nothing.  The "either succeed completely or
fail completely" aspect of the specification is sane and perfectly
ordinary.

How a concrete implementation accomplishes "fail completely" is up to
the implementation.

An implementation may choose to structure its FOO_realize() and
FOO_unrealize() in a way that lets FOO_realize() call FOO_unrealize() to
clean up on failure.

An implementation may also choose to clean up differently.

This freedom of choice is by design.

Changing the specification now would involve auditing and updating all
realize() and unrealize() methods.  Not going to happen without an
extremely compelling reason.

>>>
>>>      if (dc->realize) {
>>>      dc->realize(dev, &local_err);
>>>      }
>>>
>>>      if (local_err != NULL) {
>>>      goto fail;
>>>      }
>>>
>>> Is this on purpose? (Maybe due to some devices' realize() do their own 
>>> cleanup
>>> when fails? Sorry for the unsure, it is such a common function that I did 
>>> not
>>> check all. :( ) Or else, I prefer to do the cleanup in a unified manner, 
>>> e.g. call "dc->unrealize(dev, NULL);" which is the pci_qdev_unrealize() for 
>>> pci devices.
>> Yes, this is on purpose.
>>
>> When a realize() method fails, it must revert everything it has done so
>> far.  Results in sane "either succeed completely, or fail and do
>> nothing" semantics.
>
> Have a nice day, thanks
>
> Fei



Re: [Qemu-devel] [PATCH 03/15] hw/ssi: Remove SSIBus from "qemu/typedefs.h"

2019-01-15 Thread Thomas Huth
On 2019-01-15 13:28, Markus Armbruster wrote:
> Philippe Mathieu-Daudé  writes:
> 
>> From: Philippe Mathieu-Daudé 
>>
>> There are only three files requiring this typedef, let them
>> include "hw/ssi/ssi.h" directly to simplify "qemu/typedefs.h".
>>
>> To clean "qemu/typedefs.h", move the forward declaration
>> to "hw/ssi/ssi.h".
>>
>> Signed-off-by: Philippe Mathieu-Daudé 
>> ---
>>  hw/arm/strongarm.h  | 1 +
>>  include/hw/arm/pxa.h| 1 +
>>  include/hw/ssi/pl022.h  | 1 +
>>  include/hw/ssi/ssi.h| 1 +
>>  include/qemu/typedefs.h | 1 -
>>  5 files changed, 4 insertions(+), 1 deletion(-)
> 
> When typedefs.h changes, we recompile the world, but it pretty much only
> ever changes when new typedefs are added.  Thus, *keeping* a typedef
> there is therefore pretty cheap.
> 
> Nevertheless, we shouldn't keep typedefs there without a real reason.
> Being able to move one away without having to add any new #include
> directives is a strong sign for "no real reason".  I like patches doing
> that.
> 
> What I don't like is adding #include directives just so you can move
> typedefs out of typedefs.h: it slows down the build.  Granted, the four
> added by this patch are a drop in the bucket.  The point I'm trying to
> make is typedefs.h's purpose: it's for avoiding #include directives.
> Circular ones in particular, but others, too.

Yes, agreed, removing things from typedefs.h just to add lots of
#includes in other files is not really the best idea. I also dropped
this patch in v2 of my current PULL request because of this reason.
Phil, I suggest to simply drop this patch. What we maybe could do is to
split up typedefs.h per subsystem, so that we additionally have a
hw/arm/typedefs.h, hw/ppc/typedefs.h etc. in the end, then the
target-specific typedefs would not clutter the common qemu/typedefs.h
file anymore.

 Thomas




Re: [Qemu-devel] [PATCH 1/2] vfio-pci: Introduce vfio_register_event_notifier helper

2019-01-15 Thread Auger Eric
Hi Cornelia,

On 1/15/19 1:03 PM, Cornelia Huck wrote:
> On Fri, 11 Jan 2019 17:58:00 +0100
> Eric Auger  wrote:
> 
>> The code used to attach the eventfd handler for the ERR and
>> REQ irq indices can be factorized into a helper. In subsequent
>> patches we will extend this helper to support other irq indices.
> 
> Looks like a nice refactoring to me.
thank you
> 
>>
>> We test the notification is allowed outside of the helper:
> 
> s/We test/We test whether/
> 
>> respectively check vdev->pci_aer and VFIO_FEATURE_ENABLE_REQ.
>> Depending on the returned value we set vdev->pci_aer and
>> vdev->req_enabled. An error handle is introduced for future usage
>> although not strictly useful here.
>>
>> Signed-off-by: Eric Auger 
>> ---
>>  hw/vfio/pci.c | 291 ++
>>  1 file changed, 127 insertions(+), 164 deletions(-)
>>
>> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> index c0cb1ec289..c589a4e666 100644
>> --- a/hw/vfio/pci.c
>> +++ b/hw/vfio/pci.c
>> @@ -105,6 +105,95 @@ static void vfio_intx_eoi(VFIODevice *vbasedev)
>>  vfio_unmask_single_irqindex(vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
>>  }
>>  
>> +/*
>> + * vfio_register_event_notifier - setup/tear down eventfd
>> + * notification and handling for IRQ indices that span over
>> + * a single IRQ
>> + *
>> + * @vdev: VFIO device handle
>> + * @index: IRQ index the eventfd/handler is associated to
> 
> s/to/with/ ?
> 
>> + * @target_state: true means notifier needs to be set up
>> + * @handler to attach if @target_state is true
>> + * @errp error handle
>> + */
>> +static int vfio_register_event_notifier(VFIOPCIDevice *vdev,
>> +int index,
>> +bool target_state,
>> +void (*handler)(void *opaque),
>> +Error **errp)
> 
> (...)
> 
>> @@ -3069,8 +2998,29 @@ static void vfio_realize(PCIDevice *pdev, Error 
>> **errp)
>>  goto out_teardown;
>>  }
>>  
>> -vfio_register_err_notifier(vdev);
>> -vfio_register_req_notifier(vdev);
>> +if (vdev->pci_aer) {
>> +/*
>> + * Registers error notifier for devices supporting error recovery.
>> + * If we encounter a failure in this function, we report an error
> 
> s/in this function/while registering it/ ?
> 
>> + * and continue after disabling error recovery support for the
>> + * device.
>> + */
>> +vdev->pci_aer =
>> +!vfio_register_event_notifier(vdev, VFIO_PCI_ERR_IRQ_INDEX, 
>> true,
>> +  vfio_err_notifier_handler, &err);
>> +if (err) {
>> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> +}
> 
> I think you need to reset err to NULL if you want to reuse the variable.
Yes you're right. Thanks for spotting this.

> 
> Alternatively, you could keep the wrappers and define a local error
> variable there.
> 
>> +}
>> +
>> +if (vdev->features & VFIO_FEATURE_ENABLE_REQ) {
>> +vdev->req_enabled =
>> +!vfio_register_event_notifier(vdev, VFIO_PCI_REQ_IRQ_INDEX, 
>> true,
>> +  vfio_req_notifier_handler, &err);
>> +if (err) {
>> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> +}
>> +}
>>  vfio_setup_resetfn_quirk(vdev);
>>  
>>  return;
>> @@ -3106,9 +3056,22 @@ static void vfio_instance_finalize(Object *obj)
>>  static void vfio_exitfn(PCIDevice *pdev)
>>  {
>>  VFIOPCIDevice *vdev = PCI_VFIO(pdev);
>> +Error *err = NULL;
>>  
>> -vfio_unregister_req_notifier(vdev);
>> -vfio_unregister_err_notifier(vdev);
>> +if (vdev->req_enabled) {
>> +vfio_register_event_notifier(vdev, VFIO_PCI_REQ_IRQ_INDEX,
>> + false, NULL, &err);
>> +if (err) {
>> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> +}
> 
> Likewise.

Thank you for the review!

Eric

> 
>> +}
>> +if (vdev->pci_aer) {
>> +vfio_register_event_notifier(vdev, VFIO_PCI_ERR_IRQ_INDEX,
>> + false, NULL, &err);
>> +if (err) {
>> +warn_reportf_err(err, VFIO_MSG_PREFIX, vdev->vbasedev.name);
>> +}
>> +}
>>  pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
>>  vfio_disable_interrupts(vdev);
>>  if (vdev->intx.mmap_timer) {
> 
> 



Re: [Qemu-devel] [PATCH 2/2] vfio-pci: Use vfio_register_event_notifier in vfio_intx_enable_kvm

2019-01-15 Thread Auger Eric
Hi Cornelia,

On 1/15/19 1:12 PM, Cornelia Huck wrote:
> On Fri, 11 Jan 2019 17:58:01 +0100
> Eric Auger  wrote:
> 
>> We can also use vfio_register_event_notifier() helper in
>> vfio_intx_enable_kvm to set the signalling associated to
>> VFIO_PCI_INTX_IRQ_INDEX.
>>
>> Signed-off-by: Eric Auger 
>> ---
>>  hw/vfio/pci.c | 38 +++---
>>  1 file changed, 7 insertions(+), 31 deletions(-)
>>
> 
>>  static void vfio_intx_disable(VFIOPCIDevice *vdev)
> 
> I'm wondering why the _disable path can't use the new helper. Ordering
> issues?
> 
Yes the interleaving of actions scared me a little bit. I am going to
study this a little bit further ...

Thanks

Eric



Re: [Qemu-devel] [PATCH v1] virtio: add checks for the size of the indirect table

2019-01-15 Thread Dima Stepanov
On Tue, Jan 15, 2019 at 11:40:09AM +0100, Cornelia Huck wrote:
> On Tue, 15 Jan 2019 13:08:47 +0300
> Dima Stepanov  wrote:
> 
> > The virtqueue_pop() and virtqueue_get_avail_bytes() routines can use the
> > INDIRECT table to get the data. It is possible to create a packet which
> > will lead to the assert message like:
> >   include/exec/memory.h:1995: void
> >   address_space_read_cached(MemoryRegionCache *, hwaddr, void *, int):
> >   Assertion `addr < cache->len && len <= cache->len - addr' failed.
> >   Aborted
> > To do it the first descriptor should have a link to the INDIRECT table
> > and set the size of it to 0. It doesn't look good that the guest should
> > be able to trigger the assert in qemu. Add additional check for the size
> > of the INDIRECT table, which should not be 0.
> 
> Ouch, being able to crash QEMU by a specially crafted descriptor is bad.
> 
> Looking at the virtio spec, we don't seem to explicitly disallow
> indirect descriptors with a zero-length table. So, as an alternative to
> marking the device broken, we could also skip over such a descriptor.
> Not sure whether that makes sense, though.

Hard to say what is the better option here: mark device with the
VIRTIO_CONFIG_S_NEEDS_RESET bit or just skip the descriptor. Right now
all the parsing errors are handled using the virtio_error() call. The
possible parsing errors are: wrong address, looped descriptors, invalid
size, incorrect order and so on. Some of those errors are not described
in the virtio spec. So it looks like that this error should be also
handled by calling virtio_error().

> 
> > 
> > Signed-off-by: Dima Stepanov 
> > ---
> >  hw/virtio/virtio.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> > index 22bd1ac..a1ff647 100644
> > --- a/hw/virtio/virtio.c
> > +++ b/hw/virtio/virtio.c
> > @@ -646,7 +646,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned 
> > int *in_bytes,
> >  vring_desc_read(vdev, &desc, desc_cache, i);
> >  
> >  if (desc.flags & VRING_DESC_F_INDIRECT) {
> > -if (desc.len % sizeof(VRingDesc)) {
> > +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
> >  virtio_error(vdev, "Invalid size for indirect buffer 
> > table");
> >  goto err;
> >  }
> > @@ -902,7 +902,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
> >  desc_cache = &caches->desc;
> >  vring_desc_read(vdev, &desc, desc_cache, i);
> >  if (desc.flags & VRING_DESC_F_INDIRECT) {
> > -if (desc.len % sizeof(VRingDesc)) {
> > +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
> >  virtio_error(vdev, "Invalid size for indirect buffer table");
> >  goto done;
> >  }
> 



Re: [Qemu-devel] [PULL v2 00/27] ivshmem deprecation, qtests, typedefs and gnu99

2019-01-15 Thread Peter Maydell
On Mon, 14 Jan 2019 at 17:45, Thomas Huth  wrote:
>
>  Hi Peter!
>
> The following changes since commit 7260438b7056469610ee166f7abe9ff8a26b8b16:
>
>   Merge remote-tracking branch 
> 'remotes/palmer/tags/riscv-for-master-3.2-part2' into staging (2019-01-14 
> 11:41:43 +)
>
> are available in the git repository at:
>
>   https://gitlab.com/huth/qemu.git tags/pull-request-2019-01-14v2
>
> for you to fetch changes up to 650db715681ad1a042705484776e1974f288f3d4:
>
>   tests/hexloader-test: Don't pass -nographic to the QEMU under test 
> (2019-01-14 18:21:29 +0100)
>
> 
> - Remove deprecated "ivshmem" legacy device
> - Bug fix for vhost-user-test
> - Use more CONFIG Makefile switches for qtests
> - Get rid of global_qtests in some more qtests
> - typedef cleanups
> - Fixes for compiling with Clang
> - Force C standard to gnu99
> 

Hi; another compile failure on that ppc64 system, I'm afraid:

/home/pm215/qemu/qemu-seccomp.c:45:1: error: initializer element is not constant
 };
 ^
/home/pm215/qemu/qemu-seccomp.c:45:1: error: (near initialization for
‘sched_setscheduler_arg[0]’)

(I did a quick check with 'make -k' and it looks like there aren't
any more lurking after that one.)

The system libseccomp is libseccomp-2.3.1-3.el7.

thanks
-- PMM



Re: [Qemu-devel] [PATCH v3 10/19] nbd/client: Split out nbd_send_one_meta_context()

2019-01-15 Thread Vladimir Sementsov-Ogievskiy
12.01.2019 20:58, Eric Blake wrote:
> Refactor nbd_negotiate_simple_meta_context() to pull out the
> code that can be reused to send a LIST request for 0 or 1 query.
> No semantic change.  The old comment about 'sizeof(uint32_t)'
> being equivalent to '/* number of queries */' is no longer
> needed, now that we are computing 'sizeof(queries)' instead.
> 
> Signed-off-by: Eric Blake 
> Message-Id: <20181215135324.152629-14-ebl...@redhat.com>
> Reviewed-by: Richard W.M. Jones 
> 
> ---
> v3: Improve commit message [Rich], formatting tweak [checkpatch],
> rebase to dropped patch
> ---
>   nbd/client.c | 67 +---
>   nbd/trace-events |  2 +-
>   2 files changed, 48 insertions(+), 21 deletions(-)
> 
> diff --git a/nbd/client.c b/nbd/client.c
> index 77993890f04..3c716be2719 100644
> --- a/nbd/client.c
> +++ b/nbd/client.c
> @@ -629,6 +629,49 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
>   return QIO_CHANNEL(tioc);
>   }
> 
> +/*
> + * nbd_send_one_meta_context:
> + * Send 0 or 1 set/list meta context queries.
> + * Return 0 on success, -1 with errp set for any error
> + */
> +static int nbd_send_one_meta_context(QIOChannel *ioc,
> + uint32_t opt,
> + const char *export,
> + const char *query,
> + Error **errp)
> +{
> +int ret;
> +uint32_t export_len = strlen(export);
> +uint32_t queries = !!query;

n_ or nb_ prefix may make it more clear

> +uint32_t context_len = 0;
> +uint32_t data_len;
> +char *data;
> +char *p;
> +
> +data_len = sizeof(export_len) + export_len + sizeof(queries);
> +if (query) {
> +context_len = strlen(query);

looks like it then should be query_len

> +data_len += sizeof(context_len) + context_len;
> +} else {
> +assert(opt == NBD_OPT_LIST_META_CONTEXT);
> +}
> +data = g_malloc(data_len);
> +p = data;

may use p = data = g_malloc

> +
> +trace_nbd_opt_meta_request(nbd_opt_lookup(opt), query ?: "(all)", 
> export);
> +stl_be_p(p, export_len);
> +memcpy(p += sizeof(export_len), export, export_len);
> +stl_be_p(p += export_len, queries);
> +if (query) {
> +stl_be_p(p += sizeof(uint32_t), context_len);

:), aha, please, s/uint32_t/queries, as you promised

Hmm, its my code. It's hard to read and not very comfortable to maintain..

In block/nbd-client.c we have
payload_advance* functions, to read such formatted data, I think, it should be
good to make something like this for server-part. Not about these series, of 
course.

Interesting, troubles around "don't use be64_to_cpuS, use only be64_to_cpu",
do they apply somehow to *_be_p functions family?

> +memcpy(p += sizeof(context_len), query, context_len);
> +}
> +
> +ret = nbd_send_option_request(ioc, opt, data_len, data, errp);
> +g_free(data);
> +return ret;
> +}
> +
>   /* nbd_negotiate_simple_meta_context:
>* Request the server to set the meta context for export @info->name
>* using @info->x_dirty_bitmap with a fallback to "base:allocation",
> @@ -653,26 +696,10 @@ static int nbd_negotiate_simple_meta_context(QIOChannel 
> *ioc,
>   NBDOptionReply reply;
>   const char *context = info->x_dirty_bitmap ?: "base:allocation";
>   bool received = false;
> -uint32_t export_len = strlen(info->name);
> -uint32_t context_len = strlen(context);
> -uint32_t data_len = sizeof(export_len) + export_len +
> -sizeof(uint32_t) + /* number of queries */
> -sizeof(context_len) + context_len;
> -char *data = g_malloc(data_len);
> -char *p = data;
> 
> -trace_nbd_opt_meta_request(context, info->name);
> -stl_be_p(p, export_len);
> -memcpy(p += sizeof(export_len), info->name, export_len);
> -stl_be_p(p += export_len, 1);
> -stl_be_p(p += sizeof(uint32_t), context_len);
> -memcpy(p += sizeof(context_len), context, context_len);
> -
> -ret = nbd_send_option_request(ioc, NBD_OPT_SET_META_CONTEXT, data_len, 
> data,
> -  errp);
> -g_free(data);
> -if (ret < 0) {
> -return ret;
> +if (nbd_send_one_meta_context(ioc, NBD_OPT_SET_META_CONTEXT,
> +  info->name, context, errp) < 0) {
> +return -1;
>   }
> 
>   if (nbd_receive_option_reply(ioc, NBD_OPT_SET_META_CONTEXT, &reply,
> @@ -689,7 +716,7 @@ static int nbd_negotiate_simple_meta_context(QIOChannel 
> *ioc,
>   if (reply.type == NBD_REP_META_CONTEXT) {
>   char *name;
> 
> -if (reply.length != sizeof(info->context_id) + context_len) {
> +if (reply.length != sizeof(info->context_id) + strlen(context)) {
>   error_setg(errp, "Failed to negotiate meta context '%s', server 
> "
>  "answered with unexpected length %

[Qemu-devel] Crash when deleting an iothread that is being used

2019-01-15 Thread Alberto Garcia
Here's how to reproduce the crash:

{ "execute": "qmp_capabilities" }
{ "execute": "blockdev-add", "arguments": {"driver": "null-co", "node-name": 
"hd0"}}
{ "execute": "object-add", "arguments": {"qom-type": "iothread", "id": 
"iothread0"}}
{ "execute": "x-blockdev-set-iothread", "arguments": {"node-name": "hd0", 
"iothread": "iothread0"}}
{ "execute": "object-del", "arguments": {"id": "iothread0"}}
{ "execute": "blockdev-del", "arguments": {"node-name": "hd0"}}

The problem is that bs->aio_context is the one that belonged to the
IOThread and was destroyed by the object-del call. One would need to
do x-blockdev-set-iothread(hd0, null) before deleting the thread.

The IOThread class does not have a can_be_deleted() method to prevent
threads from being deleted. One possible implementation would require
a reference count but that doesn't seem immediately trivial because
users don't use the IOThread itself but its AioContext, and not all
bdrv_set_aio_context() are related to IOThreads.

A quicker fix is of course to prevent the threads from being deleted
at all :-)

Berto



Re: [Qemu-devel] [PATCH v1] virtio: add checks for the size of the indirect table

2019-01-15 Thread Cornelia Huck
On Tue, 15 Jan 2019 16:11:19 +0300
Dima Stepanov  wrote:

> On Tue, Jan 15, 2019 at 11:40:09AM +0100, Cornelia Huck wrote:
> > On Tue, 15 Jan 2019 13:08:47 +0300
> > Dima Stepanov  wrote:
> >   
> > > The virtqueue_pop() and virtqueue_get_avail_bytes() routines can use the
> > > INDIRECT table to get the data. It is possible to create a packet which
> > > will lead to the assert message like:
> > >   include/exec/memory.h:1995: void
> > >   address_space_read_cached(MemoryRegionCache *, hwaddr, void *, int):
> > >   Assertion `addr < cache->len && len <= cache->len - addr' failed.
> > >   Aborted
> > > To do it the first descriptor should have a link to the INDIRECT table
> > > and set the size of it to 0. It doesn't look good that the guest should
> > > be able to trigger the assert in qemu. Add additional check for the size
> > > of the INDIRECT table, which should not be 0.  
> > 
> > Ouch, being able to crash QEMU by a specially crafted descriptor is bad.
> > 
> > Looking at the virtio spec, we don't seem to explicitly disallow
> > indirect descriptors with a zero-length table. So, as an alternative to
> > marking the device broken, we could also skip over such a descriptor.
> > Not sure whether that makes sense, though.  
> 
> Hard to say what is the better option here: mark device with the
> VIRTIO_CONFIG_S_NEEDS_RESET bit or just skip the descriptor. Right now
> all the parsing errors are handled using the virtio_error() call. The
> possible parsing errors are: wrong address, looped descriptors, invalid
> size, incorrect order and so on. Some of those errors are not described
> in the virtio spec. So it looks like that this error should be also
> handled by calling virtio_error().

virtio_error() is certainly the safe option (and easiest to implement),
and handling weird descriptors is probably not worth the time.

FWIW,

Reviewed-by: Cornelia Huck 

Should this be cc:stable, as it is a guest-triggerable crash?

> 
> >   
> > > 
> > > Signed-off-by: Dima Stepanov 
> > > ---
> > >  hw/virtio/virtio.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> > > index 22bd1ac..a1ff647 100644
> > > --- a/hw/virtio/virtio.c
> > > +++ b/hw/virtio/virtio.c
> > > @@ -646,7 +646,7 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, 
> > > unsigned int *in_bytes,
> > >  vring_desc_read(vdev, &desc, desc_cache, i);
> > >  
> > >  if (desc.flags & VRING_DESC_F_INDIRECT) {
> > > -if (desc.len % sizeof(VRingDesc)) {
> > > +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
> > >  virtio_error(vdev, "Invalid size for indirect buffer 
> > > table");
> > >  goto err;
> > >  }
> > > @@ -902,7 +902,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
> > >  desc_cache = &caches->desc;
> > >  vring_desc_read(vdev, &desc, desc_cache, i);
> > >  if (desc.flags & VRING_DESC_F_INDIRECT) {
> > > -if (desc.len % sizeof(VRingDesc)) {
> > > +if (!desc.len || (desc.len % sizeof(VRingDesc))) {
> > >  virtio_error(vdev, "Invalid size for indirect buffer table");
> > >  goto done;
> > >  }  
> >   




Re: [Qemu-devel] [PATCH v2] s390x/pci: Set the iommu region size mpcifc request

2019-01-15 Thread Cornelia Huck
On Thu, 10 Jan 2019 14:00:07 +0100
Pierre Morel  wrote:

> The size of the accessible iommu memory region in the guest
> is given to the IOMMU by the guest through the mpcifc request
> specifying the PCI Base Address and the PCI Address Limit.
> 
> Let set the size of the IOMMU region to:

s/Let/Let's/

> (PCI Address Limit) - (PCI Base Address) + 1.
> 
> Signed-off-by: Pierre Morel 
> ---
>  hw/s390x/s390-pci-bus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
> index 69e0671..e97696a 100644
> --- a/hw/s390x/s390-pci-bus.c
> +++ b/hw/s390x/s390-pci-bus.c
> @@ -660,7 +660,7 @@ void s390_pci_iommu_enable(S390PCIIOMMU *iommu)
>  char *name = g_strdup_printf("iommu-s390-%04x", iommu->pbdev->uid);
>  memory_region_init_iommu(&iommu->iommu_mr, sizeof(iommu->iommu_mr),
>   TYPE_S390_IOMMU_MEMORY_REGION, 
> OBJECT(&iommu->mr),
> - name, iommu->pal + 1);
> + name, iommu->pal - iommu->pba + 1);
>  iommu->enabled = true;
>  memory_region_add_subregion(&iommu->mr, 0, 
> MEMORY_REGION(&iommu->iommu_mr));
>  g_free(name);

Looks good to me. Collin, can I get an ack from you so I can queue it?



[Qemu-devel] [RFC PATCH v2 23/37] build: convert pci.mak to Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Instead of including the same list of devices for each target,
set CONFIG_PCI to true, and make the devices default to present
whenever PCI is available.

Done mostly with the following script:

  while read i; do
 i=${i%=y}; i=${i#CONFIG_}
 sed -i -e'/^config '$i'$/!b' -en \
-e'a\' -e'default y\' -e'depends on PCI' \
  `grep -lw $i hw/*/Kconfig`
  done < default-configs/pci.mak

followed by replacing a few "depends on" clauses with "select"
whenever the symbol is not really related to PCI.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 default-configs/alpha-softmmu.mak   |  2 +-
 default-configs/arm-softmmu.mak |  2 +-
 default-configs/hppa-softmmu.mak|  2 +-
 default-configs/i386-softmmu.mak|  3 +-
 default-configs/mips-softmmu-common.mak |  2 +-
 default-configs/pci.mak | 48 -
 default-configs/ppc-softmmu.mak |  2 +-
 default-configs/riscv32-softmmu.mak |  3 +-
 default-configs/riscv64-softmmu.mak |  2 +-
 default-configs/sh4-softmmu.mak |  2 +-
 default-configs/sh4eb-softmmu.mak   |  2 +-
 default-configs/sparc64-softmmu.mak |  2 +-
 hw/audio/Kconfig|  6 
 hw/block/Kconfig|  2 ++
 hw/char/Kconfig |  2 ++
 hw/display/Kconfig  | 12 ++-
 hw/ide/Kconfig  |  3 ++
 hw/ipack/Kconfig|  2 ++
 hw/misc/Kconfig |  4 +++
 hw/net/Kconfig  | 23 
 hw/pci-bridge/Kconfig   |  4 +++
 hw/pci-host/Kconfig |  4 +++
 hw/scsi/Kconfig | 11 ++
 hw/sd/Kconfig   |  3 ++
 hw/usb/Kconfig  | 10 ++
 hw/virtio/Kconfig   |  3 ++
 hw/watchdog/Kconfig |  2 ++
 27 files changed, 101 insertions(+), 62 deletions(-)
 delete mode 100644 default-configs/pci.mak

diff --git a/default-configs/alpha-softmmu.mak 
b/default-configs/alpha-softmmu.mak
index 62afa5ec16..c71d1b7f37 100644
--- a/default-configs/alpha-softmmu.mak
+++ b/default-configs/alpha-softmmu.mak
@@ -1,7 +1,7 @@
 # Default configuration for alpha-softmmu
 
-include pci.mak
 include usb.mak
+CONFIG_PCI=y
 CONFIG_SERIAL=y
 CONFIG_SERIAL_ISA=y
 CONFIG_I82374=y
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 3903d1ada3..8c071f6224 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -1,7 +1,7 @@
 # Default configuration for arm-softmmu
 
-include pci.mak
 include usb.mak
+CONFIG_PCI=y
 CONFIG_VGA=y
 CONFIG_NAND=y
 CONFIG_ECC=y
diff --git a/default-configs/hppa-softmmu.mak b/default-configs/hppa-softmmu.mak
index 4badc0521e..74d34c05e9 100644
--- a/default-configs/hppa-softmmu.mak
+++ b/default-configs/hppa-softmmu.mak
@@ -1,5 +1,5 @@
-include pci.mak
 include usb.mak
+CONFIG_PCI=y
 CONFIG_SERIAL=y
 CONFIG_SERIAL_ISA=y
 CONFIG_ISA_BUS=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index f71284516c..554dbd8c6b 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -1,6 +1,6 @@
 # Default configuration for i386-softmmu
 
-include pci.mak
+CONFIG_PCI=y
 include sound.mak
 include usb.mak
 include hyperv.mak
@@ -52,7 +52,6 @@ CONFIG_MEM_DEVICE=y
 CONFIG_DIMM=y
 CONFIG_NVDIMM=y
 CONFIG_ACPI_NVDIMM=y
-CONFIG_PCIE_PORT=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
diff --git a/default-configs/mips-softmmu-common.mak 
b/default-configs/mips-softmmu-common.mak
index 77b40ec7d1..5ef6d49e66 100644
--- a/default-configs/mips-softmmu-common.mak
+++ b/default-configs/mips-softmmu-common.mak
@@ -1,8 +1,8 @@
 # Common mips*-softmmu CONFIG defines
 
-include pci.mak
 include sound.mak
 include usb.mak
+CONFIG_PCI=y
 CONFIG_ESP=y
 CONFIG_SCSI=y
 CONFIG_VGA_ISA=y
diff --git a/default-configs/pci.mak b/default-configs/pci.mak
deleted file mode 100644
index 553b1905de..00
--- a/default-configs/pci.mak
+++ /dev/null
@@ -1,48 +0,0 @@
-CONFIG_PCI=y
-CONFIG_PCIE=y
-# For now, CONFIG_IDE_CORE requires ISA, so we enable it here
-CONFIG_ISA_BUS=y
-CONFIG_VIRTIO_PCI=y
-include virtio.mak
-CONFIG_USB_UHCI=y
-CONFIG_USB_OHCI=y
-CONFIG_USB_EHCI=y
-CONFIG_USB_XHCI=y
-CONFIG_USB_XHCI_NEC=y
-CONFIG_NE2000_PCI=y
-CONFIG_EEPRO100_PCI=y
-CONFIG_PCNET_PCI=y
-CONFIG_PCNET_COMMON=y
-CONFIG_AC97=y
-CONFIG_HDA=y
-CONFIG_ES1370=y
-CONFIG_SCSI=y
-CONFIG_LSI_SCSI_PCI=y
-CONFIG_VMW_PVSCSI_SCSI_PCI=y
-CONFIG_MEGASAS_SCSI_PCI=y
-CONFIG_MPTSAS_SCSI_PCI=y
-CONFIG_RTL8139_PCI=y
-CONFIG_E1000_PCI=y
-CONFIG_E1000E_PCI=y
-CONFIG_AHCI=y
-CONFIG_ESP=y
-CONFIG_ESP_PCI=y
-CONFIG_SERIAL=y
-CONFIG_SERIAL_ISA=y
-CONFIG_SERIAL_PCI=y
-CONFIG_CAN_BUS=y
-CONFIG_CAN_SJA1000=y
-CONFIG_CAN_PCI=y
-CONFIG_IPACK=y
-CONFIG_WDT_IB6300ESB=y
-CONFIG_PCI_TESTDEV=y
-CONFIG_NVME_P

Re: [Qemu-devel] [Qemu-block] [PATCH] throttle-groups: fix restart coroutine iothread race

2019-01-15 Thread Stefan Hajnoczi
On Mon, Jan 14, 2019 at 09:56:28PM +0100, Alberto Garcia wrote:
> On Mon 14 Jan 2019 05:31:17 PM CET, Stefan Hajnoczi  
> wrote:
> > On Mon, Jan 14, 2019 at 05:26:48PM +0100, Alberto Garcia wrote:
> >> On Mon 14 Jan 2019 05:15:25 PM CET, Stefan Hajnoczi wrote:
> >> >> > I've been able to reproduce this in an iotest, please see v2 of this
> >> >> > series.
> >> >> 
> >> >> That iotest doesn't crash for me :-?
> >> >
> >> > Does my iotest pass for you?
> >> 
> >> Yes, it does. I'm trying to figure out why because if I run the QMP
> >> commands by hand then it does crash.
> >
> > I ran the iotest 20 times on my machine and it segfaulted every time
> > (with the fix not yet applied).
> 
> Yeah I can also reproduce it all the time if I run it by hand...
> 
> I was debugging it and although I don't know why this is different when
> I run it through tests/qemu-iotests/check, here's why it doesn't crash:
> 
> After the ThrottleGroupMember is unregistered and its BlockBackend is
> destroyed, the throttle_group_co_restart_queue() coroutine takes
> control.
> 
> The first thing that it does is lock tgm->throttled_reqs_lock. It turns
> out that although this memory has been freed (it's part of the
> BlockBackend struct) it is still accessible but contains pure
> gargabe. 'Garbage' here means that the mutex counter contains some
> random value != 0, so the thread waits, it doesn't have a chance to
> crash the process, and QEMU shuts down cleanly.
> 
> So if my understanding is correct QEMU can be shut down when there are
> iothreads waiting for a mutex. Is that something that we should be
> worried about?

Nothing joins the iothreads in vl.c:main().

The assumption is that anything using iothreads will detach from them.
For example, the vm runstate changes during shutdown so devices can
disable the iothread code path (and this involves draining in-flight
requests).

My fix effectively does this by waiting for in-flight throttling restart
coroutines.

Stefan


signature.asc
Description: PGP signature


[Qemu-devel] [RFC PATCH v2 31/37] ptimer: express dependencies with Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 hw/Kconfig   | 2 ++
 hw/net/Kconfig   | 2 ++
 hw/timer/Kconfig | 6 ++
 3 files changed, 10 insertions(+)

diff --git a/hw/Kconfig b/hw/Kconfig
index 55743a958a..f9d88986a0 100644
--- a/hw/Kconfig
+++ b/hw/Kconfig
@@ -55,6 +55,8 @@ source riscv/Kconfig
 # Symbols used by multiple targets
 config XILINX
 bool
+select PTIMER # for hw/timer/xilinx_timer.c
 
 config XILINX_AXI
 bool
+select PTIMER # for hw/dma/xilinx_axidma.c
diff --git a/hw/net/Kconfig b/hw/net/Kconfig
index 5a30fdcc17..a9aa60f9a7 100644
--- a/hw/net/Kconfig
+++ b/hw/net/Kconfig
@@ -45,6 +45,7 @@ config SMC91C111
 
 config LAN9118
 bool
+select PTIMER
 
 config NE2000_ISA
 bool
@@ -96,6 +97,7 @@ config VIRTIO_NET
 
 config ETSEC
 bool
+select PTIMER
 
 config ROCKER
 bool
diff --git a/hw/timer/Kconfig b/hw/timer/Kconfig
index e1a6e7469b..a021c742de 100644
--- a/hw/timer/Kconfig
+++ b/hw/timer/Kconfig
@@ -1,8 +1,10 @@
 config ARM_TIMER
 bool
+select PTIMER
 
 config ARM_MPTIMER
 bool
+select PTIMER
 
 config A9_GTIMER
 bool
@@ -36,12 +38,14 @@ config XLNX_ZYNQMP
 
 config ALTERA_TIMER
 bool
+select PTIMER
 
 config MC146818RTC
 bool
 
 config ALLWINNER_A10_PIT
 bool
+select PTIMER
 
 config STM32F2XX_TIMER
 bool
@@ -51,6 +55,8 @@ config SUN4V_RTC
 
 config CMSDK_APB_TIMER
 bool
+select PTIMER
 
 config CMSDK_APB_DUALTIMER
 bool
+select PTIMER
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 32/37] edid: express dependencies with kconfig

2019-01-15 Thread Yang Zhong
Signed-off-by: Yang Zhong 
Reviewed-by: Thomas Huth 
---
 hw/display/Kconfig | 2 ++
 hw/i2c/Kconfig | 1 +
 2 files changed, 3 insertions(+)

diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index 7a9d121772..933793cc13 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -38,6 +38,7 @@ config VGA_PCI
 default y
 depends on PCI
 select VGA
+select EDID
 
 config VGA_ISA
 bool
@@ -59,6 +60,7 @@ config BOCHS_DISPLAY
 default y
 depends on PCI
 select VGA
+select EDID
 
 config BLIZZARD
 bool
diff --git a/hw/i2c/Kconfig b/hw/i2c/Kconfig
index 74c9328729..ef1caa6d89 100644
--- a/hw/i2c/Kconfig
+++ b/hw/i2c/Kconfig
@@ -8,6 +8,7 @@ config SMBUS_EEPROM
 config DDC
 bool
 depends on I2C
+select EDID
 
 config VERSATILE_I2C
 bool
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 37/37] Makefile: only support defconfig

2019-01-15 Thread Yang Zhong
add CONFIG_VHOST_USER and CONFIG_LINUX in Kconfig.host, the
current Makefile only support defconfig because of randconfig
does not work.

Signed-off-by: Yang Zhong 
---
 Kconfig.host |  6 ++
 Makefile | 16 
 hw/block/Kconfig |  2 ++
 hw/scsi/Kconfig  |  2 ++
 hw/tpm/Kconfig   |  2 ++
 5 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/Kconfig.host b/Kconfig.host
index d7f503d0ca..3772627a3a 100644
--- a/Kconfig.host
+++ b/Kconfig.host
@@ -16,3 +16,9 @@ config TPM
 
 config XEN
 bool
+
+config VHOST_USER
+bool
+
+config LINUX
+bool
diff --git a/Makefile b/Makefile
index b2d45aa6d4..d8fe6df696 100644
--- a/Makefile
+++ b/Makefile
@@ -312,6 +312,9 @@ endif
 SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory --quiet) 
BUILD_DIR=$(BUILD_DIR)
 SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(TARGET_DIRS))
 SUBDIR_DEVICES_MAK_DEP=$(patsubst %, %-config-devices.mak.d, $(TARGET_DIRS))
+SUBDIR_TARGET_MAK=$(patsubst %, %/config-target.mak, $(TARGET_DIRS))
+
+-include $(SUBDIR_TARGET_MAK)
 
 ifeq ($(SUBDIR_DEVICES_MAK),)
 config-all-devices.mak:
@@ -332,16 +335,13 @@ MINIKCONF_ARGS = \
 CONFIG_SPICE=$(CONFIG_SPICE) \
 CONFIG_TPM=$(CONFIG_TPM) \
 CONFIG_XEN=$(CONFIG_XEN) \
-CONFIG_OPENGL=$(CONFIG_OPENGL)
-
-MINIKCONF = $(SHELL) $(SRC_PATH)/scripts/minikconf.sh
+CONFIG_OPENGL=$(CONFIG_OPENGL) \
+CONFIG_VHOST_USER=$(CONFIG_VHOST_USER) \
+CONFIG_LINUX=$(CONFIG_LINUX)
 
-.PHONY: allyesconfig allnoconfig defconfig randconfig
-allyesconfig allnoconfig defconfig randconfig:
-   rm */config-devices.mak config-all-devices.mak
-   $(MAKE) MINIKCONF="$(MINIKCONF) --$<" config-all-devices.mak
+MINIKCONF = $(PYTHON) $(SRC_PATH)/scripts/minikconf.py --defconfig
 
-%/config-devices.mak: default-configs/%-softmmu.mak Kconfig.host hw/Kconfig
+%/config-devices.mak: default-configs/%.mak Kconfig.host $(SRC_PATH)/hw/Kconfig
$(call quiet-command, \
 $(MINIKCONF) $@ $*-config-devices.mak.d $^ $(MINIKCONF_ARGS) > 
$@.tmp, "  GEN   $@.tmp")
$(call quiet-command, if test -f $@; then \
diff --git a/hw/block/Kconfig b/hw/block/Kconfig
index 771967ad9f..b2f1de9eca 100644
--- a/hw/block/Kconfig
+++ b/hw/block/Kconfig
@@ -33,3 +33,5 @@ config VIRTIO_BLK
 
 config VHOST_USER_BLK
 bool
+default y
+depends on VHOST_USER && LINUX
diff --git a/hw/scsi/Kconfig b/hw/scsi/Kconfig
index 22281213ba..e5d5bcaa5c 100644
--- a/hw/scsi/Kconfig
+++ b/hw/scsi/Kconfig
@@ -48,3 +48,5 @@ config VIRTIO_SCSI
 
 config VHOST_USER_SCSI
 bool
+default y
+depends on VHOST_USER && LINUX
diff --git a/hw/tpm/Kconfig b/hw/tpm/Kconfig
index 28acdb745e..6d383b7209 100644
--- a/hw/tpm/Kconfig
+++ b/hw/tpm/Kconfig
@@ -13,6 +13,8 @@ config TPM_CRB
 
 config TPM_PASSTHROUGH
 bool
+depends on TPM
 
 config TPM_EMULATOR
 bool
+depends on TPM
-- 
2.17.1




Re: [Qemu-devel] [PATCH v4 for-4.0 2/7] vhost-user: Support transferring inflight buffer between qemu and backend

2019-01-15 Thread Yongji Xie
On Tue, 15 Jan 2019 at 20:54, Michael S. Tsirkin  wrote:
>
> On Tue, Jan 15, 2019 at 02:46:42PM +0800, Yongji Xie wrote:
> > On Tue, 15 Jan 2019 at 06:25, Michael S. Tsirkin  wrote:
> > >
> > > On Wed, Jan 09, 2019 at 07:27:23PM +0800, elohi...@gmail.com wrote:
> > > > @@ -382,6 +397,30 @@ If VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD protocol 
> > > > feature is negotiated,
> > > >  slave can send file descriptors (at most 8 descriptors in each message)
> > > >  to master via ancillary data using this fd communication channel.
> > > >
> > > > +Inflight I/O tracking
> > > > +-
> > > > +
> > > > +To support slave reconnecting, slave need to track inflight I/O in a
> > > > +shared memory. VHOST_USER_GET_INFLIGHT_FD and 
> > > > VHOST_USER_SET_INFLIGHT_FD
> > > > +are used to transfer the memory between master and slave. And to 
> > > > encourage
> > > > +consistency, we provide a recommended format for this memory:
> > >
> > > I think we should make a stronger statement and actually
> > > just say what the format is. Not recommend it weakly.
> > >
> >
> > Okey, will do it.
> >
> > > > +
> > > > +offsetwidthdescription
> > > > +0x0  0x400region for queue0
> > > > +0x4000x400region for queue1
> > > > +0x8000x400region for queue2
> > > > +...  ...  ...
> > > > +
> > > > +For each virtqueue, we have a 1024 bytes region.
> > >
> > >
> > > Why is the size hardcoded? Why not a function of VQ size?
> > >
> >
> > Sorry, I didn't get your point. Should the region's size be fixed? Do
> > you mean we need to document a function for the region's size?
>
>
> Well you are saying 0x0 to 0x400 is for queue0.
> How do you know that's enough? And why are 0x400
> bytes necessary? After all max queue size can be very small.
>
>

OK, I think I get your point. So we need something like:

region's size = max_queue_size * 32 byte + xxx byte (if any)

Right?

>
> > >
> > > > The region's format is like:
> > > > +
> > > > +offset   widthdescription
> > > > +0x0  0x1  descriptor 0 is in use or not
> > > > +0x1  0x1  descriptor 1 is in use or not
> > > > +0x2  0x1  descriptor 2 is in use or not
> > > > +...  ...  ...
> > > > +
> > > > +For each descriptor, we use one byte to specify whether it's in use or 
> > > > not.
> > > > +
> > > >  Protocol features
> > > >  -
> > > >
> > >
> > > I think that it's a good idea to have a version in this region.
> > > Otherwise how are you going to handle compatibility when
> > > this needs to be extended?
> > >
> >
> > I have put the version into the message's payload: VhostUserInflight. Is it 
> > OK?
> >
> > Thanks,
> > Yongji
>
> I'm not sure I like it.  So is qemu expected to maintain it? Reset it?
> Also don't you want to be able to detect that qemu has reset the buffer?
> If we have version 1 at a known offset that can serve both purposes.
> Given it only has value within the buffer why not store it there?
>

Yes, that looks better. Will update it in v5.

Thanks,
Yongji



[Qemu-devel] [RFC PATCH v2 28/37] isa: express dependencies with kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 default-configs/i386-softmmu.mak | 10 --
 hw/audio/Kconfig |  2 ++
 hw/block/Kconfig |  2 ++
 hw/char/Kconfig  |  6 ++
 hw/display/Kconfig   |  6 ++
 hw/i386/Kconfig  |  1 +
 hw/ide/Kconfig   |  1 +
 hw/input/Kconfig |  2 ++
 hw/isa/Kconfig   |  5 +
 hw/misc/Kconfig  |  4 
 hw/net/Kconfig   |  3 +++
 hw/watchdog/Kconfig  |  2 ++
 12 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 23dcca7a31..a66fd1ee5e 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -4,23 +4,15 @@ CONFIG_PCI=y
 CONFIG_ISA=y
 include hyperv.mak
 CONFIG_VGA_ISA=y
-CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
 CONFIG_VMXNET3_PCI=y
 CONFIG_VIRTIO_VGA=y
-CONFIG_VMMOUSE=y
 CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
 CONFIG_IPMI_EXTERN=y
 CONFIG_ISA_IPMI_KCS=y
 CONFIG_ISA_IPMI_BT=y
-CONFIG_SERIAL=y
-CONFIG_SERIAL_ISA=y
-CONFIG_PARALLEL=y
 CONFIG_I8254=y
-CONFIG_PCSPK=y
-CONFIG_PCKBD=y
-CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_ACPI_X86=y
 CONFIG_ACPI_X86_ICH=y
@@ -30,14 +22,12 @@ CONFIG_APM=y
 CONFIG_I8257=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
-CONFIG_NE2000_ISA=y
 CONFIG_HPET=y
 CONFIG_APPLESMC=y
 CONFIG_I8259=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_MC146818RTC=y
 CONFIG_PCI_PIIX=y
-CONFIG_WDT_IB700=y
 CONFIG_ISA_DEBUG=y
 CONFIG_ISA_TESTDEV=y
 CONFIG_VMPORT=y
diff --git a/hw/audio/Kconfig b/hw/audio/Kconfig
index bfb30276ec..350f2d4359 100644
--- a/hw/audio/Kconfig
+++ b/hw/audio/Kconfig
@@ -35,6 +35,8 @@ config HDA
 
 config PCSPK
 bool
+default y
+depends on ISA_BUS
 
 config WM8750
 bool
diff --git a/hw/block/Kconfig b/hw/block/Kconfig
index 3710434436..83c2be5915 100644
--- a/hw/block/Kconfig
+++ b/hw/block/Kconfig
@@ -1,5 +1,7 @@
 config FDC
 bool
+default y
+depends on ISA_BUS
 
 config SSI_M25P80
 bool
diff --git a/hw/char/Kconfig b/hw/char/Kconfig
index 1ed6f0dbce..56c1177f95 100644
--- a/hw/char/Kconfig
+++ b/hw/char/Kconfig
@@ -3,6 +3,8 @@ config ESCC
 
 config PARALLEL
 bool
+default y
+depends on ISA_BUS
 
 config PL011
 bool
@@ -12,11 +14,15 @@ config SERIAL
 
 config SERIAL_ISA
 bool
+default y
+depends on ISA_BUS
+select SERIAL
 
 config SERIAL_PCI
 bool
 default y
 depends on PCI
+select SERIAL
 
 config VIRTIO_SERIAL
 bool
diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index 5e73277cc2..a53ca4601a 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -9,6 +9,9 @@ config ADS7846
 
 config VGA_CIRRUS
 bool
+default y
+depends on PCI
+select VGA
 
 config G364FB
 bool
@@ -36,9 +39,12 @@ config VGA_PCI
 
 config VGA_ISA
 bool
+depends on ISA_BUS
+select VGA
 
 config VGA_ISA_MM
 bool
+select VGA
 
 config VMWARE_VGA
 bool
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index 427bda3717..68a9064558 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -9,6 +9,7 @@ config I440FX
 
 config ISAPC
 bool
+select ISA_BUS
 
 config Q35
 bool
diff --git a/hw/ide/Kconfig b/hw/ide/Kconfig
index 3778580df2..fb15211379 100644
--- a/hw/ide/Kconfig
+++ b/hw/ide/Kconfig
@@ -12,6 +12,7 @@ config IDE_PCI
 
 config IDE_ISA
 bool
+depends on ISA_BUS
 select IDE_QDEV
 
 config IDE_PIIX
diff --git a/hw/input/Kconfig b/hw/input/Kconfig
index 91bae47498..01805ed17b 100644
--- a/hw/input/Kconfig
+++ b/hw/input/Kconfig
@@ -6,6 +6,8 @@ config LM832X
 
 config PCKBD
 bool
+default y
+depends on ISA_BUS
 
 config PL050
 bool
diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig
index b59d074453..3f451ef006 100644
--- a/hw/isa/Kconfig
+++ b/hw/isa/Kconfig
@@ -9,15 +9,20 @@ config I82378
 
 config PC87312
 bool
+select ISA_BUS
 
 config PIIX4
 bool
+select ISA_BUS
 
 config VT82C686
 bool
+select ISA_BUS
 
 config SMC37C669
 bool
 
 config LPC_ICH9
 bool
+select ISA_BUS
+select ACPI_X86_ICH
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index 1ca4b2464e..e6df7480c6 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -1,5 +1,6 @@
 config APPLESMC
 bool
+depends on ISA_BUS
 
 config MAX111X
 bool
@@ -12,9 +13,11 @@ config TMP421
 
 config ISA_DEBUG
 bool
+depends on ISA_BUS
 
 config SGA
 bool
+depends on ISA_BUS
 
 config ISA_TESTDEV
 bool
@@ -93,6 +96,7 @@ config IOTKIT_SYSINFO
 
 config PVPANIC
 bool
+depends on ISA_BUS
 
 config AUX
 bool
diff --git a/hw/net/Kconfig b/hw/net/Kconfig
index 5191c082e3..5a30fdcc17 100644
--- a/hw/net/Kconfig
+++ b/hw/net/Kconfig
@@ -48,6 +48,9 @@ config LAN9118
 
 config NE2000_ISA
 bool
+default y
+depends on ISA_BUS
+depends on PCI # for NE2000State
 
 config OPENCORES_ETH
 bool
diff 

[Qemu-devel] [RFC PATCH v2 36/37] minikconf: implement allyesconfig, allnoconfig, randconfig, defconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Apart from defconfig (which is a no-op), the others are implemented
implemented simply by ignoring the RHS of assignments and "default"
statements.  The RHS is replaced respectively by "true", "false" or
a random value.

Signed-off-by: Paolo Bonzini 
---
 Makefile |  5 +
 scripts/minikconf.py | 43 ---
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 01e7c60a0d..b2d45aa6d4 100644
--- a/Makefile
+++ b/Makefile
@@ -336,6 +336,11 @@ MINIKCONF_ARGS = \
 
 MINIKCONF = $(SHELL) $(SRC_PATH)/scripts/minikconf.sh
 
+.PHONY: allyesconfig allnoconfig defconfig randconfig
+allyesconfig allnoconfig defconfig randconfig:
+   rm */config-devices.mak config-all-devices.mak
+   $(MAKE) MINIKCONF="$(MINIKCONF) --$<" config-all-devices.mak
+
 %/config-devices.mak: default-configs/%-softmmu.mak Kconfig.host hw/Kconfig
$(call quiet-command, \
 $(MINIKCONF) $@ $*-config-devices.mak.d $^ $(MINIKCONF_ARGS) > 
$@.tmp, "  GEN   $@.tmp")
diff --git a/scripts/minikconf.py b/scripts/minikconf.py
index b0b4f76733..a6c2f0c759 100644
--- a/scripts/minikconf.py
+++ b/scripts/minikconf.py
@@ -13,8 +13,10 @@
 import os
 import sys
 import re
+import random
 
-__all__ = [ 'KconfigParserError', 'KconfigData', 'KconfigParser' ]
+__all__ = [ 'KconfigParserError', 'KconfigData', 'KconfigParser',
+'defconfig', 'allyesconfig', 'allnoconfig', 'randconfig' ]
 
 def debug_print(*args):
 #print ' '.join(str(x) for x in args)
@@ -30,6 +32,11 @@ def debug_print(*args):
 # just its name).
 # ---
 
+allyesconfig = lambda x: True
+allnoconfig = lambda x: False
+defconfig = lambda x: x
+randconfig = lambda x: random.randint(0, 1) == 1
+
 class KconfigData:
 class Expr:
 def __and__(self, rhs):
@@ -178,7 +185,8 @@ class KconfigData:
 if self.cond.evaluate():
 self.dest.set_value(True)
 
-def __init__(self):
+def __init__(self, value_mangler=defconfig):
+self.value_mangler = value_mangler
 self.previously_included = []
 self.incl_info = None
 self.defined_vars = set()
@@ -256,10 +264,12 @@ class KconfigData:
 return var_obj
 
 def do_assignment(self, var, val):
-self.clauses.append(KconfigData.AssignmentClause(var, val))
+f = self.value_mangler
+self.clauses.append(KconfigData.AssignmentClause(var, f(val)))
 
 def do_default(self, var, val, cond=None):
-self.clauses.append(KconfigData.DefaultClause(var, val, cond))
+f = self.value_mangler
+self.clauses.append(KconfigData.DefaultClause(var, f(val), cond))
 
 def do_depends_on(self, var, expr):
 self.clauses.append(KconfigData.DependsOnClause(var, expr))
@@ -307,9 +317,10 @@ class KconfigParserError(Exception):
 return "%s: %s" % (self.loc, self.msg)
 
 class KconfigParser:
+
 @classmethod
-def parse(self, fp):
-data = KconfigData()
+def parse(self, fp, mode=None):
+data = KconfigData(mode or KconfigParser.defconfig)
 parser = KconfigParser(data)
 parser.parse_file(fp)
 return data
@@ -625,11 +636,29 @@ class KconfigParser:
 
 if __name__ == '__main__':
 argv = sys.argv
+mode = defconfig
+if len(sys.argv) > 1:
+if argv[1] == '--defconfig':
+del argv[1]
+elif argv[1] == '--randconfig':
+mode = randconfig
+del argv[1]
+elif argv[1] == '--allyesconfig':
+mode = allyesconfig
+del argv[1]
+elif argv[1] == '--allnoconfig':
+mode = allnoconfig
+del argv[1]
+
 if len(argv) == 1:
 print >>sys.stderr, "%s: at least one argument is required" % argv[0]
 os.exit(1)
 
-data = KconfigData()
+if argv[1].startswith('-'):
+print >>sys.stderr, "%s: invalid option %s" % (argv[0], argv[1])
+os.exit(1)
+
+data = KconfigData(mode)
 parser = KconfigParser(data)
 for arg in argv[3:]:
 m = re.match(r'^(CONFIG_[A-Z0-9_]+)=([yn]?)$', arg)
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 34/37] virtio: make virtio dependencies with Kconfig

2019-01-15 Thread Yang Zhong
Signed-off-by: Yang Zhong 
---
 default-configs/i386-softmmu.mak  |  1 -
 default-configs/s390x-softmmu.mak |  1 -
 default-configs/virtio.mak| 14 --
 hw/9pfs/Kconfig   |  2 ++
 hw/block/Kconfig  |  2 ++
 hw/char/Kconfig   |  2 ++
 hw/display/Kconfig|  5 +
 hw/input/Kconfig  |  2 ++
 hw/net/Kconfig|  2 ++
 hw/pci-host/Kconfig   |  2 ++
 hw/scsi/Kconfig   |  1 +
 hw/virtio/Kconfig |  9 -
 12 files changed, 26 insertions(+), 17 deletions(-)
 delete mode 100644 default-configs/virtio.mak

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index ab57978b9a..992aea8f30 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -1,7 +1,6 @@
 # Default configuration for i386-softmmu
 
 CONFIG_VMXNET3_PCI=y
-CONFIG_VIRTIO_VGA=y
 CONFIG_IPMI=y
 CONFIG_IPMI_LOCAL=y
 CONFIG_IPMI_EXTERN=y
diff --git a/default-configs/s390x-softmmu.mak 
b/default-configs/s390x-softmmu.mak
index 5eef375924..6640af2ec2 100644
--- a/default-configs/s390x-softmmu.mak
+++ b/default-configs/s390x-softmmu.mak
@@ -1,6 +1,5 @@
 CONFIG_PCI=y
 CONFIG_VIRTIO_PCI=$(CONFIG_PCI)
-include virtio.mak
 CONFIG_SCLPCONSOLE=y
 CONFIG_TERMINAL3270=y
 CONFIG_S390_FLIC=y
diff --git a/default-configs/virtio.mak b/default-configs/virtio.mak
deleted file mode 100644
index 1304849018..00
--- a/default-configs/virtio.mak
+++ /dev/null
@@ -1,14 +0,0 @@
-CONFIG_VHOST_USER_SCSI=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
-CONFIG_VHOST_USER_BLK=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
-CONFIG_VIRTIO=y
-CONFIG_VIRTIO_9P=y
-CONFIG_VIRTIO_BALLOON=y
-CONFIG_VIRTIO_BLK=y
-CONFIG_VIRTIO_CRYPTO=y
-CONFIG_VIRTIO_GPU=y
-CONFIG_VIRTIO_INPUT=y
-CONFIG_VIRTIO_NET=y
-CONFIG_VIRTIO_RNG=y
-CONFIG_SCSI=y
-CONFIG_VIRTIO_SCSI=y
-CONFIG_VIRTIO_SERIAL=y
diff --git a/hw/9pfs/Kconfig b/hw/9pfs/Kconfig
index a4750999d9..d85869ca81 100644
--- a/hw/9pfs/Kconfig
+++ b/hw/9pfs/Kconfig
@@ -1,2 +1,4 @@
 config VIRTIO_9P
 bool
+default y
+depends on VIRTIO
diff --git a/hw/block/Kconfig b/hw/block/Kconfig
index 83c2be5915..771967ad9f 100644
--- a/hw/block/Kconfig
+++ b/hw/block/Kconfig
@@ -28,6 +28,8 @@ config NVME_PCI
 
 config VIRTIO_BLK
 bool
+default y
+depends on VIRTIO
 
 config VHOST_USER_BLK
 bool
diff --git a/hw/char/Kconfig b/hw/char/Kconfig
index 56c1177f95..9836739679 100644
--- a/hw/char/Kconfig
+++ b/hw/char/Kconfig
@@ -26,6 +26,8 @@ config SERIAL_PCI
 
 config VIRTIO_SERIAL
 bool
+default y
+depends on VIRTIO
 
 config STM32F2XX_USART
 bool
diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index 933793cc13..a80c0eace6 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -93,9 +93,14 @@ config QXL
 
 config VIRTIO_GPU
 bool
+default y
+depends on VIRTIO
 
 config VIRTIO_VGA
 bool
+default y
+depends on VIRTIO && PCI
+select VGA
 
 config DPCD
 bool
diff --git a/hw/input/Kconfig b/hw/input/Kconfig
index 5d64e07fc6..7434a14cb0 100644
--- a/hw/input/Kconfig
+++ b/hw/input/Kconfig
@@ -21,6 +21,8 @@ config TSC2005
 
 config VIRTIO_INPUT
 bool
+default y
+depends on VIRTIO
 
 config TSC210X
 bool
diff --git a/hw/net/Kconfig b/hw/net/Kconfig
index a9aa60f9a7..55b97edbd6 100644
--- a/hw/net/Kconfig
+++ b/hw/net/Kconfig
@@ -94,6 +94,8 @@ config XILINX_ETHLITE
 
 config VIRTIO_NET
bool
+   default y
+   depends on VIRTIO
 
 config ETSEC
 bool
diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig
index 84670ee37c..ee0111d061 100644
--- a/hw/pci-host/Kconfig
+++ b/hw/pci-host/Kconfig
@@ -22,6 +22,7 @@ config PCI_SABRE
 config PCI_PIIX
 bool
 select PCI
+select VIRTIO
 
 config PCI_Q35
 bool
@@ -30,6 +31,7 @@ config PCI_Q35
 select XIO3130
 select IOH3420
 select I82801B11
+select VIRTIO
 
 config PCI_GENERIC
 bool
diff --git a/hw/scsi/Kconfig b/hw/scsi/Kconfig
index 7a9d373382..22281213ba 100644
--- a/hw/scsi/Kconfig
+++ b/hw/scsi/Kconfig
@@ -43,6 +43,7 @@ config SPAPR_VSCSI
 config VIRTIO_SCSI
 bool
 default y
+depends on VIRTIO
 select SCSI
 
 config VHOST_USER_SCSI
diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig
index aabd6d4d96..a684de9af4 100644
--- a/hw/virtio/Kconfig
+++ b/hw/virtio/Kconfig
@@ -3,18 +3,25 @@ config VIRTIO
 
 config VIRTIO_RNG
 bool
+default y
+depends on VIRTIO
 
 config VIRTIO_PCI
 bool
 default y
 depends on PCI
-select VIRTIO
+depends on VIRTIO
 
 config VIRTIO_MMIO
 bool
+depends on VIRTIO
 
 config VIRTIO_BALLOON
 bool
+default y
+depends on VIRTIO
 
 config VIRTIO_CRYPTO
 bool
+default y
+depends on VIRTIO
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 24/37] build: convert sound.mak to Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

There is really nothing special in these devices; they are just
ISA devices.  Instead of including them for each target,
set CONFIG_ISA to true, and make the devices default to present
whenever ISA is available.  More conversion of ISA devices will
follow.

Done with the following script:

  while read i; do
 i=${i%=y}; i=${i#CONFIG_}
 sed -i -e'/^config '$i'$/!b' -en \
-e'a\' -e'default y\' -e'depends on ISA' \
  `grep -lw $i hw/*/Kconfig`
  done < default-configs/sound.mak

Signed-off-by: Paolo Bonzini 
Reviewed-by: Thomas Huth 
---
 default-configs/i386-softmmu.mak| 2 +-
 default-configs/mips-softmmu-common.mak | 2 +-
 default-configs/ppc-softmmu.mak | 2 +-
 default-configs/sound.mak   | 4 
 hw/audio/Kconfig| 8 
 5 files changed, 11 insertions(+), 7 deletions(-)
 delete mode 100644 default-configs/sound.mak

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 554dbd8c6b..cf49e3fae7 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -1,7 +1,7 @@
 # Default configuration for i386-softmmu
 
 CONFIG_PCI=y
-include sound.mak
+CONFIG_ISA=y
 include usb.mak
 include hyperv.mak
 CONFIG_VGA_ISA=y
diff --git a/default-configs/mips-softmmu-common.mak 
b/default-configs/mips-softmmu-common.mak
index 5ef6d49e66..03c7a08d1a 100644
--- a/default-configs/mips-softmmu-common.mak
+++ b/default-configs/mips-softmmu-common.mak
@@ -1,7 +1,7 @@
 # Common mips*-softmmu CONFIG defines
 
-include sound.mak
 include usb.mak
+CONFIG_ISA=y
 CONFIG_PCI=y
 CONFIG_ESP=y
 CONFIG_SCSI=y
diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak
index 301cc83279..c7003e4284 100644
--- a/default-configs/ppc-softmmu.mak
+++ b/default-configs/ppc-softmmu.mak
@@ -1,8 +1,8 @@
 # Default configuration for ppc-softmmu
 
-include sound.mak
 include usb.mak
 CONFIG_PCI=y
+ONFIG_ISA=y
 
 # For embedded PPCs:
 CONFIG_PPC4XX=y
diff --git a/default-configs/sound.mak b/default-configs/sound.mak
deleted file mode 100644
index 4f22c34b5d..00
--- a/default-configs/sound.mak
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG_SB16=y
-CONFIG_ADLIB=y
-CONFIG_GUS=y
-CONFIG_CS4231A=y
diff --git a/hw/audio/Kconfig b/hw/audio/Kconfig
index af34bbcf0c..bfb30276ec 100644
--- a/hw/audio/Kconfig
+++ b/hw/audio/Kconfig
@@ -1,5 +1,7 @@
 config SB16
 bool
+default y
+depends on ISA_BUS
 
 config ES1370
 bool
@@ -13,12 +15,18 @@ config AC97
 
 config ADLIB
 bool
+default y
+depends on ISA_BUS
 
 config GUS
 bool
+default y
+depends on ISA_BUS
 
 config CS4231A
 bool
+default y
+depends on ISA_BUS
 
 config HDA
 bool
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 29/37] i386: express dependencies with Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

This way, the default-configs file only need to specify the boards
and any optional devices.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 default-configs/i386-softmmu.mak | 39 
 hw/acpi/Kconfig  |  3 ++
 hw/display/Kconfig   |  1 +
 hw/i2c/Makefile.objs |  4 +-
 hw/i386/Kconfig  | 63 +---
 hw/isa/Kconfig   |  1 +
 hw/pci-host/Kconfig  |  5 +++
 hw/tpm/Kconfig   |  5 ++-
 8 files changed, 80 insertions(+), 41 deletions(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index a66fd1ee5e..23ea6a3888 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -1,10 +1,6 @@
 # Default configuration for i386-softmmu
 
-CONFIG_PCI=y
-CONFIG_ISA=y
 include hyperv.mak
-CONFIG_VGA_ISA=y
-CONFIG_VMWARE_VGA=y
 CONFIG_VMXNET3_PCI=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_IPMI=y
@@ -12,46 +8,25 @@ CONFIG_IPMI_LOCAL=y
 CONFIG_IPMI_EXTERN=y
 CONFIG_ISA_IPMI_KCS=y
 CONFIG_ISA_IPMI_BT=y
-CONFIG_I8254=y
-CONFIG_ACPI=y
-CONFIG_ACPI_X86=y
-CONFIG_ACPI_X86_ICH=y
-CONFIG_ACPI_MEMORY_HOTPLUG=y
-CONFIG_ACPI_CPU_HOTPLUG=y
-CONFIG_APM=y
-CONFIG_I8257=y
-CONFIG_IDE_ISA=y
-CONFIG_IDE_PIIX=y
+
+# Optional devices:
+#
 CONFIG_HPET=y
 CONFIG_APPLESMC=y
-CONFIG_I8259=y
 CONFIG_PFLASH_CFI01=y
-CONFIG_MC146818RTC=y
-CONFIG_PCI_PIIX=y
-CONFIG_ISA_DEBUG=y
 CONFIG_ISA_TESTDEV=y
-CONFIG_VMPORT=y
 CONFIG_SGA=y
-CONFIG_LPC_ICH9=y
-CONFIG_PCI_Q35=y
-CONFIG_APIC=y
-CONFIG_IOAPIC=y
 CONFIG_PVPANIC=y
 CONFIG_MEM_DEVICE=y
-CONFIG_DIMM=y
 CONFIG_NVDIMM=y
 CONFIG_ACPI_NVDIMM=y
-CONFIG_XIO3130=y
-CONFIG_IOH3420=y
-CONFIG_I82801B11=y
-CONFIG_SMBIOS=y
 CONFIG_PXB=y
 CONFIG_ACPI_VMGENID=y
-CONFIG_FW_CFG_DMA=y
 CONFIG_I2C=y
 CONFIG_SEV=$(CONFIG_KVM)
-CONFIG_VTD=y
-CONFIG_AMD_IOMMU=y
-CONFIG_PAM=y
+
+# Boards:
+#
+CONFIG_ISAPC=y
 CONFIG_I440FX=y
 CONFIG_Q35=y
diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
index 2f4871c10a..98bb3539e1 100644
--- a/hw/acpi/Kconfig
+++ b/hw/acpi/Kconfig
@@ -3,15 +3,18 @@ config ACPI
 
 config ACPI_X86
 bool
+select ACPI
 
 config ACPI_X86_ICH
 bool
+select ACPI_X86
 
 config ACPI_CPU_HOTPLUG
 bool
 
 config ACPI_MEMORY_HOTPLUG
 bool
+select MEM_DEVICE
 
 config ACPI_NVDIMM
 bool
diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index a53ca4601a..3d69435982 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -82,6 +82,7 @@ config VGA
 
 config QXL
 bool
+default y if PC
 depends on SPICE && PCI
 select VGA
 
diff --git a/hw/i2c/Makefile.objs b/hw/i2c/Makefile.objs
index 37cacde978..48f7760379 100644
--- a/hw/i2c/Makefile.objs
+++ b/hw/i2c/Makefile.objs
@@ -1,8 +1,8 @@
 common-obj-$(CONFIG_I2C) += core.o smbus.o smbus_eeprom.o
 common-obj-$(CONFIG_DDC) += i2c-ddc.o
 common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o
-common-obj-$(CONFIG_ACPI_X86) += smbus_ich9.o
-common-obj-$(CONFIG_APM) += pm_smbus.o
+common-obj-$(CONFIG_ACPI_X86_ICH) += smbus_ich9.o
+common-obj-$(CONFIG_ACPI_SMBUS) += pm_smbus.o
 common-obj-$(CONFIG_BITBANG_I2C) += bitbang_i2c.o
 common-obj-$(CONFIG_EXYNOS4) += exynos4210_i2c.o
 common-obj-$(CONFIG_IMX_I2C) += imx_i2c.o
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index 68a9064558..b359319875 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -1,21 +1,71 @@
 config KVM
 bool
 
-config I440FX
+config PC
 bool
-select QXL if SPICE
+select ISA_DEBUG
+select I8259
+select I8254
+select PCSPK
+select I82374
+select I8257
+select MC146818RTC
 select TPM_TIS if TPM
-select XEN_I386 if XEN
+
+config PC_PCI
+bool
+select APIC
+select IOAPIC
+select APM
+select PC
+
+config PC_ACPI
+bool
+select ACPI_X86
+select ACPI_CPU_HOTPLUG
+select ACPI_MEMORY_HOTPLUG
+depends on ACPI_SMBUS
+
+config I440FX
+bool
+select PC_PCI
+select PC_ACPI
+select ACPI_SMBUS
+select PCI_PIIX
+select FDC
+select IDE_PIIX
+select PAM
+select DIMM
+select SMBIOS
+select VMPORT
+select VMMOUSE
+select FW_CFG_DMA
 
 config ISAPC
 bool
 select ISA_BUS
+select PC
+select IDE_ISA
+select VGA_ISA
+# FIXME: it is in the same file as i440fx, and does not compile
+# if separated
+depends on I440FX
 
 config Q35
 bool
-select QXL if SPICE
-select TPM_TIS if TPM
-select XEN_I386 if XEN
+select PC_PCI
+select PC_ACPI
+select PCI_Q35
+select LPC_ICH9
+select AHCI
+select PAM
+select AMD_IOMMU
+select DIMM
+select SMBIOS
+select VMPORT
+select VMMOUSE
+select FW_CFG_DMA
+select VTD
 
 config VTD
 bool
@@ -28,3 +78,4 @@ config VMPORT
 
 config VMMOUSE
 bool
+depends on VMPORT
diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig
index 3f451ef006..bf72e4fef2 100644
--- a/hw/isa/Kconfig
+++ b/hw/isa/Kconfig
@@ -25,4 +25,5 @@ co

[Qemu-devel] [RFC PATCH v2 33/37] hyperv: express dependencies with kconfig

2019-01-15 Thread Yang Zhong
remove default-configs/hyperv.mak and make dependencies
with Kconfig.

Signed-off-by: Yang Zhong 
Reviewed-by: Thomas Huth 
---
 default-configs/hyperv.mak   | 2 --
 default-configs/i386-softmmu.mak | 1 -
 hw/hyperv/Kconfig| 4 
 3 files changed, 4 insertions(+), 3 deletions(-)
 delete mode 100644 default-configs/hyperv.mak

diff --git a/default-configs/hyperv.mak b/default-configs/hyperv.mak
deleted file mode 100644
index 5d0d9fd830..00
--- a/default-configs/hyperv.mak
+++ /dev/null
@@ -1,2 +0,0 @@
-CONFIG_HYPERV=$(CONFIG_KVM)
-CONFIG_HYPERV_TESTDEV=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 38622f7132..ab57978b9a 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -1,6 +1,5 @@
 # Default configuration for i386-softmmu
 
-include hyperv.mak
 CONFIG_VMXNET3_PCI=y
 CONFIG_VIRTIO_VGA=y
 CONFIG_IPMI=y
diff --git a/hw/hyperv/Kconfig b/hw/hyperv/Kconfig
index be724b7f8b..a178bac3da 100644
--- a/hw/hyperv/Kconfig
+++ b/hw/hyperv/Kconfig
@@ -1,5 +1,9 @@
 config HYPERV
 bool
+default y if PC
+depends on KVM
 
 config HYPERV_TESTDEV
 bool
+default y if PC
+depends on HYPERV
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 35/37] i386-softmmu.mak: remove all CONFIG_* except boards definitions

2019-01-15 Thread Yang Zhong
%-softmmu.mak only keep boards definitions in Kconfig mode.

Signed-off-by: Yang Zhong 
---
 default-configs/i386-softmmu.mak | 22 --
 hw/acpi/Kconfig  |  4 
 hw/i386/Kconfig  |  5 +
 hw/ipmi/Kconfig  |  6 ++
 hw/mem/Kconfig   |  2 ++
 hw/misc/Kconfig  |  4 
 hw/pci-bridge/Kconfig|  1 +
 hw/timer/Kconfig |  1 +
 8 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 992aea8f30..7b083412af 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -1,27 +1,5 @@
 # Default configuration for i386-softmmu
 
-CONFIG_VMXNET3_PCI=y
-CONFIG_IPMI=y
-CONFIG_IPMI_LOCAL=y
-CONFIG_IPMI_EXTERN=y
-CONFIG_ISA_IPMI_KCS=y
-CONFIG_ISA_IPMI_BT=y
-
-# Optional devices:
-#
-CONFIG_HPET=y
-CONFIG_APPLESMC=y
-CONFIG_PFLASH_CFI01=y
-CONFIG_ISA_TESTDEV=y
-CONFIG_SGA=y
-CONFIG_PVPANIC=y
-CONFIG_MEM_DEVICE=y
-CONFIG_NVDIMM=y
-CONFIG_ACPI_NVDIMM=y
-CONFIG_PXB=y
-CONFIG_ACPI_VMGENID=y
-CONFIG_SEV=$(CONFIG_KVM)
-
 # Boards:
 #
 CONFIG_ISAPC=y
diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
index 98bb3539e1..09af3ce3be 100644
--- a/hw/acpi/Kconfig
+++ b/hw/acpi/Kconfig
@@ -18,9 +18,13 @@ config ACPI_MEMORY_HOTPLUG
 
 config ACPI_NVDIMM
 bool
+default y
+depends on I440FX && Q35
 
 config ACPI_VMGENID
 bool
+default y
+depends on I440FX && Q35
 
 config IPMI
 bool
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index 9f5788e8e2..1bda20f315 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -1,6 +1,10 @@
 config KVM
 bool
 
+config SEV
+bool
+default y if PC && KVM
+
 config PC
 bool
 select ISA_DEBUG
@@ -25,6 +29,7 @@ config PC_ACPI
 select ACPI_CPU_HOTPLUG
 select ACPI_MEMORY_HOTPLUG
 select SMBUS_EEPROM
+select PFLASH_CFI01
 depends on ACPI_SMBUS
 
 config I440FX
diff --git a/hw/ipmi/Kconfig b/hw/ipmi/Kconfig
index 68f8ba1a54..7730ff5193 100644
--- a/hw/ipmi/Kconfig
+++ b/hw/ipmi/Kconfig
@@ -3,12 +3,18 @@ config IPMI
 
 config IPMI_LOCAL
 bool
+depends on IPMI
 
 config IPMI_EXTERN
 bool
+depends on IPMI
 
 config ISA_IPMI_KCS
 bool
+default y if PC
+select IPMI
 
 config ISA_IPMI_BT
 bool
+default y if PC
+select IPMI
diff --git a/hw/mem/Kconfig b/hw/mem/Kconfig
index a3a4372fa7..099fb84df4 100644
--- a/hw/mem/Kconfig
+++ b/hw/mem/Kconfig
@@ -6,3 +6,5 @@ config MEM_DEVICE
 
 config NVDIMM
 bool
+default y
+depends on I440FX && Q35
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index 73ceefab75..6fb1c0ca22 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -1,5 +1,6 @@
 config APPLESMC
 bool
+default y if PC
 depends on ISA_BUS
 
 config MAX111X
@@ -19,10 +20,12 @@ config ISA_DEBUG
 
 config SGA
 bool
+default y if PC
 depends on ISA_BUS
 
 config ISA_TESTDEV
 bool
+default y if PC
 
 config PCI_TESTDEV
 bool
@@ -99,6 +102,7 @@ config IOTKIT_SYSINFO
 
 config PVPANIC
 bool
+default y if PC
 depends on ISA_BUS
 
 config AUX
diff --git a/hw/pci-bridge/Kconfig b/hw/pci-bridge/Kconfig
index d54d878023..7865e182dc 100644
--- a/hw/pci-bridge/Kconfig
+++ b/hw/pci-bridge/Kconfig
@@ -5,6 +5,7 @@ config PCIE_PORT
 
 config PXB
 bool
+default y if PC
 
 config XIO3130
 bool
diff --git a/hw/timer/Kconfig b/hw/timer/Kconfig
index a021c742de..51921eb63f 100644
--- a/hw/timer/Kconfig
+++ b/hw/timer/Kconfig
@@ -15,6 +15,7 @@ config DS1338
 
 config HPET
 bool
+default y if PC
 
 config I8254
 bool
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 19/37] kconfig: introduce kconfig files

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

The Kconfig files were generated mostly with this script:

  for i in `grep -ho CONFIG_[A-Z0-9_]* default-configs/* | sort -u`; do
set fnord `git grep -lw $i -- 'hw/*/Makefile.objs' `
shift
if test $# = 1; then
  cat >> $(dirname $1)/Kconfig << EOF
config ${i#CONFIG_}
bool

EOF
  git add $(dirname $1)/Kconfig
else
  echo $i $*
fi
  done
  sed -i '$d' hw/*/Kconfig
  for i in hw/*; do
if test -d $i && ! test -f $i/Kconfig; then
  touch $i/Kconfig
  git add $i/Kconfig
fi
  done

Whenever a symbol is referenced from multiple subdirectories, the
script prints the list of directories that reference the symbol.
These symbols have to be added manually to the Kconfig files.

Kconfig.host and hw/Kconfig were created manually.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 Kconfig.host  | 17 
 hw/9pfs/Kconfig   |  2 +
 hw/Kconfig| 60 ++
 hw/acpi/Kconfig   | 23 ++
 hw/adc/Kconfig|  2 +
 hw/arm/Kconfig| 98 +++
 hw/audio/Kconfig  | 35 
 hw/block/Kconfig  | 29 +
 hw/bt/Kconfig |  2 +
 hw/char/Kconfig   | 32 ++
 hw/core/Kconfig   | 11 +
 hw/cpu/Kconfig|  8 
 hw/display/Kconfig| 77 ++
 hw/dma/Kconfig| 20 +
 hw/gpio/Kconfig   |  8 
 hw/hyperv/Kconfig |  5 +++
 hw/i2c/Kconfig| 20 +
 hw/i386/Kconfig   | 23 ++
 hw/ide/Kconfig| 35 
 hw/input/Kconfig  | 23 ++
 hw/intc/Kconfig   | 47 +
 hw/ipack/Kconfig  |  2 +
 hw/ipmi/Kconfig   | 14 +++
 hw/isa/Kconfig| 23 ++
 hw/lm32/Kconfig   |  5 +++
 hw/m68k/Kconfig   |  8 
 hw/mem/Kconfig|  8 
 hw/microblaze/Kconfig |  8 
 hw/mips/Kconfig   | 20 +
 hw/misc/Kconfig   | 92 
 hw/misc/macio/Kconfig | 11 +
 hw/net/Kconfig| 92 
 hw/nios2/Kconfig  |  2 +
 hw/nvram/Kconfig  |  8 
 hw/pci-bridge/Kconfig | 20 +
 hw/pci-host/Kconfig   | 35 
 hw/pci/Kconfig|  2 +
 hw/pcmcia/Kconfig |  2 +
 hw/ppc/Kconfig| 38 +
 hw/riscv/Kconfig  | 14 +++
 hw/scsi/Kconfig   | 26 
 hw/sd/Kconfig | 11 +
 hw/sh4/Kconfig|  8 
 hw/smbios/Kconfig |  2 +
 hw/sparc/Kconfig  |  5 +++
 hw/sparc64/Kconfig|  5 +++
 hw/ssi/Kconfig| 14 +++
 hw/timer/Kconfig  | 53 +++
 hw/tpm/Kconfig| 14 +++
 hw/usb/Kconfig| 53 +++
 hw/vfio/Kconfig   | 11 +
 hw/virtio/Kconfig | 17 
 hw/watchdog/Kconfig   | 11 +
 hw/xtensa/Kconfig |  5 +++
 54 files changed, 1216 insertions(+)
 create mode 100644 Kconfig.host
 create mode 100644 hw/9pfs/Kconfig
 create mode 100644 hw/Kconfig
 create mode 100644 hw/acpi/Kconfig
 create mode 100644 hw/adc/Kconfig
 create mode 100644 hw/arm/Kconfig
 create mode 100644 hw/audio/Kconfig
 create mode 100644 hw/block/Kconfig
 create mode 100644 hw/bt/Kconfig
 create mode 100644 hw/char/Kconfig
 create mode 100644 hw/core/Kconfig
 create mode 100644 hw/cpu/Kconfig
 create mode 100644 hw/display/Kconfig
 create mode 100644 hw/dma/Kconfig
 create mode 100644 hw/gpio/Kconfig
 create mode 100644 hw/hyperv/Kconfig
 create mode 100644 hw/i2c/Kconfig
 create mode 100644 hw/i386/Kconfig
 create mode 100644 hw/ide/Kconfig
 create mode 100644 hw/input/Kconfig
 create mode 100644 hw/intc/Kconfig
 create mode 100644 hw/ipack/Kconfig
 create mode 100644 hw/ipmi/Kconfig
 create mode 100644 hw/isa/Kconfig
 create mode 100644 hw/lm32/Kconfig
 create mode 100644 hw/m68k/Kconfig
 create mode 100644 hw/mem/Kconfig
 create mode 100644 hw/microblaze/Kconfig
 create mode 100644 hw/mips/Kconfig
 create mode 100644 hw/misc/Kconfig
 create mode 100644 hw/misc/macio/Kconfig
 create mode 100644 hw/net/Kconfig
 create mode 100644 hw/nios2/Kconfig
 create mode 100644 hw/nvram/Kconfig
 create mode 100644 hw/pci-bridge/Kconfig
 create mode 100644 hw/pci-host/Kconfig
 create mode 100644 hw/pci/Kconfig
 create mode 100644 hw/pcmcia/Kconfig
 create mode 100644 hw/ppc/Kconfig
 create mode 100644 hw/riscv/Kconfig
 create mode 100644 hw/scsi/Kconfig
 create mode 100644 hw/sd/Kconfig
 create mode 100644 hw/sh4/Kconfig
 create mode 100644 hw/smbios/Kconfig
 create mode 100644 hw/sparc/Kconfig
 create mode 100644 hw/sparc64/Kconfig
 create mode 100644 hw/ssi/Kconfig
 create mode 100644 hw/timer/Kconfig
 create mode 100644 hw/tpm/Kconfig
 create mode 100644 hw/usb/Kconfig
 create mode 100644 hw/vfio/Kconfig
 create mode 100644 hw/virtio/Kconfig
 create mode 100644 hw/watchdog/Kconfig
 create mode 100644 hw/xtensa/Kconfig

diff --git a/K

[Qemu-devel] [RFC PATCH v2 27/37] bluetooth: express dependencies with Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
Reviewed-by: Thomas Huth 
---
 hw/Makefile.objs | 2 +-
 hw/usb/Kconfig   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 39d882af6f..b95b0c74a1 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -3,7 +3,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += acpi/
 devices-dirs-$(CONFIG_SOFTMMU) += adc/
 devices-dirs-$(CONFIG_SOFTMMU) += audio/
 devices-dirs-$(CONFIG_SOFTMMU) += block/
-devices-dirs-$(CONFIG_SOFTMMU) += bt/
+devices-dirs-$(CONFIG_BLUETOOTH) += bt/
 devices-dirs-$(CONFIG_SOFTMMU) += char/
 devices-dirs-$(CONFIG_SOFTMMU) += cpu/
 devices-dirs-$(CONFIG_SOFTMMU) += display/
diff --git a/hw/usb/Kconfig b/hw/usb/Kconfig
index db46c56cc8..8feab2ac0c 100644
--- a/hw/usb/Kconfig
+++ b/hw/usb/Kconfig
@@ -79,6 +79,7 @@ config USB_BLUETOOTH
 bool
 default y
 depends on USB
+select BLUETOOTH
 
 config USB_SMARTCARD
 bool
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 21/37] ide: express dependencies with Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Signed-off-by: Paolo Bonzini 
---
 default-configs/alpha-softmmu.mak |  2 --
 default-configs/pci.mak   |  3 ---
 hw/ide/Kconfig| 15 +++
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/default-configs/alpha-softmmu.mak 
b/default-configs/alpha-softmmu.mak
index 4d654eaa0b..62afa5ec16 100644
--- a/default-configs/alpha-softmmu.mak
+++ b/default-configs/alpha-softmmu.mak
@@ -11,8 +11,6 @@ CONFIG_PARALLEL=y
 CONFIG_FDC=y
 CONFIG_PCKBD=y
 CONFIG_VGA_CIRRUS=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
 CONFIG_VMWARE_VGA=y
 CONFIG_IDE_CMD646=y
 CONFIG_I8259=y
diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index 171bdf48bc..c1b64922b9 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -23,9 +23,6 @@ CONFIG_MPTSAS_SCSI_PCI=y
 CONFIG_RTL8139_PCI=y
 CONFIG_E1000_PCI=y
 CONFIG_E1000E_PCI=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_AHCI=y
 CONFIG_ESP=y
 CONFIG_ESP_PCI=y
diff --git a/hw/ide/Kconfig b/hw/ide/Kconfig
index 5ec449525f..fe27705790 100644
--- a/hw/ide/Kconfig
+++ b/hw/ide/Kconfig
@@ -3,33 +3,48 @@ config IDE_CORE
 
 config IDE_QDEV
 bool
+select IDE_CORE
 
 config IDE_PCI
 bool
+select IDE_CORE
 
 config IDE_ISA
 bool
+select IDE_QDEV
 
 config IDE_PIIX
 bool
+select IDE_PCI
+select IDE_QDEV
 
 config IDE_CMD646
 bool
+select IDE_PCI
+select IDE_QDEV
 
 config IDE_MACIO
 bool
+select IDE_QDEV
 
 config IDE_MMIO
 bool
+select IDE_QDEV
 
 config IDE_VIA
 bool
+select IDE_PCI
+select IDE_QDEV
 
 config MICRODRIVE
 bool
+select IDE_QDEV
 
 config AHCI
 bool
+select IDE_QDEV
 
 config IDE_SII3112
 bool
+select IDE_PCI
+select IDE_QDEV
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 30/37] i2c: express dependencies with Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 default-configs/i386-softmmu.mak | 1 -
 hw/Makefile.objs | 2 +-
 hw/audio/Kconfig | 1 +
 hw/display/Kconfig   | 3 +++
 hw/gpio/Kconfig  | 1 +
 hw/i2c/Kconfig   | 6 ++
 hw/i2c/Makefile.objs | 3 ++-
 hw/i386/Kconfig  | 1 +
 hw/input/Kconfig | 1 +
 hw/isa/Kconfig   | 1 +
 hw/misc/Kconfig  | 4 
 hw/timer/Kconfig | 3 +++
 12 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 23ea6a3888..38622f7132 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -22,7 +22,6 @@ CONFIG_NVDIMM=y
 CONFIG_ACPI_NVDIMM=y
 CONFIG_PXB=y
 CONFIG_ACPI_VMGENID=y
-CONFIG_I2C=y
 CONFIG_SEV=$(CONFIG_KVM)
 
 # Boards:
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index b95b0c74a1..920086b182 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -10,7 +10,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += display/
 devices-dirs-$(CONFIG_SOFTMMU) += dma/
 devices-dirs-$(CONFIG_SOFTMMU) += gpio/
 devices-dirs-$(CONFIG_HYPERV) += hyperv/
-devices-dirs-$(CONFIG_SOFTMMU) += i2c/
+devices-dirs-$(CONFIG_I2C) += i2c/
 devices-dirs-$(CONFIG_SOFTMMU) += ide/
 devices-dirs-$(CONFIG_SOFTMMU) += input/
 devices-dirs-$(CONFIG_SOFTMMU) += intc/
diff --git a/hw/audio/Kconfig b/hw/audio/Kconfig
index 350f2d4359..5cb7118e44 100644
--- a/hw/audio/Kconfig
+++ b/hw/audio/Kconfig
@@ -40,6 +40,7 @@ config PCSPK
 
 config WM8750
 bool
+depends on I2C
 
 config PL041
 bool
diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index 3d69435982..7a9d121772 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -24,9 +24,11 @@ config PL110
 
 config SII9022
 bool
+depends on I2C
 
 config SSD0303
 bool
+depends on I2C
 
 config SSD0323
 bool
@@ -70,6 +72,7 @@ config MILKYMIST_TMU2
 
 config SM501
 bool
+depends on I2C
 
 config TCX
 bool
diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig
index d0a4abf93f..9227cb5598 100644
--- a/hw/gpio/Kconfig
+++ b/hw/gpio/Kconfig
@@ -1,5 +1,6 @@
 config MAX7310
 bool
+depends on I2C
 
 config PL061
 bool
diff --git a/hw/i2c/Kconfig b/hw/i2c/Kconfig
index d6d4402608..74c9328729 100644
--- a/hw/i2c/Kconfig
+++ b/hw/i2c/Kconfig
@@ -3,18 +3,24 @@ config I2C
 
 config SMBUS_EEPROM
 bool
+depends on I2C
 
 config DDC
 bool
+depends on I2C
 
 config VERSATILE_I2C
 bool
+select I2C
 
 config ACPI_SMBUS
 bool
+select I2C
 
 config BITBANG_I2C
 bool
+select I2C
 
 config IMX_I2C
 bool
+select I2C
diff --git a/hw/i2c/Makefile.objs b/hw/i2c/Makefile.objs
index 48f7760379..ff22aa6541 100644
--- a/hw/i2c/Makefile.objs
+++ b/hw/i2c/Makefile.objs
@@ -1,4 +1,5 @@
-common-obj-$(CONFIG_I2C) += core.o smbus.o smbus_eeprom.o
+common-obj-$(CONFIG_I2C) += core.o smbus.o
+common-obj-$(CONFIG_SMBUS_EEPROM) += smbus_eeprom.o
 common-obj-$(CONFIG_DDC) += i2c-ddc.o
 common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o
 common-obj-$(CONFIG_ACPI_X86_ICH) += smbus_ich9.o
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index b359319875..9f5788e8e2 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -24,6 +24,7 @@ config PC_ACPI
 select ACPI_X86
 select ACPI_CPU_HOTPLUG
 select ACPI_MEMORY_HOTPLUG
+select SMBUS_EEPROM
 depends on ACPI_SMBUS
 
 config I440FX
diff --git a/hw/input/Kconfig b/hw/input/Kconfig
index 01805ed17b..5d64e07fc6 100644
--- a/hw/input/Kconfig
+++ b/hw/input/Kconfig
@@ -3,6 +3,7 @@ config ADB
 
 config LM832X
 bool
+depends on I2C
 
 config PCKBD
 bool
diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig
index bf72e4fef2..82eaf183b1 100644
--- a/hw/isa/Kconfig
+++ b/hw/isa/Kconfig
@@ -18,6 +18,7 @@ config PIIX4
 config VT82C686
 bool
 select ISA_BUS
+select ACPI_SMBUS
 
 config SMC37C669
 bool
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index e6df7480c6..73ceefab75 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -7,9 +7,11 @@ config MAX111X
 
 config TMP105
 bool
+depends on I2C
 
 config TMP421
 bool
+depends on I2C
 
 config ISA_DEBUG
 bool
@@ -34,6 +36,7 @@ config EDU
 
 config PCA9552
 bool
+depends on I2C
 
 config PL310
 bool
@@ -100,3 +103,4 @@ config PVPANIC
 
 config AUX
 bool
+select I2C
diff --git a/hw/timer/Kconfig b/hw/timer/Kconfig
index 7dbc1211ab..e1a6e7469b 100644
--- a/hw/timer/Kconfig
+++ b/hw/timer/Kconfig
@@ -9,6 +9,7 @@ config A9_GTIMER
 
 config DS1338
 bool
+depends on I2C
 
 config HPET
 bool
@@ -18,6 +19,7 @@ config I8254
 
 config M41T80
 bool
+depends on I2C
 
 config M48T59
 bool
@@ -27,6 +29,7 @@ config PL031
 
 config TWL92230
 bool
+depends on I2C
 
 config XLNX_ZYNQMP
 bool
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 22/37] hw/pci/Makefile.objs: make pcie configurable

2019-01-15 Thread Yang Zhong
Make pcie splited from pci and make it configurable.

Signed-off-by: Yang Zhong 
---
 default-configs/pci.mak | 1 +
 hw/pci/Kconfig  | 3 +++
 hw/pci/Makefile.objs| 5 +++--
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index c1b64922b9..553b1905de 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -1,4 +1,5 @@
 CONFIG_PCI=y
+CONFIG_PCIE=y
 # For now, CONFIG_IDE_CORE requires ISA, so we enable it here
 CONFIG_ISA_BUS=y
 CONFIG_VIRTIO_PCI=y
diff --git a/hw/pci/Kconfig b/hw/pci/Kconfig
index d3d2205577..a717a26995 100644
--- a/hw/pci/Kconfig
+++ b/hw/pci/Kconfig
@@ -1,2 +1,5 @@
 config PCI
 bool
+
+config PCIE
+bool
diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs
index 9f905e6344..a995795a47 100644
--- a/hw/pci/Makefile.objs
+++ b/hw/pci/Makefile.objs
@@ -2,8 +2,9 @@ common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
 common-obj-$(CONFIG_PCI) += msix.o msi.o
 common-obj-$(CONFIG_PCI) += shpc.o
 common-obj-$(CONFIG_PCI) += slotid_cap.o
-common-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
-common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o
+common-obj-$(CONFIG_PCI) += pci_host.o
+common-obj-$(CONFIG_PCIE) += pcie.o pcie_aer.o
+common-obj-$(CONFIG_PCIE) += pcie_port.o pcie_host.o
 
 common-obj-$(call lnot,$(CONFIG_PCI)) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 16/37] minikconfig: add AST

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Add Python classes that represent the Kconfig abstract syntax tree.
The abstract syntax tree is stored as a list of clauses.  For example:

config FOO
depends on BAR
select BAZ

is represented as three clauses:

FOO depends on BAR
FOO default n
select BAZ if FOO

Signed-off-by: Paolo Bonzini 
---
 scripts/minikconf.py | 116 ---
 1 file changed, 98 insertions(+), 18 deletions(-)

diff --git a/scripts/minikconf.py b/scripts/minikconf.py
index fb39e35d6a..a6a28c9c47 100644
--- a/scripts/minikconf.py
+++ b/scripts/minikconf.py
@@ -26,11 +26,84 @@ __all__ = [ 'KconfigParserError', 'KconfigData', 
'KconfigParser' ]
 # ---
 
 class KconfigData:
+class Expr:
+def __and__(self, rhs):
+return KconfigData.AND(self, rhs)
+def __or__(self, rhs):
+return KconfigData.OR(self, rhs)
+def __invert__(self):
+return KconfigData.NOT(self)
+
+class AND(Expr):
+def __init__(self, lhs, rhs):
+self.lhs = lhs
+self.rhs = rhs
+def __str__(self):
+return "(%s && %s)" % (self.lhs, self.rhs)
+
+class OR(Expr):
+def __init__(self, lhs, rhs):
+self.lhs = lhs
+self.rhs = rhs
+def __str__(self):
+return "(%s || %s)" % (self.lhs, self.rhs)
+
+class NOT(Expr):
+def __init__(self, lhs):
+self.lhs = lhs
+def __str__(self):
+return "!%s" % (self.lhs)
+
+class Var(Expr):
+def __init__(self, name):
+self.name = name
+self.value = None
+def __str__(self):
+return self.name
+
+class Clause:
+def __init__(self, dest):
+self.dest = dest
+
+class AssignmentClause(Clause):
+def __init__(self, dest, value):
+KconfigData.Clause.__init__(self, dest)
+self.value = value
+def __str__(self):
+return "%s=%s" % (self.dest, 'y' if self.value else 'n')
+
+class DefaultClause(Clause):
+def __init__(self, dest, value, cond=None):
+KconfigData.Clause.__init__(self, dest)
+self.value = value
+self.cond = cond
+def __str__(self):
+value = 'y' if self.value else 'n'
+if self.cond is None:
+return "config %s default %s" % (self.dest, value)
+else:
+return "config %s default %s if %s" % (self.dest, value, 
self.cond)
+
+class DependsOnClause(Clause):
+def __init__(self, dest, expr):
+KconfigData.Clause.__init__(self, dest)
+self.expr = expr
+def __str__(self):
+return "config %s depends on %s" % (self.dest, self.expr)
+
+class SelectClause(Clause):
+def __init__(self, dest, cond):
+KconfigData.Clause.__init__(self, dest)
+self.cond = cond
+def __str__(self):
+return "select %s if %s" % (self.dest, self.cond)
+
 def __init__(self):
 self.previously_included = []
 self.incl_info = None
 self.defined_vars = set()
-self.referenced_vars = set()
+self.referenced_vars = dict()
+self.clauses = list()
 
 # semantic analysis -
 
@@ -48,26 +121,28 @@ class KconfigData:
 if (var in self.defined_vars):
 raise Exception('variable "' + var + '" defined twice')
 
-self.defined_vars.add(var)
+self.defined_vars.add(var.name)
 
 # var is a string with the variable's name.
-#
-# For now this just returns the variable's name itself.
 def do_var(self, var):
-self.referenced_vars.add(var)
-return var
+if (var in self.referenced_vars):
+return self.referenced_vars[var]
+
+var_obj = self.referenced_vars[var] = KconfigData.Var(var)
+return var_obj
 
 def do_assignment(self, var, val):
-pass
+self.clauses.append(KconfigData.AssignmentClause(var, val))
 
 def do_default(self, var, val, cond=None):
-pass
+self.clauses.append(KconfigData.DefaultClause(var, val, cond))
 
 def do_depends_on(self, var, expr):
-pass
+self.clauses.append(KconfigData.DependsOnClause(var, expr))
 
 def do_select(self, var, symbol, cond=None):
-pass
+cond = (cond & var) if cond is not None else var
+self.clauses.append(KconfigData.SelectClause(symbol, cond))
 
 # ---
 # KconfigParser implements a recursive descent parser for (simplified)
@@ -227,31 +302,34 @@ class KconfigParser:
 def parse_primary(self):
 if self.tok == TOK_NOT:
 self.get_token()
-self.parse_primary()
+val = ~self.parse_primary()
 elif self.tok == TOK_LPAREN:
 self.get_token()
- 

[Qemu-devel] [RFC PATCH v2 14/37] hw/sparc64/Makefile.objs: Create CONFIG_* for sparc64

2019-01-15 Thread Yang Zhong
Add the new configs to default-configs/sparc64-sofmmu.mak.

Signed-off-by: Yang Zhong 
---
 default-configs/sparc64-softmmu.mak | 2 ++
 hw/sparc64/Makefile.objs| 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/default-configs/sparc64-softmmu.mak 
b/default-configs/sparc64-softmmu.mak
index ce63d47046..1fae4888db 100644
--- a/default-configs/sparc64-softmmu.mak
+++ b/default-configs/sparc64-softmmu.mak
@@ -17,3 +17,5 @@ CONFIG_SUNHME=y
 CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
 CONFIG_SUN4V_RTC=y
+CONFIG_SUN4U=y
+CONFIG_NIAGARA=y
diff --git a/hw/sparc64/Makefile.objs b/hw/sparc64/Makefile.objs
index 117e0ff27d..af0525c1a2 100644
--- a/hw/sparc64/Makefile.objs
+++ b/hw/sparc64/Makefile.objs
@@ -1,4 +1,4 @@
 obj-y += sparc64.o
-obj-y += sun4u_iommu.o
-obj-y += sun4u.o
-obj-y += niagara.o
\ No newline at end of file
+obj-$(CONFIG_SUN4U) += sun4u_iommu.o
+obj-$(CONFIG_SUN4U) += sun4u.o
+obj-$(CONFIG_NIAGARA) += niagara.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 25/37] build: convert usb.mak to Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Instead of including the same list of devices for each target,
let the host controllers select CONFIG_USB and make the devices
default to present whenever USB is available.

Done with the following script:
  while read i; do
 i=${i%=y}; i=${i#CONFIG_}
 sed -i -e'/^config '$i'$/!b' -en \
-e'a\' -e'default y\' -e'depends on USB' \
  `grep -lw $i hw/*/Kconfig`
  done < default-configs/usb.mak

followed by adding "select USB" on the host controllers.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
Reviewed-by: Thomas Huth 
---
 default-configs/alpha-softmmu.mak   |  1 -
 default-configs/arm-softmmu.mak |  2 --
 default-configs/hppa-softmmu.mak|  1 -
 default-configs/i386-softmmu.mak|  1 -
 default-configs/mips-softmmu-common.mak |  1 -
 default-configs/ppc-softmmu.mak |  1 -
 default-configs/sh4-softmmu.mak |  1 -
 default-configs/sh4eb-softmmu.mak   |  1 -
 default-configs/sparc64-softmmu.mak |  1 -
 default-configs/usb.mak | 11 ---
 hw/usb/Kconfig  | 26 +
 11 files changed, 26 insertions(+), 21 deletions(-)
 delete mode 100644 default-configs/usb.mak

diff --git a/default-configs/alpha-softmmu.mak 
b/default-configs/alpha-softmmu.mak
index c71d1b7f37..ef8c9ae5ed 100644
--- a/default-configs/alpha-softmmu.mak
+++ b/default-configs/alpha-softmmu.mak
@@ -1,6 +1,5 @@
 # Default configuration for alpha-softmmu
 
-include usb.mak
 CONFIG_PCI=y
 CONFIG_SERIAL=y
 CONFIG_SERIAL_ISA=y
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 8c071f6224..92fc9911eb 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -1,6 +1,5 @@
 # Default configuration for arm-softmmu
 
-include usb.mak
 CONFIG_PCI=y
 CONFIG_VGA=y
 CONFIG_NAND=y
@@ -38,7 +37,6 @@ CONFIG_DS1338=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_MICRODRIVE=y
-CONFIG_USB=y
 CONFIG_USB_MUSB=y
 CONFIG_USB_EHCI_SYSBUS=y
 CONFIG_PLATFORM_BUS=y
diff --git a/default-configs/hppa-softmmu.mak b/default-configs/hppa-softmmu.mak
index 74d34c05e9..fe07c90937 100644
--- a/default-configs/hppa-softmmu.mak
+++ b/default-configs/hppa-softmmu.mak
@@ -1,4 +1,3 @@
-include usb.mak
 CONFIG_PCI=y
 CONFIG_SERIAL=y
 CONFIG_SERIAL_ISA=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index cf49e3fae7..23dcca7a31 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -2,7 +2,6 @@
 
 CONFIG_PCI=y
 CONFIG_ISA=y
-include usb.mak
 include hyperv.mak
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
diff --git a/default-configs/mips-softmmu-common.mak 
b/default-configs/mips-softmmu-common.mak
index 03c7a08d1a..1060374d51 100644
--- a/default-configs/mips-softmmu-common.mak
+++ b/default-configs/mips-softmmu-common.mak
@@ -1,6 +1,5 @@
 # Common mips*-softmmu CONFIG defines
 
-include usb.mak
 CONFIG_ISA=y
 CONFIG_PCI=y
 CONFIG_ESP=y
diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak
index c7003e4284..37040fd17a 100644
--- a/default-configs/ppc-softmmu.mak
+++ b/default-configs/ppc-softmmu.mak
@@ -1,6 +1,5 @@
 # Default configuration for ppc-softmmu
 
-include usb.mak
 CONFIG_PCI=y
 ONFIG_ISA=y
 
diff --git a/default-configs/sh4-softmmu.mak b/default-configs/sh4-softmmu.mak
index 57d99fa93c..9fc09f9d6d 100644
--- a/default-configs/sh4-softmmu.mak
+++ b/default-configs/sh4-softmmu.mak
@@ -1,6 +1,5 @@
 # Default configuration for sh4-softmmu
 
-include usb.mak
 CONFIG_PCI=y
 CONFIG_SERIAL=y
 CONFIG_SERIAL_ISA=y
diff --git a/default-configs/sh4eb-softmmu.mak 
b/default-configs/sh4eb-softmmu.mak
index 2e5909c381..c53051d0d5 100644
--- a/default-configs/sh4eb-softmmu.mak
+++ b/default-configs/sh4eb-softmmu.mak
@@ -1,6 +1,5 @@
 # Default configuration for sh4eb-softmmu
 
-include usb.mak
 CONFIG_PCI=y
 CONFIG_SERIAL=y
 CONFIG_SERIAL_ISA=y
diff --git a/default-configs/sparc64-softmmu.mak 
b/default-configs/sparc64-softmmu.mak
index db393d9eb3..5507346006 100644
--- a/default-configs/sparc64-softmmu.mak
+++ b/default-configs/sparc64-softmmu.mak
@@ -1,6 +1,5 @@
 # Default configuration for sparc64-softmmu
 
-include usb.mak
 CONFIG_PCI=y
 CONFIG_M48T59=y
 CONFIG_PTIMER=y
diff --git a/default-configs/usb.mak b/default-configs/usb.mak
deleted file mode 100644
index e42cfeabbe..00
--- a/default-configs/usb.mak
+++ /dev/null
@@ -1,11 +0,0 @@
-CONFIG_USB=y
-CONFIG_USB_TABLET_WACOM=y
-CONFIG_USB_STORAGE_BOT=y
-CONFIG_USB_STORAGE_UAS=y
-CONFIG_USB_STORAGE_MTP=y
-CONFIG_SCSI=y
-CONFIG_USB_SMARTCARD=y
-CONFIG_USB_AUDIO=y
-CONFIG_USB_SERIAL=y
-CONFIG_USB_NETWORK=y
-CONFIG_USB_BLUETOOTH=y
diff --git a/hw/usb/Kconfig b/hw/usb/Kconfig
index f23c542d27..0b8f41040e 100644
--- a/hw/usb/Kconfig
+++ b/hw/usb/Kconfig
@@ -5,59 +5,85 @@ config USB_UHCI
 bool
 default y
 depends on PCI
+select USB
 
 config USB_OHCI
 bool
 default y
 depends on

[Qemu-devel] [RFC PATCH v2 18/37] hw/display: make edid configurable

2019-01-15 Thread Yang Zhong
Use CONFIG_EDID to make edid-generate.c and edid-region.c
configurable.

Signed-off-by: Yang Zhong 
Reviewed-by: Thomas Huth 
---
 default-configs/pci.mak  | 1 +
 hw/display/Makefile.objs | 4 +---
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/default-configs/pci.mak b/default-configs/pci.mak
index 6c7be12779..171bdf48bc 100644
--- a/default-configs/pci.mak
+++ b/default-configs/pci.mak
@@ -47,3 +47,4 @@ CONFIG_VGA_PCI=y
 CONFIG_BOCHS_DISPLAY=y
 CONFIG_IVSHMEM_DEVICE=$(CONFIG_IVSHMEM)
 CONFIG_ROCKER=y
+CONFIG_EDID=y
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index 97acd5b6cb..a8e23c8501 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -1,4 +1,4 @@
-common-obj-y += edid-generate.o
+common-obj-$(CONFIG_EDID) += edid-generate.o edid-region.o
 
 common-obj-$(CONFIG_FW_CFG_DMA) += ramfb.o
 common-obj-$(CONFIG_FW_CFG_DMA) += ramfb-standalone.o
@@ -15,12 +15,10 @@ common-obj-$(CONFIG_SSD0323) += ssd0323.o
 common-obj-$(CONFIG_XEN) += xenfb.o
 
 common-obj-$(CONFIG_VGA_PCI) += vga-pci.o
-common-obj-$(CONFIG_VGA_PCI) += edid-region.o
 common-obj-$(CONFIG_VGA_ISA) += vga-isa.o
 common-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
 common-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
 common-obj-$(CONFIG_BOCHS_DISPLAY) += bochs-display.o
-common-obj-$(CONFIG_BOCHS_DISPLAY) += edid-region.o
 
 common-obj-$(CONFIG_BLIZZARD) += blizzard.o
 common-obj-$(CONFIG_EXYNOS4) += exynos4210_fimd.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 11/37] hw/xtensa/Makefile.objs: Build xtensa_sim and xtensa_fpga conditionally

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

Add the new CONFIG_* values to default-config/xtensa*-softmmu.mak.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
---
 default-configs/xtensa-softmmu.mak   | 3 +++
 default-configs/xtensaeb-softmmu.mak | 3 +++
 hw/xtensa/Makefile.objs  | 4 ++--
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/default-configs/xtensa-softmmu.mak 
b/default-configs/xtensa-softmmu.mak
index 9d8899cde7..baf90ca162 100644
--- a/default-configs/xtensa-softmmu.mak
+++ b/default-configs/xtensa-softmmu.mak
@@ -3,3 +3,6 @@
 CONFIG_SERIAL=y
 CONFIG_OPENCORES_ETH=y
 CONFIG_PFLASH_CFI01=y
+
+CONFIG_XTENSA_SIM=y
+CONFIG_XTENSA_FPGA=y
diff --git a/default-configs/xtensaeb-softmmu.mak 
b/default-configs/xtensaeb-softmmu.mak
index 9d8899cde7..baf90ca162 100644
--- a/default-configs/xtensaeb-softmmu.mak
+++ b/default-configs/xtensaeb-softmmu.mak
@@ -3,3 +3,6 @@
 CONFIG_SERIAL=y
 CONFIG_OPENCORES_ETH=y
 CONFIG_PFLASH_CFI01=y
+
+CONFIG_XTENSA_SIM=y
+CONFIG_XTENSA_FPGA=y
diff --git a/hw/xtensa/Makefile.objs b/hw/xtensa/Makefile.objs
index cb4998d2bf..62e244fa53 100644
--- a/hw/xtensa/Makefile.objs
+++ b/hw/xtensa/Makefile.objs
@@ -1,4 +1,4 @@
 obj-y += pic_cpu.o
-obj-y += sim.o
 obj-y += xtensa_memory.o
-obj-y += xtfpga.o
+obj-$(CONFIG_XTENSA_SIM) += sim.o
+obj-$(CONFIG_XTENSA_FPGA) += xtfpga.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 08/37] hw/sh4/Makefile.objs: New CONFIG_* varibales created for sh4 boards and device

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

Make hw/sh4 configurable and add new CONFIG_* to the 
default-configs/sh4*-softmmu.mak.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
---
 default-configs/sh4-softmmu.mak   | 3 +++
 default-configs/sh4eb-softmmu.mak | 3 +++
 hw/sh4/Makefile.objs  | 6 +++---
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/default-configs/sh4-softmmu.mak b/default-configs/sh4-softmmu.mak
index caeccd55be..4b65489624 100644
--- a/default-configs/sh4-softmmu.mak
+++ b/default-configs/sh4-softmmu.mak
@@ -19,3 +19,6 @@ CONFIG_PCSPK=y
 CONFIG_I82374=y
 CONFIG_I8257=y
 CONFIG_MC146818RTC=y
+CONFIG_R2D=y
+CONFIG_SHIX=y
+CONFIG_SH7750=y
diff --git a/default-configs/sh4eb-softmmu.mak 
b/default-configs/sh4eb-softmmu.mak
index 53b9cd7b5a..af71aa7f42 100644
--- a/default-configs/sh4eb-softmmu.mak
+++ b/default-configs/sh4eb-softmmu.mak
@@ -19,3 +19,6 @@ CONFIG_PCSPK=y
 CONFIG_I82374=y
 CONFIG_I8257=y
 CONFIG_MC146818RTC=y
+CONFIG_R2D=y
+CONFIG_SHIX=y
+CONFIG_SH7750=y
diff --git a/hw/sh4/Makefile.objs b/hw/sh4/Makefile.objs
index 2393702c57..70903d79a9 100644
--- a/hw/sh4/Makefile.objs
+++ b/hw/sh4/Makefile.objs
@@ -1,4 +1,4 @@
-obj-y += shix.o r2d.o
-
-obj-y += sh7750.o sh7750_regnames.o
+obj-$(CONFIG_R2D) +=  r2d.o
+obj-$(CONFIG_SHIX) += shix.o
+obj-$(CONFIG_SH7750) += sh7750.o sh7750_regnames.o
 obj-y += sh_pci.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 26/37] scsi: express dependencies with Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

This lets you disable SCSI altogether with "CONFIG_SCSI=n".

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 hw/scsi/Kconfig   | 12 
 hw/scsi/Makefile.objs |  2 +-
 hw/usb/Kconfig|  2 ++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/hw/scsi/Kconfig b/hw/scsi/Kconfig
index 812a12522b..7a9d373382 100644
--- a/hw/scsi/Kconfig
+++ b/hw/scsi/Kconfig
@@ -5,24 +5,29 @@ config LSI_SCSI_PCI
 bool
 default y
 depends on PCI
+select SCSI
 
 config MPTSAS_SCSI_PCI
 bool
 default y
 depends on PCI
+select SCSI
 
 config MEGASAS_SCSI_PCI
 bool
 default y
 depends on PCI
+select SCSI
 
 config VMW_PVSCSI_SCSI_PCI
 bool
 default y
 depends on PCI
+select SCSI
 
 config ESP
 bool
+select SCSI
 
 config ESP_PCI
 bool
@@ -30,8 +35,15 @@ config ESP_PCI
 depends on PCI
 select ESP
 
+config SPAPR_VSCSI
+bool
+depends on PSERIES
+select SCSI
+
 config VIRTIO_SCSI
 bool
+default y
+select SCSI
 
 config VHOST_USER_SCSI
 bool
diff --git a/hw/scsi/Makefile.objs b/hw/scsi/Makefile.objs
index 45167baeaf..54b36ed8b1 100644
--- a/hw/scsi/Makefile.objs
+++ b/hw/scsi/Makefile.objs
@@ -6,7 +6,7 @@ common-obj-$(CONFIG_MEGASAS_SCSI_PCI) += megasas.o
 common-obj-$(CONFIG_VMW_PVSCSI_SCSI_PCI) += vmw_pvscsi.o
 common-obj-$(CONFIG_ESP) += esp.o
 common-obj-$(CONFIG_ESP_PCI) += esp-pci.o
-obj-$(CONFIG_PSERIES) += spapr_vscsi.o
+obj-$(CONFIG_SPAPR_VSCSI) += spapr_vscsi.o
 
 ifeq ($(CONFIG_VIRTIO_SCSI),y)
 obj-y += virtio-scsi.o virtio-scsi-dataplane.o
diff --git a/hw/usb/Kconfig b/hw/usb/Kconfig
index 0b8f41040e..db46c56cc8 100644
--- a/hw/usb/Kconfig
+++ b/hw/usb/Kconfig
@@ -52,11 +52,13 @@ config USB_STORAGE_BOT
 bool
 default y
 depends on USB
+select SCSI
 
 config USB_STORAGE_UAS
 bool
 default y
 depends on USB
+select SCSI
 
 config USB_AUDIO
 bool
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 13/37] hw/riscv/Makefile.objs: Create CONFIG_* for riscv boards

2019-01-15 Thread Yang Zhong
Add the new configs to default-configs/riscv*-sofmmu.mak.

Signed-off-by: Yang Zhong 
---
 default-configs/riscv32-softmmu.mak |  6 ++
 default-configs/riscv64-softmmu.mak |  6 ++
 hw/riscv/Makefile.objs  | 22 +++---
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/default-configs/riscv32-softmmu.mak 
b/default-configs/riscv32-softmmu.mak
index dbc9398284..af841839d1 100644
--- a/default-configs/riscv32-softmmu.mak
+++ b/default-configs/riscv32-softmmu.mak
@@ -11,3 +11,9 @@ CONFIG_PCI_GENERIC=y
 
 CONFIG_VGA=y
 CONFIG_VGA_PCI=y
+
+CONFIG_HTIF=y
+CONFIG_HART=y
+CONFIG_SIFIVE=y
+CONFIG_SPIKE=y
+CONFIG_RISCV_VIRTIO=y
diff --git a/default-configs/riscv64-softmmu.mak 
b/default-configs/riscv64-softmmu.mak
index dbc9398284..af841839d1 100644
--- a/default-configs/riscv64-softmmu.mak
+++ b/default-configs/riscv64-softmmu.mak
@@ -11,3 +11,9 @@ CONFIG_PCI_GENERIC=y
 
 CONFIG_VGA=y
 CONFIG_VGA_PCI=y
+
+CONFIG_HTIF=y
+CONFIG_HART=y
+CONFIG_SIFIVE=y
+CONFIG_SPIKE=y
+CONFIG_RISCV_VIRTIO=y
diff --git a/hw/riscv/Makefile.objs b/hw/riscv/Makefile.objs
index 1dde01d39d..dde1b01f90 100644
--- a/hw/riscv/Makefile.objs
+++ b/hw/riscv/Makefile.objs
@@ -1,11 +1,11 @@
-obj-y += riscv_htif.o
-obj-y += riscv_hart.o
-obj-y += sifive_e.o
-obj-y += sifive_clint.o
-obj-y += sifive_prci.o
-obj-y += sifive_plic.o
-obj-y += sifive_test.o
-obj-y += sifive_u.o
-obj-y += sifive_uart.o
-obj-y += spike.o
-obj-y += virt.o
+obj-$(CONFIG_HTIF) += riscv_htif.o
+obj-$(CONFIG_HART) += riscv_hart.o
+obj-$(CONFIG_SIFIVE) += sifive_e.o
+obj-$(CONFIG_SIFIVE) += sifive_clint.o
+obj-$(CONFIG_SIFIVE) += sifive_prci.o
+obj-$(CONFIG_SIFIVE) += sifive_plic.o
+obj-$(CONFIG_SIFIVE) += sifive_test.o
+obj-$(CONFIG_SIFIVE) += sifive_u.o
+obj-$(CONFIG_SIFIVE) += sifive_uart.o
+obj-$(CONFIG_SPIKE) += spike.o
+obj-$(CONFIG_RISCV_VIRTIO) += virt.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 09/37] hw/sparc/Makefile.objs: CONFIG_* for sun4m and leon3 created

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

CONFIG_LEON3 added to default-configs/sparc-softmmu.mak.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
---
 default-configs/sparc-softmmu.mak | 2 ++
 hw/sparc/Makefile.objs| 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/default-configs/sparc-softmmu.mak 
b/default-configs/sparc-softmmu.mak
index 12f97eeb20..59a4a3d693 100644
--- a/default-configs/sparc-softmmu.mak
+++ b/default-configs/sparc-softmmu.mak
@@ -18,4 +18,6 @@ CONFIG_CS4231=y
 CONFIG_GRLIB=y
 CONFIG_STP2000=y
 CONFIG_ECCMEMCTL=y
+
 CONFIG_SUN4M=y
+CONFIG_LEON3=y
diff --git a/hw/sparc/Makefile.objs b/hw/sparc/Makefile.objs
index e2d0828c39..d57e33f83e 100644
--- a/hw/sparc/Makefile.objs
+++ b/hw/sparc/Makefile.objs
@@ -1 +1,3 @@
-obj-y += sun4m_iommu.o sun4m.o leon3.o
+obj-$(CONFIG_SUN4M) += sun4m_iommu.o
+obj-$(CONFIG_SUN4M) += sun4m.o
+obj-$(CONFIG_LEON3) += leon3.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 06/37] hw/mips/Makefile.objs: Create CONFIG_* for r4k, malta, mipssim boards

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

Add the new configs to default-configs/mips*-sofmmu.mak.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 default-configs/mips-softmmu-common.mak | 4 
 default-configs/mips64el-softmmu.mak| 1 -
 hw/mips/Makefile.objs   | 6 --
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/default-configs/mips-softmmu-common.mak 
b/default-configs/mips-softmmu-common.mak
index fae2347ee7..77b40ec7d1 100644
--- a/default-configs/mips-softmmu-common.mak
+++ b/default-configs/mips-softmmu-common.mak
@@ -36,3 +36,7 @@ CONFIG_EMPTY_SLOT=y
 CONFIG_MIPS_CPS=y
 CONFIG_MIPS_ITU=y
 CONFIG_I2C=y
+CONFIG_R4K=y
+CONFIG_MALTA=y
+CONFIG_MIPSSIM=y
+CONFIG_VT82C686=y
diff --git a/default-configs/mips64el-softmmu.mak 
b/default-configs/mips64el-softmmu.mak
index c2ae313f47..8244efb39c 100644
--- a/default-configs/mips64el-softmmu.mak
+++ b/default-configs/mips64el-softmmu.mak
@@ -9,7 +9,6 @@ CONFIG_FULONG=y
 CONFIG_JAZZ=y
 CONFIG_G364FB=y
 CONFIG_JAZZ_LED=y
-CONFIG_VT82C686=y
 CONFIG_MIPS_BOSTON=y
 CONFIG_FITLOADER=y
 CONFIG_PCI_XILINX=y
diff --git a/hw/mips/Makefile.objs b/hw/mips/Makefile.objs
index 17a311aaba..230866ae91 100644
--- a/hw/mips/Makefile.objs
+++ b/hw/mips/Makefile.objs
@@ -1,7 +1,9 @@
-obj-y += mips_r4k.o mips_malta.o mips_mipssim.o
 obj-y += addr.o mips_int.o
+obj-y += gt64xxx_pci.o
+obj-$(CONFIG_R4K) += mips_r4k.o
+obj-$(CONFIG_MALTA) += mips_malta.o
+obj-$(CONFIG_MIPSSIM) += mips_mipssim.o
 obj-$(CONFIG_JAZZ) += mips_jazz.o
 obj-$(CONFIG_FULONG) += mips_fulong2e.o
-obj-y += gt64xxx_pci.o
 obj-$(CONFIG_MIPS_CPS) += cps.o
 obj-$(CONFIG_MIPS_BOSTON) += boston.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 20/37] build: switch to Kconfig

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

The make_device_config.sh script is replaced by minikconf, which
is modified to support the same command line as its predecessor.

The roots of the parsing are default-configs/*.mak, Kconfig.host and
hw/Kconfig.  One difference with make_device_config.sh is that all symbols
have to be defined in a Kconfig file, including those coming from the
configure script.  This is the reason for the Kconfig.host file introduced
in the previous patch. Whenever a file in default-configs/*.mak used
$(...) to refer to a config-host.mak symbol, this is replaced by a
Kconfig dependency.

Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 Kconfig.host |  3 ++-
 Makefile | 14 +++--
 Makefile.target  |  7 ++-
 default-configs/i386-softmmu.mak |  3 ---
 hw/display/Kconfig   |  2 ++
 hw/i386/Kconfig  |  6 ++
 hw/intc/Kconfig  |  8 
 hw/misc/Kconfig  |  2 ++
 hw/tpm/Kconfig   |  1 +
 rules.mak|  2 +-
 scripts/make_device_config.sh| 30 ---
 scripts/minikconf.py | 35 +---
 12 files changed, 72 insertions(+), 41 deletions(-)
 delete mode 100644 scripts/make_device_config.sh

diff --git a/Kconfig.host b/Kconfig.host
index 2136a4c3ec..d7f503d0ca 100644
--- a/Kconfig.host
+++ b/Kconfig.host
@@ -1,5 +1,6 @@
 # These are "proxy" symbols used to pass config-host.mak values
-# down to Kconfig.
+# down to Kconfig.  See also MINIKCONF_ARGS in the Makefile:
+# these two need to be kept in sync.
 
 config KVM
 bool
diff --git a/Makefile b/Makefile
index a9ac16d94e..01e7c60a0d 100644
--- a/Makefile
+++ b/Makefile
@@ -326,9 +326,19 @@ endif
 
 -include $(SUBDIR_DEVICES_MAK_DEP)
 
-%/config-devices.mak: default-configs/%.mak 
$(SRC_PATH)/scripts/make_device_config.sh
+# This has to be kept in sync with Kconfig.host.
+MINIKCONF_ARGS = \
+CONFIG_KVM=$(CONFIG_KVM) \
+CONFIG_SPICE=$(CONFIG_SPICE) \
+CONFIG_TPM=$(CONFIG_TPM) \
+CONFIG_XEN=$(CONFIG_XEN) \
+CONFIG_OPENGL=$(CONFIG_OPENGL)
+
+MINIKCONF = $(SHELL) $(SRC_PATH)/scripts/minikconf.sh
+
+%/config-devices.mak: default-configs/%-softmmu.mak Kconfig.host hw/Kconfig
$(call quiet-command, \
-$(SHELL) $(SRC_PATH)/scripts/make_device_config.sh $< 
$*-config-devices.mak.d $@ > $@.tmp,"GEN","$@.tmp")
+$(MINIKCONF) $@ $*-config-devices.mak.d $^ $(MINIKCONF_ARGS) > 
$@.tmp, "  GEN   $@.tmp")
$(call quiet-command, if test -f $@; then \
  if cmp -s $@.old $@; then \
mv $@.tmp $@; \
diff --git a/Makefile.target b/Makefile.target
index 44ec4b630c..5aa8596a96 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -4,9 +4,12 @@ BUILD_DIR?=$(CURDIR)/..
 
 include ../config-host.mak
 include config-target.mak
-include config-devices.mak
 include $(SRC_PATH)/rules.mak
 
+ifdef CONFIG_SOFTMMU
+include config-devices.mak
+endif
+
 $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
 ifdef CONFIG_LINUX
 QEMU_CFLAGS += -I../linux-headers
@@ -187,7 +190,9 @@ all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
 
+ifdef CONFIG_SOFTMMU
 $(QEMU_PROG_BUILD): config-devices.mak
+endif
 
 COMMON_LDADDS = ../libqemuutil.a
 
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 8db7867015..f71284516c 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -4,7 +4,6 @@ include pci.mak
 include sound.mak
 include usb.mak
 include hyperv.mak
-CONFIG_QXL=$(CONFIG_SPICE)
 CONFIG_VGA_ISA=y
 CONFIG_VGA_CIRRUS=y
 CONFIG_VMWARE_VGA=y
@@ -37,8 +36,6 @@ CONFIG_HPET=y
 CONFIG_APPLESMC=y
 CONFIG_I8259=y
 CONFIG_PFLASH_CFI01=y
-CONFIG_TPM_TIS=$(CONFIG_TPM)
-CONFIG_TPM_CRB=$(CONFIG_TPM)
 CONFIG_MC146818RTC=y
 CONFIG_PCI_PIIX=y
 CONFIG_WDT_IB700=y
diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index d5c022c886..132aeffdbe 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -51,6 +51,7 @@ config FRAMEBUFFER
 
 config MILKYMIST_TMU2
 bool
+depends on OPENGL
 
 config SM501
 bool
@@ -66,6 +67,7 @@ config VGA
 
 config QXL
 bool
+depends on SPICE
 
 config VIRTIO_GPU
 bool
diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig
index 2dbe2b5d3e..427bda3717 100644
--- a/hw/i386/Kconfig
+++ b/hw/i386/Kconfig
@@ -3,12 +3,18 @@ config KVM
 
 config I440FX
 bool
+select QXL if SPICE
+select TPM_TIS if TPM
+select XEN_I386 if XEN
 
 config ISAPC
 bool
 
 config Q35
 bool
+select QXL if SPICE
+select TPM_TIS if TPM
+select XEN_I386 if XEN
 
 config VTD
 bool
diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig
index 69adbd135f..226ef3ae2e 100644
--- a/hw/intc/Kconfig
+++ b/hw/intc/Kconfig
@@ -21,9 +21,13 @@ config APIC
 
 config ARM_GIC_KVM
 bool
+default y
+depends on ARM_GIC &

[Qemu-devel] [RFC PATCH v2 12/37] hw/nios2/Makefile.objs: Conditionally build nios2

2019-01-15 Thread Yang Zhong
CONFIG_NIOS2_10M50_BOARD added for 10m50 dev board.

Signed-off-by: Yang Zhong 
---
 default-configs/nios2-softmmu.mak | 1 +
 hw/nios2/Makefile.objs| 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/default-configs/nios2-softmmu.mak 
b/default-configs/nios2-softmmu.mak
index 74dc70caae..f634c36d36 100644
--- a/default-configs/nios2-softmmu.mak
+++ b/default-configs/nios2-softmmu.mak
@@ -4,3 +4,4 @@ CONFIG_NIOS2=y
 CONFIG_SERIAL=y
 CONFIG_PTIMER=y
 CONFIG_ALTERA_TIMER=y
+CONFIG_NIOS2_10M50_BOARD=y
diff --git a/hw/nios2/Makefile.objs b/hw/nios2/Makefile.objs
index 6b5c421760..12a2891395 100644
--- a/hw/nios2/Makefile.objs
+++ b/hw/nios2/Makefile.objs
@@ -1 +1,2 @@
-obj-y = boot.o cpu_pic.o 10m50_devboard.o
+obj-y = boot.o cpu_pic.o
+obj-$(CONFIG_NIOS2_10M50_BOARD) += 10m50_devboard.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 00/37] Support Kconfig in QEMU

2019-01-15 Thread Yang Zhong
This Kconfig implementation is rebased from Paolo's branch
https://github.com/bonzini/qemu/commits/kconfig

I rebased most of patches except other ARCHs board definitions
this time.
https://github.com/yangzhon/qemu/commits/topic/upstream/Kconfig

The current RFC patches only support
(*) x86_64 platform build
Once design is fixed, we can do other archs.

(*) defconfig
"randconfig" build has some issues, which are mostly related
with CONFIG* in Kconfig.host abd configure. In randconfig mode,
some CONFIG* has different setting value in config-host.mak and
%/config-device.mak, which make QEMU build failure.

(*) Kconfig in hw/ directory

The current configure and build command are same with previous
commands and if we want to disable or enable some features, like
"tcg", we still need add "--enable/--disable-tcg" in configure
command line. If we want to disable one emulation device, we can
disable this in related Kconfig file in hw/ directory.

The current build command:
(*) ./configure --target-list=x86_64-softmmu
(*) make -j8

Since the Kconfig language replace traditional CONFIG_* in
default-config/%-softmmu.mak, the %-softmmu.mak file only
define embeded boards or machines, like 440fx and Q35 in x86_64
platform. The Kconfig has already defined dependency topology
between different Kconfig files, but there are still some issues

(*) Kconfig for configure(config-host.mak)
Some CONFIG* in configure  need some logic to generate, those
are hard to input this CONFIG* in Kconfig.host or Kconfig* file.

(*) Kconfig for %config-target.mak
The CONFIG* in %/config-target.mak file, this is still related
with configure.

(*) randconfig support issue.

Before this RFC patches, we have talked Kconfig in another thread
http://lists.nongnu.org/archive/html/qemu-devel/2018-09/msg02827.html

Please give your comments on this RFC thread, many thanks!

Changes in v2:
patch 1:added "CONFIG_PAM=y" in default-configs/i386-softmmu.mak
(Thomas Huth)
patch 3~14: added support for other ARCHs configurable(Paolo)
patch 15:   changed the annotate (Paolo)
patch 16:   changed the python code (Paolo)
patch 19:   added other ARCHs Kconfig files(Paolo)
patch 21:   added "select IDE_PCI" for CMD646, PIIX, VIA and SII3112(Thomas 
Huth)
patch 22:   added new patch for PCIE configurable.
patch 23:   moved "select IDE_PCI" from  CMD646, PIIX, VIA to 21 patch(Thomas 
Huth)
added "select CAN_BUS" for net/Kconfig (Thomas Huth)
added "depends on PCI" for CAN_SJA1000 (Paolo)
removed CONFIG_PCIE=y and add dependency for pcie(Paolo)
patch 26:   added "depends on PSERIES" for "config SPAPR_VSCSI" (Thomas Huth)
USB_STORAGE_BOT and USB_STORAGE_UAS must also "select SCSI"(Paolo)
patch 28:   added "select SERIAL" into "config SERIAL_PCI" (Thomas Huth)
removed "depend on ISA_BUS" from "config VGA_CIRRUS"(Thomas Huth)
patch 30:   "config XLNX_ZYNQMP_ARM" is defined in hw/arm/Kconfig(Thomas Huth)
CONFIG_AUX should select I2C(Paolo)
patch 33:   depends on HYPERV for HYPERV_TESTDEV(Thomas Huth)
removed "select HYPERV" and "select HYPERV_TESTDEV" with
"default y if PC" in "config HYPERV" and "config 
HYPERV_TESTDEV"(Paolo)
patch 34:   deleted default-configs/virtio.mak(Thomas Huth)
removed "y" in "config VIRTIO_MMIO"(Thomas Huth)
patch 35:   removed remaining CONFIG_* and removed "select " from 
hw/i386/Kconfig
to other Kconfigs(Paolo)

Paolo Bonzini (18):
  build: actually use CONFIG_PAM
  hw/i386/Makefile.objs: Build pc_piix* and pc_q35 boards
  minikconfig: add parser skeleton
  minikconfig: add AST
  minikconfig: add semantic analysis
  kconfig: introduce kconfig files
  build: switch to Kconfig
  ide: express dependencies with Kconfig
  build: convert pci.mak to Kconfig
  build: convert sound.mak to Kconfig
  build: convert usb.mak to Kconfig
  scsi: express dependencies with Kconfig
  bluetooth: express dependencies with Kconfig
  isa: express dependencies with kconfig
  i386: express dependencies with Kconfig
  i2c: express dependencies with Kconfig
  ptimer: express dependencies with Kconfig
  minikconf: implement allyesconfig, allnoconfig, randconfig, defconfig

Yang Zhong (11):
  hw/arm/Makefile.objs: CONFIG_VIRT created for virt board
  hw/nios2/Makefile.objs: Conditionally build nios2
  hw/riscv/Makefile.objs: Create CONFIG_* for riscv boards
  hw/sparc64/Makefile.objs: Create CONFIG_* for sparc64
  hw/display: make edid configurable
  hw/pci/Makefile.objs: make pcie configurable
  edid: express dependencies with kconfig
  hyperv: express dependencies with kconfig
  virtio: make virtio dependencies with Kconfig
  i386-softmmu.mak: remove all CONFIG_* except boards definitions
  Makefile: only support defconfig

Ákos Kovács (8):
  hw/m68k/Makefile.objs: Conditionally build boards
  hw/microblaze/Makefile.objs: Create configs for petalogix and xilinx
boards
  hw/mips/Makefile.o

Re: [Qemu-devel] [PULL 0/5] gitdm updates with final 2018 stats

2019-01-15 Thread Peter Maydell
On Mon, 14 Jan 2019 at 16:09, Alex Bennée  wrote:
>
> The following changes since commit 7260438b7056469610ee166f7abe9ff8a26b8b16:
>
>   Merge remote-tracking branch 
> 'remotes/palmer/tags/riscv-for-master-3.2-part2' into staging (2019-01-14 
> 11:41:43 +)
>
> are available in the Git repository at:
>
>   https://github.com/stsquad/qemu.git tags/pull-misc-gitdm-next-140119-1
>
> for you to fetch changes up to 92329a7e70bc9755fd7114b8f91f95ed0b97648f:
>
>   MAINTAINERS: add myself as a route for gitdm updates (2019-01-14 16:06:57 
> +)
>
> 
> gitdm updates with 2018 year end stats:
>
>   git log --numstat --after="1/1/2018 00:00" --before="31/12/2018 23:59" | 
> ~/src/gitdm.git/gitdm -n -l 10
>
>   Top changeset contributors by employer
>   Red Hat   3091 (43.3%)
>   Linaro1201 (16.8%)
>   (None) 484 (6.8%)
>   IBM426 (6.0%)
>   Academics (various)186 (2.6%)
>   Virtuozzo  172 (2.4%)
>   Wave Computing 118 (1.7%)
>   Igalia 109 (1.5%)
>   Xilinx 102 (1.4%)
>   Cadence Design Systems  80 (1.1%)
>
>   Top lines changed by employer
>   Red Hat   140523 (30.3%)
>   Cadence Design Systems81010 (17.5%)
>   Linaro78098 (16.8%)
>   Wave Computing33134 (7.1%)
>   IBM   18918 (4.1%)
>   SiFive14436 (3.1%)
>   Academics (various)   11995 (2.6%)
>   (None)11458 (2.5%)
>   Virtuozzo 10770 (2.3%)
>   Oracle6698 (1.4%)

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.

-- PMM



[Qemu-devel] [RFC PATCH v2 01/37] build: actually use CONFIG_PAM

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

Do not link it unconditionally into all binaries.

Signed-off-by: Paolo Bonzini 
---
 default-configs/i386-softmmu.mak | 1 +
 hw/pci-host/Makefile.objs| 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 64c998c4c8..4711155a33 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -67,3 +67,4 @@ CONFIG_I2C=y
 CONFIG_SEV=$(CONFIG_KVM)
 CONFIG_VTD=y
 CONFIG_AMD_IOMMU=y
+CONFIG_PAM=y
diff --git a/hw/pci-host/Makefile.objs b/hw/pci-host/Makefile.objs
index 6d6597c065..9d7e7cd1b8 100644
--- a/hw/pci-host/Makefile.objs
+++ b/hw/pci-host/Makefile.objs
@@ -1,4 +1,4 @@
-common-obj-y += pam.o
+common-obj-$(CONFIG_PAM) += pam.o
 
 # PPC devices
 common-obj-$(CONFIG_PREP_PCI) += prep.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 07/37] hw/ppc/Makefile.objs: Build all boards conditinally with CONFIG_*

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

CONFIG_PPC405, CONFIG_PPC440, CONFIG_MAC_OLDWORLD, CONFIG_MAX_NEWWORLD
and CONFIG_VIRTEX configuration options created for
default-configs/ppc*-softmmu.mak.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
Signed-off-by: Yang Zhong 
---
 default-configs/ppc-softmmu.mak |  7 ++-
 hw/ppc/Makefile.objs| 12 ++--
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/default-configs/ppc-softmmu.mak b/default-configs/ppc-softmmu.mak
index 23d871fb3e..96088f47ca 100644
--- a/default-configs/ppc-softmmu.mak
+++ b/default-configs/ppc-softmmu.mak
@@ -34,7 +34,6 @@ CONFIG_M41T80=y
 CONFIG_VGA_CIRRUS=y
 
 # For Macs
-CONFIG_MAC=y
 CONFIG_ESCC=y
 CONFIG_MACIO=y
 CONFIG_MACIO_GPIO=y
@@ -69,3 +68,9 @@ CONFIG_PC87312=y
 CONFIG_PCSPK=y
 CONFIG_IDE_ISA=y
 CONFIG_CS4231A=y
+
+CONFIG_PPC405=y
+CONFIG_PPC440=y
+CONFIG_MAC_OLDWORLD=y
+CONFIG_MAC_NEWWORLD=y
+CONFIG_VIRTEX=
diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
index 4e0c1c0941..2ce7973219 100644
--- a/hw/ppc/Makefile.objs
+++ b/hw/ppc/Makefile.objs
@@ -13,20 +13,20 @@ obj-y += spapr_pci_vfio.o
 endif
 obj-$(CONFIG_PSERIES) += spapr_rtas_ddw.o
 # PowerPC 4xx boards
-obj-y += ppc4xx_devs.o ppc405_uc.o
-obj-$(CONFIG_PPC4XX) += ppc4xx_pci.o ppc405_boards.o
-obj-$(CONFIG_PPC4XX) += ppc440_bamboo.o ppc440_pcix.o ppc440_uc.o
+obj-$(CONFIG_PPC405) += ppc405_boards.o  ppc405_uc.o
+obj-$(CONFIG_PPC440) += ppc440_bamboo.o ppc440_pcix.o ppc440_uc.o
+obj-$(CONFIG_PPC4XX) += ppc4xx_pci.o ppc4xx_devs.o
 obj-$(CONFIG_SAM460EX) += sam460ex.o
 # PReP
 obj-$(CONFIG_PREP) += prep.o
 obj-$(CONFIG_PREP) += prep_systemio.o
 obj-${CONFIG_RS6000_MC} += rs6000_mc.o
 # OldWorld PowerMac
-obj-$(CONFIG_MAC) += mac_oldworld.o
+obj-$(CONFIG_MAC_OLDWORLD) += mac_oldworld.o
 # NewWorld PowerMac
-obj-$(CONFIG_MAC) += mac_newworld.o
+obj-$(CONFIG_MAC_NEWWORLD) += mac_newworld.o
 # e500
 obj-$(CONFIG_E500) += e500.o mpc8544ds.o e500plat.o
 obj-$(CONFIG_E500) += mpc8544_guts.o ppce500_spin.o
 # PowerPC 440 Xilinx ML507 reference board.
-obj-$(CONFIG_XILINX) += virtex_ml507.o
+obj-$(CONFIG_VIRTEX) += virtex_ml507.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 17/37] minikconfig: add semantic analysis

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

There are three parts in the semantic analysis:

1) evaluating expressions.  This is done as a simple visit
of the Expr nodes.

2) ordering clauses.  This is done by constructing a graph of variables.
There is an edge from X to Y if Y depends on X, if X selects Y, or if
X appears in a conditional selection of Y; in other words, if the value
of X can affect the value of Y.  Each clause has a "destination" variable
whose value can be affected by the clause, and clauses will be processed
according to a topological sorting of their destination variables.
Defaults are processed after all other clauses with the same destination.

3) deriving the value of the variables.  This is done by processing
the clauses in the topological order provided by the previous step.
A "depends on" clause will force a variable to False, a "select" clause
will force a variable to True, an assignment will force a variable
to its RHS.  A default will set a variable to its RHS if it has not
been set before.  Because all variables have a default, after visiting
all clauses all variables will have been set.

Signed-off-by: Paolo Bonzini 
---
 scripts/minikconf.py | 129 +--
 1 file changed, 124 insertions(+), 5 deletions(-)

diff --git a/scripts/minikconf.py b/scripts/minikconf.py
index a6a28c9c47..48800591e2 100644
--- a/scripts/minikconf.py
+++ b/scripts/minikconf.py
@@ -15,6 +15,10 @@ import sys
 
 __all__ = [ 'KconfigParserError', 'KconfigData', 'KconfigParser' ]
 
+def debug_print(*args):
+#print ' '.join(str(x) for x in args)
+pass
+
 # ---
 # KconfigData implements the Kconfig semantics.  For now it can only
 # detect undefined symbols, i.e. symbols that were referenced in
@@ -34,6 +38,12 @@ class KconfigData:
 def __invert__(self):
 return KconfigData.NOT(self)
 
+# Abstract methods
+def add_edges_to(self, var):
+pass
+def evaluate(self):
+assert False
+
 class AND(Expr):
 def __init__(self, lhs, rhs):
 self.lhs = lhs
@@ -41,6 +51,12 @@ class KconfigData:
 def __str__(self):
 return "(%s && %s)" % (self.lhs, self.rhs)
 
+def add_edges_to(self, var):
+self.lhs.add_edges_to(var)
+self.rhs.add_edges_to(var)
+def evaluate(self):
+return self.lhs.evaluate() and self.rhs.evaluate()
+
 class OR(Expr):
 def __init__(self, lhs, rhs):
 self.lhs = lhs
@@ -48,22 +64,62 @@ class KconfigData:
 def __str__(self):
 return "(%s || %s)" % (self.lhs, self.rhs)
 
+def add_edges_to(self, var):
+self.lhs.add_edges_to(var)
+self.rhs.add_edges_to(var)
+def evaluate(self):
+return self.lhs.evaluate() or self.rhs.evaluate()
+
 class NOT(Expr):
 def __init__(self, lhs):
 self.lhs = lhs
 def __str__(self):
 return "!%s" % (self.lhs)
 
+def add_edges_to(self, var):
+self.lhs.add_edges_to(var)
+def evaluate(self):
+return not self.lhs.evaluate()
+
 class Var(Expr):
 def __init__(self, name):
 self.name = name
 self.value = None
+self.outgoing = set()
 def __str__(self):
 return self.name
 
+def has_value(self):
+return not (self.value is None)
+def set_value(self, val):
+if self.has_value() and self.value != val:
+raise Exception('contradiction between clauses when setting 
%s' % self)
+debug_print("=> %s is now %s" % (self.name, val))
+self.value = val
+
+# depth first search of the dependency graph
+def dfs(self, visited, f):
+if self in visited:
+return
+visited.add(self)
+for v in self.outgoing:
+v.dfs(visited, f)
+f(self)
+
+def add_edges_to(self, var):
+self.outgoing.add(var)
+def evaluate(self):
+if not self.has_value():
+raise Exception('cycle found including %s' % self)
+return self.value
+
 class Clause:
 def __init__(self, dest):
 self.dest = dest
+def priority(self):
+return 0
+def process(self):
+pass
 
 class AssignmentClause(Clause):
 def __init__(self, dest, value):
@@ -72,11 +128,16 @@ class KconfigData:
 def __str__(self):
 return "%s=%s" % (self.dest, 'y' if self.value else 'n')
 
+def process(self):
+self.dest.set_value(self.value)
+
 class DefaultClause(Clause):
 def __init__(self, dest, value, cond=None):
 KconfigData.Clause.__init__(self, dest)
 self.value = value
 self.cond = cond
+if not (self.cond is None):
+   

Re: [Qemu-devel] [PULL v2 00/27] ivshmem deprecation, qtests, typedefs and gnu99

2019-01-15 Thread Thomas Huth
On 2019-01-15 14:16, Peter Maydell wrote:
> On Mon, 14 Jan 2019 at 17:45, Thomas Huth  wrote:
>>
>>  Hi Peter!
>>
>> The following changes since commit 7260438b7056469610ee166f7abe9ff8a26b8b16:
>>
>>   Merge remote-tracking branch 
>> 'remotes/palmer/tags/riscv-for-master-3.2-part2' into staging (2019-01-14 
>> 11:41:43 +)
>>
>> are available in the git repository at:
>>
>>   https://gitlab.com/huth/qemu.git tags/pull-request-2019-01-14v2
>>
>> for you to fetch changes up to 650db715681ad1a042705484776e1974f288f3d4:
>>
>>   tests/hexloader-test: Don't pass -nographic to the QEMU under test 
>> (2019-01-14 18:21:29 +0100)
>>
>> 
>> - Remove deprecated "ivshmem" legacy device
>> - Bug fix for vhost-user-test
>> - Use more CONFIG Makefile switches for qtests
>> - Get rid of global_qtests in some more qtests
>> - typedef cleanups
>> - Fixes for compiling with Clang
>> - Force C standard to gnu99
>> 
> 
> Hi; another compile failure on that ppc64 system, I'm afraid:
> 
> /home/pm215/qemu/qemu-seccomp.c:45:1: error: initializer element is not 
> constant
>  };
>  ^
> /home/pm215/qemu/qemu-seccomp.c:45:1: error: (near initialization for
> ‘sched_setscheduler_arg[0]’)
> 
> (I did a quick check with 'make -k' and it looks like there aren't
> any more lurking after that one.)
> 
> The system libseccomp is libseccomp-2.3.1-3.el7.

Darn, I think this time it is a compiler bug:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63567

It's only fixed in GCC >= v5.0 :-(

I see two options:

1) Expand the macro manually:

diff --git a/qemu-seccomp.c b/qemu-seccomp.c
--- a/qemu-seccomp.c
+++ b/qemu-seccomp.c
@@ -41,7 +41,7 @@ struct QemuSeccompSyscall {
 };

 const struct scmp_arg_cmp sched_setscheduler_arg[] = {
-SCMP_A1(SCMP_CMP_NE, SCHED_IDLE)
+{ .arg = 1, .op = SCMP_CMP_NE, .datum_a = SCHED_IDLE }
 };

... then it compiles fine for me in gnu99 mode, too.

2) Scratch the whole idea with gnu99 again ...

Opinions?

 Thomas



[Qemu-devel] [RFC PATCH v2 05/37] hw/microblaze/Makefile.objs: Create configs for petalogix and xilinx boards

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

CONFIG_PETALOGIX_* and CONFIG_XLNX_*  configs added to
default-configs/microblaze-softmmu.mak and
default-configs/microblazeel-softmmu.mak.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
---
 default-configs/microblaze-softmmu.mak | 3 +++
 hw/microblaze/Makefile.objs| 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/default-configs/microblaze-softmmu.mak 
b/default-configs/microblaze-softmmu.mak
index 7fca8e4c99..14837cf74a 100644
--- a/default-configs/microblaze-softmmu.mak
+++ b/default-configs/microblaze-softmmu.mak
@@ -10,3 +10,6 @@ CONFIG_XILINX_ETHLITE=y
 CONFIG_SSI=y
 CONFIG_SSI_M25P80=y
 CONFIG_XLNX_ZYNQMP=y
+CONFIG_PETALOGIX_S3ADSP1800=y
+CONFIG_PETALOGIX_ML605=y
+CONFIG_XLNX_ZYNQMP_PMU=y
diff --git a/hw/microblaze/Makefile.objs b/hw/microblaze/Makefile.objs
index ae9fd40de7..8595a62f6c 100644
--- a/hw/microblaze/Makefile.objs
+++ b/hw/microblaze/Makefile.objs
@@ -1,4 +1,4 @@
-obj-y += petalogix_s3adsp1800_mmu.o
-obj-y += petalogix_ml605_mmu.o
-obj-y += xlnx-zynqmp-pmu.o
+obj-$(CONFIG_PETALOGIX_S3ADSP1800) += petalogix_s3adsp1800_mmu.o
+obj-$(CONFIG_PETALOGIX_ML605) += petalogix_ml605_mmu.o
+obj-$(CONFIG_XLNX_ZYNQMP_PMU) += xlnx-zynqmp-pmu.o
 obj-y += boot.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 15/37] minikconfig: add parser skeleton

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

This implements a scanner and recursive descent parser for Kconfig-like
configuration files.  The only "action" of the parser is for now to
detect undefined variables and process include files.

The main differences between Kconfig and this are:

* only the "bool" type is supported

* variables can only be defined once

* choices are not supported (but they could be added as syntactic
sugar for multiple Boolean values)

* menus and other graphical concepts (prompts, help text) are not
supported

* assignments ("CONFIG_FOO=y", "CONFIG_FOO=n") are parsed as part
of the Kconfig language, not as a separate file.

The idea was originally by Ákos Kovács, but I could not find his
implementation so I had to redo it.

Signed-off-by: Paolo Bonzini 
---
 scripts/minikconf.py | 423 +++
 1 file changed, 423 insertions(+)
 create mode 100644 scripts/minikconf.py

diff --git a/scripts/minikconf.py b/scripts/minikconf.py
new file mode 100644
index 00..fb39e35d6a
--- /dev/null
+++ b/scripts/minikconf.py
@@ -0,0 +1,423 @@
+#
+# Mini-Kconfig parser
+#
+# Copyright (c) 2015 Red Hat Inc.
+#
+# Authors:
+#  Paolo Bonzini 
+#
+# This work is licensed under the terms of the GNU GPL, version 2
+# or, at your option, any later version.  See the COPYING file in
+# the top-level directory.
+
+import os
+import sys
+
+__all__ = [ 'KconfigParserError', 'KconfigData', 'KconfigParser' ]
+
+# ---
+# KconfigData implements the Kconfig semantics.  For now it can only
+# detect undefined symbols, i.e. symbols that were referenced in
+# assignments or dependencies but were not declared with "config FOO".
+#
+# Semantic actions are represented by methods called do_*.  The do_var
+# method return the semantic value of a variable (which right now is
+# just its name).
+# ---
+
+class KconfigData:
+def __init__(self):
+self.previously_included = []
+self.incl_info = None
+self.defined_vars = set()
+self.referenced_vars = set()
+
+# semantic analysis -
+
+def check_undefined(self):
+undef = False
+for i in self.referenced_vars:
+if not (i in self.defined_vars):
+print "undefined symbol %s" % (i)
+undef = True
+return undef
+
+# semantic actions -
+
+def do_declaration(self, var):
+if (var in self.defined_vars):
+raise Exception('variable "' + var + '" defined twice')
+
+self.defined_vars.add(var)
+
+# var is a string with the variable's name.
+#
+# For now this just returns the variable's name itself.
+def do_var(self, var):
+self.referenced_vars.add(var)
+return var
+
+def do_assignment(self, var, val):
+pass
+
+def do_default(self, var, val, cond=None):
+pass
+
+def do_depends_on(self, var, expr):
+pass
+
+def do_select(self, var, symbol, cond=None):
+pass
+
+# ---
+# KconfigParser implements a recursive descent parser for (simplified)
+# Kconfig syntax.
+# ---
+
+# tokens table
+TOKENS = {}
+TOK_NONE = -1
+TOK_LPAREN = 0;   TOKENS[TOK_LPAREN] = '"("';
+TOK_RPAREN = 1;   TOKENS[TOK_RPAREN] = '")"';
+TOK_EQUAL = 2;TOKENS[TOK_EQUAL] = '"="';
+TOK_AND = 3;  TOKENS[TOK_AND] = '"&&"';
+TOK_OR = 4;   TOKENS[TOK_OR] = '"||"';
+TOK_NOT = 5;  TOKENS[TOK_NOT] = '"!"';
+TOK_DEPENDS = 6;  TOKENS[TOK_DEPENDS] = '"depends"';
+TOK_ON = 7;   TOKENS[TOK_ON] = '"on"';
+TOK_SELECT = 8;   TOKENS[TOK_SELECT] = '"select"';
+TOK_CONFIG = 9;   TOKENS[TOK_CONFIG] = '"config"';
+TOK_DEFAULT = 10; TOKENS[TOK_DEFAULT] = '"default"';
+TOK_Y = 11;   TOKENS[TOK_Y] = '"y"';
+TOK_N = 12;   TOKENS[TOK_N] = '"n"';
+TOK_SOURCE = 13;  TOKENS[TOK_SOURCE] = '"source"';
+TOK_BOOL = 14;TOKENS[TOK_BOOL] = '"bool"';
+TOK_IF = 15;  TOKENS[TOK_IF] = '"if"';
+TOK_ID = 16;  TOKENS[TOK_ID] = 'identifier';
+TOK_EOF = 17; TOKENS[TOK_EOF] = 'end of file';
+
+class KconfigParserError(Exception):
+def __init__(self, parser, msg, tok=None):
+self.loc = parser.location()
+tok = tok or parser.tok
+if tok != TOK_NONE:
+msg = '%s before %s' %(msg, TOKENS[tok])
+self.msg = msg
+
+def __str__(self):
+return "%s: %s" % (self.loc, self.msg)
+
+class KconfigParser:
+@classmethod
+def parse(self, fp):
+data = KconfigData()
+parser = KconfigParser(data)
+parser.parse_file(fp)
+if data.check_undefined():
+raise KconfigParserError(parser, "there were undefined symbols")
+
+return data
+
+def __init__(self, data):
+self.data = data
+
+def parse_file(self, fp):
+self.abs_fname = os.path.abspath(fp.name)
+self.fname = fp.name
+self.data.prev

Re: [Qemu-devel] [PATCH v1] virtio: add checks for the size of the indirect table

2019-01-15 Thread Stefan Hajnoczi
On Tue, Jan 15, 2019 at 01:08:47PM +0300, Dima Stepanov wrote:
> The virtqueue_pop() and virtqueue_get_avail_bytes() routines can use the
> INDIRECT table to get the data. It is possible to create a packet which
> will lead to the assert message like:
>   include/exec/memory.h:1995: void
>   address_space_read_cached(MemoryRegionCache *, hwaddr, void *, int):
>   Assertion `addr < cache->len && len <= cache->len - addr' failed.
>   Aborted
> To do it the first descriptor should have a link to the INDIRECT table
> and set the size of it to 0. It doesn't look good that the guest should
> be able to trigger the assert in qemu. Add additional check for the size
> of the INDIRECT table, which should not be 0.
> 
> Signed-off-by: Dima Stepanov 
> ---
>  hw/virtio/virtio.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [Qemu-devel] [Qemu-block] [PATCH] throttle-groups: fix restart coroutine iothread race

2019-01-15 Thread Alberto Garcia
On Tue 15 Jan 2019 03:18:00 PM CET, Stefan Hajnoczi wrote:
>> So if my understanding is correct QEMU can be shut down when there
>> are iothreads waiting for a mutex. Is that something that we should
>> be worried about?
>
> Nothing joins the iothreads in vl.c:main().
>
> The assumption is that anything using iothreads will detach from them.
> For example, the vm runstate changes during shutdown so devices can
> disable the iothread code path (and this involves draining in-flight
> requests).
>
> My fix effectively does this by waiting for in-flight throttling
> restart coroutines.

Yeah, it's clear in the case of your fix. Thanks!

Berto



[Qemu-devel] [RFC PATCH v2 10/37] hw/lm32/Makefile.objs: Conditionally build lm32 and milkmyst

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

CONFIG_LM32 and CONFIG_MILKYMIST added for lm32 and milkmyst build.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
---
 hw/lm32/Makefile.objs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/lm32/Makefile.objs b/hw/lm32/Makefile.objs
index ea6418ae59..c3941866c7 100644
--- a/hw/lm32/Makefile.objs
+++ b/hw/lm32/Makefile.objs
@@ -1,3 +1,3 @@
 # LM32 boards
-obj-y += lm32_boards.o
-obj-y += milkymist.o
+obj-$(CONFIG_LM32) += lm32_boards.o
+obj-$(CONFIG_MILKYMIST) += milkymist.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 03/37] hw/arm/Makefile.objs: CONFIG_VIRT created for virt board

2019-01-15 Thread Yang Zhong
make virt code configurable and the new CONFIG_VIRT definitions
added to the default-configs/arm-softmmu.mak to replace CONFIG_ACPI
in arm board.

Signed-off-by: Yang Zhong 
---
 default-configs/arm-softmmu.mak | 2 +-
 hw/arm/Makefile.objs| 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 2420491aac..3903d1ada3 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -147,7 +147,7 @@ CONFIG_PCIE_PORT=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
-CONFIG_ACPI=y
+CONFIG_VIRT=y
 CONFIG_SMBIOS=y
 CONFIG_ASPEED_SOC=y
 CONFIG_GPIO_KEY=y
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 50c7b4a927..25ff98fdbc 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -1,5 +1,5 @@
-obj-y += boot.o virt.o sysbus-fdt.o
-obj-$(CONFIG_ACPI) += virt-acpi-build.o
+obj-y += boot.o sysbus-fdt.o
+obj-$(CONFIG_VIRT) += virt.o virt-acpi-build.o
 obj-$(CONFIG_DIGIC) += digic_boards.o
 obj-$(CONFIG_EXYNOS4) += exynos4_boards.o
 obj-$(CONFIG_HIGHBANK) += highbank.o
-- 
2.17.1




[Qemu-devel] [PATCH 07/12] chardev: split tcp_chr_wait_connected into two methods

2019-01-15 Thread Daniel P . Berrangé
The tcp_chr_wait_connected method can deal with either server or client
chardevs, but some callers only care about one of these possibilities.
The tcp_chr_wait_connected method will also need some refactoring to
reliably deal with its primary goal of allowing a device frontend to
wait for an established connection, which will interfere with other
callers.

Split it into two methods, one responsible for server initiated
connections, the other responsible for client initiated connections.
In doing this split the tcp_char_connect_async() method is renamed
to become consistent with naming of the new methods.

Signed-off-by: Daniel P. Berrangé 
---
 chardev/char-socket.c | 59 +++
 1 file changed, 37 insertions(+), 22 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 3b6ff6619b..3bd1be7631 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -886,30 +886,47 @@ static void tcp_chr_accept(QIONetListener *listener,
 tcp_chr_new_client(chr, cioc);
 }
 
-static int tcp_chr_wait_connected(Chardev *chr, Error **errp)
+
+static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp)
+{
+SocketChardev *s = SOCKET_CHARDEV(chr);
+QIOChannelSocket *sioc = qio_channel_socket_new();
+tcp_chr_set_client_ioc_name(chr, sioc);
+if (qio_channel_socket_connect_sync(sioc, s->addr, errp) < 0) {
+object_unref(OBJECT(sioc));
+return -1;
+}
+tcp_chr_new_client(chr, sioc);
+object_unref(OBJECT(sioc));
+return 0;
+}
+
+
+static void tcp_chr_accept_server_sync(Chardev *chr)
 {
 SocketChardev *s = SOCKET_CHARDEV(chr);
 QIOChannelSocket *sioc;
+info_report("QEMU waiting for connection on: %s",
+chr->filename);
+sioc = qio_net_listener_wait_client(s->listener);
+tcp_chr_set_client_ioc_name(chr, sioc);
+tcp_chr_new_client(chr, sioc);
+object_unref(OBJECT(sioc));
+}
+
 
+static int tcp_chr_wait_connected(Chardev *chr, Error **errp)
+{
+SocketChardev *s = SOCKET_CHARDEV(chr);
 /* It can't wait on s->connected, since it is set asynchronously
  * in TLS and telnet cases, only wait for an accepted socket */
 while (!s->ioc) {
 if (s->is_listen) {
-info_report("QEMU waiting for connection on: %s",
-chr->filename);
-sioc = qio_net_listener_wait_client(s->listener);
-tcp_chr_set_client_ioc_name(chr, sioc);
-tcp_chr_new_client(chr, sioc);
-object_unref(OBJECT(sioc));
+tcp_chr_accept_server_sync(chr);
 } else {
-sioc = qio_channel_socket_new();
-tcp_chr_set_client_ioc_name(chr, sioc);
-if (qio_channel_socket_connect_sync(sioc, s->addr, errp) < 0) {
-object_unref(OBJECT(sioc));
+if (tcp_chr_connect_client_sync(chr, errp) < 0) {
 return -1;
 }
-tcp_chr_new_client(chr, sioc);
-object_unref(OBJECT(sioc));
 }
 }
 
@@ -958,7 +975,7 @@ cleanup:
 object_unref(OBJECT(sioc));
 }
 
-static void tcp_chr_connect_async(Chardev *chr)
+static void tcp_chr_connect_client_async(Chardev *chr)
 {
 SocketChardev *s = SOCKET_CHARDEV(chr);
 QIOChannelSocket *sioc;
@@ -982,7 +999,7 @@ static gboolean socket_reconnect_timeout(gpointer opaque)
 return false;
 }
 
-tcp_chr_connect_async(chr);
+tcp_chr_connect_client_async(chr);
 
 return false;
 }
@@ -1139,7 +1156,7 @@ static void qmp_chardev_open_socket(Chardev *chr,
 }
 
 if (s->reconnect_time) {
-tcp_chr_connect_async(chr);
+tcp_chr_connect_client_async(chr);
 } else {
 if (s->is_listen) {
 char *name;
@@ -1159,17 +1176,15 @@ static void qmp_chardev_open_socket(Chardev *chr,
 s->addr = socket_local_address(s->listener->sioc[0]->fd, errp);
 update_disconnected_filename(s);
 
-if (is_waitconnect &&
-qemu_chr_wait_connected(chr, errp) < 0) {
-return;
-}
-if (!s->ioc) {
+if (is_waitconnect) {
+tcp_chr_accept_server_sync(chr);
+} else {
 qio_net_listener_set_client_func_full(s->listener,
   tcp_chr_accept,
   chr, NULL,
   chr->gcontext);
 }
-} else if (qemu_chr_wait_connected(chr, errp) < 0) {
+} else if (tcp_chr_connect_client_sync(chr, errp) < 0) {
 return;
 }
 }
-- 
2.20.1




[Qemu-devel] [RFC PATCH v2 02/37] hw/i386/Makefile.objs: Build pc_piix* and pc_q35 boards

2019-01-15 Thread Yang Zhong
From: Paolo Bonzini 

CONFIG_PIIX and CONFIG_Q35 created for the pc board object files. These
are enabled automatically at default-configs/i386-softmmu.mak and
default-configs/x86_64-softmmu.mak

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
Reviewed-by: Thomas Huth 
---
 default-configs/i386-softmmu.mak | 2 ++
 hw/i386/Makefile.objs| 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 4711155a33..8db7867015 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -68,3 +68,5 @@ CONFIG_SEV=$(CONFIG_KVM)
 CONFIG_VTD=y
 CONFIG_AMD_IOMMU=y
 CONFIG_PAM=y
+CONFIG_I440FX=y
+CONFIG_Q35=y
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index fa87a14152..3de7ca2bb9 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -1,6 +1,8 @@
 obj-$(CONFIG_KVM) += kvm/
 obj-y += multiboot.o
-obj-y += pc.o pc_piix.o pc_q35.o
+obj-y += pc.o
+obj-$(CONFIG_I440FX) += pc_piix.o
+obj-$(CONFIG_Q35) += pc_q35.o
 obj-y += pc_sysfw.o
 obj-$(CONFIG_VTD) += x86-iommu.o intel_iommu.o
 obj-$(CONFIG_AMD_IOMMU) += x86-iommu.o amd_iommu.o
-- 
2.17.1




[Qemu-devel] [RFC PATCH v2 04/37] hw/m68k/Makefile.objs: Conditionally build boards

2019-01-15 Thread Yang Zhong
From: Ákos Kovács 

CONFIG_AN5206, CONFIG_MCF5206 and CONFIG_MCF5208 make
variables created for m68k boards, and added to
default-configs/m86k-softmmu.mak.

Signed-off-by: Ákos Kovács 
Signed-off-by: Paolo Bonzini 
---
 default-configs/m68k-softmmu.mak | 3 +++
 hw/m68k/Makefile.objs| 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/default-configs/m68k-softmmu.mak b/default-configs/m68k-softmmu.mak
index 60f7cdfbf2..a179da9077 100644
--- a/default-configs/m68k-softmmu.mak
+++ b/default-configs/m68k-softmmu.mak
@@ -2,3 +2,6 @@
 
 CONFIG_COLDFIRE=y
 CONFIG_PTIMER=y
+CONFIG_AN5206=y
+CONFIG_MCF5206=y
+CONFIG_MCF5208=y
diff --git a/hw/m68k/Makefile.objs b/hw/m68k/Makefile.objs
index d1f089c08a..fa287edd0b 100644
--- a/hw/m68k/Makefile.objs
+++ b/hw/m68k/Makefile.objs
@@ -1,2 +1,3 @@
-obj-y += an5206.o mcf5208.o
-obj-y += mcf5206.o mcf_intc.o
+obj-$(CONFIG_AN5206) += an5206.o
+obj-$(CONFIG_MCF5206) += mcf5206.o
+obj-$(CONFIG_MCF5208) += mcf5208.o mcf_intc.o
-- 
2.17.1




[Qemu-devel] [PATCH 12/12] chardev: fix race with client connections in tcp_chr_wait_connected

2019-01-15 Thread Daniel P . Berrangé
When the 'reconnect' option is given for a client connection, the
qmp_chardev_open_socket_client method will run an asynchronous
connection attempt. The QIOChannel socket executes this is a single use
background thread, so the connection will succeed immediately (assuming
the server is listening). The chardev, however, won't get the result
from this background thread until the main loop starts running and
processes idle callbacks.

Thus when tcp_chr_wait_connected is run s->ioc will be NULL, and the
state will still be TCP_CHARDEV_STATE_DISCONNECTED, but there will
already be an established connection that will be associated with the
chardev by the pending idle callback.  tcp_chr_wait_connected doesn't
see this and so attempts to establish another connection synchronously.

If the server allows multiple connections this is unhelpful but not a
fatal problem as the duplicate connection will get ignored by the
tcp_chr_new_client method when it sees the state is already connected.

If the server only supports a single connection, however, the
tcp_chr_wait_connected method will hang forever because the server will
not accept its synchronous connection attempt until the first connection
is closed.

To deal with this we must ensure that qmp_chardev_open_socket_client
does not actually start the asynchronous connection attempt. Instead it
should schedule a timer with 0ms expiry time, which will only be
processed once the main loop starts running. The tcp_chr_wait_connected
method can now safely do a synchronous connection attempt without
creating a race condition. When the timer expires it will see that a
connection has already been established and take no further action.

Signed-off-by: Daniel P. Berrangé 
---
 chardev/char-socket.c | 30 --
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 7e98a95bbd..07942d7a1b 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -965,7 +965,25 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
**errp)
 }
 }
 
-while (!s->ioc) {
+/*
+ * We expect state to be as follows:
+ *
+ *  - server
+ *- wait   -> CONNECTED
+ *- nowait -> DISCONNECTED
+ *  - client
+ *- reconnect == 0 -> CONNECTED
+ *- reconnect != 0 -> DISCONNECTED
+ *
+ */
+if (s->state == TCP_CHARDEV_STATE_CONNECTING) {
+error_setg(errp,
+   "Unexpected 'connecting' state when waiting for "
+   "connection during early startup");
+return -1;
+}
+
+while (s->state != TCP_CHARDEV_STATE_CONNECTED) {
 if (s->is_listen) {
 tcp_chr_accept_server_sync(chr);
 } else {
@@ -1106,7 +1124,15 @@ static int qmp_chardev_open_socket_client(Chardev *chr,
 
 if (reconnect > 0) {
 s->reconnect_time = reconnect;
-tcp_chr_connect_client_async(chr);
+/*
+ * We must not start the socket connect attempt until the main
+ * loop is running, otherwise qemu_chr_wait_connect will not be
+ * able to take over connection establishment during startup
+ */
+s->reconnect_timer = qemu_chr_timeout_add_ms(chr,
+ 0,
+ socket_reconnect_timeout,
+ chr);
 return 0;
 } else {
 return tcp_chr_connect_client_sync(chr, errp);
-- 
2.20.1




  1   2   3   4   >