From: David Daney <ddaney@caviumnetworks.com>
To: Rich Felker <dalias@libc.org>
Cc: David Daney <ddaney.cavm@gmail.com>, <libc-alpha@sourceware.org>,
<linux-kernel@vger.kernel.org>, <linux-mips@linux-mips.org>,
David Daney <david.daney@cavium.com>
Subject: Re: [PATCH resend] MIPS: Allow FPU emulator to use non-stack area.
Date: Mon, 6 Oct 2014 15:17:03 -0700 [thread overview]
Message-ID: <543314DF.20808@caviumnetworks.com> (raw)
In-Reply-To: <20141006215813.GB23797@brightrain.aerifal.cx>
On 10/06/2014 02:58 PM, Rich Felker wrote:
> On Mon, Oct 06, 2014 at 02:45:29PM -0700, David Daney wrote:
>> On 10/06/2014 02:31 PM, Rich Felker wrote:
>>> On Mon, Oct 06, 2014 at 02:18:19PM -0700, David Daney wrote:
>>>>> Userspace should play no part in this; requiring userspace to help
>>>>> make special accomodations for fpu emulation largely defeats the
>>>>> purpose of fpu emulation.
>>>>
>>>> That is certainly one way of looking at it. Really it is opinion,
>>>> rather than fact though.
>>>
>>> It's an opinion, yes, but it has substantial reason behind it.
>>>
>>>> GLibc is full of code (see ld.so) that in earlier incantations of
>>>> Unix/Linux was in kernel space, and was moved to userspace. Given
>>>> that there is a partitioning of code between kernel space and
>>>> userspace, I think it not totally unreasonable to consider doing
>>>> some of this in userspace.
>>>>
>>>> Even on systems with hardware FPU, the architecture specification
>>>> allows for/requires emulation of certain cases (denormals, etc.) So
>>>> it is already a requirement that userspace cooperate by always
>>>> having free space below $SP for use by the kernel. So the current
>>>> situation is that userspace is providing services for the kernel FPU
>>>> emulator.
>>>>
>>>> My suggestion is to change the nature of the way these services are
>>>> provided by the userspace program.
>>>
>>> But this isn't setup by the userspace program. It's setup by the
>>> kernel on program entry. Despite that, though, I think it's an
>>> unnecessary (and undocumented!) constraint; the fact that it requires
>>> the stack to be executable makes it even more harmful and
>>> inappropriate.
>>>
>>
>> The management of the stack is absolutely done by userspace code.
>> Any time you do pthread_create(), userspace code does mmap() to
>> allocate the stack area, it then sets permissions on the area, and
>> then it passes the address of the area to clone().
>
> This is hardly management.
>
>> Furthermore the
>> userspace code has to be very careful in its use of the $sp
>> register, so that it doesn't store data in places that will be
>> used/clobbered by the kernel.
>
> This is not "being careful". The stack pointer can never become
> invalid unless you do wacky things in asm or invoke UB.
>
>> All of this is under the control of the userspace program and done
>> with userspace code.
>
> For the most part it just happens by default. There is no particular
> intentionality needed, and certainly no hideous MIPS-specific hacks
> needed.
>
Yes, it happens by default. But it wasn't magic. It took careful work
by the ABI and toolchain designers to make it work.
>> I appreciate the fact that libc authors might prefer *not* to write
>> more code, but they could, especially if they wanted to add the
>> feature of non-executable stacks to their library implementation.
>
> So your position is that:
It is not really a position that I have. Rather a proposal for one
possible way to make non-executable stacks work on MIPS.
>
> 1. A non-exec-stack system can only run new code produced to do extra
> stuff in userspace.
Any non-executable stack solution for MIPS will require changes to the
toolchain/libc. So it is merely a question of what form the change
should take.
>
> 2. The startup code needs to do special work in userspace on MIPS to
> setup an executable area for fpu emulation.
Yes. Similar to how startup code has to do special work to set up the
TLS areas, and load shared libraries.
>
> 3. Every call to clone/CLONE_VM needs to be accompanied by a call to
> mmap and this new syscall to set the address, and every call to
> SYS_exit needs to be accompanies by a call to munmap for the
> corresponding mapping.
>
No, We don't have to mmap() on each thread creation. Many threads
(perhaps 512) could be handled by a single page, so the normal case
would be a single mmap() for the life of the program.
> This is a huge ill-designed mess.
>
Have you seen the alternatives?
Have you ever wondered why MIPS doesn't have non-executable stack support?
> Rich
>
WARNING: multiple messages have this Message-ID (diff)
From: David Daney <ddaney@caviumnetworks.com>
To: Rich Felker <dalias@libc.org>
Cc: David Daney <ddaney.cavm@gmail.com>,
libc-alpha@sourceware.org, linux-kernel@vger.kernel.org,
linux-mips@linux-mips.org, David Daney <david.daney@cavium.com>
Subject: Re: [PATCH resend] MIPS: Allow FPU emulator to use non-stack area.
Date: Mon, 6 Oct 2014 15:17:03 -0700 [thread overview]
Message-ID: <543314DF.20808@caviumnetworks.com> (raw)
Message-ID: <20141006221703.nM32y5gKIZZb-YKdH0_wsEeld6u-XaPgAvEx1npTENA@z> (raw)
In-Reply-To: <20141006215813.GB23797@brightrain.aerifal.cx>
On 10/06/2014 02:58 PM, Rich Felker wrote:
> On Mon, Oct 06, 2014 at 02:45:29PM -0700, David Daney wrote:
>> On 10/06/2014 02:31 PM, Rich Felker wrote:
>>> On Mon, Oct 06, 2014 at 02:18:19PM -0700, David Daney wrote:
>>>>> Userspace should play no part in this; requiring userspace to help
>>>>> make special accomodations for fpu emulation largely defeats the
>>>>> purpose of fpu emulation.
>>>>
>>>> That is certainly one way of looking at it. Really it is opinion,
>>>> rather than fact though.
>>>
>>> It's an opinion, yes, but it has substantial reason behind it.
>>>
>>>> GLibc is full of code (see ld.so) that in earlier incantations of
>>>> Unix/Linux was in kernel space, and was moved to userspace. Given
>>>> that there is a partitioning of code between kernel space and
>>>> userspace, I think it not totally unreasonable to consider doing
>>>> some of this in userspace.
>>>>
>>>> Even on systems with hardware FPU, the architecture specification
>>>> allows for/requires emulation of certain cases (denormals, etc.) So
>>>> it is already a requirement that userspace cooperate by always
>>>> having free space below $SP for use by the kernel. So the current
>>>> situation is that userspace is providing services for the kernel FPU
>>>> emulator.
>>>>
>>>> My suggestion is to change the nature of the way these services are
>>>> provided by the userspace program.
>>>
>>> But this isn't setup by the userspace program. It's setup by the
>>> kernel on program entry. Despite that, though, I think it's an
>>> unnecessary (and undocumented!) constraint; the fact that it requires
>>> the stack to be executable makes it even more harmful and
>>> inappropriate.
>>>
>>
>> The management of the stack is absolutely done by userspace code.
>> Any time you do pthread_create(), userspace code does mmap() to
>> allocate the stack area, it then sets permissions on the area, and
>> then it passes the address of the area to clone().
>
> This is hardly management.
>
>> Furthermore the
>> userspace code has to be very careful in its use of the $sp
>> register, so that it doesn't store data in places that will be
>> used/clobbered by the kernel.
>
> This is not "being careful". The stack pointer can never become
> invalid unless you do wacky things in asm or invoke UB.
>
>> All of this is under the control of the userspace program and done
>> with userspace code.
>
> For the most part it just happens by default. There is no particular
> intentionality needed, and certainly no hideous MIPS-specific hacks
> needed.
>
Yes, it happens by default. But it wasn't magic. It took careful work
by the ABI and toolchain designers to make it work.
>> I appreciate the fact that libc authors might prefer *not* to write
>> more code, but they could, especially if they wanted to add the
>> feature of non-executable stacks to their library implementation.
>
> So your position is that:
It is not really a position that I have. Rather a proposal for one
possible way to make non-executable stacks work on MIPS.
>
> 1. A non-exec-stack system can only run new code produced to do extra
> stuff in userspace.
Any non-executable stack solution for MIPS will require changes to the
toolchain/libc. So it is merely a question of what form the change
should take.
>
> 2. The startup code needs to do special work in userspace on MIPS to
> setup an executable area for fpu emulation.
Yes. Similar to how startup code has to do special work to set up the
TLS areas, and load shared libraries.
>
> 3. Every call to clone/CLONE_VM needs to be accompanied by a call to
> mmap and this new syscall to set the address, and every call to
> SYS_exit needs to be accompanies by a call to munmap for the
> corresponding mapping.
>
No, We don't have to mmap() on each thread creation. Many threads
(perhaps 512) could be handled by a single page, so the normal case
would be a single mmap() for the life of the program.
> This is a huge ill-designed mess.
>
Have you seen the alternatives?
Have you ever wondered why MIPS doesn't have non-executable stack support?
> Rich
>
next prev parent reply other threads:[~2014-10-06 22:17 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-06 20:23 [PATCH resend] MIPS: Allow FPU emulator to use non-stack area David Daney
2014-10-06 20:54 ` Rich Felker
2014-10-06 21:18 ` David Daney
2014-10-06 21:18 ` David Daney
2014-10-06 21:31 ` Rich Felker
2014-10-06 21:45 ` David Daney
2014-10-06 21:45 ` David Daney
2014-10-06 21:58 ` Rich Felker
2014-10-06 22:17 ` David Daney [this message]
2014-10-06 22:17 ` David Daney
2014-10-06 23:08 ` Rich Felker
2014-10-06 23:38 ` Andy Lutomirski
2014-10-06 23:48 ` David Daney
2014-10-06 23:48 ` David Daney
2014-10-06 23:54 ` Andy Lutomirski
2014-10-07 0:05 ` Rich Felker
2014-10-07 0:11 ` Andrew Pinski
2014-10-07 0:21 ` Rich Felker
2014-10-07 0:28 ` Andrew Pinski
2014-10-07 0:29 ` Andy Lutomirski
2014-10-07 0:32 ` David Daney
2014-10-07 0:33 ` David Daney
2014-10-07 0:33 ` David Daney
2014-10-07 0:48 ` Andy Lutomirski
2014-10-07 0:49 ` Rich Felker
2014-10-07 4:50 ` David Daney
2014-10-07 9:13 ` Matthew Fortune
2014-10-07 9:13 ` Matthew Fortune
2014-10-07 9:13 ` Matthew Fortune
2014-10-07 10:52 ` James Hogan
2014-10-07 11:19 ` Rich Felker
2014-10-07 16:04 ` David Daney
2014-10-07 18:32 ` Leonid Yegoshin
2014-10-07 18:43 ` David Daney
2014-10-07 19:13 ` Leonid Yegoshin
2014-10-07 18:44 ` Andy Lutomirski
2014-10-07 18:50 ` David Daney
2014-10-07 19:09 ` Rich Felker
2014-10-07 19:16 ` Leonid Yegoshin
2014-10-07 19:21 ` Rich Felker
2014-10-07 19:27 ` Leonid Yegoshin
2014-10-07 19:28 ` Andy Lutomirski
2014-10-07 20:03 ` David Daney
2014-10-08 0:22 ` Andy Lutomirski
2014-10-07 19:40 ` Matthew Fortune
2014-10-07 19:40 ` Matthew Fortune
2014-10-07 11:11 ` Rich Felker
2014-10-07 16:08 ` David Daney
2014-10-07 16:08 ` David Daney
2014-10-07 18:16 ` Andy Lutomirski
2014-10-07 23:20 ` Ralf Baechle
2014-10-07 23:59 ` David Daney
2014-10-07 23:59 ` David Daney
2014-10-08 0:18 ` Chuck Ebbert
2014-10-08 0:18 ` Chuck Ebbert
2014-10-08 2:37 ` Rich Felker
2014-10-08 10:31 ` Paul Burton
2014-10-08 10:31 ` Paul Burton
2014-10-07 1:02 ` Kevin D. Kissell
2014-10-07 1:38 ` Rich Felker
2014-10-07 4:32 ` David Daney
2014-10-07 11:53 ` James Hogan
2014-10-07 11:53 ` James Hogan
2014-10-07 12:22 ` James Hogan
2014-10-07 12:22 ` James Hogan
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=543314DF.20808@caviumnetworks.com \
--to=ddaney@caviumnetworks.com \
--cc=dalias@libc.org \
--cc=david.daney@cavium.com \
--cc=ddaney.cavm@gmail.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@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.