diff mbox

kvm: ppc: detect old headers

Message ID 1304423686-18909-1-git-send-email-agraf@suse.de
State New
Headers show

Commit Message

Alexander Graf May 3, 2011, 11:54 a.m. UTC
When compiling Qemu with older kernel headers, the PVR setting
mechanism isn't available yet. Unfortunately, back then I didn't add
a capability we could check against, so all we can do is add a configure
test to see if we support PVR setting. For BookE, we don't care yet.

This fixes compilation errors with KVM enabled on older kernel headers
(like 2.6.32).

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 configure        |   18 ++++++++++++++++++
 target-ppc/kvm.c |   16 +++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletions(-)

Comments

Jan Kiszka May 3, 2011, 12:14 p.m. UTC | #1
On 2011-05-03 13:54, Alexander Graf wrote:
> When compiling Qemu with older kernel headers, the PVR setting
> mechanism isn't available yet. Unfortunately, back then I didn't add
> a capability we could check against, so all we can do is add a configure
> test to see if we support PVR setting. For BookE, we don't care yet.
> 
> This fixes compilation errors with KVM enabled on older kernel headers
> (like 2.6.32).

Why not finally import the latest kvm kernel headers into qemu? Would
save us a lot of current and future configure and #ifdef dances.

Jan
Alexander Graf May 3, 2011, 12:28 p.m. UTC | #2
On 03.05.2011, at 14:14, Jan Kiszka wrote:

> On 2011-05-03 13:54, Alexander Graf wrote:
>> When compiling Qemu with older kernel headers, the PVR setting
>> mechanism isn't available yet. Unfortunately, back then I didn't add
>> a capability we could check against, so all we can do is add a configure
>> test to see if we support PVR setting. For BookE, we don't care yet.
>> 
>> This fixes compilation errors with KVM enabled on older kernel headers
>> (like 2.6.32).
> 
> Why not finally import the latest kvm kernel headers into qemu? Would
> save us a lot of current and future configure and #ifdef dances.

Sure, sounds like a good topic for today's call?

Alex
Jan Kiszka May 3, 2011, 12:31 p.m. UTC | #3
On 2011-05-03 14:28, Alexander Graf wrote:
> 
> On 03.05.2011, at 14:14, Jan Kiszka wrote:
> 
>> On 2011-05-03 13:54, Alexander Graf wrote:
>>> When compiling Qemu with older kernel headers, the PVR setting
>>> mechanism isn't available yet. Unfortunately, back then I didn't add
>>> a capability we could check against, so all we can do is add a configure
>>> test to see if we support PVR setting. For BookE, we don't care yet.
>>>
>>> This fixes compilation errors with KVM enabled on older kernel headers
>>> (like 2.6.32).
>>
>> Why not finally import the latest kvm kernel headers into qemu? Would
>> save us a lot of current and future configure and #ifdef dances.
> 
> Sure, sounds like a good topic for today's call?

Fine with me. Patch should be done by then as well.

Jan
Alexander Graf May 3, 2011, 12:33 p.m. UTC | #4
On 03.05.2011, at 14:31, Jan Kiszka wrote:

> On 2011-05-03 14:28, Alexander Graf wrote:
>> 
>> On 03.05.2011, at 14:14, Jan Kiszka wrote:
>> 
>>> On 2011-05-03 13:54, Alexander Graf wrote:
>>>> When compiling Qemu with older kernel headers, the PVR setting
>>>> mechanism isn't available yet. Unfortunately, back then I didn't add
>>>> a capability we could check against, so all we can do is add a configure
>>>> test to see if we support PVR setting. For BookE, we don't care yet.
>>>> 
>>>> This fixes compilation errors with KVM enabled on older kernel headers
>>>> (like 2.6.32).
>>> 
>>> Why not finally import the latest kvm kernel headers into qemu? Would
>>> save us a lot of current and future configure and #ifdef dances.
>> 
>> Sure, sounds like a good topic for today's call?
> 
> Fine with me. Patch should be done by then as well.

*shrug* I'm fairly indifferent on that topic. It would help users, so they can easier compile things, but requires us to keep the headers in sync. Do you have any good way of automating the process?


Alex
Jan Kiszka May 3, 2011, 1:02 p.m. UTC | #5
On 2011-05-03 14:33, Alexander Graf wrote:
> 
> On 03.05.2011, at 14:31, Jan Kiszka wrote:
> 
>> On 2011-05-03 14:28, Alexander Graf wrote:
>>>
>>> On 03.05.2011, at 14:14, Jan Kiszka wrote:
>>>
>>>> On 2011-05-03 13:54, Alexander Graf wrote:
>>>>> When compiling Qemu with older kernel headers, the PVR setting
>>>>> mechanism isn't available yet. Unfortunately, back then I didn't add
>>>>> a capability we could check against, so all we can do is add a configure
>>>>> test to see if we support PVR setting. For BookE, we don't care yet.
>>>>>
>>>>> This fixes compilation errors with KVM enabled on older kernel headers
>>>>> (like 2.6.32).
>>>>
>>>> Why not finally import the latest kvm kernel headers into qemu? Would
>>>> save us a lot of current and future configure and #ifdef dances.
>>>
>>> Sure, sounds like a good topic for today's call?
>>
>> Fine with me. Patch should be done by then as well.
> 
> *shrug* I'm fairly indifferent on that topic. It would help users, so they can easier compile things, but requires us to keep the headers in sync. Do you have any good way of automating the process?

There will be a 'make update-kvm-headers' target, imported from
kvm-kmod. Can be run against some recent kernel, and the result will
just have to be committed & posted.

Moreover, I will drop alternative ways of pulling in headers (except via
CFLAGS overwriting). That will typically bite the patch submitter who
requires a header update and make her/him submit latest headers as well.
So far at least for the theory.

Jan
diff mbox

Patch

diff --git a/configure b/configure
index fbf5d5f..adfbb40 100755
--- a/configure
+++ b/configure
@@ -1772,6 +1772,21 @@  recent kvm-kmod from http://sourceforge.net/projects/kvm."
 fi
 
 ##########################################
+# test for ppc kvm pvr setting
+
+if test "$kvm" = "yes" && test "$cpu" = "ppc" -o "$cpu" = "ppc64"; then
+            cat > $TMPC <<EOF
+    #include <asm/kvm.h>
+    int main(void) { struct kvm_sregs s; s.pvr = 0; return 0; }
+EOF
+    if compile_prog "$kvm_cflags" "" ; then
+        kvm_ppc_pvr=yes
+    else
+        kvm_ppc_pvr=no
+    fi
+fi
+
+##########################################
 # test for vhost net
 
 if test "$vhost_net" != "no"; then
@@ -3257,6 +3272,9 @@  case "$target_arch2" in
       if test $vhost_net = "yes" ; then
         echo "CONFIG_VHOST_NET=y" >> $config_target_mak
       fi
+      if test $kvm_ppc_pvr = "yes" ; then
+        echo "CONFIG_KVM_PPC_PVR=y" >> $config_target_mak
+      fi
     fi
 esac
 if test "$target_bigendian" = "yes" ; then
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 5a1b6cb..ccf4668 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -94,19 +94,33 @@  static int kvm_arch_sync_sregs(CPUState *cenv)
     int ret;
 
     if (cenv->excp_model == POWERPC_EXCP_BOOKE) {
+        /* What we're really trying to say is "if we're on BookE, we use
+           the native PVR for now". This is the only sane way to check
+           it though, so we potentially confuse users that they can run
+           BookE guests on BookS. Let's hope nobody dares enough :) */
         return 0;
     } else {
         if (!cap_segstate) {
-            return 0;
+            fprintf(stderr, "kvm error: missing PVR setting capability\n");
+            return -ENOSYS;
         }
     }
 
+#if !defined(CONFIG_KVM_PPC_PVR)
+    if (1) {
+        fprintf(stderr, "kvm error: missing PVR setting capability\n");
+        return -ENOSYS;
+    }
+#endif
+
     ret = kvm_vcpu_ioctl(cenv, KVM_GET_SREGS, &sregs);
     if (ret) {
         return ret;
     }
 
+#ifdef CONFIG_KVM_PPC_PVR
     sregs.pvr = cenv->spr[SPR_PVR];
+#endif
     return kvm_vcpu_ioctl(cenv, KVM_SET_SREGS, &sregs);
 }