linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/traps: Have read_cr0() only once in the #NM handler
@ 2019-01-17 12:07 Borislav Petkov
  2019-01-17 12:14 ` Sebastian Andrzej Siewior
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Borislav Petkov @ 2019-01-17 12:07 UTC (permalink / raw)
  To: X86 ML; +Cc: LKML, Andy Lutomirski, Sebastian Andrzej Siewior

From: Borislav Petkov <bp@suse.de>

... instead of twice in the code. In any case, CR0 ends up being read
once anyway:

1. The CONFIG_MATH_EMULATION case does so and exits.
2. The normal case does it once too.

However, read it on function entry instead to make the code even simpler
to follow.

No functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/x86/kernel/traps.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 9b7c4ca8f0a7..2684a9d11e66 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -880,12 +880,12 @@ do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
 dotraplinkage void
 do_device_not_available(struct pt_regs *regs, long error_code)
 {
-	unsigned long cr0;
+	unsigned long cr0 = read_cr0();
 
 	RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");
 
 #ifdef CONFIG_MATH_EMULATION
-	if (!boot_cpu_has(X86_FEATURE_FPU) && (read_cr0() & X86_CR0_EM)) {
+	if (!boot_cpu_has(X86_FEATURE_FPU) && (cr0 & X86_CR0_EM)) {
 		struct math_emu_info info = { };
 
 		cond_local_irq_enable(regs);
@@ -897,7 +897,6 @@ do_device_not_available(struct pt_regs *regs, long error_code)
 #endif
 
 	/* This should not happen. */
-	cr0 = read_cr0();
 	if (WARN(cr0 & X86_CR0_TS, "CR0.TS was set")) {
 		/* Try to fix it up and carry on. */
 		write_cr0(cr0 & ~X86_CR0_TS);
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/traps: Have read_cr0() only once in the #NM handler
  2019-01-17 12:07 [PATCH] x86/traps: Have read_cr0() only once in the #NM handler Borislav Petkov
@ 2019-01-17 12:14 ` Sebastian Andrzej Siewior
  2019-01-17 19:24 ` Andy Lutomirski
  2019-01-22 13:30 ` [tip:x86/fpu] " tip-bot for Borislav Petkov
  2 siblings, 0 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2019-01-17 12:14 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, LKML, Andy Lutomirski

On 2019-01-17 13:07:28 [+0100], Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> ... instead of twice in the code. In any case, CR0 ends up being read
> once anyway:
> 
> 1. The CONFIG_MATH_EMULATION case does so and exits.
> 2. The normal case does it once too.
> 
> However, read it on function entry instead to make the code even simpler
> to follow.

makes sense.

Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Sebastian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/traps: Have read_cr0() only once in the #NM handler
  2019-01-17 12:07 [PATCH] x86/traps: Have read_cr0() only once in the #NM handler Borislav Petkov
  2019-01-17 12:14 ` Sebastian Andrzej Siewior
@ 2019-01-17 19:24 ` Andy Lutomirski
  2019-01-22 13:30 ` [tip:x86/fpu] " tip-bot for Borislav Petkov
  2 siblings, 0 replies; 4+ messages in thread
From: Andy Lutomirski @ 2019-01-17 19:24 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, LKML, Sebastian Andrzej Siewior

On Thu, Jan 17, 2019 at 4:07 AM Borislav Petkov <bp@alien8.de> wrote:
>
> From: Borislav Petkov <bp@suse.de>
>
> ... instead of twice in the code. In any case, CR0 ends up being read
> once anyway:
>
> 1. The CONFIG_MATH_EMULATION case does so and exits.
> 2. The normal case does it once too.
>


Reviewed-by: Andy Lutomirski <luto@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:x86/fpu] x86/traps: Have read_cr0() only once in the #NM handler
  2019-01-17 12:07 [PATCH] x86/traps: Have read_cr0() only once in the #NM handler Borislav Petkov
  2019-01-17 12:14 ` Sebastian Andrzej Siewior
  2019-01-17 19:24 ` Andy Lutomirski
@ 2019-01-22 13:30 ` tip-bot for Borislav Petkov
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Borislav Petkov @ 2019-01-22 13:30 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: tglx, luto, hpa, linux-kernel, bigeasy, bp, mingo

Commit-ID:  ee35b9b9f6d52ba134b4e75442531935f295be7a
Gitweb:     https://git.kernel.org/tip/ee35b9b9f6d52ba134b4e75442531935f295be7a
Author:     Borislav Petkov <bp@suse.de>
AuthorDate: Thu, 17 Jan 2019 13:02:05 +0100
Committer:  Borislav Petkov <bp@suse.de>
CommitDate: Tue, 22 Jan 2019 14:13:35 +0100

x86/traps: Have read_cr0() only once in the #NM handler

... instead of twice in the code. In any case, CR0 ends up being read
once anyway:

1. The CONFIG_MATH_EMULATION case does so and exits.
2. The normal case does it once too.

However, read it on function entry instead to make the code even simpler
to follow.

No functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Andy Lutomirski <luto@kernel.org>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: x86@kernel.org
Link: https://lkml.kernel.org/r/20190117120728.3811-1-bp@alien8.de
---
 arch/x86/kernel/traps.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 9b7c4ca8f0a7..2684a9d11e66 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -880,12 +880,12 @@ do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
 dotraplinkage void
 do_device_not_available(struct pt_regs *regs, long error_code)
 {
-	unsigned long cr0;
+	unsigned long cr0 = read_cr0();
 
 	RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");
 
 #ifdef CONFIG_MATH_EMULATION
-	if (!boot_cpu_has(X86_FEATURE_FPU) && (read_cr0() & X86_CR0_EM)) {
+	if (!boot_cpu_has(X86_FEATURE_FPU) && (cr0 & X86_CR0_EM)) {
 		struct math_emu_info info = { };
 
 		cond_local_irq_enable(regs);
@@ -897,7 +897,6 @@ do_device_not_available(struct pt_regs *regs, long error_code)
 #endif
 
 	/* This should not happen. */
-	cr0 = read_cr0();
 	if (WARN(cr0 & X86_CR0_TS, "CR0.TS was set")) {
 		/* Try to fix it up and carry on. */
 		write_cr0(cr0 & ~X86_CR0_TS);

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-22 13:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17 12:07 [PATCH] x86/traps: Have read_cr0() only once in the #NM handler Borislav Petkov
2019-01-17 12:14 ` Sebastian Andrzej Siewior
2019-01-17 19:24 ` Andy Lutomirski
2019-01-22 13:30 ` [tip:x86/fpu] " tip-bot for Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).