From: Andrew Donnellan <ajd@linux.ibm.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Cc: "linux-hardening@vger.kernel.org"
<linux-hardening@vger.kernel.org>,
"cmr@bluescreens.de" <cmr@bluescreens.de>,
"ruscur@russell.cc" <ruscur@russell.cc>
Subject: Re: [RFC PATCH 1/6] powerpc/64s: Fix assembly to support larger values of THREAD_SIZE
Date: Wed, 26 Apr 2023 17:03:28 +1000 [thread overview]
Message-ID: <3963fc4a8a27c1cd03b1ba3d0b23f6adc843214d.camel@linux.ibm.com> (raw)
In-Reply-To: <204dee71-e3c3-e974-e8b4-ee6015cc7e3b@csgroup.eu>
On Fri, 2022-11-04 at 17:51 +0000, Christophe Leroy wrote:
>
>
> Le 04/11/2022 à 18:27, Andrew Donnellan a écrit :
> > When CONFIG_VMAP_STACK is enabled, we set THREAD_SIZE to be at
> > least the
> > size of a page.
> >
> > There's a few bits of assembly in the book3s64 code that use
> > THREAD_SIZE in
> > immediate mode instructions, which can only take an operand of up
> > to 16
> > bits signed, which isn't quite large enough.
> >
> > Fix these spots to use a scratch register or use two immediate mode
> > instructions instead, so we can later enable VMAP_STACK.
> >
> > Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
> > ---
> > arch/powerpc/include/asm/asm-compat.h | 2 ++
> > arch/powerpc/kernel/entry_64.S | 4 +++-
> > arch/powerpc/kernel/irq.c | 8 ++++++--
> > arch/powerpc/kernel/misc_64.S | 4 +++-
> > arch/powerpc/kvm/book3s_hv_rmhandlers.S | 3 ++-
> > 5 files changed, 16 insertions(+), 5 deletions(-)
> >
> > diff --git a/arch/powerpc/include/asm/asm-compat.h
> > b/arch/powerpc/include/asm/asm-compat.h
> > index 2bc53c646ccd..30dd7813bf3b 100644
> > --- a/arch/powerpc/include/asm/asm-compat.h
> > +++ b/arch/powerpc/include/asm/asm-compat.h
> > @@ -11,6 +11,7 @@
> > #define PPC_LL stringify_in_c(ld)
> > #define PPC_STL stringify_in_c(std)
> > #define PPC_STLU stringify_in_c(stdu)
> > +#define PPC_STLUX stringify_in_c(stdux)
> > #define PPC_LCMPI stringify_in_c(cmpdi)
> > #define PPC_LCMPLI stringify_in_c(cmpldi)
> > #define PPC_LCMP stringify_in_c(cmpd)
> > @@ -45,6 +46,7 @@
> > #define PPC_LL stringify_in_c(lwz)
> > #define PPC_STL stringify_in_c(stw)
> > #define PPC_STLU stringify_in_c(stwu)
> > +#define PPC_STLUX stringify_in_c(stwux)
> > #define PPC_LCMPI stringify_in_c(cmpwi)
> > #define PPC_LCMPLI stringify_in_c(cmplwi)
> > #define PPC_LCMP stringify_in_c(cmpw)
> > diff --git a/arch/powerpc/kernel/entry_64.S
> > b/arch/powerpc/kernel/entry_64.S
> > index 3e2e37e6ecab..af25db6e0205 100644
> > --- a/arch/powerpc/kernel/entry_64.S
> > +++ b/arch/powerpc/kernel/entry_64.S
> > @@ -238,7 +238,9 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
> > /* Note: this uses SWITCH_FRAME_SIZE rather than
> > INT_FRAME_SIZE
> > because we don't need to leave the 288-byte ABI gap at
> > the
> > top of the kernel stack. */
> > - addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
> > + li r9,0
> > + ori r9,r9,THREAD_SIZE-SWITCH_FRAME_SIZE
> > + add r7,r7,r9
>
> So you assume THREAD_SIZE is never more than 64k ? Is that a valid
> assumption ?
It looks like PPC_PAGE_SHIFT can be up to 18, which would make
THREAD_SIZE 256K, but that's only if you have 256K pages, which is a
44x specific feature. Otherwise AFAICT you can't get THREAD_SHIFT
larger than 16 and therefore THREAD_SIZE <= 64K.
>
> What about the below instead:
>
> addis r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE@ha
> addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE@l
That looks better anyway, thanks.
>
> >
> > /*
> > * PMU interrupts in radix may come in here. They will use
> > r1, not
> > diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
> > index 9ede61a5a469..098cf6adceec 100644
> > --- a/arch/powerpc/kernel/irq.c
> > +++ b/arch/powerpc/kernel/irq.c
> > @@ -204,7 +204,9 @@ static __always_inline void
> > call_do_softirq(const void *sp)
> > {
> > /* Temporarily switch r1 to sp, call __do_softirq() then
> > restore r1. */
> > asm volatile (
> > - PPC_STLU " %%r1, %[offset](%[sp]) ;"
> > + "li %%r0, 0 ;"
> > + "ori %%r0, %%r0, %[offset] ;"
>
> Same, you assume offset to be max 64k, is that correct ?
>
> What about
> lis r0, offset@h
> ori r0, r0, offset@l
>
> > + PPC_STLUX " %%r1, %[sp], %%r0 ;"
> > "mr %%r1, %[sp] ;"
> > "bl %[callee] ;"
> > PPC_LL " %%r1, 0(%%r1) ;"
> > @@ -256,7 +258,9 @@ static __always_inline void call_do_irq(struct
> > pt_regs *regs, void *sp)
> >
> > /* Temporarily switch r1 to sp, call __do_irq() then
> > restore r1. */
> > asm volatile (
> > - PPC_STLU " %%r1, %[offset](%[sp]) ;"
> > + "li %%r0, 0 ;"
> > + "ori %%r0, %%r0, %[offset] ;"
> > + PPC_STLUX " %%r1, %[sp], %%r0 ;"
>
> Same
>
> > "mr %%r4, %%r1 ;"
> > "mr %%r1, %[sp] ;"
> > "bl %[callee] ;"
> > diff --git a/arch/powerpc/kernel/misc_64.S
> > b/arch/powerpc/kernel/misc_64.S
> > index 36184cada00b..ff71b98500a3 100644
> > --- a/arch/powerpc/kernel/misc_64.S
> > +++ b/arch/powerpc/kernel/misc_64.S
> > @@ -384,7 +384,9 @@ _GLOBAL(kexec_sequence)
> > std r0,16(r1)
> >
> > /* switch stacks to newstack -- &kexec_stack.stack */
> > - stdu r1,THREAD_SIZE-STACK_FRAME_OVERHEAD(r3)
> > + li r0,0
> > + ori r0,r0,THREAD_SIZE-STACK_FRAME_OVERHEAD
> > + stdux r1,r3,r0
>
> Same
>
> > mr r1,r3
> >
> > li r0,0
> > diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> > b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> > index 37f50861dd98..d05e3d324f4d 100644
> > --- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> > +++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
> > @@ -2686,7 +2686,8 @@ kvmppc_bad_host_intr:
> > mr r9, r1
> > std r1, PACAR1(r13)
> > ld r1, PACAEMERGSP(r13)
> > - subi r1, r1, THREAD_SIZE/2 + INT_FRAME_SIZE
> > + subi r1, r1, THREAD_SIZE/2
> > + subi r1, r1, INT_FRAME_SIZE
>
> Same, what about
>
> subis r1, r1, THREAD_SIZE/2 + INT_FRAME_SIZE@ha
> subi r1, r1, THREAD_SIZE/2 + INT_FRAME_SIZE@l
>
> > std r9, 0(r1)
> > std r0, GPR0(r1)
> > std r9, GPR1(r1)
--
Andrew Donnellan OzLabs, ADL Canberra
ajd@linux.ibm.com IBM Australia Limited
next prev parent reply other threads:[~2023-04-26 7:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-04 17:27 [RFC PATCH 0/6] VMAP_STACK support for book3s64 Andrew Donnellan
2022-11-04 17:27 ` [RFC PATCH 1/6] powerpc/64s: Fix assembly to support larger values of THREAD_SIZE Andrew Donnellan
2022-11-04 17:51 ` Christophe Leroy
2023-04-26 7:03 ` Andrew Donnellan [this message]
2022-11-04 17:27 ` [RFC PATCH 2/6] powerpc/64s: Helpers to switch between linear and vmapped stack pointers Andrew Donnellan
2022-11-05 8:00 ` Christophe Leroy
2022-11-05 19:28 ` Christophe Leroy
2022-11-07 12:38 ` Nicholas Piggin
2022-11-04 17:27 ` [RFC PATCH 3/6] powerpc/powernv: Keep MSR in register across OPAL entry/return path Andrew Donnellan
2022-11-04 18:00 ` Christophe Leroy
2022-11-04 17:27 ` [RFC PATCH 4/6] powerpc/powernv: Convert pointers to physical addresses in OPAL call args Andrew Donnellan
2022-11-07 0:00 ` Russell Currey
2022-11-08 16:21 ` Christophe Leroy
2022-11-04 17:27 ` [RFC PATCH 5/6] powerpc/powernv/idle: Convert stack pointer to physical address Andrew Donnellan
2022-11-08 16:17 ` Christophe Leroy
2022-11-04 17:27 ` [RFC PATCH 6/6] powerpc/64s: Enable CONFIG_VMAP_STACK Andrew Donnellan
2022-11-05 17:07 ` Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3963fc4a8a27c1cd03b1ba3d0b23f6adc843214d.camel@linux.ibm.com \
--to=ajd@linux.ibm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=cmr@bluescreens.de \
--cc=linux-hardening@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=ruscur@russell.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).