paravirt_patch_32.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <asm/paravirt.h>
  2. DEF_NATIVE(pv_irq_ops, irq_disable, "cli");
  3. DEF_NATIVE(pv_irq_ops, irq_enable, "sti");
  4. DEF_NATIVE(pv_irq_ops, restore_fl, "push %eax; popf");
  5. DEF_NATIVE(pv_irq_ops, save_fl, "pushf; pop %eax");
  6. DEF_NATIVE(pv_cpu_ops, iret, "iret");
  7. DEF_NATIVE(pv_mmu_ops, read_cr2, "mov %cr2, %eax");
  8. DEF_NATIVE(pv_mmu_ops, write_cr3, "mov %eax, %cr3");
  9. DEF_NATIVE(pv_mmu_ops, read_cr3, "mov %cr3, %eax");
  10. #if defined(CONFIG_PARAVIRT_SPINLOCKS)
  11. DEF_NATIVE(pv_lock_ops, queued_spin_unlock, "movb $0, (%eax)");
  12. DEF_NATIVE(pv_lock_ops, vcpu_is_preempted, "xor %eax, %eax");
  13. #endif
  14. unsigned paravirt_patch_ident_32(void *insnbuf, unsigned len)
  15. {
  16. /* arg in %eax, return in %eax */
  17. return 0;
  18. }
  19. unsigned paravirt_patch_ident_64(void *insnbuf, unsigned len)
  20. {
  21. /* arg in %edx:%eax, return in %edx:%eax */
  22. return 0;
  23. }
  24. extern bool pv_is_native_spin_unlock(void);
  25. extern bool pv_is_native_vcpu_is_preempted(void);
  26. unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
  27. unsigned long addr, unsigned len)
  28. {
  29. const unsigned char *start, *end;
  30. unsigned ret;
  31. #define PATCH_SITE(ops, x) \
  32. case PARAVIRT_PATCH(ops.x): \
  33. start = start_##ops##_##x; \
  34. end = end_##ops##_##x; \
  35. goto patch_site
  36. switch (type) {
  37. PATCH_SITE(pv_irq_ops, irq_disable);
  38. PATCH_SITE(pv_irq_ops, irq_enable);
  39. PATCH_SITE(pv_irq_ops, restore_fl);
  40. PATCH_SITE(pv_irq_ops, save_fl);
  41. PATCH_SITE(pv_cpu_ops, iret);
  42. PATCH_SITE(pv_mmu_ops, read_cr2);
  43. PATCH_SITE(pv_mmu_ops, read_cr3);
  44. PATCH_SITE(pv_mmu_ops, write_cr3);
  45. #if defined(CONFIG_PARAVIRT_SPINLOCKS)
  46. case PARAVIRT_PATCH(pv_lock_ops.queued_spin_unlock):
  47. if (pv_is_native_spin_unlock()) {
  48. start = start_pv_lock_ops_queued_spin_unlock;
  49. end = end_pv_lock_ops_queued_spin_unlock;
  50. goto patch_site;
  51. }
  52. goto patch_default;
  53. case PARAVIRT_PATCH(pv_lock_ops.vcpu_is_preempted):
  54. if (pv_is_native_vcpu_is_preempted()) {
  55. start = start_pv_lock_ops_vcpu_is_preempted;
  56. end = end_pv_lock_ops_vcpu_is_preempted;
  57. goto patch_site;
  58. }
  59. goto patch_default;
  60. #endif
  61. default:
  62. patch_default: __maybe_unused
  63. ret = paravirt_patch_default(type, clobbers, ibuf, addr, len);
  64. break;
  65. patch_site:
  66. ret = paravirt_patch_insns(ibuf, len, start, end);
  67. break;
  68. }
  69. #undef PATCH_SITE
  70. return ret;
  71. }