diff mbox series

[v6,08/14] riscv: move boot alternatives to a slightly earlier position

Message ID 20220209123800.269774-9-heiko@sntech.de (mailing list archive)
State New, archived
Headers show
Series riscv: support for Svpbmt and D1 memory types | expand

Commit Message

Heiko Stübner Feb. 9, 2022, 12:37 p.m. UTC
Move the application of boot alternatives to soc_early_init().
This allows to catch more generic cases of code needing patches
than doing it in smp_prepare_boot_cpu() and also makes it actually
work if CONFIG_SMP is disabled for whatever reason.

The position is chosen mainly as it is before the actual soc early
init runs but also already allows accessing the devicetree
via fdt_* functions.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 arch/riscv/kernel/head.S    | 2 ++
 arch/riscv/kernel/smpboot.c | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Atish Patra Feb. 10, 2022, 10:42 p.m. UTC | #1
On Wed, Feb 9, 2022 at 4:39 AM Heiko Stuebner <heiko@sntech.de> wrote:
>
> Move the application of boot alternatives to soc_early_init().
> This allows to catch more generic cases of code needing patches
> than doing it in smp_prepare_boot_cpu() and also makes it actually
> work if CONFIG_SMP is disabled for whatever reason.
>
> The position is chosen mainly as it is before the actual soc early
> init runs but also already allows accessing the devicetree
> via fdt_* functions.
>
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> ---
>  arch/riscv/kernel/head.S    | 2 ++
>  arch/riscv/kernel/smpboot.c | 2 --
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> index 2363b43312fc..0e1bb97f9749 100644
> --- a/arch/riscv/kernel/head.S
> +++ b/arch/riscv/kernel/head.S
> @@ -10,6 +10,7 @@
>  #include <asm/thread_info.h>
>  #include <asm/page.h>
>  #include <asm/pgtable.h>
> +#include <asm/alternative.h>
>  #include <asm/csr.h>
>  #include <asm/cpu_ops_sbi.h>
>  #include <asm/hwcap.h>
> @@ -341,6 +342,7 @@ clear_bss_done:
>         call kasan_early_init
>  #endif
>         /* Start the kernel */
> +       call apply_boot_alternatives

Do you really need this early ?
if non-smp configuration is the only option, Can you do it in
setup_arch() after riscv_fill_hwcap() is called ?

By doing that, we can unify the cpu feature probing and you don't need
a separate DT parsing just for svpbmt.

>         call soc_early_init
>         tail start_kernel
>
> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> index a6d13dca1403..f1e4948a4b52 100644
> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c
> @@ -32,7 +32,6 @@
>  #include <asm/sections.h>
>  #include <asm/sbi.h>
>  #include <asm/smp.h>
> -#include <asm/alternative.h>
>
>  #include "head.h"
>
> @@ -41,7 +40,6 @@ static DECLARE_COMPLETION(cpu_running);
>  void __init smp_prepare_boot_cpu(void)
>  {
>         init_cpu_topology();
> -       apply_boot_alternatives();
>  }
>
>  void __init smp_prepare_cpus(unsigned int max_cpus)
> --
> 2.30.2
>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
Heiko Stübner Feb. 11, 2022, 1:11 a.m. UTC | #2
Hi Atish,

Am Donnerstag, 10. Februar 2022, 23:42:35 CET schrieb Atish Patra:
> On Wed, Feb 9, 2022 at 4:39 AM Heiko Stuebner <heiko@sntech.de> wrote:
> >
> > Move the application of boot alternatives to soc_early_init().
> > This allows to catch more generic cases of code needing patches
> > than doing it in smp_prepare_boot_cpu() and also makes it actually
> > work if CONFIG_SMP is disabled for whatever reason.
> >
> > The position is chosen mainly as it is before the actual soc early
> > init runs but also already allows accessing the devicetree
> > via fdt_* functions.
> >
> > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > ---
> >  arch/riscv/kernel/head.S    | 2 ++
> >  arch/riscv/kernel/smpboot.c | 2 --
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> > index 2363b43312fc..0e1bb97f9749 100644
> > --- a/arch/riscv/kernel/head.S
> > +++ b/arch/riscv/kernel/head.S
> > @@ -10,6 +10,7 @@
> >  #include <asm/thread_info.h>
> >  #include <asm/page.h>
> >  #include <asm/pgtable.h>
> > +#include <asm/alternative.h>
> >  #include <asm/csr.h>
> >  #include <asm/cpu_ops_sbi.h>
> >  #include <asm/hwcap.h>
> > @@ -341,6 +342,7 @@ clear_bss_done:
> >         call kasan_early_init
> >  #endif
> >         /* Start the kernel */
> > +       call apply_boot_alternatives
> 
> Do you really need this early ?
> if non-smp configuration is the only option, Can you do it in
> setup_arch() after riscv_fill_hwcap() is called ?

The issue I see is, we we have the soc_early_init [0] running
directly after this and the one user I see [1] already wants to
ioremap io-memory at this stage.

So judging by the fact that more early-inits will get added
in the future I do guess we should've set up the io-memory
page-type by this point?


Heiko

[0] https://elixir.bootlin.com/linux/latest/source/arch/riscv/kernel/soc.c#L14
[1] https://elixir.bootlin.com/linux/latest/source/drivers/soc/canaan/k210-sysctl.c#L66

> By doing that, we can unify the cpu feature probing and you don't need
> a separate DT parsing just for svpbmt.
> 
> >         call soc_early_init
> >         tail start_kernel
> >
> > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> > index a6d13dca1403..f1e4948a4b52 100644
> > --- a/arch/riscv/kernel/smpboot.c
> > +++ b/arch/riscv/kernel/smpboot.c
> > @@ -32,7 +32,6 @@
> >  #include <asm/sections.h>
> >  #include <asm/sbi.h>
> >  #include <asm/smp.h>
> > -#include <asm/alternative.h>
> >
> >  #include "head.h"
> >
> > @@ -41,7 +40,6 @@ static DECLARE_COMPLETION(cpu_running);
> >  void __init smp_prepare_boot_cpu(void)
> >  {
> >         init_cpu_topology();
> > -       apply_boot_alternatives();
> >  }
> >
> >  void __init smp_prepare_cpus(unsigned int max_cpus)
> > --
> > 2.30.2
> >
> >
> > _______________________________________________
> > linux-riscv mailing list
> > linux-riscv@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-riscv
> 
> 
> 
>
Atish Patra Feb. 11, 2022, 1:57 a.m. UTC | #3
On Thu, Feb 10, 2022 at 5:11 PM Heiko Stübner <heiko@sntech.de> wrote:
>
> Hi Atish,
>
> Am Donnerstag, 10. Februar 2022, 23:42:35 CET schrieb Atish Patra:
> > On Wed, Feb 9, 2022 at 4:39 AM Heiko Stuebner <heiko@sntech.de> wrote:
> > >
> > > Move the application of boot alternatives to soc_early_init().
> > > This allows to catch more generic cases of code needing patches
> > > than doing it in smp_prepare_boot_cpu() and also makes it actually
> > > work if CONFIG_SMP is disabled for whatever reason.
> > >
> > > The position is chosen mainly as it is before the actual soc early
> > > init runs but also already allows accessing the devicetree
> > > via fdt_* functions.
> > >
> > > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > > ---
> > >  arch/riscv/kernel/head.S    | 2 ++
> > >  arch/riscv/kernel/smpboot.c | 2 --
> > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> > > index 2363b43312fc..0e1bb97f9749 100644
> > > --- a/arch/riscv/kernel/head.S
> > > +++ b/arch/riscv/kernel/head.S
> > > @@ -10,6 +10,7 @@
> > >  #include <asm/thread_info.h>
> > >  #include <asm/page.h>
> > >  #include <asm/pgtable.h>
> > > +#include <asm/alternative.h>
> > >  #include <asm/csr.h>
> > >  #include <asm/cpu_ops_sbi.h>
> > >  #include <asm/hwcap.h>
> > > @@ -341,6 +342,7 @@ clear_bss_done:
> > >         call kasan_early_init
> > >  #endif
> > >         /* Start the kernel */
> > > +       call apply_boot_alternatives
> >
> > Do you really need this early ?
> > if non-smp configuration is the only option, Can you do it in
> > setup_arch() after riscv_fill_hwcap() is called ?
>
> The issue I see is, we we have the soc_early_init [0] running
> directly after this and the one user I see [1] already wants to
> ioremap io-memory at this stage.
>

Kendryte is always a special case. IIRC, ioremap is done so early
so that it can use all 8MB of SRAM.

> So judging by the fact that more early-inits will get added
> in the future I do guess we should've set up the io-memory
> page-type by this point?
>

I hope there won't be :). For any normal mmu capable SoC, I don't
see why that would be required.

>
> Heiko
>
> [0] https://elixir.bootlin.com/linux/latest/source/arch/riscv/kernel/soc.c#L14
> [1] https://elixir.bootlin.com/linux/latest/source/drivers/soc/canaan/k210-sysctl.c#L66
>
> > By doing that, we can unify the cpu feature probing and you don't need
> > a separate DT parsing just for svpbmt.
> >
> > >         call soc_early_init
> > >         tail start_kernel
> > >
> > > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> > > index a6d13dca1403..f1e4948a4b52 100644
> > > --- a/arch/riscv/kernel/smpboot.c
> > > +++ b/arch/riscv/kernel/smpboot.c
> > > @@ -32,7 +32,6 @@
> > >  #include <asm/sections.h>
> > >  #include <asm/sbi.h>
> > >  #include <asm/smp.h>
> > > -#include <asm/alternative.h>
> > >
> > >  #include "head.h"
> > >
> > > @@ -41,7 +40,6 @@ static DECLARE_COMPLETION(cpu_running);
> > >  void __init smp_prepare_boot_cpu(void)
> > >  {
> > >         init_cpu_topology();
> > > -       apply_boot_alternatives();
> > >  }
> > >
> > >  void __init smp_prepare_cpus(unsigned int max_cpus)
> > > --
> > > 2.30.2
> > >
> > >
> > > _______________________________________________
> > > linux-riscv mailing list
> > > linux-riscv@lists.infradead.org
> > > http://lists.infradead.org/mailman/listinfo/linux-riscv
> >
> >
> >
> >
>
>
>
>
Heiko Stübner Feb. 11, 2022, 9:34 a.m. UTC | #4
Am Freitag, 11. Februar 2022, 02:57:19 CET schrieb Atish Patra:
> On Thu, Feb 10, 2022 at 5:11 PM Heiko Stübner <heiko@sntech.de> wrote:
> >
> > Hi Atish,
> >
> > Am Donnerstag, 10. Februar 2022, 23:42:35 CET schrieb Atish Patra:
> > > On Wed, Feb 9, 2022 at 4:39 AM Heiko Stuebner <heiko@sntech.de> wrote:
> > > >
> > > > Move the application of boot alternatives to soc_early_init().
> > > > This allows to catch more generic cases of code needing patches
> > > > than doing it in smp_prepare_boot_cpu() and also makes it actually
> > > > work if CONFIG_SMP is disabled for whatever reason.
> > > >
> > > > The position is chosen mainly as it is before the actual soc early
> > > > init runs but also already allows accessing the devicetree
> > > > via fdt_* functions.
> > > >
> > > > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > > > ---
> > > >  arch/riscv/kernel/head.S    | 2 ++
> > > >  arch/riscv/kernel/smpboot.c | 2 --
> > > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> > > > index 2363b43312fc..0e1bb97f9749 100644
> > > > --- a/arch/riscv/kernel/head.S
> > > > +++ b/arch/riscv/kernel/head.S
> > > > @@ -10,6 +10,7 @@
> > > >  #include <asm/thread_info.h>
> > > >  #include <asm/page.h>
> > > >  #include <asm/pgtable.h>
> > > > +#include <asm/alternative.h>
> > > >  #include <asm/csr.h>
> > > >  #include <asm/cpu_ops_sbi.h>
> > > >  #include <asm/hwcap.h>
> > > > @@ -341,6 +342,7 @@ clear_bss_done:
> > > >         call kasan_early_init
> > > >  #endif
> > > >         /* Start the kernel */
> > > > +       call apply_boot_alternatives
> > >
> > > Do you really need this early ?
> > > if non-smp configuration is the only option, Can you do it in
> > > setup_arch() after riscv_fill_hwcap() is called ?
> >
> > The issue I see is, we we have the soc_early_init [0] running
> > directly after this and the one user I see [1] already wants to
> > ioremap io-memory at this stage.
> >
> 
> Kendryte is always a special case. IIRC, ioremap is done so early
> so that it can use all 8MB of SRAM.
> 
> > So judging by the fact that more early-inits will get added
> > in the future I do guess we should've set up the io-memory
> > page-type by this point?
> >
> 
> I hope there won't be :). For any normal mmu capable SoC, I don't
> see why that would be required.

ok, so we'll assume there won't be another special-special case SoC
forthcoming and hope for the best - works for me :-D

Thanks
Heiko


> > [0] https://elixir.bootlin.com/linux/latest/source/arch/riscv/kernel/soc.c#L14
> > [1] https://elixir.bootlin.com/linux/latest/source/drivers/soc/canaan/k210-sysctl.c#L66
> >
> > > By doing that, we can unify the cpu feature probing and you don't need
> > > a separate DT parsing just for svpbmt.
> > >
> > > >         call soc_early_init
> > > >         tail start_kernel
> > > >
> > > > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> > > > index a6d13dca1403..f1e4948a4b52 100644
> > > > --- a/arch/riscv/kernel/smpboot.c
> > > > +++ b/arch/riscv/kernel/smpboot.c
> > > > @@ -32,7 +32,6 @@
> > > >  #include <asm/sections.h>
> > > >  #include <asm/sbi.h>
> > > >  #include <asm/smp.h>
> > > > -#include <asm/alternative.h>
> > > >
> > > >  #include "head.h"
> > > >
> > > > @@ -41,7 +40,6 @@ static DECLARE_COMPLETION(cpu_running);
> > > >  void __init smp_prepare_boot_cpu(void)
> > > >  {
> > > >         init_cpu_topology();
> > > > -       apply_boot_alternatives();
> > > >  }
> > > >
> > > >  void __init smp_prepare_cpus(unsigned int max_cpus)
> > > > --
> > > > 2.30.2
> > > >
> > > >
> > > > _______________________________________________
> > > > linux-riscv mailing list
> > > > linux-riscv@lists.infradead.org
> > > > http://lists.infradead.org/mailman/listinfo/linux-riscv
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> 
> 
>
Palmer Dabbelt March 8, 2022, 12:47 a.m. UTC | #5
On Wed, 09 Feb 2022 04:37:54 PST (-0800), heiko@sntech.de wrote:
> Move the application of boot alternatives to soc_early_init().
> This allows to catch more generic cases of code needing patches
> than doing it in smp_prepare_boot_cpu() and also makes it actually
> work if CONFIG_SMP is disabled for whatever reason.
>
> The position is chosen mainly as it is before the actual soc early
> init runs but also already allows accessing the devicetree
> via fdt_* functions.

