x86/entry: Fix AC assertion
PATCH 1/1 x86/entry: Fix AC assertion
The WARN added in commit 3c73b81a9164 ("x86/entry, selftests: Further improve user entry sanity checks") unconditionally triggers on my IVB machine because it does not support SMAP.
For !SMAP hardware we patch out CLAC/STAC instructions and thus if userspace sets AC, we'll still have it set after entry.
--- arch/x86/include/asm/entry-common.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/x86/include/asm/entry-common.h +9 -2
@@ -18,8 +18,15 @@ static __always_inline void arch_check_u* state, not the interrupt state as imagined by Xen. */ unsigned long flags =native_save_fl (); -WARN_ON_ONCE (flags & (X86_EFLAGS_AC |X86_EFLAGS_DF | -X86_EFLAGS_NT )); +unsigned long mask =X86_EFLAGS_DF |X86_EFLAGS_NT ; + +/* +* For !SMAP hardware we patch out CLAC on entry. +*/ +if (boot_cpu_has (X86_FEATURE_SMAP )) + mask |=X86_EFLAGS_AC ; + +WARN_ON_ONCE (flags & mask);/* We think we came from user mode. Make sure pt_regs agrees. */ WARN_ON_ONCE (!user_mode (regs));
Quoted 6 lines · On 24/08/2020 11:14, [email protected] wrote:
The WARN added in commit
3c73b81a9164("x86/entry, selftests: Further improve user entry sanity checks") unconditionally triggers on my IVB machine because it does not support SMAP.For !SMAP hardware we patch out CLAC/STAC instructions and thus if userspace sets AC, we'll still have it set after entry.
Technically, you don't patch in, rather than patch out.
Quoted 13 lines
Fixes 3c73b81a9164 ("x86/entry, selftests: Further improve user entry sanity checks")Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Andy Lutomirski <[email protected]>--- arch/x86/include/asm/entry-common.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)arch/x86/include/asm/entry-common.h +0
-0@@ -18,8 +18,15 @@ static __always_inline void arch_check_u* state, not the interrupt state as imagined by Xen. */
arch/x86/include/asm/entry-common.h static __always_inline void arch_check_u · line 27
Quoted 10 lines
arch/x86/include/asm/entry-common.h +7
-2unsigned long flags =native_save_fl (); -WARN_ON_ONCE (flags & (X86_EFLAGS_AC |X86_EFLAGS_DF | -X86_EFLAGS_NT )); +unsigned long mask =X86_EFLAGS_DF |X86_EFLAGS_NT ; + +/* +* For !SMAP hardware we patch out CLAC on entry. +*/ +if (boot_cpu_has (X86_FEATURE_SMAP )) + mask |=X86_EFLAGS_AC ;
The Xen PV ABI clears AC on entry for 64bit guests, because Linux is actually running in Ring 3, and therefore susceptible to #AC's which wouldn't occur natively.
~Andrew
Quoted 9 lines · Andrew Cooper
Quoted 6 lines · On 24/08/2020 11:14, [email protected] wrote:
The WARN added in commit
3c73b81a9164("x86/entry, selftests: Further improve user entry sanity checks") unconditionally triggers on my IVB machine because it does not support SMAP.For !SMAP hardware we patch out CLAC/STAC instructions and thus if userspace sets AC, we'll still have it set after entry.
Technically, you don't patch in, rather than patch out.
True.
Quoted 18 lines
Quoted 18 lines
Fixes 3c73b81a9164 ("x86/entry, selftests: Further improve user entry sanity checks")Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Andy Lutomirski <[email protected]>--- arch/x86/include/asm/entry-common.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)arch/x86/include/asm/entry-common.h +3
-2@@ -18,8 +18,15 @@ static __always_inline void arch_check_u* state, not the interrupt state as imagined by Xen. */ unsigned long flags =native_save_fl (); -WARN_ON_ONCE (flags & (X86_EFLAGS_AC |X86_EFLAGS_DF | -X86_EFLAGS_NT )); +unsigned long mask =X86_EFLAGS_DF |X86_EFLAGS_NT ; + +/*
Quoted 8 lines
arch/x86/include/asm/entry-common.h static __always_inline void arch_check_u · line 27
Quoted 4 lines
arch/x86/include/asm/entry-common.h +4
-0+* For !SMAP hardware we patch out CLAC on entry. +*/ +if (boot_cpu_has (X86_FEATURE_SMAP )) + mask |=X86_EFLAGS_AC ;The Xen PV ABI clears AC on entry for 64bit guests, because Linux is actually running in Ring 3, and therefore susceptible to #AC's which wouldn't occur natively.
So do you then want it to be something like:
if (boot_cpu_has(X86_FEATURE_SMAP) || (IS_ENABLED(CONFIG_64_BIT) && boot_cpu_has(X86_FEATURE_XENPV)))
? Or are you fine with the proposed?
Quoted 36 lines · On 24/08/2020 16:21, [email protected] wrote:
Quoted 8 lines · Andrew Cooper
Quoted 6 lines · On 24/08/2020 11:14, [email protected] wrote:
The WARN added in commit
3c73b81a9164("x86/entry, selftests: Further improve user entry sanity checks") unconditionally triggers on my IVB machine because it does not support SMAP.For !SMAP hardware we patch out CLAC/STAC instructions and thus if userspace sets AC, we'll still have it set after entry.
Technically, you don't patch in, rather than patch out.
True.
Quoted 17 lines
Quoted 17 lines
Fixes 3c73b81a9164 ("x86/entry, selftests: Further improve user entry sanity checks")Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Andy Lutomirski <[email protected]>--- arch/x86/include/asm/entry-common.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)arch/x86/include/asm/entry-common.h +2
-2@@ -18,8 +18,15 @@ static __always_inline void arch_check_u* state, not the interrupt state as imagined by Xen. */ unsigned long flags =native_save_fl (); -WARN_ON_ONCE (flags & (X86_EFLAGS_AC |X86_EFLAGS_DF | -X86_EFLAGS_NT )); +unsigned long mask =X86_EFLAGS_DF |X86_EFLAGS_NT ; +Quoted 8 lines
arch/x86/include/asm/entry-common.h static __always_inline void arch_check_u · line 27
Quoted 5 lines
arch/x86/include/asm/entry-common.h +5
-0+/* +* For !SMAP hardware we patch out CLAC on entry. +*/ +if (boot_cpu_has (X86_FEATURE_SMAP )) + mask |=X86_EFLAGS_AC ;The Xen PV ABI clears AC on entry for 64bit guests, because Linux is actually running in Ring 3, and therefore susceptible to #AC's which wouldn't occur natively.
Quoted 6 lines
So do you then want it to be something like:
if (boot_cpu_has(X86_FEATURE_SMAP) || (IS_ENABLED(CONFIG_64_BIT) && boot_cpu_has(X86_FEATURE_XENPV)))? Or are you fine with the proposed?
Dealers choice, but this option would be slightly better overall.
(Are there any other cases where Linux will be running in Ring 3? I haven't been paying attention to recent changes in PVOps.)
~Andrew
Quoted 42 lines · Andrew Cooper
Quoted 41 lines · On 24/08/2020 16:21, [email protected] wrote:
Quoted 8 lines · Andrew Cooper
Quoted 6 lines · On 24/08/2020 11:14, [email protected] wrote:
The WARN added in commit
3c73b81a9164("x86/entry, selftests: Further improve user entry sanity checks") unconditionally triggers on my IVB machine because it does not support SMAP.For !SMAP hardware we patch out CLAC/STAC instructions and thus if userspace sets AC, we'll still have it set after entry.
Technically, you don't patch in, rather than patch out.
True.
Quoted 17 lines
Quoted 17 lines
Fixes 3c73b81a9164 ("x86/entry, selftests: Further improve user entry sanity checks")Signed-off-by Peter Zijlstra (Intel) <[email protected]>Acked-by Andy Lutomirski <[email protected]>--- arch/x86/include/asm/entry-common.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)arch/x86/include/asm/entry-common.h +2
-2@@ -18,8 +18,15 @@ static __always_inline void arch_check_u* state, not the interrupt state as imagined by Xen. */ unsigned long flags =native_save_fl (); -WARN_ON_ONCE (flags & (X86_EFLAGS_AC |X86_EFLAGS_DF | -X86_EFLAGS_NT )); +unsigned long mask =X86_EFLAGS_DF |X86_EFLAGS_NT ; +Quoted 8 lines
arch/x86/include/asm/entry-common.h static __always_inline void arch_check_u · line 27
Quoted 5 lines
arch/x86/include/asm/entry-common.h +5
-0+/* +* For !SMAP hardware we patch out CLAC on entry. +*/ +if (boot_cpu_has (X86_FEATURE_SMAP )) + mask |=X86_EFLAGS_AC ;The Xen PV ABI clears AC on entry for 64bit guests, because Linux is actually running in Ring 3, and therefore susceptible to #AC's which wouldn't occur natively.
So do you then want it to be something like:
if (boot_cpu_has(X86_FEATURE_SMAP) || (IS_ENABLED(CONFIG_64_BIT) && boot_cpu_has(X86_FEATURE_XENPV)))
Quoted 6 lines
Quoted 1 line
? Or are you fine with the proposed?
Dealers choice, but this option would be slightly better overall.
(Are there any other cases where Linux will be running in Ring 3? I haven't been paying attention to recent changes in PVOps.)
I'm not aware of any other case running kernel code in ring 3.
Juergen