Skip to contentSkip to conversation

x86: Misc cleanups

PATCH In review Borislav Petkov 4 participants 17 messages Apr 5, 2016 – Apr 13, 2016 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

cover x86: Misc cleanups

From: Borislav Petkov <[email protected]>

Hi,

here a bunch of minor cleanups ontop of the cpu_has_YYY removal pile.

Borislav Petkov (6):
x86/fpu/regset: Use boot_cpu_has()
x86/cpu: Simplify extended APIC ID detection on AMD x86/tsc: Do not check X86_FEATURE_CONSTANT_TSC in notifier call x86/tsc: Save an indentation level in recalibrate_cpu_khz() x86/fpu: Remove check_fpu() indirection
x86/fpu: Get rid of x87 math exception helpers

 arch/x86/kernel/cpu/amd.c    | 17 ++++++++++-------
 arch/x86/kernel/fpu/bugs.c   | 16 +++++-----------
 arch/x86/kernel/fpu/core.c   | 44 +++++++++++++-------------------------------
 arch/x86/kernel/fpu/regset.c |  4 ++--
 arch/x86/kernel/tsc.c        | 23 ++++++++++-------------
 5 files changed, 40 insertions(+), 64 deletions(-)
Signature · 1 line
2.7.3
author maintainer
#1 lore raw

PATCH 1/6 x86/fpu/regset: Use boot_cpu_has()

From: Borislav Petkov <[email protected]>

fpregs_{g,s}et() are not sizzling-hot paths to justify the need for static_cpu_has(). Use the normal boot_cpu_has() helper.

---
 arch/x86/kernel/fpu/regset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/fpu/regset.c +2 -2
index bc5e76c1d7c5..81422dfb152b 100644
@@ -278,7 +278,7 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
 
 	fpu__activate_fpstate_read(fpu);
 
-	if (!static_cpu_has(X86_FEATURE_FPU))
+	if (!boot_cpu_has(X86_FEATURE_FPU))
 		return fpregs_soft_get(target, regset, pos, count, kbuf, ubuf);
 
 	if (!boot_cpu_has(X86_FEATURE_FXSR))
@@ -309,7 +309,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
 	fpu__activate_fpstate_write(fpu);
 	fpstate_sanitize_xstate(fpu);
 
-	if (!static_cpu_has(X86_FEATURE_FPU))
+	if (!boot_cpu_has(X86_FEATURE_FPU))
 		return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf);
 
 	if (!boot_cpu_has(X86_FEATURE_FXSR))
Signature · 1 line
2.7.3
#2 lore raw

Re: [PATCH 1/6] x86/fpu/regset: Use boot_cpu_has()

Quoted 24 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

fpregs_{g,s}et() are not sizzling-hot paths to justify the need for static_cpu_has(). Use the normal boot_cpu_has() helper.

---
 arch/x86/kernel/fpu/regset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/fpu/regset.c +1 -1
index bc5e76c1d7c5..81422dfb152b 100644
@@ -278,7 +278,7 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
 
        fpu__activate_fpstate_read(fpu);
 
-       if (!static_cpu_has(X86_FEATURE_FPU))
+       if (!boot_cpu_has(X86_FEATURE_FPU))
                return fpregs_soft_get(target, regset, pos, count, kbuf, ubuf);
 
        if (!boot_cpu_has(X86_FEATURE_FXSR))

arch/x86/kernel/fpu/regset.c int fpregs_set(struct task_struct *target, const struct user_regset *regset, · line 315

Quoted 8 lines
arch/x86/kernel/fpu/regset.c +1 -1
@@ -309,7 +309,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
        fpu__activate_fpstate_write(fpu);
        fpstate_sanitize_xstate(fpu);
 
-       if (!static_cpu_has(X86_FEATURE_FPU))
+       if (!boot_cpu_has(X86_FEATURE_FPU))
                return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf);
 
        if (!boot_cpu_has(X86_FEATURE_FXSR))

I think the general rule should be always use static_cpu_has() for runtime checks, since it reduces down to a single jmp/nop instruction after alternatives run. Even if it's not a hot path, it saves a bit of runtime memory. boot_cpu_has() is fine for run-once init code.

--
Brian Gerst

author maintainer
#3 lore raw

Re: [PATCH 1/6] x86/fpu/regset: Use boot_cpu_has()

Quoted 4 lines · Brian Gerst

I think the general rule should be always use static_cpu_has() for runtime checks, since it reduces down to a single jmp/nop instruction after alternatives run. Even if it's not a hot path, it saves a bit of runtime memory.

So gcc generates a MOV and a TEST for boot_cpu_has(). Not exactly the bloat or slowdown.

So I look at those differently: static_cpu_has()

a) should be used on hotpaths

b) is used as such to annotate those - i.e., "ah, there's a static_cpu_has(), this is a hot path, I better be careful what I'm doing here."

boot_cpu_has() in all the rest.

And saving a couple of bytes per call site but increasing alternatives application time by milli- or microseconds... Meh. I don't see it being really worth the trouble. But this is just me.

Signature · 4 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
#4 lore raw

[tip:x86/asm] x86/fpu/regset: Replace static_cpu_has() usage with boot_cpu_has()

In reply to Borislav Petkov
x86/fpu/regset: Replace static_cpu_has() usage with boot_cpu_has()
Commit-ID:  78df526c74a4db696e1e058b9869471937d0773b
Gitweb:     http://git.kernel.org/tip/78df526c74a4db696e1e058b9869471937d0773b
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 5 Apr 2016 08:29:50 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 11:37:42 +0200

x86/fpu/regset: Replace static_cpu_has() usage with boot_cpu_has()

fpregs_{g,s}et() are not sizzling-hot paths to justify the need for static_cpu_has(). Use the normal boot_cpu_has() helper.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/fpu/regset.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/fpu/regset.c +2 -2
index bc5e76c..81422df 100644
@@ -278,7 +278,7 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
 
 	fpu__activate_fpstate_read(fpu);
 
-	if (!static_cpu_has(X86_FEATURE_FPU))
+	if (!boot_cpu_has(X86_FEATURE_FPU))
 		return fpregs_soft_get(target, regset, pos, count, kbuf, ubuf);
 
 	if (!boot_cpu_has(X86_FEATURE_FXSR))
@@ -309,7 +309,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
 	fpu__activate_fpstate_write(fpu);
 	fpstate_sanitize_xstate(fpu);
 
-	if (!static_cpu_has(X86_FEATURE_FPU))
+	if (!boot_cpu_has(X86_FEATURE_FPU))
 		return fpregs_soft_set(target, regset, pos, count, kbuf, ubuf);
 
 	if (!boot_cpu_has(X86_FEATURE_FXSR))
author maintainer
#5 lore raw

PATCH 2/6 x86/cpu: Simplify extended APIC ID detection on AMD

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Both if-branches are under if (boot_cpu_has(X86_FEATURE_APIC)), unify them.

Also, simplify the test for bits:

- 17 ("ApicExtBrdCst: APIC extended broadcast enable") and
- 18 ("ApicExtId: APIC extended ID enable.")

in "D18F0x68 Link Transaction Control."

No functionality change.

---
 arch/x86/kernel/cpu/amd.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/amd.c +10 -7
index 140eb4351a7b..2a380d7606d7 100644
@@ -565,14 +565,17 @@ static void early_init_amd(struct cpuinfo_x86 *c)
 	 * can safely set X86_FEATURE_EXTD_APICID unconditionally for families
 	 * after 16h.
 	 */
