Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1999422imm; Thu, 14 Jun 2018 07:15:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKR6FtOu+v48YkfpA2WkZxeGw3QgCviRLPvd88acjFdyIhs9y5Emt7W96r+75n88LaxobyL X-Received: by 2002:a65:644f:: with SMTP id s15-v6mr2515329pgv.228.1528985719716; Thu, 14 Jun 2018 07:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528985719; cv=none; d=google.com; s=arc-20160816; b=0CBLS3JuGxcf1zZaruznEjpih4EFjiGX1c1k/0ljHPBfvqWMZXN9mwB0QvrWgru6ku U02iDWhBySUTycYFroNRScgXR921H6JNrSH72p353eNqohvjTspP+OcrBPBdeT+2vWJa x840/bCW96RrWbPLERGCYYWpwOSauy9VMJfEFO2xwfHqvo+jJGnpA+Ij5/mceJgAUgKI kgwdoVCQ+kQZbiXpcB1SqjNo5F77xpjWd/uj0vGSIdKK9CZ1A4cHaup/a07qGa9Wm9T3 ulIxWsqu2R/QUVvnmrihSZvIveu3UnqRCrSTYh/k2eArwL+lsE5oM7Z7LrPbGVMipe/1 EoFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Sdd7zuIbEyHY0PACDkLCS582YWLaHms4SoqQBeklMbM=; b=iJKqfvIzW3gxlIHeWs42Jm0oDM/Wso3aqJjydttuhds7C4Q9peuPnmCnP/vW/Ul1ND DGr/geb/gL5mS6i7Mk/y1HGRXPIo1XxfH3Eift8/d4CCzHp0oIsTW9hVyNCSIS6PIG9w 179m6B8HQsZVCAow0NSm5arxsYJqxxNXQeJJetFhEpS2H1QUtho30g8/DkZzRjBa520a jE0ItYK3K2waIU3RvzQ7iaap5H0zBYNE00BHVcs2Qz53r2oCi134IJFubA6Q4vrfdIv8 QmQZWrxJaneY85oIn4zQZ3tK6fdVuaRV3pM0S83849OJByVwCwqY3Uoq6lAkQSf6yZay r+8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cXkTBkRf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h91-v6si5275287pld.132.2018.06.14.07.15.05; Thu, 14 Jun 2018 07:15:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cXkTBkRf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966352AbeFNOOE (ORCPT + 99 others); Thu, 14 Jun 2018 10:14:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:55556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966333AbeFNON4 (ORCPT ); Thu, 14 Jun 2018 10:13:56 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8E651208E4; Thu, 14 Jun 2018 14:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528985636; bh=XAEhnOi/sA0Jxd4sGQHPDLafIXTueMaE2dqRCIGnpDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cXkTBkRf50wE7bATZdkn/S4K81de0TnnpPfUaMc8+k/4fyzFTh48bS5/c2cRqq9iH g2Brl87jlN5qB7zdQm8ZHOiPQv0M1z67QpZ4iMVnFT2YeUXE47mHLgWdmz9qymcC8J koTMsLfM4s+2U9Mc9BPV16KP3TX0pUiPzWEAHb4c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Andy Lutomirski , Borislav Petkov , Dave Hansen , Fenghua Yu , "H. Peter Anvin" , Linus Torvalds , Oleg Nesterov , Peter Zijlstra , Quentin Casasnovas , Rik van Riel , Sai Praneeth Prakhya , Thomas Gleixner , yu-cheng yu , Ingo Molnar Subject: [PATCH 4.4 12/24] x86/fpu: Fix math emulation in eager fpu mode Date: Thu, 14 Jun 2018 16:05:07 +0200 Message-Id: <20180614132724.979415214@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180614132724.483802160@linuxfoundation.org> References: <20180614132724.483802160@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andy Lutomirski commit 4ecd16ec7059390b430af34bd8bc3ca2b5dcef9a upstream. Systems without an FPU are generally old and therefore use lazy FPU switching. Unsurprisingly, math emulation in eager FPU mode is a bit buggy. Fix it. There were two bugs involving kernel code trying to use the FPU registers in eager mode even if they didn't exist and one BUG_ON() that was incorrect. Signed-off-by: Andy Lutomirski Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Quentin Casasnovas Cc: Rik van Riel Cc: Sai Praneeth Prakhya Cc: Thomas Gleixner Cc: yu-cheng yu Link: http://lkml.kernel.org/r/b4b8d112436bd6fab866e1b4011131507e8d7fbe.1453675014.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/fpu/internal.h | 3 ++- arch/x86/kernel/fpu/core.c | 2 +- arch/x86/kernel/traps.c | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -596,7 +596,8 @@ switch_fpu_prepare(struct fpu *old_fpu, * If the task has used the math, pre-load the FPU on xsave processors * or if the past 5 consecutive context-switches used math. */ - fpu.preload = new_fpu->fpstate_active && + fpu.preload = static_cpu_has(X86_FEATURE_FPU) && + new_fpu->fpstate_active && (use_eager_fpu() || new_fpu->counter > 5); if (old_fpu->fpregs_active) { --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -437,7 +437,7 @@ void fpu__clear(struct fpu *fpu) { WARN_ON_FPU(fpu != ¤t->thread.fpu); /* Almost certainly an anomaly */ - if (!use_eager_fpu()) { + if (!use_eager_fpu() || !static_cpu_has(X86_FEATURE_FPU)) { /* FPU state will be reallocated lazily at the first use. */ fpu__drop(fpu); } else { --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -751,7 +751,6 @@ dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code) { RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU"); - BUG_ON(use_eager_fpu()); #ifdef CONFIG_MATH_EMULATION if (read_cr0() & X86_CR0_EM) {