Skip to contentSkip to conversation

ppc: Enable full Xen build

PATCH Superseded Shawn Anastasio 2 participants 31 messages Aug 2, 2023 – Aug 28, 2023

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

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().

A few miscellaneous changes were also made to non-ppc code as well, namely a few missing header fixes as well as an ARM-ism in the ns16550 driver.

Thanks,
Shawn

Shawn Anastasio (9):
xen/common: Add missing #includes treewide xen/ppc: Add public/arch-ppc.h
xen/ppc: Implement atomic.h
xen/ppc: Implement bitops.h
xen/ppc: Define minimal stub headers required for full build
ns16550: Guard accesses to vuart field by CONFIG_ARM xen/ppc: Define bug frames table in linker script 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        |  39 +++
 xen/arch/ppc/include/asm/atomic.h        | 387 +++++++++++++++++++++++
 xen/arch/ppc/include/asm/bitops.h        | 331 ++++++++++++++++++-
 xen/arch/ppc/include/asm/bug.h           |   7 +
 xen/arch/ppc/include/asm/cache.h         |   2 +
 xen/arch/ppc/include/asm/config.h        |   9 +
 xen/arch/ppc/include/asm/cpufeature.h    |   9 +
 xen/arch/ppc/include/asm/current.h       |  42 +++
 xen/arch/ppc/include/asm/delay.h         |  11 +
 xen/arch/ppc/include/asm/desc.h          |   0
 xen/arch/ppc/include/asm/device.h        |  53 ++++
 xen/arch/ppc/include/asm/div64.h         |  14 +
 xen/arch/ppc/include/asm/domain.h        |  46 +++
 xen/arch/ppc/include/asm/event.h         |  35 ++
 xen/arch/ppc/include/asm/flushtlb.h      |  23 ++
 xen/arch/ppc/include/asm/grant_table.h   |   0
 xen/arch/ppc/include/asm/guest_access.h  |  54 ++++
 xen/arch/ppc/include/asm/guest_atomics.h |  14 +
 xen/arch/ppc/include/asm/hardirq.h       |  18 ++
 xen/arch/ppc/include/asm/hypercall.h     |   0
 xen/arch/ppc/include/asm/io.h            |  15 +
 xen/arch/ppc/include/asm/iocap.h         |   7 +
 xen/arch/ppc/include/asm/iommu.h         |   7 +
 xen/arch/ppc/include/asm/irq.h           |  32 ++
 xen/arch/ppc/include/asm/mem_access.h    |   0
 xen/arch/ppc/include/asm/memory.h        |  34 ++
 xen/arch/ppc/include/asm/mm.h            | 255 ++++++++++++++-
 xen/arch/ppc/include/asm/monitor.h       |  48 +++
 xen/arch/ppc/include/asm/nospec.h        |  18 ++
 xen/arch/ppc/include/asm/numa.h          |  26 ++
 xen/arch/ppc/include/asm/p2m.h           | 105 ++++++
 xen/arch/ppc/include/asm/page.h          |  19 ++
 xen/arch/ppc/include/asm/paging.h        |   7 +
 xen/arch/ppc/include/asm/pci.h           |   7 +
 xen/arch/ppc/include/asm/percpu.h        |  26 ++
 xen/arch/ppc/include/asm/procarea.h      |  38 +++
 xen/arch/ppc/include/asm/processor.h     |   6 +
 xen/arch/ppc/include/asm/random.h        |   9 +
 xen/arch/ppc/include/asm/regs.h          |   2 +
 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        | 243 +++++++++++++-
 xen/arch/ppc/include/asm/time.h          |  20 ++
 xen/arch/ppc/include/asm/vm_event.h      |  49 +++
 xen/arch/ppc/include/asm/xenoprof.h      |   0
 xen/arch/ppc/mm-radix.c                  |  46 ++-
 xen/arch/ppc/opal.c                      |   2 -
 xen/arch/ppc/setup.c                     |  10 +-
 xen/arch/ppc/stubs.c                     | 351 ++++++++++++++++++++
 xen/arch/ppc/tlb-radix.c                 |   2 +-
 xen/arch/ppc/xen.lds.S                   |  10 +
 xen/common/memory.c                      |   1 +
 xen/common/symbols.c                     |   1 +
 xen/common/xmalloc_tlsf.c                |   1 +
 xen/drivers/char/ns16550.c               |   2 +
 xen/include/public/arch-ppc.h            | 140 ++++++++
 xen/include/public/hvm/save.h            |   2 +
 xen/include/public/pmu.h                 |   2 +
 xen/include/public/xen.h                 |   2 +
 xen/include/xen/domain.h                 |   1 +
 xen/include/xen/iommu.h                  |   1 +
 xen/include/xen/sched.h                  |   1 +
 67 files changed, 2693 insertions(+), 17 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/desc.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/procarea.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
 create mode 100644 xen/include/public/arch-ppc.h

--
2.30.2

#1 lore raw

PATCH 1/9 xen/common: Add missing #includes treewide

A few files treewide depend on defininitions in headers that they don't include. This works when arch headers end up including the required headers by chance, but broke on ppc64 with only minimal/stub arch headers.

---
 xen/common/memory.c       | 1 +
 xen/common/symbols.c      | 1 +
 xen/common/xmalloc_tlsf.c | 1 +
 xen/include/xen/domain.h  | 1 +
 xen/include/xen/iommu.h   | 1 +
 xen/include/xen/sched.h   | 1 +
 6 files changed, 6 insertions(+)
xen/common/memory.c +1 -0
index c206fa4808..1b185b00e4 100644
@@ -28,6 +28,7 @@
 #include <asm/current.h>
 #include <asm/hardirq.h>
 #include <asm/p2m.h>
+#include <asm/page.h>
 #include <public/memory.h>
 #include <xsm/xsm.h>
 
xen/common/symbols.c +1 -0
index 9377f41424..691e617925 100644
@@ -19,6 +19,7 @@
 #include <xen/virtual_region.h>
 #include <public/platform.h>
 #include <xen/guest_access.h>
+#include <xen/errno.h>
 
 #ifdef SYMBOLS_ORIGIN
 extern const unsigned int symbols_offsets[];
xen/common/xmalloc_tlsf.c +1 -0
index c603c39bb9..349b31cb4c 100644
@@ -27,6 +27,7 @@
 #include <xen/mm.h>
 #include <xen/pfn.h>
 #include <asm/time.h>
+#include <asm/page.h>
 
 #define MAX_POOL_NAME_LEN       16
 
xen/include/xen/domain.h +1 -0
index d35af34841..767127b440 100644
@@ -4,6 +4,7 @@
 
 #include <xen/types.h>
 
+#include <public/domctl.h>
 #include <public/xen.h>
 #include <asm/domain.h>
 #include <asm/numa.h>
xen/include/xen/iommu.h +1 -0
index 405db59971..ef817efec9 100644
@@ -24,6 +24,7 @@
 #include <xen/page-defs.h>
 #include <xen/pci.h>
 #include <xen/spinlock.h>
+#include <xen/errno.h>
 #include <public/domctl.h>
 #include <public/hvm/ioreq.h>
 #include <asm/device.h>
xen/include/xen/sched.h +1 -0
index 854f3e32c0..6a96534a45 100644
@@ -21,6 +21,7 @@
 #include <xen/smp.h>
 #include <xen/perfc.h>
 #include <asm/atomic.h>
+#include <asm/current.h>
 #include <xen/vpci.h>
 #include <xen/wait.h>
 #include <public/xen.h>
Signature · 1 line
2.30.2
#2 lore raw

Re: [PATCH 1/9] xen/common: Add missing #includes treewide

Quoted 6 lines · Shawn Anastasio

A few files treewide depend on defininitions in headers that they don't include. This works when arch headers end up including the required headers by chance, but broke on ppc64 with only minimal/stub arch headers.

I'm okay with the changes in principle, but I'd like to ask a question nevertheless, perhaps also for other REST maintainers (whom you should have Cc-ed, btw) to chime in.

xen/common/memory.c line 33

Quoted 9 lines
xen/common/memory.c +1 -0
@@ -28,6 +28,7 @@
 #include <asm/current.h>
 #include <asm/hardirq.h>
 #include <asm/p2m.h>
+#include <asm/page.h>
 #include <public/memory.h>
 #include <xsm/xsm.h>

I realize there are several asm/*.h being included here already. Yet generally I think common .c files would better not include any of them directly; only xen/*.h ones should (and even there one might see possible restrictions on what's "legitimate"). Do you recall what it was that's needed from asm/page.h here ...

xen/common/xmalloc_tlsf.c line 30

Quoted 7 lines
xen/common/xmalloc_tlsf.c +1 -0
@@ -27,6 +27,7 @@
 #include <xen/mm.h>
 #include <xen/pfn.h>
 #include <asm/time.h>
+#include <asm/page.h>

... and here?

xen/include/xen/domain.h line 8

Quoted 8 lines
xen/include/xen/domain.h +1 -0
@@ -4,6 +4,7 @@
 
 #include <xen/types.h>
 
+#include <public/domctl.h>
 #include <public/xen.h>

While following our sorting guidelines, this still looks a little odd. We typically would include public/xen.h first, but then almost all other public headers include it anyway. So I'm inclined to suggest to replace (rather than amend) the existing #include here.

Then again I wonder why this include is needed. xen/domain.h is effectively included everywhere, yet I would have hoped public/domctl.h isn't.

Jan

#3 lore raw

Re: [PATCH 1/9] xen/common: Add missing #includes treewide

Quoted 12 lines · Jan Beulich
Quoted 6 lines · Shawn Anastasio

A few files treewide depend on defininitions in headers that they don't include. This works when arch headers end up including the required headers by chance, but broke on ppc64 with only minimal/stub arch headers.

I'm okay with the changes in principle, but I'd like to ask a question nevertheless, perhaps also for other REST maintainers (whom you should have Cc-ed, btw) to chime in.

Quoted 15 lines

xen/common/memory.c line 33

Quoted 9 lines
xen/common/memory.c +1 -0
@@ -28,6 +28,7 @@
 #include <asm/current.h>
 #include <asm/hardirq.h>
 #include <asm/p2m.h>
+#include <asm/page.h>
 #include <public/memory.h>
 #include <xsm/xsm.h>

I realize there are several asm/*.h being included here already. Yet generally I think common .c files would better not include any of them directly; only xen/*.h ones should (and even there one might see possible restrictions on what's "legitimate"). Do you recall what it was that's needed from asm/page.h here ...

The references to invalidate_icache (memory.c:310), clear_page (memory.c:1867), and copy_page (memory.c:1876) all need asm/page.h to be included somehow. I'm not sure which file ends up including asm/page.h for build to work on x86/arm, but with my minimal PPC headers it wasn't getting incidentally included and build was failing.

Quoted 10 lines

xen/common/xmalloc_tlsf.c line 30

Quoted 8 lines
xen/common/xmalloc_tlsf.c +1 -0
@@ -27,6 +27,7 @@
 #include <xen/mm.h>
 #include <xen/pfn.h>
 #include <asm/time.h>
+#include <asm/page.h>

... and here?

Here it's the PAGE_ALIGN used at xmalloc_tlsf.c:549

Quoted 7 lines
Quoted 7 lines
xen/include/xen/domain.h +0 -0
@@ -4,6 +4,7 @@
 
 #include <xen/types.h>
 
Quoted 7 lines

xen/include/xen/domain.h line 8

Quoted 2 lines
xen/include/xen/domain.h +1 -0
+#include <public/domctl.h>
 #include <public/xen.h>

While following our sorting guidelines, this still looks a little odd. We typically would include public/xen.h first, but then almost all other public headers include it anyway. So I'm inclined to suggest to replace (rather than amend) the existing #include here.

To be clear, you're suggesting replacing the include of <public/xen.h> to <public/domctl.h>? I've tested this and it works fine, as expected.

Quoted 4 lines

Then again I wonder why this include is needed. xen/domain.h is effectively included everywhere, yet I would have hoped public/domctl.h isn't.

domctl.h is required because of the reference to struct xen_domctl_createdomain on domain.h:84. Alternatively, we could get away with a forward declaration of the struct.

Quoted 1 line

Jan

Thanks,
Shawn

#4 lore raw

Re: [PATCH 1/9] xen/common: Add missing #includes treewide

Quoted 18 lines · Shawn Anastasio
Quoted 16 lines · Jan Beulich

xen/common/memory.c line 33

Quoted 9 lines · Shawn Anastasio
xen/common/memory.c +1 -0
@@ -28,6 +28,7 @@
 #include <asm/current.h>
 #include <asm/hardirq.h>
 #include <asm/p2m.h>
+#include <asm/page.h>
 #include <public/memory.h>
 #include <xsm/xsm.h>

I realize there are several asm/*.h being included here already. Yet generally I think common .c files would better not include any of them directly; only xen/*.h ones should (and even there one might see possible restrictions on what's "legitimate"). Do you recall what it was that's needed from asm/page.h here ...

Quoted 5 lines

The references to invalidate_icache (memory.c:310), clear_page (memory.c:1867), and copy_page (memory.c:1876) all need asm/page.h to be included somehow. I'm not sure which file ends up including asm/page.h for build to work on x86/arm, but with my minimal PPC headers it wasn't getting incidentally included and build was failing.

Okay, that's unavoidable then.

Quoted 11 lines
Quoted 9 lines

xen/common/xmalloc_tlsf.c line 30

Quoted 7 lines
xen/common/xmalloc_tlsf.c +1 -0
@@ -27,6 +27,7 @@
 #include <xen/mm.h>
 #include <xen/pfn.h>
 #include <asm/time.h>
+#include <asm/page.h>

... and here?

Here it's the PAGE_ALIGN used at xmalloc_tlsf.c:549

Hmm, PAGE_ALIGN() really shouldn't be a per-arch #define.

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
xen/include/xen/domain.h +0 -0
@@ -4,6 +4,7 @@
 
 #include <xen/types.h>
 
Quoted 7 lines

xen/include/xen/domain.h line 8

Quoted 2 lines
xen/include/xen/domain.h +1 -0
+#include <public/domctl.h>
 #include <public/xen.h>

While following our sorting guidelines, this still looks a little odd. We typically would include public/xen.h first, but then almost all other public headers include it anyway. So I'm inclined to suggest to replace (rather than amend) the existing #include here.

Quoted 2 lines

To be clear, you're suggesting replacing the include of <public/xen.h> to <public/domctl.h>?

Yes (but see below).

Quoted 1 line

I've tested this and it works fine, as expected.

Good.

Quoted 7 lines
Quoted 3 lines

Then again I wonder why this include is needed. xen/domain.h is effectively included everywhere, yet I would have hoped public/domctl.h isn't.

domctl.h is required because of the reference to struct xen_domctl_createdomain on domain.h:84. Alternatively, we could get away with a forward declaration of the struct.

This is always the preferred solution, when available.

Jan

#5 lore raw

PATCH 2/9 xen/ppc: Add public/arch-ppc.h

In reply to Shawn Anastasio
---
 xen/include/public/arch-ppc.h | 140 ++++++++++++++++++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 xen/include/public/arch-ppc.h
xen/include/public/arch-ppc.h new file +140 -0
new file mode 100644
index 0000000000..0eb7ce4208
@@ -0,0 +1,140 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (C) IBM Corp. 2005, 2006
+ * Copyright (C) Raptor Engineering, LLC 2023
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ *          Timothy Pearson <[email protected]>
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_PPC64_H__
+#define __XEN_PUBLIC_ARCH_PPC64_H__
+
+#define  int64_aligned_t  int64_t __attribute__((aligned(8)))
+#define uint64_aligned_t uint64_t __attribute__((aligned(8)))
+
+#ifndef __ASSEMBLY__
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
+    typedef union { type *p; unsigned long q; }                 \
+        __guest_handle_ ## name;                                \
+    typedef union { type *p; uint64_aligned_t q; }              \
+        __guest_handle_64_ ## name
+
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
+#define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
+#define set_xen_guest_handle_raw(hnd, val)                  \
+    do {                                                    \
+        __typeof__(&(hnd)) _sxghr_tmp = &(hnd);             \
+        _sxghr_tmp->q = 0;                                  \
+        _sxghr_tmp->p = val;                                \
+    } while ( 0 )
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+#ifdef __XEN_TOOLS__
+#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
+#endif
+
+typedef uint64_t xen_pfn_t;
+#define PRI_xen_pfn PRIx64
+#define PRIu_xen_pfn PRIu64
+
+/*
+ * Maximum number of virtual CPUs in legacy multi-processor guests.
+ * Only one. All other VCPUS must use VCPUOP_register_vcpu_info.
+ */
+#define XEN_LEGACY_MAX_VCPUS 1
+
+typedef uint64_t xen_ulong_t;
+#define PRI_xen_ulong PRIx64
+#endif
+
+/*
+ * Pointers and other address fields inside interface structures are padded to
+ * 64 bits. This means that field alignments aren't different between 32- and
+ * 64-bit architectures.
+ */
+/* NB. Multi-level macro ensures __LINE__ is expanded before concatenation. */
+#define __MEMORY_PADDING(_X)
+#define _MEMORY_PADDING(_X)  __MEMORY_PADDING(_X)
+#define MEMORY_PADDING       _MEMORY_PADDING(__LINE__)
+
+/* And the trap vector is... */
+#define TRAP_INSTR "li 0,-1; sc" /* XXX just "sc"? */
+
+#ifndef __ASSEMBLY__
+
+#define XENCOMM_INLINE_FLAG (1UL << 63)
+
+typedef uint64_t xen_ulong_t;
+
+/* User-accessible registers: nost of these need to be saved/restored
+ * for every nested Xen invocation. */
+struct vcpu_guest_core_regs
+{
+    uint64_t gprs[32];
+    uint64_t lr;
+    uint64_t ctr;
+    uint64_t srr0;
+    uint64_t srr1;
+    uint64_t pc;
+    uint64_t msr;
+    uint64_t fpscr;             /* XXX Is this necessary */
+    uint64_t xer;
+    uint64_t hid4;              /* debug only */
+    uint64_t dar;               /* debug only */
+    uint32_t dsisr;             /* debug only */
+    uint32_t cr;
+    uint32_t __pad;             /* good spot for another 32bit reg */
+    uint32_t entry_vector;
+};
+typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
+
+typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */ /* XXX timebase */
+
+/* ONLY used to communicate with dom0! See also struct exec_domain. */
+struct vcpu_guest_context {
+    vcpu_guest_core_regs_t user_regs;         /* User-level CPU registers     */
+    uint64_t sdr1;                     /* Pagetable base               */
+    /* XXX etc */
+};
+typedef struct vcpu_guest_context vcpu_guest_context_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
+
+struct arch_shared_info {
+    uint64_t boot_timebase;
+};
+
+struct arch_vcpu_info {
+};
+
+struct xen_arch_domainconfig {
+};
+
+typedef struct xen_pmu_arch { uint8_t dummy; } xen_pmu_arch_t;
+
+/* Support for multi-processor guests. */
+#endif
+
+#endif
Signature · 1 line
2.30.2
#6 lore raw

