[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] xen/riscv: add support for riscv,isa-extensions devicetree property



Hi Cristian,

Thanks for contributing to Xen on RISC-V!


> Xen panics when a CPU only has the riscv,isa-extensions property in
> the device tree. It only accepts the deprecated riscv,isa property,
> which forces users to use legacy devicetrees.
> 
> Use riscv,isa-extensions if present, otherwise the legacy riscv,isa.
> If the new property is used, riscv,isa-extensions and riscv,isa-base
> must both be present and riscv,isa-base must exactly match the build
> string. Make a new shared helper riscv_isa_ext_check() which returns
> the exact state of the property: whether both are present or to use
> the legacy property. This helper makes both cpufeature.c and smpboot.c
> agree on which property a CPU uses.
> 
> A CPU with neither property is skipped with a message. Make it now
> an error because a skipped CPU is left out of the intersection, so
> Xen could use extensions that CPU lacks.
> 
> Add a per-CPU fallback so that any mix of new and legacy CPUs works.
> This deviates from Linux, which skips CPUs without riscv,isa-extensions
> and could assume extensions those CPUs lack.
> 
> Add a first-CPU flag because with the new riscv,isa-extensions, a CPU's
> set can now be empty, which would make a later CPU appear as the first
> one. This couldn't happen with riscv,isa, where 'i' is always set.
> 
> Use the new property in dt_processor_hartid(), with the legacy
> fallback, which also only used the legacy riscv,isa during
> interrupt-controller setup.
> 
> Suggested-by: Denis Mukhin <dmukhin@xxxxxxxx>
> Signed-off-by: Cristian Andrei <cristian.andrei1423@xxxxxxxxx>

I would first say explicitly what Xen currently does: it only parses
riscv,isa, which is deprecated in the DT bindings, and silently skips
CPU nodes that lack it. Something like (I also shortened the subject):

    xen/riscv: support riscv,isa-extensions devicetree property

    Xen only parses the riscv,isa devicetree property, which Linux has
    deprecated in favour of riscv,isa-base plus riscv,isa-extensions [1].
    Xen panics if no CPU node has riscv,isa, so a devicetree using only
    the new properties cannot boot Xen.

    Use riscv,isa-extensions when present, falling back to the legacy
    riscv,isa otherwise. With the new binding, riscv,isa-extensions and
    riscv,isa-base must both be present, and riscv,isa-base must match the
    base ISA Xen is built for ("rv64i" or "rv32i"). Add a shared helper,
    riscv_isa_ext_check(), so that cpufeature.c and smpboot.c agree on
    which property a CPU uses.

    Currently, a CPU node with neither property is skipped with a message.
    Make this an error instead, as a skipped CPU is left out of the ISA
    intersection and Xen could then use extensions that CPU lacks.

    Add a per-CPU fallback so that any mix of new and legacy CPUs works.
    This deviates from Linux, which skips CPUs without riscv,isa-extensions
    and could assume extensions those CPUs lack.

    Track the first CPU with a flag instead of testing whether the
    intersection is empty: with riscv,isa-extensions a CPU's set can be
    empty, which would make a later CPU look like the first one. This
    can't happen with the legacy riscv,isa, where 'i' is always set.

    dt_processor_hartid(), used during interrupt-controller setup, also
    only reads riscv,isa. Make it use the new property too, with the same
    legacy fallback.

    [1] Linux commit aeb71e42caae ("dt-bindings: riscv: deprecate riscv,isa")

> [ ... 66 lines skipped ... ]
> -static void __init riscv_fill_hwcap_from_isa_string(void)
> +int riscv_isa_ext_check(const struct dt_device_node *cpu)

The name reads like a pass/fail check, but callers act on three
outcomes: 0 (use riscv,isa-extensions), -ENOENT (new binding absent,
fall back to riscv,isa) and -EINVAL (invalid). Could it be renamed to
something like riscv_isa_ext_probe(), so that the -ENOENT test at the
call sites reads naturally? Together with the comment Oleksii asked for,
that should make it more clear.

> [ ... 63 lines skipped ... ]
> +        else if ( ret == -ENOENT &&
> +                  !dt_property_read_string(cpu, "riscv,isa", &isa) )
> +        {
> +            for ( unsigned int i = 0; (isa[i] != '\0'); i++ )

Nit: since the line is touched anyway, the parentheses around
isa[i] != '\0' can go.

> [ ... 16 lines skipped ... ]
> +        else
> +            panic("Unable to find \"riscv,isa\" or \"riscv,isa-extensions\" "
> +                  "devicetree entry for DT's cpu%lu node\n", cpuid);

Nit: maybe don't split the format string, it makes it harder to grep.
Keep the literal on one line and move cpuid to the next one:

            panic("Unable to find \"riscv,isa\" or \"riscv,isa-extensions\" 
devicetree entry for DT's cpu%lu node\n",
                  cpuid);


> [ ... 71 lines skipped ... ]
>          /*
> -         * As there is no any guarantee that SSTC will be added to riscv,isa
> -         * property by OpenSBI(it doesn't add it now) or whatever ran before
> -         * Xen, it is needed to set this bit manually.
> +         * As there is no any guarantee that SSTC will be added to

While rewrapping these lines: "there is no any guarantee" -> "there
is no guarantee".

> [ ... 35 lines skipped ... ]
> diff --git a/xen/arch/riscv/smpboot.c b/xen/arch/riscv/smpboot.c
> index 3b8bf98e20..95c4d650ac 100644
> --- a/xen/arch/riscv/smpboot.c
> +++ b/xen/arch/riscv/smpboot.c
> @@ -7,6 +7,7 @@
>  #include <xen/types.h>
>  
>  #include <asm/current.h>
> +#include <asm/cpufeature.h>

Please keep the <asm/...> group sorted alphabetically: cpufeature.h
goes before current.h.

> [ ... 17 lines skipped ... ]
> +    if ( dt_property_match_string(node, "riscv,isa-extensions", "i") < 0 ||
> +         dt_property_match_string(node, "riscv,isa-extensions", "m") < 0 ||
> +         dt_property_match_string(node, "riscv,isa-extensions", "a") < 0 )
> +    {
> +        printk("CPU with hartid=%#lx does not support ima\n", *hartid);

Missing log level: printk(XENLOG_ERR ...).

-- 
Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.