Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4816308yba; Tue, 30 Apr 2019 05:00:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNTge9arAQk7qiKFqRejcdFnVEZXdooOU76owPVhiIVHSruI4BqoeucAD8ScmMSas7K+58 X-Received: by 2002:a65:478a:: with SMTP id e10mr27020035pgs.310.1556625630101; Tue, 30 Apr 2019 05:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556625630; cv=none; d=google.com; s=arc-20160816; b=salQ6vKoviuEJL3Thm473JNU2QryI80gEyIEfSqFdRy9atkPbUra6E4+I95i3i7Z4w c8Bhg0dmHCsABe5V/zzhk+KgmZWENza+SVoEP89hpYw1cmbn3BcfiOIoVLQzxeJiQEYs PUEM8qTTZzzJgYoX8gu26Sz9g60+KqJ8HlrTyMjm1MkbpxzlzfEQoZ0eaBmoGs3cda7Z 1FOQDAfnP2o2ee7kZkyJ4WaZrapUIMyY3S03k6QcsNREJagB0fDkSW3b6NTAtfqzbl8N fNtArIhj8aE5pUk4cfUF++FFlX0MTYcH1vtZeV6IBoHHKAKMkSgTtlRCXC777R/fR6Ov +U9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/9sdUiPRqk3epMw+Dg8I9rVCXBJ6NPzCYsF0rZZGXWA=; b=q2oQKUaF+BQH86s9a0XPW1TUBvyNHdj0khUp8MuuM6RtqmWJq9pEod5MILUFkStVHR xfysh/vNODGhFFt5lw+GWR3O/i64d1qBDQr/cAVMyxQY9nToy9NhVYy7BNyDWv+uwryC JkdQ4oROf+wxIi5U/QYsFAnPiDOJU+OGjrcU6KUbRJlGey0bpHTtZeqXwxL1NmhlWxu6 PniN6I7nLnmHs0dZQ8mfkQ1YiCRt1X+UKE5vSaBPu70DyiZmqUmLBMCCY/uJb9JABf9S K0V0Nc4ohx+u41azhNkqhD8w4Lm0nPzBMAGSHyvFPLVd0J/2XErv5ojpQzBhyxStVtke yYuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P8Ac3gQb; 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 h24si34359808pgg.226.2019.04.30.05.00.13; Tue, 30 Apr 2019 05:00:30 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=P8Ac3gQb; 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 S1730063AbfD3LrK (ORCPT + 99 others); Tue, 30 Apr 2019 07:47:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:60246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730629AbfD3Lq7 (ORCPT ); Tue, 30 Apr 2019 07:46:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE3F721783; Tue, 30 Apr 2019 11:46:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624818; bh=5vTVgx5rzCtrmNgVqwNFZgnPXSr7nJIQmp1UOJVDO8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P8Ac3gQbGy5DiDnBGzU+/5EWIR/r4U8IxNCZNkFWT15Swl99WRIvNCauXpLsOmoXZ +sEJ+vxUioE6wnCCWMryl+bDdn9pxn04fwnJRrbwGqFbWSMS6TDSmapM0GH1Dp7XVA iUViE3wPrFBYlLEofzZiZoL18/qgjDVqgiNZk07Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sebastian Andrzej Siewior , Borislav Petkov , Rik van Riel , "H. Peter Anvin" , "Jason A. Donenfeld" , Andy Lutomirski , Ard Biesheuvel , Dave Hansen , Ingo Molnar , Nicolai Stange , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , kvm ML , linux-efi , x86-ml Subject: [PATCH 4.19 083/100] x86/fpu: Dont export __kernel_fpu_{begin,end}() Date: Tue, 30 Apr 2019 13:38:52 +0200 Message-Id: <20190430113612.682532449@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113608.616903219@linuxfoundation.org> References: <20190430113608.616903219@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastian Andrzej Siewior commit 12209993e98c5fa1855c467f22a24e3d5b8be205 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- 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(-) --- 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, --- 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); --- 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) {