linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address
@ 2022-02-22 15:53 Thomas Bogendoerfer
  2022-02-22 17:04 ` Arnd Bergmann
  2022-03-10 10:46 ` Maciej W. Rozycki
  0 siblings, 2 replies; 5+ messages in thread
From: Thomas Bogendoerfer @ 2022-02-22 15:53 UTC (permalink / raw)
  To: linux-mips, linux-kernel; +Cc: arnd

Address errors have always been treated as unaliged accesses and handled
as such. But address errors are also issued for illegal accesses like
user to kernel space or accesses outside of implemented spaces. This
change implements Linux exception handling for accesses to the illegal
space above the CPU implemented maximum virtual user address and the
MIPS 64bit architecture maximum. With this we can now use a fixed value
for the maximum task size on every MIPS CPU and get a more optimized
access_ok().

Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/kernel/unaligned.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/mips/kernel/unaligned.c b/arch/mips/kernel/unaligned.c
index df4b708c04a9..7b5aba5df02e 100644
--- a/arch/mips/kernel/unaligned.c
+++ b/arch/mips/kernel/unaligned.c
@@ -1480,6 +1480,23 @@ asmlinkage void do_ade(struct pt_regs *regs)
 	prev_state = exception_enter();
 	perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS,
 			1, regs, regs->cp0_badvaddr);
