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.
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.
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 <[email protected]>"
# gpg: aka "Andreas Färber <[email protected]>"
* 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
...
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 <[email protected]>"
# gpg: aka "Stefan Hajnoczi <[email protected]>"
# 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
...
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.
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").
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.
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".
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.
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.
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.
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.
Note that Paolo Bonzini <[email protected]> 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.
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.
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 <[email protected]> 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]
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.
/* 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.
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.
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 <[email protected]> pointed out that this patch changes
the semantics of blkverify, which now recurses down both bs->file and
s->test_file.
-- Stefan]
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.
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.
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.
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)
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.
Peter Maydell [Thu, 13 Mar 2014 12:32:47 +0000 (12:32 +0000)]
Merge remote-tracking branch 'remotes/afaerber/tags/qom-devices-for-peter' into staging
QOM/QTest infrastructure fixes and device conversions
* QTest cleanups and test cases for some virtio devices
* QTest for sPAPR PCI host bridge
* qom-test now tests reading all properties beneath /machine
* QOM API leak fixes
* QOM cleanups for SSI devices
* QOM conversion of QEMUMachine
* QOM realize for buses
* sPAPR PCI bus name change
# gpg: Signature made Thu 13 Mar 2014 00:22:40 GMT using RSA key ID 3E7E013F
# gpg: Good signature from "Andreas Färber <[email protected]>"
# gpg: aka "Andreas Färber <[email protected]>"
* remotes/afaerber/tags/qom-devices-for-peter: (31 commits)
libqtest: Fix possible deadlock in qtest initialization
pci: Move VMState registration/unregistration to QOM realize/unrealize
qdev: Realize buses on device realization
qdev: Prepare realize/unrealize hooks for BusState
tests: Add spapr-pci-host-bridge qtest
virtio-serial-port: Convert to QOM realize/unrealize
virtio-console: QOM cast cleanup for VirtConsole
tests: Add virtio-console qtest
tests: Add virtio-serial qtest
tests: Add virtio-scsi qtest
tests: Add virtio-rng qtest
tests: Add virtio-balloon qtest
tests: Add virtio-blk qtest
tests: Clean up IndustryPack TPCI200 gcov paths
qom-test: Test QOM properties
hw/boards: Convert current_machine to MachineState
vl: Use MachineClass instead of global QEMUMachine list
hw/core: Introduce QEMU machine as QOM object
qdev-monitor-test: Don't test human-readable error message
qdev-monitor-test: Simplify using g_assert_cmpstr()
...
Peter Maydell [Thu, 13 Mar 2014 11:24:15 +0000 (11:24 +0000)]
libqtest: Avoid inline varargs functions
Older versions of gcc (eg 4.6) can't handle varargs functions declared
inline for anything other than completely trivial uses, and complain:
tests/qom-test.c: In function 'qmp': tests/libqtest.h:359:60: sorry,
unimplemented: function 'qmp' can never be inlined because it uses
variable argument lists
Avoid this problem by putting the functions into libqtest.c instead
of using inline definitions in libqtest.h.
Gal Hammer [Tue, 25 Feb 2014 10:12:35 +0000 (12:12 +0200)]
char: restore read callback on a reattached (hotplug) chardev
Fix a bug that was introduced in commit 386a5a1e. A removal of a device
set the chr handlers to NULL. However when the device is plugged back,
its read callback is not restored so data can't be transferred from the
host to the guest (e.g. via the virtio-serial port).
This converts the old-style SysBusDevice::init() callback to a new-style
DeviceClass::realize() callback.
As a part of conversion, this replaces fprintf(stderr) with error_setg()
as realize() does not "return" any value, instead it puts the extended
error into **errp.
Currently interrupt priorities are set to 0 (highest) at the very
beginning of the guest execution which is not correct and makes the guest
produce random interrupt error messages such as:
"Interrupt 0x1001 (real) is invalid, disabling it".
This also prevents interrupt states from correct migration.
This initializes priority to 0xFF as the emulated XICS does.
pseries: Update SLOF firmware image to qemu-slof-20140304
The changelog is:
> version: update to 20140304
> Introduce dummy console device
> vio-vscsi: Fix CRQ allocation alignment
> version: update to 20140204
> virtio-9p: disable unused structure
> Make "boot net:dhcp" boot from IPv4 only
> Fix virtio device shutdown
> Change shutdown method name for virtio-scsi
> Add support for 64bit LE ABI v1 and v2 support
> Change representation of string environment variable
> cas: return error when unknown node found
> version: update
> Reset obp-tftp arguments before parsing
> Enable seamless netboot on IPv6 network
> Fix shutdown for virtio devices
> Fix zero checksum in UDP header
> Handle router advertisement message properly
> [oex]hci_exit: Check before freeing/unmapping memory
> Work around missing sc 1 traps on pHyp
> fix print_version() to return where it came from
> usb-xhci: memory freeing and using returns as bool uniformly
> Output banner and initial display output in VNC window
> use VERSION file to generate FW version
> cas: remove warning
> Add support for loading little endian ELF binaries.
> Add bswap_{16,32,64}p
> dhcpv6 and other minor net-snk fixes
> Fix missing drop in virtio-fs setup-alias
> Find next available alias name
> SLOF does not exit if given 1KB disk
> boot: enable support for bootindex
> pci-properties: add properties to enable hotplug for spapr
> e1000: remember node handle
> Increase quiesce tokens array size
> virtio: timeout after 5sec
> Enable IPv6 support in dns
> usb-ohci: fix warnings
> Add ipv6 support in net-snk
> ipv4: fix frame overwriting following arp_send_request
> e1000: fix SLOF_dma_map_out arguments
> Maintain single global packet buffer for tftp
> Increase virtio-net receive queue size
> Increase veth receive queue size
> Fix dprintf macros at various points
> usb-ohci: rewrite done_head processing code
> boot: add net in default boot order
> block 0 address in the allocator
> scsi: make-media-alias fix
> usb-xhci: add xhci host controller support
> usb-xhci: add xhci support
> Avoid veth read/write calls with zero length buffer
> boot: include other aliases
> usb-core: disable xhci
Marcel Apfelbaum [Tue, 11 Mar 2014 13:00:34 +0000 (15:00 +0200)]
libqtest: Fix possible deadlock in qtest initialization
'socket_accept' waits for QEMU to init its unix socket.
If QEMU encounters an error during command line parsing,
it can exit before initializing the communication channel.