-	if (boot_cpu_has(X86_FEATURE_APIC) && c->x86 > 0x16) {
-		set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
-	} else if (boot_cpu_has(X86_FEATURE_APIC) && c->x86 >= 0xf) {
-		/* check CPU config space for extended APIC ID */
-		unsigned int val;
-		val = read_pci_config(0, 24, 0, 0x68);
-		if ((val & ((1 << 17) | (1 << 18))) == ((1 << 17) | (1 << 18)))
+	if (boot_cpu_has(X86_FEATURE_APIC)) {
+		if (c->x86 > 0x16)
 			set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
+		else if (c->x86 >= 0xf) {
+			/* check CPU config space for extended APIC ID */
+			unsigned int val;
+
+			val = read_pci_config(0, 24, 0, 0x68);
+			if ((val >> 17 & 0x3) == 0x3)
+				set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
+		}
 	}
 #endif
 
Signature · 1 line
2.7.3
#6 lore raw

[tip:x86/asm] x86/cpu: Simplify extended APIC ID detection on AMD

x86/cpu: Simplify extended APIC ID detection on AMD
Commit-ID:  425d8c2fc5e6dddbad083502bb77c7beae545620
Gitweb:     http://git.kernel.org/tip/425d8c2fc5e6dddbad083502bb77c7beae545620
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 5 Apr 2016 08:29:51 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 11:37:42 +0200

x86/cpu: Simplify extended APIC ID detection on AMD

Both if-branches are under if (boot_cpu_has(X86_FEATURE_APIC)), unify them.

Also, simplify the test for bits:

- 17 ("ApicExtBrdCst: APIC extended broadcast enable") and
- 18 ("ApicExtId: APIC extended ID enable.")

in "D18F0x68 Link Transaction Control."

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/cpu/amd.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/amd.c +10 -7
index 54f7b44..c343a54 100644
@@ -565,14 +565,17 @@ static void early_init_amd(struct cpuinfo_x86 *c)
 	 * can safely set X86_FEATURE_EXTD_APICID unconditionally for families
 	 * after 16h.
 	 */
-	if (boot_cpu_has(X86_FEATURE_APIC) && c->x86 > 0x16) {
-		set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
-	} else if (boot_cpu_has(X86_FEATURE_APIC) && c->x86 >= 0xf) {
-		/* check CPU config space for extended APIC ID */
-		unsigned int val;
-		val = read_pci_config(0, 24, 0, 0x68);
-		if ((val & ((1 << 17) | (1 << 18))) == ((1 << 17) | (1 << 18)))
+	if (boot_cpu_has(X86_FEATURE_APIC)) {
+		if (c->x86 > 0x16)
 			set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
+		else if (c->x86 >= 0xf) {
+			/* check CPU config space for extended APIC ID */
+			unsigned int val;
+
+			val = read_pci_config(0, 24, 0, 0x68);
+			if ((val >> 17 & 0x3) == 0x3)
+				set_cpu_cap(c, X86_FEATURE_EXTD_APICID);
+		}
 	}
 #endif
 
author maintainer
#7 lore raw

PATCH 3/6 x86/tsc: Do not check X86_FEATURE_CONSTANT_TSC in notifier call

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

... because the notifier-registering routine already does that. Also, rename cpufreq_tsc() init call to something more telling.

Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 arch/x86/kernel/tsc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/kernel/tsc.c +2 -5
index a0346bc51833..5bb702c77e8f 100644
@@ -922,9 +922,6 @@ static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
 	struct cpufreq_freqs *freq = data;
 	unsigned long *lpj;
 
-	if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
-		return 0;
-
 	lpj = &boot_cpu_data.loops_per_jiffy;
 #ifdef CONFIG_SMP
 	if (!(freq->flags & CPUFREQ_CONST_LOOPS))
@@ -954,7 +951,7 @@ static struct notifier_block time_cpufreq_notifier_block = {
 	.notifier_call  = time_cpufreq_notifier
 };
 
-static int __init cpufreq_tsc(void)
+static int __init cpufreq_register_tsc_scaling(void)
 {
 	if (!boot_cpu_has(X86_FEATURE_TSC))
 		return 0;
@@ -965,7 +962,7 @@ static int __init cpufreq_tsc(void)
 	return 0;
 }
 
-core_initcall(cpufreq_tsc);
+core_initcall(cpufreq_register_tsc_scaling);
 
 #endif /* CONFIG_CPU_FREQ */
 
Signature · 1 line
2.7.3
#9 lore raw

[tip:x86/asm] x86/tsc: Do not check X86_FEATURE_CONSTANT_TSC in notifier call

In reply to Borislav Petkov
x86/tsc: Do not check X86_FEATURE_CONSTANT_TSC in notifier call
Commit-ID:  a841cca74ea7612508aee161c89987b2646ed769
Gitweb:     http://git.kernel.org/tip/a841cca74ea7612508aee161c89987b2646ed769
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 5 Apr 2016 08:29:52 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 11:37:43 +0200

x86/tsc: Do not check X86_FEATURE_CONSTANT_TSC in notifier call

... because the notifier-registering routine already does that. Also, rename cpufreq_tsc() init call to something more telling.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/tsc.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/kernel/tsc.c +2 -5
index a0346bc..5bb702c 100644
@@ -922,9 +922,6 @@ static int time_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
 	struct cpufreq_freqs *freq = data;
 	unsigned long *lpj;
 
-	if (cpu_has(&cpu_data(freq->cpu), X86_FEATURE_CONSTANT_TSC))
-		return 0;
-
 	lpj = &boot_cpu_data.loops_per_jiffy;
 #ifdef CONFIG_SMP
 	if (!(freq->flags & CPUFREQ_CONST_LOOPS))
@@ -954,7 +951,7 @@ static struct notifier_block time_cpufreq_notifier_block = {
 	.notifier_call  = time_cpufreq_notifier
 };
 
-static int __init cpufreq_tsc(void)
+static int __init cpufreq_register_tsc_scaling(void)
 {
 	if (!boot_cpu_has(X86_FEATURE_TSC))
 		return 0;
@@ -965,7 +962,7 @@ static int __init cpufreq_tsc(void)
 	return 0;
 }
 
-core_initcall(cpufreq_tsc);
+core_initcall(cpufreq_register_tsc_scaling);
 
 #endif /* CONFIG_CPU_FREQ */
 
author maintainer
#10 lore raw

PATCH 4/6 x86/tsc: Save an indentation level in recalibrate_cpu_khz()

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

... by flipping the check.

Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 arch/x86/kernel/tsc.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/kernel/tsc.c +8 -8
index 5bb702c77e8f..38ba6de56ede 100644
@@ -834,15 +834,15 @@ int recalibrate_cpu_khz(void)
 #ifndef CONFIG_SMP
 	unsigned long cpu_khz_old = cpu_khz;
 
-	if (boot_cpu_has(X86_FEATURE_TSC)) {
-		tsc_khz = x86_platform.calibrate_tsc();
-		cpu_khz = tsc_khz;
-		cpu_data(0).loops_per_jiffy =
-			cpufreq_scale(cpu_data(0).loops_per_jiffy,
-					cpu_khz_old, cpu_khz);
-		return 0;
-	} else
+	if (!boot_cpu_has(X86_FEATURE_TSC))
 		return -ENODEV;
+
+	tsc_khz = x86_platform.calibrate_tsc();
+	cpu_khz = tsc_khz;
+	cpu_data(0).loops_per_jiffy = cpufreq_scale(cpu_data(0).loops_per_jiffy,
+						    cpu_khz_old, cpu_khz);
+
+	return 0;
 #else
 	return -ENODEV;
 #endif
Signature · 1 line
2.7.3
#12 lore raw

[tip:x86/asm] x86/tsc: Save an indentation level in recalibrate_cpu_khz()

In reply to Borislav Petkov
x86/tsc: Save an indentation level in recalibrate_cpu_khz()
Commit-ID:  eff4677e9fb9b680d1d5f6ba079116548d072b7e
Gitweb:     http://git.kernel.org/tip/eff4677e9fb9b680d1d5f6ba079116548d072b7e
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 5 Apr 2016 08:29:53 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 11:37:43 +0200

x86/tsc: Save an indentation level in recalibrate_cpu_khz()

... by flipping the check.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/tsc.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/kernel/tsc.c +8 -8
index 5bb702c..38ba6de 100644
@@ -834,15 +834,15 @@ int recalibrate_cpu_khz(void)
 #ifndef CONFIG_SMP
 	unsigned long cpu_khz_old = cpu_khz;
 
-	if (boot_cpu_has(X86_FEATURE_TSC)) {
-		tsc_khz = x86_platform.calibrate_tsc();
-		cpu_khz = tsc_khz;
-		cpu_data(0).loops_per_jiffy =
-			cpufreq_scale(cpu_data(0).loops_per_jiffy,
-					cpu_khz_old, cpu_khz);
-		return 0;
-	} else
+	if (!boot_cpu_has(X86_FEATURE_TSC))
 		return -ENODEV;
+
+	tsc_khz = x86_platform.calibrate_tsc();
+	cpu_khz = tsc_khz;
+	cpu_data(0).loops_per_jiffy = cpufreq_scale(cpu_data(0).loops_per_jiffy,
+						    cpu_khz_old, cpu_khz);
+
+	return 0;
 #else
 	return -ENODEV;
 #endif
author maintainer
#13 lore raw

PATCH 5/6 x86/fpu: Remove check_fpu() indirection

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

Rename it to fpu__init_check_bugs() and do the CPU feature check at entry, thus getting rid of the old fpu__init_check_bugs() wrapper.

---
 arch/x86/kernel/fpu/bugs.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
arch/x86/kernel/fpu/bugs.c +5 -11
index 224b5ec52195..aad34aafc0e0 100644
@@ -21,11 +21,15 @@ static double __initdata y = 3145727.0;
  * We should really only care about bugs here
  * anyway. Not features.
  */
-static void __init check_fpu(void)
+void __init fpu__init_check_bugs(void)
 {
 	u32 cr0_saved;
 	s32 fdiv_bug;
 
+	/* kernel_fpu_begin/end() relies on patched alternative instructions. */
+	if (!boot_cpu_has(X86_FEATURE_FPU))
+		return;
+
 	/* We might have CR0::TS set already, clear it: */
 	cr0_saved = read_cr0();
 	write_cr0(cr0_saved & ~X86_CR0_TS);
@@ -59,13 +63,3 @@ static void __init check_fpu(void)
 		pr_warn("Hmm, FPU with FDIV bug\n");
 	}
 }
-
-void __init fpu__init_check_bugs(void)
-{
-	/*
-	 * kernel_fpu_begin/end() in check_fpu() relies on the patched
-	 * alternative instructions.
-	 */
-	if (boot_cpu_has(X86_FEATURE_FPU))
-		check_fpu();
-}
Signature · 1 line
2.7.3
#14 lore raw

[tip:x86/asm] x86/fpu: Remove check_fpu() indirection

x86/fpu: Remove check_fpu() indirection
Commit-ID:  de82fbc3823b7b15ee03466ebfb1c5ec7cc1a941
Gitweb:     http://git.kernel.org/tip/de82fbc3823b7b15ee03466ebfb1c5ec7cc1a941
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 5 Apr 2016 08:29:54 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 11:37:43 +0200

x86/fpu: Remove check_fpu() indirection

Rename it to fpu__init_check_bugs() and do the CPU feature check at entry, thus getting rid of the old fpu__init_check_bugs() wrapper.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/fpu/bugs.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
arch/x86/kernel/fpu/bugs.c +5 -11
index 224b5ec..aad34aa 100644
@@ -21,11 +21,15 @@ static double __initdata y = 3145727.0;
  * We should really only care about bugs here
  * anyway. Not features.
  */
-static void __init check_fpu(void)
+void __init fpu__init_check_bugs(void)
 {
 	u32 cr0_saved;
 	s32 fdiv_bug;
 
+	/* kernel_fpu_begin/end() relies on patched alternative instructions. */
+	if (!boot_cpu_has(X86_FEATURE_FPU))
+		return;
+
 	/* We might have CR0::TS set already, clear it: */
 	cr0_saved = read_cr0();
 	write_cr0(cr0_saved & ~X86_CR0_TS);
@@ -59,13 +63,3 @@ static void __init check_fpu(void)
 		pr_warn("Hmm, FPU with FDIV bug\n");
 	}
 }
