]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - pending/x86-fpu-don-t-export-__kernel_fpu_-begin-end.patch
5.0-stable patches
[thirdparty/kernel/stable-queue.git] / pending / x86-fpu-don-t-export-__kernel_fpu_-begin-end.patch
1 From 12209993e98c5fa1855c467f22a24e3d5b8be205 Mon Sep 17 00:00:00 2001
2 From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
3 Date: Thu, 29 Nov 2018 16:02:10 +0100
4 Subject: x86/fpu: Don't export __kernel_fpu_{begin,end}()
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
10
11 commit 12209993e98c5fa1855c467f22a24e3d5b8be205 upstream.
12
13 There is one user of __kernel_fpu_begin() and before invoking it,
14 it invokes preempt_disable(). So it could invoke kernel_fpu_begin()
15 right away. The 32bit version of arch_efi_call_virt_setup() and
16 arch_efi_call_virt_teardown() does this already.
17
18 The comment above *kernel_fpu*() claims that before invoking
19 __kernel_fpu_begin() preemption should be disabled and that KVM is a
20 good example of doing it. Well, KVM doesn't do that since commit
21
22 f775b13eedee2 ("x86,kvm: move qemu/guest FPU switching out to vcpu_run")
23
24 so it is not an example anymore.
25
26 With EFI gone as the last user of __kernel_fpu_{begin|end}(), both can
27 be made static and not exported anymore.
28
29 Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
30 Signed-off-by: Borislav Petkov <bp@suse.de>
31 Reviewed-by: Rik van Riel <riel@surriel.com>
32 Cc: "H. Peter Anvin" <hpa@zytor.com>
33 Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
34 Cc: Andy Lutomirski <luto@kernel.org>
35 Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
36 Cc: Dave Hansen <dave.hansen@linux.intel.com>
37 Cc: Ingo Molnar <mingo@redhat.com>
38 Cc: Nicolai Stange <nstange@suse.de>
39 Cc: Paolo Bonzini <pbonzini@redhat.com>
40 Cc: Radim Krčmář <rkrcmar@redhat.com>
41 Cc: Thomas Gleixner <tglx@linutronix.de>
42 Cc: kvm ML <kvm@vger.kernel.org>
43 Cc: linux-efi <linux-efi@vger.kernel.org>
44 Cc: x86-ml <x86@kernel.org>
45 Link: https://lkml.kernel.org/r/20181129150210.2k4mawt37ow6c2vq@linutronix.de
46 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
47
48 diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
49 index eea40d52ca78..45864898f7e5 100644
50 --- a/arch/x86/include/asm/efi.h
51 +++ b/arch/x86/include/asm/efi.h
52 @@ -82,8 +82,7 @@ struct efi_scratch {
53 #define arch_efi_call_virt_setup() \
54 ({ \
55 efi_sync_low_kernel_mappings(); \
56 - preempt_disable(); \
57 - __kernel_fpu_begin(); \
58 + kernel_fpu_begin(); \
59 firmware_restrict_branch_speculation_start(); \
60 \
61 if (!efi_enabled(EFI_OLD_MEMMAP)) \
62 @@ -99,8 +98,7 @@ struct efi_scratch {
63 efi_switch_mm(efi_scratch.prev_mm); \
64 \
65 firmware_restrict_branch_speculation_end(); \
66 - __kernel_fpu_end(); \
67 - preempt_enable(); \
68 + kernel_fpu_end(); \
69 })
70
71 extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
72 diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
73 index a9caac9d4a72..b56d504af654 100644
74 --- a/arch/x86/include/asm/fpu/api.h
75 +++ b/arch/x86/include/asm/fpu/api.h
76 @@ -12,17 +12,12 @@
77 #define _ASM_X86_FPU_API_H
78
79 /*
80 - * Careful: __kernel_fpu_begin/end() must be called with preempt disabled
81 - * and they don't touch the preempt state on their own.
82 - * If you enable preemption after __kernel_fpu_begin(), preempt notifier
83 - * should call the __kernel_fpu_end() to prevent the kernel/user FPU
84 - * state from getting corrupted. KVM for example uses this model.
85 - *
86 - * All other cases use kernel_fpu_begin/end() which disable preemption
87 - * during kernel FPU usage.
88 + * Use kernel_fpu_begin/end() if you intend to use FPU in kernel context. It
89 + * disables preemption so be careful if you intend to use it for long periods
90 + * of time.
91 + * If you intend to use the FPU in softirq you need to check first with
92 + * irq_fpu_usable() if it is possible.
93 */
94 -extern void __kernel_fpu_begin(void);
95 -extern void __kernel_fpu_end(void);
96 extern void kernel_fpu_begin(void);
97 extern void kernel_fpu_end(void);
98 extern bool irq_fpu_usable(void);
99 diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
100 index 2ea85b32421a..2e5003fef51a 100644
101 --- a/arch/x86/kernel/fpu/core.c
102 +++ b/arch/x86/kernel/fpu/core.c
103 @@ -93,7 +93,7 @@ bool irq_fpu_usable(void)
104 }
105 EXPORT_SYMBOL(irq_fpu_usable);
106
107 -void __kernel_fpu_begin(void)
108 +static void __kernel_fpu_begin(void)
109 {
110 struct fpu *fpu = &current->thread.fpu;
111
112 @@ -111,9 +111,8 @@ void __kernel_fpu_begin(void)
113 __cpu_invalidate_fpregs_state();
114 }
115 }
116 -EXPORT_SYMBOL(__kernel_fpu_begin);
117
118 -void __kernel_fpu_end(void)
119 +static void __kernel_fpu_end(void)
120 {
121 struct fpu *fpu = &current->thread.fpu;
122
123 @@ -122,7 +121,6 @@ void __kernel_fpu_end(void)
124
125 kernel_fpu_enable();
126 }
127 -EXPORT_SYMBOL(__kernel_fpu_end);
128
129 void kernel_fpu_begin(void)
130 {