• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_cpu_ops, clts, "clts");
13 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
14 
15 DEF_NATIVE(pv_cpu_ops, usergs_sysret64, "swapgs; sysretq");
16 DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs");
17 
18 DEF_NATIVE(, mov32, "mov %edi, %eax");
19 DEF_NATIVE(, mov64, "mov %rdi, %rax");
20 
21 #if defined(CONFIG_PARAVIRT_SPINLOCKS)
22 DEF_NATIVE(pv_lock_ops, queued_spin_unlock, "movb $0, (%rdi)");
23 #endif
24 
paravirt_patch_ident_32(void * insnbuf,unsigned len)25 unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len)
26 {
27 	return paravirt_patch_insns(insnbuf, len,
28 				    start__mov32, end__mov32);
29 }
30 
paravirt_patch_ident_64(void * insnbuf,unsigned len)31 unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
32 {
33 	return paravirt_patch_insns(insnbuf, len,
34 				    start__mov64, end__mov64);
35 }
36 
37 extern bool pv_is_native_spin_unlock(void);
38 
native_patch(u8 type,u16 clobbers,void * ibuf,unsigned long addr,unsigned len)39 unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
40 		      unsigned long addr, unsigned len)
41 {
42 	const unsigned char *start, *end;
43 	unsigned ret;
44 
45 #define PATCH_SITE(ops, x)					\
46 		case PARAVIRT_PATCH(ops.x):			\
47 			start = start_##ops##_##x;		\
48 			end = end_##ops##_##x;			\
49 			goto patch_site
50 	switch(type) {
51 		PATCH_SITE(pv_irq_ops, restore_fl);
52 		PATCH_SITE(pv_irq_ops, save_fl);
53 		PATCH_SITE(pv_irq_ops, irq_enable);
54 		PATCH_SITE(pv_irq_ops, irq_disable);
55 		PATCH_SITE(pv_cpu_ops, usergs_sysret64);
56 		PATCH_SITE(pv_cpu_ops, swapgs);
57 		PATCH_SITE(pv_mmu_ops, read_cr2);
58 		PATCH_SITE(pv_mmu_ops, read_cr3);
59 		PATCH_SITE(pv_mmu_ops, write_cr3);
60 		PATCH_SITE(pv_cpu_ops, clts);
61 		PATCH_SITE(pv_cpu_ops, wbinvd);
62 #if defined(CONFIG_PARAVIRT_SPINLOCKS)
63 		case PARAVIRT_PATCH(pv_lock_ops.queued_spin_unlock):
64 			if (pv_is_native_spin_unlock()) {
65 				start = start_pv_lock_ops_queued_spin_unlock;
66 				end   = end_pv_lock_ops_queued_spin_unlock;
67 				goto patch_site;
68 			}
69 #endif
70 
71 	default:
72 		ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
73 		break;
74 
75 patch_site:
76 		ret = paravirt_patch_insns(ibuf, len, start, end);
77 		break;
78 	}
79 #undef PATCH_SITE
80 	return ret;
81 }
82