Skip to contentSkip to conversation

dynamic sysbus instantiation and load_dtb implementation

Qemu-devel Eric Auger 5 participants 11 messages Oct 23, 2014 – Nov 13, 2014

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

Dear all,

The goal of this mail is to summarize how dynamic sysbus device tree nodes were created on ARM with "machvirt dynamic sysbus device instantiation",
https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg01626.html
and request some advises after commit "hw/arm/boot: load DTB as a ROM image", which puts into question the current implementation.

When dynamically instantiating sysbus devices from qemu command line, the complete device tree cannot be built at machine init. At time we miss key information about those devices (base address, IRQ binding, ...)

dynamic sysbus devices are "realized" after the machine init when parsing "-device" option line. This is at that time the information about the device are collected.

The QEMU binding of the devices is performed in the platform_bus machine_init_done_notifier. Only at that time the base address of the device and IRQ number are chosen.

The original idea was to create the dynamic sysbus device tree nodes in a reset callback (registered through qemu_register_reset). device tree was fully re-created at that time and new sysbus device nodes were added too. Finally archi specific load_dtb was called.

On ppc/e500 this works since load_dtb uses cpu_physical_memory_write. it was the case on ARM too until recently but commit "hw/arm/boot: load DTB as a ROM image" changed the arm load_dtb implementation. It now uses rom_add_blob_fixed. when the reset callback is called rom_load_done() was called by vl.c and prevents from changing the rom content. Hence current callback mechanism does not work anymore.

A solution I foresee to fix the issue:
construct the device tree nodes in one machine_init_done_notifier, before the rom_load_done is called. I would propose the platform bus device (hw/core/platform-bus.c in [PATCH v3 0/7] Dynamic sysbus device allocation support,
http://lists.nongnu.org/archive/html/qemu-devel/2014-09/msg04833.html)
to register another machine_init_done_notifier whose role would be to initiate the dt upgrade. I would add a function to the platform bus to pass an opaque data that allows calling architecture specific dt implementation in the notifier, if needed (on ARM only).

I understand reverting to previous cpu_physical_memory_write implementation on ARM is not the good direction.

Do you have any comments about the proposed solution, any other suggestion?

Thanks in advance

Best Regards

Eric

#1 lore raw
Quoted 33 lines · Eric Auger

Dear all,

The goal of this mail is to summarize how dynamic sysbus device tree nodes were created on ARM with "machvirt dynamic sysbus device instantiation",
https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg01626.html
and request some advises after commit "hw/arm/boot: load DTB as a ROM image", which puts into question the current implementation.

When dynamically instantiating sysbus devices from qemu command line, the complete device tree cannot be built at machine init. At time we miss key information about those devices (base address, IRQ binding, ...)

dynamic sysbus devices are "realized" after the machine init when parsing "-device" option line. This is at that time the information about the device are collected.

The QEMU binding of the devices is performed in the platform_bus machine_init_done_notifier. Only at that time the base address of the device and IRQ number are chosen.

The original idea was to create the dynamic sysbus device tree nodes in a reset callback (registered through qemu_register_reset). device tree was fully re-created at that time and new sysbus device nodes were added too. Finally archi specific load_dtb was called.

On ppc/e500 this works since load_dtb uses cpu_physical_memory_write. it was the case on ARM too until recently but commit "hw/arm/boot: load DTB as a ROM image" changed the arm load_dtb implementation. It now uses rom_add_blob_fixed. when the reset callback is called rom_load_done() was called by vl.c and prevents from changing the rom content. Hence current callback mechanism does not work anymore.

Quoted 8 lines

A solution I foresee to fix the issue:
construct the device tree nodes in one machine_init_done_notifier, before the rom_load_done is called. I would propose the platform bus device (hw/core/platform-bus.c in [PATCH v3 0/7] Dynamic sysbus device allocation support,
http://lists.nongnu.org/archive/html/qemu-devel/2014-09/msg04833.html)
to register another machine_init_done_notifier whose role would be to initiate the dt upgrade.

The platform bus doesn't have any business in creating device trees. Please do this in your machine file.

Alex

Quoted 19 lines

I would add a function to the platform bus to
pass an opaque data that allows calling architecture specific dt implementation in the notifier, if needed (on ARM only).

I understand reverting to previous cpu_physical_memory_write implementation on ARM is not the good direction.

Do you have any comments about the proposed solution, any other suggestion?

Thanks in advance

Best Regards

Eric

#2 lore raw
In reply to Eric Auger
Quoted 9 lines

Dear all,

The goal of this mail is to summarize how dynamic sysbus device tree nodes were created on ARM with "machvirt dynamic sysbus device instantiation",
https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg01626.html
and request some advises after commit "hw/arm/boot: load DTB as a ROM image", which puts into question the current implementation.

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Signature · 1 line
Ard.
Quoted 50 lines

When dynamically instantiating sysbus devices from qemu command line, the complete device tree cannot be built at machine init. At time we miss key information about those devices (base address, IRQ binding, ...)

dynamic sysbus devices are "realized" after the machine init when parsing "-device" option line. This is at that time the information about the device are collected.

The QEMU binding of the devices is performed in the platform_bus machine_init_done_notifier. Only at that time the base address of the device and IRQ number are chosen.

The original idea was to create the dynamic sysbus device tree nodes in a reset callback (registered through qemu_register_reset). device tree was fully re-created at that time and new sysbus device nodes were added too. Finally archi specific load_dtb was called.

On ppc/e500 this works since load_dtb uses cpu_physical_memory_write. it was the case on ARM too until recently but commit "hw/arm/boot: load DTB as a ROM image" changed the arm load_dtb implementation. It now uses rom_add_blob_fixed. when the reset callback is called rom_load_done() was called by vl.c and prevents from changing the rom content. Hence current callback mechanism does not work anymore.

A solution I foresee to fix the issue:
construct the device tree nodes in one machine_init_done_notifier, before the rom_load_done is called. I would propose the platform bus device (hw/core/platform-bus.c in [PATCH v3 0/7] Dynamic sysbus device allocation support,
http://lists.nongnu.org/archive/html/qemu-devel/2014-09/msg04833.html)
to register another machine_init_done_notifier whose role would be to initiate the dt upgrade. I would add a function to the platform bus to pass an opaque data that allows calling architecture specific dt implementation in the notifier, if needed (on ARM only).

I understand reverting to previous cpu_physical_memory_write implementation on ARM is not the good direction.

Do you have any comments about the proposed solution, any other suggestion?

Thanks in advance

Best Regards

Eric

#3 lore raw
Quoted 10 lines · Ard Biesheuvel
Quoted 9 lines

Dear all,

The goal of this mail is to summarize how dynamic sysbus device tree nodes were created on ARM with "machvirt dynamic sysbus device instantiation",
https://lists.gnu.org/archive/html/qemu-devel/2014-09/msg01626.html
and request some advises after commit "hw/arm/boot: load DTB as a ROM image", which puts into question the current implementation.

Quoted 5 lines

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Alex

#4 lore raw
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Ard Biesheuvel

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Any particular reason? Surely it's always the same...

-- PMM

#5 lore raw
Quoted 11 lines · Peter Maydell
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Ard Biesheuvel

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Any particular reason? Surely it's always the same...

We have the code in place anyway, it's not a performance critical code path and putting it into a rom would be a waste of RAM, as it'd keep yet another copy of something we can easily regenerate.

It's a matter of personal preference I guess.

Alex

author
#6 lore raw

Hi,

Thanks everyone for entering the thread & reading my long email.

Alex, I indeed can register the notifier in the machine file after the platform bus instantiation. This indeed guarantees the notifiers are called in the right order ...

Thanks

Best Regards

Eric

Quoted 24 lines · Alexander Graf
Quoted 11 lines · Peter Maydell
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Ard Biesheuvel

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Any particular reason? Surely it's always the same...

We have the code in place anyway, it's not a performance critical code path and putting it into a rom would be a waste of RAM, as it'd keep yet another copy of something we can easily regenerate.

It's a matter of personal preference I guess.

Alex

author
#7 lore raw
Quoted 5 lines · Eric Auger

Hi,

Thanks everyone for entering the thread & reading my long email.

Alex, I indeed can register the notifier in the machine file after

s/after/before
Eric
the

Quoted 36 lines

platform bus instantiation. This indeed guarantees the notifiers are called in the right order ...

Thanks

Best Regards

Eric

Quoted 24 lines · Alexander Graf
Quoted 11 lines · Peter Maydell
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Ard Biesheuvel

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Any particular reason? Surely it's always the same...

We have the code in place anyway, it's not a performance critical code path and putting it into a rom would be a waste of RAM, as it'd keep yet another copy of something we can easily regenerate.

It's a matter of personal preference I guess.

Alex

#8 lore raw
In reply to Alexander Graf
Quoted 13 lines · Alexander Graf
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Ard Biesheuvel

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Quoted 7 lines
Quoted 1 line

Any particular reason? Surely it's always the same...

We have the code in place anyway, it's not a performance critical code path and putting it into a rom would be a waste of RAM, as it'd keep yet another copy of something we can easily regenerate.

It's a matter of personal preference I guess.

The "pseries" machine actually uses an odd hybrid. We create a "template" device tree with the common portions during early init. That's stored permanently, but is not guest visible.

At reset time we augment the template with information which could very from one boot to another, then copy it into RAM for the SLOF firmware to read.

It's not particularly efficient, but really, who cares. It's once per resent, and we're generally talking at most a few dozen kiB of device tree.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#9 lore raw
Quoted 26 lines · David Gibson
Quoted 13 lines · Alexander Graf
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Ard Biesheuvel

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Quoted 7 lines
Quoted 1 line

Any particular reason? Surely it's always the same...

We have the code in place anyway, it's not a performance critical code path and putting it into a rom would be a waste of RAM, as it'd keep yet another copy of something we can easily regenerate.

It's a matter of personal preference I guess.

The "pseries" machine actually uses an odd hybrid. We create a "template" device tree with the common portions during early init. That's stored permanently, but is not guest visible.

Quoted 7 lines

At reset time we augment the template with information which could very from one boot to another, then copy it into RAM for the SLOF firmware to read.

It's not particularly efficient, but really, who cares. It's once per resent, and we're generally talking at most a few dozen kiB of device tree.

Oh, also, because we potentially have hotplug of VIO devices, it's *not* necessarily the same every time.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#10 lore raw
Quoted 31 lines · David Gibson
Quoted 30 lines · David Gibson
Quoted 13 lines · Alexander Graf
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Alexander Graf
Quoted 5 lines · Ard Biesheuvel

The reason for this change was that, before, the DTB would only be generated once, and after a reset, the machine would go through the kernel boot protocol as before but the DTB pointer would point to garbage. Any idea how ppc deals with this? Do they recreate the device tree after each reset?

Yes, we regenerate the device tree on each reset.

Quoted 7 lines
Quoted 1 line

Any particular reason? Surely it's always the same...

We have the code in place anyway, it's not a performance critical code path and putting it into a rom would be a waste of RAM, as it'd keep yet another copy of something we can easily regenerate.

It's a matter of personal preference I guess.

The "pseries" machine actually uses an odd hybrid. We create a "template" device tree with the common portions during early init. That's stored permanently, but is not guest visible.

At reset time we augment the template with information which could very from one boot to another, then copy it into RAM for the SLOF firmware to read.

Quoted 7 lines
Quoted 3 lines

It's not particularly efficient, but really, who cares. It's once per resent, and we're generally talking at most a few dozen kiB of device tree.

Oh, also, because we potentially have hotplug of VIO devices, it's *not* necessarily the same every time.

Thanks for your inputs. I eventually proposed an implementation based on machine init done notifier, still using rom_add_blob_fixed.

http://lists.nongnu.org/archive/html/qemu-devel/2014-10/msg03812.html

By the way, besides Alex, did anyone have time to review modifs in hw/arm/boot.c and overall process to enhance the original device tree? Are those modifications acceptable?

Thank you in advance

Best Regards

Eric