Skip to contentSkip to conversation

ARMv8.5-RNG support

PATCH Superseded Mark Brown 6 participants 30 messages Jan 10, 2020 – Jan 16, 2020

Subsystems (2)

v10 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

v10 cover ARMv8.5-RNG support

This series is based on Richard Henderson's previous v7, it addresses review comments from that version by splitting the boot and runtime interaction with the core random code so that they are completely separate and adds a new change that uses the v8.5-RNG extension to seed KASLR when ARCH_RANDOM is enabled.

v10:
- Spell out that we're adding data not entropy from setup_arch() in the commit message for patch 2.
v9:
- Make another static inline helper for early feature checks.
- Add init annotations.
- Use xor to add RNDR output to seed for KASLR.

Mark Brown (2):
arm64: random: Add data to pool from setup_arch()
arm64: Use v8.5-RNG entropy for KASLR seed

Richard Henderson (1):
arm64: Implement archrandom.h for ARMv8.5-RNG

 Documentation/arm64/cpu-feature-registers.rst |  2 +
 arch/arm64/Kconfig                            | 12 +++
 arch/arm64/include/asm/archrandom.h           | 97 +++++++++++++++++++
 arch/arm64/include/asm/cpucaps.h              |  3 +-
 arch/arm64/include/asm/sysreg.h               |  4 +
 arch/arm64/kernel/cpufeature.c                | 13 +++
 arch/arm64/kernel/kaslr.c                     | 11 +++
 arch/arm64/kernel/setup.c                     |  2 +
 8 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/archrandom.h
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#1 lore raw

PATCH v10 1/3 arm64: Implement archrandom.h for ARMv8.5-RNG

From: Richard Henderson <[email protected]>

Expose the ID_AA64ISAR0.RNDR field to userspace, as the RNG system registers are always available at EL0.

Implement arch_get_random_seed_long using RNDR. Given that the TRNG is likely to be a shared resource between cores, and VMs, do not explicitly force re-seeding with RNDRRS. In order to avoid code complexity and potential issues with hetrogenous systems only provide values after cpufeature has finalized the system capabilities.

[Modified to only function after cpufeature has finalized the system capabilities and move all the code into the header -- broonie]

---
 Documentation/arm64/cpu-feature-registers.rst |  2 +
 arch/arm64/Kconfig                            | 12 ++++
 arch/arm64/include/asm/archrandom.h           | 67 +++++++++++++++++++
 arch/arm64/include/asm/cpucaps.h              |  3 +-
 arch/arm64/include/asm/sysreg.h               |  4 ++
 arch/arm64/kernel/cpufeature.c                | 13 ++++
 6 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/archrandom.h
Documentation/arm64/cpu-feature-registers.rst +2 -0
index b6e44884e3ad..ce320785fb0c 100644
@@ -117,6 +117,8 @@ infrastructure:
      +------------------------------+---------+---------+
      | Name                         |  bits   | visible |
      +------------------------------+---------+---------+
+     | RNDR                         | [63-60] |    y    |
+     +------------------------------+---------+---------+
      | TS                           | [55-52] |    y    |
      +------------------------------+---------+---------+
      | FHM                          | [51-48] |    y    |
arch/arm64/Kconfig +12 -0
index b1b4476ddb83..835f8158220e 100644
@@ -1484,6 +1484,18 @@ config ARM64_PTR_AUTH
 
 endmenu
 
+menu "ARMv8.5 architectural features"
+
+config ARCH_RANDOM
+	bool "Enable support for random number generation"
+	default y
+	help
+	  Random number generation (part of the ARMv8.5 Extensions)
+	  provides a high bandwidth, cryptographically secure
+	  hardware random number generator.
+
+endmenu
+
 config ARM64_SVE
 	bool "ARM Scalable Vector Extension support"
 	default y
arch/arm64/include/asm/archrandom.h new file +67 -0

67 lines not on this page · raw message

arch/arm64/include/asm/cpucaps.h +2 -1
index b92683871119..515f4fbcbf91 100644
@@ -56,7 +56,8 @@
 #define ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM	46
 #define ARM64_WORKAROUND_1542419		47
 #define ARM64_WORKAROUND_1319367		48
+#define ARM64_HAS_RNG				49
 
-#define ARM64_NCAPS				49
+#define ARM64_NCAPS				50
 
 #endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/sysreg.h +4 -0
index 6e919fafb43d..5e718f279469 100644
@@ -365,6 +365,9 @@
 #define SYS_CTR_EL0			sys_reg(3, 3, 0, 0, 1)
 #define SYS_DCZID_EL0			sys_reg(3, 3, 0, 0, 7)
 
+#define SYS_RNDR_EL0			sys_reg(3, 3, 2, 4, 0)
+#define SYS_RNDRRS_EL0			sys_reg(3, 3, 2, 4, 1)
+
 #define SYS_PMCR_EL0			sys_reg(3, 3, 9, 12, 0)
 #define SYS_PMCNTENSET_EL0		sys_reg(3, 3, 9, 12, 1)
 #define SYS_PMCNTENCLR_EL0		sys_reg(3, 3, 9, 12, 2)
@@ -539,6 +542,7 @@
 			 ENDIAN_SET_EL1 | SCTLR_EL1_UCI  | SCTLR_EL1_RES1)
 
 /* id_aa64isar0 */
+#define ID_AA64ISAR0_RNDR_SHIFT		60
 #define ID_AA64ISAR0_TS_SHIFT		52
 #define ID_AA64ISAR0_FHM_SHIFT		48
 #define ID_AA64ISAR0_DP_SHIFT		44
arch/arm64/kernel/cpufeature.c +13 -0
index 04cf64e9f0c9..0fea85228956 100644
@@ -119,6 +119,7 @@ static void cpu_enable_cnp(struct arm64_cpu_capabilities const *cap);
  * sync with the documentation of the CPU feature register ABI.
  */
 static const struct arm64_ftr_bits ftr_id_aa64isar0[] = {
+	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_RNDR_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_TS_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_FHM_SHIFT, 4, 0),
 	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_DP_SHIFT, 4, 0),
@@ -1566,6 +1567,18 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 		.sign = FTR_UNSIGNED,
 		.min_field_value = 1,
 	},
