Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2001098imm; Thu, 14 Jun 2018 07:16:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ8OFGv+PGcl4LGAG/6pUStmQbRpi/OLmjgH/bnCzj652B7mNKhvJ7Haz/94eaD0OLjVFv4 X-Received: by 2002:a62:b90f:: with SMTP id z15-v6mr9814985pfe.254.1528985807744; Thu, 14 Jun 2018 07:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528985807; cv=none; d=google.com; s=arc-20160816; b=IJR8GCiq3mbNTxXYVDrK7ZVjsarouQ9VPJqT/iL/Gfg7EXCXwO+wll0q8nOWFyDoJf 4/urTxPrB9BOM9A/rwfaOYbpPdti9UFjWRLwaY3KQnBNwp9IYManrAhOYELO2IkFaSYU /spNDb7QO+mta83fYSN/ov/ooIFpvwt+PXreFiLQYnIu/cP3h43gyQyNEINf+1e+eeRr 9E672mzSqOI8laqRywsyx3KLK/AgHYfVBlPXHmQvmWKc7zUQ3Hmvyt4w6xZEhGzj4q4j UEv2Ag1w0uViH1q3TAIxuZhHnNfjfrmWwVc9qWtKkxWXRspfO6P+gjlEA5A9cXTHTpyl FHnQ== 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=Jbz47nnPQZst91KuDpA9m2neKpJz/shNswz5oS3GFpI=; b=IZ2klTe3sr6EytVvP7lCX1zCnbve/OQEesdbenSdeEMDolVWAq65ZYVKlJ3AECh2a8 ZFPdI6xNUxMcbeFBTZcqyO/fs7yVVDb+kCsKyuMrNIy0jLLVWS/z3ZYRV4oelyh/l/RW 5WQ683vDNCQRx3XWdxCwZH/VVf3t5ch3GDrIwLb+3T/4QHNYvST61NrXISaunTYp0v9l pIhnCWV1sjOb18ZMNjk/pIsXW0JAfGMjjHH3gz2Z/iEKB3PSvLdFBB0oO9NvBbFQRlYI zWLKc2pTV7X5hKlUPH/r6wueqjOP2HRK14Nlx6h1iwCEoneXUb5Tpm6fWrCI67yQhTK1 3/Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vQRmusuH; 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 u9-v6si5469044pls.462.2018.06.14.07.16.33; Thu, 14 Jun 2018 07:16:47 -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=vQRmusuH; 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 S966377AbeFNOOp (ORCPT + 99 others); Thu, 14 Jun 2018 10:14:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:55502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966319AbeFNONy (ORCPT ); Thu, 14 Jun 2018 10:13:54 -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 C927C208E3; Thu, 14 Jun 2018 14:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528985633; bh=zMq2fWR9ck3YK4+2WAQsT/RoNy238x7r/nrU+BR6kzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vQRmusuHrLDOGsXt01P9LrlOkEnoFPVr3LQgMIOyfGJEg8ju5aY+00tUK1dHliP5a NZa+klqDnAbiXvk8P4DyL6HVtlg6LFSGKnbCXeNWBfC9Kv+ORSvP6u2Ikd79eP/VK4 jxHfsPBXxM0xCIh+6akDts1H9KdYCVBiJVzKPU2k= 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 11/24] x86/fpu: Fix FNSAVE usage in eagerfpu mode Date: Thu, 14 Jun 2018 16:05:06 +0200 Message-Id: <20180614132724.940491785@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 5ed73f40735c68d8a656b46d09b1885d3b8740ae upstream. In eager fpu mode, having deactivated FPU without immediately reloading some other context is illegal. Therefore, to recover from FNSAVE, we can't just deactivate the state -- we need to reload it if we're not actively context switching. We had this wrong in fpu__save() and fpu__copy(). Fix both. __kernel_fpu_begin() was fine -- add a comment. This fixes a warning triggerable with nofxsr eagerfpu=on. 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/60662444e13c76f06e23c15c5dcdba31b4ac3d67.1453675014.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/fpu/core.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -114,6 +114,10 @@ void __kernel_fpu_begin(void) kernel_fpu_disable(); if (fpu->fpregs_active) { + /* + * Ignore return value -- we don't care if reg state + * is clobbered. + */ copy_fpregs_to_fpstate(fpu); } else { this_cpu_write(fpu_fpregs_owner_ctx, NULL); @@ -189,8 +193,12 @@ void fpu__save(struct fpu *fpu) preempt_disable(); if (fpu->fpregs_active) { - if (!copy_fpregs_to_fpstate(fpu)) - fpregs_deactivate(fpu); + if (!copy_fpregs_to_fpstate(fpu)) { + if (use_eager_fpu()) + copy_kernel_to_fpregs(&fpu->state); + else + fpregs_deactivate(fpu); + } } preempt_enable(); } @@ -259,7 +267,11 @@ static void fpu_copy(struct fpu *dst_fpu preempt_disable(); if (!copy_fpregs_to_fpstate(dst_fpu)) { memcpy(&src_fpu->state, &dst_fpu->state, xstate_size); - fpregs_deactivate(src_fpu); + + if (use_eager_fpu()) + copy_kernel_to_fpregs(&src_fpu->state); + else + fpregs_deactivate(src_fpu); } preempt_enable(); }