Skip to contentSkip to conversation

block: reject persistent bitmaps a node can never store

PATCH In review Denis V. Lunev 3 participants 12 messages Jul 16 – Aug 17 Block layer

lore
Share & tools
lore
#0 lore raw

v2 cover block: reject persistent bitmaps a node can never store

qmp_block_dirty_bitmap_add() and the incoming-migration bitmap loader both create a persistent bitmap with bdrv_create_dirty_bitmap(), which always creates it writable, without checking whether the node can actually be written to. A persistent bitmap added to an already read-only or inactive node stays writable in memory on a node that can never store it, and the next global inactivation (migration completion, save, or any other bdrv_inactivate_all() caller) fails trying to flush it back:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Patch 1 rejects this at block-dirty-bitmap-add (and, wrapped in a transaction, denies the whole transaction). Patch 2 closes the same hole on the incoming-migration path. Patch 3 fixes a knock-on regression from patch 1's approach: a bitmap that was rejected from ever being written can still exist in memory read-only and must remain removable without requiring write access.

v1 -> v2
* approach changed to deny rather than adopt (Vladimir)
* added patch to add permission check on migration path
* added patch to change permissions check on bitmap drop to more natural

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>

Denis V. Lunev (3):
block/monitor: reject persistent bitmap add on a read-only node migration/block-dirty-bitmap: reject bitmap load onto ro node block/monitor: allow dropping a bitmap never stored on disk

 block/monitor/bitmap-qmp-cmds.c               | 19 +++++++----
 block/qcow2-bitmap.c                          |  9 +++++
 migration/block-dirty-bitmap.c                | 22 +++++++++----
 qapi/block-core.json                          |  4 ++-
 tests/qemu-iotests/tests/migrate-bitmaps-test | 33 +++++++++++++++++++
 .../tests/migrate-bitmaps-test.out            |  4 +--
 .../tests/remove-bitmap-from-backing          | 29 +++++++++++++++-
 .../tests/remove-bitmap-from-backing.out      | 22 ++++++++++++-
 8 files changed, 124 insertions(+), 18 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/3 block/monitor: reject persistent bitmap add on a read-only node

qmp_block_dirty_bitmap_add() marks a new bitmap persistent without checking write access to its node. bdrv_create_dirty_bitmap() always creates bitmaps writable, so a persistent bitmap added to an already read-only node stays writable in memory on a node that can never store it, and the next global inactivation fails:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Forcing it read-only instead does not help: it was never stored, so it stays unpromotable on the next reopen to read-write and can trip bdrv_set_dirty()'s readonly assert on the first write. Reject the add instead, for both read-only and inactive nodes -- an already-inactive node skips qcow2_inactivate() on close, so a bitmap added during that window would never get stored either. Wrapped in a transaction, this denies the whole transaction, since qmp_transaction() is already all-or-none.

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>
---
 block/monitor/bitmap-qmp-cmds.c               | 15 +++++++---
 qapi/block-core.json                          |  4 ++-
 .../tests/remove-bitmap-from-backing          | 29 ++++++++++++++++++-
 .../tests/remove-bitmap-from-backing.out      | 20 +++++++++++++
 4 files changed, 62 insertions(+), 6 deletions(-)
block/monitor/bitmap-qmp-cmds.c +11 -4
index a738e7bbf7..d87ca982aa 100644
@@ -125,10 +125,17 @@ void qmp_block_dirty_bitmap_add(const char *node, const char *name,
         disabled = false;
     }
 
-    if (persistent &&
-        !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp))
-    {
-        return;
+    if (persistent) {
+        if (!bdrv_is_writable(bs)) {
+            error_setg(errp, "Cannot add a persistent bitmap to "
+                       "read-only or inactive node '%s'",
+                       bdrv_get_node_name(bs));
+            return;
+        }
+
+        if (!bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp)) {
+            return;
+        }
     }
 
     bitmap = bdrv_create_dirty_bitmap(bs, granularity, name, errp);
qapi/block-core.json +3 -1
index 1f87b07850..199efc1e00 100644
@@ -2353,7 +2353,9 @@
 # @persistent: the bitmap is persistent, i.e. it will be saved to the
 #     corresponding block device image file on its close.  For now
 #     only Qcow2 disks support persistent bitmaps.  Default is false
