From: Kevin Brodsky <kevin.brodsky@arm.com>
To: linux-mm@kvack.org
Cc: Kevin Brodsky <kevin.brodsky@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Linus Walleij <linus.walleij@linaro.org>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
"Mike Rapoport (IBM)" <rppt@kernel.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Will Deacon <will@kernel.org>,
Matthew Wilcox <willy@infradead.org>,
linux-alpha@vger.kernel.org, linux-arch@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org,
linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org,
linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org,
linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org,
linux-snps-arc@lists.infradead.org, linux-um@lists.infradead.org,
loongarch@lists.linux.dev, x86@kernel.org
Subject: [PATCH 10/10] mm: Introduce ctor/dtor at PGD level
Date: Thu, 19 Dec 2024 16:44:25 +0000 [thread overview]
Message-ID: <20241219164425.2277022-11-kevin.brodsky@arm.com> (raw)
In-Reply-To: <20241219164425.2277022-1-kevin.brodsky@arm.com>
Following on from the introduction of P4D-level ctor/dtor, let's
finish the job and introduce ctor/dtor at PGD level. The incurred
improvement in page accounting is minimal - the main motivation is
to create a single, generic place where construction/destruction
hooks can be added for all page table pages.
This patch should cover all architectures and all configurations
where PGDs are one or more regular pages. This excludes any
configuration where PGDs are allocated from a kmem_cache object.
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
---
arch/m68k/include/asm/mcf_pgalloc.h | 2 ++
arch/m68k/mm/motorola.c | 6 ++++++
arch/s390/include/asm/pgalloc.h | 8 +++++++-
include/asm-generic/pgalloc.h | 2 ++
include/linux/mm.h | 10 ++++++++++
5 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/arch/m68k/include/asm/mcf_pgalloc.h b/arch/m68k/include/asm/mcf_pgalloc.h
index 302c5bf67179..7bb9652e1d67 100644
--- a/arch/m68k/include/asm/mcf_pgalloc.h
+++ b/arch/m68k/include/asm/mcf_pgalloc.h
@@ -73,6 +73,7 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pgtable)
static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
+ pagetable_pgd_dtor(virt_to_ptdesc(pgd));
pagetable_free(virt_to_ptdesc(pgd));
}
@@ -84,6 +85,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm)
if (!ptdesc)
return NULL;
+ pagetable_pgd_ctor(ptdesc);
new_pgd = ptdesc_address(ptdesc);
memcpy(new_pgd, swapper_pg_dir, PTRS_PER_PGD * sizeof(pgd_t));
diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
index 37010ee15928..b0fbb369589f 100644
--- a/arch/m68k/mm/motorola.c
+++ b/arch/m68k/mm/motorola.c
@@ -169,6 +169,9 @@ void *get_pointer_table(int type)
case TABLE_PMD:
pagetable_pmd_ctor(virt_to_ptdesc(page));
break;
+ case TABLE_PGD:
+ pagetable_pgd_ctor(virt_to_ptdesc(page));
+ break;
}
mmu_page_ctor(page);
@@ -215,6 +218,9 @@ int free_pointer_table(void *table, int type)
case TABLE_PMD:
pagetable_pmd_dtor(virt_to_ptdesc((void *)page));
break;
+ case TABLE_PGD:
+ pagetable_pgd_dtor(virt_to_ptdesc((void *)page));
+ break;
}
free_page (page);
diff --git a/arch/s390/include/asm/pgalloc.h b/arch/s390/include/asm/pgalloc.h
index 85a5d07365aa..00b69f4ddf17 100644
--- a/arch/s390/include/asm/pgalloc.h
+++ b/arch/s390/include/asm/pgalloc.h
@@ -126,11 +126,17 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
{
- return (pgd_t *) crst_table_alloc(mm);
+ unsigned long *table = crst_table_alloc(mm);
+
+ if (!table)
+ return NULL;
+ pagetable_pgd_ctor(virt_to_ptdesc(table));
+ return (pgd_t *) table;
}
static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
{
+ pagetable_pgd_dtor(virt_to_ptdesc(pgd));
crst_table_free(mm, (unsigned long *) pgd);
}
diff --git a/include/asm-generic/pgalloc.h b/include/asm-generic/pgalloc.h
index daa8bea36952..112b09dc992e 100644
--- a/include/asm-generic/pgalloc.h
+++ b/include/asm-generic/pgalloc.h
@@ -275,6 +275,7 @@ static inline pgd_t *__pgd_alloc_noprof(struct mm_struct *mm, unsigned int order
if (!ptdesc)
return NULL;
+ pagetable_pgd_ctor(ptdesc);
return ptdesc_address(ptdesc);
}
#define __pgd_alloc(...) alloc_hooks(__pgd_alloc_noprof(__VA_ARGS__))
@@ -284,6 +285,7 @@ static inline void __pgd_free(struct mm_struct *mm, pgd_t *pgd)
struct ptdesc *ptdesc = virt_to_ptdesc(pgd);
BUG_ON((unsigned long)pgd & (PAGE_SIZE-1));
+ pagetable_pgd_dtor(ptdesc);
pagetable_free(ptdesc);
}
diff --git a/include/linux/mm.h b/include/linux/mm.h
index e8b92f4bf3f1..7347da3460c5 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3171,6 +3171,16 @@ static inline void pagetable_p4d_dtor(struct ptdesc *ptdesc)
__pagetable_dtor(ptdesc);
}
+static inline void pagetable_pgd_ctor(struct ptdesc *ptdesc)
+{
+ __pagetable_ctor(ptdesc);
+}
+
+static inline void pagetable_pgd_dtor(struct ptdesc *ptdesc)
+{
+ __pagetable_dtor(ptdesc);
+}
+
extern void __init pagecache_init(void);
extern void free_initmem(void);
--
2.47.0
next prev parent reply other threads:[~2024-12-19 16:46 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 16:44 [PATCH 00/10] Account page tables at all levels Kevin Brodsky
2024-12-19 16:44 ` [PATCH 01/10] mm: Move common parts of pagetable_*_[cd]tor to helpers Kevin Brodsky
2024-12-19 17:19 ` Peter Zijlstra
2024-12-20 10:49 ` Kevin Brodsky
2024-12-20 11:46 ` Qi Zheng
2024-12-20 13:50 ` Kevin Brodsky
2024-12-20 14:16 ` Qi Zheng
2024-12-20 14:28 ` Kevin Brodsky
2024-12-20 14:35 ` Qi Zheng
2024-12-19 16:44 ` [PATCH 02/10] parisc: mm: Ensure pagetable_pmd_[cd]tor are called Kevin Brodsky
2024-12-19 16:44 ` [PATCH 03/10] m68k: mm: Add calls to pagetable_pmd_[cd]tor Kevin Brodsky
2024-12-19 16:44 ` [PATCH 04/10] s390/mm: Add calls to pagetable_pud_[cd]tor Kevin Brodsky
2024-12-19 16:44 ` [PATCH 05/10] riscv: mm: Skip pgtable level check in {pud,p4d}_alloc_one Kevin Brodsky
2025-01-03 10:31 ` Alexandre Ghiti
2025-01-03 10:36 ` Kevin Brodsky
2024-12-19 16:44 ` [PATCH 06/10] asm-generic: pgalloc: Provide generic p4d_{alloc_one,free} Kevin Brodsky
2024-12-19 16:44 ` [PATCH 07/10] mm: Introduce ctor/dtor at P4D level Kevin Brodsky
2024-12-19 16:44 ` [PATCH 08/10] ARM: mm: Rename PGD helpers Kevin Brodsky
2024-12-19 16:44 ` [PATCH 09/10] asm-generic: pgalloc: Provide generic __pgd_{alloc,free} Kevin Brodsky
2024-12-19 16:44 ` Kevin Brodsky [this message]
2024-12-19 17:13 ` [PATCH 00/10] Account page tables at all levels Dave Hansen
2024-12-20 10:58 ` Kevin Brodsky
2024-12-20 14:45 ` Dave Hansen
2024-12-20 19:31 ` Dave Hansen
2025-01-03 9:28 ` Kevin Brodsky
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=20241219164425.2277022-11-kevin.brodsky@arm.com \
--to=kevin.brodsky@arm.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@linux.intel.com \
--cc=linus.walleij@linaro.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-hexagon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-snps-arc@lists.infradead.org \
--cc=linux-um@lists.infradead.org \
--cc=loongarch@lists.linux.dev \
--cc=luto@kernel.org \
--cc=peterz@infradead.org \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=willy@infradead.org \
--cc=x86@kernel.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