linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Albert Cahalan" <acahalan@gmail.com>
To: "Alan Cox" <alan@lxorguk.ukuu.org.uk>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: JIT emulator needs
Date: Sat, 9 Jun 2007 01:17:49 -0400	[thread overview]
Message-ID: <787b0d920706082217m246400edv754ab1e37ca0ec3b@mail.gmail.com> (raw)
In-Reply-To: <20070608121059.4efcd338@the-village.bc.nu>

On 6/8/07, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> > There is an SE Linux execmem restriction that enforces W^X.
>
> This depends on whatever SELinux rulesets you are running. Its just a
> good rule to have present that most programs shouldn't be self patching,
> and then label those that do differently.

A marking in the executable would have made more sense.
It is really broken having an unprivileged user being able to
create whole new executables but unable to lift this restriction
on those executables.

In any case, the restriction is common and troublesome.

> > Sometimes it is very helpful to have the read/write mapping
> > be a fixed offset from the read/exec mapping. A power of 2
> > can be especially desirable.
>
> mmap MAP_FIXED can do this but you need to know a lot about the memory
> layout of the system so it gets a bit platform specific.

Yes. There are unportable programs, and UNPORTABLE ones.
Memory layout can vary between vendor kernels, between normal
and 32-on-64 situations, between two different C libraries...

> > Emulators often need a cheap way to change page permissions.
>
> mprotect(, range) rather than a page at a time. The kernel will do
> merging.

Nope. This can happen rapidly and repeatedly to pages
that are essentially random. The median length of a range
will be a page or two. Merging won't do very much at all.

> > a. sysctl to set IPC_RMID by default
> > b. shmget() flag to set IPC_RMID by default
>
> Use POSIX shared memory

That appears to have the exact same problem.

> > c. open() flag to unlink a file before returning the fd
>
> Is it really that costly to create a blank file, why do you need to do it
> a lot in a JIT ?

This part isn't about cost. It's about not leaving around
debris when the JIT crashes.

> > e. mremap() flag to get a read/write mapping of a read/exec one
> > f. mremap() flag to get a read/exec mapping of a read/write one
> > g. mremap() flag to make the 5th arg (new addr) be the upper limit
>
> This is all mprotect and munmap.

That won't get me a second mapping. Supposing that I had
a second mapping, SE Linux would deny the mprotect.
I'm looking for a mapping that is born executable or a mapping
that is born writable, as needed, so that no transition is needed.

> > h. 6-bit wide mremap() "flag" to set the upper limit above given base
> > i. support the prot argument to remap_file_pages
> > j. a documented way (madvise?) to punch same-VMA zero-page holes
>
> mmap (although you get more VMAs from that) so memset() is probably
> genuinely cheaper if the permissions are not changing.

Well cost is the problem here. I sure can find some way to
get the operation done, but it isn't cheap. For some usages,
the current setup is costly enough that one must consider
abandoning the hardware MMU in favor of a software one
emitted as part of the JIT. :-(

  parent reply	other threads:[~2007-06-09  5:17 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-08  6:35 JIT emulator needs Albert Cahalan
2007-06-08  7:09 ` Eric Dumazet
2007-06-09  4:12   ` Albert Cahalan
2007-06-08 11:10 ` Alan Cox
2007-06-08 16:35   ` Nicholas Miell
2007-06-09  5:17   ` Albert Cahalan [this message]
2007-06-09 20:00 ` H. Peter Anvin
2007-06-19 15:08 ` William Lee Irwin III
2007-06-20  3:16   ` Albert Cahalan
2007-06-20 16:01     ` William Lee Irwin III
2007-06-20 16:37       ` H. Peter Anvin
2007-06-20 17:54         ` William Lee Irwin III
2007-06-20 18:23           ` H. Peter Anvin
2007-06-20 18:25         ` Albert Cahalan
2007-06-20 18:51           ` H. Peter Anvin
2007-06-21  3:21             ` Albert Cahalan
2007-06-21  3:32               ` H. Peter Anvin
2007-06-21  7:38                 ` Albert Cahalan
2007-06-20 18:43       ` Albert Cahalan
2007-06-23  3:52   ` Kyle Moffett
2007-06-24  4:14     ` William Lee Irwin III
2007-06-21 17:44 ` Arjan van de Ven
2007-06-22  5:56   ` Albert Cahalan
2007-06-22 13:43     ` Arjan van de Ven
2007-06-22 14:32       ` Albert Cahalan
2007-06-22 14:42         ` Arjan van de Ven
2007-06-23  2:30           ` Albert Cahalan
     [not found] <8tGiE-2Hv-1@gated-at.bofh.it>
     [not found] ` <8xNvm-2Tw-29@gated-at.bofh.it>
     [not found]   ` <8xYTM-3So-13@gated-at.bofh.it>
2007-06-21 11:08     ` Bodo Eggert

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=787b0d920706082217m246400edv754ab1e37ca0ec3b@mail.gmail.com \
    --to=acahalan@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.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 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).