qemu.git
7 years agospapr-vscsi: fix CRQ status
Alexey Kardashevskiy [Wed, 5 Mar 2014 05:15:16 +0000 (16:15 +1100)] 
spapr-vscsi: fix CRQ status

Normally VIOSRP_OK (0) means success and non-zero value means error
except VIOSRP_OK2 (0x99) which is another success code by weird accident.

This uses 0 as success code always as some guests do not cope with
the 0x99 value well. The existing linux driver checks for both VIOSRP_OK
and VIOSRP_OK2 since 2.6.32.

This returns non-zero code (VIOSRP_ADAPTER_FAIL == 0x10) on errors which
can only happen if DMA write failed.

Suggested-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7 years agoUpdate version for v2.0-rc0 v2.0.0-rc0
Anthony Liguori [Fri, 14 Mar 2014 03:08:15 +0000 (20:08 -0700)] 
Update version for v2.0-rc0

Signed-off-by: Anthony Liguori <aliguori@amazon.com>
7 years agoMerge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-2.0' into staging
Peter Maydell [Thu, 13 Mar 2014 21:50:39 +0000 (21:50 +0000)] 
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-2.0' into staging

QOM/QTest infrastructure fixes

* QOM cast fix for virtserialport and regression test
* QTest error handling fix
* QTest output cleanup

# gpg: Signature made Thu 13 Mar 2014 20:43:34 GMT using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg:                 aka "Andreas Färber <afaerber@suse.com>"

* remotes/afaerber/tags/qom-devices-for-2.0:
  main-loop: Suppress "I/O thread spun" warnings for qtest
  qtest: Fix crash if SIGABRT during qtest_init()
  virtio-console-test: Test virtserialport as well
  virtio-console: Fix VIRTIO_CONSOLE() cast macro

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agoMerge remote-tracking branch 'remotes/afaerber/tags/ppc-for-2.0' into staging
Peter Maydell [Thu, 13 Mar 2014 21:27:54 +0000 (21:27 +0000)] 
Merge remote-tracking branch 'remotes/afaerber/tags/ppc-for-2.0' into staging

PowerPC queue for 2.0

* Fixes for -device VGA

# gpg: Signature made Thu 13 Mar 2014 19:57:12 GMT using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg:                 aka "Andreas Färber <afaerber@suse.com>"

* remotes/afaerber/tags/ppc-for-2.0:
  spapr: Fix return value of vga initialization
  Fix vga_interface_type for command line argument '-device VGA'

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agomain-loop: Suppress "I/O thread spun" warnings for qtest
Peter Maydell [Thu, 13 Mar 2014 14:17:29 +0000 (14:17 +0000)] 
main-loop: Suppress "I/O thread spun" warnings for qtest

When running under qtest we don't actually have any vcpu threads
to be starved, so the warning about the I/O thread spinning isn't
relevant, and the way qtest manipulates the simulated clock means
the warning is produced a lot as a false positive. Suppress it if
qtest_enabled(), so 'make check' output is less noisy.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoqtest: Fix crash if SIGABRT during qtest_init()
Stefan Hajnoczi [Thu, 13 Mar 2014 09:41:34 +0000 (10:41 +0100)] 
qtest: Fix crash if SIGABRT during qtest_init()

If an assertion fails during qtest_init() the SIGABRT handler is
invoked.  This is the correct behavior since we need to kill the QEMU
process to avoid leaking it when the test dies.

The global_qtest pointer used by the SIGABRT handler is currently only
assigned after qtest_init() returns.  This results in a segfault if an
assertion failure occurs during qtest_init().

Move global_qtest assignment inside qtest_init().  Not pretty but let's
face it - the signal handler depends on global state.

Reported-by: Marcel Apfelbaum <marcel.a@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: Marcel Apfelbaum <marcel.a@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agovirtio-console-test: Test virtserialport as well
Andreas Färber [Thu, 13 Mar 2014 15:47:24 +0000 (16:47 +0100)] 
virtio-console-test: Test virtserialport as well

A test is only as good as its coverage - testing virtserialport in
addition to virtconsole showed that commit
0399a3819b27083ba69b88a9baa9025facab85bd (virtio-console: QOM cast
cleanup for VirtConsole) broke virtserialport.

Acked-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agovirtio-console: Fix VIRTIO_CONSOLE() cast macro
Andreas Färber [Thu, 13 Mar 2014 16:12:53 +0000 (17:12 +0100)] 
virtio-console: Fix VIRTIO_CONSOLE() cast macro

Commit 0399a3819b27083ba69b88a9baa9025facab85bd (virtio-console: QOM
cast cleanup for VirtConsole) broke virtserialport since it shares
functions and state struct with virtconsole. Let virtconsole inherit
from virtserialport, and use virtserialport type for casting.

Note that virtio-serial-port is the abstract base type in
virtio-serial-bus.c, whereas virtserialport is the user-instantiatable
type in virtio-console.c. Therefore using TYPE_VIRTIO_CONSOLE_SERIAL_PORT.

Reported-by: Richard W.M. Jones <rjones@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoMerge remote-tracking branch 'remotes/afaerber/tags/prep-for-2.0' into staging
Peter Maydell [Thu, 13 Mar 2014 20:09:11 +0000 (20:09 +0000)] 
Merge remote-tracking branch 'remotes/afaerber/tags/prep-for-2.0' into staging

PReP machine and devices

* ppc_rom.bin update
* Raven PCI host bridge preparations for OpenBIOS

# gpg: Signature made Thu 13 Mar 2014 19:28:37 GMT using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg:                 aka "Andreas Färber <afaerber@suse.com>"

* remotes/afaerber/tags/prep-for-2.0:
  raven: Move BIOS loading from board code to PCI host
  prep: Update ppc_rom.bin

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agospapr: Fix return value of vga initialization
Mark Wu [Mon, 10 Mar 2014 14:37:41 +0000 (22:37 +0800)] 
spapr: Fix return value of vga initialization

Before spapr_vga_init will returned false if the vga is specified by
the command '-device VGA' because vga_interface_type was evaluated to
VGA_NONE. With the change in previous patch of this series,
spapr_vga_init should return true if it's told that the vga will be
initialized in flow of the generic devices initialization.

To keep '-nodefaults' have the semantics of bare minimum, it adds a
check of 'has_defaults' in usb_enabled() to avoid that a USB controller
is added by '-nodefautls, -device VGA' implicitly.

This patch also makes two cleanups:
1. skip initialization for VGA_NONE
2. remove the useless 'break'

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoFix vga_interface_type for command line argument '-device VGA'
Mark Wu [Mon, 10 Mar 2014 14:37:40 +0000 (22:37 +0800)] 
Fix vga_interface_type for command line argument '-device VGA'

Some machine (like pseries) initialization code determines if it has
graphics according to vga_interface_type. In the original code,
vga_interface_type is evaluated to VGA_NONE even if a VGA is added
via '-device VGA'. It causes the machine not aware of the graphics
device configured. Add a new VGA device type to indicate that it has a
VGA device, which will be initialized in QOM device initialization.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoraven: Move BIOS loading from board code to PCI host
Hervé Poussineau [Mon, 4 Nov 2013 23:09:45 +0000 (00:09 +0100)] 
raven: Move BIOS loading from board code to PCI host

Raven datasheet explains where firmware lives in system memory, so do
it there instead of in board code. Other boards using the same PCI
host will not have to copy the firmware loading code.

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
[AF: Drop BIOS size workaround in favor of replacing our firmware blob]
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
7 years agoprep: Update ppc_rom.bin
Andreas Färber [Wed, 12 Mar 2014 17:43:01 +0000 (18:43 +0100)] 
prep: Update ppc_rom.bin

This increases file size from 512 KiB to 1 MiB.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
7 years agoMerge remote-tracking branch 'remotes/afaerber/tags/qom-cpu-for-2.0' into staging
Peter Maydell [Thu, 13 Mar 2014 19:13:33 +0000 (19:13 +0000)] 
Merge remote-tracking branch 'remotes/afaerber/tags/qom-cpu-for-2.0' into staging

QOM CPUState refactorings / X86CPU

* Deadlock fix for exit requests around CPU reset
* X86CPU x2apic for KVM
* X86CPU model subclasses
* SPARCCPU preparations for model subclasses
* -cpu arguments for arm, cris, lm32, moxie, openrisc, ppc, sh4, uc32
* m68k assertion cleanups
* CPUClass hooks for cpu.h inline functions
* Field movements from CPU_COMMON to CPUState and follow-up cleanups

# gpg: Signature made Thu 13 Mar 2014 19:06:56 GMT using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <afaerber@suse.de>"
# gpg:                 aka "Andreas Färber <afaerber@suse.com>"

* remotes/afaerber/tags/qom-cpu-for-2.0: (58 commits)
  user-exec: Change exception_action() argument to CPUState
  cputlb: Change tlb_set_page() argument to CPUState
  cputlb: Change tlb_flush() argument to CPUState
  cputlb: Change tlb_flush_page() argument to CPUState
  target-microblaze: Replace DisasContext::env field with MicroBlazeCPU
  target-cris: Replace DisasContext::env field with CRISCPU
  exec: Change cpu_abort() argument to CPUState
  exec: Change memory_region_section_get_iotlb() argument to CPUState
  cputlb: Change tlb_unprotect_code_phys() argument to CPUState
  cpu-exec: Change cpu_resume_from_signal() argument to CPUState
  exec: Change cpu_breakpoint_{insert,remove{,_by_ref,_all}} argument
  exec: Change cpu_watchpoint_{insert,remove{,_by_ref,_all}} argument
  target-ppc: Use PowerPCCPU in PowerPCCPUClass::handle_mmu_fault hook
  translate-all: Change tb_flush_jmp_cache() argument to CPUState
  translate-all: Change tb_gen_code() argument to CPUState
  translate-all: Change cpu_io_recompile() argument to CPUState
  translate-all: Change tb_check_watchpoint() argument to CPUState
  translate-all: Change cpu_restore_state_from_tb() argument to CPUState
  translate-all: Change cpu_restore_state() argument to CPUState
  cpu-exec: Change cpu_loop_exit() argument to CPUState
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agouser-exec: Change exception_action() argument to CPUState
Andreas Färber [Wed, 4 Sep 2013 06:54:24 +0000 (08:54 +0200)] 
user-exec: Change exception_action() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocputlb: Change tlb_set_page() argument to CPUState
Andreas Färber [Tue, 3 Sep 2013 11:59:37 +0000 (13:59 +0200)] 
cputlb: Change tlb_set_page() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocputlb: Change tlb_flush() argument to CPUState
Andreas Färber [Wed, 4 Sep 2013 00:19:44 +0000 (02:19 +0200)] 
cputlb: Change tlb_flush() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocputlb: Change tlb_flush_page() argument to CPUState
Andreas Färber [Tue, 3 Sep 2013 23:29:02 +0000 (01:29 +0200)] 
cputlb: Change tlb_flush_page() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-microblaze: Replace DisasContext::env field with MicroBlazeCPU
Andreas Färber [Tue, 3 Sep 2013 18:02:48 +0000 (20:02 +0200)] 
target-microblaze: Replace DisasContext::env field with MicroBlazeCPU

This cleans up some mb_env_get_cpu() needed for cpu_abort().

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-cris: Replace DisasContext::env field with CRISCPU
Andreas Färber [Tue, 3 Sep 2013 16:42:27 +0000 (18:42 +0200)] 
target-cris: Replace DisasContext::env field with CRISCPU

This cleans up repeated cris_env_get_cpu() for cpu_abort().

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoexec: Change cpu_abort() argument to CPUState
Andreas Färber [Tue, 3 Sep 2013 15:38:47 +0000 (17:38 +0200)] 
exec: Change cpu_abort() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoMerge remote-tracking branch 'remotes/kraxel/tags/pull-input-6' into staging
Peter Maydell [Thu, 13 Mar 2014 18:37:00 +0000 (18:37 +0000)] 
Merge remote-tracking branch 'remotes/kraxel/tags/pull-input-6' into staging

input: activate legacy kbd
gtk: Add mouse wheel support

# gpg: Signature made Thu 13 Mar 2014 10:34:17 GMT using RSA key ID D3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"

* remotes/kraxel/tags/pull-input-6:
  gtk: Add mouse wheel support
  input: activate legacy kbd

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agoexec: Change memory_region_section_get_iotlb() argument to CPUState
Andreas Färber [Tue, 3 Sep 2013 11:32:01 +0000 (13:32 +0200)] 
exec: Change memory_region_section_get_iotlb() argument to CPUState

It no longer needs CPUArchState since moving watchpoints to CPUState.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocputlb: Change tlb_unprotect_code_phys() argument to CPUState
Andreas Färber [Tue, 3 Sep 2013 08:51:26 +0000 (10:51 +0200)] 
cputlb: Change tlb_unprotect_code_phys() argument to CPUState

Note that the argument is unused.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu-exec: Change cpu_resume_from_signal() argument to CPUState
Andreas Färber [Tue, 3 Sep 2013 00:12:23 +0000 (02:12 +0200)] 
cpu-exec: Change cpu_resume_from_signal() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoexec: Change cpu_breakpoint_{insert,remove{,_by_ref,_all}} argument
Andreas Färber [Mon, 2 Sep 2013 15:26:20 +0000 (17:26 +0200)] 
exec: Change cpu_breakpoint_{insert,remove{,_by_ref,_all}} argument

Use CPUState. Allows to clean up CPUArchState in gdbstub.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoexec: Change cpu_watchpoint_{insert,remove{,_by_ref,_all}} argument
Andreas Färber [Mon, 2 Sep 2013 14:57:02 +0000 (16:57 +0200)] 
exec: Change cpu_watchpoint_{insert,remove{,_by_ref,_all}} argument

Use CPUState. This lets us drop a few local env usages.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-ppc: Use PowerPCCPU in PowerPCCPUClass::handle_mmu_fault hook
Andreas Färber [Mon, 2 Sep 2013 12:14:24 +0000 (14:14 +0200)] 
target-ppc: Use PowerPCCPU in PowerPCCPUClass::handle_mmu_fault hook

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotranslate-all: Change tb_flush_jmp_cache() argument to CPUState
Andreas Färber [Sun, 1 Sep 2013 15:52:07 +0000 (17:52 +0200)] 
translate-all: Change tb_flush_jmp_cache() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotranslate-all: Change tb_gen_code() argument to CPUState
Andreas Färber [Sun, 1 Sep 2013 15:43:17 +0000 (17:43 +0200)] 
translate-all: Change tb_gen_code() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotranslate-all: Change cpu_io_recompile() argument to CPUState
Andreas Färber [Sun, 1 Sep 2013 15:21:47 +0000 (17:21 +0200)] 
translate-all: Change cpu_io_recompile() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotranslate-all: Change tb_check_watchpoint() argument to CPUState
Andreas Färber [Sun, 1 Sep 2013 15:12:23 +0000 (17:12 +0200)] 
translate-all: Change tb_check_watchpoint() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotranslate-all: Change cpu_restore_state_from_tb() argument to CPUState
Andreas Färber [Sun, 1 Sep 2013 15:02:58 +0000 (17:02 +0200)] 
translate-all: Change cpu_restore_state_from_tb() argument to CPUState

And normalize the argument order.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotranslate-all: Change cpu_restore_state() argument to CPUState
Andreas Färber [Sun, 1 Sep 2013 14:51:34 +0000 (16:51 +0200)] 
translate-all: Change cpu_restore_state() argument to CPUState

This lets us drop some local variables in tlb_fill() functions.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu-exec: Change cpu_loop_exit() argument to CPUState
Andreas Färber [Tue, 27 Aug 2013 15:52:12 +0000 (17:52 +0200)] 
cpu-exec: Change cpu_loop_exit() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoexec: Change tlb_fill() argument to CPUState
Andreas Färber [Mon, 26 Aug 2013 22:28:06 +0000 (00:28 +0200)] 
exec: Change tlb_fill() argument to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move breakpoints field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 19:22:53 +0000 (21:22 +0200)] 
cpu: Move breakpoints field from CPU_COMMON to CPUState

