qemu.git
6 years agohw/sd/sd.c: QOMify
Peter Maydell [Thu, 18 Feb 2016 14:16:18 +0000 (14:16 +0000)] 
hw/sd/sd.c: QOMify

Turn the SD card into a QOM device.
This conversion only changes the device itself; the various
functions which are effectively methods on the device are not
touched at this point.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Message-id: 1455646193-13238-3-git-send-email-peter.maydell@linaro.org

6 years agohw/sd/sdhci.c: Remove x-drive property
Peter Maydell [Thu, 18 Feb 2016 14:16:18 +0000 (14:16 +0000)] 
hw/sd/sdhci.c: Remove x-drive property

The following commits will remove support for the old sdhci-pci
command line syntax using the x-drive property:
 -device sdhci-pci,x-drive=mydrive -drive id=mydrive,[...]
and replace it with an explicit sd device:
 -device sdhci-pci -drive id=mydrive,[...] -device sd,drive=mydrive

(This is OK because x-drive is experimental.)

This commit removes the x-drive property so that old style
command lines will fail with a reasonable error message:
  -device sdhci-pci,x-drive=mydrive: Property '.x-drive' not found

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Message-id: 1455646193-13238-2-git-send-email-peter.maydell@linaro.org

6 years agoARM: PL061: Cleaning field of PL061 device state
Wei Huang [Thu, 18 Feb 2016 14:16:17 +0000 (14:16 +0000)] 
ARM: PL061: Cleaning field of PL061 device state

This patch removes the float_high field of PL061State, which doesn't
seem to be used anywhere. Because this changes the device state, the
version ID is also bumped up for the reason of compatiblity.

Signed-off-by: Wei Huang <wei@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1455729552-28026-3-git-send-email-wei@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agoARM: PL061: Clear PL061 device state after reset
Wei Huang [Thu, 18 Feb 2016 14:16:17 +0000 (14:16 +0000)] 
ARM: PL061: Clear PL061 device state after reset

Current QEMU doesn't clear PL061 state after reset. This causes a
weird issue with guest reboot via GPIO. Here is the device state
with two reboot requests:

  (PL061State fields)           data   old_in_data   istate
VM boot                         0      0             0
After 1st ACPI reboot request   8      8             8
After VM PL061 driver ACK       8      8             0
After VM reboot                 8      8             0
------------------------------------------------------------
2nd ACPI reboot request         8

In the second reboot request above, because the old_in_data field is 8,
QEMU decides that there is a pending edge IRQ already (see
pl061_update()) in input; so it doesn't raise up IRQ again. As a result
the second reboot request is lost. The correct way is to clear PL061
device state after reset.

The default reset state is found from the documents listed below. Per
Peter's suggestion that QEMU automatically calls reset function after
device initialization, this patch removes calling pl061_reset() from
pl061_initfn().

Reference:
[1] PL061 Technical Reference Manual
[2] Stellaris LM3S8962 Microcontroller Data Sheet
[3] Stellaris LM3S5P31 Microcontroller Data Sheet

Signed-off-by: Wei Huang <wei@redhat.com>
Message-id: 1455729552-28026-2-git-send-email-wei@redhat.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agotarget-arm: Add PMUSERENR_EL0 register
Alistair Francis [Thu, 18 Feb 2016 14:16:17 +0000 (14:16 +0000)] 
target-arm: Add PMUSERENR_EL0 register

The Linux kernel accesses this register early in its setup.

Signed-off-by: Christopher Covington <christopher.covington@linaro.org>
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: b30d536cb16ec57b4412172bb6dbc3f00d293e7d.1455060548.git.alistair.francis@xilinx.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agotarget-arm: Add the pmovsclr_el0 and pmintenclr_el1 registers
Alistair Francis [Thu, 18 Feb 2016 14:16:17 +0000 (14:16 +0000)] 
target-arm: Add the pmovsclr_el0 and pmintenclr_el1 registers

Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org>
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Tested-by: Nathan Rossi <nathan@nathanrossi.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 50deeafb24958a5b6d7f594b5dda399a022c0e5b.1455060548.git.alistair.francis@xilinx.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agotarget-arm: Add the pmceid0 and pmceid1 registers
Alistair Francis [Thu, 18 Feb 2016 14:16:17 +0000 (14:16 +0000)] 
target-arm: Add the pmceid0 and pmceid1 registers

Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org>
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Tested-by: Nathan Rossi <nathan@nathanrossi.com>
Message-id: da0563119a9f56fd5fbdc26e7ed19a8a8457c5b9.1455060548.git.alistair.francis@xilinx.com
[PMM: Use 0 for PMCEID0 values for A15 and A57 since our PMU
 does not currently implement any events.]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agotarget-arm: UNDEF in the UNPREDICTABLE SRS-from-System case
Peter Maydell [Thu, 18 Feb 2016 14:16:17 +0000 (14:16 +0000)] 
target-arm: UNDEF in the UNPREDICTABLE SRS-from-System case

Make get_r13_banked() raise an exception at runtime for the
corner case of SRS from System mode, so that we can UNDEF it;
this brings us in to line with the ARM ARM's set of permitted
CONSTRAINED UNPREDICTABLE choices.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
6 years agotarget-arm: Combine user-only and softmmu get/set_r13_banked()
Peter Maydell [Thu, 18 Feb 2016 14:16:16 +0000 (14:16 +0000)] 
target-arm: Combine user-only and softmmu get/set_r13_banked()

The user-mode versions of get/set_r13_banked() exist just to assert
if they're ever called -- the translate time code should never
emit calls to them because SRS from user mode always UNDEF.
There's no code in the softmmu versions that can't compile in
CONFIG_USER_ONLY, and the assertion is not particularly useful,
so combine the two functions rather than having completely split
versions under ifdefs.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
6 years agotarget-arm: Move bank_number() into internals.h
Peter Maydell [Thu, 18 Feb 2016 14:16:16 +0000 (14:16 +0000)] 
target-arm: Move bank_number() into internals.h

Move bank_number()'s implementation into internals.h, so
it's available in the user-mode-only compile as well.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
6 years agotarget-arm: Move get/set_r13_banked() to op_helper.c
Peter Maydell [Thu, 18 Feb 2016 14:16:16 +0000 (14:16 +0000)] 
target-arm: Move get/set_r13_banked() to op_helper.c

Move get/set_r13_banked() from helper.c to op_helper.c. This will
let us add exception-raising code to them, and also puts them
in the same file as get/set_user_reg(), which makes some conceptual
sense.

(The original reason for the helper.c/op_helper.c split was that
only op_helper.c had access to the CPU env pointer; this distinction
has not been true for a long time, though, and so the split is
now rather arbitrary.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
6 years agotarget-arm: Clean up trap/undef handling of SRS
Peter Maydell [Thu, 18 Feb 2016 14:16:16 +0000 (14:16 +0000)] 
target-arm: Clean up trap/undef handling of SRS

The SRS instruction is:
 * UNDEFINED in Hyp mode
 * UNPREDICTABLE in User or System mode
 * UNPREDICTABLE if the specified mode isn't accessible
 * trapped to EL3 if EL3 is AArch64 and we are at Secure EL1

Clean up the code to handle all these cases cleanly, including
picking UNDEF as our choice of UNPREDICTABLE behaviour rather
blindly trusting the mode field passed in the instruction.
As part of this, move the check for IS_USER into gen_srs()
itself rather than having it done by the caller.

The exception is that we don't UNDEF for calls from System
mode, which need a runtime check. This will be dealt with in
the following commits.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
6 years agotarget-arm: Report correct syndrome for FPEXC32_EL2 traps
Peter Maydell [Thu, 18 Feb 2016 14:16:16 +0000 (14:16 +0000)] 
target-arm: Report correct syndrome for FPEXC32_EL2 traps

If access to FPEXC32_EL2 is trapped by CPTR_EL2.TFP or CPTR_EL3.TFP,
this should be reported with a syndrome register indicating an
FP access trap, not one indicating a system register access trap.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
6 years agotarget-arm: Implement MDCR_EL3.TDA and MDCR_EL2.TDA traps
Peter Maydell [Thu, 18 Feb 2016 14:16:15 +0000 (14:16 +0000)] 
target-arm: Implement MDCR_EL3.TDA and MDCR_EL2.TDA traps

Implement the debug register traps controlled by MDCR_EL2.TDA
and MDCR_EL3.TDA.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
6 years agotarget-arm: Implement MDCR_EL2.TDRA traps
Peter Maydell [Thu, 18 Feb 2016 14:16:15 +0000 (14:16 +0000)] 
target-arm: Implement MDCR_EL2.TDRA traps

Implement trapping of the "debug ROM" registers, which are controlled
by MDCR_EL2.TDRA for EL2 but by the more general MDCR_EL3.TDA for EL3.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
6 years agotarget-arm: Implement MDCR_EL3.TDOSA and MDCR_EL2.TDOSA traps
Peter Maydell [Thu, 18 Feb 2016 14:16:15 +0000 (14:16 +0000)] 
target-arm: Implement MDCR_EL3.TDOSA and MDCR_EL2.TDOSA traps

Implement the traps to EL2 and EL3 controlled by the bits
MDCR_EL2.TDOSA MDCR_EL3.TDOSA. These can configurably trap
accesses to the "powerdown debug" registers.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
6 years agotarget-arm: Fix handling of SCR.SMD
Peter Maydell [Thu, 18 Feb 2016 14:16:15 +0000 (14:16 +0000)] 
target-arm: Fix handling of SCR.SMD

We weren't quite implementing the handling of SCR.SMD correctly.
The condition governing whether the SMD bit should apply only
for NS state is "is EL3 is AArch32", not "is the current EL AArch32".
Fix the condition, and clarify the comment both to reflect this and
to expand slightly on what's going on for the v7-no-Virtualization case.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
6 years agotarget-arm: correct CNTFRQ access rights
Peter Maydell [Thu, 18 Feb 2016 14:16:15 +0000 (14:16 +0000)] 
target-arm: correct CNTFRQ access rights

Correct some corner cases we were getting wrong for
CNTFRQ access rights:
 * should UNDEF from 32-bit Secure EL1
 * only writable from the highest implemented exception level,
   which might not be EL1 now

To clarify the code, provide a new utility function
arm_highest_el() which returns the highest implemented
exception level.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Sergey Fedorov <serge.fdrv@gmail.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
6 years agoMerge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.6-20160218' into staging
Peter Maydell [Thu, 18 Feb 2016 10:29:47 +0000 (10:29 +0000)] 
Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-2.6-20160218' into staging

ppc patch queue for 2016-02-18

Currently accumulated patches for target-ppc, pseries machine type and
related devices.
  * Some cleanups to management of SDR1 and the hashed page table
  * Implementations of a number of simple PAPR hypercalls
  * Significant improvements to the Macintosh CUDA device
  * Several bugfixes

# gpg: Signature made Thu 18 Feb 2016 04:16:51 GMT using RSA key ID 20D9B392
# gpg: Good signature from "David Gibson <david@gibson.dropbear.id.au>"
# gpg:                 aka "David Gibson (Red Hat) <dgibson@redhat.com>"
# gpg:                 aka "David Gibson (ozlabs.org) <dgibson@ozlabs.org>"
# 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-20160218: (26 commits)
  hw/ppc/spapr: Halt CPU when powering off via RTAS call
  pseries: Include missing pseries-2.5 compat properties in pseries-2.4
  cuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commands
  cuda: remove GET_6805_ADDR command
  cuda: port SET_TIME command to new framework
  cuda: port GET_TIME command to new framework
  cuda: port SET_POWER_MESSAGES command to new framework
  cuda: port FILE_SERVER_FLAG command to new framework
  cuda: port RESET_SYSTEM command to new framework
  cuda: port POWERDOWN command to new framework
  cuda: port SET_DEVICE_LIST command to new framework
  cuda: port SET_AUTO_RATE command to new framework
  cuda: port AUTOPOLL command to new framework
  cuda: move unknown commands reject out of switch
  cuda: add a framework to handle commands
  hw/ppc/spapr: Implement the h_set_xdabr hypercall
  hw/ppc/spapr: Implement h_set_dabr
  hw/ppc/spapr: Add h_set_sprg0 hypercall
  migration: ensure htab_save_first completes after timeout
  target-ppc: Remove hack for ppc_hash64_load_hpte*() with HV KVM
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agohw/ppc/spapr: Halt CPU when powering off via RTAS call
Thomas Huth [Wed, 17 Feb 2016 18:23:19 +0000 (19:23 +0100)] 
hw/ppc/spapr: Halt CPU when powering off via RTAS call

The LoPAPR specification defines the following for the RTAS
power-off call: "On successful operation, does not return".
However, the implementation in QEMU currently returns and runs
the guest CPU again for some more cycles. This caused some
trouble with the new ppc implementation of the kvm-unit-tests
recently. So let's make sure that the QEMU implementation
follows the spec, thus stop the CPU to make sure that the
RTAS call does not return to the guest anymore.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Tested-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agopseries: Include missing pseries-2.5 compat properties in pseries-2.4
David Gibson [Tue, 16 Feb 2016 23:25:37 +0000 (10:25 +1100)] 
pseries: Include missing pseries-2.5 compat properties in pseries-2.4

Commit 4b23699 "pseries: Add pseries-2.6 machine type" added a new
SPAPR_COMPAT_2_5 macro in the usual way.  However, it didn't add this
macro to the existing SPAPR_COMPAT_2_4 macro so that pseries-2.4
inherits newer compatibility properties which are needed for 2.5 and
earlier.

This corrects the oversight.

Reported-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
6 years agocuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commands
Hervé Poussineau [Sun, 7 Feb 2016 20:34:16 +0000 (21:34 +0100)] 
cuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commands

We currently don't emulate the I2C bus provided by CUDA.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: remove GET_6805_ADDR command
Hervé Poussineau [Sun, 7 Feb 2016 20:34:15 +0000 (21:34 +0100)] 
cuda: remove GET_6805_ADDR command

It doesn't seem to be used, and operating systems should accept a 'unknown command' answer.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port SET_TIME command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:14 +0000 (21:34 +0100)] 
cuda: port SET_TIME command to new framework

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port GET_TIME command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:13 +0000 (21:34 +0100)] 
cuda: port GET_TIME command to new framework

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port SET_POWER_MESSAGES command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:12 +0000 (21:34 +0100)] 
cuda: port SET_POWER_MESSAGES command to new framework

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port FILE_SERVER_FLAG command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:11 +0000 (21:34 +0100)] 
cuda: port FILE_SERVER_FLAG command to new framework

