Message ID | 20250124090539.2506448-1-max.chou@sifive.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | target/riscv: rvv: Fix incorrect vlen comparison in prop_vlen_set | expand |
On 1/24/25 6:05 AM, Max Chou wrote: > In prop_vlen_set function, there is an incorrect comparison between > vlen(bit) and vlenb(byte). > This will cause unexpected error when user applies the `vlen=1024` cpu > option with a vendor predefined cpu type that the default vlen is > 1024(vlenb=128). > Fixes: 4f6d036ccc ("target/riscv/cpu.c: remove cpu->cfg.vlen") > Signed-off-by: Max Chou <max.chou@sifive.com> > --- Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> > target/riscv/cpu.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c > index 3d4bd157d2c..2f53acbab59 100644 > --- a/target/riscv/cpu.c > +++ b/target/riscv/cpu.c > @@ -2034,6 +2034,7 @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, > void *opaque, Error **errp) > { > RISCVCPU *cpu = RISCV_CPU(obj); > + uint16_t cpu_vlen = cpu->cfg.vlenb << 3; > uint16_t value; > > if (!visit_type_uint16(v, name, &value, errp)) { > @@ -2045,10 +2046,10 @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, > return; > } > > - if (value != cpu->cfg.vlenb && riscv_cpu_is_vendor(obj)) { > + if (value != cpu_vlen && riscv_cpu_is_vendor(obj)) { > cpu_set_prop_err(cpu, name, errp); > error_append_hint(errp, "Current '%s' val: %u\n", > - name, cpu->cfg.vlenb << 3); > + name, cpu_vlen); > return; > } >
On Fri, Jan 24, 2025 at 7:06 PM Max Chou <max.chou@sifive.com> wrote: > > In prop_vlen_set function, there is an incorrect comparison between > vlen(bit) and vlenb(byte). > This will cause unexpected error when user applies the `vlen=1024` cpu > option with a vendor predefined cpu type that the default vlen is > 1024(vlenb=128). > > Signed-off-by: Max Chou <max.chou@sifive.com> Thanks! Applied to riscv-to-apply.next Alistair > --- > target/riscv/cpu.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c > index 3d4bd157d2c..2f53acbab59 100644 > --- a/target/riscv/cpu.c > +++ b/target/riscv/cpu.c > @@ -2034,6 +2034,7 @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, > void *opaque, Error **errp) > { > RISCVCPU *cpu = RISCV_CPU(obj); > + uint16_t cpu_vlen = cpu->cfg.vlenb << 3; > uint16_t value; > > if (!visit_type_uint16(v, name, &value, errp)) { > @@ -2045,10 +2046,10 @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, > return; > } > > - if (value != cpu->cfg.vlenb && riscv_cpu_is_vendor(obj)) { > + if (value != cpu_vlen && riscv_cpu_is_vendor(obj)) { > cpu_set_prop_err(cpu, name, errp); > error_append_hint(errp, "Current '%s' val: %u\n", > - name, cpu->cfg.vlenb << 3); > + name, cpu_vlen); > return; > } > > -- > 2.34.1 > >
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 3d4bd157d2c..2f53acbab59 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -2034,6 +2034,7 @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { RISCVCPU *cpu = RISCV_CPU(obj); + uint16_t cpu_vlen = cpu->cfg.vlenb << 3; uint16_t value; if (!visit_type_uint16(v, name, &value, errp)) { @@ -2045,10 +2046,10 @@ static void prop_vlen_set(Object *obj, Visitor *v, const char *name, return; } - if (value != cpu->cfg.vlenb && riscv_cpu_is_vendor(obj)) { + if (value != cpu_vlen && riscv_cpu_is_vendor(obj)) { cpu_set_prop_err(cpu, name, errp); error_append_hint(errp, "Current '%s' val: %u\n", - name, cpu->cfg.vlenb << 3); + name, cpu_vlen); return; }
In prop_vlen_set function, there is an incorrect comparison between vlen(bit) and vlenb(byte). This will cause unexpected error when user applies the `vlen=1024` cpu option with a vendor predefined cpu type that the default vlen is 1024(vlenb=128). Signed-off-by: Max Chou <max.chou@sifive.com> --- target/riscv/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)