Skip to contentSkip to conversation

arm64: cpufeature: Don't expose ZFR0 to userspace when SVE is not enabled

PATCH In review Julien Grall 5 participants 8 messages Oct 14, 2019 – Oct 15, 2019 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: cpufeature: Don't expose ZFR0 to userspace when SVE is not enabled

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

The kernel should not used the register when CONFIG_SVE is disabled. Therefore, we only need to hidden them from the userspace.

Fixes 06a916feca2b ('arm64: Expose SVE2 features for userspace')
---
 arch/arm64/kernel/cpufeature.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm64/kernel/cpufeature.c +10 -5
index cabebf1a7976..80f459ad0190 100644
@@ -176,11 +176,16 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
 };
 
 static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = {
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
 	ARM64_FTR_END,
 };
 
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Julien Grall

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

The kernel should not used the register when CONFIG_SVE is disabled. Therefore, we only need to hidden them from the userspace.

Fixes 06a916feca2b ('arm64: Expose SVE2 features for userspace')
Quoted 38 lines
---
 arch/arm64/kernel/cpufeature.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm64/kernel/cpufeature.c +10 -5
index cabebf1a7976..80f459ad0190 100644
@@ -176,11 +176,16 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
 };
 
 static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = {
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
 	ARM64_FTR_END,
 };
 
Signature · 7 lines
2.11.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 1/1
#2 lore raw
In reply to Julien Grall

Hi Julien,

Some minor nits in the description.

Quoted 7 lines · Julien Grall

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

The kernel should not used the register when CONFIG_SVE is disabled.

s/used/use ?

Quoted 1 line

Therefore, we only need to hidden them from the userspace.

s/hidden/hide ?

With the above:

Quoted 34 lines
Fixes 06a916feca2b ('arm64: Expose SVE2 features for userspace')
---
  arch/arm64/kernel/cpufeature.c | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm64/kernel/cpufeature.c +10 -5
index cabebf1a7976..80f459ad0190 100644
@@ -176,11 +176,16 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
  };
 
  static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = {
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
  	ARM64_FTR_END,
  };
 
reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Julien Grall
Quoted 2 lines · Julien Grall

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

Nit: s/may not/will not/

Quoted 9 lines

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

The kernel should not used the register when CONFIG_SVE is disabled. Therefore, we only need to hidden them from the userspace.

Fixes 06a916feca2b ('arm64: Expose SVE2 features for userspace')

Mark.

Quoted 38 lines
---
 arch/arm64/kernel/cpufeature.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/arm64/kernel/cpufeature.c +10 -5
index cabebf1a7976..80f459ad0190 100644
@@ -176,11 +176,16 @@ static const struct arm64_ftr_bits ftr_id_aa64pfr1[] = {
 };
 
 static const struct arm64_ftr_bits ftr_id_aa64zfr0[] = {
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
-	ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SM4_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SHA3_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_BITPERM_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_AES_SHIFT, 4, 0),
+	ARM64_FTR_BITS(FTR_VISIBLE_IF_IS_ENABLED(CONFIG_ARM64_SVE),
+		       FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ZFR0_SVEVER_SHIFT, 4, 0),
 	ARM64_FTR_END,
 };
 
Signature · 7 lines
2.11.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#4 lore raw
In reply to Julien Grall
Quoted 2 lines · Julien Grall

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

I don't understand this sentence.

Quoted 2 lines

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

Undefined in what way? Generally, we can't stop exposing things that we've exposed previously in case somebody has started relying on them, so this needs better justification.

Will

#5 lore raw
Quoted 4 lines · Will Deacon
Quoted 2 lines · Julien Grall

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

Quoted 8 lines

I don't understand this sentence.

Quoted 2 lines

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

Undefined in what way? Generally, we can't stop exposing things that we've exposed previously in case somebody has started relying on them, so this needs better justification.

We still expose them with this patch, but zero them out, if the SVE is not supported. When SVE is enabled, we expose them as usual.

Cheers
Suzuki

maintainer
#6 lore raw
Quoted 10 lines · Suzuki K Poulose
Quoted 9 lines · Will Deacon
Quoted 2 lines · Julien Grall

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

I don't understand this sentence.

Quoted 2 lines

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

Quoted 6 lines
Quoted 3 lines

Undefined in what way? Generally, we can't stop exposing things that we've exposed previously in case somebody has started relying on them, so this needs better justification.

We still expose them with this patch, but zero them out, if the SVE is not supported. When SVE is enabled, we expose them as usual.

Sure, but if userspace was relying on the non-zero values, it's now broken.

What's missing from the patch description is the fact that this register is RAZ is SVE is not supported. Given that we get both the SVE HWCAP and PFR0.SVE field correct when the CONFIG option is disabled, then it's only very dodgy userspace which would parse the information in ZFR0 for this configuration and I think we can make this change as a bug fix. I'll try to write something sensible.

Will

#7 lore raw
Quoted 18 lines · Will Deacon
Quoted 10 lines · Suzuki K Poulose
Quoted 9 lines · Will Deacon
Quoted 2 lines · Julien Grall

The kernel may not support SVE if CONFIG_ARM64_SVE is not set and will hide the feature from the from userspace.

I don't understand this sentence.

Quoted 2 lines

Unfortunately, the fields of ID_AA64ZFR0_EL1 are still exposed and could lead to undefined behavior in userspace.

Quoted 6 lines
Quoted 3 lines

Undefined in what way? Generally, we can't stop exposing things that we've exposed previously in case somebody has started relying on them, so this needs better justification.

We still expose them with this patch, but zero them out, if the SVE is not supported. When SVE is enabled, we expose them as usual.

Quoted 8 lines

Sure, but if userspace was relying on the non-zero values, it's now broken.

What's missing from the patch description is the fact that this register is RAZ is SVE is not supported. Given that we get both the SVE HWCAP and PFR0.SVE field correct when the CONFIG option is disabled, then it's only very dodgy userspace which would parse the information in ZFR0 for this configuration and I think we can make this change as a bug fix. I'll try to write something sensible.

There is no SVE2 hardware yet. On SVE(1) hardware, ZFR0 is still reserved and all zero.

In theory userspace could look at the ZFR0 fields and deduce that SVE2 is valiable even when the kernel was built with SVE, but I think it highly unlikely that any software is doing this today.

i.e., I'm pretty sure this horse is still in the stable, and I'd like to see the door closed ;)

Cheers
---Dave