-
-void __init fpu__init_check_bugs(void)
-{
-	/*
-	 * kernel_fpu_begin/end() in check_fpu() relies on the patched
-	 * alternative instructions.
-	 */
-	if (boot_cpu_has(X86_FEATURE_FPU))
-		check_fpu();
-}
author maintainer
#15 lore raw

PATCH 6/6 x86/fpu: Get rid of x87 math exception helpers

In reply to Borislav Petkov

From: Borislav Petkov <[email protected]>

... and integrate their functionality into their single user fpu__exception_code().

No functionality change.

---
 arch/x86/kernel/fpu/core.c | 44 +++++++++++++-------------------------------
 1 file changed, 13 insertions(+), 31 deletions(-)
arch/x86/kernel/fpu/core.c +13 -31
index 1551b28398a4..97027545a72d 100644
@@ -506,33 +506,6 @@ void fpu__clear(struct fpu *fpu)
  * x87 math exception handling:
  */
 
-static inline unsigned short get_fpu_cwd(struct fpu *fpu)
-{
-	if (boot_cpu_has(X86_FEATURE_FXSR)) {
-		return fpu->state.fxsave.cwd;
-	} else {
-		return (unsigned short)fpu->state.fsave.cwd;
-	}
-}
-
-static inline unsigned short get_fpu_swd(struct fpu *fpu)
-{
-	if (boot_cpu_has(X86_FEATURE_FXSR)) {
-		return fpu->state.fxsave.swd;
-	} else {
-		return (unsigned short)fpu->state.fsave.swd;
-	}
-}
-
-static inline unsigned short get_fpu_mxcsr(struct fpu *fpu)
-{
-	if (boot_cpu_has(X86_FEATURE_XMM)) {
-		return fpu->state.fxsave.mxcsr;
-	} else {
-		return MXCSR_DEFAULT;
-	}
-}
-
 int fpu__exception_code(struct fpu *fpu, int trap_nr)
 {
 	int err;
@@ -547,10 +520,15 @@ int fpu__exception_code(struct fpu *fpu, int trap_nr)
 		 * so if this combination doesn't produce any single exception,
 		 * then we have a bad program that isn't synchronizing its FPU usage
 		 * and it will suffer the consequences since we won't be able to
-		 * fully reproduce the context of the exception
+		 * fully reproduce the context of the exception.
 		 */
-		cwd = get_fpu_cwd(fpu);
-		swd = get_fpu_swd(fpu);
+		if (boot_cpu_has(X86_FEATURE_FXSR)) {
+			cwd = fpu->state.fxsave.cwd;
+			swd = fpu->state.fxsave.swd;
+		} else {
+			cwd = (unsigned short)fpu->state.fsave.cwd;
+			swd = (unsigned short)fpu->state.fsave.swd;
+		}
 
 		err = swd & ~cwd;
 	} else {
@@ -560,7 +538,11 @@ int fpu__exception_code(struct fpu *fpu, int trap_nr)
 		 * unmasked exception was caught we must mask the exception mask bits
 		 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
 		 */
-		unsigned short mxcsr = get_fpu_mxcsr(fpu);
+		unsigned short mxcsr = MXCSR_DEFAULT;
+
+		if (boot_cpu_has(X86_FEATURE_XMM))
+			mxcsr = fpu->state.fxsave.mxcsr;
+
 		err = ~(mxcsr >> 7) & mxcsr;
 	}
 
