Skip to content

Commit b8cc6eb

Browse files
willdeaconMarc Zyngier
authored andcommitted
KVM: arm64: Expose unshare hypercall to the host
Introduce an unshare hypercall which can be used to unmap memory from the hypervisor stage-1 in nVHE protected mode. This will be useful to update the EL2 ownership state of pages during guest teardown, and avoids keeping dangling mappings to unreferenced portions of memory. Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 376a240 commit b8cc6eb

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ enum __kvm_host_smccc_func {
6363

6464
/* Hypercalls available after pKVM finalisation */
6565
__KVM_HOST_SMCCC_FUNC___pkvm_host_share_hyp,
66+
__KVM_HOST_SMCCC_FUNC___pkvm_host_unshare_hyp,
6667
__KVM_HOST_SMCCC_FUNC___kvm_adjust_pc,
6768
__KVM_HOST_SMCCC_FUNC___kvm_vcpu_run,
6869
__KVM_HOST_SMCCC_FUNC___kvm_flush_vm_context,

arch/arm64/kvm/hyp/include/nvhe/mem_protect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ extern const u8 pkvm_hyp_id;
5555

5656
int __pkvm_prot_finalize(void);
5757
int __pkvm_host_share_hyp(u64 pfn);
58+
int __pkvm_host_unshare_hyp(u64 pfn);
5859

5960
bool addr_is_memory(phys_addr_t phys);
6061
int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ static void handle___pkvm_host_share_hyp(struct kvm_cpu_context *host_ctxt)
147147
cpu_reg(host_ctxt, 1) = __pkvm_host_share_hyp(pfn);
148148
}
149149

150+
static void handle___pkvm_host_unshare_hyp(struct kvm_cpu_context *host_ctxt)
151+
{
152+
DECLARE_REG(u64, pfn, host_ctxt, 1);
153+
154+
cpu_reg(host_ctxt, 1) = __pkvm_host_unshare_hyp(pfn);
155+
}
156+
150157
static void handle___pkvm_create_private_mapping(struct kvm_cpu_context *host_ctxt)
151158
{
152159
DECLARE_REG(phys_addr_t, phys, host_ctxt, 1);
@@ -184,6 +191,7 @@ static const hcall_t host_hcall[] = {
184191
HANDLE_FUNC(__pkvm_prot_finalize),
185192

186193
HANDLE_FUNC(__pkvm_host_share_hyp),
194+
HANDLE_FUNC(__pkvm_host_unshare_hyp),
187195
HANDLE_FUNC(__kvm_adjust_pc),
188196
HANDLE_FUNC(__kvm_vcpu_run),
189197
HANDLE_FUNC(__kvm_flush_vm_context),

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,36 @@ int __pkvm_host_share_hyp(u64 pfn)
768768

769769
return ret;
770770
}
771+
772+
int __pkvm_host_unshare_hyp(u64 pfn)
773+
{
774+
int ret;
775+
u64 host_addr = hyp_pfn_to_phys(pfn);
776+
u64 hyp_addr = (u64)__hyp_va(host_addr);
777+
struct pkvm_mem_share share = {
778+
.tx = {
779+
.nr_pages = 1,
780+
.initiator = {
781+
.id = PKVM_ID_HOST,
782+
.addr = host_addr,
783+
.host = {
784+
.completer_addr = hyp_addr,
785+
},
786+
},
787+
.completer = {
788+
.id = PKVM_ID_HYP,
789+
},
790+
},
791+
.completer_prot = PAGE_HYP,
792+
};
793+
794+
host_lock_component();
795+
hyp_lock_component();
796+
797+
ret = do_unshare(&share);
798+
799+
hyp_unlock_component();
800+
host_unlock_component();
801+
802+
return ret;
803+
}

0 commit comments

Comments
 (0)