Re: [PATCH] Enable 32bit dirty log pointers on 64bit host

2009-10-22 Thread Alexander Graf


On 22.10.2009, at 12:23, Avi Kivity wrote:


On 10/21/2009 04:08 PM, Alexander Graf wrote:

From: Arnd Bergmanna...@arndb.de

With big endian userspace, we can't quite figure out if a pointer
is 32 bit (shifted  32) or 64 bit when we read a 64 bit pointer.

This is what happens with dirty logging. To get the pointer  
interpreted

correctly, we thus need Arnd's patch to implement a compat layer for
the ioctl:

A better way to do this is to add a separate compat_ioctl() method  
that

converts this for you.

From: Arnd Bergmanna...@arndb.de
Signed-off-by: Arnd Bergmanna...@arndb.de
Acked-by: Alexander Grafag...@suse.de




If you send someone's patch, you need to sign this off.  That says  
you are legally allowed to send it along.


Ack means I have a say in this area and it looks good to me, you  
add it when someone else is doing the sending.


Ok, so is it still a From: Arnd then? Is it still signed-off by Arnd  
even though I change it?


Is there a Based-on-patch-by: tag? :-)

Alex

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Enable 32bit dirty log pointers on 64bit host

2009-10-22 Thread Alexander Graf
From: Arnd Bergmann a...@arndb.de

With big endian userspace, we can't quite figure out if a pointer
is 32 bit (shifted  32) or 64 bit when we read a 64 bit pointer.

This is what happens with dirty logging. To get the pointer interpreted
correctly, we thus need Arnd's patch to implement a compat layer for
the ioctl:

A better way to do this is to add a separate compat_ioctl() method that
converts this for you.

Based on initial patch from Arnd Bergmann.

From: Arnd Bergmann a...@arndb.de
Signed-off-by: Arnd Bergmann a...@arndb.de
Signed-off-by: Alexander Graf ag...@suse.de

---

Changes from Arnd's example version:

  - s/log.log/log/ (Avi)
  - use sizeof(compat_log) (Avi)
  - compile fixes
---
 virt/kvm/kvm_main.c |   49 -
 1 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cac69c4..54a272f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -43,6 +43,7 @@
 #include linux/swap.h
 #include linux/bitops.h
 #include linux/spinlock.h
+#include linux/compat.h
 
 #include asm/processor.h
 #include asm/io.h
@@ -1542,6 +1543,52 @@ out:
return r;
 }
 
+#ifdef CONFIG_COMPAT
+struct compat_kvm_dirty_log {
+   __u32 slot;
+   __u32 padding1;
+   union {
+   compat_uptr_t dirty_bitmap; /* one bit per page */
+   __u64 padding2;
+   };
+};
+
+static long kvm_vm_compat_ioctl(struct file *filp,
+  unsigned int ioctl, unsigned long arg)
+{
+   struct kvm *kvm = filp-private_data;
+   int r;
+
+   if (kvm-mm != current-mm)
+   return -EIO;
+   switch (ioctl) {
+   case KVM_GET_DIRTY_LOG: {
+   struct compat_kvm_dirty_log compat_log;
+   struct kvm_dirty_log log;
+
+   r = -EFAULT;
+   if (copy_from_user(compat_log, (void __user *)arg,
+  sizeof(compat_log)))
+   goto out;
+   log.slot = compat_log.slot;
+   log.padding1 = compat_log.padding1;
+   log.padding2 = compat_log.padding2;
+   log.dirty_bitmap = compat_ptr(compat_log.dirty_bitmap);
+
+   r = kvm_vm_ioctl_get_dirty_log(kvm, log);
+   if (r)
+   goto out;
+   break;
+   }
+   default:
+   r = kvm_vm_ioctl(filp, ioctl, arg);
+   }
+
+out:
+   return r;
+}
+#endif
+
 static int kvm_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
struct page *page[1];
@@ -1576,7 +1623,7 @@ static int kvm_vm_mmap(struct file *file, struct 
vm_area_struct *vma)
 static struct file_operations kvm_vm_fops = {
.release= kvm_vm_release,
.unlocked_ioctl = kvm_vm_ioctl,
-   .compat_ioctl   = kvm_vm_ioctl,
+   .compat_ioctl   = kvm_vm_compat_ioctl,
.mmap   = kvm_vm_mmap,
 };
 
-- 
1.6.0.2

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/27] Add KVM support for Book3s_64 (PPC64) hosts v5

2009-10-22 Thread Arnd Bergmann
On Wednesday 21 October 2009, Alexander Graf wrote:
 
 KVM for PowerPC only supports embedded cores at the moment.
 
 While it makes sense to virtualize on small machines, it's even more fun
 to do so on big boxes. So I figured we need KVM for PowerPC64 as well.
 
 This patchset implements KVM support for Book3s_64 hosts and guest support
 for Book3s_64 and G3/G4.
 
 To really make use of this, you also need a recent version of qemu.
 
 
 Don't want to apply patches? Get the git tree!
 
 $ git clone git://csgraf.de/kvm
 $ git checkout origin/ppc-v4

Whole series Acked-by: Arnd Bergmann a...@arndb.de

Great work, Alex!

Arnd 
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Enable 32bit dirty log pointers on 64bit host

