tlb.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Original code:
  3. * Copyright (C) 2012 - Virtual Open Systems and Columbia University
  4. * Author: Christoffer Dall <c.dall@virtualopensystems.com>
  5. *
  6. * Mostly rewritten in C by Marc Zyngier <marc.zyngier@arm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <asm/kvm_hyp.h>
  21. /**
  22. * Flush per-VMID TLBs
  23. *
  24. * __kvm_tlb_flush_vmid(struct kvm *kvm);
  25. *
  26. * We rely on the hardware to broadcast the TLB invalidation to all CPUs
  27. * inside the inner-shareable domain (which is the case for all v7
  28. * implementations). If we come across a non-IS SMP implementation, we'll
  29. * have to use an IPI based mechanism. Until then, we stick to the simple
  30. * hardware assisted version.
  31. *
  32. * As v7 does not support flushing per IPA, just nuke the whole TLB
  33. * instead, ignoring the ipa value.
  34. */
  35. void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
  36. {
  37. dsb(ishst);
  38. /* Switch to requested VMID */
  39. kvm = kern_hyp_va(kvm);
  40. write_sysreg(kvm->arch.vttbr, VTTBR);
  41. isb();
  42. write_sysreg(0, TLBIALLIS);
  43. dsb(ish);
  44. isb();
  45. write_sysreg(0, VTTBR);
  46. }
  47. void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
  48. {
  49. __kvm_tlb_flush_vmid(kvm);
  50. }
  51. void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
  52. {
  53. struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm);
  54. /* Switch to requested VMID */
  55. write_sysreg(kvm->arch.vttbr, VTTBR);
  56. isb();
  57. write_sysreg(0, TLBIALL);
  58. dsb(nsh);
  59. isb();
  60. write_sysreg(0, VTTBR);
  61. }
  62. void __hyp_text __kvm_flush_vm_context(void)
  63. {
  64. write_sysreg(0, TLBIALLNSNHIS);
  65. write_sysreg(0, ICIALLUIS);
  66. dsb(ish);
  67. }