2008-12-04 20:52:44 +01:00
|
|
|
/*
|
|
|
|
* Virtio Block Device
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2007
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-06-29 13:47:03 +02:00
|
|
|
#ifndef QEMU_VIRTIO_BLK_H
|
|
|
|
#define QEMU_VIRTIO_BLK_H
|
2008-12-04 20:52:44 +01:00
|
|
|
|
2015-02-16 22:36:03 +01:00
|
|
|
#include "standard-headers/linux/virtio_blk.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/virtio/virtio.h"
|
|
|
|
#include "hw/block/block.h"
|
2014-03-03 11:30:08 +01:00
|
|
|
#include "sysemu/iothread.h"
|
2014-10-07 13:59:18 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2008-12-04 20:52:44 +01:00
|
|
|
|
2013-04-09 12:04:48 +02:00
|
|
|
#define TYPE_VIRTIO_BLK "virtio-blk-device"
|
2013-03-18 17:37:22 +01:00
|
|
|
#define VIRTIO_BLK(obj) \
|
|
|
|
OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
|
|
|
|
|
2009-04-23 12:58:51 +02:00
|
|
|
/* This is the last element of the write scatter-gather list */
|
2008-12-04 20:52:44 +01:00
|
|
|
struct virtio_blk_inhdr
|
|
|
|
{
|
|
|
|
unsigned char status;
|
|
|
|
};
|
|
|
|
|
2020-08-18 16:33:47 +02:00
|
|
|
#define VIRTIO_BLK_AUTO_NUM_QUEUES UINT16_MAX
|
|
|
|
|
2012-05-16 12:54:05 +02:00
|
|
|
struct VirtIOBlkConf
|
|
|
|
{
|
|
|
|
BlockConf conf;
|
2014-03-03 11:30:08 +01:00
|
|
|
IOThread *iothread;
|
2012-05-16 12:54:05 +02:00
|
|
|
char *serial;
|
2015-02-02 14:52:22 +01:00
|
|
|
uint32_t request_merging;
|
2016-06-21 14:13:10 +02:00
|
|
|
uint16_t num_queues;
|
2017-12-11 16:16:24 +01:00
|
|
|
uint16_t queue_size;
|
2019-12-20 15:09:04 +01:00
|
|
|
bool seg_max_adjust;
|
2019-02-21 11:33:10 +01:00
|
|
|
uint32_t max_discard_sectors;
|
|
|
|
uint32_t max_write_zeroes_sectors;
|
2019-11-05 19:22:17 +01:00
|
|
|
bool x_enable_wce_if_config_wce;
|
2012-05-16 12:54:05 +02:00
|
|
|
};
|
|
|
|
|
2013-02-05 17:06:20 +01:00
|
|
|
struct VirtIOBlockDataPlane;
|
|
|
|
|
2014-06-17 08:32:06 +02:00
|
|
|
struct VirtIOBlockReq;
|
2013-03-18 17:37:18 +01:00
|
|
|
typedef struct VirtIOBlock {
|
2013-03-18 17:37:27 +01:00
|
|
|
VirtIODevice parent_obj;
|
2014-10-07 13:59:18 +02:00
|
|
|
BlockBackend *blk;
|
2013-03-18 17:37:18 +01:00
|
|
|
void *rq;
|
|
|
|
QEMUBH *bh;
|
2014-10-07 13:59:17 +02:00
|
|
|
VirtIOBlkConf conf;
|
2013-03-18 17:37:18 +01:00
|
|
|
unsigned short sector_mask;
|
virtio-blk: do not relay a previous driver's WCE configuration to the current
The following sequence happens:
- the SeaBIOS virtio-blk driver does not support the WCE feature, which
causes QEMU to disable writeback caching
- the Linux virtio-blk driver resets the device, finds WCE is available
but writeback caching is disabled; tells block layer to not send cache
flush commands
- the Linux virtio-blk driver sets the DRIVER_OK bit, which causes
writeback caching to be re-enabled, but the Linux virtio-blk driver does
not know of this side effect and cache flushes remain disabled
The bug is at the third step. If the guest does know about CONFIG_WCE,
QEMU should ignore the WCE feature's state. The guest will control the
cache mode solely using configuration space. This change makes Linux
do flushes correctly, but Linux will keep SeaBIOS's writethrough mode.
Hence, whenever the guest is reset, the cache mode of the disk should
be reset to whatever was specified in the "-drive" option. With this
change, the Linux virtio-blk driver finds that writeback caching is
enabled, and tells the block layer to send cache flush commands
appropriately.
Reported-by: Rusty Russell <rusty@au1.ibm.com
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2013-09-20 17:31:55 +02:00
|
|
|
bool original_wce;
|
2013-03-18 17:37:18 +01:00
|
|
|
VMChangeStateEntry *change;
|
2016-04-06 12:16:23 +02:00
|
|
|
bool dataplane_disabled;
|
virtio-blk: fix "disabled data plane" mode
In disabled mode, virtio-blk dataplane seems to be enabled, but flow
actually goes through the normal virtio path. This patch simplifies a bit
the handling of disabled mode. In disabled mode, virtio_blk_handle_output
might be called even if s->dataplane is not NULL.
This is a bit tricky, because the current check for s->dataplane will
always trigger, causing a continuous stream of calls to
virtio_blk_data_plane_start. Unfortunately, these calls will not
do anything. To fix this, set the "started" flag even in disabled
mode, and skip virtio_blk_data_plane_start if the started flag is true.
The resulting changes also prepare the code for the next patch, were
virtio-blk dataplane will reuse the same virtio_blk_handle_output function
as "regular" virtio-blk.
Because struct VirtIOBlockDataPlane is opaque in virtio-blk.c, we have
to move s->dataplane->started inside struct VirtIOBlock.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
2016-02-14 18:17:08 +01:00
|
|
|
bool dataplane_started;
|
2013-02-05 17:06:20 +01:00
|
|
|
struct VirtIOBlockDataPlane *dataplane;
|
2019-02-21 11:33:06 +01:00
|
|
|
uint64_t host_features;
|
2019-02-21 11:33:09 +01:00
|
|
|
size_t config_size;
|
2013-03-18 17:37:18 +01:00
|
|
|
} VirtIOBlock;
|
|
|
|
|
2014-06-11 06:11:42 +02:00
|
|
|
typedef struct VirtIOBlockReq {
|
2016-01-31 11:28:57 +01:00
|
|
|
VirtQueueElement elem;
|
2015-02-02 14:52:21 +01:00
|
|
|
int64_t sector_num;
|
2014-06-11 06:11:42 +02:00
|
|
|
VirtIOBlock *dev;
|
2016-06-21 14:13:13 +02:00
|
|
|
VirtQueue *vq;
|
2014-06-11 06:11:42 +02:00
|
|
|
struct virtio_blk_inhdr *in;
|
2014-06-11 06:11:48 +02:00
|
|
|
struct virtio_blk_outhdr out;
|
2014-06-11 06:11:42 +02:00
|
|
|
QEMUIOVector qiov;
|
2015-04-02 19:50:44 +02:00
|
|
|
size_t in_len;
|
2014-06-11 06:11:42 +02:00
|
|
|
struct VirtIOBlockReq *next;
|
2015-02-02 14:52:21 +01:00
|
|
|
struct VirtIOBlockReq *mr_next;
|
2014-06-11 06:11:42 +02:00
|
|
|
BlockAcctCookie acct;
|
|
|
|
} VirtIOBlockReq;
|
|
|
|
|
2015-02-02 14:52:21 +01:00
|
|
|
#define VIRTIO_BLK_MAX_MERGE_REQS 32
|
|
|
|
|
|
|
|
typedef struct MultiReqBuffer {
|
|
|
|
VirtIOBlockReq *reqs[VIRTIO_BLK_MAX_MERGE_REQS];
|
|
|
|
unsigned int num_reqs;
|
|
|
|
bool is_write;
|
|
|
|
} MultiReqBuffer;
|
|
|
|
|
2017-02-09 09:40:47 +01:00
|
|
|
bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq);
|
virtio-blk: On restart, process queued requests in the proper context
On restart, we were scheduling a BH to process queued requests, which
would run before starting up the data plane, leading to those requests
being assigned and started on coroutines on the main context.
This could cause requests to be wrongly processed in parallel from
different threads (the main thread and the iothread managing the data
plane), potentially leading to multiple issues.
For example, stopping and resuming a VM multiple times while the guest
is generating I/O on a virtio_blk device can trigger a crash with a
stack tracing looking like this one:
<------>
Thread 2 (Thread 0x7ff736765700 (LWP 1062503)):
#0 0x00005567a13b99d6 in iov_memset
(iov=0x6563617073206f4e, iov_cnt=1717922848, offset=516096, fillc=0, bytes=7018105756081554803)
at util/iov.c:69
#1 0x00005567a13bab73 in qemu_iovec_memset
(qiov=0x7ff73ec99748, offset=516096, fillc=0, bytes=7018105756081554803) at util/iov.c:530
#2 0x00005567a12f411c in qemu_laio_process_completion (laiocb=0x7ff6512ee6c0) at block/linux-aio.c:86
#3 0x00005567a12f42ff in qemu_laio_process_completions (s=0x7ff7182e8420) at block/linux-aio.c:217
#4 0x00005567a12f480d in ioq_submit (s=0x7ff7182e8420) at block/linux-aio.c:323
#5 0x00005567a12f43d9 in qemu_laio_process_completions_and_submit (s=0x7ff7182e8420)
at block/linux-aio.c:236
#6 0x00005567a12f44c2 in qemu_laio_poll_cb (opaque=0x7ff7182e8430) at block/linux-aio.c:267
#7 0x00005567a13aed83 in run_poll_handlers_once (ctx=0x5567a2b58c70, timeout=0x7ff7367645f8)
at util/aio-posix.c:520
#8 0x00005567a13aee9f in run_poll_handlers (ctx=0x5567a2b58c70, max_ns=16000, timeout=0x7ff7367645f8)
at util/aio-posix.c:562
#9 0x00005567a13aefde in try_poll_mode (ctx=0x5567a2b58c70, timeout=0x7ff7367645f8)
at util/aio-posix.c:597
#10 0x00005567a13af115 in aio_poll (ctx=0x5567a2b58c70, blocking=true) at util/aio-posix.c:639
#11 0x00005567a109acca in iothread_run (opaque=0x5567a2b29760) at iothread.c:75
#12 0x00005567a13b2790 in qemu_thread_start (args=0x5567a2b694c0) at util/qemu-thread-posix.c:519
#13 0x00007ff73eedf2de in start_thread () at /lib64/libpthread.so.0
#14 0x00007ff73ec10e83 in clone () at /lib64/libc.so.6
Thread 1 (Thread 0x7ff743986f00 (LWP 1062500)):
#0 0x00005567a13b99d6 in iov_memset
(iov=0x6563617073206f4e, iov_cnt=1717922848, offset=516096, fillc=0, bytes=7018105756081554803)
at util/iov.c:69
#1 0x00005567a13bab73 in qemu_iovec_memset
(qiov=0x7ff73ec99748, offset=516096, fillc=0, bytes=7018105756081554803) at util/iov.c:530
#2 0x00005567a12f411c in qemu_laio_process_completion (laiocb=0x7ff6512ee6c0) at block/linux-aio.c:86
#3 0x00005567a12f42ff in qemu_laio_process_completions (s=0x7ff7182e8420) at block/linux-aio.c:217
#4 0x00005567a12f480d in ioq_submit (s=0x7ff7182e8420) at block/linux-aio.c:323
#5 0x00005567a12f4a2f in laio_do_submit (fd=19, laiocb=0x7ff5f4ff9ae0, offset=472363008, type=2)
at block/linux-aio.c:375
#6 0x00005567a12f4af2 in laio_co_submit
(bs=0x5567a2b8c460, s=0x7ff7182e8420, fd=19, offset=472363008, qiov=0x7ff5f4ff9ca0, type=2)
at block/linux-aio.c:394
#7 0x00005567a12f1803 in raw_co_prw
(bs=0x5567a2b8c460, offset=472363008, bytes=20480, qiov=0x7ff5f4ff9ca0, type=2)
at block/file-posix.c:1892
#8 0x00005567a12f1941 in raw_co_pwritev
(bs=0x5567a2b8c460, offset=472363008, bytes=20480, qiov=0x7ff5f4ff9ca0, flags=0)
at block/file-posix.c:1925
#9 0x00005567a12fe3e1 in bdrv_driver_pwritev
(bs=0x5567a2b8c460, offset=472363008, bytes=20480, qiov=0x7ff5f4ff9ca0, qiov_offset=0, flags=0)
at block/io.c:1183
#10 0x00005567a1300340 in bdrv_aligned_pwritev
(child=0x5567a2b5b070, req=0x7ff5f4ff9db0, offset=472363008, bytes=20480, align=512, qiov=0x7ff72c0425b8, qiov_offset=0, flags=0) at block/io.c:1980
#11 0x00005567a1300b29 in bdrv_co_pwritev_part
(child=0x5567a2b5b070, offset=472363008, bytes=20480, qiov=0x7ff72c0425b8, qiov_offset=0, flags=0)
at block/io.c:2137
#12 0x00005567a12baba1 in qcow2_co_pwritev_task
(bs=0x5567a2b92740, file_cluster_offset=472317952, offset=487305216, bytes=20480, qiov=0x7ff72c0425b8, qiov_offset=0, l2meta=0x0) at block/qcow2.c:2444
#13 0x00005567a12bacdb in qcow2_co_pwritev_task_entry (task=0x5567a2b48540) at block/qcow2.c:2475
#14 0x00005567a13167d8 in aio_task_co (opaque=0x5567a2b48540) at block/aio_task.c:45
#15 0x00005567a13cf00c in coroutine_trampoline (i0=738245600, i1=32759) at util/coroutine-ucontext.c:115
#16 0x00007ff73eb622e0 in __start_context () at /lib64/libc.so.6
#17 0x00007ff6626f1350 in ()
#18 0x0000000000000000 in ()
<------>
This is also known to cause crashes with this message (assertion
failed):
aio_co_schedule: Co-routine was already scheduled in 'aio_co_schedule'
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1812765
Signed-off-by: Sergio Lopez <slp@redhat.com>
Message-Id: <20200603093240.40489-3-slp@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2020-06-03 11:32:40 +02:00
|
|
|
void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh);
|
2016-04-06 12:16:26 +02:00
|
|
|
|
2008-12-04 20:52:44 +01:00
|
|
|
#endif
|