Re: [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state

2016-10-14 Thread Dave Hansen
On 10/14/2016 05:15 AM, r...@redhat.com wrote:
> From: Rik van Riel 
> 
> The __{fpu,cpu}_invalidate_fpregs_state functions can only be used
> to invalidate a resource they control.  Document that, and change
> the API a little bit to reflect that.
> 
> Go back to open coding the fpu_fpregs_owner_ctx write in the CPU
> hotplug code, which should be the exception, and move __kernel_fpu_begin
> to this API.
> 
> This patch has no functional changes to the current code.
> 
> Signed-off-by: Rik van Riel 

Looks totally sane to me.

Acked-by: Dave Hansen 


Re: [PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state

2016-10-14 Thread Dave Hansen
On 10/14/2016 05:15 AM, r...@redhat.com wrote:
> From: Rik van Riel 
> 
> The __{fpu,cpu}_invalidate_fpregs_state functions can only be used
> to invalidate a resource they control.  Document that, and change
> the API a little bit to reflect that.
> 
> Go back to open coding the fpu_fpregs_owner_ctx write in the CPU
> hotplug code, which should be the exception, and move __kernel_fpu_begin
> to this API.
> 
> This patch has no functional changes to the current code.
> 
> Signed-off-by: Rik van Riel 

Looks totally sane to me.

Acked-by: Dave Hansen 


[PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state

2016-10-14 Thread riel
From: Rik van Riel 

The __{fpu,cpu}_invalidate_fpregs_state functions can only be used
to invalidate a resource they control.  Document that, and change
the API a little bit to reflect that.

Go back to open coding the fpu_fpregs_owner_ctx write in the CPU
hotplug code, which should be the exception, and move __kernel_fpu_begin
to this API.

This patch has no functional changes to the current code.

Signed-off-by: Rik van Riel 
---
 arch/x86/include/asm/fpu/internal.h | 13 +++--
 arch/x86/kernel/fpu/core.c  |  2 +-
 arch/x86/kernel/smpboot.c   |  2 +-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h 
b/arch/x86/include/asm/fpu/internal.h
index ef52935f8a17..a75324675311 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -488,15 +488,16 @@ DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
  *
  * 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.
+ * FPU registers are no longer valid for this task.
  *
- * Must be run with preemption disabled: this clears the fpu_fpregs_owner_ctx,
- * on this CPU.
+ * Either one of these invalidation functions is enough. Invalidate
+ * a resource you control: CPU if using the CPU for something else
+ * (with preemption disabled), FPU for the current task, or a task that
+ * is prevented from running by the current task.
  */
-static inline void __cpu_invalidate_fpregs_state(unsigned int cpu)
+static inline void __cpu_invalidate_fpregs_state(void)
 {
-   per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
+   __this_cpu_write(fpu_fpregs_owner_ctx, NULL);
 }
 
 static inline void __fpu_invalidate_fpregs_state(struct fpu *fpu)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 25a45ddfdbcf..30f11ab6c07e 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -106,7 +106,7 @@ void __kernel_fpu_begin(void)
 */
copy_fpregs_to_fpstate(fpu);
} else {
-   this_cpu_write(fpu_fpregs_owner_ctx, NULL);
+   __cpu_invalidate_fpregs_state();
}
 }
 EXPORT_SYMBOL(__kernel_fpu_begin);
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index ca4c4ca2f6af..5cb801acc2e5 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -,7 +,7 @@ int native_cpu_up(unsigned int cpu, struct task_struct 
*tidle)
return err;
 
/* the FPU context is blank, nobody can own it */
-   __cpu_invalidate_fpregs_state(cpu);
+   per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
 
common_cpu_up(cpu, tidle);
 
-- 
2.7.4



[PATCH 1/2] x86/fpu: remove cpu argument to __cpu_invalidate_fpregs_state

2016-10-14 Thread riel
From: Rik van Riel 

The __{fpu,cpu}_invalidate_fpregs_state functions can only be used
to invalidate a resource they control.  Document that, and change
the API a little bit to reflect that.

Go back to open coding the fpu_fpregs_owner_ctx write in the CPU
hotplug code, which should be the exception, and move __kernel_fpu_begin
to this API.

This patch has no functional changes to the current code.

Signed-off-by: Rik van Riel 
---
 arch/x86/include/asm/fpu/internal.h | 13 +++--
 arch/x86/kernel/fpu/core.c  |  2 +-
 arch/x86/kernel/smpboot.c   |  2 +-
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/fpu/internal.h 
b/arch/x86/include/asm/fpu/internal.h
index ef52935f8a17..a75324675311 100644
--- a/arch/x86/include/asm/fpu/internal.h
+++ b/arch/x86/include/asm/fpu/internal.h
@@ -488,15 +488,16 @@ DECLARE_PER_CPU(struct fpu *, fpu_fpregs_owner_ctx);
  *
  * 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.
+ * FPU registers are no longer valid for this task.
  *
- * Must be run with preemption disabled: this clears the fpu_fpregs_owner_ctx,
- * on this CPU.
+ * Either one of these invalidation functions is enough. Invalidate
+ * a resource you control: CPU if using the CPU for something else
+ * (with preemption disabled), FPU for the current task, or a task that
+ * is prevented from running by the current task.
  */
-static inline void __cpu_invalidate_fpregs_state(unsigned int cpu)
+static inline void __cpu_invalidate_fpregs_state(void)
 {
-   per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
+   __this_cpu_write(fpu_fpregs_owner_ctx, NULL);
 }
 
 static inline void __fpu_invalidate_fpregs_state(struct fpu *fpu)
diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c
index 25a45ddfdbcf..30f11ab6c07e 100644
--- a/arch/x86/kernel/fpu/core.c
+++ b/arch/x86/kernel/fpu/core.c
@@ -106,7 +106,7 @@ void __kernel_fpu_begin(void)
 */
copy_fpregs_to_fpstate(fpu);
} else {
-   this_cpu_write(fpu_fpregs_owner_ctx, NULL);
+   __cpu_invalidate_fpregs_state();
}
 }
 EXPORT_SYMBOL(__kernel_fpu_begin);
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index ca4c4ca2f6af..5cb801acc2e5 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -,7 +,7 @@ int native_cpu_up(unsigned int cpu, struct task_struct 
*tidle)
return err;
 
/* the FPU context is blank, nobody can own it */
-   __cpu_invalidate_fpregs_state(cpu);
+   per_cpu(fpu_fpregs_owner_ctx, cpu) = NULL;
 
common_cpu_up(cpu, tidle);
 
-- 
2.7.4