Crash when booting RPi2 / bcm2836 with ftrace=function

Matthias Reichl hias at horus.com
Wed Aug 23 10:17:15 PDT 2017


On Wed, Aug 23, 2017 at 12:14:14PM -0400, Steven Rostedt wrote:
> On Wed, 23 Aug 2017 17:42:14 +0200
> Matthias Reichl <hias at horus.com> wrote:
> 
> > I haven't verified it myself but Phil Elwells first analysis here
> > sounds plausible
> > 
> > https://github.com/raspberrypi/linux/issues/2166#issuecomment-323355145
> 
> I noticed this comment:
> 
> "What makes this interesting (and is the reason this doesn't fail
>  normally) is that these functions are all called within kernel_init, so
>  the __ro_after_init attribute shouldn't have caused the variable to be
>  read-only yet."
> 
> When ftrace starts, it needs to set the kernel text to write, and when
> it finishes it sets it back to readonly. But the kernel is not set to
> readonly at boot up.
> 
> Can you test this patch? (Warning, I didn't even compile test it)

Thanks a lot, 4.9.44 and 4.13-rc6 boot up fine with the patch!

If I understand the patch correctly this brings arm rodata handling
in line with x86, so it should be quite safe to use.

Please CC me with the final patch and I'll add my Tested-by.

so long,

Hias

> 
> -- Steve
> 
> diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
> index ad80548..fd75f38 100644
> --- a/arch/arm/mm/init.c
> +++ b/arch/arm/mm/init.c
> @@ -745,19 +745,29 @@ static int __mark_rodata_ro(void *unused)
>  	return 0;
>  }
>  
> +static int kernel_set_to_readonly;
> +
>  void mark_rodata_ro(void)
>  {
> +	kernel_set_to_readonly = 1;
> +
>  	stop_machine(__mark_rodata_ro, NULL, NULL);
>  }
>  
>  void set_kernel_text_rw(void)
>  {
> +	if (!kernel_set_to_readonly)
> +		return;
> +
>  	set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), false,
>  				current->active_mm);
>  }
>  
>  void set_kernel_text_ro(void)
>  {
> +	if (!kernel_set_to_readonly)
> +		return;
> +
>  	set_section_perms(ro_perms, ARRAY_SIZE(ro_perms), true,
>  				current->active_mm);
>  }



More information about the linux-rpi-kernel mailing list