-#     for `block-dirty-bitmap-add`.  (Since: 2.10)
+#     for `block-dirty-bitmap-add`.  This fails if the node is
+#     read-only or inactive, since such a bitmap could never be
+#     stored.  (Since: 2.10)
 #
 # @disabled: the bitmap is created in the disabled state, which means
 #     that it will not track drive changes.  The bitmap may be enabled
tests/qemu-iotests/tests/remove-bitmap-from-backing +28 -1
index 15be32dcb9..a54984fa58 100755
@@ -35,7 +35,7 @@ qemu_img('bitmap', '--add', base, 'bitmap0')
 # Just assert that our method of checking bitmaps in the image works.
 assert 'bitmaps' in qemu_img_info(base)['format-specific']['data']
 
-vm = iotests.VM().add_drive(top, 'backing.node-name=base')
+vm = iotests.VM().add_drive(top, 'node-name=top,backing.node-name=base')
 vm.launch()
 
 log('Trying to remove persistent bitmap from r-o base node, should fail:')
@@ -66,6 +66,33 @@ result = vm.qmp('blockdev-reopen', **new_base_opts)
 if result != {'return': {}}:
     log('Failed to reopen: ' + str(result))
 
+log('Adding a persistent bitmap to the r-o base node, should fail:')
+vm.qmp_log('block-dirty-bitmap-add', node='base', name='bitmap1',
+          persistent=True)
+
+log('Same add inside a transaction, preceded by an otherwise valid')
+log('action: the whole transaction must fail and roll back the')
+log('already-succeeded first action too:')
+vm.qmp_log('transaction', actions=[
+    {'type': 'block-dirty-bitmap-add',
+     'data': {'node': 'top', 'name': 'bitmap2', 'persistent': True}},
+    {'type': 'block-dirty-bitmap-add',
+     'data': {'node': 'base', 'name': 'bitmap1', 'persistent': True}},
+])
+
+log('bitmap2 on the rw top node must not have survived the rollback:')
+vm.qmp_log('block-dirty-bitmap-remove', node='top', name='bitmap2')
+
+log('Marking the rw top node inactive:')
+vm.qmp_log('blockdev-set-active', **{'node-name': 'top', 'active': False})
+
+log('Adding a persistent bitmap to a rw but inactive node, should fail:')
+vm.qmp_log('block-dirty-bitmap-add', node='top', name='bitmap3',
+          persistent=True)
+
+log('Reactivating the top node:')
+vm.qmp_log('blockdev-set-active', **{'node-name': 'top', 'active': True})
+
 vm.shutdown()
 
 if 'bitmaps' in qemu_img_info(base)['format-specific']['data']:
tests/qemu-iotests/tests/remove-bitmap-from-backing.out +20 -0
index c28af82c75..fe105fe0a3 100644
@@ -4,3 +4,23 @@ Trying to remove persistent bitmap from r-o base node, should fail:
 Remove persistent bitmap from base node reopened to RW:
 {"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "base"}}
 {"return": {}}
+Adding a persistent bitmap to the r-o base node, should fail:
+{"execute": "block-dirty-bitmap-add", "arguments": {"name": "bitmap1", "node": "base", "persistent": true}}
+{"error": {"class": "GenericError", "desc": "Cannot add a persistent bitmap to read-only or inactive node 'base'"}}
+Same add inside a transaction, preceded by an otherwise valid
+action: the whole transaction must fail and roll back the
+already-succeeded first action too:
+{"execute": "transaction", "arguments": {"actions": [{"data": {"name": "bitmap2", "node": "top", "persistent": true}, "type": "block-dirty-bitmap-add"}, {"data": {"name": "bitmap1", "node": "base", "persistent": true}, "type": "block-dirty-bitmap-add"}]}}
+{"error": {"class": "GenericError", "desc": "Cannot add a persistent bitmap to read-only or inactive node 'base'"}}
+bitmap2 on the rw top node must not have survived the rollback:
+{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap2", "node": "top"}}
+{"error": {"class": "GenericError", "desc": "Dirty bitmap 'bitmap2' not found"}}
+Marking the rw top node inactive:
+{"execute": "blockdev-set-active", "arguments": {"active": false, "node-name": "top"}}
+{"return": {}}
+Adding a persistent bitmap to a rw but inactive node, should fail:
+{"execute": "block-dirty-bitmap-add", "arguments": {"name": "bitmap3", "node": "top", "persistent": true}}
+{"error": {"class": "GenericError", "desc": "Cannot add a persistent bitmap to read-only or inactive node 'top'"}}
+Reactivating the top node:
+{"execute": "blockdev-set-active", "arguments": {"active": true, "node-name": "top"}}
+{"return": {}}
Signature · 1 line
2.53.0
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] block/monitor: reject persistent bitmap add on a read-only node

Quoted 18 lines · Denis V. Lunev

qmp_block_dirty_bitmap_add() marks a new bitmap persistent without checking write access to its node. bdrv_create_dirty_bitmap() always creates bitmaps writable, so a persistent bitmap added to an already read-only node stays writable in memory on a node that can never store it, and the next global inactivation fails:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Forcing it read-only instead does not help: it was never stored, so it stays unpromotable on the next reopen to read-write and can trip bdrv_set_dirty()'s readonly assert on the first write. Reject the add instead, for both read-only and inactive nodes -- an already-inactive node skips qcow2_inactivate() on close, so a bitmap added during that window would never get stored either. Wrapped in a transaction, this denies the whole transaction, since qmp_transaction() is already all-or-none.

Quoted 5 lines
CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>

Could it be a scenario, when user intentionally create bitmap in read-only image, and expect, that it would become writeable soon? For example before block-commit.

I don't think that useful.

For usual backup scenario, user will just move bitmaps from top to base, no need to make a bitmap, dirtied by the block-commit operation itself.

If, for some reason we don't have bitmap in top image, but have in base (top is a kind of temporary snapshot), bitmaps in base would become writeable and accept new dirty bits as expected.

Creating a new bitmap, to become actually a block-status bitmap of merged top base seems a strange case.. A kind of combination of snapshot-based and backup-based backup processes?

Anyway, I think, it's quite correct immediately store an empty bitmap to the qcow2 image when creating it with persistent=true, which of course fails if image is read-only. So, I think the change is correct:

Signature · 2 lines
Best regards,
Vladimir
#3 lore raw

Re: [PATCH v2 1/3] block/monitor: reject persistent bitmap add on a read-only node

Quoted 43 lines · Vladimir Sementsov-Ogievskiy
Quoted 18 lines · Denis V. Lunev

qmp_block_dirty_bitmap_add() marks a new bitmap persistent without checking write access to its node. bdrv_create_dirty_bitmap() always creates bitmaps writable, so a persistent bitmap added to an already read-only node stays writable in memory on a node that can never store it, and the next global inactivation fails:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Forcing it read-only instead does not help: it was never stored, so it stays unpromotable on the next reopen to read-write and can trip bdrv_set_dirty()'s readonly assert on the first write. Reject the add instead, for both read-only and inactive nodes -- an already-inactive node skips qcow2_inactivate() on close, so a bitmap added during that window would never get stored either. Wrapped in a transaction, this denies the whole transaction, since qmp_transaction() is already all-or-none.

Quoted 5 lines
CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>

Could it be a scenario, when user intentionally create bitmap in read-only image, and expect, that it would become writeable soon? For example before block-commit.

I don't think that useful.

For usual backup scenario, user will just move bitmaps from top to base, no need to make a bitmap, dirtied by the block-commit operation itself.

If, for some reason we don't have bitmap in top image, but have in base (top is a kind of temporary snapshot), bitmaps in base would become writeable and accept new dirty bits as expected.

Creating a new bitmap, to become actually a block-status bitmap of merged top base seems a strange case.. A kind of combination of snapshot-based and backup-based backup processes?

Quoted 8 lines

Anyway, I think, it's quite correct immediately store an empty bitmap to the qcow2 image when creating it with persistent=true, which of course fails if image is read-only. So, I think the change is correct:

FYI: in reality this was faced by once once VMs are started to be migrated and are unable to due to CBT over CDROM. Strangely enough from time to time we do have CDROMs over qcow2 images which leads us to this.

Den

#4 lore raw

PATCH v2 2/3 migration/block-dirty-bitmap: reject bitmap load onto ro node

In reply to Denis V. Lunev

dirty_bitmap_load_start() creates an incoming migrated bitmap with bdrv_create_dirty_bitmap() and, if the source marked it persistent, calls bdrv_dirty_bitmap_set_persistence() without checking whether the destination node can be written to. Same gap as qmp_block_dirty_bitmap_add(), reached via incoming migration: a persistent bitmap for a read-only destination (e.g. a migrated CD-ROM-class attachment with dirty-bitmaps migration enabled) ends up writable in memory on a node that can never store it.

Reject it the same way, with one difference from the QMP path:
every destination node is BDRV_O_INACTIVE until migration completes, so bdrv_is_writable() would reject every incoming persistent bitmap, not just read-only ones. Check bdrv_is_read_only() alone.

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>
---
 migration/block-dirty-bitmap.c                | 22 +++++++++----
 tests/qemu-iotests/tests/migrate-bitmaps-test | 33 +++++++++++++++++++
 .../tests/migrate-bitmaps-test.out            |  4 +--
 3 files changed, 50 insertions(+), 9 deletions(-)
migration/block-dirty-bitmap.c +15 -7
index cba54e25cd..1b8f39c12b 100644
@@ -812,13 +812,6 @@ static int dirty_bitmap_load_start(QEMUFile *f, DBMLoadState *s)
         error_report("Bitmap with the same name ('%s') already exists on "
                      "destination", bdrv_dirty_bitmap_name(s->bitmap));
         return -EINVAL;
-    } else {
-        s->bitmap = bdrv_create_dirty_bitmap(s->bs, granularity,
-                                             s->bitmap_name, &local_err);
-        if (!s->bitmap) {
-            error_report_err(local_err);
-            return -EINVAL;
-        }
     }
 
     if (flags & DIRTY_BITMAP_MIG_START_FLAG_RESERVED_MASK) {
@@ -835,6 +828,21 @@ static int dirty_bitmap_load_start(QEMUFile *f, DBMLoadState *s)
         persistent = flags & DIRTY_BITMAP_MIG_START_FLAG_PERSISTENT;
     }
 