This command tells if computer should automatically wake-up after a power loss.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port RESET_SYSTEM command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:10 +0000 (21:34 +0100)] 
cuda: port RESET_SYSTEM command to new framework

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port POWERDOWN command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:09 +0000 (21:34 +0100)] 
cuda: port POWERDOWN command to new framework

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port SET_DEVICE_LIST command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:08 +0000 (21:34 +0100)] 
cuda: port SET_DEVICE_LIST command to new framework

Also implement the command, by taking device list mask into account
when polling ADB devices.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port SET_AUTO_RATE command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:07 +0000 (21:34 +0100)] 
cuda: port SET_AUTO_RATE command to new framework

Also implement the command, by removing the hardcoded period of 20 ms/50 Hz
and replacing it by the one requested by user.
Update VMState version to store this new parameter.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: port AUTOPOLL command to new framework
Hervé Poussineau [Sun, 7 Feb 2016 20:34:06 +0000 (21:34 +0100)] 
cuda: port AUTOPOLL command to new framework

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: move unknown commands reject out of switch
Hervé Poussineau [Sun, 7 Feb 2016 20:34:05 +0000 (21:34 +0100)] 
cuda: move unknown commands reject out of switch

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agocuda: add a framework to handle commands
Hervé Poussineau [Sun, 7 Feb 2016 20:34:04 +0000 (21:34 +0100)] 
cuda: add a framework to handle commands

Next commits will port existing CUDA commands to this framework.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agohw/ppc/spapr: Implement the h_set_xdabr hypercall
Thomas Huth [Thu, 11 Feb 2016 12:47:20 +0000 (13:47 +0100)] 
hw/ppc/spapr: Implement the h_set_xdabr hypercall

The H_SET_XDABR hypercall is similar to H_SET_DABR, but also sets
the extended DABR (DABRX) register.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agohw/ppc/spapr: Implement h_set_dabr
Thomas Huth [Thu, 11 Feb 2016 12:47:19 +0000 (13:47 +0100)] 
hw/ppc/spapr: Implement h_set_dabr

According to LoPAPR, h_set_dabr should simply set DABRX to 3
(if the register is available), and load the parameter into DABR.
If DABRX is not available, the hypervisor has to check the
"Breakpoint Translation" bit of the DABR register first.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agohw/ppc/spapr: Add h_set_sprg0 hypercall
Thomas Huth [Thu, 11 Feb 2016 12:47:18 +0000 (13:47 +0100)] 
hw/ppc/spapr: Add h_set_sprg0 hypercall

This is a very simple hypercall that only sets up the SPRG0
register for the guest (since writing to SPRG0 was only permitted
to the hypervisor in older versions of the PowerISA).

Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agomigration: ensure htab_save_first completes after timeout
David Gibson [Thu, 11 Feb 2016 00:40:44 +0000 (10:40 +1000)] 
migration: ensure htab_save_first completes after timeout

htab_save_first_pass could return without finishing its work due to
timeout. The patch checks if another invocation of it is necessary and
will call it in htab_save_complete if necessary.

Signed-off-by: Jianjun Duan <duanj@linux.vnet.ibm.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
[removed overlong line]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agotarget-ppc: Remove hack for ppc_hash64_load_hpte*() with HV KVM
David Gibson [Mon, 8 Feb 2016 23:30:21 +0000 (09:30 +1000)] 
target-ppc: Remove hack for ppc_hash64_load_hpte*() with HV KVM

With HV KVM, the guest's hash page table (HPT) is managed by the kernel and
not directly accessible to QEMU.  This means that spapr->htab is NULL
and normally env->external_htab would also be NULL for each cpu.

However, that would cause ppc_hash64_load_hpte*() to do the wrong thing in
the few cases where QEMU does need to load entries from the in-kernel HPT.
Specifically, seeing external_htab is NULL, they would look for an HPT
within the guest's address space instead.

To stop that we have an ugly hack in the pseries machine type code to
set external htab to (void *)1 instead.