+#endif
+#ifdef CONFIG_ARCH_RANDOM
+	{
+		.desc = "Random Number Generator",
+		.capability = ARM64_HAS_RNG,
+		.type = ARM64_CPUCAP_SYSTEM_FEATURE,
+		.matches = has_cpuid_feature,
+		.sys_reg = SYS_ID_AA64ISAR0_EL1,
+		.field_pos = ID_AA64ISAR0_RNDR_SHIFT,
+		.sign = FTR_UNSIGNED,
+		.min_field_value = 1,
+	},
 #endif
 	{},
 };
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#13 lore raw

PATCH v10 2/3 arm64: random: Add data to pool from setup_arch()

In reply to Mark Brown

Since the arm64 ARCH_RANDOM implementation is not available until cpufeature has determined the system capabilities it can't be used by the generic random code to initialize the entropy pool for early use. Instead explicitly add some data to the pool from setup_arch() if the boot CPU supports v8.5-RNG, this is the point recommended by the generic code.

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide those will be done as a future step. Providing data is better than not doing so as it will still provide an increase in variation in the output from the random code and there will be no impact on the rate at which entropy is credited compared to what we have without this patch.

---
 arch/arm64/include/asm/archrandom.h | 30 +++++++++++++++++++++++++++++
 arch/arm64/kernel/setup.c           |  2 ++
 2 files changed, 32 insertions(+)
arch/arm64/include/asm/archrandom.h +30 -0
index 5ea5a1ce5a5f..2eb1db1f0bdf 100644
@@ -59,9 +59,39 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
 	return ok;
 }
 
+static inline bool __init __early_cpu_has_rndr(void)
+{
+	/* Open code as we run prior to the first call to cpufeature. */
+	unsigned long ftr = read_sysreg_s(SYS_ID_AA64ISAR0_EL1);
+	return (ftr >> ID_AA64ISAR0_RNDR_SHIFT) & 0xf;
+}
+
+/*
+ * Our ARCH_RANDOM implementation does not function until relatively
+ * late in the boot when cpufeature has detertmined system
+ * capabilities so the core code can't use arch_get_random*() to
+ * initialize, instead we call this function to inject data from
+ * setup_arch() if the boot CPU supports v8.5-RNG.
+ */
+static inline void __init arm64_add_early_rndr_entropy(void)
+{
+	unsigned long val;
+	int i;
+
+	if (!__early_cpu_has_rndr())
+		return;
+
+	/* Add multiple values to mirror the generic code. */
+	for (i = 0; i < 16; i++)
+		if (__arm64_rndr(&val))
+			add_device_randomness(&val, sizeof(val));
+}
+
 #else
 
 static inline bool __arm64_rndr(unsigned long *v) { return false; }
+static inline bool __init __early_cpu_has_rndr(void) { return false; }
+static inline void __init arm64_add_early_rndr_entropy(void) { }
 
 #endif /* CONFIG_ARCH_RANDOM */
 #endif /* _ASM_ARCHRANDOM_H */
arch/arm64/kernel/setup.c +2 -0
index 56f664561754..170842965a32 100644
@@ -344,6 +344,8 @@ void __init setup_arch(char **cmdline_p)
 	/* Init percpu seeds for random tags after cpus are set up. */
 	kasan_init_tags();
 
+	arm64_add_early_rndr_entropy();
+
 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
 	/*
 	 * Make sure init_thread_info.ttbr0 always generates translation
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#27 lore raw

PATCH v10 3/3 arm64: Use v8.5-RNG entropy for KASLR seed

In reply to Mark Brown

When seeding KALSR on a system where we have architecture level random number generation make use of that entropy, mixing it in with the seed passed by the bootloader. Since this is run very early in init before feature detection is complete we open code rather than use archrandom.h.

---
 arch/arm64/kernel/kaslr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/kernel/kaslr.c +11 -0
index 2a11a962e571..53b8a4ee64ff 100644
@@ -120,6 +120,17 @@ u64 __init kaslr_early_init(u64 dt_phys)
 		return 0;
 	}
 
+	/*
+	 * Mix in any entropy obtainable architecturally, open coded
+	 * since this runs extremely early.
+	 */
+	if (__early_cpu_has_rndr()) {
+		unsigned long raw;
+
+		if (__arm64_rndr(&raw))
+			seed ^= raw;
+	}
+
 	if (!seed) {
 		kaslr_status = KASLR_DISABLED_NO_SEED;
 		return 0;
Signature · 7 lines
2.20.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer Reviewed-by on v10 2/3
#14 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Mark Brown
Quoted 15 lines · Mark Brown

Since the arm64 ARCH_RANDOM implementation is not available until cpufeature has determined the system capabilities it can't be used by the generic random code to initialize the entropy pool for early use. Instead explicitly add some data to the pool from setup_arch() if the boot CPU supports v8.5-RNG, this is the point recommended by the generic code.

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide those will be done as a future step. Providing data is better than not doing so as it will still provide an increase in variation in the output from the random code and there will be no impact on the rate at which entropy is credited compared to what we have without this patch.

Quoted 1 line

This is certainly better than the current state of things so:

Thanks,
Mark.

Quoted 65 lines
---
 arch/arm64/include/asm/archrandom.h | 30 +++++++++++++++++++++++++++++
 arch/arm64/kernel/setup.c           |  2 ++
 2 files changed, 32 insertions(+)
arch/arm64/include/asm/archrandom.h +30 -0
index 5ea5a1ce5a5f..2eb1db1f0bdf 100644
@@ -59,9 +59,39 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
 	return ok;
 }
 
+static inline bool __init __early_cpu_has_rndr(void)
+{
+	/* Open code as we run prior to the first call to cpufeature. */
+	unsigned long ftr = read_sysreg_s(SYS_ID_AA64ISAR0_EL1);
+	return (ftr >> ID_AA64ISAR0_RNDR_SHIFT) & 0xf;
+}
+
+/*
+ * Our ARCH_RANDOM implementation does not function until relatively
+ * late in the boot when cpufeature has detertmined system
+ * capabilities so the core code can't use arch_get_random*() to
+ * initialize, instead we call this function to inject data from
+ * setup_arch() if the boot CPU supports v8.5-RNG.
+ */
+static inline void __init arm64_add_early_rndr_entropy(void)
+{
+	unsigned long val;
+	int i;
+
+	if (!__early_cpu_has_rndr())
+		return;
+
+	/* Add multiple values to mirror the generic code. */
+	for (i = 0; i < 16; i++)
+		if (__arm64_rndr(&val))
+			add_device_randomness(&val, sizeof(val));
+}
+
 #else
 
 static inline bool __arm64_rndr(unsigned long *v) { return false; }
+static inline bool __init __early_cpu_has_rndr(void) { return false; }
+static inline void __init arm64_add_early_rndr_entropy(void) { }
 
 #endif /* CONFIG_ARCH_RANDOM */
 #endif /* _ASM_ARCHRANDOM_H */
arch/arm64/kernel/setup.c +2 -0
index 56f664561754..170842965a32 100644
@@ -344,6 +344,8 @@ void __init setup_arch(char **cmdline_p)
 	/* Init percpu seeds for random tags after cpus are set up. */
 	kasan_init_tags();
 
+	arm64_add_early_rndr_entropy();
+
 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
 	/*
 	 * Make sure init_thread_info.ttbr0 always generates translation
Signature · 1 line
2.20.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

reviewer Reviewed-by on v10 3/3
#28 lore raw

Re: [PATCH v10 3/3] arm64: Use v8.5-RNG entropy for KASLR seed

In reply to Mark Brown
Quoted 6 lines · Mark Brown

When seeding KALSR on a system where we have architecture level random number generation make use of that entropy, mixing it in with the seed passed by the bootloader. Since this is run very early in init before feature detection is complete we open code rather than use archrandom.h.

Mark.

Quoted 29 lines
---
 arch/arm64/kernel/kaslr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/kernel/kaslr.c +11 -0
index 2a11a962e571..53b8a4ee64ff 100644
@@ -120,6 +120,17 @@ u64 __init kaslr_early_init(u64 dt_phys)
 		return 0;
 	}
 
+	/*
+	 * Mix in any entropy obtainable architecturally, open coded
+	 * since this runs extremely early.
+	 */
+	if (__early_cpu_has_rndr()) {
+		unsigned long raw;
+
+		if (__arm64_rndr(&raw))
+			seed ^= raw;
+	}
+
 	if (!seed) {
 		kaslr_status = KASLR_DISABLED_NO_SEED;
 		return 0;
Signature · 1 line
2.20.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v10 2/3
#15 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Mark Brown
Quoted 15 lines · Mark Brown

Since the arm64 ARCH_RANDOM implementation is not available until cpufeature has determined the system capabilities it can't be used by the generic random code to initialize the entropy pool for early use. Instead explicitly add some data to the pool from setup_arch() if the boot CPU supports v8.5-RNG, this is the point recommended by the generic code.

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide those will be done as a future step. Providing data is better than not doing so as it will still provide an increase in variation in the output from the random code and there will be no impact on the rate at which entropy is credited compared to what we have without this patch.

Quoted 5 lines
---
 arch/arm64/include/asm/archrandom.h | 30 +++++++++++++++++++++++++++++
 arch/arm64/kernel/setup.c           |  2 ++
 2 files changed, 32 insertions(+)

r~

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v10 3/3
#29 lore raw

Re: [PATCH v10 3/3] arm64: Use v8.5-RNG entropy for KASLR seed

In reply to Mark Brown
Quoted 9 lines · Mark Brown

When seeding KALSR on a system where we have architecture level random number generation make use of that entropy, mixing it in with the seed passed by the bootloader. Since this is run very early in init before feature detection is complete we open code rather than use archrandom.h.

---
 arch/arm64/kernel/kaslr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

r~

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#2 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

In reply to Mark Brown
Quoted 16 lines · Mark Brown

From: Richard Henderson <[email protected]>

Expose the ID_AA64ISAR0.RNDR field to userspace, as the RNG system registers are always available at EL0.

Implement arch_get_random_seed_long using RNDR. Given that the TRNG is likely to be a shared resource between cores, and VMs, do not explicitly force re-seeding with RNDRRS. In order to avoid code complexity and potential issues with hetrogenous systems only provide values after cpufeature has finalized the system capabilities.

[Modified to only function after cpufeature has finalized the system capabilities and move all the code into the header -- broonie]

Quoted 9 lines
---
 Documentation/arm64/cpu-feature-registers.rst |  2 +
 arch/arm64/Kconfig                            | 12 ++++
 arch/arm64/include/asm/archrandom.h           | 67 +++++++++++++++++++
 arch/arm64/include/asm/cpucaps.h              |  3 +-
 arch/arm64/include/asm/sysreg.h               |  4 ++
 arch/arm64/kernel/cpufeature.c                | 13 ++++
 6 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/archrandom.h

In which case, should we also add an HWCAP for this?

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

Quoted 28 lines · Will Deacon
Quoted 16 lines · Mark Brown

From: Richard Henderson <[email protected]>

Expose the ID_AA64ISAR0.RNDR field to userspace, as the RNG system registers are always available at EL0.

Implement arch_get_random_seed_long using RNDR. Given that the TRNG is likely to be a shared resource between cores, and VMs, do not explicitly force re-seeding with RNDRRS. In order to avoid code complexity and potential issues with hetrogenous systems only provide values after cpufeature has finalized the system capabilities.

[Modified to only function after cpufeature has finalized the system capabilities and move all the code into the header -- broonie]

Quoted 9 lines
---
 Documentation/arm64/cpu-feature-registers.rst |  2 +
 arch/arm64/Kconfig                            | 12 ++++
 arch/arm64/include/asm/archrandom.h           | 67 +++++++++++++++++++
 arch/arm64/include/asm/cpucaps.h              |  3 +-
 arch/arm64/include/asm/sysreg.h               |  4 ++
 arch/arm64/kernel/cpufeature.c                | 13 ++++
 6 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/archrandom.h
Quoted 2 lines

In which case, should we also add an HWCAP for this?

Isn't this covered by the 'cpuid' HWCAP? We can't prevent EL0 from accessing these system registers anyway, even if we wanted to.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#16 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Mark Brown
Quoted 8 lines · Mark Brown

Since the arm64 ARCH_RANDOM implementation is not available until cpufeature has determined the system capabilities it can't be used by the generic random code to initialize the entropy pool for early use. Instead explicitly add some data to the pool from setup_arch() if the boot CPU supports v8.5-RNG, this is the point recommended by the generic code.

Quoted 8 lines

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide those will be done as a future step. Providing data is better than not doing so as it will still provide an increase in variation in the output from the random code and there will be no impact on the rate at which entropy is credited compared to what we have without this patch.

This is slightly unfortunate, as this way, we lose the ability to use random.trust_cpu=1 to get the entropy credited and initialize CRNG early.

Quoted 14 lines
---
 arch/arm64/include/asm/archrandom.h | 30 +++++++++++++++++++++++++++++
 arch/arm64/kernel/setup.c           |  2 ++
 2 files changed, 32 insertions(+)
arch/arm64/include/asm/archrandom.h +0 -0
index 5ea5a1ce5a5f..2eb1db1f0bdf 100644
@@ -59,9 +59,39 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v)
        return ok;
 }
 

arch/arm64/include/asm/archrandom.h static inline bool __must_check arch_get_random_seed_int(unsigned int *v) · line 71

Quoted 10 lines
arch/arm64/include/asm/archrandom.h +10 -0
+static inline bool __init __early_cpu_has_rndr(void)
+{
+       /* Open code as we run prior to the first call to cpufeature. */
+       unsigned long ftr = read_sysreg_s(SYS_ID_AA64ISAR0_EL1);
+       return (ftr >> ID_AA64ISAR0_RNDR_SHIFT) & 0xf;
+}
+
+/*
+ * Our ARCH_RANDOM implementation does not function until relatively
+ * late in the boot when cpufeature has detertmined system

determined

Quoted 40 lines
arch/arm64/include/asm/archrandom.h +20 -0
+ * capabilities so the core code can't use arch_get_random*() to
+ * initialize, instead we call this function to inject data from
+ * setup_arch() if the boot CPU supports v8.5-RNG.
+ */
+static inline void __init arm64_add_early_rndr_entropy(void)
+{
+       unsigned long val;
+       int i;
+
+       if (!__early_cpu_has_rndr())
+               return;
+
+       /* Add multiple values to mirror the generic code. */
+       for (i = 0; i < 16; i++)
+               if (__arm64_rndr(&val))
+                       add_device_randomness(&val, sizeof(val));
+}
+
 #else
 
 static inline bool __arm64_rndr(unsigned long *v) { return false; }
+static inline bool __init __early_cpu_has_rndr(void) { return false; }
+static inline void __init arm64_add_early_rndr_entropy(void) { }
 
 #endif /* CONFIG_ARCH_RANDOM */
 #endif /* _ASM_ARCHRANDOM_H */
arch/arm64/kernel/setup.c +2 -1
index 56f664561754..170842965a32 100644
@@ -344,6 +344,8 @@ void __init setup_arch(char **cmdline_p)
        /* Init percpu seeds for random tags after cpus are set up. */
        kasan_init_tags();
 
