From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755104Ab1K2MmP (ORCPT ); Tue, 29 Nov 2011 07:42:15 -0500 Received: from va3ehsobe001.messaging.microsoft.com ([216.32.180.11]:31111 "EHLO VA3EHSOBE008.bigfish.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753107Ab1K2MmN (ORCPT ); Tue, 29 Nov 2011 07:42:13 -0500 X-SpamScore: 0 X-BigFish: VPS0(zzzz1202hzz8275bhz2dh668h839h62h) X-Spam-TCS-SCL: 1:0 X-Forefront-Antispam-Report: CIP:163.181.249.108;KIP:(null);UIP:(null);IPV:NLI;H:ausb3twp01.amd.com;RD:none;EFVD:NLI X-WSS-ID: 0LVF9Y7-01-CQW-02 X-M-MSG: From: Hans Rosenfeld To: CC: , , , , , , , , , Hans Rosenfeld Subject: [PATCH 1/9] x86, xsave: warn on #NM exceptions caused by the kernel Date: Tue, 29 Nov 2011 13:41:20 +0100 Message-ID: <1322570488-21798-2-git-send-email-hans.rosenfeld@amd.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1322570488-21798-1-git-send-email-hans.rosenfeld@amd.com> References: <1322570488-21798-1-git-send-email-hans.rosenfeld@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-OriginatorOrg: amd.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kernel code handling the FPU states should handle the TS bit in such a way that #NM exceptions cannot happen inside the kernel. Any other kernel code using FPU features should use kernel_fpu_begin() and kernel_fpu_end(), which handles the TS bit and disallows preemption. So if a #NM exception ever comes from kernel mode, it would indicate a serious bug. Trapping this with WARN_ON_ONCE() could prove helpful in finding and eliminating such bugs. Signed-off-by: Hans Rosenfeld --- arch/x86/kernel/traps.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 6913369..953d5f6 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -777,6 +777,8 @@ EXPORT_SYMBOL_GPL(math_state_restore); dotraplinkage void __kprobes do_device_not_available(struct pt_regs *regs, long error_code) { + WARN_ON_ONCE(!user_mode_vm(regs)); + #ifdef CONFIG_MATH_EMULATION if (read_cr0() & X86_CR0_EM) { struct math_emu_info info = { }; -- 1.7.5.4