From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E63EE30E85D; Mon, 13 Jul 2026 21:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783977486; cv=none; b=dY/1NOw3/rVIBh3dG7QgEQuEkL2gntwh1kbLaSE1HemTBfl+hSep1C8eLe2oHuYcT+/Ovg9wRJnzUoBZ491eZqA6ws0rU8GIoaWx/P62gkfwNCo1IOo9CRJfvcBljBhBd6x6gx6sUK3N8OwFQRl71iZrpp1MdA5HUEgBPjglpBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783977486; c=relaxed/simple; bh=q92Ill2Qnc8PGnK8SBZtYhm7XyFaL8iK2Hk6HRQRYCU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KWj2bYBlnRfxG7qf+vSRo+U8DDPPMdNLzYcbR+RFc2coS4hWlF/1ndQXbhIBG8WlLOa99Xip7Ak3o93ubVyw6HFPz2IB7UB5n1XbYH+CGtKQIQkq9xpSQ40+zIB/ICWQ9md8sK3oyJssreYC1Z8tHgB5xrLPM5Q3z93etDm2PoU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NvF2YMXG; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NvF2YMXG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFC2B1F000E9; Mon, 13 Jul 2026 21:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783977484; bh=7AP6vL/IknWnMrMEhy8oZzGqoRe/qZtcpIw0uJFVyX8=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=NvF2YMXGsrh91m0Utx3mep+raAJ6w2eAV20dIZ2Vceh1KtH0lLgRsZPiRwnxy3ziE EhHLOxDlPyLPcRkEsCFjqbxTQoOJlyTG5u8omN4r7c2/S/zFQ7tv7gpyEb2CF4M7JR 6ipE7uR1d94f42i6B+jK76nR4i9J2CFgqVPOzc+lR2jFGfZVbKxZDiMN0XA0k1Jc/O 2Lv5a9w4YUeFP1Lqm5Ult/7gJZrmH/pN8DncPc3gl1kQwfVnFrjZQcYcx2fK0DCDLr DGwppflzLVmoQ2RgRZuksFfztRqvsQ6RK3KDcFAX//ZN1J4BuvAEHDd0MqBIrxE9Pu INPh4wS7oJaUA== Message-ID: <31988089-095a-4eed-b5e2-c677c70f79f6@kernel.org> Date: Mon, 13 Jul 2026 23:17:31 +0200 Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 10/34] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot() To: Dave Hansen , Yeoreum Yun , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-csky@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-openrisc@vger.kernel.org Cc: linux@armlinux.org.uk, akpm@linux-foundation.org, ankur.a.arora@oracle.com, rppt@kernel.org, linmag7@gmail.com, chleroy@kernel.org, klarasmodin@gmail.com, chenhuacai@kernel.org, kernel@xen0n.name, kas@kernel.org, zhangtianyang@loongson.cn, wangyuli@aosc.io, tsbogend@alpha.franken.de, ljs@kernel.org, jgg@ziepe.ca, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, ryan.roberts@arm.com, pasha.tatashin@soleen.com, rmclure@linux.ibm.com, baolin.wang@linux.alibaba.com, tj@kernel.org, kevin.brodsky@arm.com, anup@brainfault.org, atish.patra@linux.dev, pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, hannes@cmpxchg.org, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, kasong@tencent.com, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, anshuman.khandual@arm.com, yang@os.amperecomputing.com, chaitanyas.prakash@arm.com, ardb@kernel.org, guoren@kernel.org, yang.li85200@gmail.com, viro@zeniv.linux.org.uk, dinguyen@kernel.org, schuster.simon@siemens-energy.com, wangruikang@iscas.ac.cn, junhui.liu@pigmoral.tech, muchun.song@linux.dev, vishal.moola@gmail.com, namcao@linutronix.de, pavel@kernel.org, djbw@kernel.org, yu-cheng.yu@intel.com, baolu.lu@linux.intel.com, Jonathan.Cameron@huawei.com, coxu@redhat.com, andreas@gaisler.com, liam@infradead.org, vbabka@kernel.org, surenb@google.com, mhocko@suse.com, geert@linux-m68k.org, shorne@gmail.com, jonas@southpole.se, stefan.kristiansson@saunalahti.fi References: <20260713135614.1618183-1-yeoreum.yun@arm.com> <20260713135614.1618183-11-yeoreum.yun@arm.com> <710b7eb0-8e0c-4f07-991c-2285c77e1beb@intel.com> <6007625e-c3f9-4ad6-99a8-61396bccbcec@kernel.org> <32d459d1-ad19-4baf-bbb1-0565458001d2@intel.com> <3ea30f8a-bb29-4bf5-8400-1c4840d46a88@kernel.org> <7e84b200-25eb-43a6-b5e2-5f27f2d82a77@intel.com> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzS5EYXZpZCBIaWxk ZW5icmFuZCAoQ3VycmVudCkgPGRhdmlkQGtlcm5lbC5vcmc+wsGQBBMBCAA6AhsDBQkmWAik AgsJBBUKCQgCFgICHgUCF4AWIQQb2cqtc1xMOkYN/MpN3hD3AP+DWgUCaYJt/AIZAQAKCRBN 3hD3AP+DWriiD/9BLGEKG+N8L2AXhikJg6YmXom9ytRwPqDgpHpVg2xdhopoWdMRXjzOrIKD g4LSnFaKneQD0hZhoArEeamG5tyo32xoRsPwk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charset=UTF-8 Content-Transfer-Encoding: 7bit On 7/13/26 22:27, Dave Hansen wrote: > On 7/13/26 12:49, David Hildenbrand (Arm) wrote: >>> I really do think this series is changing things, not keeping them the same. >> Looking at it from that angle, I tend do agree: it further moves into the >> direction that actually the p4d_present() carries value, and the previous >> pgd_present() is just a dummy. >> >> I can see that some more work is required to untangle the mess we already have. >> >> I don't know why pgd_present() was made a dummy function and not p4d_present(), >> but I'm sure there is a good reason to it. Changing that now ... omg. > > Yeah, the p4d addition added even more wrinkles because it was the first > time we tried runtime folding in addition to the historical compile-time > folding. > > There were certainly some ugly corners of it that we never found a nice > way to fix. I know Kiryl tried pretty hard. > > But, zooming back out... I don't think this diffstat: > > 31 files changed, 329 insertions(+), 206 deletions(-) > > is nearly justified to eliminate one virtually guaranteed cached memory > read instruction. "Unnecessary", sure. But, worth the diffstat? I'm not > quite there. Just to emphasize, this prevents common code from being converted to pgdp_get() and friends, as it would make folded page tables more expensive in other page table walkers, and other arch maintainers rightfully complained about that. I don't want to be stuck with this inconsistent mess of some common code page walkers using pgp_get(), while others are stopped from being converted due to inefficiency concerns. *that* makes our common MM code worse, and it grinds my gears. And I really care more about common MM code being clean and consistent than some rusty old 32bit code being slightly worse. As discussed, we can keep the set_pgd() monstrosity from working in all places that don't use something like set_pgd(pgp_get()), bust as I raised off-list, setting something that is unconditionally pgd_present() -- a dummy -- is just extremely ugly. But ugly seems to be the theme in folded page table land. That would certainly be less churn, while leaving this questionable code in place, I'm fine with that as long as we don't add silent bugs when some arch start doing e.g., set_pgd(pgp_get()). > > Also, I think a series that adds code like this: > >> - if (level > 0) { >> + /* Ignore folded levels ... */ >> + if (((level == 0) && mm_p4d_folded(st->mm)) || >> + ((level == 1) && mm_pud_folded(st->mm)) || >> + ((level == 2) && mm_pmd_folded(st->mm))) >> + return; >> + >> + /* ... and make the actual first level remember the protection. */ >> + if (((level == 0)) || >> + ((level == 1) && mm_p4d_folded(st->mm)) || >> + ((level == 2) && mm_pud_folded(st->mm)) || >> + ((level == 3) && mm_pmd_folded(st->mm))) >> + first_level = true; > > fails the sniff test of being an effective refactor. It unquestionably > makes _that_ code worse, not better. As I said, we can improve that part. But we'll have to stop faking that each level exist, when it's really folded. That's all this code does, and the first part of this logic could be had in common code easily (just don't call on folded page tables). > > If the series was: > > Subject: Refactor page table folding in all architectures > > and we had a discussion about what the best overall thing to do for all > architectures is, I think we might have a better path forward. It would > also be a smaller series. It took me too long to understand why a "nop4d.h" file defines PGD functions to be dummies and assumes an arch to implement p4d functions. So yes, in a perfect world we'd rewrite folded page table handling entirely. BUT Let's focus on the real problem: Common code cannot consistently use pgdp_get() etc. as it harms configs with folded page tables. And that problem shouldn't require refactoring/rewriting all of page table folding at this point. > > To me, the double READ_ONCE() is a non-issue. To other arch maintainers, it is! > Having a nice, coherent > page table API in the kernel is much more important to talk about. While I agree, we are talking about avoiding degrading folded page table configs as we make common code more consistent. I hate our folded page table code when looking it from an arch perspective (common code walking just works), and I agree that it should be improved. But I disagree that it should be blocking of core-mm using page table getters consistently. -- Cheers, David