+       arm64_add_early_rndr_entropy();
+
 #ifdef CONFIG_ARM64_SW_TTBR0_PAN
        /*
         * Make sure init_thread_info.ttbr0 always generates translation
--
Quoted 2 lines

2.20.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#17 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

Quoted 18 lines · Ard Biesheuvel
Quoted 8 lines · Mark Brown

Since the arm64 ARCH_RANDOM implementation is not available until cpufeature has determined the system capabilities it can't be used by the generic random code to initialize the entropy pool for early use. Instead explicitly add some data to the pool from setup_arch() if the boot CPU supports v8.5-RNG, this is the point recommended by the generic code.

Quoted 8 lines

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide those will be done as a future step. Providing data is better than not doing so as it will still provide an increase in variation in the output from the random code and there will be no impact on the rate at which entropy is credited compared to what we have without this patch.

Quoted 3 lines

This is slightly unfortunate, as this way, we lose the ability to use random.trust_cpu=1 to get the entropy credited and initialize CRNG early.

Agreed. Do you think we should wait for that support before merging the series? Given that I don't know of any CPUs implementing this extension, we can probably afford not to rush this in.

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#4 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

In reply to Ard Biesheuvel
Quoted 29 lines · Ard Biesheuvel
Quoted 28 lines · Will Deacon
Quoted 25 lines · Mark Brown

From: Richard Henderson <[email protected]>

Expose the ID_AA64ISAR0.RNDR field to userspace, as the RNG system registers are always available at EL0.

Implement arch_get_random_seed_long using RNDR. Given that the TRNG is likely to be a shared resource between cores, and VMs, do not explicitly force re-seeding with RNDRRS. In order to avoid code complexity and potential issues with hetrogenous systems only provide values after cpufeature has finalized the system capabilities.

[Modified to only function after cpufeature has finalized the system capabilities and move all the code into the header -- broonie]

---
 Documentation/arm64/cpu-feature-registers.rst |  2 +
 arch/arm64/Kconfig                            | 12 ++++
 arch/arm64/include/asm/archrandom.h           | 67 +++++++++++++++++++
 arch/arm64/include/asm/cpucaps.h              |  3 +-
 arch/arm64/include/asm/sysreg.h               |  4 ++
 arch/arm64/kernel/cpufeature.c                | 13 ++++
 6 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/archrandom.h
Quoted 5 lines
Quoted 2 lines

In which case, should we also add an HWCAP for this?

Isn't this covered by the 'cpuid' HWCAP? We can't prevent EL0 from accessing these system registers anyway, even if we wanted to.

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#18 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Will Deacon
Quoted 20 lines · Will Deacon
Quoted 18 lines · Ard Biesheuvel
Quoted 16 lines · Mark Brown

Since the arm64 ARCH_RANDOM implementation is not available until cpufeature has determined the system capabilities it can't be used by the generic random code to initialize the entropy pool for early use. Instead explicitly add some data to the pool from setup_arch() if the boot CPU supports v8.5-RNG, this is the point recommended by the generic code.

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide those will be done as a future step. Providing data is better than not doing so as it will still provide an increase in variation in the output from the random code and there will be no impact on the rate at which entropy is credited compared to what we have without this patch.

Quoted 8 lines
Quoted 3 lines

This is slightly unfortunate, as this way, we lose the ability to use random.trust_cpu=1 to get the entropy credited and initialize CRNG early.

Agreed. Do you think we should wait for that support before merging the series? Given that I don't know of any CPUs implementing this extension, we can probably afford not to rush this in.

In a previous iteration, we did have a functional arch_get_random_seed_long() early on, which would solve this issue without even needing a patch like this.

Perhaps Mark (Rutland) can give a recap of his concerns at the time?

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

In reply to Will Deacon
Quoted 37 lines · Will Deacon
Quoted 29 lines · Ard Biesheuvel
Quoted 28 lines · Will Deacon
Quoted 25 lines · Mark Brown

From: Richard Henderson <[email protected]>

Expose the ID_AA64ISAR0.RNDR field to userspace, as the RNG system registers are always available at EL0.

Implement arch_get_random_seed_long using RNDR. Given that the TRNG is likely to be a shared resource between cores, and VMs, do not explicitly force re-seeding with RNDRRS. In order to avoid code complexity and potential issues with hetrogenous systems only provide values after cpufeature has finalized the system capabilities.

[Modified to only function after cpufeature has finalized the system capabilities and move all the code into the header -- broonie]

---
 Documentation/arm64/cpu-feature-registers.rst |  2 +
 arch/arm64/Kconfig                            | 12 ++++
 arch/arm64/include/asm/archrandom.h           | 67 +++++++++++++++++++
 arch/arm64/include/asm/cpucaps.h              |  3 +-
 arch/arm64/include/asm/sysreg.h               |  4 ++
 arch/arm64/kernel/cpufeature.c                | 13 ++++
 6 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm64/include/asm/archrandom.h
Quoted 5 lines
Quoted 2 lines

In which case, should we also add an HWCAP for this?

Isn't this covered by the 'cpuid' HWCAP? We can't prevent EL0 from accessing these system registers anyway, even if we wanted to.

Quoted 8 lines

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

I don't have a strong opinion either way.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

reviewer
#19 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Ard Biesheuvel
Quoted 29 lines · Ard Biesheuvel
Quoted 20 lines · Will Deacon
Quoted 18 lines · Ard Biesheuvel
Quoted 16 lines · Mark Brown

Since the arm64 ARCH_RANDOM implementation is not available until cpufeature has determined the system capabilities it can't be used by the generic random code to initialize the entropy pool for early use. Instead explicitly add some data to the pool from setup_arch() if the boot CPU supports v8.5-RNG, this is the point recommended by the generic code.

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide those will be done as a future step. Providing data is better than not doing so as it will still provide an increase in variation in the output from the random code and there will be no impact on the rate at which entropy is credited compared to what we have without this patch.

Quoted 7 lines
Quoted 3 lines

This is slightly unfortunate, as this way, we lose the ability to use random.trust_cpu=1 to get the entropy credited and initialize CRNG early.

Agreed. Do you think we should wait for that support before merging the series? Given that I don't know of any CPUs implementing this extension, we can probably afford not to rush this in.

Quoted 5 lines

In a previous iteration, we did have a functional arch_get_random_seed_long() early on, which would solve this issue without even needing a patch like this.

Perhaps Mark (Rutland) can give a recap of his concerns at the time?

It meant that the common runtime path had code that was only ever meant to run at boot time, and would also run on secondary CPUs until we finalized the caps, so they'd behave inconsistently across boot and hotplug paths. I was concerned that this was messy and would be painful to reason about and debug.

My suggestion was that we either:

(a) Had the arch code explicitly inject the entropy in the primary setup

    path, as these patches do, or;

(b) Had a new callback (e.g. __early_arch_get_random_seed_long()) that the core random code only called during its initialization, separate to the runtime paths.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#6 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

In reply to Ard Biesheuvel
Quoted 11 lines · Ard Biesheuvel
Quoted 7 lines · Will Deacon

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

I don't have a strong opinion either way.

Me either, or at least not enough to object to doing it - Will? Catalin?

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#7 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

Quoted 8 lines · Mark Brown
Quoted 6 lines · Ard Biesheuvel
Quoted 4 lines · Will Deacon

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

I don't have a strong opinion either way.

Me either, or at least not enough to object to doing it - Will? Catalin?

Unless we all agree to stop adding new HWCAPs, then I think you may as well add a new one here (i.e. I don't think this discussion should derail your work).

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#21 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Will Deacon
Quoted 9 lines · Will Deacon
Quoted 7 lines · Ard Biesheuvel
Quoted 3 lines

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide

This is slightly unfortunate, as this way, we lose the ability to use random.trust_cpu=1 to get the entropy credited and initialize CRNG early.

Right. OTOH that's a bit of a mess to do, I do have some thoughts but it's a bit of a mess trying to do it tastefully, especially when considering that you probably don't want an interface that it's easy for something to misuse. The effort involved certainly seems large enough to handle separately.

Quoted 3 lines

Agreed. Do you think we should wait for that support before merging the series? Given that I don't know of any CPUs implementing this extension, we can probably afford not to rush this in.

It's implemented in at least the fast models already, not checked any of the other emulators, so there's some possibility of people using it while developing other things and hopefully at least some of the various CI systems will be including emulated platforms with newer extensions in their coverage so might gain some benefit from it. Frankly the only reason I'm looking at this at all is that I'd written patch 3 because I was getting fed up with KASLR initialization being easily disabled when I was trying to test E0PD on the models (especially before I added the status print at boot to KASLR so this happened silently), having this in mainline would've helped considerably when working on that.

I don't see any downside to having the code in mainline as is, even though it's not ideal it does make things better since if for some reason anyone does end up running this code on a system that has the feature they'll get at least some benefit from it even if nothing else happens. The bulk of the code isn't going to change when the early init stuff gets improved and includes tables like cpufeature.h that make it annoying to hold out of tree, the bits that are going to change can just as well be worked on incrementally as held out of tree entirely and having the rest in means there's less friction doing that.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#22 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

Quoted 11 lines · Mark Brown
Quoted 9 lines · Will Deacon
Quoted 7 lines · Ard Biesheuvel
Quoted 3 lines

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide

This is slightly unfortunate, as this way, we lose the ability to use random.trust_cpu=1 to get the entropy credited and initialize CRNG early.

Quoted 5 lines

Right. OTOH that's a bit of a mess to do, I do have some thoughts but it's a bit of a mess trying to do it tastefully, especially when considering that you probably don't want an interface that it's easy for something to misuse. The effort involved certainly seems large enough to handle separately.

Maybe, but see below...

Quoted 4 lines
Quoted 3 lines

Agreed. Do you think we should wait for that support before merging the series? Given that I don't know of any CPUs implementing this extension, we can probably afford not to rush this in.

Quoted 12 lines

It's implemented in at least the fast models already, not checked any of the other emulators, so there's some possibility of people using it while developing other things and hopefully at least some of the various CI systems will be including emulated platforms with newer extensions in their coverage so might gain some benefit from it. Frankly the only reason I'm looking at this at all is that I'd written patch 3 because I was getting fed up with KASLR initialization being easily disabled when I was trying to test E0PD on the models (especially before I added the status print at boot to KASLR so this happened silently), having this in mainline would've helped considerably when working on that.

I was thinking specifically about users on silicon rather than developers on simulators. (I could stick this on a branch for developers if necessary).

Quoted 10 lines

I don't see any downside to having the code in mainline as is, even though it's not ideal it does make things better since if for some reason anyone does end up running this code on a system that has the feature they'll get at least some benefit from it even if nothing else happens. The bulk of the code isn't going to change when the early init stuff gets improved and includes tables like cpufeature.h that make it annoying to hold out of tree, the bits that are going to change can just as well be worked on incrementally as held out of tree entirely and having the rest in means there's less friction doing that.

The usual downside that comes from merging patches with promises of fixing them up later is that the motivating task gets marked as "done" somewhere, the developer gets given something else to do and the updates never materialise. That's not a dig at you; it's just the way these things tend to work (I've certainly been on both sides of that coin).

If there was an urgency to this, I'd suggest merging a form of Richard's code, as it appears to solve the technical issue of credited entropy whilst leaving some room for subsequent cleanup. However, I think that makes it even less likely that anybody will come back to do the cleanup because the code will be perfectly functional, so I'd prefer to wait for a complete solution unless you think it's not achievable for 5.7.

I'd also really like Ard's ack on anything relating to RNGs.

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#23 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

Quoted 58 lines · Will Deacon
Quoted 11 lines · Mark Brown
Quoted 9 lines · Will Deacon
Quoted 7 lines · Ard Biesheuvel
Quoted 3 lines

Note that we are only adding data here, it will be mixed into the pool but won't be credited as entropy. There are currently no suitable interfaces for that at present - extending the random code to provide

This is slightly unfortunate, as this way, we lose the ability to use random.trust_cpu=1 to get the entropy credited and initialize CRNG early.

Quoted 5 lines

Right. OTOH that's a bit of a mess to do, I do have some thoughts but it's a bit of a mess trying to do it tastefully, especially when considering that you probably don't want an interface that it's easy for something to misuse. The effort involved certainly seems large enough to handle separately.

Maybe, but see below...

Quoted 4 lines
Quoted 3 lines

Agreed. Do you think we should wait for that support before merging the series? Given that I don't know of any CPUs implementing this extension, we can probably afford not to rush this in.

Quoted 12 lines

It's implemented in at least the fast models already, not checked any of the other emulators, so there's some possibility of people using it while developing other things and hopefully at least some of the various CI systems will be including emulated platforms with newer extensions in their coverage so might gain some benefit from it. Frankly the only reason I'm looking at this at all is that I'd written patch 3 because I was getting fed up with KASLR initialization being easily disabled when I was trying to test E0PD on the models (especially before I added the status print at boot to KASLR so this happened silently), having this in mainline would've helped considerably when working on that.

I was thinking specifically about users on silicon rather than developers on simulators. (I could stick this on a branch for developers if necessary).

Quoted 10 lines

I don't see any downside to having the code in mainline as is, even though it's not ideal it does make things better since if for some reason anyone does end up running this code on a system that has the feature they'll get at least some benefit from it even if nothing else happens. The bulk of the code isn't going to change when the early init stuff gets improved and includes tables like cpufeature.h that make it annoying to hold out of tree, the bits that are going to change can just as well be worked on incrementally as held out of tree entirely and having the rest in means there's less friction doing that.

The usual downside that comes from merging patches with promises of fixing them up later is that the motivating task gets marked as "done" somewhere, the developer gets given something else to do and the updates never materialise. That's not a dig at you; it's just the way these things tend to work (I've certainly been on both sides of that coin).

Quoted 9 lines

If there was an urgency to this, I'd suggest merging a form of Richard's code, as it appears to solve the technical issue of credited entropy whilst leaving some room for subsequent cleanup. However, I think that makes it even less likely that anybody will come back to do the cleanup because the code will be perfectly functional, so I'd prefer to wait for a complete solution unless you think it's not achievable for 5.7.

I'd also really like Ard's ack on anything relating to RNGs.

Patches #1 and #3 are fine with me, modulo the HWCAP bit which I don't deeply care about.

But the way this patch works around our workaround for mismatched RNG caps between cores doesn't make sense to me. arch_get_random_seed_long() should just have some out of line __init path that gets invoked only during early boot, exactly how we are using it in patch #3 to seed KASLR, where we don't care about whether or not other CPUs have the extension. (Note that rand_initialize() is called very early, way before the point where we have to care about being scheduled from a CPU with RNG to one without)

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#20 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Mark Rutland
Quoted 12 lines · Mark Rutland
Quoted 3 lines · Ard Biesheuvel

In a previous iteration, we did have a functional arch_get_random_seed_long() early on, which would solve this issue without even needing a patch like this.

It meant that the common runtime path had code that was only ever meant to run at boot time, and would also run on secondary CPUs until we finalized the caps, so they'd behave inconsistently across boot and hotplug paths. I was concerned that this was messy and would be painful to reason about and debug.

Quoted 4 lines

My suggestion was that we either:

(a) Had the arch code explicitly inject the entropy in the primary setup

    path, as these patches do, or;

These patches don't quite do that, they inject data but not entropy so anything that is waiting for the pool to become fully initialized will still end up waiting, though we do still get the data mixed in. There is currently no interface which allows one to explicitly inject entropy as though from the architecture and I'm not convinced that having one would be a good idea.

Quoted 3 lines

(b) Had a new callback (e.g. __early_arch_get_random_seed_long()) that the core random code only called during its initialization, separate to the runtime paths.

This is definitely an option, but it is a bit ugly and as things stand with random.c it would I think have to cope with possibly running with multiple processors at which point we start to get back to the complexity you were originally worried about just in a code path that's less commonly executed.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#8 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

In reply to Mark Brown
Quoted 8 lines · Mark Brown
Quoted 6 lines · Ard Biesheuvel
Quoted 4 lines · Will Deacon

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

I don't have a strong opinion either way.

Me either, or at least not enough to object to doing it - Will? Catalin?

Until the ifunc resolver can work with CPUID, I think we should keep adding HWCAPn bits. We can revisit this with the toolchain people before introducing HWCAP3.

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#26 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Will Deacon
Quoted 7 lines · Will Deacon
Quoted 4 lines · Mark Brown

tables like cpufeature.h that make it annoying to hold out of tree, the bits that are going to change can just as well be worked on incrementally as held out of tree entirely and having the rest in means there's less friction doing that.

Quoted 5 lines

The usual downside that comes from merging patches with promises of fixing them up later is that the motivating task gets marked as "done" somewhere, the developer gets given something else to do and the updates never materialise. That's not a dig at you; it's just the way these things tend to work (I've certainly been on both sides of that coin).

It's certainly a way things can work, but it does assume that there is an underlying motivating task that involves getting things upstream which will cause people to do the additional work rather than just wandering off and then potentially causing someone else to redo the bit that was already done if they don't notice the code in the list archives or spend time trying to figure out if the original author will continue revising their series. We even had an awkward situation when I was at Linaro where the original author of something we depended on was continuing to work on their series but it was now a spare time activity for them so progress was painfully slow, the worst of both worlds. The most common way this happens that I run into is people implementing things for products who are doing the upstreaming on the side.

It can also have the effect of discouraging people from trying to do things in the first place, I know the likelyhood of scope creep is one of the factors that influences how likely I am to try to improve things I happen to notice while I'm working on something else and I'm fairly sure other people make similar assessments.

Quoted 4 lines

If there was an urgency to this, I'd suggest merging a form of Richard's code, as it appears to solve the technical issue of credited entropy whilst leaving some room for subsequent cleanup. However, I think that makes it even less likely that anybody will come back to do the cleanup because the

I agree with your assessment of the likelyhood of cleanup, I think an incomplete solution that doesn't credit entropy is more robustly likely to get fixed since it causes an actual problem that people will be motivated to fix as opposed to just being ugly code. I have no objection to merging Richard's static_branch_likely() approach though.

Quoted 2 lines

code will be perfectly functional, so I'd prefer to wait for a complete solution unless you think it's not achievable for 5.7.

It could happen but I wouldn't like to commit to getting something in for v5.7, that's basically just a single release given how near we are to the v5.6 merge window opening and I know changes in the random code can sometimes take a while.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#24 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Ard Biesheuvel
Quoted 9 lines · Ard Biesheuvel
Quoted 1 line · Will Deacon

I'd also really like Ard's ack on anything relating to RNGs.

Patches #1 and #3 are fine with me, modulo the HWCAP bit which I don't deeply care about.

But the way this patch works around our workaround for mismatched RNG caps between cores doesn't make sense to me.

I'd be totally happy to drop patch 2 entirely, it's a *bit* marginal if it's useful - I mainly wrote it because it's so trivial to do not because I think it's a wonderful idea.

Quoted 3 lines

arch_get_random_seed_long() should just have some out of line __init path that gets invoked only during early boot, exactly how we are using it in patch #3 to seed KASLR, where we don't care about whether

Yes, I think that would be a good place to get to if we can - if the early init thing is a separate call then we have to worry about the callers always running from the right context which sounds like trouble. It's just trying to figure out a way to write things which is clearly robust when looking at the arch code by itself, and I don't want to completely discount the possibility of a new interface from the random code to help with that yet.

Quoted 3 lines

or not other CPUs have the extension. (Note that rand_initialize() is called very early, way before the point where we have to care about being scheduled from a CPU with RNG to one without)

Everything is simple during rand_initialize(), though the actual calls to get entropy that it does happen in crng_initialize() which is also used to initialize the per-node pools for NUMA systems but that should happen after the capabilities code has run I think (pretty sure, but I need to check) so we can rely on cpus_have_const_cap(). There's also calls in prandom_init() which runs at core_initcall() so that should be fine too.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#9 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

In reply to Catalin Marinas
Quoted 12 lines · Catalin Marinas
Quoted 11 lines · Mark Brown
Quoted 9 lines · Ard Biesheuvel
Quoted 7 lines · Will Deacon

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

I don't have a strong opinion either way.

Me either, or at least not enough to object to doing it - Will? Catalin?

Until the ifunc resolver can work with CPUID, I think we should keep adding HWCAPn bits. We can revisit this with the toolchain people before introducing HWCAP3.

Why would the ifunc resolver not be able to use HWCAP_CPUID?

The first argument to the ifunc resolver, apparently since the beginning of time (2013-11-25 7520ff8c744a), AT_HWCAP has been passed directly as the first argument.

That means HWCAP_CPUID, present in AT_HWCAP, can always be tested directly. At which point one can access architected registers, with no dynamic linker relocations, to make further decisions. Admittedly there's a trap to the OS involved, but there is *far* too much info in those registers to copy everything to HWCAPn.

The current state of affairs, as of glibc-2.30, is that the first argument is augmented to include a _IFUNC_ARG_HWCAP bit, which indicates the presence of a second argument, a pointer to struct __ifunc_arg_t. This struct does include a size field, allowing the struct to be extended in future.

That said, speaking as a toolchain guy, you should conserve HWCAP2 bits so that, by preference, you do not need to introduce AT_HWCAP3. Or at least delay adding it.

r~

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#10 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

Quoted 15 lines · Richard Henderson
Quoted 14 lines · Catalin Marinas
Quoted 13 lines · Mark Brown
Quoted 11 lines · Ard Biesheuvel
Quoted 7 lines · Will Deacon

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

I don't have a strong opinion either way.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Me either, or at least not enough to object to doing it - Will? Catalin?

Until the ifunc resolver can work with CPUID, I think we should keep adding HWCAPn bits. We can revisit this with the toolchain people before introducing HWCAP3.

Why would the ifunc resolver not be able to use HWCAP_CPUID?

It can indeed check the HWCAP_CPUID but I haven't seen any plans to implement the next part, actual use of an MRS instruction to read the corresponding ID_AA64* regs. This MRS emulation was requested by (some of) the toolchain people, even the architecture gained a feature to simplify the emulation, but followed by complete silence from the toolchain folk.

Quoted 3 lines

That said, speaking as a toolchain guy, you should conserve HWCAP2 bits so that, by preference, you do not need to introduce AT_HWCAP3. Or at least delay adding it.

We still have some time before AT_HWCAP3. Also, we have 32-bit spare in both HWCAP and HWCAP2 which we can use. IIRC we didn't go into the top 32-bit of HWCAP because we were still debating whether ILP32 makes sense (and now I'm 100% convinced it doesn't ;)).

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#11 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

Quoted 24 lines · Catalin Marinas
Quoted 22 lines · Richard Henderson
Quoted 20 lines · Catalin Marinas
Quoted 8 lines · Mark Brown
Quoted 6 lines · Ard Biesheuvel
Quoted 4 lines · Will Deacon

I see your argument, but I was just going on the side of consistency because we're continuing to expose other features as HWCAPs when the capability is just a proxy for the cpuid field. I was in favour of stopping the addition of such HWCAPs years ago, but I couldn't convince Catalin ;)

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

The way I see it, we'll soon run out of HWCAP2 bits and then we'll have our hand forced.

I don't have a strong opinion either way.

Me either, or at least not enough to object to doing it - Will? Catalin?

Until the ifunc resolver can work with CPUID, I think we should keep adding HWCAPn bits. We can revisit this with the toolchain people before introducing HWCAP3.

Quoted 9 lines
Quoted 1 line

Why would the ifunc resolver not be able to use HWCAP_CPUID?

It can indeed check the HWCAP_CPUID but I haven't seen any plans to implement the next part, actual use of an MRS instruction to read the corresponding ID_AA64* regs. This MRS emulation was requested by (some of) the toolchain people, even the architecture gained a feature to simplify the emulation, but followed by complete silence from the toolchain folk.

But what infrastructure would the toolchain folks need to provide here? An ifunc resolver would simply do

void generic_func(...);
void foo_func(...);

void *resolve_foo(long hwcap)
{

   if (hwcap & HWCAP_CPUID) {
       long l;
       asm ("mrs %1, ID_AA64_...") : "=r"(l));
       if (l has 'foo')
         return foo_func;

}
return generic_func;
}

so all that is needed for using ID registers to do ifunc resolution is already there.

Quoted 11 lines
Quoted 3 lines

That said, speaking as a toolchain guy, you should conserve HWCAP2 bits so that, by preference, you do not need to introduce AT_HWCAP3. Or at least delay adding it.

We still have some time before AT_HWCAP3. Also, we have 32-bit spare in both HWCAP and HWCAP2 which we can use. IIRC we didn't go into the top 32-bit of HWCAP because we were still debating whether ILP32 makes sense (and now I'm 100% convinced it doesn't ;)).

--
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#25 lore raw

Re: [PATCH v10 2/3] arm64: random: Add data to pool from setup_arch()

In reply to Mark Brown
Quoted 8 lines · Mark Brown
Quoted 6 lines · Ard Biesheuvel
Quoted 1 line · Will Deacon

I'd also really like Ard's ack on anything relating to RNGs.

Patches #1 and #3 are fine with me, modulo the HWCAP bit which I don't deeply care about.

Quoted 6 lines
Quoted 2 lines

But the way this patch works around our workaround for mismatched RNG caps between cores doesn't make sense to me.

I'd be totally happy to drop patch 2 entirely, it's a *bit* marginal if it's useful - I mainly wrote it because it's so trivial to do not because I think it's a wonderful idea.

OK, tell you what -- please resend just 1 and 3, with the HWCAP addition (because we're not going to resolve that in time for 5.6) and I'll queue them up.

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#12 lore raw

Re: [PATCH v10 1/3] arm64: Implement archrandom.h for ARMv8.5-RNG

In reply to Ard Biesheuvel
Quoted 33 lines · Ard Biesheuvel
Quoted 6 lines · Catalin Marinas
Quoted 5 lines · Richard Henderson
Quoted 3 lines · Catalin Marinas

Until the ifunc resolver can work with CPUID, I think we should keep adding HWCAPn bits. We can revisit this with the toolchain people before introducing HWCAP3.

Quoted 8 lines
Quoted 1 line

Why would the ifunc resolver not be able to use HWCAP_CPUID?

It can indeed check the HWCAP_CPUID but I haven't seen any plans to implement the next part, actual use of an MRS instruction to read the corresponding ID_AA64* regs. This MRS emulation was requested by (some of) the toolchain people, even the architecture gained a feature to simplify the emulation, but followed by complete silence from the toolchain folk.

But what infrastructure would the toolchain folks need to provide here? An ifunc resolver would simply do

void generic_func(...);
void foo_func(...);

void *resolve_foo(long hwcap)

{
   if (hwcap & HWCAP_CPUID) {
       long l;
       asm ("mrs %1, ID_AA64_...") : "=r"(l));
       if (l has 'foo')
         return foo_func;
   }
   return generic_func;
}
Quoted 2 lines

so all that is needed for using ID registers to do ifunc resolution is already there.

If you write the resolver yourself, it should work. I was thinking of function multiversioning (which I thought using ifunc behind the scenes) but I'm not sure what the aarch64 support level is (in gcc or clang).

Anyway, I'm not aware of anyone using the MRS emulation (maybe they do and I haven't heard). I guess it doesn't help that we keep adding HWCAP bits ;).

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel