WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-ppc-devel

[XenPPC] [xenppc-unstable] [XEN] fix xenctl_cpumap translation to handle

To: xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
Subject: [XenPPC] [xenppc-unstable] [XEN] fix xenctl_cpumap translation to handle bitops accessed like arrays
From: Xen patchbot-xenppc-unstable <patchbot-xenppc-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Sun, 17 Dec 2006 18:00:14 +0000
Delivery-date: Sun, 17 Dec 2006 10:02:31 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-ppc-devel-request@lists.xensource.com?subject=help>
List-id: Xen PPC development <xen-ppc-devel.lists.xensource.com>
List-post: <mailto:xen-ppc-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-ppc-devel>, <mailto:xen-ppc-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-ppc-devel>, <mailto:xen-ppc-devel-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-ppc-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
# Node ID 4b07d05c1b4e3492199e118d03f89209caffcad2
# Parent  b04e24db308f2215c6bafaf358d1c10da79f244f
[XEN] fix xenctl_cpumap translation to handle bitops accessed like arrays

Patch submitted upstream:

On PowerPC (and other big endian and/or RISC architectures) bit
offsets in a bitmap are actually represented by a bit-offset from an
element in an array rather than a bit-offset from the base memory
pointer,  see xen/include/asm-powerpc/bitops.h for a complete
explanation.

This complicates the conversion of cpumask_t from/to xenctl_cpumap.

The following patch allows an architecture to declare that bitops are
"by long" rather than "by bit" and use an alternate scheme for
encoding.

Signed-off-by: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>
---
 xen/common/domctl.c              |   40 +++++++++++++++++++++++++++++++++++----
 xen/include/asm-powerpc/bitops.h |    3 ++
 xen/include/xen/bitops.h         |    4 +++
 3 files changed, 43 insertions(+), 4 deletions(-)

diff -r b04e24db308f -r 4b07d05c1b4e xen/common/domctl.c
--- a/xen/common/domctl.c       Sun Dec 17 12:40:10 2006 -0500
+++ b/xen/common/domctl.c       Sun Dec 17 12:53:12 2006 -0500
@@ -30,14 +30,36 @@ void cpumask_to_xenctl_cpumap(
 void cpumask_to_xenctl_cpumap(
     struct xenctl_cpumap *xenctl_cpumap, cpumask_t *cpumask)
 {
-    unsigned int guest_bytes, copy_bytes, i;
+    unsigned int guest_bytes, copy_bytes, xen_bytes, i;
     uint8_t zero = 0;
+    cpumask_t local;
 
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
 
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
-    copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
+
+    xen_bytes = (NR_CPUS + 7) / 8;
+    if (bitmap_by_long) {
+        if (((guest_bytes * 8) % BITS_PER_LONG) != 0) {
+            printk("%s: Unable to translate bitmap\n", __func__);
+            return;
+        }
+
+        /* local copy */
+        memcpy(cpus_addr(local), cpus_addr(*cpumask), sizeof (local));
+
+        /* clear unused bits */
+        for (i = NR_CPUS; i < sizeof(local) * 8; i++) {
+            /* non-atomic version */
+            __clear_bit(i, cpus_addr(local));
+        }
+
+        xen_bytes = sizeof(local);
+        cpumask = &local;
+    }
+
+    copy_bytes  = min_t(unsigned int, guest_bytes, xen_bytes);
 
     copy_to_guest(xenctl_cpumap->bitmap,
                   (uint8_t *)cpus_addr(*cpumask),
@@ -50,10 +72,20 @@ void xenctl_cpumap_to_cpumask(
 void xenctl_cpumap_to_cpumask(
     cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap)
 {
-    unsigned int guest_bytes, copy_bytes;
+    unsigned int guest_bytes, copy_bytes, xen_bytes;
 
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
-    copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
+    xen_bytes = (NR_CPUS + 7) / 8;
+
+    if (bitmap_by_long) {
+        if (((guest_bytes * 8) % BITS_PER_LONG) != 0) {
+            printk("%s: Unable to translate bitmap\n", __func__);
+            return;
+        }
+        xen_bytes = sizeof(*cpumask);
+    }
+
+    copy_bytes  = min_t(unsigned int, guest_bytes, xen_bytes);
 
     cpus_clear(*cpumask);
 
diff -r b04e24db308f -r 4b07d05c1b4e xen/include/asm-powerpc/bitops.h
--- a/xen/include/asm-powerpc/bitops.h  Sun Dec 17 12:40:10 2006 -0500
+++ b/xen/include/asm-powerpc/bitops.h  Sun Dec 17 12:53:12 2006 -0500
@@ -41,6 +41,9 @@
 #define _PPC64_BITOPS_H
 
 #include <asm/memory.h>
+
+/* The following indicates that bitops are implemented as described above */
+#define bitmap_by_long (1)
 
 /*
  * clear_bit doesn't imply a memory barrier
diff -r b04e24db308f -r 4b07d05c1b4e xen/include/xen/bitops.h
--- a/xen/include/xen/bitops.h  Sun Dec 17 12:40:10 2006 -0500
+++ b/xen/include/xen/bitops.h  Sun Dec 17 12:53:12 2006 -0500
@@ -75,6 +75,10 @@ static __inline__ int generic_fls(int x)
  * scope
  */
 #include <asm/bitops.h>
+
+#ifndef bitmap_by_long
+#define bitmap_by_long (0)
+#endif
 
 
 static inline int generic_fls64(__u64 x)

_______________________________________________
Xen-ppc-devel mailing list
Xen-ppc-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-ppc-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [XenPPC] [xenppc-unstable] [XEN] fix xenctl_cpumap translation to handle bitops accessed like arrays, Xen patchbot-xenppc-unstable <=