Skip to contentSkip to conversation

bind command leads to invalid state where plaform data is NULL

BUG Heinrich Schuchardt 2 participants 6 messages Jun 18, 2023 – Jun 20, 2023

lore
Share & tools
lore
#0 lore raw

Hello Simon,

from origin/next I build qemu_arm64_defconfig with CONFIG_CMD_BIND=yes.

I ran the image with:

qemu-system-aarch64 -semihosting \
    -machine virt,gic-version=max -accel $(ACCEL) -m 1G -smp cores=2 \
    -bios u-boot.bin -cpu $(CPU) -nographic -gdb tcp::1234 \
    -netdev user,id=eth0,tftp=tftp -device e1000,netdev=eth0,romfile= \
    -drive if=none,file=arm64.img,format=raw,id=mydisk \
    -drive if=pflash,format=raw,index=1,file=envstore.img \
    -device virtio-rng-pci \
    -device ich9-ahci,id=ahci -device ide-hd,drive=mydisk,bus=ahci.0

=> scsi bind
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

 root          0  [ + ]   root_driver           root_driver
 pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
 pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
 ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
 scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
 blk           0  [ + ]   scsi_blk              |           |--

ahci_scsi.id0lun0
partition 0 [ + ] blk_partition | | |--
ahci_scsi.id0lun0:1
partition 1 [ + ] blk_partition | | `--
ahci_scsi.id0lun0:15
bootdev 2 [ ] scsi_bootdev | `--
ahci_scsi.id0lun0.bootdev
=> unbind blk 0
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

 root          0  [ + ]   root_driver           root_driver
 pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
 pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
 ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
 scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
 bootdev       2  [   ]   scsi_bootdev          |           `--

ahci_scsi.id0lun0.bootdev
=> bind scsi 0 scsi_blk
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

 root          0  [ + ]   root_driver           root_driver
 pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
 pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
 ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
 scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
 bootdev       2  [   ]   scsi_bootdev          |           |--

ahci_scsi.id0lun0.bootdev
blk 0 [ ] scsi_blk | `-- scsi_blk
=> part list scsi 0
dev_get_uclass_plat: null device
"Synchronous Abort" handler, esr 0x96000004, far 0xd503201f14000072
elr: 000000000003392c lr : 0000000000033924 (reloc)
elr: 000000007ff1492c lr : 000000007ff14924
x0 : d503201f1400000a x1 : 0000000000000000
x2 : 0000000000000090 x3 : 0000000000000013
x4 : 000000007eda0419 x5 : 0000000000000020
x6 : 00000000ffffffd0 x7 : 000000007eda06b0
x8 : 0000000000000010 x9 : 0000000000000000
x10: 0000000000000006 x11: 000000000001869f
x12: 0000000000000016 x13: 0000000000000004
x14: 0000000000000000 x15: 000000007eda073c
x16: 000000007ff2547c x17: 0000000000000000
x18: 000000007eea0db0 x19: 0000000000000000
x20: 0000000000000000 x21: 0000000000000001
x22: 0000000000000000 x23: 000000007eda0740
x24: 0000000000000000 x25: 0000000000000000
x26: 0000000000000000 x27: 0000000000000000
x28: 0000000000000000 x29: 000000007eda06d0

Code: aa0303f7 94000287 aa0003f4 f9400260 (f9403418)

Resetting CPU ...

The crash occurs in blk_read(). blk_read() does not check if desc == NULL.

I would have expected "bind scsi 0 scsi_blk" to create a valid state where the platform data is set up.

Best regards

Heinrich

#1 lore raw

Hi Heinrich,

Quoted 80 lines · Heinrich Schuchardt

Hello Simon,

from origin/next I build qemu_arm64_defconfig with CONFIG_CMD_BIND=yes.

I ran the image with:

qemu-system-aarch64 -semihosting \
     -machine virt,gic-version=max -accel $(ACCEL) -m 1G -smp cores=2 \
     -bios u-boot.bin -cpu $(CPU) -nographic -gdb tcp::1234 \
     -netdev user,id=eth0,tftp=tftp -device e1000,netdev=eth0,romfile= \
     -drive if=none,file=arm64.img,format=raw,id=mydisk \
     -drive if=pflash,format=raw,index=1,file=envstore.img \
     -device virtio-rng-pci \
     -device ich9-ahci,id=ahci -device ide-hd,drive=mydisk,bus=ahci.0

