Skip to contentSkip to conversation

make ERR_PTR/PTR_ERR architecture specific

PATCH New Simon Goldschmidt 2 participants 7 messages Oct 22, 2019 – Nov 8, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover make ERR_PTR/PTR_ERR architecture specific

Some U-Boot pointers have redundant information, so we can use a scheme where we can return either an error code or a pointer with the same return value. The default implementation just casts the pointer to a number, however, this may fail on platforms where the end of the address range is used for valid pointers (e.g. 0xffffff00 is a valid heap pointer in socfpga SPL). For such platforms, this value provides an upper range of those error pointer values - up to 'MAX_ERRNO' bytes below this value must be unused/invalid addresses.

Simon Goldschmidt (3):
Kconfig add config ERR_PTR_OFFSET
linux err: make ERR_PTR/PTR_ERR architecture specific
arm: socfpga: gen5: fix ERR_PTR_OFFSET

 Kconfig                       | 14 ++++++++++++++
 arch/arm/mach-socfpga/Kconfig |  3 +++
 include/linux/err.h           |  8 ++++----
 3 files changed, 21 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 Kconfig add config ERR_PTR_OFFSET

Some U-Boot pointers have redundant information, so we can use a scheme where we can return either an error code or a pointer with the same return value. The default implementation just casts the pointer to a number, however, this may fail on platforms where the end of the address range is used for valid pointers (e.g. 0xffffff00 is a valid heap pointer in socfpga SPL). For such platforms, this value provides an upper range of those error pointer values - up to 'MAX_ERRNO' bytes below this value must be unused/invalid addresses.

---

 Kconfig | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Kconfig +14 -0
index 66b059f749..cda4f58ff7 100644
@@ -281,6 +281,20 @@ config SYS_LDSCRIPT
 	  Path within the source tree to the linker script to use for the
 	  main U-Boot binary.
 
+config ERR_PTR_OFFSET
+	hex
+	default 0x0
+	help
+	  Some U-Boot pointers have redundant information, so we can use a
+	  scheme where we can return either an error code or a pointer with the
+	  same return value. The default implementation just casts the pointer
+	  to a number, however, this may fail on platforms where the end of the
+	  address range is used for valid pointers (e.g. 0xffffff00 is a valid
+	  heap pointer in socfpga SPL).
+	  For such platforms, this value provides an upper range of those error
+	  pointer values - up to 'MAX_ERRNO' bytes below this value must be
+	  unused/invalid addresses.
+
 endmenu		# General setup
 
 menu "Boot images"
Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/3 Kconfig add config ERR_PTR_OFFSET

Quoted 10 lines · Simon Goldschmidt

Some U-Boot pointers have redundant information, so we can use a scheme where we can return either an error code or a pointer with the same return value. The default implementation just casts the pointer to a number, however, this may fail on platforms where the end of the address range is used for valid pointers (e.g. 0xffffff00 is a valid heap pointer in socfpga SPL). For such platforms, this value provides an upper range of those error pointer values - up to 'MAX_ERRNO' bytes below this value must be unused/invalid addresses.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191108/b2253ddc/attachment.sig>
#3 lore raw

PATCH 2/3 linux err: make ERR_PTR/PTR_ERR architecture specific

In reply to Simon Goldschmidt

This patch changes ERR_PTR/PTR_ERR to use CONFIG_ERR_PTR_OFFSET to map errno values into a pointer region that cannot contain valid pointers.

IS_ERR and IS_ERR_OR_NULL have to be converted to use PTR_ERR, too, for this to work.

---

 include/linux/err.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/err.h +4 -4
index 22e5756edd..5ede82432d 100644
@@ -23,22 +23,22 @@
 
 static inline void *ERR_PTR(long error)
 {
-	return (void *) error;
+	return (void *)(CONFIG_ERR_PTR_OFFSET + error);
 }
 
 static inline long PTR_ERR(const void *ptr)
 {
-	return (long) ptr;
+	return ((long)ptr - CONFIG_ERR_PTR_OFFSET);
 }
 
 static inline long IS_ERR(const void *ptr)
 {
-	return IS_ERR_VALUE((unsigned long)ptr);
+	return IS_ERR_VALUE((unsigned long)PTR_ERR(ptr));
 }
 
 static inline bool IS_ERR_OR_NULL(const void *ptr)
 {
-	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
+	return !ptr || IS_ERR_VALUE((unsigned long)PTR_ERR(ptr));
 }
 
 /**
Signature · 1 line
2.20.1
#4 lore raw

PATCH 2/3 linux err: make ERR_PTR/PTR_ERR architecture specific

Quoted 7 lines · Simon Goldschmidt

This patch changes ERR_PTR/PTR_ERR to use CONFIG_ERR_PTR_OFFSET to map errno values into a pointer region that cannot contain valid pointers.

IS_ERR and IS_ERR_OR_NULL have to be converted to use PTR_ERR, too, for this to work.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191108/5da820fb/attachment.sig>
#5 lore raw

PATCH 3/3 arm: socfpga: gen5: fix ERR_PTR_OFFSET

In reply to Simon Goldschmidt

The default implementation of ERR_PTR/PTR_ERR maps errno values at the and of the address range (e.g. -EINVAL/-22 gets 0xFFFFFFEA).

For socfpga gen5 SPL, this doesn't really work, as the heap is nearly at the end of the 32 bit address range.

This patch adjusts the ERR_PTR_OFFSET to map errno values into the range of the Boot ROM, which should not be used for valid pointers.

---

 arch/arm/mach-socfpga/Kconfig | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-socfpga/Kconfig +3 -0
index fc0a54214f..3770e07258 100644
@@ -1,5 +1,8 @@
 if ARCH_SOCFPGA
 
+config ERR_PTR_OFFSET
+	default 0xfffec000 if TARGET_SOCFPGA_GEN5 # Boot ROM range
+
 config NR_DRAM_BANKS
 	default 1
 
Signature · 1 line
2.20.1
#6 lore raw

PATCH 3/3 arm: socfpga: gen5: fix ERR_PTR_OFFSET

Quoted 10 lines · Simon Goldschmidt

The default implementation of ERR_PTR/PTR_ERR maps errno values at the and of the address range (e.g. -EINVAL/-22 gets 0xFFFFFFEA).

For socfpga gen5 SPL, this doesn't really work, as the heap is nearly at the end of the 32 bit address range.

This patch adjusts the ERR_PTR_OFFSET to map errno values into the range of the Boot ROM, which should not be used for valid pointers.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191108/ed3f4d48/attachment.sig>