Skip to contentSkip to conversation

powerpc/pkeys: Fix reading of ibm,processor-storage-keys property

PATCH Applied Thiago Jung Bauermann 3 participants 3 messages Sep 20, 2018 – Sep 21, 2018 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/pkeys: Fix reading of ibm,processor-storage-keys property

scan_pkey_feature() uses of_property_read_u32_array() to read the ibm,processor-storage-keys property and calls be32_to_cpu() on the value it gets. The problem is that of_property_read_u32_array() already returns the value converted to the CPU byte order.

The value of pkeys_total ends up more or less sane because there's a min() call in pkey_initialize() which reduces pkeys_total to 32. So in practice the kernel ignores the fact that the hypervisor reserved one key for itself (the device tree advertises 31 keys in my test VM).

This is wrong, but the effect in practice is that when a process tries to allocate the 32nd key, it gets an -EINVAL error instead of -ENOSPC which would indicate that there aren't any keys available

Fixes cf43d3b26452 ("powerpc: Enable pkey subsystem")
---
 arch/powerpc/mm/pkeys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/mm/pkeys.c +1 -1
index 333b1f80c435..b271b283c785 100644
@@ -45,7 +45,7 @@ static void scan_pkey_feature(void)
 	 * Since any pkey can be used for data or execute, we will just treat
 	 * all keys as equal and track them as one entity.
 	 */
-	pkeys_total = be32_to_cpu(vals[0]);
+	pkeys_total = vals[0];
 	pkeys_devtree_defined = true;
 }
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Thiago Jung Bauermann

scan_pkey_feature() uses of_property_read_u32_array() to read the ibm,processor-storage-keys property and calls be32_to_cpu() on the value it gets. The problem is that of_property_read_u32_array() already returns the value converted to the CPU byte order.

Quoted 8 lines

The value of pkeys_total ends up more or less sane because there's a min() call in pkey_initialize() which reduces pkeys_total to 32. So in practice the kernel ignores the fact that the hypervisor reserved one key for itself (the device tree advertises 31 keys in my test VM).

This is wrong, but the effect in practice is that when a process tries to allocate the 32nd key, it gets an -EINVAL error instead of -ENOSPC which would indicate that there aren't any keys available

Thanks for the fix.

Quoted 19 lines
Fixes cf43d3b26452 ("powerpc: Enable pkey subsystem")
---
 arch/powerpc/mm/pkeys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/mm/pkeys.c +1 -1
index 333b1f80c435..b271b283c785 100644
@@ -45,7 +45,7 @@ static void scan_pkey_feature(void)
 	 * Since any pkey can be used for data or execute, we will just treat
 	 * all keys as equal and track them as one entity.
 	 */
-	pkeys_total = be32_to_cpu(vals[0]);
+	pkeys_total = vals[0];
 	pkeys_devtree_defined = true;
 }
Signature · 1 line
Ram Pai
#2 lore raw

Re: powerpc/pkeys: Fix reading of ibm, processor-storage-keys property

In reply to Thiago Jung Bauermann
Quoted 10 lines · Thiago Jung Bauermann

scan_pkey_feature() uses of_property_read_u32_array() to read the ibm,processor-storage-keys property and calls be32_to_cpu() on the value it gets. The problem is that of_property_read_u32_array() already returns the value converted to the CPU byte order.

The value of pkeys_total ends up more or less sane because there's a min() call in pkey_initialize() which reduces pkeys_total to 32. So in practice the kernel ignores the fact that the hypervisor reserved one key for itself (the device tree advertises 31 keys in my test VM).

Quoted 6 lines

This is wrong, but the effect in practice is that when a process tries to allocate the 32nd key, it gets an -EINVAL error instead of -ENOSPC which would indicate that there aren't any keys available

Fixes cf43d3b26452 ("powerpc: Enable pkey subsystem")

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/c716a25b9b70084e1144f77423f5ae

cheers