Skip to content

Commit 812806b

Browse files
xiaobo55xavpatel
authored andcommitted
KVM: riscv: selftests: Change vcpu_has_ext to a common function
Move vcpu_has_ext to the processor.c and rename it to __vcpu_has_ext so that other test cases can use it for vCPU extension check. Signed-off-by: Haibo Xu <haibo1.xu@intel.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 1e97928 commit 812806b

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype,
4848
KVM_REG_RISCV_SBI_SINGLE, \
4949
idx, KVM_REG_SIZE_ULONG)
5050

51+
bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext);
52+
5153
struct ex_regs {
5254
unsigned long ra;
5355
unsigned long sp;

tools/testing/selftests/kvm/lib/riscv/processor.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515

1616
static vm_vaddr_t exception_handlers;
1717

18+
bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
19+
{
20+
unsigned long value = 0;
21+
int ret;
22+
23+
ret = __vcpu_get_reg(vcpu, ext, &value);
24+
25+
return !ret && !!value;
26+
}
27+
1828
static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
1929
{
2030
return (v + vm->page_size) & ~(vm->page_size - 1);

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,6 @@ bool check_reject_set(int err)
123123
return err == EINVAL;
124124
}
125125

126-
static bool vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext_id)
127-
{
128-
int ret;
129-
unsigned long value;
130-
131-
ret = __vcpu_get_reg(vcpu, ext_id, &value);
132-
return (ret) ? false : !!value;
133-
}
134-
135126
void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
136127
{
137128
unsigned long isa_ext_state[KVM_RISCV_ISA_EXT_MAX] = { 0 };
@@ -176,7 +167,7 @@ void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
176167
__vcpu_set_reg(vcpu, feature, 1);
177168

178169
/* Double check whether the desired extension was enabled */
179-
__TEST_REQUIRE(vcpu_has_ext(vcpu, feature),
170+
__TEST_REQUIRE(__vcpu_has_ext(vcpu, feature),
180171
"%s not available, skipping tests", s->name);
181172
}
182173
}

0 commit comments

Comments
 (0)