[kvmtool PATCH 10/10] riscv: Allow including extensions in the min CPU type using command-line

Anup Patel apatel at ventanamicro.com
Thu Apr 24 08:17:02 PDT 2025


On Thu, Apr 24, 2025 at 7:37 PM Andrew Jones <ajones at ventanamicro.com> wrote:
>
> On Thu, Apr 24, 2025 at 07:02:18PM +0530, Anup Patel wrote:
> > On Sat, Apr 12, 2025 at 7:15 PM Andrew Jones <ajones at ventanamicro.com> wrote:
> > > >  bool riscv__isa_extension_disabled(struct kvm *kvm, unsigned long isa_ext_id)
> > > >  {
> > > >       struct isa_ext_info *info = NULL;
> > > > @@ -128,16 +142,39 @@ bool riscv__isa_extension_disabled(struct kvm *kvm, unsigned long isa_ext_id)
> > > >  int riscv__cpu_type_parser(const struct option *opt, const char *arg, int unset)
> > > >  {
> > > >       struct kvm *kvm = opt->ptr;
> > > > +     const char *str, *nstr;
> > > > +     int len;
> > > >
> > > > -     if ((strncmp(arg, "min", 3) && strncmp(arg, "max", 3)) || strlen(arg) != 3)
> > > > +     if ((strncmp(arg, "min", 3) || strlen(arg) < 3) &&
> > >
> > > If arg == 'min', then it can't be less than 3 so the '|| strlen(arg) < 3'
> > > is dead code.
> > >
> > > > +         (strncmp(arg, "max", 3) || strlen(arg) != 3))
> > >
> > > I think we want
> > >
> > >  if (strlen(arg) < 3 ||
> > >      (strlen(arg) == 3 && strcmp(arg, "min") && strcmp(arg, "max")) ||
> > >      strncmp(arg, "min", 3))
> >
> > Nope, for cpu-type = "min" the strlen(arg) can be greater than 3
> > because of comma separated extensions provided as part of
> > cpu-type value.
>
> That's what the last condition 'strncmp(arg, "min", 3)' of my proposed
> compound-condition is confirming. That condition is only checked for
> strlen(arg) > 3.
>

This last condition causes "--cpu-type max" to fail.

Regards,
Anup



More information about the kvm-riscv mailing list