Most targets were using offsetof(CPUFooState, breakpoints) to determine
how much of CPUFooState to clear on reset. Use the next field after
CPU_COMMON instead, if any, or sizeof(CPUFooState) otherwise.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move watchpoint fields from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 16:23:18 +0000 (18:23 +0200)] 
cpu: Move watchpoint fields from CPU_COMMON to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move opaque field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 16:14:44 +0000 (18:14 +0200)] 
cpu: Move opaque field from CPU_COMMON to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move exception_index field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 06:31:06 +0000 (08:31 +0200)] 
cpu: Move exception_index field from CPU_COMMON to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move jmp_env field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 04:22:03 +0000 (06:22 +0200)] 
cpu: Move jmp_env field from CPU_COMMON to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move tb_jmp_cache field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 04:03:38 +0000 (06:03 +0200)] 
cpu: Move tb_jmp_cache field from CPU_COMMON to CPUState

Clear it on reset.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move icount_decr field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 03:51:49 +0000 (05:51 +0200)] 
cpu: Move icount_decr field from CPU_COMMON to CPUState

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move icount_extra field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 03:39:29 +0000 (05:39 +0200)] 
cpu: Move icount_extra field from CPU_COMMON to CPUState

Reset it.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move can_do_io field from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 03:15:23 +0000 (05:15 +0200)] 
cpu: Move can_do_io field from CPU_COMMON to CPUState

Rename can_do_io() to cpu_can_do_io() and change argument to CPUState.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Move mem_io_{pc,vaddr} fields from CPU_COMMON to CPUState
Andreas Färber [Mon, 26 Aug 2013 01:41:01 +0000 (03:41 +0200)] 
cpu: Move mem_io_{pc,vaddr} fields from CPU_COMMON to CPUState

Reset them.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Turn cpu_handle_mmu_fault() into a CPUClass hook
Andreas Färber [Mon, 26 Aug 2013 01:01:33 +0000 (03:01 +0200)] 
cpu: Turn cpu_handle_mmu_fault() into a CPUClass hook

Note that while such functions may exist both for *-user and softmmu,
only *-user uses the CPUState hook, while softmmu reuses the prototype
for calling it directly.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-m68k: Remove custom qemu_assert() function
Peter Maydell [Wed, 12 Mar 2014 13:24:49 +0000 (13:24 +0000)] 
target-m68k: Remove custom qemu_assert() function

Remove the custom qemu_assert() function defined by target-m68k/translate.c
in favour of either using glib g_assert_not_reached() (for the genuinely
can't-happen cases) or cpu_abort() (for the "this isn't implemented",
in line with other unimplemented cases in the target).

This has the benefit of silencing some clang warnings about
variables used while uninitialized (which are emitted because
clang can't figure out that qemu_assert(0, something) never
returns.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Factor out cpu_generic_init()
Andreas Färber [Tue, 4 Mar 2014 02:17:10 +0000 (03:17 +0100)] 
cpu: Factor out cpu_generic_init()

All targets using it gain the ability to set -cpu name,key=value,...
options via the default TYPE_CPU CPUClass::parse_features() implementation.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Implement CPUClass::parse_features() for the rest of CPUs
Andreas Färber [Mon, 3 Mar 2014 22:33:51 +0000 (23:33 +0100)] 
cpu: Implement CPUClass::parse_features() for the rest of CPUs

CPUs who do not provide their own implementation of feature parsing
will treat each option as a QOM property and set it to the supplied
value.

Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-sparc: Defer SPARCCPU feature inference to QOM realize
Andreas Färber [Tue, 4 Mar 2014 00:26:33 +0000 (01:26 +0100)] 
target-sparc: Defer SPARCCPU feature inference to QOM realize

Gets it out of cpu_sparc_register() and aligns with target-arm.

Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-sparc: Implement CPUClass::parse_features() for SPARCCPU
Andreas Färber [Mon, 3 Mar 2014 23:38:58 +0000 (00:38 +0100)] 
target-sparc: Implement CPUClass::parse_features() for SPARCCPU

Factor cpu_model parsing out of cpu_sparc_find_by_name() by passing
cpu_sparc_find_by_name() the name portion only and calling
CPUClass::parse_features() from cpu_sparc_register() afterwards.

Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-sparc: Use error_report() for CPU error reporting
Andreas Färber [Mon, 3 Mar 2014 22:47:54 +0000 (23:47 +0100)] 
target-sparc: Use error_report() for CPU error reporting

Replace non-debug fprintf() with error_report().

Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Introduce CPUClass::parse_features() hook
Andreas Färber [Mon, 3 Mar 2014 22:19:19 +0000 (23:19 +0100)] 
cpu: Introduce CPUClass::parse_features() hook

Adapt the X86CPU implementation to suit the generic hook.
This involves a cleanup of error handling to cope with NULL errp.

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: X86CPU model subclasses
Eduardo Habkost [Mon, 10 Feb 2014 10:21:30 +0000 (08:21 -0200)] 
target-i386: X86CPU model subclasses

Register separate QOM types for each x86 CPU model.

This will allow management code to more easily probe what each CPU model
provides, by simply creating objects using the appropriate class name,
without having to restart QEMU.

This also allows us to eliminate the qdev_prop_set_globals_for_type()
hack to set CPU-model-specific global properties.

Instead of creating separate class_init functions for each class, I just
used class_data to store a pointer to the X86CPUDefinition struct for
each CPU model. This should make the patch shorter and easier to review.
Later we can gradually convert each X86CPUDefinition field to lists of
per-class property defaults.

The "host" CPU model is special, as the feature flags depend on KVM
being initialized. So it has its own class_init and instance_init
function, and feature flags are set on instance_init instead of
class_init.

Signed-off-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Tested-by: Eduardo Habkost <ehabkost@redhat.com>
[AF: Limit the host CPU type to CONFIG_KVM as build fix]
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Prepare CPUClass::class_by_name for X86CPU
Andreas Färber [Mon, 10 Feb 2014 21:02:44 +0000 (22:02 +0100)] 
target-i386: Prepare CPUClass::class_by_name for X86CPU

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Tested-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Enable x2apic by default on KVM
Eduardo Habkost [Wed, 19 Feb 2014 14:58:12 +0000 (11:58 -0300)] 
target-i386: Enable x2apic by default on KVM

When on KVM mode, enable x2apic by default on all CPU models.

Normally we try to keep the CPU model definitions as close as the real
CPUs as possible, but x2apic can be emulated by KVM without host CPU
support for x2apic, and it improves performance by reducing APIC access
overhead. x2apic emulation is available on KVM since 2009 (Linux
2.6.32-rc1), there's no reason for not enabling x2apic by default when
running KVM.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Introduce x86_cpu_compat_disable_kvm_features()
Eduardo Habkost [Wed, 19 Feb 2014 14:58:11 +0000 (11:58 -0300)] 
target-i386: Introduce x86_cpu_compat_disable_kvm_features()

Instead of the feature-specific disable_kvm_pv_eoi() function, create a
more general function that can be used to disable other feature bits in
machine-type compat code.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Make kvm_default_features an array
Eduardo Habkost [Wed, 19 Feb 2014 14:58:10 +0000 (11:58 -0300)] 
target-i386: Make kvm_default_features an array

We will later make the KVM-specific code affect other feature words,
too.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Don't declare variables in the middle of blocks
Eduardo Habkost [Wed, 19 Feb 2014 19:39:21 +0000 (16:39 -0300)] 
target-i386: Don't declare variables in the middle of blocks

Some of my recent changes introduced variable declarations in the middle
of code blocks.

Fix the code so that it compiles without warnings when using
-Wdeclaration-after-statement.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Rename x86_def_t to X86CPUDefinition
Eduardo Habkost [Thu, 30 Jan 2014 19:48:58 +0000 (17:48 -0200)] 
target-i386: Rename x86_def_t to X86CPUDefinition

As the new X86CPU subclass code is going to change lots of the code
invoving x86_def_t, let's rename the struct to match coding style first.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Call x86_cpu_load_def() earlier
Eduardo Habkost [Thu, 30 Jan 2014 19:48:57 +0000 (17:48 -0200)] 
target-i386: Call x86_cpu_load_def() earlier

As we will initialize the X86CPU fields on instance_init eventually,
move the code that initializes the X86CPU data based on the CPU model
name closer to the object_new() call.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Rename cpu_x86_register() to x86_cpu_load_def()
Eduardo Habkost [Thu, 30 Jan 2014 19:48:56 +0000 (17:48 -0200)] 
target-i386: Rename cpu_x86_register() to x86_cpu_load_def()

There isn't any kind of "registration" involved in cpu_x86_register()
anymore: it is simply looking up a CPU model name and loading the model
definition data into the X86CPU object. Rename it to x86_cpu_load_def()
to reflect what it does.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Turn cpu_has_work() into a CPUClass hook
Andreas Färber [Sun, 25 Aug 2013 16:53:55 +0000 (18:53 +0200)] 
cpu: Turn cpu_has_work() into a CPUClass hook

Default to false.

Tidy variable naming and inline cast uses while at it.

Tested-by: Jia Liu <proljc@gmail.com> (or32)
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-xtensa: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 19:02:29 +0000 (20:02 +0100)] 
target-xtensa: Clean up ENV_GET_CPU() usage

Commits a00817cc4c18b7872e92765a4736fb2227cc237b and
fdfba1a298ae26dd44bcfdb0429314139a0bc55a added usages of ENV_GET_CPU()
macro in target-specific code.

Use xtensa_env_get_cpu() instead.

Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-unicore32: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 18:58:13 +0000 (19:58 +0100)] 
target-unicore32: Clean up ENV_GET_CPU() usage

Commit fdfba1a298ae26dd44bcfdb0429314139a0bc55a added a usage of
ENV_GET_CPU() macro in target-specific code.

Use uc32_env_get_cpu() instead.

Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-sparc: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 18:51:00 +0000 (19:51 +0100)] 
target-sparc: Clean up ENV_GET_CPU() usage

Commits fdfba1a298ae26dd44bcfdb0429314139a0bc55a,
2c17449b3022ca9623c4a7e2a504a4150ac4ad30 and
f606604f1c10b60ef294f1b9b229426521a365e3 added usages of ENV_GET_CPU()
macro in target-specific code.

Use sparc_env_get_cpu() instead and reuse the variables.

Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-s390x: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 18:40:08 +0000 (19:40 +0100)] 
target-s390x: Clean up ENV_GET_CPU() usage

Commits f606604f1c10b60ef294f1b9b229426521a365e3,
2c17449b3022ca9623c4a7e2a504a4150ac4ad30 and
5ce5944dc0ffdc43c11b5cad11e526f699aabe4c added usages of ENV_GET_CPU()
macro in target-specific code.

Use s390_env_get_cpu() instead.

Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-ppc: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 18:29:41 +0000 (19:29 +0100)] 
target-ppc: Clean up ENV_GET_CPU() usage

Commits fdfba1a298ae26dd44bcfdb0429314139a0bc55a,
ab1da85791340e504d10487e1add81b9988afa98,
f606604f1c10b60ef294f1b9b229426521a365e3 and
2c17449b3022ca9623c4a7e2a504a4150ac4ad30 added usages of ENV_GET_CPU()
macro in target-specific code.

Use ppc_env_get_cpu() instead.

Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-i386: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 18:15:27 +0000 (19:15 +0100)] 
target-i386: Clean up ENV_GET_CPU() usage

Commits fdfba1a298ae26dd44bcfdb0429314139a0bc55a,
f606604f1c10b60ef294f1b9b229426521a365e3 and
2c17449b3022ca9623c4a7e2a504a4150ac4ad30 added usages of ENV_GET_CPU()
macro in target-specific code.

Use x86_env_get_cpu() or reuse existing X86CPU variable instead.

Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-arm: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 18:10:29 +0000 (19:10 +0100)] 
target-arm: Clean up ENV_GET_CPU() usage

Commits ab1da85791340e504d10487e1add81b9988afa98,
fdfba1a298ae26dd44bcfdb0429314139a0bc55a,
2c17449b3022ca9623c4a7e2a504a4150ac4ad30 added usages of ENV_GET_CPU()
macro to target-specific code.

Use arm_env_get_cpu() instead and enforce separating variable
declarations.

Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agotarget-alpha: Clean up ENV_GET_CPU() usage
Andreas Färber [Sun, 9 Mar 2014 17:58:57 +0000 (18:58 +0100)] 
target-alpha: Clean up ENV_GET_CPU() usage

Commits 2c17449b3022ca9623c4a7e2a504a4150ac4ad30,
fdfba1a298ae26dd44bcfdb0429314139a0bc55a,
ab1da85791340e504d10487e1add81b9988afa98 and
f606604f1c10b60ef294f1b9b229426521a365e3 added usages of ENV_GET_CPU()
macro in target-specific code.

Use alpha_env_get_cpu() instead.

Cc: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agocpu: Don't clear cpu->exit_request on reset
Edgar E. Iglesias [Thu, 13 Feb 2014 05:07:14 +0000 (15:07 +1000)] 
cpu: Don't clear cpu->exit_request on reset

cpu->exit_request is part of the execution environment and should
not be cleared when a CPU resets.

Otherwise, we might deadlock QEMU if a CPU resets while there is
I/O going on.

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
7 years agoMerge remote-tracking branch 'remotes/kraxel/tags/pull-chardev-1' into staging
Peter Maydell [Thu, 13 Mar 2014 17:19:14 +0000 (17:19 +0000)] 
Merge remote-tracking branch 'remotes/kraxel/tags/pull-chardev-1' into staging

char: restore read callback on a reattached (hotplug) chardev

# gpg: Signature made Thu 13 Mar 2014 10:29:34 GMT using RSA key ID D3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"

* remotes/kraxel/tags/pull-chardev-1:
  char: restore read callback on a reattached (hotplug) chardev

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agoMerge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging
Peter Maydell [Thu, 13 Mar 2014 15:33:04 +0000 (15:33 +0000)] 
Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging

Block pull request

# gpg: Signature made Thu 13 Mar 2014 13:50:49 GMT using RSA key ID 81AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>"
# gpg: WARNING: This key is not certified with a trusted signature!
# gpg:          There is no indication that the signature belongs to the owner.
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35  775A 9CA4 ABB3 81AB 73C8

* remotes/stefanha/tags/block-pull-request: (24 commits)
  block/raw-win32: bdrv_parse_filename() for hdev
  block/raw-posix: Strip protocol prefix on creation
  block/raw-posix: bdrv_parse_filename() for cdrom
  block/raw-posix: bdrv_parse_filename() for floppy
  block/raw-posix: bdrv_parse_filename() for hdev
  qemu-io: Fix warnings from static code analysis
  block: Unlink temporary file
  qcow2: Don't write with BDRV_O_INCOMING
  qcow2: Keep option in qcow2_invalidate_cache()
  qmp: add query-iothreads command
  iothread: stash thread ID away
  dataplane: replace internal thread with IOThread
  iothread: add "iothread" qdev property type
  qdev: make get_pointer() handle temporary strings
  iothread: add I/O thread object
  aio: add aio_context_acquire() and aio_context_release()
  rfifolock: add recursive FIFO lock
  object: add object_get_canonical_path_component()
  block: Rewrite the snapshot authorization mechanism for block filters.
  iotests: Test corruption during COW request
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agooslib-posix: Fix build on FreeBSD
Andreas Färber [Thu, 13 Mar 2014 13:27:59 +0000 (14:27 +0100)] 
oslib-posix: Fix build on FreeBSD

Commit 10f5bff622cad71645e22c027b77ac31e51008ef (util: Split out
exec_dir from os_find_datadir) moved code from os-posix.c to
util/oslib-posix.c but forgot to move a FreeBSD #include alongside,
needed for CTL_KERN among others.

Cc: Fam Zheng <famz@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
Message-id: 1394717279-23406-1-git-send-email-andreas.faerber@web.de
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7 years agoblock/raw-win32: bdrv_parse_filename() for hdev
Max Reitz [Fri, 7 Mar 2014 23:39:45 +0000 (00:39 +0100)] 
block/raw-win32: bdrv_parse_filename() for hdev

The "host_device" protocol driver should strip the "host_device:" prefix
from filenames if present.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock/raw-posix: Strip protocol prefix on creation
Max Reitz [Fri, 7 Mar 2014 23:39:44 +0000 (00:39 +0100)] 
block/raw-posix: Strip protocol prefix on creation

The hdev_create() implementation in block/raw-posix.c is used by the
"host_device", "host_cdrom" and "host_floppy" protocol block drivers
together. Thus, any of the associated prefixes may occur and exactly one
should should be stripped, if it does (thus,
"host_device:host_cdrom:/dev/cdrom" is not shortened to "/dev/cdrom").

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock/raw-posix: bdrv_parse_filename() for cdrom
Max Reitz [Fri, 7 Mar 2014 23:39:43 +0000 (00:39 +0100)] 
block/raw-posix: bdrv_parse_filename() for cdrom

