U-Boot interferes with initrd binary — Revert "efi: Correct smbios-table installation" ?
Subsystems (2)
Hi all,
After upgrading some rather old U-Boot/IPXE setup on two aarch64 boards (Amlogic S922X-based ODROID N2+ and RK3399-based NanoPi R4S), I noticed strange errors in the initrd phase of my Linux kernel — usually something like "Illegal instruction" coming from "udhcpc", etc.
The setup I have boots iPXE from U-Boot (either stored on SD or SPI), which then loads a Linux kernel, two initrds and a dtb from the local network, and boots Alpine Linux.
I found that the busybox binary used in my initrd had an md5sum mismatch compared to what was expected. I ruled out network problems since checksums from within iPXE were correct.
So some code, either U-Boot, iPXE, or the Linux kernel, were interfering with the busybox binary at runtime. Since a single binary is used for many commands, and the changes were not always in the same location, there was wide variety of how things could fail, and — many times — fail in way that did not prevent booting.
As a workaround, via iPXE, I added a "padding" initrd to be loaded first, containing an 8MB long zero-byte filled file named /.aaaaargh. If there were any modifications, the would hit the padding file, not the busybox binary. If there were modifications, the file would remain completely empty upon boot.
However, they weren't:
Example dumps from two runs:
# hexdump /.aaaaargh 0000000 0000 0000 0000 0000 0000 0000 0000 0000 * 0044100 ffff ffff ffff 15dc f9c8 6f16 e188 0000 0044110 00a0 52b0 a01c 6d59 0000 0000 0000 0000 0044120 0000 0000 0000 0000 0000 0000 0000 0000 0044130 0000 0000 0000 0000 0000 0000 e1a8 6097 0044140 0000 0000 0000 0000 0000 0000 0000 0000 * 0155840 0320 0040 0000 0000 0000 0000 0000 0000 0155850 0000 0000 0000 0000 0000 0000 0000 0000 * 0800000
# hexdump /.aaaaargh 0000000 0000 0000 0000 0000 0000 0000 0000 0000 * 001f800 ffff ffff ffff 15dc f9c8 6f16 e188 0000 001f810 00a0 52b0 a01c 6d59 0000 0000 0000 0000 001f820 0000 0000 0000 0000 0000 0000 0000 0000 001f830 0000 0000 0000 0000 0000 0000 e1a8 6097 001f840 0000 0000 0000 0000 0000 0000 0000 0000 * 0094f40 0320 0040 0000 0000 0000 0000 0000 0000 0094f50 0000 0000 0000 0000 0000 0000 0000 0000 * 0800000
By git-bisect'ing the codebase I found that the following U-Boot commit must have triggered the bug:
Quoted 11 lines
commit
06ef8089f876b6dabf56caba31a05c003f03c629(HEAD)Author: Simon Glass <[email protected]> Date: Sun Dec 31 08:25:55 2023 -0700efi: Correct smbios-table installation
At present this code allocates memory when writing the tables and
then unnecessarily adds another memory map when installing it.
Adjust the code to allocate the tables using the normal U-Boot
mechanism. This avoids doing an EFI memory allocation early in U-Boot, which may use memory that would be overwritten by a 'load' command, for example.
Quoted 4 lines
Signed-off-by Simon Glass <[email protected]>lib/efi_loader/efi_smbios.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
From what I gather from the code, the use of "memalign" instead of "efi_allocate_pages" could be the reason for the observed memory corruption, but I'm no expert in this codebase.
For what it's worth, the commit can cleanly be reverted from a recent U-Boot HEAD, and indeed, the system boots fine afterwards.
I also once noticed that one time the memory corruption happened after the first few calls within initrd, so maybe it's a "free" corresponding to that memalign that is triggering this bug. Or, maybe it's all good from u-boot's side but iPXE needs to do something, I don't know. I'm just the messenger here...
I wonder what can be done other than reverting this change (or using a padding initrd during boot) ?
Thanks,
Christian
Quoted 7 lines · Christian Kohlschütter
# hexdump /.aaaaargh 0000000 0000 0000 0000 0000 0000 0000 0000 0000 * 0044100 ffff ffff ffff 15dc f9c8 6f16 e188 0000 0044110 00a0 52b0 a01c 6d59 0000 0000 0000 0000 0044120 0000 0000 0000 0000 0000 0000 0000 0000 0044130 0000 0000 0000 0000 0000 0000 e1a8 6097
This looks suspiciously like a broadcast Ethernet packet from a source MAC address of dc:15:c8:f9:16:6f with an ethertype of 0x88e1. Some quick research suggests that these are HomePlug Management packets generated by a "Fritz!" home router.
Quoted 4 lines
Quoted 4 lines
commit
06ef8089f876b6dabf56caba31a05c003f03c629(HEAD)Author: Simon Glass <[email protected]> Date: Sun Dec 31 08:25:55 2023 -0700
Quoted 8 lines
Quoted 8 lines
efi: Correct smbios-table installation
At present this code allocates memory when writing the tables and
then unnecessarily adds another memory map when installing it.
Adjust the code to allocate the tables using the normal U-Boot
mechanism. This avoids doing an EFI memory allocation early in U-Boot, which may use memory that would be overwritten by a 'load' command, for example.Signed-off-by Simon Glass <[email protected]>
No idea how that could relate to the packet you're seeing being written into random memory locations, sorry. I'll leave it to one of the U-Boot developers to respond.
Thanks,
Michael
Quoted 25 lines · Michael Brown
Quoted 7 lines · Christian Kohlschütter
# hexdump /.aaaaargh 0000000 0000 0000 0000 0000 0000 0000 0000 0000 * 0044100 ffff ffff ffff 15dc f9c8 6f16 e188 0000 0044110 00a0 52b0 a01c 6d59 0000 0000 0000 0000 0044120 0000 0000 0000 0000 0000 0000 0000 0000 0044130 0000 0000 0000 0000 0000 0000 e1a8 6097This looks suspiciously like a broadcast Ethernet packet from a source MAC address of dc:15:c8:f9:16:6f with an ethertype of
0x88e1. Some quick research suggests that these are HomePlug Management packets generated by a "Fritz!" home router.Quoted 4 lines
Quoted 4 lines
commit
06ef8089f876b6dabf56caba31a05c003f03c629(HEAD)Author: Simon Glass <[email protected]> Date: Sun Dec 31 08:25:55 2023 -0700Quoted 8 lines
Quoted 8 lines
efi: Correct smbios-table installation
At present this code allocates memory when writing the tables and
then unnecessarily adds another memory map when installing it.
Adjust the code to allocate the tables using the normal U-Boot
mechanism. This avoids doing an EFI memory allocation early in U-Boot, which may use memory that would be overwritten by a 'load' command, for example.Signed-off-by Simon Glass <[email protected]>
Quoted 6 lines
No idea how that could relate to the packet you're seeing being written into random memory locations, sorry. I'll leave it to one of the U-Boot developers to respond.
Thanks,
Michael
Whoa! Good eyes, Michael!
What is my Fritzbox doing to my initrd, and why does reverting the commit fix it?
FWIW, I also have a capture with an ethernet frame from another device on my network (ARP, ethertype 0x0806), so this is probably the content of some ethernet receive buffer...
Quoted 5 lines · Christian Kohlschütter
Whoa! Good eyes, Michael!
What is my Fritzbox doing to my initrd, and why does reverting the commit fix it?
FWIW, I also have a capture with an ethernet frame from another device on my network (ARP, ethertype
0x0806), so this is probably the content of some ethernet receive buffer...
I've taken a quick look through the U-Boot codebase, and I can't immediately see where the Ethernet device gets disabled as a result of calling ExitBootServices(). It's possibly worth noting that U-Boot may have relied upon iPXE's behavior prior to commit https://github.com/ipxe/ipxe/commit/562c74e1e:
[efi] Run ExitBootServices shutdown hook at TPL_NOTIFY
... <snip lengthy explanation as to why we need to do this> ...
Avoid calling into an underlying SNP protocol instance from within our shutdown hook at TPL_NOTIFY, since the underlying SNP driver may attempt to raise the TPL to TPL_CALLBACK (which would cause a fatal error). Failing to shut down the underlying SNP device is safe to do since the underlying device must, in any case, have installed its own ExitBootServices hook if any shutdown actions are required.
So, older versions of iPXE would have called Snp->Stop(), which in U-Boot's efi_net_stop() will call eth_halt(). Current versions of iPXE will not call Snp->Stop(), and will rely on the underlying SNP driver to have dealt with its own ExitBootServices() requirements.
I can't find any evidence of U-Boot installing an EVT_SIGNAL_EXIT_BOOT_SERVICES event to call eth_halt() when ExitBootServices() is called.
The closest I can find is a block of code in U-Boot's efi_exit_boot_services():
bootm_disable_interrupts();
if (IS_ENABLED(CONFIG_USB_DEVICE))
udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to eth_halt().
Is it possible that U-Boot is failing to call eth_halt() in response to ExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?
Michael
Hi Michael,
Quoted 34 lines · Michael Brown
Quoted 5 lines · Christian Kohlschütter
Whoa! Good eyes, Michael!
What is my Fritzbox doing to my initrd, and why does reverting the commit fix it?
FWIW, I also have a capture with an ethernet frame from another device on my network (ARP, ethertype
0x0806), so this is probably the content of some ethernet receive buffer...I've taken a quick look through the U-Boot codebase, and I can't immediately see where the Ethernet device gets disabled as a result of calling
ExitBootServices(). It's possibly worth noting that U-Boot may have relied upon iPXE's behavior prior to commit
https://github.com/ipxe/ipxe/commit/562c74e1e:[efi] Run ExitBootServices shutdown hook at
TPL_NOTIFY... <snip lengthy explanation as to why we need to do this> ...
Avoid calling into an underlying SNP protocol instance from within our shutdown hook at
TPL_NOTIFY, since the underlying SNP driver may attempt to raise the TPL toTPL_CALLBACK(which would cause a fatal error). Failing to shut down the underlying SNP device is safe to do since the underlying device must, in any case, have installed its own ExitBootServices hook if any shutdown actions are required.So, older versions of iPXE would have called
Snp->Stop(), which in U-Boot'sefi_net_stop()will calleth_halt(). Current versions of iPXE will not callSnp->Stop(), and will rely on the underlying SNP driver to have dealt with its ownExitBootServices()requirements.I can't find any evidence of U-Boot installing an
EVT_SIGNAL_EXIT_BOOT_SERVICESevent to calleth_halt()whenExitBootServices()is called.
Quoted 8 lines
The closest I can find is a block of code in U-Boot's
efi_exit_boot_services():bootm_disable_interrupts(); if (IS_ENABLED(CONFIG_USB_DEVICE)) udc_disconnect(); board_quiesce_devices(); dm_remove_devices_active();
We have discussed combining this code with the similar code in boot/bootm.c
Quoted 7 lines
but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to
eth_halt().Is it possible that U-Boot is failing to call
eth_halt()in response toExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?
The dm_remove_devices_active() is supposed to handle this, but it is possible that one of the drivers lacks a remove() method.
Regards,
Simon
Hi Simon,
Quoted 11 lines · Simon Glass
Quoted 7 lines
but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to
eth_halt().Is it possible that U-Boot is failing to call
eth_halt()in response toExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?The
dm_remove_devices_active()is supposed to handle this, but it is possible that one of the drivers lacks aremove()method.
for what it's worth, this is happening on both ODROID N2+ (meson8b-dwmac) as well as NanoPI R4S (rk_gmac-dwmac).
I also don't understand why reverting 06ef8089f876b6dabf56caba31a05c003f03c629 "fixes" this behavior. Does it mean that any memalign / malloc may cause this? Also, how can this failure mode be detected and prevented in code?
I really don't fancy the thought of remote code injection into Linux initrd by spoofing Ethernet packages, but it really looks like a possibility.
Thanks,
Christian
+Tom Rini in case this affects the release
Hi Christian,
Quoted 15 lines · Christian Kohlschütter
Hi Simon,
Quoted 11 lines · Simon Glass
Quoted 7 lines
but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to
eth_halt().Is it possible that U-Boot is failing to call
eth_halt()in response toExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?The
dm_remove_devices_active()is supposed to handle this, but it is possible that one of the drivers lacks aremove()method.
Quoted 6 lines
for what it's worth, this is happening on both ODROID N2+ (meson8b-dwmac) as well as NanoPI R4S (rk_gmac-dwmac).
I also don't understand why reverting
06ef8089f876b6dabf56caba31a05c003f03c629"fixes" this behavior. Does it mean that any memalign / malloc may cause this? Also, how can this failure mode be detected and prevented in code?I really don't fancy the thought of remote code injection into Linux initrd by spoofing Ethernet packages, but it really looks like a possibility.
Here's my idea of what might be going on based on Michael's observations:
1. designware_eth_start() starts the interface and designware_eth_stop() stops it
2. tx_descs_init() sets up the DMA and uses the device-private info (struct dw_eth_dev)
3. When the device is removed, the struct is freed, meaning that a future malloc() can use that same space.
4. DMA traffic could then write over the malloc() region
I'm not seeing where the Ethernet device's stop() is called. The dwmac_meson8b driver does not have a remove() method, so presumably DMA is still running after the device is removed. Probably the correct fix would be to add a remove() method to that driver.
Regards,
Simon
+Tom Rini (actually adding Tom to the conversation)
Quoted 32 lines · Simon Glass
+Tom Rini in case this affects the release
Hi Christian,
Quoted 15 lines · Christian Kohlschütter
Hi Simon,
Quoted 11 lines · Simon Glass
Quoted 7 lines
but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to
eth_halt().Is it possible that U-Boot is failing to call
eth_halt()in response toExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?The
dm_remove_devices_active()is supposed to handle this, but it is possible that one of the drivers lacks aremove()method.Quoted 6 lines
for what it's worth, this is happening on both ODROID N2+ (meson8b-dwmac) as well as NanoPI R4S (rk_gmac-dwmac).
I also don't understand why reverting
06ef8089f876b6dabf56caba31a05c003f03c629"fixes" this behavior. Does it mean that any memalign / malloc may cause this? Also, how can this failure mode be detected and prevented in code?I really don't fancy the thought of remote code injection into Linux initrd by spoofing Ethernet packages, but it really looks like a possibility.
Here's my idea of what might be going on based on Michael's observations:
Quoted 8 lines
1.
designware_eth_start()starts the interface anddesignware_eth_stop()stops it2.
tx_descs_init()sets up the DMA and uses the device-private info (structdw_eth_dev)3. When the device is removed, the struct is freed, meaning that a future
malloc()can use that same space.
Yes, that sounds plausible. How can such allocations be prevented?
I assume U-Boot's malloc does not know anything about iPXE's or Linux's allocation, and vice versa?
Quoted 7 lines
4. DMA traffic could then write over the
malloc()regionI'm not seeing where the Ethernet device's
stop()is called. Thedwmac_meson8bdriver does not have aremove()method, so presumably DMA is still running after the device is removed. Probably the correct fix would be to add aremove()method to that driver.
Right. Of course this means that there's still a chance that some future driver would again fail to do this. How can we prevent this? Can some removal hook be added automatically upon registration?
Quoted 3 lines
Regards,
Simon
Thanks for looking into this!
Christian
Quoted 7 lines · Christian Kohlschütter
+Tom Rini (actually adding Tom to the conversation)
Quoted 2 lines
3. When the device is removed, the struct is freed, meaning that a future
malloc()can use that same space.Yes, that sounds plausible. How can such allocations be prevented?
I assume U-Boot's malloc does not know anything about iPXE's or Linux's allocation, and vice versa?
iPXE communicates about memory allocation with U-Boot via the EFI memory allocation API (AllocatePool()/FreePool() and AllocatePages()/FreePages()). So U-Boot has all the information it needs to avoid clashing with iPXE, but I have no idea if U-Boot's malloc() uses the same memory map as U-Boot's implementation of AllocatePool() et al.
Quoted 9 lines
Quoted 6 lines
4. DMA traffic could then write over the
malloc()regionI'm not seeing where the Ethernet device's
stop()is called. Thedwmac_meson8bdriver does not have aremove()method, so presumably DMA is still running after the device is removed. Probably the correct fix would be to add aremove()method to that driver.Right. Of course this means that there's still a chance that some future driver would again fail to do this. How can we prevent this? Can some removal hook be added automatically upon registration?
If the dwmac_meson8b driver leaves the hardware in a state where "DMA is still running after the device is removed", then that is unambiguously a bug that needs to be fixed.
iPXE's internal (and unrelated) network device API avoids this class of problem by having the network device removal path automatically ensure that the network interface is closed:
There's no hard guarantee that a closed device is quiescent for DMA, but it happens to be true for most drivers that I've written over the years.
Thanks,
Michael
Hi Christian,
Quoted 38 lines · Christian Kohlschütter
+Tom Rini (actually adding Tom to the conversation)
Quoted 35 lines · Simon Glass
+Tom Rini in case this affects the release
Hi Christian,
Quoted 15 lines · Christian Kohlschütter
Hi Simon,
Quoted 11 lines · Simon Glass
Quoted 7 lines
but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to
eth_halt().Is it possible that U-Boot is failing to call
eth_halt()in response toExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?The
dm_remove_devices_active()is supposed to handle this, but it is possible that one of the drivers lacks aremove()method.Quoted 6 lines
for what it's worth, this is happening on both ODROID N2+ (meson8b-dwmac) as well as NanoPI R4S (rk_gmac-dwmac).
I also don't understand why reverting
06ef8089f876b6dabf56caba31a05c003f03c629"fixes" this behavior. Does it mean that any memalign / malloc may cause this? Also, how can this failure mode be detected and prevented in code?I really don't fancy the thought of remote code injection into Linux initrd by spoofing Ethernet packages, but it really looks like a possibility.
Here's my idea of what might be going on based on Michael's observations:
1.
designware_eth_start()starts the interface anddesignware_eth_stop()stops it
Quoted 7 lines
Quoted 5 lines
2.
tx_descs_init()sets up the DMA and uses the device-private info (structdw_eth_dev)3. When the device is removed, the struct is freed, meaning that a future
malloc()can use that same space.Yes, that sounds plausible. How can such allocations be prevented?
There is no need to prevent allocations. It is in the nature of malloc() that any memory you free can then be used by a subsequent malloc(). The bug here is that DMA needs to be disabled when the device is removed.
Quoted 6 lines
I assume U-Boot's malloc does not know anything about iPXE's or Linux's allocation, and vice versa?
Quoted 3 lines
4. DMA traffic could then write over the
malloc()region
Quoted 7 lines
Quoted 4 lines
I'm not seeing where the Ethernet device's
stop()is called. Thedwmac_meson8bdriver does not have aremove()method, so presumably DMA is still running after the device is removed. Probably the correct fix would be to add aremove()method to that driver.Right. Of course this means that there's still a chance that some future driver would again fail to do this. How can we prevent this? Can some removal hook be added automatically upon registration?
Visual inspection of each network driver should help.
I'm not sure if we want to 'stop' all the network devices before booting Linux, but perhaps we could perhaps provide that feature as a Kconfig option, e.g. in announce_and_cleanup(), which could really use a cleanup to make it common across archs.
Quoted 6 lines
Quoted 4 lines
Regards,
SimonThanks for looking into this!
Thanks for the report!
Quoted 2 lines
Christian
Regards,
Simon
Quoted 14 lines · Simon Glass
Quoted 11 lines · Christian Kohlschütter
Quoted 8 lines · Simon Glass
4. DMA traffic could then write over the
malloc()regionI'm not seeing where the Ethernet device's
stop()is called. Thedwmac_meson8bdriver does not have aremove()method, so presumably DMA is still running after the device is removed. Probably the correct fix would be to add aremove()method to that driver.Right. Of course this means that there's still a chance that some future driver would again fail to do this. How can we prevent this? Can some removal hook be added automatically upon registration?
Quoted 6 lines
Visual inspection of each network driver should help.
I'm not sure if we want to 'stop' all the network devices before booting Linux, but perhaps we could perhaps provide that feature as a
Kconfigoption, e.g. inannounce_and_cleanup(), which could really use a cleanup to make it common across archs.
If the memory used for network device DMA is not reserved to prevent use by the operating system, then you absolutely need to stop all network devices. Otherwise, what is there that prevents random parts of the OS kernel or data from being overwritten by received packets?
In the UEFI model, the point at which ExitBootServices() returns successfully is the point that any memory marked as EfiBootServicesCode or EfiBootServicesData becomes usable as general-purpose RAM by the OS. The firmware (including any DMA-capable devices configured by the firmware) is not permitted to continue to write to this memory after this point.
Thanks,
Michael
[email protected]
maintainerHi Christian
Quoted 69 lines · Simon Glass
Hi Christian,
Quoted 38 lines · Christian Kohlschütter
+Tom Rini (actually adding Tom to the conversation)
Quoted 35 lines · Simon Glass
+Tom Rini in case this affects the release
Hi Christian,
Quoted 15 lines · Christian Kohlschütter
Hi Simon,
Quoted 11 lines · Simon Glass
Quoted 7 lines
but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to
eth_halt().Is it possible that U-Boot is failing to call
eth_halt()in response toExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?The
dm_remove_devices_active()is supposed to handle this, but it is possible that one of the drivers lacks aremove()method.Quoted 6 lines
for what it's worth, this is happening on both ODROID N2+ (meson8b-dwmac) as well as NanoPI R4S (rk_gmac-dwmac).
I also don't understand why reverting
06ef8089f876b6dabf56caba31a05c003f03c629"fixes" this behavior. Does it mean that any memalign / malloc may cause this? Also, how can this failure mode be detected and prevented in code?I really don't fancy the thought of remote code injection into Linux initrd by spoofing Ethernet packages, but it really looks like a possibility.
Here's my idea of what might be going on based on Michael's observations:
1.
designware_eth_start()starts the interface anddesignware_eth_stop()stops itQuoted 7 lines
Quoted 5 lines
2.
tx_descs_init()sets up the DMA and uses the device-private info (structdw_eth_dev)3. When the device is removed, the struct is freed, meaning that a future
malloc()can use that same space.Yes, that sounds plausible. How can such allocations be prevented?
There is no need to prevent allocations. It is in the nature of
malloc()that any memory you free can then be used by a subsequentmalloc(). The bug here is that DMA needs to be disabled when the device is removed.Quoted 6 lines
I assume U-Boot's malloc does not know anything about iPXE's or Linux's allocation, and vice versa?
Quoted 3 lines
4. DMA traffic could then write over the
malloc()regionQuoted 7 lines
Quoted 4 lines
I'm not seeing where the Ethernet device's
stop()is called. Thedwmac_meson8bdriver does not have aremove()method, so presumably DMA is still running after the device is removed. Probably the correct fix would be to add aremove()method to that driver.Right. Of course this means that there's still a chance that some future driver would again fail to do this. How can we prevent this? Can some removal hook be added automatically upon registration?
Quoted 6 lines
Visual inspection of each network driver should help.
I'm not sure if we want to 'stop' all the network devices before booting Linux, but perhaps we could perhaps provide that feature as a
Kconfigoption, e.g. inannounce_and_cleanup(), which could really use a cleanup to make it common across archs.
could you test:
==========><==========================
drivers/net/dwmac_meson8b.c +10 -0
@@ -145,6 +145,15 @@ static int dwmac_meson8b_probe(struct udevice *dev)return designware_eth_probe (dev); } +static int dwmac_meson8b_remove (struct udevice *dev) +{ +struct dwmac_meson8b_plat *pdata =dev_get_plat (dev); + +designware_eth_stop (dev); + +return designware_eth_remove (dev); +} +static const struct udevice_id dwmac_meson8b_ids[] = { { .compatible ="amlogic,meson-gxbb-dwmac" , .data = (ulong )dwmac_setup_gx }, { .compatible ="amlogic,meson-g12a-dwmac" , .data = (ulong )dwmac_setup_axg },
@@ -158,6 +167,7 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .of_match = dwmac_meson8b_ids, .of_to_plat = dwmac_meson8b_of_to_plat, .probe = dwmac_meson8b_probe, + .remove = dwmac_meson8b_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat),
==========><==========================
Thanks,
Neil
Quoted 15 lines
Quoted 7 lines
Quoted 5 lines
Regards,
SimonThanks for looking into this!
Thanks for the report!
Quoted 2 lines
Christian
Regards,
Simon
Quoted 3 lines · On 4. Apr 2025, at 18:21, [email protected] wrote:
Hi Christian
...
Quoted 34 lines
could you test:
==========><==========================
drivers/net/dwmac_meson8b.c +10
-0@@ -145,6 +145,15 @@ static int dwmac_meson8b_probe(struct udevice *dev)return designware_eth_probe (dev); } +static int dwmac_meson8b_remove (struct udevice *dev) +{ +struct dwmac_meson8b_plat *pdata =dev_get_plat (dev); + +designware_eth_stop (dev); + +return designware_eth_remove (dev); +} +static const struct udevice_id dwmac_meson8b_ids[] = { { .compatible ="amlogic,meson-gxbb-dwmac" , .data = (ulong )dwmac_setup_gx }, { .compatible ="amlogic,meson-g12a-dwmac" , .data = (ulong )dwmac_setup_axg },@@ -158,6 +167,7 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .of_match = dwmac_meson8b_ids, .of_to_plat = dwmac_meson8b_of_to_plat, .probe = dwmac_meson8b_probe, + .remove = dwmac_meson8b_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat),==========><==========================
Quoted 2 lines
Thanks,
Neil
Hi Neil,
I had to make some changes to make it compile (expose "designware_eth_remove" in designware.c, it was "static"). Unfortunately, it did not make a difference (I still see ethernet activity impacting initrd).
Is there something missing for "struct dwmac_meson8b_plat *pdata = dev_get_plat(dev);" (result is currently unused)?
In the meantime, I've tried the patch from here
https://lore.kernel.org/all/[email protected]/
and it indeed fixes the problem I'm seeing.
The additional benefit is that it doesn't just apply to meson8b dwmac.
Is there perhaps an additional aspect that your fix would address?
Cheers,
Christian
Hi,
Quoted 50 lines · Christian Kohlschütter
Quoted 3 lines · On 4. Apr 2025, at 18:21, [email protected] wrote:
Hi Christian
...
Quoted 34 lines
could you test:
==========><==========================
drivers/net/dwmac_meson8b.c +10
-0@@ -145,6 +145,15 @@ static int dwmac_meson8b_probe(struct udevice *dev)return designware_eth_probe (dev); } +static int dwmac_meson8b_remove (struct udevice *dev) +{ +struct dwmac_meson8b_plat *pdata =dev_get_plat (dev); + +designware_eth_stop (dev); + +return designware_eth_remove (dev); +} +static const struct udevice_id dwmac_meson8b_ids[] = { { .compatible ="amlogic,meson-gxbb-dwmac" , .data = (ulong )dwmac_setup_gx }, { .compatible ="amlogic,meson-g12a-dwmac" , .data = (ulong )dwmac_setup_axg },@@ -158,6 +167,7 @@ U_BOOT_DRIVER(dwmac_meson8b) = { .of_match = dwmac_meson8b_ids, .of_to_plat = dwmac_meson8b_of_to_plat, .probe = dwmac_meson8b_probe, + .remove = dwmac_meson8b_remove, .ops = &designware_eth_ops, .priv_auto = sizeof(struct dw_eth_dev), .plat_auto = sizeof(struct dwmac_meson8b_plat),==========><==========================
Quoted 2 lines
Thanks,
NeilHi Neil,
I had to make some changes to make it compile (expose "
designware_eth_remove" indesignware.c, it was "static"). Unfortunately, it did not make a difference (I still see ethernet activity impacting initrd).Is there something missing for "struct
dwmac_meson8b_plat*pdata =dev_get_plat(dev);" (result is currently unused)?
Quoted 7 lines
In the meantime, I've tried the patch from here
https://lore.kernel.org/all/[email protected]/
and it indeed fixes the problem I'm seeing.The additional benefit is that it doesn't just apply to meson8b dwmac.
Is there perhaps an additional aspect that your fix would address?
I'll send a few patches for this.
Regards,
Simon
Quoted 5 lines · Christian Kohlschütter
Whoa! Good eyes, Michael!
What is my Fritzbox doing to my initrd, and why does reverting the commit fix it?
FWIW, I also have a capture with an ethernet frame from another device on my network (ARP, ethertype
0x0806), so this is probably the content of some ethernet receive buffer...
I've taken a quick look through the U-Boot codebase, and I can't immediately see where the Ethernet device gets disabled as a result of calling ExitBootServices(). It's possibly worth noting that U-Boot may have relied upon iPXE's behavior prior to commit https://github.com/ipxe/ipxe/commit/562c74e1e:
[efi] Run ExitBootServices shutdown hook at TPL_NOTIFY
... <snip lengthy explanation as to why we need to do this> ...
Avoid calling into an underlying SNP protocol instance from within our shutdown hook at TPL_NOTIFY, since the underlying SNP driver may attempt to raise the TPL to TPL_CALLBACK (which would cause a fatal error). Failing to shut down the underlying SNP device is safe to do since the underlying device must, in any case, have installed its own ExitBootServices hook if any shutdown actions are required.
So, older versions of iPXE would have called Snp->Stop(), which in U-Boot's efi_net_stop() will call eth_halt(). Current versions of iPXE will not call Snp->Stop(), and will rely on the underlying SNP driver to have dealt with its own ExitBootServices() requirements.
I can't find any evidence of U-Boot installing an EVT_SIGNAL_EXIT_BOOT_SERVICES event to call eth_halt() when ExitBootServices() is called.
The closest I can find is a block of code in U-Boot's efi_exit_boot_services():
bootm_disable_interrupts();
if (IS_ENABLED(CONFIG_USB_DEVICE))
udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();but I don't know precisely what these various functions are supposed to do, and I can't find any path that leads from any of these to eth_halt().
Is it possible that U-Boot is failing to call eth_halt() in response to ExitBootServices(), and is therefore leaving the network device active and performing DMA while the kernel starts up?
Michael
[email protected]
maintainerHi,
Quoted 5 lines · Christian Kohlschütter
Hi all,
After upgrading some rather old U-Boot/IPXE setup on two aarch64 boards (Amlogic S922X-based ODROID N2+ and RK3399-based NanoPi R4S), I noticed strange errors in the initrd phase of my Linux kernel — usually something like "Illegal instruction" coming from "udhcpc", etc.
The setup I have boots iPXE from U-Boot (either stored on SD or SPI), which then loads a Linux kernel, two initrds and a dtb from the local network, and boots Alpine Linux.
Could you help me reproduce this setup ?
As I understood you chainload ipxe.efi in U-Boot, then you boo your own distro from local network.
If you can give me your instructions I can try to reproduce and fix the meson ethernet driver.
Thanks
Neil
Quoted 68 lines
I found that the busybox binary used in my initrd had an md5sum mismatch compared to what was expected. I ruled out network problems since checksums from within iPXE were correct.
So some code, either U-Boot, iPXE, or the Linux kernel, were interfering with the busybox binary at runtime. Since a single binary is used for many commands, and the changes were not always in the same location, there was wide variety of how things could fail, and — many times — fail in way that did not prevent booting.As a workaround, via iPXE, I added a "padding" initrd to be loaded first, containing an 8MB long zero-byte filled file named /.aaaaargh. If there were any modifications, the would hit the padding file, not the busybox binary. If there were modifications, the file would remain completely empty upon boot.
However, they weren't:
Example dumps from two runs:# hexdump /.aaaaargh 0000000 0000 0000 0000 0000 0000 0000 0000 0000 * 0044100 ffff ffff ffff 15dc f9c8 6f16 e188 0000 0044110 00a0 52b0 a01c 6d59 0000 0000 0000 0000 0044120 0000 0000 0000 0000 0000 0000 0000 0000 0044130 0000 0000 0000 0000 0000 0000 e1a8 6097 0044140 0000 0000 0000 0000 0000 0000 0000 0000 * 0155840 0320 0040 0000 0000 0000 0000 0000 0000 0155850 0000 0000 0000 0000 0000 0000 0000 0000 * 0800000# hexdump /.aaaaargh 0000000 0000 0000 0000 0000 0000 0000 0000 0000 * 001f800 ffff ffff ffff 15dc f9c8 6f16 e188 0000 001f810 00a0 52b0 a01c 6d59 0000 0000 0000 0000 001f820 0000 0000 0000 0000 0000 0000 0000 0000 001f830 0000 0000 0000 0000 0000 0000 e1a8 6097 001f840 0000 0000 0000 0000 0000 0000 0000 0000 * 0094f40 0320 0040 0000 0000 0000 0000 0000 0000 0094f50 0000 0000 0000 0000 0000 0000 0000 0000 * 0800000By git-bisect'ing the codebase I found that the following U-Boot commit must have triggered the bug:
Quoted 11 lines
commit
06ef8089f876b6dabf56caba31a05c003f03c629(HEAD)Author: Simon Glass <[email protected]> Date: Sun Dec 31 08:25:55 2023 -0700efi: Correct smbios-table installation
At present this code allocates memory when writing the tables and
then unnecessarily adds another memory map when installing it.
Adjust the code to allocate the tables using the normal U-Boot
mechanism. This avoids doing an EFI memory allocation early in U-Boot, which may use memory that would be overwritten by a 'load' command, for example.Quoted 4 lines
Signed-off-by Simon Glass <[email protected]>lib/efi_loader/efi_smbios.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)From what I gather from the code, the use of "memalign" instead of "
efi_allocate_pages" could be the reason for the observed memory corruption, but I'm no expert in this codebase.For what it's worth, the commit can cleanly be reverted from a recent U-Boot HEAD, and indeed, the system boots fine afterwards.
I also once noticed that one time the memory corruption happened after the first few calls within initrd, so maybe it's a "free" corresponding to that memalign that is triggering this bug. Or, maybe it's all good from u-boot's side but iPXE needs to do something, I don't know. I'm just the messenger here...
I wonder what can be done other than reverting this change (or using a padding initrd during boot) ?
Thanks,
Christian