Skip to contentSkip to conversation

Add preliminary KVM support for non-embedded PPC

PATCH In review Alexander Graf 1 participant 6 messages Jul 16, 2009 1 message not in the archive

lore
Share & tools
lore
#1 lore raw

PATCH 1/4 Enable PPC KVM for non-embedded

In reply to Alexander Graf

We now have KVM on PPC64 too and might get it on PPC32 as well, as soon as someone writes it.

So let's enable KVM for PPC32 and PPC64 targets.

---
 configure |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
configure +11 -0
index cba0c08..d832d17 100755
@@ -1969,6 +1969,7 @@ target_kvm="$kvm"
 # Make sure the target and host cpus are compatible
 if test ! \( "$target_arch2" = "$cpu" -o \
   \( "$target_arch2" = "ppcemb" -a "$cpu" = "ppc" \) -o \
+  \( "$target_arch2" = "ppc64"  -a "$cpu" = "ppc"   \) -o \
   \( "$target_arch2" = "x86_64" -a "$cpu" = "i386"   \) -o \
   \( "$target_arch2" = "i386"   -a "$cpu" = "x86_64" \) \) ; then
   target_kvm="no"
@@ -2087,6 +2088,11 @@ case "$target_arch2" in
     echo "TARGET_ARCH=ppc" >> $config_mak
     echo "#define TARGET_ARCH \"ppc\"" >> $config_h
     echo "#define TARGET_PPC 1" >> $config_h
+    if test "$target_kvm" = "yes" ; then
+      echo "CONFIG_KVM=y" >> $config_mak
+      echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
+      echo "#define CONFIG_KVM 1" >> $config_h
+    fi
     gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
     target_phys_bits=32
   ;;
@@ -2110,6 +2116,11 @@ case "$target_arch2" in
     echo "#define TARGET_ARCH \"ppc64\"" >> $config_h
     echo "#define TARGET_PPC 1" >> $config_h
     echo "#define TARGET_PPC64 1" >> $config_h
+    if test "$target_kvm" = "yes" ; then
+      echo "CONFIG_KVM=y" >> $config_mak
+      echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
+      echo "#define CONFIG_KVM 1" >> $config_h
+    fi
     gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
     target_phys_bits=64
   ;;
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/4 Add mp_state to PPC CPU struct

In reply to Alexander Graf

Some generic code tries to access env->mp_state. Let's just make it happy and provide it.

---
 configure        |    2 ++
 target-ppc/cpu.h |    4 ++++
 2 files changed, 6 insertions(+), 0 deletions(-)
configure +2 -0
index d832d17..1909591 100755
@@ -1993,6 +1993,7 @@ case "$target_arch2" in
       echo "CONFIG_KVM=y" >> $config_mak
       echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
       echo "#define CONFIG_KVM 1" >> $config_h
+      echo "#define CONFIG_KVM_MP 1" >> $config_h
     fi
     if test "$xen" = "yes" -a "$target_softmmu" = "yes";
     then
@@ -2015,6 +2016,7 @@ case "$target_arch2" in
       echo "CONFIG_KVM=y" >> $config_mak
       echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
       echo "#define CONFIG_KVM 1" >> $config_h
+      echo "#define CONFIG_KVM_MP 1" >> $config_h
     fi
     if test "$xen" = "yes" -a "$target_softmmu" = "yes"
     then
target-ppc/cpu.h +4 -0
index 59d47d2..5582a39 100644
@@ -660,6 +660,10 @@ struct CPUPPCState {
     target_ulong hreset_vector;
 #endif
 
+#ifdef CONFIG_KVM
+    uint32_t mp_state;
+#endif
+
     /* Those resources are used only during code translation */
     /* Next instruction pointer */
     target_ulong nip;
Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/4 Fix warning in kvm-all.c

This fixes a warning I stumbled across while compiling qemu on PPC64.

---
 kvm-all.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kvm-all.c +1 -1
index 8567ac9..961fa32 100644
@@ -226,7 +226,7 @@ static int kvm_dirty_pages_log_change(target_phys_addr_t phys_addr,
     if (mem == NULL)  {
             fprintf(stderr, "BUG: %s: invalid parameters " TARGET_FMT_plx "-"
                     TARGET_FMT_plx "\n", __func__, phys_addr,
-                    phys_addr + size - 1);
+                    (target_phys_addr_t)(phys_addr + size - 1));
             return -EINVAL;
     }
 
Signature · 1 line
1.6.0.2
#0 lore raw

cover Add preliminary KVM support for non-embedded PPC

With KVM support emerging for Book3S (PPC64), let's add support for it in Qemu too, so we have a user of this awesome new infrastructure.

This patchset enabled building of Qemu on KVM, though it does not work completely due to

1) Brokenness of Qemu (PPC32 and PPC64 targets are broken for me atm)
2) Brokenness in Slot management (guest breaks in Linux's PCI init code)

Nevertheless, this is a good starting point for anyone who wants to get involved with KVM on PowerPC!

Alexander Graf (4):
Enable PPC KVM for non-embedded
Set PVR in sregs
Add mp_state to PPC CPU struct
Fix warning in kvm-all.c

 configure        |   13 +++++++++++++
 kvm-all.c        |    2 +-
 target-ppc/cpu.h |    4 ++++
 target-ppc/kvm.c |   11 +++++++++--
 4 files changed, 27 insertions(+), 3 deletions(-)
#2 lore raw

PATCH 2/4 Set PVR in sregs

In reply to Alexander Graf

We need to tell the kernel about some initial CPU state we don't have yet, so let's use the "sregs" IOCTL for that and simply put the Processor Version Register in there.

Now the kernel knows which guest CPU to virtualize.

---
 target-ppc/kvm.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
target-ppc/kvm.c +9 -2
index acbb1ab..24828bd 100644
@@ -44,7 +44,13 @@ int kvm_arch_init(KVMState *s, int smp_cpus)
 
 int kvm_arch_init_vcpu(CPUState *cenv)
 {
-    return 0;
+    int ret = 0;
+    struct kvm_sregs sregs;
+
+    sregs.pvr = cenv->spr[SPR_PVR];
+    ret = kvm_vcpu_ioctl(cenv, KVM_SET_SREGS, &sregs);
+
+    return ret;
 }
 
 int kvm_arch_put_registers(CPUState *env)
@@ -127,7 +133,8 @@ int kvm_arch_pre_run(CPUState *env, struct kvm_run *run)
      * interrupt, reset, etc) in PPC-specific env->irq_input_state. */
     if (run->ready_for_interrupt_injection &&
         (env->interrupt_request & CPU_INTERRUPT_HARD) &&
-        (env->irq_input_state & (1<<PPC40x_INPUT_INT)))
+//        (env->irq_input_state & (1<<PPC40x_INPUT_INT)))
+        (env->irq_input_state & (1<<PPC6xx_INPUT_INT)))
     {
         /* For now KVM disregards the 'irq' argument. However, in the
          * future KVM could cache it in-kernel to avoid a heavyweight exit
Signature · 1 line
1.6.0.2
#6 lore raw

[Qemu-devel] Re: [PATCH 3/4] Add mp_state to PPC CPU struct

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

Some generic code tries to access env->mp_state. Let's just make it happy and provide it.
---

configure        |    2 ++
target-ppc/cpu.h |    4 ++++
2 files changed, 6 insertions(+), 0 deletions(-)
configure +2 -0
index d832d17..1909591 100755
@@ -1993,6 +1993,7 @@ case "$target_arch2" in
      echo "CONFIG_KVM=y" >> $config_mak
      echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
      echo "#define CONFIG_KVM 1" >> $config_h
+      echo "#define CONFIG_KVM_MP 1" >> $config_h
    fi
    if test "$xen" = "yes" -a "$target_softmmu" = "yes";
    then
@@ -2015,6 +2016,7 @@ case "$target_arch2" in
      echo "CONFIG_KVM=y" >> $config_mak
      echo "KVM_CFLAGS=$kvm_cflags" >> $config_mak
      echo "#define CONFIG_KVM 1" >> $config_h
+      echo "#define CONFIG_KVM_MP 1" >> $config_h
    fi
    if test "$xen" = "yes" -a "$target_softmmu" = "yes"
    then
target-ppc/cpu.h +0 -0
index 59d47d2..5582a39 100644
@@ -660,6 +660,10 @@ struct CPUPPCState {
    target_ulong hreset_vector;
 #endif
 
Quoted 3 lines

target-ppc/cpu.h struct CPUPPCState { · line 663

Quoted 1 line
target-ppc/cpu.h +1 -0
+#ifdef CONFIG_KVM

Do you mean CONFIG_KVM_MP, right? or it is more subtle?

Ugh. Yeah I forgot to remove the CONFIG_KVM_MP stuff from the patch :)

Thanks for the catch

Alex