5a20aa56efc022bc60f2ad38a4954c700fae1881
[linux-2.6-microblaze.git] / arch / x86 / kernel / paravirt_patch_32.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <asm/paravirt.h>
3
4 DEF_NATIVE(irq, irq_disable, "cli");
5 DEF_NATIVE(irq, irq_enable, "sti");
6 DEF_NATIVE(irq, restore_fl, "push %eax; popf");
7 DEF_NATIVE(irq, save_fl, "pushf; pop %eax");
8 #ifdef CONFIG_PARAVIRT_XXL
9 DEF_NATIVE(cpu, iret, "iret");
10 #endif
11 DEF_NATIVE(mmu, read_cr2, "mov %cr2, %eax");
12 DEF_NATIVE(mmu, write_cr3, "mov %eax, %cr3");
13 DEF_NATIVE(mmu, read_cr3, "mov %cr3, %eax");
14
15 #if defined(CONFIG_PARAVIRT_SPINLOCKS)
16 DEF_NATIVE(lock, queued_spin_unlock, "movb $0, (%eax)");
17 DEF_NATIVE(lock, vcpu_is_preempted, "xor %eax, %eax");
18 #endif
19
20 unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len)
21 {
22         /* arg in %eax, return in %eax */
23         return 0;
24 }
25
26 unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
27 {
28         /* arg in %edx:%eax, return in %edx:%eax */
29         return 0;
30 }
31
32 extern bool pv_is_native_spin_unlock(void);
33 extern bool pv_is_native_vcpu_is_preempted(void);
34
35 unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
36 {
37         const unsigned char *start, *end;
38         unsigned ret;
39
40 #define PATCH_SITE(ops, x)                                      \
41                 case PARAVIRT_PATCH(ops.x):                     \
42                         start = start_##ops##_##x;              \
43                         end = end_##ops##_##x;                  \
44                         goto patch_site
45         switch (type) {
46                 PATCH_SITE(irq, irq_disable);
47                 PATCH_SITE(irq, irq_enable);
48                 PATCH_SITE(irq, restore_fl);
49                 PATCH_SITE(irq, save_fl);
50 #ifdef CONFIG_PARAVIRT_XXL
51                 PATCH_SITE(cpu, iret);
52 #endif
53                 PATCH_SITE(mmu, read_cr2);
54                 PATCH_SITE(mmu, read_cr3);
55                 PATCH_SITE(mmu, write_cr3);
56 #if defined(CONFIG_PARAVIRT_SPINLOCKS)
57                 case PARAVIRT_PATCH(lock.queued_spin_unlock):
58                         if (pv_is_native_spin_unlock()) {
59                                 start = start_lock_queued_spin_unlock;
60                                 end   = end_lock_queued_spin_unlock;
61                                 goto patch_site;
62                         }
63                         goto patch_default;
64
65                 case PARAVIRT_PATCH(lock.vcpu_is_preempted):
66                         if (pv_is_native_vcpu_is_preempted()) {
67                                 start = start_lock_vcpu_is_preempted;
68                                 end   = end_lock_vcpu_is_preempted;
69                                 goto patch_site;
70                         }
71                         goto patch_default;
72 #endif
73
74         default:
75 patch_default: __maybe_unused
76                 ret = paravirt_patch_default(type, ibuf, addr, len);
77                 break;
78
79 patch_site:
80                 ret = paravirt_patch_insns(ibuf, len, start, end);
81                 break;
82         }
83 #undef PATCH_SITE
84         return ret;
85 }