Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4591185pxj; Tue, 25 May 2021 11:24:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4+f+c5N3TvKNZPWqf5U14t3GyZ7eCCr8WgB90NwG1fMNNEvEXCBuVhoimd4G/sbS0KMjB X-Received: by 2002:a17:906:3411:: with SMTP id c17mr30853454ejb.332.1621967088440; Tue, 25 May 2021 11:24:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621967088; cv=none; d=google.com; s=arc-20160816; b=zjrTe6ccBCaq+hEb4nB1PqlmN3n7H9dEUGs007WtVFhQZv6YQ3lxd+xlD2hdx3iPpm inNDSJJHEDfQ00SHCP7QXb0SYP7U2h3+N1y+X4YNNJbCYV3OrAZKHuJMtM8/LM6weHuG 7BHCkc5xHkPnu0o13M1G8ph7VJqNKAe/6F6UNsDtBHJ42go55EbH2Zgm1/E1wBUovHXU imznTi1oFKCJWlO6bWPdE/BBOUmorwlJGu6nLJzZr88bmFrIbveKHSFidsdInq2zc99T MixUlcN3QWIIkKlqhBtnl9jf2mXbwDAqdr2U6crcASY/XFjY+186b+dAPYitLwHE3hGO Sq5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=9W1VjW2IFIkQ11eUuOMOenFO5Lw5hfp25hjB7v6+Hmo=; b=mqA+Urxd0eQI3JnIR70GUDyggj/XcJMsenK0KkdPagsasQ3DhADK5ai8TjuVIHgYot OOVKmICzn/cIbMsL//RJ52Uvs+zBSq3doBBLjk40xWf8szFPdJsStgzRXbS24+z9KkmY MKkEsG+liaKScP1fq7LOUhLEsRyyoa/h7sXnnsZKBPJIjZjSOFx+REVzXIBK1udPxl4L 9QhEE9DiYHkC2Vs7llpJ8sDBwwl2RhVO9nMZQmGfhM2AkihkesS5SOaX/atf19Hfi1z2 J9+runVgimPZcKjCDMdiCXZFCiIttlYdOsfHNuUy3VVqwbI2wU44pHw/3JPsvBXaB9iJ C1Kg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z71si18760502ede.151.2021.05.25.11.24.26; Tue, 25 May 2021 11:24:48 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232839AbhEYRpl (ORCPT + 99 others); Tue, 25 May 2021 13:45:41 -0400 Received: from mga12.intel.com ([192.55.52.136]:15706 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbhEYRpk (ORCPT ); Tue, 25 May 2021 13:45:40 -0400 IronPort-SDR: /byLTI5JQF5tTtLPB3U1HOXqOkUWjzA/pLFzd5a8ui5jf/j74yGYi8KtdgDdeBShUpJCy5/ZoT yhew8XmkankQ== X-IronPort-AV: E=McAfee;i="6200,9189,9995"; a="181897563" X-IronPort-AV: E=Sophos;i="5.82,328,1613462400"; d="scan'208";a="181897563" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 10:44:09 -0700 IronPort-SDR: uWshkxUNnbiX9UjDXkzNRFlgix7S4kdr+qVh9X9TFv2Pm7rioso6HagobCgZO8H5b9xjF3TzBw LC5dm4CJdBcg== X-IronPort-AV: E=Sophos;i="5.82,328,1613462400"; d="scan'208";a="546865626" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.209.133.101]) ([10.209.133.101]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 May 2021 10:44:08 -0700 Subject: Re: [tip: x86/fpu] x86/fpu/xstate: Define new functions for clearing fpregs and xstates To: Andy Lutomirski , LKML Cc: linux-tip-commits@vger.kernel.org, Fenghua Yu , Borislav Petkov , Dave Hansen , Tony Luck , x86 , "Shankar, Ravi V" References: <20200512145444.15483-6-yu-cheng.yu@intel.com> <158964181793.17951.15480349640697746223.tip-bot2@tip-bot2> From: "Yu, Yu-cheng" Message-ID: <10a553a5-699f-6921-705e-9afa1a8e42de@intel.com> Date: Tue, 25 May 2021 10:44:08 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/24/2021 9:34 AM, Andy Lutomirski wrote: > On Sat, May 16, 2020 at 8:10 AM tip-bot2 for Fenghua Yu > wrote: >> >> The following commit has been merged into the x86/fpu branch of tip: >> >> Commit-ID: b860eb8dce5906b14e3a7f3c771e0b3d6ef61b94 >> Gitweb: https://git.kernel.org/tip/b860eb8dce5906b14e3a7f3c771e0b3d6ef61b94 >> Author: Fenghua Yu >> AuthorDate: Tue, 12 May 2020 07:54:39 -07:00 >> Committer: Borislav Petkov >> CommitterDate: Wed, 13 May 2020 13:41:50 +02:00 >> >> x86/fpu/xstate: Define new functions for clearing fpregs and xstates > > syzbot says this is busted. I've made no effort to identify the > precise bug that is making syzbot complain, but: > >> /* >> - * Clear FPU registers by setting them up from >> - * the init fpstate: >> + * Clear FPU registers by setting them up from the init fpstate. >> + * Caller must do fpregs_[un]lock() around it. >> */ >> -static inline void copy_init_fpstate_to_fpregs(void) >> +static inline void copy_init_fpstate_to_fpregs(u64 features_mask) >> { >> - fpregs_lock(); >> - > > > >> if (use_xsave()) >> - copy_kernel_to_xregs(&init_fpstate.xsave, -1); >> + copy_kernel_to_xregs(&init_fpstate.xsave, features_mask); >> else if (static_cpu_has(X86_FEATURE_FXSR)) >> copy_kernel_to_fxregs(&init_fpstate.fxsave); >> else >> @@ -307,9 +305,6 @@ static inline void copy_init_fpstate_to_fpregs(void) >> >> if (boot_cpu_has(X86_FEATURE_OSPKE)) >> copy_init_pkru_to_fpregs(); > > if (boot_cpu_has(X86_FEATURE_OSPKE) && (features_mask & PKRU)), perhaps? > >> - >> - fpregs_mark_activate(); >> - fpregs_unlock(); >> } >> >> /* >> @@ -318,18 +313,40 @@ static inline void copy_init_fpstate_to_fpregs(void) >> * Called by sys_execve(), by the signal handler code and by various >> * error paths. >> */ >> -void fpu__clear(struct fpu *fpu) >> +static void fpu__clear(struct fpu *fpu, bool user_only) >> { >> - WARN_ON_FPU(fpu != ¤t->thread.fpu); /* Almost certainly an anomaly */ >> + WARN_ON_FPU(fpu != ¤t->thread.fpu); >> >> - fpu__drop(fpu); >> + if (!static_cpu_has(X86_FEATURE_FPU)) { >> + fpu__drop(fpu); >> + fpu__initialize(fpu); >> + return; >> + } >> >> - /* >> - * Make sure fpstate is cleared and initialized. >> - */ >> - fpu__initialize(fpu); >> - if (static_cpu_has(X86_FEATURE_FPU)) >> - copy_init_fpstate_to_fpregs(); >> + fpregs_lock(); >> + >> + if (user_only) { >> + if (!fpregs_state_valid(fpu, smp_processor_id()) && >> + xfeatures_mask_supervisor()) >> + copy_kernel_to_xregs(&fpu->state.xsave, >> + xfeatures_mask_supervisor()); > > This looks correct to me. > > So I'm guessing that syzbot may have misattributed the problem. But > we definitely need to clean up the XRSTOR #GP handling before CET > lands. > From the crash dump, the system is doing syscall_exit_to_user_mode() for __x64_sys_futex(). The futex syscall does not seem to modify xstates, but upon returning to user mode, XRSTORS gets a GP. Can this be some memory corruption? fpu__clear() is merely helping to clear the mess and seems to be innocent. I also run the syz repro on my Tiger Lake machine, and it only produces segfaults (no Bad FPU state, etc.). Yu-cheng