This patch removes that hack by having ppc_hash64_load_hpte*() explicitly
check kvmppc_kern_htab instead, which makes more sense.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
6 years agopseries: Move hash page table allocation to reset time
David Gibson [Tue, 9 Feb 2016 00:21:56 +0000 (10:21 +1000)] 
pseries: Move hash page table allocation to reset time

At the moment the size of the hash page table (HPT) is fixed based on the
maximum memory allowed to the guest.  As such, we allocate the table during
machine construction, and just clear it at reset.

However, we're planning to implement a PAPR extension allowing the hash
page table to be resized at runtime.  This will mean that on reset we want
to revert it to the default size.  It also means that when migrating, we
need to make sure the destination allocates an HPT of size matching the
host, since the guest could have changed it before the migration.

This patch replaces the spapr_alloc_htab() and spapr_reset_htab() functions
with a new spapr_reallocate_hpt() function.  This is called at reset and
inbound migration only, not during machine init any more.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
6 years agopseries: Add helper to calculate recommended hash page table size
David Gibson [Tue, 9 Feb 2016 00:15:12 +0000 (10:15 +1000)] 
pseries: Add helper to calculate recommended hash page table size

At present we calculate the recommended hash page table (HPT) size for a
pseries guest just once in ppc_spapr_init() before allocating the HPT.
In future patches we're going to want this calculation in other places, so
this splits it out into a helper function.  While we're at it, change the
calculation to use ctz() instead of an explicit loop.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
6 years agopseries: Simplify handling of the hash page table fd
David Gibson [Mon, 8 Feb 2016 23:28:58 +0000 (09:28 +1000)] 
pseries: Simplify handling of the hash page table fd

When migrating the 'pseries' machine type with KVM, we use a special fd
to access the hash page table stored within KVM.  Usually, this fd is
opened at the beginning of migration, and kept open until the migration
is complete.

However, if there is a guest reset during the migration, the fd can become
stale and we need to re-open it.  At the moment we use an 'htab_fd_stale'
flag in sPAPRMachineState to signal this, which is checked in the migration
iterators.

But that's rather ugly.  It's simpler to just close and invalidate the
fd on reset, and lazily re-open it in migration if necessary.  This patch
implements that change.

This requires a small addition to the machine state's instance_init,
so that htab_fd is initialized to -1 (telling the migration code it
needs to open it) instead of 0, which could be a valid fd.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
6 years agotarget-ppc: Include missing MMU models for SDR1 in info registers
David Gibson [Mon, 8 Feb 2016 23:28:43 +0000 (09:28 +1000)] 
target-ppc: Include missing MMU models for SDR1 in info registers

The HMP command "info registers" produces somewhat different information on
different ppc cpu variants.  For those with a hash MMU it's supposed to
include the SDR1, DAR and DSISR registers related to the MMU.  However,
the switch is missing a couple of MMU model variants, meaning we will
miss out this information on certain CPUs which should have it.

This patch corrects the oversight.  (Really these MMU model IDs need a big
cleanup, but we might as well fix the bug in the interim).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
6 years agotarget-ppc: Remove unused kvmppc_update_sdr1() stub
David Gibson [Mon, 8 Feb 2016 23:28:25 +0000 (09:28 +1000)] 
target-ppc: Remove unused kvmppc_update_sdr1() stub

This KVM stub implementation isn't used anywhere.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
6 years agohw: fix some debug message format strings
Alyssa Milburn [Thu, 4 Feb 2016 18:40:57 +0000 (18:40 +0000)] 
hw: fix some debug message format strings

Signed-off-by: Alyssa Milburn <fuzzie@fuzzie.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
6 years agoMerge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
Peter Maydell [Tue, 16 Feb 2016 17:31:56 +0000 (17:31 +0000)] 
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging

* Coverity fixes for IPMI and mptsas
* qemu-char fixes from Daniel and Marc-André
* Bug fixes that break qemu-iotests
* Changes to fix reset from panicked state
* checkpatch false positives for designated initializers
* TLS support in the NBD servers and clients

# gpg: Signature made Tue 16 Feb 2016 16:27:17 GMT using RSA key ID 78C7AE83
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>"
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>"

* remotes/bonzini/tags/for-upstream: (28 commits)
  nbd: enable use of TLS with nbd-server-start command
  nbd: enable use of TLS with qemu-nbd server
  nbd: enable use of TLS with NBD block driver
  nbd: implement TLS support in the protocol negotiation
  nbd: use "" as a default export name if none provided
  nbd: always query export list in fixed new style protocol
  nbd: allow setting of an export name for qemu-nbd server
  nbd: make client request fixed new style if advertised
  nbd: make server compliant with fixed newstyle spec
  nbd: invert client logic for negotiating protocol version
  nbd: convert to using I/O channels for actual socket I/O
  nbd: convert blockdev NBD server to use I/O channels for connection setup
  nbd: convert qemu-nbd server to use I/O channels for connection setup
  nbd: convert block client to use I/O channels for connection setup
  qemu-nbd: add support for --object command line arg
  qom: add helpers for UserCreatable object types
  ipmi: sensor number should not exceed MAX_SENSORS
  mptsas: fix wrong formula
  mptsas: fix memory leak
  mptsas: add missing va_end
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agonbd: enable use of TLS with nbd-server-start command
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:14 +0000 (18:41 +0000)] 
nbd: enable use of TLS with nbd-server-start command

This modifies the nbd-server-start QMP command so that it
is possible to request use of TLS. This is done by adding
a new optional parameter "tls-creds" which provides the ID
of a previously created QCryptoTLSCreds object instance.

TLS is only supported when using an IPv4/IPv6 socket listener.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-17-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: enable use of TLS with qemu-nbd server
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:13 +0000 (18:41 +0000)] 
nbd: enable use of TLS with qemu-nbd server

This modifies the qemu-nbd program so that it is possible to
request the use of TLS with the server. It simply adds a new
command line option --tls-creds which is used to provide the
ID of a QCryptoTLSCreds object previously created via the
--object command line option.

For example

  qemu-nbd --object tls-creds-x509,id=tls0,endpoint=server,\
                    dir=/home/berrange/security/qemutls \
           --tls-creds tls0 \
           --exportname default

