paravirt_patch_32.c 2.3 KB

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