]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/x86/kernel/alternative.c
x86: use X86_FEATURE_NOPL in alternatives
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / alternative.c
index df4099dc1c682eb4af7c4af22badf4e4f3cd770c..65a0c1b4869636122fc22dec84de26788662a2d4 100644 (file)
@@ -1,6 +1,6 @@
 #include <linux/module.h>
 #include <linux/sched.h>
-#include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/list.h>
 #include <linux/kprobes.h>
 #include <linux/mm.h>
@@ -143,37 +143,27 @@ static const unsigned char *const p6_nops[ASM_NOP_MAX+1] = {
 #ifdef CONFIG_X86_64
 
 extern char __vsyscall_0;
-static inline const unsigned char*const * find_nop_table(void)
+const unsigned char *const *find_nop_table(void)
 {
-       return boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
-              boot_cpu_data.x86 < 6 ? k8_nops : p6_nops;
+       if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
+           boot_cpu_has(X86_FEATURE_NOPL))
+               return p6_nops;
+       else
+               return k8_nops;
 }
 
 #else /* CONFIG_X86_64 */
 
-static const struct nop {
-       int cpuid;
-       const unsigned char *const *noptable;
-} noptypes[] = {
-       { X86_FEATURE_K8, k8_nops },
-       { X86_FEATURE_K7, k7_nops },
-       { X86_FEATURE_P4, p6_nops },
-       { X86_FEATURE_P3, p6_nops },
-       { -1, NULL }
-};
-
-static const unsigned char*const * find_nop_table(void)
+const unsigned char *const *find_nop_table(void)
 {
-       const unsigned char *const *noptable = intel_nops;
-       int i;
-
-       for (i = 0; noptypes[i].cpuid >= 0; i++) {
-               if (boot_cpu_has(noptypes[i].cpuid)) {
-                       noptable = noptypes[i].noptable;
-                       break;
-               }
-       }
-       return noptable;
+       if (boot_cpu_has(X86_FEATURE_K8))
+               return k8_nops;
+       else if (boot_cpu_has(X86_FEATURE_K7))
+               return k7_nops;
+       else if (boot_cpu_has(X86_FEATURE_NOPL))
+               return p6_nops;
+       else
+               return intel_nops;
 }
 
 #endif /* CONFIG_X86_64 */
@@ -279,7 +269,7 @@ struct smp_alt_module {
        struct list_head next;
 };
 static LIST_HEAD(smp_alt_modules);
-static DEFINE_SPINLOCK(smp_alt);
+static DEFINE_MUTEX(smp_alt);
 static int smp_mode = 1;       /* protected by smp_alt */
 
 void alternatives_smp_module_add(struct module *mod, char *name,
@@ -312,12 +302,12 @@ void alternatives_smp_module_add(struct module *mod, char *name,
                __func__, smp->locks, smp->locks_end,
                smp->text, smp->text_end, smp->name);
 
-       spin_lock(&smp_alt);
+       mutex_lock(&smp_alt);
        list_add_tail(&smp->next, &smp_alt_modules);
        if (boot_cpu_has(X86_FEATURE_UP))
                alternatives_smp_unlock(smp->locks, smp->locks_end,
                                        smp->text, smp->text_end);
-       spin_unlock(&smp_alt);
+       mutex_unlock(&smp_alt);
 }
 
 void alternatives_smp_module_del(struct module *mod)
@@ -327,17 +317,17 @@ void alternatives_smp_module_del(struct module *mod)
        if (smp_alt_once || noreplace_smp)
                return;
 
-       spin_lock(&smp_alt);
+       mutex_lock(&smp_alt);
        list_for_each_entry(item, &smp_alt_modules, next) {
                if (mod != item->mod)
                        continue;
                list_del(&item->next);
-               spin_unlock(&smp_alt);
+               mutex_unlock(&smp_alt);
                DPRINTK("%s: %s\n", __func__, item->name);
                kfree(item);
                return;
        }
-       spin_unlock(&smp_alt);
+       mutex_unlock(&smp_alt);
 }
 
 void alternatives_smp_switch(int smp)
@@ -359,7 +349,7 @@ void alternatives_smp_switch(int smp)
                return;
        BUG_ON(!smp && (num_online_cpus() > 1));
 
-       spin_lock(&smp_alt);
+       mutex_lock(&smp_alt);
 
        /*
         * Avoid unnecessary switches because it forces JIT based VMs to
@@ -383,7 +373,7 @@ void alternatives_smp_switch(int smp)
                                                mod->text, mod->text_end);
        }
        smp_mode = smp;
-       spin_unlock(&smp_alt);
+       mutex_unlock(&smp_alt);
 }
 
 #endif
@@ -511,31 +501,30 @@ void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
        unsigned long flags;
        char *vaddr;
        int nr_pages = 2;
+       struct page *pages[2];
+       int i;
 
-       BUG_ON(len > sizeof(long));
-       BUG_ON((((long)addr + len - 1) & ~(sizeof(long) - 1))
-               - ((long)addr & ~(sizeof(long) - 1)));
-       if (kernel_text_address((unsigned long)addr)) {
-               struct page *pages[2] = { virt_to_page(addr),
-                       virt_to_page(addr + PAGE_SIZE) };
-               if (!pages[1])
-                       nr_pages = 1;
-               vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
-               BUG_ON(!vaddr);
-               local_irq_save(flags);
-               memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
-               local_irq_restore(flags);
-               vunmap(vaddr);
+       if (!core_kernel_text((unsigned long)addr)) {
+               pages[0] = vmalloc_to_page(addr);
+               pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
        } else {
-               /*
-                * modules are in vmalloc'ed memory, always writable.
-                */
-               local_irq_save(flags);
-               memcpy(addr, opcode, len);
-               local_irq_restore(flags);
+               pages[0] = virt_to_page(addr);
+               WARN_ON(!PageReserved(pages[0]));
+               pages[1] = virt_to_page(addr + PAGE_SIZE);
        }
+       BUG_ON(!pages[0]);
+       if (!pages[1])
+               nr_pages = 1;
+       vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
+       BUG_ON(!vaddr);
+       local_irq_save(flags);
+       memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
+       local_irq_restore(flags);
+       vunmap(vaddr);
        sync_core();
        /* Could also do a CLFLUSH here to speed up CPU recovery; but
           that causes hangs on some VIA CPUs. */
+       for (i = 0; i < len; i++)
+               BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
        return addr;
 }