Skip to contentSkip to conversation

RISC-V: Always define XIP_FIXUP

PATCH Superseded Palmer Dabbelt 3 participants 6 messages Apr 28, 2021 – May 2, 2021 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Palmer Dabbelt

author maintainer
#0 lore raw

PATCH 1/1 RISC-V: Always define XIP_FIXUP

From: Palmer Dabbelt <[email protected]>

XIP depends on MMU, but XIP_FIXUP is defined throughout the kernel in order to avoid excessive ifdefs. This just makes sure to always define XIP_FIXIP, which will fix MMU=n builds.

Fixes 44c922572952 ("RISC-V: enable XIP")
---
 arch/riscv/include/asm/pgtable.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/include/asm/pgtable.h +12 -12
index 2f1384e14e31..fd749351f432 100644
@@ -73,18 +73,6 @@
 #endif
 #define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
 
-#ifdef CONFIG_XIP_KERNEL
-#define XIP_OFFSET		SZ_8M
-#define XIP_FIXUP(addr) ({							\
-	uintptr_t __a = (uintptr_t)(addr);					\
-	(__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?	\
-		__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
-		__a;								\
-	})
-#else
-#define XIP_FIXUP(addr)		(addr)
-#endif /* CONFIG_XIP_KERNEL */
-
 #endif
 
 #ifndef __ASSEMBLY__
@@ -101,6 +89,18 @@
 #include <asm/pgtable-32.h>
 #endif /* CONFIG_64BIT */
 
+#ifdef CONFIG_XIP_KERNEL
+#define XIP_OFFSET		SZ_8M
+#define XIP_FIXUP(addr) ({							\
+	uintptr_t __a = (uintptr_t)(addr);					\
+	(__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?	\
+		__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
+		__a;								\
+	})
+#else
+#define XIP_FIXUP(addr)		(addr)
+#endif /* CONFIG_XIP_KERNEL */
+
 #ifdef CONFIG_MMU
 /* Number of entries in the page global directory */
 #define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))
Signature · 1 line
2.31.1.498.g6c1eba8ee3d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

XIP depends on MMU, but XIP_FIXUP is defined throughout the kernel in order to avoid excessive ifdefs. This just makes sure to always define XIP_FIXIP, which will fix MMU=n builds.

Fixes 44c922572952 ("RISC-V: enable XIP")

Looks good to me.

Regards,
Anup

Quoted 49 lines
---
 arch/riscv/include/asm/pgtable.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/include/asm/pgtable.h +12 -13
index 2f1384e14e31..fd749351f432 100644
@@ -73,18 +73,6 @@
 #endif
 #define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
 
-#ifdef CONFIG_XIP_KERNEL
-#define XIP_OFFSET             SZ_8M
-#define XIP_FIXUP(addr) ({                                                     \
-       uintptr_t __a = (uintptr_t)(addr);                                      \
-       (__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?  \
-               __a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
-               __a;                                                            \
-       })
-#else
-#define XIP_FIXUP(addr)                (addr)
-#endif /* CONFIG_XIP_KERNEL */
-
 #endif
 
 #ifndef __ASSEMBLY__
@@ -101,6 +89,18 @@
 #include <asm/pgtable-32.h>
 #endif /* CONFIG_64BIT */
 
+#ifdef CONFIG_XIP_KERNEL
+#define XIP_OFFSET             SZ_8M
+#define XIP_FIXUP(addr) ({                                                     \
+       uintptr_t __a = (uintptr_t)(addr);                                      \
+       (__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?  \
+               __a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
+               __a;                                                            \
+       })
+#else
+#define XIP_FIXUP(addr)                (addr)
+#endif /* CONFIG_XIP_KERNEL */
+
 #ifdef CONFIG_MMU
 /* Number of entries in the page global directory */
 #define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))
--

2.31.1.498.g6c1eba8ee3d-goog

reviewer
#2 lore raw
In reply to Palmer Dabbelt

Le 4/27/21 à 11:34 PM, Palmer Dabbelt a écrit :

Quoted 5 lines

From: Palmer Dabbelt <[email protected]>

XIP depends on MMU, but XIP_FIXUP is defined throughout the kernel in order to avoid excessive ifdefs. This just makes sure to always define XIP_FIXIP, which will fix MMU=n builds.

A small typo here.

Quoted 32 lines
Fixes 44c922572952 ("RISC-V: enable XIP")
---
  arch/riscv/include/asm/pgtable.h | 24 ++++++++++++------------
  1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/include/asm/pgtable.h +0 -12
index 2f1384e14e31..fd749351f432 100644
@@ -73,18 +73,6 @@
  #endif
  #define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
 
-#ifdef CONFIG_XIP_KERNEL
-#define XIP_OFFSET		SZ_8M
-#define XIP_FIXUP(addr) ({							\
-	uintptr_t __a = (uintptr_t)(addr);					\
-	(__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?	\
-		__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
-		__a;								\
-	})
-#else
-#define XIP_FIXUP(addr)		(addr)
-#endif /* CONFIG_XIP_KERNEL */
-
  #endif
 
  #ifndef __ASSEMBLY__

arch/riscv/include/asm/pgtable.h line 93

Quoted 5 lines
arch/riscv/include/asm/pgtable.h +2 -0
@@ -101,6 +89,18 @@
  #include <asm/pgtable-32.h>
  #endif /* CONFIG_64BIT */
 
+#ifdef CONFIG_XIP_KERNEL
+#define XIP_OFFSET		SZ_8M

XIP_OFFSET is used in head.S and then this breaks XIP_KERNEL. XIP_OFFSET must live outside the ifndef __ASSEMBLY__.

Quoted 4 lines
arch/riscv/include/asm/pgtable.h +3 -0
+#define XIP_FIXUP(addr) ({							\
+	uintptr_t __a = (uintptr_t)(addr);					\
+	(__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?	\

arch/riscv/include/asm/pgtable.h line 106

Quoted 10 lines
arch/riscv/include/asm/pgtable.h +7 -0
+		__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
+		__a;								\
+	})
+#else
+#define XIP_FIXUP(addr)		(addr)
+#endif /* CONFIG_XIP_KERNEL */
+
  #ifdef CONFIG_MMU
  /* Number of entries in the page global directory */
  #define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))

Thank you for doing that!

Alex

author maintainer
#3 lore raw
Quoted 8 lines · On Wed, 28 Apr 2021 01:25:55 PDT (-0700), [email protected] wrote:

Le 4/27/21 à 11:34 PM, Palmer Dabbelt a écrit :

Quoted 5 lines

From: Palmer Dabbelt <[email protected]>

XIP depends on MMU, but XIP_FIXUP is defined throughout the kernel in order to avoid excessive ifdefs. This just makes sure to always define XIP_FIXIP, which will fix MMU=n builds.

A small typo here.

Actually two: "defined" should have been "used". Both are fixed.

Quoted 36 lines
Quoted 36 lines
Fixes 44c922572952 ("RISC-V: enable XIP")
---
  arch/riscv/include/asm/pgtable.h | 24 ++++++++++++------------
  1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/include/asm/pgtable.h +0 -12
index 2f1384e14e31..fd749351f432 100644
@@ -73,18 +73,6 @@
  #endif
  #define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
 
-#ifdef CONFIG_XIP_KERNEL
-#define XIP_OFFSET		SZ_8M
-#define XIP_FIXUP(addr) ({							\
-	uintptr_t __a = (uintptr_t)(addr);					\
-	(__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?	\
-		__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
-		__a;								\
-	})
-#else
-#define XIP_FIXUP(addr)		(addr)
-#endif /* CONFIG_XIP_KERNEL */
-
  #endif
 
  #ifndef __ASSEMBLY__
@@ -101,6 +89,18 @@
  #include <asm/pgtable-32.h>
  #endif /* CONFIG_64BIT */
 
Quoted 6 lines

arch/riscv/include/asm/pgtable.h line 93

Quoted 2 lines
arch/riscv/include/asm/pgtable.h +2 -0
+#ifdef CONFIG_XIP_KERNEL
+#define XIP_OFFSET		SZ_8M

