* [PATCH] virtio-blk: add missing AioContext lock
@ 2023-02-08 11:11 Emanuele Giuseppe Esposito
2023-02-08 12:33 ` Lukáš Doktor
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Emanuele Giuseppe Esposito @ 2023-02-08 11:11 UTC (permalink / raw)
To: qemu-block
Cc: Michael S. Tsirkin, Stefan Hajnoczi, Kevin Wolf, Hanna Reitz,
qemu-devel, Emanuele Giuseppe Esposito
virtio_blk_update_config() calls blk_get_geometry and blk_getlength,
and both functions eventually end up calling bdrv_poll_co when not
running in a coroutine:
- blk_getlength is a co_wrapper_mixed function
- blk_get_geometry calls bdrv_get_geometry -> bdrv_nb_sectors, a
co_wrapper_mixed function too
Since we are not running in a coroutine, we need to take s->blk
AioContext lock, otherwise bdrv_poll_co will inevitably call
AIO_WAIT_WHILE and therefore try to un unlock() an AioContext lock
that was never acquired.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2167838
Steps to reproduce the issue: simply boot a VM with
-object '{"qom-type":"iothread","id":"iothread1"}' \
-blockdev '{"driver":"file","filename":"$QCOW2","aio":"native","node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-1-storage"}' \
-device virtio-blk-pci,iothread=iothread1,drive=libvirt-1-format,id=virtio-disk0,bootindex=1,write-cache=on
and observe that it will fail not manage to boot with "qemu_mutex_unlock_impl: Operation not permitted"
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
hw/block/virtio-blk.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 1762517878..cefca93b31 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -894,6 +894,10 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
uint64_t capacity;
int64_t length;
int blk_size = conf->logical_block_size;
+ AioContext *ctx;
+
+ ctx = blk_get_aio_context(s->blk);
+ aio_context_acquire(ctx);
blk_get_geometry(s->blk, &capacity);
memset(&blkcfg, 0, sizeof(blkcfg));
@@ -917,6 +921,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
* per track (cylinder).
*/
length = blk_getlength(s->blk);
+ aio_context_release(ctx);
if (length > 0 && length / conf->heads / conf->secs % blk_size) {
blkcfg.geometry.sectors = conf->secs & ~s->sector_mask;
} else {
--
2.39.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: add missing AioContext lock
2023-02-08 11:11 [PATCH] virtio-blk: add missing AioContext lock Emanuele Giuseppe Esposito
@ 2023-02-08 12:33 ` Lukáš Doktor
2023-02-08 14:21 ` Michael S. Tsirkin
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Lukáš Doktor @ 2023-02-08 12:33 UTC (permalink / raw)
To: Emanuele Giuseppe Esposito, qemu-block
Cc: Michael S. Tsirkin, Stefan Hajnoczi, Kevin Wolf, Hanna Reitz, qemu-devel
[-- Attachment #1.1.1: Type: text/plain, Size: 2596 bytes --]
Dne 08. 02. 23 v 12:11 Emanuele Giuseppe Esposito napsal(a):
> virtio_blk_update_config() calls blk_get_geometry and blk_getlength,
> and both functions eventually end up calling bdrv_poll_co when not
> running in a coroutine:
> - blk_getlength is a co_wrapper_mixed function
> - blk_get_geometry calls bdrv_get_geometry -> bdrv_nb_sectors, a
> co_wrapper_mixed function too
>
> Since we are not running in a coroutine, we need to take s->blk
> AioContext lock, otherwise bdrv_poll_co will inevitably call
> AIO_WAIT_WHILE and therefore try to un unlock() an AioContext lock
> that was never acquired.
>
> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2167838
>
> Steps to reproduce the issue: simply boot a VM with
> -object '{"qom-type":"iothread","id":"iothread1"}' \
> -blockdev '{"driver":"file","filename":"$QCOW2","aio":"native","node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"}' \
> -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-1-storage"}' \
> -device virtio-blk-pci,iothread=iothread1,drive=libvirt-1-format,id=virtio-disk0,bootindex=1,write-cache=on
>
> and observe that it will fail not manage to boot with "qemu_mutex_unlock_impl: Operation not permitted"
>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> ---
> hw/block/virtio-blk.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index 1762517878..cefca93b31 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -894,6 +894,10 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
> uint64_t capacity;
> int64_t length;
> int blk_size = conf->logical_block_size;
> + AioContext *ctx;
> +
> + ctx = blk_get_aio_context(s->blk);
> + aio_context_acquire(ctx);
>
> blk_get_geometry(s->blk, &capacity);
> memset(&blkcfg, 0, sizeof(blkcfg));
> @@ -917,6 +921,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
> * per track (cylinder).
> */
> length = blk_getlength(s->blk);
> + aio_context_release(ctx);
> if (length > 0 && length / conf->heads / conf->secs % blk_size) {
> blkcfg.geometry.sectors = conf->secs & ~s->sector_mask;
> } else {
Thanks, I can't talk about the correctness of the code but function-wise it addresses the issue.
Tested-by: Lukáš Doktor <ldoktor@redhat.com>
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 10599 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: add missing AioContext lock
2023-02-08 11:11 [PATCH] virtio-blk: add missing AioContext lock Emanuele Giuseppe Esposito
2023-02-08 12:33 ` Lukáš Doktor
@ 2023-02-08 14:21 ` Michael S. Tsirkin
2023-02-09 15:20 ` Stefan Hajnoczi
2023-02-09 15:21 ` Stefan Hajnoczi
3 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2023-02-08 14:21 UTC (permalink / raw)
To: Emanuele Giuseppe Esposito
Cc: qemu-block, Stefan Hajnoczi, Kevin Wolf, Hanna Reitz, qemu-devel
On Wed, Feb 08, 2023 at 06:11:48AM -0500, Emanuele Giuseppe Esposito wrote:
> virtio_blk_update_config() calls blk_get_geometry and blk_getlength,
> and both functions eventually end up calling bdrv_poll_co when not
> running in a coroutine:
> - blk_getlength is a co_wrapper_mixed function
> - blk_get_geometry calls bdrv_get_geometry -> bdrv_nb_sectors, a
> co_wrapper_mixed function too
>
> Since we are not running in a coroutine, we need to take s->blk
> AioContext lock, otherwise bdrv_poll_co will inevitably call
> AIO_WAIT_WHILE and therefore try to un unlock() an AioContext lock
> that was never acquired.
>
> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2167838
>
> Steps to reproduce the issue: simply boot a VM with
> -object '{"qom-type":"iothread","id":"iothread1"}' \
> -blockdev '{"driver":"file","filename":"$QCOW2","aio":"native","node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"}' \
> -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-1-storage"}' \
> -device virtio-blk-pci,iothread=iothread1,drive=libvirt-1-format,id=virtio-disk0,bootindex=1,write-cache=on
>
> and observe that it will fail not manage to boot with "qemu_mutex_unlock_impl: Operation not permitted"
>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
looks reasonable
Acked-by: Michael S. Tsirkin <mst@redhat.com>
merge in block tree pls.
> ---
> hw/block/virtio-blk.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index 1762517878..cefca93b31 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -894,6 +894,10 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
> uint64_t capacity;
> int64_t length;
> int blk_size = conf->logical_block_size;
> + AioContext *ctx;
> +
> + ctx = blk_get_aio_context(s->blk);
> + aio_context_acquire(ctx);
>
> blk_get_geometry(s->blk, &capacity);
> memset(&blkcfg, 0, sizeof(blkcfg));
> @@ -917,6 +921,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
> * per track (cylinder).
> */
> length = blk_getlength(s->blk);
> + aio_context_release(ctx);
> if (length > 0 && length / conf->heads / conf->secs % blk_size) {
> blkcfg.geometry.sectors = conf->secs & ~s->sector_mask;
> } else {
> --
> 2.39.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: add missing AioContext lock
2023-02-08 11:11 [PATCH] virtio-blk: add missing AioContext lock Emanuele Giuseppe Esposito
2023-02-08 12:33 ` Lukáš Doktor
2023-02-08 14:21 ` Michael S. Tsirkin
@ 2023-02-09 15:20 ` Stefan Hajnoczi
2023-02-09 15:21 ` Stefan Hajnoczi
3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2023-02-09 15:20 UTC (permalink / raw)
To: Emanuele Giuseppe Esposito
Cc: qemu-block, Michael S. Tsirkin, Kevin Wolf, Hanna Reitz, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1574 bytes --]
On Wed, Feb 08, 2023 at 06:11:48AM -0500, Emanuele Giuseppe Esposito wrote:
> virtio_blk_update_config() calls blk_get_geometry and blk_getlength,
> and both functions eventually end up calling bdrv_poll_co when not
> running in a coroutine:
> - blk_getlength is a co_wrapper_mixed function
> - blk_get_geometry calls bdrv_get_geometry -> bdrv_nb_sectors, a
> co_wrapper_mixed function too
>
> Since we are not running in a coroutine, we need to take s->blk
> AioContext lock, otherwise bdrv_poll_co will inevitably call
> AIO_WAIT_WHILE and therefore try to un unlock() an AioContext lock
> that was never acquired.
>
> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2167838
>
> Steps to reproduce the issue: simply boot a VM with
> -object '{"qom-type":"iothread","id":"iothread1"}' \
> -blockdev '{"driver":"file","filename":"$QCOW2","aio":"native","node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"}' \
> -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-1-storage"}' \
> -device virtio-blk-pci,iothread=iothread1,drive=libvirt-1-format,id=virtio-disk0,bootindex=1,write-cache=on
>
> and observe that it will fail not manage to boot with "qemu_mutex_unlock_impl: Operation not permitted"
>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> ---
> hw/block/virtio-blk.c | 5 +++++
> 1 file changed, 5 insertions(+)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio-blk: add missing AioContext lock
2023-02-08 11:11 [PATCH] virtio-blk: add missing AioContext lock Emanuele Giuseppe Esposito
` (2 preceding siblings ...)
2023-02-09 15:20 ` Stefan Hajnoczi
@ 2023-02-09 15:21 ` Stefan Hajnoczi
3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2023-02-09 15:21 UTC (permalink / raw)
To: Emanuele Giuseppe Esposito
Cc: qemu-block, Michael S. Tsirkin, Kevin Wolf, Hanna Reitz, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 1615 bytes --]
On Wed, Feb 08, 2023 at 06:11:48AM -0500, Emanuele Giuseppe Esposito wrote:
> virtio_blk_update_config() calls blk_get_geometry and blk_getlength,
> and both functions eventually end up calling bdrv_poll_co when not
> running in a coroutine:
> - blk_getlength is a co_wrapper_mixed function
> - blk_get_geometry calls bdrv_get_geometry -> bdrv_nb_sectors, a
> co_wrapper_mixed function too
>
> Since we are not running in a coroutine, we need to take s->blk
> AioContext lock, otherwise bdrv_poll_co will inevitably call
> AIO_WAIT_WHILE and therefore try to un unlock() an AioContext lock
> that was never acquired.
>
> RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=2167838
>
> Steps to reproduce the issue: simply boot a VM with
> -object '{"qom-type":"iothread","id":"iothread1"}' \
> -blockdev '{"driver":"file","filename":"$QCOW2","aio":"native","node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},"auto-read-only":true,"discard":"unmap"}' \
> -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"direct":true,"no-flush":false},"driver":"qcow2","file":"libvirt-1-storage"}' \
> -device virtio-blk-pci,iothread=iothread1,drive=libvirt-1-format,id=virtio-disk0,bootindex=1,write-cache=on
>
> and observe that it will fail not manage to boot with "qemu_mutex_unlock_impl: Operation not permitted"
>
> Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
> ---
> hw/block/virtio-blk.c | 5 +++++
> 1 file changed, 5 insertions(+)
Thanks, applied to my block tree:
https://gitlab.com/stefanha/qemu/commits/block
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-02-09 15:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08 11:11 [PATCH] virtio-blk: add missing AioContext lock Emanuele Giuseppe Esposito
2023-02-08 12:33 ` Lukáš Doktor
2023-02-08 14:21 ` Michael S. Tsirkin
2023-02-09 15:20 ` Stefan Hajnoczi
2023-02-09 15:21 ` Stefan Hajnoczi
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.