From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4538C433B4 for ; Wed, 12 May 2021 07:46:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 940E161432 for ; Wed, 12 May 2021 07:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230211AbhELHrU (ORCPT ); Wed, 12 May 2021 03:47:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230184AbhELHrR (ORCPT ); Wed, 12 May 2021 03:47:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68189C061574; Wed, 12 May 2021 00:46:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qTeWQyqg90a0gIju1FCIhB4SaC06XxqkOWQ6xtTm4Es=; b=NlsjsMvDDgO0IMtnHraRetZsIk 6ryqjmPMmdqeCkRL7AJ5FHt0wrPbFlgAchZDkGSmgrVMivTdfDOYQhW1pSRx6CvNn8F53ygREJrAu uwjs+ea5rLshMzfYJWcpNhTVFdQkWkFajqojNth2n9xexlBh0KFLb8AAIB/mHp0bC87m1b6NAZxLs zel+3z4tBGHdYv+Dccd/5lpE18seXHJ2msM6jBB5s1Xm2Z+/wNf0K3IzMGuGPuB28Lo5ybl5llAKl GuUnQYg+iWLsWUQ+HsMWRIie6NsaB7NFYUaicWNG9g5Q9kQN1fAd/8epnob9zzKP8OLuwqFBoXMZ4 1iOJlHoA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lgjUe-00847E-Uf; Wed, 12 May 2021 07:41:39 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A9B3E300242; Wed, 12 May 2021 09:41:14 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B9CBE20237F69; Wed, 12 May 2021 09:41:14 +0200 (CEST) Date: Wed, 12 May 2021 09:41:14 +0200 From: Peter Zijlstra To: Jon Kohler Cc: Babu Moger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Dave Hansen , Yu-cheng Yu , Fenghua Yu , Tony Luck , Uros Bizjak , Petteri Aimonen , Al Viro , Kan Liang , Andrew Morton , Mike Rapoport , Fan Yang , Juergen Gross , Benjamin Thiel , Dave Jiang , Ricardo Neri , Arvind Sankar , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v3] KVM: x86: use wrpkru directly in kvm_load_{guest|host}_xsave_state Message-ID: References: <20210511170508.40034-1-jon@nutanix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511170508.40034-1-jon@nutanix.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 11, 2021 at 01:05:02PM -0400, Jon Kohler wrote: > diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h > index 8d33ad80704f..5bc4df3a4c27 100644 > --- a/arch/x86/include/asm/fpu/internal.h > +++ b/arch/x86/include/asm/fpu/internal.h > @@ -583,7 +583,13 @@ static inline void switch_fpu_finish(struct fpu *new_fpu) > if (pk) > pkru_val = pk->pkru; > } > - __write_pkru(pkru_val); > + > + /* > + * WRPKRU is relatively expensive compared to RDPKRU. > + * Avoid WRPKRU when it would not change the value. > + */ > + if (pkru_val != rdpkru()) > + wrpkru(pkru_val); Just wondering; why aren't we having that in a per-cpu variable? The usual per-cpu MSR shadow approach avoids issuing any 'special' ops entirely.