Skip to content

Commit 9177b71

Browse files
jones-drewavpatel
authored andcommitted
KVM: arm64: selftests: Rename vcpu_config and add to kvm_util.h
Rename vcpu_config to vcpu_reg_list to be more specific and add it to kvm_util.h. While it may not get used outside get-reg-list tests, exporting it doesn't hurt, as long as it has a unique enough name. This is a step in the direction of sharing most of the get- reg-list test code between architectures. Signed-off-by: Andrew Jones <[email protected]> Signed-off-by: Haibo Xu <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent c2b5aa7 commit 9177b71

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

tools/testing/selftests/kvm/aarch64/get-reg-list.c

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@
3737
static struct kvm_reg_list *reg_list;
3838
static __u64 *blessed_reg, blessed_n;
3939

40-
struct reg_sublist {
41-
const char *name;
42-
long capability;
43-
int feature;
44-
bool finalize;
45-
__u64 *regs;
46-
__u64 regs_n;
47-
__u64 *rejects_set;
48-
__u64 rejects_set_n;
49-
};
50-
5140
struct feature_id_reg {
5241
__u64 reg;
5342
__u64 id_reg;
@@ -76,12 +65,7 @@ static struct feature_id_reg feat_id_regs[] = {
7665
}
7766
};
7867

79-
struct vcpu_config {
80-
char *name;
81-
struct reg_sublist sublists[];
82-
};
83-
84-
static struct vcpu_config *vcpu_configs[];
68+
static struct vcpu_reg_list *vcpu_configs[];
8569
static int vcpu_configs_n;
8670

8771
#define for_each_sublist(c, s) \
@@ -103,9 +87,9 @@ static int vcpu_configs_n;
10387
for_each_reg_filtered(i) \
10488
if (!find_reg(blessed_reg, blessed_n, reg_list->reg[i]))
10589

106-
static const char *config_name(struct vcpu_config *c)
90+
static const char *config_name(struct vcpu_reg_list *c)
10791
{
108-
struct reg_sublist *s;
92+
struct vcpu_reg_sublist *s;
10993
int len = 0;
11094

11195
if (c->name)
@@ -390,18 +374,18 @@ static void core_reg_fixup(void)
390374
reg_list = tmp;
391375
}
392376

393-
static void prepare_vcpu_init(struct vcpu_config *c, struct kvm_vcpu_init *init)
377+
static void prepare_vcpu_init(struct vcpu_reg_list *c, struct kvm_vcpu_init *init)
394378
{
395-
struct reg_sublist *s;
379+
struct vcpu_reg_sublist *s;
396380

397381
for_each_sublist(c, s)
398382
if (s->capability)
399383
init->features[s->feature / 32] |= 1 << (s->feature % 32);
400384
}
401385

402-
static void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_config *c)
386+
static void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
403387
{
404-
struct reg_sublist *s;
388+
struct vcpu_reg_sublist *s;
405389
int feature;
406390

407391
for_each_sublist(c, s) {
@@ -412,9 +396,9 @@ static void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_config *c)
412396
}
413397
}
414398

415-
static void check_supported(struct vcpu_config *c)
399+
static void check_supported(struct vcpu_reg_list *c)
416400
{
417-
struct reg_sublist *s;
401+
struct vcpu_reg_sublist *s;
418402

419403
for_each_sublist(c, s) {
420404
if (!s->capability)
@@ -430,14 +414,14 @@ static bool print_list;
430414
static bool print_filtered;
431415
static bool fixup_core_regs;
432416

433-
static void run_test(struct vcpu_config *c)
417+
static void run_test(struct vcpu_reg_list *c)
434418
{
435419
struct kvm_vcpu_init init = { .target = -1, };
436420
int new_regs = 0, missing_regs = 0, i, n;
437421
int failed_get = 0, failed_set = 0, failed_reject = 0;
438422
struct kvm_vcpu *vcpu;
439423
struct kvm_vm *vm;
440-
struct reg_sublist *s;
424+
struct vcpu_reg_sublist *s;
441425

442426
check_supported(c);
443427

@@ -574,7 +558,7 @@ static void run_test(struct vcpu_config *c)
574558

575559
static void help(void)
576560
{
577-
struct vcpu_config *c;
561+
struct vcpu_reg_list *c;
578562
int i;
579563

580564
printf(
@@ -598,9 +582,9 @@ static void help(void)
598582
);
599583
}
600584

601-
static struct vcpu_config *parse_config(const char *config)
585+
static struct vcpu_reg_list *parse_config(const char *config)
602586
{
603-
struct vcpu_config *c;
587+
struct vcpu_reg_list *c;
604588
int i;
605589

606590
if (config[8] != '=')
@@ -620,7 +604,7 @@ static struct vcpu_config *parse_config(const char *config)
620604

621605
int main(int ac, char **av)
622606
{
623-
struct vcpu_config *c, *sel = NULL;
607+
struct vcpu_reg_list *c, *sel = NULL;
624608
int i, ret = 0;
625609
pid_t pid;
626610

@@ -1104,45 +1088,45 @@ static __u64 pauth_generic_regs[] = {
11041088
.regs_n = ARRAY_SIZE(pauth_generic_regs), \
11051089
}
11061090

1107-
static struct vcpu_config vregs_config = {
1091+
static struct vcpu_reg_list vregs_config = {
11081092
.sublists = {
11091093
BASE_SUBLIST,
11101094
VREGS_SUBLIST,
11111095
{0},
11121096
},
11131097
};
1114-
static struct vcpu_config vregs_pmu_config = {
1098+
static struct vcpu_reg_list vregs_pmu_config = {
11151099
.sublists = {
11161100
BASE_SUBLIST,
11171101
VREGS_SUBLIST,
11181102
PMU_SUBLIST,
11191103
{0},
11201104
},
11211105
};
1122-
static struct vcpu_config sve_config = {
1106+
static struct vcpu_reg_list sve_config = {
11231107
.sublists = {
11241108
BASE_SUBLIST,
11251109
SVE_SUBLIST,
11261110
{0},
11271111
},
11281112
};
1129-
static struct vcpu_config sve_pmu_config = {
1113+
static struct vcpu_reg_list sve_pmu_config = {
11301114
.sublists = {
11311115
BASE_SUBLIST,
11321116
SVE_SUBLIST,
11331117
PMU_SUBLIST,
11341118
{0},
11351119
},
11361120
};
1137-
static struct vcpu_config pauth_config = {
1121+
static struct vcpu_reg_list pauth_config = {
11381122
.sublists = {
11391123
BASE_SUBLIST,
11401124
VREGS_SUBLIST,
11411125
PAUTH_SUBLIST,
11421126
{0},
11431127
},
11441128
};
1145-
static struct vcpu_config pauth_pmu_config = {
1129+
static struct vcpu_reg_list pauth_pmu_config = {
11461130
.sublists = {
11471131
BASE_SUBLIST,
11481132
VREGS_SUBLIST,
@@ -1152,7 +1136,7 @@ static struct vcpu_config pauth_pmu_config = {
11521136
},
11531137
};
11541138

1155-
static struct vcpu_config *vcpu_configs[] = {
1139+
static struct vcpu_reg_list *vcpu_configs[] = {
11561140
&vregs_config,
11571141
&vregs_pmu_config,
11581142
&sve_config,

tools/testing/selftests/kvm/include/kvm_util_base.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/kernel.h>
1616
#include <linux/kvm.h>
1717
#include "linux/rbtree.h"
18+
#include <linux/types.h>
1819

1920
#include <asm/atomic.h>
2021

@@ -124,6 +125,21 @@ struct kvm_vm {
124125
uint32_t memslots[NR_MEM_REGIONS];
125126
};
126127

128+
struct vcpu_reg_sublist {
129+
const char *name;
130+
long capability;
131+
int feature;
132+
bool finalize;
133+
__u64 *regs;
134+
__u64 regs_n;
135+
__u64 *rejects_set;
136+
__u64 rejects_set_n;
137+
};
138+
139+
struct vcpu_reg_list {
140+
char *name;
141+
struct vcpu_reg_sublist sublists[];
142+
};
127143

128144
#define kvm_for_each_vcpu(vm, i, vcpu) \
129145
for ((i) = 0; (i) <= (vm)->last_vcpu_id; (i)++) \

0 commit comments

Comments
 (0)