Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5106239pxj; Tue, 22 Jun 2021 15:26:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdaCuan200FTceMdSlcxB+s067LwUC0v7wbM63906lBBFFJkZK0Or15YmHEB94KclJfO+4 X-Received: by 2002:a05:6e02:10c3:: with SMTP id s3mr591138ilj.37.1624400801310; Tue, 22 Jun 2021 15:26:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624400801; cv=none; d=google.com; s=arc-20160816; b=DjhYE7LZxFf8B+ByMnAVZ14sw2x+hDNmbscFu6+jQ+I7BUhvFeg0J02Ja/nIgontje h+uhenAhY+Wgbyv9+wTCUy0tQ/InriM1HDGA1aaxg8R2vQTU2j+xOp7bfgIZs5NaoTEE OwyfgYNnh4j6/ROEQvmnek5SwHIu7YBmhg+L9Y3H52j6lwON/0uP6E1p/7gphwDtTB+j NAuIfIeoPSFa9/QaDXBFOzsupdydTbqHVjODFZmOvPtP/SOw+DUJCOsqsDvFfqXeAyAD FbWOvv61pEqlLTQwVYlP1IzWEhgCjtpRusB0c/h5Cx89oZOjEoGL9zzMRvHakcK0JD0q WTmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:in-reply-to:references:date:from:cc :to:subject:ironport-sdr:ironport-sdr; bh=liyeciAtzIaBnZcA0qekfceswZTSjbQsgxyjB3Eokdc=; b=o03Z4hmFSI+BfM6b/u0uiI8NbARZfdWfTACR4lQjEWBL+bU4HA9a/xTNdHTdp0wGEy XuH2hmBrpAz6+RqYzT5x461Xg4amKpoz7u0QddyJ2mCOBq6HiPLLEOE4U4+4VBcL6KJV SBkFzVCZhGO5oqKvvlCJnngmwfAPk/kUuT5hE09jOxgRA0YASGGzq9RXkgLwyrO9pci9 DOSXsuhbFmuwFbuOw5hhQf5XbK2zoJa8hPI2WYK7zBMJ/kxYEF1TsAWdNZM2c0nK7wYP m656+96ggjwV625W443NzM0YtkCOks1l6v293RgpBRY7F/9TjSMC879FA/obCA99lybt Vsyg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si667004jao.68.2021.06.22.15.26.30; Tue, 22 Jun 2021 15:26:41 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230363AbhFVW2H (ORCPT + 99 others); Tue, 22 Jun 2021 18:28:07 -0400 Received: from mga05.intel.com ([192.55.52.43]:61015 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbhFVW2F (ORCPT ); Tue, 22 Jun 2021 18:28:05 -0400 IronPort-SDR: VhztBwRu0I7v4BkYilq/kNuqJMyym5yGQe8AhbctXp65Fb/oCjEQRYGXG84mAOxcbjyhPr98aq yFVKLwxTTxiQ== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="292779523" X-IronPort-AV: E=Sophos;i="5.83,292,1616482800"; d="scan'208";a="292779523" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 15:25:47 -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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); _