On Mon, Jun 1, 2026 at 3:56 PM Yong-Xuan Wang <[email protected]> wrote: > > Refactor the get-reg-list test to use unified sublist macros for ISA > and SBI extensions, eliminating code duplication and improving > maintainability. > > Previously, each extension had its own hand-coded sublist definition > (e.g., SUBLIST_ZICBOM, SUBLIST_AIA, etc.) and the config structures > repeated the same pattern. This made the code verbose and error-prone. > > Signed-off-by: Yong-Xuan Wang <[email protected]>
LGTM. Reviewed-by: Anup Patel <[email protected]> Thanks, Anup > --- > tools/testing/selftests/kvm/riscv/get-reg-list.c | 78 > +++++++++--------------- > 1 file changed, 28 insertions(+), 50 deletions(-) > > diff --git a/tools/testing/selftests/kvm/riscv/get-reg-list.c > b/tools/testing/selftests/kvm/riscv/get-reg-list.c > index 8d6fdb5d38b8..5033c09201ef 100644 > --- a/tools/testing/selftests/kvm/riscv/get-reg-list.c > +++ b/tools/testing/selftests/kvm/riscv/get-reg-list.c > @@ -1013,7 +1013,7 @@ static __u64 fp_d_regs[] = { > }; > > /* Define a default vector registers with length. This will be overwritten > at runtime */ > -static __u64 vector_regs[] = { > +static __u64 v_regs[] = { > KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_VECTOR | > KVM_REG_RISCV_VECTOR_CSR_REG(vstart), > KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_VECTOR | > KVM_REG_RISCV_VECTOR_CSR_REG(vl), > KVM_REG_RISCV | KVM_REG_SIZE_ULONG | KVM_REG_RISCV_VECTOR | > KVM_REG_RISCV_VECTOR_CSR_REG(vtype), > @@ -1057,37 +1057,17 @@ static __u64 vector_regs[] = { > #define SUBLIST_BASE \ > {"base", .regs = base_regs, .regs_n = ARRAY_SIZE(base_regs), \ > .skips_set = base_skips_set, .skips_set_n = > ARRAY_SIZE(base_skips_set),} > -#define SUBLIST_SBI_BASE \ > - {"sbi-base", .feature_type = VCPU_FEATURE_SBI_EXT, .feature = > KVM_RISCV_SBI_EXT_V01, \ > - .regs = sbi_base_regs, .regs_n = ARRAY_SIZE(sbi_base_regs),} > -#define SUBLIST_SBI_STA \ > - {"sbi-sta", .feature_type = VCPU_FEATURE_SBI_EXT, .feature = > KVM_RISCV_SBI_EXT_STA, \ > - .regs = sbi_sta_regs, .regs_n = ARRAY_SIZE(sbi_sta_regs),} > -#define SUBLIST_SBI_FWFT \ > - {"sbi-fwft", .feature_type = VCPU_FEATURE_SBI_EXT, .feature = > KVM_RISCV_SBI_EXT_FWFT, \ > - .regs = sbi_fwft_regs, .regs_n = ARRAY_SIZE(sbi_fwft_regs),} > -#define SUBLIST_ZICBOM \ > - {"zicbom", .feature = KVM_RISCV_ISA_EXT_ZICBOM, .regs = zicbom_regs, > .regs_n = ARRAY_SIZE(zicbom_regs),} > -#define SUBLIST_ZICBOP \ > - {"zicbop", .feature = KVM_RISCV_ISA_EXT_ZICBOP, .regs = zicbop_regs, > .regs_n = ARRAY_SIZE(zicbop_regs),} > -#define SUBLIST_ZICBOZ \ > - {"zicboz", .feature = KVM_RISCV_ISA_EXT_ZICBOZ, .regs = zicboz_regs, > .regs_n = ARRAY_SIZE(zicboz_regs),} > -#define SUBLIST_AIA \ > - {"aia", .feature = KVM_RISCV_ISA_EXT_SSAIA, .regs = aia_regs, .regs_n > = ARRAY_SIZE(aia_regs),} > -#define SUBLIST_SMSTATEEN \ > - {"smstateen", .feature = KVM_RISCV_ISA_EXT_SMSTATEEN, .regs = > smstateen_regs, .regs_n = ARRAY_SIZE(smstateen_regs),} > -#define SUBLIST_FP_F \ > - {"fp_f", .feature = KVM_RISCV_ISA_EXT_F, .regs = fp_f_regs, \ > - .regs_n = ARRAY_SIZE(fp_f_regs),} > -#define SUBLIST_FP_D \ > - {"fp_d", .feature = KVM_RISCV_ISA_EXT_D, .regs = fp_d_regs, \ > - .regs_n = ARRAY_SIZE(fp_d_regs),} > - > -#define SUBLIST_V \ > - {"v", .feature = KVM_RISCV_ISA_EXT_V, .regs = vector_regs, .regs_n = > ARRAY_SIZE(vector_regs),} > + > +#define SUBLIST_ISA(ext, extu) \ > + { \ > + .name = #ext, \ > + .feature = KVM_RISCV_ISA_EXT_##extu, \ > + .regs = ext##_regs, \ > + .regs_n = ARRAY_SIZE(ext##_regs), \ > + } > > #define KVM_ISA_EXT_SIMPLE_CONFIG(ext, extu) \ > -static __u64 regs_##ext[] = { \ > +static __u64 ext##_regs[] = { \ > KVM_REG_RISCV | KVM_REG_SIZE_ULONG | \ > KVM_REG_RISCV_ISA_EXT | KVM_REG_RISCV_ISA_SINGLE | \ > KVM_RISCV_ISA_EXT_##extu, \ > @@ -1095,18 +1075,22 @@ static __u64 regs_##ext[] = { > \ > static struct vcpu_reg_list config_##ext = { \ > .sublists = { \ > SUBLIST_BASE, \ > - { \ > - .name = #ext, \ > - .feature = KVM_RISCV_ISA_EXT_##extu, \ > - .regs = regs_##ext, \ > - .regs_n = ARRAY_SIZE(regs_##ext), \ > - }, \ > + SUBLIST_ISA(ext, extu), \ > {0}, \ > }, \ > } \ > > +#define SUBLIST_SBI(ext, extu) \ > + { \ > + .name = "sbi-"#ext, \ > + .feature_type = VCPU_FEATURE_SBI_EXT, \ > + .feature = KVM_RISCV_SBI_EXT_##extu, \ > + .regs = sbi_##ext##_regs, \ > + .regs_n = ARRAY_SIZE(sbi_##ext##_regs), \ > + } > + > #define KVM_SBI_EXT_SIMPLE_CONFIG(ext, extu) \ > -static __u64 regs_sbi_##ext[] = { \ > +static __u64 sbi_##ext##_regs[] = { \ > KVM_REG_RISCV | KVM_REG_SIZE_ULONG | \ > KVM_REG_RISCV_SBI_EXT | KVM_REG_RISCV_SBI_SINGLE | \ > KVM_RISCV_SBI_EXT_##extu, \ > @@ -1114,13 +1098,7 @@ static __u64 regs_sbi_##ext[] = { > \ > static struct vcpu_reg_list config_sbi_##ext = { \ > .sublists = { \ > SUBLIST_BASE, \ > - { \ > - .name = "sbi-"#ext, \ > - .feature_type = VCPU_FEATURE_SBI_EXT, \ > - .feature = KVM_RISCV_SBI_EXT_##extu, \ > - .regs = regs_sbi_##ext, \ > - .regs_n = ARRAY_SIZE(regs_sbi_##ext), \ > - }, \ > + SUBLIST_SBI(ext, extu), \ > {0}, \ > }, \ > } \ > @@ -1129,7 +1107,7 @@ static struct vcpu_reg_list config_sbi_##ext = { > \ > static struct vcpu_reg_list config_##ext = { \ > .sublists = { \ > SUBLIST_BASE, \ > - SUBLIST_##extu, \ > + SUBLIST_ISA(ext, extu), \ > {0}, \ > }, \ > } \ > @@ -1138,14 +1116,14 @@ static struct vcpu_reg_list config_##ext = { > \ > static struct vcpu_reg_list config_sbi_##ext = { \ > .sublists = { \ > SUBLIST_BASE, \ > - SUBLIST_SBI_##extu, \ > + SUBLIST_SBI(ext, extu), \ > {0}, \ > }, \ > } \ > > /* Note: The below list is alphabetically sorted. */ > > -KVM_SBI_EXT_SUBLIST_CONFIG(base, BASE); > +KVM_SBI_EXT_SUBLIST_CONFIG(base, V01); > KVM_SBI_EXT_SUBLIST_CONFIG(sta, STA); > KVM_SBI_EXT_SIMPLE_CONFIG(pmu, PMU); > KVM_SBI_EXT_SIMPLE_CONFIG(dbcn, DBCN); > @@ -1153,9 +1131,9 @@ KVM_SBI_EXT_SIMPLE_CONFIG(susp, SUSP); > KVM_SBI_EXT_SIMPLE_CONFIG(mpxy, MPXY); > KVM_SBI_EXT_SUBLIST_CONFIG(fwft, FWFT); > > -KVM_ISA_EXT_SUBLIST_CONFIG(aia, AIA); > -KVM_ISA_EXT_SUBLIST_CONFIG(fp_f, FP_F); > -KVM_ISA_EXT_SUBLIST_CONFIG(fp_d, FP_D); > +KVM_ISA_EXT_SUBLIST_CONFIG(aia, SSAIA); > +KVM_ISA_EXT_SUBLIST_CONFIG(fp_f, F); > +KVM_ISA_EXT_SUBLIST_CONFIG(fp_d, D); > KVM_ISA_EXT_SUBLIST_CONFIG(v, V); > KVM_ISA_EXT_SIMPLE_CONFIG(h, H); > KVM_ISA_EXT_SIMPLE_CONFIG(smnpm, SMNPM); > > -- > 2.43.7 >

