diff mbox series

[U-Boot,v1,1/5] ARM: PSCI: initialize stack pointer on secondary CPUs

Message ID 20180624190958.1818-1-stefan@agner.ch
State Accepted
Commit 77fcc2cc901e1886996fda80de464a2372a69124
Delegated to: Stefano Babic
Headers show
Series [U-Boot,v1,1/5] ARM: PSCI: initialize stack pointer on secondary CPUs | expand

Commit Message

Stefan Agner June 24, 2018, 7:09 p.m. UTC
From: Stefan Agner <stefan.agner@toradex.com>

A proper stack is required to safely use C code in psci_arch_cpu_entry.

Fixes: 486daaa618e1 ("arm: psci: add a weak function psci_arch_cpu_entry")
Cc: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
---

 arch/arm/cpu/armv7/psci.S | 2 ++
 1 file changed, 2 insertions(+)

Comments

Stefan Agner June 27, 2018, 8:36 a.m. UTC | #1
On 24.06.2018 21:09, Stefan Agner wrote:
> From: Stefan Agner <stefan.agner@toradex.com>
> 
> A proper stack is required to safely use C code in psci_arch_cpu_entry.

Patrick, I prefer to have your ack on this since you introduced
psci_arch_cpu_entry.

As far as I can tell STM32MP1 uses C code in psci_arch_cpu_entry. The
same function in i.MX 7's PSCI implementation the compiler actually
pushed stuff on the (uninitialized) stack, which caused the newly
brought up CPU to immediately crash.

Not sure if in your case the stack pointer is already setup by some
other means or your compiler does not use the stack.

In any case, I think it is better to just setup the stack properly as
done in this patch...


Stefano, I think we really want patch 2/3 applied before the release
since it fixes i.MX 7 PSCI. Right now the implementation is really
broken and not PSCI 1.0 conformant. But patch 2/3 require this patch to
be applied... Not sure how we should handle this.

--
Stefan

> 
> Fixes: 486daaa618e1 ("arm: psci: add a weak function psci_arch_cpu_entry")
> Cc: Patrick Delaunay <patrick.delaunay@st.com>
> Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
> ---
> 
>  arch/arm/cpu/armv7/psci.S | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/arm/cpu/armv7/psci.S b/arch/arm/cpu/armv7/psci.S
> index 08b5088675..983cd90442 100644
> --- a/arch/arm/cpu/armv7/psci.S
> +++ b/arch/arm/cpu/armv7/psci.S
> @@ -331,6 +331,8 @@ ENTRY(psci_cpu_entry)
>  
>  	bl	_nonsec_init
>  
> +	bl	psci_stack_setup
> +
>  	bl	psci_arch_cpu_entry
>  
>  	bl	psci_get_cpu_id			@ CPU ID => r0
Patrick DELAUNAY July 2, 2018, 9:08 a.m. UTC | #2
Hi Stefan

> From: Stefan Agner [mailto:stefan@agner.ch]
> Sent: mercredi 27 juin 2018 10:36
> Subject: Re: [PATCH v1 1/5] ARM: PSCI: initialize stack pointer on secondary CPUs
> 
> On 24.06.2018 21:09, Stefan Agner wrote:
> > From: Stefan Agner <stefan.agner@toradex.com>
> >
> > A proper stack is required to safely use C code in psci_arch_cpu_entry.
> 
> Patrick, I prefer to have your ack on this since you introduced
> psci_arch_cpu_entry.
> 
> As far as I can tell STM32MP1 uses C code in psci_arch_cpu_entry. The same
> function in i.MX 7's PSCI implementation the compiler actually pushed stuff on
> the (uninitialized) stack, which caused the newly brought up CPU to immediately
> crash.
> 
> Not sure if in your case the stack pointer is already setup by some other means
> or your compiler does not use the stack.
> 
> In any case, I think it is better to just setup the stack properly as done in this
> patch...

I expected that the secure stack is initialized by bootROM, but after check on 2018.07-rc2,
I got a crash also with the stm32mp1 platform.

After code review, my behavior  is clearly not safe: I don't sure that the initial BootROM stack
is not overlapping the installed PSCI monitor code or data.
So I agree:  it is needed to initialize the stack in psci_cpu_entry.

