Skip to contentSkip to conversation

xen/arm: Implement the hypercall handling in assembly

RFC In review Julien Grall 3 participants 13 messages Dec 15, 2015 – Dec 16, 2015

lore
Share & tools
lore
#0 lore raw

cover xen/arm: Implement the hypercall handling in assembly

Hi all,

This patch aims is a first attempt to write the hypercall dispatch in assembly in order to avoid reloading the hypercall arguments from the stack.

I've posted an early version to get comments and only the ARM64 side has been implemented.

A branch with the code can be found here:

git://xenbits.xen.org/people/julieng/xen-unstable.git branch asm-hypercall-rfc

Sincerely yours,

Julien Grall (10):
xen/arm: move lr, push and pop in a separate header xen/arm: Drop unused defines in asm/bug.h
xen/arm: Implement assembly version of WARN/BUG/ASSERT_FAILED... xen/arm64: Add an assembly macro for perf counter xen/arm: gic_inject: Introduce a local variable to store current xen/arm: gic: Allow the LRs to be cleared lazily xen/arm: Implement the code to dispatch the hypercall in assembly xen/arm64: Implement the hypercall handing fully in assembly xen/arm: Remove the C version of do_trap_hypercall xen/arm: Factorize the C code to dispatch HVC

 xen/arch/arm/Makefile                 |   1 +
 xen/arch/arm/arm64/Makefile           |   1 +
 xen/arch/arm/arm64/asm-offsets.c      |  11 +++
 xen/arch/arm/arm64/entry.S            | 165 +++++++++++++++++++++++++++++----
 xen/arch/arm/arm64/hypercall.S        |  27 ++++++
 xen/arch/arm/gic.c                    |  17 +++-
 xen/arch/arm/hypercall.S              |  88 ++++++++++++++++++
 xen/arch/arm/traps.c                  | 167 +++++-----------------------------
 xen/include/asm-arm/arm64/asm_defns.h |  62 +++++++++++++
 xen/include/asm-arm/arm64/bug.h       |   4 +
 xen/include/asm-arm/asm_defns.h       |   3 +
 xen/include/asm-arm/bug.h             |  39 ++++++--
 xen/include/asm-arm/domain.h          |   7 +-
 xen/include/asm-arm/hypercall.h       |   9 ++
 xen/include/asm-arm/processor.h       |   3 +
 15 files changed, 432 insertions(+), 172 deletions(-)
 create mode 100644 xen/arch/arm/arm64/hypercall.S
 create mode 100644 xen/arch/arm/hypercall.S
 create mode 100644 xen/include/asm-arm/arm64/asm_defns.h
Signature · 1 line
2.1.4
#1 lore raw

RFC 1/10 xen/arm: move lr, push and pop in a separate header

The shorthand lr and the macros push/pop are useful for any assembly code.

Move them in asm/arm64/asm_defns.h

---
 xen/arch/arm/arm64/entry.S            | 17 -----------------
 xen/include/asm-arm/arm64/asm_defns.h | 26 ++++++++++++++++++++++++++
 xen/include/asm-arm/asm_defns.h       |  3 +++
 3 files changed, 29 insertions(+), 17 deletions(-)
 create mode 100644 xen/include/asm-arm/arm64/asm_defns.h
xen/arch/arm/arm64/entry.S +0 -17
index 9cda8f1..2b9d4cd 100644
@@ -4,23 +4,6 @@
 #include <public/xen.h>
 
 /*
- * Register aliases.
- */
-lr      .req    x30             // link register
-
-/*
- * Stack pushing/popping (register pairs only). Equivalent to store decrement
- * before, load increment after.
- */
-        .macro  push, xreg1, xreg2
-        stp     \xreg1, \xreg2, [sp, #-16]!
-        .endm
-
-        .macro  pop, xreg1, xreg2
-        ldp     \xreg1, \xreg2, [sp], #16
-        .endm
-
-/*
  * Save/restore guest mode specific state, outer stack frame
  */
         .macro  entry_guest, compat
xen/include/asm-arm/arm64/asm_defns.h new file +26 -0
new file mode 100644
index 0000000..7085c26
@@ -0,0 +1,26 @@
+#ifndef __ASM_ARM_ARM64_DEFNS_H__
+#define __ASM_ARM_ARM64_DEFNS_H__
+
+#ifdef __ASSEMBLY__
+
+/*
+ * Register aliases.
+ */
+lr      .req    x30             // link register
+
+/*
+ * Stack pushing/popping (register pairs only). Equivalent to store decrement
+ * before, load increment after.
+ */
+.macro  push, xreg1, xreg2
+stp     \xreg1, \xreg2, [sp, #-16]!
+.endm
+
+.macro  pop, xreg1, xreg2
+ldp     \xreg1, \xreg2, [sp], #16
+.endm
+
+#endif /* !__ASSEMBLY__ */
+
+
+#endif /* __ASM_ARM_ARM64_DEFNS_H__ */
xen/include/asm-arm/asm_defns.h +3 -0
index 02be83e..365263b 100644
@@ -12,6 +12,9 @@
 # define __OP32
 #elif defined(CONFIG_ARM_64)
 # define __OP32 "w"
+
+# include <asm/arm64/asm_defns.h>
+
 #else
 # error "unknown ARM variant"
 #endif
Signature · 1 line
2.1.4
#2 lore raw

RFC 2/10 xen/arm: Drop unused defines in asm/bug.h

In reply to Julien Grall

The defines BUG_DISP_WIDTH, BUG_LINE_LO_WIDTH and BUG_LINE_HI_WIDTH have been introduced by mistake in a previous patch. They are not used at all so drop them.

---
 xen/include/asm-arm/bug.h | 4 ----
 1 file changed, 4 deletions(-)
xen/include/asm-arm/bug.h +0 -4
index ab9e811..fd3e95e 100644
@@ -11,10 +11,6 @@
 # error "unknown ARM variant"
 #endif
 
-#define BUG_DISP_WIDTH    24
-#define BUG_LINE_LO_WIDTH (31 - BUG_DISP_WIDTH)
-#define BUG_LINE_HI_WIDTH (31 - BUG_DISP_WIDTH)
-
 struct bug_frame {
     signed int loc_disp;    /* Relative address to the bug address */
     signed int file_disp;   /* Relative address to the filename */
Signature · 1 line
2.1.4
#3 lore raw

RFC 3/10 xen/arm: Implement assembly version of WARN/BUG/ASSERT_FAILED...

In reply to Julien Grall

... to produce clear error message in assembly code.

---
TODO:
- Implement the arm32 bits

---
 xen/arch/arm/arm64/entry.S      |  1 +
 xen/include/asm-arm/arm64/bug.h |  4 ++++
 xen/include/asm-arm/bug.h       | 37 +++++++++++++++++++++++++++++++++----
 3 files changed, 38 insertions(+), 4 deletions(-)
xen/arch/arm/arm64/entry.S +1 -0
index 2b9d4cd..93c80ff 100644
@@ -1,5 +1,6 @@
 #include <xen/config.h>
 #include <asm/asm_defns.h>
+#include <asm/bug.h>
 #include <asm/regs.h>
 #include <public/xen.h>
 
xen/include/asm-arm/arm64/bug.h +4 -0
index 42b0e4f..9670505 100644
@@ -5,6 +5,10 @@
 
 #define BRK_BUG_FRAME 1
 
+#ifndef __ASSEMBLY__
 #define BUG_INSTR "brk " __stringify(BRK_BUG_FRAME)
+#else
+#define BUG_INSTR brk BRK_BUG_FRAME
+#endif
 
 #endif /* __ARM_ARM64_BUG_H__ */
xen/include/asm-arm/bug.h +33 -4
index fd3e95e..ffd7f6c 100644
@@ -11,6 +11,12 @@
 # error "unknown ARM variant"
 #endif
 
+#define BUGFRAME_warn   0
+#define BUGFRAME_bug    1
+#define BUGFRAME_assert 2
+
+#ifndef __ASSEMBLY__
+
 struct bug_frame {
     signed int loc_disp;    /* Relative address to the bug address */
     signed int file_disp;   /* Relative address to the filename */
@@ -24,10 +30,6 @@ struct bug_frame {
 #define bug_line(b) ((b)->line)
 #define bug_msg(b) ((const char *)(b) + (b)->msg_disp)
 
-#define BUGFRAME_warn   0
-#define BUGFRAME_bug    1
-#define BUGFRAME_assert 2
-
 /* Many versions of GCC doesn't support the asm %c parameter which would
  * be preferable to this unpleasantness. We use mergeable string
  * sections to avoid multiple copies of the string appearing in the
@@ -71,6 +73,33 @@ extern const struct bug_frame __start_bug_frames[],
 
 int do_bug_frame(struct cpu_user_regs *regs, vaddr_t pc);
 
+#else /* !__ASSEMBLY__ */
+
+.macro BUG_FRAME type, line , file, has_msg, msg
+.L\@bug:BUG_INSTR
+.pushsection .rodata.str, "aMS", %progbits, 1
+    .L\@s1:.asciz "\file"
+    .L\@s2:
+    .if \has_msg
+    .asciz "\msg"
+    .endif
+.popsection
+.pushsection .bug_frames.\type, "a", %progbits
+    .L\@bf:
+    .long (.L\@bug - .L\@bf)
+    .long (.L\@s1 - .L\@bf)
+    .long (.L\@s2 - .L\@bf)
+    .hword \line, 0
+.popsection
+.endm
+
+#define WARN    BUG_FRAME BUGFRAME_warn, __LINE__, __FILE__, 0, 0
+#define BUG     BUG_FRAME BUGFRAME_bug, __LINE__, __FILE__, 0, 0
+#define ASSERT_FAILED(msg)                                          \
+    BUG_FRAME BUGFRAME_assert, __LINE__, __FILE__, 1, msg
+
+#endif
+
 #endif /* __ARM_BUG_H__ */
 /*
  * Local variables:
Signature · 1 line
2.1.4
#4 lore raw

RFC 4/10 xen/arm64: Add an assembly macro for perf counter

In reply to Julien Grall

Allow assembly code to use performance counter.

---
 xen/include/asm-arm/arm64/asm_defns.h | 36 +++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
xen/include/asm-arm/arm64/asm_defns.h +36 -0
index 7085c26..36442b8 100644
@@ -20,6 +20,42 @@ stp     \xreg1, \xreg2, [sp, #-16]!
 ldp     \xreg1, \xreg2, [sp], #16
 .endm
 
+#ifdef PERF_COUNTERS
+
+.macro perfc_incr, name, idx
+push    x0, x1                  /* x0 and x1 are used by the macro -> save them */
+
+/*
+ * Compute the address of the perf counters
+ *
+ * Note that each perf counters are 4 bytes and stored percpu.
+ */
+mov     x0, \idx                /* x0 <- index from ASM_PERFC_* */
+add     x0, x0, #\name          /* x0 <- index in the percpu array */
+lsl     x0, x0, 2               /* x0 <- offset from per_cpu__perfcounters. */
+ldr     x1, =per_cpu__perfcounters
+add     x0, x0, x1              /* x0 <- offset in the percpu area */
+mrs     x1, TPIDR_EL2           /* x1 <- per cpu offset */
+add     x0, x0, x1              /* x0 <- address of the perf counter for this cpu */
+
+/*
+ * Increment the perf counters.
+ *
+ * Note it's not atomic so does the C version.
+ */
+ldr     x1, [x0]                /* x1 <- current value of the counter */
+add     x1, x1, 1               /* x1 <- increment the counter */
+str     x1, [x0]                /* Store the counters incremented */
+
+pop     x0, x1                  /* Restore x0, x1 */
+.endm
+
+#define PERFC_INCR(_name, _idx) perfc_incr  ASM_PERFC_##_name, _idx
+
+#else
+#define PERFC_INCR(_name, _idx)
+#endif
+
 #endif /* !__ASSEMBLY__ */
 
 
Signature · 1 line
2.1.4
#5 lore raw

RFC 5/10 xen/arm: gic_inject: Introduce a local variable to store current

In reply to Julien Grall

current is a define which is replaced by a read to a system register. Rather than reading the system registers multiple store the result in a local variable.

---
 xen/arch/arm/gic.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
xen/arch/arm/gic.c +4 -2
index 1e1e5ba..37e579b 100644
@@ -596,11 +596,13 @@ out:
 
 void gic_inject(void)
 {
+    struct vcpu *v = current;
+
     ASSERT(!local_irq_is_enabled());
 
-    gic_restore_pending_irqs(current);
+    gic_restore_pending_irqs(v);
 
-    if ( !list_empty(&current->arch.vgic.lr_pending) && lr_all_full() )
+    if ( !list_empty(&v->arch.vgic.lr_pending) && lr_all_full() )
         gic_hw_ops->update_hcr_status(GICH_HCR_UIE, 1);
 }
 
Signature · 1 line
2.1.4
#6 lore raw

RFC 6/10 xen/arm: gic: Allow the LRs to be cleared lazily

In reply to Julien Grall

Currently the LRs are cleared every time we entered in Xen from a guest before any action is taken by the hypervisor. This requiring to reload the guest registers from the stack when an hypercall is handled for instance.

However, we only need to clear the LRs for the following actions:
- An interrupt is received and injected
- Checking hypercall preemption
- Before re-entering in the guest

A new flag has been introduced per vCPU in vgic.flags to know whether the LRs has been cleared since the vCPU has been running. The flag is always cleared before switching back to the guest vCPU.

As clearing the LRs is now lazy, we have to check if they are cleared every time we enter in the hypervisor and not only when we entered from a lower exception state.

Note that actually no one is taking advantage of clearing the LRs lazily. A follow-up patch will enable this possibility.

---
 xen/arch/arm/gic.c           | 11 +++++++++++
 xen/arch/arm/traps.c         |  9 ++++++++-
 xen/include/asm-arm/domain.h |  7 ++++++-
 3 files changed, 25 insertions(+), 2 deletions(-)
xen/arch/arm/gic.c +11 -0
index 37e579b..5d70251 100644
@@ -476,6 +476,13 @@ void gic_clear_lrs(struct vcpu *v)
     if ( is_idle_vcpu(v) )
         return;
 
+    /*
+     * Check the LRs has already been cleared for this vCPU since the
+     * last time it has running.
+     */
+    if ( test_and_set_bit(_VGIC_LRS_CLEARED, &v->arch.vgic.flags) )
+        return;
+
     gic_hw_ops->update_hcr_status(GICH_HCR_UIE, 0);
 
     spin_lock_irqsave(&v->arch.vgic.lock, flags);
@@ -566,6 +573,8 @@ int gic_events_need_delivery(void)
     int active_priority;
     int rc = 0;
 
+    gic_clear_lrs(v);
+
     mask_priority = gic_hw_ops->read_vmcr_priority();
     active_priority = find_next_bit(&apr, 32, 0);
 
@@ -602,6 +611,8 @@ void gic_inject(void)
 
     gic_restore_pending_irqs(v);
 
+    clear_bit(_VGIC_LRS_CLEARED, &v->arch.vgic.flags);
+
     if ( !list_empty(&v->arch.vgic.lr_pending) && lr_all_full() )
         gic_hw_ops->update_hcr_status(GICH_HCR_UIE, 1);
 }
xen/arch/arm/traps.c +8 -1
index c49bd3f..f222d96 100644
@@ -2451,7 +2451,12 @@ bad_data_abort:
 
 static void enter_hypervisor_head(struct cpu_user_regs *regs)
 {
-    if ( guest_mode(regs) )
+    /*
+     * enter_hypervisor_head is called by most of the traps generated by the
+     * processor. It could be taken from the hypervisor or the guest.
+     * However current is only valid after Xen has finished to boot.
+     */
+    if ( likely(system_state > SYS_STATE_active) )
         gic_clear_lrs(current);
 }
 
@@ -2602,6 +2607,8 @@ asmlinkage void do_trap_fiq(struct cpu_user_regs *regs)
 
 asmlinkage void leave_hypervisor_tail(void)
 {
+    gic_clear_lrs(current);
+
     while (1)
     {
         local_irq_disable();
xen/include/asm-arm/domain.h +6 -1
index e7e40da..401b4d0 100644
@@ -245,7 +245,12 @@ struct arch_vcpu
 
         /* GICv3: redistributor base and flags for this vCPU */
         paddr_t rdist_base;
-#define VGIC_V3_RDIST_LAST  (1 << 0)        /* last vCPU of the rdist */
+/* Last vCPU of the rdist */
+#define _VGIC_V3_RDIST_LAST (0)
+#define VGIC_V3_RDIST_LAST (1 << _VGIC_V3_RDIST_LAST)
+/* LRs have been cleared for this vCPU */
+#define _VGIC_LRS_CLEARED   (1)
+#define VGIC_LRS_CLEARED    (1 << _VGIC_LRS_CLEARED)
         uint8_t flags;
     } vgic;
 
Signature · 1 line
2.1.4
#7 lore raw

RFC 7/10 xen/arm: Implement the code to dispatch the hypercall in assembly

In reply to Julien Grall

Each hypercalls have different number of arguments. To avoid worry about the number of arguments, all the hypercall handler are cast to a 5-arguments function. However, based on the C-spec (see 6.3.2.3 paragraph 8 and 6.7.5.3 paraph 2) the behavior is undefined.

This is also the first step to handle the hypercall directly in assembly.

---
TODO:
- Implement do_dispatch_hypercall for ARM32

---
 xen/arch/arm/Makefile           |  1 +
 xen/arch/arm/arm64/Makefile     |  1 +
 xen/arch/arm/arm64/hypercall.S  | 27 +++++++++++++
 xen/arch/arm/hypercall.S        | 88 ++++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/traps.c            | 90 ++++++-----------------------------------
 xen/include/asm-arm/hypercall.h |  9 +++++
 6 files changed, 139 insertions(+), 77 deletions(-)
 create mode 100644 xen/arch/arm/arm64/hypercall.S
 create mode 100644 xen/arch/arm/hypercall.S
xen/arch/arm/Makefile +1 -0
index 4ac5edd..3bf7455 100644
@@ -40,6 +40,7 @@ obj-y += device.o
 obj-y += decode.o
 obj-y += processor.o
 obj-y += smc.o
+obj-y += hypercall.o
 
 #obj-bin-y += ....o
 
xen/arch/arm/arm64/Makefile +1 -0
index c7243f5..1255b4b 100644
@@ -8,5 +8,6 @@ obj-y += vfp.o
 obj-y += smpboot.o
 obj-y += domctl.o
 obj-y += cache.o
+obj-y += hypercall.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm64/hypercall.S new file +27 -0
new file mode 100644
index 0000000..d831181
@@ -0,0 +1,27 @@
+#include <xen/config.h>
+#include <asm/asm_defns.h>
+
+/*
+ * int do_dispatch_hypercall(register_t arg1, register_t arg2,
+ *                           register_t arg3, register_t arg4,
+ *                           register_t arg5, register_t nr)
+ *
+ * x0 - arg1
+ * x1 - arg2
+ * x2 - arg3
+ * x3 - arg4
+ * x4 - arg5
+ * x5 - nr
+ *
+ * return the hypercall result in x0.
+ */
+ENTRY(do_dispatch_hypercall)
+    push    x19, lr                 /* Save lr (x19 is here because the stack need to be 16 bytes aligned */
+    ldr     x10, =hypercall_table
+    ldr     x10, [x10, x5, lsl #3]  /* x10 := pointer to hypercall function */
+
+    blr     x10                     /* Call the hypercall */
+
+    pop     x19, lr                 /* Restore lr */
+
+    ret
xen/arch/arm/hypercall.S new file +88 -0

88 lines not on this page · raw message

xen/arch/arm/traps.c +13 -77

152 lines not on this page · raw message

xen/include/asm-arm/hypercall.h +9 -0
index a0c5a31..41e43ec 100644
@@ -9,6 +9,15 @@ long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(void) a
 long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
                        XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl);
 
+register_t do_deprecated_hypercall(void);
+
+register_t do_dispatch_hypercall(register_t arg0, register_t arg1,
+                                 register_t arg2, register_t arg3,
+                                 register_t arg4, register_t nr);
+
+extern const uint8_t hypercall_args_table[];
+extern const void *hypercall_table[];
+
 #endif /* __ASM_ARM_HYPERCALL_H__ */
 /*
  * Local variables:
Signature · 1 line
2.1.4
#8 lore raw

RFC 8/10 xen/arm64: Implement the hypercall handing fully in assembly

In reply to Julien Grall

Currently when the guest is issuing an hypercall, all the registers are saved in the stack and then later reload from the stack before calling the hypercall dispatcher.

To avoid spending time loading from the stack the arguments, the hypercall handler can be implemented in assembly.

This patch implements the assembly version of do_trap_hypercall for AArch64.

Note that the C version of do_trap_hypercall will be dropped in a follow-up patch.

---
 xen/arch/arm/arm64/asm-offsets.c |  11 +++
 xen/arch/arm/arm64/entry.S       | 147 ++++++++++++++++++++++++++++++++++++++-
 xen/include/asm-arm/processor.h  |   3 +
 3 files changed, 159 insertions(+), 2 deletions(-)
xen/arch/arm/arm64/asm-offsets.c +11 -0
index a3ce816..6f0e8f1 100644
@@ -23,6 +23,12 @@
 void __dummy__(void)
 {
    OFFSET(UREGS_X0, struct cpu_user_regs, x0);
+   OFFSET(UREGS_X1, struct cpu_user_regs, x1);
+   OFFSET(UREGS_X2, struct cpu_user_regs, x2);
+   OFFSET(UREGS_X3, struct cpu_user_regs, x3);
+   OFFSET(UREGS_X4, struct cpu_user_regs, x4);
+   OFFSET(UREGS_X12, struct cpu_user_regs, x12);
+   OFFSET(UREGS_X16, struct cpu_user_regs, x16);
    OFFSET(UREGS_LR, struct cpu_user_regs, lr);
 
    OFFSET(UREGS_SP, struct cpu_user_regs, sp);
@@ -50,6 +56,11 @@ void __dummy__(void)
 
    BLANK();
    OFFSET(INITINFO_stack, struct init_info, stack);
+
+#ifdef PERF_COUNTERS
+   BLANK();
+   DEFINE(ASM_PERFC_hypercalls, PERFC_hypercalls);
+#endif
 }
 
 /*
xen/arch/arm/arm64/entry.S +145 -2

171 lines not on this page · raw message

xen/include/asm-arm/processor.h +3 -0
index 7e6eb66..da02599 100644
@@ -483,6 +483,9 @@ union hsr {
 };
 #endif
 
+#define HSR_EC_SHIFT    26
+#define HSR_ISS_MASK    0x00ffffff
+
 /* HSR.EC == HSR_CP{15,14,10}_32 */
 #define HSR_CP32_OP2_MASK (0x000e0000)
 #define HSR_CP32_OP2_SHIFT (17)
Signature · 1 line
2.1.4
#9 lore raw

RFC 9/10 xen/arm: Remove the C version of do_trap_hypercall

In reply to Julien Grall

This has been fully implemented in assembly so it's not necessary to keep it anymore.

---

It's possible to factorize the code to handle HVC32/HVC64, but this will be done in the next patch.

---
 xen/arch/arm/traps.c | 74 ++++++----------------------------------------------
 1 file changed, 8 insertions(+), 66 deletions(-)
xen/arch/arm/traps.c +8 -66
index cc67d23..3cd8992 100644
@@ -1335,70 +1335,6 @@ static void do_trap_psci(struct cpu_user_regs *regs)
     }
 }
 
-#ifdef CONFIG_ARM_64
-#define HYPERCALL_RESULT_REG(r) (r)->x0
-#define HYPERCALL_ARG1(r) (r)->x0
-#define HYPERCALL_ARG2(r) (r)->x1
-#define HYPERCALL_ARG3(r) (r)->x2
-#define HYPERCALL_ARG4(r) (r)->x3
-#define HYPERCALL_ARG5(r) (r)->x4
-#define HYPERCALL_ARGS(r) (r)->x0, (r)->x1, (r)->x2, (r)->x3, (r)->x4
-#else
-#define HYPERCALL_RESULT_REG(r) (r)->r0
-#define HYPERCALL_ARG1(r) (r)->r0
-#define HYPERCALL_ARG2(r) (r)->r1
-#define HYPERCALL_ARG3(r) (r)->r2
-#define HYPERCALL_ARG4(r) (r)->r3
-#define HYPERCALL_ARG5(r) (r)->r4
-#define HYPERCALL_ARGS(r) (r)->r0, (r)->r1, (r)->r2, (r)->r3, (r)->r4
-#endif
-
-static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,
-                              unsigned long iss)
-{
-#ifndef NDEBUG
-    register_t orig_pc = regs->pc;
-#endif
-
-    if ( iss != XEN_HYPERCALL_TAG )
-        domain_crash_synchronous();
-
-    if ( *nr >= NR_hypercalls )
-    {
-        perfc_incr(invalid_hypercalls);
-        HYPERCALL_RESULT_REG(regs) = -ENOSYS;
-        return;
-    }
-
-    perfc_incra(hypercalls, *nr);
-
-    HYPERCALL_RESULT_REG(regs) = do_dispatch_hypercall(HYPERCALL_ARGS(regs),
-                                                       *nr);
-
-#ifndef NDEBUG
-    /*
-     * Clobber argument registers only if pc is unchanged, otherwise
-     * this is a hypercall continuation.
-     */
-    if ( orig_pc == regs->pc )
-    {
-        switch ( hypercall_args_table[*nr] ) {
-        case 5: HYPERCALL_ARG5(regs) = 0xDEADBEEF;
-        case 4: HYPERCALL_ARG4(regs) = 0xDEADBEEF;
-        case 3: HYPERCALL_ARG3(regs) = 0xDEADBEEF;
-        case 2: HYPERCALL_ARG2(regs) = 0xDEADBEEF;
-        case 1: /* Don't clobber x0/r0 -- it's the return value */
-            break;
-        case 0:
-            ASSERT(hypercall_table[*nr] == do_ni_hypercall);
-            break;
-        default: BUG();
-        }
-        *nr = 0xDEADBEEF;
-    }
-#endif
-}
-
 static bool_t check_multicall_32bit_clean(struct multicall_entry *multi)
 {
     int i;
@@ -2476,7 +2412,10 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
 #endif
         if ( hsr.iss == 0 )
             return do_trap_psci(regs);
-        do_trap_hypercall(regs, (register_t *)&regs->r12, hsr.iss);
+
+        /* The ISS is not supported */
+        domain_crash_synchronous();
+
         break;
 #ifdef CONFIG_ARM_64
     case HSR_EC_HVC64:
@@ -2488,7 +2427,10 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
 #endif
         if ( hsr.iss == 0 )
             return do_trap_psci(regs);
-        do_trap_hypercall(regs, &regs->x16, hsr.iss);
+
+        /* The ISS is not supported */
+        domain_crash_synchronous();
+
         break;
     case HSR_EC_SMC64:
         /*
Signature · 1 line
2.1.4
#10 lore raw

RFC 10/10 xen/arm: Factorize the C code to dispatch HVC

In reply to Julien Grall

Now that Xen hypercall is fully dispatched in assembly, the code to handle HVC32/HVC64 is mostly the same.

Create an helper to avoid duplicating the code.

---
 xen/arch/arm/traps.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)
xen/arch/arm/traps.c +16 -20
index 3cd8992..a49530a 100644
@@ -1335,6 +1335,20 @@ static void do_trap_psci(struct cpu_user_regs *regs)
     }
 }
 
+static void do_trap_hvc(struct cpu_user_regs *regs, uint32_t iss)
+{
+
+#ifndef NDEBUG
+    if ( (iss & 0xff00) == 0xff00 )
+        return do_debug_trap(regs, iss & 0x00ff);
+#endif
+    if ( iss == 0 )
+        return do_trap_psci(regs);
+
+    /* The ISS is not supported */
+    domain_crash_synchronous();
+}
+
 static bool_t check_multicall_32bit_clean(struct multicall_entry *multi)
 {
     int i;
@@ -2406,31 +2420,13 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
     case HSR_EC_HVC32:
         GUEST_BUG_ON(!psr_mode_is_32bit(regs->cpsr));
         perfc_incr(trap_hvc32);
-#ifndef NDEBUG
-        if ( (hsr.iss & 0xff00) == 0xff00 )
-            return do_debug_trap(regs, hsr.iss & 0x00ff);
-#endif
-        if ( hsr.iss == 0 )
-            return do_trap_psci(regs);
-
-        /* The ISS is not supported */
-        domain_crash_synchronous();
-
+        do_trap_hvc(regs, hsr.iss);
         break;
 #ifdef CONFIG_ARM_64
     case HSR_EC_HVC64:
         GUEST_BUG_ON(psr_mode_is_32bit(regs->cpsr));
         perfc_incr(trap_hvc64);
-#ifndef NDEBUG
-        if ( (hsr.iss & 0xff00) == 0xff00 )
-            return do_debug_trap(regs, hsr.iss & 0x00ff);
-#endif
-        if ( hsr.iss == 0 )
-            return do_trap_psci(regs);
-
-        /* The ISS is not supported */
-        domain_crash_synchronous();
-
+        do_trap_hvc(regs, hsr.iss);
         break;
     case HSR_EC_SMC64:
         /*
Signature · 1 line
2.1.4
#11 lore raw
In reply to Julien Grall
Quoted 4 lines · Julien Grall

Hi all,

This patch aims is a first attempt to write the hypercall dispatch in assembly in order to avoid reloading the hypercall arguments from the stack.

Why? A couple of stack operations are in the noise, performance wise.

I have half a patch series to do exactly the opposite for x86 PV guests, as C is far more maintainable than asm.

~Andrew

#12 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi all,

This patch aims is a first attempt to write the hypercall dispatch in assembly
in order to avoid reloading the hypercall arguments from the stack.

Why?  A couple of stack operations are in the noise, performance wise.

At least on ARM It's quite a bit more than a couple (dozens but not hundreds I would say, and I've not looked at the patch yet to see how much it saves out of those), but clearly it would need to be measured at some point before taking it too much further than an RFC.

There's a second issue which is that the current C dispatch table approach which uses a common typedef is not strictly speaking valid C, since it is undefined behaviour to call a function through a typedef which has a different prototype (Ian J can probably explain it better than I, with chapter and verse etc).

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel