All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@linux-mips.org>
To: Rich Felker <dalias@libc.org>
Cc: Andy Lutomirski <luto@kernel.org>,
	Linux MIPS Mailing List <linux-mips@linux-mips.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Paul Burton <paul.burton@imgtec.com>,
	David Daney <david.daney@cavium.com>,
	Ralf Baechle <ralf@linux-mips.org>,
	Paul Burton <paul.burton@mips.com>,
	James Hogan <jhogan@kernel.org>
Subject: Re: Fixing MIPS delay slot emulation weakness?
Date: Sun, 16 Dec 2018 13:50:13 +0000 (GMT)	[thread overview]
Message-ID: <alpine.LFD.2.21.1812160319120.11202@eddie.linux-mips.org> (raw)
In-Reply-To: <20181216023259.GE23599@brightrain.aerifal.cx>

On Sat, 15 Dec 2018, Rich Felker wrote:

> >  I think "trivial" is an understatement, you at least need to decode the 
> > delay-slot instruction enough to tell privileged and user instructions 
> > apart and send SIGILL where appropriate.  Some user instructions send 
> > exceptions too and you need to handle them accordingly.
> 
> I meant simply that making them safe is trivial if they're not
> accessing memory, only modifying the regisster file in the signal
> context. Not that emulating them is trivial.

 OK, fair enough.

> On the other hand it might be cleaner, safer, and easier to simply
> write a full mips ISA emulator, put it in the vdso, and have the
> kernel immediately return-to-userspace on hitting floating point
> instructions and let the emulator code there take care of it all and
> then return to the normal flow of execution.

 The problem is matching hardware being run on and then maintaining that 
stuff.  I'd call that a maintenance nightmare, I'm afraid.  See what pain 
we have to go through already to get FPU emulation right, and there's much 
less variation.

> >  OTOH, for things like ADDIUPC you need to interpret the instruction 
> > anyway, as the value of the PC used for calculation will be wrong except 
> > in the original location.
> 
> Indeed. Assuming arbitrary ISA extensions including stuff that does
> PC-relative arithmetic, there's no way to execute it out-of-place
> without knowing how to interpret it.

 Well, ADDIUPC is a standard microMIPS instruction.  Then R6 has more 
stuff like that in the regular MIPS instruction set, e.g. AUIPC, LWPC.

> >  What about all the odd and especially vendor-specific load/store 
> > instructions like ASET, SAA or SWAPW?  Would we need to have all the 
> > possible encodings provided in the VDSO?
> 
> Can all kinds of weird stuff like this go in delay slots? I'm more
> familiar with SH delay slots where lots of instructions are
> slot-illegal. If so perhaps the full-emulator-in-userspace approach is
> better.

 I've double-checked and ASET is actually not allowed in a delay slot, 
because it uses multiple bus cycles for data access.  This is also why 
LWP, LWM, etc. are not allowed either.  Also control transfer instructions 
are not allowed (unlike with SPARC), such as branches, ERET or YIELD (not 
that the two latter instructions matter for us).  Most of stuff is allowed 
in delay slots though.

 It doesn't help that information about that is scattered across many 
documents.  You can check for the NODS flag in the opcodes library from 
binutils though, which is almost 100% accurate, except for the SYNC 
instructions, for semantic reasons (i.e. they are allowed, but we don't 
want GAS to reorder them).  Most of the disallowed stuff is in the 
microMIPS instruction set, due to encodings that execute as hardware 
macros.

  Maciej

  reply	other threads:[~2018-12-16 13:50 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-15 19:19 Fixing MIPS delay slot emulation weakness? Andy Lutomirski
2018-12-15 21:26 ` Paul Burton
2018-12-16 18:11   ` Rich Felker
2018-12-16 18:55   ` Andy Lutomirski
2018-12-15 22:50 ` Rich Felker
2018-12-16  2:15   ` Maciej W. Rozycki
2018-12-16  2:32     ` Rich Felker
2018-12-16 13:50       ` Maciej W. Rozycki [this message]
2018-12-16 18:13         ` Rich Felker
2018-12-16 18:59           ` Andy Lutomirski
2018-12-16 19:45             ` Maciej W. Rozycki
2018-12-17  0:59             ` Rich Felker
2018-12-17  1:55               ` Maciej W. Rozycki
2018-12-18  1:13                 ` Aaro Koskinen
2018-12-19  4:32 ` Paul Burton
2018-12-19 21:12   ` Hugh Dickins
2018-12-20 17:56     ` Paul Burton
2018-12-20 17:45 ` [PATCH] MIPS: math-emu: Write-protect delay slot emulation pages Paul Burton
     [not found]   ` <20181220192616.42976218FE@mail.kernel.org>
2018-12-21 21:16     ` Paul Burton
2018-12-22 19:16       ` Sasha Levin
2018-12-23 16:16   ` Paul Burton

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=alpine.LFD.2.21.1812160319120.11202@eddie.linux-mips.org \
    --to=macro@linux-mips.org \
    --cc=dalias@libc.org \
    --cc=david.daney@cavium.com \
    --cc=jhogan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=luto@kernel.org \
    --cc=paul.burton@imgtec.com \
    --cc=paul.burton@mips.com \
    --cc=ralf@linux-mips.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.