Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4240158pxj; Wed, 12 May 2021 00:48:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywMbsBeVyz/cS5esj2WTxOvgeMjQhRhdFC4/sI+4ZHGAAxGpBEViZq2Cqv0hqjUmPgo8PL X-Received: by 2002:a92:d1c3:: with SMTP id u3mr5773690ilg.262.1620805688438; Wed, 12 May 2021 00:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620805688; cv=none; d=google.com; s=arc-20160816; b=wiiSQywXxKWU1GiKcjPG3P4YlgcmirmPyH/ZuOHS+bQkytj4c+LA46ja5rypgJOgja TJbPUtjdvbNI+8ivFaZdegg6DwxsDa/bl+dIqTDVW6kgNoApXPAz2OH/8hk4EhTrzknG 3xixOjVG7jOmS68xjyS3+qY1dTWbAD6ygnWGViTZHL9OkM5XIILJeKPX2IfC2O5VTFxu kT6QofPTx9f/kEt21z9QkNpKA+LXTg3iqpxgPb5C1b2Q9kFpD4gcs65sz2w+Z2QYBVnE uJFrbJOODUKbSqor3SXqfLbLSOi6ffY6UduP65rb4emoncAKYpFOt+18+jJDxsBCY7C4 3KZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qTeWQyqg90a0gIju1FCIhB4SaC06XxqkOWQ6xtTm4Es=; b=nOmUuHe81Y+OSyKVE6/aaE7cmDcwh7piquRkzUB4EYAvo8p7gfYYKJSujNePk2+MQ5 r0nUQaL6fN9qG0tKyG0te3oXweYm+l/yC/50/AOJnXN/bFsg80NNVnuQRHhMN+FWFc5t h0WKL5RcrC36XSiNiWDL2wi89aog6/jkPbjsgRpbO8MWCYJ2qKvKT4cPDhLOVcAG14mL GhcWcF74XPVNZwKPAQkO4/2HbBSPtIAGeo180Hfb5kLVakxrfLEvZ2Fm0xX4UC3pUlqh pcKwm8QZ7pT2mfDWXjhiuwH57JKQcz7cTmWtXFsj2OlDdZIBq2oCAaXiKFG1pcq6239H e4XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=NlsjsMvD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si23701490ila.129.2021.05.12.00.47.54; Wed, 12 May 2021 00:48:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=NlsjsMvD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbhELHrT (ORCPT + 99 others); Wed, 12 May 2021 03:47:19 -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.