lkml.org 
[lkml]   [2022]   [Sep]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v6 1/2] x86/fpu: Allow PKRU to be (once again) written by ptrace.
On Mon, Aug 29, 2022, Kyle Huey wrote:
> @@ -1246,6 +1246,21 @@ static int copy_uabi_to_xstate(struct fpstate *fpstate, const void *kbuf,
> }
> }
>
> + /*
> + * Update the user protection key storage. Allow KVM to
> + * pass in a NULL pkru pointer if the mask bit is unset
> + * for its legacy ABI behavior.
> + */
> + if (pkru)
> + *pkru = 0;
> +
> + if (hdr.xfeatures & XFEATURE_MASK_PKRU) {
> + struct pkru_state *xpkru;
> +
> + xpkru = __raw_xsave_addr(xsave, XFEATURE_PKRU);
> + *pkru = xpkru->pkru;
> + }

What about writing this as:

if (hdr.xfeatures & XFEATURE_MASK_PKRU) {
...

*pkru = xpkru->pkru;
} else if (pkru) {
*pkru = 0;
}

to make it slightly more obvious that @pkru must be non-NULL if the feature flag
is enabled?

Or we could be paranoid, though I'm not sure this is worthwhile.

if ((hdr.xfeatures & XFEATURE_MASK_PKRU) &&
!WARN_ON_ONCE(!pkru)) {
...

*pkru = xpkru->pkru;
} else if (pkru) {
*pkru = 0;
}


Otherwise, looks good from a KVM perspective. Thanks!

\
 
 \ /
  Last update: 2022-09-01 17:31    [W:0.054 / U:1.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site