2009-10-22 Thread Marcelo Tosatti
On Wed, Oct 21, 2009 at 04:08:29PM +0200, Alexander Graf wrote:
 From: Arnd Bergmann a...@arndb.de
 
 With big endian userspace, we can't quite figure out if a pointer
 is 32 bit (shifted  32) or 64 bit when we read a 64 bit pointer.
 
 This is what happens with dirty logging. To get the pointer interpreted
 correctly, we thus need Arnd's patch to implement a compat layer for
 the ioctl:
 
 A better way to do this is to add a separate compat_ioctl() method that
 converts this for you.
 
 From: Arnd Bergmann a...@arndb.de
 Signed-off-by: Arnd Bergmann a...@arndb.de
 Acked-by: Alexander Graf ag...@suse.de
 
 ---
 
 Changes from Arnd's example version:
 
   - s/log.log/log/ (Avi)
   - use sizeof(compat_log) (Avi)
   - compile fixes

Applied, thanks.

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/27] Add KVM support for Book3s_64 (PPC64) hosts v5

2009-10-22 Thread Hollis Blanchard
On Wed, 2009-10-21 at 17:03 +0200, Alexander Graf wrote:
 KVM for PowerPC only supports embedded cores at the moment.
 
 While it makes sense to virtualize on small machines, it's even more fun
 to do so on big boxes. So I figured we need KVM for PowerPC64 as well.
 
 This patchset implements KVM support for Book3s_64 hosts and guest support
 for Book3s_64 and G3/G4.

Acked-by: Hollis Blanchard holl...@us.ibm.com

Avi, please apply these patches, and one more (unrelated) to fix the
Book E build that I will send in just a moment.

-- 
Hollis Blanchard
IBM Linux Technology Center

--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvmppc: Fix BUILD_BUG_ON condition

2009-10-22 Thread Hollis Blanchard
The old BUILD_BUG_ON implementation didn't work with __builtin_constant_p().
Fixing that revealed this test had been inverted for a long time without
anybody noticing...

Signed-off-by: Hollis Blanchard holl...@us.ibm.com

diff --git a/arch/powerpc/kvm/timing.h b/arch/powerpc/kvm/timing.h
--- a/arch/powerpc/kvm/timing.h
+++ b/arch/powerpc/kvm/timing.h
@@ -48,7 +48,7 @@ static inline void kvmppc_set_exit_type(
 static inline void kvmppc_account_exit_stat(struct kvm_vcpu *vcpu, int type)
 {
/* type has to be known at build time for optimization */
-   BUILD_BUG_ON(__builtin_constant_p(type));
+   BUILD_BUG_ON(!__builtin_constant_p(type));
switch (type) {
case EXT_INTR_EXITS:
vcpu-stat.ext_intr_exits++;
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] BUILD_BUG_ON: make it handle more cases

2009-10-22 Thread Américo Wang
On Tue, Oct 20, 2009 at 10:43 PM, Alan Jenkins
sourcejedi.l...@googlemail.com wrote:
 On 10/20/09, Américo Wang xiyou.wangc...@gmail.com wrote:
 On Tue, Oct 20, 2009 at 02:15:33PM +1030, Rusty Russell wrote:
BUILD_BUG_ON used to use the optimizer to do code elimination or fail
at link time; it was changed to first the size of a negative array (a
nicer compile time error), then (in
8c87df457cb58fe75b9b893007917cf8095660a0) to a bitfield.

bitfields: needs a literal constant at parse time, and can't be put under
      if (__builtin_constant_p(x)) for example.
negative array: can handle anything, but if the compiler can't tell it's
      a constant, silently has no effect.
link time: breaks link if the compiler can't determine the value, but the
      linker output is not usually as informative as a compiler error.

If we use the negative-array-size method *and* the link time trick,
we get the ability to use BUILD_BUG_ON() under __builtin_constant_p()
branches, and maximal ability for the compiler to detect errors at
build time.

Signed-off-by: Rusty Russell ru...@rustcorp.com.au

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -683,12 +683,6 @@ struct sysinfo {
      char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. 
 */
 };

-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
-
-/* Force a compilation error if condition is constant and true */
-#define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)]))
-
 /* Force a compilation error if condition is true, but also produce a
    result (of value 0 and type size_t), so the expression can be used
    e.g. in a structure initializer (or where-ever else comma expressions
@@ -696,6 +690,33 @@ struct sysinfo {
 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))

+/**
+ * BUILD_BUG_ON - break compile if a condition is true.
+ * @cond: the condition which the compiler should know is false.
+ *
+ * If you have some code which relies on certain constants being equal, or
+ * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
+ * detect if someone changes it.
+ *
+ * The implementation uses gcc's reluctance to create a negative array,
 but
+ * gcc (as of 4.4) only emits that error for obvious cases (eg. not
 arguments
+ * to inline functions).  So as a fallback we use the optimizer; if it
 can't
+ * prove the condition is false, it will cause a link error on the
 undefined
+ * __build_bug_on_failed.  This error message can be harder to track
 down
+ * though, hence the two different methods.
+ */
+#ifndef __OPTIMIZE__
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
+#else
+extern int __build_bug_on_failed;

 Hmm, what exactly is __build_bug_on_failed?

 Well, we haven't added a definition for it in this patch.  I'm sure
 grep will tell you it wasn't defined before hand either.  So any
 reference to it is an error - which will be reported at link time.

+#define BUILD_BUG_ON(condition)                                      \
+     do {                                                    \
+             ((void)sizeof(char[1 - 2*!!(condition)]));      \
+             if (condition) __build_bug_on_failed = 1;       \

 If condition is known false at compile time, gcc -O will eliminate
 the code which refers to __build_bug_on_failed.  If it's not proved to
 be false - it will break the build, which is exactly what we want
 BUILD_BUG_ON to do.

Ah, clever trick! Got it.
Thanks!

Reviewed-by: WANG Cong xiyou.wangc...@gmail.com
--
To unsubscribe from this list: send the line unsubscribe kvm-ppc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html