TLS requires the new style NBD protocol, so if no export name
is set (via --export-name), then we use the default NBD protocol
export name ""

TLS is only supported when using an IPv4/IPv6 socket listener.
It is not possible to use with UNIX sockets, which includes
when connecting the NBD server to a host device.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-16-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: enable use of TLS with NBD block driver
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:12 +0000 (18:41 +0000)] 
nbd: enable use of TLS with NBD block driver

This modifies the NBD driver so that it is possible to request
use of TLS. This is done by providing the 'tls-creds' parameter
with the ID of a previously created QCryptoTLSCreds object.

For example

  $QEMU -object tls-creds-x509,id=tls0,endpoint=client,\
                dir=/home/berrange/security/qemutls \
        -drive driver=nbd,host=localhost,port=9000,tls-creds=tls0

The client will drop the connection if the NBD server does not
provide TLS.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-15-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: implement TLS support in the protocol negotiation
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:11 +0000 (18:41 +0000)] 
nbd: implement TLS support in the protocol negotiation

This extends the NBD protocol handling code so that it is capable
of negotiating TLS support during the connection setup. This involves
requesting the STARTTLS protocol option before any other NBD options.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-14-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: use "" as a default export name if none provided
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:10 +0000 (18:41 +0000)] 
nbd: use "" as a default export name if none provided

If the user does not provide an export name and the server
is running the new style protocol, where export names are
mandatory, use "" as the default export name if the user
has not specified any. "" is defined in the NBD protocol
as the default name to use in such scenarios.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-13-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: always query export list in fixed new style protocol
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:09 +0000 (18:41 +0000)] 
nbd: always query export list in fixed new style protocol

With the new style protocol, the NBD client will currenetly
send NBD_OPT_EXPORT_NAME as the first (and indeed only)
option it wants. The problem is that the NBD protocol spec
does not allow for returning an error message with the
NBD_OPT_EXPORT_NAME option. So if the server mandates use
of TLS, the client will simply see an immediate connection
close after issuing NBD_OPT_EXPORT_NAME which is not user
friendly.

To improve this situation, if we have the fixed new style
protocol, we can sent NBD_OPT_LIST as the first option
to query the list of server exports. We can check for our
named export in this list and raise an error if it is not
found, instead of going ahead and sending NBD_OPT_EXPORT_NAME
with a name that we know will be rejected.

This improves the error reporting both in the case that the
server required TLS, and in the case that the client requested
export name does not exist on the server.

If the server does not support NBD_OPT_LIST, we just ignore
that and carry on with NBD_OPT_EXPORT_NAME as before.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-12-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: allow setting of an export name for qemu-nbd server
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:08 +0000 (18:41 +0000)] 
nbd: allow setting of an export name for qemu-nbd server

The qemu-nbd server currently always uses the old style protocol
since it never sets any export name. This is a problem because
future TLS support will require use of the new style protocol
negotiation.

This adds "--exportname NAME" / "-x NAME" arguments to qemu-nbd
which allow the user to set an explicit export name. When an
export name is set the server will always use the new style
NBD protocol.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-11-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: make client request fixed new style if advertised
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:07 +0000 (18:41 +0000)] 
nbd: make client request fixed new style if advertised

If the server advertises support for the fixed new style
negotiation, the client should in turn enable new style.
This will allow the client to negotiate further NBD
options besides the export name.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-10-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: make server compliant with fixed newstyle spec
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:06 +0000 (18:41 +0000)] 
nbd: make server compliant with fixed newstyle spec

If the client does not request the fixed new style protocol,
then we should only accept NBD_OPT_EXPORT_NAME. All other
options are only valid when fixed new style has been activated.

The qemu-nbd client doesn't currently request fixed new style
protocol, but this change won't break qemu-nbd, because it
fortunately only ever uses NBD_OPT_EXPORT_NAME, so was never
triggering the non-compliant server behaviour.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-9-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: invert client logic for negotiating protocol version
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:05 +0000 (18:41 +0000)] 
nbd: invert client logic for negotiating protocol version

The nbd_receive_negotiate() method takes different code
paths based on whether 'name == NULL', and then checks
the expected protocol version in each branch.

This patch inverts the logic, so that it takes different
code paths based on what protocol version it receives and
then checks if name is NULL or not as needed.

This facilitates later code which allows the client to
be capable of using the new style protocol regardless
of whether an export name is listed or not.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-8-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: convert to using I/O channels for actual socket I/O
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:04 +0000 (18:41 +0000)] 
nbd: convert to using I/O channels for actual socket I/O

Now that all callers are converted to use I/O channels for
initial connection setup, it is possible to switch the core
NBD protocol handling core over to use QIOChannel APIs for
actual sockets I/O.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-7-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: convert blockdev NBD server to use I/O channels for connection setup
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:03 +0000 (18:41 +0000)] 
nbd: convert blockdev NBD server to use I/O channels for connection setup

This converts the blockdev NBD server to use the QIOChannelSocket
class for initial listener socket setup and accepting of client
connections. Actual I/O is still being performed against the
socket file descriptor using the POSIX socket APIs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-6-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: convert qemu-nbd server to use I/O channels for connection setup
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:02 +0000 (18:41 +0000)] 
nbd: convert qemu-nbd server to use I/O channels for connection setup

This converts the qemu-nbd server to use the QIOChannelSocket
class for initial listener socket setup and accepting of client
connections. Actual I/O is still being performed against the
socket file descriptor using the POSIX socket APIs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-5-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agonbd: convert block client to use I/O channels for connection setup
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:01 +0000 (18:41 +0000)] 
nbd: convert block client to use I/O channels for connection setup

This converts the NBD block driver client to use the QIOChannelSocket
class for initial connection setup. The NbdClientSession struct has
two pointers, one to the master QIOChannelSocket providing the raw
data channel, and one to a QIOChannel which is the current channel
used for I/O. Initially the two point to the same object, but when
TLS support is added, they will point to different objects.

The qemu-img & qemu-io tools now need to use MODULE_INIT_QOM to
ensure the QIOChannel object classes are registered. The qemu-nbd
tool already did this.

In this initial conversion though, all I/O is still actually done
using the raw POSIX sockets APIs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-4-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agoqemu-nbd: add support for --object command line arg
Daniel P. Berrange [Wed, 10 Feb 2016 18:41:00 +0000 (18:41 +0000)] 
qemu-nbd: add support for --object command line arg

