public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Red Hat)" <david@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: David Wang <00107082@163.com>,
	catalin.marinas@arm.com, lance.yang@linux.dev, b-padhi@ti.com,
	akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	Jan Polensky <japo@linux.ibm.com>
Subject: Re: Linux 6.18-rc6
Date: Tue, 18 Nov 2025 08:28:11 +0100	[thread overview]
Message-ID: <ca1ca90a-7349-49e1-86d1-5db64e3e187e@kernel.org> (raw)
In-Reply-To: <CAHk-=wjBszCmj5A3cQ4PBB=x9BR58hyoQqfVNef48v3N=4Z3mQ@mail.gmail.com>

On 18.11.25 02:10, Linus Torvalds wrote:
> On Mon, 17 Nov 2025 at 11:17, David Hildenbrand (Red Hat)
> <david@kernel.org> wrote:
>>
>> So, I briefly tried on x86 with KASAN and the one-liner. I was assuming
>> that KASAN would complain because we are clearing the page before doing
>> the kasan_unpoison_pages() (IOW, writing to a KASAN-poisoned page).
>>
>> It didn't trigger, and I assume it is because clear_highpage() on x86
>> will not be instrumented by KASAN (my theory).
>>
>> The comment in kernel_init_pages() indicates that s390x uses memset()
>> for that purpose and I would assume that that one would be instrumented.
> 
> So I have thought about this some more, and I am not entirely happy
> about any of this, but I think the way forward is to
> 
>   (a) make tag_clear_highpage() just do multiple pages in one go (and
> rename it as tag_clear_highpage*s*() in the process)

That sounds reasonable given that the only caller we have wants to iterate.

> 
>   (b) make it have an actually return value to indicate whether it
> initialized things

Works for me.

> 
> which means that the post_alloc_hook() code just becomes
> 
>          if (zero_tags)
>                  init = tag_clear_highpages(page, 1 << order);
> 
> and then the generic fallback becomes just
> 
>    static inline bool tag_clear_highpages(struct page *page, int numpages)
>    {
>           return false;
>    }
> 
> which makes this all a complete no-op for architectures that don't do
> this memory tagging.
> 
> And the one architecture that *does* do it - arm64 - actually
> simplifies too, because now instead of being called in a loop - and
> having that
> 
>          if (!system_supports_mte()) {
>                   clear_highpage(page);
>                   return;
>          }
> 
> in every iteration of the loop, it now just gets called *once*, and it
> instead just does
> 
>          if (!system_supports_mte())
>                  return false;
> 
> and then it does the *clearing* in a loop instead.

Ack.

> 
> End result: that all looks much saner to me, and should avoid all the
> issues with KASAN (well, arm64 currently clearly depends on
> mte_zero_clear_page_tags() being assembly code that doesn't trigger
> KASAN anyway).
> 
> But maybe it looks saner to me just because I've written that code now.

:)

It should optimize out on !arm64 and optimize arm64 as well (less 
function calls for higher-order pages), so that's clearly better.

> 
> Anyway, here's my suggested patch. I still prefer this over having
> more config variables and #ifdef's. I'd much rather have code that
> just does the right thing and becomes null and void when it's
> effecitlvely disabled by not having hardware support.
> 
> Comments?

Works for me and saves me from continuing my fight with KASAN on s390x I 
started yesterday evening to find out if the one-liner would be 
problematic with KASAN poisoning.

I very much prefer to let kernel_init_pages() handle ordinary (non-tag) 
initialization after KASAN did its unpoison magic.


Do you want to quickly send that patch with linux-mm on CC or do you 
just want to commit it? If you're busy I can quickly send it around.

In any case, feel free to add my

Reviewed-by: David Hildenbrand (Red Hat) <david@kernel.org>

> 
> This is all entirely untested, but I did build it on both x86-64 and
> arm64. So it must be perfect. Right?
> 
> Side note: I really *detest* that stupid "__HAVE_ARCH_XYZ" pattern. I
> hate it. Why do people insist on that stupid pattern? We *have* a name
> already: the name of the thing that the architecture implements. Don't
> make up a new one with all caps and a __HAVE_ARCH_ prefix. If an
> architecture implements the feature "xyz", it should just do "define
> xyz xyz" and be done with it, and then code can test whether it is
> implemented by just doing "#ifdef xyz".
> 
> But I did *not* change that stupid existing pattern. I left it alone,
> and just added the 'S' since now it's multiple pages.  But I really do
> want to bring this up again, because it's so silly to make up new
> names to say "I defined that other name". Just *use* the name.

I stumbled over that just recently myself, and it's just done extremely 
inconsistently even within MM.

Maybe this one is worth spelling out in the coding style, as I was 
recently also unsure what the best practice is in the end. Let me see if 
I can find time for that.

> 
> If you implement "xyz" as a macro, you're done. And if it's
> implemented as an inline function, just add the "#define xyz xyz" to
> show that you did it.

I general, I agree if it's about real "features" that consist of a 
single function. I think it's a different story once a feature actually 
consists of multiple functions that can be cleanly abstracted in a 
config option.


-- 
Cheers

David

  parent reply	other threads:[~2025-11-18  7:28 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-16 22:42 Linux 6.18-rc6 Linus Torvalds
2025-11-17  8:20 ` David Wang
2025-11-17 10:33   ` Linus Torvalds
2025-11-17 12:56     ` David Wang
2025-11-17 13:30       ` David Hildenbrand (Red Hat)
2025-11-17 13:45         ` David Wang
2025-11-17 14:08           ` David Hildenbrand (Red Hat)
2025-11-17 15:28             ` David Wang
2025-11-17 16:59             ` Xi Ruoyao
2025-11-17 21:19               ` Joan Bruguera Micó
2025-11-17 17:28             ` Linus Torvalds
2025-11-17 17:53               ` David Hildenbrand (Red Hat)
2025-11-17 17:59                 ` Linus Torvalds
2025-11-17 18:24                   ` David Hildenbrand (Red Hat)
2025-11-17 19:17                     ` David Hildenbrand (Red Hat)
2025-11-18  1:10                       ` Linus Torvalds
2025-11-18  4:13                         ` David Wang
2025-11-18 13:55                           ` David Wang
2025-11-18 14:12                             ` David Hildenbrand (Red Hat)
2025-11-18 14:33                               ` David Wang
2025-11-18 14:44                               ` Carlos Llamas
2025-11-18 14:51                                 ` David Hildenbrand (Red Hat)
2025-11-18 14:53                                   ` Carlos Llamas
2025-11-18 15:09                                   ` David Wang
2025-11-18  7:28                         ` David Hildenbrand (Red Hat) [this message]
2025-11-18 16:49                           ` Linus Torvalds
2025-11-19 15:42                             ` Catalin Marinas
2025-11-18  3:59             ` Carlos Llamas
2025-11-17 16:42       ` Linus Torvalds
2025-11-17 18:13 ` Guenter Roeck
2025-11-18 17:23 ` Stephanie Gawroriski
2025-11-18 18:01   ` Linus Torvalds
2025-11-18 20:18     ` Stephanie Gawroriski
2025-11-19  9:08       ` Heikki Krogerus
2025-11-19 14:18         ` Stephanie Gawroriski
2025-11-19 15:04         ` Stephanie Gawroriski
2025-11-24  9:50           ` Heikki Krogerus
2025-11-26 16:01             ` Stephanie Gawroriski
2025-11-27  9:53               ` Heikki Krogerus

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=ca1ca90a-7349-49e1-86d1-5db64e3e187e@kernel.org \
    --to=david@kernel.org \
    --cc=00107082@163.com \
    --cc=akpm@linux-foundation.org \
    --cc=b-padhi@ti.com \
    --cc=catalin.marinas@arm.com \
    --cc=japo@linux.ibm.com \
    --cc=lance.yang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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