[PATCH 3/6] block/blkio: convert to blk_io_plug_call() API

2023-05-17 Thread Stefan Hajnoczi
Stop using the .bdrv_co_io_plug() API because it is not multi-queue block layer friendly. Use the new blk_io_plug_call() API to batch I/O submission instead. Signed-off-by: Stefan Hajnoczi --- block/blkio.c | 40 +--- 1 file changed, 21 insertions(+), 19

[PATCH 6/6] block: remove bdrv_co_io_plug() API

2023-05-17 Thread Stefan Hajnoczi
No block driver implements .bdrv_co_io_plug() anymore. Get rid of the function pointers. Signed-off-by: Stefan Hajnoczi --- include/block/block-io.h | 3 --- include/block/block_int-common.h | 11 -- block/io.c | 37 3

[PATCH 1/6] block: add blk_io_plug_call() API

2023-05-17 Thread Stefan Hajnoczi
Introduce a new API for thread-local blk_io_plug() that does not traverse the block graph. The goal is to make blk_io_plug() multi-queue friendly. Instead of having block drivers track whether or not we're in a plugged section, provide an API that allows them to defer a function call until we're

[PATCH 2/6] block/nvme: convert to blk_io_plug_call() API

2023-05-17 Thread Stefan Hajnoczi
Stop using the .bdrv_co_io_plug() API because it is not multi-queue block layer friendly. Use the new blk_io_plug_call() API to batch I/O submission instead. Signed-off-by: Stefan Hajnoczi --- block/nvme.c | 44 1 file changed, 12 insertions(+), 32

[PATCH 5/6] block/linux-aio: convert to blk_io_plug_call() API

2023-05-17 Thread Stefan Hajnoczi
Stop using the .bdrv_co_io_plug() API because it is not multi-queue block layer friendly. Use the new blk_io_plug_call() API to batch I/O submission instead. Signed-off-by: Stefan Hajnoczi --- include/block/raw-aio.h | 7 --- block/file-posix.c | 28

[PATCH 4/6] block/io_uring: convert to blk_io_plug_call() API

2023-05-17 Thread Stefan Hajnoczi
Stop using the .bdrv_co_io_plug() API because it is not multi-queue block layer friendly. Use the new blk_io_plug_call() API to batch I/O submission instead. Signed-off-by: Stefan Hajnoczi --- include/block/raw-aio.h | 7 --- block/file-posix.c | 10 - block/io_uring.c

[PATCH 0/6] block: add blk_io_plug_call() API

2023-05-17 Thread Stefan Hajnoczi
The existing blk_io_plug() API is not block layer multi-queue friendly because the plug state is per-BlockDriverState. Change blk_io_plug()'s implementation so it is thread-local. This is done by introducing the blk_io_plug_call() function that block drivers use to batch calls while plugged. It

Re: [PATCH] hw/ide: Remove unuseful IDE_DMA__COUNT definition

2023-05-17 Thread John Snow
On Fri, Feb 24, 2023 at 10:34 AM Philippe Mathieu-Daudé wrote: > > First, IDE_DMA__COUNT represents the number of enumerated > values, but is incorrectly listed as part of the enum. > > Second, IDE_DMA_CMD_str() is internal to core.c and only > takes sane enums from ide_dma_cmd. So no need to

Re: [PATCH 9/9] hw/ide/ahci: fix broken SError handling

2023-05-17 Thread John Snow
On Fri, Apr 28, 2023 at 9:23 AM Niklas Cassel wrote: > > From: Niklas Cassel > > When encountering an NCQ error, you should not write the NCQ tag to the > SError register. This is completely wrong. Mea culpa ... ! > > The SError register has a clear definition, where each bit represents a >

Re: [PATCH 7/9] hw/ide/ahci: trigger either error IRQ or regular IRQ, not both

2023-05-17 Thread John Snow
On Fri, Apr 28, 2023 at 9:23 AM Niklas Cassel wrote: > > From: Niklas Cassel > > According to AHCI 1.3.1, 5.3.8.1 RegFIS:Entry, if ERR_STAT is set, > we jump to state ERR:FatalTaskfile, which will raise a TFES IRQ > unconditionally, regardless if the I bit is set in the FIS or not. > > Thus, we

Re: [PATCH 6/9] hw/ide/ahci: PxSACT and PxCI is cleared when PxCMD.ST is cleared

2023-05-17 Thread John Snow
On Fri, Apr 28, 2023 at 9:23 AM Niklas Cassel wrote: > > From: Niklas Cassel > > According to AHCI 1.3.1 definition of PxSACT: > This field is cleared when PxCMD.ST is written from a '1' to a '0' by > software. This field is not cleared by a COMRESET or a software reset. > > According to AHCI

Re: [PATCH 3/9] hw/ide/ahci: write D2H FIS on when processing NCQ command

2023-05-17 Thread John Snow
On Fri, Apr 28, 2023 at 9:22 AM Niklas Cassel wrote: > > From: Niklas Cassel > > The way that BUSY + PxCI is cleared for NCQ (FPDMA QUEUED) commands is > described in SATA 3.5a Gold: > > 11.15 FPDMA QUEUED command protocol > DFPDMAQ2: ClearInterfaceBsy > "Transmit Register Device to Host FIS

Re: [PATCH 2/9] hw/ide/core: set ERR_STAT in unsupported command completion

2023-05-17 Thread John Snow
On Fri, Apr 28, 2023 at 9:22 AM Niklas Cassel wrote: > > From: Niklas Cassel > > Currently, the first time sending an unsupported command > (e.g. READ LOG DMA EXT) will not have ERR_STAT set in the completion. > Sending the unsupported command again, will correctly have ERR_STAT set. > > When

Re: [PATCH] migration: for snapshots, hold the BQL during setup callbacks

2023-05-17 Thread Peter Xu
On Wed, May 10, 2023 at 08:31:13AM +0200, Juan Quintela wrote: > Peter Xu wrote: > > Hi > > [Adding Kevin to the party] > > > On Fri, May 05, 2023 at 03:46:52PM +0200, Fiona Ebner wrote: > >> To fix it, ensure that the BQL is held during setup. To avoid changing > >> the behavior for migration

Re: [PULL 18/18] tested: add test for nested aio_poll() in poll handlers

2023-05-17 Thread Richard Henderson
On 5/17/23 09:51, Kevin Wolf wrote: From: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Message-Id: <20230502184134.534703-3-stefa...@redhat.com> Tested-by: Kevin Wolf Signed-off-by: Kevin Wolf --- tests/unit/test-nested-aio-poll.c | 130 ++

Re: [PATCH 1/9] hw/ide/ahci: remove stray backslash

2023-05-17 Thread John Snow
On Fri, Apr 28, 2023 at 9:22 AM Niklas Cassel wrote: > > From: Niklas Cassel > > This backslash obviously does not belong here, so remove it. Reviewed-by: John Snow > > Signed-off-by: Niklas Cassel > --- > hw/ide/ahci.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git

Re: [PATCH 0/9] misc AHCI cleanups

2023-05-17 Thread John Snow
On Fri, Apr 28, 2023 at 9:22 AM Niklas Cassel wrote: > > From: Niklas Cassel > > Hello John, > Hi Niklas! I haven't been actively involved with AHCI for a while, so I am not sure I can find the time to give this a deep scrub. I'm going to assume based on '@wdc.com` that you probably know a

[PULL 16/18] iotests/245: Check if 'compress' driver is available

2023-05-17 Thread Kevin Wolf
Skip TestBlockdevReopen.test_insert_compress_filter() if the 'compress' driver isn't available. In order to make the test succeed when the case is skipped, we also need to remove any output from it (which would be missing in the case where we skip it). This is done by replacing qemu_io_log() with

[PULL 11/18] qemu-img: Take graph lock more selectively

2023-05-17 Thread Kevin Wolf
If we take a reader lock, we can't call any functions that take a writer lock internally without causing deadlocks once the reader lock is actually enforced in the main thread, too. Take the reader lock only where it is actually needed. Signed-off-by: Kevin Wolf Message-Id:

[PULL 12/18] test-bdrv-drain: Take graph lock more selectively

2023-05-17 Thread Kevin Wolf
If we take a reader lock, we can't call any functions that take a writer lock internally without causing deadlocks once the reader lock is actually enforced in the main thread, too. Take the reader lock only where it is actually needed. Signed-off-by: Kevin Wolf Message-Id:

[PULL 06/18] blockdev: qmp_transaction: drop extra generic layer

2023-05-17 Thread Kevin Wolf
From: Vladimir Sementsov-Ogievskiy Let's simplify things: First, actions generally don't need access to common BlkActionState structure. The only exclusion are backup actions that need block_job_txn. Next, for transaction actions of Transaction API is more native to allocated state structure

[PULL 08/18] block: Call .bdrv_co_create(_opts) unlocked

