linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Keno Fischer <keno@juliacomputing.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Andi Kleen <andi@firstfloor.org>, Kyle Huey <khuey@kylehuey.com>,
	Robert O'Callahan <robert@ocallahan.org>
Subject: Re: [RFC PATCH v2] x86/arch_prctl: Add ARCH_SET_XCR0 to set XCR0 per-thread
Date: Tue, 7 Apr 2020 13:21:34 -0700	[thread overview]
Message-ID: <9921cb2e-a7cb-c1d0-b120-c08f06be7c7f@intel.com> (raw)
In-Reply-To: <CABV8kRzfR32+MpAvTAPHCN902WtHSxySujcO2yAB3OT0caVDJg@mail.gmail.com>

On 4/7/20 10:55 AM, Keno Fischer wrote:
> On Tue, Apr 7, 2020 at 12:27 PM Dave Hansen <dave.hansen@intel.com> wrote:
>>
>>>> How does this work with things like xstateregs_[gs]et() where the format
>>>> of the kernel buffer and thus the kernel XCR0 is exposed as part of our
>>>> ABI?  With this patch, wouldn't a debugger app see a state buffer that
>>>> looks invalid?
>>>
>>> Since those operate on the in-kernel buffer of these, which
>>> in this patch always uses the unmodified XCR0, ptracers
>>> should not observe a difference.
>>
>> Those operate on *BOTH* kernel and userspace buffers.  They copy between
>> them.  That's kinda the point. :)
> 
> Right, what I meant was that in this patch the kernel level
> xsaves that populates the struct fpu always runs with
> an unmodified XCR0, so the contents of the xsave area
> in struct fpu does not change layout (this is the major
> change in this patch over v1).

The userspace buffer is... a userspace buffer.  It is not and should not
be tied to the format of the kernel buffer.

> Are you referring to a ptracer which runs with a modified XCR0, and
> assumes that the value it gets back from ptrace will have an
> XSTATE_BV equal to its own observed XCR0 and thus get confused about
> the layout of the buffer (or potentially have not copied all of the
> relevant xstate because it calculated a wrong buffer size)?

I don't think it's insane for a process to assume that it can XRSTOR a
buffer that it gets back from ptrace.  That seems like something that
could clearly be an ABI that apps depend on.

Also, let's look at the comment about where XCR0 shows up in the ABI
(arch/x86/include/asm/user.h):

>  * For now, only the first 8 bytes of the software usable bytes[464..471] will
>  * be used and will be set to OS enabled xstate mask (which is same as the
>  * 64bit mask returned by the xgetbv's xCR0).

That also makes it sound like we expect there to be a *SINGLE* value
across the entire system.  It also makes me wonder *which* xgetbv is
expected to match USER_XSTATE_XCR0_WORD.  It can't be the ptracee since
we expect them to change XCR0.  It can't be the ptracer because they can
use this new prctl too.  So does it refer to the kernel?  Or, should the
new prctl() *disable* future ptrace()s?

> If so, I think that's just a buggy ptracer. The kernel's xfeature
> mask is available via ptrace and a well-behaved ptracer should use
> that (e.g. gdb does, though it looks like it then also assumes that
> the xstate has no holes, so it potentially gets the layout wrong
> anyway).

I'm trying to figure out what the semantics are of this whole thing.  It
can't be "don't let userspace observe the real XCR0" because ptrace
exposes that.  Is it, "make memory images portable, unless it's a memory
image from ptrace"?

> In general, I don't really want the modified XCR0 to affect
> anything other than the particular instructions that depend
> on it and maybe the signal frame (though as I said before,
> I'm open to either here).

Just remember that, in the end, we don't get to say what a good ptracer
or bad ptracer is.  If they're expecting semantics that we've kept
constant for 10 years, we change the semantics, and the app breaks, the
kernel is in the wrong.

I also don't feel like I have a good handle on what ptracers *do* with
their XSAVE buffers that they get/set.  How many apps in a distro do
something with this interface?

  reply	other threads:[~2020-04-07 20:21 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07  1:12 [RFC PATCH v2] x86/arch_prctl: Add ARCH_SET_XCR0 to set XCR0 per-thread Keno Fischer
2020-04-07  3:57 ` Andy Lutomirski
2020-04-07  4:44   ` Keno Fischer
2020-04-07  4:53     ` Kyle Huey
2020-04-07 12:33       ` Peter Zijlstra
2020-04-07 13:52         ` Keno Fischer
2020-04-07 12:21 ` Peter Zijlstra
2020-04-07 14:06   ` Dave Hansen
2020-04-07 14:16     ` Andy Lutomirski
2020-04-07 18:30       ` Keno Fischer
2020-04-14 23:20         ` Andy Lutomirski
2020-04-15  0:09           ` Keno Fischer
2020-04-16  1:07             ` Andy Lutomirski
2020-04-16  1:14               ` Keno Fischer
2020-04-16  1:16                 ` Keno Fischer
2020-04-16  1:22                   ` Andy Lutomirski
2020-04-07 16:29     ` Kyle Huey
2020-04-07 13:14 ` Dave Hansen
     [not found]   ` <CABV8kRw1TQsqs+z43bSfZ5isctuFGMB4g_ztDYihiiXHcy4nVA@mail.gmail.com>
2020-04-07 16:27     ` Dave Hansen
2020-04-07 17:55       ` Keno Fischer
2020-04-07 20:21         ` Dave Hansen [this message]
2020-04-07 21:42           ` Andy Lutomirski
2020-04-07 22:15           ` Keno Fischer
2020-04-14 19:55             ` Keno Fischer
2020-04-07 14:20 ` Andi Kleen
2020-04-07 18:06   ` Keno Fischer

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=9921cb2e-a7cb-c1d0-b120-c08f06be7c7f@intel.com \
    --to=dave.hansen@intel.com \
    --cc=andi@firstfloor.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=keno@juliacomputing.com \
    --cc=khuey@kylehuey.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=robert@ocallahan.org \
    --cc=tglx@linutronix.de \
    --cc=x86@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).