Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1738866imu; Wed, 28 Nov 2018 14:23:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/VyVQrw6RpZMqU0ErV9KBDhLYcyZhPdRC0uJPb3ymJUxfGKcX/uq6SnPwdJG1CRkNLYAi67 X-Received: by 2002:a17:902:f082:: with SMTP id go2mr38845864plb.115.1543443795554; Wed, 28 Nov 2018 14:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543443795; cv=none; d=google.com; s=arc-20160816; b=zHhZ+d3jrBeh3McHbfDa/u9Y9hBC2ST8DhUDNXVcgH46LM6Ii4A1z03QQhPM1LpG3D 79sF3pmDTU3xLRC5ns+8qHDHyjhdrIfHGTETCNjPcjCj9jGzbEYpQRyhMyA1AXtw13Dy 63hgYYYrC9em5Jt1n4G7r5ncJXnYo4xbCnYxLlxQdTlq0y6YDQPImOioPlTgKDbjhHQM HMujVszdc4hnnx22Kdw7jxzcNDzp5WtBQ25gE4lfwEHelPAfQeIEeEza35RZfxP1PHnX B8WmBmD4sxeJZaLvPbB2V00ZjnV87g1rA+p2xSExN+aKSndZUd1t8eWwBD6pn4EXtZE9 WXTQ== 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=fc3djevXZpkclvTOlVIGiwkVq4htZi60FN3RuZF+uhk=; b=nCkuJmaHl9eKT/XOEHEzpyfjkw/AtRuLpDNd0bOdDn/aDRx8QkjrT/odBREmAxy8gO yek5oRRSeAPjVL+VHoWX0x28RUObq6YlpBiq2ikd0sgP1DJoeP44ItAwgthVRydthc38 WkDFcqTblhF2YLqeaNvV5An626nbJqpD+xO7mC5C/TJhpT7Gpzox+SvMs5A4AKM2ziTZ eDy8Yr/yaoAORPVaAUbubdTbe07hEmE3b7VP1hu+eeWs1+NOIlQGDhV6N+2ujrWjDm/A uqWIc86dtyXLKJn573JjFwu/gdDDdNz195FBJX6L6xMVOEeb9Y7IcmHwH6tGy39iQVEV qjeQ== 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 e2si8180686pgs.94.2018.11.28.14.23.00; Wed, 28 Nov 2018 14:23:15 -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 S1727333AbeK2JYl (ORCPT + 99 others); Thu, 29 Nov 2018 04:24:41 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:33229 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727223AbeK2JYl (ORCPT ); Thu, 29 Nov 2018 04:24:41 -0500 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gS8D0-0001GX-51; Wed, 28 Nov 2018 23:21:26 +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 25/29] x86/fpu: Update xstate's PKRU value on write_pkru() Date: Wed, 28 Nov 2018 23:20:31 +0100 Message-Id: <20181128222035.2996-26-bigeasy@linutronix.de> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181128222035.2996-1-bigeasy@linutronix.de> References: <20181128222035.2996-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 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 40616e8052924..5eed44798ae95 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,22 @@ 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 = get_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(); + if (pk) + pk->pkru = pkru; + __write_pkru(pkru); + __fpregs_changes_end(); } static inline int pte_young(pte_t pte) -- 2.20.0.rc1