Skip to contentSkip to conversation

Convert motorola to use ptdescs

PATCH In review Vishal Moola (Oracle) 2 participants 10 messages Jun 11, 2025 – Jun 26, 2025 m68k architecture

lore
Share & tools
lore
#0 lore raw

cover Convert motorola to use ptdescs

m68k's Motorola still uses struct page (it's pointer tables) to track page tables. This patchset converts it to use ptdescs, to help prepare for allocating memory descriptors independently of struct page.

It also includes some minor cleanups to make the code more readable.

----

Based on mm-new. This has only been compile tested, but there are no expected runtime changes.

Vishal Moola (Oracle) (4):
m68k: mm: Convert get_pointer_table() to use ptdescs
m68k: mm: Convert free_pointer_table() to use ptdescs
m68k: mm: Convert init_pointer_table() to use ptdescs
m68k: mm: Convert pointer table macros to use ptdescs

 arch/m68k/mm/motorola.c | 54 ++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 27 deletions(-)
Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/4 m68k: mm: Convert get_pointer_table() to use ptdescs

Motorola uses get_pointer_table() for page tables, so it should be using struct ptdesc, not struct page.

This helps us prepare to allocate ptdescs as their own memory descriptor, and prepares to remove a user of page->lru.

---
 arch/m68k/mm/motorola.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
arch/m68k/mm/motorola.c +13 -11
index 745bd575dcfa..35c3571ffbef 100644
@@ -148,16 +148,18 @@ void *get_pointer_table(struct mm_struct *mm, int type)
 
 	/*
 	 * For a pointer table for a user process address space, a
-	 * table is taken from a page allocated for the purpose.  Each
-	 * page can hold 8 pointer tables.  The page is remapped in
+	 * table is taken from a ptdesc allocated for the purpose.  Each
+	 * ptdesc can hold 8 pointer tables.  The ptdesc is remapped in
 	 * virtual address space to be noncacheable.
 	 */
 	if (mask == 0) {
-		void *page;
+		struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL | __GFP_ZERO, 0);
+		void *pt_addr;
 		ptable_desc *new;
 
-		if (!(page = (void *)get_zeroed_page(GFP_KERNEL)))
+		if (!ptdesc)
 			return NULL;
+		pt_addr = ptdesc_address(ptdesc);
 
 		switch (type) {
 		case TABLE_PTE:
@@ -165,23 +167,23 @@ void *get_pointer_table(struct mm_struct *mm, int type)
 			 * m68k doesn't have SPLIT_PTE_PTLOCKS for not having
 			 * SMP.
 			 */
-			pagetable_pte_ctor(mm, virt_to_ptdesc(page));
+			pagetable_pte_ctor(mm, ptdesc);
 			break;
 		case TABLE_PMD:
-			pagetable_pmd_ctor(mm, virt_to_ptdesc(page));
+			pagetable_pmd_ctor(mm, ptdesc);
 			break;
 		case TABLE_PGD:
-			pagetable_pgd_ctor(virt_to_ptdesc(page));
+			pagetable_pgd_ctor(ptdesc);
 			break;
 		}
 
-		mmu_page_ctor(page);
+		mmu_page_ctor(pt_addr);
 
-		new = PD_PTABLE(page);
+		new = PD_PTABLE(pt_addr);
 		PD_MARKBITS(new) = ptable_mask(type) - 1;
 		list_add_tail(new, dp);
 
-		return (pmd_t *)page;
+		return (pmd_t *)pt_addr;
 	}
 
 	for (tmp = 1, off = 0; (mask & tmp) == 0; tmp <<= 1, off += ptable_size(type))
@@ -191,7 +193,7 @@ void *get_pointer_table(struct mm_struct *mm, int type)
 		/* move to end of list */
 		list_move_tail(dp, &ptable_list[type]);
 	}
-	return page_address(PD_PAGE(dp)) + off;
+	return ptdesc_address(PD_PTDESC(dp)) + off;
 }
 
 int free_pointer_table(void *table, int type)
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] m68k: mm: Convert get_pointer_table() to use ptdescs

Hi Vishal,

Quoted 7 lines · Vishal Moola (Oracle)

Motorola uses get_pointer_table() for page tables, so it should be using struct ptdesc, not struct page.

This helps us prepare to allocate ptdescs as their own memory descriptor, and prepares to remove a user of page->lru.