I think this is OK, but it warrants testing on the K210 -- specifically 
the system is in an odd state before soc_early_init (IIRC some of memory 
doesn't work right) so I'm always a bit worried about calling stuff 
there.  I don't have a K210 (or at least a working one), so I'm not 
going to be able to test it.

> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> ---
>  arch/riscv/kernel/head.S    | 2 ++
>  arch/riscv/kernel/smpboot.c | 2 --
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> index 2363b43312fc..0e1bb97f9749 100644
> --- a/arch/riscv/kernel/head.S
> +++ b/arch/riscv/kernel/head.S
> @@ -10,6 +10,7 @@
>  #include <asm/thread_info.h>
>  #include <asm/page.h>
>  #include <asm/pgtable.h>
> +#include <asm/alternative.h>
>  #include <asm/csr.h>
>  #include <asm/cpu_ops_sbi.h>
>  #include <asm/hwcap.h>
> @@ -341,6 +342,7 @@ clear_bss_done:
>  	call kasan_early_init
>  #endif
>  	/* Start the kernel */
> +	call apply_boot_alternatives
>  	call soc_early_init
>  	tail start_kernel
>
> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> index a6d13dca1403..f1e4948a4b52 100644
> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c
> @@ -32,7 +32,6 @@
>  #include <asm/sections.h>
>  #include <asm/sbi.h>
>  #include <asm/smp.h>
> -#include <asm/alternative.h>
>
>  #include "head.h"
>
> @@ -41,7 +40,6 @@ static DECLARE_COMPLETION(cpu_running);
>  void __init smp_prepare_boot_cpu(void)
>  {
>  	init_cpu_topology();
> -	apply_boot_alternatives();
>  }
>
>  void __init smp_prepare_cpus(unsigned int max_cpus)
Heiko Stübner March 23, 2022, 4:51 p.m. UTC | #6
Am Dienstag, 8. März 2022, 01:47:23 CET schrieb Palmer Dabbelt:
> On Wed, 09 Feb 2022 04:37:54 PST (-0800), heiko@sntech.de wrote:
> > Move the application of boot alternatives to soc_early_init().
> > This allows to catch more generic cases of code needing patches
> > than doing it in smp_prepare_boot_cpu() and also makes it actually
> > work if CONFIG_SMP is disabled for whatever reason.
> >
> > The position is chosen mainly as it is before the actual soc early
> > init runs but also already allows accessing the devicetree
> > via fdt_* functions.
> 
> I think this is OK, but it warrants testing on the K210 -- specifically 
> the system is in an odd state before soc_early_init (IIRC some of memory 
> doesn't work right) so I'm always a bit worried about calling stuff 
> there.  I don't have a K210 (or at least a working one), so I'm not 
> going to be able to test it.

just to finalize this partial thread, v7 and onward doesn't move
the alternative-application this early but instead actually behind
fill_hwcaps to be able to read available extensions.

So nothing to do for this - for people reading along, and me if
I don't remember this in the future ;-)

> > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> > ---
> >  arch/riscv/kernel/head.S    | 2 ++
> >  arch/riscv/kernel/smpboot.c | 2 --
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
> > index 2363b43312fc..0e1bb97f9749 100644
> > --- a/arch/riscv/kernel/head.S
> > +++ b/arch/riscv/kernel/head.S
> > @@ -10,6 +10,7 @@
> >  #include <asm/thread_info.h>
> >  #include <asm/page.h>
> >  #include <asm/pgtable.h>
> > +#include <asm/alternative.h>
> >  #include <asm/csr.h>
> >  #include <asm/cpu_ops_sbi.h>
> >  #include <asm/hwcap.h>
> > @@ -341,6 +342,7 @@ clear_bss_done:
> >  	call kasan_early_init
> >  #endif
> >  	/* Start the kernel */
> > +	call apply_boot_alternatives
> >  	call soc_early_init
> >  	tail start_kernel
> >
> > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> > index a6d13dca1403..f1e4948a4b52 100644
> > --- a/arch/riscv/kernel/smpboot.c
> > +++ b/arch/riscv/kernel/smpboot.c
> > @@ -32,7 +32,6 @@
> >  #include <asm/sections.h>
> >  #include <asm/sbi.h>
> >  #include <asm/smp.h>
> > -#include <asm/alternative.h>
> >
> >  #include "head.h"
> >
> > @@ -41,7 +40,6 @@ static DECLARE_COMPLETION(cpu_running);
> >  void __init smp_prepare_boot_cpu(void)
> >  {
> >  	init_cpu_topology();
> > -	apply_boot_alternatives();
> >  }
> >
> >  void __init smp_prepare_cpus(unsigned int max_cpus)
>
diff mbox series

Patch

diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 2363b43312fc..0e1bb97f9749 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -10,6 +10,7 @@ 
 #include <asm/thread_info.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
+#include <asm/alternative.h>
 #include <asm/csr.h>
 #include <asm/cpu_ops_sbi.h>
 #include <asm/hwcap.h>
@@ -341,6 +342,7 @@  clear_bss_done:
 	call kasan_early_init
 #endif
 	/* Start the kernel */
+	call apply_boot_alternatives
 	call soc_early_init
 	tail start_kernel
 
diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index a6d13dca1403..f1e4948a4b52 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -32,7 +32,6 @@ 
 #include <asm/sections.h>
 #include <asm/sbi.h>
 #include <asm/smp.h>
-#include <asm/alternative.h>
 
 #include "head.h"
 
@@ -41,7 +40,6 @@  static DECLARE_COMPLETION(cpu_running);
 void __init smp_prepare_boot_cpu(void)
 {
 	init_cpu_topology();
-	apply_boot_alternatives();
 }
 
 void __init smp_prepare_cpus(unsigned int max_cpus)