The "host_cdrom" protocol drivers should strip the "host_cdrom:" prefix
from filenames if present.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock/raw-posix: bdrv_parse_filename() for floppy
Max Reitz [Fri, 7 Mar 2014 23:39:42 +0000 (00:39 +0100)] 
block/raw-posix: bdrv_parse_filename() for floppy

The "host_floppy" protocol driver should strip the "host_floppy:" prefix
from filenames if present.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock/raw-posix: bdrv_parse_filename() for hdev
Max Reitz [Fri, 7 Mar 2014 23:39:41 +0000 (00:39 +0100)] 
block/raw-posix: bdrv_parse_filename() for hdev

The "host_device" protocol driver should strip the "host_device:" prefix
from filenames if present.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoqemu-io: Fix warnings from static code analysis
Stefan Weil [Wed, 5 Mar 2014 21:23:00 +0000 (22:23 +0100)] 
qemu-io: Fix warnings from static code analysis

Smatch complains about several global symbols which should be local.

Add the missing 'static' attributes and move the 'extern' declaration
of variable qemuio_misalign to qemu-io.h. This variable also changes
the type from 'int' to 'bool' which better fits documents its use.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock: Unlink temporary file
Max Reitz [Sat, 15 Feb 2014 17:03:21 +0000 (18:03 +0100)] 
block: Unlink temporary file

If the image file cannot be opened and was created as a temporary file,
it should be deleted; thus, in this case, we should jump to the
"unlink_and_fail" label and not just to "fail".

Reported-by: Benoît Canet <benoit@irqsave.net>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoqcow2: Don't write with BDRV_O_INCOMING
Kevin Wolf [Tue, 11 Mar 2014 14:15:03 +0000 (15:15 +0100)] 
qcow2: Don't write with BDRV_O_INCOMING

qcow2_open() causes writes when repairing an image with the dirty flag
set and when clearing autoclear flags. It shouldn't do this when another
qemu instance is still actively working on this image file.

One effect of the bug is that images may have a cleared dirty flag while
the migration source host still has it in use with lazy refcounts
enabled, so refcounts are not accurate and the dirty flag must remain
set.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoqcow2: Keep option in qcow2_invalidate_cache()
Kevin Wolf [Tue, 11 Mar 2014 16:42:41 +0000 (17:42 +0100)] 
qcow2: Keep option in qcow2_invalidate_cache()

Instead of manually building a list of all options from BDRVQcowState
values just reuse the options that were used to open the image.
qcow2_open() won't fully use all of the options in the QDict, but that's
okay.

This fixes all of the driver-specific options in qcow2, except for
lazy-refcounts, which was special cased before.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoqmp: add query-iothreads command
Stefan Hajnoczi [Thu, 27 Feb 2014 10:48:42 +0000 (11:48 +0100)] 
qmp: add query-iothreads command

The "query-iothreads" command returns a list of information about
iothreads.  See the patch for API documentation.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoiothread: stash thread ID away
Stefan Hajnoczi [Thu, 27 Feb 2014 10:48:41 +0000 (11:48 +0100)] 
iothread: stash thread ID away

Keep the thread ID around so we can report it via QMP.

There's only one problem: qemu_get_thread_id() (gettid() wrapper on
Linux) must be called from the thread itself.  There is no way to get
the thread ID outside the thread.

This patch uses a condvar to wait for iothread_run() to populate the
thread_id inside the thread.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agodataplane: replace internal thread with IOThread
Stefan Hajnoczi [Mon, 3 Mar 2014 10:30:08 +0000 (11:30 +0100)] 
dataplane: replace internal thread with IOThread

Today virtio-blk dataplane uses a 1:1 device-per-thread model.  Now that
IOThreads have been introduced we can generalize this to N:M devices per
threads.

This patch drops thread code from dataplane in favor of running inside
an IOThread AioContext.

As a bonus we solve the case where a guest keeps submitting I/O requests
while dataplane is trying to stop.  Previously the dataplane thread
would continue to process requests until the request gave it a break.
Now we can shut down in bounded time thanks to
aio_context_acquire/release.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoiothread: add "iothread" qdev property type
Stefan Hajnoczi [Mon, 3 Mar 2014 10:30:07 +0000 (11:30 +0100)] 
iothread: add "iothread" qdev property type

Add a "iothread" qdev property type so devices can be hooked up to an
IOThread from the comand-line:

  qemu -object iothread,id=iothread0 \
       -device some-device,x-iothread=iothread0

Note that Paolo Bonzini <pbonzini@redhat.com> has suggested using QOM
links instead.  This way the relationship between the objects is
reflected in QOM.  There are currently shortcomings of
object_property_add_link() which prevent this use case.  I will attempt
to fix them and move to QOM links in a separate series.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoqdev: make get_pointer() handle temporary strings
Igor Mammedov [Mon, 3 Mar 2014 10:30:06 +0000 (11:30 +0100)] 
qdev: make get_pointer() handle temporary strings

get_pointer()'s print() callback might return a heap allocated
string, to avoid adding dedicated get_pointer_foo for this case
convert current print() callbacks to return temporary heap
allocated string and make get_pointer() free it.

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoiothread: add I/O thread object
Stefan Hajnoczi [Mon, 3 Mar 2014 10:30:05 +0000 (11:30 +0100)] 
iothread: add I/O thread object

This is a stand-in for Michael Roth's QContext.  I expect this to be
replaced once QContext is completed.

The IOThread object is an AioContext event loop thread.  This patch adds
the concept of multiple event loop threads, allowing users to define
them.

