Skip to content

Commit 071ef07

Browse files
committed
KVM: riscv: selftests: Selectively filter-out AIA registers
Currently the AIA ONE_REG registers are reported by get-reg-list as new registers for various vcpu_reg_list configs whenever Ssaia is available on the host because Ssaia extension can only be disabled by Smstateen extension which is not always available. To tackle this, we should filter-out AIA ONE_REG registers only when Ssaia can't be disabled for a VCPU. Fixes: 4770693 ("KVM: riscv: selftests: Add get-reg-list test") Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent ba1af6e commit 071ef07

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#define REG_MASK (KVM_REG_ARCH_MASK | KVM_REG_SIZE_MASK)
1414

15+
static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX];
16+
1517
bool filter_reg(__u64 reg)
1618
{
1719
switch (reg & ~REG_MASK) {
@@ -48,6 +50,15 @@ bool filter_reg(__u64 reg)
4850
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIFENCEI:
4951
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHPM:
5052
return true;
53+
/* AIA registers are always available when Ssaia can't be disabled */
54+
case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siselect):
55+
case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1):
56+
case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2):
57+
case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(sieh):
58+
case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(siph):
59+
case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio1h):
60+
case KVM_REG_RISCV_CSR | KVM_REG_RISCV_CSR_AIA | KVM_REG_RISCV_CSR_AIA_REG(iprio2h):
61+
return isa_ext_cant_disable[KVM_RISCV_ISA_EXT_SSAIA];
5162
default:
5263
break;
5364
}
@@ -71,14 +82,22 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext)
7182

7283
void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
7384
{
85+
unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 };
7486
struct vcpu_reg_sublist *s;
87+
int rc;
88+
89+
for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++)
90+
__vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(i), &isa_ext_state[i]);
7591

7692
/*
7793
* Disable all extensions which were enabled by default
7894
* if they were available in the risc-v host.
7995
*/
80-
for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++)
81-
__vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0);
96+
for (int i = 0; i < KVM_RISCV_ISA_EXT_MAX; i++) {
97+
rc = __vcpu_set_reg(vcpu, RISCV_ISA_EXT_REG(i), 0);
98+
if (rc && isa_ext_state[i])
99+
isa_ext_cant_disable[i] = true;
100+
}
82101

83102
for_each_sublist(c, s) {
84103
if (!s->feature)

0 commit comments

Comments
 (0)