Skip to contentSkip to conversation

exec: Fix qemu_ram_block_from_host for Xen

PATCH In review Anthony PERARD 2 participants 3 messages Jun 9, 2016 – Jun 13, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exec: Fix qemu_ram_block_from_host for Xen

Since f615f39 (exec: remove ram_addr argument from qemu_ram_block_from_host), migration under Xen is likely to fail, with a SEGV of QEMU. But the commit only reveal a bug with the calculation of the offset value in qemu_ram_block_from_host().

This patch calculates the offset from the ram_addr as qemu_ram_addr_from_host() will later calculate the ram_addr from the offset.

---
 exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +1 -1
index f2c9e37..f13106d 100644
@@ -1935,7 +1935,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
         ram_addr = xen_ram_addr_from_mapcache(ptr);
         block = qemu_get_ram_block(ram_addr);
         if (block) {
-            *offset = (host - block->host);
+            *offset = ram_addr - block->offset;
         }
         rcu_read_unlock();
         return block;
Signature · 1 line
Anthony PERARD
Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Anthony PERARD

Since f615f39 (exec: remove ram_addr argument from qemu_ram_block_from_host), migration under Xen is likely to fail, with a SEGV of QEMU. But the commit only reveal a bug with the calculation of the offset value in qemu_ram_block_from_host().

This patch calculates the offset from the ram_addr as qemu_ram_addr_from_host() will later calculate the ram_addr from the offset.

---
 exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +0 -0
index f2c9e37..f13106d 100644

exec.c RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset, · line 1941

Quoted 8 lines
exec.c +1 -1
@@ -1935,7 +1935,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
         ram_addr = xen_ram_addr_from_mapcache(ptr);
         block = qemu_get_ram_block(ram_addr);
         if (block) {
-            *offset = (host - block->host);
+            *offset = ram_addr - block->offset;
         }
         rcu_read_unlock();
         return block;

Feel free to send a pull request yourself!

Thanks, and sorry for the breakage. Indeed the broken code comes from commit 422148d3e56c3c9a07c0cf36c1e0a0b76f09c357.

Paolo

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/1
#2 lore raw
In reply to Anthony PERARD
Quoted 20 lines · Anthony PERARD

Since f615f39 (exec: remove ram_addr argument from qemu_ram_block_from_host), migration under Xen is likely to fail, with a SEGV of QEMU. But the commit only reveal a bug with the calculation of the offset value in qemu_ram_block_from_host().

This patch calculates the offset from the ram_addr as qemu_ram_addr_from_host() will later calculate the ram_addr from the offset.

---
 exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
exec.c +0 -0
index f2c9e37..f13106d 100644

exec.c RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset, · line 1941

Quoted 8 lines
exec.c +1 -1
@@ -1935,7 +1935,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
         ram_addr = xen_ram_addr_from_mapcache(ptr);
         block = qemu_get_ram_block(ram_addr);
         if (block) {
-            *offset = (host - block->host);
+            *offset = ram_addr - block->offset;
         }
         rcu_read_unlock();
         return block;

Feel free to send a pull request yourself!

Thanks, and sorry for the breakage. Indeed the broken code comes from commit 422148d3e56c3c9a07c0cf36c1e0a0b76f09c357.

Paolo