From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796415067; b=EvbAn3aTCiMwvhncKyun3xyhOy9ZnImqE3clVvZx9irau3od/Pl8220BWKfOpDBF9Zig NozoqXhc7XSPGPlvDOUQ8d4WIFF/LxQ+oq4ANAsOEYU1G/dW+Yr8hCYx5+NADksrb/3ml uIORL6s1GKKfD0tDeIOap6GhjnnDNUaFl/m/k+XzbUdc5m74HT6cTIx3gXFr4lvvedSVH ZOR5mnZxMVtewFZnxmFin4pk4LGy1/PHA0cGRl1fM55j3tc98eU5WequY+9rfpkLmeA+z XD2o6mFcE1I5hotk3bPJFz3qzVvmKBRnD3a8NF9PtI+dLDSe6gpA4rRcIbkulC8yE1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796415067; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=J+ugVkWNO0xiWkdtOXRT2JB2FiM0nn46DsLMC6VJM5M=; b=Dd0EV8IQIiGku33HKSSg9zNv4kVC084bNhAOIEqItOiQwhTGzRyx0bkmQOpukswKN9X7 EcsQrJpI1KfPwvSp09p4GpkwExTY+rKnZBC4hKdGdMrVC/g71qXOhp5f7N+H0GK8DCUw6 rGYel1VJ6yG4VSRXZ8i6GigpmiCa/e/JSfTsE+qD84W/i8lSSKv6G3g9bw1J3KL0Xgw2+ VjTGkiRnYZlSdFZagB34HmAoDpUsjMOXlhMPYKsIyJKoREjzGmKojVss5smoQeRXQIDsL fCFs6kX4V4lM/4b34ZvTsOsA3JYFKZE4HGgKxG1dngJK0iYz51i0fwIGX3yf5BkXlUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XQcRO5zh; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C4BD606A322 for ; Fri, 4 Dec 2026 20:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XQcRO5zh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 274631F00936; Fri, 4 Dec 2026 20:11:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796415067; bh=J+ugVkWNO0xiWkdtOXRT2JB2FiM0nn46DsLMC6VJM5M=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=XQcRO5zh39wt8qzwtlITmBkfS0uNN3KY21GH70KJoOm6LylNdgicbD35MZCwMquov eZj6l7SB2ay2ZAau6ldmph1Frl0m9PtwbO94vhTBvhQfp1g6QvBt/FAc50Dw8Qe0mp XsMu/YuS+HShMFQeWOOj7Y40HdX91k+Om+SfLFqxb9KzpptxFe4eOjbdhGiyVlipkV NielZ2AdGvkWfroBVYwUsbCMxYOzPx1WlV61oxi4m3rY7sMTTaBycUOfSphV+JaQhT MwJE8So+iqvYI3vKG30sJ4pnij4bhBYNQKxrWxutxkvcRm/w7CPEYW6fkseVBgs8/t U5ai9Frj8/hNA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 16/17] x86/fpu: Ensure guest FPU is resident in hardware when updating actual XFD MSR Reply-To: sashiko-reviews@lists.linux.dev To: "Paolo Bonzini" , kvm@vger.kernel.org In-Reply-To: <20261204175930.2154542-17-pbonzini@redhat.com> References: <20261204175930.2154542-1-pbonzini@redhat.com> <20261204175930.2154542-17-pbonzini@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:11:06 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] x86/fpu: Fixes trailer cites wrong commit for fpu_update_guest_xfd() bug -- commit 8e958ac03ba6613579a0c2ac427b8e549024a0e8 Author: Sean Christopherson > x86/fpu: Ensure guest FPU is resident in hardware when updating actual XF= D MSR > > When updating a guest FPU's XFD, ensure the guest FPU state is resident in > hardware. Failure to do so means updating XFD may effectively clobber XF= D, > and in the worst case scenario can lead to an #NM due to failing to update > XFD. Specifically, if the guest FPU is in-use (associated with the curre= nt > task) and the current task has TIF_NEED_FPU_LOAD, then lock and load the > task's FPU regs. > > The underlying issue is that TIF_NEED_FPU_LOAD doesn't actually mean the > FPU isn't resident in hardware, it only says the FPU *might* not be resid= ent > in hardware and *may* need a reload. E.g. if the current task was tagged > with TIF_NEED_FPU_LOAD by switch_fpu(), but never evicted from hardware, > then KVM's call to switch_fpu_return() will elide the xfd_update_state() > call (and the XRSTOR) due to the FPU being valid, and run the vCPU with a > stale XFD. > > E.g. on a single pCPU 'A', timeshared by two vCPUs: > > vcpu0 / fpu0 vcpu1 / fpu1 > TIF_NEED_FPU_LOAD =3D 1 > > dirty TMM0 (XINUSE[18] =3D=3D 1) > wrmsr(MSR_IA32_XFD, 0x40000) > fpu_sync_guest_vmexit_xfd_state() > > TIF_NEED_FPU_LOAD =3D 1 (switch_fpu()) > fpu_fpregs_owner_ctx =3D fpu0 > fpu0->last_cpu =3D A > > fpu_update_guest_xfd(fpu1, 0) > wrmsrq(MSR_IA32_XFD, 0) > fpregs_state_valid() =3D=3D true > | > -> switch_fpu_return() skips > restore_fpregs_from_fpstate() and > xfd_update_state() > > fpu_swap_kvm_fpstate() (exit to user) > | > -> fpu0->regs.xsave.header.xfeatures > is saved with XSTATE_BV[18] =3D 1 > > fpu_swap_kvm_fpstate() (entry from user) > | > -> restore_fpregs_from_fpstate() =3D> #NM > > Alternatively, fpu_update_guest_xfd() could skip xfd_update_state() *and* > force an invalidation of the current FPU (set last_cpu =3D -1) to ensure = the > correct XFD is loaded when doing switch_fpu_return(). However, that gets > all kinds of convoluted, and emulating an XFD write with TIF_NEED_FPU_LOA= D=3D1 > is very uncommon, and in all likelihood the guest FPU is going to be load= ed > into hardware in the near future anyways, i.e. avoiding (maybe) loading t= he > guest FPU buys nothing but complexity. > > Fixes: b45f72177594 ("x86/fpu: Clear XSTATE_BV[i] in guest XSAVE state wh= enever XFD[i]=3D1") > Cc: stable@vger.kernel.org > Reported-by: Stefan Teodorescu > Suggested-by: Stefan Teodorescu > Reported-by: Chris Mason > Suggested-by: Chris Mason > Cc: Josef Bacik > Cc: Paolo Bonzini > Cc: David Woodhouse > Cc: Jim Mattson > Acked-by: Dave Hansen > Signed-off-by: Sean Christopherson > Link: https://patch.msgid.link/20261119001506.64568-4-seanjc@google.com > Signed-off-by: Paolo Bonzini [Severity: Low] Should the Fixes tag cite 8eb9a48ac1e8 ("x86/fpu: Provide fpu_update_guest_xfd() for IA32_XFD emulation") instead of b45f72177594 ("x86/fpu: Clear XSTATE_BV[i] in guest XSAVE state whenever XFD[i]=3D1")? The cited commit only added XSTATE_BV clearing when xfd is non-zero and TIF_NEED_FPU_LOAD is set, which is not reached in the xfd =3D=3D 0 scenario above. Calling xfd_update_state() without first loading the guest FPU into hardware dates back to the earlier commit, so citing the later one leaves older stable trees out of backport tracking. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204175930.2154= 542-1-pbonzini@redhat.com?part=3D16