Skip to contentSkip to conversation

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

PATCH Superseded Parth Dixit 2 participants 5 messages Jul 17, 2014 – Jul 25, 2014 1 message not in the archive

v5 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 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
- moved do_common_cpu up in vpsci.c removed declaration
- removed PSCI_ARGS macro
- added new macro for 32 bit arguments
- added new function psci_mode_check

---
Changelog v5
- removed PSCI_ARGS macro
- preload error value for calls that do not return
- added new macro for 32 bit arguments
- casting return calls to appropriate types
- added new function psci_mode_check
- added error checks for PSCI v0.2 function id's

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            | 131 +++++++++++++++++++++++++++----------
 xen/arch/arm/vpsci.c            | 139 ++++++++++++++++++++++++++++++++++++++--
 xen/include/asm-arm/processor.h |   3 +
 xen/include/asm-arm/psci.h      |  76 +++++++++++++++++++---
 6 files changed, 308 insertions(+), 48 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 +98 -33

155 lines not on this page · raw message

xen/arch/arm/vpsci.c +134 -5

181 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 +68 -8

88 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw
Quoted 7 lines · Parth Dixit

Changelog v5
- removed PSCI_ARGS macro
- preload error value for calls that do not return
- added new macro for 32 bit arguments
- casting return calls to appropriate types
- added new function psci_mode_check
- added error checks for PSCI v0.2 function id's

Looking good. I've a couple of questions which I hope you can answer.

Quoted 16 lines
xen/arch/arm/traps.c +12 -2
+static void do_trap_psci(struct cpu_user_regs *regs)
+{
+    register_t fid = PSCI_ARG(regs,0);
 
-    psci_call = arm_psci_table[PSCI_OP_REG(regs)].fn;
-    if ( psci_call == NULL )
+    /* preloading in case psci_mode_check fails */
+    PSCI_RESULT_REG(regs) = (int32_t)PSCI_INVALID_PARAMETERS;
[...]
+    case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
+        if ( psci_mode_check(current->domain, fid) )
+            PSCI_RESULT_REG(regs) =
+               (uint32_t) do_psci_0_2_migrate_info_up_cpu();
+        else
+            PSCI_RESULT_REG(regs) = (uint32_t)PSCI_INVALID_PARAMETERS;
+        break;

[...]

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

Quoted 9 lines
xen/arch/arm/traps.c +9 -0
+    case PSCI_0_2_FN_CPU_ON:
+    case PSCI_0_2_FN64_CPU_ON:
+        if ( psci_mode_check(current->domain, fid) )
+        {
+        register_t vcpuid = PSCI_ARG(regs,1);
+        register_t epoint = PSCI_ARG(regs,2);
+        register_t cid = PSCI_ARG(regs,3);
+        PSCI_RESULT_REG(regs) =
+            (int32_t) do_psci_0_2_cpu_on(vcpuid, epoint, cid);

Indentation here is broken.

I notice that sometimes you have an else case setting PSCI_INVALID_PARAMETERS and other times you don't. Is that just an oversight or is there a reason why they should differ?

I don't think you need to cast the PSCI_* result codes BTW.

[...]

xen/arch/arm/vpsci.c int do_psci_cpu_off(uint32_t power_state) · line 122

Quoted 6 lines
xen/arch/arm/vpsci.c +6 -0
+int32_t do_psci_0_2_cpu_suspend(uint32_t power_state, register_t entry_point,
+                            register_t context_id)
+{
+    struct vcpu *v = current;
+    struct domain *d = v->domain;
+    struct cpu_user_regs *regs = &v->arch.cpu_info->guest_cpu_user_regs;

I think it would make sense to pass this as an argument, but if not then guest_cpu_user_regs() is the accessor to use.

Quoted 5 lines
xen/arch/arm/vpsci.c +5 -0
+
+    if ( is_32bit_domain(d) )
+    {
+        regs->pc32 = entry_point;
+        regs->r0 = context_id;

xen/arch/arm/vpsci.c int do_psci_cpu_off(uint32_t power_state) · line 137

Quoted 10 lines
xen/arch/arm/vpsci.c +10 -0
+    }
+#ifdef CONFIG_ARM_64
+    else
+    {
+        regs->pc = entry_point;
+        regs->x0 = context_id;
+    }
+#endif
+    vcpu_block_unless_event_pending(v);
+    return PSCI_SUCCESS;

This only seems to be handling the case where the requested power state is power down and not the standby state.

By my reading when bit 16 if the power_state argument is 0 (standby) then entry_point and context_id are ignored and the PSCI call is expected to return success to the place it was called from, not jump to entry_point.

If bit 16 is one you are supposed to return to entry_point with x0/r0 set to context_id, but because you return PSCI_SUCCESS that will get written to x0/r0 by the generic handler clobbering your write of x0/r0 above. You should probably return the desired value (with an explanatory comment)

The upper bits of power_state also describe an affinity level to put to sleep, which you also don't handle AFAICT. Perhaps since we don't actually have affinities > 0 what you've done is OK, what do you think?

The lower bits are supposed to be some sort of per platform ID which we are supposed to have exposed via tables. I'm not sure there are any DTB bindings for that, so perhaps we can ignore it.

The handling of bit 16 is the only bit which really concerns me here, the rest seem like things we can tolerate.

Ian.

A message that is not in the archive (sent off-list or not yet received): CABy3MNkuZ_S0YPHyPwXXdp_rGvJ2VrPmsTLW=k=CBqN4qXpmdA@mail.gmail.com

#3 lore raw

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

forgot to add xen-devel list...

---------- Forwarded message ----------
From: Parth Dixit <[email protected]>
Date: 25 July 2014 11:05
Subject: Re: [PATCH v5] xen/arm : emulation of arm's PSCI v0.2 standard
To: Ian Campbell <[email protected]>

Quoted 38 lines · Ian Campbell
Quoted 7 lines · Parth Dixit

Changelog v5
- removed PSCI_ARGS macro
- preload error value for calls that do not return
- added new macro for 32 bit arguments
- casting return calls to appropriate types
- added new function psci_mode_check
- added error checks for PSCI v0.2 function id's

Looking good. I've a couple of questions which I hope you can answer.

Quoted 16 lines
xen/arch/arm/traps.c +12 -2
+static void do_trap_psci(struct cpu_user_regs *regs)
+{
+    register_t fid = PSCI_ARG(regs,0);
 
-    psci_call = arm_psci_table[PSCI_OP_REG(regs)].fn;
-    if ( psci_call == NULL )
+    /* preloading in case psci_mode_check fails */
+    PSCI_RESULT_REG(regs) = (int32_t)PSCI_INVALID_PARAMETERS;
[...]
+    case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU:
+        if ( psci_mode_check(current->domain, fid) )
+            PSCI_RESULT_REG(regs) =
+               (uint32_t) do_psci_0_2_migrate_info_up_cpu();
+        else
+            PSCI_RESULT_REG(regs) = (uint32_t)PSCI_INVALID_PARAMETERS;
+        break;

[...]

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

Quoted 9 lines
xen/arch/arm/traps.c +9 -0
+    case PSCI_0_2_FN_CPU_ON:
+    case PSCI_0_2_FN64_CPU_ON:
+        if ( psci_mode_check(current->domain, fid) )
+        {
+        register_t vcpuid = PSCI_ARG(regs,1);
+        register_t epoint = PSCI_ARG(regs,2);
+        register_t cid = PSCI_ARG(regs,3);
+        PSCI_RESULT_REG(regs) =
+            (int32_t) do_psci_0_2_cpu_on(vcpuid, epoint, cid);
Quoted 1 line

Indentation here is broken.

i will fix in patchset v6

Quoted 4 lines

I notice that sometimes you have an else case setting PSCI_INVALID_PARAMETERS and other times you don't. Is that just an oversight or is there a reason why they should differ?

It was done because rest of the functions were using default preloaded value with return type int32 , functions with else case are functions that have return type other than int32(uint32 or register_t) but as you have commented further if PSCI* result codes do not require casting, this will go away.
To summarize i will remove the casting of result codes this will also do away the need of else statements in patchset v6.

Quoted 13 lines

I don't think you need to cast the PSCI_* result codes BTW.

[...]

xen/arch/arm/vpsci.c int do_psci_cpu_off(uint32_t power_state) · line 122

Quoted 6 lines
xen/arch/arm/vpsci.c +6 -0
+int32_t do_psci_0_2_cpu_suspend(uint32_t power_state, register_t entry_point,
+                            register_t context_id)
+{
+    struct vcpu *v = current;
+    struct domain *d = v->domain;
+    struct cpu_user_regs *regs = &v->arch.cpu_info->guest_cpu_user_regs;

I think it would make sense to pass this as an argument, but if not then guest_cpu_user_regs() is the accessor to use.

sure, will take care in patchset v6

Quoted 24 lines
Quoted 5 lines
xen/arch/arm/vpsci.c +5 -0
+
+    if ( is_32bit_domain(d) )
+    {
+        regs->pc32 = entry_point;
+        regs->r0 = context_id;

xen/arch/arm/vpsci.c int do_psci_cpu_off(uint32_t power_state) · line 137

Quoted 10 lines
xen/arch/arm/vpsci.c +10 -0
+    }
+#ifdef CONFIG_ARM_64
+    else
+    {
+        regs->pc = entry_point;
+        regs->x0 = context_id;
+    }
+#endif
+    vcpu_block_unless_event_pending(v);
+    return PSCI_SUCCESS;

This only seems to be handling the case where the requested power state is power down and not the standby state.

By my reading when bit 16 if the power_state argument is 0 (standby) then entry_point and context_id are ignored and the PSCI call is expected to return success to the place it was called from, not jump to entry_point.

Quoted 5 lines

If bit 16 is one you are supposed to return to entry_point with x0/r0 set to context_id, but because you return PSCI_SUCCESS that will get written to x0/r0 by the generic handler clobbering your write of x0/r0 above. You should probably return the desired value (with an explanatory comment)

valid point, i am just wondering why kvm implementation ignored these values, i will implement it in next patchset

Quoted 3 lines

The upper bits of power_state also describe an affinity level to put to sleep, which you also don't handle AFAICT. Perhaps since we don't actually have affinities > 0 what you've done is OK, what do you think?

I think it is better to put a comment explicitly stating that we have ignored the value because affinities > 0 are not valid for xen or we can check for affinity and return if it is greater than zero. I think i'll go with check, will take care in next patchset

Quoted 9 lines

The lower bits are supposed to be some sort of per platform ID which we are supposed to have exposed via tables. I'm not sure there are any DTB bindings for that, so perhaps we can ignore it.

The handling of bit 16 is the only bit which really concerns me here, the rest seem like things we can tolerate.

Ian.

Thanks
parth

#4 lore raw
Quoted 5 lines · Parth Dixit
Quoted 4 lines

I notice that sometimes you have an else case setting PSCI_INVALID_PARAMETERS and other times you don't. Is that just an oversight or is there a reason why they should differ?

Quoted 7 lines

It was done because rest of the functions were using default preloaded value with return type int32 , functions with else case are functions that have return type other than int32(uint32 or register_t) but as you have commented further if PSCI* result codes do not require casting, this will go away.
To summarize i will remove the casting of result codes this will also do away the need of else statements in patchset v6.

Sounds good.

Quoted 24 lines
Quoted 24 lines
Quoted 5 lines
xen/arch/arm/vpsci.c +5 -0
+
+    if ( is_32bit_domain(d) )
+    {
+        regs->pc32 = entry_point;
+        regs->r0 = context_id;

xen/arch/arm/vpsci.c int do_psci_cpu_off(uint32_t power_state) · line 137

Quoted 10 lines
xen/arch/arm/vpsci.c +10 -0
+    }
+#ifdef CONFIG_ARM_64
+    else
+    {
+        regs->pc = entry_point;
+        regs->x0 = context_id;
+    }
+#endif
+    vcpu_block_unless_event_pending(v);
+    return PSCI_SUCCESS;

This only seems to be handling the case where the requested power state is power down and not the standby state.

By my reading when bit 16 if the power_state argument is 0 (standby) then entry_point and context_id are ignored and the PSCI call is expected to return success to the place it was called from, not jump to entry_point.

Quoted 7 lines
Quoted 5 lines

If bit 16 is one you are supposed to return to entry_point with x0/r0 set to context_id, but because you return PSCI_SUCCESS that will get written to x0/r0 by the generic handler clobbering your write of x0/r0 above. You should probably return the desired value (with an explanatory comment)

valid point, i am just wondering why kvm implementation ignored these values,

It's possible that I'm being overly picky in reading the spec.

My concern is that there isn't currently much in the way of reference implementations of this thing to compare against for real world behaviour. When such things turn up and behave differently to Xen (or KVM for that matter), perhaps because they interpret the ambiguities in the spec differently, and the spec is clarified we may end up having to change. Which then runs the risk of regressions for existing guests etc.

Quoted 1 line

i will implement it in next patchset

Thanks.

Quoted 8 lines
Quoted 3 lines

The upper bits of power_state also describe an affinity level to put to sleep, which you also don't handle AFAICT. Perhaps since we don't actually have affinities > 0 what you've done is OK, what do you think?

I think it is better to put a comment explicitly stating that we have ignored the value because affinities > 0 are not valid for xen or we can check for affinity and return if it is greater than zero. I think i'll go with check, will take care in next patchset

I'm not 100% what the spec allows/requires us to do here. I've asked ARM. I suspect shutting down only the local core would be permissible.

Ian.

#5 lore raw
Quoted 11 lines · Ian Campbell
Quoted 8 lines
Quoted 3 lines

The upper bits of power_state also describe an affinity level to put to sleep, which you also don't handle AFAICT. Perhaps since we don't actually have affinities > 0 what you've done is OK, what do you think?

I think it is better to put a comment explicitly stating that we have ignored the value because affinities > 0 are not valid for xen or we can check for affinity and return if it is greater than zero. I think i'll go with check, will take care in next patchset

I'm not 100% what the spec allows/requires us to do here. I've asked ARM. I suspect shutting down only the local core would be permissible.

I've asked ARM and this is fine. If the caller asks us to power down the "cluster" we don't have to actually go that deep and since we are virtualised it doesn't really matter.

BTW, WRT to stand by vs power down (bit 16). For standby you always return to the next instruction after the SMC where as for power down you can return either to the next instruction or the entry point address. Since we don't actually implement hardware sleep states which don't preserve the full CPU state we may as well take the easy option of always returning to the next instruction.

Ian.