lkl: pci: Fix freeing DMA allocation with CPU address#637
Conversation
lkl_dma_alloc() returns a kernel virtual address derived from the allocated page. The DMA ops free callback receives that same CPU address, but lkl_dma_free() passed it directly to __free_pages(), which expects a struct page pointer. Convert the CPU address with virt_to_page() before freeing it. Add an LKL PCI KUnit test that exercises dma_alloc_attrs() and dma_free_attrs() through stub PCI host ops, and wire it into the LKL test configuration via PCI_KUNIT. Signed-off-by: Cheng Lingfei <[email protected]>
We also enable kunit test in CI, and remove kunit.filter_glob= in CONFIG_BUILTIN_CMDLINE to avoid the kasan and pci test be filtered out. Signed-off-by: Cheng Lingfei <[email protected]>
|
thanks @clingfei ! |
Yes, I am using CONFIG_MMU=y. I wanted to see how LKL supports DMA. Then I realized that this might be a confusion between __free_pages and free_pages. |
|
|
||
| #define KASAN_CMD_LINE "kunit.filter_glob=kasan* " | ||
| #define KASAN_CMD_LINE | ||
|
|
There was a problem hiding this comment.
if we remove that kasan filter, this macro variable is always empty, no ?
we can remove it if necessary.
(I guess the original intention of this filter is to shorten the test exec time)
Cc: @rodionov
There was a problem hiding this comment.
if we remove that kasan filter, this macro variable is always empty, no ? we can remove it if necessary.
Yes, those command-line macros are always empty now. Removing them does not affect the test.
| #define LKL_MMU_TEST_CMD_LINE "kunit.filter_glob=lkl_mmu " | ||
| #define LKL_MMU_TEST_CMD_LINE | ||
| #else | ||
| #define LKL_MMU_TEST_CMD_LINE |
lkl_dma_alloc() returns a kernel virtual address derived from the allocated page. The DMA ops free callback receives that same CPU address, but lkl_dma_free() passed it directly to __free_pages(), which expects a struct page pointer.
Convert the CPU address with virt_to_page() before freeing it.
Add an LKL PCI KUnit test that exercises dma_alloc_attrs() and dma_free_attrs() through stub PCI host ops, and wire it into the LKL test configuration via PCI_KUNIT.