From: Sean Christopherson <seanjc@google.com>
To: Tianrui Zhao <zhaotianrui@loongson.cn>
Cc: Shuah Khan <shuah@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
Vishal Annapurve <vannapurve@google.com>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
loongarch@lists.linux.dev, Peter Xu <peterx@redhat.com>,
Vipin Sharma <vipinsh@google.com>,
maobibo@loongson.cn
Subject: Re: [PATCH v1 3/4] selftests: kvm: Add ucall tests for LoongArch KVM
Date: Wed, 2 Aug 2023 11:08:43 -0700 [thread overview]
Message-ID: <ZMqbqwuCdI2XpJ9q@google.com> (raw)
In-Reply-To: <20230801020206.1957986-4-zhaotianrui@loongson.cn>
On Tue, Aug 01, 2023, Tianrui Zhao wrote:
> Add ucall tests for LoongArch KVM, it means that VM use hypercall
s/tests/support
> to return to userspace and handle the mmio exception.
>
> Based-on: <20230720062813.4126751-1-zhaotianrui@loongson.cn>
> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
> ---
> .../selftests/kvm/lib/loongarch/ucall.c | 44 +++++++++++++++++++
> 1 file changed, 44 insertions(+)
> create mode 100644 tools/testing/selftests/kvm/lib/loongarch/ucall.c
>
> diff --git a/tools/testing/selftests/kvm/lib/loongarch/ucall.c b/tools/testing/selftests/kvm/lib/loongarch/ucall.c
> new file mode 100644
> index 000000000000..b32f7c7f6548
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/lib/loongarch/ucall.c
> @@ -0,0 +1,44 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * ucall support. A ucall is a "hypercall to userspace".
> + *
> + */
> +#include "kvm_util.h"
> +
> +/*
> + * ucall_exit_mmio_addr holds per-VM values (global data is duplicated by each
> + * VM), it must not be accessed from host code.
> + */
> +static vm_vaddr_t *ucall_exit_mmio_addr;
> +
> +void ucall_arch_init(struct kvm_vm *vm, vm_paddr_t mmio_gpa)
> +{
> + vm_vaddr_t mmio_gva = vm_vaddr_unused_gap(vm, vm->page_size, KVM_UTIL_MIN_VADDR);
> +
> + virt_map(vm, mmio_gva, mmio_gpa, 1);
> +
> + vm->ucall_mmio_addr = mmio_gpa;
> +
> + write_guest_global(vm, ucall_exit_mmio_addr, (vm_vaddr_t *)mmio_gva);
> +}
> +
> +void ucall_arch_do_ucall(vm_vaddr_t uc)
> +{
> +
Extra newline.
> + WRITE_ONCE(*ucall_exit_mmio_addr, uc);
> +}
> +
> +void *ucall_arch_get_ucall(struct kvm_vcpu *vcpu)
> +{
> + struct kvm_run *run = vcpu->run;
> +
> + if (run->exit_reason == KVM_EXIT_MMIO &&
> + run->mmio.phys_addr == vcpu->vm->ucall_mmio_addr) {
> + TEST_ASSERT(run->mmio.is_write && run->mmio.len == sizeof(uint64_t),
> + "Unexpected ucall exit mmio address access");
> +
> + return (void *)(*((uint64_t *)run->mmio.data));
> + }
> +
> + return NULL;
> +}
> --
> 2.39.1
>
next prev parent reply other threads:[~2023-08-02 18:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 2:02 [PATCH v1 0/4] selftests: kvm: Add LoongArch support Tianrui Zhao
2023-08-01 2:02 ` [PATCH v1 1/4] selftests: kvm: Add kvm selftests header files for LoongArch Tianrui Zhao
2023-08-02 17:01 ` Sean Christopherson
2023-08-03 3:30 ` zhaotianrui
2023-08-01 2:02 ` [PATCH v1 2/4] selftests: kvm: Add processor tests for LoongArch KVM Tianrui Zhao
2023-08-02 18:07 ` Sean Christopherson
2023-08-03 6:32 ` zhaotianrui
2023-08-01 2:02 ` [PATCH v1 3/4] selftests: kvm: Add ucall " Tianrui Zhao
2023-08-02 18:08 ` Sean Christopherson [this message]
2023-08-03 6:42 ` zhaotianrui
2023-08-01 2:02 ` [PATCH v1 4/4] selftests: kvm: Add LoongArch tests into makefile Tianrui Zhao
2023-08-02 18:10 ` Sean Christopherson
2023-08-03 6:52 ` zhaotianrui
2023-08-02 16:58 ` [PATCH v1 0/4] selftests: kvm: Add LoongArch support Sean Christopherson
2023-08-03 3:14 ` zhaotianrui
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=ZMqbqwuCdI2XpJ9q@google.com \
--to=seanjc@google.com \
--cc=chenhuacai@kernel.org \
--cc=kernel@xen0n.name \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=maobibo@loongson.cn \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=shuah@kernel.org \
--cc=vannapurve@google.com \
--cc=vipinsh@google.com \
--cc=zhaotianrui@loongson.cn \
/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