[PATCHv2] x86: add is_f00f_bug helper to fault_32|64.c

From: Harvey Harrison
Date: Tue Jan 15 2008 - 22:42:28 EST


On Tue, 2008-01-15 at 22:22 -0500, H. Peter Anvin wrote:
> Kyle McMartin wrote:
> > On Tue, Jan 15, 2008 at 06:48:35PM -0800, Harvey Harrison wrote:
> >> +#ifdef CONFIG_X86_F00F_BUG
> >> +void do_invalid_op(struct pt_regs *, unsigned long);
> >> +#endif
> >> +
> >> +static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
> >> +{
> >> +#ifdef CONFIG_X86_F00F_BUG
> >> + unsigned long nr;
> >
> > You can just put the prototype inside the function, you know...
>
> You can also make the prototype unconditional, even if the function
> doesn't necessarily exist.

I'll go with the unconditional prototype, the function will always
exist, it's a bit hard to find as it's done with a macro in
traps_32|64.c.

Harvey


From: Harvey Harrison <harvey.harrison@xxxxxxxxx>

Further towards unifying these files, add another helper
in same spirit as is_errata93.

Signed-off-by: Harvey Harrison <harvey.harrison@xxxxxxxxx>
---
arch/x86/mm/fault_32.c | 39 ++++++++++++++++++++++-----------------
arch/x86/mm/fault_64.c | 24 ++++++++++++++++++++++++
2 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/arch/x86/mm/fault_32.c b/arch/x86/mm/fault_32.c
index 936bb0c..dae4f69 100644
--- a/arch/x86/mm/fault_32.c
+++ b/arch/x86/mm/fault_32.c
@@ -211,8 +211,6 @@ void dump_pagetable(unsigned long address)
printk("\n");
}

-void do_invalid_op(struct pt_regs *, unsigned long);
-
static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
{
unsigned index = pgd_index(address);
@@ -288,6 +286,26 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
return 0;
}

+void do_invalid_op(struct pt_regs *, unsigned long);
+
+static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
+{
+#ifdef CONFIG_X86_F00F_BUG
+ unsigned long nr;
+ /*
+ * Pentium F0 0F C7 C8 bug workaround.
+ */
+ if (boot_cpu_data.f00f_bug) {
+ nr = (address - idt_descr.address) >> 3;
+
+ if (nr == 6) {
+ do_invalid_op(regs, 0);
+ return 1;
+ }
+ }
+#endif
+ return 0;
+}

/*
* Handle a fault on the vmalloc or module mapping area
@@ -570,21 +588,8 @@ bad_area_nosemaphore:
return;
}

-#ifdef CONFIG_X86_F00F_BUG
- /*
- * Pentium F0 0F C7 C8 bug workaround.
- */
- if (boot_cpu_data.f00f_bug) {
- unsigned long nr;
-
- nr = (address - idt_descr.address) >> 3;
-
- if (nr == 6) {
- do_invalid_op(regs, 0);
- return;
- }
- }
-#endif
+ if (is_f00f_bug(regs, address))
+ return;

no_context:
/* Are we prepared to handle this kernel fault? */
diff --git a/arch/x86/mm/fault_64.c b/arch/x86/mm/fault_64.c
index cde110c..ce1a870 100644
--- a/arch/x86/mm/fault_64.c
+++ b/arch/x86/mm/fault_64.c
@@ -256,6 +256,27 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
return 0;
}

+void do_invalid_op(struct pt_regs *, unsigned long);
+
+static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
+{
+#ifdef CONFIG_X86_F00F_BUG
+ unsigned long nr;
+ /*
+ * Pentium F0 0F C7 C8 bug workaround.
+ */
+ if (boot_cpu_data.f00f_bug) {
+ nr = (address - idt_descr.address) >> 3;
+
+ if (nr == 6) {
+ do_invalid_op(regs, 0);
+ return 1;
+ }
+ }
+#endif
+ return 0;
+}
+
static noinline void pgtable_bad(unsigned long address, struct pt_regs *regs,
unsigned long error_code)
{
@@ -572,6 +593,9 @@ bad_area_nosemaphore:
return;
}

+ if (is_f00f_bug(regs, address))
+ return;
+
no_context:
/* Are we prepared to handle this kernel fault? */
if (fixup_exception(regs))
--
1.5.4.rc2.1164.g6451



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/