Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5303242imm; Tue, 18 Sep 2018 07:29:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYmc6E+CwpnqjIXKYDpRGkoZnr9hfWP2t18O1Rib+ZM4OJOO2m5ummJzpKsekHYCbbb8DGC X-Received: by 2002:a63:e811:: with SMTP id s17-v6mr28042547pgh.176.1537280997332; Tue, 18 Sep 2018 07:29:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537280997; cv=none; d=google.com; s=arc-20160816; b=PCKTnhLC6fs1Eyo1dbS/4sang1U7ErN38nSGL6MwgmIT4nUb755gTTwd260Ukc0avu yzT1HfVCBeSNlSP/be1cYrf9VfyEweyUvEs7nCd1a72zzEl0oYZ5axJ56/BRl3JD6I/L Z+D3Hlt5j5ErealNPPaNfaNoDHJC0nvBsQGwwca6ce5BuFRF+EP+0YStkRDoS5Z0Ku3m NnDLdHdvrWyAaYfrOwcKfvzQKWsKDaV98ZoAmzrHg0TrbRcAOPdPThnAqG/v/r13E5lr 3mRrfsnYSVG/829uUiMtHU+WaKB5MGcYG5KZLwutVfCPS5sF/YsHLukG4gm6CPpOumAd 3qVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=tVmK09/7FAVl11RI9+53G/XMvY+lO02+P/Y2/BCrGxc=; b=qpWTy6Ue1kymxVKr+qGQJgnieG9qzmYyDWBw6go2HOs0f+8FwTXgYBPXZOaMrtGyxm yGi/8YAf7ojh8qXjnX8SIc08qmwYVLzazJlbqP2M9pKysadDNvx92apxC3wX6aOOoxoj uFcx+pGxBmH4YjOMfLRwBeFp8AW4moV/MpbWuad7nB/uDl+EuE9B2sUd5lZzBXHfvueE /vozlSC2+CvP/CvL9NibxImxXRnrlsy2aronhU/8nCmphI7jPeYT542T3P54NqhwSoev 56RPxV8ZLsPu3NLquHwsNq3AVDCP24HCbfWfgbW5+KpI4A5TMrQ2XRP0AK9V0MH7ImKA jfsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11-v6si18833011plg.237.2018.09.18.07.29.41; Tue, 18 Sep 2018 07:29:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730366AbeIRT77 (ORCPT + 99 others); Tue, 18 Sep 2018 15:59:59 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:57940 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729518AbeIRT76 (ORCPT ); Tue, 18 Sep 2018 15:59:58 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1g2Gxx-0003SF-Of; Tue, 18 Sep 2018 16:27:01 +0200 Date: Tue, 18 Sep 2018 16:27:01 +0200 From: Sebastian Andrzej Siewior To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Radim =?utf-8?B?S3LEjW3DocWZ?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel Subject: Re: [RFC PATCH 04/10 v2 ] x86/fpu: eager switch PKRU state Message-ID: <20180918142701.atfb4ul45k7tl6ew@linutronix.de> References: <20180912133353.20595-1-bigeasy@linutronix.de> <20180912133353.20595-5-bigeasy@linutronix.de> <8e5b64e4-b3e6-f884-beb6-b7b69ab2d8c1@redhat.com> <20180914203501.qibhpmueosvkr74w@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-09-17 10:37:20 [+0200], Paolo Bonzini wrote: > > . This is (again) > > untested since I have no box with this PKRU feature. This only available > > on Intel's Xeon Scalable, right? > > It is available on QEMU too (the slower JIT thing without KVM, i.e. use > /usr/bin/qemu-system-x86_64 instead of /usr/bin/qemu-kvm or /usr/bin/kvm). okay. I managed to get the kernel to report this flag as available now. > > - if (preload) > > - __fpregs_load_activate(new_fpu, cpu); > > + if (!preload) > > + return; > > + > > + __fpregs_load_activate(new_fpu, cpu); > > + > > +#ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS > > + /* Protection keys need to be in place right at context switch time. */ > > + if (boot_cpu_has(X86_FEATURE_OSPKE)) { > > + if (new_fpu->pkru != __read_pkru()) > > + __write_pkru(new_fpu->pkru); > > + } > > +#endif > > I think this would be before the "if (preload)"? I did not find an explicit loading of pkru except this "xrestore" which happens on "preload". From what I saw, preload was always set except for kernel threads. Based on that, it looks to me like it can be skipped if there is no FPU/kernel thread. > > > > if (boot_cpu_has(X86_FEATURE_OSPKE)) > > - copy_init_pkru_to_fpregs(); > > + pkru_set_init_value(); > > } > > > > Likewise, move this to fpu__clear and outside "if > (static_cpu_has(X86_FEATURE_FPU))"? okay. But if there is no FPU we did not save/restore the pkru value. Is this supposed to be an improvement? > Also, a __read_pkru() seems to be missing in switch_fpu_prepare. But the value is stored during write_pkru(). So the copy that is saved should be identical to the value that would be read, correct? > > Thanks, > > Paolo Sebastian