Skip to contentSkip to conversation

fix xenctl_cpumap translation to handle bitops accessed like arrays

PATCH In review Jimi Xenidis 2 participants 15 messages Dec 17, 2006 – Jan 21, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix xenctl_cpumap translation to handle bitops accessed like arrays

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.

---

xen/common/domctl.c +36 -4
diff -r b04e24db308f xen/common/domctl.c
@@ -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);
 
xen/include/asm-powerpc/bitops.h +3 -0
diff -r b04e24db308f xen/include/asm-powerpc/bitops.h
@@ -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
xen/include/xen/bitops.h +4 -0
diff -r b04e24db308f xen/include/xen/bitops.h
@@ -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)
#1 lore raw
Quoted 11 lines · Jimi Xenidis

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.

If the array-element type matters on big-endian systems then the tools really need fixing: one libxc operation passes down a uint32_t unit; another a uint64_t. Perhaps we should fix so they pass down 8-bit units (as the type of xenctl_cpumap_t would suggest) and then we could have byte_to_long_bitmap and long_to_byte_bitmap in Xen (which might encourage us to pull proper endianness headers into Xen).

-- Keir

#2 lore raw
Quoted 8 lines · Keir Fraser
Quoted 6 lines · Jimi Xenidis

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.

Quoted 8 lines
Quoted 5 lines

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.

If the array-element type matters on big-endian systems then the tools really need fixing: one libxc operation passes down a uint32_t unit;

Of the 3 usages only the tracebuffer mask uses uint32_t, maybe that could be repaired with the updated tracing work.

Quoted 4 lines

another
a uint64_t. Perhaps we should fix so they pass down 8-bit units (as the type of xenctl_cpumap_t would suggest) and then we could have byte_to_long_bitmap and long_to_byte_bitmap in Xen

Are you suggesting to still use bits in the bytes?
If so, then do you want "C" ordering in the byte or arch bit ordering? Perhaps we simply to us the byte array as a list of CPU numbers, with -1 to terminate?

Quoted 2 lines

(which might encourage us to pull proper
endianness headers into Xen).

I suspect that this is more "RISC thing" than an "Endian thing" since it is possible for little endian arch to use the array method (like ARM?).

Pulling in endian headers could be avoided.

-JX

#3 lore raw
Quoted 11 lines · Jimi Xenidis
Quoted 6 lines

another
a uint64_t. Perhaps we should fix so they pass down 8-bit units (as the type
of xenctl_cpumap_t would suggest) and then we could have byte_to_long_bitmap
and long_to_byte_bitmap in Xen

Are you suggesting to still use bits in the bytes?
If so, then do you want "C" ordering in the byte or arch bit ordering? Perhaps we simply to us the byte array as a list of CPU numbers, with -1 to terminate?

I mean bits 8k to 8k+7 inclusive are contained in byte at offset k in the cpumap, and in the obvious order (8k is least significant bit; 8k+7 is most significant). This is the byte-oriented bitmap type that your bitops.h goes on about. Since xenctl_cpumap_t is defined as a byte array and byte count, this interpretation would make sense.

-- Keir

#4 lore raw

Is this what you were looking for? let me know and I'll complete it.

-JX

tools/libxc/xc_domain.c +25 -8
diff -r c145c6638187 tools/libxc/xc_domain.c
@@ -96,16 +96,25 @@ int xc_vcpu_setaffinity(int xc_handle,
 {
     DECLARE_DOMCTL;
     int ret = -1;
+    uint8_t cpumap_array[sizeof (cpumap)];
+    int i;
 
     domctl.cmd = XEN_DOMCTL_setvcpuaffinity;
     domctl.domain = (domid_t)domid;
     domctl.u.vcpuaffinity.vcpu    = vcpu;
 
+    memset(cpumap_array, 0, sizeof(cpumap_array));
+
+    for (i = 0; i < sizeof (cpumap) * 8; i ++) {
+        if (cpumap & (1UL << i))
+            set_bit8(i, cpumap_array);
+    }
+
     set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
-                         (uint8_t *)&cpumap);
-    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
+                         cpumap_array);
+    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap_array) * 8;
     
