Skip to content

Commit

Permalink
KVM: selftests: get-reg-list: support ID register features
Browse files Browse the repository at this point in the history
This stops the test complaining about missing registers, when running
on an older kernel that does not support newer features.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oliver.upton@linux.dev>
Cc: Mark Brown <broonie@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Link: https://lore.kernel.org/r/20230606145859.697944-20-joey.gouly@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
  • Loading branch information
Joey Gouly authored and Catalin Marinas committed Jun 6, 2023
1 parent 6c792b7 commit ee053e0
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tools/testing/selftests/kvm/aarch64/get-reg-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ struct reg_sublist {
__u64 rejects_set_n;
};

struct feature_id_reg {
__u64 reg;
__u64 id_reg;
__u64 feat_shift;
__u64 feat_min;
};

static struct feature_id_reg feat_id_regs[] = {
};

struct vcpu_config {
char *name;
struct reg_sublist sublists[];
Expand All @@ -68,7 +78,8 @@ static int vcpu_configs_n;

#define for_each_missing_reg(i) \
for ((i) = 0; (i) < blessed_n; ++(i)) \
if (!find_reg(reg_list->reg, reg_list->n, blessed_reg[i]))
if (!find_reg(reg_list->reg, reg_list->n, blessed_reg[i])) \
if (check_supported_feat_reg(vcpu, blessed_reg[i]))

#define for_each_new_reg(i) \
for_each_reg_filtered(i) \
Expand Down Expand Up @@ -132,6 +143,25 @@ static bool find_reg(__u64 regs[], __u64 nr_regs, __u64 reg)
return false;
}

static bool check_supported_feat_reg(struct kvm_vcpu *vcpu, __u64 reg)
{
int i, ret;
__u64 data, feat_val;

for (i = 0; i < ARRAY_SIZE(feat_id_regs); i++) {
if (feat_id_regs[i].reg == reg) {
ret = __vcpu_get_reg(vcpu, feat_id_regs[i].id_reg, &data);
if (ret < 0)
return false;

feat_val = ((data >> feat_id_regs[i].feat_shift) & 0xf);
return feat_val >= feat_id_regs[i].feat_min;
}
}

return true;
}

static const char *str_with_index(const char *template, __u64 index)
{
char *str, *p;
Expand Down

0 comments on commit ee053e0

Please sign in to comment.