Skip to contentSkip to conversation

mm: clean up redundant code

PATCH In review Feng Lee 3 participants 4 messages May 9, 2025

Subsystems (3)
lore
Share & tools
lore

Feng Lee

author
#0 lore raw

PATCH v2 1/1 mm: clean up redundant code

Remove pgd_offset_gate() completely and simply make the single caller use pgd_offset()

It appears that the gate area resides in the kernel-mapped segment exclusively on IA64. Therefore, removing pgd_offset_k is safe since IA64 is now obsolete.

---
Changes in v2:
- remove pgd_offset_gate completely
- remove pgd_offset_k from the get_gate_page function completely

---
 include/linux/pgtable.h | 4 ----
 mm/gup.c                | 5 +----
 2 files changed, 1 insertion(+), 8 deletions(-)
include/linux/pgtable.h +0 -4
index b50447ef1c92..f1e890b60460 100644
@@ -1164,10 +1164,6 @@ static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio)
 }
 #endif
 
-#ifndef __HAVE_ARCH_PGD_OFFSET_GATE
-#define pgd_offset_gate(mm, addr)	pgd_offset(mm, addr)
-#endif
-
 #ifndef __HAVE_ARCH_MOVE_PTE
 #define move_pte(pte, old_addr, new_addr)	(pte)
 #endif
mm/gup.c +1 -4
index f32168339390..0685403fe510 100644
@@ -1101,10 +1101,7 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address,
 	/* user gate pages are read-only */
 	if (gup_flags & FOLL_WRITE)
 		return -EFAULT;
-	if (address > TASK_SIZE)
-		pgd = pgd_offset_k(address);
-	else
-		pgd = pgd_offset_gate(mm, address);
+	pgd = pgd_offset(mm, address);
 	if (pgd_none(*pgd))
 		return -EFAULT;
 	p4d = p4d_offset(pgd, address);
Signature · 1 line
2.49.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 3 lines · Feng Lee

Remove pgd_offset_gate() completely and simply make the single caller use pgd_offset()

"."

Quoted 7 lines

It appears that the gate area resides in the kernel-mapped segment exclusively on IA64. Therefore, removing pgd_offset_k is safe since IA64 is now obsolete.

Better to rename the subject to be more specific, e.g. "mm: remove obsolete pgd_offset_gate()" or similar. Otherwise,

Quoted 41 lines

---
Changes in v2:
- remove pgd_offset_gate completely
- remove pgd_offset_k from the get_gate_page function completely

---
 include/linux/pgtable.h | 4 ----
 mm/gup.c                | 5 +----
 2 files changed, 1 insertion(+), 8 deletions(-)
include/linux/pgtable.h +0 -4
index b50447ef1c92..f1e890b60460 100644
@@ -1164,10 +1164,6 @@ static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio)
 }
 #endif
 
-#ifndef __HAVE_ARCH_PGD_OFFSET_GATE
-#define pgd_offset_gate(mm, addr)      pgd_offset(mm, addr)
-#endif
-
 #ifndef __HAVE_ARCH_MOVE_PTE
 #define move_pte(pte, old_addr, new_addr)      (pte)
 #endif
mm/gup.c +1 -5
index f32168339390..0685403fe510 100644
@@ -1101,10 +1101,7 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address,
        /* user gate pages are read-only */
        if (gup_flags & FOLL_WRITE)
                return -EFAULT;
-       if (address > TASK_SIZE)
-               pgd = pgd_offset_k(address);
-       else
-               pgd = pgd_offset_gate(mm, address);
+       pgd = pgd_offset(mm, address);
        if (pgd_none(*pgd))
                return -EFAULT;
        p4d = p4d_offset(pgd, address);
--
Quoted 2 lines

2.49.0

Thanks
barry

author
#2 lore raw
Quoted 12 lines · Feng Lee
Quoted 3 lines

Remove pgd_offset_gate() completely and simply make the single caller use pgd_offset()

"."

Quoted 5 lines

It appears that the gate area resides in the kernel-mapped segment exclusively on IA64. Therefore, removing pgd_offset_k is safe since IA64 is now obsolete.

Quoted 7 lines
Quoted 2 lines

Better to rename the subject to be more specific, e.g. "mm: remove obsolete pgd_offset_gate()" or similar. Otherwise,

Thank you very much for your review comments. I will promptly implement the suggested revisions.

Quoted 38 lines
Quoted 38 lines

---
Changes in v2:
- remove pgd_offset_gate completely
- remove pgd_offset_k from the get_gate_page function completely

---
 include/linux/pgtable.h | 4 ----
 mm/gup.c                | 5 +----
 2 files changed, 1 insertion(+), 8 deletions(-)
include/linux/pgtable.h +0 -4
index b50447ef1c92..f1e890b60460 100644
@@ -1164,10 +1164,6 @@ static inline void arch_swap_restore(swp_entry_t entry, struct folio *folio)
 }
 #endif
 
-#ifndef __HAVE_ARCH_PGD_OFFSET_GATE
-#define pgd_offset_gate(mm, addr)      pgd_offset(mm, addr)
-#endif
-
 #ifndef __HAVE_ARCH_MOVE_PTE
 #define move_pte(pte, old_addr, new_addr)      (pte)
 #endif
mm/gup.c +1 -4
index f32168339390..0685403fe510 100644
@@ -1101,10 +1101,7 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address,
        /* user gate pages are read-only */
        if (gup_flags & FOLL_WRITE)
                return -EFAULT;
-       if (address > TASK_SIZE)
-               pgd = pgd_offset_k(address);
-       else
-               pgd = pgd_offset_gate(mm, address);
+       pgd = pgd_offset(mm, address);
        if (pgd_none(*pgd))
Quoted 8 lines
Quoted 5 lines
mm/gup.c +0 -1
                return -EFAULT;
        p4d = p4d_offset(pgd, address);
--

2.49.0

Thanks
barry

Best regards,
Feng

#3 lore raw
In reply to Barry Song
Quoted 12 lines · Barry Song
Quoted 3 lines · Feng Lee

Remove pgd_offset_gate() completely and simply make the single caller use pgd_offset()

"."

Quoted 5 lines

It appears that the gate area resides in the kernel-mapped segment exclusively on IA64. Therefore, removing pgd_offset_k is safe since IA64 is now obsolete.

Quoted 5 lines
Quoted 2 lines

Better to rename the subject to be more specific, e.g. "mm: remove obsolete pgd_offset_gate()" or similar. Otherwise,

With that

Thanks!

Signature · 3 lines
Cheers,

David / dhildenb