Skip to content

Commit 6354d15

Browse files
rananta468Marc Zyngier
authored andcommitted
KVM: arm64: Implement __kvm_tlb_flush_vmid_range()
Define __kvm_tlb_flush_vmid_range() (for VHE and nVHE) to flush a range of stage-2 page-tables using IPA in one go. If the system supports FEAT_TLBIRANGE, the following patches would conveniently replace global TLBI such as vmalls12e1is in the map, unmap, and dirty-logging paths with ripas2e1is instead. Signed-off-by: Raghavendra Rao Ananta <rananta@google.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Reviewed-by: Shaoqin Huang <shahuang@redhat.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230811045127.3308641-10-rananta@google.com
1 parent 4d73a9c commit 6354d15

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum __kvm_host_smccc_func {
7070
__KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid_ipa,
7171
__KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid_ipa_nsh,
7272
__KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid,
73+
__KVM_HOST_SMCCC_FUNC___kvm_tlb_flush_vmid_range,
7374
__KVM_HOST_SMCCC_FUNC___kvm_flush_cpu_context,
7475
__KVM_HOST_SMCCC_FUNC___kvm_timer_set_cntvoff,
7576
__KVM_HOST_SMCCC_FUNC___vgic_v3_read_vmcr,
@@ -229,6 +230,8 @@ extern void __kvm_tlb_flush_vmid_ipa(struct kvm_s2_mmu *mmu, phys_addr_t ipa,
229230
extern void __kvm_tlb_flush_vmid_ipa_nsh(struct kvm_s2_mmu *mmu,
230231
phys_addr_t ipa,
231232
int level);
233+
extern void __kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu,
234+
phys_addr_t start, unsigned long pages);
232235
extern void __kvm_tlb_flush_vmid(struct kvm_s2_mmu *mmu);
233236

234237
extern void __kvm_timer_set_cntvoff(u64 cntvoff);

arch/arm64/kvm/hyp/nvhe/hyp-main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ static void handle___kvm_tlb_flush_vmid_ipa_nsh(struct kvm_cpu_context *host_ctx
135135
__kvm_tlb_flush_vmid_ipa_nsh(kern_hyp_va(mmu), ipa, level);
136136
}
137137

138+
static void
139+
handle___kvm_tlb_flush_vmid_range(struct kvm_cpu_context *host_ctxt)
140+
{
141+
DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1);
142+
DECLARE_REG(phys_addr_t, start, host_ctxt, 2);
143+
DECLARE_REG(unsigned long, pages, host_ctxt, 3);
144+
145+
__kvm_tlb_flush_vmid_range(kern_hyp_va(mmu), start, pages);
146+
}
147+
138148
static void handle___kvm_tlb_flush_vmid(struct kvm_cpu_context *host_ctxt)
139149
{
140150
DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1);
@@ -327,6 +337,7 @@ static const hcall_t host_hcall[] = {
327337
HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa),
328338
HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa_nsh),
329339
HANDLE_FUNC(__kvm_tlb_flush_vmid),
340+
HANDLE_FUNC(__kvm_tlb_flush_vmid_range),
330341
HANDLE_FUNC(__kvm_flush_cpu_context),
331342
HANDLE_FUNC(__kvm_timer_set_cntvoff),
332343
HANDLE_FUNC(__vgic_v3_read_vmcr),

arch/arm64/kvm/hyp/nvhe/tlb.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,36 @@ void __kvm_tlb_flush_vmid_ipa_nsh(struct kvm_s2_mmu *mmu,
182182
__tlb_switch_to_host(&cxt);
183183
}
184184

185+
void __kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu,
186+
phys_addr_t start, unsigned long pages)
187+
{
188+
struct tlb_inv_context cxt;
189+
unsigned long stride;
190+
191+
/*
192+
* Since the range of addresses may not be mapped at
193+
* the same level, assume the worst case as PAGE_SIZE
194+
*/
195+
stride = PAGE_SIZE;
196+
start = round_down(start, stride);
197+
198+
/* Switch to requested VMID */
199+
__tlb_switch_to_guest(mmu, &cxt, false);
200+
201+
__flush_s2_tlb_range_op(ipas2e1is, start, pages, stride, 0);
202+
203+
dsb(ish);
204+
__tlbi(vmalle1is);
205+
dsb(ish);
206+
isb();
207+
208+
/* See the comment in __kvm_tlb_flush_vmid_ipa() */
209+
if (icache_is_vpipt())
210+
icache_inval_all_pou();
211+
212+
__tlb_switch_to_host(&cxt);
213+
}
214+
185215
void __kvm_tlb_flush_vmid(struct kvm_s2_mmu *mmu)
186216
{
187217
struct tlb_inv_context cxt;

arch/arm64/kvm/hyp/vhe/tlb.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,34 @@ void __kvm_tlb_flush_vmid_ipa_nsh(struct kvm_s2_mmu *mmu,
143143
__tlb_switch_to_host(&cxt);
144144
}
145145

146+
void __kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu,
147+
phys_addr_t start, unsigned long pages)
148+
{
149+
struct tlb_inv_context cxt;
150+
unsigned long stride;
151+
152+
/*
153+
* Since the range of addresses may not be mapped at
154+
* the same level, assume the worst case as PAGE_SIZE
155+
*/
156+
stride = PAGE_SIZE;
157+
start = round_down(start, stride);
158+
159+
dsb(ishst);
160+
161+
/* Switch to requested VMID */
162+
__tlb_switch_to_guest(mmu, &cxt);
163+
164+
__flush_s2_tlb_range_op(ipas2e1is, start, pages, stride, 0);
165+
166+
dsb(ish);
167+
__tlbi(vmalle1is);
168+
dsb(ish);
169+
isb();
170+
171+
__tlb_switch_to_host(&cxt);
172+
}
173+
146174
void __kvm_tlb_flush_vmid(struct kvm_s2_mmu *mmu)
147175
{
148176
struct tlb_inv_context cxt;

0 commit comments

Comments
 (0)