From patchwork Tue Jun 22 22:25:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Hansen X-Patchwork-Id: 12338695 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=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 6C672C48BE5 for ; Tue, 22 Jun 2021 22:26:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1FF9C60FF1 for ; Tue, 22 Jun 2021 22:26:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1FF9C60FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1A4DC6B007B; Tue, 22 Jun 2021 18:26:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1829D6B007D; Tue, 22 Jun 2021 18:26:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06CD96B007E; Tue, 22 Jun 2021 18:26:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id 616426B007B for ; Tue, 22 Jun 2021 18:26:04 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8D9428248D52 for ; Tue, 22 Jun 2021 22:26:04 +0000 (UTC) X-FDA: 78282793848.32.46FF4C9 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf17.hostedemail.com (Postfix) with ESMTP id E1E454000383 for ; Tue, 22 Jun 2021 22:26:03 +0000 (UTC) IronPort-SDR: 6lYE2uFnWWLvGAWxkrj4gHhAqd3dz+8+6RvIysyV1PBWbqv/k77Jw8opG5ckljLHnFlEE1RaFT oBaT9KwUx06w== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="207093945" X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="207093945" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 15:25:48 -0700 IronPort-SDR: OvEfGTHKrvcznJEOTWglAbmLt6y7j8CFBFu+hvM0nq4uUgoziE1rtMms5F+9Fvb60+RO1bzDiO P2fhww5pESSA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="454430987" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga008.fm.intel.com with ESMTP; 22 Jun 2021 15:25:47 -0700 Subject: [RFC][PATCH 4/8] x86/fpu: remove PKRU from FPU user state clearing To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org,Dave Hansen ,tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,x86@kernel.org,luto@kernel.org From: Dave Hansen Date: Tue, 22 Jun 2021 15:25:02 -0700 References: <20210622222455.E901B5AC@viggo.jf.intel.com> In-Reply-To: <20210622222455.E901B5AC@viggo.jf.intel.com> Message-Id: <20210622222502.EA11BE12@viggo.jf.intel.com> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E1E454000383 Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=intel.com (policy=none); spf=none (imf17.hostedemail.com: domain of dave.hansen@linux.intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=dave.hansen@linux.intel.com X-Stat-Signature: tuuu83pzr78bhc95h5ex9sstp1xneu71 X-HE-Tag: 1624400763-885475 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Dave Hansen The signal code has a few points where it initializes user FPU state. Remove PKRU from the set of features which are initialized in the FPU code. Use write_pkru() to explicitly initialize PKRU instead of using the fpstate/XSAVE infrastructure. Signed-off-by: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: Andy Lutomirski --- b/arch/x86/kernel/fpu/core.c | 8 +++++--- b/arch/x86/kernel/fpu/signal.c | 5 ++++- b/arch/x86/kernel/signal.c | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff -puN arch/x86/kernel/fpu/core.c~no-pkru-in-fpu__clear_user_states arch/x86/kernel/fpu/core.c --- a/arch/x86/kernel/fpu/core.c~no-pkru-in-fpu__clear_user_states 2021-06-22 14:49:10.026051754 -0700 +++ b/arch/x86/kernel/fpu/core.c 2021-06-22 14:49:10.039051754 -0700 @@ -209,7 +209,8 @@ static inline void fpstate_init_xstate(s * XRSTORS requires these bits set in xcomp_bv, or it will * trigger #GP: */ - xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | xfeatures_mask_all; + xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | + xfeatures_mask_fpstate(); } static inline void fpstate_init_fxstate(struct fxregs_state *fx) @@ -389,8 +390,9 @@ void fpu__clear_user_states(struct fpu * os_xrstor(&fpu->state.xsave, xfeatures_mask_supervisor()); } - /* Reset user states in registers. */ - load_fpregs_from_init_fpstate(xfeatures_mask_restore_user()); + /* Reset user registers maintained in fpstate. */ + load_fpregs_from_init_fpstate(xfeatures_mask_fpstate() & + xfeatures_mask_restore_user()); /* * Now all FPU registers have their desired values. Inform the FPU diff -puN arch/x86/kernel/fpu/signal.c~no-pkru-in-fpu__clear_user_states arch/x86/kernel/fpu/signal.c --- a/arch/x86/kernel/fpu/signal.c~no-pkru-in-fpu__clear_user_states 2021-06-22 14:49:10.031051754 -0700 +++ b/arch/x86/kernel/fpu/signal.c 2021-06-22 14:49:10.040051754 -0700 @@ -437,6 +437,7 @@ int fpu__restore_sig(void __user *buf, i int ret; if (unlikely(!buf)) { + write_pkru(pkru_get_init_value()); fpu__clear_user_states(¤t->thread.fpu); return 0; } @@ -468,8 +469,10 @@ int fpu__restore_sig(void __user *buf, i ret = __fpu_restore_sig(buf, buf_fx, ia32_fxstate); out: - if (unlikely(ret)) + if (unlikely(ret)) { + write_pkru(pkru_get_init_value()); fpu__clear_user_states(¤t->thread.fpu); + } return ret; } diff -puN arch/x86/kernel/signal.c~no-pkru-in-fpu__clear_user_states arch/x86/kernel/signal.c --- a/arch/x86/kernel/signal.c~no-pkru-in-fpu__clear_user_states 2021-06-22 14:49:10.033051754 -0700 +++ b/arch/x86/kernel/signal.c 2021-06-22 14:49:10.043051754 -0700 @@ -835,6 +835,7 @@ handle_signal(struct ksignal *ksig, stru /* * Ensure the signal handler starts with the new fpu state. */ + write_pkru(pkru_get_init_value()); fpu__clear_user_states(fpu); } signal_setup_done(failed, ksig, stepping);