Skip to contentSkip to conversation

RISC-V: Various XIP fixes

PATCH In review Palmer Dabbelt 3 participants 11 messages Apr 20, 2022 – May 25, 2022 RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover RISC-V: Various XIP fixes

I found a handful of XIP-related bit rot when chasing down a LKP-reported issue. They're not really related, aside from all being XIP-related. I thought I had an XIP build test, I'll make sure to add/resurrect one when I get back around to these.

Changes since v1 <[email protected]>:
* Defines the mapping functions themselves to have no-op bodies, as opposed to wrapping their uses.
* 2-4 are new patches.

#1 lore raw

PATCH v2 1/4 RISC-V: Avoid empty create_*_mapping definitions

From: Palmer Dabbelt <[email protected]>

At least one use of these, that in create_fdt_early_page_table(), triggers warnings and should cause a real error (create_pmd_mpping() ends up skipped on XIP_KERNEL).

Fixes 677b9eb8810e ("riscv: mm: Prepare pt_ops helper functions for sv57")
---
 arch/riscv/mm/init.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/riscv/mm/init.c +3 -3
index 9535bea8688c..7bc9a21e29fb 100644
@@ -567,9 +567,9 @@ static void __init create_p4d_mapping(p4d_t *p4dp,
 	create_pte_mapping(__nextp, __va, __pa, __sz, __prot)
 #define fixmap_pgd_next		((uintptr_t)fixmap_pte)
 #define early_dtb_pgd_next	((uintptr_t)early_dtb_pmd)
-#define create_p4d_mapping(__pmdp, __va, __pa, __sz, __prot)
-#define create_pud_mapping(__pmdp, __va, __pa, __sz, __prot)
-#define create_pmd_mapping(__pmdp, __va, __pa, __sz, __prot)
+#define create_p4d_mapping(__pmdp, __va, __pa, __sz, __prot) do {} while(0)
+#define create_pud_mapping(__pmdp, __va, __pa, __sz, __prot) do {} while(0)
+#define create_pmd_mapping(__pmdp, __va, __pa, __sz, __prot) do {} while(0)
 #endif /* __PAGETABLE_PMD_FOLDED */
 
 void __init create_pgd_mapping(pgd_t *pgdp,
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/4] RISC-V: Avoid empty create_*_mapping definitions

Quoted 1 line · Palmer Dabbelt

(create_pmd_mpping() ends up skipped on XIP_KERNEL).

Does it? There is always the semicolon left as the body of the conditional (which is why you get the empty-body warning in the first place).

Signature · 8 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

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

Re: [PATCH v2 1/4] RISC-V: Avoid empty create_*_mapping definitions

Quoted 7 lines · On Wed, 20 Apr 2022 15:11:37 PDT (-0700), [email protected] wrote:
Quoted 1 line · Palmer Dabbelt

(create_pmd_mpping() ends up skipped on XIP_KERNEL).

Does it? There is always the semicolon left as the body of the conditional (which is why you get the empty-body warning in the first place).

Yep, you're right. I fixed up the commit message, thanks!

#4 lore raw

PATCH v2 2/4 RISC-V: ignore xipImage

In reply to Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

This built file shows up in "git status" without an explicit ignore.

---
 arch/riscv/boot/.gitignore | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/boot/.gitignore +1 -0
index 90e66adb7de5..0cea9f7fa9d5 100644
@@ -4,3 +4,4 @@ Image.*
 loader
 loader.lds
 loader.bin
+xipImage
Signature · 1 line
2.34.1
Reviewed-by on v2 2/4
#5 lore raw

Re: [PATCH v2 2/4] RISC-V: ignore xipImage

Quoted 22 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

This built file shows up in "git status" without an explicit ignore.

---
 arch/riscv/boot/.gitignore | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/boot/.gitignore +1 -1
index 90e66adb7de5..0cea9f7fa9d5 100644
@@ -4,3 +4,4 @@ Image.*
 loader
 loader.lds
 loader.bin
+xipImage
--

2.34.1

Signature · 4 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/
#6 lore raw

PATCH v2 3/4 RISC-V: Split out the XIP fixups into their own file

In reply to Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

This was broken by the original refactoring (as the XIP definitions depend on <asm/pgtable.h>) and then more broken by the merge (as I accidentally took the old version). This fixes both breakages, while also pulling this out of <asm/asm.h> to avoid polluting most assembly files with the XIP fixups.

Fixes bee7fbc38579 ("RISC-V CPU Idle Support")
Fixes 63b13e64a829 ("RISC-V: Add arch functions for non-retentive suspend entry/exit")
---
 arch/riscv/include/asm/asm.h       | 26 ------------------------
 arch/riscv/include/asm/xip_fixup.h | 32 ++++++++++++++++++++++++++++++
 arch/riscv/kernel/head.S           |  1 +
 arch/riscv/kernel/suspend_entry.S  |  1 +
 4 files changed, 34 insertions(+), 26 deletions(-)
 create mode 100644 arch/riscv/include/asm/xip_fixup.h
arch/riscv/include/asm/asm.h +0 -26
index 8c2549b16ac0..618d7c5af1a2 100644
@@ -67,30 +67,4 @@
 #error "Unexpected __SIZEOF_SHORT__"
 #endif
 
-#ifdef __ASSEMBLY__
-
-/* Common assembly source macros */
-
-#ifdef CONFIG_XIP_KERNEL
-.macro XIP_FIXUP_OFFSET reg
-	REG_L t0, _xip_fixup
-	add \reg, \reg, t0
-.endm
-.macro XIP_FIXUP_FLASH_OFFSET reg
-	la t1, __data_loc
-	REG_L t1, _xip_phys_offset
-	sub \reg, \reg, t1
-	add \reg, \reg, t0
-.endm
-_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
-_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET
-#else
-.macro XIP_FIXUP_OFFSET reg
-.endm
-.macro XIP_FIXUP_FLASH_OFFSET reg
-.endm
-#endif /* CONFIG_XIP_KERNEL */
-
-#endif /* __ASSEMBLY__ */
-
 #endif /* _ASM_RISCV_ASM_H */
arch/riscv/include/asm/xip_fixup.h new file +32 -0
new file mode 100644
index 000000000000..0d0754305324
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * XIP fixup macros, only useful in assembly.
+ */
+#ifndef _ASM_RISCV_XIP_FIXUP_H
+#define _ASM_RISCV_XIP_FIXUP_H
+
+#include <linux/pgtable.h>
+
+#ifdef CONFIG_XIP_KERNEL
+.macro XIP_FIXUP_OFFSET reg
+        REG_L t0, _xip_fixup
+        add \reg, \reg, t0
+.endm
+.macro XIP_FIXUP_FLASH_OFFSET reg
+        la t1, __data_loc
+        li t0, XIP_OFFSET_MASK
+        and t1, t1, t0
+        li t1, XIP_OFFSET
+        sub t0, t0, t1
+        sub \reg, \reg, t0
+.endm
+
+_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
+#else
+.macro XIP_FIXUP_OFFSET reg
+.endm
+.macro XIP_FIXUP_FLASH_OFFSET reg
+.endm
+#endif /* CONFIG_XIP_KERNEL */
+
+#endif
arch/riscv/kernel/head.S +1 -0
index 893b8bb69391..822c33aa7f45 100644
@@ -14,6 +14,7 @@
 #include <asm/hwcap.h>
 #include <asm/image.h>
+#include <asm/xip_fixup.h>
 #include "efi-header.S"
 
 __HEAD
arch/riscv/kernel/suspend_entry.S +1 -0
index 4b07b809a2b8..aafcca58c19d 100644
@@ -8,6 +8,7 @@
 #include <asm/asm.h>
 #include <asm/asm-offsets.h>
 #include <asm/csr.h>
+#include <asm/xip_fixup.h>
 
 	.text
 	.altmacro
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v2 3/4
#7 lore raw

Re: [PATCH v2 3/4] RISC-V: Split out the XIP fixups into their own file

Quoted 70 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

This was broken by the original refactoring (as the XIP definitions depend on <asm/pgtable.h>) and then more broken by the merge (as I accidentally took the old version). This fixes both breakages, while also pulling this out of <asm/asm.h> to avoid polluting most assembly files with the XIP fixups.

Fixes bee7fbc38579 ("RISC-V CPU Idle Support")
Fixes 63b13e64a829 ("RISC-V: Add arch functions for non-retentive suspend entry/exit")
---
 arch/riscv/include/asm/asm.h       | 26 ------------------------
 arch/riscv/include/asm/xip_fixup.h | 32 ++++++++++++++++++++++++++++++
 arch/riscv/kernel/head.S           |  1 +
 arch/riscv/kernel/suspend_entry.S  |  1 +
 4 files changed, 34 insertions(+), 26 deletions(-)
 create mode 100644 arch/riscv/include/asm/xip_fixup.h
arch/riscv/include/asm/asm.h +0 -26
index 8c2549b16ac0..618d7c5af1a2 100644
@@ -67,30 +67,4 @@
 #error "Unexpected __SIZEOF_SHORT__"
 #endif
 
-#ifdef __ASSEMBLY__
-
-/* Common assembly source macros */
-
-#ifdef CONFIG_XIP_KERNEL
-.macro XIP_FIXUP_OFFSET reg
-       REG_L t0, _xip_fixup
-       add \reg, \reg, t0
-.endm
-.macro XIP_FIXUP_FLASH_OFFSET reg
-       la t1, __data_loc
-       REG_L t1, _xip_phys_offset
-       sub \reg, \reg, t1
-       add \reg, \reg, t0
-.endm
-_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
-_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET
-#else
-.macro XIP_FIXUP_OFFSET reg
-.endm
-.macro XIP_FIXUP_FLASH_OFFSET reg
-.endm
-#endif /* CONFIG_XIP_KERNEL */
-
-#endif /* __ASSEMBLY__ */
-
 #endif /* _ASM_RISCV_ASM_H */
arch/riscv/include/asm/xip_fixup.h new file +9 -0
new file mode 100644
index 000000000000..0d0754305324
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * XIP fixup macros, only useful in assembly.
+ */
+#ifndef _ASM_RISCV_XIP_FIXUP_H
+#define _ASM_RISCV_XIP_FIXUP_H
+
+#include <linux/pgtable.h>
+

arch/riscv/include/asm/xip_fixup.h line 19

Quoted 10 lines
arch/riscv/include/asm/xip_fixup.h new file +10 -0
+#ifdef CONFIG_XIP_KERNEL
+.macro XIP_FIXUP_OFFSET reg
+        REG_L t0, _xip_fixup
+        add \reg, \reg, t0
+.endm
+.macro XIP_FIXUP_FLASH_OFFSET reg
+        la t1, __data_loc
+        li t0, XIP_OFFSET_MASK
+        and t1, t1, t0
+        li t1, XIP_OFFSET

I still prefer the style:
REG_L t1, _xip_phys_offset
...
_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET

Because it's more clear and has the same style as your _xip_fixup.

Others:

arch/riscv/include/asm/xip_fixup.h line 22

Quoted 3 lines
arch/riscv/include/asm/xip_fixup.h new file +3 -0
+        sub t0, t0, t1
+        sub \reg, \reg, t0
+.endm

-.endm

Quoted 36 lines
arch/riscv/include/asm/xip_fixup.h new file +10 -0
+
+_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
+#else
+.macro XIP_FIXUP_OFFSET reg
+.endm
+.macro XIP_FIXUP_FLASH_OFFSET reg
+.endm
+#endif /* CONFIG_XIP_KERNEL */
+
+#endif
arch/riscv/kernel/head.S +1 -0
index 893b8bb69391..822c33aa7f45 100644
@@ -14,6 +14,7 @@
 #include <asm/hwcap.h>
 #include <asm/image.h>
+#include <asm/xip_fixup.h>
 #include "efi-header.S"
 
 __HEAD
arch/riscv/kernel/suspend_entry.S +1 -1
index 4b07b809a2b8..aafcca58c19d 100644
@@ -8,6 +8,7 @@
 #include <asm/asm.h>
 #include <asm/asm-offsets.h>
 #include <asm/csr.h>
+#include <asm/xip_fixup.h>
 
        .text
        .altmacro
--

2.34.1

Signature · 9 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/

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

Re: [PATCH v2 3/4] RISC-V: Split out the XIP fixups into their own file

Quoted 86 lines · On Wed, 20 Apr 2022 23:45:23 PDT (-0700), [email protected] wrote:
Quoted 70 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

This was broken by the original refactoring (as the XIP definitions depend on <asm/pgtable.h>) and then more broken by the merge (as I accidentally took the old version). This fixes both breakages, while also pulling this out of <asm/asm.h> to avoid polluting most assembly files with the XIP fixups.

Fixes bee7fbc38579 ("RISC-V CPU Idle Support")
Fixes 63b13e64a829 ("RISC-V: Add arch functions for non-retentive suspend entry/exit")
---
 arch/riscv/include/asm/asm.h       | 26 ------------------------
 arch/riscv/include/asm/xip_fixup.h | 32 ++++++++++++++++++++++++++++++
 arch/riscv/kernel/head.S           |  1 +
 arch/riscv/kernel/suspend_entry.S  |  1 +
 4 files changed, 34 insertions(+), 26 deletions(-)
 create mode 100644 arch/riscv/include/asm/xip_fixup.h
arch/riscv/include/asm/asm.h +0 -26
index 8c2549b16ac0..618d7c5af1a2 100644
@@ -67,30 +67,4 @@
 #error "Unexpected __SIZEOF_SHORT__"
 #endif
 
-#ifdef __ASSEMBLY__
-
-/* Common assembly source macros */
-
-#ifdef CONFIG_XIP_KERNEL
-.macro XIP_FIXUP_OFFSET reg
-       REG_L t0, _xip_fixup
-       add \reg, \reg, t0
-.endm
-.macro XIP_FIXUP_FLASH_OFFSET reg
-       la t1, __data_loc
-       REG_L t1, _xip_phys_offset
-       sub \reg, \reg, t1
-       add \reg, \reg, t0
-.endm
-_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
-_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET
-#else
-.macro XIP_FIXUP_OFFSET reg
-.endm
-.macro XIP_FIXUP_FLASH_OFFSET reg
-.endm
-#endif /* CONFIG_XIP_KERNEL */
-
-#endif /* __ASSEMBLY__ */
-
 #endif /* _ASM_RISCV_ASM_H */
arch/riscv/include/asm/xip_fixup.h new file +9 -0
new file mode 100644
index 000000000000..0d0754305324
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * XIP fixup macros, only useful in assembly.
+ */
+#ifndef _ASM_RISCV_XIP_FIXUP_H
+#define _ASM_RISCV_XIP_FIXUP_H
+
+#include <linux/pgtable.h>
+

arch/riscv/include/asm/xip_fixup.h line 19

Quoted 10 lines
arch/riscv/include/asm/xip_fixup.h new file +10 -0
+#ifdef CONFIG_XIP_KERNEL
+.macro XIP_FIXUP_OFFSET reg
+        REG_L t0, _xip_fixup
+        add \reg, \reg, t0
+.endm
+.macro XIP_FIXUP_FLASH_OFFSET reg
+        la t1, __data_loc
+        li t0, XIP_OFFSET_MASK
+        and t1, t1, t0
+        li t1, XIP_OFFSET

I still prefer the style:
REG_L t1, _xip_phys_offset
...
_xip_phys_offset: .dword CONFIG_XIP_PHYS_ADDR + XIP_OFFSET

Quoted 1 line

Because it's more clear and has the same style as your _xip_fixup.

Thanks, not quite shure how I pulled the old version over. I've fixed this one up.

Quoted 43 lines

Others:

arch/riscv/include/asm/xip_fixup.h line 22

Quoted 3 lines
arch/riscv/include/asm/xip_fixup.h new file +3 -0
+        sub t0, t0, t1
+        sub \reg, \reg, t0
+.endm

-.endm

Quoted 36 lines
arch/riscv/include/asm/xip_fixup.h new file +10 -0
+
+_xip_fixup: .dword CONFIG_PHYS_RAM_BASE - CONFIG_XIP_PHYS_ADDR - XIP_OFFSET
+#else
+.macro XIP_FIXUP_OFFSET reg
+.endm
+.macro XIP_FIXUP_FLASH_OFFSET reg
+.endm
+#endif /* CONFIG_XIP_KERNEL */
+
+#endif
arch/riscv/kernel/head.S +1 -0
index 893b8bb69391..822c33aa7f45 100644
@@ -14,6 +14,7 @@
 #include <asm/hwcap.h>
 #include <asm/image.h>
+#include <asm/xip_fixup.h>
 #include "efi-header.S"
 
 __HEAD
arch/riscv/kernel/suspend_entry.S +1 -1
index 4b07b809a2b8..aafcca58c19d 100644
@@ -8,6 +8,7 @@
 #include <asm/asm.h>
 #include <asm/asm-offsets.h>
 #include <asm/csr.h>
+#include <asm/xip_fixup.h>
 
        .text
        .altmacro
--

2.34.1

#9 lore raw

PATCH v2 4/4 RISC-V: Fix the XIP build

In reply to Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

A handful of functions unused functions were enabled during XIP builds, which themselves didn't build correctly. This just disables the functions entirely.

Fixes e8a62cc26ddf ("riscv: Implement sv48 support")
---
 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -1
index 7bc9a21e29fb..d2054a6cd791 100644
@@ -660,7 +660,7 @@ static __init pgprot_t pgprot_from_va(uintptr_t va)
 }
 #endif /* CONFIG_STRICT_KERNEL_RWX */
 
-#ifdef CONFIG_64BIT
+#if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL)
 static void __init disable_pgtable_l5(void)
 {
 	pgtable_l5_enabled = false;
Signature · 7 lines
2.34.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v2 4/4
#10 lore raw

Re: [PATCH v2 4/4] RISC-V: Fix the XIP build

Quoted 29 lines · Palmer Dabbelt

From: Palmer Dabbelt <[email protected]>

A handful of functions unused functions were enabled during XIP builds, which themselves didn't build correctly. This just disables the functions entirely.

Fixes e8a62cc26ddf ("riscv: Implement sv48 support")
---
 arch/riscv/mm/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -2
index 7bc9a21e29fb..d2054a6cd791 100644
@@ -660,7 +660,7 @@ static __init pgprot_t pgprot_from_va(uintptr_t va)
 }
 #endif /* CONFIG_STRICT_KERNEL_RWX */
 
-#ifdef CONFIG_64BIT
+#if defined(CONFIG_64BIT) && !defined(CONFIG_XIP_KERNEL)
 static void __init disable_pgtable_l5(void)
 {
        pgtable_l5_enabled = false;
--

2.34.1

Signature · 9 lines
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/

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