Pull request

-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAl7aFK8ACgkQnKSrs4Gr
 c8gocQf9G0xxCGrh99I7BAOoiA52vTl9sSjwVzIFzmzHSCnAGaERY+wSfuipILsz
 0/DlD0KBcQqwEkIGRJ9iNJgQIkOGc5MTlgNQojjFkBuM4eHiv+Ow+TomIAOEZnmL
 qJ2rslk/bHjKpOXjiXfa5SiLcPi2z8nJkTkRo3p9sg+iVJRAQsIydBK+LZc+iInD
 CvWsOYgGySqw5CH3h+S4Kt5WBcgxiaHzUqt+kXgMqjkKewHndIKKJavHaR3+GdrN
 kG3lTDLuDZ4CCs9o0VZxKVW10VrH8RYjuF9VdRVg0KJCp24v2+o7WiiPF5DRZ/7t
 QbYZjfovdQB6jhy5HXM4RXzsOp1HIg==
 =/HM9
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging

Pull request

# gpg: Signature made Fri 05 Jun 2020 10:47:27 BST
# gpg:                using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [full]
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>" [full]
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35  775A 9CA4 ABB3 81AB 73C8

* remotes/stefanha/tags/block-pull-request:
  block: Factor out bdrv_run_co()
  exec: Rename qemu_ram_writeback() as qemu_ram_msync()
  hw/block: Let the NVMe emulated device be target-agnostic
  memory: Extract memory_region_msync() from memory_region_writeback()
  memory: Rename memory_region_do_writeback -> memory_region_writeback
  fuzz: run the main-loop in fork-server process
  fuzz: add mangled object name to linker script
  fuzz: fix typo in i440fx-qtest-reboot arguments
  fuzz: add datadir for oss-fuzz compatability
  io_uring: use io_uring_cq_ready() to check for ready cqes
  io_uring: retry io_uring_submit() if it fails with errno=EINTR

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2020-06-05 11:53:37 +01:00
commit b489f015fb
16 changed files with 134 additions and 144 deletions

View File