+
+#ifdef CONFIG_64BIT
+	/*
+	 * check, if we are hitting space between CPU implemented maximum
+	 * virtual user address and 64bit maximum virtual user address
+	 * and do exception handling to get EFAULTs for get_user/put_user
+	 */
+	if ((regs->cp0_badvaddr >= (1UL << cpu_vmbits)) &&
+	    (regs->cp0_badvaddr < XKSSEG)) {
+		if (fixup_exception(regs)) {
+			current->thread.cp0_baduaddr = regs->cp0_badvaddr;
+			return;
+		}
+		goto sigbus;
+	}
+#endif
+
 	/*
 	 * Did we catch a fault trying to load an instruction?
 	 */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address
  2022-02-22 15:53 [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address Thomas Bogendoerfer
@ 2022-02-22 17:04 ` Arnd Bergmann
  2022-02-22 19:58   ` Thomas Bogendoerfer
  2022-03-10 10:46 ` Maciej W. Rozycki
  1 sibling, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2022-02-22 17:04 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, Linux Kernel Mailing List

On Tue, Feb 22, 2022 at 4:53 PM Thomas Bogendoerfer
<tsbogend@alpha.franken.de> wrote:
>
> Address errors have always been treated as unaliged accesses and handled
> as such. But address errors are also issued for illegal accesses like
> user to kernel space or accesses outside of implemented spaces. This
> change implements Linux exception handling for accesses to the illegal
> space above the CPU implemented maximum virtual user address and the
> MIPS 64bit architecture maximum. With this we can now use a fixed value
> for the maximum task size on every MIPS CPU and get a more optimized
> access_ok().
>
> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

Thank you for addressing this. Should I add this patch to my series
ahead of "mips: use simpler access_ok()"? That way I can keep it all
in my asm-generic tree as a series for 5.18.

>  arch/mips/kernel/unaligned.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>
> diff --git a/arch/mips/kernel/unaligned.c b/arch/mips/kernel/unaligned.c
> index df4b708c04a9..7b5aba5df02e 100644
> --- a/arch/mips/kernel/unaligned.c
> +++ b/arch/mips/kernel/unaligned.c
> @@ -1480,6 +1480,23 @@ asmlinkage void do_ade(struct pt_regs *regs)
>         prev_state = exception_enter();
>         perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS,
>                         1, regs, regs->cp0_badvaddr);
> +
> +#ifdef CONFIG_64BIT
> +       /*
> +        * check, if we are hitting space between CPU implemented maximum
> +        * virtual user address and 64bit maximum virtual user address
> +        * and do exception handling to get EFAULTs for get_user/put_user
> +        */
> +       if ((regs->cp0_badvaddr >= (1UL << cpu_vmbits)) &&
> +           (regs->cp0_badvaddr < XKSSEG)) {

It might be clearer to use TASK_SIZE_MAX here instead of XKSSEG,
to match the check in access_ok(). If you like, I can change that while
applying.

        Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address
  2022-02-22 17:04 ` Arnd Bergmann
@ 2022-02-22 19:58   ` Thomas Bogendoerfer
  2022-02-22 21:42     ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Bogendoerfer @ 2022-02-22 19:58 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-mips, Linux Kernel Mailing List

On Tue, Feb 22, 2022 at 06:04:07PM +0100, Arnd Bergmann wrote:
> On Tue, Feb 22, 2022 at 4:53 PM Thomas Bogendoerfer
> <tsbogend@alpha.franken.de> wrote:
> >
> > Address errors have always been treated as unaliged accesses and handled
> > as such. But address errors are also issued for illegal accesses like
> > user to kernel space or accesses outside of implemented spaces. This
> > change implements Linux exception handling for accesses to the illegal
> > space above the CPU implemented maximum virtual user address and the
> > MIPS 64bit architecture maximum. With this we can now use a fixed value
> > for the maximum task size on every MIPS CPU and get a more optimized
> > access_ok().
> >
> > Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> 
> Thank you for addressing this. Should I add this patch to my series
> ahead of "mips: use simpler access_ok()"? That way I can keep it all
> in my asm-generic tree as a series for 5.18.

yes please add it to your series.

> >  arch/mips/kernel/unaligned.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> >
> > diff --git a/arch/mips/kernel/unaligned.c b/arch/mips/kernel/unaligned.c
> > index df4b708c04a9..7b5aba5df02e 100644
> > --- a/arch/mips/kernel/unaligned.c
> > +++ b/arch/mips/kernel/unaligned.c
> > @@ -1480,6 +1480,23 @@ asmlinkage void do_ade(struct pt_regs *regs)
> >         prev_state = exception_enter();
> >         perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS,
> >                         1, regs, regs->cp0_badvaddr);
> > +
> > +#ifdef CONFIG_64BIT
> > +       /*
> > +        * check, if we are hitting space between CPU implemented maximum
> > +        * virtual user address and 64bit maximum virtual user address
> > +        * and do exception handling to get EFAULTs for get_user/put_user
> > +        */
> > +       if ((regs->cp0_badvaddr >= (1UL << cpu_vmbits)) &&
> > +           (regs->cp0_badvaddr < XKSSEG)) {
> 
> It might be clearer to use TASK_SIZE_MAX here instead of XKSSEG,
> to match the check in access_ok(). If you like, I can change that while
> applying.

I had TASK_SIZE_MAX in an intermediate version, but decided to go with XKSSEG,
because it's what this check is about. It's about checking what the MIPS
architecture defined.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address
  2022-02-22 19:58   ` Thomas Bogendoerfer
@ 2022-02-22 21:42     ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2022-02-22 21:42 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, Linux Kernel Mailing List

On Tue, Feb 22, 2022 at 8:58 PM Thomas Bogendoerfer
<tsbogend@alpha.franken.de> wrote:
>
> On Tue, Feb 22, 2022 at 06:04:07PM +0100, Arnd Bergmann wrote:
> > On Tue, Feb 22, 2022 at 4:53 PM Thomas Bogendoerfer
> > <tsbogend@alpha.franken.de> wrote:
> > >
> > > Address errors have always been treated as unaliged accesses and handled
> > > as such. But address errors are also issued for illegal accesses like
> > > user to kernel space or accesses outside of implemented spaces. This
> > > change implements Linux exception handling for accesses to the illegal
> > > space above the CPU implemented maximum virtual user address and the
> > > MIPS 64bit architecture maximum. With this we can now use a fixed value
> > > for the maximum task size on every MIPS CPU and get a more optimized
> > > access_ok().
> > >
> > > Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> >
> > Thank you for addressing this. Should I add this patch to my series
> > ahead of "mips: use simpler access_ok()"? That way I can keep it all
> > in my asm-generic tree as a series for 5.18.
>
> yes please add it to your series.

Done now.

> >
> > It might be clearer to use TASK_SIZE_MAX here instead of XKSSEG,
> > to match the check in access_ok(). If you like, I can change that while
> > applying.
>
> I had TASK_SIZE_MAX in an intermediate version, but decided to go with XKSSEG,
> because it's what this check is about. It's about checking what the MIPS
> architecture defined.

Right, makes sense.

Thanks,

        Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address
  2022-02-22 15:53 [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address Thomas Bogendoerfer
  2022-02-22 17:04 ` Arnd Bergmann
@ 2022-03-10 10:46 ` Maciej W. Rozycki
  1 sibling, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2022-03-10 10:46 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, arnd

On Tue, 22 Feb 2022, Thomas Bogendoerfer wrote:

> Address errors have always been treated as unaliged accesses and handled
> as such. But address errors are also issued for illegal accesses like
> user to kernel space or accesses outside of implemented spaces. This
> change implements Linux exception handling for accesses to the illegal
> space above the CPU implemented maximum virtual user address and the
> MIPS 64bit architecture maximum. With this we can now use a fixed value
> for the maximum task size on every MIPS CPU and get a more optimized
> access_ok().

 Decades ago I had a patch to handle this with CPU-specific limits, which 
in the end I have not submitted for one reason or another.  I guess we 
didn't have what is `cpu_vmbits' nowadays.  I'll see if I can dig it out 
and check if there's anything interesting there we might also require.

 Overall good work, and I'm rather embarassed we have gone so far without 
it.  Thanks!

  Maciej

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-10 10:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 15:53 [PATCH] MIPS: Handle address errors for accesses above CPU max virtual user address Thomas Bogendoerfer
2022-02-22 17:04 ` Arnd Bergmann
2022-02-22 19:58   ` Thomas Bogendoerfer
2022-02-22 21:42     ` Arnd Bergmann
2022-03-10 10:46 ` Maciej W. Rozycki

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).