When SMP guests run on SMP hosts it makes sense to instantiate multiple
IOThreads.  This spreads event loop processing across multiple cores.
Note that additional patches are required to actually bind a device to
an IOThread.

[Andreas Färber <afaerber@suse.de> pointed out that the embedded parent
object instance should be called "parent_obj" and have a newline
afterwards.  This patch has been changed to reflect this.
-- Stefan]

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoaio: add aio_context_acquire() and aio_context_release()
Stefan Hajnoczi [Mon, 3 Mar 2014 10:30:04 +0000 (11:30 +0100)] 
aio: add aio_context_acquire() and aio_context_release()

It can be useful to run an AioContext from a thread which normally does
not "own" the AioContext.  For example, request draining can be
implemented by acquiring the AioContext and looping aio_poll() until all
requests have been completed.

The following pattern should work:

  /* Event loop thread */
  while (running) {
      aio_context_acquire(ctx);
      aio_poll(ctx, true);
      aio_context_release(ctx);
  }

  /* Another thread */
  aio_context_acquire(ctx);
  bdrv_read(bs, 0x1000, buf, 1);
  aio_context_release(ctx);

This patch implements aio_context_acquire() and aio_context_release().

Note that existing aio_poll() callers do not need to worry about
acquiring and releasing - it is only needed when multiple threads will
call aio_poll() on the same AioContext.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agorfifolock: add recursive FIFO lock
Stefan Hajnoczi [Mon, 3 Mar 2014 10:30:03 +0000 (11:30 +0100)] 
rfifolock: add recursive FIFO lock

QemuMutex does not guarantee fairness and cannot be acquired
recursively:

Fairness means each locker gets a turn and the scheduler cannot cause
starvation.

Recursive locking is useful for composition, it allows a sequence of
locking operations to be invoked atomically by acquiring the lock around
them.

This patch adds RFifoLock, a recursive lock that guarantees FIFO order.
Its first user is added in the next patch.

RFifoLock has one additional feature: it can be initialized with an
optional contention callback.  The callback is invoked whenever a thread
must wait for the lock.  For example, it can be used to poke the current
owner so that they release the lock soon.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoobject: add object_get_canonical_path_component()
Stefan Hajnoczi [Mon, 3 Mar 2014 10:30:02 +0000 (11:30 +0100)] 
object: add object_get_canonical_path_component()

It is often useful to find an object's child property name.  Also use
this new function to simplify the implementation of
object_get_canonical_path().

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock: Rewrite the snapshot authorization mechanism for block filters.
Benoît Canet [Mon, 3 Mar 2014 18:11:34 +0000 (19:11 +0100)] 
block: Rewrite the snapshot authorization mechanism for block filters.

This patch keep the recursive way of doing things but simplify it by giving
two responsabilities to all block filters implementors.

They will need to do two things:

-Set the is_filter field of their block driver to true.

-Implement the bdrv_recurse_is_first_non_filter method of their block driver like
it is done on the Quorum block driver. (block/quorum.c)

[Paolo Bonzini <pbonzini@redhat.com> pointed out that this patch changes
the semantics of blkverify, which now recurses down both bs->file and
s->test_file.
-- Stefan]

Reported-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Benoit Canet <benoit@irqsave.net>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoiotests: Test corruption during COW request
Max Reitz [Mon, 10 Mar 2014 22:44:09 +0000 (23:44 +0100)] 
iotests: Test corruption during COW request

Extend test file 060 by a test case for corruption occuring concurrently
to a COW request. QEMU should not crash but rather return an appropriate
error message.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock: bs->drv may be NULL in bdrv_debug_resume()
Max Reitz [Mon, 10 Mar 2014 22:44:08 +0000 (23:44 +0100)] 
block: bs->drv may be NULL in bdrv_debug_resume()

Currently, bdrv_debug_resume() requires every bs->drv in the BDS stack
to be NULL until a bs->drv with an implementation of bdrv_debug_resume()
is found. For a normal function, this would be fine, but this is a
function for debugging purposes and should therefore allow intermediate
BDS not to have a driver (i.e., be "ejected"). Otherwise, it is hard to
debug such situations.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoqcow2: Check bs->drv in copy_sectors()
Max Reitz [Mon, 10 Mar 2014 22:44:07 +0000 (23:44 +0100)] 
qcow2: Check bs->drv in copy_sectors()

Before dereferencing bs->drv for a call to its member bdrv_co_readv(),
copy_sectors() should check whether that pointer is indeed valid, since
it may have been set to NULL by e.g. a concurrent write triggering the
corruption prevention mechanism.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoblock: Update image size in bdrv_invalidate_cache()
Kevin Wolf [Tue, 11 Mar 2014 09:58:39 +0000 (10:58 +0100)] 
block: Update image size in bdrv_invalidate_cache()

After migration has completed, we call bdrv_invalidate_cache() so that
drivers which cache some data drop their stale copy of the data and
reread it from the image file to get a new version of data that the
source modified while the migration was running.

Reloading metadata from the image file is useless, though, if the size
of the image file stays stale (this is a value that is cached for all
image formats in block.c). Reads from (meta)data after the old EOF
return only zeroes, causing image corruption.

We need to update bs->total_sectors in all layers that could potentially
have changed their size (i.e. backing files are not a concern - if they
are changed, we're in bigger trouble)

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
7 years agoqcow2-refcount: Sanitize refcount table entry
Max Reitz [Fri, 7 Mar 2014 22:10:12 +0000 (23:10 +0100)] 
qcow2-refcount: Sanitize refcount table entry

When reading the refcount table entry in get_refcount(), only bits which
are actually significant for the refcount block offset should be taken
into account.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>