All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/25] block layer: split block APIs in global state and I/O
@ 2021-10-12  8:48 Emanuele Giuseppe Esposito
  2021-10-12  8:48 ` [PATCH v3 01/25] main-loop.h: introduce qemu_in_main_thread() Emanuele Giuseppe Esposito
                   ` (24 more replies)
  0 siblings, 25 replies; 39+ messages in thread
From: Emanuele Giuseppe Esposito @ 2021-10-12  8:48 UTC (permalink / raw)
  To: qemu-block
  Cc: Kevin Wolf, Fam Zheng, Vladimir Sementsov-Ogievskiy,
	Daniel P. Berrangé,
	Eduardo Habkost, Juan Quintela, qemu-devel, John Snow,
	Emanuele Giuseppe Esposito, Richard Henderson, Markus Armbruster,
	Dr. David Alan Gilbert, Hanna Reitz, Stefan Hajnoczi,
	Paolo Bonzini, Eric Blake

Currently, block layer APIs like block-backend.h contain a mix of
functions that are either running in the main loop and under the
BQL, or are thread-safe functions and run in iothreads performing I/O.
The functions running under BQL also take care of modifying the
block graph, by using drain and/or aio_context_acquire/release.
This makes it very confusing to understand where each function
runs, and what assumptions it provided with regards to thread
safety.

We call the functions running under BQL "global state (GS) API", and
distinguish them from the thread-safe "I/O API".

The aim of this series is to split the relevant block headers in
global state and I/O sub-headers. The division will be done in
this way:
header.h will be split in header-global-state.h, header-io.h and
header-common.h. The latter will just contain the data structures
needed by header-global-state and header-io, and common helpers
that are neither in GS nor in I/O. header.h will remain for
legacy and to avoid changing all includes in all QEMU c files,
but will only include the two new headers. No function shall be
added in header.c .
Once we split all relevant headers, it will be much easier to see what
uses the AioContext lock and remove it, which is the overall main
goal of this and other series that I posted/will post.

In addition to splitting the relevant headers shown in this series,
it is also very helpful splitting the function pointers in some
block structures, to understand what runs under AioContext lock and
what doesn't. This is what patches 19-25 do.

Each function in the GS API will have an assertion, checking
that it is always running under BQL.
I/O functions are instead thread safe (or so should be), meaning
that they *can* run under BQL, but also in an iothread in another
AioContext. Therefore they do not provide any assertion, and
need to be audited manually to verify the correctness.

Adding assetions has helped finding 2 bugs already, as shown in
my series "Migration: fix missing iothread locking".

Tested this series by running unit tests, qemu-iotests and qtests
(x86_64).
Some functions in the GS API are used everywhere but not
properly tested. Therefore their assertion is never actually run in
the tests, so despite my very careful auditing, it is not impossible
to exclude that some will trigger while actually using QEMU.

Patch 1 introduces qemu_in_main_thread(), the function used in
all assertions. This had to be introduced otherwise all unit tests
would fail, since they run in the main loop but use the code in
stubs/iothread.c
Patches 2-14 and 19-25 (with the exception of patch 9, that is an additional
assert) are all structured in the same way: first we split the header
and in the next (even) patch we add assertions.
The rest of the patches ontain either both assertions and split,
or have no assertions.

Next steps once this get reviewed:
1) audit the GS API and replace the AioContext lock with drains,
or remove them when not necessary (requires further discussion).
2) [optional as it should be already the case] audit the I/O API
and check that thread safety is guaranteed

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
v2 -> v3:
* rename "graph API" into "global state API"
* change order of patches, block.h comes before block-backend.h
* change GS and I/O comment headers to avoid redundancy, all other
  headers refer to block-global-state.h and block-io.h
* fix typo on GS and I/O headers
* use assert instead of g_assert
* move bdrv_pwrite_sync, bdrv_block_status and bdrv_co_copy_range_{from/to}
  to the I/O API
* change assert_bdrv_graph_writable implementation, since we need
  to introduce additional drains
* remove transactions API split
* add preparation patch for blockdev.h (patch 13)
* backup-top -> copy-on-write
* change I/O comment in job.h into a better meaningful explanation
* fix all warnings given by checkpatch, mostly due to /* */ to be
  split in separate lines