Signature · 1 line
2.7.3
#16 lore raw

[tip:x86/asm] x86/fpu: Get rid of x87 math exception helpers

x86/fpu: Get rid of x87 math exception helpers
Commit-ID:  6aa6dbfced51dec6cde159c6167ad3dad6add823
Gitweb:     http://git.kernel.org/tip/6aa6dbfced51dec6cde159c6167ad3dad6add823
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 5 Apr 2016 08:29:55 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 13 Apr 2016 11:37:44 +0200

x86/fpu: Get rid of x87 math exception helpers

... and integrate their functionality into their single user fpu__exception_code().

No functionality change.

Cc Andy Lutomirski <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brian Gerst <[email protected]>
Cc Denys Vlasenko <[email protected]>
Cc H. Peter Anvin <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
---
 arch/x86/kernel/fpu/core.c | 44 +++++++++++++-------------------------------
 1 file changed, 13 insertions(+), 31 deletions(-)
arch/x86/kernel/fpu/core.c +13 -31
index 1551b28..9702754 100644
@@ -506,33 +506,6 @@ void fpu__clear(struct fpu *fpu)
  * x87 math exception handling:
  */
 
-static inline unsigned short get_fpu_cwd(struct fpu *fpu)
-{
-	if (boot_cpu_has(X86_FEATURE_FXSR)) {
-		return fpu->state.fxsave.cwd;
-	} else {
-		return (unsigned short)fpu->state.fsave.cwd;
-	}
-}
-
-static inline unsigned short get_fpu_swd(struct fpu *fpu)
-{
-	if (boot_cpu_has(X86_FEATURE_FXSR)) {
-		return fpu->state.fxsave.swd;
-	} else {
-		return (unsigned short)fpu->state.fsave.swd;
-	}
-}
-
-static inline unsigned short get_fpu_mxcsr(struct fpu *fpu)
-{
-	if (boot_cpu_has(X86_FEATURE_XMM)) {
-		return fpu->state.fxsave.mxcsr;
-	} else {
-		return MXCSR_DEFAULT;
-	}
-}
-
 int fpu__exception_code(struct fpu *fpu, int trap_nr)
 {
 	int err;
@@ -547,10 +520,15 @@ int fpu__exception_code(struct fpu *fpu, int trap_nr)
 		 * so if this combination doesn't produce any single exception,
 		 * then we have a bad program that isn't synchronizing its FPU usage
 		 * and it will suffer the consequences since we won't be able to
-		 * fully reproduce the context of the exception
+		 * fully reproduce the context of the exception.
 		 */
-		cwd = get_fpu_cwd(fpu);
-		swd = get_fpu_swd(fpu);
+		if (boot_cpu_has(X86_FEATURE_FXSR)) {
+			cwd = fpu->state.fxsave.cwd;
+			swd = fpu->state.fxsave.swd;
+		} else {
+			cwd = (unsigned short)fpu->state.fsave.cwd;
+			swd = (unsigned short)fpu->state.fsave.swd;
+		}
 
 		err = swd & ~cwd;
 	} else {
@@ -560,7 +538,11 @@ int fpu__exception_code(struct fpu *fpu, int trap_nr)
 		 * unmasked exception was caught we must mask the exception mask bits
 		 * at 0x1f80, and then use these to mask the exception bits at 0x3f.
 		 */
-		unsigned short mxcsr = get_fpu_mxcsr(fpu);
+		unsigned short mxcsr = MXCSR_DEFAULT;
+
+		if (boot_cpu_has(X86_FEATURE_XMM))
+			mxcsr = fpu->state.fxsave.mxcsr;
+
 		err = ~(mxcsr >> 7) & mxcsr;
 	}