=> scsi bind
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

  root          0  [ + ]   root_driver           root_driver
  pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
  pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
  ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
  scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
  blk           0  [ + ]   scsi_blk              |           |--

ahci_scsi.id0lun0
partition 0 [ + ] blk_partition | | |--
ahci_scsi.id0lun0:1
partition 1 [ + ] blk_partition | | `--
ahci_scsi.id0lun0:15
bootdev 2 [ ] scsi_bootdev | `--
ahci_scsi.id0lun0.bootdev
=> unbind blk 0
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

  root          0  [ + ]   root_driver           root_driver
  pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
  pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
  ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
  scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
  bootdev       2  [   ]   scsi_bootdev          |           `--

ahci_scsi.id0lun0.bootdev
=> bind scsi 0 scsi_blk
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

  root          0  [ + ]   root_driver           root_driver
  pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
  pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
  ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
  scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
  bootdev       2  [   ]   scsi_bootdev          |           |--

ahci_scsi.id0lun0.bootdev
blk 0 [ ] scsi_blk | `-- scsi_blk
=> part list scsi 0
dev_get_uclass_plat: null device
"Synchronous Abort" handler, esr 0x96000004, far 0xd503201f14000072
elr: 000000000003392c lr : 0000000000033924 (reloc)
elr: 000000007ff1492c lr : 000000007ff14924
x0 : d503201f1400000a x1 : 0000000000000000
x2 : 0000000000000090 x3 : 0000000000000013
x4 : 000000007eda0419 x5 : 0000000000000020
x6 : 00000000ffffffd0 x7 : 000000007eda06b0
x8 : 0000000000000010 x9 : 0000000000000000
x10: 0000000000000006 x11: 000000000001869f
x12: 0000000000000016 x13: 0000000000000004
x14: 0000000000000000 x15: 000000007eda073c
x16: 000000007ff2547c x17: 0000000000000000
x18: 000000007eea0db0 x19: 0000000000000000
x20: 0000000000000000 x21: 0000000000000001
x22: 0000000000000000 x23: 000000007eda0740
x24: 0000000000000000 x25: 0000000000000000
x26: 0000000000000000 x27: 0000000000000000
x28: 0000000000000000 x29: 000000007eda06d0

Code: aa0303f7 94000287 aa0003f4 f9400260 (f9403418)

Resetting CPU ...

Quoted 8 lines

The crash occurs in blk_read(). blk_read() does not check if desc == NULL.

I would have expected "bind scsi 0 scsi_blk" to create a valid state where the platform data is set up.

Best regards

Heinrich

I am not sure what 'scsi bind' does.

But binding a blk device needs to be done by its parent device. I suspect the 'bind' command does not know how to set up things correctly. See for example blk_create_device() which does quite a lot of setup.

What are you trying to fix / do?

Regards,
Simon

#2 lore raw
Quoted 92 lines · Simon Glass

Hi Heinrich,

Quoted 80 lines · Heinrich Schuchardt

Hello Simon,

from origin/next I build qemu_arm64_defconfig with CONFIG_CMD_BIND=yes.

I ran the image with:

qemu-system-aarch64 -semihosting \
      -machine virt,gic-version=max -accel $(ACCEL) -m 1G -smp cores=2 \
      -bios u-boot.bin -cpu $(CPU) -nographic -gdb tcp::1234 \
      -netdev user,id=eth0,tftp=tftp -device e1000,netdev=eth0,romfile= \
      -drive if=none,file=arm64.img,format=raw,id=mydisk \
      -drive if=pflash,format=raw,index=1,file=envstore.img \
      -device virtio-rng-pci \
      -device ich9-ahci,id=ahci -device ide-hd,drive=mydisk,bus=ahci.0

=> scsi bind
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

   root          0  [ + ]   root_driver           root_driver
   pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
   pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
   ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
   scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
   blk           0  [ + ]   scsi_blk              |           |--

ahci_scsi.id0lun0
partition 0 [ + ] blk_partition | | |--
ahci_scsi.id0lun0:1
partition 1 [ + ] blk_partition | | `--
ahci_scsi.id0lun0:15
bootdev 2 [ ] scsi_bootdev | `--
ahci_scsi.id0lun0.bootdev
=> unbind blk 0
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

   root          0  [ + ]   root_driver           root_driver
   pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
   pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
   ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
   scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
   bootdev       2  [   ]   scsi_bootdev          |           `--

ahci_scsi.id0lun0.bootdev
=> bind scsi 0 scsi_blk
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

   root          0  [ + ]   root_driver           root_driver
   pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
   pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
   ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
   scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
   bootdev       2  [   ]   scsi_bootdev          |           |--

ahci_scsi.id0lun0.bootdev
blk 0 [ ] scsi_blk | `-- scsi_blk
=> part list scsi 0
dev_get_uclass_plat: null device
"Synchronous Abort" handler, esr 0x96000004, far 0xd503201f14000072
elr: 000000000003392c lr : 0000000000033924 (reloc)
elr: 000000007ff1492c lr : 000000007ff14924
x0 : d503201f1400000a x1 : 0000000000000000
x2 : 0000000000000090 x3 : 0000000000000013
x4 : 000000007eda0419 x5 : 0000000000000020
x6 : 00000000ffffffd0 x7 : 000000007eda06b0
x8 : 0000000000000010 x9 : 0000000000000000
x10: 0000000000000006 x11: 000000000001869f
x12: 0000000000000016 x13: 0000000000000004
x14: 0000000000000000 x15: 000000007eda073c
x16: 000000007ff2547c x17: 0000000000000000
x18: 000000007eea0db0 x19: 0000000000000000
x20: 0000000000000000 x21: 0000000000000001
x22: 0000000000000000 x23: 000000007eda0740
x24: 0000000000000000 x25: 0000000000000000
x26: 0000000000000000 x27: 0000000000000000
x28: 0000000000000000 x29: 000000007eda06d0

Code: aa0303f7 94000287 aa0003f4 f9400260 (f9403418)

Resetting CPU ...

Quoted 8 lines

The crash occurs in blk_read(). blk_read() does not check if desc == NULL.

I would have expected "bind scsi 0 scsi_blk" to create a valid state where the platform data is set up.

Best regards

Heinrich

Quoted 8 lines

I am not sure what 'scsi bind' does.

But binding a blk device needs to be done by its parent device. I suspect the 'bind' command does not know how to set up things correctly. See for example blk_create_device() which does quite a lot of setup.

What are you trying to fix / do?

I just wanted to have an example for creating a man-page for the bind command. Unfortunately new commands were created without man-page.

I have an example for "<node path> <driver>". Do you have a better example for "bind <class> <index> <driver>"?

Best regards

Heinrich

#3 lore raw

Hi Heinrich,

Quoted 101 lines · Heinrich Schuchardt
Quoted 99 lines · Simon Glass

Hi Heinrich,

Quoted 80 lines · Heinrich Schuchardt

Hello Simon,

from origin/next I build qemu_arm64_defconfig with CONFIG_CMD_BIND=yes.

I ran the image with:

qemu-system-aarch64 -semihosting \
      -machine virt,gic-version=max -accel $(ACCEL) -m 1G -smp cores=2 \
      -bios u-boot.bin -cpu $(CPU) -nographic -gdb tcp::1234 \
      -netdev user,id=eth0,tftp=tftp -device e1000,netdev=eth0,romfile= \
      -drive if=none,file=arm64.img,format=raw,id=mydisk \
      -drive if=pflash,format=raw,index=1,file=envstore.img \
      -device virtio-rng-pci \
      -device ich9-ahci,id=ahci -device ide-hd,drive=mydisk,bus=ahci.0

=> scsi bind
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

   root          0  [ + ]   root_driver           root_driver
   pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
   pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
   ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
   scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
   blk           0  [ + ]   scsi_blk              |           |--

ahci_scsi.id0lun0
partition 0 [ + ] blk_partition | | |--
ahci_scsi.id0lun0:1
partition 1 [ + ] blk_partition | | `--
ahci_scsi.id0lun0:15
bootdev 2 [ ] scsi_bootdev | `--
ahci_scsi.id0lun0.bootdev
=> unbind blk 0
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

   root          0  [ + ]   root_driver           root_driver
   pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
   pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
   ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
   scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
   bootdev       2  [   ]   scsi_bootdev          |           `--

ahci_scsi.id0lun0.bootdev
=> bind scsi 0 scsi_blk
=> dm tree
Class Index Probed Driver Name
-----------------------------------------------------------

   root          0  [ + ]   root_driver           root_driver
   pci           0  [ + ]   pci_generic_ecam      |-- pcie@10000000
   pci_generi    0  [   ]   pci_generic_drv       |   |-- pci_0:0.0
   ahci          0  [ + ]   ahci_pci              |   `-- ahci_pci
   scsi          0  [ + ]   ahci_scsi             |       `-- ahci_scsi
   bootdev       2  [   ]   scsi_bootdev          |           |--

ahci_scsi.id0lun0.bootdev
blk 0 [ ] scsi_blk | `-- scsi_blk
=> part list scsi 0
dev_get_uclass_plat: null device
"Synchronous Abort" handler, esr 0x96000004, far 0xd503201f14000072
elr: 000000000003392c lr : 0000000000033924 (reloc)
elr: 000000007ff1492c lr : 000000007ff14924
x0 : d503201f1400000a x1 : 0000000000000000
x2 : 0000000000000090 x3 : 0000000000000013
x4 : 000000007eda0419 x5 : 0000000000000020
x6 : 00000000ffffffd0 x7 : 000000007eda06b0
x8 : 0000000000000010 x9 : 0000000000000000
x10: 0000000000000006 x11: 000000000001869f
x12: 0000000000000016 x13: 0000000000000004
x14: 0000000000000000 x15: 000000007eda073c
x16: 000000007ff2547c x17: 0000000000000000
x18: 000000007eea0db0 x19: 0000000000000000
x20: 0000000000000000 x21: 0000000000000001
x22: 0000000000000000 x23: 000000007eda0740
x24: 0000000000000000 x25: 0000000000000000
x26: 0000000000000000 x27: 0000000000000000
x28: 0000000000000000 x29: 000000007eda06d0

Code: aa0303f7 94000287 aa0003f4 f9400260 (f9403418)

Resetting CPU ...

Quoted 8 lines

The crash occurs in blk_read(). blk_read() does not check if desc == NULL.

I would have expected "bind scsi 0 scsi_blk" to create a valid state where the platform data is set up.

Best regards

Heinrich

I am not sure what 'scsi bind' does.

But binding a blk device needs to be done by its parent device. I suspect the 'bind' command does not know how to set up things correctly. See for example blk_create_device() which does quite a lot of setup.

Quoted 7 lines
Quoted 1 line

What are you trying to fix / do?

I just wanted to have an example for creating a man-page for the bind command. Unfortunately new commands were created without man-page.

I have an example for "<node path> <driver>". Do you have a better example for "bind <class> <index> <driver>"?

I suggest a simple device that needs no setup. The original commit[1] suggests using USB - does that worK?

Regards,
Simon

[1] 49c752c93a78 ("cmd: Add bind/unbind commands to bind a device to a driver from the command line")

#4 lore raw
Quoted 8 lines · Simon Glass

I suggest a simple device that needs no setup. The original commit[1] suggests using USB - does that worK?

Regards,
Simon

[1] 49c752c93a78 ("cmd: Add bind/unbind commands to bind a device to a driver from the command line")

I see devices listed after bind but I do not see any device that could be used after binding it with the bind command.

Here is another instance where using the bind command leads to a crash (on pine64-lts_defconfig).

Another question:
Is it correct that two devices have the same name?

=> dm tree
Class Index Probed Driver Name
--------------------------------------------------

 watchdog      0  [ + ]   sunxi_wdt   |   |-- watchdog@1c20ca0
 sysreset      0  [   ]   wdt_reboot  |   |   `-- watchdog@1c20ca0

=> unbind sysreset 0
=> bind watchdog 0 wdt_reboot
=> reset
resetting ...
"Synchronous Abort" handler, esr 0x96000004, far 0xea000006ea000070
elr: 000000004a044054 lr : 000000004a034c94 (reloc)
elr: 00000000bdf8d054 lr : 00000000bdf7dc94
x0 : 0000000000000000 x1 : 0000000000000000
x2 : 00000000bdf7dc6c x3 : ea000006ea000008
x4 : 00000000b9f1ec78 x5 : 00000000b9f2cbd0
x6 : 0000000000000072 x7 : 00000000b9f1ed30
x8 : 0000000000000040 x9 : fffffffffffffff0
x10: 0000000000000006 x11: 000000000001869f
x12: 00000000b9f1eec8 x13: 00000000b9f1efd0
x14: 0000000000000000 x15: 00000000b9f1e79f
x16: 00000000bdf7dc6c x17: 0000000000000000
x18: 00000000b9f28d90 x19: 0000000000000001
x20: 0000000000000001 x21: 0000000000000000
x22: 00000000b9f38680 x23: 0000000000000001
x24: 00000000bdff4f54 x25: 0000000000000000
x26: 00000000b9f2d2d0 x27: 0000000000000000
x28: 0000000000000000 x29: 00000000b9f1ecd0

Code: a8c27bfd d65f03c0 d65f03c0 f9400003 (f9403463)

The crash is in do_reset().

Best regards

Heinrich

#5 lore raw

Hi Heinrich,

Quoted 5 lines · Heinrich Schuchardt
Quoted 3 lines · Simon Glass

I suggest a simple device that needs no setup. The original commit[1] suggests using USB - does that worK?

Quoted 8 lines
Quoted 5 lines

Regards,
Simon

[1] 49c752c93a78 ("cmd: Add bind/unbind commands to bind a device to a driver from the command line")

I see devices listed after bind but I do not see any device that could be used after binding it with the bind command.

It might be worth asking the author. If there is any parent/uclass/device priv/plat then it won't be set up by this command.

Quoted 6 lines

Here is another instance where using the bind command leads to a crash (on pine64-lts_defconfig).

Another question:
Is it correct that two devices have the same name?

It shouldn't cause any problems since we don't normally reference devices by name. But it could be confusing for the user if there are two children of the same device with the same name.

Quoted 29 lines

=> dm tree
Class Index Probed Driver Name
--------------------------------------------------

  watchdog      0  [ + ]   sunxi_wdt   |   |-- watchdog@1c20ca0
  sysreset      0  [   ]   wdt_reboot  |   |   `-- watchdog@1c20ca0

=> unbind sysreset 0
=> bind watchdog 0 wdt_reboot
=> reset
resetting ...
"Synchronous Abort" handler, esr 0x96000004, far 0xea000006ea000070
elr: 000000004a044054 lr : 000000004a034c94 (reloc)
elr: 00000000bdf8d054 lr : 00000000bdf7dc94
x0 : 0000000000000000 x1 : 0000000000000000
x2 : 00000000bdf7dc6c x3 : ea000006ea000008
x4 : 00000000b9f1ec78 x5 : 00000000b9f2cbd0
x6 : 0000000000000072 x7 : 00000000b9f1ed30
x8 : 0000000000000040 x9 : fffffffffffffff0
x10: 0000000000000006 x11: 000000000001869f
x12: 00000000b9f1eec8 x13: 00000000b9f1efd0
x14: 0000000000000000 x15: 00000000b9f1e79f
x16: 00000000bdf7dc6c x17: 0000000000000000
x18: 00000000b9f28d90 x19: 0000000000000001
x20: 0000000000000001 x21: 0000000000000000
x22: 00000000b9f38680 x23: 0000000000000001
x24: 00000000bdff4f54 x25: 0000000000000000
x26: 00000000b9f2d2d0 x27: 0000000000000000
x28: 0000000000000000 x29: 00000000b9f1ecd0

Quoted 3 lines
Code: a8c27bfd d65f03c0 d65f03c0 f9400003 (f9403463)

The crash is in do_reset().

Looking at the device, it needs plat data and uses it in wdt_reboot_of_to_plat().

Regards,
Simon