-    if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 )
+    if ( lock_pages(cpumap_array, sizeof(cpumap_array)) != 0 )
     {
         PERROR("Could not lock memory for Xen hypercall");
         goto out;
@@ -113,7 +122,7 @@ int xc_vcpu_setaffinity(int xc_handle,
 
     ret = do_domctl(xc_handle, &domctl);
 
-    unlock_pages(&cpumap, sizeof(cpumap));
+    unlock_pages(cpumap_array, sizeof(cpumap_array));
 
  out:
     return ret;
@@ -127,16 +136,18 @@ int xc_vcpu_getaffinity(int xc_handle,
 {
     DECLARE_DOMCTL;
     int ret = -1;
+    uint8_t cpumap_array[sizeof (*cpumap)];
+    int i;
 
     domctl.cmd = XEN_DOMCTL_getvcpuaffinity;
     domctl.domain = (domid_t)domid;
     domctl.u.vcpuaffinity.vcpu = vcpu;
 
     set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap,
-                         (uint8_t *)cpumap);
-    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
+                         (uint8_t *)cpumap_array);
+    domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap_array) * 8;
     
-    if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 )
+    if ( lock_pages(cpumap_array, sizeof(cpumap_array)) != 0 )
     {
         PERROR("Could not lock memory for Xen hypercall");
         goto out;
@@ -144,7 +155,13 @@ int xc_vcpu_getaffinity(int xc_handle,
 
     ret = do_domctl(xc_handle, &domctl);
 
-    unlock_pages(cpumap, sizeof(*cpumap));
+    unlock_pages(cpumap_array, sizeof(cpumap_array));
+
+    *cpumap = 0;
+    for (i = 0; i < sizeof (*cpumap) * 8; i ++) {
+        if (test_bit8(i, cpumap_array))
+            *cpumap |= 1UL << i;
+    }
 
  out:
     return ret;
xen/common/domctl.c +18 -7
diff -r c145c6638187 xen/common/domctl.c
@@ -28,20 +28,24 @@ extern void arch_getdomaininfo_ctxt(
     struct vcpu *, struct vcpu_guest_context *);
 
 void cpumask_to_xenctl_cpumap(
-    struct xenctl_cpumap *xenctl_cpumap, cpumask_t *cpumask)
+    struct xenctl_cpumap *xenctl_cpumap, const cpumask_t *cpumask)
 {
     unsigned int guest_bytes, copy_bytes, i;
     uint8_t zero = 0;
+    uint8_t local[sizeof (*cpumask)];
 
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
 
+    memset(local, 0, sizeof (local));
+    for_each_cpu_mask(i, *cpumask) {
+        set_bit8(i, local);
+    }
+
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
 
-    copy_to_guest(xenctl_cpumap->bitmap,
-                  (uint8_t *)cpus_addr(*cpumask),
-                  copy_bytes);
+    copy_to_guest(xenctl_cpumap->bitmap, &local[0], copy_bytes);
 
     for ( i = copy_bytes; i < guest_bytes; i++ )
         copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1);
@@ -51,6 +55,8 @@ void xenctl_cpumap_to_cpumask(
     cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap)
 {
     unsigned int guest_bytes, copy_bytes;
+    unsigned int i;
+    uint8_t local[sizeof (*cpumask)];
 
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
@@ -60,9 +66,14 @@ void xenctl_cpumap_to_cpumask(
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
 
-    copy_from_guest((uint8_t *)cpus_addr(*cpumask),
-                    xenctl_cpumap->bitmap,
-                    copy_bytes);
+    memset(local, 0, sizeof(local));
+
+    copy_from_guest(&local[0], xenctl_cpumap->bitmap, copy_bytes);
+
+    for ( i = 0; i < NR_CPUS; i++) {
+        if (test_bit8(i, local))
+            cpu_set(i, *cpumask);
+    }
 }
 
 static inline int is_free_domid(domid_t dom)
xen/include/public/domctl.h +16 -0
diff -r c145c6638187 xen/include/public/domctl.h
@@ -424,6 +424,22 @@ typedef struct xen_domctl xen_domctl_t;
 typedef struct xen_domctl xen_domctl_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_t);
 
+/*
+ * these routine implement bitmasks as uint8_t arrays for portability
+ */
+static inline int test_bit8(ulong nr, const uint8_t *addr)
+{
+	return (1U & (addr[nr >> 3] >> (nr & 15)));
+}
+
+static inline void set_bit8(ulong nr, uint8_t *addr)
+{
+	uint8_t bit = 1UL << (nr & 15);
+	uint8_t *p = addr + (nr >> 3);
+
+	*p |= bit;
+}
+
 #endif /* __XEN_PUBLIC_DOMCTL_H__ */
 
 /*
xen/include/xen/cpumask.h +1 -1
diff -r c145c6638187 xen/include/xen/cpumask.h
@@ -382,7 +382,7 @@ extern cpumask_t cpu_present_map;
 /* Copy to/from cpumap provided by control tools. */
 struct xenctl_cpumap;
 void cpumask_to_xenctl_cpumap(
-    struct xenctl_cpumap *enctl_cpumap, cpumask_t *cpumask);
+    struct xenctl_cpumap *enctl_cpumap, const cpumask_t *cpumask);
 void xenctl_cpumap_to_cpumask(
     cpumask_t *cpumask, struct xenctl_cpumap *enctl_cpumap);
#5 lore raw
Quoted 3 lines · Jimi Xenidis

Is this what you were looking for? let me know and I'll complete it.

-JX

How about functions long_to_byte_bitmap(bitmap, nr_bits) and byte_to_long_bitmap(bitmap, nr_bits) defined in asm/bitops.h? These would be no-op for ia64 and x86, and could perform an in-place endian swap on each longword on powerpc.

-- Keir

#6 lore raw
Quoted 8 lines · Keir Fraser
Quoted 3 lines · Jimi Xenidis

Is this what you were looking for? let me know and I'll complete it.

-JX

How about functions long_to_byte_bitmap(bitmap, nr_bits) and byte_to_long_bitmap(bitmap, nr_bits) defined in asm/bitops.h?

hmm, as I see it we have 3 interfaces that should remain compatible.
1) The hvcall which uses a byte array
2) The libxc calls where 2 use uint64_t and one uses uint32_t
3) The xm/xc.c call which constructs a python list using "C"
ordering of the uint*_t word

so we would need similar interfaces in libxc and we would need a byte_to_uint{64,32}(), unless you want to change the libxc interfaces as well.

Quoted 3 lines

These would be
no-op for ia64 and x86, and could perform an in-place endian swap on each longword on powerpc.

I see now (I'm not that familiar with x86) that bitops in x86 are "consistent" with "C" shifting so x86 experience no change, however is it worth optimizing this? -JX

#7 lore raw
Quoted 9 lines · Jimi Xenidis
Quoted 2 lines

How about functions long_to_byte_bitmap(bitmap, nr_bits) and byte_to_long_bitmap(bitmap, nr_bits) defined in asm/bitops.h?

hmm, as I see it we have 3 interfaces that should remain compatible.
1) The hvcall which uses a byte array
2) The libxc calls where 2 use uint64_t and one uses uint32_t
3) The xm/xc.c call which constructs a python list using "C"
ordering of the uint*_t word

Quoted 3 lines

so we would need similar interfaces in libxc and we would need a byte_to_uint{64,32}(), unless you want to change the libxc interfaces as well.

I am suggesting we change just the hypervisor interface to expect a byte-oriented bitmap. So the libxc interfaces can stay as they are, but the libxc functions will need to do conversion from uint32_t/uint64_t to a byte-oriented bitmap. There is no loss of backward compatibility here for ia64 or x86 as little-endian systems do not care whether a bitmap is byte- word- or longword-oriented -- they're all identical.

Quoted 3 lines

I see now (I'm not that familiar with x86) that bitops in x86 are "consistent" with "C" shifting so x86 experience no change, however is it worth optimizing this?

The way you are doing the conversion would be fine. I'm mainly aiming for a clean abstraction and formalising the concept of a 'byte-oriented bitmap' is the best way of doing this that I can see right now.

-- Keir

#8 lore raw
Quoted 5 lines · Keir Fraser
Quoted 3 lines · Jimi Xenidis
Quoted 2 lines

How about functions long_to_byte_bitmap(bitmap, nr_bits) and byte_to_long_bitmap(bitmap, nr_bits) defined in asm/bitops.h?

[snip]

Quoted 4 lines

The way you are doing the conversion would be fine. I'm mainly aiming for a clean abstraction and formalising the concept of a 'byte-oriented bitmap' is the best way of doing this that I can see right now.

Sorry for taking so long with this, please comment on the following:

The following patch adds the ability to convert form "long" based bitmaps to "byte" base bitmaps for portability. This is only has the hypervisor side, but the definitions are such that the same prototype can be use by XC and Xen.

Sadly it adds a copy on the xenctl_cpumap_to_cpumask(), but it minimally impacts the common paths.

-JX

xen/arch/powerpc/domctl.c +41 -0
diff -r a6813a652f39 xen/arch/powerpc/domctl.c
@@ -116,3 +116,44 @@ long arch_do_domctl(struct xen_domctl *d
 
     return ret;
 }
+
+/*
+ * these routine implement bitmasks as uint8_t arrays for portability
+ */
+static inline int test_bit8(ulong nr, const uint8_t *addr)
+{
+	return (1U & (addr[nr >> 3] >> (nr & 15)));
+}
+
+static inline void set_bit8(ulong nr, uint8_t *addr)
+{
+	uint8_t bit = 1UL << (nr & 15);
+	uint8_t *p = addr + (nr >> 3);
+
+	*p |= bit;
+}
+
+
+void *long_to_byte_bitmap(uint8_t *bp, const ulong *lp, size_t n)
+{
+    int i;
+
+    memset(bp, 0, n);
+    for (i = 0; i < n * 8; i++) {
+        if (test_bit(i, lp))
+            set_bit8(i, bp);
+    }
+    return bp;
+}
+
+void *byte_to_long_bitmap(ulong *lp, const uint8_t *bp, size_t n)
+{
+    int i;
+
+    memset(lp, 0, n);
+    for (i = 0; i < n * 8; i++) {
+        if (test_bit8(i, bp))
+            __set_bit(i, lp); /* non-atomic */
+    }
+    return lp;
+}
xen/common/domctl.c +9 -6
diff -r a6813a652f39 xen/common/domctl.c
@@ -32,6 +32,8 @@ void cpumask_to_xenctl_cpumap(
 {
     unsigned int guest_bytes, copy_bytes, i;
     uint8_t zero = 0;
+    uint8_t local[sizeof (*cpumask)];
+    void *ptr;
 
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
@@ -39,9 +41,9 @@ void cpumask_to_xenctl_cpumap(
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
 
-    copy_to_guest(xenctl_cpumap->bitmap,
-                  (uint8_t *)cpus_addr(*cpumask),
-                  copy_bytes);
+    ptr = long_to_byte_bitmap(local, cpus_addr(*cpumask), copy_bytes);
+
+    copy_to_guest(xenctl_cpumap->bitmap, ptr, copy_bytes);
 
     for ( i = copy_bytes; i < guest_bytes; i++ )
         copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1);
@@ -51,6 +53,7 @@ void xenctl_cpumap_to_cpumask(
     cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap)
 {
     unsigned int guest_bytes, copy_bytes;
+    uint8_t local[sizeof (*cpumask)];
 
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
@@ -60,9 +63,9 @@ void xenctl_cpumap_to_cpumask(
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
 
-    copy_from_guest((uint8_t *)cpus_addr(*cpumask),
-                    xenctl_cpumap->bitmap,
-                    copy_bytes);
+    copy_from_guest(&local[0], xenctl_cpumap->bitmap, copy_bytes);
+
+    byte_to_long_bitmap(cpus_addr(*cpumask), local, copy_bytes);
 }
 
 static inline int is_free_domid(domid_t dom)
xen/include/public/arch-powerpc.h +2 -0
diff -r a6813a652f39 xen/include/public/arch-powerpc.h
@@ -118,4 +118,6 @@ struct arch_vcpu_info {
 #define MAX_VIRT_CPUS 32
 #endif
 
+#define __HAVE_ARCH_BYTE_TO_LONG_BITMAP
+
 #endif
xen/include/public/domctl.h +10 -0
diff -r a6813a652f39 xen/include/public/domctl.h
@@ -424,6 +424,16 @@ typedef struct xen_domctl xen_domctl_t;
 typedef struct xen_domctl xen_domctl_t;
 DEFINE_XEN_GUEST_HANDLE(xen_domctl_t);
 
+#ifdef __HAVE_ARCH_BYTE_TO_LONG_BITMAP
+extern void *long_to_byte_bitmap(uint8_t *bp, const ulong *lp,
+                                 size_t n);
+extern void *byte_to_long_bitmap(ulong *lp, const uint8_t *bp,
+                                 size_t n);
+#else
+#define long_to_byte_bitmap(bp, lp, s) ((void)bp, (void)s, lp)
+#define byte_to_long_bitmap(lp, bp, s) memcpy(lp, bp, s)
+#endif
+
 #endif /* __XEN_PUBLIC_DOMCTL_H__ */
 
 /*
#9 lore raw
Quoted 9 lines · Jimi Xenidis

Sorry for taking so long with this, please comment on the following:

The following patch adds the ability to convert form "long" based bitmaps to "byte" base bitmaps for portability. This is only has the hypervisor side, but the definitions are such that the same prototype can be use by XC and Xen.

Sadly it adds a copy on the xenctl_cpumap_to_cpumask(), but it minimally impacts the common paths.

Fine interface. On the Xen side the prototypes should go in xen/bitmap.h and the implementations in common/bitmap.c. I've added the Linux byteorder functions so in bitmap.c you ifdef on __BIG_ENDIAN and then use le32_to_cpu or le64_to_cpu (depending on BITS_PER_LONG). There's a question over whether we should do this transformation in-place on the bitmap, or use the copying semantics that you've chosen. I guess the latter is cleaner. Actually, your 'no-op' long_to_byte_bitmap() implementation does not memcpy -- why is that?

On the guest side you'll need to dup the function prototypes and implementations in libxenctrl. Trying to share prototypes or anything via the public headers is just skanky. Add a comment to xenctl_cpumap to explain the format (explain it is 'little endian' or 'byte oriented' with an ascii diagram) and leave it at that.

-- Keir

#10 lore raw
Quoted 9 lines · Keir Fraser
Quoted 7 lines · Jimi Xenidis

Sorry for taking so long with this, please comment on the following:

The following patch adds the ability to convert form "long" based bitmaps to "byte" base bitmaps for portability. This is only has the hypervisor side, but the definitions are such that the same prototype can be use by XC and Xen.

Quoted 5 lines
Quoted 2 lines

Sadly it adds a copy on the xenctl_cpumap_to_cpumask(), but it minimally impacts the common paths.

Fine interface. On the Xen side the prototypes should go in xen/bitmap.h and the implementations in common/bitmap.c.

Ack

Quoted 3 lines

I've added the Linux byteorder
functions so in bitmap.c you ifdef on __BIG_ENDIAN and then use le32_to_cpu or le64_to_cpu (depending on BITS_PER_LONG).

Ack

Quoted 3 lines

There's a question over whether
we should do this transformation in-place on the bitmap, or use the copying semantics that you've chosen. I guess the latter is cleaner.

A copy will almost always be necessary since the source or destination (always the long) may actually be active and could have come from anywhere, where the byte is most likely local.

Quoted 2 lines

Actually, your
'no-op' long_to_byte_bitmap() implementation does not memcpy -- why is that?

This is a little (possibly dirty) attempt to avoid a copy if no conversion is required. As long as the caller uses the return value all is well.
I'd happy to make it a memcpy() and feel better about it.

Quoted 6 lines

On the guest side you'll need to dup the function prototypes and implementations in libxenctrl. Trying to share prototypes or anything via the public headers is just skanky. Add a comment to xenctl_cpumap to explain the format (explain it is 'little endian' or 'byte oriented' with an ascii diagram) and leave it at that.

Ack

-JX

#11 lore raw
Quoted 8 lines · Jimi Xenidis
Quoted 3 lines

Actually, your
'no-op' long_to_byte_bitmap() implementation does not memcpy -- why is that?

This is a little (possibly dirty) attempt to avoid a copy if no conversion is required.
As long as the caller uses the return value all is well. I'd happy to make it a memcpy() and feel better about it.

Yes please.

K.

#12 lore raw

From the patch that you committed, AFAICT this function does not do anything:

void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)

{
	unsigned long l;
	int i, j, b;

	for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
		l = 0;
		for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
			l <<= 8;
			l |= bp[b+j];
			nbits -= 8;
		}
		lp[i] = l;
	}
}
Quoted 18 lines · Keir Fraser
Quoted 8 lines · Jimi Xenidis
Quoted 3 lines

Actually, your
'no-op' long_to_byte_bitmap() implementation does not memcpy -- why is that?

This is a little (possibly dirty) attempt to avoid a copy if no conversion is required.
As long as the caller uses the return value all is well. I'd happy to make it a memcpy() and feel better about it.

Yes please.

K.

#13 lore raw

Yes looks like I screwed up the source endianness. Perhaps the first two lines of the inner loop should be replaced by:
l |= (unsigned long)bp[b+j] << (j*8);

(and a similar change to the similar function) in libxc?

-- Keir

Quoted 19 lines · Jimi Xenidis

From the patch that you committed, AFAICT this function does not do
anything:

void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)
{
unsigned long l;
int i, j, b;

for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { l = 0;
for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { l <<= 8;
l |= bp[b+j];
nbits -= 8;
}
lp[i] = l;
}
}

#14 lore raw

Ack.. I saw it hit Xen-staging.. Thanks

-JX

Quoted 30 lines · Keir Fraser

Yes looks like I screwed up the source endianness. Perhaps the first two lines of the inner loop should be replaced by:
l |= (unsigned long)bp[b+j] << (j*8);

(and a similar change to the similar function) in libxc?

-- Keir

Quoted 19 lines · Jimi Xenidis

From the patch that you committed, AFAICT this function does not do
anything:

void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)
{
unsigned long l;
int i, j, b;

for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { l = 0;
for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { l <<= 8;
l |= bp[b+j];
nbits -= 8;
}
lp[i] = l;
}
}