Skip to contentSkip to conversation

ppc: Enable full Xen build

PATCH Superseded Shawn Anastasio 2 participants 13 messages Sep 1, 2023 – Sep 11, 2023

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover ppc: Enable full Xen build

Hello all,

This patch series performs all of the additions necessary to drop the build overrides for PPC and enable the full Xen build. Except in cases where compatibile implementations already exist (e.g. atomic.h and bitops.h), the newly added definitions are simple, unimplemented stubs that just call BUG_ON("unimplemented").

A few miscellaneous changes were also made to non-ppc code as well, specifically a few missing header fixes in common.

Thanks,
Shawn

--
v3: Address review comments from v2.

v2: Address review comments from v1. Some changes are still pending until the following patches are merged:
- [PATCH] mem-sharing: move (x86) / drop (Arm) arch_dump_shared_mem_info()
https://lists.xen.org/archives/html/xen-devel/2023-08/msg00887.html

- [PATCH] move max_page and total_pages to common code
https://lists.xen.org/archives/html/xen-devel/2023-08/msg00874.html

Shawn Anastasio (5):
xen/ppc: Implement atomic.h
xen/ppc: Implement bitops.h
xen/ppc: Define minimal stub headers required for full build xen/ppc: Add stub function and symbol definitions xen/ppc: Enable full Xen build

 xen/arch/ppc/Kconfig                     |   1 +
 xen/arch/ppc/Makefile                    |  17 +-
 xen/arch/ppc/arch.mk                     |   3 -
 xen/arch/ppc/include/asm/altp2m.h        |  25 ++
 xen/arch/ppc/include/asm/atomic.h        | 384 +++++++++++++++++++++++
 xen/arch/ppc/include/asm/bitops.h        | 330 ++++++++++++++++++-
 xen/arch/ppc/include/asm/bug.h           |   9 +
 xen/arch/ppc/include/asm/cache.h         |   2 +
 xen/arch/ppc/include/asm/config.h        |  10 +
 xen/arch/ppc/include/asm/cpufeature.h    |  10 +
 xen/arch/ppc/include/asm/current.h       |  43 +++
 xen/arch/ppc/include/asm/delay.h         |  12 +
 xen/arch/ppc/include/asm/device.h        |  53 ++++
 xen/arch/ppc/include/asm/div64.h         |  14 +
 xen/arch/ppc/include/asm/domain.h        |  47 +++
 xen/arch/ppc/include/asm/event.h         |  36 +++
 xen/arch/ppc/include/asm/flushtlb.h      |  24 ++
 xen/arch/ppc/include/asm/grant_table.h   |   5 +
 xen/arch/ppc/include/asm/guest_access.h  |  68 ++++
 xen/arch/ppc/include/asm/guest_atomics.h |  23 ++
 xen/arch/ppc/include/asm/hardirq.h       |  19 ++
 xen/arch/ppc/include/asm/hypercall.h     |   5 +
 xen/arch/ppc/include/asm/io.h            |  16 +
 xen/arch/ppc/include/asm/iocap.h         |   8 +
 xen/arch/ppc/include/asm/iommu.h         |   8 +
 xen/arch/ppc/include/asm/irq.h           |  33 ++
 xen/arch/ppc/include/asm/mem_access.h    |   5 +
 xen/arch/ppc/include/asm/memory.h        |  34 ++
 xen/arch/ppc/include/asm/mm.h            | 248 ++++++++++++++-
 xen/arch/ppc/include/asm/monitor.h       |  43 +++
 xen/arch/ppc/include/asm/nospec.h        |  15 +
 xen/arch/ppc/include/asm/numa.h          |  26 ++
 xen/arch/ppc/include/asm/p2m.h           | 105 +++++++
 xen/arch/ppc/include/asm/page.h          |  18 ++
 xen/arch/ppc/include/asm/paging.h        |   7 +
 xen/arch/ppc/include/asm/pci.h           |   7 +
 xen/arch/ppc/include/asm/percpu.h        |  24 ++
 xen/arch/ppc/include/asm/processor.h     |  10 +
 xen/arch/ppc/include/asm/random.h        |   9 +
 xen/arch/ppc/include/asm/setup.h         |   6 +
 xen/arch/ppc/include/asm/smp.h           |  18 ++
 xen/arch/ppc/include/asm/softirq.h       |   8 +
 xen/arch/ppc/include/asm/spinlock.h      |  15 +
 xen/arch/ppc/include/asm/system.h        | 224 ++++++++++++-
 xen/arch/ppc/include/asm/time.h          |  21 ++
 xen/arch/ppc/include/asm/vm_event.h      |  49 +++
 xen/arch/ppc/include/asm/xenoprof.h      |   0
 xen/arch/ppc/mm-radix.c                  |  44 ++-
 xen/arch/ppc/setup.c                     |   8 +
 xen/arch/ppc/stubs.c                     | 345 ++++++++++++++++++++
 xen/arch/ppc/tlb-radix.c                 |   2 +-
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 54 files changed, 2491 insertions(+), 11 deletions(-)
 create mode 100644 xen/arch/ppc/include/asm/altp2m.h
 create mode 100644 xen/arch/ppc/include/asm/atomic.h
 create mode 100644 xen/arch/ppc/include/asm/cpufeature.h
 create mode 100644 xen/arch/ppc/include/asm/current.h
 create mode 100644 xen/arch/ppc/include/asm/delay.h
 create mode 100644 xen/arch/ppc/include/asm/device.h
 create mode 100644 xen/arch/ppc/include/asm/div64.h
 create mode 100644 xen/arch/ppc/include/asm/domain.h
 create mode 100644 xen/arch/ppc/include/asm/event.h
 create mode 100644 xen/arch/ppc/include/asm/flushtlb.h
 create mode 100644 xen/arch/ppc/include/asm/grant_table.h
 create mode 100644 xen/arch/ppc/include/asm/guest_access.h
 create mode 100644 xen/arch/ppc/include/asm/guest_atomics.h
 create mode 100644 xen/arch/ppc/include/asm/hardirq.h
 create mode 100644 xen/arch/ppc/include/asm/hypercall.h
 create mode 100644 xen/arch/ppc/include/asm/io.h
 create mode 100644 xen/arch/ppc/include/asm/iocap.h
 create mode 100644 xen/arch/ppc/include/asm/iommu.h
 create mode 100644 xen/arch/ppc/include/asm/irq.h
 create mode 100644 xen/arch/ppc/include/asm/mem_access.h
 create mode 100644 xen/arch/ppc/include/asm/memory.h
 create mode 100644 xen/arch/ppc/include/asm/monitor.h
 create mode 100644 xen/arch/ppc/include/asm/nospec.h
 create mode 100644 xen/arch/ppc/include/asm/numa.h
 create mode 100644 xen/arch/ppc/include/asm/p2m.h
 create mode 100644 xen/arch/ppc/include/asm/paging.h
 create mode 100644 xen/arch/ppc/include/asm/pci.h
 create mode 100644 xen/arch/ppc/include/asm/percpu.h
 create mode 100644 xen/arch/ppc/include/asm/random.h
 create mode 100644 xen/arch/ppc/include/asm/setup.h
 create mode 100644 xen/arch/ppc/include/asm/smp.h
 create mode 100644 xen/arch/ppc/include/asm/softirq.h
 create mode 100644 xen/arch/ppc/include/asm/spinlock.h
 create mode 100644 xen/arch/ppc/include/asm/time.h
 create mode 100644 xen/arch/ppc/include/asm/vm_event.h
 create mode 100644 xen/arch/ppc/include/asm/xenoprof.h
 create mode 100644 xen/arch/ppc/stubs.c

--
2.30.2

#1 lore raw

PATCH v3 1/5 xen/ppc: Implement atomic.h

Implement atomic.h for PPC, based off of the original Xen 3.2 implementation.

---
v3:
- Drop full copyright text headers
- Drop unnecessary spaces after casts
- const-ize write_atomic_size
- Don't use GNU 0-length array extension in read_atomic
- Use "+m" asm constraint instead of separate "=m" and "m"
- Fix line-continuing backslash formatting in arch_cmpxchg

v2:
- Fix style of asm block constraints to include required spaces
- Fix macro local variable naming (use trailing underscore instead of leading)
- Drop unnecessary parens in __atomic_add_unless

 xen/arch/ppc/include/asm/atomic.h | 384 ++++++++++++++++++++++++++++++
 xen/arch/ppc/include/asm/memory.h |  34 +++
 2 files changed, 418 insertions(+)
 create mode 100644 xen/arch/ppc/include/asm/atomic.h
 create mode 100644 xen/arch/ppc/include/asm/memory.h
xen/arch/ppc/include/asm/atomic.h new file +384 -0
new file mode 100644
index 0000000000..06cd24ead4
@@ -0,0 +1,384 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * PowerPC64 atomic operations
+ *
+ * Copyright (C) 2001 Paul Mackerras <[email protected]>, IBM
+ * Copyright (C) 2001 Anton Blanchard <[email protected]>, IBM
+ * Copyright Raptor Engineering LLC
+ */
+
+#ifndef _ASM_PPC64_ATOMIC_H_
+#define _ASM_PPC64_ATOMIC_H_
+
+#include <xen/atomic.h>
+
+#include <asm/memory.h>
+
+static inline int atomic_read(const atomic_t *v)
+{
+    return *(volatile int *)&v->counter;
+}
+
+static inline int _atomic_read(atomic_t v)
+{
+    return v.counter;
+}
+
+static inline void atomic_set(atomic_t *v, int i)
+{
+    v->counter = i;
+}
+
+static inline void _atomic_set(atomic_t *v, int i)
+{
+    v->counter = i;
+}
+
+void __bad_atomic_read(const volatile void *p, void *res);
+void __bad_atomic_size(void);
+
+#define build_atomic_read(name, insn, type)                                    \
+    static inline type name(const volatile type *addr)                         \
+    {                                                                          \
+        type ret;                                                              \
+        asm volatile ( insn "%U1%X1 %0,%1" : "=r" (ret) : "m<>" (*addr) );     \
+        return ret;                                                            \
+    }
+
+#define build_atomic_write(name, insn, type)                                   \
+    static inline void name(volatile type *addr, type val)                     \
+    {                                                                          \
+        asm volatile ( insn "%U0%X0 %1,%0" : "=m<>" (*addr) : "r" (val) );     \
+    }
+
+#define build_add_sized(name, ldinsn, stinsn, type)                            \
+    static inline void name(volatile type *addr, type val)                     \
+    {                                                                          \
+        type t;                                                                \
+        asm volatile ( "1: " ldinsn " %0,0,%3\n"                               \
+                       "add%I2 %0,%0,%2\n"                                     \
+                       stinsn " %0,0,%3 \n"                                    \
+                       "bne- 1b\n"                                             \
+                       : "=&r" (t), "+m" (*addr)                               \
+                       : "r" (val), "r" (addr)                                 \
+                       : "cc" );                                               \
+    }
+
+build_atomic_read(read_u8_atomic, "lbz", uint8_t)
+build_atomic_read(read_u16_atomic, "lhz", uint16_t)
+build_atomic_read(read_u32_atomic, "lwz", uint32_t)
+build_atomic_read(read_u64_atomic, "ldz", uint64_t)
+
+build_atomic_write(write_u8_atomic, "stb", uint8_t)
+build_atomic_write(write_u16_atomic, "sth", uint16_t)
+build_atomic_write(write_u32_atomic, "stw", uint32_t)
+build_atomic_write(write_u64_atomic, "std", uint64_t)
+
+build_add_sized(add_u8_sized, "lbarx", "stbcx.",uint8_t)
+build_add_sized(add_u16_sized, "lharx", "sthcx.", uint16_t)
+build_add_sized(add_u32_sized, "lwarx", "stwcx.", uint32_t)
+
+#undef build_atomic_read
+#undef build_atomic_write
+#undef build_add_sized
+
+static always_inline void read_atomic_size(const volatile void *p, void *res,
+                                           unsigned int size)
+{
+    ASSERT(IS_ALIGNED((vaddr_t)p, size));
+    switch ( size )
+    {
+    case 1:
+        *(uint8_t *)res = read_u8_atomic(p);
+        break;
+    case 2:
+        *(uint16_t *)res = read_u16_atomic(p);
+        break;
+    case 4:
+        *(uint32_t *)res = read_u32_atomic(p);
+        break;
+    case 8:
+        *(uint64_t *)res = read_u64_atomic(p);
+        break;
+    default:
+        __bad_atomic_read(p, res);
+        break;
+    }
+}
+
+static always_inline void write_atomic_size(volatile void *p, const void *val,
+                                            unsigned int size)
+{
+    ASSERT(IS_ALIGNED((vaddr_t)p, size));
+    switch ( size )
+    {
+    case 1:
+        write_u8_atomic(p, *(const uint8_t *)val);
+        break;
+    case 2:
+        write_u16_atomic(p, *(const uint16_t *)val);
+        break;
+    case 4:
+        write_u32_atomic(p, *(const uint32_t *)val);
+        break;
+    case 8:
+        write_u64_atomic(p, *(const uint64_t *)val);
+        break;
+    default:
+        __bad_atomic_size();
+        break;
+    }
+}
+
+#define read_atomic(p)                                                         \
+    ({                                                                         \
+        union {                                                                \
+            typeof(*(p)) val;                                                  \
+            char c[sizeof(*(p))];                                              \
+        } x_;                                                                  \
+        read_atomic_size(p, x_.c, sizeof(*(p)));                               \
+        x_.val;                                                                \
+    })
+
+#define write_atomic(p, x)                                                     \
+    do                                                                         \
+    {                                                                          \
+        typeof(*(p)) x_ = (x);                                                 \
+        write_atomic_size(p, &x_, sizeof(*(p)));                               \
+    } while ( 0 )
+
+#define add_sized(p, x)                                                        \
+    ({                                                                         \
+        typeof(*(p)) x_ = (x);                                                 \
+        switch ( sizeof(*(p)) )                                                \
+        {                                                                      \
+        case 1:                                                                \
+            add_u8_sized((uint8_t *)(p), x_);                                  \
+            break;                                                             \
+        case 2:                                                                \
+            add_u16_sized((uint16_t *)(p), x_);                                \
+            break;                                                             \
+        case 4:                                                                \
+            add_u32_sized((uint32_t *)(p), x_);                                \
+            break;                                                             \
+        default:                                                               \
+            __bad_atomic_size();                                               \
+            break;                                                             \
+        }                                                                      \
+    })
+
+static inline void atomic_add(int a, atomic_t *v)
+{
+    int t;
+
+    asm volatile ( "1: lwarx %0,0,%3\n"
+                   "add %0,%2,%0\n"
+                   "stwcx. %0,0,%3\n"
+                   "bne- 1b"
+                   : "=&r" (t), "+m" (v->counter)
+                   : "r" (a), "r" (&v->counter)
+                   : "cc" );
+}
+
+static inline int atomic_add_return(int a, atomic_t *v)
+{
+    int t;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: lwarx %0,0,%2\n"
+                   "add %0,%1,%0\n"
+                   "stwcx. %0,0,%2\n"
+                   "bne- 1b"
+                   PPC_ATOMIC_EXIT_BARRIER
+                   : "=&r" (t)
+                   : "r" (a), "r" (&v->counter)
+                   : "cc", "memory" );
+
+    return t;
+}
+
+static inline void atomic_sub(int a, atomic_t *v)
+{
+    int t;
+
+    asm volatile ( "1: lwarx %0,0,%3\n"
+                   "subf %0,%2,%0\n"
+                   "stwcx. %0,0,%3\n"
+                   "bne- 1b"
+                   : "=&r" (t), "+m" (v->counter)
+                   : "r" (a), "r" (&v->counter)
+                   : "cc" );
+}
+
+static inline int atomic_sub_return(int a, atomic_t *v)
+{
+    int t;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: lwarx %0,0,%2\n"
+                   "subf %0,%1,%0\n"
+                   "stwcx. %0,0,%2\n"
+                   "bne- 1b"
+                   PPC_ATOMIC_EXIT_BARRIER
+                   : "=&r" (t)
+                   : "r" (a), "r" (&v->counter)
+                   : "cc", "memory" );
+
+    return t;
+}
+
+static inline void atomic_inc(atomic_t *v)
+{
+    int t;
+
+    asm volatile ( "1: lwarx %0,0,%2\n"
+                   "addic %0,%0,1\n"
+                   "stwcx. %0,0,%2\n"
+                   "bne- 1b"
+                   : "=&r" (t), "+m" (v->counter)
+                   : "r" (&v->counter)
+                   : "cc" );
+}
+
+static inline int atomic_inc_return(atomic_t *v)
+{
+    int t;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: lwarx %0,0,%1\n"
+                   "addic %0,%0,1\n"
+                   "stwcx. %0,0,%1\n"
+                   "bne- 1b"
+                   PPC_ATOMIC_EXIT_BARRIER
+                   : "=&r" (t)
+                   : "r" (&v->counter)
+                   : "cc", "memory" );
+
+    return t;
+}
+
+static inline void atomic_dec(atomic_t *v)
+{
+    int t;
+
+    asm volatile ( "1: lwarx %0,0,%2\n"
+                   "addic %0,%0,-1\n"
+                   "stwcx. %0,0,%2\n"
+                   "bne- 1b"
+                   : "=&r" (t), "+m" (v->counter)
+                   : "r" (&v->counter)
+                   : "cc" );
+}
+
+static inline int atomic_dec_return(atomic_t *v)
+{
+    int t;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: lwarx %0,0,%1\n"
+                   "addic %0,%0,-1\n"
+                   "stwcx. %0,0,%1\n"
+                   "bne- 1b"
+                   PPC_ATOMIC_EXIT_BARRIER
+                   : "=&r" (t)
+                   : "r" (&v->counter)
+                   : "cc", "memory" );
+
+    return t;
+}
+
+/*
+ * Atomically test *v and decrement if it is greater than 0.
+ * The function returns the old value of *v minus 1.
+ */
+static inline int atomic_dec_if_positive(atomic_t *v)
+{
+    int t;
+
+    asm volatile( PPC_ATOMIC_ENTRY_BARRIER
+                  "1: lwarx %0,0,%1 # atomic_dec_if_positive\n"
+                  "addic. %0,%0,-1\n"
+                  "blt- 2f\n"
+                  "stwcx. %0,0,%1\n"
+                  "bne- 1b\n"
+                  PPC_ATOMIC_EXIT_BARRIER
+                  "2:"
+                  : "=&r" (t)
+                  : "r" (&v->counter)
+                  : "cc", "memory" );
+
+    return t;
+}
+
+static inline atomic_t atomic_compareandswap(atomic_t old, atomic_t new,
+                                             atomic_t *v)
+{
+    atomic_t rc;
+    rc.counter = __cmpxchg(&v->counter, old.counter, new.counter, sizeof(int));
+    return rc;
+}
+
+#define arch_cmpxchg(ptr, o, n)                                                \
+    ({                                                                         \
+        __typeof__(*(ptr)) o_ = (o);                                           \
+        __typeof__(*(ptr)) n_ = (n);                                           \
+        (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long) o_,              \
+                                       (unsigned long) n_, sizeof(*(ptr)));    \
+    })
+
+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
+{
+    return arch_cmpxchg(&v->counter, old, new);
+}
+
+#define ATOMIC_OP(op, insn, suffix, sign) \
+    static inline void atomic_##op(int a, atomic_t *v)                           \
+    {                                                                            \
+        int t;                                                                   \
+        asm volatile ( "1: lwarx %0,0,%3\n"                                      \
+                       insn "%I2" suffix " %0,%0,%2\n"                           \
+                       "stwcx. %0,0,%3 \n"                                       \
+                       "bne- 1b\n"                                               \
+                       : "=&r" (t), "+m" (v->counter)                            \
+                       : "r" #sign (a), "r" (&v->counter)                        \
+                       : "cc" );                                                 \
+    }
+
+ATOMIC_OP(and, "and", ".", K)
+
+static inline int atomic_sub_and_test(int i, atomic_t *v)
+{
+    return atomic_sub_return(i, v) == 0;
+}
+
+static inline int atomic_inc_and_test(atomic_t *v)
+{
+    return atomic_add_return(1, v) == 0;
+}
+
+static inline int atomic_dec_and_test(atomic_t *v)
+{
+    return atomic_sub_return(1, v) == 0;
+}
+
+static inline int atomic_add_negative(int i, atomic_t *v)
+{
+    return atomic_add_return(i, v) < 0;
+}
+
+static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+{
+	int c, old;
+
+	c = atomic_read(v);
+	while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c)
+		c = old;
+	return c;
+}
+
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+    return __atomic_add_unless(v, a, u);
+}
+
+#endif /* _ASM_PPC64_ATOMIC_H_ */
xen/arch/ppc/include/asm/memory.h new file +21 -0
new file mode 100644
index 0000000000..a159ba2d63
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) IBM Corp. 2005
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ */
+
+#ifndef _ASM_MEMORY_H_
+#define _ASM_MEMORY_H_
+
+#include <xen/config.h>
+
+#ifdef CONFIG_SMP
+#define PPC_ATOMIC_ENTRY_BARRIER "sync\n"
+#define PPC_ATOMIC_EXIT_BARRIER  "sync\n"
+#else
+#define PPC_ATOMIC_ENTRY_BARRIER
+#define PPC_ATOMIC_EXIT_BARRIER
+#endif
+
+#endif

--
2.30.2

#2 lore raw

Re: [PATCH v3 1/5] xen/ppc: Implement atomic.h

xen/arch/ppc/include/asm/atomic.h line 317

Quoted 5 lines · Shawn Anastasio
xen/arch/ppc/include/asm/atomic.h new file +5 -0
+static inline atomic_t atomic_compareandswap(atomic_t old, atomic_t new,
+                                             atomic_t *v)
+{
+    atomic_t rc;
+    rc.counter = __cmpxchg(&v->counter, old.counter, new.counter, sizeof(int));

I can't seem to be able to spot where __cmpxchg() is defined. (I really only wanted to check why it needs the 4th argument, which here rather would want to be e.g. sizeof(v->counter). If it can't be omitted.)

xen/arch/ppc/include/asm/atomic.h line 326

Quoted 9 lines
xen/arch/ppc/include/asm/atomic.h new file +9 -0
+    return rc;
+}
+
+#define arch_cmpxchg(ptr, o, n)                                                \
+    ({                                                                         \
+        __typeof__(*(ptr)) o_ = (o);                                           \
+        __typeof__(*(ptr)) n_ = (n);                                           \
+        (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long) o_,              \
+                                       (unsigned long) n_, sizeof(*(ptr)));    \

Nit: Stray blanks again after cast specifiers.

Quoted 4 lines
xen/arch/ppc/include/asm/memory.h new file +1 -0
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */

xen/arch/ppc/include/asm/memory.h line 11

Quoted 10 lines
xen/arch/ppc/include/asm/memory.h new file +10 -0
+/*
+ * Copyright (C) IBM Corp. 2005
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ */
+
+#ifndef _ASM_MEMORY_H_
+#define _ASM_MEMORY_H_
+
+#include <xen/config.h>

As mentioned before - no need for this explicit #include.

xen/arch/ppc/include/asm/memory.h line 19

Quoted 7 lines
xen/arch/ppc/include/asm/memory.h new file +7 -0
+#ifdef CONFIG_SMP
+#define PPC_ATOMIC_ENTRY_BARRIER "sync\n"
+#define PPC_ATOMIC_EXIT_BARRIER  "sync\n"
+#else
+#define PPC_ATOMIC_ENTRY_BARRIER
+#define PPC_ATOMIC_EXIT_BARRIER
+#endif

Is this correct, considering that we have no CONFIG_SMP and assume SMP in all cases?

I'm sorry for not paying attention earlier.

Jan

#3 lore raw

Re: [PATCH v3 1/5] xen/ppc: Implement atomic.h

Quoted 10 lines · Jan Beulich

xen/arch/ppc/include/asm/atomic.h line 317

Quoted 5 lines · Shawn Anastasio
xen/arch/ppc/include/asm/atomic.h new file +5 -0
+static inline atomic_t atomic_compareandswap(atomic_t old, atomic_t new,
+                                             atomic_t *v)
+{
+    atomic_t rc;
+    rc.counter = __cmpxchg(&v->counter, old.counter, new.counter, sizeof(int));

I can't seem to be able to spot where __cmpxchg() is defined. (I really only wanted to check why it needs the 4th argument, which here rather would want to be e.g. sizeof(v->counter). If it can't be omitted.)

Found it in patch 3, which suggests an incorrect split of patches. May not matter all that much of course if the headers aren't used before enough of the machinery is in place. But then such broken connections would be nice to mention in the description.

Jan

#4 lore raw

Re: [PATCH v3 1/5] xen/ppc: Implement atomic.h

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

xen/arch/ppc/include/asm/atomic.h line 317

Quoted 5 lines · Shawn Anastasio
xen/arch/ppc/include/asm/atomic.h new file +5 -0
+static inline atomic_t atomic_compareandswap(atomic_t old, atomic_t new,
+                                             atomic_t *v)
+{
+    atomic_t rc;
+    rc.counter = __cmpxchg(&v->counter, old.counter, new.counter, sizeof(int));

I can't seem to be able to spot where __cmpxchg() is defined. (I really only wanted to check why it needs the 4th argument, which here rather would want to be e.g. sizeof(v->counter). If it can't be omitted.)

As you later saw, it's defined in system.h later in patch 3. This was an error I made when splitting up the changes into this patchset. If you're fine with it I'll just add a mention in the commit message that the definitions in this commit are not yet fully usable.

Also I will change the size parameter to sizeof(v->counter) per your suggestion.

Quoted 12 lines

xen/arch/ppc/include/asm/atomic.h line 326

Quoted 9 lines
xen/arch/ppc/include/asm/atomic.h new file +9 -0
+    return rc;
+}
+
+#define arch_cmpxchg(ptr, o, n)                                                \
+    ({                                                                         \
+        __typeof__(*(ptr)) o_ = (o);                                           \
+        __typeof__(*(ptr)) n_ = (n);                                           \
+        (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long) o_,              \
+                                       (unsigned long) n_, sizeof(*(ptr)));    \

Nit: Stray blanks again after cast specifiers.

Will fix.

Quoted 8 lines
Quoted 8 lines
xen/arch/ppc/include/asm/memory.h new file +5 -0
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) IBM Corp. 2005
+ *
+ * Authors: Jimi Xenidis <[email protected]>
Quoted 9 lines

xen/arch/ppc/include/asm/memory.h line 11

Quoted 6 lines
xen/arch/ppc/include/asm/memory.h new file +6 -0
+ */
+
+#ifndef _ASM_MEMORY_H_
+#define _ASM_MEMORY_H_
+
+#include <xen/config.h>

As mentioned before - no need for this explicit #include.

Will drop.

Quoted 11 lines

xen/arch/ppc/include/asm/memory.h line 19

Quoted 7 lines
xen/arch/ppc/include/asm/memory.h new file +7 -0
+#ifdef CONFIG_SMP
+#define PPC_ATOMIC_ENTRY_BARRIER "sync\n"
+#define PPC_ATOMIC_EXIT_BARRIER  "sync\n"
+#else
+#define PPC_ATOMIC_ENTRY_BARRIER
+#define PPC_ATOMIC_EXIT_BARRIER
+#endif

Is this correct, considering that we have no CONFIG_SMP and assume SMP in all cases?

Quoted 2 lines

I'm sorry for not paying attention earlier.

Good observation, and no problem. I will remove the ifdef and the !SMP case.

Quoted 1 line

Jan

Thanks,
Shawn

#5 lore raw

Re: [PATCH v3 1/5] xen/ppc: Implement atomic.h

Quoted 13 lines · Shawn Anastasio
Quoted 11 lines · Jan Beulich

xen/arch/ppc/include/asm/atomic.h line 317

Quoted 5 lines · Shawn Anastasio
xen/arch/ppc/include/asm/atomic.h new file +5 -0
+static inline atomic_t atomic_compareandswap(atomic_t old, atomic_t new,
+                                             atomic_t *v)
+{
+    atomic_t rc;
+    rc.counter = __cmpxchg(&v->counter, old.counter, new.counter, sizeof(int));

I can't seem to be able to spot where __cmpxchg() is defined. (I really only wanted to check why it needs the 4th argument, which here rather would want to be e.g. sizeof(v->counter). If it can't be omitted.)