@ -35,8 +35,6 @@
#include "qemu/main-loop.h"
#include "sysemu/replay.h"
#define NOT_DONE 0x7fffffff /* used while emulated sync operation in progress */
/* Maximum bounce buffer for copy-on-read and write zeroes, in bytes */
#define MAX_BOUNCE_BUFFER (32768 << BDRV_SECTOR_BITS)
@ -891,29 +889,63 @@ static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset,
return 0;
}
typedef int coroutine_fn BdrvRequestEntry(void *opaque);
typedef struct BdrvRunCo {
BdrvRequestEntry *entry;
void *opaque;
int ret;
bool done;
Coroutine *co; /* Coroutine, running bdrv_run_co_entry, for debugging */
} BdrvRunCo;
static void coroutine_fn bdrv_run_co_entry(void *opaque)
{
BdrvRunCo *arg = opaque;
arg->ret = arg->entry(arg->opaque);
arg->done = true;
aio_wait_kick();
}
static int bdrv_run_co(BlockDriverState *bs, BdrvRequestEntry *entry,
void *opaque)
{
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
return entry(opaque);
} else {
BdrvRunCo s = { .entry = entry, .opaque = opaque };
s.co = qemu_coroutine_create(bdrv_run_co_entry, &s);
bdrv_coroutine_enter(bs, s.co);
BDRV_POLL_WHILE(bs, !s.done);
return s.ret;
}
}
typedef struct RwCo {
BdrvChild *child;
int64_t offset;
QEMUIOVector *qiov;
bool is_write;
int ret;
BdrvRequestFlags flags;
} RwCo;
static void coroutine_fn bdrv_rw_co_entry(void *opaque)
static int coroutine_fn bdrv_rw_co_entry(void *opaque)
{
RwCo *rwco = opaque;
if (!rwco->is_write) {
rwco->ret = bdrv_co_preadv(rwco->child, rwco->offset,
rwco->qiov->size, rwco->qiov,
rwco->flags);
return bdrv_co_preadv(rwco->child, rwco->offset,
rwco->qiov->size, rwco->qiov,
rwco->flags);
} else {
rwco->ret = bdrv_co_pwritev(rwco->child, rwco->offset,
rwco->qiov->size, rwco->qiov,
rwco->flags);
return bdrv_co_pwritev(rwco->child, rwco->offset,
rwco->qiov->size, rwco->qiov,
rwco->flags);
}
aio_wait_kick();
}
/*
@ -923,25 +955,15 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset,
QEMUIOVector *qiov, bool is_write,
BdrvRequestFlags flags)
{
Coroutine *co;
RwCo rwco = {
.child = child,
.offset = offset,
.qiov = qiov,
.is_write = is_write,
.ret = NOT_DONE,
.flags = flags,
};
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_rw_co_entry(&rwco);
} else {
co = qemu_coroutine_create(bdrv_rw_co_entry, &rwco);
bdrv_coroutine_enter(child->bs, co);
BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE);
}
return rwco.ret;
return bdrv_run_co(child->bs, bdrv_rw_co_entry, &rwco);
}
int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
@ -2229,8 +2251,6 @@ typedef struct BdrvCoBlockStatusData {
int64_t *pnum;
int64_t *map;
BlockDriverState **file;
int ret;
bool done;
} BdrvCoBlockStatusData;
int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs,
@ -2484,16 +2504,14 @@ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
}
/* Coroutine wrapper for bdrv_block_status_above() */
static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque)
{
BdrvCoBlockStatusData *data = opaque;
data->ret = bdrv_co_block_status_above(data->bs, data->base,
data->want_zero,
data->offset, data->bytes,
data->pnum, data->map, data->file);
data->done = true;
aio_wait_kick();
return bdrv_co_block_status_above(data->bs, data->base,
data->want_zero,
data->offset, data->bytes,
data->pnum, data->map, data->file);
}
/*
@ -2508,7 +2526,6 @@ static int bdrv_common_block_status_above(BlockDriverState *bs,
int64_t *map,
BlockDriverState **file)
{
Coroutine *co;
BdrvCoBlockStatusData data = {
.bs = bs,
.base = base,
@ -2518,18 +2535,9 @@ static int bdrv_common_block_status_above(BlockDriverState *bs,
.pnum = pnum,
.map = map,
.file = file,
.done = false,
};
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_block_status_above_co_entry(&data);
} else {
co = qemu_coroutine_create(bdrv_block_status_above_co_entry, &data);
bdrv_coroutine_enter(bs, co);
BDRV_POLL_WHILE(bs, !data.done);
}
return data.ret;
return bdrv_run_co(bs, bdrv_block_status_above_co_entry, &data);
}
int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base,
@ -2630,7 +2638,6 @@ typedef struct BdrvVmstateCo {
QEMUIOVector *qiov;
int64_t pos;
bool is_read;
int ret;
} BdrvVmstateCo;
static int coroutine_fn
@ -2658,33 +2665,25 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
return ret;
}
static void coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque)
static int coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque)
{
BdrvVmstateCo *co = opaque;
co->ret = bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read);
aio_wait_kick();
return bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read);
}
static inline int
bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
bool is_read)
{
if (qemu_in_coroutine()) {
return bdrv_co_rw_vmstate(bs, qiov, pos, is_read);
} else {
BdrvVmstateCo data = {
.bs = bs,
.qiov = qiov,
.pos = pos,
.is_read = is_read,
.ret = -EINPROGRESS,
};
Coroutine *co = qemu_coroutine_create(bdrv_co_rw_vmstate_entry, &data);
BdrvVmstateCo data = {
.bs = bs,
.qiov = qiov,
.pos = pos,
.is_read = is_read,
};
bdrv_coroutine_enter(bs, co);
BDRV_POLL_WHILE(bs, data.ret == -EINPROGRESS);
return data.ret;
}
return bdrv_run_co(bs, bdrv_co_rw_vmstate_entry, &data);
}
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
@ -2762,18 +2761,9 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb)
/**************************************************************/
/* Coroutine block device emulation */
typedef struct FlushCo {
BlockDriverState *bs;
int ret;
} FlushCo;
static void coroutine_fn bdrv_flush_co_entry(void *opaque)
static int coroutine_fn bdrv_flush_co_entry(void *opaque)
{
FlushCo *rwco = opaque;
rwco->ret = bdrv_co_flush(rwco->bs);
aio_wait_kick();
return bdrv_co_flush(opaque);
}
int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
@ -2890,36 +2880,20 @@ early_exit:
int bdrv_flush(BlockDriverState *bs)
{
Coroutine *co;
FlushCo flush_co = {
.bs = bs,
.ret = NOT_DONE,
};
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_flush_co_entry(&flush_co);
} else {
co = qemu_coroutine_create(bdrv_flush_co_entry, &flush_co);
bdrv_coroutine_enter(bs, co);
BDRV_POLL_WHILE(bs, flush_co.ret == NOT_DONE);
}
return flush_co.ret;
return bdrv_run_co(bs, bdrv_flush_co_entry, bs);
}
typedef struct DiscardCo {
BdrvChild *child;
int64_t offset;
int64_t bytes;
int ret;
} DiscardCo;
static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque)
static int coroutine_fn bdrv_pdiscard_co_entry(void *opaque)
{
DiscardCo *rwco = opaque;
rwco->ret = bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes);
aio_wait_kick();
return bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes);
}
int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset,
@ -3038,24 +3012,13 @@ out:
int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes)
{
Coroutine *co;
DiscardCo rwco = {
.child = child,
.offset = offset,
.bytes = bytes,
.ret = NOT_DONE,
};
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_pdiscard_co_entry(&rwco);
} else {
co = qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco);
bdrv_coroutine_enter(child->bs, co);
BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE);
}
return rwco.ret;
return bdrv_run_co(child->bs, bdrv_pdiscard_co_entry, &rwco);
}
int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf)
@ -3463,21 +3426,19 @@ typedef struct TruncateCo {
PreallocMode prealloc;
BdrvRequestFlags flags;
Error **errp;
int ret;
} TruncateCo;
static void coroutine_fn bdrv_truncate_co_entry(void *opaque)
static int coroutine_fn bdrv_truncate_co_entry(void *opaque)
{
TruncateCo *tco = opaque;
tco->ret = bdrv_co_truncate(tco->child, tco->offset, tco->exact,
tco->prealloc, tco->flags, tco->errp);
aio_wait_kick();
return bdrv_co_truncate(tco->child, tco->offset, tco->exact,
tco->prealloc, tco->flags, tco->errp);
}
int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
{
Coroutine *co;
TruncateCo tco = {
.child = child,
.offset = offset,
@ -3485,17 +3446,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
.prealloc = prealloc,
.flags = flags,
.errp = errp,
.ret = NOT_DONE,
};
if (qemu_in_coroutine()) {
/* Fast-path if already in coroutine context */
bdrv_truncate_co_entry(&tco);
} else {
co = qemu_coroutine_create(bdrv_truncate_co_entry, &tco);
bdrv_coroutine_enter(child->bs, co);
BDRV_POLL_WHILE(child->bs, tco.ret == NOT_DONE);
}
return tco.ret;
return bdrv_run_co(child->bs, bdrv_truncate_co_entry, &tco);
}

