All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Burton <paul.burton@imgtec.com>
To: "Maciej W. Rozycki" <macro@imgtec.com>,
	Fredrik Noring <noring@nocrew.org>
Cc: <linux-mips@linux-mips.org>
Subject: Re: [PATCH v2] MIPS: Add basic R5900 support
Date: Thu, 21 Sep 2017 11:11:45 -0700	[thread overview]
Message-ID: <6075527.JN7xhOrQ8g@np-p-burton> (raw)
In-Reply-To: <alpine.DEB.2.00.1709171001160.16752@tp.orcam.me.uk>

[-- Attachment #1: Type: text/plain, Size: 3408 bytes --]

Hi Maciej/Fredrik,

On Monday, 18 September 2017 10:05:56 PDT Maciej W. Rozycki wrote:
> Hi Fredrik,
> 
> > >  For the initial R5900 support I think there are two options here,
> > > 
> > > depending on what hardware supports:
> > > 
> > > 1. If (for binary compatibility reasons) 128-bit GPR support can somehow
> > > 
> > >    be disabled in hardware, by flipping a CP0 register bit or suchlike,
> > >    then I suggest doing that in the first stage.
> > 
> > Unfortunately I haven't found such a switch. There is also a set of
> > 128-bit
> > multimedia instructions to consider (GCC is perhaps unlikely to generate
> > those but assembly code is an option too).
> 
>  The usual minimal approach is to have compiler intrinsics implemented.
> 
> > > 2. Otherwise I think that the context initialisation/switch code has to
> > > be
> > > 
> > >    adjusted such that the upper GPR halves are set to a known state,
> > >    either zeroed or sign-extended from bit #63 (or #31 really, given the
> > >    initial 32-bit port only) according to hardware requirements, so as
> > >    to
> > >    make execution stable and prevent data from leaking between contexts.
> > > 
> > > Later on proper 128-bit support can be added, though for that to make
> > > sense you need to have compiler support too, which AFAICT is currently
> > > missing.  Myself I'd rather defer commenting on that further support
> > > until
> > > we get to it, although of course someone else might be willing to sketch
> > > an idea.
> > 
> > I have a working 32-bit kernel now, except that BusyBox randomly crashes
> > unless the kernel saves/restores 64-bit GPRs. The executables and
> > libraries
> > declare "ELF 32-bit LSB, MIPS, MIPS-III version 1" so in theory, I
> > suppose,
> > they ought to be 32-bit only. It is possible that the error lies in the
> > kernel handling of the GPRs but I have double-checked this in several
> > ways.
> 
>  Virtually all 64-bit MIPS processors have the CP0.Status.UX bit, which
> the Linux kernel keeps clear for o32 processes (CP0.Status.PX is currently
> unsupported and is kept clear as well), which means that an attempt to use
> any instruction that affects register bits beyond bit #31 will cause a
> Reserved Instruction exception, and in turn SIGILL being sent to the
> program.

This isn't actually true - we currently set ST0_UX unconditionally if the 
kernel is built with CONFIG_64BIT=y. It doesn't matter whether a user program 
is MIPS32 or MIPS64 code, it always runs with UX=1. We also always save all 64 
bits of each GPR - not just the least significant 32 bits when running an o32 
program.

This means 32 bit user code could try using MIPS64 instructions if it wanted 
to, it would just probably be a bad idea.

I think this would be nice to change such that we had UX=PX=0 for o32 
programs, UX=0 PX=1 for n32 programs, UX=1 PX=x for n64 programs, but right 
now we just have UX=1 always for 64 bit kernels.

> > Are there other Linux MIPS implementations that reset GPRs like this?
> 
>  No, because keeping CP0.Status.UX clear guarantees that only instructions
> which sign-extend register results from bit #31 can be used.

I agree that there are no other implementations with this issue - but the 
reason isn't the UX bit, it's that instructions sign extend into wider GPRs 
and the kernel always saves at least as much of a GPR as user code can access.

Thanks,
    Paul

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Paul Burton <paul.burton@imgtec.com>
To: "Maciej W. Rozycki" <macro@imgtec.com>,
	Fredrik Noring <noring@nocrew.org>