Thanks for your patch!

i.e. will queue in the m68k tree for v6.17, with the small changes described below.

Quoted 5 lines
arch/m68k/mm/motorola.c +0 -0
@@ -148,16 +148,18 @@ void *get_pointer_table(struct mm_struct *mm, int type)
 
        /*

arch/m68k/mm/motorola.c void *get_pointer_table(struct mm_struct *mm, int type) · line 156

Quoted 10 lines
arch/m68k/mm/motorola.c +3 -3
         * For a pointer table for a user process address space, a
-        * table is taken from a page allocated for the purpose.  Each
-        * page can hold 8 pointer tables.  The page is remapped in
+        * table is taken from a ptdesc allocated for the purpose.  Each
+        * ptdesc can hold 8 pointer tables.  The ptdesc is remapped in
         * virtual address space to be noncacheable.
         */
        if (mask == 0) {
-               void *page;
+               struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL | __GFP_ZERO, 0);

I will move the assignment just before the NULL-check below, to ease applying the WIP preempt patches on top.

arch/m68k/mm/motorola.c void *get_pointer_table(struct mm_struct *mm, int type) · line 157

Quoted 1 line
arch/m68k/mm/motorola.c +1 -0
+               void *pt_addr;

I will move this one line down, to follow the reverse Xmas rule.

arch/m68k/mm/motorola.c void *get_pointer_table(struct mm_struct *mm, int type) · line 165

Quoted 9 lines
arch/m68k/mm/motorola.c +2 -1
                ptable_desc *new;
 
-               if (!(page = (void *)get_zeroed_page(GFP_KERNEL)))
+               if (!ptdesc)
                        return NULL;
+               pt_addr = ptdesc_address(ptdesc);
 
                switch (type) {
                case TABLE_PTE:

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw

PATCH 2/4 m68k: mm: Convert free_pointer_table() to use ptdescs

In reply to Vishal Moola (Oracle)

Motorola uses free_pointer_table() for page tables, so it should be using struct ptdesc, not struct page.

This helps us prepare to allocate ptdescs as their own memory descriptor, and prepares to remove a user of page->lru.

---
 arch/m68k/mm/motorola.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
arch/m68k/mm/motorola.c +6 -7
index 35c3571ffbef..6a459710b2a7 100644
@@ -200,21 +200,20 @@ int free_pointer_table(void *table, int type)
 {
 	ptable_desc *dp;
 	unsigned long ptable = (unsigned long)table;
-	unsigned long page = ptable & PAGE_MASK;
-	unsigned int mask = 1U << ((ptable - page)/ptable_size(type));
+	unsigned long pt_addr = ptable & PAGE_MASK;
+	unsigned int mask = 1U << ((ptable - pt_addr)/ptable_size(type));
 
-	dp = PD_PTABLE(page);
+	dp = PD_PTABLE(pt_addr);
 	if (PD_MARKBITS (dp) & mask)
 		panic ("table already free!");
 
 	PD_MARKBITS (dp) |= mask;
 
 	if (PD_MARKBITS(dp) == ptable_mask(type)) {
-		/* all tables in page are free, free page */
+		/* all tables in ptdesc are free, free ptdesc */
 		list_del(dp);
-		mmu_page_dtor((void *)page);
-		pagetable_dtor(virt_to_ptdesc((void *)page));
-		free_page (page);
+		mmu_page_dtor((void *)pt_addr);
+		pagetable_dtor_free(virt_to_ptdesc((void *)pt_addr));
 		return 1;
 	} else if (ptable_list[type].next != dp) {
 		/*
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] m68k: mm: Convert free_pointer_table() to use ptdescs

Quoted 7 lines · Vishal Moola (Oracle)

Motorola uses free_pointer_table() for page tables, so it should be using struct ptdesc, not struct page.

This helps us prepare to allocate ptdescs as their own memory descriptor, and prepares to remove a user of page->lru.

i.e. will queue in the m68k tree for v6.17.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

PATCH 3/4 m68k: mm: Convert init_pointer_table() to use ptdescs

In reply to Vishal Moola (Oracle)

Motorola uses init_pointer_table() for page tables, so it should be using struct ptdesc, not struct page.

This helps us prepare to allocate ptdescs as their own memory descriptor, and prepares to remove a user of page->lru.

---
 arch/m68k/mm/motorola.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
arch/m68k/mm/motorola.c +6 -6
index 6a459710b2a7..9bd79f42abd5 100644
@@ -121,10 +121,10 @@ void __init init_pointer_table(void *table, int type)
 {
 	ptable_desc *dp;
 	unsigned long ptable = (unsigned long)table;
-	unsigned long page = ptable & PAGE_MASK;
-	unsigned int mask = 1U << ((ptable - page)/ptable_size(type));
+	unsigned long pt_addr = ptable & PAGE_MASK;
+	unsigned int mask = 1U << ((ptable - pt_addr)/ptable_size(type));
 
-	dp = PD_PTABLE(page);
+	dp = PD_PTABLE(pt_addr);
 	if (!(PD_MARKBITS(dp) & mask)) {
 		PD_MARKBITS(dp) = ptable_mask(type);
 		list_add(dp, &ptable_list[type]);
@@ -133,9 +133,9 @@ void __init init_pointer_table(void *table, int type)
 	PD_MARKBITS(dp) &= ~mask;
 	pr_debug("init_pointer_table: %lx, %x\n", ptable, PD_MARKBITS(dp));
 
-	/* unreserve the page so it's possible to free that page */
-	__ClearPageReserved(PD_PAGE(dp));
-	init_page_count(PD_PAGE(dp));
+	/* unreserve the ptdesc so it's possible to free that ptdesc */
+	__ClearPageReserved(ptdesc_page(PD_PTDESC(dp)));
+	init_page_count(ptdesc_page(PD_PTDESC(dp)));
 
 	return;
 }
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] m68k: mm: Convert init_pointer_table() to use ptdescs

Quoted 7 lines · Vishal Moola (Oracle)

Motorola uses init_pointer_table() for page tables, so it should be using struct ptdesc, not struct page.

This helps us prepare to allocate ptdescs as their own memory descriptor, and prepares to remove a user of page->lru.

i.e. will queue in the m68k tree for v6.17.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#7 lore raw

PATCH 4/4 m68k: mm: Convert pointer table macros to use ptdescs

In reply to Vishal Moola (Oracle)

Motorola uses its pointer tables for page tables, so its macros should be using struct ptdesc, not struct page. This removes a user of page->lru.

---
 arch/m68k/mm/motorola.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/m68k/mm/motorola.c +2 -3
index 9bd79f42abd5..492e34dc45e6 100644
@@ -92,7 +92,7 @@ void mmu_page_dtor(void *page)
 }
 
 /* ++andreas: {get,free}_pointer_table rewritten to use unused fields from
-   struct page instead of separately kmalloced struct.  Stolen from
+   struct ptdesc instead of separately kmalloced struct.  Stolen from
    arch/sparc/mm/srmmu.c ... */
 
 typedef struct list_head ptable_desc;
@@ -103,8 +103,7 @@ static struct list_head ptable_list[3] = {
 	LIST_HEAD_INIT(ptable_list[2]),
 };
 
-#define PD_PTABLE(page) ((ptable_desc *)&(virt_to_page((void *)(page))->lru))
-#define PD_PAGE(ptable) (list_entry(ptable, struct page, lru))
+#define PD_PTABLE(ptdesc) ((ptable_desc *)&(virt_to_ptdesc((void *)(ptdesc))->pt_list))
 #define PD_PTDESC(ptable) (list_entry(ptable, struct ptdesc, pt_list))
 #define PD_MARKBITS(dp) (*(unsigned int *)&PD_PTDESC(dp)->pt_index)
 
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] m68k: mm: Convert pointer table macros to use ptdescs

Quoted 4 lines · Vishal Moola (Oracle)

Motorola uses its pointer tables for page tables, so its macros should be using struct ptdesc, not struct page. This removes a user of page->lru.

i.e. will queue in the m68k tree for v6.17.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#9 lore raw
In reply to Vishal Moola (Oracle)
Quoted 10 lines · Vishal Moola (Oracle)

m68k's Motorola still uses struct page (it's pointer tables) to track page tables. This patchset converts it to use ptdescs, to help prepare for allocating memory descriptors independently of struct page.

It also includes some minor cleanups to make the code more readable.

----

Based on mm-new. This has only been compile tested, but there are no expected runtime changes.

Just a friendly ping requesting someone takes a look at this series.. It should be simple, just make sure I didn't miss anything :)