<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/arch/x86/include/asm/fpu, branch linux-5.8.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.8.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.8.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2020-06-29T08:02:00Z</updated>
<entry>
<title>x86/fpu: Reset MXCSR to default in kernel_fpu_begin()</title>
<updated>2020-06-29T08:02:00Z</updated>
<author>
<name>Petteri Aimonen</name>
</author>
<published>2020-06-16T09:12:57Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7ad816762f9bf89e940e618ea40c43138b479e10'/>
<id>urn:sha1:7ad816762f9bf89e940e618ea40c43138b479e10</id>
<content type='text'>
Previously, kernel floating point code would run with the MXCSR control
register value last set by userland code by the thread that was active
on the CPU core just before kernel call. This could affect calculation
results if rounding mode was changed, or a crash if a FPU/SIMD exception
was unmasked.

Restore MXCSR to the kernel's default value.

 [ bp: Carve out from a bigger patch by Petteri, add feature check, add
   FNINIT call too (amluto). ]

Signed-off-by: Petteri Aimonen &lt;jpa@git.mail.kapsi.fi&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Link: https://bugzilla.kernel.org/show_bug.cgi?id=207979
Link: https://lkml.kernel.org/r/20200624114646.28953-2-bp@alien8.de
</content>
</entry>
<entry>
<title>x86/fpu: Introduce copy_supervisor_to_kernel()</title>
<updated>2020-05-16T09:24:14Z</updated>
<author>
<name>Yu-cheng Yu</name>
</author>
<published>2020-05-12T14:54:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=eeedf1533687b8e81865fdbde79eddf7c4b76c9a'/>
<id>urn:sha1:eeedf1533687b8e81865fdbde79eddf7c4b76c9a</id>
<content type='text'>
The XSAVES instruction takes a mask and saves only the features specified
in that mask.  The kernel normally specifies that all features be saved.

XSAVES also unconditionally uses the "compacted format" which means that
all specified features are saved next to each other in memory.  If a
feature is removed from the mask, all the features after it will "move
up" into earlier locations in the buffer.

Introduce copy_supervisor_to_kernel(), which saves only supervisor states
and then moves those states into the standard location where they are
normally found.

Signed-off-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Link: https://lkml.kernel.org/r/20200512145444.15483-9-yu-cheng.yu@intel.com
</content>
</entry>
<entry>
<title>x86/fpu/xstate: Update copy_kernel_to_xregs_err() for supervisor states</title>
<updated>2020-05-14T14:46:43Z</updated>
<author>
<name>Yu-cheng Yu</name>
</author>
<published>2020-05-12T14:54:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c95473e175dd1234b7440daa6eb2670ebf529653'/>
<id>urn:sha1:c95473e175dd1234b7440daa6eb2670ebf529653</id>
<content type='text'>
The function copy_kernel_to_xregs_err() uses XRSTOR which can work with
standard or compacted format without supervisor xstates. However, when
supervisor xstates are present, XRSTORS must be used. Fix it by using
XRSTORS when supervisor state handling is enabled.

I also considered if there were additional cases where XRSTOR might be
mistakenly called instead of XRSTORS.  There are only three XRSTOR sites
in the kernel:

1. copy_kernel_to_xregs_booting(), already switches between XRSTOR and
   XRSTORS based on X86_FEATURE_XSAVES.

2. copy_user_to_xregs(), which *needs* XRSTOR because it is copying from
   userspace and must never copy supervisor state with XRSTORS.

3. copy_kernel_to_xregs_err() mistakenly used XRSTOR only.  Fix it.

 [ bp: Massage commit message. ]

Signed-off-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Reviewed-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Link: https://lkml.kernel.org/r/20200512145444.15483-8-yu-cheng.yu@intel.com
</content>
</entry>
<entry>
<title>x86/fpu/xstate: Define new functions for clearing fpregs and xstates</title>
<updated>2020-05-13T11:41:50Z</updated>
<author>
<name>Fenghua Yu</name>
</author>
<published>2020-05-12T14:54:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b860eb8dce5906b14e3a7f3c771e0b3d6ef61b94'/>
<id>urn:sha1:b860eb8dce5906b14e3a7f3c771e0b3d6ef61b94</id>
<content type='text'>
Currently, fpu__clear() clears all fpregs and xstates.  Once XSAVES
supervisor states are introduced, supervisor settings (e.g. CET xstates)
must remain active for signals; It is necessary to have separate functions:

- Create fpu__clear_user_states(): clear only user settings for signals;
- Create fpu__clear_all(): clear both user and supervisor settings in
   flush_thread().

Also modify copy_init_fpstate_to_fpregs() to take a mask from above two
functions.

Remove obvious side-comment in fpu__clear(), while at it.

 [ bp: Make the second argument of fpu__clear() bool after requesting it
   a bunch of times during review.
  - Add a comment about copy_init_fpstate_to_fpregs() locking needs. ]

Co-developed-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Fenghua Yu &lt;fenghua.yu@intel.com&gt;
Signed-off-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Reviewed-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Tony Luck &lt;tony.luck@intel.com&gt;
Link: https://lkml.kernel.org/r/20200512145444.15483-6-yu-cheng.yu@intel.com
</content>
</entry>
<entry>
<title>x86/fpu/xstate: Separate user and supervisor xfeatures mask</title>
<updated>2020-05-13T08:31:07Z</updated>
<author>
<name>Yu-cheng Yu</name>
</author>
<published>2020-05-12T14:54:37Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=524bb73bc15c56f5587e33c817e103a259b019d2'/>
<id>urn:sha1:524bb73bc15c56f5587e33c817e103a259b019d2</id>
<content type='text'>
Before the introduction of XSAVES supervisor states, 'xfeatures_mask' is
used at various places to determine XSAVE buffer components and XCR0 bits.
It contains only user xstates.  To support supervisor xstates, it is
necessary to separate user and supervisor xstates:

- First, change 'xfeatures_mask' to 'xfeatures_mask_all', which represents
  the full set of bits that should ever be set in a kernel XSAVE buffer.
- Introduce xfeatures_mask_supervisor() and xfeatures_mask_user() to
  extract relevant xfeatures from xfeatures_mask_all.

Co-developed-by: Fenghua Yu &lt;fenghua.yu@intel.com&gt;
Signed-off-by: Fenghua Yu &lt;fenghua.yu@intel.com&gt;
Signed-off-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Reviewed-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Tony Luck &lt;tony.luck@intel.com&gt;
Link: https://lkml.kernel.org/r/20200512145444.15483-4-yu-cheng.yu@intel.com
</content>
</entry>
<entry>
<title>x86/fpu/xstate: Define new macros for supervisor and user xstates</title>
<updated>2020-05-12T18:34:38Z</updated>
<author>
<name>Fenghua Yu</name>
</author>
<published>2020-05-12T14:54:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8ab22804efefea9ecf3c68aa00f1fa69c70fcfad'/>
<id>urn:sha1:8ab22804efefea9ecf3c68aa00f1fa69c70fcfad</id>
<content type='text'>
XCNTXT_MASK is 'all supported xfeatures' before introducing supervisor
xstates.  Rename it to XFEATURE_MASK_USER_SUPPORTED to make clear that
these are user xstates.

Replace XFEATURE_MASK_SUPERVISOR with the following:
- XFEATURE_MASK_SUPERVISOR_SUPPORTED: Currently nothing.  ENQCMD and
  Control-flow Enforcement Technology (CET) will be introduced in separate
  series.
- XFEATURE_MASK_SUPERVISOR_UNSUPPORTED: Currently only Processor Trace.
- XFEATURE_MASK_SUPERVISOR_ALL: the combination of above.

Co-developed-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Fenghua Yu &lt;fenghua.yu@intel.com&gt;
Signed-off-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Reviewed-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Tony Luck &lt;tony.luck@intel.com&gt;
Link: https://lkml.kernel.org/r/20200512145444.15483-3-yu-cheng.yu@intel.com
</content>
</entry>
<entry>
<title>x86/fpu/xstate: Rename validate_xstate_header() to validate_user_xstate_header()</title>
<updated>2020-05-12T18:20:32Z</updated>
<author>
<name>Fenghua Yu</name>
</author>
<published>2020-05-12T14:54:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5274e6c172c47241534e970df26a522497086624'/>
<id>urn:sha1:5274e6c172c47241534e970df26a522497086624</id>
<content type='text'>
The function validate_xstate_header() validates an xstate header coming
from userspace (PTRACE or sigreturn). To make it clear, rename it to
validate_user_xstate_header().

