paravirt_patch_64.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_cpu_ops, clts, "clts");
  12. DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
  13. DEF_NATIVE(pv_cpu_ops, usergs_sysret64, "swapgs; sysretq");
  14. DEF_NATIVE(pv_cpu_ops, swapgs, "swapgs");
  15. DEF_NATIVE(, mov32, "mov %edi, %eax");
  16. DEF_NATIVE(, mov64, "mov %rdi, %rax");
  17. #if defined(CONFIG_PARAVIRT_SPINLOCKS)
  18. DEF_NATIVE(pv_lock_ops, queued_spin_unlock, "movb $0, (%rdi)");
  19. #endif
  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. extern bool pv_is_native_spin_unlock(void);
  31. unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
  32. unsigned long addr, unsigned len)
  33. {
  34. const unsigned char *start, *end;
  35. unsigned ret;
  36. #define PATCH_SITE(ops, x) \
  37. case PARAVIRT_PATCH(ops.x): \
  38. start = start_##ops##_##x; \
  39. end = end_##ops##_##x; \
  40. goto patch_site
  41. switch(type) {
  42. PATCH_SITE(pv_irq_ops, restore_fl);
  43. PATCH_SITE(pv_irq_ops, save_fl);
  44. PATCH_SITE(pv_irq_ops, irq_enable);
  45. PATCH_SITE(pv_irq_ops, irq_disable);
  46. PATCH_SITE(pv_cpu_ops, usergs_sysret64);
  47. PATCH_SITE(pv_cpu_ops, swapgs);
  48. PATCH_SITE(pv_mmu_ops, read_cr2);
  49. PATCH_SITE(pv_mmu_ops, read_cr3);
  50. PATCH_SITE(pv_mmu_ops, write_cr3);
  51. PATCH_SITE(pv_cpu_ops, clts);
  52. PATCH_SITE(pv_cpu_ops, wbinvd);
  53. #if defined(CONFIG_PARAVIRT_SPINLOCKS)
  54. case PARAVIRT_PATCH(pv_lock_ops.queued_spin_unlock):
  55. if (pv_is_native_spin_unlock()) {
  56. start = start_pv_lock_ops_queued_spin_unlock;
  57. end = end_pv_lock_ops_queued_spin_unlock;
  58. goto patch_site;
  59. }
  60. #endif
  61. default:
  62. ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
  63. break;
  64. patch_site:
  65. ret = paravirt_patch_insns(ibuf, len, start, end);
  66. break;
  67. }
  68. #undef PATCH_SITE
  69. return ret;
  70. }