kvm_mm.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef __KVM_MM_H__
  3. #define __KVM_MM_H__ 1
  4. /*
  5. * Architectures can choose whether to use an rwlock or spinlock
  6. * for the mmu_lock. These macros, for use in common code
  7. * only, avoids using #ifdefs in places that must deal with
  8. * multiple architectures.
  9. */
  10. #ifdef KVM_HAVE_MMU_RWLOCK
  11. #define KVM_MMU_LOCK_INIT(kvm) rwlock_init(&(kvm)->mmu_lock)
  12. #define KVM_MMU_LOCK(kvm) write_lock(&(kvm)->mmu_lock)
  13. #define KVM_MMU_UNLOCK(kvm) write_unlock(&(kvm)->mmu_lock)
  14. #else
  15. #define KVM_MMU_LOCK_INIT(kvm) spin_lock_init(&(kvm)->mmu_lock)
  16. #define KVM_MMU_LOCK(kvm) spin_lock(&(kvm)->mmu_lock)
  17. #define KVM_MMU_UNLOCK(kvm) spin_unlock(&(kvm)->mmu_lock)
  18. #endif /* KVM_HAVE_MMU_RWLOCK */
  19. kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool interruptible,
  20. bool *async, bool write_fault, bool *writable);
  21. #ifdef CONFIG_HAVE_KVM_PFNCACHE
  22. void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm,
  23. unsigned long start,
  24. unsigned long end);
  25. #else
  26. static inline void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm,
  27. unsigned long start,
  28. unsigned long end)
  29. {
  30. }
  31. #endif /* HAVE_KVM_PFNCACHE */
  32. #ifdef CONFIG_KVM_PRIVATE_MEM
  33. void kvm_gmem_init(struct module *module);
  34. int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args);
  35. int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,
  36. unsigned int fd, loff_t offset);
  37. void kvm_gmem_unbind(struct kvm_memory_slot *slot);
  38. #else
  39. static inline void kvm_gmem_init(struct module *module)
  40. {
  41. }
  42. static inline int kvm_gmem_bind(struct kvm *kvm,
  43. struct kvm_memory_slot *slot,
  44. unsigned int fd, loff_t offset)
  45. {
  46. WARN_ON_ONCE(1);
  47. return -EIO;
  48. }
  49. static inline void kvm_gmem_unbind(struct kvm_memory_slot *slot)
  50. {
  51. WARN_ON_ONCE(1);
  52. }
  53. #endif /* CONFIG_KVM_PRIVATE_MEM */
  54. #endif /* __KVM_MM_H__ */