Cc: linux-mips@linux-mips.org
Subject: Re: [PATCH v2] MIPS: Add basic R5900 support
Date: Thu, 21 Sep 2017 11:11:45 -0700	[thread overview]
Message-ID: <6075527.JN7xhOrQ8g@np-p-burton> (raw)
Message-ID: <20170921181145.5cynB6tWC1Zmpn9SgXfim-NIffqy95mhkHhQ0-YO5uY@z> (raw)
In-Reply-To: <alpine.DEB.2.00.1709171001160.16752@tp.orcam.me.uk>

[-- Attachment #1: Type: text/plain, Size: 3408 bytes --]

Hi Maciej/Fredrik,

On Monday, 18 September 2017 10:05:56 PDT Maciej W. Rozycki wrote:
> Hi Fredrik,
> 
> > >  For the initial R5900 support I think there are two options here,
> > > 
> > > depending on what hardware supports:
> > > 
> > > 1. If (for binary compatibility reasons) 128-bit GPR support can somehow
> > > 
> > >    be disabled in hardware, by flipping a CP0 register bit or suchlike,
> > >    then I suggest doing that in the first stage.
> > 
> > Unfortunately I haven't found such a switch. There is also a set of
> > 128-bit
> > multimedia instructions to consider (GCC is perhaps unlikely to generate
> > those but assembly code is an option too).
> 
>  The usual minimal approach is to have compiler intrinsics implemented.
> 
> > > 2. Otherwise I think that the context initialisation/switch code has to
> > > be
> > > 
> > >    adjusted such that the upper GPR halves are set to a known state,
> > >    either zeroed or sign-extended from bit #63 (or #31 really, given the
> > >    initial 32-bit port only) according to hardware requirements, so as
> > >    to
> > >    make execution stable and prevent data from leaking between contexts.
> > > 
> > > Later on proper 128-bit support can be added, though for that to make
> > > sense you need to have compiler support too, which AFAICT is currently
> > > missing.  Myself I'd rather defer commenting on that further support
> > > until
> > > we get to it, although of course someone else might be willing to sketch
> > > an idea.
> > 
> > I have a working 32-bit kernel now, except that BusyBox randomly crashes
> > unless the kernel saves/restores 64-bit GPRs. The executables and
> > libraries
> > declare "ELF 32-bit LSB, MIPS, MIPS-III version 1" so in theory, I
> > suppose,
> > they ought to be 32-bit only. It is possible that the error lies in the
> > kernel handling of the GPRs but I have double-checked this in several
> > ways.
> 
>  Virtually all 64-bit MIPS processors have the CP0.Status.UX bit, which
> the Linux kernel keeps clear for o32 processes (CP0.Status.PX is currently
> unsupported and is kept clear as well), which means that an attempt to use
> any instruction that affects register bits beyond bit #31 will cause a
> Reserved Instruction exception, and in turn SIGILL being sent to the
> program.

This isn't actually true - we currently set ST0_UX unconditionally if the 
kernel is built with CONFIG_64BIT=y. It doesn't matter whether a user program 
is MIPS32 or MIPS64 code, it always runs with UX=1. We also always save all 64 
bits of each GPR - not just the least significant 32 bits when running an o32 
program.

This means 32 bit user code could try using MIPS64 instructions if it wanted 
to, it would just probably be a bad idea.

I think this would be nice to change such that we had UX=PX=0 for o32 
programs, UX=0 PX=1 for n32 programs, UX=1 PX=x for n64 programs, but right 
now we just have UX=1 always for 64 bit kernels.

> > Are there other Linux MIPS implementations that reset GPRs like this?
> 
>  No, because keeping CP0.Status.UX clear guarantees that only instructions
> which sign-extend register results from bit #31 can be used.

I agree that there are no other implementations with this issue - but the 
reason isn't the UX bit, it's that instructions sign extend into wider GPRs 
and the kernel always saves at least as much of a GPR as user code can access.

