Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp206246ybl; Tue, 7 Jan 2020 04:55:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxMGJpzi5EcBPIOgJY8N+RUy1pk91IRzEluwMK/33WipSD3u0AnXPaSuPT5s7zCZ69kwONT X-Received: by 2002:a9d:730e:: with SMTP id e14mr114859452otk.62.1578401731813; Tue, 07 Jan 2020 04:55:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578401731; cv=none; d=google.com; s=arc-20160816; b=v+kZOaFXq0NIWePBEr0q10AJ46lWWBXbmC7AXwjUdQPy5EJ2AV1tS1mwdwN66wPMfT vbBuSCCQWZNXdRtmHI5XTHpy9rv3w3wlBXVohVRleSLkWXBh7J6kHoogcoHF99UAqPAv 19MpNZFEpT/OcMTFyi11lC3g/bIe2nF/Mb+EFRgb+3vVxTwlGRc89lgwqbMoSfgrr9tD e9lS2qfttenjGWlQ1zVVXsS9FlYDhMX39HbLY8ukrtUSC7TJJZNyDKmOhYRNbqEvTLFo PqsQ9Jqvf/3vZiegIwvrctvCc32O4YfOw9lHVsF2tU4sG7UNBtjLfEUFcp8Vv9jGvGW6 PbtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=RIMtZqdXETT7/btbwnmlZEIViaCK7e/30pvKn/lXEsY=; b=XGhrNXqmDl+/UAyEGpSsG8356KiM+5SBVsZZAIwZINx7nh1iXadTRZM+CQDQYKkfPc 209lMiJGFC9Z0KAllXlUE7kmqZ8QRl/kjT9XIgIMcTBGTAj6Nmscjj2E+fEGl0t8WZGG FBdUXwOzxvPNNWoMIKANEsjGEnVRHO7qjT3R3nd+yXwLLCQN1RCySmkzbkTo2YiDHCql 6o1wQJBtD5PX0DAzvQlO+ZGeOSeDn8T4gWHG9w/SHGl0A7JJdYGUTXdOA9BhfJcEcZNH uPzn49i8lKFCxy6PfMoDT02XHgCr6Pve3aj4MufB4l9UPhaoJQOc7SD0k/XGSDRyCxgJ veIA== ARC-Authentication-Results: i=1; mx.google.com; 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 e24si5337233oti.247.2020.01.07.04.55.18; Tue, 07 Jan 2020 04:55:31 -0800 (PST) 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; 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 S1728075AbgAGMxB (ORCPT + 99 others); Tue, 7 Jan 2020 07:53:01 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:45336 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727834AbgAGMxB (ORCPT ); Tue, 7 Jan 2020 07:53:01 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iooLg-00009S-7J; Tue, 07 Jan 2020 13:52:40 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id D28C01C2CD0; Tue, 7 Jan 2020 13:52:39 +0100 (CET) Date: Tue, 07 Jan 2020 12:52:39 -0000 From: "tip-bot2 for Sebastian Andrzej Siewior" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/fpu] x86/fpu: Deactivate FPU state after failure during state load Cc: "Yu-cheng Yu" , Sebastian Andrzej Siewior , Borislav Petkov , Andy Lutomirski , Dave Hansen , Fenghua Yu , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Peter Zijlstra , "Ravi V. Shankar" , Rik van Riel , Thomas Gleixner , Tony Luck , "x86-ml" , LKML In-Reply-To: <20191220195906.plk6kpmsrikvbcfn@linutronix.de> References: <20191220195906.plk6kpmsrikvbcfn@linutronix.de> MIME-Version: 1.0 Message-ID: <157840155965.30329.313988118654552721.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/fpu branch of tip: Commit-ID: bbc55341b9c67645d1a5471506370caf7dd4a203 Gitweb: https://git.kernel.org/tip/bbc55341b9c67645d1a5471506370caf7dd4a203 Author: Sebastian Andrzej Siewior AuthorDate: Fri, 20 Dec 2019 20:59:06 +01:00 Committer: Borislav Petkov CommitterDate: Tue, 07 Jan 2020 13:44:42 +01:00 x86/fpu: Deactivate FPU state after failure during state load In __fpu__restore_sig(), fpu_fpregs_owner_ctx needs to be reset if the FPU state was not fully restored. Otherwise the following may happen (on the same CPU): Task A Task B fpu_fpregs_owner_ctx *active* A.fpu __fpu__restore_sig() ctx switch load B.fpu *active* B.fpu fpregs_lock() copy_user_to_fpregs_zeroing() copy_kernel_to_xregs() *modify* copy_user_to_xregs() *fails* fpregs_unlock() ctx switch skip loading B.fpu, *active* B.fpu In the success case, fpu_fpregs_owner_ctx is set to the current task. In the failure case, the FPU state might have been modified by loading the init state. In this case, fpu_fpregs_owner_ctx needs to be reset in order to ensure that the FPU state of the following task is loaded from saved state (and not skipped because it was the previous state). Reset fpu_fpregs_owner_ctx after a failure during restore occurred, to ensure that the FPU state for the next task is always loaded. The problem was debugged-by Yu-cheng Yu . [ bp: Massage commit message. ] Fixes: 5f409e20b7945 ("x86/fpu: Defer FPU state load until return to userspace") Reported-by: Yu-cheng Yu Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Borislav Petkov Cc: Andy Lutomirski Cc: Dave Hansen Cc: Fenghua Yu Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Jann Horn Cc: Peter Zijlstra Cc: "Ravi V. Shankar" Cc: Rik van Riel Cc: Thomas Gleixner Cc: Tony Luck Cc: x86-ml Link: https://lkml.kernel.org/r/20191220195906.plk6kpmsrikvbcfn@linutronix.de --- arch/x86/kernel/fpu/signal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 0071b79..400a05e 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -352,6 +352,7 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size) fpregs_unlock(); return 0; } + fpregs_deactivate(fpu); fpregs_unlock(); } @@ -403,6 +404,8 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size) } if (!ret) fpregs_mark_activate(); + else + fpregs_deactivate(fpu); fpregs_unlock(); err_out: