KVM: riscv: selftests: Change vcpu_has_ext to a common function
authorHaibo Xu <haibo1.xu@intel.com>
Mon, 22 Jan 2024 09:58:41 +0000 (17:58 +0800)
committerAnup Patel <anup@brainfault.org>
Wed, 6 Mar 2024 15:23:27 +0000 (20:53 +0530)
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>
tools/testing/selftests/kvm/include/riscv/processor.h
tools/testing/selftests/kvm/lib/riscv/processor.c
tools/testing/selftests/kvm/riscv/get-reg-list.c

index fe8eda69ce00c85ba7f3d7d359b83680f65c48a5..1b0a9e9d2d3010896bdf6b95dc1f0c21595a6462 100644 (file)
@@ -48,6 +48,8 @@ static inline uint64_t __kvm_reg_id(uint64_t type, uint64_t subtype,
                                                     KVM_REG_RISCV_SBI_SINGLE,          \
                                                     idx, KVM_REG_SIZE_ULONG)
 
+bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext);
+
 struct ex_regs {
        unsigned long ra;
        unsigned long sp;
index 4be94d0f0b94f41270c467a966acfab2e1b63b1e..ec66d331a127389447510070d4fdfb916ffa4155 100644 (file)
 
 static vm_vaddr_t exception_handlers;
 
+bool __vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext)
+{
+       unsigned long value = 0;
+       int ret;
+
+       ret = __vcpu_get_reg(vcpu, ext, &value);
+
+       return !ret && !!value;
+}
+
 static uint64_t page_align(struct kvm_vm *vm, uint64_t v)
 {
        return (v + vm->page_size) & ~(vm->page_size - 1);
index 6435e7a6564252fae5e1cbd2275a6fc0c3a7f12f..8cece02ca23ad12aafed94e6d28e2bd1170a6a59 100644 (file)
@@ -123,15 +123,6 @@ bool check_reject_set(int err)
        return err == EINVAL;
 }
 
-static bool vcpu_has_ext(struct kvm_vcpu *vcpu, uint64_t ext_id)
-{
-       int ret;
-       unsigned long value;
-
-       ret = __vcpu_get_reg(vcpu, ext_id, &value);
-       return (ret) ? false : !!value;
-}
-
 void finalize_vcpu(struct kvm_vcpu *vcpu, struct vcpu_reg_list *c)
 {
        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)
                __vcpu_set_reg(vcpu, feature, 1);
 
                /* Double check whether the desired extension was enabled */
-               __TEST_REQUIRE(vcpu_has_ext(vcpu, feature),
+               __TEST_REQUIRE(__vcpu_has_ext(vcpu, feature),
                               "%s not available, skipping tests", s->name);
        }
 }