* rebase on current master (c09124dcb8), and split the following new functions:
	blk_replace_bs (I/O)
	bdrv_bsc_is_data (I/O)
	bdrv_bsc_invalidate_range (I/O)
	bdrv_bsc_fill (I/O)
	bdrv_new_open_driver_opts (GS)
	blk_get_max_hw_iov (I/O)
  they are all added in patches 4 and 6.

v1 -> v2:
* remove the iothread locking bug fix, and send it as separate patch
* rename graph API -> global state API
* better documented patch 1 (qemu_in_main_thread)
* add and split all other block layer headers
* fix warnings given by checkpatch on multiline comments

Emanuele Giuseppe Esposito (25):
  main-loop.h: introduce qemu_in_main_thread()
  include/block/block: split header into I/O and global state API
  assertions for block global state API
  include/sysemu/block-backend: split header into I/O and global state
    (GS) API
  block/block-backend.c: assertions for block-backend
  include/block/block_int: split header into I/O and global state API
  assertions for block_int global state API
  block: introduce assert_bdrv_graph_writable
  include/block/blockjob_int.h: split header into I/O and GS API
  assertions for blockjob_int.h
  include/block/blockjob.h: global state API
  assertions for blockob.h global state API
  include/sysemu/blockdev.h: move drive_add and inline drive_def
  include/systemu/blockdev.h: global state API
  assertions for blockdev.h global state API
  include/block/snapshot: global state API + assertions
  block/copy-before-write.h: global state API + assertions
  block/coroutines: I/O API
  block_int-common.h: split function pointers in BlockDriver
  block_int-common.h: assertion in the callers of BlockDriver function
    pointers
  block_int-common.h: split function pointers in BdrvChildClass
  block_int-common.h: assertions in the callers of BdrvChildClass
    function pointers
  block-backend-common.h: split function pointers in BlockDevOps
  job.h: split function pointers in JobDriver
  job.h: assertions in the callers of JobDriver funcion pointers

 block.c                                     |  188 ++-
 block/backup.c                              |    1 +
 block/block-backend.c                       |  104 +-
 block/commit.c                              |    4 +
 block/copy-before-write.c                   |    2 +
 block/copy-before-write.h                   |    7 +
 block/coroutines.h                          |    7 +
 block/dirty-bitmap.c                        |    1 +
 block/io.c                                  |   37 +
 block/meson.build                           |    7 +-
 block/mirror.c                              |    4 +
 block/monitor/bitmap-qmp-cmds.c             |    6 +
 block/monitor/block-hmp-cmds.c              |    2 +-
 block/snapshot.c                            |   28 +
 block/stream.c                              |    2 +
 blockdev.c                                  |   52 +-
 blockjob.c                                  |   14 +
 include/block/block-common.h                |  389 +++++
 include/block/block-global-state.h          |  263 ++++
 include/block/block-io.h                    |  283 ++++
 include/block/block.h                       |  863 +----------
 include/block/block_int-common.h            | 1193 +++++++++++++++
 include/block/block_int-global-state.h      |  327 ++++
 include/block/block_int-io.h                |  163 ++
 include/block/block_int.h                   | 1478 +------------------
 include/block/blockjob.h                    |    9 +
 include/block/blockjob_int.h                |   28 +
 include/block/snapshot.h                    |   13 +-
 include/qemu/job.h                          |   16 +
 include/qemu/main-loop.h                    |   13 +
 include/sysemu/block-backend-common.h       |   92 ++
 include/sysemu/block-backend-global-state.h |  122 ++
 include/sysemu/block-backend-io.h           |  134 ++
 include/sysemu/block-backend.h              |  264 +---
 include/sysemu/blockdev.h                   |   20 +-
 job.c                                       |    9 +
 migration/savevm.c                          |    2 +
 softmmu/cpus.c                              |    5 +
 softmmu/qdev-monitor.c                      |    2 +
 softmmu/vl.c                                |   25 +-
 stubs/iothread-lock.c                       |    5 +
 41 files changed, 3544 insertions(+), 2640 deletions(-)
 create mode 100644 include/block/block-common.h
 create mode 100644 include/block/block-global-state.h
 create mode 100644 include/block/block-io.h
 create mode 100644 include/block/block_int-common.h
 create mode 100644 include/block/block_int-global-state.h
 create mode 100644 include/block/block_int-io.h
 create mode 100644 include/sysemu/block-backend-common.h
 create mode 100644 include/sysemu/block-backend-global-state.h
 create mode 100644 include/sysemu/block-backend-io.h

