Skip to contentSkip to conversation

kvm_physical_sync_dirty_bitmap: ignore ENOENT from kvm_vm_ioctl

PATCH In review Michael Tokarev 3 participants 4 messages Apr 11, 2014 – Apr 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm_physical_sync_dirty_bitmap: ignore ENOENT from kvm_vm_ioctl

ENOENT means the kernel has an empty dirty bitmap for this slot. Don't abort in that case. This appears to solve the bug reported at

https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1303926

which first showed up with commit b533f658a98325d: fix return check for KVM_GET_DIRTY_LOG ioctl

---
 kvm-all.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
kvm-all.c +8 -2
index cd4111d..47fa948 100644
@@ -441,13 +441,19 @@ static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section)
 
         d.slot = mem->slot;
 
-        if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) < 0) {
+        ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d);
+        if (ret >= 0) {
+            /* regular case, process returned bitmap */
+            kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
+        } else if (ret == -ENOENT) {
+            /* kernel does not have dirty bitmap in this slot */
+            ret = 0;
+        } else {
             DPRINTF("ioctl failed %d\n", errno);
             ret = -1;
             break;
         }
 
-        kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
         start_addr = mem->start_addr + mem->memory_size;
     }
     g_free(d.dirty_bitmap);
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Michael Tokarev

ENOENT means the kernel has an empty dirty bitmap for this slot. Don't abort in that case. This appears to solve the bug reported at

https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1303926

which first showed up with commit b533f658a98325d: fix return check for KVM_GET_DIRTY_LOG ioctl

This does look better than my version, thanks. As you say my version was closer to the old behavior, but if the kernel has no dirty bitmap we shouldn't be acting on it, so this looks better imo.

(I've not tested yet, but it looks right and works for you :)

Quoted 33 lines
---
 kvm-all.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
kvm-all.c +8 -2
index cd4111d..47fa948 100644
@@ -441,13 +441,19 @@ static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section)
 
         d.slot = mem->slot;
 
-        if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) < 0) {
+        ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d);
+        if (ret >= 0) {
+            /* regular case, process returned bitmap */
+            kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
+        } else if (ret == -ENOENT) {
+            /* kernel does not have dirty bitmap in this slot */
+            ret = 0;
+        } else {
             DPRINTF("ioctl failed %d\n", errno);
             ret = -1;
             break;
         }
 
-        kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
         start_addr = mem->start_addr + mem->memory_size;
     }
     g_free(d.dirty_bitmap);
Signature · 1 line
1.7.10.4
#2 lore raw
In reply to Michael Tokarev

Il 11/04/2014 04:31, Michael Tokarev ha scritto:

Quoted 32 lines

ENOENT means the kernel has an empty dirty bitmap for this slot. Don't abort in that case. This appears to solve the bug reported at

https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1303926

which first showed up with commit b533f658a98325d: fix return check for KVM_GET_DIRTY_LOG ioctl

---
 kvm-all.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
kvm-all.c +7 -1
index cd4111d..47fa948 100644
@@ -441,13 +441,19 @@ static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section)
 
         d.slot = mem->slot;
 
-        if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) < 0) {
+        ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d);
+        if (ret >= 0) {
+            /* regular case, process returned bitmap */
+            kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
+        } else if (ret == -ENOENT) {
+            /* kernel does not have dirty bitmap in this slot */
+            ret = 0;

kvm-all.c static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section) · line 459

Quoted 10 lines
kvm-all.c +1 -1
+        } else {
             DPRINTF("ioctl failed %d\n", errno);
             ret = -1;
             break;
         }
 
-        kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
         start_addr = mem->start_addr + mem->memory_size;
     }
     g_free(d.dirty_bitmap);

I'd rather revert b533f658a98325d instead.

Paolo

#3 lore raw
Quoted 38 lines · Paolo Bonzini

Il 11/04/2014 04:31, Michael Tokarev ha scritto:

Quoted 37 lines

ENOENT means the kernel has an empty dirty bitmap for this slot. Don't abort in that case. This appears to solve the bug reported at

https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1303926

which first showed up with commit b533f658a98325d: fix return check for KVM_GET_DIRTY_LOG ioctl

---
kvm-all.c | 10 ++++++++--

1 file changed, 8 insertions(+), 2 deletions(-)
kvm-all.c +8 -1
index cd4111d..47fa948 100644
@@ -441,13 +441,19 @@ static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section)
 
        d.slot = mem->slot;
 
-        if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) < 0) {
+        ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d);
+        if (ret >= 0) {
+            /* regular case, process returned bitmap */
+            kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
+        } else if (ret == -ENOENT) {
+            /* kernel does not have dirty bitmap in this slot */
+            ret = 0;
+        } else {
            DPRINTF("ioctl failed %d\n", errno);
            ret = -1;
            break;
        }
 
Quoted 7 lines

kvm-all.c static int kvm_physical_sync_dirty_bitmap(MemoryRegionSection *section) · line 459

Quoted 5 lines
kvm-all.c +0 -1
-        kvm_get_dirty_pages_log_range(section, d.dirty_bitmap);
        start_addr = mem->start_addr + mem->memory_size;
    }
    g_free(d.dirty_bitmap);

I'd rather revert b533f658a98325d instead.

That seems wrong though. If we want to ignore all errors that's one thing, but before that commit we just ignored all errors other than EPERM.