linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Shigeru Yoshida <syoshida@redhat.com>
Cc: glider@google.com, elver@google.com, dvyukov@google.com,
	akpm@linux-foundation.org, leon@kernel.org,
	m.szyprowski@samsung.com, kasan-dev@googlegroups.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kmsan: fix kmsan_handle_dma() to avoid false positives
Date: Thu, 2 Oct 2025 10:59:08 -0300	[thread overview]
Message-ID: <20251002135908.GE3195829@ziepe.ca> (raw)
In-Reply-To: <20251002051024.3096061-1-syoshida@redhat.com>

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@nvidia.com>

> @@ -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


  reply	other threads:[~2025-10-02 13:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20251002051101eucas1p250c65f775d8e64053ee7e009142c89c7@eucas1p2.samsung.com>
2025-10-02  5:10 ` Shigeru Yoshida
2025-10-02 13:59   ` Jason Gunthorpe [this message]
2025-10-03  6:59   ` Marek Szyprowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251002135908.GE3195829@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=akpm@linux-foundation.org \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=syoshida@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox