LKML Archive on lore.kernel.org
 help / Atom feed
From: Marc Dionne <marc.c.dionne@gmail.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: x86/fpu: Don't export __kernel_fpu_{begin,end}()
Date: Mon, 7 Jan 2019 18:08:26 -0400
Message-ID: <CAB9dFdsZb-sZixeOzrt8F50h1pnUK2W2Cxx8+xjhgd0=6xs7iw@mail.gmail.com> (raw)
In-Reply-To: <git-mailbomb-linux-master-12209993e98c5fa1855c467f22a24e3d5b8be205@kernel.org>

On Thu, Dec 27, 2018 at 11:20 AM Linux Kernel Mailing List
<linux-kernel@vger.kernel.org> wrote:
>
> Commit:     12209993e98c5fa1855c467f22a24e3d5b8be205
> Parent:     2f2fcc40a961ed04f0e130803fbaa868c2899310
> Refname:    refs/heads/master
> Web:        https://git.kernel.org/torvalds/c/12209993e98c5fa1855c467f22a24e3d5b8be205
> Author:     Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> AuthorDate: Thu Nov 29 16:02:10 2018 +0100
> Committer:  Borislav Petkov <bp@suse.de>
> CommitDate: Tue Dec 4 12:37:28 2018 +0100
>
>     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
>
>       f775b13eedee2 ("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
> ---
>  arch/x86/include/asm/efi.h     |  6 ++----
>  arch/x86/include/asm/fpu/api.h | 15 +++++----------
>  arch/x86/kernel/fpu/core.c     |  6 ++----
>  3 files changed, 9 insertions(+), 18 deletions(-)
>
> diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
> index eea40d52ca78..45864898f7e5 100644
> --- a/arch/x86/include/asm/efi.h
> +++ b/arch/x86/include/asm/efi.h
> @@ -82,8 +82,7 @@ struct efi_scratch {
>  #define arch_efi_call_virt_setup()                                     \
>  ({                                                                     \
>         efi_sync_low_kernel_mappings();                                 \
> -       preempt_disable();                                              \
> -       __kernel_fpu_begin();                                           \
> +       kernel_fpu_begin();                                             \
>         firmware_restrict_branch_speculation_start();                   \
>                                                                         \
>         if (!efi_enabled(EFI_OLD_MEMMAP))                               \
> @@ -99,8 +98,7 @@ struct efi_scratch {
>                 efi_switch_mm(efi_scratch.prev_mm);                     \
>                                                                         \
>         firmware_restrict_branch_speculation_end();                     \
> -       __kernel_fpu_end();                                             \
> -       preempt_enable();                                               \
> +       kernel_fpu_end();                                               \
>  })
>
>  extern void __iomem *__init efi_ioremap(unsigned long addr, unsigned long size,
> diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h
> index a9caac9d4a72..b56d504af654 100644
> --- a/arch/x86/include/asm/fpu/api.h
> +++ b/arch/x86/include/asm/fpu/api.h
> @@ -12,17 +12,12 @@
>  #define _ASM_X86_FPU_API_H
>
>  /*
> - * Careful: __kernel_fpu_begin/end() must be called with preempt disabled
> - * and they don't touch the preempt state on their own.
> - * If you enable preemption after __kernel_fpu_begin(), preempt notifier
> - * should call the __kernel_fpu_end() to prevent the kernel/user FPU
> - * state from getting corrupted. KVM for example uses this model.
> - *
> - * All other cases use kernel_fpu_begin/end() which disable preemption
> - * during kernel FPU usage.
> + * Use kernel_fpu_begin/end() if you intend to use FPU in kernel context. It
> + * disables preemption so be careful if you intend to use it for long periods
> + * of time.
> + * If you intend to use the FPU in softirq you need to check first with
> + * irq_fpu_usable() if it is possible.
>   */
> -extern void __kernel_fpu_begin(void);
> -extern void __kernel_fpu_end(void);
>  extern void kernel_fpu_begin(void);
>  extern void kernel_fpu_end(void);
>  extern bool irq_fpu_usable(void);
> diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
> index 2ea85b32421a..2e5003fef51a 100644
> --- a/arch/x86/kernel/fpu/core.c
> +++ b/arch/x86/kernel/fpu/core.c
> @@ -93,7 +93,7 @@ bool irq_fpu_usable(void)
>  }
>  EXPORT_SYMBOL(irq_fpu_usable);
>
> -void __kernel_fpu_begin(void)
> +static void __kernel_fpu_begin(void)
>  {
>         struct fpu *fpu = &current->thread.fpu;
>
> @@ -111,9 +111,8 @@ void __kernel_fpu_begin(void)
>                 __cpu_invalidate_fpregs_state();
>         }
>  }
> -EXPORT_SYMBOL(__kernel_fpu_begin);
>
> -void __kernel_fpu_end(void)
> +static void __kernel_fpu_end(void)
>  {
>         struct fpu *fpu = &current->thread.fpu;
>
> @@ -122,7 +121,6 @@ void __kernel_fpu_end(void)
>
>         kernel_fpu_enable();
>  }
> -EXPORT_SYMBOL(__kernel_fpu_end);
>
>  void kernel_fpu_begin(void)
>  {

This commit removes an exported function pair that is currently used
by out of tree modules, while the replacement pair
(kernel_fpu_begin/end) is EXPORT_SYMBOL_GPL.  So this is making
existing functionality GPL only, which will probably be an issue for
several out of tree modules that use the fpu.

Could kernel_fpu_begin/end be made plain EXPORT_SYMBOL?

Marc

       reply index

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <git-mailbomb-linux-master-12209993e98c5fa1855c467f22a24e3d5b8be205@kernel.org>
2019-01-07 22:08 ` Marc Dionne [this message]
2019-01-09 11:19   ` Sebastian Andrzej Siewior
2019-01-09 16:52     ` Greg Kroah-Hartman
2019-01-09 17:09       ` Sebastian Andrzej Siewior
2019-01-09 17:40         ` Marc Dionne
2019-01-10 13:13           ` Greg Kroah-Hartman
2019-01-10 13:11         ` Greg Kroah-Hartman
2019-01-10 17:32           ` Hutter, Tony
2019-01-10 18:07             ` Sebastian Andrzej Siewior
2019-01-10 18:24               ` Greg Kroah-Hartman
2019-01-11  3:18                 ` Kash Pande
2019-01-11  5:04                 ` Lukas Wunner
2019-01-11  5:40                   ` Greg Kroah-Hartman
2019-01-11 18:06                     ` Lukas Wunner
2019-01-23 15:58                     ` Pavel Machek
2019-01-15 13:01                 ` Rene Schickbauer
2019-01-15 13:32                   ` Christoph Hellwig
2019-01-15 13:42                   ` Greg Kroah-Hartman
2019-01-15 18:51                     ` Kash Pande
2019-01-21 12:30                     ` Stephan von Krawczynski
2019-01-15 18:26                 ` Kash Pande
2019-01-11  3:07 Kash Pande
     [not found] <20190111054058.GA27966 () kroah ! com>
2019-01-11  6:24 ` Kash Pande

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAB9dFdsZb-sZixeOzrt8F50h1pnUK2W2Cxx8+xjhgd0=6xs7iw@mail.gmail.com' \
    --to=marc.c.dionne@gmail.com \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox