From: Jan Kiszka <[email protected]>

Same reasoning and some strategy as for arm: pull the exception code
into entry.S. This allows to shutdown_el2 to fall through to vmreturn.
asm/setup.h effectively becomes the new entry.h here.

Signed-off-by: Jan Kiszka <[email protected]>
---
 hypervisor/arch/arm64/Kbuild                       |  3 +-
 hypervisor/arch/arm64/entry.S                      | 80 +++++++++++++++++-
 hypervisor/arch/arm64/exception.S                  | 98 ----------------------
 hypervisor/arch/arm64/include/asm/control.h        |  3 -
 .../arch/arm64/include/asm/{setup.h => entry.h}    | 10 +--
 hypervisor/arch/arm64/setup.c                      |  2 +-
 hypervisor/arch/arm64/traps.c                      |  1 +
 7 files changed, 86 insertions(+), 111 deletions(-)
 delete mode 100644 hypervisor/arch/arm64/exception.S
 rename hypervisor/arch/arm64/include/asm/{setup.h => entry.h} (57%)

diff --git a/hypervisor/arch/arm64/Kbuild b/hypervisor/arch/arm64/Kbuild
index 91c2a912..26b9ff36 100644
--- a/hypervisor/arch/arm64/Kbuild
+++ b/hypervisor/arch/arm64/Kbuild
@@ -17,5 +17,4 @@ include $(src)/../arm-common/Kbuild
 always := built-in.o
 
 obj-y := $(COMMON_OBJECTS)
-obj-y += entry.o setup.o control.o mmio.o caches.o
-obj-y += exception.o traps.o
+obj-y += entry.o setup.o control.o mmio.o caches.o traps.o
diff --git a/hypervisor/arch/arm64/entry.S b/hypervisor/arch/arm64/entry.S
index ff57c79e..61c5dc49 100644
--- a/hypervisor/arch/arm64/entry.S
+++ b/hypervisor/arch/arm64/entry.S
@@ -272,6 +272,59 @@ bootstrap_vectors:
        ventry  .
 
 
+.macro handle_vmexit exit_reason
+       .align  7
+       /* Fill the struct registers. Should comply with NUM_USR_REGS */
+       stp     x29, x30, [sp, #-16]!
+       stp     x27, x28, [sp, #-16]!
+       stp     x25, x26, [sp, #-16]!
+       stp     x23, x24, [sp, #-16]!
+       stp     x21, x22, [sp, #-16]!
+       stp     x19, x20, [sp, #-16]!
+       stp     x17, x18, [sp, #-16]!
+       stp     x15, x16, [sp, #-16]!
+       stp     x13, x14, [sp, #-16]!
+       stp     x11, x12, [sp, #-16]!
+       stp     x9, x10, [sp, #-16]!
+       stp     x7, x8, [sp, #-16]!
+       stp     x5, x6, [sp, #-16]!
+       stp     x3, x4, [sp, #-16]!
+       stp     x1, x2, [sp, #-16]!
+
+       mov     x1, #\exit_reason
+       stp     x1, x0, [sp, #-16]!
+
+       mov     x29, xzr        /* reset fp,lr */
+       mov     x30, xzr
+       mrs     x0, tpidr_el2
+       mov     x1, sp
+       bl      arch_handle_exit
+       b       .
+.endm
+
+       .align 11
+hyp_vectors:
+       ventry  .
+       ventry  .
+       ventry  .
+       ventry  .
+
+       handle_vmexit EXIT_REASON_EL2_ABORT
+       ventry  .
+       ventry  .
+       ventry  .
+
+       handle_vmexit EXIT_REASON_EL1_ABORT
+       handle_vmexit EXIT_REASON_EL1_IRQ
+       ventry  .
+       ventry  .
+
+       ventry  .
+       ventry  .
+       ventry  .
+       ventry  .
+
+
        .pushsection    .trampoline, "ax"
        .globl enable_mmu_el2
 enable_mmu_el2:
@@ -337,7 +390,30 @@ shutdown_el2:
 
        msr     tpidr_el2, xzr
 
-       /* Call vmreturn(guest_registers) */
+       /* Prepare continuation as vmreturn(guest_registers). */
        add     x0, x0, #(PERCPU_STACK_END - 32 * 8)
-       b       vmreturn
+
+       /* Fall through to vmreturn */
+
+       .globl vmreturn
+vmreturn:
+       /* x0: struct registers* */
+       mov     sp, x0
+       ldp     x1, x0, [sp], #16       /* x1 is the exit_reason */
+       ldp     x1, x2, [sp], #16
+       ldp     x3, x4, [sp], #16
+       ldp     x5, x6, [sp], #16
+       ldp     x7, x8, [sp], #16
+       ldp     x9, x10, [sp], #16
+       ldp     x11, x12, [sp], #16
+       ldp     x13, x14, [sp], #16
+       ldp     x15, x16, [sp], #16
+       ldp     x17, x18, [sp], #16
+       ldp     x19, x20, [sp], #16
+       ldp     x21, x22, [sp], #16
+       ldp     x23, x24, [sp], #16
+       ldp     x25, x26, [sp], #16
+       ldp     x27, x28, [sp], #16
+       ldp     x29, x30, [sp], #16
+       eret
        .popsection
diff --git a/hypervisor/arch/arm64/exception.S 
b/hypervisor/arch/arm64/exception.S
deleted file mode 100644
index 3e5d8eb9..00000000
--- a/hypervisor/arch/arm64/exception.S
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Jailhouse AArch64 support
- *
- * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
- *
- * Authors:
- *  Antonios Motakis <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
- */
-
-#include <asm/processor.h>
-#include <asm/sysregs.h>
-
-.macro ventry  label
-       .align  7
-       b       \label
-.endm
-
-.macro handle_vmexit exit_reason
-       .align  7
-       /* Fill the struct registers. Should comply with NUM_USR_REGS */
-       stp     x29, x30, [sp, #-16]!
-       stp     x27, x28, [sp, #-16]!
-       stp     x25, x26, [sp, #-16]!
-       stp     x23, x24, [sp, #-16]!
-       stp     x21, x22, [sp, #-16]!
-       stp     x19, x20, [sp, #-16]!
-       stp     x17, x18, [sp, #-16]!
-       stp     x15, x16, [sp, #-16]!
-       stp     x13, x14, [sp, #-16]!
-       stp     x11, x12, [sp, #-16]!
-       stp     x9, x10, [sp, #-16]!
-       stp     x7, x8, [sp, #-16]!
-       stp     x5, x6, [sp, #-16]!
-       stp     x3, x4, [sp, #-16]!
-       stp     x1, x2, [sp, #-16]!
-
-       mov     x1, #\exit_reason
-       stp     x1, x0, [sp, #-16]!
-
-       mov     x29, xzr        /* reset fp,lr */
-       mov     x30, xzr
-       mrs     x0, tpidr_el2
-       mov     x1, sp
-       bl      arch_handle_exit
-       b       .
-.endm
-
-       .text
-       .globl hyp_vectors
-       .align 11
-hyp_vectors:
-       ventry  .
-       ventry  .
-       ventry  .
-       ventry  .
-
-       handle_vmexit EXIT_REASON_EL2_ABORT
-       ventry  .
-       ventry  .
-       ventry  .
-
-       handle_vmexit EXIT_REASON_EL1_ABORT
-       handle_vmexit EXIT_REASON_EL1_IRQ
-       ventry  .
-       ventry  .
-
-       ventry  .
-       ventry  .
-       ventry  .
-       ventry  .
-
-
-       .pushsection .trampoline, "ax"
-       .globl vmreturn
-vmreturn:
-       /* x0: struct registers* */
-       mov     sp, x0
-       ldp     x1, x0, [sp], #16       /* x1 is the exit_reason */
-       ldp     x1, x2, [sp], #16
-       ldp     x3, x4, [sp], #16
-       ldp     x5, x6, [sp], #16
-       ldp     x7, x8, [sp], #16
-       ldp     x9, x10, [sp], #16
-       ldp     x11, x12, [sp], #16
-       ldp     x13, x14, [sp], #16
-       ldp     x15, x16, [sp], #16
-       ldp     x17, x18, [sp], #16
-       ldp     x19, x20, [sp], #16
-       ldp     x21, x22, [sp], #16
-       ldp     x23, x24, [sp], #16
-       ldp     x25, x26, [sp], #16
-       ldp     x27, x28, [sp], #16
-       ldp     x29, x30, [sp], #16
-       eret
-       .popsection
diff --git a/hypervisor/arch/arm64/include/asm/control.h 
b/hypervisor/arch/arm64/include/asm/control.h
index 014c3d7a..904eb4ea 100644
--- a/hypervisor/arch/arm64/include/asm/control.h
+++ b/hypervisor/arch/arm64/include/asm/control.h
@@ -32,9 +32,6 @@ void arch_reset_self(struct per_cpu *cpu_data);
 void arch_shutdown_self(struct per_cpu *cpu_data);
 unsigned int arm_cpu_by_mpidr(struct cell *cell, unsigned long mpidr);
 
-void __attribute__((noreturn)) vmreturn(struct registers *guest_regs);
-void __attribute__((noreturn)) shutdown_el2(struct per_cpu *cpu_data);
-
 void arm_cpu_reset(unsigned long pc);
 void arm_cpu_park(void);
 void arm_cpu_kick(unsigned int cpu_id);
diff --git a/hypervisor/arch/arm64/include/asm/setup.h 
b/hypervisor/arch/arm64/include/asm/entry.h
similarity index 57%
rename from hypervisor/arch/arm64/include/asm/setup.h
rename to hypervisor/arch/arm64/include/asm/entry.h
index 81161f85..0aa3a227 100644
--- a/hypervisor/arch/arm64/include/asm/setup.h
+++ b/hypervisor/arch/arm64/include/asm/entry.h
@@ -2,19 +2,19 @@
  * Jailhouse AArch64 support
  *
  * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ * Copyright (c) Siemens AG, 2017
  *
  * Authors:
  *  Antonios Motakis <[email protected]>
+ *  Jan Kiszka <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2.  See
  * the COPYING file in the top-level directory.
  */
 
-#ifndef _JAILHOUSE_ASM_SETUP_H
-#define _JAILHOUSE_ASM_SETUP_H
-
-#include <jailhouse/types.h>
+#include <asm/percpu.h>
 
 void enable_mmu_el2(u64 ttbr0_el2);
+void __attribute__((noreturn)) shutdown_el2(struct per_cpu *cpu_data);
 
-#endif /* !_JAILHOUSE_ASM_SETUP_H */
+void __attribute__((noreturn)) vmreturn(struct registers *guest_regs);
diff --git a/hypervisor/arch/arm64/setup.c b/hypervisor/arch/arm64/setup.c
index e46f5bee..f304a4e1 100644
--- a/hypervisor/arch/arm64/setup.c
+++ b/hypervisor/arch/arm64/setup.c
@@ -16,8 +16,8 @@
 #include <jailhouse/printk.h>
 #include <jailhouse/processor.h>
 #include <asm/control.h>
+#include <asm/entry.h>
 #include <asm/irqchip.h>
-#include <asm/setup.h>
 #include <asm/setup-common.h>
 
 extern u8 __trampoline_start[];
diff --git a/hypervisor/arch/arm64/traps.c b/hypervisor/arch/arm64/traps.c
index 4a35d0d5..cd309233 100644
--- a/hypervisor/arch/arm64/traps.c
+++ b/hypervisor/arch/arm64/traps.c
@@ -14,6 +14,7 @@
 #include <jailhouse/control.h>
 #include <jailhouse/printk.h>
 #include <asm/control.h>
+#include <asm/entry.h>
 #include <asm/gic.h>
 #include <asm/mmio.h>
 #include <asm/psci.h>
-- 
2.12.3

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to