All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Rik van Riel <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, hpa@zytor.com, torvalds@linux-foundation.org,
	jpoimboe@redhat.com, dave.hansen@linux.intel.com, bp@alien8.de,
	dvlasenk@redhat.com, mingo@kernel.org, riel@redhat.com,
	quentin.casasnovas@oracle.com, peterz@infradead.org,
	linux-kernel@vger.kernel.org, brgerst@gmail.com,
	fenghua.yu@intel.com, luto@kernel.org, oleg@redhat.com
Subject: [tip:x86/fpu] x86/fpu: Rename lazy restore functions to "register state valid"
Date: Fri, 7 Oct 2016 02:46:22 -0700	[thread overview]
Message-ID: <tip-25d83b531c1aa4fca5b4e24ed10f493268f162bc@git.kernel.org> (raw)
In-Reply-To: <1475627678-20788-8-git-send-email-riel@redhat.com>

Commit-ID:  25d83b531c1aa4fca5b4e24ed10f493268f162bc
Gitweb:     http://git.kernel.org/tip/25d83b531c1aa4fca5b4e24ed10f493268f162bc
Author:     Rik van Riel <riel@redhat.com>
AuthorDate: Tue, 4 Oct 2016 20:34:36 -0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 7 Oct 2016 11:14:41 +0200

x86/fpu: Rename lazy restore functions to "register state valid"

Name the functions after the state they track, rather than the function
they currently enable. This should make it more obvious when we use the
fpu_register_state_valid() function for something else in the future.

Signed-off-by: Rik van Riel <riel@redhat.com>
Reviewed-by: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Quentin Casasnovas <quentin.casasnovas@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: pbonzini@redhat.com
Link: http://lkml.kernel.org/r/1475627678-20788-8-git-send-email-riel@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/fpu/internal.h | 26 ++++++++++++++++++++------
 arch/x86/kernel/fpu/core.c          |  4 ++--
 arch/x86/kernel/smpboot.c           |  2 +-
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h b/arch/x86/include/asm/fpu/internal.h
index 499d6ed..d2cfe16 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -479,18 +479,32 @@ extern int copy_fpstate_to_sigframe(void __user *buf, void __user *fp, int size)
 DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
 
 /*
+ * The in-register FPU state for an FPU context on a CPU is assumed to be
+ * valid if the fpu->last_cpu matches the CPU, and the fpu_fpregs_owner_ctx
+ * matches the FPU.
+ *
+ * If the FPU register state is valid, the kernel can skip restoring the
+ * FPU state from memory.
+ *
+ * Any code that clobbers the FPU registers or updates the in-memory
+ * FPU state for a task MUST let the rest of the kernel know that the
+ * FPU registers are no longer valid for this task. Calling either of
+ * these two invalidate functions is enough, use whichever is convenient.
+ *
  * Must be run with preemption disabled: this clears the fpu_fpregs_owner_ctx,
  * on this CPU.
- *
- * This will disable any lazy FPU state restore of the current FPU state,
- * but if the current thread owns the FPU, it will still be saved by.
  */
-static inline void __cpu_disable_lazy_restore(unsigned int cpu)
+static inline void __cpu_invalidate_fpregs_state(unsigned int cpu)
 {
 	per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
 }
 
-static inline int fpu_want_lazy_restore(struct fpu *fpu, unsigned int cpu)
+static inline void __fpu_invalidate_fpregs_state(struct fpu *fpu)
+{
+	fpu->last_cpu = -1;
+}
+
+static inline int fpregs_state_valid(struct fpu *fpu, unsigned int cpu)
 {
 	return fpu == this_cpu_read_stable(fpu_fpregs_owner_ctx) && cpu == fpu->last_cpu;
 }