Re: [PATCH 2/9] xen/ppc: Add public/arch-ppc.h

Quoted 20 lines · Shawn Anastasio
---
 xen/include/public/arch-ppc.h | 140 ++++++++++++++++++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 xen/include/public/arch-ppc.h
xen/include/public/arch-ppc.h new file +8 -0
new file mode 100644
index 0000000000..0eb7ce4208
@@ -0,0 +1,140 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *

xen/include/public/arch-ppc.h line 18

Quoted 10 lines
xen/include/public/arch-ppc.h new file +10 -0
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.

Any reason for a spelled out license rather than an SPDX header?

xen/include/public/arch-ppc.h line 28

Quoted 9 lines
xen/include/public/arch-ppc.h new file +9 -0
+ * Copyright (C) IBM Corp. 2005, 2006
+ * Copyright (C) Raptor Engineering, LLC 2023
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ *          Timothy Pearson <[email protected]>
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_PPC64_H__
+#define __XEN_PUBLIC_ARCH_PPC64_H__

The 64 wants dropping here, considering the name of the header.

xen/include/public/arch-ppc.h line 31

Quoted 2 lines
xen/include/public/arch-ppc.h new file +2 -0
+#define  int64_aligned_t  int64_t __attribute__((aligned(8)))
+#define uint64_aligned_t uint64_t __attribute__((aligned(8)))

I understand arch-arm.h has it this way too, but in public headers I think we're better off using __aligned__ (in the example here).

Quoted 7 lines
xen/include/public/arch-ppc.h new file +7 -0
+#ifndef __ASSEMBLY__
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
+    typedef union { type *p; unsigned long q; }                 \
+        __guest_handle_ ## name;                                \
+    typedef union { type *p; uint64_aligned_t q; }              \
+        __guest_handle_64_ ## name
+

xen/include/public/arch-ppc.h line 49

Quoted 10 lines
xen/include/public/arch-ppc.h new file +10 -0
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
+#define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
+#define set_xen_guest_handle_raw(hnd, val)                  \
+    do {                                                    \
+        __typeof__(&(hnd)) _sxghr_tmp = &(hnd);             \

In new code, can you please avoid underscore-prefixed macro locals, which violate name space rules set forth by the standard? We appear to be adopting underscore-suffixed naming for such locals.

xen/include/public/arch-ppc.h line 51

Quoted 2 lines
xen/include/public/arch-ppc.h new file +2 -0
+        _sxghr_tmp->q = 0;                                  \
+        _sxghr_tmp->p = val;                                \

"val" need parenthesizing here.

Quoted 20 lines
xen/include/public/arch-ppc.h new file +20 -0
+    } while ( 0 )
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+#ifdef __XEN_TOOLS__
+#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
+#endif
+
+typedef uint64_t xen_pfn_t;
+#define PRI_xen_pfn PRIx64
+#define PRIu_xen_pfn PRIu64
+
+/*
+ * Maximum number of virtual CPUs in legacy multi-processor guests.
+ * Only one. All other VCPUS must use VCPUOP_register_vcpu_info.
+ */
+#define XEN_LEGACY_MAX_VCPUS 1
+
+typedef uint64_t xen_ulong_t;
+#define PRI_xen_ulong PRIx64
+#endif

xen/include/public/arch-ppc.h line 81

Quoted 10 lines
xen/include/public/arch-ppc.h new file +10 -0
+
+/*
+ * Pointers and other address fields inside interface structures are padded to
+ * 64 bits. This means that field alignments aren't different between 32- and
+ * 64-bit architectures.
+ */
+/* NB. Multi-level macro ensures __LINE__ is expanded before concatenation. */
+#define __MEMORY_PADDING(_X)
+#define _MEMORY_PADDING(_X)  __MEMORY_PADDING(_X)
+#define MEMORY_PADDING       _MEMORY_PADDING(__LINE__)

This doesn't parallel anything in other architectures afaics, and it is also not used anywhere in this header. What is this about? If it needs to stay, it'll need properly moving into XEN_* namespace.

xen/include/public/arch-ppc.h line 84

Quoted 2 lines
xen/include/public/arch-ppc.h new file +2 -0
+/* And the trap vector is... */
+#define TRAP_INSTR "li 0,-1; sc" /* XXX just "sc"? */

Same question / remark here.

xen/include/public/arch-ppc.h line 88

Quoted 3 lines
xen/include/public/arch-ppc.h new file +3 -0
+#ifndef __ASSEMBLY__
+
+#define XENCOMM_INLINE_FLAG (1UL << 63)

Is this an indication that you mean to revive xencomm.h?

xen/include/public/arch-ppc.h line 93

Quoted 4 lines
xen/include/public/arch-ppc.h new file +4 -0
+typedef uint64_t xen_ulong_t;
+
+/* User-accessible registers: nost of these need to be saved/restored
+ * for every nested Xen invocation. */

Nit: comment style (and s/nost/most/).

Quoted 35 lines
xen/include/public/arch-ppc.h new file +35 -0
+struct vcpu_guest_core_regs
+{
+    uint64_t gprs[32];
+    uint64_t lr;
+    uint64_t ctr;
+    uint64_t srr0;
+    uint64_t srr1;
+    uint64_t pc;
+    uint64_t msr;
+    uint64_t fpscr;             /* XXX Is this necessary */
+    uint64_t xer;
+    uint64_t hid4;              /* debug only */
+    uint64_t dar;               /* debug only */
+    uint32_t dsisr;             /* debug only */
+    uint32_t cr;
+    uint32_t __pad;             /* good spot for another 32bit reg */
+    uint32_t entry_vector;
+};
+typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
+
+typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */ /* XXX timebase */
+
+/* ONLY used to communicate with dom0! See also struct exec_domain. */
+struct vcpu_guest_context {
+    vcpu_guest_core_regs_t user_regs;         /* User-level CPU registers     */
+    uint64_t sdr1;                     /* Pagetable base               */
+    /* XXX etc */
+};
+typedef struct vcpu_guest_context vcpu_guest_context_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
+
+struct arch_shared_info {
+    uint64_t boot_timebase;
+};
+

xen/include/public/arch-ppc.h line 138

Quoted 10 lines
xen/include/public/arch-ppc.h new file +10 -0
+struct arch_vcpu_info {
+};
+
+struct xen_arch_domainconfig {
+};
+
+typedef struct xen_pmu_arch { uint8_t dummy; } xen_pmu_arch_t;
+
+/* Support for multi-processor guests. */
+#endif

Stray comment?

Jan

#7 lore raw

Re: [PATCH 2/9] xen/ppc: Add public/arch-ppc.h

Quoted 25 lines · Jan Beulich
Quoted 24 lines · Shawn Anastasio
---
 xen/include/public/arch-ppc.h | 140 ++++++++++++++++++++++++++++++++++
 1 file changed, 140 insertions(+)
 create mode 100644 xen/include/public/arch-ppc.h
xen/include/public/arch-ppc.h new file +12 -0
new file mode 100644
index 0000000000..0eb7ce4208
@@ -0,0 +1,140 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Quoted 9 lines

xen/include/public/arch-ppc.h line 18

Quoted 6 lines
xen/include/public/arch-ppc.h new file +6 -0
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.

Any reason for a spelled out license rather than an SPDX header?

This was an oversight when importing the file from the old Xen 3.2 source tree. I'll drop the license text in favor of an SPDX header.

Quoted 11 lines

xen/include/public/arch-ppc.h line 28

Quoted 9 lines
xen/include/public/arch-ppc.h new file +9 -0
+ * Copyright (C) IBM Corp. 2005, 2006
+ * Copyright (C) Raptor Engineering, LLC 2023
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ *          Timothy Pearson <[email protected]>
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_PPC64_H__
+#define __XEN_PUBLIC_ARCH_PPC64_H__

The 64 wants dropping here, considering the name of the header.

Ditto. Will fix.

Quoted 5 lines

xen/include/public/arch-ppc.h line 31

Quoted 2 lines
xen/include/public/arch-ppc.h new file +2 -0
+#define  int64_aligned_t  int64_t __attribute__((aligned(8)))
+#define uint64_aligned_t uint64_t __attribute__((aligned(8)))

I understand arch-arm.h has it this way too, but in public headers I think we're better off using __aligned__ (in the example here).

Sure, I can make that change.

Quoted 13 lines
Quoted 13 lines
xen/include/public/arch-ppc.h new file +13 -0
+#ifndef __ASSEMBLY__
+#define ___DEFINE_XEN_GUEST_HANDLE(name, type)                  \
+    typedef union { type *p; unsigned long q; }                 \
+        __guest_handle_ ## name;                                \
+    typedef union { type *p; uint64_aligned_t q; }              \
+        __guest_handle_64_ ## name
+
+#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
+    ___DEFINE_XEN_GUEST_HANDLE(name, type);   \
+    ___DEFINE_XEN_GUEST_HANDLE(const_##name, const type)
+#define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
+#define __XEN_GUEST_HANDLE(name)        __guest_handle_64_ ## name
+#define XEN_GUEST_HANDLE(name)          __XEN_GUEST_HANDLE(name)
Quoted 8 lines

xen/include/public/arch-ppc.h line 49

Quoted 4 lines
xen/include/public/arch-ppc.h new file +4 -0
+#define XEN_GUEST_HANDLE_PARAM(name)    __guest_handle_ ## name
+#define set_xen_guest_handle_raw(hnd, val)                  \
+    do {                                                    \
+        __typeof__(&(hnd)) _sxghr_tmp = &(hnd);             \

In new code, can you please avoid underscore-prefixed macro locals, which violate name space rules set forth by the standard? We appear to be adopting underscore-suffixed naming for such locals.

Sure, will fix.

Quoted 4 lines

xen/include/public/arch-ppc.h line 51

Quoted 2 lines
xen/include/public/arch-ppc.h new file +2 -0
+        _sxghr_tmp->q = 0;                                  \
+        _sxghr_tmp->p = val;                                \

"val" need parenthesizing here.

Will fix.

Quoted 26 lines
Quoted 26 lines
xen/include/public/arch-ppc.h new file +26 -0
+    } while ( 0 )
+#define set_xen_guest_handle(hnd, val) set_xen_guest_handle_raw(hnd, val)
+
+#ifdef __XEN_TOOLS__
+#define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
+#endif
+
+typedef uint64_t xen_pfn_t;
+#define PRI_xen_pfn PRIx64
+#define PRIu_xen_pfn PRIu64
+
+/*
+ * Maximum number of virtual CPUs in legacy multi-processor guests.
+ * Only one. All other VCPUS must use VCPUOP_register_vcpu_info.
+ */
+#define XEN_LEGACY_MAX_VCPUS 1
+
+typedef uint64_t xen_ulong_t;
+#define PRI_xen_ulong PRIx64
+#endif
+
+/*
+ * Pointers and other address fields inside interface structures are padded to
+ * 64 bits. This means that field alignments aren't different between 32- and
+ * 64-bit architectures.
+ */
Quoted 8 lines

xen/include/public/arch-ppc.h line 81

Quoted 4 lines
xen/include/public/arch-ppc.h new file +4 -0
+/* NB. Multi-level macro ensures __LINE__ is expanded before concatenation. */
+#define __MEMORY_PADDING(_X)
+#define _MEMORY_PADDING(_X)  __MEMORY_PADDING(_X)
+#define MEMORY_PADDING       _MEMORY_PADDING(__LINE__)

This doesn't parallel anything in other architectures afaics, and it is also not used anywhere in this header. What is this about? If it needs to stay, it'll need properly moving into XEN_* namespace.

This was another holdover from the old Xen code. I'll remove it.

Quoted 4 lines

xen/include/public/arch-ppc.h line 84

Quoted 2 lines
xen/include/public/arch-ppc.h new file +2 -0
+/* And the trap vector is... */
+#define TRAP_INSTR "li 0,-1; sc" /* XXX just "sc"? */

Same question / remark here.

Ditto, will remove.

Quoted 6 lines

xen/include/public/arch-ppc.h line 88

Quoted 4 lines
xen/include/public/arch-ppc.h new file +3 -0
+#ifndef __ASSEMBLY__
+
+#define XENCOMM_INLINE_FLAG (1UL << 63)

Is this an indication that you mean to revive xencomm.h?

No, this was yet another holdover from the old Xen tree. I'll remove it.

Quoted 7 lines

xen/include/public/arch-ppc.h line 93

Quoted 4 lines
xen/include/public/arch-ppc.h new file +4 -0
+typedef uint64_t xen_ulong_t;
+
+/* User-accessible registers: nost of these need to be saved/restored
+ * for every nested Xen invocation. */

Nit: comment style (and s/nost/most/).

Will fix.

Quoted 39 lines
Quoted 39 lines
xen/include/public/arch-ppc.h new file +39 -0
+struct vcpu_guest_core_regs
+{
+    uint64_t gprs[32];
+    uint64_t lr;
+    uint64_t ctr;
+    uint64_t srr0;
+    uint64_t srr1;
+    uint64_t pc;
+    uint64_t msr;
+    uint64_t fpscr;             /* XXX Is this necessary */
+    uint64_t xer;
+    uint64_t hid4;              /* debug only */
+    uint64_t dar;               /* debug only */
+    uint32_t dsisr;             /* debug only */
+    uint32_t cr;
+    uint32_t __pad;             /* good spot for another 32bit reg */
+    uint32_t entry_vector;
+};
+typedef struct vcpu_guest_core_regs vcpu_guest_core_regs_t;
+
+typedef uint64_t tsc_timestamp_t; /* RDTSC timestamp */ /* XXX timebase */
+
+/* ONLY used to communicate with dom0! See also struct exec_domain. */
+struct vcpu_guest_context {
+    vcpu_guest_core_regs_t user_regs;         /* User-level CPU registers     */
+    uint64_t sdr1;                     /* Pagetable base               */
+    /* XXX etc */
+};
+typedef struct vcpu_guest_context vcpu_guest_context_t;
+DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
+
+struct arch_shared_info {
+    uint64_t boot_timebase;
+};
+
+struct arch_vcpu_info {
+};
+
+struct xen_arch_domainconfig {
Quoted 8 lines

xen/include/public/arch-ppc.h line 138

Quoted 6 lines
xen/include/public/arch-ppc.h new file +6 -0
+};
+
+typedef struct xen_pmu_arch { uint8_t dummy; } xen_pmu_arch_t;
+
+/* Support for multi-processor guests. */
+#endif

Stray comment?

Yup, I'll drop it.

Quoted 2 lines

Jan

Thanks,
Shawn

#8 lore raw

PATCH 3/9 xen/ppc: Implement atomic.h

In reply to Shawn Anastasio

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

---
 xen/arch/ppc/include/asm/atomic.h | 387 ++++++++++++++++++++++++++++++
 xen/arch/ppc/include/asm/memory.h |  34 +++
 2 files changed, 421 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 +387 -0
new file mode 100644
index 0000000000..336dedc476
@@ -0,0 +1,387 @@
+/* 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
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PPC64_ATOMIC_H_
+#define _ASM_PPC64_ATOMIC_H_
+
+#include <xen/atomic.h>
+
+#include <asm/memory.h>
+#include <asm/system.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, void *val,
+                                            unsigned int size)
+{
+    ASSERT(IS_ALIGNED((vaddr_t) p, size));
+    switch ( size )
+    {
+    case 1:
+        write_u8_atomic(p, *(uint8_t *)val);
+        break;
+    case 2:
+        write_u16_atomic(p, *(uint16_t *)val);
+        break;
+    case 4:
+        write_u32_atomic(p, *(uint32_t *)val);
+        break;
+    case 8:
+        write_u64_atomic(p, *(uint64_t *)val);
+        break;
+    default:
+        __bad_atomic_size();
+        break;
+    }
+}
+
+#define read_atomic(p)                                                         \
+    ({                                                                         \
+        union {                                                                \
+            typeof(*(p)) val;                                                  \
+            char c[0];                                                         \
+        } 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), "m"(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), "m"(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), "m"(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), "m"(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 +34 -0
new file mode 100644
index 0000000000..7b12e01b1a
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * 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
Signature · 1 line
2.30.2
#9 lore raw

Re: [PATCH 3/9] xen/ppc: Implement atomic.h

Quoted 2 lines · Shawn Anastasio

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

Since likely that originally came from Linux, did you cross check that Linux hasn't gained any bug fixes in the meantime?

Other than this just a couple of nits; I'm not really qualified to review in particular the inline assembly here, I'm afraid.

Quoted 9 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
@@ -0,0 +1,387 @@
+/* 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

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+ * Copyright Raptor Engineering LLC
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PPC64_ATOMIC_H_
+#define _ASM_PPC64_ATOMIC_H_

To fit the name, no "64" please.

Quoted 23 lines
xen/arch/ppc/include/asm/atomic.h new file +23 -0
+#include <xen/atomic.h>
+
+#include <asm/memory.h>
+#include <asm/system.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;

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+}
+
+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) );       \

As I think I had mentioned before, asm() contraints want a blank between closing quote and opend paren. I.e. like this

        asm volatile ( insn "%U1%X1 %0,%1" : "=r" (ret) : "m<>" (*addr) );
Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
+#define read_atomic(p)                                                         \
+    ({                                                                         \
+        union {                                                                \
+            typeof(*(p)) val;                                                  \
+            char c[0];                                                         \
+        } x_;                                                                  \

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+        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 )

Up to here you use underscore-suffixed locals, but then ...

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

Quoted 3 lines
xen/arch/ppc/include/asm/atomic.h new file +3 -0
+#define add_sized(p, x)                                                        \
+    ({                                                                         \
+        typeof(*(p)) __x = (x);                                                \

... you have even two prefixing underscores here.

Quoted 17 lines
xen/arch/ppc/include/asm/atomic.h new file +17 -0
+        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;                                                             \
+        }                                                                      \
+    })
+

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+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), "m"(v->counter) : "cc" );

"+m" and then drop the last input?

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

Quoted 13 lines
xen/arch/ppc/include/asm/atomic.h new file +13 -0
+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");

Missing blanks near the parentheses. Would also be nice if the padding blanks actually vertically aligned the operands.

Quoted 5 lines
xen/arch/ppc/include/asm/atomic.h new file +5 -0
+    return t;
+}
+
+static inline atomic_t atomic_compareandswap(atomic_t old, atomic_t new,
+                                             atomic_t *v)

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+{
+    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);                                          \

Problematic leading underscores again.

Quoted 40 lines
xen/arch/ppc/include/asm/atomic.h new file +40 -0
+        (__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)

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+{
+    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)

Btw, no real need to parenthesize v in cases like this one. Otoh a needs parenthesizing.

Jan

#10 lore raw

Re: [PATCH 3/9] xen/ppc: Implement atomic.h

Quoted 6 lines · Jan Beulich
Quoted 2 lines · Shawn Anastasio

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

Since likely that originally came from Linux, did you cross check that Linux hasn't gained any bug fixes in the meantime?

I did -- the atomic barrier instructions used by linux have changed since this code was originally written, so I've updated them to be inline with modern linux.

Quoted 16 lines

Other than this just a couple of nits; I'm not really qualified to review in particular the inline assembly here, I'm afraid.

Quoted 13 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
@@ -0,0 +1,387 @@
+/* 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
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
Quoted 8 lines

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

Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PPC64_ATOMIC_H_
+#define _ASM_PPC64_ATOMIC_H_

To fit the name, no "64" please.

Will fix.

Quoted 37 lines
Quoted 23 lines
xen/arch/ppc/include/asm/atomic.h new file +23 -0
+#include <xen/atomic.h>
+
+#include <asm/memory.h>
+#include <asm/system.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;

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+}
+
+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) );       \

As I think I had mentioned before, asm() contraints want a blank between closing quote and opend paren. I.e. like this

Quoted 2 lines
        asm volatile ( insn "%U1%X1 %0,%1" : "=r" (ret) : "m<>" (*addr) );

My mistake, I went through and hand-formatted all of this code to try to be inline with Xen's style but forgot about the constraints.

As an aside, I don't suppose there is an automatic formatter somewhere that I've missed? I found an old clang-format fork that claims to add support for Xen's formatting[1] but it seems to only handle a subset of Xen's rules so I haven't found it very useful.

[1] https://github.com/NastyaVicodin/llvm-project/commits/main

Quoted 19 lines
Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
+#define read_atomic(p)                                                         \
+    ({                                                                         \
+        union {                                                                \
+            typeof(*(p)) val;                                                  \
+            char c[0];                                                         \
+        } x_;                                                                  \

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+        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 )

Up to here you use underscore-suffixed locals, but then ...

Quoted 6 lines

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

Quoted 3 lines
xen/arch/ppc/include/asm/atomic.h new file +3 -0
+#define add_sized(p, x)                                                        \
+    ({                                                                         \
+        typeof(*(p)) __x = (x);                                                \

... you have even two prefixing underscores here.

The definitions of these macros were directly copied from elsewhere in Xen (x86 and arm). I can change them all to use underscore-suffixed local naming here, though.

Quoted 21 lines
Quoted 21 lines
xen/arch/ppc/include/asm/atomic.h new file +21 -0
+        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;
+
Quoted 9 lines

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

Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
+    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), "m"(v->counter) : "cc" );

"+m" and then drop the last input?

Yes, that makes sense. Not sure why it was originally written that way but I'll change it.

Quoted 8 lines
Quoted 8 lines
xen/arch/ppc/include/asm/atomic.h new file +8 -0
+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"
Quoted 8 lines

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

Quoted 5 lines
xen/arch/ppc/include/asm/atomic.h new file +5 -0
+                 "stwcx.    %0,0,%1\n"
+                 "bne-    1b\n"
+                 PPC_ATOMIC_EXIT_BARRIER
+                 "2:" : "=&r"(t)
+                 : "r"(&v->counter) : "cc", "memory");

Missing blanks near the parentheses. Would also be nice if the padding blanks actually vertically aligned the operands.

I tried to make the spacing uniform across all asm blocks in this file, but the convention I used was just a single space between the mnemonic and the operands. I seemed to have missed this one though, so I'll bring it in line with the others.

Quoted 9 lines
Quoted 9 lines
xen/arch/ppc/include/asm/atomic.h new file +9 -0
+    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;
Quoted 9 lines

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

Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
+}
+
+#define arch_cmpxchg(ptr, o, n)                                                \
+    ({                                                                         \
+        __typeof__(*(ptr)) _o_ = (o);                                          \
+        __typeof__(*(ptr)) _n_ = (n);                                          \

Problematic leading underscores again.

Will fix.

Quoted 45 lines
Quoted 45 lines
xen/arch/ppc/include/asm/atomic.h new file +45 -0
+        (__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)
Quoted 8 lines

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

Quoted 5 lines
xen/arch/ppc/include/asm/atomic.h new file +5 -0
+{
+	int c, old;
+
+	c = atomic_read(v);
+	while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c)

Btw, no real need to parenthesize v in cases like this one. Otoh a needs parenthesizing.

FWIW this was copied directly from arm64/atomic.h, but seeing as its a normal function and not a macro I'm not sure I see why a would need parenthesis. I'll drop the ones around v though.

Quoted 1 line

Jan

Thanks,
Shawn

#11 lore raw

Re: [PATCH 3/9] xen/ppc: Implement atomic.h

Quoted 11 lines · Shawn Anastasio
Quoted 6 lines · Jan Beulich
Quoted 2 lines · Shawn Anastasio

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

Since likely that originally came from Linux, did you cross check that Linux hasn't gained any bug fixes in the meantime?

I did -- the atomic barrier instructions used by linux have changed since this code was originally written, so I've updated them to be inline with modern linux.

Please mention this in the description then.

Quoted 43 lines
Quoted 37 lines
Quoted 23 lines
xen/arch/ppc/include/asm/atomic.h new file +23 -0
+#include <xen/atomic.h>
+
+#include <asm/memory.h>
+#include <asm/system.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;

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+}
+
+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) );       \

As I think I had mentioned before, asm() contraints want a blank between closing quote and opend paren. I.e. like this

Quoted 2 lines
        asm volatile ( insn "%U1%X1 %0,%1" : "=r" (ret) : "m<>" (*addr) );

My mistake, I went through and hand-formatted all of this code to try to be inline with Xen's style but forgot about the constraints.

Quoted 6 lines

As an aside, I don't suppose there is an automatic formatter somewhere that I've missed? I found an old clang-format fork that claims to add support for Xen's formatting[1] but it seems to only handle a subset of Xen's rules so I haven't found it very useful.

[1] https://github.com/NastyaVicodin/llvm-project/commits/main

Work there was recently revived, but we're not quite there yet, sorry.

Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
+#define read_atomic(p)                                                         \
+    ({                                                                         \
+        union {                                                                \
+            typeof(*(p)) val;                                                  \
+            char c[0];                                                         \
+        } x_;                                                                  \

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

Quoted 10 lines
xen/arch/ppc/include/asm/atomic.h new file +10 -0
+        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 )

Up to here you use underscore-suffixed locals, but then ...

Quoted 3 lines
xen/arch/ppc/include/asm/atomic.h new file +3 -0
+#define add_sized(p, x)                                                        \
+    ({                                                                         \
+        typeof(*(p)) __x = (x);                                                \
Quoted 6 lines
Quoted 2 lines

... you have even two prefixing underscores here.

The definitions of these macros were directly copied from elsewhere in Xen (x86 and arm). I can change them all to use underscore-suffixed local naming here, though.

We're still far away from eliminating all pre-existing issues. So copying existing code is always at risk of then getting such comments. Again - sorry for that, but otherwise we'll grow the number of issues.

Quoted 31 lines
Quoted 21 lines
Quoted 21 lines
xen/arch/ppc/include/asm/atomic.h new file +21 -0
+        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;
+
Quoted 9 lines

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

Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -0
+    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), "m"(v->counter) : "cc" );

"+m" and then drop the last input?

Quoted 2 lines

Yes, that makes sense. Not sure why it was originally written that way but I'll change it.

I think this was attributed to not sufficiently well written documentation for older gcc.

Quoted 10 lines
Quoted 9 lines

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

Quoted 6 lines
xen/arch/ppc/include/asm/atomic.h new file +6 -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)

Btw, no real need to parenthesize v in cases like this one. Otoh a needs parenthesizing.

Quoted 3 lines

FWIW this was copied directly from arm64/atomic.h, but seeing as its a normal function and not a macro I'm not sure I see why a would need parenthesis.

Oh, right you are. The parenthesized v misled me.

Jan

#12 lore raw

PATCH 4/9 xen/ppc: Implement bitops.h

In reply to Shawn Anastasio

Implement bitops.h, based on Linux's implementation as of commit 5321d1b1afb9a17302c6cec79f0cbf823eb0d3fc

---
 xen/arch/ppc/include/asm/bitops.h | 331 +++++++++++++++++++++++++++++-
 1 file changed, 327 insertions(+), 4 deletions(-)
xen/arch/ppc/include/asm/bitops.h +327 -4
index a7cd8ec7c5..286f68cbfe 100644
@@ -1,11 +1,334 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Adapted from Linux's arch/powerpc/include/asm/bitops.h.
+ *
+ * Merged version by David Gibson <[email protected]>.
+ * Based on ppc64 versions by: Dave Engebretsen, Todd Inglett, Don
+ * Reed, Pat McCarthy, Peter Bergner, Anton Blanchard.  They
+ * originally took it from the ppc32 code.
+ */
 #ifndef _ASM_PPC_BITOPS_H
 #define _ASM_PPC_BITOPS_H
 
-#include <xen/compiler.h>
+#define __set_bit(n,p)            set_bit(n,p)
+#define __clear_bit(n,p)          clear_bit(n,p)
+
+#define BITOP_BITS_PER_WORD     32
+#define BITOP_MASK(nr)          (1UL << ((nr) % BITOP_BITS_PER_WORD))
+#define BITOP_WORD(nr)          ((nr) / BITOP_BITS_PER_WORD)
+#define BITS_PER_BYTE           8
 
 /* PPC bit number conversion */
-#define PPC_BITLSHIFT(be)	(BITS_PER_LONG - 1 - (be))
-#define PPC_BIT(bit)		(1UL << PPC_BITLSHIFT(bit))
-#define PPC_BITMASK(bs, be)	((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs))
+#define PPC_BITLSHIFT(be)    (BITS_PER_LONG - 1 - (be))
+#define PPC_BIT(bit)         (1UL << PPC_BITLSHIFT(bit))
+#define PPC_BITMASK(bs, be)  ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs))
+
+/* Macro for generating the ***_bits() functions */
+#define DEFINE_BITOP(fn, op, prefix)        \
+static inline void fn(unsigned long mask,    \
+        volatile unsigned int *_p)     \
+{                                       \
+    unsigned long old;                  \
+    unsigned int *p = (unsigned int *)_p;    \
+    __asm__ __volatile__ (              \
+    prefix                              \
+"1: lwarx %0,0,%3,0\n"                  \
+    #op "%I2 %0,%0,%2\n"                \
+    "stwcx. %0,0,%3\n"                  \
+    "bne- 1b\n"                         \
+    : "=&r" (old), "+m" (*p)            \
+    : "rK" (mask), "r" (p)              \
+    : "cc", "memory");                  \
+}
+
+DEFINE_BITOP(set_bits, or, "")
+DEFINE_BITOP(change_bits, xor, "")
+
+#define DEFINE_CLROP(fn, prefix)                    \
+static inline void fn(unsigned long mask, volatile unsigned int *_p)    \
+{                                    \
+    unsigned long old;                        \
+    unsigned int *p = (unsigned int *)_p;                \
+                                    		\
+    asm volatile (                        	\
+    	prefix                        			\
+    	"1: lwarx %0,0,%3,0\n"     		\
+        "andc %0,%0,%2\n"                	\
+        "stwcx. %0,0,%3\n"                	\
+        "bne- 1b\n"                    		\
+        : "=&r" (old), "+m" (*p)            \
+        : "r" (mask), "r" (p)               \
+        : "cc", "memory");                	\
+}
+
+DEFINE_CLROP(clear_bits, "")
+
+static inline void set_bit(int nr, volatile void *addr)
+{
+    set_bits(BITOP_MASK(nr), (volatile unsigned int *)addr + BITOP_WORD(nr));
+}
+static inline void clear_bit(int nr, volatile void *addr)
+{
+    clear_bits(BITOP_MASK(nr), (volatile unsigned int *)addr + BITOP_WORD(nr));
+}
+
+/**
+ * test_bit - Determine whether a bit is set
+ * @nr: bit number to test
+ * @addr: Address to start counting from
+ */
+static inline int test_bit(int nr, const volatile void *addr)
+{
+        const volatile unsigned long *p = (const volatile unsigned long *)addr;
+        return 1UL & (p[BITOP_WORD(nr)] >> (nr & (BITOP_BITS_PER_WORD-1)));
+}
+
+static inline unsigned long test_and_clear_bits(unsigned long mask, volatile void *_p)
+{
+    unsigned long old, t;
+    unsigned int *p = (unsigned int *)_p;
+
+    asm volatile (
+		"sync\n"
+    "1:" "lwarx %0,0,%3,0\n"
+        "andc    %1,%0,%2\n"
+        "stwcx. %1,0,%3\n"
+        "bne- 1b\n"
+		"sync\n"
+        : "=&r" (old), "=&r" (t)
+        : "r" (mask), "r" (p)
+        : "cc", "memory");
+
+    return (old & mask);
+}
+
+static inline int test_and_clear_bit(unsigned int nr,
+					  				 volatile void *addr)
+{
+	return test_and_clear_bits(BITOP_MASK(nr), addr + BITOP_WORD(nr)) != 0;
+}
+
+#define DEFINE_TESTOP(fn, op, eh)	\
+static inline unsigned long fn(			\
+		unsigned long mask,			\
+		volatile unsigned int *_p)		\
+{							\
+	unsigned long old, t;				\
+	unsigned int *p = (unsigned int *)_p;		\
+	__asm__ __volatile__ (				\
+	"sync\n"						\
+"1:" "lwarx %0,0,%3,%4\n"			\
+	#op "%I2 %1,%0,%2\n"				\
+	"stwcx. %1,0,%3\n"				\
+	"bne- 1b\n"					\
+	"sync\n"						\
+	: "=&r" (old), "=&r" (t)			\
+	: "rK" (mask), "r" (p), "n" (eh)		\
+	: "cc", "memory");				\
+	return (old & mask);				\
+}
+
+DEFINE_TESTOP(test_and_set_bits, or, 0)
+
+static inline int test_and_set_bit(unsigned long nr, volatile void *addr)
+{
+	return test_and_set_bits(BITOP_MASK(nr), (volatile unsigned int *)addr + BITOP_WORD(nr)) != 0;
+}
+
+/**
+ * __test_and_set_bit - Set a bit and return its old value
+ * @nr: Bit to set
+ * @addr: Address to count from
+ *
+ * This operation is non-atomic and can be reordered.
+ * If two examples of this operation race, one can appear to succeed
+ * but actually fail.  You must protect multiple accesses with a lock.
+ */
+static inline int __test_and_set_bit(int nr, volatile void *addr)
+{
+        unsigned int mask = BITOP_MASK(nr);
+        volatile unsigned int *p =
+                ((volatile unsigned int *)addr) + BITOP_WORD(nr);
+        unsigned int old = *p;
+
+        *p = old | mask;
+        return (old & mask) != 0;
+}
+
+/**
+ * __test_and_clear_bit - Clear a bit and return its old value
+ * @nr: Bit to clear
+ * @addr: Address to count from
+ *
+ * This operation is non-atomic and can be reordered.
+ * If two examples of this operation race, one can appear to succeed
+ * but actually fail.  You must protect multiple accesses with a lock.
+ */
+static inline int __test_and_clear_bit(int nr, volatile void *addr)
+{
+        unsigned int mask = BITOP_MASK(nr);
+        volatile unsigned int *p =
+                ((volatile unsigned int *)addr) + BITOP_WORD(nr);
+        unsigned int old = *p;
+
+        *p = old & ~mask;
+        return (old & mask) != 0;
+}
+
+#define flsl(x) generic_flsl(x)
+#define fls(x) generic_fls(x)
+#define ffs(x) ({ unsigned int __t = (x); fls(__t & -__t); })
+#define ffsl(x) ({ unsigned long __t = (x); flsl(__t & -__t); })
+
+/* Based on linux/include/asm-generic/bitops/ffz.h */
+/*
+ * ffz - find first zero in word.
+ * @word: The word to search
+ *
+ * Undefined if no zero exists, so code should check against ~0UL first.
+ */
+#define ffz(x)  __ffs(~(x))
+
+/**
+ * hweightN - returns the hamming weight of a N-bit word
+ * @x: the word to weigh
+ *
+ * The Hamming Weight of a number is the total number of bits set in it.
+ */
+#define hweight64(x) generic_hweight64(x)
+#define hweight32(x) generic_hweight32(x)
+#define hweight16(x) generic_hweight16(x)
+#define hweight8(x) generic_hweight8(x)
+
+/* Based on linux/include/asm-generic/bitops/builtin-__ffs.h */
+/**
+ * __ffs - find first bit in word.
+ * @word: The word to search
+ *
+ * Undefined if no bit exists, so code should check against 0 first.
+ */
+static /*__*/always_inline unsigned long __ffs(unsigned long word)
+{
+        return __builtin_ctzl(word);
+}
+
+/**
+ * find_first_set_bit - find the first set bit in @word
+ * @word: the word to search
+ *
+ * Returns the bit-number of the first set bit (first bit being 0).
+ * The input must *not* be zero.
+ */
+#define find_first_set_bit(x) ({ ffsl(x) - 1; })
+
+/*
+ * Find the first set bit in a memory region.
+ */
+static inline unsigned long find_first_bit(const unsigned long *addr,
+										   unsigned long size)
+{
+	const unsigned long *p = addr;
+	unsigned long result = 0;
+	unsigned long tmp;
+
+	while (size & ~(BITS_PER_LONG-1)) {
+		if ((tmp = *(p++)))
+			goto found;
+		result += BITS_PER_LONG;
+		size -= BITS_PER_LONG;
+	}
+	if (!size)
+		return result;
+
+	tmp = (*p) & (~0UL >> (BITS_PER_LONG - size));
+	if (tmp == 0UL)		/* Are any bits set? */
+		return result + size;	/* Nope. */
+found:
+	return result + __ffs(tmp);
+}
+
+static inline unsigned long find_next_bit(const unsigned long *addr,
+										  unsigned long size,
+			    						  unsigned long offset)
+{
+	const unsigned long *p = addr + BITOP_WORD(offset);
+	unsigned long result = offset & ~(BITS_PER_LONG-1);
+	unsigned long tmp;
+
+	if (offset >= size)
+		return size;
+	size -= result;
+	offset %= BITS_PER_LONG;
+	if (offset) {
+		tmp = *(p++);
+		tmp &= (~0UL << offset);
+		if (size < BITS_PER_LONG)
+			goto found_first;
+		if (tmp)
+			goto found_middle;
+		size -= BITS_PER_LONG;
+		result += BITS_PER_LONG;
+	}
+	while (size & ~(BITS_PER_LONG-1)) {
+		if ((tmp = *(p++)))
+			goto found_middle;
+		result += BITS_PER_LONG;
+		size -= BITS_PER_LONG;
+	}
+	if (!size)
+		return result;
+	tmp = *p;
+
+found_first:
+	tmp &= (~0UL >> (BITS_PER_LONG - size));
+	if (tmp == 0UL)		/* Are any bits set? */
+		return result + size;	/* Nope. */
+found_middle:
+	return result + __ffs(tmp);
+}
+
+/*
+ * This implementation of find_{first,next}_zero_bit was stolen from
+ * Linus' asm-alpha/bitops.h.
+ */
+static inline unsigned long find_next_zero_bit(const unsigned long *addr,
+											   unsigned long size,
+											   unsigned long offset)
+{
+	const unsigned long *p = addr + BITOP_WORD(offset);
+	unsigned long result = offset & ~(BITS_PER_LONG-1);
+	unsigned long tmp;
+
+	if (offset >= size)
+		return size;
+	size -= result;
+	offset %= BITS_PER_LONG;
+	if (offset) {
+		tmp = *(p++);
+		tmp |= ~0UL >> (BITS_PER_LONG - offset);
+		if (size < BITS_PER_LONG)
+			goto found_first;
+		if (~tmp)
+			goto found_middle;
+		size -= BITS_PER_LONG;
+		result += BITS_PER_LONG;
+	}
+	while (size & ~(BITS_PER_LONG-1)) {
+		if (~(tmp = *(p++)))
+			goto found_middle;
+		result += BITS_PER_LONG;
+		size -= BITS_PER_LONG;
+	}
+	if (!size)
+		return result;
+	tmp = *p;
+
+found_first:
+	tmp |= ~0UL << size;
+	if (tmp == ~0UL)	/* Are any bits zero? */
+		return result + size;	/* Nope. */
+found_middle:
+	return result + ffz(tmp);
+}
 
 #endif /* _ASM_PPC_BITOPS_H */
Signature · 1 line
2.30.2
#13 lore raw

Re: [PATCH 4/9] xen/ppc: Implement bitops.h

Quoted 2 lines · Shawn Anastasio

Implement bitops.h, based on Linux's implementation as of commit 5321d1b1afb9a17302c6cec79f0cbf823eb0d3fc

But with PPC32 bits dropped afaics, and with leading hard tabs replaced by four spaces - which in turn appears to yield some unhelpful placement of line-continuing backslashes. And with some asm-generic/bitops/builtin-*.h expanded. Please mention all adjustments you made, to allow for some future importing of updates to go as smoothly as possible.

Jan

#14 lore raw

Re: [PATCH 4/9] xen/ppc: Implement bitops.h

Quoted 10 lines · Jan Beulich
Quoted 2 lines · Shawn Anastasio

Implement bitops.h, based on Linux's implementation as of commit 5321d1b1afb9a17302c6cec79f0cbf823eb0d3fc

But with PPC32 bits dropped afaics, and with leading hard tabs replaced by four spaces - which in turn appears to yield some unhelpful placement of line-continuing backslashes. And with some asm-generic/bitops/builtin-*.h expanded. Please mention all adjustments you made, to allow for some future importing of updates to go as smoothly as possible.

Yes, that is all correct. Additionally, the code was adapted to use 32-bit words for bitmap entries like the rest of Xen's architectures do instead of the 64-bit longs used by the Linux implementation. I provided the reference to the Linux commit for completeness' sake, but to be clear, my changes have caused it to diverge enough where I wouldn't expect direct imports from Linux to be (conveniently) possible.

I'll clarify this in the commit message and also fix the macro line-continuing backslash spacing.

Quoted 1 line

Jan

Thanks,
Shawn

#15 lore raw

PATCH 5/9 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.

---
 xen/arch/ppc/Kconfig                     |   1 +
 xen/arch/ppc/include/asm/altp2m.h        |  39 ++++
 xen/arch/ppc/include/asm/bug.h           |   7 +
 xen/arch/ppc/include/asm/cache.h         |   2 +
 xen/arch/ppc/include/asm/config.h        |   9 +
 xen/arch/ppc/include/asm/cpufeature.h    |   9 +
 xen/arch/ppc/include/asm/current.h       |  42 ++++
 xen/arch/ppc/include/asm/delay.h         |  11 +
 xen/arch/ppc/include/asm/desc.h          |   0
 xen/arch/ppc/include/asm/device.h        |  53 +++++
 xen/arch/ppc/include/asm/div64.h         |  14 ++
 xen/arch/ppc/include/asm/domain.h        |  46 ++++
 xen/arch/ppc/include/asm/event.h         |  35 ++++
 xen/arch/ppc/include/asm/flushtlb.h      |  23 ++
 xen/arch/ppc/include/asm/grant_table.h   |   0
 xen/arch/ppc/include/asm/guest_access.h  |  54 +++++
 xen/arch/ppc/include/asm/guest_atomics.h |  14 ++
 xen/arch/ppc/include/asm/hardirq.h       |  18 ++
 xen/arch/ppc/include/asm/hypercall.h     |   0
 xen/arch/ppc/include/asm/io.h            |  15 ++
 xen/arch/ppc/include/asm/iocap.h         |   7 +
 xen/arch/ppc/include/asm/iommu.h         |   7 +
 xen/arch/ppc/include/asm/irq.h           |  32 +++
 xen/arch/ppc/include/asm/mem_access.h    |   0
 xen/arch/ppc/include/asm/mm.h            | 255 ++++++++++++++++++++++-
 xen/arch/ppc/include/asm/monitor.h       |  48 +++++
 xen/arch/ppc/include/asm/nospec.h        |  18 ++
 xen/arch/ppc/include/asm/numa.h          |  26 +++
 xen/arch/ppc/include/asm/p2m.h           | 105 ++++++++++
 xen/arch/ppc/include/asm/page.h          |  19 ++
 xen/arch/ppc/include/asm/paging.h        |   7 +
 xen/arch/ppc/include/asm/pci.h           |   7 +
 xen/arch/ppc/include/asm/percpu.h        |  26 +++
 xen/arch/ppc/include/asm/procarea.h      |  38 ++++
 xen/arch/ppc/include/asm/processor.h     |   6 +
 xen/arch/ppc/include/asm/random.h        |   9 +
 xen/arch/ppc/include/asm/regs.h          |   2 +
 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        | 243 ++++++++++++++++++++-
 xen/arch/ppc/include/asm/time.h          |  20 ++
 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/opal.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 +
 51 files changed, 1368 insertions(+), 7 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/desc.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/procarea.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 +39 -0
new file mode 100644
index 0000000000..73a1e3a114
@@ -0,0 +1,39 @@
+/*
+ * Alternate p2m
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_PPC_ALTP2M_H__
+#define __ASM_PPC_ALTP2M_H__
+
+#include <xen/sched.h>
+
+/* 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. */
+    BUG();
+    return 0;
+}
+
+#endif /* __ASM_PPC_ALTP2M_H__ */
xen/arch/ppc/include/asm/bug.h +7 -0
index e5e874b31c..d02e8e2898 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,10 @@
 
 #define BUG_FN_REG r0
 
+#define BUG() do { \
+    die(); \
+} while (0)
+
+#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 +9 -0
index b76f940431..965b79aa64 100644
@@ -41,6 +41,15 @@
 
 #define XEN_VIRT_START _AT(vaddr_t, 0xc000000000000000)
 
+#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 +9 -0
new file mode 100644
index 0000000000..3552b9231d
@@ -0,0 +1,9 @@
+#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 +42 -0

42 lines not on this page · raw message

xen/arch/ppc/include/asm/delay.h new file +11 -0
new file mode 100644
index 0000000000..36be1775f8
@@ -0,0 +1,11 @@
+#ifndef __ASM_PPC_DELAY_H__
+#define __ASM_PPC_DELAY_H__
+
+#include <xen/lib.h>
+
+static inline void udelay(unsigned long usecs)
+{
+    BUG();
+}
+
+#endif /* __ASM_PPC_DELAY_H__ */
xen/arch/ppc/include/asm/desc.h new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
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..6959c3fb26
@@ -0,0 +1,14 @@
+#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;                             \
+    __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 +46 -0

46 lines not on this page · raw message

xen/arch/ppc/include/asm/event.h new file +35 -0
new file mode 100644
index 0000000000..3141127f31
@@ -0,0 +1,35 @@
+#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(); }
+static inline void vcpu_mark_events_pending(struct vcpu *v) { BUG(); }
+static inline void vcpu_update_evtchn_irq(struct vcpu *v) { BUG(); }
+static inline void vcpu_block_unless_event_pending(struct vcpu *v) { BUG(); }
+
+static inline int vcpu_event_delivery_is_enabled(struct vcpu *v)
+{
+    BUG();
+    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();
+    return 0;
+}
+
+static inline void local_event_delivery_enable(void)
+{
+    BUG();
+}
+
+#endif /* __ASM_PPC_EVENT_H__ */
xen/arch/ppc/include/asm/flushtlb.h new file +23 -0
new file mode 100644
index 0000000000..1af3bd2301
@@ -0,0 +1,23 @@
+#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 +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/ppc/include/asm/guest_access.h new file +54 -0

54 lines not on this page · raw message

xen/arch/ppc/include/asm/guest_atomics.h new file +14 -0
new file mode 100644
index 0000000000..bf4f802a15
@@ -0,0 +1,14 @@
+#ifndef __ASM_PPC_GUEST_ATOMICS_H__
+#define __ASM_PPC_GUEST_ATOMICS_H__
+
+#include <xen/lib.h>
+
+/* TODO: implement */
+#define guest_test_bit(d, nr, p)            ({ (void) (d); (void) (nr); (void) (p); BUG(); false; })
+#define guest_clear_bit(d, nr, p)           ({ (void) (d); (void) (nr); (void) (p); BUG(); false; })
+#define guest_set_bit(d, nr, p)             ({ (void) (d); (void) (nr); (void) (p); BUG(); false; })
+#define guest_test_and_set_bit(d, nr, p)    ({ (void) (d); (void) (nr); (void) (p); BUG(); false; })
+#define guest_test_and_clear_bit(d, nr, p)  ({ (void) (d); (void) (nr); (void) (p); BUG(); false; })
+#define guest_test_and_change_bit(d, nr, p) ({ (void) (d); (void) (nr); (void) (p); BUG(); false; })
+
+#endif /* __ASM_PPC_GUEST_ATOMICS_H__ */
xen/arch/ppc/include/asm/hardirq.h new file +18 -0
new file mode 100644
index 0000000000..51ef290961
@@ -0,0 +1,18 @@
+#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 +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/ppc/include/asm/io.h new file +15 -0
new file mode 100644
index 0000000000..f8f3bd6ff7
@@ -0,0 +1,15 @@
+#ifndef __ASM_PPC_IO_H__
+#define __ASM_PPC_IO_H__
+
+#include <xen/lib.h>
+
+/* TODO */
+#define readb(c)                ({ (void)(c); BUG(); 0; })
+#define readw(c)                ({ (void)(c); BUG(); 0; })
+#define readl(c)                ({ (void)(c); BUG(); 0; })
+
+#define writeb(v,c)             ({ (void)(v); (void)(c); BUG(); })
+#define writew(v,c)             ({ (void)(v); (void)(c); BUG(); })
+#define writel(v,c)             ({ (void)(v); (void)(c); BUG(); })
+
+#endif /* __ASM_PPC_IO_H__ */
xen/arch/ppc/include/asm/iocap.h new file +7 -0
new file mode 100644
index 0000000000..16ae0cf1c8
@@ -0,0 +1,7 @@
+#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 +7 -0
new file mode 100644
index 0000000000..fb1a381518
@@ -0,0 +1,7 @@
+#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 +32 -0
new file mode 100644
index 0000000000..99d30dd2bf
@@ -0,0 +1,32 @@
+#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();
+}
+
+static inline int platform_get_irq(const struct dt_device_node *device, int index)
+{
+    BUG();
+}
+
+#endif /* __ASM_PPC_IRQ_H__ */
xen/arch/ppc/include/asm/mem_access.h new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2
xen/arch/ppc/include/asm/mm.h +253 -2

272 lines not on this page · raw message

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

48 lines not on this page · raw message

xen/arch/ppc/include/asm/nospec.h new file +18 -0
new file mode 100644
index 0000000000..4d8ec923e9
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * From arch/arm/include/asm/nospec.h.
+ * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ */
+#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 +19 -0
index e58b0a7354..713630c393 100644
@@ -39,6 +39,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:
  *
@@ -175,4 +178,20 @@ struct prtb_entry {
 
 void tlbie_all(void);
 
+static inline void invalidate_icache(void)
+{
+    BUG();
+}
+
+#define clear_page(page) memset((void *)(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();
+}
+
+#define PAGE_ALIGN(x) (((x) + PAGE_SIZE - 1) & PAGE_MASK)
+
 #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 +26 -0
new file mode 100644
index 0000000000..faae72ee41
@@ -0,0 +1,26 @@
+#ifndef __PPC_PERCPU_H__
+#define __PPC_PERCPU_H__
+
+#ifndef __ASSEMBLY__
+
+#include <xen/types.h>
+
+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/procarea.h new file +38 -0
new file mode 100644
index 0000000000..55a358f1e4
@@ -0,0 +1,38 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) IBM Corp. 2005
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ */
+
+#ifndef _ASM_PROCAREA_H_
+#define _ASM_PROCAREA_H_
+
+#include <xen/types.h>
+
+struct vcpu;
+struct gdb_state;
+
+struct processor_area
+{
+    unsigned int whoami;
+    unsigned int hard_id;
+    struct vcpu *cur_vcpu;
+    void *hyp_stack_base;
+    unsigned long saved_regs[2];
+};
+
+#endif
xen/arch/ppc/include/asm/processor.h +6 -0
index 417288738c..695f98af5b 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.
@@ -175,6 +179,8 @@ static inline void noreturn die(void)
         HMT_very_low();
 }
 
+#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/regs.h +2 -0
index d5f47a6ff1..68135ca584 100644
@@ -23,6 +23,8 @@
 #ifndef _ASM_REG_DEFS_H_
 #define _ASM_REG_DEFS_H_
 
+#include <xen/types.h>
+
 /* Special Purpose Registers */
 #define SPRN_VRSAVE 256
 #define SPRN_DSISR  18
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 +242 -1

248 lines not on this page · raw message

xen/arch/ppc/include/asm/time.h new file +20 -0
new file mode 100644
index 0000000000..7872d3c15b
@@ -0,0 +1,20 @@
+#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(); }
+
+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 071e71b73e..399898a36d 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/opal.c +0 -2
index 396a9e403b..1183b7d5ef 100644
@@ -1,10 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "xen/compiler.h"
 #include <asm/boot.h>
 #include <asm/early_printk.h>
 #include <asm/opal-api.h>
 #include <asm/processor.h>
-#include <asm/mm.h>
 #include <xen/types.h>
 #include <xen/libfdt/libfdt.h>
 #include <xen/init.h>
xen/arch/ppc/tlb-radix.c +1 -1
index 69934076a7..551e8280de 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
Signature · 1 line
2.30.2
#16 lore raw

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

Quoted 10 lines · Shawn Anastasio
xen/arch/ppc/include/asm/altp2m.h new file +7 -0
@@ -0,0 +1,39 @@
+/*
+ * Alternate p2m
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,

xen/arch/ppc/include/asm/altp2m.h line 17

Quoted 10 lines
xen/arch/ppc/include/asm/altp2m.h new file +10 -0
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */

Please use an SPDX header instead in new code. I also wonder about the Intel copyright. I realize it's that way in the Arm header that you apparently copied, but even there it's pretty odd. I don't think such a pair of stub functions is reasonably copyrightable.

xen/arch/ppc/include/asm/altp2m.h line 22

Quoted 4 lines
xen/arch/ppc/include/asm/altp2m.h new file +4 -0
+#ifndef __ASM_PPC_ALTP2M_H__
+#define __ASM_PPC_ALTP2M_H__
+
+#include <xen/sched.h>

I don't think this is needed here (nor in Arm's original). All you need are forward decls of struct domain and struct vcpu. And xen/bug.h plus xen/types.h.

Quoted 11 lines
xen/arch/ppc/include/asm/bug.h +1 -0
@@ -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

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

Quoted 6 lines
xen/arch/ppc/include/asm/bug.h +3 -0
@@ -15,4 +16,10 @@
 
 #define BUG_FN_REG r0
 
+#define BUG() do { \
+    die(); \
+} while (0)

This looks like it's temporary. I think any construct that later needs updating wants marking in some common way (such that it's easy to grep for items left to be dealt with; you have such a comment in e.g. asm/event.h). Of course if an entire header consists of _only_ stubs, perhaps a single such comment would suffice.

xen/arch/ppc/include/asm/cache.h line 6

Quoted 7 lines
xen/arch/ppc/include/asm/cache.h +1 -0
@@ -3,4 +3,6 @@
 #ifndef _ASM_PPC_CACHE_H
 #define _ASM_PPC_CACHE_H
 
+#define __read_mostly __section(".data.read_mostly")

Not something for you to do, but we really want to move this to xen/cache.h.

xen/arch/ppc/include/asm/desc.h

Quoted 3 lines
xen/arch/ppc/include/asm/desc.h new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2

Along the lines of the above - common code should not include this header, and Arm shouldn't need one either. I'll see if I can sort this.

Quoted 62 lines
xen/arch/ppc/include/asm/mm.h +42 -2
@@ -1,19 +1,270 @@
 #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>
 
+void setup_initial_pagetables(void);
+
+extern unsigned long total_pages;
+
 #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))
 
 #define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK))
-#define maddr_to_virt(pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START)
+#define maddr_to_virt(pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START))
 
 /* Convert between Xen-heap virtual addresses and machine addresses. */
 #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();
+    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)
+
+#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. */

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

Quoted 10 lines
xen/arch/ppc/include/asm/mm.h +10 -0
+#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 static memory */
+#define PGC_static     0

You don't need this.

Quoted 29 lines
xen/arch/ppc/include/asm/mm.h +29 -0
+/* 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) \
+    (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn)))
+

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

Quoted 10 lines
xen/arch/ppc/include/asm/mm.h +10 -0
+#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)))
+
+#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 max_page ((unsigned long )0)

It's clear this is temporary, but it would still be nice if you could omit stray blanks.

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

Quoted 11 lines
xen/arch/ppc/include/asm/monitor.h new file +8 -0
@@ -0,0 +1,48 @@
+/* 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/sched.h>
+#include <public/domctl.h>

Judging from the contents of the file, you don't need either (and you certainly don't need public/domctl.h twice). Only xen/types.h looks to be needed right now.

Quoted 10 lines
xen/arch/ppc/include/asm/numa.h new file +7 -0
@@ -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;

xen/arch/ppc/include/asm/numa.h line 17

Quoted 10 lines
xen/arch/ppc/include/asm/numa.h new file +10 -0
+
+/* 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;

At least "Arm" wants replacing in the comment, I think.

xen/arch/ppc/include/asm/percpu.h line 6

Quoted 9 lines
xen/arch/ppc/include/asm/percpu.h new file +6 -0
@@ -0,0 +1,26 @@
+#ifndef __PPC_PERCPU_H__
+#define __PPC_PERCPU_H__
+
+#ifndef __ASSEMBLY__
+
+#include <xen/types.h>

Looks like nothing in the file requires this.

Quoted 7 lines
xen/arch/ppc/include/asm/procarea.h new file +4 -0
@@ -0,0 +1,38 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or

xen/arch/ppc/include/asm/procarea.h line 14

Quoted 10 lines
xen/arch/ppc/include/asm/procarea.h new file +10 -0
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

SPDX again please (and there's at least one more below).

xen/arch/ppc/include/asm/procarea.h line 24

Quoted 9 lines
xen/arch/ppc/include/asm/procarea.h new file +9 -0
+ * Copyright (C) IBM Corp. 2005
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ */
+
+#ifndef _ASM_PROCAREA_H_
+#define _ASM_PROCAREA_H_
+
+#include <xen/types.h>

Again nothing looks to require this.

xen/arch/ppc/include/asm/procarea.h line 27

Quoted 2 lines
xen/arch/ppc/include/asm/procarea.h new file +2 -0
+struct vcpu;
+struct gdb_state;

The later of these is unused below. The former is used, but in a way that would require a forward decl only in C++.

xen/arch/ppc/include/asm/processor.h line 115

Quoted 9 lines
xen/arch/ppc/include/asm/processor.h +3 -0
@@ -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)

As mentioned elsewhere, please try to avoid leading underscores in macro parameter names (or macro local variables, just to mention it again in this context).

xen/arch/ppc/include/asm/processor.h static inline void noreturn die(void) · line 182

Quoted 5 lines
xen/arch/ppc/include/asm/processor.h +1 -0
@@ -175,6 +179,8 @@ static inline void noreturn die(void)
         HMT_very_low();
 }
 
+#define cpu_relax() asm volatile ( "or %r1, %r1, %r1; or %r2, %r2, %r2" )

Just like HMT_very_low() this could do with a comment explaining the "interesting" ORs (until such time when the assembler supports suitable mnemonics).

xen/arch/ppc/include/asm/regs.h line 30

Quoted 11 lines
xen/arch/ppc/include/asm/regs.h +2 -0
@@ -23,6 +23,8 @@
 #ifndef _ASM_REG_DEFS_H_
 #define _ASM_REG_DEFS_H_
 
+#include <xen/types.h>
+
 /* Special Purpose Registers */
 #define SPRN_VRSAVE 256
 #define SPRN_DSISR  18

Why would this #include be needed here all of the sudden?

Quoted 20 lines
xen/arch/ppc/include/asm/system.h +17 -0
@@ -1,6 +1,247 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Copyright (C) IBM Corp. 2005
+ * Copyright (C) Raptor Engineering LLC

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

Quoted 10 lines
xen/arch/ppc/include/asm/system.h +6 -1
+ *
+ * Authors: Jimi Xenidis <[email protected]>
+ *          Shawn Anastasio <[email protected]>
+ */
+
 #ifndef _ASM_SYSTEM_H_
 #define _ASM_SYSTEM_H_
 
-#define smp_wmb() __asm__ __volatile__ ( "lwsync" : : : "memory" )
+#include <xen/config.h>

As mentioned before - any such #include you find is a leftover.

Jan

#17 lore raw

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

Quoted 18 lines · Jan Beulich
Quoted 17 lines · Shawn Anastasio
xen/arch/ppc/include/asm/altp2m.h new file +14 -0
@@ -0,0 +1,39 @@
+/*
+ * Alternate p2m
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
Quoted 8 lines

xen/arch/ppc/include/asm/altp2m.h line 17

Quoted 3 lines
xen/arch/ppc/include/asm/altp2m.h new file +3 -0
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */

Please use an SPDX header instead in new code. I also wonder about the Intel copyright. I realize it's that way in the Arm header that you apparently copied, but even there it's pretty odd. I don't think such a pair of stub functions is reasonably copyrightable.

Yes, I agree the copyright is a bit strange and was likely just copied on the Arm side from the original x86 header. Since I'm not copying any actually implemented code, I think it's safe to drop this in favor of just a standard SPDX header. I'll make that change.

Quoted 9 lines

xen/arch/ppc/include/asm/altp2m.h line 22

Quoted 4 lines
xen/arch/ppc/include/asm/altp2m.h new file +4 -0
+#ifndef __ASM_PPC_ALTP2M_H__
+#define __ASM_PPC_ALTP2M_H__
+
+#include <xen/sched.h>

I don't think this is needed here (nor in Arm's original). All you need are forward decls of struct domain and struct vcpu. And xen/bug.h plus xen/types.h.

Fair enough -- and bug.h seems to already include types.h for us, so we only need the one include plus the two forward declarations. I'll update this.

Quoted 14 lines
Quoted 14 lines
xen/arch/ppc/include/asm/bug.h +1 -0
@@ -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,10 @@
 
 #define BUG_FN_REG r0
 
Quoted 9 lines

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

Quoted 3 lines
xen/arch/ppc/include/asm/bug.h +3 -0
+#define BUG() do { \
+    die(); \
+} while (0)

This looks like it's temporary. I think any construct that later needs updating wants marking in some common way (such that it's easy to grep for items left to be dealt with; you have such a comment in e.g. asm/event.h). Of course if an entire header consists of _only_ stubs, perhaps a single such comment would suffice.

Yes, agreed that this macro deserves a TODO comment.

As for the rest of the stub functions that this patch implements, are you suggesting that each file with stubs should contain a similar comment? Another alternative that I thought of would be to define a BUG_UNIMPLEMENTED() macro or similar and call that inside of all the stub functions.

Quoted 11 lines

xen/arch/ppc/include/asm/cache.h line 6

Quoted 7 lines
xen/arch/ppc/include/asm/cache.h +1 -0
@@ -3,4 +3,6 @@
 #ifndef _ASM_PPC_CACHE_H
 #define _ASM_PPC_CACHE_H
 
+#define __read_mostly __section(".data.read_mostly")

Not something for you to do, but we really want to move this to xen/cache.h.

Perfect, will drop this from my series.

Quoted 8 lines

xen/arch/ppc/include/asm/desc.h

Quoted 3 lines
xen/arch/ppc/include/asm/desc.h new file +0 -0
new file mode 100644
index 0000000000..e69de29bb2

Along the lines of the above - common code should not include this header, and Arm shouldn't need one either. I'll see if I can sort this.

Ditto.

Quoted 66 lines
Quoted 66 lines
xen/arch/ppc/include/asm/mm.h +46 -2
@@ -1,19 +1,270 @@
 #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>
 
+void setup_initial_pagetables(void);
+
+extern unsigned long total_pages;
+
 #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))
 
 #define virt_to_maddr(va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK))
-#define maddr_to_virt(pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START)
+#define maddr_to_virt(pa) ((void *)((paddr_t)(pa) | XEN_VIRT_START))
 
 /* Convert between Xen-heap virtual addresses and machine addresses. */
 #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();
+    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)
+
+#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)
Quoted 9 lines

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

Quoted 6 lines
xen/arch/ppc/include/asm/mm.h +6 -0
+#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 static memory */
+#define PGC_static     0

You don't need this.

Will drop.

Quoted 34 lines
Quoted 34 lines
xen/arch/ppc/include/asm/mm.h +34 -0
+/* 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) \
+    (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)))
+
+#define page_get_owner(_p)    (_p)->v.inuse.domain
Quoted 9 lines

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

Quoted 5 lines
xen/arch/ppc/include/asm/mm.h +5 -0
+#define page_set_owner(_p,_d) ((_p)->v.inuse.domain = (_d))
+
+/* TODO: implement */
+#define mfn_valid(mfn) ({ (void) (mfn); 0; })
+#define max_page ((unsigned long )0)

It's clear this is temporary, but it would still be nice if you could omit stray blanks.

With your max_page/total_pages common patch I can drop this entirely.

Quoted 7 lines
Quoted 7 lines
xen/arch/ppc/include/asm/monitor.h new file +4 -0
@@ -0,0 +1,48 @@
+/* Derived from xen/arch/arm/include/asm/monitor.h */
+#ifndef __ASM_PPC_MONITOR_H__
+#define __ASM_PPC_MONITOR_H__
+
Quoted 8 lines

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

