Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7446883imu; Mon, 3 Dec 2018 13:06:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/XGSrj7Oxy3KrHZf8hXhAvTh033cfAnDQvDKj2uEMMo4kHr99iPYQGANFCQeL7tlw2kPG2u X-Received: by 2002:a63:1f4e:: with SMTP id q14mr13954603pgm.88.1543871162968; Mon, 03 Dec 2018 13:06:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543871162; cv=none; d=google.com; s=arc-20160816; b=BjXwUs4qvI5Fs80zRuPT9wVwTj4yI+utVGmxhATUJEAk8fEw4SULfwt+zX2miuuY8d KPj6D9xpa8Sh4FKM4yxnEQGIetHavjSDpu6evcHyqOc+89snMsQEOb7PpWbugfqUeN1x EGkVWBYVOv+6wGOqdXMwMfgdO1HjxPPLGIXcH4Gtxe0KHboD/2SogeFX82ph3ks2G1Mf LPpqWpAhDOfyStXCHjxsEldHze5689z6mjmeMuQ305rie1UW2tneTOOSk1WFa1RZt9n6 lx1BVxuHDazXBm2LQ2mh6GSQavRrYBBcqpHmA7NtHsoLMEmz3u+oS8BlEbM1qa1xWMXn VqjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=jk0Y2jmwlx9gR8/Mwt37nmGaFw/HMj5Fai/y7aOl93c=; b=WC25uTJBm7ubqLm6CzYYNi9T/dHQdkF/+5IF8NT1d8DyH7M/7CVSEyeIbkAbqQXaqJ NsOHYlOJ2KgmIg1tJKI7Hm+NKGmgGvE2X/TjIBPrRCOYzL2IAc5xqb+I1hxiSGT/oGqP 4Vlkp6CpHTjxj1IWeYNk0ZmlvheqV5Dao6n/7UvTWbgoYdkuCfmvY9tRhSUt1ynOHopY /wN0WZi0KMAkTzONXBwU33JCpYET/8TJZSw9hWiujlLoFqhPJp2D+wMBdVvjzHk79d4h Isk015uFi9XRzDPPr6x0JCwZjY+uJ+a3wNqANtEAJJ7UalGMCFL9snTsOGmWeuWpqJfQ n9UQ== 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 o7si14034240pgl.42.2018.12.03.13.05.48; Mon, 03 Dec 2018 13:06:02 -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 S1726119AbeLCVEt (ORCPT + 99 others); Mon, 3 Dec 2018 16:04:49 -0500 Received: from terminus.zytor.com ([198.137.202.136]:36291 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726045AbeLCVEs (ORCPT ); Mon, 3 Dec 2018 16:04:48 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wB3L4PTj596284 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 3 Dec 2018 13:04:25 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wB3L4P4k596281; Mon, 3 Dec 2018 13:04:25 -0800 Date: Mon, 3 Dec 2018 13:04:25 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Sebastian Andrzej Siewior Message-ID: Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, rkrcmar@redhat.com, tglx@linutronix.de, hpa@zytor.com, ard.biesheuvel@linaro.org, bp@suse.de, luto@kernel.org, linux-efi@vger.kernel.org, pbonzini@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, riel@surriel.com, mingo@redhat.com, nstange@suse.de, bigeasy@linutronix.de, kvm@vger.kernel.org, Jason@zx2c4.com Reply-To: dave.hansen@linux.intel.com, mingo@redhat.com, x86@kernel.org, nstange@suse.de, riel@surriel.com, bigeasy@linutronix.de, kvm@vger.kernel.org, Jason@zx2c4.com, linux-kernel@vger.kernel.org, mingo@kernel.org, rkrcmar@redhat.com, hpa@zytor.com, tglx@linutronix.de, ard.biesheuvel@linaro.org, luto@kernel.org, bp@suse.de, linux-efi@vger.kernel.org, pbonzini@redhat.com In-Reply-To: <20181129150210.2k4mawt37ow6c2vq@linutronix.de> References: <20181129150210.2k4mawt37ow6c2vq@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/fpu] x86/fpu: Don't export __kernel_fpu_{begin,end}() Git-Commit-ID: 7d79adb87fa79e4a4c59424fd5b5a922861fc5f6 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7d79adb87fa79e4a4c59424fd5b5a922861fc5f6 Gitweb: https://git.kernel.org/tip/7d79adb87fa79e4a4c59424fd5b5a922861fc5f6 Author: Sebastian Andrzej Siewior AuthorDate: Thu, 29 Nov 2018 16:02:10 +0100 Committer: Borislav Petkov CommitDate: Mon, 3 Dec 2018 19:37:27 +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 Signed-off-by: Borislav Petkov Reviewed-by: Rik van Riel Cc: "H. Peter Anvin" Cc: "Jason A. Donenfeld" Cc: Andy Lutomirski Cc: Ard Biesheuvel Cc: Dave Hansen Cc: Ingo Molnar Cc: Nicolai Stange Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Thomas Gleixner Cc: kvm ML Cc: linux-efi Cc: x86-ml Link: https://lkml.kernel.org/r/20181129150210.2k4mawt37ow6c2vq@linutronix.de --- 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 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..e368d8d94ca6 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 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 = ¤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) {