[PATCH v3 05/22] arm64: capabilities: Add flags to handle the conflicts on late CPU

2018-02-09 Thread Suzuki K Poulose
When a CPU is brought up, it is checked against the caps that are
known to be enabled on the system (via verify_local_cpu_capabilities()).
Based on the state of the capability on the CPU vs. that of System we
could have the following combinations of conflict.

x-x
| Type  | System   | Late CPU |
|-|
|  a|   y  |n |
|-|
|  b|   n  |y |
x-x

Case (a) is not permitted for caps which are system features, which the
system expects all the CPUs to have (e.g VHE). While (a) is ignored for
all errata work arounds. However, there could be exceptions to the plain
filtering approach. e.g, KPTI is an optional feature for a late CPU as
long as the system already enables it.

Case (b) is not permitted for errata work arounds that cannot be activated
after the kernel has finished booting.And we ignore (b) for features. Here,
yet again, KPTI is an exception, where if a late CPU needs KPTI we are too
late to enable it (because we change the allocation of ASIDs etc).

Add two different flags to indicate how the conflict should be handled.

 ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU - CPUs may have the capability
 ARM64_CPUCAP_OPTIONAL_FOR_LATE_CPU - CPUs may not have the cappability.

Now that we have the flags to describe the behavior of the errata and
the features, as we treat them, define types for ERRATUM and FEATURE.

Cc: Will Deacon 
Cc: Mark Rutland 
Reviewed-by: Dave Martin 
Signed-off-by: Suzuki K Poulose 
---
 arch/arm64/include/asm/cpufeature.h | 70 -
 arch/arm64/kernel/cpu_errata.c  |  8 ++---
 arch/arm64/kernel/cpufeature.c  | 30 
 3 files changed, 88 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/include/asm/cpufeature.h 
b/arch/arm64/include/asm/cpufeature.h
index a2b708b9a6e3..5f58623a4599 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -145,7 +145,8 @@ extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0;
  *capabilities and if there is a conflict, the kernel takes an action, 
based
  *on the severity (e.g, a CPU could be prevented from booting or cause a
  *kernel panic). The CPU is allowed to "affect" the state of the 
capability,
- *if it has not been finalised already.
+ *if it has not been finalised already. See section 5 for more details on
+ *conflicts.
  *
  * 4) Action: As mentioned in (2), the kernel can take an action for each 
detected
  *capability, on all CPUs on the system. Appropriate actions include, 
turning
@@ -161,6 +162,34 @@ extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0;
  * b) Any late CPU, brought up after (1), the action is triggered via:
  * check_local_cpu_capabilities() -> 
verify_local_cpu_capabilities()
  *
+ * 5) Conflicts: Based on the state of the capability on a late CPU vs. the 
system
+ *state, we could have the following combinations :
+ *
+ * x-x
+ * | Type  | System   | Late CPU |
+ * |-|
+ * |  a|   y  |n |
+ * |-|
+ * |  b|   n  |y |
+ * x-x
+ *
+ * Two separate flag bits are defined to indicate whether each kind of 
conflict
+ * can be allowed:
+ * ARM64_CPUCAP_OPTIONAL_FOR_LATE_CPU - Case(a) is allowed
+ * ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU - Case(b) is allowed
+ *
+ * Case (a) is not permitted for a capability that the system requires
+ * all CPUs to have in order for the capability to be enabled. This is
+ * typical for capabilities that represent enhanced functionality.
+ *
+ * Case (b) is not permitted for a capability that must be enabled during
+ * boot if any CPU in the system requires it in order to run safely.
+ * This is typical for erratum work arounds that cannot be enabled after 
the
+ * corresponding capability is finalised.
+ *
+ * In some non-typical cases either both (a) and (b), or neither, should be
+ * permitted. This can be described by including neither or both flags in 
the
+ * capability's type field.
  */
 
 
@@ -174,6 +203,33 @@ extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0;
 #define SCOPE_SYSTEM   ARM64_CPUCAP_SCOPE_SYSTEM
 #define SCOPE_LOCAL_CPU
ARM64_CPUCAP_SCOPE_LOCAL_CPU
 
+/*
+ * Is it permitted for a late CPU to have this capability when system
+ * hasn't already enabled it ?
+ */
+#define ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU((u16)BIT(4))
+/* Is it safe for a late CPU to miss this capability when system has it */
+#define 

[PATCH v3 05/22] arm64: capabilities: Add flags to handle the conflicts on late CPU

2018-02-09 Thread Suzuki K Poulose
When a CPU is brought up, it is checked against the caps that are
known to be enabled on the system (via verify_local_cpu_capabilities()).
Based on the state of the capability on the CPU vs. that of System we
could have the following combinations of conflict.

x-x
| Type  | System   | Late CPU |
|-|
|  a|   y  |n |
|-|
|  b|   n  |y |
x-x

Case (a) is not permitted for caps which are system features, which the
system expects all the CPUs to have (e.g VHE). While (a) is ignored for
all errata work arounds. However, there could be exceptions to the plain
filtering approach. e.g, KPTI is an optional feature for a late CPU as
long as the system already enables it.

Case (b) is not permitted for errata work arounds that cannot be activated
after the kernel has finished booting.And we ignore (b) for features. Here,
yet again, KPTI is an exception, where if a late CPU needs KPTI we are too
late to enable it (because we change the allocation of ASIDs etc).

Add two different flags to indicate how the conflict should be handled.

 ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU - CPUs may have the capability
 ARM64_CPUCAP_OPTIONAL_FOR_LATE_CPU - CPUs may not have the cappability.

Now that we have the flags to describe the behavior of the errata and
the features, as we treat them, define types for ERRATUM and FEATURE.

Cc: Will Deacon 
Cc: Mark Rutland 
Reviewed-by: Dave Martin 
Signed-off-by: Suzuki K Poulose 
---
 arch/arm64/include/asm/cpufeature.h | 70 -
 arch/arm64/kernel/cpu_errata.c  |  8 ++---
 arch/arm64/kernel/cpufeature.c  | 30 
 3 files changed, 88 insertions(+), 20 deletions(-)

diff --git a/arch/arm64/include/asm/cpufeature.h 
b/arch/arm64/include/asm/cpufeature.h
index a2b708b9a6e3..5f58623a4599 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -145,7 +145,8 @@ extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0;
  *capabilities and if there is a conflict, the kernel takes an action, 
based
  *on the severity (e.g, a CPU could be prevented from booting or cause a
  *kernel panic). The CPU is allowed to "affect" the state of the 
capability,
- *if it has not been finalised already.
+ *if it has not been finalised already. See section 5 for more details on
+ *conflicts.
  *
  * 4) Action: As mentioned in (2), the kernel can take an action for each 
detected
  *capability, on all CPUs on the system. Appropriate actions include, 
turning
@@ -161,6 +162,34 @@ extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0;
  * b) Any late CPU, brought up after (1), the action is triggered via:
  * check_local_cpu_capabilities() -> 
verify_local_cpu_capabilities()
  *
+ * 5) Conflicts: Based on the state of the capability on a late CPU vs. the 
system
+ *state, we could have the following combinations :
+ *
+ * x-x
+ * | Type  | System   | Late CPU |
+ * |-|
+ * |  a|   y  |n |
+ * |-|
+ * |  b|   n  |y |
+ * x-x
+ *
+ * Two separate flag bits are defined to indicate whether each kind of 
conflict
+ * can be allowed:
+ * ARM64_CPUCAP_OPTIONAL_FOR_LATE_CPU - Case(a) is allowed
+ * ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU - Case(b) is allowed
+ *
+ * Case (a) is not permitted for a capability that the system requires
+ * all CPUs to have in order for the capability to be enabled. This is
+ * typical for capabilities that represent enhanced functionality.
+ *
+ * Case (b) is not permitted for a capability that must be enabled during
+ * boot if any CPU in the system requires it in order to run safely.
+ * This is typical for erratum work arounds that cannot be enabled after 
the
+ * corresponding capability is finalised.
+ *
+ * In some non-typical cases either both (a) and (b), or neither, should be
+ * permitted. This can be described by including neither or both flags in 
the
+ * capability's type field.
  */
 
 
@@ -174,6 +203,33 @@ extern struct arm64_ftr_reg arm64_ftr_reg_ctrel0;
 #define SCOPE_SYSTEM   ARM64_CPUCAP_SCOPE_SYSTEM
 #define SCOPE_LOCAL_CPU
ARM64_CPUCAP_SCOPE_LOCAL_CPU
 
+/*
+ * Is it permitted for a late CPU to have this capability when system
+ * hasn't already enabled it ?
+ */
+#define ARM64_CPUCAP_PERMITTED_FOR_LATE_CPU((u16)BIT(4))
+/* Is it safe for a late CPU to miss this capability when system has it */
+#define ARM64_CPUCAP_OPTIONAL_FOR_LATE_CPU ((u16)BIT(5))
+
+/*
+ * CPU errata workarounds that need to be