Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7455013imu; Mon, 3 Dec 2018 13:13:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/XchapA43T+5Z13sY3LlbhV98pRHq2XoQu/bhok4/oXbOpoFdQVzwNAtks/hkc4RsWWsxV8 X-Received: by 2002:a63:1904:: with SMTP id z4mr14062271pgl.135.1543871604125; Mon, 03 Dec 2018 13:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543871604; cv=none; d=google.com; s=arc-20160816; b=orzkhAF9uWzhZfVL+xQMJN0zyWlON0jqkBOsjTZEK7+xU6jHS8cGr+/QwCFSbBC+3S 7vBdUBqN3D1qFROkV/PDDUb9R/q4ggHzbmqW5dfPnfXde250nf4walO8LA9C2GeZ4qBZ zGFTA86k/OAY5edfprtimw+cVVsiYRixKsorWEzKyVG/hUEFYWiWyl0Ag35rxi5qUvcY zJZk560NYr9s2j75ellZK/0ep0v1OydWjnVetqil9/whYGijgIPg+OL5/AwWm82tRFqm bL0ifAUa1L3C0qME8/lga7FE1GAFKjfnHUbcS5WXbcWWvL/miiccbCYBUJbdYPoIHlID dF+Q== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=yhIoV1dlJMenFm8edG2JD4Ef45e8aCymQaFOXM0M0dE=; b=irDA7gTDO7U8VkXfpfazMj8RZ3zwfjasIJ8kCqvBp5NSBLPeesnmwJtBR6fGRuU8oX m1m28oA4Zt6f/a3qmfjna+MqrU6QHHlg1VzccH10hVuQUZNuNvTIqrH4f9BXZGShufYU HSE4qmfget+8cLjgZn2e8SxDRAEbm91lLkIv1dzltmFr25uhEh7BiBGhewPrAjlN03pm r2M//AuS4NxRrQ8e7tSI/Iga9UtWsIl6yzYk+TvV/WAfXD9MtQ9eW+uFDC6eKRg+e74Z g2ORscJbpkUEl8n4tOH9uPD9OfEVIPHQONT5W8tbrkmkK5/4gE91ApRPTPnPe22CjWPn u5zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c6f3xHN6; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r22si12989450pgl.537.2018.12.03.13.13.07; Mon, 03 Dec 2018 13:13:24 -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; dkim=pass header.i=@linaro.org header.s=google header.b=c6f3xHN6; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726008AbeLCVMc (ORCPT + 99 others); Mon, 3 Dec 2018 16:12:32 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:40110 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725951AbeLCVMc (ORCPT ); Mon, 3 Dec 2018 16:12:32 -0500 Received: by mail-it1-f196.google.com with SMTP id h193so10909751ita.5 for ; Mon, 03 Dec 2018 13:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=yhIoV1dlJMenFm8edG2JD4Ef45e8aCymQaFOXM0M0dE=; b=c6f3xHN64JNAu4OHg/gLyl2qOK/TyxhK5AoPdT8JT95w4+yCIEe4lDyPPdt1sO90Za cv4m2Kb0E52NPtiVkgWSQ32NW+9TaiIl2HMvc5JGpfkHrggS9lAkq1h9D7eKAndtP4aY T0UGAyBmnNVj2BsWAghwV2wrDMauz7DgGwBuA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=yhIoV1dlJMenFm8edG2JD4Ef45e8aCymQaFOXM0M0dE=; b=MlyhvrjFX51+LFjMjQnH64cpwrKO4lLXVPsbniiLApNASTrqQ7CUwaK8UELf8vtSnB kaE7kYE+CF6PlIAMRbmbgKlFkaALkp3JOkWZ9Vw2Q4eImdfhNgW9I3dLXCzjLsl5SESL g3wvS9zZGGO8xoMyTQ1qugVmBLVjVBbJwr0RputEOP9nN89MWmWV4kEZN8Px66TDdiPx N8/0EGwsGAXm2S+qDZfY4SOm0skapp2W9jzDpkqDDSw5voo4fY10KObLSzUP3Z8qE39u P9d61vSFdOt+HRCMmx03wzPhj3OrJcMD5J0TPE8rHSwgC8j3s/dX3KwfLq0JwB+6vmd2 ZNYQ== X-Gm-Message-State: AA+aEWYZ8wAtXhNmAIcWQ8PiWu/6U8iv2kNpWttYJfOYhsa7zBHsORka 9LW3jaDhh3BkT9ABmtSUO501VNahzz/c+mOYMElSAw== X-Received: by 2002:a24:edc4:: with SMTP id r187mr10260248ith.158.1543871550657; Mon, 03 Dec 2018 13:12:30 -0800 (PST) MIME-Version: 1.0 References: <20181129150210.2k4mawt37ow6c2vq@linutronix.de> In-Reply-To: From: Ard Biesheuvel Date: Mon, 3 Dec 2018 22:12:19 +0100 Message-ID: Subject: Re: [tip:x86/fpu] x86/fpu: Don't export __kernel_fpu_{begin,end}() To: Dave Hansen , Ingo Molnar , "the arch/x86 maintainers" , nstange@suse.de, Rik van Riel , Sebastian Andrzej Siewior , KVM devel mailing list , "Jason A. Donenfeld" , Linux Kernel Mailing List , Ingo Molnar , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , "H. Peter Anvin" , Thomas Gleixner , Andy Lutomirski , Borislav Petkov , linux-efi , Paolo Bonzini Cc: linux-tip-commits@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 3 Dec 2018 at 22:04, tip-bot for Sebastian Andrzej Siewior wrote: > > Commit-ID: 7d79adb87fa79e4a4c59424fd5b5a922861fc5f6 > Gitweb: https://git.kernel.org/tip/7d79adb87fa79e4a4c59424fd5b5a92286= 1fc5f6 > 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=C4=8Dm=C3=A1=C5=99 > Cc: Thomas Gleixner > Cc: kvm ML > Cc: linux-efi > Cc: x86-ml > Link: https://lkml.kernel.org/r/20181129150210.2k4mawt37ow6c2vq@linutroni= x.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 lon= g size, > diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/ap= i.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 disable= d > - * 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 pe= riods > + * 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. According to the documentation in x86/kernel/fpu/core.c, this is not true. So which one is accurate? > */ > -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 =3D ¤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 =3D ¤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) > {