[PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands

Daniel Henrique Barboza posted 10 patches 1 year, 9 months ago
Failed in applying to current master (apply log)
hmp-commands-info.hx         |  13 +++
hmp-commands.hx              |  13 +++
hw/arm/boot.c                |   3 +-
hw/ppc/pegasos2.c            |   3 +
hw/ppc/spapr.c               |   3 +
hw/ppc/spapr_hcall.c         |   3 +
include/sysemu/device_tree.h |   3 +
monitor/misc.c               |  25 ++++
softmmu/device_tree.c        | 219 +++++++++++++++++++++++++++++++++++
9 files changed, 284 insertions(+), 1 deletion(-)
[PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands
Posted by Daniel Henrique Barboza 1 year, 9 months ago
Hi,

After dealing with a FDT element that isn't being shown in the userspace
and having to shutdown the guest, dump the FDT using 'machine -dumpdtb' and
then using 'dtc' to see what was inside the FDT, I thought it was a good
idea to add extra support for FDT handling in QEMU.

This series introduces 2 commands. 'fdt-save' behaves similar to what
'machine -dumpdtb' does, with the advantage of saving the FDT of a running
guest on demand. This command is implemented in patch 03.

The second command, 'info fdt <command>' is more sophisticated. This
command can print specific nodes and properties of the FDT. A few
examples:

- print the /cpus/cpu@0 from an ARM 'virt' machine:

(qemu) info fdt /cpus/cpu@0
/cpus/cpu@0 {
    phandle = <0x8001>
    reg = <0x0>
    compatible = 'arm,cortex-a57'
    device_type = 'cpu'
}
(qemu) 

- print the device_type property of the interrupt-controller node of a
pSeries machine:

(qemu) info fdt /interrupt-controller/device_type
/interrupt-controller/device_type = 'PowerPC-External-Interrupt-Presentation'
(qemu) 

Issuing a 'info fdt /' will dump all the FDT. 'info fdt' is implemented
in patches 4-10.

Both 'fdt-save' and 'info fdt' works across machines and archs based on
two premises: the FDT must be created using libfdt (which is the case of
all FDTs created with device_tree.c helpers and the _FDT macro) and the
FDT must be reachable via MachineState->fdt.

To meet the prerequisites for ARM machines, patch 1 makes a change in
arm_load_dtb(). Patches 2 and 3 makes a similar change for two PowerPC
machines that weren't using machine->fdt.

Tests were done using the ARM machvirt machine and ppc64 pSeries
machine, but any machine that meets the forementioned conditions will be
supported by these 2 new commands. 


Daniel Henrique Barboza (10):
  hw/arm/boot.c: do not free machine->fdt in arm_load_dtb()
  hw/ppc/pegasos2.c: set machine->fdt in machine_reset()
  hw/ppc: set machine->fdt in spapr machine
  hmp, device_tree.c: introduce fdt-save
  hmp, device_tree.c: introduce 'info fdt' command
  device_tree.c: support printing of strings props
  device_tree.c: support remaining FDT prop types
  device_node.c: enable 'info fdt' to print subnodes
  device_tree.c: add fdt_print_property() helper
  hmp, device_tree.c: add 'info fdt <property>' support

 hmp-commands-info.hx         |  13 +++
 hmp-commands.hx              |  13 +++
 hw/arm/boot.c                |   3 +-
 hw/ppc/pegasos2.c            |   3 +
 hw/ppc/spapr.c               |   3 +
 hw/ppc/spapr_hcall.c         |   3 +
 include/sysemu/device_tree.h |   3 +
 monitor/misc.c               |  25 ++++
 softmmu/device_tree.c        | 219 +++++++++++++++++++++++++++++++++++
 9 files changed, 284 insertions(+), 1 deletion(-)

-- 
2.36.1
Re: [PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands
Posted by Daniel P. Berrangé 1 year, 9 months ago
On Fri, Jul 22, 2022 at 04:59:57PM -0300, Daniel Henrique Barboza wrote:
> Hi,
> 
> After dealing with a FDT element that isn't being shown in the userspace
> and having to shutdown the guest, dump the FDT using 'machine -dumpdtb' and
> then using 'dtc' to see what was inside the FDT, I thought it was a good
> idea to add extra support for FDT handling in QEMU.
> 
> This series introduces 2 commands. 'fdt-save' behaves similar to what
> 'machine -dumpdtb' does, with the advantage of saving the FDT of a running
> guest on demand. This command is implemented in patch 03.
> 
> The second command, 'info fdt <command>' is more sophisticated. This
> command can print specific nodes and properties of the FDT. A few
> examples:
> 
> - print the /cpus/cpu@0 from an ARM 'virt' machine:
> 
> (qemu) info fdt /cpus/cpu@0
> /cpus/cpu@0 {
>     phandle = <0x8001>
>     reg = <0x0>
>     compatible = 'arm,cortex-a57'
>     device_type = 'cpu'
> }
> (qemu) 
> 
> - print the device_type property of the interrupt-controller node of a
> pSeries machine:
> 
> (qemu) info fdt /interrupt-controller/device_type
> /interrupt-controller/device_type = 'PowerPC-External-Interrupt-Presentation'
> (qemu)

Please don't add new HMP-only commands. These should be provided
as QMP commands, where the HMP is a tiny shim to the QMP.

If you don't want to think about formally modelling the data
for 'info fdt' / 'query-fdt', then just put an 'x-' prefix on
the QMP command and return printed formatted data, as illustrated
in:

https://www.qemu.org/docs/master/devel/writing-monitor-commands.html#writing-a-debugging-aid-returning-unstructured-text

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands
Posted by Daniel Henrique Barboza 1 year, 9 months ago

On 7/25/22 06:11, Daniel P. Berrangé wrote:
> On Fri, Jul 22, 2022 at 04:59:57PM -0300, Daniel Henrique Barboza wrote:
>> Hi,
>>
>> After dealing with a FDT element that isn't being shown in the userspace
>> and having to shutdown the guest, dump the FDT using 'machine -dumpdtb' and
>> then using 'dtc' to see what was inside the FDT, I thought it was a good
>> idea to add extra support for FDT handling in QEMU.
>>
>> This series introduces 2 commands. 'fdt-save' behaves similar to what
>> 'machine -dumpdtb' does, with the advantage of saving the FDT of a running
>> guest on demand. This command is implemented in patch 03.
>>
>> The second command, 'info fdt <command>' is more sophisticated. This
>> command can print specific nodes and properties of the FDT. A few
>> examples:
>>
>> - print the /cpus/cpu@0 from an ARM 'virt' machine:
>>
>> (qemu) info fdt /cpus/cpu@0
>> /cpus/cpu@0 {
>>      phandle = <0x8001>
>>      reg = <0x0>
>>      compatible = 'arm,cortex-a57'
>>      device_type = 'cpu'
>> }
>> (qemu)
>>
>> - print the device_type property of the interrupt-controller node of a
>> pSeries machine:
>>
>> (qemu) info fdt /interrupt-controller/device_type
>> /interrupt-controller/device_type = 'PowerPC-External-Interrupt-Presentation'
>> (qemu)
> 
> Please don't add new HMP-only commands. These should be provided
> as QMP commands, where the HMP is a tiny shim to the QMP.

I wasn't sure if this would be useful to be in QMP, but perhaps it's better to
let QMP consumers to decide whether use it or not.

I'll repost both as QMP commands with an HMP layer on top of them.


Daniel

> 
> If you don't want to think about formally modelling the data
> for 'info fdt' / 'query-fdt', then just put an 'x-' prefix on
> the QMP command and return printed formatted data, as illustrated
> in:
> 
> https://www.qemu.org/docs/master/devel/writing-monitor-commands.html#writing-a-debugging-aid-returning-unstructured-text
> 
> With regards,
> Daniel

Re: [PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands
Posted by Daniel P. Berrangé 1 year, 9 months ago
On Mon, Jul 25, 2022 at 10:16:11AM -0300, Daniel Henrique Barboza wrote:
> 
> 
> On 7/25/22 06:11, Daniel P. Berrangé wrote:
> > On Fri, Jul 22, 2022 at 04:59:57PM -0300, Daniel Henrique Barboza wrote:
> > > Hi,
> > > 
> > > After dealing with a FDT element that isn't being shown in the userspace
> > > and having to shutdown the guest, dump the FDT using 'machine -dumpdtb' and
> > > then using 'dtc' to see what was inside the FDT, I thought it was a good
> > > idea to add extra support for FDT handling in QEMU.
> > > 
> > > This series introduces 2 commands. 'fdt-save' behaves similar to what
> > > 'machine -dumpdtb' does, with the advantage of saving the FDT of a running
> > > guest on demand. This command is implemented in patch 03.
> > > 
> > > The second command, 'info fdt <command>' is more sophisticated. This
> > > command can print specific nodes and properties of the FDT. A few
> > > examples:
> > > 
> > > - print the /cpus/cpu@0 from an ARM 'virt' machine:
> > > 
> > > (qemu) info fdt /cpus/cpu@0
> > > /cpus/cpu@0 {
> > >      phandle = <0x8001>
> > >      reg = <0x0>
> > >      compatible = 'arm,cortex-a57'
> > >      device_type = 'cpu'
> > > }
> > > (qemu)
> > > 
> > > - print the device_type property of the interrupt-controller node of a
> > > pSeries machine:
> > > 
> > > (qemu) info fdt /interrupt-controller/device_type
> > > /interrupt-controller/device_type = 'PowerPC-External-Interrupt-Presentation'
> > > (qemu)
> > 
> > Please don't add new HMP-only commands. These should be provided
> > as QMP commands, where the HMP is a tiny shim to the QMP.
> 
> I wasn't sure if this would be useful to be in QMP, but perhaps it's better to
> let QMP consumers to decide whether use it or not.

That's not a relevant question to consider. The end goal is for HMP
to be 100% implemented in terms of QMP commands. So if anything is
required for HMP, then by definition it is also required for QMP.

The only question is whether the QMP command should be marked stable
or unstable. If there's any doubt, that pushes towards the 'unstable'
side, such that we don't have to promise API compat

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH for-7.2 00/10] add hmp 'save-fdt' and 'info fdt' commands
Posted by BALATON Zoltan 1 year, 9 months ago
On Fri, 22 Jul 2022, Daniel Henrique Barboza wrote:
> Hi,
>
> After dealing with a FDT element that isn't being shown in the userspace
> and having to shutdown the guest, dump the FDT using 'machine -dumpdtb' and
> then using 'dtc' to see what was inside the FDT, I thought it was a good
> idea to add extra support for FDT handling in QEMU.
>
> This series introduces 2 commands. 'fdt-save' behaves similar to what
> 'machine -dumpdtb' does, with the advantage of saving the FDT of a running
> guest on demand. This command is implemented in patch 03.
>
> The second command, 'info fdt <command>' is more sophisticated. This
> command can print specific nodes and properties of the FDT. A few
> examples:
>
> - print the /cpus/cpu@0 from an ARM 'virt' machine:
>
> (qemu) info fdt /cpus/cpu@0
> /cpus/cpu@0 {
>    phandle = <0x8001>
>    reg = <0x0>
>    compatible = 'arm,cortex-a57'
>    device_type = 'cpu'
> }
> (qemu)
>
> - print the device_type property of the interrupt-controller node of a
> pSeries machine:
>
> (qemu) info fdt /interrupt-controller/device_type
> /interrupt-controller/device_type = 'PowerPC-External-Interrupt-Presentation'
> (qemu)
>
> Issuing a 'info fdt /' will dump all the FDT. 'info fdt' is implemented
> in patches 4-10.
>
> Both 'fdt-save' and 'info fdt' works across machines and archs based on
> two premises: the FDT must be created using libfdt (which is the case of
> all FDTs created with device_tree.c helpers and the _FDT macro) and the
> FDT must be reachable via MachineState->fdt.
>
> To meet the prerequisites for ARM machines, patch 1 makes a change in
> arm_load_dtb(). Patches 2 and 3 makes a similar change for two PowerPC
> machines that weren't using machine->fdt.

There are some other machines that load a dtb with load_device_tree(). Do 
they need some patches too?

Regards,
BALATON Zoltan

> Tests were done using the ARM machvirt machine and ppc64 pSeries
> machine, but any machine that meets the forementioned conditions will be
> supported by these 2 new commands.
>
>
> Daniel Henrique Barboza (10):
>  hw/arm/boot.c: do not free machine->fdt in arm_load_dtb()
>  hw/ppc/pegasos2.c: set machine->fdt in machine_reset()
>  hw/ppc: set machine->fdt in spapr machine
>  hmp, device_tree.c: introduce fdt-save
>  hmp, device_tree.c: introduce 'info fdt' command
>  device_tree.c: support printing of strings props
>  device_tree.c: support remaining FDT prop types
>  device_node.c: enable 'info fdt' to print subnodes
>  device_tree.c: add fdt_print_property() helper
>  hmp, device_tree.c: add 'info fdt <property>' support
>
> hmp-commands-info.hx         |  13 +++
> hmp-commands.hx              |  13 +++
> hw/arm/boot.c                |   3 +-
> hw/ppc/pegasos2.c            |   3 +
> hw/ppc/spapr.c               |   3 +
> hw/ppc/spapr_hcall.c         |   3 +
> include/sysemu/device_tree.h |   3 +
> monitor/misc.c               |  25 ++++
> softmmu/device_tree.c        | 219 +++++++++++++++++++++++++++++++++++
> 9 files changed, 284 insertions(+), 1 deletion(-)
>
>