-- 
2.27.0



^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2021-10-21 15:14 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12  8:48 [PATCH v3 00/25] block layer: split block APIs in global state and I/O Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 01/25] main-loop.h: introduce qemu_in_main_thread() Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 02/25] include/block/block: split header into I/O and global state API Emanuele Giuseppe Esposito
2021-10-14 20:31   ` Eric Blake
2021-10-15 10:05     ` Emanuele Giuseppe Esposito
2021-10-21 14:11   ` Stefan Hajnoczi
2021-10-12  8:48 ` [PATCH v3 03/25] assertions for block " Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 04/25] include/sysemu/block-backend: split header into I/O and global state (GS) API Emanuele Giuseppe Esposito
2021-10-21 14:28   ` Stefan Hajnoczi
2021-10-12  8:48 ` [PATCH v3 05/25] block/block-backend.c: assertions for block-backend Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 06/25] include/block/block_int: split header into I/O and global state API Emanuele Giuseppe Esposito
2021-10-21 14:35   ` Stefan Hajnoczi
2021-10-12  8:48 ` [PATCH v3 07/25] assertions for block_int " Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 08/25] block: introduce assert_bdrv_graph_writable Emanuele Giuseppe Esposito
2021-10-12 11:07   ` Paolo Bonzini
2021-10-21 15:09   ` Stefan Hajnoczi
2021-10-12  8:48 ` [PATCH v3 09/25] include/block/blockjob_int.h: split header into I/O and GS API Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 10/25] assertions for blockjob_int.h Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 11/25] include/block/blockjob.h: global state API Emanuele Giuseppe Esposito
2021-10-21 14:35   ` Stefan Hajnoczi
2021-10-12  8:48 ` [PATCH v3 12/25] assertions for blockob.h " Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 13/25] include/sysemu/blockdev.h: move drive_add and inline drive_def Emanuele Giuseppe Esposito
2021-10-12 11:06   ` Paolo Bonzini
2021-10-21 15:08   ` Stefan Hajnoczi
2021-10-12  8:48 ` [PATCH v3 14/25] include/systemu/blockdev.h: global state API Emanuele Giuseppe Esposito
2021-10-12 11:07   ` Paolo Bonzini
2021-10-12  8:48 ` [PATCH v3 15/25] assertions for blockdev.h " Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 16/25] include/block/snapshot: global state API + assertions Emanuele Giuseppe Esposito
2021-10-12  8:48 ` [PATCH v3 17/25] block/copy-before-write.h: " Emanuele Giuseppe Esposito
2021-10-21 15:10   ` Stefan Hajnoczi
2021-10-12  8:48 ` [PATCH v3 18/25] block/coroutines: I/O API Emanuele Giuseppe Esposito
2021-10-12  8:49 ` [PATCH v3 19/25] block_int-common.h: split function pointers in BlockDriver Emanuele Giuseppe Esposito
2021-10-12  8:49 ` [PATCH v3 20/25] block_int-common.h: assertion in the callers of BlockDriver function pointers Emanuele Giuseppe Esposito
2021-10-12  8:49 ` [PATCH v3 21/25] block_int-common.h: split function pointers in BdrvChildClass Emanuele Giuseppe Esposito
2021-10-12  8:49 ` [PATCH v3 22/25] block_int-common.h: assertions in the callers of BdrvChildClass function pointers Emanuele Giuseppe Esposito
2021-10-12  8:49 ` [PATCH v3 23/25] block-backend-common.h: split function pointers in BlockDevOps Emanuele Giuseppe Esposito
2021-10-12  8:49 ` [PATCH v3 24/25] job.h: split function pointers in JobDriver Emanuele Giuseppe Esposito
2021-10-21 15:11   ` Stefan Hajnoczi
2021-10-12  8:49 ` [PATCH v3 25/25] job.h: assertions in the callers of JobDriver funcion pointers Emanuele Giuseppe Esposito

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.