Skip to content

Commit ba1af6e

Browse files
committed
KVM: riscv: selftests: Fix ISA_EXT register handling in get-reg-list
Same set of ISA_EXT registers are not present on all host because ISA_EXT registers are visible to the KVM user space based on the ISA extensions available on the host. Also, disabling an ISA extension using corresponding ISA_EXT register does not affect the visibility of the ISA_EXT register itself. Based on the above, we should filter-out all ISA_EXT registers. Fixes: 4770693 ("KVM: riscv: selftests: Add get-reg-list test") Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent 17f71a2 commit ba1af6e

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,33 @@
1414

1515
bool filter_reg(__u64 reg)
1616
{
17+
switch (reg & ~REG_MASK) {
1718
/*
18-
* Some ISA extensions are optional and not present on all host,
19-
* but they can't be disabled through ISA_EXT registers when present.
20-
* So, to make life easy, just filtering out these kind of registers.
19+
* Same set of ISA_EXT registers are not present on all host because
20+
* ISA_EXT registers are visible to the KVM user space based on the
21+
* ISA extensions available on the host. Also, disabling an ISA
22+
* extension using corresponding ISA_EXT register does not affect
23+
* the visibility of the ISA_EXT register itself.
24+
*
25+
* Based on above, we should filter-out all ISA_EXT registers.
2126
*/
22-
switch (reg & ~REG_MASK) {
27+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_A:
28+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_C:
29+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_D:
30+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_F:
31+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_H:
32+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_I:
33+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_M:
34+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_SVPBMT:
2335
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_SSTC:
2436
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_SVINVAL:
2537
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZIHINTPAUSE:
38+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZICBOM:
39+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZICBOZ:
2640
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZBB:
2741
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_SSAIA:
42+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_V:
43+
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_SVNAPOT:
2844
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZBA:
2945
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZBS:
3046
case KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_ZICNTR:
@@ -50,12 +66,7 @@ static inline bool vcpu_has_ext(struct kvm_vcpu *vcpu, int ext)
5066
unsigned long value;
5167

5268
ret = __vcpu_get_reg(vcpu, RISCV_ISA_EXT_REG(ext), &value);
53-
if (ret) {
54-
printf("Failed to get ext %d", ext);
55-
return false;
56-
}
57-
58-
return !!value;
69+
return (ret) ? false : !!value;
5970
}
6071

6172
void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
@@ -506,10 +517,6 @@ static __u64 base_regs[] = {
506517
KVM_REG_RISCV | KVM_REG_SIZE_U64 | KVM_REG_RISCV_TIMER | KVM_REG_RISCV_TIMER_REG(time),
507518
KVM_REG_RISCV | KVM_REG_SIZE_U64 | KVM_REG_RISCV_TIMER | KVM_REG_RISCV_TIMER_REG(compare),
508519
KVM_REG_RISCV | KVM_REG_SIZE_U64 | KVM_REG_RISCV_TIMER | KVM_REG_RISCV_TIMER_REG(state),
509-
KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_A,
510-
KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_C,
511-
KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_I,
512-
KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_ISA_EXT | KVM_RISCV_ISA_EXT_M,
513520
KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_V01,
514521
KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_TIME,
515522
KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | KVM_RISCV_SBI_EXT_IPI,

0 commit comments

Comments
 (0)