x86, locking/spinlocks: Remove ticket (spin)lock implementation
[cascardo/linux.git] / arch / x86 / kernel / paravirt_patch_64.c
1 #include <asm/paravirt.h>
2 #include <asm/asm-offsets.h>
3 #include <linux/stringify.h>
4
5 DEF_NATIVE(pv_irq_ops, irq_disable, "cli");
6 DEF_NATIVE(pv_irq_ops, irq_enable, "sti");
7 DEF_NATIVE(pv_irq_ops, restore_fl, "pushq %rdi; popfq");
8 DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
9 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
10 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
11 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
12 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
13 DEF_NATIVE(pv_cpu_ops, clts, "clts");
14 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
15
16 DEF_NATIVE(pv_cpu_ops, usergs_sysret64, "swapgs; sysretq");
17 DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs");
18
19 DEF_NATIVE(, mov32, "mov %edi, %eax");
20 DEF_NATIVE(, mov64, "mov %rdi, %rax");
21
22 #if defined(CONFIG_PARAVIRT_SPINLOCKS)
23 DEF_NATIVE(pv_lock_ops, queued_spin_unlock, "movb $0, (%rdi)");
24 #endif
25
26 unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len)
27 {
28         return paravirt_patch_insns(insnbuf, len,
29                                     start__mov32, end__mov32);
30 }
31
32 unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
33 {
34         return paravirt_patch_insns(insnbuf, len,
35                                     start__mov64, end__mov64);
36 }
37
38 extern bool pv_is_native_spin_unlock(void);
39
40 unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
41                       unsigned long addr, unsigned len)
42 {
43         const unsigned char *start, *end;
44         unsigned ret;
45
46 #define PATCH_SITE(ops, x)                                      \
47                 case PARAVIRT_PATCH(ops.x):                     \
48                         start = start_##ops##_##x;              \
49                         end = end_##ops##_##x;                  \
50                         goto patch_site
51         switch(type) {
52                 PATCH_SITE(pv_irq_ops, restore_fl);
53                 PATCH_SITE(pv_irq_ops, save_fl);
54                 PATCH_SITE(pv_irq_ops, irq_enable);
55                 PATCH_SITE(pv_irq_ops, irq_disable);
56                 PATCH_SITE(pv_cpu_ops, usergs_sysret64);
57                 PATCH_SITE(pv_cpu_ops, swapgs);
58                 PATCH_SITE(pv_mmu_ops, read_cr2);
59                 PATCH_SITE(pv_mmu_ops, read_cr3);
60                 PATCH_SITE(pv_mmu_ops, write_cr3);
61                 PATCH_SITE(pv_cpu_ops, clts);
62                 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
63                 PATCH_SITE(pv_cpu_ops, wbinvd);
64 #if defined(CONFIG_PARAVIRT_SPINLOCKS)
65                 case PARAVIRT_PATCH(pv_lock_ops.queued_spin_unlock):
66                         if (pv_is_native_spin_unlock()) {
67                                 start = start_pv_lock_ops_queued_spin_unlock;
68                                 end   = end_pv_lock_ops_queued_spin_unlock;
69                                 goto patch_site;
70                         }
71 #endif
72
73         default:
74                 ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
75                 break;
76
77 patch_site:
78                 ret = paravirt_patch_insns(ibuf, len, start, end);
79                 break;
80         }
81 #undef PATCH_SITE
82         return ret;
83 }