Skip to content

x86/fpu: Fix MXCSR handling and SSE component definition

Chang S. Bae linux-kselftest lkml 3 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 0 repliesNew
  2. v24 patches 3 repliesSuperseded
  3. v14 patches 1 replySuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3x86/fpu: Fix the MXCSR state reshuffling between userspace and kernel buffersarch/x86/kernel/fpu/xstate.c+49 -210 replies
2/3selftests/x86/mxcsr: Test the MXCSR state write via ptracetools/testing/selftests/x86/Makefile tools/testing/selftests/x86/mxcsr.c+201 -10 replies
3/3x86/fpu: Correct the legacy state offset and size informationarch/x86/kernel/fpu/xstate.c+12 -70 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/3] x86/fpu: Fix MXCSR handling and SSE component definition

Hi all,

Changes from v2 [1]:
* Drop the changes in fpstate_clear_xstate_component().
* Massage the WARNING and the comment in xfeature_get_offset().

If the former function is called for any legacy state, the WARNING is eventually emitted by the latter function in this call chain:
fpstate_clear_xstate_component()

    -> get_xsave_addr()
      -> __raw_xsave_addr()
        -> xfeature_get_offset()

So, the change in the outer function (the old patch3) was considered as not necessary.

Thanks Sean Christopherson for the feedback.

== Regression ==

Recently the XSTATE copy functions were unitized together [2]. At a glance, this change appears to relapse the ptrace write on the MXCSR state when the non-compacted format is used in the kernel.

But, this regression appears to root in the XSAVES-enabling code [3] that introduced the XSTATE conversion along with the MXCSR mistreatment.

== MXCSR Hindsight ==

MXCSR is architecturally part of the SSE component. The MXCSR association of XSTATE_BV depends on the XSAVE format.

The change [3], however, presumed MXCSR as part of the X87 component and made the kernel referencing XSTATE_BV regardless of the format.

== Patches ==

* Fix the MXCSR conversion code along with adding the test case.
* The hard-coded legacy state offset and size are adjusted in the end. And add a WARN when they are referenced.

These patches can be also found in this repository:
git://github.com/intel/amx-linux.git mxcsr

Thanks,
Chang

[1] v2: https://lore.kernel.org/lkml/[email protected]/
[2] Commit 43be46e89698 ("x86/fpu: Sanitize xstateregs_set()")
[3] Commit 91c3dba7dbc1 ("x86/fpu/xstate: Fix PTRACE frames for XSAVES")

Chang S. Bae (3):
x86/fpu: Fix the MXCSR state reshuffling between userspace and kernel
buffers
selftests/x86/mxcsr: Test the MXCSR state write via ptrace x86/fpu: Correct the legacy state offset and size information

 arch/x86/kernel/fpu/xstate.c         |  89 ++++++++----
 tools/testing/selftests/x86/Makefile |   2 +-
 tools/testing/selftests/x86/mxcsr.c  | 200 +++++++++++++++++++++++++++
 3 files changed, 262 insertions(+), 29 deletions(-)
 create mode 100644 tools/testing/selftests/x86/mxcsr.c

base-commit: 03c739a21613a1a85f730dd972ff928e573f7235

Signature · 1 line
2.17.1