Skip to content

Commit 1220999

Browse files
Sebastian Andrzej Siewiorsuryasaimadhu
authored andcommitted
x86/fpu: Don't export __kernel_fpu_{begin,end}()
There is one user of __kernel_fpu_begin() and before invoking it, it invokes preempt_disable(). So it could invoke kernel_fpu_begin() right away. The 32bit version of arch_efi_call_virt_setup() and arch_efi_call_virt_teardown() does this already. The comment above *kernel_fpu*() claims that before invoking __kernel_fpu_begin() preemption should be disabled and that KVM is a good example of doing it. Well, KVM doesn't do that since commit f775b13 ("x86,kvm: move qemu/guest FPU switching out to vcpu_run") so it is not an example anymore. With EFI gone as the last user of __kernel_fpu_{begin|end}(), both can be made static and not exported anymore. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: Rik van Riel <riel@surriel.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: "Jason A. Donenfeld" <Jason@zx2c4.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Nicolai Stange <nstange@suse.de> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: kvm ML <kvm@vger.kernel.org> Cc: linux-efi <linux-efi@vger.kernel.org> Cc: x86-ml <x86@kernel.org> Link: https://lkml.kernel.org/r/20181129150210.2k4mawt37ow6c2vq@linutronix.de
1 parent 2f2fcc4 commit 1220999

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

arch/x86/include/asm/efi.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ struct efi_scratch {
8282
#define arch_efi_call_virt_setup() \
8383
({ \
8484
efi_sync_low_kernel_mappings(); \
85-
preempt_disable(); \
86-
__kernel_fpu_begin(); \
85+
kernel_fpu_begin(); \
8786
firmware_restrict_branch_speculation_start(); \
8887
\
8988
if (!efi_enabled(EFI_OLD_MEMMAP)) \
@@ -99,8 +98,7 @@ struct efi_scratch {
9998
efi_switch_mm(efi_scratch.prev_mm); \
10099
\
101100
firmware_restrict_branch_speculation_end(); \
102-
__kernel_fpu_end(); \
103-
preempt_enable(); \
101+
kernel_fpu_end(); \
104102
})
105103

106104
extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,

arch/x86/include/asm/fpu/api.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@
1212
#define _ASM_X86_FPU_API_H
1313

1414
/*
15-
* Careful: __kernel_fpu_begin/end() must be called with preempt disabled
16-
* and they don't touch the preempt state on their own.
17-
* If you enable preemption after __kernel_fpu_begin(), preempt notifier
18-
* should call the __kernel_fpu_end() to prevent the kernel/user FPU
19-
* state from getting corrupted. KVM for example uses this model.
20-
*
21-
* All other cases use kernel_fpu_begin/end() which disable preemption
22-
* during kernel FPU usage.
15+
* Use kernel_fpu_begin/end() if you intend to use FPU in kernel context. It
16+
* disables preemption so be careful if you intend to use it for long periods
17+
* of time.
18+
* If you intend to use the FPU in softirq you need to check first with
19+
* irq_fpu_usable() if it is possible.
2320
*/
24-
extern void __kernel_fpu_begin(void);
25-
extern void __kernel_fpu_end(void);
2621
extern void kernel_fpu_begin(void);
2722
extern void kernel_fpu_end(void);
2823
extern bool irq_fpu_usable(void);

arch/x86/kernel/fpu/core.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool irq_fpu_usable(void)
9393
}
9494
EXPORT_SYMBOL(irq_fpu_usable);
9595

96-
void __kernel_fpu_begin(void)
96+
static void __kernel_fpu_begin(void)
9797
{
9898
struct fpu *fpu = &current->thread.fpu;
9999

@@ -111,9 +111,8 @@ void __kernel_fpu_begin(void)
111111
__cpu_invalidate_fpregs_state();
112112
}
113113
}
114-
EXPORT_SYMBOL(__kernel_fpu_begin);
115114

116-
void __kernel_fpu_end(void)
115+
static void __kernel_fpu_end(void)
117116
{
118117
struct fpu *fpu = &current->thread.fpu;
119118

@@ -122,7 +121,6 @@ void __kernel_fpu_end(void)
122121

123122
kernel_fpu_enable();
124123
}
125-
EXPORT_SYMBOL(__kernel_fpu_end);
126124

127125
void kernel_fpu_begin(void)
128126
{

0 commit comments

Comments
 (0)