Re: [PATCH 12/22] x86/fpu: Only write PKRU if it is different from current

From: Dave Hansen
Date: Mon Feb 25 2019 - 13:08:13 EST


On 2/21/19 3:50 AM, Sebastian Andrzej Siewior wrote:
> @@ -111,6 +111,12 @@ static inline void __write_pkru(u32 pkru)
> {
> u32 ecx = 0, edx = 0;
>
> + /*
> + * WRPKRU is relatively expensive compared to RDPKRU.
> + * Avoid WRPKRU when it would not change the value.
> + */
> + if (pkru == __read_pkru())
> + return;
> /*
> * "wrpkru" instruction. Loads contents in EAX to PKRU,
> * requires that ecx = edx = 0.

Could we do this in write_pkru() instead? I tried to keep the __
versions of read and write as simple and symmetric as possible.