Re: [PATCH v2 3/3] i387: support lazy restore of FPU state

From: Linus Torvalds
Date: Mon Feb 20 2012 - 21:19:06 EST


On Mon, Feb 20, 2012 at 6:10 PM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> The attached trivial patch fixes it, I bet.

Actually, it doesn't fix it on x86-32, because we actually have an
#ifdef CONFIG_X86_64 around the "current_task" definition due to
pointless differences in how we do that on x86-64 and x86-32.

So much for the "common" part of "arch/x86/kernel/cpu/common.c"

> Although I do wonder if we should just make kernel_fpu_begin() be a
> real function instead of inlining it. I'm not sure it makes sense to
> inline that thing, and it might be better to export that one instead.

I do think that would be better in the long run, but for now here's an
updated "trivial" patch to fix it.

I want the fpu_owner_task to be declared next to the cache-hot
task-switching stuff, and since they are different on 32-bit and
64-bit (for no really good reason), that gets duplicated too. Sad.

Linus

Linus
arch/x86/kernel/cpu/common.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index b667148dfad7..c0f7d68d318f 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1045,6 +1045,7 @@ DEFINE_PER_CPU(char *, irq_stack_ptr) =
DEFINE_PER_CPU(unsigned int, irq_count) = -1;

DEFINE_PER_CPU(struct task_struct *, fpu_owner_task);
+EXPORT_PER_CPU_SYMBOL(fpu_owner_task);

/*
* Special IST stacks which the CPU switches to when it calls
@@ -1113,6 +1114,8 @@ void debug_stack_reset(void)

DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
EXPORT_PER_CPU_SYMBOL(current_task);
+DEFINE_PER_CPU(struct task_struct *, fpu_owner_task);
+EXPORT_PER_CPU_SYMBOL(fpu_owner_task);

#ifdef CONFIG_CC_STACKPROTECTOR
DEFINE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);