2005-04-07 01:11:01

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH 1/6] freepgt2: free_pgtables from FIRST_USER_ADDRESS

The patches to free_pgtables by vma left problems on any architectures
which leave some user address page table entries unencapsulated by vma.
Andi has fixed the 32-bit vDSO on x86_64 to use a vma. Now fix arm (and
arm26), whose first PAGE_SIZE is reserved (perhaps) for machine vectors.

Our calls to free_pgtables must not touch that area, and exit_mmap's
BUG_ON(nr_ptes) must allow that arm's get_pgd_slow may (or may not) have
allocated an extra page table, which its free_pgd_slow would free later.

FIRST_USER_PGD_NR has misled me and others: until all the arches define
FIRST_USER_ADDRESS instead, a hack in mmap.c to derive one from t'other.
This patch fixes the bugs, the remaining patches just clean it up.

Signed-off-by: Hugh Dickins <[email protected]>
---

mm/mmap.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)

--- 2.6.12-rc2-mm1/mm/mmap.c 2005-04-05 15:23:00.000000000 +0100
+++ linux/mm/mmap.c 2005-04-05 18:59:01.000000000 +0100
@@ -1608,6 +1608,11 @@ static void unmap_vma_list(struct mm_str
validate_mm(mm);
}

+#ifndef FIRST_USER_ADDRESS /* temporary hack */
+#define THIS_IS_ARM FIRST_USER_PGD_NR
+#define FIRST_USER_ADDRESS (THIS_IS_ARM * PAGE_SIZE)
+#endif
+
/*
* Get rid of page table information in the indicated region.
*
@@ -1626,7 +1631,7 @@ static void unmap_region(struct mm_struc
tlb = tlb_gather_mmu(mm, 0);
unmap_vmas(&tlb, mm, vma, start, end, &nr_accounted, NULL);
vm_unacct_memory(nr_accounted);
- free_pgtables(&tlb, vma, prev? prev->vm_end: 0,
+ free_pgtables(&tlb, vma, prev? prev->vm_end: FIRST_USER_ADDRESS,
next? next->vm_start: 0);
tlb_finish_mmu(tlb, start, end);
spin_unlock(&mm->page_table_lock);
@@ -1906,7 +1911,7 @@ void exit_mmap(struct mm_struct *mm)
/* Use -1 here to ensure all VMAs in the mm are unmapped */
end = unmap_vmas(&tlb, mm, vma, 0, -1, &nr_accounted, NULL);
vm_unacct_memory(nr_accounted);
- free_pgtables(&tlb, vma, 0, 0);
+ free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
tlb_finish_mmu(tlb, 0, end);

mm->mmap = mm->mmap_cache = NULL;
@@ -1927,7 +1932,7 @@ void exit_mmap(struct mm_struct *mm)
vma = next;
}

- BUG_ON(mm->nr_ptes); /* This is just debugging */
+ BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
}

