Revert "ANDROID: KVM: arm64: Use PSCI MEM_PROTECT to zap guest pages on reset"

This reverts commit 4347917056.

Bug: 233587962
Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: I3224c53a791029db52821f5333fe0ba9da168f64
This commit is contained in:
Will Deacon
2022-07-07 15:48:59 +01:00
parent 668645c585
commit a66888825b
4 changed files with 4 additions and 59 deletions

View File

@@ -91,9 +91,6 @@ int refill_memcache(struct kvm_hyp_memcache *mc, unsigned long min_pages,
struct kvm_hyp_memcache *host_mc);
void reclaim_guest_pages(struct kvm_shadow_vm *vm, struct kvm_hyp_memcache *mc);
void psci_mem_protect_inc(void);
void psci_mem_protect_dec(void);
static __always_inline void __load_host_stage2(void)
{
if (static_branch_likely(&kvm_protected_mode_initialized))

View File

@@ -1073,14 +1073,10 @@ static int guest_complete_donation(u64 addr, const struct pkvm_mem_transition *t
u64 size = tx->nr_pages * PAGE_SIZE;
int err;
if (tx->initiator.id == PKVM_ID_HOST) {
psci_mem_protect_inc();
if (ipa_in_pvmfw_region(vm, addr)) {
err = pkvm_load_pvmfw_pages(vm, addr, phys, size);
if (err)
return err;
}
if (tx->initiator.id == PKVM_ID_HOST && ipa_in_pvmfw_region(vm, addr)) {
err = pkvm_load_pvmfw_pages(vm, addr, phys, size);
if (err)
return err;
}
return kvm_pgtable_stage2_map(&vm->pgt, addr, size, phys, prot,
@@ -1897,7 +1893,6 @@ int __pkvm_host_reclaim_page(u64 pfn)
if (ret)
goto unlock;
page->flags &= ~HOST_PAGE_NEED_POISONING;
psci_mem_protect_dec();
}
ret = host_stage2_set_owner_locked(addr, PAGE_SIZE, pkvm_host_id);

View File

@@ -222,44 +222,6 @@ asmlinkage void __noreturn kvm_host_psci_cpu_entry(bool is_cpu_on)
__host_enter(host_ctxt);
}
static DEFINE_HYP_SPINLOCK(mem_protect_lock);
static u64 psci_mem_protect(s64 offset)
{
static u64 cnt;
u64 new = cnt + offset;
hyp_assert_lock_held(&mem_protect_lock);
if (!offset || kvm_host_psci_config.version < PSCI_VERSION(1, 1))
return cnt;
if (!cnt || !new)
psci_call(PSCI_1_1_FN64_MEM_PROTECT, offset < 0 ? 0 : 1, 0, 0);
cnt = new;
return cnt;
}
static bool psci_mem_protect_active(void)
{
return psci_mem_protect(0);
}
void psci_mem_protect_inc(void)
{
hyp_spin_lock(&mem_protect_lock);
psci_mem_protect(1);
hyp_spin_unlock(&mem_protect_lock);
}
void psci_mem_protect_dec(void)
{
hyp_spin_lock(&mem_protect_lock);
psci_mem_protect(-1);
hyp_spin_unlock(&mem_protect_lock);
}
static unsigned long psci_0_1_handler(u64 func_id, struct kvm_cpu_context *host_ctxt)
{
if (is_psci_0_1(cpu_off, func_id) || is_psci_0_1(migrate, func_id))
@@ -289,8 +251,6 @@ static unsigned long psci_0_2_handler(u64 func_id, struct kvm_cpu_context *host_
case PSCI_0_2_FN_SYSTEM_OFF:
case PSCI_0_2_FN_SYSTEM_RESET:
pkvm_clear_pvmfw_pages();
/* Avoid racing with a MEM_PROTECT call. */
hyp_spin_lock(&mem_protect_lock);
return psci_forward(host_ctxt);
case PSCI_0_2_FN64_CPU_SUSPEND:
return psci_cpu_suspend(func_id, host_ctxt);
@@ -306,11 +266,6 @@ static unsigned long psci_1_0_handler(u64 func_id, struct kvm_cpu_context *host_
switch (func_id) {
case PSCI_1_1_FN64_SYSTEM_RESET2:
pkvm_clear_pvmfw_pages();
hyp_spin_lock(&mem_protect_lock);
if (psci_mem_protect_active()) {
return psci_0_2_handler(PSCI_0_2_FN_SYSTEM_RESET,
host_ctxt);
}
fallthrough;
case PSCI_1_0_FN_PSCI_FEATURES:
case PSCI_1_0_FN_SET_SUSPEND_MODE:

View File

@@ -55,8 +55,6 @@
#define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14)
#define PSCI_1_1_FN64_SYSTEM_RESET2 PSCI_0_2_FN64(18)
#define PSCI_1_1_FN64_MEM_PROTECT PSCI_0_2_FN64(19)
/* PSCI v0.2 power state encoding for CPU_SUSPEND function */
#define PSCI_0_2_POWER_STATE_ID_MASK 0xffff
#define PSCI_0_2_POWER_STATE_ID_SHIFT 0