linux/Documentation/x86
Dave Hansen 30d02551ba x86/fpu: Optimize out sigframe xfeatures when in init state
tl;dr: AMX state is ~8k.  Signal frames can have space for this
~8k and each signal entry writes out all 8k even if it is zeros.
Skip writing zeros for AMX to speed up signal delivery by about
4% overall when AMX is in its init state.

This is a user-visible change to the sigframe ABI.

== Hardware XSAVE Background ==

XSAVE state components may be tracked by the processor as being
in their initial configuration.  Software can detect which
features are in this configuration by looking at the XSTATE_BV
field in an XSAVE buffer or with the XGETBV(1) instruction.

Both the XSAVE and XSAVEOPT instructions enumerate features s
being in the initial configuration via the XSTATE_BV field in the
XSAVE header,  However, XSAVEOPT declines to actually write
features in their initial configuration to the buffer.  XSAVE
writes the feature unconditionally, regardless of whether it is
in the initial configuration or not.

Basically, XSAVE users never need to inspect XSTATE_BV to
determine if the feature has been written to the buffer.
XSAVEOPT users *do* need to inspect XSTATE_BV.  They might also
need to clear out the buffer if they want to make an isolated
change to the state, like modifying one register.

== Software Signal / XSAVE Background ==

Signal frames have historically been written with XSAVE itself.
Each state is written in its entirety, regardless of being in its
initial configuration.

In other words, the signal frame ABI uses the XSAVE behavior, not
the XSAVEOPT behavior.

== Problem ==

This means that any application which has acquired permission to
use AMX via ARCH_REQ_XCOMP_PERM will write 8k of state to the
signal frame.  This 8k write will occur even when AMX was in its
initial configuration and software *knows* this because of
XSTATE_BV.

This problem also exists to a lesser degree with AVX-512 and its
2k of state.  However, AVX-512 use does not require
ARCH_REQ_XCOMP_PERM and is more likely to have existing users
which would be impacted by any change in behavior.

== Solution ==

Stop writing out AMX xfeatures which are in their initial state
to the signal frame.  This effectively makes the signal frame
XSAVE buffer look as if it were written with a combination of
XSAVEOPT and XSAVE behavior.  Userspace which handles XSAVEOPT-
style buffers should be able to handle this naturally.

For now, include only the AMX xfeatures: XTILE and XTILEDATA in
this new behavior.  These require new ABI to use anyway, which
makes their users very unlikely to be broken.  This XSAVEOPT-like
behavior should be expected for all future dynamic xfeatures.  It
may also be extended to legacy features like AVX-512 in the
future.

Only attempt this optimization on systems with dynamic features.
Disable dynamic feature support (XFD) if XGETBV1 is unavailable
by adding a CPUID dependency.

This has been measured to reduce the *overall* cycle cost of
signal delivery by about 4%.

Fixes: 2308ee57d9 ("x86/fpu/amx: Enable the AMX feature in 64-bit mode")
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: "Chang S. Bae" <chang.seok.bae@intel.com>
Link: https://lore.kernel.org/r/20211102224750.FA412E26@davehans-spike.ostc.intel.com
2021-11-03 22:42:35 +01:00
..
i386 Documentation: x86: convert i386/IO-APIC.txt to reST 2019-05-08 14:34:11 -06:00
x86_64 Another collection of documentation patches, mostly fixes but also includes 2021-09-08 16:28:14 -07:00
amd-memory-encryption.rst x86/msr: Rename MSR_K8_SYSCFG to MSR_AMD64_SYSCFG 2021-05-10 07:51:38 +02:00
boot.rst docs: x86: avoid using ReST :doc:foo markup 2021-06-17 13:24:39 -06:00
booting-dt.rst dt: Remove booting-without-of.rst 2020-10-13 13:33:16 -05:00
buslock.rst Documentation/x86: Add ratelimit in buslock.rst 2021-05-18 16:39:31 +02:00
cpuinfo.rst Documentation/x86: Add documentation for /proc/cpuinfo feature flags 2020-09-01 11:07:15 +02:00
earlyprintk.rst Documentation: x86: earlyprintk: drop doubled words 2020-07-13 09:47:38 -06:00
elf_auxvec.rst x86/elf: Support a new ELF aux vector AT_MINSIGSTKSZ 2021-05-19 12:18:45 +02:00
entry_64.rst Documentation: x86: convert entry_64.txt to reST 2019-05-08 14:34:09 -06:00
exception-tables.rst Merge branch 'x86-cleanups-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2020-03-31 11:04:05 -07:00
features.rst docs: archis: add a per-architecture features list 2020-12-03 15:10:15 -07:00
index.rst Documentation/x86: Add documentation for using dynamic XSTATE features 2021-10-28 14:54:58 +02:00
intel_txt.rst docs: x86: move two x86-specific files to x86 arch dir 2019-07-15 11:03:01 -03:00
intel-iommu.rst docs: prevent warnings due to autosectionlabel 2020-03-20 17:01:29 -06:00
kernel-stacks.rst Some late arriving documentation changes. In particular, this contains the 2019-05-10 13:24:53 -04:00
mds.rst x86/speculation/mds: Improve CPU buffer clear documentation 2019-05-16 09:05:12 +02:00
microcode.rst Documentation: x86: convert microcode.txt to reST 2019-05-08 14:34:11 -06:00
mtrr.rst docs: x86: avoid using ReST :doc:foo markup 2021-06-17 13:24:39 -06:00
orc-unwinder.rst Documentation: x86: convert orc-unwinder.txt to reST 2019-05-08 14:34:11 -06:00
pat.rst remove ioremap_nocache and devm_ioremap_nocache 2020-01-06 09:45:59 +01:00
pti.rst Documentation: x86: convert pti.txt to reST 2019-05-08 14:34:10 -06:00
resctrl.rst Documentation/x86: Rename resctrl_ui.rst and add two errata to the file 2020-10-27 16:47:00 +01:00
sgx.rst x86/sgx/virt: implement SGX_IOC_VEPC_REMOVE ioctl 2021-10-22 08:32:12 -07:00
sva.rst Documentation/x86: Add documentation for SVA (Shared Virtual Addressing) 2020-09-17 19:29:42 +02:00
tlb.rst Documentation: x86: convert tlb.txt to reST 2019-05-08 14:34:10 -06:00
topology.rst x86/CPU/AMD: Save AMD NodeId as cpu_die_id 2020-11-19 11:43:13 +01:00
tsx_async_abort.rst x86/speculation/taa: Add documentation for TSX Async Abort 2019-10-28 08:37:00 +01:00
usb-legacy-support.rst Documentation: x86: convert usb-legacy-support.txt to reST 2019-05-08 14:34:11 -06:00
xstate.rst x86/fpu: Optimize out sigframe xfeatures when in init state 2021-11-03 22:42:35 +01:00
zero-page.rst Documentation: x86: convert zero-page.txt to reST 2019-05-08 14:34:10 -06:00