[PATCH] KVM: riscv: selftests: add check_supported_reg() into get-reg-list test

Yong-Xuan Wang posted 1 patch 1 month, 1 week ago
tools/testing/selftests/kvm/riscv/get-reg-list.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
[PATCH] KVM: riscv: selftests: add check_supported_reg() into get-reg-list test
Posted by Yong-Xuan Wang 1 month, 1 week ago
Not all the registers in a sublist are supported on a platform, e.g. the
SUBLIST_SBI_FWFT list. Add the check_supported_reg() to remove the false
alarm of missing registers.

Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
---
 tools/testing/selftests/kvm/riscv/get-reg-list.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c
index 8d6b951434eb..d7cb9b5d37df 100644
--- a/tools/testing/selftests/kvm/riscv/get-reg-list.c
+++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c
@@ -28,6 +28,18 @@ enum {
 
 static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX];
 
+bool check_supported_reg(struct kvm_vcpu *vcpu, __u64 reg)
+{
+	int ret;
+	u64 data;
+
+	ret = __vcpu_get_reg(vcpu, reg, &data);
+	if (ret < 0)
+		return false;
+
+	return true;
+}
+
 bool filter_reg(__u64 reg)
 {
 	switch (reg & ~REG_MASK) {

---
base-commit: ddbf9c76c4020bf63a0799b00faad40caa3de6c2
change-id: 20260503-kvm-get_reg_list-0b041a27fb23
Re: [PATCH] KVM: riscv: selftests: add check_supported_reg() into get-reg-list test
Posted by Andrew Jones 1 month, 1 week ago
On Sun, May 03, 2026 at 09:00:53PM -0700, Yong-Xuan Wang wrote:
> Not all the registers in a sublist are supported on a platform, e.g. the
> SUBLIST_SBI_FWFT list. Add the check_supported_reg() to remove the false
> alarm of missing registers.
> 
> Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>
> ---
>  tools/testing/selftests/kvm/riscv/get-reg-list.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c b/tools/testing/selftests/kvm/riscv/get-reg-list.c
> index 8d6b951434eb..d7cb9b5d37df 100644
> --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c
> +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c
> @@ -28,6 +28,18 @@ enum {
>  
>  static bool isa_ext_cant_disable[KVM_RISCV_ISA_EXT_MAX];
>  
> +bool check_supported_reg(struct kvm_vcpu *vcpu, __u64 reg)
> +{
> +	int ret;
> +	u64 data;
> +
> +	ret = __vcpu_get_reg(vcpu, reg, &data);
> +	if (ret < 0)
> +		return false;
> +
> +	return true;
> +}
> +

arm64 implements this function to only return false when a register's
corresponding feature register isn't present or it indicates the feature
isn't present. The above would return false for all missing registers,
even when they shouldn't be. OIOW, the above makes for_each_missing_reg()
useless for riscv.

When its OK for registers to be missing, then we need some way to
determine that. If a sublist has optional registers then it should
be broken into multiple sublists. Then, this function can be implemented
to return false for registers in the sublists of optional registers when
we have determined those sublists won't be present.

Thanks,
drew