From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 387F61A4F3C for ; Tue, 18 Nov 2025 07:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763450896; cv=none; b=G54I5uYQELhc/ectjdcvd7o4r4iKLsmI7zg5bdbWkIght3Mvy8di56IE/ra+CfvUWFwN4dYIIFhrBLeJs0fa+IiOU3rGjvwwRsIouHPUdlSvRMbSvf1N3I3KmDV+Xb987SW3vD2N+Vu759eSp5oNrJx69iRMtZZnmR2nGomPH48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763450896; c=relaxed/simple; bh=j9Q9Yj7QcBTDqvnX15aYA6XTHTC/wSqj6DVyLqbXgLo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=f96AikYGgGZezb+tF8Zug/wLNzSRHuuI8hxMEbpICTIdceXcADWZgD78QbTELb8WWMDlbFOwxZMrYjGoILsb3D49wvlAU9YyXGi18QlDNBSin6bWHFofzhh9KZldEB5t3qtaY+k5HQaz7nDu3W4UA5GkhkIY7q4k9IezKxJHNmc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pp5ipRS/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pp5ipRS/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6702C4CEFB; Tue, 18 Nov 2025 07:28:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763450895; bh=j9Q9Yj7QcBTDqvnX15aYA6XTHTC/wSqj6DVyLqbXgLo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=pp5ipRS/sZ8iduGabUkkCOWsYqoquYoiJm7tCQoj14wfPYDu3MFsGr4bY02T/YFZu QKNawnPDxQYl4IJC3rqn4yLTGnpfSMfBBqIkSJ79wZ4UAGaHlZQTzh5ftQ8Jv2+wfB sSmiwFtHG1qfyNOpZRv3ty0mlFGIC7axY5nQdAdC8IKJikL7yaTbFO0PKdjRzTUxi+ wkjXL5zfXfC8OTlmipUOgHtoOfUblVSuBn44P35STZEzpAy42mjWTAWeBKPZaXKCl7 ne5A9vs8a9wbTAXOvOb0Pfi7c08ZBCpxio355LA9Pn3CoKbQiwh4OoZTYacHQEGgzj G4yb4MjpVBCFg== Message-ID: Date: Tue, 18 Nov 2025 08:28:11 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Linux 6.18-rc6 To: Linus Torvalds 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 References: <20251117082023.90176-1-00107082@163.com> <6c09aaea.aa4a.19a91e379ab.Coremail.00107082@163.com> <37bad560-a8f3-4ae2-aa34-1edc635062c0@kernel.org> <1c14c47e.ab83.19a92102b26.Coremail.00107082@163.com> <25e4c75c-097d-44bb-8739-136a0238d5bf@kernel.org> <189cfb08-2593-4ff1-a3fa-3c7957cb6b60@kernel.org> <08790cc2-0db4-4920-8331-9061114e8645@kernel.org> <5903ee6c-3774-47d6-b14a-51201fd75c0f@kernel.org> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 18.11.25 02:10, Linus Torvalds wrote: > On Mon, 17 Nov 2025 at 11:17, David Hildenbrand (Red Hat) > 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) > > 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