aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64/kvm/hyp/tlb.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm64/kvm/hyp/tlb.c')
-rw-r--r--arch/arm64/kvm/hyp/tlb.c64
1 files changed, 55 insertions, 9 deletions
diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c
index e8e7ba2bc11f..9e1d2b75eecd 100644
--- a/arch/arm64/kvm/hyp/tlb.c
+++ b/arch/arm64/kvm/hyp/tlb.c
@@ -18,14 +18,62 @@
18#include <asm/kvm_hyp.h> 18#include <asm/kvm_hyp.h>
19#include <asm/tlbflush.h> 19#include <asm/tlbflush.h>
20 20
21static void __hyp_text __tlb_switch_to_guest_vhe(struct kvm *kvm)
22{
23 u64 val;
24
25 /*
26 * With VHE enabled, we have HCR_EL2.{E2H,TGE} = {1,1}, and
27 * most TLB operations target EL2/EL0. In order to affect the
28 * guest TLBs (EL1/EL0), we need to change one of these two
29 * bits. Changing E2H is impossible (goodbye TTBR1_EL2), so
30 * let's flip TGE before executing the TLB operation.
31 */
32 write_sysreg(kvm->arch.vttbr, vttbr_el2);
33 val = read_sysreg(hcr_el2);
34 val &= ~HCR_TGE;
35 write_sysreg(val, hcr_el2);
36 isb();
37}
38
39static void __hyp_text __tlb_switch_to_guest_nvhe(struct kvm *kvm)
40{
41 write_sysreg(kvm->arch.vttbr, vttbr_el2);
42 isb();
43}
44
45static hyp_alternate_select(__tlb_switch_to_guest,
46 __tlb_switch_to_guest_nvhe,
47 __tlb_switch_to_guest_vhe,
48 ARM64_HAS_VIRT_HOST_EXTN);
49
50static void __hyp_text __tlb_switch_to_host_vhe(struct kvm *kvm)
51{
52 /*
53 * We're done with the TLB operation, let's restore the host's
54 * view of HCR_EL2.
55 */
56 write_sysreg(0, vttbr_el2);
57 write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2);
58}
59
60static void __hyp_text __tlb_switch_to_host_nvhe(struct kvm *kvm)
61{
62 write_sysreg(0, vttbr_el2);
63}
64
65static hyp_alternate_select(__tlb_switch_to_host,
66 __tlb_switch_to_host_nvhe,
67 __tlb_switch_to_host_vhe,
68 ARM64_HAS_VIRT_HOST_EXTN);
69
21void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) 70void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
22{ 71{
23 dsb(ishst); 72 dsb(ishst);
24 73
25 /* Switch to requested VMID */ 74 /* Switch to requested VMID */
26 kvm = kern_hyp_va(kvm); 75 kvm = kern_hyp_va(kvm);
27 write_sysreg(kvm->arch.vttbr, vttbr_el2); 76 __tlb_switch_to_guest()(kvm);
28 isb();
29 77
30 /* 78 /*
31 * We could do so much better if we had the VA as well. 79 * We could do so much better if we had the VA as well.
@@ -46,7 +94,7 @@ void __hyp_text __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
46 dsb(ish); 94 dsb(ish);
47 isb(); 95 isb();
48 96
49 write_sysreg(0, vttbr_el2); 97 __tlb_switch_to_host()(kvm);
50} 98}
51 99
52void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm) 100void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
@@ -55,14 +103,13 @@ void __hyp_text __kvm_tlb_flush_vmid(struct kvm *kvm)
55 103
56 /* Switch to requested VMID */ 104 /* Switch to requested VMID */
57 kvm = kern_hyp_va(kvm); 105 kvm = kern_hyp_va(kvm);
58 write_sysreg(kvm->arch.vttbr, vttbr_el2); 106 __tlb_switch_to_guest()(kvm);
59 isb();
60 107
61 __tlbi(vmalls12e1is); 108 __tlbi(vmalls12e1is);
62 dsb(ish); 109 dsb(ish);
63 isb(); 110 isb();
64 111
65 write_sysreg(0, vttbr_el2); 112 __tlb_switch_to_host()(kvm);
66} 113}
67 114
68void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu) 115void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
@@ -70,14 +117,13 @@ void __hyp_text __kvm_tlb_flush_local_vmid(struct kvm_vcpu *vcpu)
70 struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm); 117 struct kvm *kvm = kern_hyp_va(kern_hyp_va(vcpu)->kvm);
71 118
72 /* Switch to requested VMID */ 119 /* Switch to requested VMID */
73 write_sysreg(kvm->arch.vttbr, vttbr_el2); 120 __tlb_switch_to_guest()(kvm);
74 isb();
75 121
76 __tlbi(vmalle1); 122 __tlbi(vmalle1);
77 dsb(nsh); 123 dsb(nsh);
78 isb(); 124 isb();
79 125
80 write_sysreg(0, vttbr_el2); 126 __tlb_switch_to_host()(kvm);
81} 127}
82 128
83void __hyp_text __kvm_flush_vm_context(void) 129void __hyp_text __kvm_flush_vm_context(void)