All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Paolo Bonzini" <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 16/17] x86/fpu: Ensure guest FPU is resident in hardware when updating actual XFD MSR
Date: Fri, 04 Dec 2026 20:11:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-250603@kernel.org> (raw)
In-Reply-To: <20261204175930.2154542-17-pbonzini@redhat.com>

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 <seanjc@google.com>

> x86/fpu: Ensure guest FPU is resident in hardware when updating actual XFD 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 XFD,
> 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 current
> 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 resident
> 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 = 1
>                                         <schedules out>
>   dirty TMM0 (XINUSE[18] == 1)
>   wrmsr(MSR_IA32_XFD, 0x40000)
>   fpu_sync_guest_vmexit_xfd_state()
>   <schedules out>
>   TIF_NEED_FPU_LOAD = 1 (switch_fpu())
>   fpu_fpregs_owner_ctx = fpu0
>   fpu0->last_cpu = A
>                                         <schedules in>
>                                         fpu_update_guest_xfd(fpu1, 0)
>                                         wrmsrq(MSR_IA32_XFD, 0)
>   fpregs_state_valid() == 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] = 1
>
>   fpu_swap_kvm_fpstate() (entry from user)
>   |
>   -> restore_fpregs_from_fpstate() => #NM
>
> Alternatively, fpu_update_guest_xfd() could skip xfd_update_state() *and*
> force an invalidation of the current FPU (set last_cpu = -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_LOAD=1
> is very uncommon, and in all likelihood the guest FPU is going to be loaded
> into hardware in the near future anyways, i.e. avoiding (maybe) loading the
> guest FPU buys nothing but complexity.
>
> Fixes: b45f72177594 ("x86/fpu: Clear XSTATE_BV[i] in guest XSAVE state whenever XFD[i]=1")
> Cc: stable@vger.kernel.org
> Reported-by: Stefan Teodorescu <fane@google.com>
> Suggested-by: Stefan Teodorescu <fane@google.com>
> Reported-by: Chris Mason <mason@kernel.org>
> Suggested-by: Chris Mason <mason@kernel.org>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: David Woodhouse <dwmw2@infradead.org>
> Cc: Jim Mattson <jmattson@google.com>
> Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> Link: https://patch.msgid.link/20261119001506.64568-4-seanjc@google.com
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

[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]=1")?

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 == 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.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204175930.2154542-1-pbonzini@redhat.com?part=16

  reply	other threads:[~2026-12-04 20:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 17:59 [PATCH 00/17] Fixes for various (mostly x86) KVM vulnerabilities Paolo Bonzini
2026-12-04 17:59 ` [PATCH 01/17] KVM: x86/mmu: Flush TLBs if child SPTE is zapped when splitting a huge SPTE Paolo Bonzini
2026-12-04 17:59 ` [PATCH 02/17] KVM: x86/mmu: Propagate the return from kvm_zap_all_rmap_sptes() out of __rmap_add() Paolo Bonzini
2026-12-04 17:59 ` [PATCH 03/17] KVM: x86: Disable hypervisor (VMX Preemption) timer if TSC deadline wraps Paolo Bonzini
2026-12-04 17:59 ` [PATCH 04/17] KVM: x86: Reset local APIC timer metadata on RESET, INIT, and KVM_SET_LAPIC Paolo Bonzini
2026-12-04 17:59 ` [PATCH 05/17] RISC-V: KVM: Flush TLBs *before* dropping mmu_lock, e.g. when yielding Paolo Bonzini
2026-12-04 19:07   ` sashiko-bot
2026-12-04 17:59 ` [PATCH 06/17] LoongArch: KVM: Flush TLBs *before* dropping mmu_lock Paolo Bonzini
2026-12-04 17:59 ` [PATCH 07/17] KVM: x86/mmu: Flush all TLB entries, not a precise range, when yielding Paolo Bonzini
2026-12-04 17:59 ` [PATCH 08/17] KVM: x86/mmu: Flush TLBs in kvm_unmap_gfn_range() if the unmap may block/yield Paolo Bonzini
2026-12-04 17:59 ` [PATCH 09/17] KVM: x86/xen: Pin kvm->mm prior to borrowing mm when setting event channel Paolo Bonzini
2026-12-04 17:59 ` [PATCH 10/17] KVM: Fold kvm_flush_shadow_all() into kvm_mmu_notifier_release() Paolo Bonzini
2026-12-04 17:59 ` [PATCH 11/17] KVM: WARN if there are in-flight memslot updates when a VM's process exits Paolo Bonzini
2026-12-04 17:59 ` [PATCH 12/17] KVM: Set mn_active_invalidate_count when the VM's mm is released Paolo Bonzini
2026-12-04 17:59 ` [PATCH 13/17] KVM: Invalidate all GFN=>PFN caches when VM and/or its process is dying Paolo Bonzini
2026-12-04 20:01   ` sashiko-bot
2026-12-04 17:59 ` [PATCH 14/17] x86/fpu: Bail early from guest XFD update if XFD isn't supported Paolo Bonzini
2026-12-04 17:59 ` [PATCH 15/17] x86/fpu: Clear XSTATE_BV[i] in guest XSAVE state if guest FPU isn't in-use Paolo Bonzini
2026-12-04 17:59 ` [PATCH 16/17] x86/fpu: Ensure guest FPU is resident in hardware when updating actual XFD MSR Paolo Bonzini
2026-12-04 20:11   ` sashiko-bot [this message]
2026-12-04 17:59 ` [PATCH 17/17] KVM: VMX: Ensure pCPU is valid before sending IPI to deliver posted IRQ Paolo Bonzini
2026-12-04 20:27   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-250603@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.