ANDROID: KVM: arm64: Allow relinqush for p-guest with huge-mappings

Issue a hyp_request SPLIT to the host whenever a huge-mapping is hit by
the relinquish path. We can then let the guest retry to relinquish the
memory.

Bug: 419548963
Bug: 357781595
Bug: 278011447
Change-Id: I171499f23c253f1244d9967d9b0a9bfbde922d34
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
This commit is contained in:
Vincent Donnefort
2025-05-22 18:19:04 +01:00
parent 05a9e97a23
commit 10a77358c7
2 changed files with 15 additions and 3 deletions

View File

@@ -411,8 +411,10 @@ int __pkvm_guest_relinquish_to_host(struct pkvm_hyp_vcpu *vcpu,
goto end;
/* We don't support splitting non-leaf mappings */
if (level != KVM_PGTABLE_LAST_LEVEL)
if (level != KVM_PGTABLE_LAST_LEVEL) {
ret = -E2BIG;
goto end;
}
state = guest_get_page_state(pte, ipa);
if (state != PKVM_PAGE_OWNED) {

View File

@@ -1626,9 +1626,19 @@ static bool pkvm_memrelinquish_call(struct pkvm_hyp_vcpu *hyp_vcpu,
goto out_guest_err;
ret = __pkvm_guest_relinquish_to_host(hyp_vcpu, ipa, &pa);
if (ret == -ENOMEM) {
if (pkvm_handle_empty_memcache(hyp_vcpu, exit_code))
if (ret == -E2BIG) {
struct kvm_hyp_req *req = pkvm_hyp_req_reserve(hyp_vcpu, KVM_HYP_REQ_TYPE_SPLIT);
if (!req) {
ret = -ENOMEM;
goto out_guest_err;
}
req->split.guest_ipa = ALIGN_DOWN(ipa, PMD_SIZE);
req->split.size = PMD_SIZE;
write_sysreg_el2(read_sysreg_el2(SYS_ELR) - 4, SYS_ELR);
*exit_code = ARM_EXCEPTION_HYP_REQ;
return false;
} else if (ret) {