Re: [patch 09/41] x86/kvm: Avoid looking up PKRU in XSAVE buffer

From: Borislav Petkov
Date: Tue Jun 15 2021 - 06:09:14 EST


On Mon, Jun 14, 2021 at 12:34:31PM -0700, Dave Hansen wrote:
> I gave that a shot. Two wrinkles: The PKRU memcpy() needs 'offset' from
> cpuid_count() and the PKRU case also needs the 'valid -=' manipulation.
> The result is attached, and while it makes the diff look better, I
> don't think the resulting code is an improvement.

Bah, that was too much wishful and faulty thinking on my part, forget
what I said.

> I *think* these are already stored in xfeature_uncompacted_offset[]. It
> would be a pretty simple matter to export it. I just assumed that this
> is a slow enough path that the KVM folks don't care.

I guess. Yeah, let's cleanup the FPU mess first and then see what makes
sense or not.

> I'm happy to change it, but I usually like to separate declarations from
> pure code. Although, I guess that's a bit inconsistent in that file.

No, this is what I mean:

+ src = get_xsave_addr(xsave, xfeature_nr);
+ if (src)
+ memcpy(dest + offset, src, size);

vs

+ void *dest = get_xsave_addr(xsave, xfeature_nr);
+
+ if (dest)
memcpy(dest, src + offset, size);

both in your patch.

It is a lot easier when reading the code to have the error handling
glued together with the previous function call.

Thx.

--
Regards/Gruss,
Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg