Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2317863ybt; Tue, 16 Jun 2020 02:56:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWgqtqq1nFm2RA1rsGNyHKJ+GBdQLKzhGAXKCCqHWgMyYdPPq5n8mwdrIISb8A3Juplgck X-Received: by 2002:aa7:d158:: with SMTP id r24mr1761334edo.272.1592301365181; Tue, 16 Jun 2020 02:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592301365; cv=none; d=google.com; s=arc-20160816; b=Y13H9tEfio52RIcPTYQRrrrgK/LaenCizBPzE0x83C8NG5fZ3UxFML6IceOtY0gIV2 6EVWUAAeD1dZsU/8eEHx3Y1kHtmndS0nI0R3nYM0lbgVgvytB37bBWd3SARu29TWuIsh q/3enpsomnMpujT1qjUinNSLyFuYeIllawxnmzbIsRmtUeG4TNsD55+UbZomysQj6eoV M77ZQiT/sAD5msjzIYXlKsbdSL38lbBwt6F6IkLj5dcPRa5VE/BgMfNYETfH2bOuWnWj bAZqhQKbzLZTq1+k3MNavr23bueKA9MU5N/D+Fv3XGk7GUIW88+bt8vO76ydwq7MMNW1 KJ8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=rOV5dWY1hwX8A8h8h/o4gakUbHaT5FDjfbK9K8CtYAY=; b=ZzZD1R1d1J5VehRd6i5GK1MJm2DEVbx2zcrhPcm83GDxBF7/wNK++RbABJYkph8Gwd 4heq9TlzWix+35slwJg2qgM7w9RnRgLUy12gx6g003T8ubBJMAeiMhTivnRPBPPiblkw M6K7h/P8DRNA6oB89bXKZqIHikEJApzrLAMssi8BwfL/u/XiEf/CVfMThmaGKwNajtlX T3ZvxhBf35PNS0l3I/ObrCUUPujne6P2jjav6pY84Td5AWrU2dMXBo6imus0R6X+qxfx /6M+JtEzznuJnh7jGvi2MkNs4kl1TqNdTqnZAbnuBS7j/VfHNLOf3ERCuEq4vhgcpJKC 34ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=FEaeSamp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si10063397ejw.326.2020.06.16.02.55.42; Tue, 16 Jun 2020 02:56:05 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=FEaeSamp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726606AbgFPJxt (ORCPT + 99 others); Tue, 16 Jun 2020 05:53:49 -0400 Received: from mail.skyhub.de ([5.9.137.197]:55442 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725911AbgFPJxt (ORCPT ); Tue, 16 Jun 2020 05:53:49 -0400 Received: from zn.tnic (p200300ec2f0f4c0030193e5e894dac2c.dip0.t-ipconnect.de [IPv6:2003:ec:2f0f:4c00:3019:3e5e:894d:ac2c]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 2DC321EC0284; Tue, 16 Jun 2020 11:53:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1592301228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:references; bh=rOV5dWY1hwX8A8h8h/o4gakUbHaT5FDjfbK9K8CtYAY=; b=FEaeSampGLvuc8K2hfxQPo9ZgKhy4pl/pjRca6n5d5/Aag6fc/HYoDA/NzTeUu3JGFE5xT sJuNVYd7Vgg2ty1POhzUPlRaZO6jduNkIaBuhHXLfzmDCDOjIDyLdeZaKD8Yy61/J1EOdm /AWKVT+edRBsTOTp3JAi1T6G7M1fRts= Date: Tue, 16 Jun 2020 11:53:40 +0200 From: Borislav Petkov To: x86-ml , jpa@kernelbug.mail.kapsi.fi Cc: Dave Hansen , "H. Peter Anvin" , Sebastian Andrzej Siewior , lkml Subject: [PATCH] x86/fpu: Reset MXCSR to default in kernel_fpu_begin() Message-ID: <20200616095340.GD13515@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ok, here's the fix first so that it goes in. I'll hammer on the test case later. --- From: Petteri Aimonen Previously, kernel floating point code would run with the MXCSR control register value last set by userland code by the thread that was active on the CPU core just before kernel call. This could affect calculation results if rounding mode was changed, or a crash if a FPU/SIMD exception was unmasked. Restore MXCSR to the kernel's default value. [ bp: Carve out from a bigger patch by Petteri, add feature check. ] Signed-off-by: Petteri Aimonen Signed-off-by: Borislav Petkov Link: https://bugzilla.kernel.org/show_bug.cgi?id=207979 --- arch/x86/include/asm/fpu/internal.h | 5 +++++ arch/x86/kernel/fpu/core.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index 42159f45bf9c..845e7481ab77 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -623,6 +623,11 @@ static inline void switch_fpu_finish(struct fpu *new_fpu) * MXCSR and XCR definitions: */ +static inline void ldmxcsr(u32 mxcsr) +{ + asm volatile("ldmxcsr %0" :: "m" (mxcsr)); +} + extern unsigned int mxcsr_feature_mask; #define XCR_XFEATURE_ENABLED_MASK 0x00000000 diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 06c818967bb6..f398fedc590a 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -101,6 +101,9 @@ void kernel_fpu_begin(void) copy_fpregs_to_fpstate(¤t->thread.fpu); } __cpu_invalidate_fpregs_state(); + + if (boot_cpu_has(X86_FEATURE_XMM)) + ldmxcsr(MXCSR_DEFAULT); } EXPORT_SYMBOL_GPL(kernel_fpu_begin); -- 2.21.0 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette