linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	dave.hansen@linux.intel.com, kirill.shutemov@linux.intel.com,
	Shakeel Butt <shakeel.butt@linux.dev>,
	SeongJae Park <sj@kernel.org>,
	David Hildenbrand <david@redhat.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jens Axboe <axboe@kernel.dk>,
	Pavel Begunkov <asml.silence@gmail.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Ryan Roberts <ryan.roberts@arm.com>
Subject: Re: untagged_addr_remote() in do_madvise()
Date: Tue, 14 Jan 2025 13:13:36 -0800	[thread overview]
Message-ID: <ea7c7077-7ad1-4ee2-a80e-13b5eb291a7e@intel.com> (raw)
In-Reply-To: <a351166f-518c-4322-b26f-d0646f14ab8b@lucifer.local>

On 1/14/25 12:41, Lorenzo Stoakes wrote:
...
> However, MADV_HWPOISON, MADV_SOFT_OFFLINE seems fundamentally broken for tagged
> addresses:
> 
> #ifdef CONFIG_MEMORY_FAILURE
> 	if (behavior == MADV_HWPOISON || behavior == MADV_SOFT_OFFLINE)
> 		return madvise_inject_error(behavior, start, start + len_in);
> #endif
> 
> ^ this is invoked before untagged_addr_remote() is called (as no mmap lock is
> acquired) and so no attempt at untagging happens at all...!

Except this call path:

	madvise_inject_error() ->
	get_user_pages_fast() ->
	gup_fast_fallback()

does its own untagging:

        start = untagged_addr(start) & PAGE_MASK;

It might also have some funky behavior if start+len_in overflows. But,
just as in the other case, it's invalid to begin with so I think
userspace kinda gets to keep the pieces.

But I do 100% agree that this is non-obvious. In a perfect world, tagged
addresses would get untagged at the user/kernel boundary in _one_ choke
point. But the world is hard and that would make things too easy and
then we wouldn't get paid the big bucks. ;)

To clarify things, I don't think it'd be the worst thing to just move
the madvise_inject_error() down and have that case acquire
mmap_read_lock(). Sure, it's not required, but it's basically debugging
code and I can't imagine it's avoiding the lock for performance reasons.


  reply	other threads:[~2025-01-14 21:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-14 19:43 Liam R. Howlett
2025-01-14 20:15 ` Dave Hansen
2025-01-14 20:41 ` Lorenzo Stoakes
2025-01-14 21:13   ` Dave Hansen [this message]
2025-01-15 11:55     ` Lorenzo Stoakes

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=ea7c7077-7ad1-4ee2-a80e-13b5eb291a7e@intel.com \
    --to=dave.hansen@intel.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=sj@kernel.org \
    --cc=vbabka@suse.cz \
    /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