Skip to contentSkip to conversation

xen/arm : Adding helper function for WFI

PATCH In review Parth Dixit 2 participants 4 messages Jul 14, 2014 – Jul 16, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 xen/arm : Adding helper function for WFI

WFI functionality is required at different places in xen. Moving it to seperate helper function so that it is easier to call WFI function and avoid duplication of code

- renamed vcpu_block_event to vcpu_block_unless_event_pending

---
Changelog v4
- added space in comments
- renamed vcpu_block_event to vcpu_block_unless_event_pending Changelog v3 :
- new patch for helper function, this functionality existed in same patch in v2

xen/arch/arm/domain.c | 13 +++++++++++++

 xen/arch/arm/traps.c        | 10 +---------
 xen/include/asm-arm/event.h |  1 +
 3 files changed, 15 insertions(+), 9 deletions(-)
xen/arch/arm/domain.c +13 -0
index 2ae6941..7ddd2d8 100644
@@ -779,6 +779,19 @@ void vcpu_mark_events_pending(struct vcpu *v)
     vgic_vcpu_inject_irq(v, v->domain->arch.evtchn_irq, 1);
 }
 
+/* The ARM spec declares that even if local irqs are masked in
+ * the CPSR register, an irq should wake up a cpu from WFI anyway.
+ * For this reason we need to check for irqs that need delivery,
+ * ignoring the CPSR register, *after* calling SCHEDOP_block to
+ * avoid races with vgic_vcpu_inject_irq.
+ */
+void vcpu_block_unless_event_pending(struct vcpu *v)
+{
+    vcpu_block();
+    if ( local_events_need_delivery_nomask() )
+        vcpu_unblock(current);
+}
+
 /*
  * Local variables:
  * mode: C
xen/arch/arm/traps.c +1 -9
index 03a3da6..8102540 100644
@@ -1670,15 +1670,7 @@ asmlinkage void do_trap_hypervisor(struct cpu_user_regs *regs)
             return;
         }
         /* at the moment we only trap WFI */
-        vcpu_block();
-        /* The ARM spec declares that even if local irqs are masked in
-         * the CPSR register, an irq should wake up a cpu from WFI anyway.
-         * For this reason we need to check for irqs that need delivery,
-         * ignoring the CPSR register, *after* calling SCHEDOP_block to
-         * avoid races with vgic_vcpu_inject_irq.
-         */
-        if ( local_events_need_delivery_nomask() )
-            vcpu_unblock(current);
+        vcpu_block_unless_event_pending(current);
         advance_pc(regs, hsr);
         break;
     case HSR_EC_CP15_32:
xen/include/asm-arm/event.h +1 -0
index dd3ad13..5330dfe 100644
@@ -6,6 +6,7 @@
 
 void vcpu_kick(struct vcpu *v);
 void vcpu_mark_events_pending(struct vcpu *v);
+void vcpu_block_unless_event_pending(struct vcpu *v);
 
 static inline int vcpu_event_delivery_is_enabled(struct vcpu *v)
 {
Signature · 1 line
1.9.1
#1 lore raw

PATCH v4 2/2 xen/arm : emulation of arm's PSCI v0.2 standard

Arm based virtual machines dom0/guest will request power related functionality from xen through PSCI interface. This patch implements version 0.2 of PSCI standard specified by arm for 64bit and 32 bit arm machines.

- removed arm_psci_fn_t
- implemented psci_cpu_on with additional error conditions
- added switch-case in do_trap_psci function
- added PSCI v0.2 macros in psci.h
- removed tables for PSCI v0.1 and v0.2
- implemented affinity_info

---
Changelog v4
- added target_affinity_mask[] to local variable
- removed AFF3 masking for 64 bit cpu
- added do_common_cpu_on for PSCI v0.1 and v0.2
- moved cpu_on decision based on entry point
- removed vpsci_ver introduced in v3
- removed psci tables
- added new macro for selecting arguments
- do_trap_psci is now switch case based instead of tables

Changelog v3
- moved wfi helper to seperate patch
- replaced new wfi function in traps.c
- removed defining power_state variable using value directly
- added new line between declaration
- merged PSCI v0.1 and v0.2 cpu_on function to avoid duplication
- removed spurious change
- renamed PSCI return values to reflect v0.2 moved them to top
- removed PSCI v0.1 version declaration for now, will introduce it when needed
- removed hard tabs in the code lifted from linux
- removed PSCI_0_1_MAX
- did not retained copyright header from linux as most of functions are removed
- added two function tables for PSCI v0.1 and PSCI v0.2
- added compatibility string to libxl_arm to expose new functionality
- refactored affinity_info code
- added table for masking function
- removed definitions of unused PSCI v0.2 functions
- removed function id's of unused PSCI v0.2 functions
- renamed constant PSCI_0_2_TOS_MP ( multicore aware) as per spec

 tools/libxl/libxl_arm.c         |   2 +-
 xen/arch/arm/domain_build.c     |   5 +-
 xen/arch/arm/traps.c            |  99 ++++++++++++++++++---------
 xen/arch/arm/vpsci.c            | 148 +++++++++++++++++++++++++++++++++++++---
 xen/include/asm-arm/processor.h |   3 +
 xen/include/asm-arm/psci.h      |  68 ++++++++++++++++--
 6 files changed, 279 insertions(+), 46 deletions(-)
tools/libxl/libxl_arm.c +1 -1
index 4f0f0e2..e8bcd05 100644
@@ -237,7 +237,7 @@ static int make_psci_node(libxl__gc *gc, void *fdt)
     res = fdt_begin_node(fdt, "psci");
     if (res) return res;
 
-    res = fdt_property_compat(gc, fdt, 1, "arm,psci");
+    res = fdt_property_compat(gc, fdt, 2, "arm,psci-0.2","arm,psci");
     if (res) return res;
 
     res = fdt_property_string(fdt, "method", "hvc");
xen/arch/arm/domain_build.c +4 -1
index c424793..ebd4170 100644
@@ -388,6 +388,9 @@ static int make_hypervisor_node(struct domain *d,
 static int make_psci_node(void *fdt, const struct dt_device_node *parent)
 {
     int res;
+    const char compat[] =
+        "arm,psci-0.2""\0"
+        "arm,psci";
 
     DPRINT("Create PSCI node\n");
 
@@ -396,7 +399,7 @@ static int make_psci_node(void *fdt, const struct dt_device_node *parent)
     if ( res )
         return res;
 
-    res = fdt_property_string(fdt, "compatible", "arm,psci");
+    res = fdt_property(fdt, "compatible", compat, sizeof(compat));
     if ( res )
         return res;
 
xen/arch/arm/traps.c +67 -32

122 lines not on this page · raw message

xen/arch/arm/vpsci.c +140 -8

186 lines not on this page · raw message

xen/include/asm-arm/processor.h +3 -0
index 9267c1b..8a237c4 100644
@@ -16,6 +16,9 @@
 #define MPIDR_AFF0_MASK     (_AC(0xff,U) << MPIDR_AFF0_SHIFT)
 #define MPIDR_HWID_MASK     _AC(0xffffff,U)
 #define MPIDR_INVALID       (~MPIDR_HWID_MASK)
+#define MPIDR_LEVEL_BITS    (8)
+#define AFFINITY_MASK(level)    ~((_AC(0x1,U) << ((level) * MPIDR_LEVEL_BITS)) - 1)
+
 
 /* TTBCR Translation Table Base Control Register */
 #define TTBCR_EAE    _AC(0x80000000,U)
xen/include/asm-arm/psci.h +64 -4

80 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v4 2/2] xen/arm : emulation of arm's PSCI v0.2 standard

On Mon, 2014-07-14 at 19:21 +0530, Parth Dixit wrote:

Thanks.

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1068

Quoted 7 lines
xen/arch/arm/traps.c +2 -1
@@ -1082,31 +1064,84 @@ static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code)
 #ifdef CONFIG_ARM_64
 #define PSCI_OP_REG(r) (r)->x0
 #define PSCI_RESULT_REG(r) (r)->x0
-#define PSCI_ARGS(r) (r)->x1, (r)->x2
+#define PSCI_ARGS(r) (r)->x1, (r)->x2, (r)->x3
+#define PSCI_ARG(r,n) (r)->x##n

It seems like one or the other of these is redundant. Special casing functions which have exactly three arguments is unnecessary.

Quoted 15 lines
xen/arch/arm/traps.c +2 -6
 #else
 #define PSCI_OP_REG(r) (r)->r0
 #define PSCI_RESULT_REG(r) (r)->r0
-#define PSCI_ARGS(r) (r)->r1, (r)->r2
+#define PSCI_ARGS(r) (r)->r1, (r)->r2, (r)->r3
+#define PSCI_ARG(r,n) (r)->r##n
 #endif
 
 static void do_trap_psci(struct cpu_user_regs *regs)
 {
-    arm_psci_fn_t psci_call = NULL;
-
-    if ( PSCI_OP_REG(regs) >= ARRAY_SIZE(arm_psci_table) )
-    {
-        domain_crash_synchronous();

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1082

Quoted 10 lines
xen/arch/arm/traps.c +4 -5
-        return;
-    }
-
-    psci_call = arm_psci_table[PSCI_OP_REG(regs)].fn;
-    if ( psci_call == NULL )
+    switch( PSCI_OP_REG(regs) )
     {
+    case PSCI_cpu_off:
+        {
+            uint32_t pstate = (u32)( PSCI_ARG(regs,1) );

Don't mix and match uintNN_t with uNN please. We generally prefer the uintXX_t version. If you wanted you could incorporate this into a PSCI_ARG32 macro (up to you).

I think the braces around PSCI_ARG are not needed, are they? Or if they are then they should be in the macro I think.

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1083

Quoted 1 line
xen/arch/arm/traps.c +1 -0
+            PSCI_RESULT_REG(regs) = do_psci_cpu_off(pstate);

I think you also need to cast the result of any SMC32 call, in order to properly zero the top bits of x0 in the SMC64 case, to match the architectural behaviour of writing to w0.

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1103

Quoted 2 lines
xen/arch/arm/traps.c +2 -0
+    case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
+    case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU:

You need to check is_32bit_domain here and reject calls from the wrong mode for each fn type with INVALID_PARAMETERS.

Perhaps either split the two cases, or a psci_mode_check(v, PSCI_OP_REG(regs)) helper which just checks bit 30? Sadly you can't pull that check to the top since some SMC32 calls are valid for aarch64 and some aren't.

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1104

Quoted 1 line
xen/arch/arm/traps.c +1 -0
+        PSCI_RESULT_REG(regs) = do_psci_0_2_migrate_info_up_cpu();

Need to be careful here. An AArch32 guest running on an AArch64 hypervisor might end up with a truncated result. Perhaps that is OK, since all of their MIDR/cpu_target stuff is already truncated.

I'd be happier if the top half of the register state for an AArch32 guest remained clear though, I so I think a cast should be used (which suggests that splitting the two cases will be cleaner).

xen/arch/arm/traps.c static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) · line 1110

Quoted 6 lines
xen/arch/arm/traps.c +6 -0
+        break;
+    case PSCI_0_2_FN_SYSTEM_OFF:
+        do_psci_0_2_system_off();
+        break;
+    case PSCI_0_2_FN_SYSTEM_RESET:
+        do_psci_0_2_system_reset();

I guess neither of these return, but it seems wise to preload the return value with PSCI_RET_INTERNAL_FAILURE just in case.

xen/arch/arm/vpsci.c line 24

Quoted 13 lines
xen/arch/arm/vpsci.c +5 -0
index 1ceb8cb..2ce96d4 100644
@@ -17,24 +17,92 @@
 #include <asm/current.h>
 #include <asm/gic.h>
 #include <asm/psci.h>
+#include <public/sched.h>
+#include <asm-arm/event.h>
+
+static int do_common_cpu_on(register_t target_cpu, register_t entry_point,
+                       register_t context_id,int ver);

Please order the functions in the file to avoid forward decls where possible.

Ian.

#3 lore raw
In reply to Parth Dixit
Quoted 7 lines · Parth Dixit

WFI functionality is required at different places in xen. Moving it to seperate helper function so that it is easier to call WFI function and avoid duplication of code

- renamed vcpu_block_event to vcpu_block_unless_event_pending

Acked + Applied, thanks.