* [PATCH] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined
@ 2022-09-20 15:29 Yury Norov
2022-09-20 22:20 ` Stephen Rothwell
0 siblings, 1 reply; 3+ messages in thread
From: Yury Norov @ 2022-09-20 15:29 UTC (permalink / raw)
To: linuxppc-dev, linux-kernel, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Alexey Kardashevskiy, Alan Modra, Daniel Axtens
Cc: Stephen Rothwell, Yury Norov
generic_secondary_common_init() calls LOAD_REG_ADDR(r7, nr_cpu_ids)
conditionally on CONFIG_SMP. However, if NR_CPUS == 1, kernel doesn't
use the nr_cpu_ids, and in C code, it's just:
#if NR_CPUS == 1
#define nr_cpu_ids
...
The [1] makes declaration of nr_cpu_ids conditional on NR_CPUS == 1,
and that reveals the issue: compiler can't link the
LOAD_REG_ADDR(r7, nr_cpu_ids) against nonexisting symbol.
Current code looks unsafe for those who build kernel with CONFIG_SMP=y and
NR_CPUS == 1. This is weird configuration, but not disallowed.
Fix the linker error by replacing LOAD_REG_ADDR() with LOAD_REG_IMMEDIATE()
conditionally on NR_CPUS == 1.
The issue was spotted after applying [1], which adds a CONFIG_FORCE_NR_CPUS
option that has the similar effect on nr_cpu_ids. So, in this patch, make
the LOAD_REG() conditional on CONFIG_FORCE_NR_CPUS too.
On top of:
[1] https://lore.kernel.org/lkml/20220905230820.3295223-4-yury.norov@gmail.com/T/#m96ffe122721893471fd3470d911a8f2fad6d03b3
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
arch/powerpc/kernel/head_64.S | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index cf2c08902c05..7cb97881635e 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -400,7 +400,11 @@ generic_secondary_common_init:
#else
LOAD_REG_ADDR(r8, paca_ptrs) /* Load paca_ptrs pointe */
ld r8,0(r8) /* Get base vaddr of array */
+#if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
+ LOAD_REG_IMMEDIATE(r7, NR_CPUS)
+#else
LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */
+#endif
lwz r7,0(r7) /* also the max paca allocated */
li r5,0 /* logical cpu id */
1:
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined
2022-09-20 15:29 [PATCH] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined Yury Norov
@ 2022-09-20 22:20 ` Stephen Rothwell
2022-09-20 22:41 ` Yury Norov
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Rothwell @ 2022-09-20 22:20 UTC (permalink / raw)
To: Yury Norov
Cc: Alexey Kardashevskiy, linux-kernel, Alan Modra, Nicholas Piggin,
linuxppc-dev, Daniel Axtens
[-- Attachment #1: Type: text/plain, Size: 969 bytes --]
Hi Yury,
On Tue, 20 Sep 2022 08:29:35 -0700 Yury Norov <yury.norov@gmail.com> wrote:
>
> diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
> index cf2c08902c05..7cb97881635e 100644
> --- a/arch/powerpc/kernel/head_64.S
> +++ b/arch/powerpc/kernel/head_64.S
> @@ -400,7 +400,11 @@ generic_secondary_common_init:
> #else
> LOAD_REG_ADDR(r8, paca_ptrs) /* Load paca_ptrs pointe */
> ld r8,0(r8) /* Get base vaddr of array */
> +#if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
> + LOAD_REG_IMMEDIATE(r7, NR_CPUS)
> +#else
> LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */
> +#endif
> lwz r7,0(r7) /* also the max paca allocated */
> li r5,0 /* logical cpu id */
> 1:
> --
> 2.34.1
>
I don't know PPC assembly very well, but should the #endif be one line
lower so that the constant is not dereferenced in the non-#else case?
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined
2022-09-20 22:20 ` Stephen Rothwell
@ 2022-09-20 22:41 ` Yury Norov
0 siblings, 0 replies; 3+ messages in thread
From: Yury Norov @ 2022-09-20 22:41 UTC (permalink / raw)
To: Stephen Rothwell
Cc: Alexey Kardashevskiy, linux-kernel, Alan Modra, Nicholas Piggin,
linuxppc-dev, Daniel Axtens
On Wed, Sep 21, 2022 at 08:20:06AM +1000, Stephen Rothwell wrote:
> Hi Yury,
>
> On Tue, 20 Sep 2022 08:29:35 -0700 Yury Norov <yury.norov@gmail.com> wrote:
> >
>
> > diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
> > index cf2c08902c05..7cb97881635e 100644
> > --- a/arch/powerpc/kernel/head_64.S
> > +++ b/arch/powerpc/kernel/head_64.S
> > @@ -400,7 +400,11 @@ generic_secondary_common_init:
> > #else
> > LOAD_REG_ADDR(r8, paca_ptrs) /* Load paca_ptrs pointe */
> > ld r8,0(r8) /* Get base vaddr of array */
> > +#if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS)
> > + LOAD_REG_IMMEDIATE(r7, NR_CPUS)
> > +#else
> > LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */
> > +#endif
> > lwz r7,0(r7) /* also the max paca allocated */
> > li r5,0 /* logical cpu id */
> > 1:
> > --
> > 2.34.1
> >
>
> I don't know PPC assembly very well, but should the #endif be one line
> lower so that the constant is not dereferenced in the non-#else case?
Looks like you're right. Thanks, I'll send a v2.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-20 22:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 15:29 [PATCH] powerpc/64: don't refer nr_cpu_ids in asm code when it's undefined Yury Norov
2022-09-20 22:20 ` Stephen Rothwell
2022-09-20 22:41 ` Yury Norov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).