From: James Hogan <james.hogan@imgtec.com> To: Ralf Baechle <ralf@linux-mips.org> Cc: <linux-mips@linux-mips.org>, Paul Burton <paul.burton@imgtec.com>, "James Hogan" <james.hogan@imgtec.com> Subject: [PATCH 1/2] MIPS: Properly disable FPU in start_thread() Date: Mon, 1 Feb 2016 13:50:36 +0000 [thread overview] Message-ID: <1454334637-3860-2-git-send-email-james.hogan@imgtec.com> (raw) In-Reply-To: <1454334637-3860-1-git-send-email-james.hogan@imgtec.com> start_thread() (called for execve(2)) clears the TIF_USEDFPU flag without atomically disabling the FPU. With a preemptive kernel, an unfortunately timed preemption after this could result in another task (or KVM guest) being scheduled in with the FPU still enabled, since lose_fpu_inatomic() only turns it off if TIF_USEDFPU is set. Use lose_fpu(0) instead of the separate FPU / MSA management, which should do the right thing (drop FPU properly and atomically without saving state) and will be more future proof. Signed-off-by: James Hogan <james.hogan@imgtec.com> Reviewed-by: Paul Burton <paul.burton@imgtec.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: linux-mips@linux-mips.org --- arch/mips/kernel/process.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index f2975d4d1e44..eddd5fd6fdfa 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -65,12 +65,10 @@ void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp) status = regs->cp0_status & ~(ST0_CU0|ST0_CU1|ST0_FR|KU_MASK); status |= KU_USER; regs->cp0_status = status; + lose_fpu(0); + clear_thread_flag(TIF_MSA_CTX_LIVE); clear_used_math(); - clear_fpu_owner(); init_dsp(); - clear_thread_flag(TIF_USEDMSA); - clear_thread_flag(TIF_MSA_CTX_LIVE); - disable_msa(); regs->cp0_epc = pc; regs->regs[29] = sp; } -- 2.4.10
WARNING: multiple messages have this Message-ID (diff)
From: James Hogan <james.hogan@imgtec.com> To: Ralf Baechle <ralf@linux-mips.org> Cc: linux-mips@linux-mips.org, Paul Burton <paul.burton@imgtec.com>, James Hogan <james.hogan@imgtec.com> Subject: [PATCH 1/2] MIPS: Properly disable FPU in start_thread() Date: Mon, 1 Feb 2016 13:50:36 +0000 [thread overview] Message-ID: <1454334637-3860-2-git-send-email-james.hogan@imgtec.com> (raw) Message-ID: <20160201135036.7ydhWPDbVps3-34fAU5yROKwjs0EoASDnOiH9X6ghoE@z> (raw) In-Reply-To: <1454334637-3860-1-git-send-email-james.hogan@imgtec.com> start_thread() (called for execve(2)) clears the TIF_USEDFPU flag without atomically disabling the FPU. With a preemptive kernel, an unfortunately timed preemption after this could result in another task (or KVM guest) being scheduled in with the FPU still enabled, since lose_fpu_inatomic() only turns it off if TIF_USEDFPU is set. Use lose_fpu(0) instead of the separate FPU / MSA management, which should do the right thing (drop FPU properly and atomically without saving state) and will be more future proof. Signed-off-by: James Hogan <james.hogan@imgtec.com> Reviewed-by: Paul Burton <paul.burton@imgtec.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: linux-mips@linux-mips.org --- arch/mips/kernel/process.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index f2975d4d1e44..eddd5fd6fdfa 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -65,12 +65,10 @@ void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp) status = regs->cp0_status & ~(ST0_CU0|ST0_CU1|ST0_FR|KU_MASK); status |= KU_USER; regs->cp0_status = status; + lose_fpu(0); + clear_thread_flag(TIF_MSA_CTX_LIVE); clear_used_math(); - clear_fpu_owner(); init_dsp(); - clear_thread_flag(TIF_USEDMSA); - clear_thread_flag(TIF_MSA_CTX_LIVE); - disable_msa(); regs->cp0_epc = pc; regs->regs[29] = sp; } -- 2.4.10
next prev parent reply other threads:[~2016-02-01 13:51 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-02-01 13:50 [PATCH 0/2] MIPS: Fix FPU preemption issues James Hogan 2016-02-01 13:50 ` James Hogan 2016-02-01 13:50 ` James Hogan [this message] 2016-02-01 13:50 ` [PATCH 1/2] MIPS: Properly disable FPU in start_thread() James Hogan 2016-02-01 13:50 ` [PATCH 2/2] MIPS: Fix FPU disable with preemption James Hogan 2016-02-01 13:50 ` James Hogan 2016-02-01 22:54 ` [PATCH 0/2] MIPS: Fix FPU preemption issues Ralf Baechle
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=1454334637-3860-2-git-send-email-james.hogan@imgtec.com \ --to=james.hogan@imgtec.com \ --cc=linux-mips@linux-mips.org \ --cc=paul.burton@imgtec.com \ --cc=ralf@linux-mips.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: linkBe 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.