Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3535843imu; Wed, 7 Nov 2018 11:51:04 -0800 (PST) X-Google-Smtp-Source: AJdET5dfvNiGPHR/Og0pTrny98DjLKdgTDPNJ4w8FzFW2MMBitWx9/r14WIj5zppu7BJo6/GZkh3 X-Received: by 2002:a17:902:2863:: with SMTP id e90-v6mr714001plb.244.1541620264352; Wed, 07 Nov 2018 11:51:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541620264; cv=none; d=google.com; s=arc-20160816; b=06P3TUfoKhwq4v680wsdfkkOs7+lMAXLMrOIiGTKaAosgIKDr9YZO0+bDBmnGnsXIs Tt3H723ivub4wzFHY88cV+zpBDoVIZFFh8tgq5yhA2TK8oAKJZb5QfrnFZBxYbBkB8Xh 7wswBgJzk/EZXds1O9pQDQKiTUnpKvOgEArg2jA5PUX2lOE1Gb327J5EOoOKOrPEq0+z BqwkQNh9o8dPDfrA/Qt5XClhJCmHlgNSotiXiVvHvfJT7zLRE8Yximd9XMmzoeW1Jwli /sLRijxIqD78NcLlfj97MBJIUMr05Wcx4FD9Jr5thl3WpxFlD2g4dAZqd70Vr8THgfXV rYxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=II6g8a4ciVS/GisiBw/dbad/cM8RyjoaIkWN7izJ4RE=; b=zg7arVmVSurAmA3mg+HycIcuIpyOCeiArxjU82YJdw+IZzEyakiuVQecHf2kW1yYaD pAffEpK/fb8qYobfLKV1ZjpeaB9a/0oIiZ+m/HQWB5xQZtTKwrRGBNQUddXVqe2qVAhF W54xDwZqlH4HOkHpOaENFcJaAIbMpgnXXgsdM/Q/+t44w4g2RjpOa/0vrUmIdl8s413m kCmqrtK9o+JrFn3A1u5QOPAzb+6ra+qmywT9QV/d06DvLeSLuY604lIiNvqlT3LjD2bt NV890okfxWIs6K/RtxJo0f/bXGNBCom80pQkfOoIuP/56p3Z/buNOU5JneXrD5wHhWOX 2j3w== 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 ba4-v6si1568918plb.93.2018.11.07.11.50.41; Wed, 07 Nov 2018 11:51:04 -0800 (PST) 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 S1726961AbeKHFVr (ORCPT + 99 others); Thu, 8 Nov 2018 00:21:47 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:41974 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727694AbeKHFVW (ORCPT ); Thu, 8 Nov 2018 00:21:22 -0500 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gKTpP-00070Q-TO; Wed, 07 Nov 2018 20:49:28 +0100 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Andy Lutomirski , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel , Dave Hansen , Sebastian Andrzej Siewior Subject: [PATCH 21/23] x86/fpu: Update xstate's PKRU value on write_pkru() Date: Wed, 7 Nov 2018 20:48:56 +0100 Message-Id: <20181107194858.9380-22-bigeasy@linutronix.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181107194858.9380-1-bigeasy@linutronix.de> References: <20181107194858.9380-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During the context switch the xstate is loaded which also includes the PKRU value. If xstate is restored on return to userland it is required that the PKRU value in xstate is the same as the one in the CPU. Save the PKRU in xstate during modification. Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/include/asm/pgtable.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 40616e8052924..45ca1c7802812 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -23,6 +23,8 @@ #ifndef __ASSEMBLY__ #include +#include +#include extern pgd_t early_top_pgt[PTRS_PER_PGD]; int __init __early_make_pgtable(unsigned long address, pmdval_t pmd); @@ -133,8 +135,21 @@ static inline u32 read_pkru(void) static inline void write_pkru(u32 pkru) { - if (boot_cpu_has(X86_FEATURE_OSPKE)) - __write_pkru(pkru); + struct pkru_state *pk; + + if (!boot_cpu_has(X86_FEATURE_OSPKE)) + return; + + pk = __raw_xsave_addr(¤t->thread.fpu.state.xsave, XFEATURE_PKRU); + /* + * The PKRU value in xstate needs to be in sync with the value that is + * written to the CPU. The FPU restore on return to userland would + * otherwise load the previous value again. + */ + __fpregs_changes_begin(); + pk->pkru = pkru; + __write_pkru(pkru); + __fpregs_changes_end(); } static inline int pte_young(pte_t pte) -- 2.19.1