Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2573966imu; Thu, 29 Nov 2018 07:06:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/VzFCnRxOm7Dm4hPwFU1LgGusSV6EgVhoM4Q/VCt5ChN8Kw/eDVpJp5t+eTYyAyH5hhQz0m X-Received: by 2002:a62:8145:: with SMTP id t66mr1726310pfd.55.1543503976796; Thu, 29 Nov 2018 07:06:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543503976; cv=none; d=google.com; s=arc-20160816; b=Z+vxpldAI4FT2r35Bt9/0nlsY3JwaArkSoN1GMx2x5eSUxIK/sD/VHdZQsUr42ngkS ZrAlgdjAnivw0IKWcdM8QdRQayebVH1IoRyd+q3UPqLH1CI5vy/SHmaKU/6hZ5AXQ3mg VKVQm2kJFKTt9hz+Ajhx0iWTnZXkEAT0EleTRGXo8Z59ytUU8aJuVUBk9Je22YceQGrT lDRrTz+SZjykRKZ5fkT9I6rzfPx0m0S2XCrZPPcYDQ6i9s7cW8n5XOfEb3u7ijTTguK8 RKLT6fRd7iBffO4RcKIVRs/aJcWvs1u1MJn4Z/flEVUfPyLrXHvtwF1RNtvjW+tUs9EO rT3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=LfxD6I17Mqcl7f7qXWGK842W1N93nXXux8nxm/Jqc/g=; b=Fd85p4UP9cSPRffW/+tpMJQCCDnjiUNkV32Zqc37VSdK3FW1bHB/3N5aZP76UuPD1P 8fd9i/XoaYGVmEjIAQf79kEL89ZOpUZszBv7U+YOzGIecJSi0Yl7AL/zf9n1OdlUqtnC y2u9o8J8gm07hu+7UNGr6TXjupCRZsKahyTIxTbFb2RQw6tIZ7zMdliwtA9/047xVfA0 BVfIQdFj3YFrjOqIRBAVtt6y+fP95bFw5gxVlKYvB7XLxdu6I7lxDWfB9JkHLyBA+Fet NeWSBwR6lUr+D4fuil5A8y1HLCZQneMrKuW5Fy62ToWQBZTqEqSgFjvhP6EtWInk/B2l dGNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay4si2241466plb.235.2018.11.29.07.06.02; Thu, 29 Nov 2018 07:06:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730341AbeK3CHx convert rfc822-to-8bit (ORCPT + 99 others); Thu, 29 Nov 2018 21:07:53 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:35004 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728787AbeK3CHw (ORCPT ); Thu, 29 Nov 2018 21:07:52 -0500 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1gSNpS-0008Nl-Ao; Thu, 29 Nov 2018 16:02:10 +0100 Date: Thu, 29 Nov 2018 16:02:10 +0100 From: Sebastian Andrzej Siewior To: Rik van Riel Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Dave Hansen Subject: [PATCH 07/29 v2] x86/fpu: don't export __kernel_fpu_{begin|end}() Message-ID: <20181129150210.2k4mawt37ow6c2vq@linutronix.de> References: <20181128222035.2996-1-bigeasy@linutronix.de> <20181128222035.2996-8-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is one user using __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}(), it can be made static and not exported anymore. Reviewed-by: Rik van Riel Signed-off-by: Sebastian Andrzej Siewior --- v1…v2: `carefull' -> `careful' arch/x86/include/asm/efi.h | 6 ++---- arch/x86/include/asm/fpu/api.h | 16 ++++++---------- arch/x86/kernel/fpu/core.c | 6 ++---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index eea40d52ca785..45864898f7e50 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 a9caac9d4a729..e368d8d94ca68 100644 --- a/arch/x86/include/asm/fpu/api.h +++ b/arch/x86/include/asm/fpu/api.h @@ -12,17 +12,13 @@ #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. + * Using the FPU in hardirq is not allowed. */ -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 2ea85b32421a0..2e5003fef51a9 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 = ¤t->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 = ¤t->thread.fpu; @@ -122,7 +121,6 @@ void __kernel_fpu_end(void) kernel_fpu_enable(); } -EXPORT_SYMBOL(__kernel_fpu_end); void kernel_fpu_begin(void) { -- 2.20.0.rc1