Re: [PATCH] [3/11] x86: Stop MCEs and NMIs during code patching

From: Mathieu Desnoyers
Date: Fri Jul 20 2007 - 12:04:18 EST


* Andi Kleen (ak@xxxxxxx) wrote:

> Index: linux/arch/x86_64/kernel/nmi.c
> ===================================================================
> --- linux.orig/arch/x86_64/kernel/nmi.c
> +++ linux/arch/x86_64/kernel/nmi.c
> @@ -384,11 +384,14 @@ int __kprobes nmi_watchdog_tick(struct p
> return rc;
> }
>
> +static unsigned ignore_nmis;
> +
> asmlinkage __kprobes void do_nmi(struct pt_regs * regs, long error_code)
> {
> nmi_enter();
> add_pda(__nmi_count,1);
> - default_do_nmi(regs);
> + if (!ignore_nmis)
> + default_do_nmi(regs);
> nmi_exit();
> }
>
> @@ -401,6 +404,18 @@ int do_nmi_callback(struct pt_regs * reg
> return 0;
> }
>
> +void stop_nmi(void)
> +{
> + ignore_nmis++;
> + acpi_nmi_disable();
> +}

I would do:

acpi_nmi_disable();
ignore_nmis++;

Instead, so we minimize the chances to have to drop a do_nmi.

> +
> +void restart_nmi(void)
> +{
> + ignore_nmis--;
> + acpi_nmi_enable();
> +}
> +
> #ifdef CONFIG_SYSCTL
>
...
> #endif /* ASM_NMI_H */
> Index: linux/arch/i386/kernel/traps.c
> ===================================================================
> --- linux.orig/arch/i386/kernel/traps.c
> +++ linux/arch/i386/kernel/traps.c
> @@ -774,6 +774,8 @@ static __kprobes void default_do_nmi(str
> reassert_nmi();
> }
>
> +static int ignore_nmis;
> +
> fastcall __kprobes void do_nmi(struct pt_regs * regs, long error_code)
> {
> int cpu;
> @@ -784,11 +786,24 @@ fastcall __kprobes void do_nmi(struct pt
>
> ++nmi_count(cpu);
>
> - default_do_nmi(regs);
> + if (!ignore_nmis)
> + default_do_nmi(regs);
>
> nmi_exit();
> }
>
> +void stop_nmi(void)
> +{
> + ignore_nmis++;
> + acpi_nmi_disable();
> +}
> +

Same here, I would swap the two.

> +void restart_nmi(void)
> +{
> + ignore_nmis--;
> + acpi_nmi_enable();
> +}
> +

Besides that, it looks good.

Mathieu

--
Mathieu Desnoyers
Computer Engineering Ph.D. Student, Ecole Polytechnique de Montreal
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
-
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/