From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5521413D62 for ; Wed, 22 Jul 2026 21:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784754029; cv=none; b=HdwDDjuTryGSWZX48jRPyR+ouJFpgqUWNw7w16zJn8cvsWxEhJk6irq7a09Vhx9onQrSnVnEGg99k6yjGjbzjnccVZ9uaLXGE4cUNMF+7l3p1G06tP9jpguN78HIF+YqspSuzUxE/jy/dJ1pGXSoOZSbJLQAxykF1vvzK9daSPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784754029; c=relaxed/simple; bh=T2r4Egp/s+16B0hoCunOZbfeqvExxi27eFGafMCU8ps=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kpay0DDvsdbKRUqLvbih6RiZygHITVX7cZCS7B5QAOlnZiNvqKXTxdspGLeTqZ8N+7SAp+L5+Tu/2kJWUJesNXUUty7u1uM70hW27dRklN7t5sd3Dap9ubEOa2mybQmrakMUwMfVbmMXAAjAdXovKWtmv3NyRq3lKaubhGd/h7s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=YWMrR1YN; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="YWMrR1YN" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D08F51595; Wed, 22 Jul 2026 14:00:21 -0700 (PDT) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 27E8B3F59E; Wed, 22 Jul 2026 14:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784754026; bh=T2r4Egp/s+16B0hoCunOZbfeqvExxi27eFGafMCU8ps=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YWMrR1YN3bfiCwiezM9DJOx6TakLDNvhmwvKnHA5Wkhoz7J/eEz5QdDttGzppOqLI zc4F6tSsSpkQhSGeJsl+pVpGr5bnG6/UISWfFwGO6FJzqovJrkoePCsw3tVFPUswwq Upv27aJLOhDf0wbnQxdJABxfJrqgq2VT4sARSYOY= Date: Wed, 22 Jul 2026 22:00:17 +0100 From: Yeoreum Yun To: Dave Hansen Cc: Yeoreum Yun , Russell King , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Catalin Marinas , Will Deacon , Arnd Bergmann , Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Lorenzo Stoakes , Tianrui Zhao , Bibo Mao , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-openrisc@vger.kernel.org Subject: Re: [PATCH RFC v2 13/20] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot() Message-ID: References: <20260722-dummy_ptxp3-v2-0-d9e4bad31e0a@arm.com> <20260722-dummy_ptxp3-v2-13-d9e4bad31e0a@arm.com> <33c774f6-2750-4831-8eee-e43dc471da32@intel.com> Precedence: bulk X-Mailing-List: loongarch@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33c774f6-2750-4831-8eee-e43dc471da32@intel.com> On Wed, Jul 22, 2026 at 01:20:39PM -0700, Dave Hansen wrote: > On 7/22/26 10:37, Yeoreum Yun wrote: > >> On 7/22/26 08:30, Yeoreum Yun wrote: > >>> struct pg_state { > >>> struct ptdump_state ptdump; > >>> + int first_level; > >>> int level; > >>> pgprotval_t current_prot; > >>> pgprotval_t effective_prot; > >> There is zero reason on x86 to hold this value in a data structure. It > >> is 100% determined at boot time or earlier. Pre-5-level-paging it's a > >> compile-time constant. > >> > >> On x86, it never varies per-mm. > > However, mm_pXd_folded() requires to mm for other architecture like > > s390. might save the mm instead of first_level and calls the > > ptdump_pt_level_first() with static inline version would make the > > constant comparison. So it requires to save *mm* structure in here. > > I'm having a really hard time parsing that. > > I think you're trying to say that the effective_prot_p*() functions need > to know the first level but they don't (today) need the mm_struct. If > they don't get the (calculated) first_level passed in, they need the > mm_struct instead. > > I think you're arguing 'pg_state' needs a ->first_level or a ->mm. > Having a pg_state->mm doesn't seem bad to me at all. > > But, it's also a little bit silly. It would not be rocket science to > pass an mm_struct down to the effective_prot_p*() functions. It makes a > whole lot of sense to me for a page table walking function to need > metadata from the mm_struct to walk correctly. Yes. I mean to add pg_state->mm like: diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 2afa7a23340e..aaf00f0c6624 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -38,6 +38,7 @@ struct pg_state { bool check_wx; unsigned long wx_pages; struct seq_file *seq; + struct mm_struct *mm; }; struct addr_marker { @@ -254,7 +255,7 @@ static void effective_prot(struct ptdump_state *pt_st, int level, u64 val) pgprotval_t prot = val & PTE_FLAGS_MASK; pgprotval_t effective; - if (level > 0) { + if (level > pgtable_first_level(st->mm)) { pgprotval_t higher_prot = st->prot_levels[level - 1]; effective = (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) | @@ -452,7 +453,8 @@ bool ptdump_walk_pgd_level_core(struct seq_file *m, .level = -1, .to_dmesg = dmesg, .check_wx = checkwx, - .seq = m + .seq = m, + .mm = mm, }; ptdump_walk_pgd(&st.ptdump, mm, pgd); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 8c093c119e5a..6e7d0580db99 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2490,4 +2490,15 @@ pgprot_t vm_get_page_prot(vm_flags_t vm_flags) \ } \ EXPORT_SYMBOL(vm_get_page_prot); +static inline int pgtable_first_level(struct mm_struct *mm) +{ + if (mm_pmd_folded(mm)) + return 3; + if (mm_pud_folded(mm)) + return 2; + if (mm_p4d_folded(mm)) + return 1; + return 0; +} + #endif /* _LINUX_PGTABLE_H */ -- Sincerely, Yeoreum Yun From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83DA3C4453A for ; Wed, 22 Jul 2026 21:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pZKOah5v/NY77i9+fUFSu/Ufr9EgQ5wE3wp2yEG1fSA=; b=DTzHas8kHd3E/9 RQvQKf8KlZPZZJDW21wCJ/xeihLxVgsYrsqHrB6jykAPEHTCxw7IxLSbBKTT92Gpd5S0aXDigOmdr GKgPCwWMrHK6cqLil4+Ec9NRCvrxvfeFAshMCThTCfoMpIPwOEsg7uCIukstnz0Rpsk5fSWWtYGB5 62HvAB76C06R4Y5AlJd5hjDgOGiTvcUrL0ZVoDrtF0+jO6UM6d2/z6Z24jtOf+kSO7lMLNl7opqxl +yHWS42YnOyCrcRiBB8cZIDOCRMGRtarIwUoqkEVSeAu8RUe0uF4yWjDQe7PPAiSMlxbcBZQYCGX3 joeIadALktaQeeusO0dQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wme3K-0000000Clz8-2jIR; Wed, 22 Jul 2026 21:00:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wme3I-0000000Clyd-1VH5; Wed, 22 Jul 2026 21:00:29 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D08F51595; Wed, 22 Jul 2026 14:00:21 -0700 (PDT) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 27E8B3F59E; Wed, 22 Jul 2026 14:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784754026; bh=T2r4Egp/s+16B0hoCunOZbfeqvExxi27eFGafMCU8ps=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YWMrR1YN3bfiCwiezM9DJOx6TakLDNvhmwvKnHA5Wkhoz7J/eEz5QdDttGzppOqLI zc4F6tSsSpkQhSGeJsl+pVpGr5bnG6/UISWfFwGO6FJzqovJrkoePCsw3tVFPUswwq Upv27aJLOhDf0wbnQxdJABxfJrqgq2VT4sARSYOY= Date: Wed, 22 Jul 2026 22:00:17 +0100 From: Yeoreum Yun To: Dave Hansen Cc: Yeoreum Yun , Russell King , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Catalin Marinas , Will Deacon , Arnd Bergmann , Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Lorenzo Stoakes , Tianrui Zhao , Bibo Mao , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-openrisc@vger.kernel.org Subject: Re: [PATCH RFC v2 13/20] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot() Message-ID: References: <20260722-dummy_ptxp3-v2-0-d9e4bad31e0a@arm.com> <20260722-dummy_ptxp3-v2-13-d9e4bad31e0a@arm.com> <33c774f6-2750-4831-8eee-e43dc471da32@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <33c774f6-2750-4831-8eee-e43dc471da32@intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260722_140028_480712_FAA96221 X-CRM114-Status: GOOD ( 26.45 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Wed, Jul 22, 2026 at 01:20:39PM -0700, Dave Hansen wrote: > On 7/22/26 10:37, Yeoreum Yun wrote: > >> On 7/22/26 08:30, Yeoreum Yun wrote: > >>> struct pg_state { > >>> struct ptdump_state ptdump; > >>> + int first_level; > >>> int level; > >>> pgprotval_t current_prot; > >>> pgprotval_t effective_prot; > >> There is zero reason on x86 to hold this value in a data structure. It > >> is 100% determined at boot time or earlier. Pre-5-level-paging it's a > >> compile-time constant. > >> > >> On x86, it never varies per-mm. > > However, mm_pXd_folded() requires to mm for other architecture like > > s390. might save the mm instead of first_level and calls the > > ptdump_pt_level_first() with static inline version would make the > > constant comparison. So it requires to save *mm* structure in here. > > I'm having a really hard time parsing that. > > I think you're trying to say that the effective_prot_p*() functions need > to know the first level but they don't (today) need the mm_struct. If > they don't get the (calculated) first_level passed in, they need the > mm_struct instead. > > I think you're arguing 'pg_state' needs a ->first_level or a ->mm. > Having a pg_state->mm doesn't seem bad to me at all. > > But, it's also a little bit silly. It would not be rocket science to > pass an mm_struct down to the effective_prot_p*() functions. It makes a > whole lot of sense to me for a page table walking function to need > metadata from the mm_struct to walk correctly. Yes. I mean to add pg_state->mm like: diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 2afa7a23340e..aaf00f0c6624 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -38,6 +38,7 @@ struct pg_state { bool check_wx; unsigned long wx_pages; struct seq_file *seq; + struct mm_struct *mm; }; struct addr_marker { @@ -254,7 +255,7 @@ static void effective_prot(struct ptdump_state *pt_st, int level, u64 val) pgprotval_t prot = val & PTE_FLAGS_MASK; pgprotval_t effective; - if (level > 0) { + if (level > pgtable_first_level(st->mm)) { pgprotval_t higher_prot = st->prot_levels[level - 1]; effective = (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) | @@ -452,7 +453,8 @@ bool ptdump_walk_pgd_level_core(struct seq_file *m, .level = -1, .to_dmesg = dmesg, .check_wx = checkwx, - .seq = m + .seq = m, + .mm = mm, }; ptdump_walk_pgd(&st.ptdump, mm, pgd); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 8c093c119e5a..6e7d0580db99 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2490,4 +2490,15 @@ pgprot_t vm_get_page_prot(vm_flags_t vm_flags) \ } \ EXPORT_SYMBOL(vm_get_page_prot); +static inline int pgtable_first_level(struct mm_struct *mm) +{ + if (mm_pmd_folded(mm)) + return 3; + if (mm_pud_folded(mm)) + return 2; + if (mm_p4d_folded(mm)) + return 1; + return 0; +} + #endif /* _LINUX_PGTABLE_H */ -- Sincerely, Yeoreum Yun _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B39FC4453C for ; Wed, 22 Jul 2026 21:00:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FL7DoT5t9gZnzhbkiL94BlDM0bTVFQfipjp8ZrzWR/o=; b=456dVwV5t1es1s qf1My80CgV2UTpDAU4/gQowddwxsTcqjBNMPs4XB2wYYhf4SblJEcmBCU6uq4szimoU6FfCahCeuD Dahaw9edO3mNoABgFVeN2Sy74W5t8Vbv6Z+vn13y3sCv9F3qPpVmn3BdboFji6UtjoQrxiMOXjYMP UmdJNuaSxw4SeNxfFDAoSkbKW7djg/4FrJ4VT3n7gzj0eIqMjGO8U6JWYz2CWV2eI1JznuiB1XQhM uzQJ+oT7QWbcQMHKxGvsTXD4CGoxURb9VINar72OQIfya8g8kdHm1cbUcu+Ri3OWETnhGNHl/lXnT //S4qeJ2YlXWAw7skO9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wme3K-0000000Clz4-2WBZ; Wed, 22 Jul 2026 21:00:30 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wme3I-0000000Clyd-1VH5; Wed, 22 Jul 2026 21:00:29 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D08F51595; Wed, 22 Jul 2026 14:00:21 -0700 (PDT) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 27E8B3F59E; Wed, 22 Jul 2026 14:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1784754026; bh=T2r4Egp/s+16B0hoCunOZbfeqvExxi27eFGafMCU8ps=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YWMrR1YN3bfiCwiezM9DJOx6TakLDNvhmwvKnHA5Wkhoz7J/eEz5QdDttGzppOqLI zc4F6tSsSpkQhSGeJsl+pVpGr5bnG6/UISWfFwGO6FJzqovJrkoePCsw3tVFPUswwq Upv27aJLOhDf0wbnQxdJABxfJrqgq2VT4sARSYOY= Date: Wed, 22 Jul 2026 22:00:17 +0100 From: Yeoreum Yun To: Dave Hansen Cc: Yeoreum Yun , Russell King , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Catalin Marinas , Will Deacon , Arnd Bergmann , Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Lorenzo Stoakes , Tianrui Zhao , Bibo Mao , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-openrisc@vger.kernel.org Subject: Re: [PATCH RFC v2 13/20] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot() Message-ID: References: <20260722-dummy_ptxp3-v2-0-d9e4bad31e0a@arm.com> <20260722-dummy_ptxp3-v2-13-d9e4bad31e0a@arm.com> <33c774f6-2750-4831-8eee-e43dc471da32@intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <33c774f6-2750-4831-8eee-e43dc471da32@intel.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260722_140028_480712_FAA96221 X-CRM114-Status: GOOD ( 26.45 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org On Wed, Jul 22, 2026 at 01:20:39PM -0700, Dave Hansen wrote: > On 7/22/26 10:37, Yeoreum Yun wrote: > >> On 7/22/26 08:30, Yeoreum Yun wrote: > >>> struct pg_state { > >>> struct ptdump_state ptdump; > >>> + int first_level; > >>> int level; > >>> pgprotval_t current_prot; > >>> pgprotval_t effective_prot; > >> There is zero reason on x86 to hold this value in a data structure. It > >> is 100% determined at boot time or earlier. Pre-5-level-paging it's a > >> compile-time constant. > >> > >> On x86, it never varies per-mm. > > However, mm_pXd_folded() requires to mm for other architecture like > > s390. might save the mm instead of first_level and calls the > > ptdump_pt_level_first() with static inline version would make the > > constant comparison. So it requires to save *mm* structure in here. > > I'm having a really hard time parsing that. > > I think you're trying to say that the effective_prot_p*() functions need > to know the first level but they don't (today) need the mm_struct. If > they don't get the (calculated) first_level passed in, they need the > mm_struct instead. > > I think you're arguing 'pg_state' needs a ->first_level or a ->mm. > Having a pg_state->mm doesn't seem bad to me at all. > > But, it's also a little bit silly. It would not be rocket science to > pass an mm_struct down to the effective_prot_p*() functions. It makes a > whole lot of sense to me for a page table walking function to need > metadata from the mm_struct to walk correctly. Yes. I mean to add pg_state->mm like: diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 2afa7a23340e..aaf00f0c6624 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -38,6 +38,7 @@ struct pg_state { bool check_wx; unsigned long wx_pages; struct seq_file *seq; + struct mm_struct *mm; }; struct addr_marker { @@ -254,7 +255,7 @@ static void effective_prot(struct ptdump_state *pt_st, int level, u64 val) pgprotval_t prot = val & PTE_FLAGS_MASK; pgprotval_t effective; - if (level > 0) { + if (level > pgtable_first_level(st->mm)) { pgprotval_t higher_prot = st->prot_levels[level - 1]; effective = (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) | @@ -452,7 +453,8 @@ bool ptdump_walk_pgd_level_core(struct seq_file *m, .level = -1, .to_dmesg = dmesg, .check_wx = checkwx, - .seq = m + .seq = m, + .mm = mm, }; ptdump_walk_pgd(&st.ptdump, mm, pgd); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 8c093c119e5a..6e7d0580db99 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2490,4 +2490,15 @@ pgprot_t vm_get_page_prot(vm_flags_t vm_flags) \ } \ EXPORT_SYMBOL(vm_get_page_prot); +static inline int pgtable_first_level(struct mm_struct *mm) +{ + if (mm_pmd_folded(mm)) + return 3; + if (mm_pud_folded(mm)) + return 2; + if (mm_p4d_folded(mm)) + return 1; + return 0; +} + #endif /* _LINUX_PGTABLE_H */ -- Sincerely, Yeoreum Yun -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv