lkml.org 
[lkml]   [2022]   [Oct]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 1/1] x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly
From
On 10/18/22 15:13, Chang S. Bae wrote:
> @@ -1141,10 +1141,14 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate,
> */
> pkru.pkru = pkru_val;
> membuf_write(&to, &pkru, sizeof(pkru));
> + } else if (!(header.xfeatures & BIT_ULL(i))) {
> + /*
> + * Every extended state component has an all zeros
> + * init state.
> + */
> + membuf_zero(&to, xstate_sizes[i]);
> } else {
> - copy_feature(header.xfeatures & BIT_ULL(i), &to,
> - __raw_xsave_addr(xsave, i),
> - __raw_xsave_addr(xinit, i),
> + membuf_write(&to, __raw_xsave_addr(xsave, i),
> xstate_sizes[i]);
> }

Just to add a bit more context, this is inside this loop:

mask = fpstate->user_xfeatures;
for_each_extended_xfeature(i, mask) {
if (zerofrom < xstate_offsets[i])
membuf_zero(&to, xstate_offsets[i] - zerofrom);
...
}
if (to.left)
membuf_zero(&to, to.left);

In other words, the loop and the surrounding code already know how to
membuf_zero() any gaps in the middle or the end of the user buffer.
Would it be simpler to just adjust the 'mask' over which the loop iterates?

I think that would end up being something like:

mask = fpstate->user_xfeatures &
(xsave->xfeatures | xinit->xfeatures);

Logically, that makes sense too. We're copying out of either 'xsave' or
'xinit'. If a feature isn't in either one of those we can't do the
copy_feature() on it.

\
 
 \ /
  Last update: 2022-10-20 18:58    [W:0.095 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site