Skip to contentSkip to conversation

riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX

PATCH In review Sebastien Van Cauwenberghe 3 participants 7 messages Nov 16, 2020 – Jan 29, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX

From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
From: Sebastien Van Cauwenberghe <[email protected]>
Date: Mon, 16 Nov 2020 13:37:32 +0100
Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
disabled

Allows the sections to be aligned on smaller boundaries and therefore results in a smaller kernel image size.

---
 arch/riscv/include/asm/set_memory.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/riscv/include/asm/set_memory.h +3 -3
index 4c5bae7ca01c..172e63d942b0 100644
@@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
+#ifdef CONFIG_STRICT_KERNEL_RWX
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)
 #else
 #define SECTION_ALIGN (1 << 22)
 #endif
-#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#else /* !CONFIG_STRICT_KERNEL_RWX */
 #define SECTION_ALIGN L1_CACHE_BYTES
-#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 #endif /* _ASM_RISCV_SET_MEMORY_H */
Signature · 8 lines
2.28.0



_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/1
#1 lore raw
Quoted 42 lines · Sebastien Van Cauwenberghe

From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
From: Sebastien Van Cauwenberghe <[email protected]>
Date: Mon, 16 Nov 2020 13:37:32 +0100
Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
disabled

Allows the sections to be aligned on smaller boundaries and therefore results in a smaller kernel image size.

---
 arch/riscv/include/asm/set_memory.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/riscv/include/asm/set_memory.h +3 -4
index 4c5bae7ca01c..172e63d942b0 100644
@@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
+#ifdef CONFIG_STRICT_KERNEL_RWX
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)
 #else
 #define SECTION_ALIGN (1 << 22)
 #endif
-#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#else /* !CONFIG_STRICT_KERNEL_RWX */
 #define SECTION_ALIGN L1_CACHE_BYTES
-#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 #endif /* _ASM_RISCV_SET_MEMORY_H */
--

2.28.0

Quoted 4 lines

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

Thanks for the fix.

Signature · 7 lines
Regards,
Atish

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw
In reply to Sebastien Van Cauwenberghe

Hi Sebastien,

Quoted 10 lines · Sebastien Van Cauwenberghe

From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
From: Sebastien Van Cauwenberghe <[email protected]>
Date: Mon, 16 Nov 2020 13:37:32 +0100
Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
disabled

Allows the sections to be aligned on smaller boundaries and therefore results in a smaller kernel image size.

Thanks for your patch!

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +1 -1
@@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
+#ifdef CONFIG_STRICT_KERNEL_RWX
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)

arch/riscv/include/asm/set_memory.h int set_direct_map_default_noflush(struct page *page); · line 40

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +2 -2
 #else
 #define SECTION_ALIGN (1 << 22)
 #endif
-#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#else /* !CONFIG_STRICT_KERNEL_RWX */
 #define SECTION_ALIGN L1_CACHE_BYTES
-#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 #endif /* _ASM_RISCV_SET_MEMORY_H */

Since commit 19a00869028f4a28 ("RISC-V: Protect all kernel sections including init early"), you also need (whitespace-damaged-gmail-patch):

arch/riscv/kernel/setup.c +3 -1
@@ -293,6 +293,8 @@ void free_initmem(void)
        unsigned long init_begin = (unsigned long)__init_begin;
        unsigned long init_end = (unsigned long)__init_end;
 
-       set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+       if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+               set_memory_rw_nx(init_begin,
+                                (init_end - init_begin) >> PAGE_SHIFT);
        free_initmem_default(POISON_FREE_INITMEM);
 }

Else it crashes here without any kernel output.

Feel free to fold this into your patch.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

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

#3 lore raw
Quoted 46 lines · Geert Uytterhoeven

Hi Sebastien,

Quoted 10 lines · Sebastien Van Cauwenberghe

From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
From: Sebastien Van Cauwenberghe <[email protected]>
Date: Mon, 16 Nov 2020 13:37:32 +0100
Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
disabled

Allows the sections to be aligned on smaller boundaries and therefore results in a smaller kernel image size.

Thanks for your patch!

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +1 -1
@@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
+#ifdef CONFIG_STRICT_KERNEL_RWX
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)

arch/riscv/include/asm/set_memory.h int set_direct_map_default_noflush(struct page *page); · line 40

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +2 -2
 #else
 #define SECTION_ALIGN (1 << 22)
 #endif
-#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#else /* !CONFIG_STRICT_KERNEL_RWX */
 #define SECTION_ALIGN L1_CACHE_BYTES
-#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 #endif /* _ASM_RISCV_SET_MEMORY_H */

Since commit 19a00869028f4a28 ("RISC-V: Protect all kernel sections including init early"), you also need (whitespace-damaged-gmail-patch):

arch/riscv/kernel/setup.c void free_initmem(void) · line 300

Quoted 9 lines
arch/riscv/kernel/setup.c +3 -1
@@ -293,6 +293,8 @@ void free_initmem(void)
        unsigned long init_begin = (unsigned long)__init_begin;
        unsigned long init_end = (unsigned long)__init_end;
 
-       set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+       if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+               set_memory_rw_nx(init_begin,
+                                (init_end - init_begin) >> PAGE_SHIFT);
        free_initmem_default(POISON_FREE_INITMEM);
 }

Thanks for the fix. I guess you need to disable
CONFIG_STRICT_KERNEL_RWX explicitly
to notice this issue.

Quoted 4 lines

Else it crashes here without any kernel output.

Feel free to fold this into your patch.

IMO, this can be a separate patch with Fixes tag.

Quoted 15 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

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

Signature · 7 lines
Regards,
Atish

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

Hi Atish,

Quoted 46 lines · Atish Patra
Quoted 45 lines · Geert Uytterhoeven
Quoted 10 lines · Sebastien Van Cauwenberghe

From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
From: Sebastien Van Cauwenberghe <[email protected]>
Date: Mon, 16 Nov 2020 13:37:32 +0100
Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
disabled

Allows the sections to be aligned on smaller boundaries and therefore results in a smaller kernel image size.

Thanks for your patch!

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +1 -1
@@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
+#ifdef CONFIG_STRICT_KERNEL_RWX
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)

arch/riscv/include/asm/set_memory.h int set_direct_map_default_noflush(struct page *page); · line 40

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +2 -2
 #else
 #define SECTION_ALIGN (1 << 22)
 #endif
-#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#else /* !CONFIG_STRICT_KERNEL_RWX */
 #define SECTION_ALIGN L1_CACHE_BYTES
-#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 #endif /* _ASM_RISCV_SET_MEMORY_H */

Since commit 19a00869028f4a28 ("RISC-V: Protect all kernel sections including init early"), you also need (whitespace-damaged-gmail-patch):

arch/riscv/kernel/setup.c +0 -0
@@ -293,6 +293,8 @@ void free_initmem(void)
        unsigned long init_begin = (unsigned long)__init_begin;
        unsigned long init_end = (unsigned long)__init_end;
 
Quoted 11 lines

arch/riscv/kernel/setup.c void free_initmem(void) · line 300

Quoted 7 lines
arch/riscv/kernel/setup.c +3 -1
-       set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+       if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+               set_memory_rw_nx(init_begin,
+                                (init_end - init_begin) >> PAGE_SHIFT);
        free_initmem_default(POISON_FREE_INITMEM);
 }

Thanks for the fix. I guess you need to disable
CONFIG_STRICT_KERNEL_RWX explicitly
to notice this issue.

Indeed.

Quoted 6 lines
Quoted 4 lines

Else it crashes here without any kernel output.

Feel free to fold this into your patch.

IMO, this can be a separate patch with Fixes tag.

Why? Sebastien's patch (which hasn't been applied yet) no longer works due to interaction with a commit in v5.11-rc1.

Gr{oetje,eeting}s,

Geert

Signature · 10 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#5 lore raw
Quoted 66 lines · Geert Uytterhoeven

Hi Atish,

Quoted 46 lines · Atish Patra
Quoted 45 lines · Geert Uytterhoeven
Quoted 10 lines · Sebastien Van Cauwenberghe

From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
From: Sebastien Van Cauwenberghe <[email protected]>
Date: Mon, 16 Nov 2020 13:37:32 +0100
Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
disabled

Allows the sections to be aligned on smaller boundaries and therefore results in a smaller kernel image size.

Thanks for your patch!

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +1 -1
@@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
+#ifdef CONFIG_STRICT_KERNEL_RWX
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)

arch/riscv/include/asm/set_memory.h int set_direct_map_default_noflush(struct page *page); · line 40

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +2 -2
 #else
 #define SECTION_ALIGN (1 << 22)
 #endif
-#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#else /* !CONFIG_STRICT_KERNEL_RWX */
 #define SECTION_ALIGN L1_CACHE_BYTES
-#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 #endif /* _ASM_RISCV_SET_MEMORY_H */

Since commit 19a00869028f4a28 ("RISC-V: Protect all kernel sections including init early"), you also need (whitespace-damaged-gmail-patch):

arch/riscv/kernel/setup.c +0 -0
@@ -293,6 +293,8 @@ void free_initmem(void)
        unsigned long init_begin = (unsigned long)__init_begin;
        unsigned long init_end = (unsigned long)__init_end;
 
Quoted 11 lines

arch/riscv/kernel/setup.c void free_initmem(void) · line 300

Quoted 7 lines
arch/riscv/kernel/setup.c +3 -1
-       set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+       if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+               set_memory_rw_nx(init_begin,
+                                (init_end - init_begin) >> PAGE_SHIFT);
        free_initmem_default(POISON_FREE_INITMEM);
 }

Thanks for the fix. I guess you need to disable
CONFIG_STRICT_KERNEL_RWX explicitly
to notice this issue.

Indeed.

Quoted 2 lines
Quoted 2 lines

Else it crashes here without any kernel output.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Feel free to fold this into your patch.

IMO, this can be a separate patch with Fixes tag.

Why? Sebastien's patch (which hasn't been applied yet) no longer works due to interaction with a commit in v5.11-rc1.

Technically, Sebastien's patch was an improvement while this one fixes an issue so that the Fixes tag can be added.
But the original patch was merged in this cycle only. So these changes can be a single change as long as it is sent as an rc fix. I am fine with either way.

@Sebastien: Can you send the updated patch soon so that palmer can pull this one as an RC fix?

Quoted 10 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

--
Regards,
Atish

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

#6 lore raw
Quoted 77 lines · Atish Patra
Quoted 66 lines · Geert Uytterhoeven

Hi Atish,

Quoted 46 lines · Atish Patra
Quoted 45 lines · Geert Uytterhoeven
Quoted 10 lines · Sebastien Van Cauwenberghe

From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
From: Sebastien Van Cauwenberghe <[email protected]>
Date: Mon, 16 Nov 2020 13:37:32 +0100
Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
disabled

Allows the sections to be aligned on smaller boundaries and therefore results in a smaller kernel image size.

Thanks for your patch!

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +1 -1
@@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
 
 #endif /* __ASSEMBLY__ */
 
-#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
+#ifdef CONFIG_STRICT_KERNEL_RWX
 #ifdef CONFIG_64BIT
 #define SECTION_ALIGN (1 << 21)

arch/riscv/include/asm/set_memory.h int set_direct_map_default_noflush(struct page *page); · line 40

Quoted 10 lines
arch/riscv/include/asm/set_memory.h +2 -2
 #else
 #define SECTION_ALIGN (1 << 22)
 #endif
-#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#else /* !CONFIG_STRICT_KERNEL_RWX */
 #define SECTION_ALIGN L1_CACHE_BYTES
-#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
+#endif /* CONFIG_STRICT_KERNEL_RWX */
 
 #endif /* _ASM_RISCV_SET_MEMORY_H */

Since commit 19a00869028f4a28 ("RISC-V: Protect all kernel sections including init early"), you also need (whitespace-damaged-gmail-patch):

arch/riscv/kernel/setup.c +0 -0
@@ -293,6 +293,8 @@ void free_initmem(void)
        unsigned long init_begin = (unsigned long)__init_begin;
        unsigned long init_end = (unsigned long)__init_end;
 
Quoted 11 lines

arch/riscv/kernel/setup.c void free_initmem(void) · line 300

Quoted 7 lines
arch/riscv/kernel/setup.c +3 -1
-       set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
+       if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
+               set_memory_rw_nx(init_begin,
+                                (init_end - init_begin) >> PAGE_SHIFT);
        free_initmem_default(POISON_FREE_INITMEM);
 }

Thanks for the fix. I guess you need to disable
CONFIG_STRICT_KERNEL_RWX explicitly
to notice this issue.

Indeed.

Quoted 2 lines
Quoted 2 lines

Else it crashes here without any kernel output.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Feel free to fold this into your patch.

IMO, this can be a separate patch with Fixes tag.

Why? Sebastien's patch (which hasn't been applied yet) no longer works due to interaction with a commit in v5.11-rc1.

Quoted 9 lines

Technically, Sebastien's patch was an improvement while this one fixes an issue so that the Fixes tag can be added.
But the original patch was merged in this cycle only. So these changes can be a single change as long as it is sent as an rc fix. I am fine with either way.

@Sebastien: Can you send the updated patch soon so that palmer can pull this one as an RC fix?

I have sent the fixes to the mailing list with appropriate tags.

Quoted 17 lines
Quoted 11 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

--
Regards,
Atish

Signature · 7 lines
Regards,
Atish

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