Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3537082imu; Wed, 7 Nov 2018 11:52:19 -0800 (PST) X-Google-Smtp-Source: AJdET5e6j/B9fpvCZLQCA4FObugjvXguAh/2nAOZ7iW/h2X/5OiUbGdXkeGOwrvSHaeoIYHca8QO X-Received: by 2002:a17:902:6b88:: with SMTP id p8-v6mr1538061plk.19.1541620339854; Wed, 07 Nov 2018 11:52:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541620339; cv=none; d=google.com; s=arc-20160816; b=mnp8gdmR5vh7fHGYvCYBojl/u6b9Y56yZxmGiMTAZK8R0XDegupzVe3nJ7e1Pxl/tJ t4hgxp9SRlsMMlE7w8MzqrxtEGAVKlbl725EcTCP2MoVJMr+gJwv93Y6Iw3YrBCersgw Dc5ktWw6sZdeSn8R4yi4Mt55nAFCcZ0v0AChU53IJAj2JWwr+9eMiVsQDmAMmUneQc1k dLX+HmUPn/JyFrIEMSFFQZpZoOQQfZlwdePLfxJGQPq3UQ+mG5wiZOA1BSoGJmdJiEeD g/FbAo1L5CEHPUb2Xy9W7MTkUgtf6TiohmiRVjyzd5w8GkM9si6lSoVCkSJsKSe07x+c eVqQ== 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=DG+rhTP0DN/Iw8T8BzwEZNSjXFLu1YME0u7N4Ct85pg=; b=B3JC4x7ssIo8OomqspVj9VLW9zkTcYIGp8nxpGUUMwkgayLaNi8Se64YNZ3csobVqs JpePtRkN9FsNAUAMWfgDlVvaQ7ugc5Y0YNbP0VALkmcYt9+kOpitQzc2zFNL+ZU8ONRP 7dUopCCf4YxqUJg6fHdfZeiKnwy5kFGVLxYfcoywlTCXHhK0nK6viYwXt6Rv/N5Vg7HE dbEIChPgyblaWcWhIWRhblfx4JsZmZKHDtQizjrXmBXHiDneMKjwVLIfqJwcMce/bycs qoEEnI0Nm5yp9TC4UZtv2sWUIbW9vuxUmxVss3PuDH6nbIS0nGhsR2YDSun2QmjsNitg 63LQ== 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 x12-v6si1572274pfn.111.2018.11.07.11.52.04; Wed, 07 Nov 2018 11:52:19 -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 S1727563AbeKHFVM (ORCPT + 99 others); Thu, 8 Nov 2018 00:21:12 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:41899 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727337AbeKHFVM (ORCPT ); Thu, 8 Nov 2018 00:21:12 -0500 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1gKTpD-00070Q-C9; Wed, 07 Nov 2018 20:49:16 +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 11/23] x86/fpu: Add (__)make_fpregs_active helpers Date: Wed, 7 Nov 2018 20:48:46 +0100 Message-Id: <20181107194858.9380-12-bigeasy@linutronix.de> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181107194858.9380-1-bigeasy@linutronix.de> References: <20181107194858.9380-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 | 26 ++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/fpu/api.h b/arch/x86/include/asm/fpu/api.h index a9caac9d4a729..8c03b42416656 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 /* * Careful: __kernel_fpu_begin/end() must be called with preempt disabled @@ -27,6 +28,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 d7f9e14c73c19..260cd4f4ba2bb 100644 --- a/arch/x86/include/asm/fpu/internal.h +++ b/arch/x86/include/asm/fpu/internal.h @@ -512,6 +512,20 @@ static inline void fpregs_activate(struct fpu *fpu) trace_x86_fpu_regs_activated(fpu); } +/* + * Load the FPU state for the current task. Call with preemption disabled. + */ +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); + else + copy_kernel_to_fpregs(&init_fpstate); + } + fpregs_activate(fpu); +} + /* * FPU state switching for scheduling. * @@ -547,16 +561,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); - else - copy_kernel_to_fpregs(&init_fpstate); - } - - fpregs_activate(new_fpu); - } + if (static_cpu_has(X86_FEATURE_FPU)) + __fpregs_load_activate(new_fpu, cpu); } /* -- 2.19.1