paravirt_patch_64.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <asm/paravirt.h>
  2. #include <asm/asm-offsets.h>
  3. #include <linux/stringify.h>
  4. DEF_NATIVE(pv_irq_ops, irq_disable, "cli");
  5. DEF_NATIVE(pv_irq_ops, irq_enable, "sti");
  6. DEF_NATIVE(pv_irq_ops, restore_fl, "pushq %rdi; popfq");
  7. DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
  8. DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
  9. DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
  10. DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
  11. DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
  12. DEF_NATIVE(pv_cpu_ops, clts, "clts");
  13. DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
  14. DEF_NATIVE(pv_cpu_ops, irq_enable_sysexit, "swapgs; sti; sysexit");
  15. DEF_NATIVE(pv_cpu_ops, usergs_sysret64, "swapgs; sysretq");
  16. DEF_NATIVE(pv_cpu_ops, usergs_sysret32, "swapgs; sysretl");
  17. DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs");
  18. DEF_NATIVE(, mov32, "mov %edi, %eax");
  19. DEF_NATIVE(, mov64, "mov %rdi, %rax");
  20. unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len)
  21. {
  22. return paravirt_patch_insns(insnbuf, len,
  23. start__mov32, end__mov32);
  24. }
  25. unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
  26. {
  27. return paravirt_patch_insns(insnbuf, len,
  28. start__mov64, end__mov64);
  29. }
  30. unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
  31. unsigned long addr, unsigned len)
  32. {
  33. const unsigned char *start, *end;
  34. unsigned ret;
  35. #define PATCH_SITE(ops, x) \
  36. case PARAVIRT_PATCH(ops.x): \
  37. start = start_##ops##_##x; \
  38. end = end_##ops##_##x; \
  39. goto patch_site
  40. switch(type) {
  41. PATCH_SITE(pv_irq_ops, restore_fl);
  42. PATCH_SITE(pv_irq_ops, save_fl);
  43. PATCH_SITE(pv_irq_ops, irq_enable);
  44. PATCH_SITE(pv_irq_ops, irq_disable);
  45. PATCH_SITE(pv_cpu_ops, irq_enable_sysexit);
  46. PATCH_SITE(pv_cpu_ops, usergs_sysret32);
  47. PATCH_SITE(pv_cpu_ops, usergs_sysret64);
  48. PATCH_SITE(pv_cpu_ops, swapgs);
  49. PATCH_SITE(pv_mmu_ops, read_cr2);
  50. PATCH_SITE(pv_mmu_ops, read_cr3);
  51. PATCH_SITE(pv_mmu_ops, write_cr3);
  52. PATCH_SITE(pv_cpu_ops, clts);
  53. PATCH_SITE(pv_mmu_ops, flush_tlb_single);
  54. PATCH_SITE(pv_cpu_ops, wbinvd);
  55. patch_site:
  56. ret = paravirt_patch_insns(ibuf, len, start, end);
  57. break;
  58. default:
  59. ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
  60. break;
  61. }
  62. #undef PATCH_SITE
  63. return ret;
  64. }