Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1739607imu; Wed, 28 Nov 2018 14:24:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/VrauOoK2sbP64gAaHSDRdQnfXSG2g8WY//NJsxAWmsMPOtNAPIEg8RdxOdaxK8KQ5YrE0W X-Received: by 2002:a17:902:4324:: with SMTP id i33-v6mr39635196pld.253.1543443849782; Wed, 28 Nov 2018 14:24:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543443849; cv=none; d=google.com; s=arc-20160816; b=JQgLAlpsxAd9pBb+JB0x+Sxdh7r3CgFwhW1wzTPpxz5m0ynKv35IRs9PlRgeLTNuGf 7hTGLX0oU22WHFbePFYL6P4M04XI1JIaWNS8J8Xz5BKLHvNSbsVds/lYw0xsOXRAMGoM OnvUPIdvURR6hvfz9saF4so1owpodpUhEqcO7eNN6Xu3NJ3K4SQYl/OQnXj0er17P1bd Xgyknk9aMkOMrLuVMT6jEVJcEGlVXAUZDQA4Xmb9d+HVzVyvmyZTZ6WW0wOLZ906T7Y2 DK4W1Amq3F46u21tM/cKyCcBHE15EixWjFI8KwHzrBCaK8wrIW0yOKilI7bZOTxJSkC/ 7C2w== 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; bh=3JeQKqKyp6JpBsKB2tuM8CyiMGYl4bLCsA0f/ZMEviw=; b=wRZpbMnw9Tla7Q3DasdV4ud/SkXFHE83e5PgSzEsw6LbjYVlR+PxSzYXdajj4MxN0y LBUiw3wLsNz6ym3XYuklTqJSDD2L29UiTcVpiBWHb+K34xQa/Id5Sq3mrOGQ1u56YIU2 YEbODtl0XT78yh6Pt/k2Qz/wZOD9QNDw3la86kLGOrOko3cSHur0hyCWFth45FHUXvWB +aOtxClcl+0Wpn1b1MV1TRVQ/dxviNcTAiXTqxtzYHP4XI/hMEJhWwY4cSUxyW0PUYaM /ncgmN+r8vVN65tsrQh1ptAPAsQVp658uJ65+VK6qgfjOySTMpr8Ak/lHgkfo8gcZz7x sJmQ== 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 133si9646137pfw.64.2018.11.28.14.23.55; Wed, 28 Nov 2018 14:24:09 -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 S1727068AbeK2JY0 (ORCPT + 99 others); Thu, 29 Nov 2018 04:24:26 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:33152 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726989AbeK2JYY (ORCPT ); Thu, 29 Nov 2018 04:24:24 -0500 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gS8Cj-0001GX-87; Wed, 28 Nov 2018 23:21:09 +0100 From: Sebastian Andrzej Siewior To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, Andy Lutomirski , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel , Dave Hansen , Sebastian Andrzej Siewior Subject: [PATCH 16/29] x86/fpu: Add (__)make_fpregs_active helpers Date: Wed, 28 Nov 2018 23:20:22 +0100 Message-Id: <20181128222035.2996-17-bigeasy@linutronix.de> X-Mailer: git-send-email 2.20.0.rc1 In-Reply-To: <20181128222035.2996-1-bigeasy@linutronix.de> References: <20181128222035.2996-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rik van Riel Add helper function that ensures the floating point registers for the current task are active. Use with preemption disabled. Signed-off-by: Rik van Riel Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/include/asm/fpu/api.h | 11 +++++++++++ arch/x86/include/asm/fpu/internal.h | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index d6e094c282779..d6522b5706bb5 100644 --- a/arch/x86/include/asm/fpu/api.h +++ b/arch/x86/include/asm/fpu/api.h @@ -10,6 +10,7 @@ #ifndef _ASM_X86_FPU_API_H #define _ASM_X86_FPU_API_H +#include /* * Use kernel_fpu_begin/end() if you intend to use FPU in kernel context. It @@ -23,6 +24,16 @@ extern void kernel_fpu_begin(void); extern void kernel_fpu_end(void); extern bool irq_fpu_usable(void); +static inline void __fpregs_changes_begin(void) +{ + preempt_disable(); +} + +static inline void __fpregs_changes_end(void) +{ + preempt_enable(); +} + /* * Query the presence of one or more xfeatures. Works on any legacy CPU as well. * diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h index a8b4c1e92c010..21a8b4f5a5efd 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -513,6 +513,15 @@ static inline void fpregs_activate(struct fpu *fpu) trace_x86_fpu_regs_activated(fpu); } +static inline void __fpregs_load_activate(struct fpu *fpu, int cpu) +{ + if (!fpregs_state_valid(fpu, cpu)) { + if (current->mm) + copy_kernel_to_fpregs(&fpu->state); + fpregs_activate(fpu); + } +} + /* * FPU state switching for scheduling. * @@ -548,14 +557,8 @@ switch_fpu_prepare(struct fpu *old_fpu, int cpu) */ static inline void switch_fpu_finish(struct fpu *new_fpu, int cpu) { - if (static_cpu_has(X86_FEATURE_FPU)) { - if (!fpregs_state_valid(new_fpu, cpu)) { - if (current->mm) - copy_kernel_to_fpregs(&new_fpu->state); - } - - fpregs_activate(new_fpu); - } + if (static_cpu_has(X86_FEATURE_FPU)) + __fpregs_load_activate(new_fpu, cpu); } /* -- 2.20.0.rc1