]> Git Repo - qemu.git/log
qemu.git
8 years agoMerge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.6-20160324' into staging
Peter Maydell [Thu, 24 Mar 2016 15:22:39 +0000 (15:22 +0000)]
Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.6-20160324' into staging

ppc patch queue for 2016-03-24

Accumulated patches for target-ppc, pseries machine type and related
devices.

* Preliminary patches from BenH & Cédric Le Goater's powernv code
    * We don't want the full machine type before 2.7
    * Adding some of the SPRs also fixes migration corner cases for
      spapr (when qemu has no knowledge of the registers, they're
      obviously not migrated)
    * We include some patches that aren't strictly fixes, but make
      applying the others easier, and they're low risk
* Fix to buffer management which significantly improves throughput in
  the spapr-llan virtual network device
* Start with 64-bit mode enabled on spapr.  This is the way it's
  supposed to be but we broke it a while back and didn't notice
  because Linux guests cope anyway.
    * Picked up by kvm-unit-tests
    * Still some bugs here that I'm working on

# gpg: Signature made Thu 24 Mar 2016 04:29:42 GMT using RSA key ID 20D9B392
# gpg: Good signature from "David Gibson <[email protected]>"
# gpg:                 aka "David Gibson (Red Hat) <[email protected]>"
# gpg:                 aka "David Gibson (ozlabs.org) <[email protected]>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 75F4 6586 AE61 A66C C44E  87DC 6C38 CACA 20D9 B392

* remotes/dgibson/tags/ppc-for-2.6-20160324:
  ppc: move POWER8 Book4 regs in their own routine
  hw/net/spapr_llan: Enable the RX buffer pools by default for new machines
  hw/net/spapr_llan: Fix receive buffer handling for better performance
  hw/net/spapr_llan: Extract rx buffer code into separate functions
  ppc: A couple more dummy POWER8 Book4 regs
  ppc: Add dummy CIABR SPR
  ppc: Add POWER8 IAMR register
  ppc: Fix writing to AMR/UAMOR
  ppc: Initialize AMOR in PAPR mode
  ppc: Add dummy SPR_IC for POWER8
  ppc: Create cpu_ppc_set_papr() helper
  ppc: Add a bunch of hypervisor SPRs to Book3s
  ppc: Add macros to register hypervisor mode SPRs
  ppc: Update SPR definitions
  spapr/target-ppc/kvm: Only add hcall-instructions if KVM supports it
  ppc64: set MSR_SF bit

Signed-off-by: Peter Maydell <[email protected]>
8 years agoMerge remote-tracking branch 'remotes/lalrae/tags/mips-20160323' into staging
Peter Maydell [Thu, 24 Mar 2016 14:30:20 +0000 (14:30 +0000)]
Merge remote-tracking branch 'remotes/lalrae/tags/mips-20160323' into staging

MIPS patches 2016-03-23

Changes:
* add mips-softmmu-common.mak
* indicate presence of IEEE 754-2008 FPU in MIPS64R6-generic and P5600

# gpg: Signature made Wed 23 Mar 2016 16:38:04 GMT using RSA key ID 0B29DA6B
# gpg: Good signature from "Leon Alrae <[email protected]>"

* remotes/lalrae/tags/mips-20160323:
  default-configs: add mips-softmmu-common.mak
  target-mips: indicate presence of IEEE 754-2008 FPU in R6/R5+MSA CPUs

Signed-off-by: Peter Maydell <[email protected]>
8 years agoMerge remote-tracking branch 'remotes/pmaydell/tags/pull-cocoa-20160323-1' into staging
Peter Maydell [Thu, 24 Mar 2016 13:43:30 +0000 (13:43 +0000)]
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-cocoa-20160323-1' into staging

cocoa queue:
 * update cocoa UI front end to use QKeyCodes
 * fix the help menu documentation links to actually work
   (with both an installed and an uninstalled QEMU)

# gpg: Signature made Wed 23 Mar 2016 14:31:01 GMT using RSA key ID 14360CDE
# gpg: Good signature from "Peter Maydell <[email protected]>"
# gpg:                 aka "Peter Maydell <[email protected]>"
# gpg:                 aka "Peter Maydell <[email protected]>"

* remotes/pmaydell/tags/pull-cocoa-20160323-1:
  ui/cocoa.m: switch to QKeyCode
  qapi-schema.json: Add power and keypad equal keys
  ui/cocoa.m: fix help menus

Signed-off-by: Peter Maydell <[email protected]>
8 years agoMerge remote-tracking branch 'remotes/bkoppelmann/tags/pull-tricore-20160323' into...
Peter Maydell [Thu, 24 Mar 2016 12:36:38 +0000 (12:36 +0000)]
Merge remote-tracking branch 'remotes/bkoppelmann/tags/pull-tricore-20160323' into staging

TriCore FPU + bugfixes

# gpg: Signature made Wed 23 Mar 2016 08:26:03 GMT using RSA key ID 6B69CA14
# gpg: Good signature from "Bastian Koppelmann <[email protected]>"

* remotes/bkoppelmann/tags/pull-tricore-20160323:
  target-tricore: Add ftoi and itof instructions
  target-tricore: Add cmp.f instruction
  target-tricore: Add div.f instruction
  target-tricore: Add mul.f instruction
  target-tricore: add add.f/sub.f instructions
  target-tricore: Move general CHECK_REG_PAIR of decode_rrr_divide
  target-tricore: Add FPU infrastructure
  target-tricore: Fix psw_read() clearing too many bits
  target-tricore: Fix helper_msub64_q_ssov not reseting OVF bit
  target-tricore: add missing break in insn decode switch stmt

Signed-off-by: Peter Maydell <[email protected]>
8 years agoppc: move POWER8 Book4 regs in their own routine
Cédric Le Goater [Tue, 22 Mar 2016 14:23:13 +0000 (15:23 +0100)]
ppc: move POWER8 Book4 regs in their own routine

commit fce55481360d "ppc: A couple more dummy POWER8 Book4 regs"
squashed in to rapidly a set of POWER8 Book4 regs in the wrong
routine. This patch introduces the missing gen_spr_power8_book4()
routine to fix their location.

Signed-off-by: Cédric Le Goater <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agohw/net/spapr_llan: Enable the RX buffer pools by default for new machines
Thomas Huth [Mon, 21 Mar 2016 16:25:24 +0000 (17:25 +0100)]
hw/net/spapr_llan: Enable the RX buffer pools by default for new machines

RX buffer pools are now enabled by default for new machine types.
For older machine types, they are still disabled to avoid breaking
migration.

Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agohw/net/spapr_llan: Fix receive buffer handling for better performance
Thomas Huth [Mon, 21 Mar 2016 16:25:23 +0000 (17:25 +0100)]
hw/net/spapr_llan: Fix receive buffer handling for better performance

tl;dr:
This patch introduces an alternate way of handling the receive
buffers of the spapr-vlan device, resulting in much better
receive performance for the guest.

Full story:
One of our testers recently discovered that the performance of the
spapr-vlan device is very poor compared to other NICs, and that
a simple "ping -i 0.2 -s 65507 someip" in the guest can result
in more than 50% lost ping packets (especially with older guest
kernels < 3.17).

After doing some analysis, it was clear that there is a problem
with the way we handle the receive buffers in spapr_llan.c: The
ibmveth driver of the guest Linux kernel tries to add a lot of
buffers into several buffer pools (with 512, 2048 and 65536 byte
sizes by default, but it can be changed via the entries in the
/sys/devices/vio/1000/pool* directories of the guest). However,
the spapr-vlan device of QEMU only tries to squeeze all receive
buffer descriptors into one single page which has been supplied
by the guest during the H_REGISTER_LOGICAL_LAN call, without
taking care of different buffer sizes. This has two bad effects:
First, only a very limited number of buffer descriptors is accepted
at all. Second, we also hand 64k buffers to the guest even if
the 2k buffers would fit better - and this results in dropped packets
in the IP layer of the guest since too much skbuf memory is used.

Though it seems at a first glance like PAPR says that we should store
the receive buffer descriptors in the page that is supplied during
the H_REGISTER_LOGICAL_LAN call, chapter 16.4.1.2 in the LoPAPR spec
declares that "the contents of these descriptors are architecturally
opaque, none of these descriptors are manipulated by code above
the architected interfaces". That means we don't have to store
the RX buffer descriptors in this page, but can also manage the
receive buffers at the hypervisor level only. This is now what we
are doing here: Introducing proper RX buffer pools which are also
sorted by size of the buffers, so we can hand out a buffer with
the best fitting size when a packet has been received.

To avoid problems with migration from/to older version of QEMU,
the old behavior is also retained and enabled by default. The new
buffer management has to be enabled via a new "use-rx-buffer-pools"
property.

Now with the new buffer pool management enabled, the problem with
"ping -s 65507" is fixed for me, and the throughput of a simple
test with wget increases from creeping 3MB/s up to 20MB/s!

Signed-off-by: Thomas Huth <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agohw/net/spapr_llan: Extract rx buffer code into separate functions
Thomas Huth [Mon, 21 Mar 2016 16:25:22 +0000 (17:25 +0100)]
hw/net/spapr_llan: Extract rx buffer code into separate functions

Refactor the code a little bit by extracting the code that reads
and writes the receive buffer list page into separate functions.
There should be no functional change in this patch, this is just
a preparation for the upcoming extensions that introduce receive
buffer pools.

Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Reviewed-by: Laurent Vivier <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: A couple more dummy POWER8 Book4 regs
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:40 +0000 (13:52 +0100)]
ppc: A couple more dummy POWER8 Book4 regs

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
[clg: squashed in patch 'ppc: Add dummy ACOP SPR' ]
Signed-off-by: Cédric Le Goater <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Add dummy CIABR SPR
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:39 +0000 (13:52 +0100)]
ppc: Add dummy CIABR SPR

We should implement HW breakpoint/watchpoint, qemu supports them...

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Add POWER8 IAMR register
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:38 +0000 (13:52 +0100)]
ppc: Add POWER8 IAMR register

With appropriate AMR-like masks. Not actually used by the translation
logic at that point

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
[clg: changed spr_register_hv(SPR_IAMR) to spr_register_kvm_hv(SPR_IAMR)
      changed gen_spr_amr() prototype ]
Signed-off-by: Cédric Le Goater <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Fix writing to AMR/UAMOR
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:37 +0000 (13:52 +0100)]
ppc: Fix writing to AMR/UAMOR

The masks weren't chosen nor applied properly. The architecture specifies
that writes to AMR are masked by UAMOR for PR=1, otherwise AMOR for HV=0.

The writes to UAMOR are masked by AMOR for HV=0

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
[clg: moved gen_spr_amr() prototype change to next patch ]
Signed-off-by: Cédric Le Goater <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Initialize AMOR in PAPR mode
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:36 +0000 (13:52 +0100)]
ppc: Initialize AMOR in PAPR mode

Make sure we give the guest full authorization

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Add dummy SPR_IC for POWER8
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:35 +0000 (13:52 +0100)]
ppc: Add dummy SPR_IC for POWER8

It's supposed to be an instruction counter. For now make us not
crash when accessing it.

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Create cpu_ppc_set_papr() helper
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:34 +0000 (13:52 +0100)]
ppc: Create cpu_ppc_set_papr() helper

And move the code adjusting the MSR mask and calling kvmppc_set_papr()
to it. This allows us to add a few more things such as disabling setting
of MSR:HV and appropriate LPCR bits which will be used when fixing
the exception model.

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Reviewed-by: David Gibson <[email protected]>
[clg: removed LPCR setting ]
Signed-off-by: Cédric Le Goater <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Add a bunch of hypervisor SPRs to Book3s
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:33 +0000 (13:52 +0100)]
ppc: Add a bunch of hypervisor SPRs to Book3s

We don't give them a KVM reg number to most of the registers yet as no
current KVM version supports HV mode. For DAWR and DAWRX, the KVM reg
number is needed since this register can be set by the guest via the
H_SET_MODE hypercall.

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
[clg: squashed in patch 'ppc: Add KVM numbers to some P8 SPRs'
      changed the commit log with a proposal of Thomas Huth
      removed all hunks except those related to AMOR and DAWR* ]
Signed-off-by: Cédric Le Goater <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Add macros to register hypervisor mode SPRs
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:32 +0000 (13:52 +0100)]
ppc: Add macros to register hypervisor mode SPRs

The current set of spr_register_* macros only take the user and
supervisor function pointers. To make the transition easy, we
don't change that but we add "_hv" variants that can be used to
register all 3 sets.

To simplify the transition, users of the "old" macro will set the
hypervisor callback to be the same as the supervisor one. The new
registration function only needs to be used for registers that are
either hypervisor only or behave differently in HV mode.

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Reviewed-by: David Gibson <[email protected]>
[clg: fixed else if condition in gen_op_mfspr() ]
Signed-off-by: Cédric Le Goater <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoppc: Update SPR definitions
Benjamin Herrenschmidt [Mon, 21 Mar 2016 12:52:31 +0000 (13:52 +0100)]
ppc: Update SPR definitions

Add definitions for additional SPR numbers and SPR bit definitions
that will be relevant for subsequent improvements to POWER8 emulation

Also fix the definition of LPIDR which was incorrect (and is different
for server and embedded).

Signed-off-by: Benjamin Herrenschmidt <[email protected]>
Reviewed-by: Thomas Huth <[email protected]>
Reviewed-by: David Gibson <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agospapr/target-ppc/kvm: Only add hcall-instructions if KVM supports it
Alexey Kardashevskiy [Mon, 21 Mar 2016 02:14:02 +0000 (13:14 +1100)]
spapr/target-ppc/kvm: Only add hcall-instructions if KVM supports it

ePAPR defines "hcall-instructions" device-tree property which contains
code to call hypercalls in ePAPR paravirtualized guests.  In general
pseries guests won't use this property, instead using the PAPR defined
hypercall interface.

However, this property has been re-used to implement a hack to allow
PR KVM to run (slightly modified) guests in some situations where it
otherwise wouldn't be able to (because the system's L0 hypervisor
doesn't forward the PAPR hypercalls to the PR KVM kernel).

Hence, this property is always present in the device tree for pseries
guests. All KVM guests use it at least to read features via the
KVM_HC_FEATURES hypercall.

The property is populated by the code returned from the KVM's
KVM_PPC_GET_PVINFO ioctl; if not implemented in the KVM, QEMU supplies
code which will fail all hypercall attempts. If QEMU does not create
the property, and the guest kernel is compiled with
CONFIG_EPAPR_PARAVIRT (which is normally the case), there is exactly
the same stub at @epapr_hypercall_start already.

Rather than maintaining this fairly useless stub implementation, it
makes more sense not to create the property in the device tree in the
first place if the host kernel does not implement it.

This changes kvmppc_get_hypercall() to return 1 if the host kernel
does not implement KVM_CAP_PPC_GET_PVINFO. The caller can use it to decide
on whether to create the property or not.

This changes the pseries machine to not create the property if KVM does
not implement KVM_PPC_GET_PVINFO. In practice this means that from now
on the property will not be created if either HV KVM or TCG is used.

Signed-off-by: Alexey Kardashevskiy <[email protected]>
[reworded commit message for clarity --dwg]
Signed-off-by: David Gibson <[email protected]>
8 years agoppc64: set MSR_SF bit
Laurent Vivier [Wed, 16 Mar 2016 09:43:52 +0000 (10:43 +0100)]
ppc64: set MSR_SF bit

When a qemu-system-ppc64 is started, the 64-bit mode bit
is not set in MSR.

Signed-off-by: Laurent Vivier <[email protected]>
Reviewed-by: Alexander Graf <[email protected]>
Signed-off-by: David Gibson <[email protected]>
8 years agoui/cocoa.m: switch to QKeyCode
John Arbuckle [Wed, 23 Mar 2016 14:26:18 +0000 (14:26 +0000)]
ui/cocoa.m: switch to QKeyCode

This patch removes the pc/xt keycode map and replaces it with the QKeyCode
keymap.

Signed-off-by: John Arbuckle <[email protected]>
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
8 years agoqapi-schema.json: Add power and keypad equal keys
John Arbuckle [Wed, 23 Mar 2016 14:26:17 +0000 (14:26 +0000)]
qapi-schema.json: Add power and keypad equal keys

Add the power and keypad equal keys. These keys are found on a real Macintosh
keyboard.

Signed-off-by: John Arbuckle <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
8 years agoui/cocoa.m: fix help menus
John Arbuckle [Wed, 23 Mar 2016 14:26:17 +0000 (14:26 +0000)]
ui/cocoa.m: fix help menus

Make the help menus actually work. The code will search thru three different
locations for the help file. If it can't be found a dialog will tell the user
the file can't be found.

Signed-off-by: John Arbuckle <[email protected]>
Message-id: F6B689F9-4DBD-4C50-BC38-35E5DD03D396@gmail.com
Reviewed-by: Peter Maydell <[email protected]>
Signed-off-by: Peter Maydell <[email protected]>
8 years agodefault-configs: add mips-softmmu-common.mak
Leon Alrae [Wed, 2 Mar 2016 13:21:11 +0000 (13:21 +0000)]
default-configs: add mips-softmmu-common.mak

Add mips-softmmu-common.mak and include it in existing mips*-softmmu.mak
files to avoid having to repeat CONFIG defines four times.

Suggested-by: Peter Maydell <[email protected]>
Signed-off-by: Leon Alrae <[email protected]>
8 years agotarget-mips: indicate presence of IEEE 754-2008 FPU in R6/R5+MSA CPUs
Leon Alrae [Wed, 24 Feb 2016 10:47:10 +0000 (10:47 +0000)]
target-mips: indicate presence of IEEE 754-2008 FPU in R6/R5+MSA CPUs

MIPS Release 6 and MIPS SIMD Architecture make it mandatory to have IEEE
754-2008 FPU which is indicated by CP1 FIR.HAS2008, FCSR.ABS2008 and
FCSR.NAN2008 bits set to 1.

In QEMU we still keep these bits cleared as there is no 2008-NaN support.
However, this now causes problems preventing from running R6 Linux with
the v4.5 kernel. Kernel refuses to execute 2008-NaN ELFs on a CPU
whose FPU does not support 2008-NaN encoding:

  (...)
  VFS: Mounted root (ext4 filesystem) readonly on device 8:0.
  devtmpfs: mounted
  Freeing unused kernel memory: 256K (ffffffff806f0000 - ffffffff80730000)
  request_module: runaway loop modprobe binfmt-464c
  Starting init: /sbin/init exists but couldn't execute it (error -8)
  request_module: runaway loop modprobe binfmt-464c
  Starting init: /bin/sh exists but couldn't execute it (error -8)
  Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/init.txt for guidance.

Therefore always indicate presence of 2008-NaN support in R6 as well as in
R5+MSA CPUs, even though this feature is not yet supported by MIPS in QEMU.

Signed-off-by: Leon Alrae <[email protected]>
8 years agoMerge remote-tracking branch 'remotes/armbru/tags/pull-ivshmem-2016-03-18' into staging
Peter Maydell [Wed, 23 Mar 2016 12:57:44 +0000 (12:57 +0000)]
Merge remote-tracking branch 'remotes/armbru/tags/pull-ivshmem-2016-03-18' into staging

ivshmem: Fixes, cleanups, device model split

# gpg: Signature made Mon 21 Mar 2016 20:33:54 GMT using RSA key ID EB918653
# gpg: Good signature from "Markus Armbruster <[email protected]>"
# gpg:                 aka "Markus Armbruster <[email protected]>"

* remotes/armbru/tags/pull-ivshmem-2016-03-18: (40 commits)
  contrib/ivshmem-server: Print "not for production" warning
  ivshmem: Require master to have ID zero
  ivshmem: Drop ivshmem property x-memdev
  ivshmem: Clean up after the previous commit
  ivshmem: Split ivshmem-plain, ivshmem-doorbell off ivshmem
  ivshmem: Replace int role_val by OnOffAuto master
  qdev: New DEFINE_PROP_ON_OFF_AUTO
  ivshmem: Inline check_shm_size() into its only caller
  ivshmem: Simplify memory regions for BAR 2 (shared memory)
  ivshmem: Implement shm=... with a memory backend
  ivshmem: Tighten check of property "size"
  ivshmem: Simplify how we cope with short reads from server
  ivshmem: Drop the hackish test for UNIX domain chardev
  ivshmem: Rely on server sending the ID right after the version
  ivshmem: Propagate errors through ivshmem_recv_setup()
  ivshmem: Receive shared memory synchronously in realize()
  ivshmem: Plug leaks on unplug, fix peer disconnect
  ivshmem: Disentangle ivshmem_read()
  ivshmem: Simplify rejection of invalid peer ID from server
  ivshmem: Assert interrupts are set up once
  ...

Signed-off-by: Peter Maydell <[email protected]>
8 years agotarget-tricore: Add ftoi and itof instructions
Bastian Koppelmann [Fri, 11 Mar 2016 15:03:17 +0000 (16:03 +0100)]
target-tricore: Add ftoi and itof instructions

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1457708597[email protected]>

8 years agotarget-tricore: Add cmp.f instruction
Bastian Koppelmann [Fri, 11 Mar 2016 15:03:16 +0000 (16:03 +0100)]
target-tricore: Add cmp.f instruction

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1457708597[email protected]>

8 years agotarget-tricore: Add div.f instruction
Bastian Koppelmann [Fri, 11 Mar 2016 15:03:15 +0000 (16:03 +0100)]
target-tricore: Add div.f instruction

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1457708597[email protected]>

8 years agotarget-tricore: Add mul.f instruction
Bastian Koppelmann [Fri, 11 Mar 2016 15:03:14 +0000 (16:03 +0100)]
target-tricore: Add mul.f instruction

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1457708597[email protected]>

8 years agotarget-tricore: add add.f/sub.f instructions
Bastian Koppelmann [Fri, 11 Mar 2016 15:03:13 +0000 (16:03 +0100)]
target-tricore: add add.f/sub.f instructions

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1457708597[email protected]>

8 years agotarget-tricore: Move general CHECK_REG_PAIR of decode_rrr_divide
Bastian Koppelmann [Fri, 11 Mar 2016 15:03:12 +0000 (16:03 +0100)]
target-tricore: Move general CHECK_REG_PAIR of decode_rrr_divide

The add.f and sub.f to be implemented don't use 64 bit registers
and a general usage of CHECK_REG_PAIR would always generate an
exception for them.

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1457708597[email protected]>

8 years agotarget-tricore: Add FPU infrastructure
Bastian Koppelmann [Fri, 11 Mar 2016 15:03:11 +0000 (16:03 +0100)]
target-tricore: Add FPU infrastructure

This patch adds a file for all the FPU related helpers with all the includes,
useful defines, and a function to update the status bits. Additionally it adds
a mask for the rounding mode bits of PSW as well as all the opcodes for the
FPU instructions.

Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1457708597[email protected]>

8 years agotarget-tricore: Fix psw_read() clearing too many bits
Bastian Koppelmann [Mon, 21 Mar 2016 08:03:03 +0000 (09:03 +0100)]
target-tricore: Fix psw_read() clearing too many bits

psw_read() ought to sync the PSW value with the
cached status bits (C,V,SV,AV,SAV). For this the bits
are cleared in the PSW before they are written from the
cached bits. The clear mask is too big and clears two
additional bits.

Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1458547383[email protected]>

8 years agotarget-tricore: Fix helper_msub64_q_ssov not reseting OVF bit
Bastian Koppelmann [Mon, 21 Mar 2016 08:03:02 +0000 (09:03 +0100)]
target-tricore: Fix helper_msub64_q_ssov not reseting OVF bit

When this instruction does not produce an overflow the corresponding
bit has to be reset.

Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1458547383[email protected]>

8 years agotarget-tricore: add missing break in insn decode switch stmt
Bastian Koppelmann [Mon, 21 Mar 2016 08:03:01 +0000 (09:03 +0100)]
target-tricore: add missing break in insn decode switch stmt

After decoding/translating a RRR_DIVIDE/RRRR_EXTRACT_INSERT type instruction
we would simply fall through and would decode/translate another unintended
RRR2_MADD/RRRW_EXTRACT_INSERT instruction.

Signed-off-by: Bastian Koppelmann <[email protected]>
Message-Id: <1458547383[email protected]>

8 years agoMerge remote-tracking branch 'remotes/weil/tags/pull-wxx-20160322' into staging
Peter Maydell [Tue, 22 Mar 2016 20:27:55 +0000 (20:27 +0000)]
Merge remote-tracking branch 'remotes/weil/tags/pull-wxx-20160322' into staging

wxx patch queue

# gpg: Signature made Tue 22 Mar 2016 18:18:36 GMT using RSA key ID 677450AD
# gpg: Good signature from "Stefan Weil <[email protected]>"
# gpg:                 aka "Stefan Weil <[email protected]>"
# gpg:                 aka "Stefan Weil <[email protected]>"
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: 4923 6FEA 75C9 5D69 8EC2  B78A E08C 21D5 6774 50AD