+    /* Not bdrv_is_writable(): nodes stay inactive until migration ends. */
+    if (persistent && bdrv_is_read_only(s->bs)) {
+        error_report("Cannot make migrated bitmap '%s' persistent "
+                     "on read-only node '%s'", s->bitmap_name,
+                     bdrv_get_node_name(s->bs));
+        return -EINVAL;
+    }
+
+    s->bitmap = bdrv_create_dirty_bitmap(s->bs, granularity,
+                                         s->bitmap_name, &local_err);
+    if (!s->bitmap) {
+        error_report_err(local_err);
+        return -EINVAL;
+    }
+
     if (persistent) {
         bdrv_dirty_bitmap_set_persistence(s->bitmap, true);
     }
tests/qemu-iotests/tests/migrate-bitmaps-test +33 -0
index 8fb4099201..cb9154ca8d 100755
@@ -206,6 +206,39 @@ class TestDirtyBitmapMigration(iotests.QMPTestCase):
             self.vm_b.launch()
             self.check_bitmap(self.vm_b, sha256 if persistent else False)
 
+    def test_migration_to_readonly_destination(self):
+        granularity = 512
+        mig_caps = [{'capability': 'events', 'state': True},
+                   {'capability': 'dirty-bitmaps', 'state': True}]
+
+        self.vm_b.add_incoming("defer")
+        self.vm_b.add_drive(disk_b, 'read-only=on')
+
+        self.add_bitmap(self.vm_a, granularity, True)
+        self.vm_a.hmp_qemu_io('drive0', 'write 0 4096')
+
+        self.vm_a.cmd('migrate-set-capabilities', capabilities=mig_caps)
+        self.vm_a.cmd('migrate', uri=mig_cmd)
+        while True:
+            event = self.vm_a.event_wait('MIGRATION')
+            if event['data']['status'] == 'completed':
+                break
+        self.vm_a.shutdown()
+
+        self.vm_b.launch()
+        self.vm_b.cmd('migrate-set-capabilities', capabilities=mig_caps)
+        self.vm_b.cmd('migrate-incoming', uri=incoming_cmd)
+        while True:
+            event = self.vm_b.event_wait('MIGRATION')
+            if event['data']['status'] in ('completed', 'failed'):
+                break
+
+        self.assert_qmp(event, 'data/status', 'failed')
+
+        # A failed incoming load makes the destination process exit on
+        # its own; reap it so tearDown()'s shutdown() is a clean no-op.
+        self.vm_b.wait()
+
 
 def inject_test_case(klass, suffix, method, *args, **kwargs):
     mc = operator.methodcaller(method, *args, **kwargs)
