qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block: Acquire the AioContext in guess_disk_lchs()
@ 2019-01-09 14:28 Alberto Garcia
  2019-01-09 14:50 ` Stefan Hajnoczi
  2019-01-09 15:07 ` Kevin Wolf
  0 siblings, 2 replies; 4+ messages in thread
From: Alberto Garcia @ 2019-01-09 14:28 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alberto Garcia, qemu-block, Stefan Hajnoczi, Paolo Bonzini,
	Kevin Wolf, Max Reitz

This fixes the following crash:

{ "execute": "blockdev-add",
  "arguments": {"driver": "null-co", "node-name": "hd0"}}
{ "execute": "object-add",
  "arguments": {"qom-type": "iothread", "id": "iothread0"}}
{ "execute": "x-blockdev-set-iothread",
  "arguments": {"node-name": "hd0", "iothread": "iothread0"}}
{ "execute": "device_add",
  "arguments": {"id": "virtio0", "driver": "virtio-blk-pci",
                "drive": "hd0"}}
qemu: qemu_mutex_unlock_impl: Operation not permitted
Aborted

Signed-off-by: Alberto Garcia <berto@igalia.com>
---
 hw/block/hd-geometry.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c
index 79384a2b0a..0d9a7b7e7d 100644
--- a/hw/block/hd-geometry.c
+++ b/hw/block/hd-geometry.c
@@ -55,6 +55,7 @@ struct partition {
 static int guess_disk_lchs(BlockBackend *blk,
                            int *pcylinders, int *pheads, int *psectors)
 {
+    AioContext *ctx = blk_get_aio_context(blk);
     uint8_t buf[BDRV_SECTOR_SIZE];
     int i, heads, sectors, cylinders;
     struct partition *p;
@@ -68,7 +69,10 @@ static int guess_disk_lchs(BlockBackend *blk,
      * but also in async I/O mode. So the I/O throttling function has to
      * be disabled temporarily here, not permanently.
      */
-    if (blk_pread_unthrottled(blk, 0, buf, BDRV_SECTOR_SIZE) < 0) {
+    aio_context_acquire(ctx);
+    i = blk_pread_unthrottled(blk, 0, buf, BDRV_SECTOR_SIZE);
+    aio_context_release(ctx);
+    if (i < 0) {
         return -1;
     }
     /* test msdos magic */
-- 
2.11.0

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

* Re: [Qemu-devel] [PATCH] block: Acquire the AioContext in guess_disk_lchs()
  2019-01-09 14:28 [Qemu-devel] [PATCH] block: Acquire the AioContext in guess_disk_lchs() Alberto Garcia
@ 2019-01-09 14:50 ` Stefan Hajnoczi
  2019-01-09 15:07 ` Kevin Wolf
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2019-01-09 14:50 UTC (permalink / raw)
  To: Alberto Garcia
  Cc: qemu-devel, qemu-block, Paolo Bonzini, Kevin Wolf, Max Reitz

[-- Attachment #1: Type: text/plain, Size: 802 bytes --]

On Wed, Jan 09, 2019 at 04:28:50PM +0200, Alberto Garcia wrote:
> This fixes the following crash:
> 
> { "execute": "blockdev-add",
>   "arguments": {"driver": "null-co", "node-name": "hd0"}}
> { "execute": "object-add",
>   "arguments": {"qom-type": "iothread", "id": "iothread0"}}
> { "execute": "x-blockdev-set-iothread",
>   "arguments": {"node-name": "hd0", "iothread": "iothread0"}}
> { "execute": "device_add",
>   "arguments": {"id": "virtio0", "driver": "virtio-blk-pci",
>                 "drive": "hd0"}}
> qemu: qemu_mutex_unlock_impl: Operation not permitted
> Aborted
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> ---
>  hw/block/hd-geometry.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

* Re: [Qemu-devel] [PATCH] block: Acquire the AioContext in guess_disk_lchs()
  2019-01-09 14:28 [Qemu-devel] [PATCH] block: Acquire the AioContext in guess_disk_lchs() Alberto Garcia
  2019-01-09 14:50 ` Stefan Hajnoczi
@ 2019-01-09 15:07 ` Kevin Wolf
  2019-01-09 17:28   ` Alberto Garcia
  1 sibling, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2019-01-09 15:07 UTC (permalink / raw)
  To: Alberto Garcia
  Cc: qemu-devel, qemu-block, Stefan Hajnoczi, Paolo Bonzini, Max Reitz,
	armbru

Am 09.01.2019 um 15:28 hat Alberto Garcia geschrieben:
> This fixes the following crash:
> 
> { "execute": "blockdev-add",
>   "arguments": {"driver": "null-co", "node-name": "hd0"}}
> { "execute": "object-add",
>   "arguments": {"qom-type": "iothread", "id": "iothread0"}}
> { "execute": "x-blockdev-set-iothread",
>   "arguments": {"node-name": "hd0", "iothread": "iothread0"}}
> { "execute": "device_add",
>   "arguments": {"id": "virtio0", "driver": "virtio-blk-pci",
>                 "drive": "hd0"}}
> qemu: qemu_mutex_unlock_impl: Operation not permitted
> Aborted
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>

This looks like the same thing that I talked about with Markus
yesterday. He asked me where to put the acquire/release pair. My answer
was that there is more than one way to do it, but I suspect that the
realize functions of the devices may call the block layer more than once
and putting the acquire/release there might be nicer. We would then
document blkconf_geometry() to assume that the AioContext is already
locked.

There are many calls for node management stuff where we never defined
the locking rules, but where we might reasonably assume that they only
affect things that are only ever accessed from the main thread. But
there are also things like blk_ioctl() in scsi_block_realize(), which
should most certainly run with the lock held.

What do you think?

(I also wondered whether virtio-blk is affected as well or whether it
moves the BlockBackend to the iothread AioContext only later. Your
reproducer answers this question. :-))

Kevin

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

* Re: [Qemu-devel] [PATCH] block: Acquire the AioContext in guess_disk_lchs()
  2019-01-09 15:07 ` Kevin Wolf
@ 2019-01-09 17:28   ` Alberto Garcia
  0 siblings, 0 replies; 4+ messages in thread
From: Alberto Garcia @ 2019-01-09 17:28 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: qemu-devel, qemu-block, Stefan Hajnoczi, Paolo Bonzini, Max Reitz,
	armbru

On Wed 09 Jan 2019 04:07:33 PM CET, Kevin Wolf wrote:
> This looks like the same thing that I talked about with Markus
> yesterday. He asked me where to put the acquire/release pair. My
> answer was that there is more than one way to do it, but I suspect
> that the realize functions of the devices may call the block layer
> more than once and putting the acquire/release there might be nicer.

Makes sense I guess, and it should be safe. I'll give it a try tomorrow
and send a new patch.

Berto

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

end of thread, other threads:[~2019-01-09 17:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-09 14:28 [Qemu-devel] [PATCH] block: Acquire the AioContext in guess_disk_lchs() Alberto Garcia
2019-01-09 14:50 ` Stefan Hajnoczi
2019-01-09 15:07 ` Kevin Wolf
2019-01-09 17:28   ` Alberto Garcia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).