Suggested-by: Dave Hansen &lt;dave.hansen@intel.com&gt;
Signed-off-by: Fenghua Yu &lt;fenghua.yu@intel.com&gt;
Signed-off-by: Yu-cheng Yu &lt;yu-cheng.yu@intel.com&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Reviewed-by: Dave Hansen &lt;dave.hansen@linux.intel.com&gt;
Reviewed-by: Tony Luck &lt;tony.luck@intel.com&gt;
Reviewed-by: Borislav Petkov &lt;bp@suse.de&gt;
Link: https://lkml.kernel.org/r/20200512145444.15483-2-yu-cheng.yu@intel.com
</content>
</entry>
<entry>
<title>x86/fpu: Don't cache access to fpu_fpregs_owner_ctx</title>
<updated>2019-11-28T09:16:46Z</updated>
<author>
<name>Sebastian Andrzej Siewior</name>
</author>
<published>2019-11-28T08:53:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=59c4bd853abcea95eccc167a7d7fd5f1a5f47b98'/>
<id>urn:sha1:59c4bd853abcea95eccc167a7d7fd5f1a5f47b98</id>
<content type='text'>
The state/owner of the FPU is saved to fpu_fpregs_owner_ctx by pointing
to the context that is currently loaded. It never changed during the
lifetime of a task - it remained stable/constant.

After deferred FPU registers loading until return to userland was
implemented, the content of fpu_fpregs_owner_ctx may change during
preemption and must not be cached.

This went unnoticed for some time and was now noticed, in particular
since gcc 9 is caching that load in copy_fpstate_to_sigframe() and
reusing it in the retry loop:

  copy_fpstate_to_sigframe()
    load fpu_fpregs_owner_ctx and save on stack
    fpregs_lock()
    copy_fpregs_to_sigframe() /* failed */
    fpregs_unlock()
         *** PREEMPTION, another uses FPU, changes fpu_fpregs_owner_ctx ***

    fault_in_pages_writeable() /* succeed, retry */

    fpregs_lock()
	__fpregs_load_activate()
	  fpregs_state_valid() /* uses fpu_fpregs_owner_ctx from stack */
    copy_fpregs_to_sigframe() /* succeeds, random FPU content */

This is a comparison of the assembly produced by gcc 9, without vs with this
patch:

| # arch/x86/kernel/fpu/signal.c:173:      if (!access_ok(buf, size))
|        cmpq    %rdx, %rax      # tmp183, _4
|        jb      .L190   #,
|-# arch/x86/include/asm/fpu/internal.h:512:       return fpu == this_cpu_read_stable(fpu_fpregs_owner_ctx) &amp;&amp; cpu == fpu-&gt;last_cpu;
|-#APP
|-# 512 "arch/x86/include/asm/fpu/internal.h" 1
|-       movq %gs:fpu_fpregs_owner_ctx,%rax      #, pfo_ret__
|-# 0 "" 2
|-#NO_APP
|-       movq    %rax, -88(%rbp) # pfo_ret__, %sfp
…
|-# arch/x86/include/asm/fpu/internal.h:512:       return fpu == this_cpu_read_stable(fpu_fpregs_owner_ctx) &amp;&amp; cpu == fpu-&gt;last_cpu;
|-       movq    -88(%rbp), %rcx # %sfp, pfo_ret__
|-       cmpq    %rcx, -64(%rbp) # pfo_ret__, %sfp
|+# arch/x86/include/asm/fpu/internal.h:512:       return fpu == this_cpu_read(fpu_fpregs_owner_ctx) &amp;&amp; cpu == fpu-&gt;last_cpu;
|+#APP
|+# 512 "arch/x86/include/asm/fpu/internal.h" 1
|+       movq %gs:fpu_fpregs_owner_ctx(%rip),%rax        # fpu_fpregs_owner_ctx, pfo_ret__
|+# 0 "" 2
|+# arch/x86/include/asm/fpu/internal.h:512:       return fpu == this_cpu_read(fpu_fpregs_owner_ctx) &amp;&amp; cpu == fpu-&gt;last_cpu;
|+#NO_APP
|+       cmpq    %rax, -64(%rbp) # pfo_ret__, %sfp

Use this_cpu_read() instead this_cpu_read_stable() to avoid caching of
fpu_fpregs_owner_ctx during preemption points.

The Fixes: tag points to the commit where deferred FPU loading was
added. Since this commit, the compiler is no longer allowed to move the
load of fpu_fpregs_owner_ctx somewhere else / outside of the locked
section. A task preemption will change its value and stale content will
be observed.

 [ bp: Massage. ]

Debugged-by: Austin Clements &lt;austin@google.com&gt;
Debugged-by: David Chase &lt;drchase@golang.org&gt;
Debugged-by: Ian Lance Taylor &lt;ian@airs.com&gt;
Fixes: 5f409e20b7945 ("x86/fpu: Defer FPU state load until return to userspace")
Signed-off-by: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Reviewed-by: Rik van Riel &lt;riel@surriel.com&gt;
Tested-by: Borislav Petkov &lt;bp@suse.de&gt;
Cc: Aubrey Li &lt;aubrey.li@intel.com&gt;
Cc: Austin Clements &lt;austin@google.com&gt;
Cc: Barret Rhoden &lt;brho@google.com&gt;
Cc: Dave Hansen &lt;dave.hansen@intel.com&gt;
Cc: David Chase &lt;drchase@golang.org&gt;
Cc: "H. Peter Anvin" &lt;hpa@zytor.com&gt;
Cc: ian@airs.com
Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Cc: Josh Bleecher Snyder &lt;josharian@gmail.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: x86-ml &lt;x86@kernel.org&gt;
Link: https://lkml.kernel.org/r/20191128085306.hxfa2o3knqtu4wfn@linutronix.de
Link: https://bugzilla.kernel.org/show_bug.cgi?id=205663
</content>
</entry>
<entry>
<title>x86/fpu: Inline fpu__xstate_clear_all_cpu_caps()</title>
<updated>2019-07-07T10:01:47Z</updated>
<author>
<name>Sebastian Andrzej Siewior</name>
</author>
<published>2019-07-04T06:07:43Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7891bc0ab739a31538b5f879a523232b8b07a0d3'/>
<id>urn:sha1:7891bc0ab739a31538b5f879a523232b8b07a0d3</id>
<content type='text'>
All fpu__xstate_clear_all_cpu_caps() does is to invoke one simple
function since commit

  73e3a7d2a7c3b ("x86/fpu: Remove the explicit clearing of XSAVE dependent features")

so invoke that function directly and remove the wrapper.

Signed-off-by: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Signed-off-by: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Link: https://lkml.kernel.org/r/20190704060743.rvew4yrjd6n33uzx@linutronix.de

</content>
</entry>
<entry>
<title>x86/fpu: Don't use current-&gt;mm to check for a kthread</title>
<updated>2019-06-13T18:57:49Z</updated>
<author>
<name>Christoph Hellwig</name>
</author>
<published>2019-06-04T17:54:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8d3289f2fa1e0c7e2f72c7352f1efb75d2ad7c76'/>
<id>urn:sha1:8d3289f2fa1e0c7e2f72c7352f1efb75d2ad7c76</id>
<content type='text'>
current-&gt;mm can be non-NULL if a kthread calls use_mm(). Check for
PF_KTHREAD instead to decide when to store user mode FP state.

Fixes: 2722146eb784 ("x86/fpu: Remove fpu-&gt;initialized")
Reported-by: Peter Zijlstra &lt;peterz@infradead.org&gt;
Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Signed-off-by: Borislav Petkov &lt;bp@suse.de&gt;
Acked-by: Sebastian Andrzej Siewior &lt;bigeasy@linutronix.de&gt;
Cc: Aubrey Li &lt;aubrey.li@intel.com&gt;
Cc: Dave Hansen &lt;dave.hansen@intel.com&gt;
Cc: "H. Peter Anvin" &lt;hpa@zytor.com&gt;
Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Cc: Jann Horn &lt;jannh@google.com&gt;
Cc: Nicolai Stange &lt;nstange@suse.de&gt;
Cc: Rik van Riel &lt;riel@surriel.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: x86-ml &lt;x86@kernel.org&gt;
Link: https://lkml.kernel.org/r/20190604175411.GA27477@lst.de
</content>
</entry>
</feed>
