Re: [PATCH] kmsan: fix kmsan_handle_dma() to avoid false positives
From: Jason Gunthorpe
Date: Thu Oct 02 2025 - 09:59:24 EST
On Thu, Oct 02, 2025 at 02:10:24PM +0900, Shigeru Yoshida wrote:
> KMSAN reports an uninitialized value issue in dma_map_phys()[1]. This
> is a false positive caused by the way the virtual address is handled
> in kmsan_handle_dma(). Fix it by translating the physical address to
> a virtual address using phys_to_virt().
This is the same sort of thinko as was found on the alpha patch, it is
tricky!
Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
> @@ -339,13 +339,12 @@ static void kmsan_handle_dma_page(const void *addr, size_t size,
> void kmsan_handle_dma(phys_addr_t phys, size_t size,
> enum dma_data_direction dir)
> {
> - struct page *page = phys_to_page(phys);
This throws away the page_offset encoded in phys
> u64 page_offset, to_go;
> void *addr;
>
> if (PhysHighMem(phys))
> return;
> - addr = page_to_virt(page);
And this gives an addr that is now 0 page_offset, which is not right.
> + addr = phys_to_virt(phys);
Make more sense anyhow when combined with PhysHighMem() and gives the
right page_offset.
Jason