tests/qemu-iotests/tests/migrate-bitmaps-test.out +2 -2
index cafb8161f7..73e375a9d7 100644
@@ -1,5 +1,5 @@
-.....................................
+......................................
 ----------------------------------------------------------------------
-Ran 37 tests
+Ran 38 tests
 
 OK
Signature · 1 line
2.53.0
Reviewed-by on v2 2/3
#5 lore raw

Re: [PATCH v2 2/3] migration/block-dirty-bitmap: reject bitmap load onto ro node

Quoted 14 lines · Denis V. Lunev

dirty_bitmap_load_start() creates an incoming migrated bitmap with bdrv_create_dirty_bitmap() and, if the source marked it persistent, calls bdrv_dirty_bitmap_set_persistence() without checking whether the destination node can be written to. Same gap as qmp_block_dirty_bitmap_add(), reached via incoming migration: a persistent bitmap for a read-only destination (e.g. a migrated CD-ROM-class attachment with dirty-bitmaps migration enabled) ends up writable in memory on a node that can never store it.

Reject it the same way, with one difference from the QMP path:
every destination node is BDRV_O_INACTIVE until migration completes, so bdrv_is_writable() would reject every incoming persistent bitmap, not just read-only ones. Check bdrv_is_read_only() alone.

Quoted 5 lines
CC Eric Blake<[email protected]>
CC Vladimir Sementsov-Ogievskiy<[email protected]>
CC John Snow<[email protected]>
CC Andrey Drobyshev<[email protected]>
Signature · 2 lines
Best regards,
Vladimir
#6 lore raw

PATCH v2 3/3 block/monitor: allow dropping a bitmap never stored on disk

In reply to Denis V. Lunev

block-dirty-bitmap-remove refuses any readonly bitmap outright, via the generic BDRV_BITMAP_RO check in bdrv_dirty_bitmap_check(). That check cannot tell whether the bitmap is actually on disk, so it also blocks dropping one that only ever existed in memory, which needs no write at all.

Drop the blanket check and let qcow2 decide: bdrv_remove_persistent_ dirty_bitmap() already treats an absent on-disk entry as a no-op, so such a bitmap is now released with no write attempted. For one that is genuinely stored, qcow2_co_remove_persistent_dirty_bitmap_locked() now checks can_write() before it would update the on-disk directory, so removal still fails there, with a message naming the actual reason instead of just the bitmap's readonly flag.

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>
---
 block/monitor/bitmap-qmp-cmds.c                         | 4 ++--
 block/qcow2-bitmap.c                                    | 9 +++++++++
 tests/qemu-iotests/tests/remove-bitmap-from-backing.out | 2 +-
 3 files changed, 12 insertions(+), 3 deletions(-)
block/monitor/bitmap-qmp-cmds.c +2 -2
index d87ca982aa..aabf2790b6 100644
@@ -165,11 +165,11 @@ BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,
         return NULL;
     }
 
-    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY | BDRV_BITMAP_RO,
-                                errp)) {
+    if (bdrv_dirty_bitmap_check(bitmap, BDRV_BITMAP_BUSY, errp)) {
         return NULL;
     }
 
+    /* Dropping a bitmap needs no write access unless it is actually stored. */
     if (bdrv_dirty_bitmap_get_persistence(bitmap) &&
         bdrv_remove_persistent_dirty_bitmap(bs, name, errp) < 0)
     {
block/qcow2-bitmap.c +9 -0
index 256ec99878..ac5a724588 100644
@@ -1487,6 +1487,15 @@ int coroutine_fn qcow2_co_remove_persistent_dirty_bitmap(BlockDriverState *bs,
         goto out;
     }
 
+    if (!can_write(bs)) {
+        error_setg(errp, "Cannot remove persistent bitmap '%s': "
+                   "no write access to node '%s'", name,
+                   bdrv_get_node_name(bs));
+        ret = -EACCES;
+        bm = NULL;
+        goto out;
+    }
+
     QSIMPLEQ_REMOVE(bm_list, bm, Qcow2Bitmap, entry);
 
     ret = update_ext_header_and_dir(bs, bm_list);
tests/qemu-iotests/tests/remove-bitmap-from-backing.out +1 -1
index fe105fe0a3..628fa737d9 100644
@@ -1,6 +1,6 @@
 Trying to remove persistent bitmap from r-o base node, should fail:
 {"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "base"}}
-{"error": {"class": "GenericError", "desc": "Bitmap 'bitmap0' is readonly and cannot be modified"}}
+{"error": {"class": "GenericError", "desc": "Cannot remove persistent bitmap 'bitmap0': no write access to node 'base'"}}
 Remove persistent bitmap from base node reopened to RW:
 {"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", "node": "base"}}
 {"return": {}}
Signature · 1 line
2.53.0
Reviewed-by on v2 3/3
#7 lore raw

Re: [PATCH v2 3/3] block/monitor: allow dropping a bitmap never stored on disk

Quoted 14 lines · Denis V. Lunev

block-dirty-bitmap-remove refuses any readonly bitmap outright, via the generic BDRV_BITMAP_RO check in bdrv_dirty_bitmap_check(). That check cannot tell whether the bitmap is actually on disk, so it also blocks dropping one that only ever existed in memory, which needs no write at all.

Drop the blanket check and let qcow2 decide: bdrv_remove_persistent_ dirty_bitmap() already treats an absent on-disk entry as a no-op, so such a bitmap is now released with no write attempted. For one that is genuinely stored, qcow2_co_remove_persistent_dirty_bitmap_locked() now checks can_write() before it would update the on-disk directory, so removal still fails there, with a message naming the actual reason instead of just the bitmap's readonly flag.

Quoted 5 lines
CC Eric Blake<[email protected]>
CC Vladimir Sementsov-Ogievskiy<[email protected]>
CC John Snow<[email protected]>
CC Andrey Drobyshev<[email protected]>
Signature · 2 lines
Best regards,
Vladimir
#8 lore raw
In reply to Denis V. Lunev
Quoted 37 lines · Denis V. Lunev

This email originated from an IP that might not be authorized by the domain it was sent from. Do not click links or open attachments unless it is an email you expected to receive. qmp_block_dirty_bitmap_add() and the incoming-migration bitmap loader
both create a persistent bitmap with bdrv_create_dirty_bitmap(), which
always creates it writable, without checking whether the node can
actually be written to. A persistent bitmap added to an already
read-only or inactive node stays writable in memory on a node that
can never store it, and the next global inactivation (migration
completion, save, or any other bdrv_inactivate_all() caller) fails
trying to flush it back:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Patch 1 rejects this at block-dirty-bitmap-add (and, wrapped in a transaction, denies the whole transaction). Patch 2 closes the same hole on the incoming-migration path. Patch 3 fixes a knock-on regression from patch 1's approach: a bitmap that was rejected from ever being written can still exist in memory read-only and must remain removable without requiring write access.

v1 -> v2
* approach changed to deny rather than adopt (Vladimir)
* added patch to add permission check on migration path
* added patch to change permissions check on bitmap drop to more natural

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>

Denis V. Lunev (3):
block/monitor: reject persistent bitmap add on a read-only node migration/block-dirty-bitmap: reject bitmap load onto ro node block/monitor: allow dropping a bitmap never stored on disk

Quoted 10 lines
 block/monitor/bitmap-qmp-cmds.c               | 19 +++++++----
 block/qcow2-bitmap.c                          |  9 +++++
 migration/block-dirty-bitmap.c                | 22 +++++++++----
 qapi/block-core.json                          |  4 ++-
 tests/qemu-iotests/tests/migrate-bitmaps-test | 33 +++++++++++++++++++
 .../tests/migrate-bitmaps-test.out            |  4 +--
 .../tests/remove-bitmap-from-backing          | 29 +++++++++++++++-
 .../tests/remove-bitmap-from-backing.out      | 22 ++++++++++++-
 8 files changed, 124 insertions(+), 18 deletions(-)

Hi, Vladimir!

Will this go through your tree? It is looking like nobody else cares.

Den

#9 lore raw
Quoted 48 lines · Denis V. Lunev
Quoted 37 lines · Denis V. Lunev

This email originated from an IP that might not be authorized by the domain it was sent from. Do not click links or open attachments unless it is an email you expected to receive. qmp_block_dirty_bitmap_add() and the incoming-migration bitmap loader
both create a persistent bitmap with bdrv_create_dirty_bitmap(), which
always creates it writable, without checking whether the node can
actually be written to. A persistent bitmap added to an already
read-only or inactive node stays writable in memory on a node that
can never store it, and the next global inactivation (migration
completion, save, or any other bdrv_inactivate_all() caller) fails
trying to flush it back:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Patch 1 rejects this at block-dirty-bitmap-add (and, wrapped in a transaction, denies the whole transaction). Patch 2 closes the same hole on the incoming-migration path. Patch 3 fixes a knock-on regression from patch 1's approach: a bitmap that was rejected from ever being written can still exist in memory read-only and must remain removable without requiring write access.

v1 -> v2
* approach changed to deny rather than adopt (Vladimir)
* added patch to add permission check on migration path
* added patch to change permissions check on bitmap drop to more natural

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>

Denis V. Lunev (3):
block/monitor: reject persistent bitmap add on a read-only node migration/block-dirty-bitmap: reject bitmap load onto ro node block/monitor: allow dropping a bitmap never stored on disk

Quoted 10 lines
  block/monitor/bitmap-qmp-cmds.c               | 19 +++++++----
  block/qcow2-bitmap.c                          |  9 +++++
  migration/block-dirty-bitmap.c                | 22 +++++++++----
  qapi/block-core.json                          |  4 ++-
  tests/qemu-iotests/tests/migrate-bitmaps-test | 33 +++++++++++++++++++
  .../tests/migrate-bitmaps-test.out            |  4 +--
  .../tests/remove-bitmap-from-backing          | 29 +++++++++++++++-
  .../tests/remove-bitmap-from-backing.out      | 22 ++++++++++++-
  8 files changed, 124 insertions(+), 18 deletions(-)
Quoted 4 lines

Hi, Vladimir!

Will this go through your tree? It is looking like nobody else cares.

Yes, seems so. Thanks, applied to my block branch.

There's still a chance to stop me within 2-3 weeks before 11.2 cycle opens.

Signature · 2 lines
Best regards,
Vladimir
#10 lore raw
Quoted 49 lines · Vladimir Sementsov-Ogievskiy
Quoted 48 lines · Denis V. Lunev
Quoted 47 lines · Denis V. Lunev

This email originated from an IP that might not be authorized by the domain it was sent from. Do not click links or open attachments unless it is an email you expected to receive. qmp_block_dirty_bitmap_add() and the incoming-migration bitmap loader
both create a persistent bitmap with bdrv_create_dirty_bitmap(), which
always creates it writable, without checking whether the node can
actually be written to. A persistent bitmap added to an already
read-only or inactive node stays writable in memory on a node that
can never store it, and the next global inactivation (migration
completion, save, or any other bdrv_inactivate_all() caller) fails
trying to flush it back:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Patch 1 rejects this at block-dirty-bitmap-add (and, wrapped in a transaction, denies the whole transaction). Patch 2 closes the same hole on the incoming-migration path. Patch 3 fixes a knock-on regression from patch 1's approach: a bitmap that was rejected from ever being written can still exist in memory read-only and must remain removable without requiring write access.

v1 -> v2
* approach changed to deny rather than adopt (Vladimir)
* added patch to add permission check on migration path
* added patch to change permissions check on bitmap drop to more natural

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>

Denis V. Lunev (3):
block/monitor: reject persistent bitmap add on a read-only node migration/block-dirty-bitmap: reject bitmap load onto ro node block/monitor: allow dropping a bitmap never stored on disk

  block/monitor/bitmap-qmp-cmds.c               | 19 +++++++----
  block/qcow2-bitmap.c                          |  9 +++++
  migration/block-dirty-bitmap.c                | 22 +++++++++----
  qapi/block-core.json                          |  4 ++-
  tests/qemu-iotests/tests/migrate-bitmaps-test | 33 +++++++++++++++++++
  .../tests/migrate-bitmaps-test.out            |  4 +--
  .../tests/remove-bitmap-from-backing          | 29 +++++++++++++++-
  .../tests/remove-bitmap-from-backing.out      | 22 ++++++++++++-
  8 files changed, 124 insertions(+), 18 deletions(-)
Quoted 8 lines
Quoted 4 lines

Hi, Vladimir!

Will this go through your tree? It is looking like nobody else cares.

Yes, seems so. Thanks, applied to my block branch.

There's still a chance to stop me within 2-3 weeks before 11.2 cycle opens.

Hmmm :-)

11.2 seems opened. Is it right time to push?

Thank you in advance,
    Den

#11 lore raw
Quoted 54 lines · Denis V. Lunev
Quoted 53 lines · Vladimir Sementsov-Ogievskiy
Quoted 52 lines · Denis V. Lunev
Quoted 37 lines · Denis V. Lunev

This email originated from an IP that might not be authorized by the domain it was sent from. Do not click links or open attachments unless it is an email you expected to receive. qmp_block_dirty_bitmap_add() and the incoming-migration bitmap loader
both create a persistent bitmap with bdrv_create_dirty_bitmap(), which
always creates it writable, without checking whether the node can
actually be written to. A persistent bitmap added to an already
read-only or inactive node stays writable in memory on a node that
can never store it, and the next global inactivation (migration
completion, save, or any other bdrv_inactivate_all() caller) fails
trying to flush it back:

Lost persistent bitmaps during inactivation of node '<node>': No write access migration_block_inactivate: bdrv_inactivate_all() failed: -22

Patch 1 rejects this at block-dirty-bitmap-add (and, wrapped in a transaction, denies the whole transaction). Patch 2 closes the same hole on the incoming-migration path. Patch 3 fixes a knock-on regression from patch 1's approach: a bitmap that was rejected from ever being written can still exist in memory read-only and must remain removable without requiring write access.

v1 -> v2
* approach changed to deny rather than adopt (Vladimir)
* added patch to add permission check on migration path
* added patch to change permissions check on bitmap drop to more natural

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>
CC John Snow <[email protected]>
CC Andrey Drobyshev <[email protected]>

Denis V. Lunev (3):
block/monitor: reject persistent bitmap add on a read-only node migration/block-dirty-bitmap: reject bitmap load onto ro node block/monitor: allow dropping a bitmap never stored on disk

Quoted 10 lines
   block/monitor/bitmap-qmp-cmds.c               | 19 +++++++----
   block/qcow2-bitmap.c                          |  9 +++++
   migration/block-dirty-bitmap.c                | 22 +++++++++----
   qapi/block-core.json                          |  4 ++-
   tests/qemu-iotests/tests/migrate-bitmaps-test | 33 +++++++++++++++++++
   .../tests/migrate-bitmaps-test.out            |  4 +--
   .../tests/remove-bitmap-from-backing          | 29 +++++++++++++++-
   .../tests/remove-bitmap-from-backing.out      | 22 ++++++++++++-
   8 files changed, 124 insertions(+), 18 deletions(-)

Hi, Vladimir!

Will this go through your tree? It is looking like nobody else cares.

Quoted 8 lines
Quoted 4 lines

Yes, seems so. Thanks, applied to my block branch.

There's still a chance to stop me within 2-3 weeks before 11.2 cycle opens.

Hmmm :-)

11.2 seems opened. Is it right time to push?

Was on vacation :). Will do this week.

Signature · 2 lines
Best regards,
Vladimir