/* Insert vm structure into process list sorted by address


2005-04-07 01:14:45

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH 2/6] freepgt2: sys_mincore ignore FIRST_USER_PGD_NR

Remove use of FIRST_USER_PGD_NR from sys_mincore: it's inconsistent (no
other syscall refers to it), unnecessary (sys_mincore loops over vmas
further down) and incorrect (misses user addresses in ARM's first pgd).

Signed-off-by: Hugh Dickins <[email protected]>
---

mm/mincore.c | 3 ---
1 files changed, 3 deletions(-)

--- 2.6.12-rc2-mm1/mm/mincore.c 2005-04-05 15:21:02.000000000 +0100
+++ linux/mm/mincore.c 2005-04-05 18:59:01.000000000 +0100
@@ -118,9 +118,6 @@ asmlinkage long sys_mincore(unsigned lon
if (start & ~PAGE_CACHE_MASK)
goto einval;

- if (start < FIRST_USER_PGD_NR * PGDIR_SIZE)
- goto enomem;
-
limit = TASK_SIZE;
if (start >= limit)
goto enomem;

2005-04-07 01:15:46

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH 3/6] freepgt2: arm FIRST_USER_ADDRESS PAGE_SIZE

ARM define FIRST_USER_ADDRESS as PAGE_SIZE (beyond the machine vectors
when they are mapped low), and use that definition in place of locally
defined MIN_MAP_ADDR.

Signed-off-by: Hugh Dickins <[email protected]>
---

arch/arm/kernel/sys_arm.c | 11 ++---------
include/asm-arm/pgtable.h | 7 +++++++
2 files changed, 9 insertions(+), 9 deletions(-)

--- 2.6.12-rc2-mm1/arch/arm/kernel/sys_arm.c 2005-04-05 15:20:23.000000000 +0100
+++ linux/arch/arm/kernel/sys_arm.c 2005-04-05 18:59:00.000000000 +0100
@@ -51,13 +51,6 @@ asmlinkage int sys_pipe(unsigned long __
return error;
}

-/*
- * This is the lowest virtual address we can permit any user space
- * mapping to be mapped at. This is particularly important for
- * non-high vector CPUs.
- */
-#define MIN_MAP_ADDR (PAGE_SIZE)
-
/* common code for old and new mmaps */
inline long do_mmap2(
unsigned long addr, unsigned long len,
@@ -69,7 +62,7 @@ inline long do_mmap2(

flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);

- if (flags & MAP_FIXED && addr < MIN_MAP_ADDR)
+ if (flags & MAP_FIXED && addr < FIRST_USER_ADDRESS)
goto out;

error = -EBADF;
@@ -122,7 +115,7 @@ sys_arm_mremap(unsigned long addr, unsig
{
unsigned long ret = -EINVAL;

- if (flags & MREMAP_FIXED && new_addr < MIN_MAP_ADDR)
+ if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS)
goto out;

down_write(&current->mm->mmap_sem);
--- 2.6.12-rc2-mm1/include/asm-arm/pgtable.h 2005-04-05 15:20:55.000000000 +0100
+++ linux/include/asm-arm/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -102,6 +102,13 @@ extern void __pgd_error(const char *file
#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
#define PGDIR_MASK (~(PGDIR_SIZE-1))

+/*
+ * This is the lowest virtual address we can permit any user space
+ * mapping to be mapped at. This is particularly important for
+ * non-high vector CPUs.
+ */
+#define FIRST_USER_ADDRESS PAGE_SIZE
+
#define FIRST_USER_PGD_NR 1
#define USER_PTRS_PER_PGD ((TASK_SIZE/PGDIR_SIZE) - FIRST_USER_PGD_NR)

2005-04-07 01:19:16

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH 4/6] freepgt2: arm26 FIRST_USER_ADDRESS PAGE_SIZE

ARM26 define FIRST_USER_ADDRESS as PAGE_SIZE (beyond the machine vectors
when they are mapped low), and use that definition in place of locally
defined MIN_MAP_ADDR. Previously, ARM26 permitted user mappings at 0 if
the machine vectors were mapped high; but that's inconsistent with ARM,
and FIRST_USER_ADDRESS would then have to be determined at runtime.
Let's fix it at PAGE_SIZE throughout the architecture.

Signed-off-by: Hugh Dickins <[email protected]>
---

arch/arm26/kernel/sys_arm.c | 9 ++++-----
include/asm-arm26/pgtable.h | 7 +++++++
2 files changed, 11 insertions(+), 5 deletions(-)

--- 2.6.12-rc2-mm1/arch/arm26/kernel/sys_arm.c 2005-03-02 07:38:58.000000000 +0000
+++ linux/arch/arm26/kernel/sys_arm.c 2005-04-05 18:59:00.000000000 +0100
@@ -64,10 +64,10 @@ inline long do_mmap2(
flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);

/*
- * If we are doing a fixed mapping, and address < PAGE_SIZE,
+ * If we are doing a fixed mapping, and address < FIRST_USER_ADDRESS,
* then deny it.
*/
- if (flags & MAP_FIXED && addr < PAGE_SIZE && vectors_base() == 0)
+ if (flags & MAP_FIXED && addr < FIRST_USER_ADDRESS)
goto out;

error = -EBADF;
@@ -121,11 +121,10 @@ sys_arm_mremap(unsigned long addr, unsig
unsigned long ret = -EINVAL;

/*
- * If we are doing a fixed mapping, and address < PAGE_SIZE,
+ * If we are doing a fixed mapping, and address < FIRST_USER_ADDRESS,
* then deny it.
*/
- if (flags & MREMAP_FIXED && new_addr < PAGE_SIZE &&
- vectors_base() == 0)
+ if (flags & MREMAP_FIXED && new_addr < FIRST_USER_ADDRESS)
goto out;

down_write(&current->mm->mmap_sem);
--- 2.6.12-rc2-mm1/include/asm-arm26/pgtable.h 2005-04-05 15:20:55.000000000 +0100
+++ linux/include/asm-arm26/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -62,6 +62,13 @@
#define PTRS_PER_PMD 1
#define PTRS_PER_PTE 32

+/*
+ * This is the lowest virtual address we can permit any user space
+ * mapping to be mapped at. This is particularly important for
+ * non-high vector CPUs.
+ */
+#define FIRST_USER_ADDRESS PAGE_SIZE
+
#define FIRST_USER_PGD_NR 1
#define USER_PTRS_PER_PGD ((TASK_SIZE/PGD_SIZE) - FIRST_USER_PGD_NR)

2005-04-07 01:24:00

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH 6/6] freepgt2: remove FIRST_USER_ADDRESS hack

Once all the MMU architectures define FIRST_USER_ADDRESS,
remove hack from mmap.c which derived it from FIRST_USER_PGD_NR.

Signed-off-by: Hugh Dickins <[email protected]>
---

mm/mmap.c | 5 -----
1 files changed, 5 deletions(-)

--- 2.6.12-rc2-mm1+/mm/mmap.c 2005-04-05 18:59:01.000000000 +0100
+++ linux/mm/mmap.c 2005-04-07 00:32:43.000000000 +0100
@@ -1608,11 +1608,6 @@ static void unmap_vma_list(struct mm_str
validate_mm(mm);
}

-#ifndef FIRST_USER_ADDRESS /* temporary hack */
-#define THIS_IS_ARM FIRST_USER_PGD_NR
-#define FIRST_USER_ADDRESS (THIS_IS_ARM * PAGE_SIZE)
-#endif
-
/*
* Get rid of page table information in the indicated region.
*

2005-04-07 01:25:18

by Hugh Dickins

[permalink] [raw]
Subject: [PATCH 5/6] freepgt2: arch FIRST_USER_ADDRESS 0

Replace misleading definition of FIRST_USER_PGD_NR 0 by definition of
FIRST_USER_ADDRESS 0 in all the MMU architectures beyond arm and arm26.

Signed-off-by: Hugh Dickins <[email protected]>
---

include/asm-alpha/pgtable.h | 2 +-
include/asm-cris/pgtable.h | 2 +-
include/asm-frv/pgtable.h | 2 +-
include/asm-i386/pgtable.h | 2 +-
include/asm-ia64/pgtable.h | 2 +-
include/asm-m32r/pgtable.h | 2 +-
include/asm-m68k/pgtable.h | 2 +-
include/asm-mips/pgtable-32.h | 2 +-
include/asm-mips/pgtable-64.h | 2 +-
include/asm-parisc/pgtable.h | 2 +-
include/asm-ppc/pgtable.h | 2 +-
include/asm-ppc64/pgtable.h | 2 +-
include/asm-s390/pgtable.h | 4 ++--
include/asm-sh/pgtable.h | 2 +-
include/asm-sh64/pgtable.h | 2 +-
include/asm-sparc/pgtable.h | 2 +-
include/asm-sparc64/pgtable.h | 2 +-
include/asm-um/pgtable-2level.h | 2 +-
include/asm-um/pgtable-3level.h | 2 +-
include/asm-x86_64/pgtable.h | 2 +-
20 files changed, 21 insertions(+), 21 deletions(-)

--- 2.6.12-rc2-mm1/include/asm-alpha/pgtable.h 2005-04-05 15:20:54.000000000 +0100
+++ linux/include/asm-alpha/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -42,7 +42,7 @@
#define PTRS_PER_PMD (1UL << (PAGE_SHIFT-3))
#define PTRS_PER_PGD (1UL << (PAGE_SHIFT-3))
#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

/* Number of pointers that fit on a page: this will go away. */
#define PTRS_PER_PAGE (1UL << (PAGE_SHIFT-3))
--- 2.6.12-rc2-mm1/include/asm-cris/pgtable.h 2005-04-05 15:20:55.000000000 +0100
+++ linux/include/asm-cris/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -76,7 +76,7 @@ extern void paging_init(void);
*/

#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

/* zero page used for uninitialized stuff */
#ifndef __ASSEMBLY__
--- 2.6.12-rc2-mm1/include/asm-frv/pgtable.h 2005-04-05 15:20:55.000000000 +0100
+++ linux/include/asm-frv/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -141,7 +141,7 @@ extern unsigned long empty_zero_page;
#define PTRS_PER_PTE 4096

#define USER_PGDS_IN_LAST_PML4 (TASK_SIZE / PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
#define KERNEL_PGD_PTRS (PTRS_PER_PGD - USER_PGD_PTRS)
--- 2.6.12-rc2-mm1/include/asm-i386/pgtable.h 2005-04-05 15:20:55.000000000 +0100
+++ linux/include/asm-i386/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -60,7 +60,7 @@ void paging_init(void);
#define PGDIR_MASK (~(PGDIR_SIZE-1))

#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
#define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
--- 2.6.12-rc2-mm1/include/asm-ia64/pgtable.h 2005-04-05 15:22:58.000000000 +0100
+++ linux/include/asm-ia64/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -93,7 +93,7 @@
#define PGDIR_MASK (~(PGDIR_SIZE-1))
#define PTRS_PER_PGD (1UL << (PAGE_SHIFT-3))
#define USER_PTRS_PER_PGD (5*PTRS_PER_PGD/8) /* regions 0-4 are user regions */
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

/*
* Definitions for second level:
--- 2.6.12-rc2-mm1/include/asm-m32r/pgtable.h 2005-04-05 15:20:56.000000000 +0100
+++ linux/include/asm-m32r/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -51,7 +51,7 @@ extern unsigned long empty_zero_page[102
#define PGDIR_MASK (~(PGDIR_SIZE - 1))

#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#ifndef __ASSEMBLY__
/* Just any arbitrary offset to the start of the vmalloc VM area: the
--- 2.6.12-rc2-mm1/include/asm-m68k/pgtable.h 2005-04-05 15:20:56.000000000 +0100
+++ linux/include/asm-m68k/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -61,7 +61,7 @@
#define PTRS_PER_PGD 128
#endif
#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

/* Virtual address region for use by kernel_map() */
#ifdef CONFIG_SUN3
--- 2.6.12-rc2-mm1/include/asm-mips/pgtable-32.h 2005-03-02 07:38:57.000000000 +0000
+++ linux/include/asm-mips/pgtable-32.h 2005-04-05 18:59:00.000000000 +0100
@@ -74,7 +74,7 @@ extern int add_temporary_entry(unsigned
#define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))

#define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define VMALLOC_START KSEG2

--- 2.6.12-rc2-mm1/include/asm-mips/pgtable-64.h 2004-12-24 21:36:18.000000000 +0000
+++ linux/include/asm-mips/pgtable-64.h 2005-04-05 18:59:00.000000000 +0100
@@ -89,7 +89,7 @@
#define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))

#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define VMALLOC_START XKSEG
#define VMALLOC_END \
--- 2.6.12-rc2-mm1/include/asm-parisc/pgtable.h 2005-04-05 15:20:57.000000000 +0100
+++ linux/include/asm-parisc/pgtable.h 2005-04-05 18:59:00.000000000 +0100
@@ -120,7 +120,7 @@
* pgd entries used up by user/kernel:
*/

-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#ifndef __ASSEMBLY__
extern void *vmalloc_start;
--- 2.6.12-rc2-mm1/include/asm-ppc/pgtable.h 2005-04-05 15:20:57.000000000 +0100
+++ linux/include/asm-ppc/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -96,7 +96,7 @@ extern unsigned long ioremap_bot, iorema
#define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT))

#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT)
#define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
--- 2.6.12-rc2-mm1/include/asm-ppc64/pgtable.h 2005-04-05 15:22:59.000000000 +0100
+++ linux/include/asm-ppc64/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -41,7 +41,7 @@
#define PTRS_PER_PGD (1 << PGD_INDEX_SIZE)

#define USER_PTRS_PER_PGD (1024)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define EADDR_SIZE (PTE_INDEX_SIZE + PMD_INDEX_SIZE + \
PGD_INDEX_SIZE + PAGE_SHIFT)
--- 2.6.12-rc2-mm1/include/asm-s390/pgtable.h 2005-04-05 15:20:57.000000000 +0100
+++ linux/include/asm-s390/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -95,14 +95,14 @@ extern char empty_zero_page[PAGE_SIZE];
# define USER_PTRS_PER_PGD 512
# define USER_PGD_PTRS 512
# define KERNEL_PGD_PTRS 512
-# define FIRST_USER_PGD_NR 0
#else /* __s390x__ */
# define USER_PTRS_PER_PGD 2048
# define USER_PGD_PTRS 2048
# define KERNEL_PGD_PTRS 2048
-# define FIRST_USER_PGD_NR 0
#endif /* __s390x__ */

+#define FIRST_USER_ADDRESS 0
+
#define pte_ERROR(e) \
printk("%s:%d: bad pte %p.\n", __FILE__, __LINE__, (void *) pte_val(e))
#define pmd_ERROR(e) \
--- 2.6.12-rc2-mm1/include/asm-sh/pgtable.h 2005-04-05 15:20:58.000000000 +0100
+++ linux/include/asm-sh/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -44,7 +44,7 @@ extern unsigned long empty_zero_page[102
#define PGDIR_MASK (~(PGDIR_SIZE-1))

#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define PTE_PHYS_MASK 0x1ffff000

--- 2.6.12-rc2-mm1/include/asm-sh64/pgtable.h 2005-04-05 15:20:58.000000000 +0100
+++ linux/include/asm-sh64/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -238,7 +238,7 @@ static inline pmd_t * pmd_offset(pgd_t *

/* Round it up ! */
#define USER_PTRS_PER_PGD ((TASK_SIZE+PGDIR_SIZE-1)/PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#ifndef __ASSEMBLY__
#define VMALLOC_END 0xff000000
--- 2.6.12-rc2-mm1/include/asm-sparc/pgtable.h 2005-04-05 15:20:58.000000000 +0100
+++ linux/include/asm-sparc/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -63,7 +63,7 @@ BTFIXUPDEF_INT(page_kernel)
#define PTRS_PER_PMD BTFIXUP_SIMM13(ptrs_per_pmd)
#define PTRS_PER_PGD BTFIXUP_SIMM13(ptrs_per_pgd)
#define USER_PTRS_PER_PGD BTFIXUP_SIMM13(user_ptrs_per_pgd)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0
#define PTE_SIZE (PTRS_PER_PTE*4)

#define PAGE_NONE __pgprot(BTFIXUP_INT(page_none))
--- 2.6.12-rc2-mm1/include/asm-sparc64/pgtable.h 2005-04-05 15:22:59.000000000 +0100
+++ linux/include/asm-sparc64/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -78,7 +78,7 @@
#define PTRS_PER_PGD (1UL << PGDIR_BITS)

/* Kernel has a separate 44bit address space. */
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define pte_ERROR(e) __builtin_trap()
#define pmd_ERROR(e) __builtin_trap()
--- 2.6.12-rc2-mm1/include/asm-um/pgtable-2level.h 2005-04-05 15:20:58.000000000 +0100
+++ linux/include/asm-um/pgtable-2level.h 2005-04-05 18:59:01.000000000 +0100
@@ -23,7 +23,7 @@
#define PTRS_PER_PTE 1024
#define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
#define PTRS_PER_PGD 1024
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define pte_ERROR(e) \
printk("%s:%d: bad pte %p(%08lx).\n", __FILE__, __LINE__, &(e), \
--- 2.6.12-rc2-mm1/include/asm-um/pgtable-3level.h 2005-04-05 15:20:58.000000000 +0100
+++ linux/include/asm-um/pgtable-3level.h 2005-04-05 18:59:01.000000000 +0100
@@ -31,7 +31,7 @@
#define PTRS_PER_PMD 512
#define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
#define PTRS_PER_PGD 512
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#define pte_ERROR(e) \
printk("%s:%d: bad pte %p(%016lx).\n", __FILE__, __LINE__, &(e), \
--- 2.6.12-rc2-mm1/include/asm-x86_64/pgtable.h 2005-04-05 15:20:58.000000000 +0100
+++ linux/include/asm-x86_64/pgtable.h 2005-04-05 18:59:01.000000000 +0100
@@ -114,7 +114,7 @@ extern inline void pgd_clear (pgd_t * pg
#define PGDIR_MASK (~(PGDIR_SIZE-1))

#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
-#define FIRST_USER_PGD_NR 0
+#define FIRST_USER_ADDRESS 0

#ifndef __ASSEMBLY__
#define MAXMEM 0x3fffffffffffUL

2005-04-07 02:22:19

by Ian molton

[permalink] [raw]
Subject: Re: [PATCH 4/6] freepgt2: arm26 FIRST_USER_ADDRESS PAGE_SIZE

Hugh Dickins wrote:
> ARM26 define FIRST_USER_ADDRESS as PAGE_SIZE (beyond the machine vectors
> when they are mapped low), and use that definition in place of locally
> defined MIN_MAP_ADDR. Previously, ARM26 permitted user mappings at 0 if
> the machine vectors were mapped high; but that's inconsistent with ARM,
> and FIRST_USER_ADDRESS would then have to be determined at runtime.
> Let's fix it at PAGE_SIZE throughout the architecture.

This is correct because ARM26 cant map vectors high at all.

applied.

2005-04-07 10:15:09

by David Howells

[permalink] [raw]
Subject: Re: [PATCH 2/6] freepgt2: sys_mincore ignore FIRST_USER_PGD_NR

Hugh Dickins <[email protected]> wrote:

>
> Remove use of FIRST_USER_PGD_NR from sys_mincore: it's inconsistent (no
> other syscall refers to it), unnecessary (sys_mincore loops over vmas
> further down) and incorrect (misses user addresses in ARM's first pgd).

You should make it use FIRST_USER_ADDRESS instead. This check allows NULL
pointers and suchlike to be weeded out before having to take the semaphore.

Also, just because no other syscall refers to such a value doesn't mean that
this one shouldn't and that others shouldn't.

David

2005-04-07 14:31:45

by Nick Piggin

[permalink] [raw]
Subject: Re: [PATCH 2/6] freepgt2: sys_mincore ignore FIRST_USER_PGD_NR

David Howells wrote:
> Hugh Dickins <[email protected]> wrote:
>
>
>>Remove use of FIRST_USER_PGD_NR from sys_mincore: it's inconsistent (no
>>other syscall refers to it), unnecessary (sys_mincore loops over vmas
>>further down) and incorrect (misses user addresses in ARM's first pgd).
>
>
> You should make it use FIRST_USER_ADDRESS instead. This check allows NULL
> pointers and suchlike to be weeded out before having to take the semaphore.
>

I'm not sure whether it is worth keeping the singular special
case here to slightly speed up what would probably be a bug in
a userspace program.

--
SUSE Labs, Novell Inc.

2005-04-08 03:40:38

by Hugh Dickins

[permalink] [raw]
Subject: Re: [PATCH 2/6] freepgt2: sys_mincore ignore FIRST_USER_PGD_NR

On Fri, 8 Apr 2005, Nick Piggin wrote:
> David Howells wrote:
> > Hugh Dickins <[email protected]> wrote:
> >
> > > Remove use of FIRST_USER_PGD_NR from sys_mincore: it's inconsistent
> > > (no
> > > other syscall refers to it), unnecessary (sys_mincore loops over vmas
> > > further down) and incorrect (misses user addresses in ARM's first
> > > pgd).
> >
> > You should make it use FIRST_USER_ADDRESS instead. This check allows NULL
> > pointers and suchlike to be weeded out before having to take the
> > semaphore.
>
> I'm not sure whether it is worth keeping the singular special
> case here to slightly speed up what would probably be a bug in
> a userspace program.

Well put - though you're more diffident about it than I would be!

Furthermore, it only allows NULL pointers and suchlike to be weeded
out on the ARM (and ARM26) architecture, no other. I'm not averse
to optimizing ARM and ARM26, but it's much too insignificant an
optimization to warrant reference to such an architectural detail.

And it breaks the (peculiar) sys_mincore convention of doing all the
work while returning -ENOMEM, if there were any holes in the address
range. David's check stops it from doing any work in that case.

FIRST_USER_ADDRESS should be used in the very few places
it is necessary, and not spread around beyond them.

Hugh