View File

@ -231,7 +231,7 @@ static int ioq_submit(LuringState *s)
trace_luring_io_uring_submit(s, ret);
/* Prevent infinite loop if submission is refused */
if (ret <= 0) {
if (ret == -EAGAIN) {
if (ret == -EAGAIN || ret == -EINTR) {
continue;
}
break;
@ -277,13 +277,10 @@ static void qemu_luring_completion_cb(void *opaque)
static bool qemu_luring_poll_cb(void *opaque)
{
LuringState *s = opaque;
struct io_uring_cqe *cqes;
if (io_uring_peek_cqe(&s->ring, &cqes) == 0) {
if (cqes) {
luring_process_completions_and_submit(s);
return true;
}
if (io_uring_cq_ready(&s->ring)) {
luring_process_completions_and_submit(s);
return true;
}
return false;

2
exec.c
View File

@ -2127,7 +2127,7 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp)
* Otherwise no-op.
* @Note: this is supposed to be a synchronous op.
*/
void qemu_ram_writeback(RAMBlock *block, ram_addr_t start, ram_addr_t length)
void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length)
{
/* The requested range should fit in within the block range */
g_assert((start + length) <= block->used_length);

View File

@ -13,6 +13,6 @@ common-obj-$(CONFIG_SH4) += tc58128.o
obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o
obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o
obj-$(CONFIG_NVME_PCI) += nvme.o
common-obj-$(CONFIG_NVME_PCI) += nvme.o
obj-y += dataplane/

View File

@ -46,8 +46,7 @@
#include "qapi/visitor.h"
#include "sysemu/hostmem.h"
#include "sysemu/block-backend.h"
#include "exec/ram_addr.h"
#include "exec/memory.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qemu/cutils.h"
@ -1207,8 +1206,7 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)
*/
if (addr == 0xE08 &&
(NVME_PMRCAP_PMRWBM(n->bar.pmrcap) & 0x02)) {
qemu_ram_writeback(n->pmrdev->mr.ram_block,
0, n->pmrdev->size);
memory_region_msync(&n->pmrdev->mr, 0, n->pmrdev->size);
}
memcpy(&val, ptr + addr, size);
} else {

View File

@ -1473,15 +1473,26 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr);
*/
void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize,
Error **errp);
/**
* memory_region_do_writeback: Trigger cache writeback or msync for
* memory_region_msync: Synchronize selected address range of
* a memory mapped region
*
* @mr: the memory region to be msync
* @addr: the initial address of the range to be sync
* @size: the size of the range to be sync
*/
void memory_region_msync(MemoryRegion *mr, hwaddr addr, hwaddr size);
/**
* memory_region_writeback: Trigger cache writeback for
* selected address range
*
* @mr: the memory region to be updated
* @addr: the initial address of the range to be written back
* @size: the size of the range to be written back
*/
void memory_region_do_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size);
void memory_region_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size);
/**
* memory_region_set_log: Turn dirty logging on or off for a region.

View File

@ -136,12 +136,12 @@ void qemu_ram_free(RAMBlock *block);
int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
void qemu_ram_writeback(RAMBlock *block, ram_addr_t start, ram_addr_t length);
void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length);
/* Clear whole block of mem */
static inline void qemu_ram_block_writeback(RAMBlock *block)
{
qemu_ram_writeback(block, 0, block->used_length);
qemu_ram_msync(block, 0, block->used_length);
}
#define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1)

