]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
x86: initialize use_xsave once
authorKonstantin Belousov <kib@FreeBSD.org>
Tue, 18 Apr 2023 15:50:26 +0000 (18:50 +0300)
committerKonstantin Belousov <kib@FreeBSD.org>
Tue, 18 Apr 2023 23:22:28 +0000 (02:22 +0300)
commit617a11eab6337693eae9d160453adf1943ab6a37
tree13bc325088ac9f1b62c66243d05d27c748de149f
parent93ca6ff2958cace3b7b883ed797ea6539881a6a2
x86: initialize use_xsave once

The explanation from https://reviews.freebsd.org/D39637 by stevek:
The "use_xsave" variable is a global and that is only supposed to be
initialized early before scheduling gets started. However, with the way
the ifuncs for "fpusave" and "fpurestore" are implemented, the value
could be changed at runtime when scheduling is active if "use_xsave"
was set to 0 by the tunable. This leaves a window of opportunity where
"use_xsave" gets re-initialized to 1 and a context switch could occur
with a thread that was not set up to be able to use xsave functionality.
This can lead to an "privileged instruction fault".

The fix is to protect "use_xsave" from being initialized more than once.

Reported and reviewed by: stevek
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D39660
sys/amd64/amd64/fpu.c
sys/amd64/amd64/machdep.c
sys/i386/i386/machdep.c
sys/i386/i386/npx.c