mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: Andrei Vagin <avagin@google.com>
Cc: Daniel Wade <danjwade95@gmail.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>, <x86@kernel.org>,
	"H . Peter Anvin" <hpa@zytor.com>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86/fpu: Put non-enabled dynamic features into init state on sigreturn
Date: Sat, 21 Nov 2026 14:08:03 -0800	[thread overview]
Message-ID: <aae55e1a-3b4f-47ef-8a97-3eb3a470bf86@intel.com> (raw)
In-Reply-To: <av5TI7uMazFmWYid@google.com>

On 11/18/2026 5:38 PM, Andrei Vagin wrote:
>>
>> How could that happen?
> 
> The code relies on this: while a task owns the FPU registers, a dynamic
> feature it has not enabled is in its init state.
> restore_fpregs_from_fpstate() maintains that by restoring with
> fpu_kernel_cfg.max_features (the comment there describes exactly this
> case), and fpu__clear_user_states() does the same on signal delivery.
> 
> The 64-bit sigreturn path doesn't. restore_fpregs_from_user() restores
> from the user buffer with RFBM and init_bv both limited to
> fpstate->user_xfeatures, then calls fpregs_mark_activate(). That clears
> TIF_NEED_FPU_LOAD, so the full restore on exit to user, which would have
> put XTILE_DATA into init state, never runs.
> 
> If the registers still belonged to current, that's fine. But the task
> can lose them inside rt_sigreturn: the first XRSTOR from the frame
> faults and fault_in_readable() sleeps, or the task is simply preempted.
> Switching out only saves the registers. It doesn't clear them, so the
> next AMX user leaves its tiles there:
> 
>    CPU0
>    A: rt_sigreturn()            A has AMX permission, XTILE_DATA not enabled
>         sleeps / preempted      A's state saved, TIF_NEED_FPU_LOAD set
>    B: runs, uses AMX            B's tiles are now in the registers
>    A: back in rt_sigreturn()
>         restore_fpregs_from_user()
>           xfd_update_state()    XFD[18] set: B's tiles hidden, not cleared
>           XRSTOR(frame, RFBM)   bit 18 not in RFBM or init_bv: untouched
>           fpregs_mark_activate()
>    A: exit to user              no reload, B's tiles still in the registers
> 

Thanks! Much better description to me.

> Here is the selftest to rerpoduce the issue:

Yes, this is good. Maybe better to trim a bit if considering to the 
mainline.

Thanks,
Chang

  parent reply	other threads:[~2026-11-21 22:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 11:26 Daniel Wade
2026-11-18 20:19 ` Chang S. Bae
2026-11-19  1:38   ` Andrei Vagin
2026-11-19  7:50     ` Andrei Vagin
2026-11-21 22:08     ` Chang S. Bae [this message]
2026-11-20 23:34 ` Andrei Vagin
2026-11-21 22:08 ` Chang S. Bae

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=aae55e1a-3b4f-47ef-8a97-3eb3a470bf86@intel.com \
    --to=chang.seok.bae@intel.com \
    --cc=avagin@google.com \
    --cc=bp@alien8.de \
    --cc=danjwade95@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®