From: Oliver Upton <oupton@google.com>
To: Ricardo Koller <ricarkol@google.com>
Cc: kvm@vger.kernel.org, maz@kernel.org, bgardon@google.com,
pbonzini@redhat.com, axelrasmussen@google.com,
kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v3 02/13] KVM: selftests: aarch64: Add vm_get_pte_gpa library function
Date: Thu, 19 May 2022 03:48:00 +0000 [thread overview]
Message-ID: <YoW98HI27sP5lHKR@google.com> (raw)
In-Reply-To: <20220408004120.1969099-3-ricarkol@google.com>
Hey Ricardo,
Sorry about my last email hitting your v2. I fudged my inbox filtering
so v3 missed my explicit-cc inbox. Oops!
On Thu, Apr 07, 2022 at 05:41:09PM -0700, Ricardo Koller wrote:
> Add a library function (in-guest)
This function is called from host userspace, no?
> to get the GPA of the PTE of a
> particular GVA. This will be used in a future commit by a test to clear
> and check the AF (access flag) of a particular page.
>
> Signed-off-by: Ricardo Koller <ricarkol@google.com>
> ---
> .../selftests/kvm/include/aarch64/processor.h | 2 ++
> .../selftests/kvm/lib/aarch64/processor.c | 24 +++++++++++++++++--
> 2 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
> index 8f9f46979a00..caa572d83062 100644
> --- a/tools/testing/selftests/kvm/include/aarch64/processor.h
> +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
> @@ -125,6 +125,8 @@ void vm_install_exception_handler(struct kvm_vm *vm,
> void vm_install_sync_handler(struct kvm_vm *vm,
> int vector, int ec, handler_fn handler);
>
> +vm_paddr_t vm_get_pte_gpa(struct kvm_vm *vm, vm_vaddr_t gva);
> +
> static inline void cpu_relax(void)
> {
> asm volatile("yield" ::: "memory");
> diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> index 9343d82519b4..ee006d354b79 100644
> --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
> +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
> @@ -139,7 +139,7 @@ void virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr)
> _virt_pg_map(vm, vaddr, paddr, attr_idx);
> }
>
> -vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
> +vm_paddr_t vm_get_pte_gpa(struct kvm_vm *vm, vm_vaddr_t gva)
> {
> uint64_t *ptep;
>
> @@ -162,7 +162,7 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
> goto unmapped_gva;
> /* fall through */
> case 2:
> - ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pte_index(vm, gva) * 8;
> + ptep = (uint64_t *)(pte_addr(vm, *ptep) + pte_index(vm, gva) * 8);
this seems a bit odd. ptep is an HVA in the above cases, but really a
GPA here.
Also -- not your code but the baked-in assumption that the stage-1 MMU
always maps at leaf page granularity might be a bit of a mess if we ever
do anything more interesting inside of the guest.
> if (!ptep)
> goto unmapped_gva;
> break;
> @@ -170,6 +170,26 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
> TEST_FAIL("Page table levels must be 2, 3, or 4");
> }
>
> + return (vm_paddr_t)ptep;
> +
> +unmapped_gva:
> + TEST_FAIL("No mapping for vm virtual address, gva: 0x%lx", gva);
> + exit(1);
Isn't this just a workaround for the fact that TEST_FAIL() doesn't have
the noreturn attribute specified somewhere?
> +}
> +
> +vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
> +{
> + uint64_t *ptep;
> + vm_paddr_t ptep_gpa;
> +
> + ptep_gpa = vm_get_pte_gpa(vm, gva);
> + if (!ptep_gpa)
> + goto unmapped_gva;
This branch will never be taken since vm_get_pte_gpa() will explode on
its own, right?
--
Thanks,
Oliver
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
next prev parent reply other threads:[~2022-05-19 3:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 0:41 [PATCH v3 00/13] KVM: selftests: Add aarch64/page_fault_test Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 01/13] KVM: selftests: Add a userfaultfd library Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 02/13] KVM: selftests: aarch64: Add vm_get_pte_gpa library function Ricardo Koller
2022-05-19 3:48 ` Oliver Upton [this message]
2022-04-08 0:41 ` [PATCH v3 03/13] KVM: selftests: Add vm_alloc_page_table_in_memslot " Ricardo Koller
2022-05-19 3:53 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 04/13] KVM: selftests: aarch64: Export _virt_pg_map with a pt_memslot arg Ricardo Koller
2022-05-19 4:05 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 05/13] KVM: selftests: Add missing close and munmap in __vm_mem_region_delete Ricardo Koller
2022-05-19 4:06 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 06/13] KVM: selftests: Add vm_mem_region_get_src_fd library function Ricardo Koller
2022-05-19 4:08 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 07/13] KVM: selftests: aarch64: Construct DEFAULT_MAIR_EL1 using sysreg.h macros Ricardo Koller
2022-05-19 4:17 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 08/13] tools: Copy bitfield.h from the kernel sources Ricardo Koller
2022-05-19 4:25 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 09/13] KVM: selftests: aarch64: Add aarch64/page_fault_test Ricardo Koller
2022-05-25 19:43 ` Oliver Upton
2022-04-08 0:41 ` [PATCH v3 10/13] KVM: selftests: aarch64: Add userfaultfd tests into page_fault_test Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 11/13] KVM: selftests: aarch64: Add dirty logging " Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 12/13] KVM: selftests: aarch64: Add readonly memslot " Ricardo Koller
2022-04-08 0:41 ` [PATCH v3 13/13] KVM: selftests: aarch64: Add mix of " Ricardo Koller
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=YoW98HI27sP5lHKR@google.com \
--to=oupton@google.com \
--cc=axelrasmussen@google.com \
--cc=bgardon@google.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=maz@kernel.org \
--cc=pbonzini@redhat.com \
--cc=ricarkol@google.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