1 // SPDX-License-Identifier: GPL-2.0
2 #include <asm/paravirt.h>
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");
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");
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");
20 unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len)
22 /* arg in %eax, return in %eax */
26 unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
28 /* arg in %edx:%eax, return in %edx:%eax */
32 extern bool pv_is_native_spin_unlock(void);
33 extern bool pv_is_native_vcpu_is_preempted(void);
35 unsigned native_patch(u8 type, void *ibuf, unsigned long addr, unsigned len)
37 const unsigned char *start, *end;
40 #define PATCH_SITE(ops, x) \
41 case PARAVIRT_PATCH(ops.x): \
42 start = start_##ops##_##x; \
43 end = end_##ops##_##x; \
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);
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;
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;
75 patch_default: __maybe_unused
76 ret = paravirt_patch_default(type, ibuf, addr, len);
80 ret = paravirt_patch_insns(ibuf, len, start, end);