Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3594637ybl; Fri, 20 Dec 2019 12:01:23 -0800 (PST) X-Google-Smtp-Source: APXvYqwowqm9xpn2+sGGk3I92QW/zR6zGvZiHDo2Euamq2ewlFLJG/bCFhnrIrQDB2QpANr2MKrI X-Received: by 2002:a9d:6857:: with SMTP id c23mr4231930oto.351.1576872083430; Fri, 20 Dec 2019 12:01:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576872083; cv=none; d=google.com; s=arc-20160816; b=EfN2b+1vxmRvsuLRYV0me5Z08bXKDauf9noPww97nDstiMWlvz8PKL4JLoZBAPCdXR NQY2UAwqattOUcGOz3gFnqFrsucK8qnq8ibKBgThsf8q3eo6y92V6YAy+EwvYU5McWcf PFtiWRG5eqMFLau5x2AswVmm5L5u6DVbCk+0WYhA80OkjauMkvZCHdRMp2thELaxzodL zVkrYcn87TzsmGcVJGup23p88KzzyEoybYj6Gik5YdsoFt6DnYzp2YPpgcLQuMJRTxPH xp+hSJJzL7+0kJAtPgEZgi6/LjhPJBHdkRK4pE9WFELhqqQS+48zgaF04uCdBScE46sy Mt6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=UdI6jJ2iClNlhfzcqHvPAygsJ72vcPPVs5pEi878HyU=; b=wdDbAvyHGo/9yGv4HfI8oxjLlPppSvGFkoXD7bJcOs7zN4br11VWVKTSuWSCAdXhrn Uhw98yEW/+psw1oeagJAJYOrJYyXpyxQBmAet3uLK92RoKFPXq/0lF7VbmutA7zRWjk7 WTPcHeCpzu39SEGE9WwAf3oATJBxlntV/NwECuwD6eyyHU7MquiJLJ0ZuJVImWNcIody wuOsmM2GYRqWTII9Ieh5Udq5eEK3Arf8Zoes6OITIoKqzhM7GjIWOdjhp6mzAVuEU8NB kqukTFhTHEy7hXrNn7g5InpKxdo6lBTzPoVe04wXy4BiwEWKqP+ek10ekpweai4qGacL xuUg== 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 t15si1737384oth.160.2019.12.20.12.01.09; Fri, 20 Dec 2019 12:01:23 -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 S1727492AbfLTT7O (ORCPT + 99 others); Fri, 20 Dec 2019 14:59:14 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:34151 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727411AbfLTT7O (ORCPT ); Fri, 20 Dec 2019 14:59:14 -0500 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1iiOQU-00081G-OF; Fri, 20 Dec 2019 20:59:06 +0100 Date: Fri, 20 Dec 2019 20:59:06 +0100 From: Sebastian Andrzej Siewior To: Yu-cheng Yu Cc: linux-kernel@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , Dave Hansen , Tony Luck , Andy Lutomirski , Borislav Petkov , Rik van Riel , "Ravi V. Shankar" , Fenghua Yu , Peter Zijlstra Subject: [PATCH] x86/fpu: Deacticate FPU state after failure during state load Message-ID: <20191220195906.plk6kpmsrikvbcfn@linutronix.de> References: <20191212210855.19260-1-yu-cheng.yu@intel.com> <20191212210855.19260-4-yu-cheng.yu@intel.com> <20191218155449.sk4gjabtynh67jqb@linutronix.de> <587463c4e5fa82dff8748e5f753890ac390e993e.camel@intel.com> <20191219142217.axgpqlb7zzluoxnf@linutronix.de> <19a94f88f1bc66bb81dbf5dd72083d03ca5090e9.camel@intel.com> <20191219171635.phdsfkvsyazwaq7s@linutronix.de> <1607597639a6c6255127fef07704ee9193e33166.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1607597639a6c6255127fef07704ee9193e33166.camel@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In __fpu__restore_sig() we need to reset `fpu_fpregs_owner_ctx' 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 succeess case we set `fpu_fpregs_owner_ctx' to the current task. In the failure case we *might* have modified the FPU state because we loaded the init state. In this case we need to reset `fpu_fpregs_owner_ctx' to ensure that the FPU state of the following task is loaded from saved state (and not skip because it was the previous state). Reset `fpu_fpregs_owner_ctx' after a failure during restore occured to ensure that the FPU state for the next task is always loaded. Fixes: 5f409e20b7945 ("x86/fpu: Defer FPU state load until return to userspace") Reported-by: Yu-cheng Yu Debugged-by: Yu-cheng Yu Signed-off-by: Sebastian Andrzej Siewior --- 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 0071b794ed193..400a05e1c1c51 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: -- 2.24.1