Re: [PATCH] x86: Fix code patching for paravirt-alternatives on 486

From: H. Peter Anvin
Date: Tue Sep 08 2009 - 20:34:09 EST


On 09/08/2009 04:23 PM, Ben Hutchings wrote:
>
> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
> index c776826..74ddfce 100644
> --- a/arch/x86/include/asm/processor.h
> +++ b/arch/x86/include/asm/processor.h
> @@ -708,6 +708,12 @@ static inline void sync_core(void)
> {
> int tmp;
>
> +#if defined(CONFIG_M386) || defined(CONFIG_M486)
> + /* This is unnecessary on 386- and 486-class processors, most of
> + which don't even implement CPUID. */
> + if (boot_cpu_data.x86 < 5)
> + return;
> +#endif
> asm volatile("cpuid" : "=a" (tmp) : "0" (1)
> : "ebx", "ecx", "edx", "memory");
> }
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index 4869351..330ab89 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -498,6 +498,9 @@ static void *__init_or_module text_poke_early(void *addr, const void *opcode,
> unsigned long flags;
> local_irq_save(flags);
> memcpy(addr, opcode, len);
> + /* Force 486-class processors to flush prefetched instructions,
> + since we may have just patched local_irq_restore(). */
> + asm volatile("jmp 1f\n1:\n" ::: "memory");
> local_irq_restore(flags);
> sync_core();
> /* Could also do a CLFLUSH here to speed up CPU recovery; but

I'm wondering if it wouldn't be cleaner to fold the jump into
sync_core() and moving the sync_core() up before local_irq_restore().

-hpa
--
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/