Fix dt-validate issues on qemu dtbdumps due to dt-bindings
Subsystems (5)
cover Fix dt-validate issues on qemu dtbdumps due to dt-bindings
From: Conor Dooley <[email protected]>
The device trees produced automatically for the virt and spike machines fail dt-validate on several grounds. Some of these need to be fixed in the linux kernel's dt-bindings, but others are caused by bugs in QEMU.
Patches been sent that fix the QEMU issues [0], but a couple of them need to be fixed in the kernel's dt-bindings. The first patches add compatibles for "riscv,{clint,plic}0" which are present in drivers and the auto generated QEMU dtbs. The final patch should be ignored for all serious purposes unless you want to wash your eyes out afterwards, but JIC the versioned extensions ever come up, it's there.
Thanks to Rob Herring for reporting these issues [1], Conor.
To reproduce the errors:
./build/qemu-system-riscv64 -nographic -machine virt,dumpdtb=qemu.dtb
dt-validate -p /path/to/linux/kernel/Documentation/devicetree/bindings/processed-schema.json qemu.dtb (The processed schema needs to be generated first)
0 - https://lore.kernel.org/linux-riscv/[email protected]/
1 - https://lore.kernel.org/linux-riscv/[email protected]/
Changes since v1:
- drop the "legacy systems" bit from the binding descriptions
- convert to a regex for the isa string
Conor Dooley (4):
dt-bindings: timer: sifive,clint: add legacy riscv compatible
dt-bindings: interrupt-controller: sifive,plic: add legacy riscv
compatible
dt-bindings: riscv: add new riscv,isa strings for emulators
dt-bindings: riscv: isa string bonus content
.../sifive,plic-1.0.0.yaml | 5 +++++ .../devicetree/bindings/riscv/cpus.yaml | 9 ++++++--- .../bindings/timer/sifive,clint.yaml | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-)
base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
Signature · 1 line
2.37.1
PATCH 1/4 dt-bindings: timer: sifive,clint: add legacy riscv compatible
From: Conor Dooley <[email protected]>
While "real" hardware might not use the compatible string "riscv,clint0" it is present in the driver & QEMU uses it for automatically generated virt machine dtbs. To avoid dt-validate problems with QEMU produced dtbs, such as the following, add it to the binding.
riscv-virt.dtb: clint@2000000: compatible:0: 'sifive,clint0' is not one of ['sifive,fu540-c000-clint', 'starfive,jh7100-clint', 'canaan,k210-clint']
--- .../bindings/timer/sifive,clint.yaml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/timer/sifive,clint.yaml +12 -6
@@ -22,12 +22,18 @@ description: properties: compatible: - items: - - enum: - - sifive,fu540-c000-clint - - starfive,jh7100-clint - - canaan,k210-clint - - const: sifive,clint0 + oneOf: + - items: + - enum: + - sifive,fu540-c000-clint + - starfive,jh7100-clint + - canaan,k210-clint + - const: sifive,clint0 + - items: + - const: sifive,clint0 + - const: riscv,clint0 + deprecated: true + description: For the QEMU virt machine only description: Should be "<vendor>,<chip>-clint" and "sifive,clint<version>".
Signature · 1 line
2.37.1
PATCH 2/4 dt-bindings: interrupt-controller: sifive,plic: add legacy riscv compatible
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
While "real" hardware might not use the compatible string "riscv,plic0" it is present in the driver & QEMU uses it for automatically generated virt machine dtbs. To avoid dt-validate problems with QEMU produced dtbs, such as the following, add it to the binding.
riscv-virt.dtb: plic@c000000: compatible: 'oneOf' conditional failed, one must be fixed:
'sifive,plic-1.0.0' is not one of ['sifive,fu540-c000-plic', 'starfive,jh7100-plic', 'canaan,k210-plic']
'sifive,plic-1.0.0' is not one of ['allwinner,sun20i-d1-plic']
'sifive,plic-1.0.0' was expected
'thead,c900-plic' was expectedriscv-virt.dtb: plic@c000000: '#address-cells' is a required property
--- .../bindings/interrupt-controller/sifive,plic-1.0.0.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/interrupt-controller/sifive,plic-1.0.0.yaml +5 -0
@@ -66,6 +66,11 @@ properties: - enum: - allwinner,sun20i-d1-plic - const: thead,c900-plic + - items: + - const: sifive,plic-1.0.0 + - const: riscv,plic0 + deprecated: true + description: For the QEMU virt machine only reg: maxItems: 1
Signature · 1 line
2.37.1
PATCH 3/4 dt-bindings: riscv: add new riscv,isa strings for emulators
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
The QEMU virt and spike machines currently export a riscv,isa string of "rv64imafdcsuh",
While the RISC-V foundation has been ratifying a bunch of extenstions etc, the kernel has remained relatively static with what hardware is supported - but the same is not true of QEMU. Using the virt machine and running dt-validate on the dumped dtb fails, partly due to the unexpected isa string.
Rather than enumerate the many many possbilities, change the pattern to a regex, with the following assumptions:
- the single letter order is fixed & we don't care about things that can't even do "ima"
- the standard multi letter extensions are all in a "_z<foo>" format where the first letter of <foo> is a valid single letter extension
- _s & _h are used for supervisor and hyper visor extensions.
- after the first two chars, a standard multi letter extension name
could be an english word (ifencei anyone?) so it's not worth
restricting the charset
- vendor ISA extensions begind with _x and have no charset restrictions
- we don't care about an e extension from an OS pov
- that attempting to validate the contents of the multiletter extensions with dt-validate beyond the formatting is a futile, massively verbose or unwieldy exercise at best.
- ima are required
The following limitations also apply:
- multi letter extension ordering is not enforced. dt-schema does not appear to allow for named match groups, so the resulting regex would be even more of a headache.
- ditto for the numbered extensions.
Finally, add me as a maintainer of the binding so that when it breaks in the future, I can be held responsible!
---
Palmer, feel free to drop the maintainer addition. I just mostly want to clean up my own mess on this when they decide to ratify more extensions & this comes back up again.
--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/riscv/cpus.yaml +2 -3
@@ -9,6 +9,7 @@ title: RISC-V bindings for 'cpus' DT nodes maintainers: - Paul Walmsley <[email protected]> - Palmer Dabbelt <[email protected]> + - Conor Dooley <[email protected]> description: | This document uses some terminology common to the RISC-V community
@@ -79,9 +80,7 @@ properties: insensitive, letters in the riscv,isa string must be all lowercase to simplify parsing. $ref: "/schemas/types.yaml#/definitions/string" - enum: - - rv64imac - - rv64imafdc + pattern: ^rv(?:64|32)imaf?d?q?c?b?v?k?h?(?:(?:_[zsh][imafdqcbvksh]|_x)(?:[a-z])+)*$ # RISC-V requires 'timebase-frequency' in /cpus, so disallow it here timebase-frequency: false
Signature · 1 line
2.37.1
Re: [PATCH 3/4] dt-bindings: riscv: add new riscv,isa strings for emulators
Quoted 74 lines · Conor Dooley
From: Conor Dooley <[email protected]>
The QEMU virt and spike machines currently export a riscv,isa string of "rv64imafdcsuh",
While the RISC-V foundation has been ratifying a bunch of extenstions etc, the kernel has remained relatively static with what hardware is supported - but the same is not true of QEMU. Using the virt machine and running dt-validate on the dumped dtb fails, partly due to the unexpected isa string.
Rather than enumerate the many many possbilities, change the pattern to a regex, with the following assumptions:
- the single letter order is fixed & we don't care about things that can't even do "ima"
- the standard multi letter extensions are all in a "_z<foo>" format where the first letter of <foo> is a valid single letter extension
- _s & _h are used for supervisor and hyper visor extensions.
- after the first two chars, a standard multi letter extension name
could be an english word (ifencei anyone?) so it's not worth
restricting the charset
- vendor ISA extensions begind with _x and have no charset restrictions
- we don't care about an e extension from an OS pov
- that attempting to validate the contents of the multiletter extensions with dt-validate beyond the formatting is a futile, massively verbose or unwieldy exercise at best.
- ima are requiredThe following limitations also apply:
- multi letter extension ordering is not enforced. dt-schema does not appear to allow for named match groups, so the resulting regex would be even more of a headache.
- ditto for the numbered extensions.Finally, add me as a maintainer of the binding so that when it breaks in the future, I can be held responsible!
Reported-by Rob Herring <[email protected]>Signed-off-by Conor Dooley <[email protected]>---
Palmer, feel free to drop the maintainer addition. I just mostly want to clean up my own mess on this when they decide to ratify more extensions & this comes back up again.--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)Documentation/devicetree/bindings/riscv/cpus.yaml +2
-3@@ -9,6 +9,7 @@ title: RISC-V bindings for 'cpus' DT nodes maintainers: - Paul Walmsley <[email protected]> - Palmer Dabbelt <[email protected]> + - Conor Dooley <[email protected]> description: | This document uses some terminology common to the RISC-V community@@ -79,9 +80,7 @@ properties: insensitive, letters in the riscv,isa string must be all lowercase to simplify parsing. $ref: "/schemas/types.yaml#/definitions/string" - enum: - - rv64imac - - rv64imafdc + pattern: ^rv(?:64|32)imaf?d?q?c?b?v?k?h?(?:(?:_[zsh][imafdqcbvksh]|_x)(?:[a-z])+)*$ # RISC-V requires 'timebase-frequency' in /cpus, so disallow it here timebase-frequency: falseSignature · 1 line
2.37.1
I'd say "looks good to me", but it's a regex, so "good" is a strong word. Instead, here's a [somewhat tentative]
Thanks,
drew
Re: [PATCH 3/4] dt-bindings: riscv: add new riscv,isa strings for emulators
Quoted 8 lines · Andrew Jones
Quoted 2 lines · Conor Dooley
From: Conor Dooley <[email protected]>
I'd say "looks good to me", but it's a regex, so "good" is a strong word. Instead, here's a [somewhat tentative]
Reviewed-by Andrew Jones <[email protected]>
Hey Andrew, unfortunately I messed up mailing this patchset (I forgot to delete after running format-patch without -v2) Would you mind responding to what I have labeled as v3? The content is the same, I just messed up sending!
Thanks for reviewing. I agree with "good" being a strong word here,
Conor.
PATCH 4/4 dt-bindings: riscv: isa string bonus content
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
**NOT FOR CONSIDERATION**
I figured, sure why not add the strings for version number validation, just in case we need them in the future. The commented out string is considered by dt-schema to be "not a regex", but regex101 thinks it is... Maybe dt-schema does not support named match groups, but they are the only way that I could trivially find to make this somewhat manageable. Either way, it is permissive so it allows combinations of "M", "MpM" & no number.
--- Documentation/devicetree/bindings/riscv/cpus.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/riscv/cpus.yaml +5 -1
@@ -80,7 +80,11 @@ properties: insensitive, letters in the riscv,isa string must be all lowercase to simplify parsing. $ref: "/schemas/types.yaml#/definitions/string" - pattern: ^rv(?:64|32)imaf?d?q?c?b?v?k?h?(?:(?:_[zsh][imafdqcbvksh]|_x)(?:[a-z])+)*$ + oneOf: + - pattern: ^rv(?:64|32)imaf?d?q?c?b?v?k?h?(?:(?:_[zsh][imafdqcbvksh]|_x)(?:[a-z])+)*$ + - pattern: ^rv(?:64|32)(?:i\d+)(?:m\d+)(?:a\d+)(?:f\d+)?(?:d\d+)?(?:q\d+)?(?:c\d+)?(?:b\d+)?(?:v\d+)?(?:k\d+)?(?:h\d+)?(?:(?:_[zsh][imafdqcbvksh]|_x)(?:[a-z])+\d+)*$ + - pattern: ^rv(?:64|32)(?:i\d+p\d+)(?:m\d+p\d+)(?:a\d+p\d+)(?:f\d+p\d+)?(?:d\d+p\d+)?(?:q\d+p\d+)?(?:c\d+p\d+)?(?:b\d+p\d+)?(?:v\d+p\d+)?(?:k\d+p\d+)?(?:h\d+p\d+)?(?:(?:_[zsh][imafdqcbvksh]|_x)(?:[a-z])+(?:\d+p\d+))*$ +# - pattern: ^rv(?:64|32)(?:i(?<num>(?:\d+|\d+p\d+)?)?)(?:m(?:\k<num>)?)(?:a(?:\k<num>)?)(?:f(?:\k<num>)?)?(?:d(?:\k<num>)?)?(?:q(?:\k<num>)?)?(?:c(?:\k<num>)?)?(?:b(?:\k<num>)?)?(?:v(?:\k<num>)?)?(?:k(?:\k<num>)?)?(?:h(?:\k<num>)?)?(?:(?:_[zsh][imafdqcbvksh]|_x)(?:[a-z])*(?:\d+|\d+p\d+)?)+$ # RISC-V requires 'timebase-frequency' in /cpus, so disallow it here timebase-frequency: false
Signature · 1 line
2.37.1
v2 cover Fix dt-validate issues on qemu dtbdumps due to dt-bindings
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
The device trees produced automatically for the virt and spike machines fail dt-validate on several grounds. Some of these need to be fixed in the linux kernel's dt-bindings, but others are caused by bugs in QEMU.
Patches been sent that fix the QEMU issues [0], but a couple of them need to be fixed in the kernel's dt-bindings. The first patches add compatibles for "riscv,{clint,plic}0" which are present in drivers and the auto generated QEMU dtbs. The final patch should be ignored for all serious purposes unless you want to wash your eyes out afterwards, but JIC the versioned extensions ever come up, it's there.
Thanks to Rob Herring for reporting these issues [1], Conor.
To reproduce the errors:
./build/qemu-system-riscv64 -nographic -machine virt,dumpdtb=qemu.dtb
dt-validate -p /path/to/linux/kernel/Documentation/devicetree/bindings/processed-schema.json qemu.dtb (The processed schema needs to be generated first)
0 - https://lore.kernel.org/linux-riscv/[email protected]/
1 - https://lore.kernel.org/linux-riscv/[email protected]/
Changes since v1:
- drop the "legacy systems" bit from the binding descriptions
- convert to a regex for the isa string
Conor Dooley (4):
dt-bindings: timer: sifive,clint: add legacy riscv compatible
dt-bindings: interrupt-controller: sifive,plic: add legacy riscv
compatible
dt-bindings: riscv: add new riscv,isa strings for emulators
dt-bindings: riscv: isa string bonus content
.../sifive,plic-1.0.0.yaml | 5 +++++ .../devicetree/bindings/riscv/cpus.yaml | 9 ++++++--- .../bindings/timer/sifive,clint.yaml | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-)
base-commit: 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
Signature · 1 line
2.37.1
Please also ignore this series, I accidentally had too much in the folder.
Quoted 42 lines · Conor Dooley
From: Conor Dooley <[email protected]>
The device trees produced automatically for the virt and spike machines fail dt-validate on several grounds. Some of these need to be fixed in the linux kernel's dt-bindings, but others are caused by bugs in QEMU.
Patches been sent that fix the QEMU issues [0], but a couple of them need to be fixed in the kernel's dt-bindings. The first patches add compatibles for "riscv,{clint,plic}0" which are present in drivers and the auto generated QEMU dtbs. The final patch should be ignored for all serious purposes unless you want to wash your eyes out afterwards, but JIC the versioned extensions ever come up, it's there.
Thanks to Rob Herring for reporting these issues [1], Conor.
To reproduce the errors:
./build/qemu-system-riscv64 -nographic -machine virt,dumpdtb=qemu.dtb
dt-validate -p /path/to/linux/kernel/Documentation/devicetree/bindings/processed-schema.json qemu.dtb (The processed schema needs to be generated first)0 - https://lore.kernel.org/linux-riscv/[email protected]/
1 - https://lore.kernel.org/linux-riscv/[email protected]/Changes since v1:
- drop the "legacy systems" bit from the binding descriptions
- convert to a regex for the isa stringConor Dooley (4):
dt-bindings: timer: sifive,clint: add legacy riscv compatible
dt-bindings: interrupt-controller: sifive,plic: add legacy riscv
compatible
dt-bindings: riscv: add new riscv,isa strings for emulators
dt-bindings: riscv: isa string bonus content.../sifive,plic-1.0.0.yaml | 5 +++++ .../devicetree/bindings/riscv/cpus.yaml | 9 ++++++--- .../bindings/timer/sifive,clint.yaml | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-)base-commit:
568035b01cfb107af8d2e4bd2fb9aea22cf5b868
PATCH v2 1/4 dt-bindings: timer: sifive,clint: add legacy riscv compatible
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
While "real" hardware might not use the compatible string "riscv,clint0" it is present in the driver & QEMU uses it for automatically generated virt machine dtbs. To avoid dt-validate problems with QEMU produced dtbs, such as the following, add it to the binding.
riscv-virt.dtb: clint@2000000: compatible:0: 'sifive,clint0' is not one of ['sifive,fu540-c000-clint', 'starfive,jh7100-clint', 'canaan,k210-clint']
--- .../bindings/timer/sifive,clint.yaml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/timer/sifive,clint.yaml +12 -6
@@ -22,12 +22,18 @@ description: properties: compatible: - items: - - enum: - - sifive,fu540-c000-clint - - starfive,jh7100-clint - - canaan,k210-clint - - const: sifive,clint0 + oneOf: + - items: + - enum: + - sifive,fu540-c000-clint + - starfive,jh7100-clint + - canaan,k210-clint + - const: sifive,clint0 + - items: + - const: sifive,clint0 + - const: riscv,clint0 + deprecated: true + description: For the QEMU virt machine only description: Should be "<vendor>,<chip>-clint" and "sifive,clint<version>".
Signature · 1 line
2.37.1
PATCH v2 1/4 hw/riscv: virt: fix uart node name
In reply to Conor DooleyFrom: Conor Dooley <[email protected]>
"uart" is not a node name that complies with the dt-schema.
Change the node name to "serial" to ix warnings seen during
dt-validate on a dtbdump of the virt machine such as:
/stuff/qemu/qemu.dtb: uart@10000000: $nodename:0: 'uart@10000000' does not match '^serial(@.*)?$'
From schema: /stuff/linux/Documentation/devicetree/bindings/serial/8250.yaml
--- hw/riscv/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/virt.c +1 -1
@@ -917,7 +917,7 @@ static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap,char *name;MachineState *mc =MACHINE (s); - name =g_strdup_printf ("/soc/uart@%lx" , (long )memmap[VIRT_UART0 ].base); + name =g_strdup_printf ("/soc/serial@%lx" , (long )memmap[VIRT_UART0 ].base);qemu_fdt_add_subnode (mc->fdt, name);qemu_fdt_setprop_string (mc->fdt, name,"compatible" ,"ns16550a" ); qemu_fdt_setprop_cells(mc->fdt, name, "reg",
Signature · 1 line
2.37.1
Re: [PATCH v2 1/4] hw/riscv: virt: fix uart node name
On 17/08/2022 21:05, Conor Dooley wrote:
I didn't realise this one slipped out too when I messed up mailing unrelated patches yesterday, this is identical to what I previously submitted as a v2 - I ran send-email on a dirty directory...
I can re-submit this as v3 if it makes things easier?
Thanks,
Conor.
Quoted 35 lines
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
From: Conor Dooley <[email protected]>
"uart" is not a node name that complies with the dt-schema.
Change the node name to "serial" to ix warnings seen during
dt-validate on a dtbdump of the virt machine such as:
/stuff/qemu/qemu.dtb: uart@10000000: $nodename:0: 'uart@10000000' does not match '^serial(@.*)?$'
From schema: /stuff/linux/Documentation/devicetree/bindings/serial/8250.yamlReported-by Rob Herring <[email protected]>Fixes 04331d0b56 ("RISC-V VirtIO Machine")Reviewed-by Alistair Francis <[email protected]>Signed-off-by Conor Dooley <[email protected]>--- hw/riscv/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/riscv/virt.c +1
-2@@ -917,7 +917,7 @@ static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap,char *name;MachineState *mc =MACHINE (s); - name =g_strdup_printf ("/soc/uart@%lx" , (long )memmap[VIRT_UART0 ].base); + name =g_strdup_printf ("/soc/serial@%lx" , (long )memmap[VIRT_UART0 ].base);qemu_fdt_add_subnode (mc->fdt, name);qemu_fdt_setprop_string (mc->fdt, name,"compatible" ,"ns16550a" ); qemu_fdt_setprop_cells(mc->fdt, name, "reg", --2.37.1
Please ignore this series, I accidentally had too much in the folder.
Quoted 42 lines · Conor Dooley
From: Conor Dooley <[email protected]>
The device trees produced automatically for the virt and spike machines fail dt-validate on several grounds. Some of these need to be fixed in the linux kernel's dt-bindings, but others are caused by bugs in QEMU.
Patches been sent that fix the QEMU issues [0], but a couple of them need to be fixed in the kernel's dt-bindings. The first patches add compatibles for "riscv,{clint,plic}0" which are present in drivers and the auto generated QEMU dtbs. The final patch should be ignored for all serious purposes unless you want to wash your eyes out afterwards, but JIC the versioned extensions ever come up, it's there.
Thanks to Rob Herring for reporting these issues [1], Conor.
To reproduce the errors:
./build/qemu-system-riscv64 -nographic -machine virt,dumpdtb=qemu.dtb
dt-validate -p /path/to/linux/kernel/Documentation/devicetree/bindings/processed-schema.json qemu.dtb (The processed schema needs to be generated first)0 - https://lore.kernel.org/linux-riscv/[email protected]/
1 - https://lore.kernel.org/linux-riscv/[email protected]/Changes since v1:
- drop the "legacy systems" bit from the binding descriptions
- convert to a regex for the isa stringConor Dooley (4):
dt-bindings: timer: sifive,clint: add legacy riscv compatible
dt-bindings: interrupt-controller: sifive,plic: add legacy riscv
compatible
dt-bindings: riscv: add new riscv,isa strings for emulators
dt-bindings: riscv: isa string bonus content.../sifive,plic-1.0.0.yaml | 5 +++++ .../devicetree/bindings/riscv/cpus.yaml | 9 ++++++--- .../bindings/timer/sifive,clint.yaml | 18 ++++++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-)base-commit:
568035b01cfb107af8d2e4bd2fb9aea22cf5b868