Skip to content

Commit 0adce4d

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Introduce __pkvm_tlb_flush_vmid()
Introduce a new hypercall to flush the TLBs of non-protected guests. The host kernel will be responsible for issuing this hypercall after changing stage-2 permissions using the __pkvm_host_relax_guest_perms() or __pkvm_host_wrprotect_guest() paths. This is left under the host's responsibility for performance reasons. Note however that the TLB maintenance for all *unmap* operations still remains entirely under the hypervisor's responsibility for security reasons -- an unmapped page may be donated to another entity, so a stale TLB entry could be used to leak private data. Tested-by: Fuad Tabba <[email protected]> Reviewed-by: Fuad Tabba <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 76f0b18 commit 0adce4d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ enum __kvm_host_smccc_func {
8787
__KVM_HOST_SMCCC_FUNC___pkvm_teardown_vm,
8888
__KVM_HOST_SMCCC_FUNC___pkvm_vcpu_load,
8989
__KVM_HOST_SMCCC_FUNC___pkvm_vcpu_put,
90+
__KVM_HOST_SMCCC_FUNC___pkvm_tlb_flush_vmid,
9091
};
9192

9293
#define DECLARE_KVM_VHE_SYM(sym) extern char sym[]

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,22 @@ static void handle___kvm_tlb_flush_vmid(struct kvm_cpu_context *host_ctxt)
389389
__kvm_tlb_flush_vmid(kern_hyp_va(mmu));
390390
}
391391

392+
static void handle___pkvm_tlb_flush_vmid(struct kvm_cpu_context *host_ctxt)
393+
{
394+
DECLARE_REG(pkvm_handle_t, handle, host_ctxt, 1);
395+
struct pkvm_hyp_vm *hyp_vm;
396+
397+
if (!is_protected_kvm_enabled())
398+
return;
399+
400+
hyp_vm = get_np_pkvm_hyp_vm(handle);
401+
if (!hyp_vm)
402+
return;
403+
404+
__kvm_tlb_flush_vmid(&hyp_vm->kvm.arch.mmu);
405+
put_pkvm_hyp_vm(hyp_vm);
406+
}
407+
392408
static void handle___kvm_flush_cpu_context(struct kvm_cpu_context *host_ctxt)
393409
{
394410
DECLARE_REG(struct kvm_s2_mmu *, mmu, host_ctxt, 1);
@@ -573,6 +589,7 @@ static const hcall_t host_hcall[] = {
573589
HANDLE_FUNC(__pkvm_teardown_vm),
574590
HANDLE_FUNC(__pkvm_vcpu_load),
575591
HANDLE_FUNC(__pkvm_vcpu_put),
592+
HANDLE_FUNC(__pkvm_tlb_flush_vmid),
576593
};
577594

578595
static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)

0 commit comments

Comments
 (0)