2023-05-25 07:47:21

by Haibo Xu

[permalink] [raw]
Subject: [PATCH v2 00/11] RISCV: Add KVM_GET_REG_LIST API

KVM_GET_REG_LIST will dump all register IDs that are available to
KVM_GET/SET_ONE_REG and It's very useful to identify some platform
regression issue during VM migration.

Patch 1-7 re-structured the get-reg-list test in aarch64 to make some
of the code as common test framework that can be shared by riscv.

Patch 8 enabled the KVM_GET_REG_LIST API in riscv and patch 9-11 added
the corresponding kselftest for checking possible register regressions.

The get-reg-list kvm selftest was ported from aarch64 and tested with
Linux 6.4-rc1 on a Qemu riscv virt machine.

---
Changed since v1:
* rebase to Andrew's changes
* fix coding style

Andrew Jones (7):
KVM: arm64: selftests: Replace str_with_index with strdup_printf
KVM: arm64: selftests: Drop SVE cap check in print_reg
KVM: arm64: selftests: Remove print_reg's dependency on vcpu_config
KVM: arm64: selftests: Rename vcpu_config and add to kvm_util.h
KVM: arm64: selftests: Delete core_reg_fixup
KVM: arm64: selftests: Split get-reg-list test code
KVM: arm64: selftests: Finish generalizing get-reg-list

Haibo Xu (4):
KVM: riscv: Add KVM_GET_REG_LIST API support
KVM: riscv: selftests: Make check_supported arch specific
KVM: riscv: selftests: Skip some registers set operation
KVM: riscv: selftests: Add get-reg-list test

Documentation/virt/kvm/api.rst | 2 +-
arch/riscv/kvm/vcpu.c | 372 ++++++++++++
tools/testing/selftests/kvm/Makefile | 13 +-
.../selftests/kvm/aarch64/get-reg-list.c | 540 ++----------------
tools/testing/selftests/kvm/get-reg-list.c | 426 ++++++++++++++
.../selftests/kvm/include/kvm_util_base.h | 16 +
.../selftests/kvm/include/riscv/processor.h | 3 +
.../testing/selftests/kvm/include/test_util.h | 2 +
tools/testing/selftests/kvm/lib/test_util.c | 15 +
.../selftests/kvm/riscv/get-reg-list.c | 539 +++++++++++++++++
10 files changed, 1428 insertions(+), 500 deletions(-)
create mode 100644 tools/testing/selftests/kvm/get-reg-list.c
create mode 100644 tools/testing/selftests/kvm/riscv/get-reg-list.c

--
2.34.1



2023-05-25 07:47:53

by Haibo Xu

[permalink] [raw]
Subject: [PATCH v2 10/11] KVM: riscv: selftests: Skip some registers set operation

Set operation on some riscv registers(mostly pesudo ones) was not
supported and should be skipped in the get-reg-list test. Just
reuse the rejects_set utilities to handle it in riscv.

Signed-off-by: Haibo Xu <[email protected]>
---
tools/testing/selftests/kvm/get-reg-list.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
index f1fc113e9719..ebd6b580b33b 100644
--- a/tools/testing/selftests/kvm/get-reg-list.c
+++ b/tools/testing/selftests/kvm/get-reg-list.c
@@ -211,16 +211,22 @@ static void run_test(struct vcpu_reg_list *c)
++failed_get;
}

- /* rejects_set registers are rejected after KVM_ARM_VCPU_FINALIZE */
+ /*
+ * rejects_set registers are rejected after KVM_ARM_VCPU_FINALIZE on aarch64,
+ * or registers that should skip set operation on riscv.
+ */
for_each_sublist(c, s) {
if (s->rejects_set && find_reg(s->rejects_set, s->rejects_set_n, reg.id)) {
reject_reg = true;
- ret = __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, &reg);
- if (ret != -1 || errno != EPERM) {
- printf("%s: Failed to reject (ret=%d, errno=%d) ", config_name(c), ret, errno);
- print_reg(config_name(c), reg.id);
- putchar('\n');
- ++failed_reject;
+ if ((reg.id & KVM_REG_ARCH_MASK) == KVM_REG_ARM64) {
+ ret = __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, &reg);
+ if (ret != -1 || errno != EPERM) {
+ printf("%s: Failed to reject (ret=%d, errno=%d) ",
+ config_name(c), ret, errno);
+ print_reg(config_name(c), reg.id);
+ putchar('\n');
+ ++failed_reject;
+ }
}
break;
}
--
2.34.1


2023-05-25 07:47:56

by Haibo Xu

[permalink] [raw]
Subject: [PATCH v2 07/11] KVM: arm64: selftests: Finish generalizing get-reg-list

From: Andrew Jones <[email protected]>

Add some unfortunate #ifdeffery to ensure the common get-reg-list.c
can be compiled and run with other architectures. The next
architecture to support get-reg-list should now only need to provide
$(ARCH_DIR)/get-reg-list.c where arch-specific print_reg() and
vcpu_configs[] get defined.

Signed-off-by: Andrew Jones <[email protected]>
---
tools/testing/selftests/kvm/get-reg-list.c | 26 +++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
index 69bb91087081..f6ad7991a812 100644
--- a/tools/testing/selftests/kvm/get-reg-list.c
+++ b/tools/testing/selftests/kvm/get-reg-list.c
@@ -98,6 +98,7 @@ void __weak print_reg(const char *prefix, __u64 id)
printf("\t0x%llx,\n", id);
}

+#ifdef __aarch64__
static void prepare_vcpu_init(struct vcpu_reg_list *c, struct kvm_vcpu_init *init)
{
struct vcpu_reg_sublist *s;
@@ -120,6 +121,25 @@ static void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
}
}

+static struct kvm_vcpu *vcpu_config_get_vcpu(struct vcpu_reg_list *c, struct kvm_vm *vm)
+{
+ struct kvm_vcpu_init init = { .target = -1, };
+ struct kvm_vcpu *vcpu;
+
+ prepare_vcpu_init(c, &init);
+ vcpu = __vm_vcpu_add(vm, 0);
+ aarch64_vcpu_setup(vcpu, &init);
+ finalize_vcpu(vcpu, c);
+
+ return vcpu;
+}
+#else
+static struct kvm_vcpu *vcpu_config_get_vcpu(struct vcpu_reg_list *c, struct kvm_vm *vm)
+{
+ return __vm_vcpu_add(vm, 0);
+}
+#endif
+
static void check_supported(struct vcpu_reg_list *c)
{
struct vcpu_reg_sublist *s;
@@ -139,7 +159,6 @@ static bool print_filtered;

static void run_test(struct vcpu_reg_list *c)
{
- struct kvm_vcpu_init init = { .target = -1, };
int new_regs = 0, missing_regs = 0, i, n;
int failed_get = 0, failed_set = 0, failed_reject = 0;
struct kvm_vcpu *vcpu;
@@ -149,10 +168,7 @@ static void run_test(struct vcpu_reg_list *c)
check_supported(c);

vm = vm_create_barebones();
- prepare_vcpu_init(c, &init);
- vcpu = __vm_vcpu_add(vm, 0);
- aarch64_vcpu_setup(vcpu, &init);
- finalize_vcpu(vcpu, c);
+ vcpu = vcpu_config_get_vcpu(c, vm);

reg_list = vcpu_get_reg_list(vcpu);

--
2.34.1


2023-05-25 07:48:09

by Haibo Xu

[permalink] [raw]
Subject: [PATCH v2 02/11] KVM: arm64: selftests: Drop SVE cap check in print_reg

From: Andrew Jones <[email protected]>

The check doesn't prove much anyway, as the reg lists could be
messed up too. Just drop the check to simplify making print_reg
more independent.

Signed-off-by: Andrew Jones <[email protected]>
---
.../testing/selftests/kvm/aarch64/get-reg-list.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
index c152523a5ed4..915272c342f9 100644
--- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c
+++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c
@@ -100,16 +100,6 @@ static const char *config_name(struct vcpu_config *c)
return c->name;
}

-static bool has_cap(struct vcpu_config *c, long capability)
-{
- struct reg_sublist *s;
-
- for_each_sublist(c, s)
- if (s->capability == capability)
- return true;
- return false;
-}
-
static bool filter_reg(__u64 reg)
{
/*
@@ -287,10 +277,7 @@ static void print_reg(struct vcpu_config *c, __u64 id)
printf("\tKVM_REG_ARM_FW_FEAT_BMAP_REG(%lld),\n", id & 0xffff);
break;
case KVM_REG_ARM64_SVE:
- if (has_cap(c, KVM_CAP_ARM_SVE))
- printf("\t%s,\n", sve_id_to_str(c, id));
- else
- TEST_FAIL("%s: KVM_REG_ARM64_SVE is an unexpected coproc type in reg id: 0x%llx", config_name(c), id);
+ printf("\t%s,\n", sve_id_to_str(c, id));
break;
default:
TEST_FAIL("%s: Unexpected coproc type: 0x%llx in reg id: 0x%llx",
--
2.34.1


2023-05-25 16:51:24

by Andrew Jones

[permalink] [raw]
Subject: Re: [PATCH v2 10/11] KVM: riscv: selftests: Skip some registers set operation

On Thu, May 25, 2023 at 03:38:34PM +0800, Haibo Xu wrote:
> Set operation on some riscv registers(mostly pesudo ones) was not
> supported and should be skipped in the get-reg-list test. Just
> reuse the rejects_set utilities to handle it in riscv.
>
> Signed-off-by: Haibo Xu <[email protected]>
> ---
> tools/testing/selftests/kvm/get-reg-list.c | 20 +++++++++++++-------
> 1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/get-reg-list.c b/tools/testing/selftests/kvm/get-reg-list.c
> index f1fc113e9719..ebd6b580b33b 100644
> --- a/tools/testing/selftests/kvm/get-reg-list.c
> +++ b/tools/testing/selftests/kvm/get-reg-list.c
> @@ -211,16 +211,22 @@ static void run_test(struct vcpu_reg_list *c)
> ++failed_get;
> }
>
> - /* rejects_set registers are rejected after KVM_ARM_VCPU_FINALIZE */
> + /*
> + * rejects_set registers are rejected after KVM_ARM_VCPU_FINALIZE on aarch64,
> + * or registers that should skip set operation on riscv.
> + */
> for_each_sublist(c, s) {
> if (s->rejects_set && find_reg(s->rejects_set, s->rejects_set_n, reg.id)) {
> reject_reg = true;
> - ret = __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, &reg);
> - if (ret != -1 || errno != EPERM) {
> - printf("%s: Failed to reject (ret=%d, errno=%d) ", config_name(c), ret, errno);
> - print_reg(config_name(c), reg.id);
> - putchar('\n');
> - ++failed_reject;
> + if ((reg.id & KVM_REG_ARCH_MASK) == KVM_REG_ARM64) {
> + ret = __vcpu_ioctl(vcpu, KVM_SET_ONE_REG, &reg);
> + if (ret != -1 || errno != EPERM) {
> + printf("%s: Failed to reject (ret=%d, errno=%d) ",
> + config_name(c), ret, errno);
> + print_reg(config_name(c), reg.id);
> + putchar('\n');
> + ++failed_reject;
> + }
> }
> break;
> }
> --
> 2.34.1
>

Reviewed-by: Andrew Jones <[email protected]>

2023-05-25 17:26:23

by Andrew Jones

[permalink] [raw]
Subject: Re: [PATCH v2 00/11] RISCV: Add KVM_GET_REG_LIST API

On Thu, May 25, 2023 at 03:38:24PM +0800, Haibo Xu wrote:
> KVM_GET_REG_LIST will dump all register IDs that are available to
> KVM_GET/SET_ONE_REG and It's very useful to identify some platform
> regression issue during VM migration.
>
> Patch 1-7 re-structured the get-reg-list test in aarch64 to make some
> of the code as common test framework that can be shared by riscv.
>
> Patch 8 enabled the KVM_GET_REG_LIST API in riscv and patch 9-11 added
> the corresponding kselftest for checking possible register regressions.
>
> The get-reg-list kvm selftest was ported from aarch64 and tested with
> Linux 6.4-rc1 on a Qemu riscv virt machine.
>
> ---
> Changed since v1:
> * rebase to Andrew's changes
> * fix coding style
>
> Andrew Jones (7):
> KVM: arm64: selftests: Replace str_with_index with strdup_printf
> KVM: arm64: selftests: Drop SVE cap check in print_reg
> KVM: arm64: selftests: Remove print_reg's dependency on vcpu_config
> KVM: arm64: selftests: Rename vcpu_config and add to kvm_util.h
> KVM: arm64: selftests: Delete core_reg_fixup
> KVM: arm64: selftests: Split get-reg-list test code
> KVM: arm64: selftests: Finish generalizing get-reg-list

All the patches above should also have your s-o-b since your posting them.

Thanks,
drew

2023-05-26 06:37:32

by Haibo Xu

[permalink] [raw]
Subject: Re: [PATCH v2 00/11] RISCV: Add KVM_GET_REG_LIST API

On Fri, May 26, 2023 at 1:20 AM Andrew Jones <[email protected]> wrote:
>
> On Thu, May 25, 2023 at 03:38:24PM +0800, Haibo Xu wrote:
> > KVM_GET_REG_LIST will dump all register IDs that are available to
> > KVM_GET/SET_ONE_REG and It's very useful to identify some platform
> > regression issue during VM migration.
> >
> > Patch 1-7 re-structured the get-reg-list test in aarch64 to make some
> > of the code as common test framework that can be shared by riscv.
> >
> > Patch 8 enabled the KVM_GET_REG_LIST API in riscv and patch 9-11 added
> > the corresponding kselftest for checking possible register regressions.
> >
> > The get-reg-list kvm selftest was ported from aarch64 and tested with
> > Linux 6.4-rc1 on a Qemu riscv virt machine.
> >
> > ---
> > Changed since v1:
> > * rebase to Andrew's changes
> > * fix coding style
> >
> > Andrew Jones (7):
> > KVM: arm64: selftests: Replace str_with_index with strdup_printf
> > KVM: arm64: selftests: Drop SVE cap check in print_reg
> > KVM: arm64: selftests: Remove print_reg's dependency on vcpu_config
> > KVM: arm64: selftests: Rename vcpu_config and add to kvm_util.h
> > KVM: arm64: selftests: Delete core_reg_fixup
> > KVM: arm64: selftests: Split get-reg-list test code
> > KVM: arm64: selftests: Finish generalizing get-reg-list
>
> All the patches above should also have your s-o-b since your posting them.
>

Sure.

> Thanks,
> drew