XIP_OFFSET is used in head.S and then this breaks XIP_KERNEL. XIP_OFFSET must live outside the ifndef __ASSEMBLY__.

Thanks, I hadn't even seen XIP_OFFSET. This is fixed in the v2.

Do you have an XIP config that will run on QEMU, and a way to run it? If so, can you post a defconfig and some instructions? That'll make it easier to test on my end.

Quoted 18 lines
Quoted 4 lines
arch/riscv/include/asm/pgtable.h +3 -0
+#define XIP_FIXUP(addr) ({							\
+	uintptr_t __a = (uintptr_t)(addr);					\
+	(__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + SZ_16M) ?	\

arch/riscv/include/asm/pgtable.h line 106

Quoted 10 lines
arch/riscv/include/asm/pgtable.h +7 -0
+		__a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - XIP_OFFSET :\
+		__a;								\
+	})
+#else
+#define XIP_FIXUP(addr)		(addr)
+#endif /* CONFIG_XIP_KERNEL */
+
  #ifdef CONFIG_MMU
  /* Number of entries in the page global directory */
  #define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))

Thank you for doing that!

Alex

reviewer
#4 lore raw

Le 4/29/21 à 12:43 AM, Palmer Dabbelt a écrit :

Quoted 57 lines · On Wed, 28 Apr 2021 01:25:55 PDT (-0700), [email protected] wrote:
Quoted 8 lines

Le 4/27/21 à 11:34 PM, Palmer Dabbelt a écrit :

Quoted 5 lines

From: Palmer Dabbelt <[email protected]>

XIP depends on MMU, but XIP_FIXUP is defined throughout the kernel in order to avoid excessive ifdefs.  This just makes sure to always define XIP_FIXIP, which will fix MMU=n builds.

A small typo here.

Actually two: "defined" should have been "used".  Both are fixed.

Quoted 38 lines
Quoted 38 lines
Fixes 44c922572952 ("RISC-V: enable XIP")

---
  arch/riscv/include/asm/pgtable.h | 24 ++++++++++++------------

  1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/include/asm/pgtable.h +0 -12
index 2f1384e14e31..fd749351f432 100644
@@ -73,18 +73,6 @@
   #endif
   #define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
 
-#ifdef CONFIG_XIP_KERNEL
-#define XIP_OFFSET        SZ_8M
-#define XIP_FIXUP(addr) ({                            \
-    uintptr_t __a = (uintptr_t)(addr);                    \
-    (__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + 
 SZ_16M) ?    \
-        __a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - 
 XIP_OFFSET :\
-        __a;                                \
-    })
-#else
-#define XIP_FIXUP(addr)        (addr)
-#endif /* CONFIG_XIP_KERNEL */
-
   #endif

  #ifndef __ASSEMBLY__

arch/riscv/include/asm/pgtable.h +0 -0
@@ -101,6 +89,18 @@
   #include <asm/pgtable-32.h>
   #endif /* CONFIG_64BIT */
 
Quoted 6 lines

arch/riscv/include/asm/pgtable.h line 93

Quoted 2 lines
arch/riscv/include/asm/pgtable.h +2 -0
+#ifdef CONFIG_XIP_KERNEL
+#define XIP_OFFSET        SZ_8M

XIP_OFFSET is used in head.S and then this breaks XIP_KERNEL. XIP_OFFSET must live outside the ifndef __ASSEMBLY__.

Quoted 4 lines

Thanks, I hadn't even seen XIP_OFFSET.  This is fixed in the v2.

Do you have an XIP config that will run on QEMU, and a way to run it? If so, can you post a defconfig and some instructions?  That'll make it easier to test on my end.

Yes, I'll do that later today or tomorrow.

Quoted 25 lines
Quoted 19 lines
Quoted 13 lines
arch/riscv/include/asm/pgtable.h +10 -0
+#define XIP_FIXUP(addr) ({                            \
+    uintptr_t __a = (uintptr_t)(addr);                    \
+    (__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + 
 SZ_16M) ?    \
+        __a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - 
 XIP_OFFSET :\
+        __a;                                \
+    })
+#else
+#define XIP_FIXUP(addr)        (addr)
+#endif /* CONFIG_XIP_KERNEL */
+
   #ifdef CONFIG_MMU
Quoted 3 lines

  /* Number of entries in the page global directory */ #define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))

Thank you for doing that!

Quoted 1 line

Alex

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

reviewer
#5 lore raw
In reply to Palmer Dabbelt

Hi Palmer,

Le 4/29/21 à 12:43 AM, Palmer Dabbelt a écrit :

Quoted 57 lines · On Wed, 28 Apr 2021 01:25:55 PDT (-0700), [email protected] wrote:
Quoted 8 lines

Le 4/27/21 à 11:34 PM, Palmer Dabbelt a écrit :

Quoted 5 lines

From: Palmer Dabbelt <[email protected]>

XIP depends on MMU, but XIP_FIXUP is defined throughout the kernel in order to avoid excessive ifdefs.  This just makes sure to always define XIP_FIXIP, which will fix MMU=n builds.

A small typo here.

Actually two: "defined" should have been "used".  Both are fixed.

Quoted 38 lines
Quoted 38 lines
Fixes 44c922572952 ("RISC-V: enable XIP")

---
  arch/riscv/include/asm/pgtable.h | 24 ++++++++++++------------

  1 file changed, 12 insertions(+), 12 deletions(-)
arch/riscv/include/asm/pgtable.h +0 -12
index 2f1384e14e31..fd749351f432 100644
@@ -73,18 +73,6 @@
   #endif
   #define FIXADDR_START    (FIXADDR_TOP - FIXADDR_SIZE)
 
-#ifdef CONFIG_XIP_KERNEL
-#define XIP_OFFSET        SZ_8M
-#define XIP_FIXUP(addr) ({                            \
-    uintptr_t __a = (uintptr_t)(addr);                    \
-    (__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + 
 SZ_16M) ?    \
-        __a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - 
 XIP_OFFSET :\
-        __a;                                \
-    })
-#else
-#define XIP_FIXUP(addr)        (addr)
-#endif /* CONFIG_XIP_KERNEL */
-
   #endif

  #ifndef __ASSEMBLY__

arch/riscv/include/asm/pgtable.h +0 -0
@@ -101,6 +89,18 @@
   #include <asm/pgtable-32.h>
   #endif /* CONFIG_64BIT */
 
Quoted 6 lines

arch/riscv/include/asm/pgtable.h line 93

Quoted 2 lines
arch/riscv/include/asm/pgtable.h +2 -0
+#ifdef CONFIG_XIP_KERNEL
+#define XIP_OFFSET        SZ_8M

XIP_OFFSET is used in head.S and then this breaks XIP_KERNEL. XIP_OFFSET must live outside the ifndef __ASSEMBLY__.

Quoted 3 lines

Thanks, I hadn't even seen XIP_OFFSET.  This is fixed in the v2.

Do you have an XIP config that will run on QEMU, and a way to run it? If so, can you post a defconfig and some instructions?  That'll make it easier to test on my end.

I posted a tutorial here on how I test XIP kernel:

https://alexghiti.github.io/xip/XIP.html

If something does not work for you, please tell me.

Alex

Quoted 26 lines
Quoted 20 lines
Quoted 14 lines
arch/riscv/include/asm/pgtable.h +10 -0
+#define XIP_FIXUP(addr) ({                            \
+    uintptr_t __a = (uintptr_t)(addr);                    \
+    (__a >= CONFIG_XIP_PHYS_ADDR && __a < CONFIG_XIP_PHYS_ADDR + 
 SZ_16M) ?    \
+        __a - CONFIG_XIP_PHYS_ADDR + CONFIG_PHYS_RAM_BASE - 
 XIP_OFFSET :\
+        __a;                                \
+    })
+#else
+#define XIP_FIXUP(addr)        (addr)
+#endif /* CONFIG_XIP_KERNEL */
+
   #ifdef CONFIG_MMU
Quoted 3 lines

  /* Number of entries in the page global directory */ #define PTRS_PER_PGD    (PAGE_SIZE / sizeof(pgd_t))

Thank you for doing that!

Quoted 1 line

Alex

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