@@ -588,7 +602,7 @@ switch_fpu_prepare(struct fpu *old_fpu, struct fpu *new_fpu, int cpu)
 	} else {
 		old_fpu->last_cpu = -1;
 		if (fpu.preload) {
-			if (fpu_want_lazy_restore(new_fpu, cpu))
+			if (fpregs_state_valid(new_fpu, cpu))
 				fpu.preload = 0;
 			else
 				prefetch(&new_fpu->state);
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 6a37d52..25a45dd 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -336,7 +336,7 @@ void fpu__activate_fpstate_write(struct fpu *fpu)
 
 	if (fpu->fpstate_active) {
 		/* Invalidate any lazy state: */
-		fpu->last_cpu = -1;
+		__fpu_invalidate_fpregs_state(fpu);
 	} else {
 		fpstate_init(&fpu->state);
 		trace_x86_fpu_init_state(fpu);
@@ -379,7 +379,7 @@ void fpu__current_fpstate_write_begin(void)
 	 * ensures we will not be lazy and skip a XRSTOR in the
 	 * future.
 	 */
-	fpu->last_cpu = -1;
+	__fpu_invalidate_fpregs_state(fpu);
 }
 
 /*
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 42a9362..ca4c4ca 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1111,7 +1111,7 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
 		return err;
 
 	/* the FPU context is blank, nobody can own it */
-	__cpu_disable_lazy_restore(cpu);
+	__cpu_invalidate_fpregs_state(cpu);
 
 	common_cpu_up(cpu, tidle);
 

  parent reply	other threads:[~2016-10-07  9:48 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-05  0:34 [PATCH 0/9] x86/fpu: remove lazy FPU mode & various FPU cleanups riel
2016-10-05  0:34 ` [PATCH 1/9] x86/crypto: Remove X86_FEATURE_EAGER_FPU ifdef from the crc32c code riel
2016-10-05  0:40   ` Rik van Riel
2016-10-07  9:43   ` [tip:x86/fpu] x86/crypto, x86/fpu: Remove X86_FEATURE_EAGER_FPU #ifdef " tip-bot for Andy Lutomirski
2016-10-05  0:34 ` [PATCH 2/9] x86/fpu: Hard-disable lazy fpu mode riel
2016-10-05  7:14   ` Paolo Bonzini
2016-10-05 13:57     ` Rik van Riel
2016-10-05 14:03       ` Paolo Bonzini
2016-10-05 15:59         ` Andy Lutomirski
2016-10-05 16:09           ` Paolo Bonzini
2016-10-07  9:43   ` [tip:x86/fpu] x86/fpu: Hard-disable lazy FPU mode tip-bot for Andy Lutomirski
2016-10-05  0:34 ` [PATCH 3/9] x86/fpu: Remove the XFEATURE_MASK_EAGER/LAZY distinction riel
2016-10-07  9:44   ` [tip:x86/fpu] " tip-bot for Andy Lutomirski
2016-10-05  0:34 ` [PATCH 4/9] x86/fpu: Remove use_eager_fpu() riel
2016-10-07  9:44   ` [tip:x86/fpu] " tip-bot for Andy Lutomirski
2016-10-05  0:34 ` [PATCH 5/9] x86/fpu: remove fpu.counter riel
2016-10-05  2:07   ` Andy Lutomirski
2016-10-07  9:45   ` [tip:x86/fpu] x86/fpu: Remove struct fpu::counter tip-bot for Rik van Riel
2016-10-05  0:34 ` [PATCH 6/9] x86/fpu,kvm: remove kvm vcpu->fpu_counter riel
2016-10-07  9:45   ` [tip:x86/fpu] x86/fpu, kvm: Remove KVM vcpu->fpu_counter tip-bot for Rik van Riel
2016-10-05  0:34 ` [PATCH 7/9] x86/fpu: rename lazy restore functions to "register state valid" riel
2016-10-05  2:09   ` Andy Lutomirski
2016-10-07  9:46   ` tip-bot for Rik van Riel [this message]
2016-10-05  0:34 ` [PATCH 8/9] x86/fpu: remove __fpregs_(de)activate riel
2016-10-05  2:10   ` Andy Lutomirski
2016-10-07  9:46   ` [tip:x86/fpu] x86/fpu: Remove __fpregs_(de)activate() tip-bot for Rik van Riel
2016-10-05  0:34 ` [PATCH 9/9] x86/fpu: split old & new fpu code paths riel
2016-10-07  9:47   ` [tip:x86/fpu] x86/fpu: Split old & new FPU " tip-bot for Rik van Riel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-25d83b531c1aa4fca5b4e24ed10f493268f162bc@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dvlasenk@redhat.com \
    --cc=fenghua.yu@intel.com \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=quentin.casasnovas@oracle.com \
    --cc=riel@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.