Skip to contentSkip to conversation

Block patches

GIT PULL Stefan Hajnoczi 4 participants 14 messages Feb 11, 2019 – Feb 12, 2019

lore
Share & tools
lore
#1 lore raw

[Qemu-devel] [PULL 2/9] qemugdb/coroutine: fix arch_prctl has unknown return type

In reply to Stefan Hajnoczi

From: Vladimir Sementsov-Ogievskiy <[email protected]>

qemu coroutine command results in following error output:

Python Exception <class 'gdb.error'> 'arch_prctl' has unknown return type; cast the call to its declared return type: Error occurred in Python command: 'arch_prctl' has unknown return type; cast the call to its declared return type

Fix it by giving it what it wants: arch_prctl return type.

Information on the topic:
https://sourceware.org/gdb/onlinedocs/gdb/Calling.html

Message-id: [email protected]

---
 scripts/qemugdb/coroutine.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qemugdb/coroutine.py +1 -1
index ab699794ab..81f811ac00 100644
@@ -22,7 +22,7 @@ def get_fs_base():
        pthread_self().'''
     # %rsp - 120 is scratch space according to the SystemV ABI
     old = gdb.parse_and_eval('*(uint64_t*)($rsp - 120)')
-    gdb.execute('call arch_prctl(0x1003, $rsp - 120)', False, True)
+    gdb.execute('call (int)arch_prctl(0x1003, $rsp - 120)', False, True)
     fs_base = gdb.parse_and_eval('*(uint64_t*)($rsp - 120)')
     gdb.execute('set *(uint64_t*)($rsp - 120) = %s' % old, False, True)
     return fs_base
Signature · 1 line
2.20.1
#2 lore raw

[Qemu-devel] [PULL 3/9] virtio-blk: cleanup using VirtIOBlock *s and VirtIODevice *vdev

In reply to Stefan Hajnoczi

From: Stefano Garzarella <[email protected]>

In several part we still using req->dev or VIRTIO_DEVICE(req->dev) when we have already defined s and vdev pointers:

    VirtIOBlock *s = req->dev;
    VirtIODevice *vdev = VIRTIO_DEVICE(s);

Message-id: [email protected]

---
 hw/block/virtio-blk.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
hw/block/virtio-blk.c +9 -13
index 9a87b3bfac..843bb2bec8 100644
@@ -63,9 +63,8 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
 static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
     bool is_read)
 {
-    BlockErrorAction action = blk_get_error_action(req->dev->blk,
-                                                   is_read, error);
     VirtIOBlock *s = req->dev;
+    BlockErrorAction action = blk_get_error_action(s->blk, is_read, error);
 
     if (action == BLOCK_ERROR_ACTION_STOP) {
         /* Break the link as the next request is going to be parsed from the
@@ -138,7 +137,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
     }
 
     virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
-    block_acct_done(blk_get_stats(req->dev->blk), &req->acct);
+    block_acct_done(blk_get_stats(s->blk), &req->acct);
     virtio_blk_free_request(req);
 
 out:
@@ -513,7 +512,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
               - sizeof(struct virtio_blk_inhdr);
     iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr));
 
-    type = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out.type);
+    type = virtio_ldl_p(vdev, &req->out.type);
 
     /* VIRTIO_BLK_T_OUT defines the command direction. VIRTIO_BLK_T_BARRIER
      * is an optional flag. Although a guest should not send this flag if
@@ -522,8 +521,7 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
     case VIRTIO_BLK_T_IN:
     {
         bool is_write = type & VIRTIO_BLK_T_OUT;
-        req->sector_num = virtio_ldq_p(VIRTIO_DEVICE(req->dev),
-                                       &req->out.sector);
+        req->sector_num = virtio_ldq_p(vdev, &req->out.sector);
 
         if (is_write) {
             qemu_iovec_init_external(&req->qiov, out_iov, out_num);
@@ -535,25 +533,23 @@ static int virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb)
                                          req->qiov.size / BDRV_SECTOR_SIZE);
         }
 
-        if (!virtio_blk_sect_range_ok(req->dev, req->sector_num,
-                                      req->qiov.size)) {
+        if (!virtio_blk_sect_range_ok(s, req->sector_num, req->qiov.size)) {
             virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
-            block_acct_invalid(blk_get_stats(req->dev->blk),
+            block_acct_invalid(blk_get_stats(s->blk),
                                is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
             virtio_blk_free_request(req);
             return 0;
         }
 
-        block_acct_start(blk_get_stats(req->dev->blk),
-                         &req->acct, req->qiov.size,
+        block_acct_start(blk_get_stats(s->blk), &req->acct, req->qiov.size,
                          is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ);
 
         /* merge would exceed maximum number of requests or IO direction
          * changes */
         if (mrb->num_reqs > 0 && (mrb->num_reqs == VIRTIO_BLK_MAX_MERGE_REQS ||
                                   is_write != mrb->is_write ||
-                                  !req->dev->conf.request_merging)) {
-            virtio_blk_submit_multireq(req->dev->blk, mrb);
+                                  !s->conf.request_merging)) {
+            virtio_blk_submit_multireq(s->blk, mrb);
         }
 
         assert(mrb->num_reqs < VIRTIO_BLK_MAX_MERGE_REQS);
Signature · 1 line
2.20.1
#3 lore raw

[Qemu-devel] [PULL 4/9] virtio-blk: add acct_failed param to virtio_blk_handle_rw_error()

In reply to Stefan Hajnoczi

From: Stefano Garzarella <[email protected]>

We add acct_failed param in order to use virtio_blk_handle_rw_error() also when is not required to call block_acct_failed(). (eg. a discard operation is failed)

Message-id: [email protected]

---
 hw/block/virtio-blk.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/block/virtio-blk.c +6 -4
index 843bb2bec8..c95a6f4c9b 100644
@@ -61,7 +61,7 @@ static void virtio_blk_req_complete(VirtIOBlockReq *req, unsigned char status)
 }
 
 static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
-    bool is_read)
+    bool is_read, bool acct_failed)
 {
     VirtIOBlock *s = req->dev;
     BlockErrorAction action = blk_get_error_action(s->blk, is_read, error);
@@ -74,7 +74,9 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
         s->rq = req;
     } else if (action == BLOCK_ERROR_ACTION_REPORT) {
         virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
-        block_acct_failed(blk_get_stats(s->blk), &req->acct);
+        if (acct_failed) {
+            block_acct_failed(blk_get_stats(s->blk), &req->acct);
+        }
         virtio_blk_free_request(req);
     }
 
@@ -112,7 +114,7 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
              * the memory until the request is completed (which will
              * happen on the other side of the migration).
              */
-            if (virtio_blk_handle_rw_error(req, -ret, is_read)) {
+            if (virtio_blk_handle_rw_error(req, -ret, is_read, true)) {
                 continue;
             }
         }
@@ -131,7 +133,7 @@ static void virtio_blk_flush_complete(void *opaque, int ret)
 
     aio_context_acquire(blk_get_aio_context(s->conf.conf.blk));
     if (ret) {
-        if (virtio_blk_handle_rw_error(req, -ret, 0)) {
+        if (virtio_blk_handle_rw_error(req, -ret, 0, true)) {
             goto out;
         }
     }
Signature · 1 line
2.20.1
#4 lore raw

[Qemu-devel] [PULL 5/9] virtio-blk: add host_features field in VirtIOBlock

In reply to Stefan Hajnoczi

From: Stefano Garzarella <[email protected]>

Since configurable features for virtio-blk are growing, this patch adds host_features field in the struct VirtIOBlock. (as in virtio-net) In this way, we can avoid to add new fields for new properties and we can directly set VIRTIO_BLK_F* flags in the host_features.

We update "config-wce" and "scsi" property definition to use the new host_features field without change the behaviour.

Message-id: [email protected]

---
 include/hw/virtio/virtio-blk.h |  3 +--
 hw/block/virtio-blk.c          | 16 +++++++++-------
 2 files changed, 10 insertions(+), 9 deletions(-)
include/hw/virtio/virtio-blk.h +1 -2
index 5117431d96..f7345b0511 100644
@@ -35,8 +35,6 @@ struct VirtIOBlkConf
     BlockConf conf;
     IOThread *iothread;
     char *serial;
-    uint32_t scsi;
-    uint32_t config_wce;
     uint32_t request_merging;
     uint16_t num_queues;
     uint16_t queue_size;
@@ -57,6 +55,7 @@ typedef struct VirtIOBlock {
     bool dataplane_disabled;
     bool dataplane_started;
     struct VirtIOBlockDataPlane *dataplane;
+    uint64_t host_features;
 } VirtIOBlock;
 
 typedef struct VirtIOBlockReq {
hw/block/virtio-blk.c +9 -7
index c95a6f4c9b..6526b94910 100644
@@ -241,7 +241,7 @@ static int virtio_blk_handle_scsi_req(VirtIOBlockReq *req)
      */
     scsi = (void *)elem->in_sg[elem->in_num - 2].iov_base;
 
-    if (!blk->conf.scsi) {
+    if (!virtio_has_feature(blk->host_features, VIRTIO_BLK_F_SCSI)) {
         status = VIRTIO_BLK_S_UNSUPP;
         goto fail;
     }
@@ -779,12 +779,15 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features,
 {
     VirtIOBlock *s = VIRTIO_BLK(vdev);
 
+    /* Firstly sync all virtio-blk possible supported features */
+    features |= s->host_features;
+
     virtio_add_feature(&features, VIRTIO_BLK_F_SEG_MAX);
     virtio_add_feature(&features, VIRTIO_BLK_F_GEOMETRY);
     virtio_add_feature(&features, VIRTIO_BLK_F_TOPOLOGY);
     virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE);
     if (virtio_has_feature(features, VIRTIO_F_VERSION_1)) {
-        if (s->conf.scsi) {
+        if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_SCSI)) {
             error_setg(errp, "Please set scsi=off for virtio-blk devices in order to use virtio 1.0");
             return 0;
         }
@@ -793,9 +796,6 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features,
         virtio_add_feature(&features, VIRTIO_BLK_F_SCSI);
     }
 
-    if (s->conf.config_wce) {
-        virtio_add_feature(&features, VIRTIO_BLK_F_CONFIG_WCE);
-    }
     if (blk_enable_write_cache(s->blk)) {
         virtio_add_feature(&features, VIRTIO_BLK_F_WCE);
     }
@@ -1010,9 +1010,11 @@ static Property virtio_blk_properties[] = {
     DEFINE_BLOCK_ERROR_PROPERTIES(VirtIOBlock, conf.conf),
     DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf),
     DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial),
-    DEFINE_PROP_BIT("config-wce", VirtIOBlock, conf.config_wce, 0, true),
+    DEFINE_PROP_BIT64("config-wce", VirtIOBlock, host_features,
+                      VIRTIO_BLK_F_CONFIG_WCE, true),
 #ifdef __linux__
-    DEFINE_PROP_BIT("scsi", VirtIOBlock, conf.scsi, 0, false),
+    DEFINE_PROP_BIT64("scsi", VirtIOBlock, host_features,
+                      VIRTIO_BLK_F_SCSI, false),
 #endif
     DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, 0,
                     true),
Signature · 1 line
2.20.1
#5 lore raw

[Qemu-devel] [PULL 6/9] virtio-blk: add "discard" and "write-zeroes" properties

In reply to Stefan Hajnoczi

From: Stefano Garzarella <[email protected]>

In order to avoid migration issues, we enable DISCARD and WRITE_ZEROES features only for machine type >= 4.0

As discussed with Michael S. Tsirkin and Stefan Hajnoczi on the list [1], DISCARD operation should not have security implications (eg. page cache attacks), so we can enable it by default.

[1] https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00504.html

Message-id: [email protected]

---
 hw/block/virtio-blk.c | 4 ++++
 hw/core/machine.c     | 2 ++
 2 files changed, 6 insertions(+)
hw/block/virtio-blk.c +4 -0
index 6526b94910..feeaf77965 100644
@@ -1022,6 +1022,10 @@ static Property virtio_blk_properties[] = {
     DEFINE_PROP_UINT16("queue-size", VirtIOBlock, conf.queue_size, 128),
     DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD,
                      IOThread *),
+    DEFINE_PROP_BIT64("discard", VirtIOBlock, host_features,
+                      VIRTIO_BLK_F_DISCARD, true),
+    DEFINE_PROP_BIT64("write-zeroes", VirtIOBlock, host_features,
+                      VIRTIO_BLK_F_WRITE_ZEROES, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/core/machine.c +2 -0
index 077fbd182a..766ca5899d 100644
@@ -33,6 +33,8 @@ GlobalProperty hw_compat_3_1[] = {
     { "usb-kbd", "serial", "42" },
     { "usb-mouse", "serial", "42" },
     { "usb-kbd", "serial", "42" },
+    { "virtio-blk-device", "discard", "false" },
+    { "virtio-blk-device", "write-zeroes", "false" },
 };
 const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1);
 
Signature · 1 line
2.20.1
#6 lore raw

[Qemu-devel] [PULL 7/9] virtio-blk: add DISCARD and WRITE_ZEROES features

In reply to Stefan Hajnoczi

From: Stefano Garzarella <[email protected]>

This patch adds the support of DISCARD and WRITE_ZEROES commands, that have been introduced in the virtio-blk protocol to have better performance when using SSD backend.

We support only one segment per request since multiple segments are not widely used and there are no userspace APIs that allow applications to submit multiple segments in a single call.

Message-id: [email protected]

---
 include/hw/virtio/virtio-blk.h |   2 +
 hw/block/virtio-blk.c          | 184 +++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+)
include/hw/virtio/virtio-blk.h +2 -0
index f7345b0511..015b523fe0 100644
@@ -38,6 +38,8 @@ struct VirtIOBlkConf
     uint32_t request_merging;
     uint16_t num_queues;
     uint16_t queue_size;
+    uint32_t max_discard_sectors;
+    uint32_t max_write_zeroes_sectors;
 };
 
 struct VirtIOBlockDataPlane;
hw/block/virtio-blk.c +184 -0

220 lines not on this page · raw message

Signature · 1 line
2.20.1
#7 lore raw

[Qemu-devel] [PULL 9/9] tests/virtio-blk: add test for WRITE_ZEROES command

In reply to Stefan Hajnoczi

From: Stefano Garzarella <[email protected]>

If the WRITE_ZEROES feature is enabled, we check this command in the test_basic().

Message-id: [email protected]

---
 tests/virtio-blk-test.c | 60 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
tests/virtio-blk-test.c +60 -0
index 0739498da7..35bd92dbfc 100644
@@ -244,6 +244,66 @@ static void test_basic(QVirtioDevice *dev, QGuestAllocator *alloc,
 
     guest_free(alloc, req_addr);
 
+    if (features & (1u << VIRTIO_BLK_F_WRITE_ZEROES)) {
+        struct virtio_blk_discard_write_zeroes dwz_hdr;
+        void *expected;
+
+        /*
+         * WRITE_ZEROES request on the same sector of previous test where
+         * we wrote "TEST".
+         */
+        req.type = VIRTIO_BLK_T_WRITE_ZEROES;
+        req.data = (char *) &dwz_hdr;
+        dwz_hdr.sector = 0;
+        dwz_hdr.num_sectors = 1;
+        dwz_hdr.flags = 0;
+
+        req_addr = virtio_blk_request(alloc, dev, &req, sizeof(dwz_hdr));
+
+        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
+        qvirtqueue_add(vq, req_addr + 16, sizeof(dwz_hdr), false, true);
+        qvirtqueue_add(vq, req_addr + 16 + sizeof(dwz_hdr), 1, true, false);
+
+        qvirtqueue_kick(dev, vq, free_head);
+
+        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+                               QVIRTIO_BLK_TIMEOUT_US);
+        status = readb(req_addr + 16 + sizeof(dwz_hdr));
+        g_assert_cmpint(status, ==, 0);
+
+        guest_free(alloc, req_addr);
+
+        /* Read request to check if the sector contains all zeroes */
+        req.type = VIRTIO_BLK_T_IN;
+        req.ioprio = 1;
+        req.sector = 0;
+        req.data = g_malloc0(512);
+
+        req_addr = virtio_blk_request(alloc, dev, &req, 512);
+
+        g_free(req.data);
+
+        free_head = qvirtqueue_add(vq, req_addr, 16, false, true);
+        qvirtqueue_add(vq, req_addr + 16, 512, true, true);
+        qvirtqueue_add(vq, req_addr + 528, 1, true, false);
+
+        qvirtqueue_kick(dev, vq, free_head);
+
+        qvirtio_wait_used_elem(dev, vq, free_head, NULL,
+                               QVIRTIO_BLK_TIMEOUT_US);
+        status = readb(req_addr + 528);
+        g_assert_cmpint(status, ==, 0);
+
+        data = g_malloc(512);
+        expected = g_malloc0(512);
+        memread(req_addr + 16, data, 512);
+        g_assert_cmpmem(data, 512, expected, 512);
+        g_free(expected);
+        g_free(data);
+
+        guest_free(alloc, req_addr);
+    }
+
     if (features & (1u << VIRTIO_F_ANY_LAYOUT)) {
         /* Write and read with 2 descriptor layout */
         /* Write request */
Signature · 1 line
2.20.1
#8 lore raw

[Qemu-devel] [PULL 8/9] tests/virtio-blk: change assert on data_size in virtio_blk_request()

In reply to Stefan Hajnoczi

From: Stefano Garzarella <[email protected]>

The size of data in the virtio_blk_request must be a multiple of 512 bytes for IN and OUT requests, or a multiple of the size of struct virtio_blk_discard_write_zeroes for DISCARD and WRITE_ZEROES requests.

Message-id: [email protected]

---
 tests/virtio-blk-test.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
tests/virtio-blk-test.c +14 -1
index 04c608764b..0739498da7 100644
@@ -144,7 +144,20 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioDevice *d,
     uint64_t addr;
     uint8_t status = 0xFF;
 
-    g_assert_cmpuint(data_size % 512, ==, 0);
+    switch (req->type) {
+    case VIRTIO_BLK_T_IN:
+    case VIRTIO_BLK_T_OUT:
+        g_assert_cmpuint(data_size % 512, ==, 0);
+        break;
+    case VIRTIO_BLK_T_DISCARD:
+    case VIRTIO_BLK_T_WRITE_ZEROES:
+        g_assert_cmpuint(data_size %
+                         sizeof(struct virtio_blk_discard_write_zeroes), ==, 0);
+        break;
+    default:
+        g_assert_cmpuint(data_size, ==, 0);
+    }
+
     addr = guest_alloc(alloc, sizeof(*req) + data_size);
 
     virtio_blk_fix_request(d, req);
Signature · 1 line
2.20.1
#0 lore raw

The following changes since commit e47f81b617684c4546af286d307b69014a83538a:

Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging (2019-02-07 18:53:25 +0000)

are available in the Git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 55140166667bb555c5d05165b93b25557d2e6397:

tests/virtio-blk: add test for WRITE_ZEROES command (2019-02-11 11:58:17 +0800)

----------------------------------------------------------------
Pull request

User-visible changes:

* virtio-blk: DISCARD and WRITE_ZEROES support

----------------------------------------------------------------

Peter Xu (1):
iothread: fix iothread hang when stop too soon

Stefano Garzarella (7):
virtio-blk: cleanup using VirtIOBlock *s and VirtIODevice *vdev
virtio-blk: add acct_failed param to virtio_blk_handle_rw_error()
virtio-blk: add host_features field in VirtIOBlock
virtio-blk: add "discard" and "write-zeroes" properties
virtio-blk: add DISCARD and WRITE_ZEROES features tests/virtio-blk: change assert on data_size in virtio_blk_request() tests/virtio-blk: add test for WRITE_ZEROES command

Vladimir Sementsov-Ogievskiy (1):
qemugdb/coroutine: fix arch_prctl has unknown return type

 include/hw/virtio/virtio-blk.h |   5 +-
 hw/block/virtio-blk.c          | 236 +++++++++++++++++++++++++++++----
 hw/core/machine.c              |   2 +
 iothread.c                     |   6 +-
 tests/virtio-blk-test.c        |  75 ++++++++++-
 scripts/qemugdb/coroutine.py   |   2 +-
 6 files changed, 297 insertions(+), 29 deletions(-)
Signature · 1 line
2.20.1
#9 lore raw

[Qemu-devel] [PULL 1/9] iothread: fix iothread hang when stop too soon

From: Peter Xu <[email protected]>

Lukas reported an hard to reproduce QMP iothread hang on s390 that QEMU might hang at pthread_join() of the QMP monitor iothread before quitting:

Thread 1
#0 0x000003ffad10932c in pthread_join
#1 0x0000000109e95750 in qemu_thread_join

      at /home/thuth/devel/qemu/util/qemu-thread-posix.c:570
  #2  0x0000000109c95a1c in iothread_stop
  #3  0x0000000109bb0874 in monitor_cleanup
  #4  0x0000000109b55042 in main

While the iothread is still in the main loop:

Thread 4

  #0  0x000003ffad0010e4 in ??
  #1  0x000003ffad553958 in g_main_context_iterate.isra.19
  #2  0x000003ffad553d90 in g_main_loop_run
  #3  0x0000000109c9585a in iothread_run
      at /home/thuth/devel/qemu/iothread.c:74
  #4  0x0000000109e94752 in qemu_thread_start
      at /home/thuth/devel/qemu/util/qemu-thread-posix.c:502
  #5  0x000003ffad10825a in start_thread
  #6  0x000003ffad00dcf2 in thread_start

IMHO it's because there's a race between the main thread and iothread when stopping the thread in following sequence:

    main thread                       iothread
    ===========                       ==============
                                      aio_poll()
    iothread_get_g_main_context
      set iothread->worker_context
    iothread_stop
      schedule iothread_stop_bh
                                        execute iothread_stop_bh [1]
                                          set iothread->running=false
                                          (since main_loop==NULL so
                                           skip to quit main loop.
                                           Note: although main_loop is
                                           NULL but worker_context is
                                           not!)
                                      atomic_read(&iothread->worker_context) [2]
                                        create main_loop object
                                        g_main_loop_run() [3]
    pthread_join() [4]

We can see that when execute iothread_stop_bh() at [1] it's possible that main_loop is still NULL because it's only created until the first check of the worker_context later at [2]. Then the iothread will hang in the main loop [3] and it'll starve the main thread too [4].

Here the simple solution should be that we check again the "running" variable before check against worker_context.

CC Thomas Huth <[email protected]>
CC Dr. David Alan Gilbert <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Lukáš Doktor <[email protected]>
CC Markus Armbruster <[email protected]>
CC Eric Blake <[email protected]>
CC Paolo Bonzini <[email protected]>

Message-id: [email protected]

---
 iothread.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
iothread.c +5 -1
index 2fb1cdf55d..e615b7ae52 100644
@@ -63,7 +63,11 @@ static void *iothread_run(void *opaque)
     while (iothread->running) {
         aio_poll(iothread->ctx, true);
 
-        if (atomic_read(&iothread->worker_context)) {
+        /*
+         * We must check the running state again in case it was
+         * changed in previous aio_poll()
+         */
+        if (iothread->running && atomic_read(&iothread->worker_context)) {
             GMainLoop *loop;
 
             g_main_context_push_thread_default(iothread->worker_context);
Signature · 1 line
2.20.1
#10 lore raw
In reply to Stefan Hajnoczi
Quoted 11 lines · Stefan Hajnoczi

The following changes since commit e47f81b617684c4546af286d307b69014a83538a:

Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging (2019-02-07 18:53:25 +0000)

are available in the Git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 55140166667bb555c5d05165b93b25557d2e6397:

Quoted 8 lines

tests/virtio-blk: add test for WRITE_ZEROES command (2019-02-11 11:58:17 +0800)

----------------------------------------------------------------
Pull request

User-visible changes:

* virtio-blk: DISCARD and WRITE_ZEROES support

Hi; this fails to pass "make check" (all platforms):

MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))} QTEST_QEMU_BINARY=arm-softmmu/qemu-system-arm QTEST_QEMU_IMG=qemu-img tests/virtio-blk-test -m
=quick -k --tap < /dev/null | ./scripts/tap-driver.pl --test-name="virtio-blk-test"
** ERROR:/home/pm215/qemu/tests/virtio-blk-test.c:272:test_basic:
assertion failed (status == 0): (1 == 0)
ERROR - too few tests run (expected 1, got 0)

thanks
-- PMM

#11 lore raw
Quoted 23 lines · Peter Maydell
Quoted 11 lines · Stefan Hajnoczi

The following changes since commit e47f81b617684c4546af286d307b69014a83538a:

Merge remote-tracking branch 'remotes/thibault/tags/samuel-thibault' into staging (2019-02-07 18:53:25 +0000)

are available in the Git repository at:

git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 55140166667bb555c5d05165b93b25557d2e6397:

Quoted 8 lines

tests/virtio-blk: add test for WRITE_ZEROES command (2019-02-11 11:58:17 +0800)

----------------------------------------------------------------
Pull request

User-visible changes:

* virtio-blk: DISCARD and WRITE_ZEROES support

Hi; this fails to pass "make check" (all platforms):

Quoted 9 lines

MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))} QTEST_QEMU_BINARY=arm-softmmu/qemu-system-arm QTEST_QEMU_IMG=qemu-img tests/virtio-blk-test -m
=quick -k --tap < /dev/null | ./scripts/tap-driver.pl --test-name="virtio-blk-test"
** ERROR:/home/pm215/qemu/tests/virtio-blk-test.c:272:test_basic:
assertion failed (status == 0): (1 == 0)
ERROR - too few tests run (expected 1, got 0)

Stefano, I'm dropping the virtio-blk DISCARD/WRITE_ZEROES series. Please debug this failure.

I cannot reproduce it on a Linux host so maybe it's related to macOS. First I thought it's because write zeroes is not supported on macOS, but QEMU should fall back to writing a bounce buffer of zeroes.

Stefan

#12 lore raw
Quoted 14 lines · Stefan Hajnoczi
Quoted 12 lines · Peter Maydell

Hi; this fails to pass "make check" (all platforms):

MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))} QTEST_QEMU_BINARY=arm-softmmu/qemu-system-arm QTEST_QEMU_IMG=qemu-img tests/virtio-blk-test -m
=quick -k --tap < /dev/null | ./scripts/tap-driver.pl --test-name="virtio-blk-test"
** ERROR:/home/pm215/qemu/tests/virtio-blk-test.c:272:test_basic:
assertion failed (status == 0): (1 == 0)
ERROR - too few tests run (expected 1, got 0)

Quoted 7 lines

Stefano, I'm dropping the virtio-blk DISCARD/WRITE_ZEROES series. Please debug this failure.

I cannot reproduce it on a Linux host so maybe it's related to macOS. First I thought it's because write zeroes is not supported on macOS, but QEMU should fall back to writing a bounce buffer of zeroes.

Hi Stefan,
I'll debug it! I also have a macOS here, so I'll try on it.

Thanks,
Stefano

#13 lore raw
In reply to Stefan Hajnoczi
Quoted 14 lines · Stefan Hajnoczi
Quoted 11 lines · Peter Maydell

Hi; this fails to pass "make check" (all platforms):

MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))} QTEST_QEMU_BINARY=arm-softmmu/qemu-system-arm QTEST_QEMU_IMG=qemu-img tests/virtio-blk-test -m
=quick -k --tap < /dev/null | ./scripts/tap-driver.pl --test-name="virtio-blk-test"
** ERROR:/home/pm215/qemu/tests/virtio-blk-test.c:272:test_basic:
assertion failed (status == 0): (1 == 0)
ERROR - too few tests run (expected 1, got 0)

Quoted 6 lines

Stefano, I'm dropping the virtio-blk DISCARD/WRITE_ZEROES series. Please debug this failure.

I cannot reproduce it on a Linux host so maybe it's related to macOS. First I thought it's because write zeroes is not supported on macOS, but QEMU should fall back to writing a bounce buffer of zeroes.

The test failed everywhere, including the Linux platforms, not just OSX.

thanks
-- PMM