From: Ingo Molnar <mingo@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
Oleg Nesterov <oleg@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>, Brian Gerst <brgerst@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: Rethinking sigcontext's xfeatures slightly for PKRU's benefit?
Date: Fri, 18 Dec 2015 09:32:36 +0100 [thread overview]
Message-ID: <20151218083236.GA29790@gmail.com> (raw)
In-Reply-To: <CALCETrWMofAX8TbZNyPaCWUHqcE85wpehDR05irEPtTYiVMXRA@mail.gmail.com>
* Andy Lutomirski <luto@amacapital.net> wrote:
> > >> But what about the register state when delivering a signal? Don't we
> > >> set the registers to the init state? Do we need to preserve PKRU state
> > >> instead of init'ing it? The init state _is_ nice here because it is
> > >> permissive allows us to do something useful no matter what PKRU gets set to.
> > >
> > > I think we leave the extended regs alone. Don't we?
> > >
> > > I think that, for most signals, we want to leave PKRU as is,
> > > especially for things that aren't SIGSEGV. For SIGSEGV, maybe we want
> > > an option to reset PKRU on delivery (and then set the flag to restore
> > > on return?).
> >
> > Is there some precedent for doing the state differently for different
> > signals?
>
> Yes, to a very limited extent: SA_ONSTACK.
>
> >
> > >> Well, the signal handler isn't necessarily going to clobber it, but the
> > >> delivery code already clobbers it when going to the init state.
> > >
> > > Can you point to that code?
> >
> > handle_signal() -> fpu__clear()
> >
> > The comment around it says:
> >
> > "Ensure the signal handler starts with the new fpu state."
> >
>
> You win this round :)
>
> So maybe we should have a mask of xfeatures that aren't cleared on
> signal delivery (e.g. PKRU, perhaps) and that are, by default,
> preserved across signal returns.
So the principle is this: signals are conceptually like creating a new thread of
execution, and that's a very powerful programming concept, like fork() or
pthread_create() are powerful concepts. So we definitely want to keep that default
behavior, and I don't think we want to deviate from that for typical new extended
CPU context features, even if signal delivery slows down as a result.
But we've been arguing about 'lightweight signals' for up to two decades that I
can remember. (The first such suggestion was to not save the FPU state, back when
FPU saves were ridiculously slow compared to other parts of saving/restoring a
context.)
So having a well-enumerated, extensible opt-in mask (which defaults to 'all state
saved') that allows smart signal handlers to skip the save/restore of certain CPU
context components would be acceptable I think.
But I'd still expect this to be limited to closely coded, specialistic signal
handlers - as the trend goes against such type of specialization: compilers and
runtime environments do take advantage of new CPU features so if you want to have
an 'easy to use' signal handler, you should use the default one.
I'd not be surprised if large-scale signal users like Valgrind could benefit.
> > I'm sure we can preserve it, we just need to be _careful_.
>
> Right.
>
> How much does XSAVEOPT help here? IOW if we're careful to save to the same
> place we restored from and we don't modify the state in the mean time, how much
> of the time do we save? In the best case, I guess we save the memory writes but
> not the reads?
So I'd not design new signal interfaces around current behavior, I'd design them
for the existing patterns (which center around programming ease of use) - with
opt-in, performance-enhancing specializations.
Thanks,
Ingo
next prev parent reply other threads:[~2015-12-18 8:32 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-18 1:48 Rethinking sigcontext's xfeatures slightly for PKRU's benefit? Andy Lutomirski
2015-12-18 2:13 ` Dave Hansen
2015-12-18 2:32 ` Andy Lutomirski
2015-12-18 2:52 ` Dave Hansen
2015-12-18 5:29 ` Andy Lutomirski
2015-12-18 6:43 ` H. Peter Anvin
2015-12-18 16:04 ` Andy Lutomirski
2015-12-18 16:56 ` Dave Hansen
2015-12-18 18:42 ` Dave Hansen
2015-12-18 19:21 ` Andy Lutomirski
2015-12-18 20:07 ` Dave Hansen
2015-12-18 20:28 ` Andy Lutomirski
2015-12-18 20:37 ` Linus Torvalds
2015-12-18 20:49 ` Andy Lutomirski
2015-12-18 20:58 ` H. Peter Anvin
2015-12-18 21:02 ` Andy Lutomirski
2015-12-18 21:08 ` Dave Hansen
2015-12-18 21:04 ` Linus Torvalds
2015-12-18 21:09 ` Linus Torvalds
2015-12-18 21:12 ` Dave Hansen
2015-12-18 21:45 ` Linus Torvalds
2015-12-18 22:28 ` Andy Lutomirski
2015-12-18 23:08 ` Linus Torvalds
2015-12-18 23:16 ` Andy Lutomirski
2015-12-18 23:20 ` Linus Torvalds
2015-12-21 17:04 ` Dave Hansen
2015-12-21 22:52 ` Andy Lutomirski
2015-12-21 23:00 ` Dave Hansen
2015-12-21 23:02 ` Andy Lutomirski
2015-12-21 23:05 ` Dave Hansen
2015-12-21 23:04 ` Dave Hansen
2015-12-21 23:07 ` Andy Lutomirski
2016-06-30 17:36 ` Andy Lutomirski
2016-06-30 21:25 ` Dave Hansen
2016-07-01 16:30 ` Andy Lutomirski
2015-12-29 23:48 ` Dave Hansen
2015-12-18 8:32 ` Ingo Molnar [this message]
2015-12-18 8:59 ` Christoph Hellwig
2015-12-18 12:57 ` Borislav Petkov
2016-01-12 13:38 ` Ingo Molnar
2016-01-12 13:42 ` Christoph Hellwig
2016-01-13 10:48 ` Ingo Molnar
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=20151218083236.GA29790@gmail.com \
--to=mingo@kernel.org \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=oleg@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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