Allow creation of user creatable object types with qemu-nbd
via a new --object command line arg. This will be used to supply
passwords and/or encryption keys to the various block driver
backends via the recently added 'secret' object type.

 # printf letmein > mypasswd.txt
 # qemu-nbd --object secret,id=sec0,file=mypasswd.txt \
      ...other nbd args...

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-3-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agoqom: add helpers for UserCreatable object types
Daniel P. Berrange [Wed, 10 Feb 2016 18:40:59 +0000 (18:40 +0000)] 
qom: add helpers for UserCreatable object types

The QMP monitor code has two helper methods object_add
and qmp_object_del that are called from several places
in the code (QMP, HMP and main emulator startup).

The HMP and main emulator startup code also share
further logic that extracts the qom-type & id
values from a qdict.

We soon need to use this logic from qemu-img, qemu-io
and qemu-nbd too, but don't want those to depend on
the monitor, nor do we want to duplicate the code.

To avoid this, move some code out of qmp.c and hmp.c
adding new methods to qom/object_interfaces.c

 - user_creatable_add - takes a QDict holding a full
   object definition & instantiates it
 - user_creatable_add_type - takes an ID, type name,
   and QDict holding object properties & instantiates
   it
 - user_creatable_add_opts - takes a QemuOpts holding
   a full object definition & instantiates it
 - user_creatable_add_opts_foreach - variant on
   user_creatable_add_opts which can be directly used
   in conjunction with qemu_opts_foreach.
 - user_creatable_del - takes an ID and deletes the
   corresponding object

The existing code is updated to use these new methods.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-2-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agoMerge remote-tracking branch 'remotes/berrange/tags/pull-io-next-2016-02-16-1' into...
Peter Maydell [Tue, 16 Feb 2016 15:47:35 +0000 (15:47 +0000)] 
Merge remote-tracking branch 'remotes/berrange/tags/pull-io-next-2016-02-16-1' into staging

Merge I/O fixes 2016/02/16 v1

# gpg: Signature made Tue 16 Feb 2016 15:42:29 GMT using RSA key ID 15104FDF
# gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>"
# gpg:                 aka "Daniel P. Berrange <berrange@redhat.com>"

* remotes/berrange/tags/pull-io-next-2016-02-16-1:
  io: convert QIOChannelBuffer to use uint8_t instead of char
  io: introduce helper for creating channels from file descriptors
  io: improve docs for QIOChannelSocket async functions

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agoipmi: sensor number should not exceed MAX_SENSORS
Cédric Le Goater [Tue, 16 Feb 2016 08:05:44 +0000 (09:05 +0100)] 
ipmi: sensor number should not exceed MAX_SENSORS

Fix a number of off-by-ones, one of them spotted by Coverity.

Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agomptsas: fix wrong formula
Paolo Bonzini [Tue, 16 Feb 2016 07:49:15 +0000 (08:49 +0100)] 
mptsas: fix wrong formula

MPI_DOORBELL_WHO_INIT_SHIFT is being repeated twice.  Reported
by Coverity.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agomptsas: fix memory leak
Paolo Bonzini [Tue, 16 Feb 2016 07:41:52 +0000 (08:41 +0100)] 
mptsas: fix memory leak

Reported by Coverity.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agomptsas: add missing va_end
Paolo Bonzini [Tue, 16 Feb 2016 07:35:49 +0000 (08:35 +0100)] 
mptsas: add missing va_end

Reported by Coverity.

Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agomigration: fix incorrect memory_global_dirty_log_start outside BQL
Paolo Bonzini [Mon, 15 Feb 2016 18:57:57 +0000 (19:57 +0100)] 
migration: fix incorrect memory_global_dirty_log_start outside BQL

This can cause various segmentation faults or aborts in qemu-iotests
test 091.

Fixes: 5b82b703b69acc67b78b98a5efc897a3912719eb
Cc: Dave Gilbert <dgilbert@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agooslib-posix.c: Move workaround for OSX daemon() deprecation to osdep.h
Peter Maydell [Mon, 8 Feb 2016 19:08:10 +0000 (19:08 +0000)] 
oslib-posix.c: Move workaround for OSX daemon() deprecation to osdep.h

The right place for "work around issues with system headers" code
is osdep.h. Move the workaround for OSX's stdlib.h emitting a
deprecation warning for daemon() to that header.

This also fixes a problem where running clean-includes on
oslib-posix.c would erroneously remove the #include <stdlib.h>
from it, breaking the workaround.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agoall: Clean up includes
Peter Maydell [Mon, 8 Feb 2016 19:01:23 +0000 (19:01 +0000)] 
all: Clean up includes

Clean up includes so that osdep.h is included first and headers
which it implies are not included manually.

This commit was created with scripts/clean-includes.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agoscripts/tracetool: Include qemu/osdep.h in generated .c files
Peter Maydell [Mon, 8 Feb 2016 18:53:31 +0000 (18:53 +0000)] 
scripts/tracetool: Include qemu/osdep.h in generated .c files

Include qemu/osdep.h as the first include in generated .c files,
so they don't implicitly rely on some other included header
to pull it in.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agoscripts/feature_to_c.sh: Include qemu/osdep.h rather than config.h
Peter Maydell [Mon, 8 Feb 2016 19:17:08 +0000 (19:17 +0000)] 
scripts/feature_to_c.sh: Include qemu/osdep.h rather than config.h

In the .c files generated by this script, include qemu/osdep.h
as the first included header, not config.h.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agoqapi: Clean up includes in generated files
Eric Blake [Mon, 8 Feb 2016 15:36:46 +0000 (08:36 -0700)] 
qapi: Clean up includes in generated files

As a followup to commit cbf2115, clean up the includes in files
generated by QAPI so that osdep.h is included first in .c files,
and headers which it implies are not included manually.  This
patch is done manually, since Coccinelle (and therefore
scripts/clean-includes) doesn't see into the generator scripts.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agotests: Clean up includes
Peter Maydell [Mon, 8 Feb 2016 18:08:51 +0000 (18:08 +0000)] 
tests: Clean up includes

Clean up includes so that osdep.h is included first and headers
which it implies are not included manually.