View File

@ -15,6 +15,8 @@ extern const char *qemu_name;
extern QemuUUID qemu_uuid;
extern bool qemu_uuid_set;
void qemu_add_data_dir(const char *path);
void qemu_add_exit_notifier(Notifier *notify);
void qemu_remove_exit_notifier(Notifier *notify);

View File

@ -2197,15 +2197,21 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp
qemu_ram_resize(mr->ram_block, newsize, errp);
}
void memory_region_msync(MemoryRegion *mr, hwaddr addr, hwaddr size)
{
if (mr->ram_block) {
qemu_ram_msync(mr->ram_block, addr, size);
}
}
void memory_region_do_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size)
void memory_region_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size)
{
/*
* Might be extended case needed to cover
* different types of memory regions
*/
if (mr->ram_block && mr->dirty_log_mask) {
qemu_ram_writeback(mr->ram_block, addr, size);
if (mr->dirty_log_mask) {
memory_region_msync(mr, addr, size);
}
}

View File

@ -1993,7 +1993,7 @@ char *qemu_find_file(int type, const char *name)
return NULL;
}
static void qemu_add_data_dir(const char *path)
void qemu_add_data_dir(const char *path)
{
int i;

View File

@ -6813,7 +6813,7 @@ static void dccvap_writefn(CPUARMState *env, const ARMCPRegInfo *opaque,
mr = memory_region_from_host(haddr, &offset);
if (mr) {
memory_region_do_writeback(mr, offset, dline_size);
memory_region_writeback(mr, offset, dline_size);
}
}
}

View File

@ -28,6 +28,11 @@ SECTIONS
/* Internal Libfuzzer TracePC object which contains the ValueProfileMap */
FuzzerTracePC*(.bss*);
/*
* In case the above line fails, explicitly specify the (mangled) name of
* the object we care about
*/
*(.bss._ZN6fuzzer3TPCE);
}
.data.fuzz_end : ALIGN(4K)
{

View File

@ -137,6 +137,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
{
char *target_name;
char *dir;
/* Initialize qgraph and modules */
qos_graph_init();
@ -147,6 +148,20 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
target_name = strstr(**argv, "-target-");
if (target_name) { /* The binary name specifies the target */
target_name += strlen("-target-");
/*
* With oss-fuzz, the executable is kept in the root of a directory (we
* cannot assume the path). All data (including bios binaries) must be
* in the same dir, or a subdir. Thus, we cannot place the pc-bios so
* that it would be in exec_dir/../pc-bios.
* As a workaround, oss-fuzz allows us to use argv[0] to get the
* location of the executable. Using this we add exec_dir/pc-bios to
* the datadirs.
*/
dir = g_build_filename(g_path_get_dirname(**argv), "pc-bios", NULL);
if (g_file_test(dir, G_FILE_TEST_IS_DIR)) {
qemu_add_data_dir(dir);
}
g_free(dir);
} else if (*argc > 1) { /* The target is specified as an argument */
target_name = (*argv)[1];
if (!strstr(target_name, "--fuzz-target=")) {

View File

@ -151,12 +151,13 @@ static void i440fx_fuzz_qos_fork(QTestState *s,
i440fx_fuzz_qos(s, Data, Size);
_Exit(0);
} else {
flush_events(s);
wait(NULL);
}
}
static const char *i440fx_qtest_argv = TARGET_NAME " -machine accel=qtest"
"-m 0 -display none";
" -m 0 -display none";
static const char *i440fx_argv(FuzzTarget *t)
{
return i440fx_qtest_argv;

View File

@ -122,6 +122,7 @@ static void virtio_net_fork_fuzz(QTestState *s,
flush_events(s);
_Exit(0);
} else {
flush_events(s);
wait(NULL);
}
}
@ -134,6 +135,7 @@ static void virtio_net_fork_fuzz_check_used(QTestState *s,
flush_events(s);
_Exit(0);
} else {
flush_events(s);
wait(NULL);
}
}

View File

@ -145,6 +145,7 @@ static void virtio_scsi_fork_fuzz(QTestState *s,
flush_events(s);
_Exit(0);
} else {
flush_events(s);
wait(NULL);
}
}
@ -164,6 +165,7 @@ static void virtio_scsi_with_flag_fuzz(QTestState *s,
}
_Exit(0);
} else {
flush_events(s);
wait(NULL);
}
}