Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3339892yba; Mon, 6 May 2019 22:48:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8V6avMBI2PMrQkNEgFQIsQp7ffqmEeWj8nj2oWW1l17wpldXnb2ak2sh1T+rsBdpfZiwr X-Received: by 2002:a63:fa4a:: with SMTP id g10mr11060892pgk.147.1557208128061; Mon, 06 May 2019 22:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557208128; cv=none; d=google.com; s=arc-20160816; b=IHzfnrdKw4WK4nZe0AG78dpEeq9ySlO+U0bvaXPlji0aR0qJfiZQ5K8qp0z8tSGs/y 11CUM6D8748kGYQTWVKP3gw+FUAvsunQTvAtVmr39Zk4RnnvaHf8NRuuZ0gVJPtssVbP yUmEGJa5jNz4qMFTVADy9fEs3R4CYBVz0Xu1hUtWDBM+tGF63BFUsWLvzbsJArd48eCg pRINAfGLnDYdfR4YA7P+KveQg9J74aHPgsPIFGSfYCTaUMnM0zYclx8a+ALtdiwMSYxl HVuvEaipG6uijsiMHInLdZlyx+JGZA4WNu7Mo10kj77D1yKyB6o1W7FJ9weiw/y7DGy/ sKdw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GHHc1j+NjaSQVZFJbN5E7SF+qkWcrkGoL2GyLGA2P10=; b=pq95s8MLZkshGakPx2FPgVyLeQZlRUQv76Z2AKGxS24rWrwtiKYY0a0uaI3Hqy7tHX g6TRTrbpxkV0JZ2vl+RQOSxpESzhCry2xs6c5naBCFd18PybozONok0kEBXSeKLol/XO K3iMOkqLpZjEYhP5RmYm1ngJ85Bq6TnQ2zLEoGeFoWyslsH95avNmRCmjpde5MjuvrzN sc27iFHqM+JcjqLIob9yXdRO5W+RLilFZPEZ0G+6kYkjJrX9aqOVKyK2umpoiJTi7N03 uSal44bP55UEDumHElgtBPAuFNq9ERpNrF3nbRYGw359kRoooN+00WLJZ/Gz6izX2AEB WnEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j9HV1Fzm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11si2959884plg.248.2019.05.06.22.48.33; Mon, 06 May 2019 22:48:48 -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=j9HV1Fzm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727774AbfEGFlK (ORCPT + 99 others); Tue, 7 May 2019 01:41:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:60530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728620AbfEGFlF (ORCPT ); Tue, 7 May 2019 01:41:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DAA9520675; Tue, 7 May 2019 05:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557207663; bh=9x7eHrXpvak8eqL0Qp4voPwED6YGX3O6T9ioe5rx+54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j9HV1FzmubExhSyFYjap0PLcTfvGhuDAQ7drpaIRIOcNy7Rm59V5kfHd+W+cTBTYK Lm6sRH41iG7N/hBjLy7U0GpYdmBMfh9fVZadDz/dH8julqnDXGdyviWLnZv5WBMxO3 6B/Ob8x6c3/sS39w+v8sbdYPWpPzVPAOoKe7TQS8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: 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 , Sasha Levin Subject: [PATCH AUTOSEL 4.14 84/95] x86/fpu: Don't export __kernel_fpu_{begin,end}() Date: Tue, 7 May 2019 01:38:13 -0400 Message-Id: <20190507053826.31622-84-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190507053826.31622-1-sashal@kernel.org> References: <20190507053826.31622-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore 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 [ Upstream commit 12209993e98c5fa1855c467f22a24e3d5b8be205 ] 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: Sasha Levin --- 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 a399c1ebf6f0..96fd0251f8f5 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_scratch.use_pgd) { \ @@ -104,8 +103,7 @@ struct efi_scratch { } \ \ 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 = ¤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.1