Moreover after your patch the crash is solved for my platform stm32mp1.

> 
> Stefano, I think we really want patch 2/3 applied before the release since it fixes
> i.MX 7 PSCI. Right now the implementation is really broken and not PSCI 1.0
> conformant. But patch 2/3 require this patch to be applied... Not sure how we
> should handle this.
> 
> --
> Stefan

Acked-by: Patrick DELAUNAY <Patrick.delaunay@st.com>
Tested-by: Patrick DELAUNAY <Patrick.delaunay@st.com>

Test done on stm32mp1 platform

Thanks!
Patrick
Stefan Agner July 3, 2018, 12:32 p.m. UTC | #3
Hi Tom, Hi Stefano,

On 02.07.2018 11:08, Patrick DELAUNAY wrote:
> Hi Stefan
> 
>> From: Stefan Agner [mailto:stefan@agner.ch]
>> Sent: mercredi 27 juin 2018 10:36
>> Subject: Re: [PATCH v1 1/5] ARM: PSCI: initialize stack pointer on secondary CPUs
>>
>> On 24.06.2018 21:09, Stefan Agner wrote:
>> > From: Stefan Agner <stefan.agner@toradex.com>
>> >
>> > A proper stack is required to safely use C code in psci_arch_cpu_entry.
>>
>> Patrick, I prefer to have your ack on this since you introduced
>> psci_arch_cpu_entry.
>>
>> As far as I can tell STM32MP1 uses C code in psci_arch_cpu_entry. The same
>> function in i.MX 7's PSCI implementation the compiler actually pushed stuff on
>> the (uninitialized) stack, which caused the newly brought up CPU to immediately
>> crash.
>>
>> Not sure if in your case the stack pointer is already setup by some other means
>> or your compiler does not use the stack.
>>
>> In any case, I think it is better to just setup the stack properly as done in this
>> patch...
> 
> I expected that the secure stack is initialized by bootROM, but after
> check on 2018.07-rc2,
> I got a crash also with the stm32mp1 platform.
> 
> After code review, my behavior  is clearly not safe: I don't sure that
> the initial BootROM stack
> is not overlapping the installed PSCI monitor code or data.
> So I agree:  it is needed to initialize the stack in psci_cpu_entry.
> 
> Moreover after your patch the crash is solved for my platform stm32mp1.

Given that this fixes two platforms I guess it definitely should go into
v2018.07.

Technically, for i.MX 7 only patch 1, 2 and 3 are necessary, but 4 and 5
are fairly straight forward and seem to work fine here.

Patch 1 is generic, so not sure through which trees the patchset should
go...

--
Stefan

> 
>>
>> Stefano, I think we really want patch 2/3 applied before the release since it fixes
>> i.MX 7 PSCI. Right now the implementation is really broken and not PSCI 1.0
>> conformant. But patch 2/3 require this patch to be applied... Not sure how we
>> should handle this.
>>
>> --
>> Stefan
> 
> Acked-by: Patrick DELAUNAY <Patrick.delaunay@st.com>
> Tested-by: Patrick DELAUNAY <Patrick.delaunay@st.com>
> 
> Test done on stm32mp1 platform
> 
> Thanks!
> Patrick
Tom Rini July 3, 2018, 12:41 p.m. UTC | #4
On Tue, Jul 03, 2018 at 02:32:28PM +0200, Stefan Agner wrote:
> Hi Tom, Hi Stefano,
> 
> On 02.07.2018 11:08, Patrick DELAUNAY wrote:
> > Hi Stefan
> > 
> >> From: Stefan Agner [mailto:stefan@agner.ch]
> >> Sent: mercredi 27 juin 2018 10:36
> >> Subject: Re: [PATCH v1 1/5] ARM: PSCI: initialize stack pointer on secondary CPUs
> >>
> >> On 24.06.2018 21:09, Stefan Agner wrote:
> >> > From: Stefan Agner <stefan.agner@toradex.com>
> >> >
> >> > A proper stack is required to safely use C code in psci_arch_cpu_entry.
> >>
> >> Patrick, I prefer to have your ack on this since you introduced
> >> psci_arch_cpu_entry.
> >>
> >> As far as I can tell STM32MP1 uses C code in psci_arch_cpu_entry. The same
> >> function in i.MX 7's PSCI implementation the compiler actually pushed stuff on
> >> the (uninitialized) stack, which caused the newly brought up CPU to immediately
> >> crash.
> >>
> >> Not sure if in your case the stack pointer is already setup by some other means
> >> or your compiler does not use the stack.
> >>
> >> In any case, I think it is better to just setup the stack properly as done in this
> >> patch...
> > 
> > I expected that the secure stack is initialized by bootROM, but after
> > check on 2018.07-rc2,
> > I got a crash also with the stm32mp1 platform.
> > 
> > After code review, my behavior  is clearly not safe: I don't sure that
> > the initial BootROM stack
> > is not overlapping the installed PSCI monitor code or data.
> > So I agree:  it is needed to initialize the stack in psci_cpu_entry.
> > 
> > Moreover after your patch the crash is solved for my platform stm32mp1.
> 
> Given that this fixes two platforms I guess it definitely should go into
> v2018.07.
> 
> Technically, for i.MX 7 only patch 1, 2 and 3 are necessary, but 4 and 5
> are fairly straight forward and seem to work fine here.
> 
> Patch 1 is generic, so not sure through which trees the patchset should
> go...

I'm OK with the series coming in if Stefano is.
Stefano Babic July 23, 2018, 9:24 a.m. UTC | #5
On 03/07/2018 14:32, Stefan Agner wrote:
> Hi Tom, Hi Stefano,
> 
> On 02.07.2018 11:08, Patrick DELAUNAY wrote:
>> Hi Stefan
>>
>>> From: Stefan Agner [mailto:stefan@agner.ch]
>>> Sent: mercredi 27 juin 2018 10:36
>>> Subject: Re: [PATCH v1 1/5] ARM: PSCI: initialize stack pointer on secondary CPUs
>>>
>>> On 24.06.2018 21:09, Stefan Agner wrote:
>>>> From: Stefan Agner <stefan.agner@toradex.com>
>>>>
>>>> A proper stack is required to safely use C code in psci_arch_cpu_entry.
>>>
>>> Patrick, I prefer to have your ack on this since you introduced
>>> psci_arch_cpu_entry.
>>>
>>> As far as I can tell STM32MP1 uses C code in psci_arch_cpu_entry. The same
>>> function in i.MX 7's PSCI implementation the compiler actually pushed stuff on
>>> the (uninitialized) stack, which caused the newly brought up CPU to immediately
>>> crash.
>>>
>>> Not sure if in your case the stack pointer is already setup by some other means
>>> or your compiler does not use the stack.
>>>
>>> In any case, I think it is better to just setup the stack properly as done in this
>>> patch...
>>
>> I expected that the secure stack is initialized by bootROM, but after
>> check on 2018.07-rc2,
>> I got a crash also with the stm32mp1 platform.
>>
>> After code review, my behavior  is clearly not safe: I don't sure that
>> the initial BootROM stack
>> is not overlapping the installed PSCI monitor code or data.
>> So I agree:  it is needed to initialize the stack in psci_cpu_entry.
>>
>> Moreover after your patch the crash is solved for my platform stm32mp1.
> 
> Given that this fixes two platforms I guess it definitely should go into
> v2018.07.
> 
> Technically, for i.MX 7 only patch 1, 2 and 3 are necessary, but 4 and 5
> are fairly straight forward and seem to work fine here.
> 
> Patch 1 is generic, so not sure through which trees the patchset should
> go...


Sorry for late answer, but benner late as never...;-)

I have applied the whole patchset to u-boot-imx. I will push it in a
couple of hours on the server.

Regards,
Stefano
diff mbox series

Patch

diff --git a/arch/arm/cpu/armv7/psci.S b/arch/arm/cpu/armv7/psci.S
index 08b5088675..983cd90442 100644
--- a/arch/arm/cpu/armv7/psci.S
+++ b/arch/arm/cpu/armv7/psci.S
@@ -331,6 +331,8 @@  ENTRY(psci_cpu_entry)
 
 	bl	_nonsec_init
 
+	bl	psci_stack_setup
+
 	bl	psci_arch_cpu_entry
 
 	bl	psci_get_cpu_id			@ CPU ID => r0