[PATCH 0/3] firewire: core: add KUnit tests for tree building
Takashi Sakamoto <[email protected]>
| Newsgroups | gmane.linux.kernel,gmane.linux.kernel.firewire.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, The core function builds internal node tree by parsing self ID sequence at bus reset. Abdun Nihaal points to a memory leak in this process at encountering a failure in the middle of self ID sequence enumeration[1]. This issue is not yet solved, and some unit tests make it easier to work for it, mainly to avoid some regressions when refactoring codes. This patchset adds some KUnit tests for the purpose. Especially, the tests added at the last patch includes actual cases to hit the memory leak. In my development environment (Ubuntu 26.04, amd64), I can see the memory leak by enabling and redirecting some tracepoints events to kmsg on the qemu process for KUnit tests execution: ``` $ python3 tools/testing/kunit/kunit.py run \ --arch=x86_64 \ --cross_compile=x86_64-linux-gnu- \ --kunitconfig=drivers/firewire/ \ --kconfig_add=CONFIG_FTRACE=y \ --kernel_args=tp_printk=1 \ --kernel_args=trace_event=kmem:kmalloc,kmem:kfree \ --kernel_args=hash_pointers=never \ --raw_output=all ``` In the KUnit tests for successful cases, the allocated memory objects are released successfully in the test side, like: ``` kmalloc: call_site=build_tree+0x203/0x5d0 ptr=ffff8e10413f0b80 bytes_req=48 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO node=-1 accounted=false kmalloc: call_site=build_tree+0x203/0x5d0 ptr=ffff8e10413f0b40 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO node=-1 accounted=false kfree: call_site=for_each_fw_node+0x17c/0x230 ptr=ffff8e10413f0b40 kfree: call_site=for_each_fw_node+0x17c/0x230 ptr=ffff8e10413f0b80 ``` For the issued cases, we can see no kfree events corresponding to the allocated memory objects, like: ``` kmalloc: call_site=build_tree+0x203/0x5d0 ptr=ffff8e10413f0940 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO node=-1 accounted=false kmalloc: call_site=build_tree+0x203/0x5d0 ptr=ffff8e10413f0900 bytes_req=48 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO node=-1 accounted=false kmalloc: call_site=build_tree+0x203/0x5d0 ptr=ffff8e10413f08c0 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO node=-1 accounted=false kmalloc: call_site=build_tree+0x203/0x5d0 ptr=ffff8e10413f0880 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_ATOMIC|__GFP_ZERO node=-1 accounted=false firewire_core node_tree_test_invalid_parent_port_count.dummy-device: parent port inconsistency for node 3: parent_count=2 ... ``` The memory objects remain in the build_tree() function and should be released internally. This is the addressing issue. [1] https://lore.kernel.org/lkml/[email protected]/ Takashi Sakamoto (3): firewire: core: add KUnit test skeleton for node tree firewire: core: add KUnit tests for successful tree building firewire: core: add KUnit tests for failure of tree building drivers/firewire/.kunitconfig | 1 + drivers/firewire/Kconfig | 15 + drivers/firewire/core-topology.c | 4 + drivers/firewire/node-tree-test.c | 611 ++++++++++++++++++++++++++++++ 4 files changed, 631 insertions(+) create mode 100644 drivers/firewire/node-tree-test.c base-commit: a5367912ba81dfb3180fce89b545b009e57f17a5 -- 2.53.0