From: "wangyanan (Y)" <wangyanan55@huawei.com>
To: <kvm@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Ben Gardon <bgardon@google.com>,
Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Ingo Molnar <mingo@kernel.org>, Andrew Jones <drjones@redhat.com>,
Peter Xu <peterx@redhat.com>, Marc Zyngier <maz@kernel.org>,
<wanghaibin.wang@huawei.com>, <yuzenghui@huawei.com>
Subject: Re: [RFC PATCH v2 3/7] KVM: selftests: Make a generic helper to get vm guest mode strings
Date: Fri, 26 Feb 2021 13:56:41 +0800 [thread overview]
Message-ID: <5fb5933a-0191-5901-e0e2-eeb4583b40d8@huawei.com> (raw)
In-Reply-To: <20210225055940.18748-4-wangyanan55@huawei.com>
On 2021/2/25 13:59, Yanan Wang wrote:
> For generality and conciseness, make an API which can be used in all
> kvm libs and selftests to get vm guest mode strings. And the index i
> is checked in the API in case of possiable faults.
>
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
And here too, will include Suggested-by: Sean Christopherson
<seanjc@google.com>.
> ---
> .../testing/selftests/kvm/include/kvm_util.h | 4 +--
> tools/testing/selftests/kvm/lib/kvm_util.c | 29 ++++++++++++-------
> 2 files changed, 19 insertions(+), 14 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
> index 2d7eb6989e83..f52a7492f47f 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util.h
> @@ -68,9 +68,6 @@ enum vm_guest_mode {
> #define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT)
> #define PTES_PER_MIN_PAGE ptes_per_page(MIN_PAGE_SIZE)
>
> -#define vm_guest_mode_string(m) vm_guest_mode_string[m]
> -extern const char * const vm_guest_mode_string[];
> -
> struct vm_guest_mode_params {
> unsigned int pa_bits;
> unsigned int va_bits;
> @@ -84,6 +81,7 @@ int vm_enable_cap(struct kvm_vm *vm, struct kvm_enable_cap *cap);
> int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id,
> struct kvm_enable_cap *cap);
> void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size);
> +const char *vm_guest_mode_string(uint32_t i);
>
> struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm);
> void kvm_vm_free(struct kvm_vm *vmp);
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index d787cb802b4a..cc22c4ab7d67 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -141,17 +141,24 @@ static void vm_open(struct kvm_vm *vm, int perm)
> "rc: %i errno: %i", vm->fd, errno);
> }
>
> -const char * const vm_guest_mode_string[] = {
> - "PA-bits:52, VA-bits:48, 4K pages",
> - "PA-bits:52, VA-bits:48, 64K pages",
> - "PA-bits:48, VA-bits:48, 4K pages",
> - "PA-bits:48, VA-bits:48, 64K pages",
> - "PA-bits:40, VA-bits:48, 4K pages",
> - "PA-bits:40, VA-bits:48, 64K pages",
> - "PA-bits:ANY, VA-bits:48, 4K pages",
> -};
> -_Static_assert(sizeof(vm_guest_mode_string)/sizeof(char *) == NUM_VM_MODES,
> - "Missing new mode strings?");
> +const char *vm_guest_mode_string(uint32_t i)
> +{
> + static const char * const strings[] = {
> + [VM_MODE_P52V48_4K] = "PA-bits:52, VA-bits:48, 4K pages",
> + [VM_MODE_P52V48_64K] = "PA-bits:52, VA-bits:48, 64K pages",
> + [VM_MODE_P48V48_4K] = "PA-bits:48, VA-bits:48, 4K pages",
> + [VM_MODE_P48V48_64K] = "PA-bits:48, VA-bits:48, 64K pages",
> + [VM_MODE_P40V48_4K] = "PA-bits:40, VA-bits:48, 4K pages",
> + [VM_MODE_P40V48_64K] = "PA-bits:40, VA-bits:48, 64K pages",
> + [VM_MODE_PXXV48_4K] = "PA-bits:ANY, VA-bits:48, 4K pages",
> + };
> + _Static_assert(sizeof(strings)/sizeof(char *) == NUM_VM_MODES,
> + "Missing new mode strings?");
> +
> + TEST_ASSERT(i < NUM_VM_MODES, "Guest mode ID %d too big", i);
> +
> + return strings[i];
> +}
>
> const struct vm_guest_mode_params vm_guest_mode_params[] = {
> { 52, 48, 0x1000, 12 },
next prev parent reply other threads:[~2021-02-26 5:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-25 5:59 [RFC PATCH v2 0/7] Some improvement and a new test for kvm page table Yanan Wang
2021-02-25 5:59 ` [RFC PATCH v2 1/7] tools include: sync head files of mmap flag encodings about hugetlb Yanan Wang
2021-02-25 5:59 ` [RFC PATCH v2 2/7] KVM: selftests: Use flag CLOCK_MONOTONIC_RAW for timing Yanan Wang
2021-02-25 18:54 ` Andrew Jones
2021-02-26 2:49 ` wangyanan (Y)
2021-02-25 5:59 ` [RFC PATCH v2 3/7] KVM: selftests: Make a generic helper to get vm guest mode strings Yanan Wang
2021-02-25 18:55 ` Andrew Jones
2021-02-26 5:56 ` wangyanan (Y) [this message]
2021-02-25 5:59 ` [RFC PATCH v2 4/7] KVM: selftests: Add a helper to get system configured THP page size Yanan Wang
2021-02-25 23:27 ` Ben Gardon
2021-02-25 5:59 ` [RFC PATCH v2 5/7] KVM: selftests: List all hugetlb src types specified with page sizes Yanan Wang
2021-02-25 23:42 ` Ben Gardon
2021-02-26 5:45 ` wangyanan (Y)
2021-02-25 5:59 ` [RFC PATCH v2 6/7] KVM: selftests: Adapt vm_userspace_mem_region_add to new helpers Yanan Wang
2021-02-25 23:44 ` Ben Gardon
2021-02-26 5:48 ` wangyanan (Y)
2021-02-25 5:59 ` [RFC PATCH v2 7/7] KVM: selftests: Add a test for kvm page table code Yanan Wang
2021-02-25 23:45 ` [RFC PATCH v2 0/7] Some improvement and a new test for kvm page table Ben Gardon
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=5fb5933a-0191-5901-e0e2-eeb4583b40d8@huawei.com \
--to=wangyanan55@huawei.com \
--cc=acme@redhat.com \
--cc=bgardon@google.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mingo@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanghaibin.wang@huawei.com \
--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
all inboxes | Powered by JetHome®