From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dave Hansen Subject: Re: [PATCH 12/22] x86/fpu: Only write PKRU if it is different from current Date: Mon, 25 Feb 2019 10:08:10 -0800 Message-ID: <198b2412-e81d-6c55-c74f-c2cab60fc5f2@intel.com> References: <20190221115020.12385-1-bigeasy@linutronix.de> <20190221115020.12385-13-bigeasy@linutronix.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: x86@kernel.org, Andy Lutomirski , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel , Dave Hansen To: Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org Return-path: In-Reply-To: <20190221115020.12385-13-bigeasy@linutronix.de> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org 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.