Re: [PATCH 08/10] x86/xsaves: Fix PTRACE frames for XSAVES

From: Andy Lutomirski
Date: Mon Feb 22 2016 - 17:56:32 EST


On Mon, Feb 22, 2016 at 2:53 PM, Dave Hansen
<dave.hansen@xxxxxxxxxxxxxxx> wrote:
> On 02/22/2016 02:45 PM, Andy Lutomirski wrote:
>>> +/*
>>> > + * Convert from kernel XSAVES compacted format to standard format and copy
>>> > + * to a ptrace buffer. It supports partial copy but pos always starts from
>>> > + * zero. This is called from xstateregs_get() and there we check the cpu
>>> > + * has XSAVES.
>>> > + */
>>> > +int copyout_from_xsaves(unsigned int pos, unsigned int count, void *kbuf,
>>> > + void __user *ubuf, const struct xregs_state *xsave)
>> Now that you've written this code, can it be shared with the signal
>> handling code?
>
> It could be. But the signal handler code has the advantage of already
> having the data in the registers since it's running on its *own* FPU
> state, so it can just call XSAVE(S) directly.
>
> This ptrace code *could* do a kernel_fpu_begin(), XRSTOR the user buffer
> into the registers, XRSTOR the ptracee's system state in to the
> registers, then XSAVES the whole thing to the kernel buffer, then
> kernel_fpu_end().
>
> Or, we could remove the signal handler's ability to XSAVE directly to
> userspace. But it already *had* that and we know it works.

Some day I kind of want to delete all this xsave/xrstor directly on
user buffers code. I've never been thrilled with the concept, and it
has messy (although AFAICT not presently buggy [1]) interactions with
context switches, and it can't run with preemption disabled because it
can take page faults.

In the mean time, it's fine as far as I know, but maybe it would be
cleaner if it used the software copy code. Or maybe we can change it
later if a good reason shows up.

[1] actually there's a minor bug in the 32-bit compat code that
Borislav has a patch for.

--
Andy Lutomirski
AMA Capital Management, LLC