[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z-6p49EcsZKid7L1@google.com>
Date: Thu, 3 Apr 2025 15:31:47 +0000
From: Quentin Perret <qperret@...gle.com>
To: Vincent Donnefort <vdonnefort@...gle.com>
Cc: maz@...nel.org, oliver.upton@...ux.dev, joey.gouly@....com,
suzuki.poulose@....com, yuzenghui@...wei.com,
catalin.marinas@....com, will@...nel.org,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.linux.dev,
linux-kernel@...r.kernel.org, kernel-team@...roid.com
Subject: Re: [PATCH v2 3/9] KVM: arm64: Add a range to
__pkvm_host_unshare_guest()
On Thursday 06 Mar 2025 at 11:00:32 (+0000), Vincent Donnefort wrote:
> @@ -1012,51 +1011,52 @@ static int __check_host_shared_guest(struct pkvm_hyp_vm *vm, u64 *__phys, u64 ip
> return ret;
> if (!kvm_pte_valid(pte))
> return -ENOENT;
> - if (level != KVM_PGTABLE_LAST_LEVEL)
> + if (kvm_granule_size(level) != size)
> return -E2BIG;
>
> - state = guest_get_page_state(pte, ipa);
> - if (state != PKVM_PAGE_SHARED_BORROWED)
> - return -EPERM;
> + ret = __guest_check_page_state_range(vm, ipa, size, PKVM_PAGE_SHARED_BORROWED);
> + if (ret)
> + return ret;
Given that hard rely on kvm_granule_size(level) == size above, we should
be guaranteed that the PTE covers the entire range we're interested in.
So is there a point in starting a new page-table walk here? Could we
just keep guest_get_page_state() directly?
>
> phys = kvm_pte_to_phys(pte);
> - ret = check_range_allowed_memory(phys, phys + PAGE_SIZE);
> + ret = check_range_allowed_memory(phys, phys + size);
> if (WARN_ON(ret))
> return ret;
>
> - page = hyp_phys_to_page(phys);
> - if (page->host_state != PKVM_PAGE_SHARED_OWNED)
> - return -EPERM;
> - if (WARN_ON(!page->host_share_guest_count))
> - return -EINVAL;
> + for_each_hyp_page(phys, size, page) {
> + if (page->host_state != PKVM_PAGE_SHARED_OWNED)
> + return -EPERM;
> + if (WARN_ON(!page->host_share_guest_count))
> + return -EINVAL;
> + }
>
> *__phys = phys;
>
> return 0;
> }
Powered by blists - more mailing lists