Skip to content

Commit 97be675

Browse files
atishp04avpatel
authored andcommitted
KVM: riscv: selftests: Add helper functions for extension checks
__vcpu_has_ext can check both SBI and ISA extensions when the first argument is properly converted to SBI/ISA extension IDs. Introduce two helper functions to make life easier for developers so they don't have to worry about the conversions. Replace the current usages as well with new helpers. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent 9408a23 commit 97be675

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tools/testing/selftests/kvm/include/riscv/processor.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype,
5050

5151
bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext);
5252

53+
static inline bool __vcpu_has_isa_ext(struct kvm_vcpu *vcpu, uint64_t isa_ext)
54+
{
55+
return __vcpu_has_ext(vcpu, RISCV_ISA_EXT_REG(isa_ext));
56+
}
57+
58+
static inline bool __vcpu_has_sbi_ext(struct kvm_vcpu *vcpu, uint64_t sbi_ext)
59+
{
60+
return __vcpu_has_ext(vcpu, RISCV_SBI_EXT_REG(sbi_ext));
61+
}
62+
5363
struct ex_regs {
5464
unsigned long ra;
5565
unsigned long sp;

tools/testing/selftests/kvm/riscv/arch_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct kvm_vm *test_vm_create(void)
8585
int nr_vcpus = test_args.nr_vcpus;
8686

8787
vm = vm_create_with_vcpus(nr_vcpus, guest_code, vcpus);
88-
__TEST_REQUIRE(__vcpu_has_ext(vcpus[0], RISCV_ISA_EXT_REG(KVM_RISCV_ISA_EXT_SSTC)),
88+
__TEST_REQUIRE(__vcpu_has_isa_ext(vcpus[0], KVM_RISCV_ISA_EXT_SSTC),
8989
"SSTC not available, skipping test\n");
9090

9191
vm_init_vector_tables(vm);

0 commit comments

Comments
 (0)