2023-05-17 Thread Kevin Wolf
These are functions that modify the graph, so they must be able to take a writer lock. This is impossible if they already hold the reader lock. If they need a reader lock for some of their operations, they should take it internally. Many of them go through blk_*(), which will always take the lock

[PULL 17/18] aio-posix: do not nest poll handlers

2023-05-17 Thread Kevin Wolf
From: Stefan Hajnoczi QEMU's event loop supports nesting, which means that event handler functions may themselves call aio_poll(). The condition that triggered a handler must be reset before the nested aio_poll() call, otherwise the same handler will be called and immediately re-enter aio_poll.

[PULL 14/18] blockjob: Adhere to rate limit even when reentered early

2023-05-17 Thread Kevin Wolf
When jobs are sleeping, for example to enforce a given rate limit, they can be reentered early, in particular in order to get paused, to update the rate limit or to get cancelled. Before this patch, they behave in this case as if they had fully completed their rate limiting delay. This means that

[PULL 01/18] blockdev: refactor transaction to use Transaction API

2023-05-17 Thread Kevin Wolf
From: Vladimir Sementsov-Ogievskiy We are going to add more block-graph modifying transaction actions, and block-graph modifying functions are already based on Transaction API. Next, we'll need to separately update permissions after several graph-modifying actions, and this would be simple with

[PULL 09/18] block/export: Fix null pointer dereference in error path

2023-05-17 Thread Kevin Wolf
There are some error paths in blk_exp_add() that jump to 'fail:' before 'exp' is even created. So we can't just unconditionally access exp->blk. Add a NULL check, and switch from exp->blk to blk, which is available earlier, just to be extra sure that we really cover all cases where BlockDevOps

[PULL 15/18] graph-lock: Honour read locks even in the main thread

2023-05-17 Thread Kevin Wolf
There are some conditions under which we don't actually need to do anything for taking a reader lock: Writing the graph is only possible from the main context while holding the BQL. So if a reader is running in the main context under the BQL and knows that it won't be interrupted until the next

[PULL 03/18] blockdev: qmp_transaction: refactor loop to classic for

2023-05-17 Thread Kevin Wolf
From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Message-Id: <20230510150624.310640-4-vsement...@yandex-team.ru> Signed-off-by: Kevin Wolf --- blockdev.c | 9 +++-- 1 file changed, 3 insertions(+), 6 deletions(-) diff --git

[PULL 02/18] blockdev: transactions: rename some things

2023-05-17 Thread Kevin Wolf
From: Vladimir Sementsov-Ogievskiy Look at qmp_transaction(): dev_list is not obvious name for list of actions. Let's look at qapi spec, this argument is "actions". Let's follow the common practice of using same argument names in qapi scheme and code. To be honest, rename props to properties

[PULL 10/18] qcow2: Unlock the graph in qcow2_do_open() where necessary

2023-05-17 Thread Kevin Wolf
qcow2_do_open() calls a few no_co_wrappers that wrap functions taking the graph lock internally as a writer. Therefore, it can't hold the reader lock across these calls, it causes deadlocks. Drop the lock temporarily around the calls. Signed-off-by: Kevin Wolf Message-Id:

[PULL 18/18] tested: add test for nested aio_poll() in poll handlers

2023-05-17 Thread Kevin Wolf
From: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Message-Id: <20230502184134.534703-3-stefa...@redhat.com> Tested-by: Kevin Wolf Signed-off-by: Kevin Wolf --- tests/unit/test-nested-aio-poll.c | 130 ++ tests/unit/meson.build| 1 + 2 files

[PULL 13/18] test-bdrv-drain: Call bdrv_co_unref() in coroutine context

2023-05-17 Thread Kevin Wolf
bdrv_unref() is a no_coroutine_fn, so calling it from coroutine context is invalid. Use bdrv_co_unref() instead. Signed-off-by: Kevin Wolf Message-Id: <20230510203601.418015-7-kw...@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/unit/test-bdrv-drain.c | 2 +- 1 file

[PULL 04/18] blockdev: transaction: refactor handling transaction properties

2023-05-17 Thread Kevin Wolf
From: Vladimir Sementsov-Ogievskiy Only backup supports GROUPED mode. Make this logic more clear. And avoid passing extra thing to each action. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20230510150624.310640-5-vsement...@yandex-team.ru> Reviewed-by: Kevin Wolf Signed-off-by:

[PULL 05/18] blockdev: use state.bitmap in block-dirty-bitmap-add action

2023-05-17 Thread Kevin Wolf
From: Vladimir Sementsov-Ogievskiy Other bitmap related actions use the .bitmap pointer in .abort action, let's do same here: 1. It helps further refactoring, as bitmap-add is the only bitmap action that uses state.action in .abort 2. It must be safe: transaction actions rely on the fact

[PULL 07/18] docs/interop/qcow2.txt: fix description about "zlib" clusters

2023-05-17 Thread Kevin Wolf
From: Akihiro Suda "zlib" clusters are actually raw deflate (RFC1951) clusters without zlib headers. Signed-off-by: Akihiro Suda Message-Id: <168424874322.11954.134094204635185952...@git.sr.ht> Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf ---

[PULL 00/18] Block layer patches

2023-05-17 Thread Kevin Wolf
The following changes since commit 6972ef1440a9d685482d78672620a7482f2bd09a: Merge tag 'pull-tcg-20230516-3' of https://gitlab.com/rth7680/qemu into staging (2023-05-16 21:30:27 -0700) are available in the Git repository at: https://repo.or.cz/qemu/kevin.git tags/for-upstream for you to

Re: [PATCH 0/2] aio-posix: do not nest poll handlers

2023-05-17 Thread Kevin Wolf
Am 02.05.2023 um 20:41 hat Stefan Hajnoczi geschrieben: > The following stack exhaustion was reported in > https://bugzilla.redhat.com/show_bug.cgi?id=2186181: > > ... > #51 0x55884fca7451 aio_poll (qemu-kvm + 0x9d6451) > #52 0x55884fab9cbd bdrv_poll_co (qemu-kvm + 0x7e8cbd) > #53

Re: [PATCH qemu] docs/interop/qcow2.txt: fix description about "zlib" clusters

2023-05-17 Thread Kevin Wolf
Am 16.05.2023 um 16:32 hat ~akihirosuda geschrieben: > From: Akihiro Suda > > "zlib" clusters are actually raw deflate (RFC1951) clusters without > zlib headers. > > Signed-off-by: Akihiro Suda Thanks, applied to the block branch. Kevin

[PATCH 3/3] iotests: Test commit with iothreads and ongoing I/O

2023-05-17 Thread Kevin Wolf
This tests exercises graph locking, draining, and graph modifications with AioContext switches a lot. Amongst others, it serves as a regression test for bdrv_graph_wrlock() deadlocking because it is called with a locked AioContext and for AioContext handling in the NBD server. Signed-off-by:

[PATCH 2/3] nbd/server: Fix drained_poll to wake coroutine in right AioContext

2023-05-17 Thread Kevin Wolf
nbd_drained_poll() generally runs in the main thread, not whatever iothread the NBD server coroutine is meant to run in, so it can't directly reenter the coroutines to wake them up. The code seems to have the right intention, it specifies the correct AioContext when it calls

[PATCH 1/3] graph-lock: Disable locking for now

2023-05-17 Thread Kevin Wolf
In QEMU 8.0, we've been seeing deadlocks in bdrv_graph_wrlock(). They come from callers that hold an AioContext lock, which is not allowed during polling. In theory, we could temporarily release the lock, but callers are inconsistent about whether they hold a lock, and if they do, some are also

[PATCH 0/3] block/graph-lock: Disable locking for now

2023-05-17 Thread Kevin Wolf
tl;dr is that graph locking introduced deadlocks in 8.0, and disabling it for now fixes them again. See patch 1 for the details. I still intend the fix this properly before we remove the AioContext lock (which is when the deadlock would be automatically solved), but it's not trivial enough for

Re: [PATCH v3 1/1] block/blkio: use qemu_open() to support fd passing for virtio-blk

2023-05-17 Thread Stefan Hajnoczi
On Wed, May 17, 2023 at 09:19:26AM +0200, Stefano Garzarella wrote: > CCing Markus for some advice. > > On Tue, May 16, 2023 at 11:04:21AM -0500, Jonathon Jongsma wrote: > > On 5/15/23 5:10 AM, Stefano Garzarella wrote: > > > On Thu, May 11, 2023 at 11:03:22AM -0500, Jonathon Jongsma wrote: > > >

Re: [PATCH v3 1/1] block/blkio: use qemu_open() to support fd passing for virtio-blk

2023-05-17 Thread Stefano Garzarella
CCing Markus for some advice. On Tue, May 16, 2023 at 11:04:21AM -0500, Jonathon Jongsma wrote: On 5/15/23 5:10 AM, Stefano Garzarella wrote: On Thu, May 11, 2023 at 11:03:22AM -0500, Jonathon Jongsma wrote: On 5/11/23 4:15 AM, Stefano Garzarella wrote: The virtio-blk-vhost-vdpa driver in