Skip to contentSkip to conversation

PSCI v0.2 support and DT bindings

PATCH Superseded Ashwin Chaugule 4 participants 12 messages Apr 25, 2014 – Apr 28, 2014

Subsystems (4)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v8 cover PSCI v0.2 support and DT bindings

This patchset introduces some functions as defined in the PSCI v0.2 spec and a corresponding DT binding to differentiate it from previous PSCI versions. Since PSCIv0.2 has standard function IDs, it is possible to statically assign them rather than depend on values from DT.

This patchset depends on the PSCI header (/uapi/linux/psci.h) introduced by
http://www.spinics.net/lists/arm-kernel/msg319712.html

Changes in v8:

		-	Replace msleep(100) with 10 x msleep(10)

Changes in v7:
- Add two new functions: SYSTEM_OFF and SYSTEM_RESET as defined in PSCIv0.2.
- Added a delay before calling cpu_kill to avoid race with cpu_die.

Changes in v6:
- rebase on top of uapi/linux/psci.h introduced by Anups patch
http://www.spinics.net/lists/arm-kernel/msg319712.html
- rebase on top of Catalins tree tip.

Changes in v5:
- Add uapi/linux/psci.h to kbuild
- ret with err if PSCI_ID_VERSION is not implemented.

Changes in v4:

        -       Correct copyright banner format.
        -       Check if PSCI Version ID is supported.
        -       Add all PSCI RET codes in uapi header.
        -       Explicitely ret 1 from psci_cpu_kill()

Changes in v3:

        -       Roll up common functionality for getting conduit method.
        -       Remove #defines for ARM32 and ARM64 in uapi/linux/psci.h
        -       Remove functions not supported by PSCI v0.1
        -       Misc cleanups.
        -       Add PSCI_AFFINITY_INFO return types in uapi header.
        -       Changed function names for PSCI v0.1 and PSCI v0.2
        -       Added copyright info to uapi header.
        -       Fixed args to affinity_info call.
        -       Fix typo in psci_init definition when PSCI is not defined.

Changes in v2:

        -       Add AFFINITY_INFO and MIGRATE_INFO_TYPE functions.
        -       Add binding Documentation.
        -       Add function to get PSCI version.
        -       Add common #defines in uapi/linux/psci.h
        -       Implement cpu_kill and check if CPU is dead via AFFINITY_INFO.
        -       Misc cleanups.

Changes in v1:

- Add new binding "arm, psci-0.2"
- Separate conduit and PSCI function assignment methods.

Ashwin Chaugule (3):
PSCI: Add initial support for PSCIv0.2 functions
Documentation: devicetree: Add new binding for PSCIv0.2
ARM: Check if a CPU has gone offline

 Documentation/devicetree/bindings/arm/psci.txt |  35 ++++-
 arch/arm/include/asm/psci.h                    |   7 +-
 arch/arm/kernel/psci.c                         | 196 +++++++++++++++++++-----
 arch/arm/kernel/psci_smp.c                     |  32 ++++
 arch/arm64/include/asm/psci.h                  |   2 +-
 arch/arm64/kernel/psci.c                       | 200 ++++++++++++++++++++-----
 include/uapi/linux/psci.h                      |   5 +
 7 files changed, 399 insertions(+), 78 deletions(-)
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH v8 1/3 PSCI: Add initial support for PSCIv0.2 functions

The PSCIv0.2 spec defines standard values of function IDs and introduces a few new functions. Detect version of PSCI and appropriately select the right PSCI functions.

---
 arch/arm/include/asm/psci.h   |   7 +-
 arch/arm/kernel/psci.c        | 196 +++++++++++++++++++++++++++++++++--------
 arch/arm64/include/asm/psci.h |   2 +-
 arch/arm64/kernel/psci.c      | 200 ++++++++++++++++++++++++++++++++++--------
 4 files changed, 328 insertions(+), 77 deletions(-)
arch/arm/include/asm/psci.h +5 -2
index c4ae171..b93e34a 100644
@@ -29,16 +29,19 @@ struct psci_operations {
 	int (*cpu_off)(struct psci_power_state state);
 	int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
 	int (*migrate)(unsigned long cpuid);
+	int (*affinity_info)(unsigned long target_affinity,
+			unsigned long lowest_affinity_level);
+	int (*migrate_info_type)(void);
 };
 
 extern struct psci_operations psci_ops;
 extern struct smp_operations psci_smp_ops;
 
 #ifdef CONFIG_ARM_PSCI
-void psci_init(void);
+int psci_init(void);
 bool psci_smp_available(void);
 #else
-static inline void psci_init(void) { }
+static inline int psci_init(void) { }
 static inline bool psci_smp_available(void) { return false; }
 #endif
 
arch/arm/kernel/psci.c +159 -37

269 lines not on this page · raw message

arch/arm64/include/asm/psci.h +1 -1
index d15ab8b4..e5312ea 100644
@@ -14,6 +14,6 @@
 #ifndef __ASM_PSCI_H
 #define __ASM_PSCI_H
 
-void psci_init(void);
+int psci_init(void);
 
 #endif /* __ASM_PSCI_H */
arch/arm64/kernel/psci.c +163 -37

282 lines not on this page · raw message

Signature · 1 line
1.8.3.2
#2 lore raw

PATCH v8 2/3 Documentation: devicetree: Add new binding for PSCIv0.2

In reply to Ashwin Chaugule

The PSCI v0.2+ spec defines standard values for PSCI function IDs. Add a new binding entry so that pre v0.2 implementations can use DT entries for function IDs and v0.2+ implementations use standard entries as defined by the PSCIv0.2 specification.

---
 Documentation/devicetree/bindings/arm/psci.txt | 35 +++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/arm/psci.txt +34 -1
index 433afe9..d01a90b 100644
@@ -21,7 +21,15 @@ to #0.
 
 Main node required properties:
 
- - compatible    : Must be "arm,psci"
+ - compatible    : should contain at least one of:
+
+				 * "arm,psci" : for implementations complying to PSCI versions prior to
+					0.2. For these cases function IDs must be provided.
+
+				 * "arm,psci-0.2" : for implementations complying to PSCI 0.2. Function
+					IDs are not required and should be ignored by an OS with PSCI 0.2
+					support, but are permitted to be present for compatibility with
+					existing software when "arm,psci" is later in the compatible list.
 
  - method        : The method of calling the PSCI firmware. Permitted
                    values are:
@@ -45,6 +53,8 @@ Main node optional properties:
 
 Example:
 
+Case 1: PSCI v0.1 only.
+
 	psci {
 		compatible	= "arm,psci";
 		method		= "smc";
@@ -53,3 +63,26 @@ Example:
 		cpu_on		= <0x95c10002>;
 		migrate		= <0x95c10003>;
 	};
+
+
+Case 2: PSCI v0.2 only
+
+	psci {
+		compatible	= "arm,psci-0.2";
+		method		= "smc";
+	};
+
+Case 3: PSCI v0.2 and PSCI v0.1.
+
+	As described above, for compatibility with existing kernels, the
+	hypervisor will likely want to provide IDs, e.g.
+
+	psci {
+		compatible = "arm,psci-0.2", "arm,psci";
+		method = "hvc";
+
+		cpu_on = < arbitrary value >;
+		cpu_off = < arbitrary value >;
+
+		...
+	};
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

In reply to Ashwin Chaugule

PSCIv0.2 adds a new function called AFFINITY_INFO, which can be used to query if a specified CPU has actually gone offline. Calling this function via cpu_kill ensures that a CPU has quiesced after a call to cpu_die.

---
 arch/arm/kernel/psci_smp.c | 32 ++++++++++++++++++++++++++++++++
 include/uapi/linux/psci.h  |  5 +++++
 2 files changed, 37 insertions(+)
arch/arm/kernel/psci_smp.c +32 -0
index 570a48c..94e230c 100644
@@ -16,6 +16,8 @@
 #include <linux/init.h>
 #include <linux/smp.h>
 #include <linux/of.h>
+#include <linux/delay.h>
+#include <uapi/linux/psci.h>
 
 #include <asm/psci.h>
 #include <asm/smp_plat.h>
@@ -66,6 +68,35 @@ void __ref psci_cpu_die(unsigned int cpu)
        /* We should never return */
        panic("psci: cpu %d failed to shutdown\n", cpu);
 }
+
+int __ref psci_cpu_kill(unsigned int cpu)
+{
+	int err, i;
+
+	if (!psci_ops.affinity_info)
+		return 1;
+	/*
+	 * cpu_kill could race with cpu_die and we can
+	 * potentially end up declaring this cpu undead
+	 * while it is dying. So, try again a few times.
+	 */
+
+	for (i=0; i<10; i++) {
+		err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
+
+		if (err == PSCI_AFFINITY_INFO_RET_OFF)
+			return 1;
+
+		msleep(10);
+		pr_info("Retrying again to check for CPU kill\n");
+	}
+
+	pr_err("psci: Cannot kill CPU:%d, psci ret val: %d\n",
+			cpu, err);
+	/* Make platform_cpu_kill() fail. */
+	return 0;
+}
+
 #endif
 
 bool __init psci_smp_available(void)
@@ -78,5 +109,6 @@ struct smp_operations __initdata psci_smp_ops = {
 	.smp_boot_secondary	= psci_boot_secondary,
 #ifdef CONFIG_HOTPLUG_CPU
 	.cpu_die		= psci_cpu_die,
+	.cpu_kill		= psci_cpu_kill,
 #endif
 };
include/uapi/linux/psci.h +5 -0
index a4136c3..857209b 100644
@@ -74,4 +74,9 @@
 #define PSCI_RET_NOT_PRESENT			-7
 #define PSCI_RET_DISABLED			-8
 
+/* Return values from the PSCI_ID_AFFINITY_INFO Function. */
+#define PSCI_AFFINITY_INFO_RET_ON			0
+#define PSCI_AFFINITY_INFO_RET_OFF			1
+#define PSCI_AFFINITY_INFO_RET_ON_PENDING	2
+
 #endif /* _UAPI_LINUX_PSCI_H */
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

Hi Ashwin,

Quoted 73 lines · Ashwin Chaugule

PSCIv0.2 adds a new function called AFFINITY_INFO, which can be used to query if a specified CPU has actually gone offline. Calling this function via cpu_kill ensures that a CPU has quiesced after a call to cpu_die.

---
 arch/arm/kernel/psci_smp.c | 32 ++++++++++++++++++++++++++++++++
 include/uapi/linux/psci.h  |  5 +++++
 2 files changed, 37 insertions(+)
arch/arm/kernel/psci_smp.c +32 -0
index 570a48c..94e230c 100644
@@ -16,6 +16,8 @@
 #include <linux/init.h>
 #include <linux/smp.h>
 #include <linux/of.h>
+#include <linux/delay.h>
+#include <uapi/linux/psci.h>
 
 #include <asm/psci.h>
 #include <asm/smp_plat.h>
@@ -66,6 +68,35 @@ void __ref psci_cpu_die(unsigned int cpu)
        /* We should never return */
        panic("psci: cpu %d failed to shutdown\n", cpu);
 }
+
+int __ref psci_cpu_kill(unsigned int cpu)
+{
+       int err, i;
+
+       if (!psci_ops.affinity_info)
+               return 1;
+       /*
+        * cpu_kill could race with cpu_die and we can
+        * potentially end up declaring this cpu undead
+        * while it is dying. So, try again a few times.
+        */
+
+       for (i=0; i<10; i++) {
+               err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
+
+               if (err == PSCI_AFFINITY_INFO_RET_OFF)
+                       return 1;
+
+               msleep(10);
+               pr_info("Retrying again to check for CPU kill\n");
+       }
+
+       pr_err("psci: Cannot kill CPU:%d, psci ret val: %d\n",
+                       cpu, err);
+       /* Make platform_cpu_kill() fail. */
+       return 0;
+}
+
 #endif
 
 bool __init psci_smp_available(void)
@@ -78,5 +109,6 @@ struct smp_operations __initdata psci_smp_ops = {
        .smp_boot_secondary     = psci_boot_secondary,
 #ifdef CONFIG_HOTPLUG_CPU
        .cpu_die                = psci_cpu_die,
+       .cpu_kill               = psci_cpu_kill,
 #endif
 };
include/uapi/linux/psci.h +0 -0
index a4136c3..857209b 100644

include/uapi/linux/psci.h line 80

Quoted 7 lines
include/uapi/linux/psci.h +4 -0
@@ -74,4 +74,9 @@
 #define PSCI_RET_NOT_PRESENT                   -7
 #define PSCI_RET_DISABLED                      -8
 
+/* Return values from the PSCI_ID_AFFINITY_INFO Function. */
+#define PSCI_AFFINITY_INFO_RET_ON                      0
+#define PSCI_AFFINITY_INFO_RET_OFF                     1
+#define PSCI_AFFINITY_INFO_RET_ON_PENDING      2

I have already added this return values in v10 patchset for PSCI v0.2 emulation for KVM ARM/ARM64.
(http://www.spinics.net/lists/kvm-arm/msg09062.html)

Please rebase your patch against that.

Quoted 5 lines
include/uapi/linux/psci.h +1 -1
+
 #endif /* _UAPI_LINUX_PSCI_H */
--

1.8.3.2

Regards,
Anup

#5 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

Hello,

Quoted 15 lines · Anup Patel

include/uapi/linux/psci.h line 80

Quoted 10 lines
include/uapi/linux/psci.h +4 -0
@@ -74,4 +74,9 @@
 #define PSCI_RET_NOT_PRESENT                   -7
 #define PSCI_RET_DISABLED                      -8
 
+/* Return values from the PSCI_ID_AFFINITY_INFO Function. */
+#define PSCI_AFFINITY_INFO_RET_ON                      0
+#define PSCI_AFFINITY_INFO_RET_OFF                     1
+#define PSCI_AFFINITY_INFO_RET_ON_PENDING      2

I have already added this return values in v10 patchset for PSCI v0.2 emulation for KVM ARM/ARM64.
(http://www.spinics.net/lists/kvm-arm/msg09062.html)

Quoted 1 line

Please rebase your patch against that.

Ok will do.

Whats the merge plan for these patches? We both share a common header but the code that uses it would seemingly go up via different trees. armv8 (Catalin) and KVM (Christoffer)?

Cheers,
Ashwin

#6 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

Quoted 18 lines · Ashwin Chaugule

Hello,

Quoted 15 lines · Anup Patel

include/uapi/linux/psci.h line 80

Quoted 10 lines
include/uapi/linux/psci.h +4 -0
@@ -74,4 +74,9 @@
 #define PSCI_RET_NOT_PRESENT                   -7
 #define PSCI_RET_DISABLED                      -8
 
+/* Return values from the PSCI_ID_AFFINITY_INFO Function. */
+#define PSCI_AFFINITY_INFO_RET_ON                      0
+#define PSCI_AFFINITY_INFO_RET_OFF                     1
+#define PSCI_AFFINITY_INFO_RET_ON_PENDING      2

I have already added this return values in v10 patchset for PSCI v0.2 emulation for KVM ARM/ARM64.
(http://www.spinics.net/lists/kvm-arm/msg09062.html)

Quoted 9 lines
Quoted 1 line

Please rebase your patch against that.

Ok will do.

Whats the merge plan for these patches? We both share a common header but the code that uses it would seemingly go up via different trees. armv8 (Catalin) and KVM (Christoffer)?

Are they inter-dependent? I thought your patches depended on Anup's - not the other way around?

If my assumption is correct, I think we can make sure to send the pull request to kvm/next early and ask Catalin to pull in kvm/next before pulling your changes.

I'm cc'ing both Catalin and Paolo here for their advice.

Thanks,
-Christoffer

#7 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

Quoted 11 lines · Christoffer Dall
Quoted 5 lines

Whats the merge plan for these patches? We both share a common header but the code that uses it would seemingly go up via different trees. armv8 (Catalin) and KVM (Christoffer)?

Are they inter-dependent? I thought your patches depended on Anup's - not the other way around?

If my assumption is correct, I think we can make sure to send the pull request to kvm/next early and ask Catalin to pull in kvm/next before pulling your changes.

Right. My patches depend on the header (uapi/psci.h) introduced by Anups patchset.

Cheers,
Ashwin

#8 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

In reply to Christoffer Dall

Il 28/04/2014 14:23, Christoffer Dall ha scritto:

Quoted 8 lines

Are they inter-dependent? I thought your patches depended on Anup's - not the other way around?

If my assumption is correct, I think we can make sure to send the pull request to kvm/next early and ask Catalin to pull in kvm/next before pulling your changes.

I'm cc'ing both Catalin and Paolo here for their advice.

Is Anup's patchset already on a branch? If you send me a pointer to it I can look at that branch history and see what's best.

Paolo

#9 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

Quoted 4 lines · Paolo Bonzini

Il 28/04/2014 14:23, Christoffer Dall ha scritto:

Quoted 3 lines

Are they inter-dependent? I thought your patches depended on Anup's - not the other way around?

Quoted 9 lines
Quoted 5 lines

If my assumption is correct, I think we can make sure to send the pull request to kvm/next early and ask Catalin to pull in kvm/next before pulling your changes.

I'm cc'ing both Catalin and Paolo here for their advice.

Is Anup's patchset already on a branch? If you send me a pointer to it I can look at that branch history and see what's best.

I didn't merge it yet - need to make one final pass over it (likely later tonight).

But this is the series:
https://lists.cs.columbia.edu/pipermail/kvmarm/2014-April/009061.html

I believe Ashwin's patch set depends only on "ARM/ARM64: KVM: Add common header for PSCI related defines".

Thanks,
-Christoffer

#10 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

Il 28/04/2014 15:06, Christoffer Dall ha scritto:

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

Is Anup's patchset already on a branch? If you send me a pointer to it I can look at that branch history and see what's best.

I didn't merge it yet - need to make one final pass over it (likely later tonight).

But this is the series:
https://lists.cs.columbia.edu/pipermail/kvmarm/2014-April/009061.html

Even better. :)

1) Catalin can apply "Add common header for PSCI related defines", or Ashwin can resend his series with the patch at the beginning. Duplicate commits are fine, especially for seldom-modified files where they do not cause conflicts.

2) Send Anup's patchset as a pull request to both me and Catalin, relative to v3.16-rc1, both of us can apply it and Ashwin's series can be commit on top.

Paolo

#11 lore raw

PATCH v8 3/3 ARM: Check if a CPU has gone offline

Quoted 16 lines · Paolo Bonzini

Il 28/04/2014 15:06, Christoffer Dall ha scritto:

Quoted 10 lines
Quoted 4 lines
Quoted 4 lines

Is Anup's patchset already on a branch? If you send me a pointer to it I can look at that branch history and see what's best.

I didn't merge it yet - need to make one final pass over it (likely later tonight).

But this is the series:
https://lists.cs.columbia.edu/pipermail/kvmarm/2014-April/009061.html

Even better. :)

Quoted 9 lines

1) Catalin can apply "Add common header for PSCI related defines", or Ashwin can resend his series with the patch at the beginning. Duplicate commits are fine, especially for seldom-modified files where they do not cause conflicts.

2) Send Anup's patchset as a pull request to both me and Catalin, relative to v3.16-rc1, both of us can apply it and Ashwin's series can be commit on top.

(2) sounds cleaner to me, we'll do that

thanks,
-Christoffer