This commit was created with scripts/clean-includes.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Tested-by: Eric Blake <eblake@redhat.com>
6 years agotests/i440fx-test: Don't define ARRAY_SIZE locally
Peter Maydell [Mon, 8 Feb 2016 18:37:01 +0000 (18:37 +0000)] 
tests/i440fx-test: Don't define ARRAY_SIZE locally

Don't define ARRAY_SIZE locally; instead include osdep.h for it.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agolibdecnumber: Clean up includes
Peter Maydell [Tue, 9 Feb 2016 11:02:46 +0000 (11:02 +0000)] 
libdecnumber: Clean up includes

Clean up includes so that osdep.h is included first and headers
which it implies are not included manually.

This commit was created with scripts/clean-includes.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agocris: Clean up includes
Peter Maydell [Tue, 9 Feb 2016 10:55:48 +0000 (10:55 +0000)] 
cris: Clean up includes

Clean up includes so that osdep.h is included first and headers
which it implies are not included manually.

This commit was created with scripts/clean-includes.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agotarget-cris: Remove unnecessary ifdef from mmu.c
Peter Maydell [Tue, 9 Feb 2016 10:54:10 +0000 (10:54 +0000)] 
target-cris: Remove unnecessary ifdef from mmu.c

mmu.c is only built for CONFIG_SOFTMMU targets, so there is
no need to redundantly surround the whole file contents with
an #ifndef CONFIG_USER_ONLY. The ifdef also confuses the
Coccinelle tool.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agohw/block/nand.c: Include osdep.h first
Peter Maydell [Mon, 8 Feb 2016 19:11:45 +0000 (19:11 +0000)] 
hw/block/nand.c: Include osdep.h first

Include osdep.h as the first header in nand.c; this has to be
done manually because coccinelle gets confused by the way that
this C file includes itself.

We fix some odd spacing in #includes while we are in the area.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
6 years agobuild: Don't redefine 'inline'
Eric Blake [Tue, 9 Feb 2016 18:49:48 +0000 (11:49 -0700)] 
build: Don't redefine 'inline'

Actively redefining 'inline' is wrong for C++, where gcc has an
extension 'inline namespace' which fails to compile if the
keyword 'inline' is replaced by a macro expansion.  This will
matter once we start to include "qemu/osdep.h" first from C++
files, depending also on whether the system headers are new
enough to be using the gcc extension.

But rather than just guard things by __cplusplus, let's look at
the overall picture.  Commit df2542c737ea2 in 2007 defined 'inline'
to the gcc attribute __always_inline__, with the rationale "To
avoid discarded inlining bug".  But compilers have improved since
then, and we are probably better off trusting the compiler rather
than trying to force its hand.

So just nuke our craziness.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1455043788-28112-1-git-send-email-eblake@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agovl: fix migration from prelaunch state
Paolo Bonzini [Mon, 15 Feb 2016 18:40:04 +0000 (19:40 +0100)] 
vl: fix migration from prelaunch state

Reproducer is simply to migrate a virtual machine that was started with -S,
or that was already migrated.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agovl: change QEMU state machine for system reset
Denis V. Lunev [Sat, 13 Feb 2016 13:26:26 +0000 (16:26 +0300)] 
vl: change QEMU state machine for system reset

This patch implements proposal from Paolo to handle system reset when
the guest is not running.

"After a reset, main_loop_should_exit should actually transition
to VM_STATE_PRELAUNCH (*not* RUN_STATE_PAUSED) for *all* states except
RUN_STATE_INMIGRATE, RUN_STATE_SAVE_VM (which I think cannot happen
there) and (of course) RUN_STATE_RUNNING."

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1455369986-20353-1-git-send-email-den@openvz.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agobuild: Don't redefine 'inline'
Eric Blake [Tue, 9 Feb 2016 18:49:48 +0000 (11:49 -0700)] 
build: Don't redefine 'inline'

Actively redefining 'inline' is wrong for C++, where gcc has an
extension 'inline namespace' which fails to compile if the
keyword 'inline' is replaced by a macro expansion.  This will
matter once we start to include "qemu/osdep.h" first from C++
files, depending also on whether the system headers are new
enough to be using the gcc extension.

But rather than just guard things by __cplusplus, let's look at
the overall picture.  Commit df2542c737ea2 in 2007 defined 'inline'
to the gcc attribute __always_inline__, with the rationale "To
avoid discarded inlining bug".  But compilers have improved since
then, and we are probably better off trusting the compiler rather
than trying to force its hand.

So just nuke our craziness.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <1455043788-28112-1-git-send-email-eblake@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agochar: fix handling of QIO_CHANNEL_ERR_BLOCK
Daniel P. Berrange [Fri, 12 Feb 2016 14:46:50 +0000 (14:46 +0000)] 
char: fix handling of QIO_CHANNEL_ERR_BLOCK

If io_channel_send_full gets QIO_CHANNEL_ERR_BLOCK it
and has already sent some of the data, it should return
that amount of data, not EAGAIN, as that would cause
the caller to re-try already sent data.

Unfortunately due to a previous rebase conflict resolution
error, the code for dealing with this was in the wrong
part of the conditional, and so mistakenly ran on other
I/O errors.

This be seen running

   qemu-system-x86_64 -monitor stdio

and entering 'info mtree', when running on a slow console
(eg a slow remote ssh session). The monitor would get into
an indefinite loop writing the same data until it managed
to send it all without getting EAGAIN.

Reported-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455288410-27046-1-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agoRevert "qemu-char: Keep pty slave file descriptor open until the master is closed"
Paolo Bonzini [Fri, 12 Feb 2016 15:05:10 +0000 (16:05 +0100)] 
Revert "qemu-char: Keep pty slave file descriptor open until the master is closed"

This reverts commit 34689e206abddac87a5217d458534e24f2a05562.

Marc-André Lureau provided the following commentary: "It looks like if
a the slave is opened, then Linux will buffer the master writes, up to
a few kb and then throttle, so it's not entirely blocked but eventually
the guest VM dies.  However, not having any slave open it will simply let
the write go and discard the data.  At least, virt-install configures
a pty for the serial but viewers like virt-manager do not necessarily
open it.  And, if there are no viewers, it will just hang.  If qemu
starts reading all the data from the slave, I don't think interactions
with other slaves will work. I don't see much options but to close the
slave, thus reverting this patch."

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agocheckpatch: Eliminate false positive in case of space before square bracket in a...
Leonid Bloch [Thu, 29 Oct 2015 09:48:38 +0000 (11:48 +0200)] 
checkpatch: Eliminate false positive in case of space before square bracket in a definition

Now, macro definition such as "#define abc(x) [x] = y" should pass
without an error.

Signed-off-by: Leonid Bloch <leonid@daynix.com>
Message-Id: <1446112118-12376-3-git-send-email-leonid@daynix.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agocheckpatch: Eliminate false positive in case of comma-space-square bracket
Leonid Bloch [Thu, 29 Oct 2015 09:48:37 +0000 (11:48 +0200)] 
checkpatch: Eliminate false positive in case of comma-space-square bracket

Previously, an error was printed in cases such as:
{ [1] = 5, [2] = 6 }
The space passed OK after a curly brace, but not after a comma.
Now, a space before a square bracket is allowed, if a comma comes before
it.

Signed-off-by: Leonid Bloch <leonid@daynix.com>
Message-Id: <1446112118-12376-2-git-send-email-leonid@daynix.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
6 years agoio: convert QIOChannelBuffer to use uint8_t instead of char
Daniel P. Berrange [Fri, 12 Feb 2016 16:45:31 +0000 (16:45 +0000)] 
io: convert QIOChannelBuffer to use uint8_t instead of char

The QIOChannelBuffer struct uses a 'char *' for its data
buffer. It will give simpler type compatibility with the
migration APIs if it uses 'uint8_t *' instead, avoiding
several casts.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
6 years agoio: introduce helper for creating channels from file descriptors
Daniel P. Berrange [Wed, 3 Feb 2016 14:00:28 +0000 (14:00 +0000)] 
io: introduce helper for creating channels from file descriptors

Depending on what object a file descriptor refers to a different
type of IO channel will be needed - either a QIOChannelFile or
a QIOChannelSocket. Introduce a qio_channel_new_fd() method
which will return the appropriate channel implementation.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
6 years agoio: improve docs for QIOChannelSocket async functions
Daniel P. Berrange [Wed, 3 Feb 2016 13:47:36 +0000 (13:47 +0000)] 
io: improve docs for QIOChannelSocket async functions

In the docs for qio_channel_socket_connect_async,
qio_channel_socket_listen_async and
qio_channel_socket_dgram_async, mention that the
SocketAddress parameters are copied, so can be freed
immediately.

Reviewed-by: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
6 years agoMerge remote-tracking branch 'remotes/rth/tags/pull-i386-20160215' into staging
Peter Maydell [Mon, 15 Feb 2016 11:45:11 +0000 (11:45 +0000)] 
Merge remote-tracking branch 'remotes/rth/tags/pull-i386-20160215' into staging

Add XSAVE, MPX, FSGSBASE.

# gpg: Signature made Mon 15 Feb 2016 11:21:50 GMT using RSA key ID 4DD0279B
# gpg: Good signature from "Richard Henderson <rth7680@gmail.com>"
# gpg:                 aka "Richard Henderson <rth@redhat.com>"
# gpg:                 aka "Richard Henderson <rth@twiddle.net>"

* remotes/rth/tags/pull-i386-20160215:
  target-i386: Implement FSGSBASE
  target-i386: Enable CR4/XCR0 features for user-mode
  target-i386: Clear bndregs during legacy near jumps
  target-i386: Implement BNDLDX, BNDSTX
  target-i386: Update BNDSTATUS for exceptions raised by BOUND
  target-i386: Implement BNDCL, BNDCU, BNDCN
  target-i386: Implement BNDMOV
  target-i386: Implement BNDMK
  target-i386: Split up gen_lea_modrm
  target-i386: Perform set/reset_inhibit_irq inline
  target-i386: Enable control registers for MPX
  target-i386: Implement XSAVEOPT
  target-i386: Add XSAVE extension
  target-i386: Rearrange processing of 0F AE
  target-i386: Rearrange processing of 0F 01
  target-i386: Split fxsave/fxrstor implementation

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6 years agotarget-i386: Implement FSGSBASE
Richard Henderson [Wed, 18 Nov 2015 11:55:47 +0000 (12:55 +0100)] 
target-i386: Implement FSGSBASE

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Enable CR4/XCR0 features for user-mode
Richard Henderson [Tue, 7 Jul 2015 15:13:10 +0000 (16:13 +0100)] 
target-i386: Enable CR4/XCR0 features for user-mode

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Clear bndregs during legacy near jumps
Richard Henderson [Tue, 7 Jul 2015 13:38:58 +0000 (14:38 +0100)] 
target-i386: Clear bndregs during legacy near jumps

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Implement BNDLDX, BNDSTX
Richard Henderson [Tue, 7 Jul 2015 13:08:41 +0000 (14:08 +0100)] 
target-i386: Implement BNDLDX, BNDSTX

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Update BNDSTATUS for exceptions raised by BOUND
Richard Henderson [Mon, 6 Jul 2015 18:37:40 +0000 (19:37 +0100)] 
target-i386: Update BNDSTATUS for exceptions raised by BOUND

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Implement BNDCL, BNDCU, BNDCN
Richard Henderson [Mon, 6 Jul 2015 18:37:00 +0000 (19:37 +0100)] 
target-i386: Implement BNDCL, BNDCU, BNDCN

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Implement BNDMOV
Richard Henderson [Mon, 6 Jul 2015 18:10:23 +0000 (19:10 +0100)] 
target-i386: Implement BNDMOV

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Implement BNDMK
Richard Henderson [Thu, 9 Jul 2015 07:22:46 +0000 (08:22 +0100)] 
target-i386: Implement BNDMK

Signed-off-by: Richard Henderson <rth@twiddle.net>
6 years agotarget-i386: Split up gen_lea_modrm
Richard Henderson [Thu, 9 Jul 2015 07:22:01 +0000 (08:22 +0100)] 
target-i386: Split up gen_lea_modrm

This is immediately usable by lea and multi-byte nop,
and will be required to implement parts of the mpx spec.

Signed-off-by: Richard Henderson <rth@twiddle.net>