From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750853AbdAXIrH (ORCPT ); Tue, 24 Jan 2017 03:47:07 -0500 Received: from terminus.zytor.com ([65.50.211.136]:54060 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750704AbdAXIrF (ORCPT ); Tue, 24 Jan 2017 03:47:05 -0500 Date: Tue, 24 Jan 2017 00:46:17 -0800 From: tip-bot for Yu-cheng Yu Message-ID: Cc: dave.hansen@linux.intel.com, tglx@linutronix.de, haokexin@gmail.com, Joakim.Tjernlund@infinera.com, peterz@infradead.org, mingo@kernel.org, ravi.v.shankar@intel.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, hpa@zytor.com, fenghua.yu@intel.com, luto@kernel.org, bp@suse.de, yu-cheng.yu@intel.com Reply-To: dave.hansen@linux.intel.com, linux-kernel@vger.kernel.org, ravi.v.shankar@intel.com, torvalds@linux-foundation.org, haokexin@gmail.com, tglx@linutronix.de, Joakim.Tjernlund@infinera.com, mingo@kernel.org, peterz@infradead.org, hpa@zytor.com, fenghua.yu@intel.com, luto@kernel.org, yu-cheng.yu@intel.com, bp@suse.de In-Reply-To: <1485212084-4418-1-git-send-email-yu-cheng.yu@intel.com> References: <1485212084-4418-1-git-send-email-yu-cheng.yu@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/fpu/xstate: Fix xcomp_bv in XSAVES header Git-Commit-ID: dffba9a31c7769be3231c420d4b364c92ba3f1ac X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: dffba9a31c7769be3231c420d4b364c92ba3f1ac Gitweb: http://git.kernel.org/tip/dffba9a31c7769be3231c420d4b364c92ba3f1ac Author: Yu-cheng Yu AuthorDate: Mon, 23 Jan 2017 14:54:44 -0800 Committer: Ingo Molnar CommitDate: Tue, 24 Jan 2017 09:04:48 +0100 x86/fpu/xstate: Fix xcomp_bv in XSAVES header The compacted-format XSAVES area is determined at boot time and never changed after. The field xsave.header.xcomp_bv indicates which components are in the fixed XSAVES format. In fpstate_init() we did not set xcomp_bv to reflect the XSAVES format since at the time there is no valid data. However, after we do copy_init_fpstate_to_fpregs() in fpu__clear(), as in commit: b22cbe404a9c x86/fpu: Fix invalid FPU ptrace state after execve() and when __fpu_restore_sig() does fpu__restore() for a COMPAT-mode app, a #GP occurs. This can be easily triggered by doing valgrind on a COMPAT-mode "Hello World," as reported by Joakim Tjernlund and others: https://bugzilla.kernel.org/show_bug.cgi?id=190061 Fix it by setting xcomp_bv correctly. This patch also moves the xcomp_bv initialization to the proper place, which was in copyin_to_xsaves() as of: 4c833368f0bf x86/fpu: Set the xcomp_bv when we fake up a XSAVES area which fixed the bug too, but it's more efficient and cleaner to initialize things once per boot, not for every signal handling operation. Reported-by: Kevin Hao Reported-by: Joakim Tjernlund Signed-off-by: Yu-cheng Yu Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Fenghua Yu Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Ravi V. Shankar Cc: Thomas Gleixner Cc: haokexin@gmail.com Link: http://lkml.kernel.org/r/1485212084-4418-1-git-send-email-yu-cheng.yu@intel.com [ Combined it with 4c833368f0bf. ] Signed-off-by: Ingo Molnar --- arch/x86/kernel/fpu/core.c | 4 +++- arch/x86/kernel/fpu/xstate.c | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index e4e97a5..de72344 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -183,7 +184,8 @@ void fpstate_init(union fpregs_state *state) * it will #GP. Make sure it is replaced after the memset(). */ if (static_cpu_has(X86_FEATURE_XSAVES)) - state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT; + state->xsave.header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | + xfeatures_mask; if (static_cpu_has(X86_FEATURE_FXSR)) fpstate_init_fxstate(&state->fxsave); diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index e287b90..1d77704 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1070,7 +1070,6 @@ int copyin_to_xsaves(const void *kbuf, const void __user *ubuf, * Add back in the features that came in from userspace: */ xsave->header.xfeatures |= xfeatures; - xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | xsave->header.xfeatures; return 0; }