Skip to contentSkip to conversation

PPC KVM bringup patches round 2

PATCH In review Alexander Graf 2 participants 18 messages Jul 23, 2009 – Jul 24, 2009 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover PPC KVM bringup patches round 2

Thanks a lot for commiting the previous patches. I still needed these to get a guest booted as broken as with TCG ;-).

Alexander Graf (3):
Move mp_state to CPU_COMMON
Assume PPC64 host on PPC32 KVM
PPC: Round VGA BIOS size to page boundary

 cpu-defs.h        |    3 ++-
 hw/ppc_newworld.c |    3 +++
 hw/ppc_oldworld.c |    4 ++++
 kvm-all.c         |    6 ++++++
 target-i386/cpu.h |    1 -
 5 files changed, 15 insertions(+), 2 deletions(-)
#2 lore raw

PATCH 2/3 Assume PPC64 host on PPC32 KVM

In reply to Alexander Graf

When talking to the kernel about dirty maps, we need to find out which bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common), we can't interpret the bits properly anymore, because we think long is 32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running on a PPC64 host. Currently there is no dirty bitmap implementation for PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
 kvm-all.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +6 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
         for (phys_addr = mem->start_addr, addr = mem->phys_offset;
              phys_addr < mem->start_addr + mem->memory_size;
              phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long sizes in user and
+              * kernel space, so assume we're always on ppc64. */
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
             unsigned long *bitmap = (unsigned long *)d.dirty_bitmap;
+#endif
             unsigned nr = (phys_addr - mem->start_addr) >> TARGET_PAGE_BITS;
             unsigned word = nr / (sizeof(*bitmap) * 8);
             unsigned bit = nr % (sizeof(*bitmap) * 8);
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/3 PPC: Round VGA BIOS size to page boundary

When giving KVM a slot of a size not on page boundary, it chokes. So let's just round up the VGA BIOS size so nobody complains anymore and we don't need to implement sub-page slots.

Required for booting a PPC guest in KVM.

---
 hw/ppc_newworld.c |    3 +++
 hw/ppc_oldworld.c |    4 ++++
 2 files changed, 7 insertions(+), 0 deletions(-)
hw/ppc_newworld.c +3 -0
index 4e5043c..b28a23d 100644
@@ -179,6 +179,9 @@ static void ppc_core99_init (ram_addr_t ram_size,
         vga_bios_ptr[3] = 'V';
         cpu_to_be32w((uint32_t *)(vga_bios_ptr + 4), vga_bios_size);
         vga_bios_size += 8;
+
+        /* Round to page boundary */
+        vga_bios_size = (vga_bios_size + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK;
     }
 
     if (linux_boot) {
hw/ppc_oldworld.c +4 -0
index b26e407..0daa25b 100644
@@ -212,6 +212,9 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
         vga_bios_ptr[3] = 'V';
         cpu_to_be32w((uint32_t *)(vga_bios_ptr + 4), vga_bios_size);
         vga_bios_size += 8;
+
+        /* Round to page boundary */
+        vga_bios_size = (vga_bios_size + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK;
     }
 
     if (linux_boot) {
@@ -310,6 +313,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
     pic = heathrow_pic_init(&pic_mem_index, 1, heathrow_irqs);
     pci_bus = pci_grackle_init(0xfec00000, pic);
     pci_vga_init(pci_bus, vga_bios_offset, vga_bios_size);
+printf("Mapping VGA to 0x%lx - 0x%lx\n", vga_bios_offset, vga_bios_offset + vga_bios_size);
 
     escc_mem_index = escc_init(0x80013000, pic[0x0f], pic[0x10], serial_hds[0],
                                serial_hds[1], ESCC_CLOCK, 4);
Signature · 1 line
1.6.0.2
#1 lore raw

PATCH 1/3 Move mp_state to CPU_COMMON

In reply to Alexander Graf

MP State is implemented in the generic code, so let's move the variable it accesses to generic code as well.

Unbreaks PPC w/ KVM.

---
 cpu-defs.h        |    3 ++-
 target-i386/cpu.h |    1 -
 2 files changed, 2 insertions(+), 2 deletions(-)
cpu-defs.h +2 -1
index d73ec0a..2482398 100644
@@ -195,6 +195,7 @@ typedef struct CPUWatchpoint {
     const char *cpu_model_str;                                          \
     struct KVMState *kvm_state;                                         \
     struct kvm_run *kvm_run;                                            \
-    int kvm_fd;
+    int kvm_fd;                                                         \
+    int mp_state;
 
 #endif
target-i386/cpu.h +0 -1
index 08200ed..ce3fbc1 100644
@@ -689,7 +689,6 @@ typedef struct CPUX86State {
 
     /* For KVM */
     uint64_t interrupt_bitmap[256 / 64];
-    uint32_t mp_state;
 
     /* in order to simplify APIC support, we leave this pointer to the
        user */
Signature · 1 line
1.6.0.2
#4 lore raw

Re: [Qemu-devel] [PATCH 3/3] PPC: Round VGA BIOS size to page boundary

In reply to Alexander Graf
Quoted 11 lines · Alexander Graf

When giving KVM a slot of a size not on page boundary, it chokes. So let's just round up the VGA BIOS size so nobody complains anymore and we don't need to implement sub-page slots.

Required for booting a PPC guest in KVM.

---

hw/ppc_newworld.c |    3 +++
hw/ppc_oldworld.c |    4 ++++
2 files changed, 7 insertions(+), 0 deletions(-)

[...]

hw/ppc_oldworld.c static void ppc_heathrow_init (ram_addr_t · line 318

Quoted 8 lines
    if (linux_boot) {
hw/ppc_oldworld.c +1 -0
@@ -310,6 +313,7 @@ static void ppc_heathrow_init (ram_addr_t  
 ram_size,
    pic = heathrow_pic_init(&pic_mem_index, 1, heathrow_irqs);
    pci_bus = pci_grackle_init(0xfec00000, pic);
    pci_vga_init(pci_bus, vga_bios_offset, vga_bios_size);
+printf("Mapping VGA to 0x%lx - 0x%lx\n", vga_bios_offset,  
 vga_bios_offset + vga_bios_size);

Don't do this at home kids :-).

Please skip the last chunk.

Alex

#6 lore raw

[Qemu-devel] Re: [PATCH 3/3] PPC: Round VGA BIOS size to page boundary

In reply to a message not in the archive
Quoted 43 lines · Juan Quintela
Quoted 42 lines · Alexander Graf

When giving KVM a slot of a size not on page boundary, it chokes. So let's just round up the VGA BIOS size so nobody complains anymore and we don't need to implement sub-page slots.

Required for booting a PPC guest in KVM.

---

hw/ppc_newworld.c |    3 +++
hw/ppc_oldworld.c |    4 ++++
2 files changed, 7 insertions(+), 0 deletions(-)
hw/ppc_newworld.c +3 -0
index 4e5043c..b28a23d 100644
@@ -179,6 +179,9 @@ static void ppc_core99_init (ram_addr_t ram_size,
        vga_bios_ptr[3] = 'V';
        cpu_to_be32w((uint32_t *)(vga_bios_ptr + 4), vga_bios_size);
        vga_bios_size += 8;
+
+        /* Round to page boundary */
+        vga_bios_size = (vga_bios_size + TARGET_PAGE_SIZE) &  
 TARGET_PAGE_MASK;
    }
 
    if (linux_boot) {
hw/ppc_oldworld.c +3 -0
index b26e407..0daa25b 100644
@@ -212,6 +212,9 @@ static void ppc_heathrow_init (ram_addr_t  
 ram_size,
        vga_bios_ptr[3] = 'V';
        cpu_to_be32w((uint32_t *)(vga_bios_ptr + 4), vga_bios_size);
        vga_bios_size += 8;
+
+        /* Round to page boundary */
+        vga_bios_size = (vga_bios_size + TARGET_PAGE_SIZE) &  
 TARGET_PAGE_MASK;
    }
Quoted 10 lines

hw/ppc_oldworld.c static void ppc_heathrow_init (ram_addr_t · line 318

Quoted 8 lines
    if (linux_boot) {
hw/ppc_oldworld.c +1 -0
@@ -310,6 +313,7 @@ static void ppc_heathrow_init (ram_addr_t  
 ram_size,
    pic = heathrow_pic_init(&pic_mem_index, 1, heathrow_irqs);
    pci_bus = pci_grackle_init(0xfec00000, pic);
    pci_vga_init(pci_bus, vga_bios_offset, vga_bios_size);
+printf("Mapping VGA to 0x%lx - 0x%lx\n", vga_bios_offset,  
 vga_bios_offset + vga_bios_size);

bad indentation.

Thanks :-). I usually do this bad indentation to indicate to myself that this is a temporary debug line that I need to remove before committing.

I think I wrote a reply to the post saying that this chunk should be removed, but it's good to know that someone glimpses over my patches :-).

Thanks again!

Alex

#7 lore raw

[Qemu-devel] Re: [PATCH 3/3] PPC: Round VGA BIOS size to page boundary

In reply to Alexander Graf
Quoted 17 lines · Alexander Graf

When giving KVM a slot of a size not on page boundary, it chokes. So let's just round up the VGA BIOS size so nobody complains anymore and we don't need to implement sub-page slots.

Required for booting a PPC guest in KVM.

---
 hw/ppc_newworld.c |    3 +++
 hw/ppc_oldworld.c |    4 ++++
 2 files changed, 7 insertions(+), 0 deletions(-)
hw/ppc_newworld.c +0 -0
index 4e5043c..b28a23d 100644

hw/ppc_newworld.c static void ppc_core99_init (ram_addr_t ram_size, · line 184

Quoted 6 lines
hw/ppc_newworld.c +3 -0
@@ -179,6 +179,9 @@ static void ppc_core99_init (ram_addr_t ram_size,
         vga_bios_ptr[3] = 'V';
         cpu_to_be32w((uint32_t *)(vga_bios_ptr + 4), vga_bios_size);
         vga_bios_size += 8;
+
+        /* Round to page boundary */
+        vga_bios_size = (vga_bios_size + TARGET_PAGE_SIZE) & TARGET_PAGE_MASK;

To be really nit-picky: ;)

(vga_bios_size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#9 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

In reply to Alexander Graf
Quoted 27 lines · Alexander Graf

When talking to the kernel about dirty maps, we need to find out which bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common), we can't interpret the bits properly anymore, because we think long is 32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running on a PPC64 host. Currently there is no dirty bitmap implementation for PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
 kvm-all.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +0 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
         for (phys_addr = mem->start_addr, addr = mem->phys_offset;
              phys_addr < mem->start_addr + mem->memory_size;
              phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {

kvm-all.c int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, · line 369

Quoted 10 lines
kvm-all.c +6 -0
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long sizes in user and
+              * kernel space, so assume we're always on ppc64. */
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
             unsigned long *bitmap = (unsigned long *)d.dirty_bitmap;
+#endif
             unsigned nr = (phys_addr - mem->start_addr) >> TARGET_PAGE_BITS;
             unsigned word = nr / (sizeof(*bitmap) * 8);
             unsigned bit = nr % (sizeof(*bitmap) * 8);

This rather screams for a generic fix. Current code assumes sizeof(unsigned long) == 8. That should already break on 32-bit x86 hosts. So either do (sizeof(*bitmap) * sizeof(unsigned long)) or switch to uint64_t - but for ALL hosts.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#8 lore raw

[Qemu-devel] Re: [PATCH 3/3] PPC: Round VGA BIOS size to page boundary

In reply to Jan Kiszka
Quoted 28 lines · Jan Kiszka
Quoted 17 lines · Alexander Graf

When giving KVM a slot of a size not on page boundary, it chokes. So let's just round up the VGA BIOS size so nobody complains anymore and we don't need to implement sub-page slots.

Required for booting a PPC guest in KVM.

---

hw/ppc_newworld.c |    3 +++
hw/ppc_oldworld.c |    4 ++++
2 files changed, 7 insertions(+), 0 deletions(-)
hw/ppc_newworld.c +0 -0
index 4e5043c..b28a23d 100644

hw/ppc_newworld.c static void ppc_core99_init (ram_addr_t ram_size, · line 185

Quoted 7 lines
hw/ppc_newworld.c +3 -0
@@ -179,6 +179,9 @@ static void ppc_core99_init (ram_addr_t ram_size,
        vga_bios_ptr[3] = 'V';
        cpu_to_be32w((uint32_t *)(vga_bios_ptr + 4), vga_bios_size);
        vga_bios_size += 8;
+
+        /* Round to page boundary */
+        vga_bios_size = (vga_bios_size + TARGET_PAGE_SIZE) &  
 TARGET_PAGE_MASK;

To be really nit-picky: ;)

Quoted 1 line

(vga_bios_size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;

Right :-).

Alex

#10 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

In reply to Jan Kiszka
Quoted 39 lines · Jan Kiszka
Quoted 38 lines · Alexander Graf

When talking to the kernel about dirty maps, we need to find out which bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common), we can't interpret the bits properly anymore, because we think long is 32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running on a PPC64 host. Currently there is no dirty bitmap implementation for PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
kvm-all.c | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +2 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int  
 kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
        for (phys_addr = mem->start_addr, addr = mem->phys_offset;
             phys_addr < mem->start_addr + mem->memory_size;
             phys_addr += TARGET_PAGE_SIZE, addr +=  
 TARGET_PAGE_SIZE) {
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long  

sizes in user and

kvm-all.c +4 -0
+              * kernel space, so assume we're always on ppc64. */
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
            unsigned long *bitmap = (unsigned long *)d.dirty_bitmap;
+#endif
            unsigned nr = (phys_addr - mem->start_addr) >>  
Quoted 8 lines
Quoted 3 lines
TARGET_PAGE_BITS;
            unsigned word = nr / (sizeof(*bitmap) * 8);
            unsigned bit = nr % (sizeof(*bitmap) * 8);

This rather screams for a generic fix. Current code assumes sizeof(unsigned long) == 8. That should already break on 32-bit x86 hosts. So either do (sizeof(*bitmap) * sizeof(unsigned long)) or switch to uint64_t - but for ALL hosts.

I don't see where that would break. The kernel treats the array as ulong*, userspace treats it as ulong* and set_bit in kernel does bitmap[word] |= (1 << bit). So as long as userspace long and kernel long are the same, it works.

In fact - it should even work out with little endian and different ulong sizes. It just breaks on BE.

Alex

#11 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 51 lines · Alexander Graf
Quoted 39 lines · Jan Kiszka
Quoted 38 lines · Alexander Graf

When talking to the kernel about dirty maps, we need to find out which bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common),
we can't interpret the bits properly anymore, because we think long is 32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running on a PPC64 host. Currently there is no dirty bitmap implementation for PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
kvm-all.c | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +2 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int
 kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
        for (phys_addr = mem->start_addr, addr = mem->phys_offset;
             phys_addr < mem->start_addr + mem->memory_size;
             phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long sizes

in user and

kvm-all.c +4 -0
+              * kernel space, so assume we're always on ppc64. */
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
            unsigned long *bitmap = (unsigned long *)d.dirty_bitmap;
+#endif
            unsigned nr = (phys_addr - mem->start_addr) >>
Quoted 8 lines
Quoted 3 lines
TARGET_PAGE_BITS;
            unsigned word = nr / (sizeof(*bitmap) * 8);
            unsigned bit = nr % (sizeof(*bitmap) * 8);

This rather screams for a generic fix. Current code assumes sizeof(unsigned long) == 8. That should already break on 32-bit x86 hosts. So either do (sizeof(*bitmap) * sizeof(unsigned long)) or switch to uint64_t - but for ALL hosts.

Quoted 7 lines

I don't see where that would break. The kernel treats the array as ulong*, userspace treats it as ulong* and set_bit in kernel does bitmap[word] |= (1 << bit). So as long as userspace long and kernel long are the same, it works.

In fact - it should even work out with little endian and different ulong sizes. It just breaks on BE.

Err, yes, forget it.

But let's help me understanding the actual problem: Do you have different ulong sizes in your scenario? Why? Is it a compat issue of 32-bit userland on 64-bit kernel?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#12 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 59 lines · Jan Kiszka
Quoted 58 lines · Alexander Graf
Quoted 41 lines · Jan Kiszka
Quoted 40 lines · Alexander Graf

When talking to the kernel about dirty maps, we need to find out which bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common),
we can't interpret the bits properly anymore, because we think long is 32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running on a PPC64 host. Currently there is no dirty bitmap implementation for PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
kvm-all.c | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +2 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int
 kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
       for (phys_addr = mem->start_addr, addr = mem->phys_offset;
            phys_addr < mem->start_addr + mem->memory_size;
            phys_addr += TARGET_PAGE_SIZE, addr +=  
 TARGET_PAGE_SIZE) {
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long  

sizes
in user and

kvm-all.c +4 -0
+              * kernel space, so assume we're always on ppc64. */
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
           unsigned long *bitmap = (unsigned long *)d.dirty_bitmap;
+#endif
           unsigned nr = (phys_addr - mem->start_addr) >>
Quoted 8 lines
Quoted 3 lines
TARGET_PAGE_BITS;
           unsigned word = nr / (sizeof(*bitmap) * 8);
           unsigned bit = nr % (sizeof(*bitmap) * 8);

This rather screams for a generic fix. Current code assumes sizeof(unsigned long) == 8. That should already break on 32-bit x86 hosts. So either do (sizeof(*bitmap) * sizeof(unsigned long)) or switch to uint64_t - but for ALL hosts.

I don't see where that would break. The kernel treats the array as ulong*, userspace treats it as ulong* and set_bit in kernel does bitmap[word] |= (1 << bit). So as long as userspace long and kernel long are the same, it works.

Quoted 8 lines
Quoted 2 lines

In fact - it should even work out with little endian and different ulong sizes. It just breaks on BE.

Err, yes, forget it.

But let's help me understanding the actual problem: Do you have different ulong sizes in your scenario? Why? Is it a compat issue of 32-bit userland on 64-bit kernel?

32-bit userland on 64-bit kernel.

kernel: sizeof(ulong) = 8
userspace: sizeof(ulong) = 4

now, with big endian, a "1" is on the rightmost byte - which means looking at the bytes it's

kernel: byte[7]
userspace: byte[3]

So if you set bit nr "1" with the current logic, the kernel would set bit "1" (in the first 8 bytes), userspace would read bit "1" in the second byte, thus 32 + 1.

On little endian, the lower word is on the first 4 bytes, so it would still be bit "1" in the first byte.

Alex

#13 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 64 lines · Alexander Graf
Quoted 61 lines · Jan Kiszka
Quoted 59 lines · Alexander Graf
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Alexander Graf

When talking to the kernel about dirty maps, we need to find out which bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common),
we can't interpret the bits properly anymore, because we think long is 32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running
on a PPC64 host. Currently there is no dirty bitmap implementation for PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
kvm-all.c | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +2 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int
 kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
       for (phys_addr = mem->start_addr, addr = mem->phys_offset;
            phys_addr < mem->start_addr + mem->memory_size;
            phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) {
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long sizes

in user and

kvm-all.c +4 -0
+              * kernel space, so assume we're always on ppc64. */
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
           unsigned long *bitmap = (unsigned long *)d.dirty_bitmap;
+#endif
           unsigned nr = (phys_addr - mem->start_addr) >>
Quoted 8 lines
Quoted 3 lines
TARGET_PAGE_BITS;
           unsigned word = nr / (sizeof(*bitmap) * 8);
           unsigned bit = nr % (sizeof(*bitmap) * 8);

This rather screams for a generic fix. Current code assumes sizeof(unsigned long) == 8. That should already break on 32-bit x86 hosts. So either do (sizeof(*bitmap) * sizeof(unsigned long)) or switch to uint64_t - but for ALL hosts.

I don't see where that would break. The kernel treats the array as ulong*, userspace treats it as ulong* and set_bit in kernel does bitmap[word] |= (1 << bit). So as long as userspace long and kernel long are the same, it works.

In fact - it should even work out with little endian and different ulong sizes. It just breaks on BE.

Quoted 7 lines
Quoted 5 lines

Err, yes, forget it.

But let's help me understanding the actual problem: Do you have different ulong sizes in your scenario? Why? Is it a compat issue of 32-bit userland on 64-bit kernel?

32-bit userland on 64-bit kernel.

OK. So this is an issue due to an underspecified KVM ABI, right?

Quoted 10 lines

kernel: sizeof(ulong) = 8
userspace: sizeof(ulong) = 4

now, with big endian, a "1" is on the rightmost byte - which means looking at the bytes it's

kernel: byte[7]
userspace: byte[3]

Quoted 7 lines

So if you set bit nr "1" with the current logic, the kernel would set bit "1" (in the first 8 bytes), userspace would read bit "1" in the second byte, thus 32 + 1.

On little endian, the lower word is on the first 4 bytes, so it would still be bit "1" in the first byte.

Big endian machines require us to agree on the word size of the bitmap so that 32-on-64-bit works - and 32-on-32 doesn't break. I think the latter would be the case with your patch, no? Or don't we have 32-bit KVM PowerPC kernels?

In any case, I suggest to pin down the word size and use it for all hosts.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#14 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 71 lines · Jan Kiszka
Quoted 70 lines · Alexander Graf
Quoted 67 lines · Jan Kiszka
Quoted 56 lines · Alexander Graf
Quoted 44 lines · Jan Kiszka
Quoted 43 lines · Alexander Graf

When talking to the kernel about dirty maps, we need to find out which bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common),
we can't interpret the bits properly anymore, because we think long is 32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running
on a PPC64 host. Currently there is no dirty bitmap implementation for PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
kvm-all.c | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +2 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int
 kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
      for (phys_addr = mem->start_addr, addr = mem->phys_offset;
           phys_addr < mem->start_addr + mem->memory_size;
           phys_addr += TARGET_PAGE_SIZE, addr +=  
 TARGET_PAGE_SIZE) {
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long  

sizes
in user and
+ * kernel space, so assume we're always on ppc64.
*/

kvm-all.c +2 -0
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
          unsigned long *bitmap = (unsigned long  

*)d.dirty_bitmap;
+#endif

          unsigned nr = (phys_addr - mem->start_addr) >>
Quoted 8 lines
Quoted 3 lines
TARGET_PAGE_BITS;
          unsigned word = nr / (sizeof(*bitmap) * 8);
          unsigned bit = nr % (sizeof(*bitmap) * 8);

This rather screams for a generic fix. Current code assumes sizeof(unsigned long) == 8. That should already break on 32-bit x86 hosts. So either do (sizeof(*bitmap) * sizeof(unsigned long)) or switch to uint64_t - but for ALL hosts.

Quoted 7 lines

I don't see where that would break. The kernel treats the array as ulong*, userspace treats it as ulong* and set_bit in kernel does bitmap[word] |= (1 << bit). So as long as userspace long and kernel long are the same, it works.

In fact - it should even work out with little endian and different ulong sizes. It just breaks on BE.

Err, yes, forget it.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

But let's help me understanding the actual problem: Do you have different ulong sizes in your scenario? Why? Is it a compat issue of 32-bit userland on 64-bit kernel?

32-bit userland on 64-bit kernel.

OK. So this is an issue due to an underspecified KVM ABI, right?

Well it's a design decision in the (generic KVM) ABI.

Quoted 13 lines
Quoted 13 lines

kernel: sizeof(ulong) = 8
userspace: sizeof(ulong) = 4

now, with big endian, a "1" is on the rightmost byte - which means looking at the bytes it's

kernel: byte[7]
userspace: byte[3]

So if you set bit nr "1" with the current logic, the kernel would set bit "1" (in the first 8 bytes), userspace would read bit "1" in the second byte, thus 32 + 1.

Quoted 8 lines
Quoted 3 lines

On little endian, the lower word is on the first 4 bytes, so it would still be bit "1" in the first byte.

Big endian machines require us to agree on the word size of the bitmap so that 32-on-64-bit works - and 32-on-32 doesn't break. I think the latter would be the case with your patch, no? Or don't we have 32-bit KVM PowerPC kernels?

There are no 32-bit PowerPC KVM kernels that can do dirty logging.

Quoted 1 line

In any case, I suggest to pin down the word size and use it for all hosts.

That would break backwards compatibility.

Alex

#15 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 82 lines · Alexander Graf
Quoted 79 lines · Jan Kiszka
Quoted 78 lines · Alexander Graf
Quoted 74 lines · Jan Kiszka
Quoted 64 lines · Alexander Graf
Quoted 46 lines · Jan Kiszka
Quoted 45 lines · Alexander Graf

When talking to the kernel about dirty maps, we need to find out which
bits were actually set. This is done by set_bit and test_bit like functiontality which uses the "long" variable type.

Now, with PPC32 userspace and PPC64 kernel space (which is pretty common),
we can't interpret the bits properly anymore, because we think long is
32 bits wide.

So for PPC dirty bitmap analysis, let's just assume we're always running
on a PPC64 host. Currently there is no dirty bitmap implementation for
PPC32 / PPCEMB anyways.

Unbreaks dirty logging on PPC.

---
kvm-all.c | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
kvm-all.c +2 -0
index 824bb4c..bfaa623 100644
@@ -357,7 +357,13 @@ int
 kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
      for (phys_addr = mem->start_addr, addr = mem->phys_offset;
           phys_addr < mem->start_addr + mem->memory_size;
           phys_addr += TARGET_PAGE_SIZE, addr +=
 TARGET_PAGE_SIZE) {
+#ifdef HOST_PPC
+             /* Big endian keeps us from having different long

sizes
in user and

kvm-all.c +4 -0
+              * kernel space, so assume we're always on ppc64. */
+            uint64_t *bitmap = (uint64_t *)d.dirty_bitmap;
+#else
          unsigned long *bitmap = (unsigned long *)d.dirty_bitmap;
+#endif
          unsigned nr = (phys_addr - mem->start_addr) >>

TARGET_PAGE_BITS;

Quoted 8 lines
Quoted 2 lines
          unsigned word = nr / (sizeof(*bitmap) * 8);
          unsigned bit = nr % (sizeof(*bitmap) * 8);

This rather screams for a generic fix. Current code assumes sizeof(unsigned long) == 8. That should already break on 32-bit x86 hosts. So either do (sizeof(*bitmap) * sizeof(unsigned long)) or switch
to uint64_t - but for ALL hosts.

I don't see where that would break. The kernel treats the array as ulong*, userspace treats it as ulong* and set_bit in kernel does bitmap[word] |= (1 << bit). So as long as userspace long and kernel long
are the same, it works.

Quoted 3 lines

In fact - it should even work out with little endian and different ulong
sizes. It just breaks on BE.

Err, yes, forget it.

But let's help me understanding the actual problem: Do you have different ulong sizes in your scenario? Why? Is it a compat issue of 32-bit userland on 64-bit kernel?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

32-bit userland on 64-bit kernel.

OK. So this is an issue due to an underspecified KVM ABI, right?

Well it's a design decision in the (generic KVM) ABI.

I wouldn't call it a "decision" :). I think it happened to be ulong as KVM grew up on x86.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines

kernel: sizeof(ulong) = 8
userspace: sizeof(ulong) = 4

now, with big endian, a "1" is on the rightmost byte - which means looking at the bytes it's

kernel: byte[7]
userspace: byte[3]

So if you set bit nr "1" with the current logic, the kernel would set bit "1" (in the first 8 bytes), userspace would read bit "1" in the second byte, thus 32 + 1.

On little endian, the lower word is on the first 4 bytes, so it would still be bit "1" in the first byte.

Quoted 6 lines
Quoted 4 lines

Big endian machines require us to agree on the word size of the bitmap so that 32-on-64-bit works - and 32-on-32 doesn't break. I think the latter would be the case with your patch, no? Or don't we have 32-bit KVM PowerPC kernels?

There are no 32-bit PowerPC KVM kernels that can do dirty logging.

By design or by lack of implementation?

And what if some other arch with support for both pops up? #ifdef HOST_PPC is no long-term solutions. And I see no need to install a temporary workaround given the currently existing kernel support.

Quoted 5 lines
Quoted 3 lines

In any case, I suggest to pin down the word size and use it for all hosts.

That would break backwards compatibility.

x86 and ia64 are little endian for which is doesn't matter, PowerPC and s390 don't support dirty logging so far. Or what would break?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#16 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Alexander Graf

On 24.07.2009, at 13:51, Jan Kiszka wrote:

[...]

Quoted 3 lines
Quoted 1 line

There are no 32-bit PowerPC KVM kernels that can do dirty logging.

By design or by lack of implementation?

Lack of implementation.

Quoted 3 lines

And what if some other arch with support for both pops up? #ifdef HOST_PPC is no long-term solutions. And I see no need to install a temporary workaround given the currently existing kernel support.

I'd like to have the qemu bits sorted out while polishing the kvm parts, so when kvm support shows up mainline there's a working userspace part.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

In any case, I suggest to pin down the word size and use it for all hosts.

That would break backwards compatibility.

x86 and ia64 are little endian for which is doesn't matter, PowerPC and s390 don't support dirty logging so far. Or what would break?

Oh you mean just always use u32* and be done with it?

Sounds appealing...

Alex

#17 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 14 lines · Alexander Graf
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Alexander Graf

On 24.07.2009, at 13:51, Jan Kiszka wrote:

[...]

Quoted 3 lines
Quoted 1 line

There are no 32-bit PowerPC KVM kernels that can do dirty logging.

By design or by lack of implementation?

Quoted 8 lines

Lack of implementation.

Quoted 3 lines

And what if some other arch with support for both pops up? #ifdef HOST_PPC is no long-term solutions. And I see no need to install a temporary workaround given the currently existing kernel support.

I'd like to have the qemu bits sorted out while polishing the kvm parts, so when kvm support shows up mainline there's a working userspace part.

I understand. But the risk is that what you submit to qemu and kvm may receive different reviews and finally look different. So for stuff which concerns not yet existing (or fully implemented) interfaces, the other way around is better. Specifically if there is a "risk" that it makes into a qemu release before the corresponding kernel bits are official.

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

In any case, I suggest to pin down the word size and use it for all hosts.

That would break backwards compatibility.

x86 and ia64 are little endian for which is doesn't matter, PowerPC and s390 don't support dirty logging so far. Or what would break?

Oh you mean just always use u32* and be done with it?

Or u64* as you suggested. It doesn't matter for existing support, and future support should simply use that type even on 32-bit hosts.

Quoted 4 lines

Sounds appealing...

Alex

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#18 lore raw

[Qemu-devel] Re: [PATCH 2/3] Assume PPC64 host on PPC32 KVM

Quoted 21 lines · Jan Kiszka
Quoted 20 lines · Alexander Graf
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Alexander Graf

On 24.07.2009, at 13:51, Jan Kiszka wrote:

[...]

Quoted 3 lines
Quoted 1 line

There are no 32-bit PowerPC KVM kernels that can do dirty logging.

By design or by lack of implementation?

Lack of implementation.

Quoted 3 lines

And what if some other arch with support for both pops up? #ifdef HOST_PPC is no long-term solutions. And I see no need to install a temporary workaround given the currently existing kernel support.

Quoted 8 lines
Quoted 2 lines

I'd like to have the qemu bits sorted out while polishing the kvm parts, so when kvm support shows up mainline there's a working userspace part.

I understand. But the risk is that what you submit to qemu and kvm may receive different reviews and finally look different. So for stuff which concerns not yet existing (or fully implemented) interfaces, the other way around is better. Specifically if there is a "risk" that it makes into a qemu release before the corresponding kernel bits are official.

Well, it looks like doing the qemu parts first was a good idea, because we can still change the interfaces :-).

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

In any case, I suggest to pin down the word size and use it for all hosts.

That would break backwards compatibility.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

x86 and ia64 are little endian for which is doesn't matter, PowerPC and s390 don't support dirty logging so far. Or what would break?

Oh you mean just always use u32* and be done with it?

Or u64* as you suggested. It doesn't matter for existing support, and future support should simply use that type even on 32-bit hosts.

Right. I guess it's time for v2!

Alex