Quoted 4 lines
xen/arch/ppc/include/asm/monitor.h new file +4 -0
+#include <public/domctl.h>
+
+#include <xen/sched.h>
+#include <public/domctl.h>

Judging from the contents of the file, you don't need either (and you certainly don't need public/domctl.h twice). Only xen/types.h looks to be needed right now.

The implementation of arch_monitor_get_capabilities uses XEN_DOMCTL_* macros defined in public/domctl.h. xen/errno.h is also needed for EOPNOTSUPP (it seemed to be getting included by sched.h). I'll drop the sched.h include as well as the duplicate public/domctl.h include though.

Quoted 14 lines
Quoted 14 lines
xen/arch/ppc/include/asm/numa.h new file +11 -0
@@ -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)
Quoted 9 lines

xen/arch/ppc/include/asm/numa.h line 17

Quoted 6 lines
xen/arch/ppc/include/asm/numa.h new file +6 -0
+
+/*
+ * 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;

At least "Arm" wants replacing in the comment, I think.

Good catch.

Quoted 12 lines

xen/arch/ppc/include/asm/percpu.h line 6

Quoted 9 lines
xen/arch/ppc/include/asm/percpu.h new file +6 -0
@@ -0,0 +1,26 @@
+#ifndef __PPC_PERCPU_H__
+#define __PPC_PERCPU_H__
+
+#ifndef __ASSEMBLY__
+
+#include <xen/types.h>

Looks like nothing in the file requires this.

You are correct. I'll drop it.

Quoted 11 lines
Quoted 11 lines
xen/arch/ppc/include/asm/procarea.h new file +8 -0
@@ -0,0 +1,38 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Quoted 9 lines

xen/arch/ppc/include/asm/procarea.h line 14

Quoted 6 lines
xen/arch/ppc/include/asm/procarea.h new file +6 -0
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

SPDX again please (and there's at least one more below).

Will fix.

Quoted 12 lines

xen/arch/ppc/include/asm/procarea.h line 24

Quoted 9 lines
xen/arch/ppc/include/asm/procarea.h new file +9 -0
+ * Copyright (C) IBM Corp. 2005
+ *
+ * Authors: Hollis Blanchard <[email protected]>
+ */
+
+#ifndef _ASM_PROCAREA_H_
+#define _ASM_PROCAREA_H_
+
+#include <xen/types.h>

Again nothing looks to require this.

Will remove.

Quoted 6 lines

xen/arch/ppc/include/asm/procarea.h line 27

Quoted 2 lines
xen/arch/ppc/include/asm/procarea.h new file +2 -0
+struct vcpu;
+struct gdb_state;

The later of these is unused below. The former is used, but in a way that would require a forward decl only in C++.

I'll drop them both.

Quoted 6 lines
Quoted 6 lines
xen/arch/ppc/include/asm/processor.h +0 -0
@@ -110,6 +110,10 @@
 /* Macro to adjust thread priority for hardware multithreading */
 #define HMT_very_low()  asm volatile ( "or %r31, %r31, %r31" )
 
Quoted 8 lines

xen/arch/ppc/include/asm/processor.h line 115

Quoted 3 lines
xen/arch/ppc/include/asm/processor.h +3 -0
+/* TODO: This isn't correct */
+#define cpu_to_core(_cpu)   (0)
+#define cpu_to_socket(_cpu) (0)

As mentioned elsewhere, please try to avoid leading underscores in macro parameter names (or macro local variables, just to mention it again in this context).

Will fix.

Quoted 16 lines

xen/arch/ppc/include/asm/processor.h static inline void noreturn die(void) · line 182

Quoted 5 lines
xen/arch/ppc/include/asm/processor.h +1 -0
@@ -175,6 +179,8 @@ static inline void noreturn die(void)
         HMT_very_low();
 }
 
+#define cpu_relax() asm volatile ( "or %r1, %r1, %r1; or %r2, %r2, %r2" )

Just like HMT_very_low() this could do with a comment explaining the "interesting" ORs (until such time when the assembler supports suitable mnemonics).

Quoted 6 lines
xen/arch/ppc/include/asm/regs.h +0 -0
@@ -23,6 +23,8 @@
 #ifndef _ASM_REG_DEFS_H_
 #define _ASM_REG_DEFS_H_
 
Quoted 8 lines

xen/arch/ppc/include/asm/regs.h line 30

Quoted 5 lines
xen/arch/ppc/include/asm/regs.h +2 -0
+#include <xen/types.h>
+
 /* Special Purpose Registers */
 #define SPRN_VRSAVE 256
 #define SPRN_DSISR  18

Why would this #include be needed here all of the sudden?

This was a stray change I forgot to remove. Will fix.

Quoted 28 lines
Quoted 28 lines
xen/arch/ppc/include/asm/system.h +22 -0
@@ -1,6 +1,247 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * 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 4 lines

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

Quoted 2 lines
xen/arch/ppc/include/asm/system.h +1 -1
-#define smp_wmb() __asm__ __volatile__ ( "lwsync" : : : "memory" )
+#include <xen/config.h>

As mentioned before - any such #include you find is a leftover.

Will update.

Quoted 1 line

Jan

Thanks,
Shawn

#18 lore raw

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

Quoted 16 lines · Shawn Anastasio
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Shawn Anastasio
xen/arch/ppc/include/asm/bug.h +0 -0
@@ -15,4 +16,10 @@
 
 #define BUG_FN_REG r0
 
Quoted 9 lines

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

Quoted 3 lines
xen/arch/ppc/include/asm/bug.h +3 -0
+#define BUG() do { \
+    die(); \
+} while (0)

This looks like it's temporary. I think any construct that later needs updating wants marking in some common way (such that it's easy to grep for items left to be dealt with; you have such a comment in e.g. asm/event.h). Of course if an entire header consists of _only_ stubs, perhaps a single such comment would suffice.

Quoted 5 lines

Yes, agreed that this macro deserves a TODO comment.

As for the rest of the stub functions that this patch implements, are you suggesting that each file with stubs should contain a similar comment?

Well, each one needs to be (and remain) easily identifiable.

Quoted 3 lines

Another alternative that I thought of would be to define a BUG_UNIMPLEMENTED() macro or similar and call that inside of all the stub functions.

I like this. Or maybe BUG_ON("unimplemented") could also be an option; not sure though if the compiler wouldn't complain about the resulting if ( unlikely("unimplemented") ).

Jan

#19 lore raw

PATCH 6/9 ns16550: Guard accesses to `vuart` field by CONFIG_ARM

In reply to Shawn Anastasio

When CONFIG_ARM is defined, a vuart field is added to struct ns16550, but accesses to this field in ns16550_uart_dt_init weren't correctly guarded. Fix build on !ARM platforms that define CONFIG_HAS_DEVICE_TREE by correctly guarding access to the vuart field in this function.

---
 xen/drivers/char/ns16550.c | 2 ++
 1 file changed, 2 insertions(+)
xen/drivers/char/ns16550.c +2 -0
index 212a9c49ae..c0598efb27 100644
@@ -1797,11 +1797,13 @@ static int __init ns16550_uart_dt_init(struct dt_device_node *dev,
 
     uart->dw_usr_bsy = dt_device_is_compatible(dev, "snps,dw-apb-uart");
 
+#ifdef CONFIG_ARM
     uart->vuart.base_addr = uart->io_base;
     uart->vuart.size = uart->io_size;
     uart->vuart.data_off = UART_THR <<uart->reg_shift;
     uart->vuart.status_off = UART_LSR<<uart->reg_shift;
     uart->vuart.status = UART_LSR_THRE|UART_LSR_TEMT;
+#endif
 
     /* Register with generic serial driver. */
     serial_register_uart(uart - ns16550_com, &ns16550_driver, uart);
Signature · 1 line
2.30.2
Reviewed-by on v1 6/9
#20 lore raw

Re: [PATCH 6/9] ns16550: Guard accesses to `vuart` field by CONFIG_ARM

Quoted 6 lines · Shawn Anastasio

When CONFIG_ARM is defined, a vuart field is added to struct ns16550, but accesses to this field in ns16550_uart_dt_init weren't correctly guarded. Fix build on !ARM platforms that define CONFIG_HAS_DEVICE_TREE by correctly guarding access to the vuart field in this function.

#21 lore raw

PATCH 7/9 xen/ppc: Define bug frames table in linker script

In reply to Shawn Anastasio

Define the bug frames table in ppc's linker script as is done by other architectures.

---
 xen/arch/ppc/xen.lds.S | 10 ++++++++++
 1 file changed, 10 insertions(+)
xen/arch/ppc/xen.lds.S +10 -0
index 2fa81d5a83..692aa34add 100644
@@ -41,6 +41,16 @@ SECTIONS
     . = ALIGN(PAGE_SIZE);
     .rodata : {
         _srodata = .;          /* Read-only data */
+        /* Bug frames table */
+       __start_bug_frames = .;
+       *(.bug_frames.0)
+       __stop_bug_frames_0 = .;
+       *(.bug_frames.1)
+       __stop_bug_frames_1 = .;
+       *(.bug_frames.2)
+       __stop_bug_frames_2 = .;
+       *(.bug_frames.3)
+       __stop_bug_frames_3 = .;
         *(.rodata)
         *(.rodata.*)
         *(.data.rel.ro)
Signature · 1 line
2.30.2
Acked-by on v1 7/9
#22 lore raw

Re: [PATCH 7/9] xen/ppc: Define bug frames table in linker script

Quoted 9 lines · Shawn Anastasio
xen/arch/ppc/xen.lds.S +3 -0
@@ -41,6 +41,16 @@ SECTIONS
     . = ALIGN(PAGE_SIZE);
     .rodata : {
         _srodata = .;          /* Read-only data */
+        /* Bug frames table */
+       __start_bug_frames = .;
+       *(.bug_frames.0)

xen/arch/ppc/xen.lds.S SECTIONS · line 56

Quoted 10 lines
xen/arch/ppc/xen.lds.S +7 -0
+       __stop_bug_frames_0 = .;
+       *(.bug_frames.1)
+       __stop_bug_frames_1 = .;
+       *(.bug_frames.2)
+       __stop_bug_frames_2 = .;
+       *(.bug_frames.3)
+       __stop_bug_frames_3 = .;
         *(.rodata)
         *(.rodata.*)
         *(.data.rel.ro)

Looks like the added lines are indented by one too few blanks. With that adjusted:

Jan

#23 lore raw

PATCH 8/9 xen/ppc: Add stub function and symbol definitions

In reply to Shawn Anastasio

Add stub function and symbol definitions required by common code. If the file that the definition is supposed to be located in doesn't already exist yet, temporarily place its definition in the new stubs.c

---
 xen/arch/ppc/Makefile   |   1 +
 xen/arch/ppc/mm-radix.c |  44 +++++
 xen/arch/ppc/setup.c    |  10 +-
 xen/arch/ppc/stubs.c    | 351 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 404 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/ppc/stubs.c
xen/arch/ppc/Makefile +1 -0
index a059ac4c0a..969910b3b6 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_EARLY_PRINTK) += early_printk.init.o
 obj-y += mm-radix.o
 obj-y += opal.o
 obj-y += setup.o
+obj-y += stubs.o
 obj-y += tlb-radix.o
 
 $(TARGET): $(TARGET)-syms
xen/arch/ppc/mm-radix.c +44 -0

47 lines not on this page · raw message

xen/arch/ppc/setup.c +8 -2
index 466993987b..06c0a5fa80 100644
@@ -1,5 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <xen/lib.h>
 #include <xen/init.h>
+#include <xen/mm.h>
+#include <public/version.h>
 #include <asm/boot.h>
 #include <asm/early_printk.h>
 #include <asm/processor.h>
@@ -7,8 +10,6 @@
 /* Xen stack for bringing up the first CPU. */
 unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE);
 
-void __init setup_initial_pagetables(void);
-
 void __init noreturn start_xen(unsigned long r3, unsigned long r4,
                                unsigned long r5, unsigned long r6,
                                unsigned long r7)
@@ -39,3 +40,8 @@ void __init noreturn start_xen(unsigned long r3, unsigned long r4,
 
     unreachable();
 }
+
+void arch_get_xen_caps(xen_capabilities_info_t *info)
+{
+    BUG();
+}
xen/arch/ppc/stubs.c new file +351 -0

351 lines not on this page · raw message

Signature · 1 line
2.30.2
#24 lore raw

Re: [PATCH 8/9] xen/ppc: Add stub function and symbol definitions

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 270

Quoted 8 lines · Shawn Anastasio
xen/arch/ppc/mm-radix.c +2 -0
@@ -266,3 +266,47 @@ void __init setup_initial_pagetables(void)
     /* Turn on the MMU */
     enable_mmu();
 }
+
+

Nit: No double blank lines please.

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 274

Quoted 4 lines
xen/arch/ppc/mm-radix.c +4 -0
+/*
+ * TODO: Implement the functions below
+ */
+unsigned long total_pages;

Hmm, yet one more prereq patch for me to make: There should be no need for every arch to have a definition, when common code requires the variable. While looking there I found max_page, which common code references as well. I'm surprised you get away without. I guess I'll learn why that is when making the patch moving both.

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 275

Quoted 1 line
xen/arch/ppc/mm-radix.c +1 -0
+unsigned long frametable_base_pdx __read_mostly;

While we still have many instances like this, we prefer this form:

unsigned long __read_mostly frametable_base_pdx;

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 285

Quoted 10 lines
xen/arch/ppc/mm-radix.c +10 -0
+
+void put_page(struct page_info *p)
+{
+    BUG();
+}
+
+void arch_dump_shared_mem_info(void)
+{
+    BUG();
+}

And perhaps one further prereq patch to avoid the need for this.

Quoted 8 lines
xen/arch/ppc/mm-radix.c +8 -0
+int xenmem_add_to_physmap_one(struct domain *d,
+                              unsigned int space,
+                              union add_to_physmap_extra extra,
+                              unsigned long idx,
+                              gfn_t gfn)
+{
+    BUG();
+}

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 304

Quoted 10 lines
xen/arch/ppc/mm-radix.c +10 -0
+
+int destroy_xen_mappings(unsigned long s, unsigned long e)
+{
+    BUG();
+}
+
+int map_pages_to_xen(unsigned long virt,
+                     mfn_t mfn,
+                     unsigned long nr_mfns,
+                     unsigned int flags)

There's a patch in flight regarding the naming of this last parameter. I guess PPC would best be in sync right away.

xen/arch/ppc/setup.c line 8

Quoted 11 lines
xen/arch/ppc/setup.c +3 -0
@@ -1,5 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <xen/lib.h>
 #include <xen/init.h>
+#include <xen/mm.h>
+#include <public/version.h>
 #include <asm/boot.h>
 #include <asm/early_printk.h>
 #include <asm/processor.h>

There's no need for xen/lib.h to come ahead of xen/init.h, is there?

Quoted 13 lines
xen/arch/ppc/stubs.c new file +9 -0
@@ -0,0 +1,351 @@
[...]
+static void ack_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+static void end_none(struct irq_desc *irq)
+{
+    BUG();
+}

xen/arch/ppc/stubs.c line 163

Quoted 10 lines
xen/arch/ppc/stubs.c new file +10 -0
+
+hw_irq_controller no_irq_type = {
+    .typename = "none",
+    .startup = irq_startup_none,
+    .shutdown = irq_shutdown_none,
+    .enable = irq_enable_none,
+    .disable = irq_disable_none,
+    .ack = ack_none,
+    .end = end_none
+};

I would recommend to avoid filling pointers (and hence having private hook functions) where it's not clear whether they'll be required. "end", for example, is an optional hook on x86. Iirc common code doesn't use any of the hooks.

Jan

#25 lore raw

Re: [PATCH 8/9] xen/ppc: Add stub function and symbol definitions

Quoted 12 lines · Jan Beulich

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 270

Quoted 8 lines · Shawn Anastasio
xen/arch/ppc/mm-radix.c +2 -0
@@ -266,3 +266,47 @@ void __init setup_initial_pagetables(void)
     /* Turn on the MMU */
     enable_mmu();
 }
+
+

Nit: No double blank lines please.

Will fix.

Quoted 11 lines

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 274

Quoted 4 lines
xen/arch/ppc/mm-radix.c +4 -0
+/*
+ * TODO: Implement the functions below
+ */
+unsigned long total_pages;

Hmm, yet one more prereq patch for me to make: There should be no need for every arch to have a definition, when common code requires the variable. While looking there I found max_page, which common code references as well. I'm surprised you get away without. I guess I'll learn why that is when making the patch moving both.

Since your patch for this has gone though, I'll drop this in v2.

Quoted 6 lines

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 275

Quoted 1 line
xen/arch/ppc/mm-radix.c +1 -0
+unsigned long frametable_base_pdx __read_mostly;

While we still have many instances like this, we prefer this form:

unsigned long __read_mostly frametable_base_pdx;

Will update.

Quoted 4 lines
Quoted 4 lines
xen/arch/ppc/mm-radix.c +4 -0
+
+void put_page(struct page_info *p)
+{
+    BUG();
Quoted 9 lines

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 285

Quoted 6 lines
xen/arch/ppc/mm-radix.c +6 -0
+}
+
+void arch_dump_shared_mem_info(void)
+{
+    BUG();
+}

And perhaps one further prereq patch to avoid the need for this.

Will remove from this series pending merge of your prereq patch.

Quoted 13 lines
Quoted 13 lines
xen/arch/ppc/mm-radix.c +13 -0
+int xenmem_add_to_physmap_one(struct domain *d,
+                              unsigned int space,
+                              union add_to_physmap_extra extra,
+                              unsigned long idx,
+                              gfn_t gfn)
+{
+    BUG();
+}
+
+int destroy_xen_mappings(unsigned long s, unsigned long e)
+{
+    BUG();
+}
Quoted 9 lines

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 304

Quoted 5 lines
xen/arch/ppc/mm-radix.c +5 -0
+
+int map_pages_to_xen(unsigned long virt,
+                     mfn_t mfn,
+                     unsigned long nr_mfns,
+                     unsigned int flags)

There's a patch in flight regarding the naming of this last parameter. I guess PPC would best be in sync right away.

I can't seem to find the patch in question and it doesn't seem like it has been merged in the meantime. Could you provide a link?

Quoted 5 lines
Quoted 5 lines
xen/arch/ppc/setup.c +1 -0
@@ -1,5 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <xen/lib.h>
Quoted 9 lines

xen/arch/ppc/setup.c line 8

Quoted 6 lines
xen/arch/ppc/setup.c +2 -0
 #include <xen/init.h>
+#include <xen/mm.h>
+#include <public/version.h>
 #include <asm/boot.h>
 #include <asm/early_printk.h>
 #include <asm/processor.h>

There's no need for xen/lib.h to come ahead of xen/init.h, is there?

There is not -- I'll fix the ordering.

Quoted 20 lines
Quoted 20 lines
xen/arch/ppc/stubs.c new file +16 -0
@@ -0,0 +1,351 @@
[...]
+static void ack_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+static void end_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+hw_irq_controller no_irq_type = {
+    .typename = "none",
+    .startup = irq_startup_none,
+    .shutdown = irq_shutdown_none,
+    .enable = irq_enable_none,
+    .disable = irq_disable_none,
Quoted 9 lines

xen/arch/ppc/stubs.c line 163

Quoted 3 lines
xen/arch/ppc/stubs.c new file +3 -0
+    .ack = ack_none,
+    .end = end_none
+};

I would recommend to avoid filling pointers (and hence having private hook functions) where it's not clear whether they'll be required. "end", for example, is an optional hook on x86. Iirc common code doesn't use any of the hooks.

Alright, I'll drop the end_none stub and leave the .end pointer as NULL.

Quoted 1 line

Jan

Thanks,
Shawn

#26 lore raw

Re: [PATCH 8/9] xen/ppc: Add stub function and symbol definitions

Quoted 7 lines · Shawn Anastasio
Quoted 6 lines · Jan Beulich
Quoted 4 lines · Shawn Anastasio
xen/arch/ppc/mm-radix.c +4 -0
+int map_pages_to_xen(unsigned long virt,
+                     mfn_t mfn,
+                     unsigned long nr_mfns,
+                     unsigned int flags)
Quoted 6 lines
Quoted 3 lines

There's a patch in flight regarding the naming of this last parameter. I guess PPC would best be in sync right away.

I can't seem to find the patch in question and it doesn't seem like it has been merged in the meantime. Could you provide a link?

Looks like I was misremembering, and it was modify_xen_mappings() instead. I'm sorry for the noise.

Quoted 29 lines
Quoted 20 lines
Quoted 20 lines
xen/arch/ppc/stubs.c new file +16 -0
@@ -0,0 +1,351 @@
[...]
+static void ack_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+static void end_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+hw_irq_controller no_irq_type = {
+    .typename = "none",
+    .startup = irq_startup_none,
+    .shutdown = irq_shutdown_none,
+    .enable = irq_enable_none,
+    .disable = irq_disable_none,
Quoted 8 lines

xen/arch/ppc/stubs.c line 163

Quoted 3 lines
xen/arch/ppc/stubs.c new file +3 -0
+    .ack = ack_none,
+    .end = end_none
+};

I would recommend to avoid filling pointers (and hence having private hook functions) where it's not clear whether they'll be required. "end", for example, is an optional hook on x86. Iirc common code doesn't use any of the hooks.

Quoted 2 lines

Alright, I'll drop the end_none stub and leave the .end pointer as NULL.

Yet my comment was about all the (presently dead) hook functions.

Jan

#27 lore raw

Re: [PATCH 8/9] xen/ppc: Add stub function and symbol definitions

Quoted 12 lines · Jan Beulich
Quoted 11 lines · Shawn Anastasio
Quoted 9 lines · Jan Beulich

xen/arch/ppc/mm-radix.c void __init setup_initial_pagetables(void) · line 304

Quoted 4 lines · Shawn Anastasio
xen/arch/ppc/mm-radix.c +4 -0
+int map_pages_to_xen(unsigned long virt,
+                     mfn_t mfn,
+                     unsigned long nr_mfns,
+                     unsigned int flags)

There's a patch in flight regarding the naming of this last parameter. I guess PPC would best be in sync right away.

Quoted 6 lines
Quoted 2 lines

I can't seem to find the patch in question and it doesn't seem like it has been merged in the meantime. Could you provide a link?

Looks like I was misremembering, and it was modify_xen_mappings() instead. I'm sorry for the noise.

No problem.

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 13 lines
xen/arch/ppc/stubs.c new file +9 -0
@@ -0,0 +1,351 @@
[...]
+static void ack_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+static void end_none(struct irq_desc *irq)
+{
+    BUG();
+}

xen/arch/ppc/stubs.c line 163

Quoted 10 lines
xen/arch/ppc/stubs.c new file +10 -0
+
+hw_irq_controller no_irq_type = {
+    .typename = "none",
+    .startup = irq_startup_none,
+    .shutdown = irq_shutdown_none,
+    .enable = irq_enable_none,
+    .disable = irq_disable_none,
+    .ack = ack_none,
+    .end = end_none
+};

I would recommend to avoid filling pointers (and hence having private hook functions) where it's not clear whether they'll be required. "end", for example, is an optional hook on x86. Iirc common code doesn't use any of the hooks.

Quoted 4 lines
Quoted 2 lines

Alright, I'll drop the end_none stub and leave the .end pointer as NULL.

Yet my comment was about all the (presently dead) hook functions.

Sorry, I misunderstood. To clarify, by "hook functions" you're referring to all of the function pointer fields of hw_irq_controller? Are all users of this struct going to properly check for NULL before trying to call these function pointers?

Quoted 1 line

Jan

Thanks,
Shawn

#28 lore raw

Re: [PATCH 8/9] xen/ppc: Add stub function and symbol definitions

Quoted 36 lines · Shawn Anastasio
Quoted 35 lines · Jan Beulich
Quoted 33 lines · Shawn Anastasio
Quoted 21 lines · Jan Beulich
Quoted 20 lines · Shawn Anastasio
xen/arch/ppc/stubs.c new file +16 -0
@@ -0,0 +1,351 @@
[...]
+static void ack_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+static void end_none(struct irq_desc *irq)
+{
+    BUG();
+}
+
+hw_irq_controller no_irq_type = {
+    .typename = "none",
+    .startup = irq_startup_none,
+    .shutdown = irq_shutdown_none,
+    .enable = irq_enable_none,
+    .disable = irq_disable_none,
Quoted 8 lines

xen/arch/ppc/stubs.c line 163

Quoted 3 lines
xen/arch/ppc/stubs.c new file +3 -0
+    .ack = ack_none,
+    .end = end_none
+};

I would recommend to avoid filling pointers (and hence having private hook functions) where it's not clear whether they'll be required. "end", for example, is an optional hook on x86. Iirc common code doesn't use any of the hooks.

Alright, I'll drop the end_none stub and leave the .end pointer as NULL.

Quoted 6 lines
Quoted 1 line

Yet my comment was about all the (presently dead) hook functions.

Sorry, I misunderstood. To clarify, by "hook functions" you're referring to all of the function pointer fields of hw_irq_controller? Are all users of this struct going to properly check for NULL before trying to call these function pointers?

If I'm not mistaken, all uses of these hooks are in arch-specific code (we don't have a proper common layer, unlike Linux). Hence what checks there are going to be is all up to you. But as long as none of the fields are used, supplying (stub) hooks is pointless in the first place. IOW you can leave the pointers at NULL now and still use them later without checks, so long as at _that_ time you populate them (and then not just pointing to stub functions).

My main point here is: This introduction of temporary stubs would better be as little overhead and as little code churn as possible - minimum number of new symbols/functions/objects, just enough for things to build.

Jan

#29 lore raw

PATCH 9/9 xen/ppc: Enable full Xen build

In reply to Shawn Anastasio

Bring ppc's Makefile and arch.mk in line with arm and x86 to disable the build overrides and enable the full Xen build.

---
 xen/arch/ppc/Makefile | 16 +++++++++++++++-
 xen/arch/ppc/arch.mk  |  3 ---
 2 files changed, 15 insertions(+), 4 deletions(-)
xen/arch/ppc/Makefile +15 -1
index 969910b3b6..7b68b5ace2 100644
@@ -12,10 +12,24 @@ $(TARGET): $(TARGET)-syms
 	cp -f $< $@
 
 $(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) -o $@
+	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< \
+	    $(objtree)/common/symbols-dummy.o -o $(dot-target).0
+	$(NM) -pa --format=sysv $(dot-target).0 \
+		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+		> $(dot-target).0.S
+	$(MAKE) $(build)=$(@D) $(dot-target).0.o
+	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< \
+	    $(dot-target).0.o -o $(dot-target).1
+	$(NM) -pa --format=sysv $(dot-target).1 \
+		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+		> $(dot-target).1.S
+	$(MAKE) $(build)=$(@D) $(dot-target).1.o
+	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) \
+	    $(dot-target).1.o -o $@
 	$(NM) -pa --format=sysv $@ \
 		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
 		> [email protected]
+	rm -f $(@D)/.$(@F).[0-9]*
 
 $(obj)/xen.lds: $(src)/xen.lds.S FORCE
 	$(call if_changed_dep,cpp_lds_S)
xen/arch/ppc/arch.mk +0 -3
index d05cbf1df5..917ad0e6a8 100644
@@ -7,6 +7,3 @@ CFLAGS += -m64 -mlittle-endian -mcpu=$(ppc-march-y)
 CFLAGS += -mstrict-align -mcmodel=medium -mabi=elfv2 -fPIC -mno-altivec -mno-vsx -msoft-float
 
 LDFLAGS += -m elf64lppc
-
-# TODO: Drop override when more of the build is working
-override ALL_OBJS-y = arch/$(SRCARCH)/built_in.o common/libfdt/built_in.o lib/built_in.o
Signature · 1 line
2.30.2