From f3fe2e661221cb139f21bc91bc28980a61f34080 Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Wed, 9 Nov 2022 14:44:50 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Adjust PSCI MEM_PROTECT refcount across share/unshare When a protected guest shares or unshares a page with the host, we should decrement and increment the PSCI MEM_PROTECT refcount respectively since shared pages do not require poisoning on the reclaim path and will therefore not be accounted for. Bug: 258425493 Reported-by: Quentin Perret Signed-off-by: Will Deacon Change-Id: I80a4fad44de4313c6708a8259a1802ded379f03b --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 810436d85608..5d2ce6e14405 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -929,6 +929,9 @@ static int host_complete_share(u64 addr, const struct pkvm_mem_transition *tx, { u64 size = tx->nr_pages * PAGE_SIZE; + if (tx->initiator.id == PKVM_ID_GUEST) + psci_mem_protect_dec(); + return __host_set_page_state_range(addr, size, PKVM_PAGE_SHARED_BORROWED); } @@ -937,6 +940,9 @@ static int host_complete_unshare(u64 addr, const struct pkvm_mem_transition *tx) u64 size = tx->nr_pages * PAGE_SIZE; pkvm_id owner_id = initiator_owner_id(tx); + if (tx->initiator.id == PKVM_ID_GUEST) + psci_mem_protect_inc(); + return host_stage2_set_owner_locked(addr, size, owner_id); }