* remotes/weil/tags/pull-wxx-20160322:
  wxx: Add support for ncurses
  Remove unneeded include statements for setjmp.h
  Include setjmp.h in qemu/osdep.h (bug fix for w64)

Signed-off-by: Peter Maydell <[email protected]>
8 years agowxx: Add support for ncurses
Stefan Weil [Wed, 16 Mar 2016 20:27:25 +0000 (21:27 +0100)]
wxx: Add support for ncurses

We used to support only pdcurses for Windows, but recently Cygwin added
mingw64-i686-ncurses and mingw64-x86_64-ncurses packages which are
supported now, too.

Signed-off-by: Stefan Weil <[email protected]>
8 years agoRemove unneeded include statements for setjmp.h
Stefan Weil [Mon, 14 Mar 2016 14:47:05 +0000 (15:47 +0100)]
Remove unneeded include statements for setjmp.h

As soon as setjmp.h is included from qemu/osdep.h, those old include
statements are no longer needed.

Add also setjmp.h to the list in scripts/clean-includes.

Signed-off-by: Stefan Weil <[email protected]>
8 years agoInclude setjmp.h in qemu/osdep.h (bug fix for w64)
Stefan Weil [Sat, 12 Mar 2016 06:20:49 +0000 (07:20 +0100)]
Include setjmp.h in qemu/osdep.h (bug fix for w64)

setjmp must be declared before sysemu/os-win32.h
because it is redefined there for 64 bit Windows.

Reviewed-by: Richard Henderson <[email protected]>
Tested-by: Andrew Baumann <[email protected]>
Signed-off-by: Stefan Weil <[email protected]>
8 years agoMerge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2016-03-21-tag' into staging
Peter Maydell [Tue, 22 Mar 2016 17:39:48 +0000 (17:39 +0000)]
Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2016-03-21-tag' into staging

qemu-ga patch queue for 2.6

* remove unused variable

# gpg: Signature made Mon 21 Mar 2016 17:32:42 GMT using RSA key ID F108B584
# gpg: Good signature from "Michael Roth <[email protected]>"
# gpg:                 aka "Michael Roth <[email protected]>"
# gpg:                 aka "Michael Roth <[email protected]>"

* remotes/mdroth/tags/qga-pull-2016-03-21-tag:
  qemu-ga: drop unused local err variable

Signed-off-by: Peter Maydell <[email protected]>
8 years agoMerge remote-tracking branch 'remotes/kraxel/tags/pull-usb-20160321-1' into staging
Peter Maydell [Tue, 22 Mar 2016 16:42:06 +0000 (16:42 +0000)]
Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-20160321-1' into staging

usb: bugfix collection.

# gpg: Signature made Mon 21 Mar 2016 11:07:39 GMT using RSA key ID D3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <[email protected]>"
# gpg:                 aka "Gerd Hoffmann <[email protected]>"
# gpg:                 aka "Gerd Hoffmann (private) <[email protected]>"

* remotes/kraxel/tags/pull-usb-20160321-1:
  usb: ehci: add capability mmio write function
  hw/usb/dev-mtp: Guard inotify usage with CONFIG_INOTIFY1
  usb: fix unbound stack warning for inotify_watchfn
  usb: fix unbound stack usage for usb_mtp_add_str
  usb: fix unbounded stack warning for xhci_dma_write_u32s
  usb: Fix compilation for Windows

Signed-off-by: Peter Maydell <[email protected]>
8 years agocontrib/ivshmem-server: Print "not for production" warning
Markus Armbruster [Tue, 15 Mar 2016 18:34:55 +0000 (19:34 +0100)]
contrib/ivshmem-server: Print "not for production" warning

The code is okay for illustrating how things work and for testing, but
its error handling make it unfit for production use.  Print a warning
to protect the innocent.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Require master to have ID zero
Markus Armbruster [Tue, 15 Mar 2016 18:34:54 +0000 (19:34 +0100)]
ivshmem: Require master to have ID zero

Migration with ivshmem needs to be carefully orchestrated to work.
Exactly one peer (the "master") migrates to the destination, all other
peers need to unplug (and disconnect), migrate, plug back (and
reconnect).  This is sort of documented in qemu-doc.

If peers connect on the destination before migration completes, the
shared memory can get messed up.  This isn't documented anywhere.  Fix
that in qemu-doc.

To avoid messing up register IVPosition on migration, the server must
assign the same ID on source and destination.  ivshmem-spec.txt leaves
ID assignment unspecified, however.

Amend ivshmem-spec.txt to require the first client to receive ID zero.
The example ivshmem-server complies: it always assigns the first
unused ID.

For a bit of additional safety, enforce ID zero for the master.  This
does nothing when we're not using a server, because the ID is zero for
all peers then.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Drop ivshmem property x-memdev
Markus Armbruster [Tue, 15 Mar 2016 18:34:53 +0000 (19:34 +0100)]
ivshmem: Drop ivshmem property x-memdev

Use ivshmem-plain instead.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Clean up after the previous commit
Markus Armbruster [Tue, 15 Mar 2016 18:34:52 +0000 (19:34 +0100)]
ivshmem: Clean up after the previous commit

Move code to more sensible places.  Use the opportunity to reorder and
document IVShmemState members.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Split ivshmem-plain, ivshmem-doorbell off ivshmem
Markus Armbruster [Tue, 15 Mar 2016 18:34:51 +0000 (19:34 +0100)]
ivshmem: Split ivshmem-plain, ivshmem-doorbell off ivshmem

ivshmem can be configured with and without interrupt capability
(a.k.a. "doorbell").  The two configurations have largely disjoint
options, which makes for a confusing (and badly checked) user
interface.  Moreover, the device can't tell the guest whether its
doorbell is enabled.

Create two new device models ivshmem-plain and ivshmem-doorbell, and
deprecate the old one.

Changes from ivshmem:

* PCI revision is 1 instead of 0.  The new revision is fully backwards
  compatible for guests.  Guests may elect to require at least
  revision 1 to make sure they're not exposed to the funny "no shared
  memory, yet" state.

* Property "role" replaced by "master".  role=master becomes
  master=on, role=peer becomes master=off.  Default is off instead of
  auto.

* Property "use64" is gone.  The new devices always have 64 bit BARs.

Changes from ivshmem to ivshmem-plain:

* The Interrupt Pin register in PCI config space is zero (does not use
  an interrupt pin) instead of one (uses INTA).

* Property "x-memdev" is renamed to "memdev".

* Properties "shm" and "size" are gone.  Use property "memdev"
  instead.

* Property "msi" is gone.  The new device can't have MSI-X capability.
  It can't interrupt anyway.

* Properties "ioeventfd" and "vectors" are gone.  They're meaningless
  without interrupts anyway.

Changes from ivshmem to ivshmem-doorbell:

* Property "msi" is gone.  The new device always has MSI-X capability.

* Property "ioeventfd" defaults to on instead of off.

* Property "size" is gone.  The new device can only map all the shared
  memory received from the server.

Guests can easily find out whether the device is configured for
interrupts by checking for MSI-X capability.

Note: some code added in sub-optimal places to make the diff easier to
review.  The next commit will move it to more sensible places.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Replace int role_val by OnOffAuto master
Markus Armbruster [Tue, 15 Mar 2016 18:34:50 +0000 (19:34 +0100)]
ivshmem: Replace int role_val by OnOffAuto master

In preparation of making it a qdev property.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoqdev: New DEFINE_PROP_ON_OFF_AUTO
Markus Armbruster [Tue, 15 Mar 2016 18:34:49 +0000 (19:34 +0100)]
qdev: New DEFINE_PROP_ON_OFF_AUTO

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Inline check_shm_size() into its only caller
Markus Armbruster [Tue, 15 Mar 2016 18:34:48 +0000 (19:34 +0100)]
ivshmem: Inline check_shm_size() into its only caller

Improve the error messages while there.

Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <1458066895[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
8 years agoivshmem: Simplify memory regions for BAR 2 (shared memory)
Markus Armbruster [Tue, 15 Mar 2016 18:34:47 +0000 (19:34 +0100)]
ivshmem: Simplify memory regions for BAR 2 (shared memory)

ivshmem_realize() puts the shared memory region in a container region.
Used to be necessary to permit delayed mapping of the shared memory.
However, we recently moved to synchronous mapping, in "ivshmem:
Receive shared memory synchronously in realize()" and the commit
following it.  The container is redundant since then.  Drop it.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Implement shm=... with a memory backend
Markus Armbruster [Tue, 15 Mar 2016 18:34:46 +0000 (19:34 +0100)]
ivshmem: Implement shm=... with a memory backend

ivshmem has its very own code to create and map shared memory.
Replace that with an implicitly created memory backend.  Reduces the
number of ways we create BAR 2 from three to two.

The memory-backend-file is currently available only with CONFIG_LINUX,
so this adds a second Linuxism to ivshmem (the other one is eventfd).
Should we ever need to make it portable to systems where
memory-backend-file can't be made to serve, we could create a
memory-backend-shmem that allocates memory with shm_open().

Bonus fix: shared memory files are now created with permissions 0655
instead of 0777.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Tighten check of property "size"
Markus Armbruster [Tue, 15 Mar 2016 18:34:45 +0000 (19:34 +0100)]
ivshmem: Tighten check of property "size"

If size_t is narrower than 64 bits, passing uint64_t ivshmem_size to
mmap() truncates.  Reject such sizes.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Simplify how we cope with short reads from server
Markus Armbruster [Tue, 15 Mar 2016 18:34:44 +0000 (19:34 +0100)]
ivshmem: Simplify how we cope with short reads from server

Short reads from a UNIX domain sockets are exceedingly unlikely when
the other side always sends eight bytes and we always read eight
bytes.  We cope with them anyway.  However, the code doing that is
rather convoluted.  Dumb it down radically.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Drop the hackish test for UNIX domain chardev
Markus Armbruster [Tue, 15 Mar 2016 18:34:43 +0000 (19:34 +0100)]
ivshmem: Drop the hackish test for UNIX domain chardev

The chardev must be capable of transmitting SCM_RIGHTS ancillary
messages.  We check it by comparing CharDriverState member filename to
"unix:".  That's almost as brittle as it is disgusting.

When the actual transmission all happened asynchronously, this check
was all we could do in realize(), and thus better than nothing.  But
now we receive at least one SCM_RIGHTS synchronously in realize(),
it's not worth its keep anymore.  Drop it.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Rely on server sending the ID right after the version
Markus Armbruster [Tue, 15 Mar 2016 18:34:42 +0000 (19:34 +0100)]
ivshmem: Rely on server sending the ID right after the version

The protocol specification (ivshmem-spec.txt, formerly
ivshmem_device_spec.txt) has always required the ID message to be sent
right at the beginning, and ivshmem-server has always complied.  The
device, however, accepts it out of order.  If an interrupt setup
arrived before it, though, it would be misinterpreted as connect
notification.  Fix the latent bug by relying on the spec and
ivshmem-server's actual behavior.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Propagate errors through ivshmem_recv_setup()
Markus Armbruster [Tue, 15 Mar 2016 18:34:41 +0000 (19:34 +0100)]
ivshmem: Propagate errors through ivshmem_recv_setup()

This kills off the funny state described in the previous commit.

Simplify ivshmem_io_read() accordingly, and update documentation.

Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <1458066895[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
8 years agoivshmem: Receive shared memory synchronously in realize()
Markus Armbruster [Tue, 15 Mar 2016 18:34:40 +0000 (19:34 +0100)]
ivshmem: Receive shared memory synchronously in realize()

When configured for interrupts (property "chardev" given), we receive
the shared memory from an ivshmem server.  We do so asynchronously
after realize() completes, by setting up callbacks with
qemu_chr_add_handlers().

Keeping server I/O out of realize() that way avoids delays due to a
slow server.  This is probably relevant only for hot plug.

However, this funny "no shared memory, yet" state of the device also
causes a raft of issues that are hard or impossible to work around:

* The guest is exposed to this state: when we enter and leave it its
  shared memory contents is apruptly replaced, and device register
  IVPosition changes.

  This is a known issue.  We document that guests should not access
  the shared memory after device initialization until the IVPosition
  register becomes non-negative.

  For cold plug, the funny state is unlikely to be visible in
  practice, because we normally receive the shared memory long before
  the guest gets around to mess with the device.

  For hot plug, the timing is tighter, but the relative slowness of
  PCI device configuration has a good chance to hide the funny state.

  In either case, guests complying with the documented procedure are
  safe.

* Migration becomes racy.

  If migration completes before the shared memory setup completes on
  the source, shared memory contents is silently lost.  Fortunately,
  migration is rather unlikely to win this race.

  If the shared memory's ramblock arrives at the destination before
  shared memory setup completes, migration fails.

  There is no known way for a management application to wait for
  shared memory setup to complete.

  All you can do is retry failed migration.  You can improve your
  chances by leaving more time between running the destination QEMU
  and the migrate command.

  To mitigate silent memory loss, you need to ensure the server
  initializes shared memory exactly the same on source and
  destination.

  These issues are entirely undocumented so far.

I'd expect the server to be almost always fast enough to hide these
issues.  But then rare catastrophic races are in a way the worst kind.

This is way more trouble than I'm willing to take from any device.
Kill the funny state by receiving shared memory synchronously in
realize().  If your hot plug hangs, go kill your ivshmem server.

For easier review, this commit only makes the receive synchronous, it
doesn't add the necessary error propagation.  Without that, the funny
state persists.  The next commit will do that, and kill it off for
real.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Plug leaks on unplug, fix peer disconnect
Markus Armbruster [Tue, 15 Mar 2016 18:34:39 +0000 (19:34 +0100)]
ivshmem: Plug leaks on unplug, fix peer disconnect

close_peer_eventfds() cleans up three things: ioeventfd triggers if
they exist, eventfds, and the array to store them.

Commit 98609cd (v1.2.0) fixed it not to clean up ioeventfd triggers
when they don't exist (property ioeventfd=off, which is the default).
Unfortunately, the fix also made it skip cleanup of the eventfds and
the array then.  This is a memory and file descriptor leak on unplug.

Additionally, the reset of nb_eventfds is skipped.  Doesn't matter on
unplug.  On peer disconnect, however, this permanently wedges the
interrupt vectors used for that peer's ID.  The eventfds stay behind,
but aren't connected to a peer anymore.  When the ID gets recycled for
a new peer, the new peer's eventfds get assigned to vectors after the
old ones.  Commonly, the device's number of vectors matches the
server's, so the new ones get dropped with a "Too many eventfd
received" message.  Interrupts either don't work (common case) or go
to the wrong vector.

Fix by narrowing the conditional to just the ioeventfd trigger
cleanup.

While there, move the "invalid" peer check to the only caller where it
can actually happen, and tighten it to reject own ID.

Cc: Paolo Bonzini <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Disentangle ivshmem_read()
Markus Armbruster [Tue, 15 Mar 2016 18:34:38 +0000 (19:34 +0100)]
ivshmem: Disentangle ivshmem_read()

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Simplify rejection of invalid peer ID from server
Markus Armbruster [Tue, 15 Mar 2016 18:34:37 +0000 (19:34 +0100)]
ivshmem: Simplify rejection of invalid peer ID from server

ivshmem_read() processes server messages.  These are 64 bit signed
integers.  -1 is shared memory setup, 16 bit unsigned is a peer ID,
anything else is invalid.

ivshmem_read() rejects invalid negative messages right away, silently.

Invalid positive messages get rejected only in resize_peers(), and
ivshmem_read() then prints the rather cryptic message "failed to
resize peers array".

Extend the first check to cover all invalid messages, make it report
"server sent invalid message", and drop the second check.

Now resize_peers() can't fail anymore; simplify.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Assert interrupts are set up once
Markus Armbruster [Tue, 15 Mar 2016 18:34:36 +0000 (19:34 +0100)]
ivshmem: Assert interrupts are set up once

An interrupt is set up when the interrupt's file descriptor is
received.  Each message applies to the next interrupt vector.
Therefore, each vector cannot be set up more than once.

ivshmem_add_kvm_msi_virq() half-heartedly tries not to rely on this by
doing nothing then, but that's not going to recover from this error
should it become possible in the future.  watch_vector_notifier()
doesn't even try.

Simply assert what is the case, so we get alerted if we ever screw it
up.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Leave INTx alone when using MSI-X
Markus Armbruster [Tue, 15 Mar 2016 18:34:35 +0000 (19:34 +0100)]
ivshmem: Leave INTx alone when using MSI-X

The ivshmem device can either use MSI-X or legacy INTx for interrupts.

With MSI-X enabled, peer interrupt events trigger an MSI as they
should.  But software can still raise INTx via interrupt status and
mask register in BAR 0.  This is explicitly prohibited by PCI Local
Bus Specification Revision 3.0, section 6.8.3.3:

    While enabled for MSI or MSI-X operation, a function is prohibited
    from using its INTx# pin (if implemented) to request service (MSI,
    MSI-X, and INTx# are mutually exclusive).

Fix the device model to leave INTx alone when using MSI-X.

Document that we claim to use INTx in config space even when we don't.
Unlike other devices, ivshmem does *not* use INTx when configured for
MSI-X and MSI-X isn't enabled by software.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Clean up MSI-X conditions
Markus Armbruster [Tue, 15 Mar 2016 18:34:34 +0000 (19:34 +0100)]
ivshmem: Clean up MSI-X conditions

There are three predicates related to MSI-X:

* ivshmem_has_feature(s, IVSHMEM_MSI) is true unless the non-MSI-X
  variant of the device is selected with msi=off.

* msix_present() is true when the device has the PCI capability MSI-X.
  It's initially false, and becomes true during successful realize of
  the MSI-X variant of the device.  Thus, it's the same as
  ivshmem_has_feature(s, IVSHMEM_MSI) for realized devices.

* msix_enabled() is true when msix_present() is true and guest software
  has enabled MSI-X.

Code that differs between the non-MSI-X and the MSI-X variant of the
device needs to be guarded by ivshmem_has_feature(s, IVSHMEM_MSI) or
by msix_present(), except the latter works only for realized devices.

Code that depends on whether MSI-X is in use needs to be guarded with
msix_enabled().

Code review led me to two minor messes:

* ivshmem_vector_notify() calls msix_notify() even when
  !msix_enabled(), unlike most other MSI-X-capable devices.  As far as
  I can tell, msix_notify() does nothing when !msix_enabled().  Add
  the guard anyway.

* Most callers of ivshmem_use_msix() guard it with
  ivshmem_has_feature(s, IVSHMEM_MSI).  Not necessary, because
  ivshmem_use_msix() does nothing when !msix_present().  That's
  ivshmem's only use of msix_present(), though.  Guard it
  consistently, and drop the now redundant msix_present() check.
  While there, rename ivshmem_use_msix() to ivshmem_msix_vector_use().

Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <1458066895[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
8 years agoivshmem: Clean up register callbacks
Markus Armbruster [Tue, 15 Mar 2016 18:34:33 +0000 (19:34 +0100)]
ivshmem: Clean up register callbacks

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Failed realize() can leave migration blocker behind
Markus Armbruster [Tue, 15 Mar 2016 18:34:32 +0000 (19:34 +0100)]
ivshmem: Failed realize() can leave migration blocker behind

If pci_ivshmem_realize() fails after it created its migration blocker,
the blocker is left in place.  Fix that by creating it last.

Likewise, if it fails after it called fifo8_create(), it leaks fifo
memory.  Fix that the same way.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Fix harmless misuse of Error
Markus Armbruster [Tue, 15 Mar 2016 18:34:31 +0000 (19:34 +0100)]
ivshmem: Fix harmless misuse of Error

We reuse errp after passing it host_memory_backend_get_memory().  If
both host_memory_backend_get_memory() and the reuse set an error, the
reuse will fail the assertion in error_setv().  Fortunately,
host_memory_backend_get_memory() can't fail.

Pass it &error_abort to make our assumption explicit, and to get the
assertion failure in the right place should it become invalid.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Don't destroy the chardev on version mismatch
Markus Armbruster [Tue, 15 Mar 2016 18:34:30 +0000 (19:34 +0100)]
ivshmem: Don't destroy the chardev on version mismatch

Yes, the chardev is commonly useless after we read a bad version from
it, but destroying it is inappropriate anyway: the user created it, so
the user should be able to hold on to it as long as he likes.  We
don't destroy it on other errors.  Screwed up in commit 5105b1d.

Stop reading instead.

Also note QEMU's behavior in ivshmem-spec.txt.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Drop ivshmem_event() stub
Markus Armbruster [Tue, 15 Mar 2016 18:34:29 +0000 (19:34 +0100)]
ivshmem: Drop ivshmem_event() stub

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Clean up after commit 9940c32
Markus Armbruster [Tue, 15 Mar 2016 18:34:28 +0000 (19:34 +0100)]
ivshmem: Clean up after commit 9940c32

IVShmemState member eventfd_chr is useless since commit 9940c32.  Drop
it.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Compile debug prints unconditionally to prevent bit-rot
Markus Armbruster [Tue, 15 Mar 2016 18:34:27 +0000 (19:34 +0100)]
ivshmem: Compile debug prints unconditionally to prevent bit-rot

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Add missing newlines to debug printfs
Markus Armbruster [Tue, 15 Mar 2016 18:34:26 +0000 (19:34 +0100)]
ivshmem: Add missing newlines to debug printfs

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem: Rewrite specification document
Markus Armbruster [Tue, 15 Mar 2016 18:34:25 +0000 (19:34 +0100)]
ivshmem: Rewrite specification document

This started as an attempt to update ivshmem_device_spec.txt for
clarity, accuracy and completeness while working on its code, and
quickly became a full rewrite.  Since the diff would be useless
anyway, I'm using the opportunity to rename the file to
ivshmem-spec.txt.

I tried hard to ensure the new text contradicts neither the old text
nor the code.  If the new text contradicts the old text but not the
code, it's probably a bug in the old text.  If the new text
contradicts both, its probably a bug in the new text.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem-test: Improve test cases /ivshmem/server-*
Markus Armbruster [Tue, 15 Mar 2016 18:34:24 +0000 (19:34 +0100)]
ivshmem-test: Improve test cases /ivshmem/server-*

Document missing test: behavior with MSI-X present but not enabled.

For MSI-X, we test and clear the interrupt pending bit before testing
the interrupt.  For INTx, we only clear.  Change to test and clear for
consistency.

Test MSI-X vector 1 in addition to vector 0.

Improve comments.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem-test: Clean up wait for devices to become operational
Markus Armbruster [Tue, 15 Mar 2016 18:34:23 +0000 (19:34 +0100)]
ivshmem-test: Clean up wait for devices to become operational

test_ivshmem_server() waits until the first byte in BAR 2 contains the
0x42 we put into shared memory.  Works because the byte reads zero
until the device maps the shared memory gotten from the server.

Check the IVPosition register instead: it's initially -1, and becomes
non-negative right when the device maps the share memory, so no
change, just cleaner, because it's what guest software is supposed to
do.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem-test: Improve test case /ivshmem/single
Markus Armbruster [Tue, 15 Mar 2016 18:34:22 +0000 (19:34 +0100)]
ivshmem-test: Improve test case /ivshmem/single

Test state of registers after reset.

Test reading Interrupt Status clears it.

Test (invalid) read of Doorbell.

Add more comments.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agotests/libqos/pci-pc: Fix qpci_pc_iomap() to map BARs aligned
Markus Armbruster [Tue, 15 Mar 2016 18:34:21 +0000 (19:34 +0100)]
tests/libqos/pci-pc: Fix qpci_pc_iomap() to map BARs aligned

qpci_pc_iomap() maps BARs one after the other, without padding.  This
is wrong.  PCI Local Bus Specification Revision 3.0, 6.2.5.1. Address
Maps: "all address spaces used are a power of two in size and are
naturally aligned".  That's because the size of a BAR is given by the
number of address bits the device decodes, and the BAR needs to be
mapped at a multiple of that size to ensure the address decoding
works.

Fix qpci_pc_iomap() accordingly.  This takes care of a FIXME in
ivshmem-test.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoevent_notifier: Make event_notifier_init_fd() #ifdef CONFIG_EVENTFD
Markus Armbruster [Tue, 15 Mar 2016 18:34:20 +0000 (19:34 +0100)]
event_notifier: Make event_notifier_init_fd() #ifdef CONFIG_EVENTFD

Event notifiers are designed for eventfd(2).  They can fall back to
pipes, but according to Paolo, event_notifier_init_fd() really
requires the real thing, and should therefore be under #ifdef
CONFIG_EVENTFD.  Do that.

Its only user is ivshmem, which is currently CONFIG_POSIX.  Narrow it
to CONFIG_EVENTFD.

Cc: Paolo Bonzini <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoMerge remote-tracking branch 'remotes/berrange/tags/pull-crypto-2016-03-21-1' into...
Peter Maydell [Mon, 21 Mar 2016 10:19:12 +0000 (10:19 +0000)]
Merge remote-tracking branch 'remotes/berrange/tags/pull-crypto-2016-03-21-1' into staging

Merge crypto 2016/03/21 v1

# gpg: Signature made Mon 21 Mar 2016 10:05:51 GMT using RSA key ID 15104FDF
# gpg: Good signature from "Daniel P. Berrange <[email protected]>"
# gpg:                 aka "Daniel P. Berrange <[email protected]>"

* remotes/berrange/tags/pull-crypto-2016-03-21-1:
  crypto: fix cipher function signature mismatch with nettle & xts
  crypto: add compat cast5_set_key with  nettle < 3.0.0

Signed-off-by: Peter Maydell <[email protected]>
8 years agocrypto: fix cipher function signature mismatch with nettle & xts
Daniel P. Berrange [Fri, 18 Mar 2016 12:39:12 +0000 (12:39 +0000)]
crypto: fix cipher function signature mismatch with nettle & xts

For versions of nettle < 3.0.0, the cipher functions took a
'void *ctx' and 'unsigned len' instad of 'const void *ctx'
and 'size_t len'. The xts functions though are builtin to
QEMU and always expect the latter signatures. Define a
second set of wrappers to use with the correct signatures
needed by XTS mode.

Signed-off-by: Daniel P. Berrange <[email protected]>
8 years agocrypto: add compat cast5_set_key with nettle < 3.0.0
Daniel P. Berrange [Fri, 18 Mar 2016 12:30:53 +0000 (12:30 +0000)]
crypto: add compat cast5_set_key with  nettle < 3.0.0

Prior to the nettle 3.0.0 release, the cast5_set_key function
was actually named cast128_set_key, so we must add a compatibility
definition.

Signed-off-by: Daniel P. Berrange <[email protected]>
8 years agoqemu-ga: drop unused local err variable
Stefan Hajnoczi [Wed, 16 Mar 2016 15:16:02 +0000 (15:16 +0000)]
qemu-ga: drop unused local err variable

Commit 125b310e1d62e3a1dc1e7758563e598957ca7ae4 ("qemu-ga: move
channel/transport functionality into wrapper class") stopped using the
local err variable in channel_event_cb().

This patch deletes the unused variable.

Signed-off-by: Stefan Hajnoczi <[email protected]>
Reviewed-by: Fam Zheng <[email protected]>
Signed-off-by: Michael Roth <[email protected]>
8 years agoMerge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-03-18' into staging
Peter Maydell [Fri, 18 Mar 2016 17:18:41 +0000 (17:18 +0000)]
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2016-03-18' into staging

QAPI patches for 2016-03-18

# gpg: Signature made Fri 18 Mar 2016 09:54:57 GMT using RSA key ID EB918653
# gpg: Good signature from "Markus Armbruster <[email protected]>"
# gpg:                 aka "Markus Armbruster <[email protected]>"

* remotes/armbru/tags/pull-qapi-2016-03-18:
  qapi: Use anonymous bases in QMP flat unions
  qapi: Allow anonymous base for flat union
  qapi: Make BlockdevOptions doc example closer to reality
  qapi: Don't special-case simple union wrappers
  qapi: Drop unused c_null()
  qapi: Inline gen_visit_members() into lone caller
  qapi-commands: Inline single-use helpers of gen_marshal()
  qapi-commands: Utilize implicit struct visits
  qapi-event: Utilize implicit struct visits
  qapi-event: Drop qmp_output_get_qobject() null check
  qapi: Emit implicit structs in generated C
  qapi: Adjust names of implicit types
  qapi: Make c_type() more OO-like
  qapi: Fix command with named empty argument type
  qapi: Assert in places where variants are not handled

Signed-off-by: Peter Maydell <[email protected]>
8 years agoqemu-doc: Fix ivshmem huge page example
Markus Armbruster [Tue, 15 Mar 2016 18:34:19 +0000 (19:34 +0100)]
qemu-doc: Fix ivshmem huge page example

Option parameter "share" is missing.  Without it, you get a *private*
mmap(), which defeats ivshmem's purpose pretty thoroughly ;)

While there, switch to the conventional mountpoint of hugetlbfs
/dev/hugepages.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agoivshmem-server: Don't overload POSIX shmem and file name
Markus Armbruster [Tue, 15 Mar 2016 18:34:18 +0000 (19:34 +0100)]
ivshmem-server: Don't overload POSIX shmem and file name

Option -m NAME is interpreted as directory name if we can statfs() it
and its on hugetlbfs.  Else it's interpreted as POSIX shared memory
object name.  This is nuts.

Always interpret -m as directory.  Create new -M for POSIX shared
memory.  Last of -m or -M wins.

Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <1458066895[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
8 years agoivshmem-server: Fix and clean up command line help
Markus Armbruster [Tue, 15 Mar 2016 18:34:17 +0000 (19:34 +0100)]
ivshmem-server: Fix and clean up command line help

Burying error messages in ~20 lines of usage help is bad form.  Print
a single line pointing to -h instead.

Print -h help to stdout rather than stderr.  Fix default of -p.  Clean
up the help text a bit.

Signed-off-by: Markus Armbruster <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
Message-Id: <1458066895[email protected]>

8 years agotarget-ppc: Document TOCTTOU in hugepage support
Markus Armbruster [Tue, 15 Mar 2016 18:34:16 +0000 (19:34 +0100)]
target-ppc: Document TOCTTOU in hugepage support

The code to find the minimum page size is is vulnerable to TOCTTOU.
Added in commit 2d103aa "target-ppc: fix hugepage support when using
memory-backend-file" (v2.4.0).  Since I can't fix it myself right now,
add a FIXME comment.

Cc: Paolo Bonzini <[email protected]>
Cc: Michael Roth <[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
Message-Id: <1458066895[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]>
8 years agousb: ehci: add capability mmio write function
Prasad J Pandit [Fri, 29 Jan 2016 13:00:34 +0000 (18:30 +0530)]
usb: ehci: add capability mmio write function

USB Ehci emulation supports host controller capability registers.
But its mmio '.write' function was missing, which lead to a null
pointer dereference issue. Add a do nothing 'ehci_caps_write'
definition to avoid it; Do nothing because capability registers
are Read Only(RO).

Reported-by: Zuozhi Fzz <[email protected]>
Signed-off-by: Prasad J Pandit <[email protected]>
Message-id: 1454072434[email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
8 years agohw/usb/dev-mtp: Guard inotify usage with CONFIG_INOTIFY1
Matthew Fortune [Tue, 23 Feb 2016 15:44:27 +0000 (15:44 +0000)]
hw/usb/dev-mtp: Guard inotify usage with CONFIG_INOTIFY1

inotify_init1 usage was guarded by a check for linux but does not
exist on older distributions like CentOS 5 resulting in build
failures.

Signed-off-by: Matthew Fortune <[email protected]>
Message-id: 6D39441BF12EF246A7ABCE6654B023536BB85D4A@hhmail02.hh.imgtec.org
Signed-off-by: Gerd Hoffmann <[email protected]>
8 years agousb: fix unbound stack warning for inotify_watchfn
Peter Xu [Wed, 9 Mar 2016 06:07:20 +0000 (14:07 +0800)]
usb: fix unbound stack warning for inotify_watchfn

Signed-off-by: Peter Xu <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Message-id: 1457503640[email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
8 years agousb: fix unbound stack usage for usb_mtp_add_str
Peter Xu [Thu, 10 Mar 2016 02:35:24 +0000 (10:35 +0800)]
usb: fix unbound stack usage for usb_mtp_add_str

Use heap instead of stack.

Signed-off-by: Peter Xu <[email protected]>
Signed-off-by: Gerd Hoffmann <[email protected]>
8 years agousb: fix unbounded stack warning for xhci_dma_write_u32s
Peter Xu [Fri, 11 Mar 2016 01:51:46 +0000 (09:51 +0800)]
usb: fix unbounded stack warning for xhci_dma_write_u32s

All the callers for xhci_dma_write_u32s() are using mostly 5 * uint32_t
in len. To avoid unbound stack warning for the function, make it
statically allocated, and assert when it's not big enough in the
future.

Signed-off-by: Peter Xu <[email protected]>
Message-id: 1457661106[email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
8 years agousb: Fix compilation for Windows
Stefan Weil [Wed, 16 Mar 2016 20:17:19 +0000 (21:17 +0100)]
usb: Fix compilation for Windows

Mingw-w64 does not provide sys/ioctl.h and Linux builds don't need it,
so remove that include statement.

ERROR is defined by wingdi.h (included via windows.h). Undefine it before
it is redefined to avoid a compiler warning / error.

Signed-off-by: Stefan Weil <[email protected]>
Message-id: 1458159439[email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
8 years agoqapi: Use anonymous bases in QMP flat unions
Eric Blake [Thu, 17 Mar 2016 22:48:40 +0000 (16:48 -0600)]
qapi: Use anonymous bases in QMP flat unions

Now that the generator supports it, we might as well use an
anonymous base rather than breaking out a single-use Base
structure, for all three of our current QMP flat unions.

Oddly enough, this change does not affect the resulting
introspection output (because we already inline the members of
a base type into an object, and had no independent use of the
base type reachable from a command).

The case_whitelist now has to list the name of an implicit
type; which is not too bad (consider it a feature if it makes
it harder for developers to make the whitelist grow :)

Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1458254921[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
8 years agoqapi: Allow anonymous base for flat union
Eric Blake [Thu, 17 Mar 2016 22:48:39 +0000 (16:48 -0600)]
qapi: Allow anonymous base for flat union

Rather than requiring all flat unions to explicitly create
a separate base struct, we can allow the qapi schema to specify
the common members via an inline dictionary. This is similar to
how commands can specify an inline anonymous type for its 'data'.
We already have several struct types that only exist to serve as
a single flat union's base; the next commit will clean them up.
In particular, this patch's change to the BlockdevOptions example
in qapi-code-gen.txt will actually be done in the real QAPI schema.

Now that anonymous bases are legal, we need to rework the
flat-union-bad-base negative test (as previously written, it
forms what is now valid QAPI; tweak it to now provide coverage
of a new error message path), and add a positive test in
qapi-schema-test to use an anonymous base (making the integer
argument optional, for even more coverage).

Note that this patch only allows anonymous bases for flat unions;
simple unions are already enough syntactic sugar that we do not
want to burden them further.  Meanwhile, while it would be easy
to also allow an anonymous base for structs, that would be quite
redundant, as the members can be put right into the struct
instead.

Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1458254921[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
8 years agoqapi: Make BlockdevOptions doc example closer to reality
Eric Blake [Thu, 17 Mar 2016 22:48:38 +0000 (16:48 -0600)]
qapi: Make BlockdevOptions doc example closer to reality

Although we don't want to repeat the entire BlockdevOptions
QMP command in the example, it helps if we aren't needlessly
diverging (the initial example was written before we had
committed the actual QMP interface).  Use names that match what
is found in qapi/block-core.json, such as '*read-only' rather
than 'readonly', or 'BlockdevRef' rather than 'BlockRef'.

For the simple union example, invent BlockdevOptionsSimple so
that later text is unambiguous which of the two union forms is
meant (telling the user to refer back to two 'BlockdevOptions'
wasn't nice, and QMP has only the flat union form).

Also, mention that the discriminator of a flat union is
non-optional.

Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1458254921[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
8 years agoqapi: Don't special-case simple union wrappers
Eric Blake [Thu, 17 Mar 2016 22:48:37 +0000 (16:48 -0600)]
qapi: Don't special-case simple union wrappers

Simple unions were carrying a special case that hid their 'data'
QMP member from the resulting C struct, via the hack method
QAPISchemaObjectTypeVariant.simple_union_type().  But by using
the work we started by unboxing flat union and alternate
branches, coupled with the ability to visit the members of an
implicit type, we can now expose the simple union's implicit
type in qapi-types.h:

| struct q_obj_ImageInfoSpecificQCow2_wrapper {
|     ImageInfoSpecificQCow2 *data;
| };
|
| struct q_obj_ImageInfoSpecificVmdk_wrapper {
|     ImageInfoSpecificVmdk *data;
| };
...
| struct ImageInfoSpecific {
|     ImageInfoSpecificKind type;
|     union { /* union tag is @type */
|         void *data;
|-        ImageInfoSpecificQCow2 *qcow2;
|-        ImageInfoSpecificVmdk *vmdk;
|+        q_obj_ImageInfoSpecificQCow2_wrapper qcow2;
|+        q_obj_ImageInfoSpecificVmdk_wrapper vmdk;
|     } u;
| };

Doing this removes asymmetry between QAPI's QMP side and its
C side (both sides now expose 'data'), and means that the
treatment of a simple union as sugar for a flat union is now
equivalent in both languages (previously the two approaches used
a different layer of dereferencing, where the simple union could
be converted to a flat union with equivalent C layout but
different {} on the wire, or to an equivalent QMP wire form
but with different C representation).  Using the implicit type
also lets us get rid of the simple_union_type() hack.

Of course, now all clients of simple unions have to adjust from
using su->u.member to using su->u.member.data; while this touches
a number of files in the tree, some earlier cleanup patches
helped minimize the change to the initialization of a temporary
variable rather than every single member access.  The generated
qapi-visit.c code is also affected by the layout change:

|@@ -7393,10 +7393,10 @@ void visit_type_ImageInfoSpecific_member
|     }
|     switch (obj->type) {
|     case IMAGE_INFO_SPECIFIC_KIND_QCOW2:
|-        visit_type_ImageInfoSpecificQCow2(v, "data", &obj->u.qcow2, &err);
|+        visit_type_q_obj_ImageInfoSpecificQCow2_wrapper_members(v, &obj->u.qcow2, &err);
|         break;
|     case IMAGE_INFO_SPECIFIC_KIND_VMDK:
|-        visit_type_ImageInfoSpecificVmdk(v, "data", &obj->u.vmdk, &err);
|+        visit_type_q_obj_ImageInfoSpecificVmdk_wrapper_members(v, &obj->u.vmdk, &err);
|         break;
|     default:
|         abort();

Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1458254921[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
8 years agoqapi: Drop unused c_null()
Eric Blake [Thu, 17 Mar 2016 22:48:36 +0000 (16:48 -0600)]
qapi: Drop unused c_null()

Now that we are always bulk-initializing a QAPI C struct to 0
(whether by g_malloc0() or by 'Type arg = {0};'), we no longer
have any clients of c_null() in the generator for per-element
initialization.  This patch is easy enough to revert if we find
a use in the future, but in the present, get rid of the dead code.

Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1458254921[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
8 years agoqapi: Inline gen_visit_members() into lone caller
Eric Blake [Thu, 17 Mar 2016 22:48:35 +0000 (16:48 -0600)]
qapi: Inline gen_visit_members() into lone caller

Commit 82ca8e46 noticed that we had multiple implementations of
visiting every member of a struct, and consolidated it into
gen_visit_fields() (now gen_visit_members()) with enough
parameters to cater to slight differences between the clients.
But recent exposure of implicit types has meant that we are now
down to a single use of that method, so we can clean up the
unused conditionals and just inline it into the remaining
caller: gen_visit_object_members().

Likewise, gen_err_check() no longer needs optional parameters,
as the lone use of non-defaults was via gen_visit_members().

No change to generated code.

Suggested-by: Markus Armbruster <[email protected]>
Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1458254921[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
8 years agoqapi-commands: Inline single-use helpers of gen_marshal()
Eric Blake [Thu, 17 Mar 2016 22:48:34 +0000 (16:48 -0600)]
qapi-commands: Inline single-use helpers of gen_marshal()

Originally, gen_marshal_input_visit() (or gen_visitor_input_block()
before commit f1538019) was factored out to make it easy to do two
passes of a visit to each member of a (possibly-implicit) object,
without duplicating lots of code.  But after recent changes, those
visits now occupy a single line of emitted code, and the helper
method has become a series of conditionals both before and after
the one important line, making it rather awkward to see at a glance
what gets emitted on the first (parsing) or second (deallocation)
pass.  It's a lot easier to read the generator code if we just
inline both uses directly into gen_marshal(), without all the
conditionals.

Once we've done that, it's easy to notice that gen_marshal_vars()
is used only once, and inlining it too lets us consolidate some
mcgen() calls that used to be split across helpers.

gen_call() remains a single-use helper function, but it has
enough indentation and complexity that inlining it would hamper
legibility.

No change to generated output.  The fact that the diffstat shows
a net reduction in lines is an argument in favor of this cleanup.

Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1458254921[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
This page took 0.101149 seconds and 4 git commands to generate.