2022-03-25 01:00:35

by Thomas Gleixner

[permalink] [raw]
Subject: [patch 0/7] x86/fpu: Cure supervisor mode (ENQCMD) fallout

Folks!

The (re)enabling of ENQCMD or the enabling of any supervisor only state
results in a possible inconsistency of the host and guest FPU XSTATE layout
on systems which support that feature.

The reason is that on the host the FPU state has to include supervisor
features while the guest FPU state is strictly user features only.

The problem is restricted to a few places:

1) The size calculation in the dynamic state permission PRCTL which lacks
adding the supervisor state size for calculating the kernel buffer
size.

2) The offset calculations in the copy to/from UABI functions which
use precalculated offsets which are only valid for the host.

The cure is to use runtime calculation for the offsets based on the
XCOMP_BV bitmask in the XSTATE header in case of compacted buffers. For
non-compacted format nothing changes.

The following series addresses this and it turns out to be an overall
valuable cleanup and simplification of the code:

core.c | 3
xstate.c | 211 ++++++++++++++++++---------------------------------------------
2 files changed, 62 insertions(+), 152 deletions(-)

The result of the consolidation of the buffer size calculation (last patch
in the series) is a significant reduction of cycles spent for initializing
XSTATE due to the avoidance of a gazillion redundant CPUID invocations:

Before: XSTATE init: 174344 cycles
After: XSTATE init: 73890 cycles

It builds, boots on host and guest, but is not yet extensively tested.
Testing with a AMX + PASID enabled machine has not been done at all as I
don't have easy access to such a beast.

The series is based on:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/urgent

and available from git:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git x86/fpu

Thanks,

tglx



2022-03-28 22:07:29

by Chang S. Bae

[permalink] [raw]
Subject: Re: [patch 0/7] x86/fpu: Cure supervisor mode (ENQCMD) fallout

On 3/24/2022 6:47 AM, Thomas Gleixner wrote:
>
> It builds, boots on host and guest, but is not yet extensively tested.
> Testing with a AMX + PASID enabled machine has not been done at all as I
> don't have easy access to such a beast.

The AMX tests [1][2] went well on both host and guest. Also dmesg logs
look to be okay:

On host,

$ sudo dmesg | grep fpu
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating
point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x020: 'AVX-512 opmask'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x040: 'AVX-512 Hi256'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x080: 'AVX-512 ZMM_Hi256'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x200: 'Protection Keys
User registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x400: 'PASID state'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x20000: 'AMX Tile config'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x40000: 'AMX Tile data'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: xstate_offset[5]: 832, xstate_sizes[5]: 64
[ 0.000000] x86/fpu: xstate_offset[6]: 896, xstate_sizes[6]: 512
[ 0.000000] x86/fpu: xstate_offset[7]: 1408, xstate_sizes[7]: 1024
[ 0.000000] x86/fpu: xstate_offset[9]: 2432, xstate_sizes[9]: 8
[ 0.000000] x86/fpu: xstate_offset[10]: 2440, xstate_sizes[10]: 8
[ 0.000000] x86/fpu: xstate_offset[17]: 2496, xstate_sizes[17]: 64
[ 0.000000] x86/fpu: xstate_offset[18]: 2560, xstate_sizes[18]: 8192
[ 0.000000] x86/fpu: Enabled xstate features 0x606e7, context size is
10752 bytes, using 'compacted' format.

On guest,
(AMX is available with the upstream Qemu [3].)

$ sudo dmesg | grep fpu
...
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x200: 'Protection Keys
User registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x20000: 'AMX Tile config'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x40000: 'AMX Tile data'
...
[ 0.000000] x86/fpu: xstate_offset[9]: 2432, xstate_sizes[9]: 8
[ 0.000000] x86/fpu: xstate_offset[17]: 2496, xstate_sizes[17]: 64
[ 0.000000] x86/fpu: xstate_offset[18]: 2560, xstate_sizes[18]: 8192
[ 0.000000] x86/fpu: Enabled xstate features 0x602e7, context size is
10752 bytes, using 'compacted' format.

Thanks,
Chang

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git/tree/tools/testing/selftests/x86/amx.c?h=x86/fpu
[2]
https://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git/tree/tools/testing/selftests/kvm/x86_64/amx_test.c?h=x86/fpu
[3]
https://git.qemu.org/?p=qemu.git;a=commit;h=3d31fe4d662f13c70eb7e87f29513623ccd76322

2022-03-28 23:25:18

by Fenghua Yu

[permalink] [raw]
Subject: Re: [patch 0/7] x86/fpu: Cure supervisor mode (ENQCMD) fallout

Hi, Thomas,

On Thu, Mar 24, 2022 at 02:47:07PM +0100, Thomas Gleixner wrote:
> It builds, boots on host and guest, but is not yet extensively tested.
> Testing with a AMX + PASID enabled machine has not been done at all as I
> don't have easy access to such a beast.

I run many copies of dsa_test [1] (i.e. multi-threading and multi-tasking)
to stressfully exercise FPU PASID state context switch on native.
No issue is found so far.

1. https://github.com/intel/idxd-config

Thanks.

-Fenghua