From: Vincent Donnefort <vdonnefort@google.com>
To: Quentin Perret <qperret@google.com>
Cc: maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com,
suzuki.poulose@arm.com, yuzenghui@huawei.com,
catalin.marinas@arm.com, will@kernel.org,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH v2 3/9] KVM: arm64: Add a range to __pkvm_host_unshare_guest()
Date: Fri, 4 Apr 2025 18:05:28 +0100 [thread overview]
Message-ID: <Z_ARWDH60WayM0MP@google.com> (raw)
In-Reply-To: <Z-6p49EcsZKid7L1@google.com>
On Thu, Apr 03, 2025 at 03:31:47PM +0000, Quentin Perret wrote:
> 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?
Ha yes, the walk wouldn't do anything more than what we can with that PTE!
>
> >
> > 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;
> > }
next prev parent reply other threads:[~2025-04-04 17:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 11:00 [PATCH v2 0/9] Stage-2 huge mappings for pKVM np-guests Vincent Donnefort
2025-03-06 11:00 ` [PATCH v2 1/9] KVM: arm64: Handle huge mappings for np-guest CMOs Vincent Donnefort
2025-04-03 14:24 ` Quentin Perret
2025-03-06 11:00 ` [PATCH v2 2/9] KVM: arm64: Add a range to __pkvm_host_share_guest() Vincent Donnefort
2025-04-03 15:27 ` Quentin Perret
2025-04-04 16:47 ` Vincent Donnefort
2025-03-06 11:00 ` [PATCH v2 3/9] KVM: arm64: Add a range to __pkvm_host_unshare_guest() Vincent Donnefort
2025-04-03 15:31 ` Quentin Perret
2025-04-04 17:05 ` Vincent Donnefort [this message]
2025-03-06 11:00 ` [PATCH v2 4/9] KVM: arm64: Add a range to __pkvm_host_wrprotect_guest() Vincent Donnefort
2025-03-06 11:00 ` [PATCH v2 5/9] KVM: arm64: Add a range to __pkvm_host_test_clear_young_guest() Vincent Donnefort
2025-03-06 11:00 ` [PATCH v2 6/9] KVM: arm64: Convert pkvm_mappings to interval tree Vincent Donnefort
2025-03-06 11:00 ` [PATCH v2 7/9] KVM: arm64: Add a range to pkvm_mappings Vincent Donnefort
2025-03-06 11:00 ` [PATCH v2 8/9] KVM: arm64: Stage-2 huge mappings for np-guests Vincent Donnefort
2025-04-03 14:21 ` Quentin Perret
2025-04-04 17:08 ` Vincent Donnefort
2025-03-06 11:00 ` [PATCH v2 9/9] KVM: arm64: np-guest CMOs with PMD_SIZE fixmap Vincent Donnefort
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z_ARWDH60WayM0MP@google.com \
--to=vdonnefort@google.com \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=qperret@google.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).