Quoted 4 lines

As you later saw, it's defined in system.h later in patch 3. This was an error I made when splitting up the changes into this patchset. If you're fine with it I'll just add a mention in the commit message that the definitions in this commit are not yet fully usable.

Sure, that's going to be okay.

Jan

#6 lore raw

PATCH v3 3/5 xen/ppc: Define minimal stub headers required for full build

In reply to Shawn Anastasio

Additionally, change inclusion of asm/ headers to corresponding xen/ ones throughout arch/ppc now that they work.

---
v3:
- Drop procarea.h
- Add SPDX headers to all headers touched or added by this patch
- (altp2m.h) Use ASSERT_UNREACHABLE for function that is meant to stay unimplemented
- (current.h) Consistently use plain C types in struct cpu_info
- (current.h) Fix formatting of inline asm in get_cpu_info()
- (device.h) Drop unnecessary DEVICE_GIC enumeration inherited from ARM
- (div64.h) Drop underscore-prefixed macro variables, fix formatting
- (domain.h) Drop unnecessary space after cast in guest_mode()
- (guest_access.h) Clean up line wrapping of functions w/ many parameters
- (guest_atomics.h) Avoid overly-long stub macros
- (grant_table.h) Add include guard + SPDX
- (hypercall.h) Add include guard + SPDX
- (mem_access.h) Add include guard + SPDX
- (mm.h) BUG_ON("unimplemented") for mfn_to_gfn/set_gpfn_from_mfn
- (mm.h) Define PDX_GROUP_SHIFT in terms of XEN_PT_SHIFT_LVL_3
- (monitor.h) BUG_ON("unimplemented") for arch_monitor_get_capabilities
- (system.h) Fix formatting of inline assembly + macros
- (time.h) Fix too-deep indentation

v2:
- Use BUG_ON("unimplemented") instead of BUG() for unimplemented functions to make searching easier.
- (altp2m.h) Drop Intel license in favor of an SPDX header
- (altp2m.h) Drop <xen/sched.h> include in favor of <xen/bug.h> and forward declarations of struct domain and struct vcpu.
- (bug.h) Add TODO comments above BUG and BUG_FRAME implementations
- (desc.h) Drop desc.h
- (mm.h) Drop <asm/config.h> include
- (mm.h) Drop PGC_static definition
- (mm.h) Drop max_page definition
- (mm.h/mm-radix.c) Drop total_pages definition
- (monitor.h) Drop <xen/sched.h> and <public/domctl.h> includes in favor of just <xen/errno.h>
- (page.h) Drop PAGE_ALIGN definition
- (percpu.h) Drop <xen/types.h> include
- (procarea.h) Drop license text in favor of SPDX header
- (procarea.h) Drop unnecessary forward declarations and <xen/types.h> include
- (processor.h) Fix macro parameter naming (drop leading underscore)
- (processor.h) Add explanation comment to cpu_relax()
- (regs.h) Drop stray hunk adding <xen/types.h> include
- (system.h) Drop license text in favor of SPDX header
- (system.h) Drop <xen/config.h> include
- (opal.c) Drop stray hunk changing opal.c includes

 xen/arch/ppc/Kconfig                     |   1 +
 xen/arch/ppc/include/asm/altp2m.h        |  25 +++
 xen/arch/ppc/include/asm/bug.h           |   9 +
 xen/arch/ppc/include/asm/cache.h         |   2 +
 xen/arch/ppc/include/asm/config.h        |  10 +
 xen/arch/ppc/include/asm/cpufeature.h    |  10 +
 xen/arch/ppc/include/asm/current.h       |  43 ++++
 xen/arch/ppc/include/asm/delay.h         |  12 ++
 xen/arch/ppc/include/asm/device.h        |  53 +++++
 xen/arch/ppc/include/asm/div64.h         |  14 ++
 xen/arch/ppc/include/asm/domain.h        |  47 +++++
 xen/arch/ppc/include/asm/event.h         |  36 ++++
 xen/arch/ppc/include/asm/flushtlb.h      |  24 +++
 xen/arch/ppc/include/asm/grant_table.h   |   5 +
 xen/arch/ppc/include/asm/guest_access.h  |  68 +++++++
 xen/arch/ppc/include/asm/guest_atomics.h |  23 +++
 xen/arch/ppc/include/asm/hardirq.h       |  19 ++
 xen/arch/ppc/include/asm/hypercall.h     |   5 +
 xen/arch/ppc/include/asm/io.h            |  16 ++
 xen/arch/ppc/include/asm/iocap.h         |   8 +
 xen/arch/ppc/include/asm/iommu.h         |   8 +
 xen/arch/ppc/include/asm/irq.h           |  33 +++
 xen/arch/ppc/include/asm/mem_access.h    |   5 +
 xen/arch/ppc/include/asm/mm.h            | 248 ++++++++++++++++++++++-
 xen/arch/ppc/include/asm/monitor.h       |  43 ++++
 xen/arch/ppc/include/asm/nospec.h        |  15 ++
 xen/arch/ppc/include/asm/numa.h          |  26 +++
 xen/arch/ppc/include/asm/p2m.h           | 105 ++++++++++
 xen/arch/ppc/include/asm/page.h          |  18 ++
 xen/arch/ppc/include/asm/paging.h        |   7 +
 xen/arch/ppc/include/asm/pci.h           |   7 +
 xen/arch/ppc/include/asm/percpu.h        |  24 +++
 xen/arch/ppc/include/asm/processor.h     |  10 +
 xen/arch/ppc/include/asm/random.h        |   9 +
 xen/arch/ppc/include/asm/setup.h         |   6 +
 xen/arch/ppc/include/asm/smp.h           |  18 ++
 xen/arch/ppc/include/asm/softirq.h       |   8 +
 xen/arch/ppc/include/asm/spinlock.h      |  15 ++
 xen/arch/ppc/include/asm/system.h        | 224 +++++++++++++++++++-
 xen/arch/ppc/include/asm/time.h          |  21 ++
 xen/arch/ppc/include/asm/vm_event.h      |  49 +++++
 xen/arch/ppc/include/asm/xenoprof.h      |   0
 xen/arch/ppc/mm-radix.c                  |   2 +-
 xen/arch/ppc/tlb-radix.c                 |   2 +-
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 47 files changed, 1335 insertions(+), 4 deletions(-)
 create mode 100644 xen/arch/ppc/include/asm/altp2m.h
 create mode 100644 xen/arch/ppc/include/asm/cpufeature.h
 create mode 100644 xen/arch/ppc/include/asm/current.h
 create mode 100644 xen/arch/ppc/include/asm/delay.h
 create mode 100644 xen/arch/ppc/include/asm/device.h
 create mode 100644 xen/arch/ppc/include/asm/div64.h
 create mode 100644 xen/arch/ppc/include/asm/domain.h
 create mode 100644 xen/arch/ppc/include/asm/event.h
 create mode 100644 xen/arch/ppc/include/asm/flushtlb.h
 create mode 100644 xen/arch/ppc/include/asm/grant_table.h
 create mode 100644 xen/arch/ppc/include/asm/guest_access.h
 create mode 100644 xen/arch/ppc/include/asm/guest_atomics.h
 create mode 100644 xen/arch/ppc/include/asm/hardirq.h
 create mode 100644 xen/arch/ppc/include/asm/hypercall.h
 create mode 100644 xen/arch/ppc/include/asm/io.h
 create mode 100644 xen/arch/ppc/include/asm/iocap.h
 create mode 100644 xen/arch/ppc/include/asm/iommu.h
 create mode 100644 xen/arch/ppc/include/asm/irq.h
 create mode 100644 xen/arch/ppc/include/asm/mem_access.h
 create mode 100644 xen/arch/ppc/include/asm/monitor.h
 create mode 100644 xen/arch/ppc/include/asm/nospec.h
 create mode 100644 xen/arch/ppc/include/asm/numa.h
 create mode 100644 xen/arch/ppc/include/asm/p2m.h
 create mode 100644 xen/arch/ppc/include/asm/paging.h
 create mode 100644 xen/arch/ppc/include/asm/pci.h
 create mode 100644 xen/arch/ppc/include/asm/percpu.h
 create mode 100644 xen/arch/ppc/include/asm/random.h
 create mode 100644 xen/arch/ppc/include/asm/setup.h
 create mode 100644 xen/arch/ppc/include/asm/smp.h
 create mode 100644 xen/arch/ppc/include/asm/softirq.h
 create mode 100644 xen/arch/ppc/include/asm/spinlock.h
 create mode 100644 xen/arch/ppc/include/asm/time.h
 create mode 100644 xen/arch/ppc/include/asm/vm_event.h
 create mode 100644 xen/arch/ppc/include/asm/xenoprof.h
xen/arch/ppc/Kconfig +1 -0
index ab116ffb2a..a6eae597af 100644
@@ -1,6 +1,7 @@
 config PPC
 	def_bool y
 	select HAS_DEVICE_TREE
+	select HAS_PDX
 
 config PPC64
 	def_bool y
xen/arch/ppc/include/asm/altp2m.h new file +25 -0
new file mode 100644
index 0000000000..bd5c9aa415
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_ALTP2M_H__
+#define __ASM_PPC_ALTP2M_H__
+
+#include <xen/bug.h>
+
+struct domain;
+struct vcpu;
+
+/* Alternate p2m on/off per domain */
+static inline bool altp2m_active(const struct domain *d)
+{
+    /* Not implemented on PPC. */
+    return false;
+}
+
+/* Alternate p2m VCPU */
+static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v)
+{
+    /* Not implemented on PPC, should not be reached. */
+    ASSERT_UNREACHABLE();
+    return 0;
+}
+
+#endif /* __ASM_PPC_ALTP2M_H__ */
xen/arch/ppc/include/asm/bug.h +9 -0
index e5e874b31c..35d4568402 100644
@@ -4,6 +4,7 @@
 #define _ASM_PPC_BUG_H
 
 #include <xen/stringify.h>
+#include <asm/processor.h>
 
 /*
  * Power ISA guarantees that an instruction consisting of all zeroes is
@@ -15,4 +16,12 @@
 
 #define BUG_FN_REG r0
 
+/* TODO: implement this properly */
+#define BUG() do { \
+    die(); \
+} while (0)
+
+/* TODO: implement this properly */
+#define BUG_FRAME(type, line, ptr, second_frame, msg) do { } while (0)
+
 #endif /* _ASM_PPC_BUG_H */
xen/arch/ppc/include/asm/cache.h +2 -0
index 8a0a6b7b17..0d7323d789 100644
@@ -3,4 +3,6 @@
 #ifndef _ASM_PPC_CACHE_H
 #define _ASM_PPC_CACHE_H
 
+#define __read_mostly __section(".data.read_mostly")
+
 #endif /* _ASM_PPC_CACHE_H */
xen/arch/ppc/include/asm/config.h +10 -0
index 30438d22d2..a11a09c570 100644
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef __PPC_CONFIG_H__
 #define __PPC_CONFIG_H__
 
@@ -41,6 +42,15 @@
 
 #define XEN_VIRT_START _AC(0xc000000000000000, UL)
 
+#define VMAP_VIRT_START (XEN_VIRT_START + GB(1))
+#define VMAP_VIRT_SIZE  GB(1)
+
+#define FRAMETABLE_VIRT_START  (XEN_VIRT_START + GB(32))
+#define FRAMETABLE_SIZE        GB(32)
+#define FRAMETABLE_NR          (FRAMETABLE_SIZE / sizeof(*frame_table))
+
+#define HYPERVISOR_VIRT_START  XEN_VIRT_START
+
 #define SMP_CACHE_BYTES (1 << 6)
 
 #define STACK_ORDER 0
xen/arch/ppc/include/asm/cpufeature.h new file +10 -0
new file mode 100644
index 0000000000..1c5946512b
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_CPUFEATURE_H__
+#define __ASM_PPC_CPUFEATURE_H__
+
+static inline int cpu_nr_siblings(unsigned int cpu)
+{
+    return 1;
+}
+
+#endif /* __ASM_PPC_CPUFEATURE_H__ */
xen/arch/ppc/include/asm/current.h new file +43 -0

43 lines not on this page · raw message

xen/arch/ppc/include/asm/delay.h new file +12 -0
new file mode 100644
index 0000000000..da6635888b
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_DELAY_H__
+#define __ASM_PPC_DELAY_H__
+
+#include <xen/lib.h>
+
+static inline void udelay(unsigned long usecs)
+{
+    BUG_ON("unimplemented");
+}
+
+#endif /* __ASM_PPC_DELAY_H__ */
xen/arch/ppc/include/asm/device.h new file +53 -0

53 lines not on this page · raw message

xen/arch/ppc/include/asm/div64.h new file +14 -0
new file mode 100644
index 0000000000..d213e50585
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_DIV64_H__
+#define __ASM_PPC_DIV64_H__
+
+#include <xen/types.h>
+
+#define do_div(n, base) ({                       \
+    uint32_t base_ = (base);                     \
+    uint32_t rem_ = (uint64_t)(n) % base_;       \
+    (n) = (uint64_t)(n) / base_;                 \
+    rem_;                                        \
+})
+
+#endif /* __ASM_PPC_DIV64_H__ */
xen/arch/ppc/include/asm/domain.h new file +47 -0

47 lines not on this page · raw message

xen/arch/ppc/include/asm/event.h new file +36 -0
new file mode 100644
index 0000000000..1b95ee4f61
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_EVENT_H__
+#define __ASM_PPC_EVENT_H__
+
+#include <xen/lib.h>
+
+/* TODO: implement */
+static inline void vcpu_kick(struct vcpu *v) { BUG_ON("unimplemented"); }
+static inline void vcpu_mark_events_pending(struct vcpu *v) { BUG_ON("unimplemented"); }
+static inline void vcpu_update_evtchn_irq(struct vcpu *v) { BUG_ON("unimplemented"); }
+static inline void vcpu_block_unless_event_pending(struct vcpu *v) { BUG_ON("unimplemented"); }
+
+static inline int vcpu_event_delivery_is_enabled(struct vcpu *v)
+{
+    BUG_ON("unimplemented");
+    return 0;
+}
+
+/* No arch specific virq definition now. Default to global. */
+static inline bool arch_virq_is_global(unsigned int virq)
+{
+    return true;
+}
+
+static inline int local_events_need_delivery(void)
+{
+    BUG_ON("unimplemented");
+    return 0;
+}
+
+static inline void local_event_delivery_enable(void)
+{
+    BUG_ON("unimplemented");
+}
+
+#endif /* __ASM_PPC_EVENT_H__ */
xen/arch/ppc/include/asm/flushtlb.h new file +24 -0
new file mode 100644
index 0000000000..afcb740783
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_FLUSHTLB_H__
+#define __ASM_PPC_FLUSHTLB_H__
+
+#include <xen/cpumask.h>
+
+/*
+ * Filter the given set of CPUs, removing those that definitely flushed their
+ * TLB since @page_timestamp.
+ */
+/* XXX lazy implementation just doesn't clear anything.... */
+static inline void tlbflush_filter(cpumask_t *mask, uint32_t page_timestamp) {}
+
+#define tlbflush_current_time()                 (0)
+
+static inline void page_set_tlbflush_timestamp(struct page_info *page)
+{
+    page->tlbflush_timestamp = tlbflush_current_time();
+}
+
+/* Flush specified CPUs' TLBs */
+void arch_flush_tlb_mask(const cpumask_t *mask);
+
+#endif /* __ASM_PPC_FLUSHTLB_H__ */
xen/arch/ppc/include/asm/grant_table.h new file +5 -0
new file mode 100644
index 0000000000..d0ff58dd3d
@@ -0,0 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_GRANT_TABLE_H__
+#define __ASM_PPC_GRANT_TABLE_H__
+
+#endif /* __ASM_PPC_GRANT_TABLE_H__ */
xen/arch/ppc/include/asm/guest_access.h new file +68 -0

68 lines not on this page · raw message

xen/arch/ppc/include/asm/guest_atomics.h new file +23 -0
new file mode 100644
index 0000000000..1190e10bbb
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_GUEST_ATOMICS_H__
+#define __ASM_PPC_GUEST_ATOMICS_H__
+
+#include <xen/lib.h>
+
+/* TODO: implement */
+#define unimplemented_guest_bit_op(d, nr, p) ({                                \
+    (void)(d);                                                                 \
+    (void)(nr);                                                                \
+    (void)(p);                                                                 \
+    BUG_ON("unimplemented");                                                   \
+    false;                                                                     \
+})
+
+#define guest_test_bit(d, nr, p)            unimplemented_guest_bit_op(d, nr, p)
+#define guest_clear_bit(d, nr, p)           unimplemented_guest_bit_op(d, nr, p)
+#define guest_set_bit(d, nr, p)             unimplemented_guest_bit_op(d, nr, p)
+#define guest_test_and_set_bit(d, nr, p)    unimplemented_guest_bit_op(d, nr, p)
+#define guest_test_and_clear_bit(d, nr, p)  unimplemented_guest_bit_op(d, nr, p)
+#define guest_test_and_change_bit(d, nr, p) unimplemented_guest_bit_op(d, nr, p)
+
+#endif /* __ASM_PPC_GUEST_ATOMICS_H__ */
xen/arch/ppc/include/asm/hardirq.h new file +19 -0
new file mode 100644
index 0000000000..343efc7e69
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_HARDIRQ_H__
+#define __ASM_PPC_HARDIRQ_H__
+
+#include <xen/cache.h>
+
+typedef struct {
+        unsigned long __softirq_pending;
+        unsigned int __local_irq_count;
+} __cacheline_aligned irq_cpustat_t;
+
+#include <xen/irq_cpustat.h>    /* Standard mappings for irq_cpustat_t above */
+
+#define in_irq() (local_irq_count(smp_processor_id()) != 0)
+
+#define irq_enter()     (local_irq_count(smp_processor_id())++)
+#define irq_exit()      (local_irq_count(smp_processor_id())--)
+
+#endif /* __ASM_PPC_HARDIRQ_H__ */
xen/arch/ppc/include/asm/hypercall.h new file +5 -0
new file mode 100644
index 0000000000..1e8ca0ce9c
@@ -0,0 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_HYPERCALL_H__
+#define __ASM_PPC_HYPERCALL_H__
+
+#endif /* __ASM_PPC_HYPERCALL_H__ */
xen/arch/ppc/include/asm/io.h new file +16 -0
new file mode 100644
index 0000000000..85b5b27157
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_IO_H__
+#define __ASM_PPC_IO_H__
+
+#include <xen/lib.h>
+
+/* TODO */
+#define readb(c)        ({ (void)(c); BUG_ON("unimplemented"); 0; })
+#define readw(c)        ({ (void)(c); BUG_ON("unimplemented"); 0; })
+#define readl(c)        ({ (void)(c); BUG_ON("unimplemented"); 0; })
+
+#define writeb(v,c)     ({ (void)(v); (void)(c); BUG_ON("unimplemented"); })
+#define writew(v,c)     ({ (void)(v); (void)(c); BUG_ON("unimplemented"); })
+#define writel(v,c)     ({ (void)(v); (void)(c); BUG_ON("unimplemented"); })
+
+#endif /* __ASM_PPC_IO_H__ */
xen/arch/ppc/include/asm/iocap.h new file +8 -0
new file mode 100644
index 0000000000..76bf13a70f
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_IOCAP_H__
+#define __ASM_PPC_IOCAP_H__
+
+#define cache_flush_permitted(d)                        \
+    (!rangeset_is_empty((d)->iomem_caps))
+
+#endif /* __ASM_PPC_IOCAP_H__ */
xen/arch/ppc/include/asm/iommu.h new file +8 -0
new file mode 100644
index 0000000000..024ead3473
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_IOMMU_H__
+#define __ASM_PPC_IOMMU_H__
+
+struct arch_iommu {
+};
+
+#endif /* __ASM_PPC_IOMMU_H__ */
xen/arch/ppc/include/asm/irq.h new file +33 -0
new file mode 100644
index 0000000000..5c37d0cf25
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_IRQ_H__
+#define __ASM_PPC_IRQ_H__
+
+#include <xen/lib.h>
+#include <xen/device_tree.h>
+#include <public/device_tree_defs.h>
+
+/* TODO */
+#define nr_irqs 0U
+#define nr_static_irqs 0
+#define arch_hwdom_irqs(domid) 0U
+
+#define domain_pirq_to_irq(d, pirq) (pirq)
+
+struct arch_pirq {
+};
+
+struct arch_irq_desc {
+    unsigned int type;
+};
+
+static inline void arch_move_irqs(struct vcpu *v)
+{
+    BUG_ON("unimplemented");
+}
+
+static inline int platform_get_irq(const struct dt_device_node *device, int index)
+{
+    BUG_ON("unimplemented");
+}
+
+#endif /* __ASM_PPC_IRQ_H__ */
xen/arch/ppc/include/asm/mem_access.h new file +5 -0
new file mode 100644
index 0000000000..e7986dfdbd
@@ -0,0 +1,5 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_MEM_ACCESS_H__
+#define __ASM_PPC_MEM_ACCESS_H__
+
+#endif /* __ASM_PPC_MEM_ACCESS_H__ */
xen/arch/ppc/include/asm/mm.h +247 -1

263 lines not on this page · raw message

xen/arch/ppc/include/asm/monitor.h new file +43 -0

43 lines not on this page · raw message

xen/arch/ppc/include/asm/nospec.h new file +15 -0
new file mode 100644
index 0000000000..b97322e48d
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* From arch/arm/include/asm/nospec.h. */
+#ifndef __ASM_PPC_NOSPEC_H__
+#define __ASM_PPC_NOSPEC_H__
+
+static inline bool evaluate_nospec(bool condition)
+{
+    return condition;
+}
+
+static inline void block_speculation(void)
+{
+}
+
+#endif /* __ASM_PPC_NOSPEC_H__ */
xen/arch/ppc/include/asm/numa.h new file +26 -0
new file mode 100644
index 0000000000..d857bba2ba
@@ -0,0 +1,26 @@
+#ifndef __ASM_PPC_NUMA_H__
+#define __ASM_PPC_NUMA_H__
+
+#include <xen/types.h>
+#include <xen/mm.h>
+
+typedef uint8_t nodeid_t;
+
+/* Fake one node for now. See also node_online_map. */
+#define cpu_to_node(cpu) 0
+#define node_to_cpumask(node)   (cpu_online_map)
+
+/*
+ * TODO: make first_valid_mfn static when NUMA is supported on Arm, this
+ * is required because the dummy helpers are using it.
+ */
+extern mfn_t first_valid_mfn;
+
+/* XXX: implement NUMA support */
+#define node_spanned_pages(nid) (max_page - mfn_x(first_valid_mfn))
+#define node_start_pfn(nid) (mfn_x(first_valid_mfn))
+#define __node_distance(a, b) (20)
+
+#define arch_want_default_dmazone() (false)
+
+#endif /* __ASM_PPC_NUMA_H__ */
xen/arch/ppc/include/asm/p2m.h new file +105 -0

105 lines not on this page · raw message

xen/arch/ppc/include/asm/page.h +18 -0
index 3c90e8bf19..7ede71e2fc 100644
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef _ASM_PPC_PAGE_H
 #define _ASM_PPC_PAGE_H
 
@@ -36,6 +37,9 @@
 #define PTE_XEN_RO   (PTE_XEN_BASE | PTE_EAA_READ)
 #define PTE_XEN_RX   (PTE_XEN_BASE | PTE_EAA_READ | PTE_EAA_EXECUTE)
 
+/* TODO */
+#define PAGE_HYPERVISOR 0
+
 /*
  * Radix Tree layout for 64KB pages:
  *
@@ -177,4 +181,18 @@ struct prtb_entry {
 
 void tlbie_all(void);
 
+static inline void invalidate_icache(void)
+{
+    BUG_ON("unimplemented");
+}
+
+#define clear_page(page) memset(page, 0, PAGE_SIZE)
+#define copy_page(dp, sp) memcpy(dp, sp, PAGE_SIZE)
+
+/* TODO: Flush the dcache for an entire page. */
+static inline void flush_page_to_ram(unsigned long mfn, bool sync_icache)
+{
+    BUG_ON("unimplemented");
+}
+
 #endif /* _ASM_PPC_PAGE_H */
xen/arch/ppc/include/asm/paging.h new file +7 -0
new file mode 100644
index 0000000000..eccacece29
@@ -0,0 +1,7 @@
+#ifndef __ASM_PPC_PAGING_H__
+#define __ASM_PPC_PAGING_H__
+
+#define paging_mode_translate(d)              (1)
+#define paging_mode_external(d)               (1)
+
+#endif /* __ASM_PPC_PAGING_H__ */
xen/arch/ppc/include/asm/pci.h new file +7 -0
new file mode 100644
index 0000000000..e76c8e5475
@@ -0,0 +1,7 @@
+#ifndef __ASM_PPC_PCI_H__
+#define __ASM_PPC_PCI_H__
+
+struct arch_pci_dev {
+};
+
+#endif /* __ASM_PPC_PCI_H__ */
xen/arch/ppc/include/asm/percpu.h new file +24 -0
new file mode 100644
index 0000000000..e7c40c0f03
@@ -0,0 +1,24 @@
+#ifndef __PPC_PERCPU_H__
+#define __PPC_PERCPU_H__
+
+#ifndef __ASSEMBLY__
+
+extern char __per_cpu_start[], __per_cpu_data_end[];
+extern unsigned long __per_cpu_offset[NR_CPUS];
+void percpu_init_areas(void);
+
+#define smp_processor_id() 0 /* TODO: Fix this */
+
+#define per_cpu(var, cpu)  \
+    (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]))
+#define this_cpu(var) \
+    (*RELOC_HIDE(&per_cpu__##var, smp_processor_id()))
+
+#define per_cpu_ptr(var, cpu)  \
+    (*RELOC_HIDE(var, __per_cpu_offset[cpu]))
+#define this_cpu_ptr(var) \
+    (*RELOC_HIDE(var, smp_processor_id()))
+
+#endif
+
+#endif /* __PPC_PERCPU_H__ */
xen/arch/ppc/include/asm/processor.h +10 -0
index 6b70569eb8..0e651d0aa9 100644
@@ -110,6 +110,10 @@
 /* Macro to adjust thread priority for hardware multithreading */
 #define HMT_very_low()  asm volatile ( "or %r31, %r31, %r31" )
 
+/* TODO: This isn't correct */
+#define cpu_to_core(cpu)   (0)
+#define cpu_to_socket(cpu) (0)
+
 /*
  * User-accessible registers: most of these need to be saved/restored
  * for every nested Xen invocation.
@@ -178,6 +182,12 @@ static inline void noreturn die(void)
         HMT_very_low();
 }
 
+/*
+ * Implemented on pre-POWER10 by setting HMT to low then to medium using
+ * the special OR forms. See HMT_very_low above.
+ */
+#define cpu_relax() asm volatile ( "or %r1, %r1, %r1; or %r2, %r2, %r2" )
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_PPC_PROCESSOR_H */
xen/arch/ppc/include/asm/random.h new file +9 -0
new file mode 100644
index 0000000000..2f9e9bbae4
@@ -0,0 +1,9 @@
+#ifndef __ASM_PPC_RANDOM_H__
+#define __ASM_PPC_RANDOM_H__
+
+static inline unsigned int arch_get_random(void)
+{
+    return 0;
+}
+
+#endif /* __ASM_PPC_RANDOM_H__ */
xen/arch/ppc/include/asm/setup.h new file +6 -0
new file mode 100644
index 0000000000..e4f64879b6
@@ -0,0 +1,6 @@
+#ifndef __ASM_PPC_SETUP_H__
+#define __ASM_PPC_SETUP_H__
+
+#define max_init_domid (0)
+
+#endif /* __ASM_PPC_SETUP_H__ */
xen/arch/ppc/include/asm/smp.h new file +18 -0
new file mode 100644
index 0000000000..eca43f0e6c
@@ -0,0 +1,18 @@
+#ifndef __ASM_SMP_H
+#define __ASM_SMP_H
+
+#include <xen/cpumask.h>
+#include <xen/percpu.h>
+
+DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask);
+DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask);
+
+#define cpu_is_offline(cpu) unlikely(!cpu_online(cpu))
+
+/*
+ * Do we, for platform reasons, need to actually keep CPUs online when we
+ * would otherwise prefer them to be off?
+ */
+#define park_offline_cpus false
+
+#endif
xen/arch/ppc/include/asm/softirq.h new file +8 -0
new file mode 100644
index 0000000000..a0b28a5e51
@@ -0,0 +1,8 @@
+#ifndef __ASM_PPC_SOFTIRQ_H__
+#define __ASM_PPC_SOFTIRQ_H__
+
+#define NR_ARCH_SOFTIRQS 0
+
+#define arch_skip_send_event_check(cpu) 0
+
+#endif /* __ASM_PPC_SOFTIRQ_H__ */
xen/arch/ppc/include/asm/spinlock.h new file +15 -0
new file mode 100644
index 0000000000..4bdb4b1e98
@@ -0,0 +1,15 @@
+#ifndef __ASM_SPINLOCK_H
+#define __ASM_SPINLOCK_H
+
+#define arch_lock_acquire_barrier() smp_mb()
+#define arch_lock_release_barrier() smp_mb()
+
+#define arch_lock_relax() cpu_relax()
+#define arch_lock_signal()
+#define arch_lock_signal_wmb()      \
+({                                  \
+    smp_wmb();                      \
+    arch_lock_signal();             \
+})
+
+#endif /* __ASM_SPINLOCK_H */
xen/arch/ppc/include/asm/system.h +223 -1

229 lines not on this page · raw message

xen/arch/ppc/include/asm/time.h new file +21 -0
new file mode 100644
index 0000000000..d47a6f9245
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_TIME_H__
+#define __ASM_PPC_TIME_H__
+
+#include <xen/lib.h>
+#include <asm/processor.h>
+#include <asm/regs.h>
+
+struct vcpu;
+
+/* TODO: implement */
+static inline void force_update_vcpu_system_time(struct vcpu *v) { BUG_ON("unimplemented"); }
+
+typedef unsigned long cycles_t;
+
+static inline cycles_t get_cycles(void)
+{
+    return mfspr(SPRN_TBRL);
+}
+
+#endif /* __ASM_PPC_TIME_H__ */
xen/arch/ppc/include/asm/vm_event.h new file +49 -0

49 lines not on this page · raw message

xen/arch/ppc/include/asm/xenoprof.h new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/ppc/mm-radix.c +1 -1
index 3feeb90ebc..06129cef9c 100644
@@ -1,13 +1,13 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 #include <xen/init.h>
 #include <xen/kernel.h>
+#include <xen/mm.h>
 #include <xen/types.h>
 #include <xen/lib.h>
 
 #include <asm/bitops.h>
 #include <asm/byteorder.h>
 #include <asm/early_printk.h>
-#include <asm/mm.h>
 #include <asm/page.h>
 #include <asm/processor.h>
 #include <asm/regs.h>
xen/arch/ppc/tlb-radix.c +1 -1
index 3dde102c62..74213113e0 100644
@@ -5,9 +5,9 @@
  *
  * Copyright 2015-2016, Aneesh Kumar K.V, IBM Corporation.
  */
+#include <xen/bitops.h>
 #include <xen/stringify.h>
 
-#include <asm/bitops.h>
 #include <asm/msr.h>
 #include <asm/processor.h>
 
xen/include/public/hvm/save.h +2 -0
index 464ebdb0da..2cf4238daa 100644
@@ -89,6 +89,8 @@ DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);
 #include "../arch-x86/hvm/save.h"
 #elif defined(__arm__) || defined(__aarch64__)
 #include "../arch-arm/hvm/save.h"
+#elif defined(__powerpc64__)
+#include "../arch-ppc.h"
 #else
 #error "unsupported architecture"
 #endif
xen/include/public/pmu.h +2 -0
index eb87a81e7b..5a176b6ac3 100644
@@ -11,6 +11,8 @@
 #include "arch-x86/pmu.h"
 #elif defined (__arm__) || defined (__aarch64__)
 #include "arch-arm.h"
+#elif defined (__powerpc64__)
+#include "arch-ppc.h"
 #else
 #error "Unsupported architecture"
 #endif
xen/include/public/xen.h +2 -0
index 920567e006..b812a0a324 100644
@@ -16,6 +16,8 @@
 #include "arch-x86/xen.h"
 #elif defined(__arm__) || defined (__aarch64__)
 #include "arch-arm.h"
+#elif defined(__powerpc64__)
+#include "arch-ppc.h"
 #else
 #error "Unsupported architecture"
 #endif

--
2.30.2

#7 lore raw

Re: [PATCH v3 3/5] xen/ppc: Define minimal stub headers required for full build

Quoted 37 lines · Shawn Anastasio
xen/arch/ppc/include/asm/device.h new file +34 -0
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_DEVICE_H__
+#define __ASM_PPC_DEVICE_H__
+
+enum device_type
+{
+    DEV_DT,
+    DEV_PCI,
+};
+
+struct device {
+    enum device_type type;
+#ifdef CONFIG_HAS_DEVICE_TREE
+    struct dt_device_node *of_node; /* Used by drivers imported from Linux */
+#endif
+};
+
+enum device_class
+{
+    DEVICE_SERIAL,
+    DEVICE_IOMMU,
+    DEVICE_PCI_HOSTBRIDGE,
+    /* Use for error */
+    DEVICE_UNKNOWN,
+};
+
+struct device_desc {
+    /* Device name */
+    const char *name;
+    /* Device class */
+    enum device_class class;
+    /* List of devices supported by this driver */
+    const struct dt_device_match *dt_match;
+    /*

xen/arch/ppc/include/asm/device.h line 44

Quoted 10 lines
xen/arch/ppc/include/asm/device.h new file +10 -0
+     * Device initialization.
+     *
+     * -EAGAIN is used to indicate that device probing is deferred.
+     */
+    int (*init)(struct dt_device_node *dev, const void *data);
+};
+
+typedef struct device device_t;
+
+#define DT_DEVICE_START(_name, _namestr, _class)                    \

Nit: Underscore-prefixed macro parameter names again.

Quoted 18 lines
xen/arch/ppc/include/asm/mm.h +8 -0
@@ -1,10 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef _ASM_PPC_MM_H
 #define _ASM_PPC_MM_H
 
+#include <public/xen.h>
+#include <xen/pdx.h>
+#include <xen/types.h>
+#include <asm/config.h>
 #include <asm/page-bits.h>
+#include <asm/page.h>
+
+void setup_initial_pagetables(void);
 
 #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
 #define paddr_to_pfn(pa)  ((unsigned long)((pa) >> PAGE_SHIFT))

xen/arch/ppc/include/asm/mm.h line 25

Quoted 10 lines
xen/arch/ppc/include/asm/mm.h +7 -0
+#define paddr_to_pdx(pa)    mfn_to_pdx(maddr_to_mfn(pa))
+#define gfn_to_gaddr(gfn)   pfn_to_paddr(gfn_x(gfn))
+#define gaddr_to_gfn(ga)    _gfn(paddr_to_pfn(ga))
+#define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
+#define maddr_to_mfn(ma)    _mfn(paddr_to_pfn(ma))
+#define vmap_to_mfn(va)     maddr_to_mfn(virt_to_maddr((vaddr_t)va))
+#define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
 
 #define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK))
 #define maddr_to_virt(pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START))

Is it intentional that the additions don't align, padding-wise, with the surrounding #define-s?

Quoted 13 lines
xen/arch/ppc/include/asm/mm.h +8 -1
@@ -13,6 +28,237 @@
 #define __pa(x)             (virt_to_maddr(x))
 #define __va(x)             (maddr_to_virt(x))
 
-void setup_initial_pagetables(void);
+/* Convert between Xen-heap virtual addresses and machine frame numbers. */
+#define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT)
+#define __mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
+
+/* Convert between Xen-heap virtual addresses and page-info structures. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    BUG_ON("unimplemented");

xen/arch/ppc/include/asm/mm.h line 48

Quoted 10 lines
xen/arch/ppc/include/asm/mm.h +10 -0
+    return NULL;
+}
+
+/*
+ * We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored version
+ * remain intact.
+ */
+#define virt_to_mfn(va)     __virt_to_mfn(va)
+#define mfn_to_virt(mfn)    __mfn_to_virt(mfn)

Is the comment really applicable? The only non-arch-specific file still doing so is xenoprof.c, and I'm not sure you mean to support xenoprof on PPC. PPC-specific files would better be introduced in a type-safe way right from the beginning.

Quoted 38 lines
xen/arch/ppc/include/asm/mm.h +38 -0
+#define PG_shift(idx)   (BITS_PER_LONG - (idx))
+#define PG_mask(x, idx) (x ## UL << PG_shift(idx))
+
+#define PGT_none          PG_mask(0, 1)  /* no special uses of this page   */
+#define PGT_writable_page PG_mask(1, 1)  /* has writable mappings?         */
+#define PGT_type_mask     PG_mask(1, 1)  /* Bits 31 or 63.                 */
+
+ /* 2-bit count of uses of this frame as its current type. */
+#define PGT_count_mask    PG_mask(3, 3)
+
+/* Cleared when the owning guest 'frees' this page. */
+#define _PGC_allocated    PG_shift(1)
+#define PGC_allocated     PG_mask(1, 1)
+/* Page is Xen heap? */
+#define _PGC_xen_heap     PG_shift(2)
+#define PGC_xen_heap      PG_mask(1, 2)
+/* Page is broken? */
+#define _PGC_broken       PG_shift(7)
+#define PGC_broken        PG_mask(1, 7)
+ /* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */
+#define PGC_state         PG_mask(3, 9)
+#define PGC_state_inuse   PG_mask(0, 9)
+#define PGC_state_offlining PG_mask(1, 9)
+#define PGC_state_offlined PG_mask(2, 9)
+#define PGC_state_free    PG_mask(3, 9)
+#define page_state_is(pg, st) (((pg)->count_info&PGC_state) == PGC_state_##st)
+/* Page is not reference counted */
+#define _PGC_extra        PG_shift(10)
+#define PGC_extra         PG_mask(1, 10)
+
+/* Count of references to this frame. */
+#define PGC_count_width   PG_shift(10)
+#define PGC_count_mask    ((1UL<<PGC_count_width)-1)
+
+/*
+ * Page needs to be scrubbed. Since this bit can only be set on a page that is
+ * free (i.e. in PGC_state_free) we can reuse PGC_allocated bit.
+ */

xen/arch/ppc/include/asm/mm.h line 97

Quoted 10 lines
xen/arch/ppc/include/asm/mm.h +10 -0
+#define _PGC_need_scrub   _PGC_allocated
+#define PGC_need_scrub    PGC_allocated
+
+#define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
+#define is_xen_heap_mfn(mfn) \
+    (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
+
+#define is_xen_fixed_mfn(mfn)                                   \
+    ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) &&           \
+     (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1)))

Please use (or, preferred, do not use) & and cast consistently on _start and _end.

Quoted 46 lines
xen/arch/ppc/include/asm/mm.h +46 -0
+#define page_get_owner(_p)    (_p)->v.inuse.domain
+#define page_set_owner(_p,_d) ((_p)->v.inuse.domain = (_d))
+
+/* TODO: implement */
+#define mfn_valid(mfn) ({ (void) (mfn); 0; })
+
+#define domain_set_alloc_bitsize(d) ((void)(d))
+#define domain_clamp_alloc_bitsize(d, b) (b)
+
+#define PFN_ORDER(pfn_) ((pfn_)->v.free.order)
+
+struct page_info
+{
+    /* Each frame can be threaded onto a doubly-linked list. */
+    struct page_list_entry list;
+
+    /* Reference count and various PGC_xxx flags and fields. */
+    unsigned long count_info;
+
+    /* Context-dependent fields follow... */
+    union {
+        /* Page is in use: ((count_info & PGC_count_mask) != 0). */
+        struct {
+            /* Type reference count and various PGT_xxx flags and fields. */
+            unsigned long type_info;
+        } inuse;
+        /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */
+        union {
+            struct {
+                /*
+                 * Index of the first *possibly* unscrubbed page in the buddy.
+                 * One more bit than maximum possible order to accommodate
+                 * INVALID_DIRTY_IDX.
+                 */
+#define INVALID_DIRTY_IDX ((1UL << (MAX_ORDER + 1)) - 1)
+                unsigned long first_dirty:MAX_ORDER + 1;
+
+                /* Do TLBs need flushing for safety before next page use? */
+                bool need_tlbflush:1;
+
+#define BUDDY_NOT_SCRUBBING    0
+#define BUDDY_SCRUBBING        1
+#define BUDDY_SCRUB_ABORT      2
+                unsigned long scrub_state:2;
+            };
+

xen/arch/ppc/include/asm/mm.h line 154

Quoted 10 lines
xen/arch/ppc/include/asm/mm.h +10 -0
+            unsigned long val;
+        } free;
+
+    } u;
+
+    union {
+        /* Page is in use, but not as a shadow. */
+        struct {
+            /* Owner of this page (zero if page is anonymous). */
+            struct domain *domain;

Since this is a pointer, NULL (instead of zero) would seem more appropriate in the comment.

Quoted 8 lines
xen/arch/ppc/include/asm/mm.h +8 -0
+        } inuse;
+
+        /* Page is on a free list. */
+        struct {
+            /* Order-size of the free chunk this page is the head of. */
+            unsigned int order;
+        } free;
+

xen/arch/ppc/include/asm/mm.h line 172

Quoted 10 lines
xen/arch/ppc/include/asm/mm.h +10 -0
+    } v;
+
+    union {
+        /*
+         * Timestamp from 'TLB clock', used to avoid extra safety flushes.
+         * Only valid for: a) free pages, and b) pages with zero type count
+         */
+        u32 tlbflush_timestamp;
+    };
+    u64 pad;

uint<N>_t please (or unsigned int/long).

Quoted 36 lines
xen/arch/ppc/include/asm/monitor.h new file +33 -0
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Derived from xen/arch/arm/include/asm/monitor.h */
+#ifndef __ASM_PPC_MONITOR_H__
+#define __ASM_PPC_MONITOR_H__
+
+#include <public/domctl.h>
+#include <xen/errno.h>
+
+static inline
+void arch_monitor_allow_userspace(struct domain *d, bool allow_userspace)
+{
+}
+
+static inline
+int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
+{
+    /* No arch-specific monitor ops on PPC. */
+    return -EOPNOTSUPP;
+}
+
+int arch_monitor_domctl_event(struct domain *d,
+                              struct xen_domctl_monitor_op *mop);
+
+static inline
+int arch_monitor_init_domain(struct domain *d)
+{
+    /* No arch-specific domain initialization on PPC. */
+    return 0;
+}
+
+static inline
+void arch_monitor_cleanup_domain(struct domain *d)
+{

xen/arch/ppc/include/asm/monitor.h line 43

Quoted 10 lines
xen/arch/ppc/include/asm/monitor.h new file +10 -0
+    /* No arch-specific domain cleanup on PPC. */
+}
+
+static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
+{
+    BUG_ON("unimplemented");
+    return 0;
+}
+
+#endif /* __ASM_PPC_MONITOR_H__ */

From a formal perspective you'll need Tamas's ack for this file, so you may want to Cc him. (Also for vm_event.h, unless the generic solution there doesn't land first.)

Quoted 14 lines
xen/arch/ppc/include/asm/p2m.h new file +11 -0
@@ -0,0 +1,105 @@
+#ifndef __ASM_PPC_P2M_H__
+#define __ASM_PPC_P2M_H__
+
+#include <asm/page-bits.h>
+
+#define paddr_bits PADDR_BITS
+
+/*
+ * List of possible type for each page in the p2m entry.
+ * The number of available bit per page in the pte for this purpose is 4 bits.
+ * So it's possible to only have 16 fields. If we run out of value in the

xen/arch/ppc/include/asm/p2m.h line 21

Quoted 10 lines
xen/arch/ppc/include/asm/p2m.h new file +10 -0
+ * future, it's possible to use higher value for pseudo-type and don't store
+ * them in the p2m entry.
+ */
+typedef enum {
+    p2m_invalid = 0,    /* Nothing mapped here */
+    p2m_ram_rw,         /* Normal read/write guest RAM */
+    p2m_ram_ro,         /* Read-only; writes are silently dropped */
+    p2m_mmio_direct_dev,/* Read/write mapping of genuine Device MMIO area */
+    p2m_mmio_direct_nc, /* Read/write mapping of genuine MMIO area non-cacheable */
+    p2m_mmio_direct_c,  /* Read/write mapping of genuine MMIO area cacheable */

Didn't you agree to drop at least what's clear Arm-specific?

Quoted 15 lines
xen/arch/ppc/include/asm/system.h +9 -0
@@ -1,6 +1,228 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) IBM Corp. 2005
+ * Copyright (C) Raptor Engineering LLC
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ *          Shawn Anastasio <[email protected]>
+ */
+
 #ifndef _ASM_SYSTEM_H_
 #define _ASM_SYSTEM_H_
 

xen/arch/ppc/include/asm/system.h line 21

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +9 -1
-#define smp_wmb() __asm__ __volatile__ ( "lwsync" : : : "memory" )
+#include <xen/lib.h>
+#include <asm/memory.h>
+#include <asm/time.h>
+#include <asm/processor.h>
+#include <asm/msr.h>
+
+#define xchg(ptr,x) 							                               \
+({									                                           \
+	__typeof__(*(ptr)) _x_ = (x);					                           \

Hard tabs look to have slipped in here.

Quoted 25 lines
xen/arch/ppc/include/asm/system.h +25 -0
+	(__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr)));    \
+})
+
+#define build_xchg(fn, type, ldinsn, stinsn) \
+static inline unsigned long fn(volatile type *m, unsigned long val)            \
+{                                                                              \
+    unsigned long dummy;                                                       \
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER                                    \
+                   "1: " ldinsn " %0,0,%3\n"                                   \
+                   stinsn " %2,0,%3\n"                                         \
+                   "2:  bne- 1b"                                               \
+                   PPC_ATOMIC_EXIT_BARRIER                                     \
+                   : "=&r" (dummy), "=m" (*m)                                  \
+                   : "r" (val), "r" (m)                                        \
+                   : "cc", "memory" );                                         \
+    return dummy;                                                              \
+}
+
+build_xchg(__xchg_u8, uint8_t, "lbarx", "stbcx.")
+build_xchg(__xchg_u16, uint16_t, "lharx", "sthcx.")
+build_xchg(__xchg_u32, uint32_t, "lwarx", "stwcx.")
+build_xchg(__xchg_u64, uint64_t, "ldarx", "stdcx.")
+
+#undef build_xchg
+

xen/arch/ppc/include/asm/system.h line 56

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +10 -0
+/*
+ * This function doesn't exist, so you'll get a linker error
+ * if something tries to do an invalid xchg().
+ */
+extern void __xchg_called_with_bad_pointer(void);
+
+static inline unsigned long __xchg(volatile void *ptr, unsigned long x,
+                                   int size)
+{
+    switch (size) {

Nit: Since the file looks like it wants to use Xen style:

switch ( size )
{

please.

Quoted 73 lines
xen/arch/ppc/include/asm/system.h +73 -0
+    case 1:
+        return __xchg_u8(ptr, x);
+    case 2:
+        return __xchg_u16(ptr, x);
+    case 4:
+        return __xchg_u32(ptr, x);
+    case 8:
+        return __xchg_u64(ptr, x);
+    }
+    __xchg_called_with_bad_pointer();
+    return x;
+}
+
+
+static inline unsigned long __cmpxchg_u32(volatile int *p, int old, int new)
+{
+    unsigned int prev;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: lwarx   %0,0,%2\n"
+                   "cmpw    0,%0,%3\n"
+                   "bne-    2f\n "
+                   "stwcx.  %4,0,%2\n"
+                   "bne-    1b\n"
+                   PPC_ATOMIC_EXIT_BARRIER "\n"
+                   "2:"
+                   : "=&r" (prev), "=m" (*p)
+                   : "r" (p), "r" (old), "r" (new), "m" (*p)
+                   : "cc", "memory" );
+
+    return prev;
+}
+
+static inline unsigned long __cmpxchg_u64(volatile long *p, unsigned long old,
+                                          unsigned long new)
+{
+    unsigned long prev;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: ldarx   %0,0,%2\n"
+                   "cmpd    0,%0,%3\n"
+                   "bne-    2f\n"
+                   "stdcx.  %4,0,%2\n"
+                   "bne-    1b"
+                   PPC_ATOMIC_EXIT_BARRIER "\n"
+                   "2:"
+                   : "=&r" (prev), "=m" (*p)
+                   : "r" (p), "r" (old), "r" (new), "m" (*p)
+                   : "cc", "memory" );
+
+    return prev;
+}
+
+/* This function doesn't exist, so you'll get a linker error
+   if something tries to do an invalid cmpxchg().  */
+extern void __cmpxchg_called_with_bad_pointer(void);
+
+static always_inline unsigned long __cmpxchg(
+    volatile void *ptr,
+    unsigned long old,
+    unsigned long new,
+    int size)
+{
+    switch (size) {
+    case 2:
+        BUG_ON("unimplemented"); return 0; /* XXX implement __cmpxchg_u16 ? */
+    case 4:
+        return __cmpxchg_u32(ptr, old, new);
+    case 8:
+        return __cmpxchg_u64(ptr, old, new);
+    }
+    __cmpxchg_called_with_bad_pointer();
+    return old;

xen/arch/ppc/include/asm/system.h line 139

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +10 -0
+}
+
+#define cmpxchg_user(ptr,o,n) cmpxchg(ptr,o,n)
+
+#define cmpxchg(ptr,o,n)                         \
+  ({                                     \
+     __typeof__(*(ptr)) _o_ = (o);                   \
+     __typeof__(*(ptr)) _n_ = (n);                   \
+     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,       \
+                    (unsigned long)_n_, sizeof(*(ptr))); \

Not: Style (multiple previously mentioned issues).

Quoted 18 lines
xen/arch/ppc/include/asm/system.h +18 -0
+  })
+
+
+/*
+ * Memory barrier.
+ * The sync instruction guarantees that all memory accesses initiated
+ * by this processor have been performed (with respect to all other
+ * mechanisms that access memory).  The eieio instruction is a barrier
+ * providing an ordering (separately) for (a) cacheable stores and (b)
+ * loads and stores to non-cacheable memory (e.g. I/O devices).
+ *
+ * mb() prevents loads and stores being reordered across this point.
+ * rmb() prevents loads being reordered across this point.
+ * wmb() prevents stores being reordered across this point.
+ * read_barrier_depends() prevents data-dependent loads being reordered
+ *  across this point (nop on PPC).
+ *
+ * We have to use the sync instructions for mb(), since lwsync doesn't

xen/arch/ppc/include/asm/system.h line 167

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +10 -0
+ * order loads with respect to previous stores.  Lwsync is fine for
+ * rmb(), though.
+ * For wmb(), we use sync since wmb is used in drivers to order
+ * stores to system memory with respect to writes to the device.
+ * However, smp_wmb() can be a lighter-weight eieio barrier on
+ * SMP since it is only used to order updates to system memory.
+ */
+#define mb()   __asm__ __volatile__ ("sync" : : : "memory")
+#define rmb()  __asm__ __volatile__ ("lwsync" : : : "memory")
+#define wmb()  __asm__ __volatile__ ("sync" : : : "memory")

Nit: Missing blanks.

Quoted 7 lines
xen/arch/ppc/include/asm/system.h +7 -0
+#define read_barrier_depends()  do { } while(0)
+
+#define set_mb(var, value)  do { var = value; smp_mb(); } while (0)
+#define set_wmb(var, value) do { var = value; smp_wmb(); } while (0)
+
+#define smp_mb__before_atomic()    smp_mb()
+#define smp_mb__after_atomic()     smp_mb()

xen/arch/ppc/include/asm/system.h line 184

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +10 -0
+
+#ifdef CONFIG_SMP
+#define smp_mb()    mb()
+#define smp_rmb()   rmb()
+#define smp_wmb()   __asm__ __volatile__ ("lwsync" : : : "memory")
+#define smp_read_barrier_depends()  read_barrier_depends()
+#else
+#define smp_mb()    __asm__ __volatile__("": : :"memory")
+#define smp_rmb()   __asm__ __volatile__("": : :"memory")
+#define smp_wmb()   __asm__ __volatile__("": : :"memory")

And more missing blanks (further below from here).

Quoted 5 lines
xen/arch/ppc/include/asm/system.h +5 -0
+#define smp_read_barrier_depends()  do { } while(0)
+#endif /* CONFIG_SMP */
+
+#define local_save_flags(flags) ((flags) = mfmsr())
+#define local_irq_restore(flags) do { \

xen/arch/ppc/include/asm/system.h line 199

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +10 -0
+        __asm__ __volatile__("": : :"memory"); \
+        mtmsrd((flags)); \
+} while(0)
+
+static inline void local_irq_disable(void)
+{
+    unsigned long msr;
+    msr = mfmsr();
+    mtmsrd(msr & ~MSR_EE);
+    asm volatile ( "" : : : "memory" );

That's simply barrier(), isn't it? Please avoid open-coding. (More further down.)

Quoted 5 lines
xen/arch/ppc/include/asm/time.h new file +2 -0
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_TIME_H__

xen/arch/ppc/include/asm/time.h line 12

Quoted 10 lines
xen/arch/ppc/include/asm/time.h new file +10 -0
+#define __ASM_PPC_TIME_H__
+
+#include <xen/lib.h>
+#include <asm/processor.h>
+#include <asm/regs.h>
+
+struct vcpu;
+
+/* TODO: implement */
+static inline void force_update_vcpu_system_time(struct vcpu *v) { BUG_ON("unimplemented"); }

Nit: Too long line.

Jan

#8 lore raw

Re: [PATCH v3 3/5] xen/ppc: Define minimal stub headers required for full build

Quoted 42 lines · Jan Beulich
Quoted 41 lines · Shawn Anastasio
xen/arch/ppc/include/asm/device.h new file +38 -0
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_DEVICE_H__
+#define __ASM_PPC_DEVICE_H__
+
+enum device_type
+{
+    DEV_DT,
+    DEV_PCI,
+};
+
+struct device {
+    enum device_type type;
+#ifdef CONFIG_HAS_DEVICE_TREE
+    struct dt_device_node *of_node; /* Used by drivers imported from Linux */
+#endif
+};
+
+enum device_class
+{
+    DEVICE_SERIAL,
+    DEVICE_IOMMU,
+    DEVICE_PCI_HOSTBRIDGE,
+    /* Use for error */
+    DEVICE_UNKNOWN,
+};
+
+struct device_desc {
+    /* Device name */
+    const char *name;
+    /* Device class */
+    enum device_class class;
+    /* List of devices supported by this driver */
+    const struct dt_device_match *dt_match;
+    /*
+     * Device initialization.
+     *
+     * -EAGAIN is used to indicate that device probing is deferred.
+     */
Quoted 9 lines

xen/arch/ppc/include/asm/device.h line 44

Quoted 6 lines
xen/arch/ppc/include/asm/device.h new file +6 -0
+    int (*init)(struct dt_device_node *dev, const void *data);
+};
+
+typedef struct device device_t;
+
+#define DT_DEVICE_START(_name, _namestr, _class)                    \

Nit: Underscore-prefixed macro parameter names again.

Will fix.

Quoted 26 lines
Quoted 26 lines
xen/arch/ppc/include/asm/mm.h +15 -0
@@ -1,10 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 #ifndef _ASM_PPC_MM_H
 #define _ASM_PPC_MM_H
 
+#include <public/xen.h>
+#include <xen/pdx.h>
+#include <xen/types.h>
+#include <asm/config.h>
 #include <asm/page-bits.h>
+#include <asm/page.h>
+
+void setup_initial_pagetables(void);
 
 #define pfn_to_paddr(pfn) ((paddr_t)(pfn) << PAGE_SHIFT)
 #define paddr_to_pfn(pa)  ((unsigned long)((pa) >> PAGE_SHIFT))
+#define paddr_to_pdx(pa)    mfn_to_pdx(maddr_to_mfn(pa))
+#define gfn_to_gaddr(gfn)   pfn_to_paddr(gfn_x(gfn))
+#define gaddr_to_gfn(ga)    _gfn(paddr_to_pfn(ga))
+#define mfn_to_maddr(mfn)   pfn_to_paddr(mfn_x(mfn))
+#define maddr_to_mfn(ma)    _mfn(paddr_to_pfn(ma))
+#define vmap_to_mfn(va)     maddr_to_mfn(virt_to_maddr((vaddr_t)va))
+#define vmap_to_page(va)    mfn_to_page(vmap_to_mfn(va))
 
Quoted 6 lines

xen/arch/ppc/include/asm/mm.h line 25

Quoted 2 lines
xen/arch/ppc/include/asm/mm.h +0 -0
 #define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK))
 #define maddr_to_virt(pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START))

Is it intentional that the additions don't align, padding-wise, with the surrounding #define-s?

No -- good catch. I'll adjust the padding to line up properly.

Quoted 20 lines
Quoted 20 lines
xen/arch/ppc/include/asm/mm.h +15 -1
@@ -13,6 +28,237 @@
 #define __pa(x)             (virt_to_maddr(x))
 #define __va(x)             (maddr_to_virt(x))
 
-void setup_initial_pagetables(void);
+/* Convert between Xen-heap virtual addresses and machine frame numbers. */
+#define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT)
+#define __mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
+
+/* Convert between Xen-heap virtual addresses and page-info structures. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
+/*
+ * We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored version
+ * remain intact.
Quoted 9 lines

xen/arch/ppc/include/asm/mm.h line 48

Quoted 3 lines
xen/arch/ppc/include/asm/mm.h +3 -0
+ */
+#define virt_to_mfn(va)     __virt_to_mfn(va)
+#define mfn_to_virt(mfn)    __mfn_to_virt(mfn)

Is the comment really applicable? The only non-arch-specific file still doing so is xenoprof.c, and I'm not sure you mean to support xenoprof on PPC. PPC-specific files would better be introduced in a type-safe way right from the beginning.

To be clear, you're suggesting that I define virt_to_mfn and mfn_to_virt to operate on the type-safe mfn_t wrapper? When doing this, xen/include/xen/domain_page.h:63 fails to build, since it seems to assume that these macros do not use the type-safe mfn_t:

  static inline void *map_domain_page_global(mfn_t mfn)
  {
      return mfn_to_virt(mfn_x(mfn));
  }

If the comment is no longer accurate I can drop it, but there definitely seems to be an assumption in the codebase that these macros operate on raw unsigned longs rather than mfn_t.

Quoted 43 lines
Quoted 43 lines
xen/arch/ppc/include/asm/mm.h +43 -0
+#define PG_shift(idx)   (BITS_PER_LONG - (idx))
+#define PG_mask(x, idx) (x ## UL << PG_shift(idx))
+
+#define PGT_none          PG_mask(0, 1)  /* no special uses of this page   */
+#define PGT_writable_page PG_mask(1, 1)  /* has writable mappings?         */
+#define PGT_type_mask     PG_mask(1, 1)  /* Bits 31 or 63.                 */
+
+ /* 2-bit count of uses of this frame as its current type. */
+#define PGT_count_mask    PG_mask(3, 3)
+
+/* Cleared when the owning guest 'frees' this page. */
+#define _PGC_allocated    PG_shift(1)
+#define PGC_allocated     PG_mask(1, 1)
+/* Page is Xen heap? */
+#define _PGC_xen_heap     PG_shift(2)
+#define PGC_xen_heap      PG_mask(1, 2)
+/* Page is broken? */
+#define _PGC_broken       PG_shift(7)
+#define PGC_broken        PG_mask(1, 7)
+ /* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */
+#define PGC_state         PG_mask(3, 9)
+#define PGC_state_inuse   PG_mask(0, 9)
+#define PGC_state_offlining PG_mask(1, 9)
+#define PGC_state_offlined PG_mask(2, 9)
+#define PGC_state_free    PG_mask(3, 9)
+#define page_state_is(pg, st) (((pg)->count_info&PGC_state) == PGC_state_##st)
+/* Page is not reference counted */
+#define _PGC_extra        PG_shift(10)
+#define PGC_extra         PG_mask(1, 10)
+
+/* Count of references to this frame. */
+#define PGC_count_width   PG_shift(10)
+#define PGC_count_mask    ((1UL<<PGC_count_width)-1)
+
+/*
+ * Page needs to be scrubbed. Since this bit can only be set on a page that is
+ * free (i.e. in PGC_state_free) we can reuse PGC_allocated bit.
+ */
+#define _PGC_need_scrub   _PGC_allocated
+#define PGC_need_scrub    PGC_allocated
+
+#define is_xen_heap_page(page) ((page)->count_info & PGC_xen_heap)
+#define is_xen_heap_mfn(mfn) \
Quoted 9 lines

xen/arch/ppc/include/asm/mm.h line 97

Quoted 5 lines
xen/arch/ppc/include/asm/mm.h +5 -0
+    (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
+
+#define is_xen_fixed_mfn(mfn)                                   \
+    ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) &&           \
+     (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1)))

Please use (or, preferred, do not use) & and cast consistently on _start and _end.

Will fix.

Quoted 51 lines
Quoted 51 lines
xen/arch/ppc/include/asm/mm.h +51 -0
+#define page_get_owner(_p)    (_p)->v.inuse.domain
+#define page_set_owner(_p,_d) ((_p)->v.inuse.domain = (_d))
+
+/* TODO: implement */
+#define mfn_valid(mfn) ({ (void) (mfn); 0; })
+
+#define domain_set_alloc_bitsize(d) ((void)(d))
+#define domain_clamp_alloc_bitsize(d, b) (b)
+
+#define PFN_ORDER(pfn_) ((pfn_)->v.free.order)
+
+struct page_info
+{
+    /* Each frame can be threaded onto a doubly-linked list. */
+    struct page_list_entry list;
+
+    /* Reference count and various PGC_xxx flags and fields. */
+    unsigned long count_info;
+
+    /* Context-dependent fields follow... */
+    union {
+        /* Page is in use: ((count_info & PGC_count_mask) != 0). */
+        struct {
+            /* Type reference count and various PGT_xxx flags and fields. */
+            unsigned long type_info;
+        } inuse;
+        /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */
+        union {
+            struct {
+                /*
+                 * Index of the first *possibly* unscrubbed page in the buddy.
+                 * One more bit than maximum possible order to accommodate
+                 * INVALID_DIRTY_IDX.
+                 */
+#define INVALID_DIRTY_IDX ((1UL << (MAX_ORDER + 1)) - 1)
+                unsigned long first_dirty:MAX_ORDER + 1;
+
+                /* Do TLBs need flushing for safety before next page use? */
+                bool need_tlbflush:1;
+
+#define BUDDY_NOT_SCRUBBING    0
+#define BUDDY_SCRUBBING        1
+#define BUDDY_SCRUB_ABORT      2
+                unsigned long scrub_state:2;
+            };
+
+            unsigned long val;
+        } free;
+
+    } u;
+
Quoted 9 lines

xen/arch/ppc/include/asm/mm.h line 154

Quoted 5 lines
xen/arch/ppc/include/asm/mm.h +5 -0
+    union {
+        /* Page is in use, but not as a shadow. */
+        struct {
+            /* Owner of this page (zero if page is anonymous). */
+            struct domain *domain;

Since this is a pointer, NULL (instead of zero) would seem more appropriate in the comment.

Will update comment.

Quoted 12 lines
Quoted 12 lines
xen/arch/ppc/include/asm/mm.h +12 -0
+        } inuse;
+
+        /* Page is on a free list. */
+        struct {
+            /* Order-size of the free chunk this page is the head of. */
+            unsigned int order;
+        } free;
+
+    } v;
+
+    union {
+        /*
Quoted 9 lines

xen/arch/ppc/include/asm/mm.h line 172

Quoted 6 lines
xen/arch/ppc/include/asm/mm.h +6 -0
+         * Timestamp from 'TLB clock', used to avoid extra safety flushes.
+         * Only valid for: a) free pages, and b) pages with zero type count
+         */
+        u32 tlbflush_timestamp;
+    };
+    u64 pad;

uint<N>_t please (or unsigned int/long).

Will use uint<N>_t.

Quoted 47 lines
Quoted 46 lines
xen/arch/ppc/include/asm/monitor.h new file +43 -0
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Derived from xen/arch/arm/include/asm/monitor.h */
+#ifndef __ASM_PPC_MONITOR_H__
+#define __ASM_PPC_MONITOR_H__
+
+#include <public/domctl.h>
+#include <xen/errno.h>
+
+static inline
+void arch_monitor_allow_userspace(struct domain *d, bool allow_userspace)
+{
+}
+
+static inline
+int arch_monitor_domctl_op(struct domain *d, struct xen_domctl_monitor_op *mop)
+{
+    /* No arch-specific monitor ops on PPC. */
+    return -EOPNOTSUPP;
+}
+
+int arch_monitor_domctl_event(struct domain *d,
+                              struct xen_domctl_monitor_op *mop);
+
+static inline
+int arch_monitor_init_domain(struct domain *d)
+{
+    /* No arch-specific domain initialization on PPC. */
+    return 0;
+}
+
+static inline
+void arch_monitor_cleanup_domain(struct domain *d)
+{
+    /* No arch-specific domain cleanup on PPC. */
+}
+
+static inline uint32_t arch_monitor_get_capabilities(struct domain *d)
+{
+    BUG_ON("unimplemented");
+    return 0;
+}
+
+#endif /* __ASM_PPC_MONITOR_H__ */
Quoted 4 lines
Quoted 1 line

From a formal perspective you'll need Tamas's ack for this file, so you

may want to Cc him. (Also for vm_event.h, unless the generic solution there doesn't land first.)

My apologies, meant to CC him but forgot. Will do for next version of series.

Quoted 18 lines
Quoted 18 lines
xen/arch/ppc/include/asm/p2m.h new file +15 -0
@@ -0,0 +1,105 @@
+#ifndef __ASM_PPC_P2M_H__
+#define __ASM_PPC_P2M_H__
+
+#include <asm/page-bits.h>
+
+#define paddr_bits PADDR_BITS
+
+/*
+ * List of possible type for each page in the p2m entry.
+ * The number of available bit per page in the pte for this purpose is 4 bits.
+ * So it's possible to only have 16 fields. If we run out of value in the
+ * future, it's possible to use higher value for pseudo-type and don't store
+ * them in the p2m entry.
+ */
+typedef enum {
Quoted 9 lines

xen/arch/ppc/include/asm/p2m.h line 21

Quoted 6 lines
xen/arch/ppc/include/asm/p2m.h new file +6 -0
+    p2m_invalid = 0,    /* Nothing mapped here */
+    p2m_ram_rw,         /* Normal read/write guest RAM */
+    p2m_ram_ro,         /* Read-only; writes are silently dropped */
+    p2m_mmio_direct_dev,/* Read/write mapping of genuine Device MMIO area */
+    p2m_mmio_direct_nc, /* Read/write mapping of genuine MMIO area non-cacheable */
+    p2m_mmio_direct_c,  /* Read/write mapping of genuine MMIO area cacheable */

Didn't you agree to drop at least what's clear Arm-specific?

Yes -- that was an oversight. Will fix.

Quoted 15 lines
Quoted 15 lines
xen/arch/ppc/include/asm/system.h +9 -0
@@ -1,6 +1,228 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) IBM Corp. 2005
+ * Copyright (C) Raptor Engineering LLC
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ *          Shawn Anastasio <[email protected]>
+ */
+
 #ifndef _ASM_SYSTEM_H_
 #define _ASM_SYSTEM_H_
 
Quoted 13 lines

xen/arch/ppc/include/asm/system.h line 21

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +9 -1
-#define smp_wmb() __asm__ __volatile__ ( "lwsync" : : : "memory" )
+#include <xen/lib.h>
+#include <asm/memory.h>
+#include <asm/time.h>
+#include <asm/processor.h>
+#include <asm/msr.h>
+
+#define xchg(ptr,x) 							                               \
+({									                                           \
+	__typeof__(*(ptr)) _x_ = (x);					                           \

Hard tabs look to have slipped in here.

Good eye. Will fix.

Quoted 38 lines
Quoted 25 lines
xen/arch/ppc/include/asm/system.h +25 -0
+	(__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr)));    \
+})
+
+#define build_xchg(fn, type, ldinsn, stinsn) \
+static inline unsigned long fn(volatile type *m, unsigned long val)            \
+{                                                                              \
+    unsigned long dummy;                                                       \
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER                                    \
+                   "1: " ldinsn " %0,0,%3\n"                                   \
+                   stinsn " %2,0,%3\n"                                         \
+                   "2:  bne- 1b"                                               \
+                   PPC_ATOMIC_EXIT_BARRIER                                     \
+                   : "=&r" (dummy), "=m" (*m)                                  \
+                   : "r" (val), "r" (m)                                        \
+                   : "cc", "memory" );                                         \
+    return dummy;                                                              \
+}
+
+build_xchg(__xchg_u8, uint8_t, "lbarx", "stbcx.")
+build_xchg(__xchg_u16, uint16_t, "lharx", "sthcx.")
+build_xchg(__xchg_u32, uint32_t, "lwarx", "stwcx.")
+build_xchg(__xchg_u64, uint64_t, "ldarx", "stdcx.")
+
+#undef build_xchg
+

xen/arch/ppc/include/asm/system.h line 56

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +10 -0
+/*
+ * This function doesn't exist, so you'll get a linker error
+ * if something tries to do an invalid xchg().
+ */
+extern void __xchg_called_with_bad_pointer(void);
+
+static inline unsigned long __xchg(volatile void *ptr, unsigned long x,
+                                   int size)
+{
+    switch (size) {

Nit: Since the file looks like it wants to use Xen style:

Quoted 5 lines

switch ( size )
{

please.

Will do.

Quoted 77 lines
Quoted 77 lines
xen/arch/ppc/include/asm/system.h +77 -0
+    case 1:
+        return __xchg_u8(ptr, x);
+    case 2:
+        return __xchg_u16(ptr, x);
+    case 4:
+        return __xchg_u32(ptr, x);
+    case 8:
+        return __xchg_u64(ptr, x);
+    }
+    __xchg_called_with_bad_pointer();
+    return x;
+}
+
+
+static inline unsigned long __cmpxchg_u32(volatile int *p, int old, int new)
+{
+    unsigned int prev;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: lwarx   %0,0,%2\n"
+                   "cmpw    0,%0,%3\n"
+                   "bne-    2f\n "
+                   "stwcx.  %4,0,%2\n"
+                   "bne-    1b\n"
+                   PPC_ATOMIC_EXIT_BARRIER "\n"
+                   "2:"
+                   : "=&r" (prev), "=m" (*p)
+                   : "r" (p), "r" (old), "r" (new), "m" (*p)
+                   : "cc", "memory" );
+
+    return prev;
+}
+
+static inline unsigned long __cmpxchg_u64(volatile long *p, unsigned long old,
+                                          unsigned long new)
+{
+    unsigned long prev;
+
+    asm volatile ( PPC_ATOMIC_ENTRY_BARRIER
+                   "1: ldarx   %0,0,%2\n"
+                   "cmpd    0,%0,%3\n"
+                   "bne-    2f\n"
+                   "stdcx.  %4,0,%2\n"
+                   "bne-    1b"
+                   PPC_ATOMIC_EXIT_BARRIER "\n"
+                   "2:"
+                   : "=&r" (prev), "=m" (*p)
+                   : "r" (p), "r" (old), "r" (new), "m" (*p)
+                   : "cc", "memory" );
+
+    return prev;
+}
+
+/* This function doesn't exist, so you'll get a linker error
+   if something tries to do an invalid cmpxchg().  */
+extern void __cmpxchg_called_with_bad_pointer(void);
+
+static always_inline unsigned long __cmpxchg(
+    volatile void *ptr,
+    unsigned long old,
+    unsigned long new,
+    int size)
+{
+    switch (size) {
+    case 2:
+        BUG_ON("unimplemented"); return 0; /* XXX implement __cmpxchg_u16 ? */
+    case 4:
+        return __cmpxchg_u32(ptr, old, new);
+    case 8:
+        return __cmpxchg_u64(ptr, old, new);
+    }
+    __cmpxchg_called_with_bad_pointer();
+    return old;
+}
+
+#define cmpxchg_user(ptr,o,n) cmpxchg(ptr,o,n)
+
Quoted 9 lines

xen/arch/ppc/include/asm/system.h line 139

Quoted 6 lines
xen/arch/ppc/include/asm/system.h +6 -0
+#define cmpxchg(ptr,o,n)                         \
+  ({                                     \
+     __typeof__(*(ptr)) _o_ = (o);                   \
+     __typeof__(*(ptr)) _n_ = (n);                   \
+     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,       \
+                    (unsigned long)_n_, sizeof(*(ptr))); \

Not: Style (multiple previously mentioned issues).

Will clean up.

Quoted 22 lines
Quoted 22 lines
xen/arch/ppc/include/asm/system.h +22 -0
+  })
+
+
+/*
+ * Memory barrier.
+ * The sync instruction guarantees that all memory accesses initiated
+ * by this processor have been performed (with respect to all other
+ * mechanisms that access memory).  The eieio instruction is a barrier
+ * providing an ordering (separately) for (a) cacheable stores and (b)
+ * loads and stores to non-cacheable memory (e.g. I/O devices).
+ *
+ * mb() prevents loads and stores being reordered across this point.
+ * rmb() prevents loads being reordered across this point.
+ * wmb() prevents stores being reordered across this point.
+ * read_barrier_depends() prevents data-dependent loads being reordered
+ *  across this point (nop on PPC).
+ *
+ * We have to use the sync instructions for mb(), since lwsync doesn't
+ * order loads with respect to previous stores.  Lwsync is fine for
+ * rmb(), though.
+ * For wmb(), we use sync since wmb is used in drivers to order
+ * stores to system memory with respect to writes to the device.
Quoted 9 lines

xen/arch/ppc/include/asm/system.h line 167

Quoted 6 lines
xen/arch/ppc/include/asm/system.h +6 -0
+ * However, smp_wmb() can be a lighter-weight eieio barrier on
+ * SMP since it is only used to order updates to system memory.
+ */
+#define mb()   __asm__ __volatile__ ("sync" : : : "memory")
+#define rmb()  __asm__ __volatile__ ("lwsync" : : : "memory")
+#define wmb()  __asm__ __volatile__ ("sync" : : : "memory")

Nit: Missing blanks.

Will fix.

Quoted 11 lines
Quoted 11 lines
xen/arch/ppc/include/asm/system.h +11 -0
+#define read_barrier_depends()  do { } while(0)
+
+#define set_mb(var, value)  do { var = value; smp_mb(); } while (0)
+#define set_wmb(var, value) do { var = value; smp_wmb(); } while (0)
+
+#define smp_mb__before_atomic()    smp_mb()
+#define smp_mb__after_atomic()     smp_mb()
+
+#ifdef CONFIG_SMP
+#define smp_mb()    mb()
+#define smp_rmb()   rmb()
Quoted 9 lines

xen/arch/ppc/include/asm/system.h line 184

Quoted 6 lines
xen/arch/ppc/include/asm/system.h +6 -0
+#define smp_wmb()   __asm__ __volatile__ ("lwsync" : : : "memory")
+#define smp_read_barrier_depends()  read_barrier_depends()
+#else
+#define smp_mb()    __asm__ __volatile__("": : :"memory")
+#define smp_rmb()   __asm__ __volatile__("": : :"memory")
+#define smp_wmb()   __asm__ __volatile__("": : :"memory")

And more missing blanks (further below from here).

Will fix, along with removal of dead !CONFIG_SMP path.

Quoted 10 lines
Quoted 10 lines
xen/arch/ppc/include/asm/system.h +10 -0
+#define smp_read_barrier_depends()  do { } while(0)
+#endif /* CONFIG_SMP */
+
+#define local_save_flags(flags) ((flags) = mfmsr())
+#define local_irq_restore(flags) do { \
+        __asm__ __volatile__("": : :"memory"); \
+        mtmsrd((flags)); \
+} while(0)
+
+static inline void local_irq_disable(void)
Quoted 9 lines

xen/arch/ppc/include/asm/system.h line 199

Quoted 5 lines
xen/arch/ppc/include/asm/system.h +5 -0
+{
+    unsigned long msr;
+    msr = mfmsr();
+    mtmsrd(msr & ~MSR_EE);
+    asm volatile ( "" : : : "memory" );

That's simply barrier(), isn't it? Please avoid open-coding. (More further down.)

Good call. Will change all occurrences to barrier().

Quoted 9 lines
Quoted 9 lines
xen/arch/ppc/include/asm/time.h new file +6 -0
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_PPC_TIME_H__
+#define __ASM_PPC_TIME_H__
+
+#include <xen/lib.h>
+#include <asm/processor.h>
Quoted 9 lines

xen/arch/ppc/include/asm/time.h line 12

Quoted 6 lines
xen/arch/ppc/include/asm/time.h new file +6 -0
+#include <asm/regs.h>
+
+struct vcpu;
+
+/* TODO: implement */
+static inline void force_update_vcpu_system_time(struct vcpu *v) { BUG_ON("unimplemented"); }

Nit: Too long line.

Will fix.

Quoted 1 line

Jan

Thanks,
Shawn

#9 lore raw

Re: [PATCH v3 3/5] xen/ppc: Define minimal stub headers required for full build

Quoted 37 lines · Shawn Anastasio
Quoted 21 lines · Jan Beulich
Quoted 20 lines · Shawn Anastasio
xen/arch/ppc/include/asm/mm.h +15 -1
@@ -13,6 +28,237 @@
 #define __pa(x)             (virt_to_maddr(x))
 #define __va(x)             (maddr_to_virt(x))
 
-void setup_initial_pagetables(void);
+/* Convert between Xen-heap virtual addresses and machine frame numbers. */
+#define __virt_to_mfn(va) (virt_to_maddr(va) >> PAGE_SHIFT)
+#define __mfn_to_virt(mfn) (maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT))
+
+/* Convert between Xen-heap virtual addresses and page-info structures. */
+static inline struct page_info *virt_to_page(const void *v)
+{
+    BUG_ON("unimplemented");
+    return NULL;
+}
+
+/*
+ * We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored version
+ * remain intact.
Quoted 9 lines

xen/arch/ppc/include/asm/mm.h line 48

Quoted 3 lines
xen/arch/ppc/include/asm/mm.h +3 -0
+ */
+#define virt_to_mfn(va)     __virt_to_mfn(va)
+#define mfn_to_virt(mfn)    __mfn_to_virt(mfn)

Is the comment really applicable? The only non-arch-specific file still doing so is xenoprof.c, and I'm not sure you mean to support xenoprof on PPC. PPC-specific files would better be introduced in a type-safe way right from the beginning.

To be clear, you're suggesting that I define virt_to_mfn and mfn_to_virt to operate on the type-safe mfn_t wrapper? When doing this, xen/include/xen/domain_page.h:63 fails to build, since it seems to assume that these macros do not use the type-safe mfn_t:

Quoted 4 lines
  static inline void *map_domain_page_global(mfn_t mfn)
  {
      return mfn_to_virt(mfn_x(mfn));
  }

Oh, I see. That's a result of (at least) 41c48004d1d8 ("xen/mm: Use __virt_to_mfn in map_domain_page instead of virt_to_mfn") not going far enough and f46b6197344f ("xen: Convert page_to_mfn and mfn_to_page to use typesafe MFN") not properly doing the intended conversion. Let me (try to) make a patch, once again ...

Quoted 3 lines

If the comment is no longer accurate I can drop it, but there definitely seems to be an assumption in the codebase that these macros operate on raw unsigned longs rather than mfn_t.

Well, the comment is new (in PPC), so it cannot really be "no longer accurate". It (sadly) still is accurate in Arm, but I was hoping we would be able to do better in new ports.

Jan

#10 lore raw
In reply to Shawn Anastasio
Quoted 10 lines · Shawn Anastasio

Hello all,

This patch series performs all of the additions necessary to drop the build overrides for PPC and enable the full Xen build. Except in cases where compatibile implementations already exist (e.g. atomic.h and bitops.h), the newly added definitions are simple, unimplemented stubs that just call BUG_ON("unimplemented").

A few miscellaneous changes were also made to non-ppc code as well, specifically a few missing header fixes in common.

Nit: This is stale now, isn't it?

But what I really wanted to mention here: Something's odd with how you sent this series. I received 0, 1, and 3 as one thread, 2 and 5 as another one, and 4 entirely standalone. The list archive [1] has all of 2, 4, and 5 as standalone mails.

Another thing I wanted to ask: Would it be possible to configure whatever mail client you use for sending patches to send plain ASCII or UTF-8 text, not quoted-printable ones? At least for me, so far having shoveled in most of your patches, that encoding gets in the way of running a pre-apply-test with plain "patch --dry-run -F0" on all patches (from a script I use for committing). I can help myself with plain "git am", but sooner or later some patch will end up having a collision with something else having gone in, and then I'll need to manually clean up after the failed / incomplete command.

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2023-09/threads.html

#11 lore raw
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Shawn Anastasio

Hello all,

This patch series performs all of the additions necessary to drop the build overrides for PPC and enable the full Xen build. Except in cases where compatibile implementations already exist (e.g. atomic.h and bitops.h), the newly added definitions are simple, unimplemented stubs that just call BUG_ON("unimplemented").

Quoted 4 lines
Quoted 2 lines

A few miscellaneous changes were also made to non-ppc code as well, specifically a few missing header fixes in common.

Nit: This is stale now, isn't it?

Yes, I'll drop that sentence.

Quoted 5 lines

But what I really wanted to mention here: Something's odd with how you sent this series. I received 0, 1, and 3 as one thread, 2 and 5 as another one, and 4 entirely standalone. The list archive [1] has all of 2, 4, and 5 as standalone mails.

I'm also seeing this in my own inbox -- I'm not sure what happened here since I used the same exact git send-email invocation that I used last time.

Quoted 10 lines

Another thing I wanted to ask: Would it be possible to configure whatever mail client you use for sending patches to send plain ASCII or UTF-8 text, not quoted-printable ones? At least for me, so far having shoveled in most of your patches, that encoding gets in the way of running a pre-apply-test with plain "patch --dry-run -F0" on all patches (from a script I use for committing). I can help myself with plain "git am", but sooner or later some patch will end up having a collision with something else having gone in, and then I'll need to manually clean up after the failed / incomplete command.

If I'm understanding correctly, it looks like git send-email's --transfer-encoding=8bit [1] should do what you're asking. I'll do this for future submissions.

[1] https://git-scm.com/docs/git-send-email

Quoted 1 line

Jan

Thanks,
Shawn

#12 lore raw
Quoted 13 lines · Shawn Anastasio
Quoted 11 lines · Jan Beulich

On 01.09.2023 20:25, Shawn Anastasio wrote:
Another thing I wanted to ask: Would it be possible to configure whatever mail client you use for sending patches to send plain ASCII or UTF-8 text, not quoted-printable ones? At least for me, so far having shoveled in most of your patches, that encoding gets in the way of running a pre-apply-test with plain "patch --dry-run -F0" on all patches (from a script I use for committing). I can help myself with plain "git am", but sooner or later some patch will end up having a collision with something else having gone in, and then I'll need to manually clean up after the failed / incomplete command.

Quoted 3 lines

If I'm understanding correctly, it looks like git send-email's --transfer-encoding=8bit [1] should do what you're asking. I'll do this for future submissions.

I've done this for my latest series dropping pseries support, but it seems the messages that reached the mailing list are still encoded as quoted-printable, despite git reporting that they were sent as 8bit.

I suppose my SMTP server is mangling the encoding, then. I'll look into this some more, but hopefully the quoted-printable patches I send in the meantime won't pose too much of an inconvenience.

Thanks,
Shawn