Thanks,
    Paul

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2017-09-21 18:12 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-27 13:23 [PATCH] MIPS: Add basic R5900 support Fredrik Noring
2017-08-28 13:53 ` Ralf Baechle
2017-08-28 17:11   ` Maciej W. Rozycki
2017-08-29 17:33   ` Fredrik Noring
2017-08-29 17:24 ` Maciej W. Rozycki
2017-08-29 17:24   ` Maciej W. Rozycki
2017-08-30 13:23   ` Fredrik Noring
2017-08-31 15:11     ` Maciej W. Rozycki
2017-08-31 15:11       ` Maciej W. Rozycki
2017-09-02 10:28   ` Fredrik Noring
2017-09-09 10:13     ` Maciej W. Rozycki
2017-09-09 10:13       ` Maciej W. Rozycki
2017-09-11  5:21       ` Maciej W. Rozycki
2017-09-11  5:21         ` Maciej W. Rozycki
2017-09-12 17:59         ` Fredrik Noring
2017-09-15 11:12           ` Maciej W. Rozycki
2017-09-15 11:12             ` Maciej W. Rozycki
2017-09-15 13:19             ` Fredrik Noring
2017-09-15 18:28               ` Maciej W. Rozycki
2017-09-15 18:28                 ` Maciej W. Rozycki
2017-09-02 14:10   ` [PATCH v2] " Fredrik Noring
2017-09-11  5:18     ` Maciej W. Rozycki
2017-09-11  5:18       ` Maciej W. Rozycki
2017-09-11 15:17       ` Fredrik Noring
2017-09-14 13:50         ` Maciej W. Rozycki
2017-09-14 13:50           ` Maciej W. Rozycki
2017-09-16 13:34           ` Fredrik Noring
2017-09-18 17:05             ` Maciej W. Rozycki
2017-09-18 17:05               ` Maciej W. Rozycki
2017-09-18 19:24               ` Fredrik Noring
2017-09-19 12:44                 ` Maciej W. Rozycki
2017-09-19 12:44                   ` Maciej W. Rozycki
2017-09-20 14:54                   ` Fredrik Noring
2017-09-26 11:50                     ` Maciej W. Rozycki
2017-09-26 11:50                       ` Maciej W. Rozycki
2017-09-27 17:21                       ` Fredrik Noring
2017-09-28 12:13                         ` Maciej W. Rozycki
2017-09-28 12:13                           ` Maciej W. Rozycki
2017-09-30  6:56                           ` Fredrik Noring
2017-10-02  9:05                             ` Maciej W. Rozycki
2017-10-02  9:05                               ` Maciej W. Rozycki
2017-10-02 16:33                               ` Fredrik Noring
2017-10-29 17:20                               ` Fredrik Noring
2017-11-10 23:34                                 ` Maciej W. Rozycki
2017-11-10 23:34                                   ` Maciej W. Rozycki
2017-11-11 16:04                                   ` Fredrik Noring
2018-01-29 20:27                                     ` Fredrik Noring
2018-01-31 23:01                                       ` Maciej W. Rozycki
2018-02-11  7:29                                         ` [RFC] MIPS: R5900: Workaround for the short loop bug Fredrik Noring
2018-02-12  9:25                                           ` Maciej W. Rozycki
2018-02-12 15:22                                             ` Fredrik Noring
2018-02-11  7:46                                         ` [RFC] MIPS: R5900: Use SYNC.L for data cache and SYNC.P for instruction cache Fredrik Noring
2018-02-11  7:56                                         ` [RFC] MIPS: R5900: Workaround exception NOP execution bug (FLX05) Fredrik Noring
2018-02-12  9:28                                           ` Maciej W. Rozycki
2018-02-15 19:15                                             ` [RFC v2] " Fredrik Noring
2018-02-15 20:49                                               ` Maciej W. Rozycki
2018-02-17 11:16                                                 ` Fredrik Noring
2018-02-17 11:57                                                   ` Maciej W. Rozycki
2018-02-17 13:38                                                     ` Fredrik Noring
2018-02-17 15:03                                                       ` Maciej W. Rozycki
2018-02-17 20:04                                                         ` Fredrik Noring
2018-02-20 14:09                                                           ` Maciej W. Rozycki
2018-02-22 17:04                                                             ` Fredrik Noring
2018-02-18  8:47                                                 ` Fredrik Noring
2018-02-20 14:41                                                   ` Maciej W. Rozycki
2018-02-22 17:27                                                     ` Fredrik Noring
2018-02-11  8:01                                         ` [RFC] MIPS: R5900: Workaround for CACHE instruction near branch delay slot Fredrik Noring
2018-02-11 11:16                                           ` Aw: " "Jürgen Urban"
2018-02-11  8:09                                         ` [RFC] MIPS: R5900: The ERET instruction has issues with delay slot and CACHE Fredrik Noring
2018-02-11 11:07                                           ` Aw: " "Jürgen Urban"
2018-02-11  8:29                                         ` [RFC] MIPS: R5900: Use mandatory SYNC.L in exception handlers Fredrik Noring
2018-02-11 10:33                                           ` Aw: " "Jürgen Urban"
2018-02-12  9:22                                             ` Maciej W. Rozycki
2018-02-12  9:22                                               ` Maciej W. Rozycki
2018-02-18 10:30                                               ` Fredrik Noring
2018-02-17 14:43                                         ` [RFC] MIPS: R5900: Workaround for saving and restoring FPU registers Fredrik Noring
2018-02-17 15:18                                           ` Maciej W. Rozycki
2018-02-17 17:47                                             ` Fredrik Noring
2018-02-17 19:33                                               ` Maciej W. Rozycki
2018-02-18  9:26                                         ` [RFC] MIPS: R5900: Workaround where MSB must be 0 for the instruction cache Fredrik Noring
2018-02-18 11:08                                         ` [RFC] MIPS: R5900: Add mandatory SYNC.P to all M[FT]C0 instructions Fredrik Noring
2018-03-03 12:26                                         ` [RFC] MIPS: PS2: Interrupt request (IRQ) support Fredrik Noring
2018-03-03 13:09                                           ` Maciej W. Rozycki
2018-03-03 14:14                                             ` Fredrik Noring
2018-04-09 15:51                                             ` Fredrik Noring
2018-03-18 10:45                                           ` Fredrik Noring
2018-03-19 19:15                                             ` Thomas Gleixner
2018-06-18 18:52                                             ` [RFC v2] " Fredrik Noring
2017-10-30 17:55                               ` [PATCH v2] MIPS: Add basic R5900 support Fredrik Noring
2017-11-24 10:26                                 ` Maciej W. Rozycki
2017-11-24 10:26                                   ` Maciej W. Rozycki
2017-11-24 10:39                                   ` Maciej W. Rozycki
2017-11-24 10:39                                     ` Maciej W. Rozycki
2017-09-20 14:07               ` Fredrik Noring
2017-09-21 21:07                 ` Maciej W. Rozycki
2017-09-21 21:07                   ` Maciej W. Rozycki
2017-09-22 16:37                   ` Fredrik Noring
2017-09-22 16:37                     ` Fredrik Noring
2017-09-29 23:55                     ` Maciej W. Rozycki
2017-09-29 23:55                       ` Maciej W. Rozycki
2017-09-30 18:26                       ` Fredrik Noring
2017-10-02  9:11                         ` Maciej W. Rozycki
2017-10-02  9:11                           ` Maciej W. Rozycki
2017-10-03 19:49                           ` Fredrik Noring
2017-10-05 19:04                             ` Fredrik Noring
2017-10-06 20:28                           ` Fredrik Noring
2017-10-15 16:39                             ` Fredrik Noring
2017-10-17 12:23                               ` Maciej W. Rozycki
2017-10-17 12:23                                 ` Maciej W. Rozycki
2017-10-21 18:00                                 ` Fredrik Noring
2017-10-23 16:10                                   ` Maciej W. Rozycki
2017-10-23 16:10                                     ` Maciej W. Rozycki
2017-09-21 18:11               ` Paul Burton [this message]
2017-09-21 18:11                 ` Paul Burton
2017-09-21 19:48                 ` Maciej W. Rozycki
2017-09-21 19:48                   ` Maciej W. Rozycki
2017-10-29 18:42       ` Fredrik Noring

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=6075527.JN7xhOrQ8g@np-p-burton \
    --to=paul.burton@imgtec.com \
    --cc=linux-mips@linux-mips.org \
    --cc=macro@imgtec.com \
    --cc=noring@nocrew.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.