Skip to contentSkip to conversation

switch the remaining architectures to use generic GUP v4

PATCH In review Christoph Hellwig 9 participants 40 messages Jun 25, 2019 – Aug 11, 2019

Subsystems (15)
lore
Share & tools
lore
#0 lore raw

Hi Linus and maintainers,

below is a series to switch mips, sh and sparc64 to use the generic GUP code so that we only have one codebase to touch for further improvements to this code. I don't have hardware for any of these architectures, and generally no clue about their page table management, so handle with care.

Changes since v3:
- improve a few commit messages
- clean up gup_fast_permitted a bit more
- split the code reordering in gup.c into a separate patch
- drop the patch to pass argument in a structure for now

Changes since v2:
- rebase to mainline to pick up the untagged_addr definition
- fix the gup range check to be start <= end to catch the 0 length case
- use pfn based version for the missing pud_page/pgd_page definitions
- fix a wrong check in the sparc64 version of pte_access_permitted

Changes since v1:
- fix various issues found by the build bot
- cherry pick and use the untagged_addr helper form Andrey
- add various refactoring patches to share more code over architectures
- move the powerpc hugepd code to mm/gup.c and sync it with the generic hup semantics

#1 lore raw

PATCH 1/16 mm: use untagged_addr() for get_user_pages_fast addresses

This will allow sparc64, or any future architecture with memory tagging to override its tags for get_user_pages and get_user_pages_fast.

---
 mm/gup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/gup.c +2 -2
index ddde097cf9e4..6bb521db67ec 100644
@@ -2146,7 +2146,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
 	unsigned long flags;
 	int nr = 0;
 
-	start &= PAGE_MASK;
+	start = untagged_addr(start) & PAGE_MASK;
 	len = (unsigned long) nr_pages << PAGE_SHIFT;
 	end = start + len;
 
@@ -2219,7 +2219,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages,
 	unsigned long addr, len, end;
 	int nr = 0, ret = 0;
 
-	start &= PAGE_MASK;
+	start = untagged_addr(start) & PAGE_MASK;
 	addr = start;
 	len = (unsigned long) nr_pages << PAGE_SHIFT;
 	end = start + len;
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/16 mm: simplify gup_fast_permitted

In reply to Christoph Hellwig

Pass in the already calculated end value instead of recomputing it, and leave the end > start check in the callers instead of duplicating them in the arch code.

---
 arch/s390/include/asm/pgtable.h   |  8 +-------
 arch/x86/include/asm/pgtable_64.h |  8 +-------
 mm/gup.c                          | 17 +++++++----------
 3 files changed, 9 insertions(+), 24 deletions(-)
arch/s390/include/asm/pgtable.h +1 -7
index 9f0195d5fa16..9b274fcaacb6 100644
@@ -1270,14 +1270,8 @@ static inline pte_t *pte_offset(pmd_t *pmd, unsigned long address)
 #define pte_offset_map(pmd, address) pte_offset_kernel(pmd, address)
 #define pte_unmap(pte) do { } while (0)
 
-static inline bool gup_fast_permitted(unsigned long start, int nr_pages)
+static inline bool gup_fast_permitted(unsigned long start, unsigned long end)
 {
-	unsigned long len, end;
-
-	len = (unsigned long) nr_pages << PAGE_SHIFT;
-	end = start + len;
-	if (end < start)
-		return false;
 	return end <= current->mm->context.asce_limit;
 }
 #define gup_fast_permitted gup_fast_permitted
arch/x86/include/asm/pgtable_64.h +1 -7
index 0bb566315621..4990d26dfc73 100644
@@ -259,14 +259,8 @@ extern void init_extra_mapping_uc(unsigned long phys, unsigned long size);
 extern void init_extra_mapping_wb(unsigned long phys, unsigned long size);
 
 #define gup_fast_permitted gup_fast_permitted
-static inline bool gup_fast_permitted(unsigned long start, int nr_pages)
+static inline bool gup_fast_permitted(unsigned long start, unsigned long end)
 {
-	unsigned long len, end;
-
-	len = (unsigned long)nr_pages << PAGE_SHIFT;
-	end = start + len;
-	if (end < start)
-		return false;
 	if (end >> __VIRTUAL_MASK_SHIFT)
 		return false;
 	return true;
mm/gup.c +7 -10
index 6bb521db67ec..3237f33792e6 100644
@@ -2123,13 +2123,9 @@ static void gup_pgd_range(unsigned long addr, unsigned long end,
  * Check if it's allowed to use __get_user_pages_fast() for the range, or
  * we need to fall back to the slow version:
  */
-bool gup_fast_permitted(unsigned long start, int nr_pages)
+static bool gup_fast_permitted(unsigned long start, unsigned long end)
 {
-	unsigned long len, end;
-
-	len = (unsigned long) nr_pages << PAGE_SHIFT;
-	end = start + len;
-	return end >= start;
+	return true;
 }
 #endif
 
@@ -2150,6 +2146,8 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
 	len = (unsigned long) nr_pages << PAGE_SHIFT;
 	end = start + len;
 
+	if (end <= start)
+		return 0;
 	if (unlikely(!access_ok((void __user *)start, len)))
 		return 0;
 
@@ -2165,7 +2163,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
 	 * block IPIs that come from THPs splitting.
 	 */
 
-	if (gup_fast_permitted(start, nr_pages)) {
+	if (gup_fast_permitted(start, end)) {
 		local_irq_save(flags);
 		gup_pgd_range(start, end, write ? FOLL_WRITE : 0, pages, &nr);
 		local_irq_restore(flags);
@@ -2224,13 +2222,12 @@ int get_user_pages_fast(unsigned long start, int nr_pages,
 	len = (unsigned long) nr_pages << PAGE_SHIFT;
 	end = start + len;
 
-	if (nr_pages <= 0)
+	if (end <= start)
 		return 0;
-
 	if (unlikely(!access_ok((void __user *)start, len)))
 		return -EFAULT;
 
-	if (gup_fast_permitted(start, nr_pages)) {
+	if (gup_fast_permitted(start, end)) {
 		local_irq_disable();
 		gup_pgd_range(addr, end, gup_flags, pages, &nr);
 		local_irq_enable();
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/16 mm: lift the x86_32 PAE version of gup_get_pte to common code

In reply to Christoph Hellwig

The split low/high access is the only non-READ_ONCE version of gup_get_pte that did show up in the various arch implemenations. Lift it to common code and drop the ifdef based arch override.

---
 arch/x86/Kconfig                      |  1 +
 arch/x86/include/asm/pgtable-3level.h | 47 ------------------------
 arch/x86/kvm/mmu.c                    |  2 +-
 mm/Kconfig                            |  3 ++
 mm/gup.c                              | 51 ++++++++++++++++++++++++---
 5 files changed, 52 insertions(+), 52 deletions(-)
arch/x86/Kconfig +1 -0
index 2bbbd4d1ba31..7cd53cc59f0f 100644
@@ -121,6 +121,7 @@ config X86
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
 	select GENERIC_TIME_VSYSCALL
+	select GUP_GET_PTE_LOW_HIGH		if X86_PAE
 	select HARDLOCKUP_CHECK_TIMESTAMP	if X86_64
 	select HAVE_ACPI_APEI			if ACPI
 	select HAVE_ACPI_APEI_NMI		if ACPI
arch/x86/include/asm/pgtable-3level.h +0 -47

53 lines not on this page · raw message

arch/x86/kvm/mmu.c +1 -1
index 98f6e4f88b04..4a9c63d1c20a 100644
@@ -650,7 +650,7 @@ static u64 __update_clear_spte_slow(u64 *sptep, u64 spte)
 
 /*
  * The idea using the light way get the spte on x86_32 guest is from
- * gup_get_pte(arch/x86/mm/gup.c).
+ * gup_get_pte (mm/gup.c).
  *
  * An spte tlb flush may be pending, because kvm_set_pte_rmapp
  * coalesces them and we are running out of the MMU lock.  Therefore
mm/Kconfig +3 -0
index f0c76ba47695..fe51f104a9e0 100644
@@ -762,6 +762,9 @@ config GUP_BENCHMARK
 
 	  See tools/testing/selftests/vm/gup_benchmark.c
 
+config GUP_GET_PTE_LOW_HIGH
+	bool
+
 config ARCH_HAS_PTE_SPECIAL
 	bool
 
mm/gup.c +47 -4

64 lines not on this page · raw message

Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/16 MIPS: use the generic get_user_pages_fast code

In reply to Christoph Hellwig

The mips code is mostly equivalent to the generic one, minus various bugfixes and an arch override for gup_fast_permitted.

Note that this defines ARCH_HAS_PTE_SPECIAL for mips as mips has pte_special and pte_mkspecial implemented and used in the existing gup code. They are no-op stubs, though which makes me a little unsure if this is really right thing to do.

Note that this also adds back a missing cpu_has_dc_aliases check for __get_user_pages_fast, which the old code was only doing for get_user_pages_fast. This clearly looks like an oversight, as any condition that makes get_user_pages_fast unsafe also applies to __get_user_pages_fast.

---
 arch/mips/Kconfig               |   3 +
 arch/mips/include/asm/pgtable.h |   3 +
 arch/mips/mm/Makefile           |   1 -
 arch/mips/mm/gup.c              | 303 --------------------------------
 4 files changed, 6 insertions(+), 304 deletions(-)
 delete mode 100644 arch/mips/mm/gup.c
arch/mips/Kconfig +3 -0
index 70d3200476bf..64108a2a16d4 100644
@@ -6,6 +6,7 @@ config MIPS
 	select ARCH_BINFMT_ELF_STATE if MIPS_FP_SUPPORT
 	select ARCH_CLOCKSOURCE_DATA
 	select ARCH_HAS_ELF_RANDOMIZE
+	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select ARCH_HAS_UBSAN_SANITIZE_ALL
 	select ARCH_SUPPORTS_UPROBES
@@ -34,6 +35,7 @@ config MIPS
 	select GENERIC_SCHED_CLOCK if !CAVIUM_OCTEON_SOC
 	select GENERIC_SMP_IDLE_THREAD
 	select GENERIC_TIME_VSYSCALL
+	select GUP_GET_PTE_LOW_HIGH if CPU_MIPS32 && PHYS_ADDR_T_64BIT
 	select HANDLE_DOMAIN_IRQ
 	select HAVE_ARCH_COMPILER_H
 	select HAVE_ARCH_JUMP_LABEL
@@ -55,6 +57,7 @@ config MIPS
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_FUNCTION_TRACER
+	select HAVE_GENERIC_GUP
 	select HAVE_IDE
 	select HAVE_IOREMAP_PROT
 	select HAVE_IRQ_EXIT_ON_IRQ_STACK
arch/mips/include/asm/pgtable.h +3 -0
index 4ccb465ef3f2..7d27194e3b45 100644
@@ -20,6 +20,7 @@
 #include <asm/cmpxchg.h>
 #include <asm/io.h>
 #include <asm/pgtable-bits.h>
+#include <asm/cpu-features.h>
 
 struct mm_struct;
 struct vm_area_struct;
@@ -626,6 +627,8 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
 
 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
+#define gup_fast_permitted(start, end)	(!cpu_has_dc_aliases)
+
 #include <asm-generic/pgtable.h>
 
 /*
arch/mips/mm/Makefile +0 -1
index f34d7ff5eb60..1e8d335025d7 100644
@@ -7,7 +7,6 @@ obj-y				+= cache.o
 obj-y				+= context.o
 obj-y				+= extable.o
 obj-y				+= fault.o
-obj-y				+= gup.o
 obj-y				+= init.o
 obj-y				+= mmap.o
 obj-y				+= page.o
arch/mips/mm/gup.c deleted +0 -303

303 lines not on this page · raw message

Signature · 1 line
2.20.1
#5 lore raw

Re: [PATCH 04/16] MIPS: use the generic get_user_pages_fast code

Hi,

Quoted 8 lines · Christoph Hellwig

The mips code is mostly equivalent to the generic one, minus various bugfixes and an arch override for gup_fast_permitted.

Note that this defines ARCH_HAS_PTE_SPECIAL for mips as mips has pte_special and pte_mkspecial implemented and used in the existing gup code. They are no-op stubs, though which makes me a little unsure if this is really right thing to do.

Quoted 8 lines

Note that this also adds back a missing cpu_has_dc_aliases check for __get_user_pages_fast, which the old code was only doing for get_user_pages_fast. This clearly looks like an oversight, as any condition that makes get_user_pages_fast unsafe also applies to __get_user_pages_fast.

This patch causes all mips images (mips, mips64, mipsel, mipsel64) to crash when booting in qemu. Unfortunately the patch can not be reverted easily since there are context changes, causing build failures after the revert, so I can not verify if this is the only problem.

Crash log (same for all variants):

...
Run /sbin/init as init process

BUG: Bad page map in process mount  pte:00b70401 pmd:8e5dc000
page:80c24880 refcount:1 mapcount:-1 mapping:00000000 index:0x0
flags: 0x1000(reserved)
raw: 00001000 80c24884 80c24884 00000000 00000000 00000000 fffffffe 00000001
page dumped because: bad pte

addr:(ptrval) vm_flags:04044411 anon_vma:(ptrval) mapping:(ptrval) index:0
qemu-system-mips: terminating on signal 15 from pid 13034 (/bin/bash)

Guenter

---
bisect log:

# bad: [48568d8c7f479ec45b9c3d02b4b1895f3ef61a03] Add linux-next specific files for 20190628
# good: [4b972a01a7da614b4796475f933094751a295a2f] Linux 5.2-rc6
git bisect start 'HEAD' 'v5.2-rc6'
# good: [89a77c9176fe88f68c3bf7bd255cfea6797258d4] Merge remote-tracking branch 'crypto/master'
git bisect good 89a77c9176fe88f68c3bf7bd255cfea6797258d4
# good: [2cedca636ad73ed838bd636685b245404e490c73] Merge remote-tracking branch 'security/next-testing' git bisect good 2cedca636ad73ed838bd636685b245404e490c73
# good: [ea260819fdc2f8a64e6c87f3ad80ecc5e4015921] Merge remote-tracking branch 'char-misc/char-misc-next' git bisect good ea260819fdc2f8a64e6c87f3ad80ecc5e4015921
# good: [aca42ca2a32eacf804ac56a33526f049debc8ec0] Merge remote-tracking branch 'rpmsg/for-next'
git bisect good aca42ca2a32eacf804ac56a33526f049debc8ec0
# good: [f4cd0c7f3c07876f7173b5306e974644c6eec141] Merge remote-tracking branch 'pidfd/for-next'
git bisect good f4cd0c7f3c07876f7173b5306e974644c6eec141
# bad: [09c57a8ab1fc3474b4a620247a0f9e3ac61c4cfe] mm/sparsemem: support sub-section hotplug
git bisect bad 09c57a8ab1fc3474b4a620247a0f9e3ac61c4cfe
# good: [aaffcf10880c363870413c5cdee5dfb6a923e9ae] mm: memcontrol: dump memory.stat during cgroup OOM git bisect good aaffcf10880c363870413c5cdee5dfb6a923e9ae
# bad: [81d90bb2d2784258ed7c0762ecf34d4665198bad] um: switch to generic version of pte allocation git bisect bad 81d90bb2d2784258ed7c0762ecf34d4665198bad
# bad: [dadae650472841f004882a2409aa844e37809c60] sparc64-add-the-missing-pgd_page-definition-fix git bisect bad dadae650472841f004882a2409aa844e37809c60
# good: [d1edd06c6ac8c8c49345ff34de1c72ee571f3f7b] mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages git bisect good d1edd06c6ac8c8c49345ff34de1c72ee571f3f7b
# good: [b1ceaacca9e63794bd3f574c928e7e6aca01bce7] mm: simplify gup_fast_permitted
git bisect good b1ceaacca9e63794bd3f574c928e7e6aca01bce7
# bad: [59f238b3353caf43b118e1bb44010aa1abd56d7f] sh: add the missing pud_page definition
git bisect bad 59f238b3353caf43b118e1bb44010aa1abd56d7f
# bad: [93a184240a74cb0242b9b970f0bc018c4fdf24fd] MIPS: use the generic get_user_pages_fast code
git bisect bad 93a184240a74cb0242b9b970f0bc018c4fdf24fd
# good: [7c6a77cff73127e9495e345a0903d55b1b0fb323] mm: lift the x86_32 PAE version of gup_get_pte to common code git bisect good 7c6a77cff73127e9495e345a0903d55b1b0fb323

# first bad commit: [93a184240a74cb0242b9b970f0bc018c4fdf24fd] MIPS: use the generic get_user_pages_fast code
#6 lore raw

PATCH 5/16 sh: add the missing pud_page definition

In reply to Christoph Hellwig

sh only had pud_page_vaddr, but not pud_page.

---
 arch/sh/include/asm/pgtable-3level.h | 1 +
 1 file changed, 1 insertion(+)
arch/sh/include/asm/pgtable-3level.h +1 -0
index 7d8587eb65ff..3c7ff20f3f94 100644
@@ -37,6 +37,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
 {
 	return pud_val(pud);
 }
+#define pud_page(pud)		pfn_to_page(pud_pfn(pud))
 
 #define pmd_index(address)	(((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
Signature · 1 line
2.20.1
#7 lore raw

PATCH 6/16 sh: use the generic get_user_pages_fast code

In reply to Christoph Hellwig

The sh code is mostly equivalent to the generic one, minus various bugfixes and two arch overrides that this patch adds to pgtable.h.

---
 arch/sh/Kconfig               |   2 +
 arch/sh/include/asm/pgtable.h |  37 +++++
 arch/sh/mm/Makefile           |   2 +-
 arch/sh/mm/gup.c              | 277 ----------------------------------
 4 files changed, 40 insertions(+), 278 deletions(-)
 delete mode 100644 arch/sh/mm/gup.c
arch/sh/Kconfig +2 -0
index b77f512bb176..6fddfc3c9710 100644
@@ -14,6 +14,7 @@ config SUPERH
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_PERF_EVENTS
 	select HAVE_DEBUG_BUGVERBOSE
+	select HAVE_GENERIC_GUP
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
 	select ARCH_HAS_GCOV_PROFILE_ALL
@@ -63,6 +64,7 @@ config SUPERH
 config SUPERH32
 	def_bool "$(ARCH)" = "sh"
 	select ARCH_32BIT_OFF_T
+	select GUP_GET_PTE_LOW_HIGH if X2TLB
 	select HAVE_KPROBES
 	select HAVE_KRETPROBES
 	select HAVE_IOREMAP_PROT if MMU && !X2TLB
arch/sh/include/asm/pgtable.h +37 -0
index 3587103afe59..9085d1142fa3 100644
@@ -149,6 +149,43 @@ extern void paging_init(void);
 extern void page_table_range_init(unsigned long start, unsigned long end,
 				  pgd_t *pgd);
 
+static inline bool __pte_access_permitted(pte_t pte, u64 prot)
+{
+	return (pte_val(pte) & (prot | _PAGE_SPECIAL)) = prot;
+}
+
+#ifdef CONFIG_X2TLB
+static inline bool pte_access_permitted(pte_t pte, bool write)
+{
+	u64 prot = _PAGE_PRESENT;
+
+	prot |= _PAGE_EXT(_PAGE_EXT_KERN_READ | _PAGE_EXT_USER_READ);
+	if (write)
+		prot |= _PAGE_EXT(_PAGE_EXT_KERN_WRITE | _PAGE_EXT_USER_WRITE);
+	return __pte_access_permitted(pte, prot);
+}
+#elif defined(CONFIG_SUPERH64)
+static inline bool pte_access_permitted(pte_t pte, bool write)
+{
+	u64 prot = _PAGE_PRESENT | _PAGE_USER | _PAGE_READ;
+
+	if (write)
+		prot |= _PAGE_WRITE;
+	return __pte_access_permitted(pte, prot);
+}
+#else
+static inline bool pte_access_permitted(pte_t pte, bool write)
+{
+	u64 prot = _PAGE_PRESENT | _PAGE_USER;
+
+	if (write)
+		prot |= _PAGE_RW;
+	return __pte_access_permitted(pte, prot);
+}
+#endif
+
+#define pte_access_permitted pte_access_permitted
+
 /* arch/sh/mm/mmap.c */
 #define HAVE_ARCH_UNMAPPED_AREA
 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
arch/sh/mm/Makefile +1 -1
index fbe5e79751b3..5051b38fd5b6 100644
@@ -17,7 +17,7 @@ cacheops-$(CONFIG_CPU_SHX3)		+= cache-shx3.o
 obj-y			+= $(cacheops-y)
 
 mmu-y			:= nommu.o extable_32.o
-mmu-$(CONFIG_MMU)	:= extable_$(BITS).o fault.o gup.o ioremap.o kmap.o \
+mmu-$(CONFIG_MMU)	:= extable_$(BITS).o fault.o ioremap.o kmap.o \
 			   pgtable.o tlbex_$(BITS).o tlbflush_$(BITS).o
 
 obj-y			+= $(mmu-y)
arch/sh/mm/gup.c deleted +0 -277

277 lines not on this page · raw message

Signature · 1 line
2.20.1
#8 lore raw

Re: [PATCH 06/16] sh: use the generic get_user_pages_fast code

Quoted 4 lines · Christoph Hellwig

The sh code is mostly equivalent to the generic one, minus various bugfixes and two arch overrides that this patch adds to pgtable.h.

sh:defconfig no longer builds with this patch applied.

mm/gup.c: In function 'gup_huge_pud':
arch/sh/include/asm/pgtable-3level.h:40:36: error:
implicit declaration of function 'pud_pfn'; did you mean 'pte_pfn'?

Bisect log attached.

Guenter

---
# bad: [48568d8c7f479ec45b9c3d02b4b1895f3ef61a03] Add linux-next specific files for 20190628
# good: [4b972a01a7da614b4796475f933094751a295a2f] Linux 5.2-rc6
git bisect start 'HEAD' 'v5.2-rc6'
# good: [89a77c9176fe88f68c3bf7bd255cfea6797258d4] Merge remote-tracking branch 'crypto/master'
git bisect good 89a77c9176fe88f68c3bf7bd255cfea6797258d4
# good: [2cedca636ad73ed838bd636685b245404e490c73] Merge remote-tracking branch 'security/next-testing' git bisect good 2cedca636ad73ed838bd636685b245404e490c73
# good: [ea260819fdc2f8a64e6c87f3ad80ecc5e4015921] Merge remote-tracking branch 'char-misc/char-misc-next' git bisect good ea260819fdc2f8a64e6c87f3ad80ecc5e4015921
# good: [aca42ca2a32eacf804ac56a33526f049debc8ec0] Merge remote-tracking branch 'rpmsg/for-next'
git bisect good aca42ca2a32eacf804ac56a33526f049debc8ec0
# good: [f4cd0c7f3c07876f7173b5306e974644c6eec141] Merge remote-tracking branch 'pidfd/for-next'
git bisect good f4cd0c7f3c07876f7173b5306e974644c6eec141
# bad: [09c57a8ab1fc3474b4a620247a0f9e3ac61c4cfe] mm/sparsemem: support sub-section hotplug
git bisect bad 09c57a8ab1fc3474b4a620247a0f9e3ac61c4cfe
# good: [aaffcf10880c363870413c5cdee5dfb6a923e9ae] mm: memcontrol: dump memory.stat during cgroup OOM git bisect good aaffcf10880c363870413c5cdee5dfb6a923e9ae
# bad: [81d90bb2d2784258ed7c0762ecf34d4665198bad] um: switch to generic version of pte allocation git bisect bad 81d90bb2d2784258ed7c0762ecf34d4665198bad
# bad: [dadae650472841f004882a2409aa844e37809c60] sparc64-add-the-missing-pgd_page-definition-fix git bisect bad dadae650472841f004882a2409aa844e37809c60
# good: [d1edd06c6ac8c8c49345ff34de1c72ee571f3f7b] mm: memcg/slab: stop setting page->mem_cgroup pointer for slab pages git bisect good d1edd06c6ac8c8c49345ff34de1c72ee571f3f7b
# good: [b1ceaacca9e63794bd3f574c928e7e6aca01bce7] mm: simplify gup_fast_permitted
git bisect good b1ceaacca9e63794bd3f574c928e7e6aca01bce7
# good: [59f238b3353caf43b118e1bb44010aa1abd56d7f] sh: add the missing pud_page definition
git bisect good 59f238b3353caf43b118e1bb44010aa1abd56d7f
# bad: [51bbf54b3f26a85217db720f4e5b01a6c4d3f010] sparc64: add the missing pgd_page definition
git bisect bad 51bbf54b3f26a85217db720f4e5b01a6c4d3f010
# bad: [be748d6e72113580af7e37ad68a0047659e60189] sh: use the generic get_user_pages_fast code
git bisect bad be748d6e72113580af7e37ad68a0047659e60189

# first bad commit: [be748d6e72113580af7e37ad68a0047659e60189] sh: use the generic get_user_pages_fast code
#9 lore raw

PATCH 7/16 sparc64: add the missing pgd_page definition

In reply to Christoph Hellwig

sparc64 only had pgd_page_vaddr, but not pgd_page.

---
 arch/sparc/include/asm/pgtable_64.h | 1 +
 1 file changed, 1 insertion(+)
arch/sparc/include/asm/pgtable_64.h +1 -0
index 22500c3be7a9..f0dcf991d27f 100644
@@ -861,6 +861,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
 #define pud_clear(pudp)			(pud_val(*(pudp)) = 0UL)
 #define pgd_page_vaddr(pgd)		\
 	((unsigned long) __va(pgd_val(pgd)))
+#define pgd_page(pgd)			pfn_to_page(pgd_pfn(pgd))
 #define pgd_present(pgd)		(pgd_val(pgd) != 0U)
 #define pgd_clear(pgdp)			(pgd_val(*(pgdp)) = 0UL)
 
Signature · 1 line
2.20.1
#10 lore raw

PATCH 8/16 sparc64: define untagged_addr()

In reply to Christoph Hellwig

Add a helper to untag a user pointer. This is needed for ADI support in get_user_pages_fast.

---
 arch/sparc/include/asm/pgtable_64.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
arch/sparc/include/asm/pgtable_64.h +22 -0
index f0dcf991d27f..1904782dcd39 100644
@@ -1076,6 +1076,28 @@ static inline int io_remap_pfn_range(struct vm_area_struct *vma,
 }
 #define io_remap_pfn_range io_remap_pfn_range 
 
+static inline unsigned long untagged_addr(unsigned long start)
+{
+	if (adi_capable()) {
+		long addr = start;
+
+		/* If userspace has passed a versioned address, kernel
+		 * will not find it in the VMAs since it does not store
+		 * the version tags in the list of VMAs. Storing version
+		 * tags in list of VMAs is impractical since they can be
+		 * changed any time from userspace without dropping into
+		 * kernel. Any address search in VMAs will be done with
+		 * non-versioned addresses. Ensure the ADI version bits
+		 * are dropped here by sign extending the last bit before
+		 * ADI bits. IOMMU does not implement version tags.
+		 */
+		return (addr << (long)adi_nbits()) >> (long)adi_nbits();
+	}
+
+	return start;
+}
+#define untagged_addr untagged_addr
+
 #include <asm/tlbflush.h>
 #include <asm-generic/pgtable.h>
 
Signature · 1 line
2.20.1
#11 lore raw

PATCH 9/16 sparc64: use the generic get_user_pages_fast code

In reply to Christoph Hellwig

The sparc64 code is mostly equivalent to the generic one, minus various bugfixes and two arch overrides that this patch adds to pgtable.h.

---
 arch/sparc/Kconfig                  |   1 +
 arch/sparc/include/asm/pgtable_64.h |  18 ++
 arch/sparc/mm/Makefile              |   2 +-
 arch/sparc/mm/gup.c                 | 340 ----------------------------
 4 files changed, 20 insertions(+), 341 deletions(-)
 delete mode 100644 arch/sparc/mm/gup.c
arch/sparc/Kconfig +1 -0
index 26ab6f5bbaaf..22435471f942 100644
@@ -28,6 +28,7 @@ config SPARC
 	select RTC_DRV_M48T59
 	select RTC_SYSTOHC
 	select HAVE_ARCH_JUMP_LABEL if SPARC64
+	select HAVE_GENERIC_GUP if SPARC64
 	select GENERIC_IRQ_SHOW
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select GENERIC_PCI_IOMAP
arch/sparc/include/asm/pgtable_64.h +18 -0
index 1904782dcd39..547ff96fb228 100644
@@ -1098,6 +1098,24 @@ static inline unsigned long untagged_addr(unsigned long start)
 }
 #define untagged_addr untagged_addr
 
+static inline bool pte_access_permitted(pte_t pte, bool write)
+{
+	u64 prot;
+
+	if (tlb_type = hypervisor) {
+		prot = _PAGE_PRESENT_4V | _PAGE_P_4V;
+		if (write)
+			prot |= _PAGE_WRITE_4V;
+	} else {
+		prot = _PAGE_PRESENT_4U | _PAGE_P_4U;
+		if (write)
+			prot |= _PAGE_WRITE_4U;
+	}
+
+	return (pte_val(pte) & (prot | _PAGE_SPECIAL)) = prot;
+}
+#define pte_access_permitted pte_access_permitted
+
 #include <asm/tlbflush.h>
 #include <asm-generic/pgtable.h>
 
arch/sparc/mm/Makefile +1 -1
index d39075b1e3b7..b078205b70e0 100644
@@ -5,7 +5,7 @@
 asflags-y := -ansi
 ccflags-y := -Werror
 
-obj-$(CONFIG_SPARC64)   += ultra.o tlb.o tsb.o gup.o
+obj-$(CONFIG_SPARC64)   += ultra.o tlb.o tsb.o
 obj-y                   += fault_$(BITS).o
 obj-y                   += init_$(BITS).o
 obj-$(CONFIG_SPARC32)   += extable.o srmmu.o iommu.o io-unit.o
arch/sparc/mm/gup.c deleted +0 -340

340 lines not on this page · raw message

Signature · 1 line
2.20.1
#12 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Hi,

Quoted 5 lines · Christoph Hellwig

The sparc64 code is mostly equivalent to the generic one, minus various bugfixes and two arch overrides that this patch adds to pgtable.h.

Quoted 7 lines
---
 arch/sparc/Kconfig                  |   1 +
 arch/sparc/include/asm/pgtable_64.h |  18 ++
 arch/sparc/mm/Makefile              |   2 +-
 arch/sparc/mm/gup.c                 | 340 ----------------------------
 4 files changed, 20 insertions(+), 341 deletions(-)
 delete mode 100644 arch/sparc/mm/gup.c

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505 (thanks to Anatoly for bisecting) and introduced a regression:
futex.test from the strace test suite now causes an Oops on sparc64 in futex syscall.

Here is a heavily stripped down reproducer:

// SPDX-License-Identifier: GPL-2.0-or-later
#include <err.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <asm/unistd.h>
int main(void)

{
	size_t page_size = sysconf(_SC_PAGESIZE);
	size_t alloc_size = 3 * page_size;
	void *p = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE,
		       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
	if (MAP_FAILED == p)
		err(EXIT_FAILURE, "mmap(%zu)", alloc_size);
	void *hole = p + page_size;
	if (munmap(hole, page_size))
		err(EXIT_FAILURE, "munmap(%p, %zu)", hole, page_size);
	syscall(__NR_futex, (unsigned long) hole, 0L, 0L, 0L, 0L, 0L);
	return 0;
}
Signature · 1 line
ldv
#13 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Quoted 5 lines · Dmitry V. Levin

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505 (thanks to Anatoly for bisecting) and introduced a regression:
futex.test from the strace test suite now causes an Oops on sparc64 in futex syscall.

Can you post the oops here in the same thread too? Maybe it's already posted somewhere else, but I can't seem to find anything likely on lkml at least..

On x86-64, it obviously just causes the (expected) EFAULT error from the futex call.

Somebody with access to sparc64 probably needs to debug this, but having the exact oops wouldn't hurt...

Linus

#14 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Quoted 10 lines · Linus Torvalds
Quoted 5 lines · Dmitry V. Levin

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505 (thanks to Anatoly for bisecting) and introduced a regression:
futex.test from the strace test suite now causes an Oops on sparc64 in futex syscall.

Can you post the oops here in the same thread too? Maybe it's already posted somewhere else, but I can't seem to find anything likely on lkml at least..

Sure, here it is:

[  514.137217] Unable to handle kernel paging request at virtual address 00060000541d0000
[  514.137295] tsk->{mm,active_mm}->context = 00000000000005b2
[  514.137343] tsk->{mm,active_mm}->pgd = fff80024955a2000
[  514.137387]               \|/ ____ \|/
                             "@'/ .. \`@"
                             /_| \__/ |_\
                                \__U_/
[  514.137493] futex(1599): Oops [#1]
[  514.137533] CPU: 26 PID: 1599 Comm: futex Not tainted 5.2.0-05721-gd3649f68b433 #1096
[  514.137595] TSTATE: 0000000011001603 TPC: 000000000051adc4 TNPC: 000000000051adc8 Y: 00000000    Not tainted
[  514.137678] TPC: <get_futex_key+0xe4/0x6a0>
[  514.137712] g0: 0000000000000000 g1: 0000000000e75178 g2: 000000000009a21d g3: 0000000000000000
[  514.137769] g4: fff8002474fbc0e0 g5: fff80024aa80c000 g6: fff8002495aec000 g7: 0000000000000200
[  514.137825] o0: 0000000000000001 o1: 0000000000000001 o2: 0000000000000000 o3: fff8002495aefa28
[  514.137882] o4: fff8000100030000 o5: fff800010002e000 sp: fff8002495aef161 ret_pc: 000000000051ada4
[  514.137944] RPC: <get_futex_key+0xc4/0x6a0>
[  514.137978] l0: 000000000051b144 l1: 0000000000000001 l2: 0000000000c01950 l3: fff80024626051c0
[  514.138036] l4: 0000000000c01970 l5: 0000000000cf6800 l6: 00060000541d13f0 l7: 00000000014b3000
[  514.138094] i0: 0000000000000001 i1: 000000000051af30 i2: fff8002495aefc28 i3: 0000000000000001
[  514.138152] i4: 0000000000cf69b0 i5: fff800010002e000 i6: fff8002495aef231 i7: 000000000051b3a8
[  514.138211] I7: <futex_wait_setup+0x28/0x120>
[  514.138245] Call Trace:
[  514.138271]  [000000000051b3a8] futex_wait_setup+0x28/0x120
[  514.138313]  [000000000051b550] futex_wait+0xb0/0x200
[  514.138352]  [000000000051d734] do_futex+0xd4/0xc00
[  514.138390]  [000000000051e384] sys_futex+0x124/0x140
[  514.138435]  [0000000000406294] linux_sparc_syscall+0x34/0x44
[  514.138478] Disabling lock debugging due to kernel taint
[  514.138501] Caller[000000000051b3a8]: futex_wait_setup+0x28/0x120
[  514.138524] Caller[000000000051b550]: futex_wait+0xb0/0x200
[  514.138547] Caller[000000000051d734]: do_futex+0xd4/0xc00
[  514.138568] Caller[000000000051e384]: sys_futex+0x124/0x140
[  514.138590] Caller[0000000000406294]: linux_sparc_syscall+0x34/0x44
[  514.138614] Caller[0000010000000e90]: 0x10000000e90
[  514.138633] Instruction DUMP:
[  514.138635]  0640016e 
[  514.138650]  b13da000 
[  514.138663]  ec5fa7f7 
[  514.138676] <c25da008>
[  514.138689]  ae100016 
[  514.138702]  84086001 
[  514.138714]  82007fff 
[  514.138727]  af789401 
[  514.138740]  f05de018 
Signature · 1 line
ldv
#15 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Quoted 2 lines · Dmitry V. Levin

Sure, here it is:

Hmm. I'm not seeing anything obviously wrong in the generic gup conversion.

From the oops, I assume that the problem is that get_user_pages_fast() returned an invalid page, causing the bad access later in get_futex_key(). But that's odd too, considering that get_user_pages_fast() had already accessed the page (both for looking up the head, and for then doing things like SetPageReferenced(page)).

The only half-way subtle thing is the pte_access_permitted() movement, but it looks like it matches what gup_pte_range() did in the original sparc64 code. And the address masking is done the same way too, as far as I can tell.

So clearly there's something wrong there, but I'm not seeing it. Maybe I'm incorrectly looking at that pte case, and the problem happened earlier.

Anyway, I suspect some sparc64 person needs to delve into it.

I know this got reviewed by sparc64 people (the final commit message only has a single Reviewed-by, but I see an Ack by Davem in my maill that seems to have gotten lost by the time the patch made it in), but maybe actually nobody ever _tested_ it until it hit my tree?

Linus

maintainer
#16 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

From: Linus Torvalds <[email protected]>
Date: Wed, 17 Jul 2019 17:17:16 -0700

Quoted 1 line

Anyway, I suspect some sparc64 person needs to delve into it.

I'll take a look at it soon if someone doesn't figure it out before me.

maintainer
#17 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

In reply to Linus Torvalds

From: Linus Torvalds <[email protected]>
Date: Wed, 17 Jul 2019 17:17:16 -0700

Quoted 3 lines

From the oops, I assume that the problem is that get_user_pages_fast() returned an invalid page, causing the bad access later in get_futex_key().

That's correct. It's the first deref of page that oops's.

Quoted 3 lines

But that's odd too, considering that get_user_pages_fast() had already accessed the page (both for looking up the head, and for then doing things like SetPageReferenced(page)).

Even the huge page cases all do that dereference as well, so it is indeed a mystery how the pointer works inside of get_user_pages_fast() but becomes garbage in the caller.

This page pointer sits on the stack, so maybe something stores garbage there meanwhile. Maybe the issue is even compiler dependent.

I'll keep looking over the changes made here for clues.

maintainer
#18 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

In reply to Dmitry V. Levin

From: "Dmitry V. Levin" <[email protected]>
Date: Thu, 18 Jul 2019 00:59:56 +0300

Quoted 6 lines

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505 (thanks to Anatoly for bisecting) and introduced a regression:
futex.test from the strace test suite now causes an Oops on sparc64 in futex syscall.

Here is a heavily stripped down reproducer:

Does not reproduce for me on a T4-2 machine.

So this problem might depend on the type of system you are on, I suspect it's one of those "pre-Niagara vs. Niagara and later" situations because that's the dividing line between two set of wildly different TLB and cache management methods.

What kind of machine are you on?

#19 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Quoted 10 lines · David Miller

From: "Dmitry V. Levin" <[email protected]>
Date: Thu, 18 Jul 2019 00:59:56 +0300

Quoted 6 lines

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505 (thanks to Anatoly for bisecting) and introduced a regression:
futex.test from the strace test suite now causes an Oops on sparc64 in futex syscall.

Here is a heavily stripped down reproducer:

Quoted 8 lines

Does not reproduce for me on a T4-2 machine.

So this problem might depend on the type of system you are on, I suspect it's one of those "pre-Niagara vs. Niagara and later" situations because that's the dividing line between two set of wildly different TLB and cache management methods.

What kind of machine are you on?

FYI, I'm pretty sure I tested this on Guenthers build test qemu setup in the end, which further speaks for the different machines issue.

#20 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

In reply to David Miller
Quoted 7 lines · David Miller
Quoted 6 lines

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505 (thanks to Anatoly for bisecting) and introduced a regression:
futex.test from the strace test suite now causes an Oops on sparc64 in futex syscall.

Here is a heavily stripped down reproducer:

Quoted 8 lines

Does not reproduce for me on a T4-2 machine.

So this problem might depend on the type of system you are on, I suspect it's one of those "pre-Niagara vs. Niagara and later" situations because that's the dividing line between two set of wildly different TLB and cache management methods.

What kind of machine are you on?

David,

the first test where it was discovered was done on my test LDOM named ttip, hardware (hypervisor) is T5-2 server, running under Solaris 11.4 OS.
ttip LDOM is debian sparc64 unstable , so with almost all the latest software (gcc 8.3.0, binutils 2.32.51.20190707-1, debian GLIBC 2.28-10, etc..)

For another test, i also installed LDOM with oracle sparc linux
https://oss.oracle.com/projects/linux-sparc/ , but I've to install a more fresh version of gcc on it first, since system installed gcc 4.4 is too old for a git kernel (linux-2.6/Documentation/Changes lists gcc 4.6 as a minimal version), so I choose to install gcc-7.4.0 to /opt/ (leaving system installed gcc 4.4 under /usr/bin). Compiled and installed git kernel version, i.e. last tag 5.3.0-rc1 and ran the test. Kernel still produced oops.

maintainer
#21 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

From: Anatoly Pugachev <[email protected]>
Date: Wed, 24 Jul 2019 22:32:17 +0300

Quoted 7 lines

the first test where it was discovered was done on my test LDOM named ttip, hardware (hypervisor) is T5-2 server, running under Solaris 11.4 OS.
ttip LDOM is debian sparc64 unstable , so with almost all the latest software (gcc 8.3.0, binutils 2.32.51.20190707-1, debian GLIBC 2.28-10, etc..)

Quoted 8 lines

For another test, i also installed LDOM with oracle sparc linux
https://oss.oracle.com/projects/linux-sparc/ , but I've to install a more fresh version of gcc on it first, since system installed gcc 4.4 is too old for a git kernel (linux-2.6/Documentation/Changes lists gcc 4.6 as a minimal version), so I choose to install gcc-7.4.0 to /opt/ (leaving system installed gcc 4.4 under /usr/bin). Compiled and installed git kernel version, i.e. last tag 5.3.0-rc1 and ran the test. Kernel still produced oops.

I suspect, therefore, that we have a miscompile.

Please put your unstripped vmlinux image somewhere so I can take a closer look.

Thank you.

#22 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Quoted 20 lines · David Miller

From: Anatoly Pugachev <[email protected]>
Date: Wed, 24 Jul 2019 22:32:17 +0300

Quoted 7 lines

the first test where it was discovered was done on my test LDOM named ttip, hardware (hypervisor) is T5-2 server, running under Solaris 11.4 OS.
ttip LDOM is debian sparc64 unstable , so with almost all the latest software (gcc 8.3.0, binutils 2.32.51.20190707-1, debian GLIBC 2.28-10, etc..)

Quoted 8 lines

For another test, i also installed LDOM with oracle sparc linux
https://oss.oracle.com/projects/linux-sparc/ , but I've to install a more fresh version of gcc on it first, since system installed gcc 4.4 is too old for a git kernel (linux-2.6/Documentation/Changes lists gcc 4.6 as a minimal version), so I choose to install gcc-7.4.0 to /opt/ (leaving system installed gcc 4.4 under /usr/bin). Compiled and installed git kernel version, i.e. last tag 5.3.0-rc1 and ran the test. Kernel still produced oops.

Quoted 4 lines

I suspect, therefore, that we have a miscompile.

Please put your unstripped vmlinux image somewhere so I can take a closer look.

David,

http://u164.east.ru/kernel/

there's vmlinuz-5.3.0-rc1 kernel and archive 5.3.0-rc1-modules.tar.gz of /lib/modules/5.3.0-rc1/
this is from oracle sparclinux LDOM , compiled with 7.4.0 gcc

Thank you.

maintainer
#23 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

From: Anatoly Pugachev <[email protected]>
Date: Thu, 25 Jul 2019 21:33:24 +0300

Quoted 5 lines

http://u164.east.ru/kernel/

there's vmlinuz-5.3.0-rc1 kernel and archive 5.3.0-rc1-modules.tar.gz of /lib/modules/5.3.0-rc1/
this is from oracle sparclinux LDOM , compiled with 7.4.0 gcc

Thank you, I'll take a look.

maintainer
#24 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

In reply to Anatoly Pugachev

From: Anatoly Pugachev <[email protected]>
Date: Thu, 25 Jul 2019 21:33:24 +0300

Quoted 5 lines

http://u164.east.ru/kernel/

there's vmlinuz-5.3.0-rc1 kernel and archive 5.3.0-rc1-modules.tar.gz of /lib/modules/5.3.0-rc1/
this is from oracle sparclinux LDOM , compiled with 7.4.0 gcc

Please, I really really need the unstripped kernel image with all the symbols. This vmlinuz file is stripped already. The System.map does not serve as a replacement.

Thank you.

#25 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Quoted 9 lines · David Miller

From: Anatoly Pugachev <[email protected]>
Date: Thu, 25 Jul 2019 21:33:24 +0300

Quoted 3 lines

there's vmlinuz-5.3.0-rc1 kernel and archive 5.3.0-rc1-modules.tar.gz of /lib/modules/5.3.0-rc1/
this is from oracle sparclinux LDOM , compiled with 7.4.0 gcc

Please, I really really need the unstripped kernel image with all the symbols. This vmlinuz file is stripped already. The System.map does not serve as a replacement.

David,

http://u164.east.ru/kernel2/

I'm sorry missed debug kernel first. Enabled CONFIG_DEBUG_INFO=y

#26 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

In reply to Dmitry V. Levin
Quoted 16 lines · Dmitry V. Levin

Hi,

Quoted 5 lines · Christoph Hellwig

The sparc64 code is mostly equivalent to the generic one, minus various bugfixes and two arch overrides that this patch adds to pgtable.h.

Quoted 7 lines
---
 arch/sparc/Kconfig                  |   1 +
 arch/sparc/include/asm/pgtable_64.h |  18 ++
 arch/sparc/mm/Makefile              |   2 +-
 arch/sparc/mm/gup.c                 | 340 ----------------------------
 4 files changed, 20 insertions(+), 341 deletions(-)
 delete mode 100644 arch/sparc/mm/gup.c
Quoted 5 lines

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505 (thanks to Anatoly for bisecting) and introduced a regression:
futex.test from the strace test suite now causes an Oops on sparc64 in futex syscall

I have been working on reproducing this problem but ran into a different problem. I found 5.1 and newer kernels no longer boot on an S7 server or in an ldom on a T7 server (kernel hangs after "crc32c_sparc64: Using sparc64 crc32c opcode optimized CRC32C implementation" on console). A long git bisect session between 5.0 and 5.1 pointed to commit 73a66023c937 ("sparc64: fix sparc_ipc type conversion") but that makes no sense. I will keep working on finding root cause. I wonder if Anatoly's git bisect result is also suspect.

--
Khalid

#27 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

In reply to Dmitry V. Levin
Quoted 14 lines · Dmitry V. Levin
Quoted 5 lines · Christoph Hellwig

The sparc64 code is mostly equivalent to the generic one, minus various bugfixes and two arch overrides that this patch adds to pgtable.h.

Quoted 7 lines
---
 arch/sparc/Kconfig                  |   1 +
 arch/sparc/include/asm/pgtable_64.h |  18 ++
 arch/sparc/mm/Makefile              |   2 +-
 arch/sparc/mm/gup.c                 | 340 ----------------------------
 4 files changed, 20 insertions(+), 341 deletions(-)
 delete mode 100644 arch/sparc/mm/gup.c
Quoted 1 line

So this ended up as commit 7b9afb86b6328f10dc2cad9223d7def12d60e505

I've tried to revert this commit on a current master branch , but i'm getting :

linux-2.6$ git show 7b9afb86b632 > /tmp/gup.patch
linux-2.6$ patch -p1 -R < /tmp/gup.patch
...
linux-2.6$ make -j && make -j modules
...
CALL scripts/atomic/check-atomics.sh
CALL scripts/checksyscalls.sh
<stdin>:1511:2: warning: #warning syscall clone3 not implemented [-Wcpp]

  CHK     include/generated/compile.h
  CHK     include/generated/autoksyms.h
  GEN     .version
  CHK     include/generated/compile.h
  UPD     include/generated/compile.h
  CC      init/version.o
  AR      init/built-in.a
  LD      vmlinux.o

ld: mm/gup.o: in function `__get_user_pages_fast':
gup.c:(.text+0x1bc0): multiple definition of `__get_user_pages_fast'; arch/sparc/mm/gup.o:gup.c:(.text+0x620): first defined here
ld: mm/gup.o: in function `get_user_pages_fast':
gup.c:(.text+0x1be0): multiple definition of `get_user_pages_fast'; arch/sparc/mm/gup.o:gup.c:(.text+0x740): first defined here
make: *** [Makefile:1060: vmlinux] Error 1

Can someone help me to revert this commit? Is it even possible? Since it's not only futex strace calls getting killed and producing OOPS, even util-linux.git 'make check' hangs machine/LDOM with multiple OOPS in logs, while previous (before this commit) kernel passes tests ok (and without kernel OOPS). I've already tried to compile current master with gcc-6, gcc-7, gcc-8 debian versions, but all produce same OOPS.

Thanks.

#28 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

There isn't really a way to use an arch-specific get_user_pages_fast in mainline, you'd need to revert the whole series. As a relatively quick workaround you can just remove the

select HAVE_FAST_GUP if SPARC64

line from arch/sparc/Kconfig

#29 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

For the record the futex test case OOPSes a 5.3-rc3 kernel running on a Sun Blade 2500 (2 x USIIIi). This system runs a custom distro with a custom toolchain (gcc-8.3 based), so I doubt it's a distro problem.

Quoted 8 lines · Christoph Hellwig

There isn't really a way to use an arch-specific get_user_pages_fast in mainline, you'd need to revert the whole series. As a relatively quick workaround you can just remove the

select HAVE_FAST_GUP if SPARC64

line from arch/sparc/Kconfig

#30 lore raw

Re: [PATCH 09/16] sparc64: use the generic get_user_pages_fast code

Quoted 3 lines · Mikael Pettersson

For the record the futex test case OOPSes a 5.3-rc3 kernel running on a Sun Blade 2500 (2 x USIIIi). This system runs a custom distro with a custom toolchain (gcc-8.3 based), so I doubt it's a distro problem.

Mikael, Khalid,

can you please test util-linux source code with 'make check' on current git kernel and post the results?
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git

Thanks.

As with my test machine/LDOM, util-linux 'make check' hangs git kernel with the OOPS in the end of this message.

PS: And I was able to revert patch so current kernel git master branch works again, futex strace test works as before (not being killed and does not produce kernel OOPS), as well util-linux 'make check' does not kills kernel. If anyone interested I can post the patch, but I'm not sure it's a right thing to do, if all other architectures were converted to use generic GUP code (mm/gup.c).

[   47.600488] BUG: Bad rss-counter state mm:00000000ae46ef00 idx:0 val:-17
[   47.600645] BUG: Bad rss-counter state mm:00000000ae46ef00 idx:1 val:102
[   47.673090] fdisk[4270]: segfault at 20 ip fff8000100007ed8 (rpc
fff8000100007e30) sp 000007feffe79661 error 1 in
ld-2.28.so[fff8000100000000+22000]
[   47.674415] BUG: Bad rss-counter state mm:00000000ca65883c idx:0 val:17
[   47.674722] BUG: Bad rss-counter state mm:00000000ca65883c idx:1 val:1
[   47.785453] ------------[ cut here ]------------
[   47.785722] WARNING: CPU: 17 PID: 96 at mm/slab.h:410
kmem_cache_free+0xb4/0x300
[   47.785880] virt_to_cache: Object is not a Slab page!
[   47.786003] Modules linked in: tun ip_set_hash_net ip_set nf_tables

nfnetlink binfmt_misc camellia_sparc64 des_sparc64 des_generic aes_sparc64 md5_sparc64 sha512_sparc64 sha256_sparc64 n2_rng rng_core flash sha1_sparc64 ip_tables x_tables ipv6 nf_defrag_ipv6 autofs4 ext4 crc16 mbcache jbd2 raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor xor async_tx raid6_pq raid1 raid0 multipath linear md_mod crc32c_sparc64

[   47.787041] CPU: 17 PID: 96 Comm: ksoftirqd/17 Not tainted 5.3.0-rc3 #1143
[   47.787181] Call Trace:
[   47.787268]  [0000000000464540] __warn+0xc0/0x100
[   47.787384]  [00000000004645b4] warn_slowpath_fmt+0x34/0x60
[   47.787512]  [00000000006758f4] kmem_cache_free+0xb4/0x300
[   47.787648]  [0000000000451b68] pgtable_free+0x28/0x40
[   47.787779]  [00000000006470fc] tlb_remove_table_rcu+0x3c/0x80
[   47.787928]  [00000000004fae94] rcu_core+0xbd4/0x1000
[   47.788048]  [00000000004fb7ac] rcu_core_si+0xc/0x20
[   47.788177]  [0000000000abc648] __do_softirq+0x288/0x500
[   47.788296]  [000000000046beb0] run_ksoftirqd+0x30/0x80
[   47.788433]  [0000000000493c64] smpboot_thread_fn+0x244/0x280
[   47.788575]  [000000000048ef50] kthread+0x110/0x140
[   47.788707]  [00000000004060e4] ret_from_fork+0x1c/0x2c
[   47.788835]  [0000000000000000] 0x0
[   47.788927] irq event stamp: 19420
[   47.789028] hardirqs last  enabled at (19428): [<00000000004e2910>]
console_unlock+0x630/0x6c0
[   47.789230] hardirqs last disabled at (19435): [<00000000004e23dc>]
console_unlock+0xfc/0x6c0
[   47.789420] softirqs last  enabled at (19254): [<0000000000abc854>]
__do_softirq+0x494/0x500
[   47.789612] softirqs last disabled at (19259): [<000000000046beb0>]
run_ksoftirqd+0x30/0x80
[   47.789795] ---[ end trace afb11a4826780c48 ]---
[   47.925975] Unable to handle kernel paging request at virtual
address 0006120000000000
[   47.926088] tsk->{mm,active_mm}->context = 0000000000001b68
[   47.926150] tsk->{mm,active_mm}->pgd = fff8002438f90000
[   47.926202]               \|/ ____ \|/
[   47.926202]               "@'/ .. \`@"
[   47.926202]               /_| \__/ |_\
[   47.926202]                  \__U_/
[   47.926311] kworker/25:2(653): Oops [#1]
[   47.926354] CPU: 25 PID: 653 Comm: kworker/25:2 Tainted: G        W
        5.3.0-rc3 #1143
[   47.926433] Workqueue: xfs-conv/dm-0 xfs_end_io
[   47.926479] TSTATE: 0000000080001605 TPC: 000000000067588c TNPC:
0000000000675890 Y: 00000000    Tainted: G        W
[   47.926570] TPC: <kmem_cache_free+0x4c/0x300>
[   47.926611] g0: 0000000000675668 g1: 0006120000000000 g2:
0000004000000000 g3: 0006000000000000
[   47.926682] g4: fff80024938c8e40 g5: fff80024a83bc000 g6:
fff8002490254000 g7: 0000000000000102
[   47.926751] o0: 0000000000000000 o1: 0000000000d02c30 o2:
fff80024938c96b8 o3: 000000000000c000
[   47.926821] o4: 00000000014c3000 o5: 0000000000000000 sp:
fff80024ad577121 ret_pc: 00000000004d5148
[   47.926898] RPC: <lock_is_held_type+0x68/0xe0>
[   47.926940] l0: 0000000000000000 l1: 0000000000000000 l2:
00000000f0000000 l3: 0000000000000080
[   47.927010] l4: 0000000000d953c0 l5: 0000000000d953c0 l6:
0000000000000002 l7: 000000000000000b
[   47.927080] i0: fff800003040b1e0 i1: 0000000000000000 i2:
fff80024938c96b8 i3: fff80024938c8e40
[   47.927149] i4: 0000000000000004 i5: fff80024938c9730 i6:
fff80024ad5771d1 i7: 00000000006409f4
[   47.927223] I7: <ptlock_free+0x14/0x40>
[   47.927261] Call Trace:
[   47.927291]  [00000000006409f4] ptlock_free+0x14/0x40
[   47.927342]  [0000000000450a54] __pte_free+0x34/0x80
[   47.927388]  [0000000000451b54] pgtable_free+0x14/0x40
[   47.927436]  [00000000006470fc] tlb_remove_table_rcu+0x3c/0x80
[   47.927497]  [00000000004fae94] rcu_core+0xbd4/0x1000
[   47.927543]  [00000000004fb7ac] rcu_core_si+0xc/0x20
[   47.927593]  [0000000000abc648] __do_softirq+0x288/0x500
[   47.927644]  [000000000042d054] do_softirq_own_stack+0x34/0x60
[   47.927697]  [000000000046c1c8] irq_exit+0x68/0xe0
[   47.927742]  [0000000000abc1b8] timer_interrupt+0x98/0xc0
[   47.927791]  [0000000000427490] sys_call_table+0x780/0x970
[   47.927845]  [0000000000609ba8] test_clear_page_writeback+0x2c8/0x300
[   47.927900]  [00000000005f9d18] end_page_writeback+0x58/0xa0
[   47.927951]  [00000000007b83f8] xfs_destroy_ioend+0xf8/0x240
[   47.928002]  [00000000007b86a4] xfs_end_ioend+0x164/0x1e0
[   47.928050]  [00000000007b9550] xfs_end_io+0x90/0xc0
[   47.928095] Disabling lock debugging due to kernel taint
[   47.928118] Caller[00000000006409f4]: ptlock_free+0x14/0x40
[   47.928140] Caller[0000000000450a54]: __pte_free+0x34/0x80
[   47.928162] Caller[0000000000451b54]: pgtable_free+0x14/0x40
[   47.928184] Caller[00000000006470fc]: tlb_remove_table_rcu+0x3c/0x80
[   47.928208] Caller[00000000004fae94]: rcu_core+0xbd4/0x1000
[   47.928230] Caller[00000000004fb7ac]: rcu_core_si+0xc/0x20
[   47.928252] Caller[0000000000abc648]: __do_softirq+0x288/0x500
[   47.928278] Caller[000000000042d054]: do_softirq_own_stack+0x34/0x60
[   47.928306] Caller[000000000046c1c8]: irq_exit+0x68/0xe0
[   47.928330] Caller[0000000000abc1b8]: timer_interrupt+0x98/0xc0
[   47.928357] Caller[0000000000427490]: sys_call_table+0x780/0x970
[   47.928384] Caller[0000000000609b9c]: test_clear_page_writeback+0x2bc/0x300
[   47.928412] Caller[00000000005f9d18]: end_page_writeback+0x58/0xa0
[   47.928736] Caller[00000000007b83f8]: xfs_destroy_ioend+0xf8/0x240
[   47.928770] Caller[00000000007b86a4]: xfs_end_ioend+0x164/0x1e0
[   47.928798] Caller[00000000007b9550]: xfs_end_io+0x90/0xc0
[   47.928829] Caller[0000000000486ea4]: process_one_work+0x3e4/0x720
[   47.928858] Caller[00000000004874b8]: worker_thread+0x2d8/0x5a0
[   47.928888] Caller[000000000048ef50]: kthread+0x110/0x140
[   47.928922] Caller[00000000004060e4]: ret_from_fork+0x1c/0x2c
[   47.928952] Caller[0000000000000000]: 0x0
[   47.928973] Instruction DUMP:
[   47.928976]  82004002
[   47.928995]  83287003
[   47.929013]  82004003
[   47.929031] <c4586008>
[   47.929048]  8608a001
[   47.929065]  8400bfff
[   47.929082]  8578c401
[   47.929098]  82100002
[   47.929115]  c458a008
[   47.929132]
[   47.929161] Kernel panic - not syncing: Aiee, killing interrupt handler!
[   47.933949] Press Stop-A (L1-A) from sun keyboard or send break
[   47.933949] twice on console to return to the boot prom
[   47.933995] ---[ end Kernel panic - not syncing: Aiee, killing

interrupt handler! ]---

#31 lore raw

PATCH 10/16 mm: rename CONFIG_HAVE_GENERIC_GUP to CONFIG_HAVE_FAST_GUP

In reply to Christoph Hellwig

We only support the generic GUP now, so rename the config option to be more clear, and always use the mm/Kconfig definition of the symbol and select it from the arch Kconfigs.

---
 arch/arm/Kconfig     | 5 +----
 arch/arm64/Kconfig   | 4 +---
 arch/mips/Kconfig    | 2 +-
 arch/powerpc/Kconfig | 2 +-
 arch/s390/Kconfig    | 2 +-
 arch/sh/Kconfig      | 2 +-
 arch/sparc/Kconfig   | 2 +-
 arch/x86/Kconfig     | 4 +---
 mm/Kconfig           | 2 +-
 mm/gup.c             | 4 ++--
 10 files changed, 11 insertions(+), 18 deletions(-)
arch/arm/Kconfig +1 -4
index 8869742a85df..3879a3e2c511 100644
@@ -73,6 +73,7 @@ config ARM
 	select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU
 	select HAVE_EXIT_THREAD
+	select HAVE_FAST_GUP if ARM_LPAE
 	select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
 	select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG
 	select HAVE_FUNCTION_TRACER if !XIP_KERNEL
@@ -1596,10 +1597,6 @@ config ARCH_SELECT_MEMORY_MODEL
 config HAVE_ARCH_PFN_VALID
 	def_bool ARCH_HAS_HOLES_MEMORYMODEL || !SPARSEMEM
 
-config HAVE_GENERIC_GUP
-	def_bool y
-	depends on ARM_LPAE
-
 config HIGHMEM
 	bool "High Memory Support"
 	depends on MMU
arch/arm64/Kconfig +1 -3
index 697ea0510729..4a6ee3e92757 100644
@@ -140,6 +140,7 @@ config ARM64
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS
+	select HAVE_FAST_GUP
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUNCTION_GRAPH_TRACER
@@ -262,9 +263,6 @@ config GENERIC_CALIBRATE_DELAY
 config ZONE_DMA32
 	def_bool y
 
-config HAVE_GENERIC_GUP
-	def_bool y
-
 config ARCH_ENABLE_MEMORY_HOTPLUG
 	def_bool y
 
arch/mips/Kconfig +1 -1
index 64108a2a16d4..b1e42f0e4ed0 100644
@@ -54,10 +54,10 @@ config MIPS
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_EXIT_THREAD
+	select HAVE_FAST_GUP
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_FUNCTION_TRACER
-	select HAVE_GENERIC_GUP
 	select HAVE_IDE
 	select HAVE_IOREMAP_PROT
 	select HAVE_IRQ_EXIT_ON_IRQ_STACK
arch/powerpc/Kconfig +1 -1
index 8c1c636308c8..992a04796e56 100644
@@ -185,12 +185,12 @@ config PPC
 	select HAVE_DYNAMIC_FTRACE_WITH_REGS	if MPROFILE_KERNEL
 	select HAVE_EBPF_JIT			if PPC64
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS	if !(CPU_LITTLE_ENDIAN && POWER7_CPU)
+	select HAVE_FAST_GUP
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_ERROR_INJECTION
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_FUNCTION_TRACER
 	select HAVE_GCC_PLUGINS			if GCC_VERSION >= 50200   # plugin support on gcc <= 5.1 is buggy on PPC
-	select HAVE_GENERIC_GUP
 	select HAVE_HW_BREAKPOINT		if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx)
 	select HAVE_IDE
 	select HAVE_IOREMAP_PROT
arch/s390/Kconfig +1 -1
index 109243fdb6ec..aaff0376bf53 100644
@@ -137,6 +137,7 @@ config S390
 	select HAVE_DMA_CONTIGUOUS
 	select HAVE_DYNAMIC_FTRACE
 	select HAVE_DYNAMIC_FTRACE_WITH_REGS
+	select HAVE_FAST_GUP
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS
 	select HAVE_FENTRY
 	select HAVE_FTRACE_MCOUNT_RECORD
@@ -144,7 +145,6 @@ config S390
 	select HAVE_FUNCTION_TRACER
 	select HAVE_FUTEX_CMPXCHG if FUTEX
 	select HAVE_GCC_PLUGINS
-	select HAVE_GENERIC_GUP
 	select HAVE_KERNEL_BZIP2
 	select HAVE_KERNEL_GZIP
 	select HAVE_KERNEL_LZ4
arch/sh/Kconfig +1 -1
index 6fddfc3c9710..f6b15ecc37a3 100644
@@ -14,7 +14,7 @@ config SUPERH
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_PERF_EVENTS
 	select HAVE_DEBUG_BUGVERBOSE
-	select HAVE_GENERIC_GUP
+	select HAVE_FAST_GUP if MMU
 	select ARCH_HAVE_CUSTOM_GPIO_H
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG if (GUSA_RB || CPU_SH4A)
 	select ARCH_HAS_GCOV_PROFILE_ALL
arch/sparc/Kconfig +1 -1
index 22435471f942..659232b760e1 100644
@@ -28,7 +28,7 @@ config SPARC
 	select RTC_DRV_M48T59
 	select RTC_SYSTOHC
 	select HAVE_ARCH_JUMP_LABEL if SPARC64
-	select HAVE_GENERIC_GUP if SPARC64
+	select HAVE_FAST_GUP if SPARC64
 	select GENERIC_IRQ_SHOW
 	select ARCH_WANT_IPC_PARSE_VERSION
 	select GENERIC_PCI_IOMAP
arch/x86/Kconfig +1 -3
index 7cd53cc59f0f..44500e0ed630 100644
@@ -157,6 +157,7 @@ config X86
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS
 	select HAVE_EISA
 	select HAVE_EXIT_THREAD
+	select HAVE_FAST_GUP
 	select HAVE_FENTRY			if X86_64 || DYNAMIC_FTRACE
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_GRAPH_TRACER
@@ -2874,9 +2875,6 @@ config HAVE_ATOMIC_IOMAP
 config X86_DEV_DMA_OPS
 	bool
 
-config HAVE_GENERIC_GUP
-	def_bool y
-
 source "drivers/firmware/Kconfig"
 
 source "arch/x86/kvm/Kconfig"
mm/Kconfig +1 -1
index fe51f104a9e0..98dffb0f2447 100644
@@ -132,7 +132,7 @@ config HAVE_MEMBLOCK_NODE_MAP
 config HAVE_MEMBLOCK_PHYS_MAP
 	bool
 
-config HAVE_GENERIC_GUP
+config HAVE_FAST_GUP
 	bool
 
 config ARCH_KEEP_MEMBLOCK
mm/gup.c +2 -2
index 9b72f2ea3471..7328890ad8d3 100644
@@ -1651,7 +1651,7 @@ struct page *get_dump_page(unsigned long addr)
 #endif /* CONFIG_ELF_CORE */
 
 /*
- * Generic Fast GUP
+ * Fast GUP
  *
  * get_user_pages_fast attempts to pin user pages by walking the page
  * tables directly and avoids taking locks. Thus the walker needs to be
@@ -1683,7 +1683,7 @@ struct page *get_dump_page(unsigned long addr)
  *
  * This code is based heavily on the PowerPC implementation by Nick Piggin.
  */
-#ifdef CONFIG_HAVE_GENERIC_GUP
+#ifdef CONFIG_HAVE_FAST_GUP
 #ifdef CONFIG_GUP_GET_PTE_LOW_HIGH
 /*
  * WARNING: only to be used in the get_user_pages_fast() implementation.
Signature · 1 line
2.20.1
#32 lore raw

PATCH 11/16 mm: reorder code blocks in gup.c

In reply to Christoph Hellwig

This moves the actually exported functions towards the end of the file, and reorders some functions to be in more logical blocks as a preparation for moving various stubs inline into the main functionality using IS_ENABLED().

---
 mm/gup.c | 410 +++++++++++++++++++++++++++----------------------------
 1 file changed, 205 insertions(+), 205 deletions(-)
mm/gup.c +205 -205
index 7328890ad8d3..b29249581672 100644
@@ -1100,86 +1100,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
 	return pages_done;
 }
 
-/*
- * We can leverage the VM_FAULT_RETRY functionality in the page fault
- * paths better by using either get_user_pages_locked() or
- * get_user_pages_unlocked().
- *
- * get_user_pages_locked() is suitable to replace the form:
- *
- *      down_read(&mm->mmap_sem);
- *      do_something()
- *      get_user_pages(tsk, mm, ..., pages, NULL);
- *      up_read(&mm->mmap_sem);
- *
- *  to:
- *
- *      int locked = 1;
- *      down_read(&mm->mmap_sem);
- *      do_something()
- *      get_user_pages_locked(tsk, mm, ..., pages, &locked);
- *      if (locked)
- *          up_read(&mm->mmap_sem);
- */
-long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
-			   unsigned int gup_flags, struct page **pages,
-			   int *locked)
-{
-	/*
-	 * FIXME: Current FOLL_LONGTERM behavior is incompatible with
-	 * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on
-	 * vmas.  As there are no users of this flag in this call we simply
-	 * disallow this option for now.
-	 */
-	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
-		return -EINVAL;
-
-	return __get_user_pages_locked(current, current->mm, start, nr_pages,
-				       pages, NULL, locked,
-				       gup_flags | FOLL_TOUCH);
-}
-EXPORT_SYMBOL(get_user_pages_locked);
-
-/*
- * get_user_pages_unlocked() is suitable to replace the form:
- *
- *      down_read(&mm->mmap_sem);
- *      get_user_pages(tsk, mm, ..., pages, NULL);
- *      up_read(&mm->mmap_sem);
- *
- *  with:
- *
- *      get_user_pages_unlocked(tsk, mm, ..., pages);
- *
- * It is functionally equivalent to get_user_pages_fast so
- * get_user_pages_fast should be used instead if specific gup_flags
- * (e.g. FOLL_FORCE) are not required.
- */
-long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
-			     struct page **pages, unsigned int gup_flags)
-{
-	struct mm_struct *mm = current->mm;
-	int locked = 1;
-	long ret;
-
-	/*
-	 * FIXME: Current FOLL_LONGTERM behavior is incompatible with
-	 * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on
-	 * vmas.  As there are no users of this flag in this call we simply
-	 * disallow this option for now.
-	 */
-	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
-		return -EINVAL;
-
-	down_read(&mm->mmap_sem);
-	ret = __get_user_pages_locked(current, mm, start, nr_pages, pages, NULL,
-				      &locked, gup_flags | FOLL_TOUCH);
-	if (locked)
-		up_read(&mm->mmap_sem);
-	return ret;
-}
-EXPORT_SYMBOL(get_user_pages_unlocked);
-
 /*
  * get_user_pages_remote() - pin user pages in memory
  * @tsk:	the task_struct to use for page fault accounting, or
@@ -1256,6 +1176,153 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
 }
 EXPORT_SYMBOL(get_user_pages_remote);
 
+/**
+ * populate_vma_page_range() -  populate a range of pages in the vma.
+ * @vma:   target vma
+ * @start: start address
+ * @end:   end address
+ * @nonblocking:
+ *
+ * This takes care of mlocking the pages too if VM_LOCKED is set.
+ *
+ * return 0 on success, negative error code on error.
+ *
+ * vma->vm_mm->mmap_sem must be held.
+ *
+ * If @nonblocking is NULL, it may be held for read or write and will
+ * be unperturbed.
+ *
+ * If @nonblocking is non-NULL, it must held for read only and may be
+ * released.  If it's released, *@nonblocking will be set to 0.
+ */
+long populate_vma_page_range(struct vm_area_struct *vma,
+		unsigned long start, unsigned long end, int *nonblocking)
+{
+	struct mm_struct *mm = vma->vm_mm;
+	unsigned long nr_pages = (end - start) / PAGE_SIZE;
+	int gup_flags;
+
+	VM_BUG_ON(start & ~PAGE_MASK);
+	VM_BUG_ON(end   & ~PAGE_MASK);
+	VM_BUG_ON_VMA(start < vma->vm_start, vma);
+	VM_BUG_ON_VMA(end   > vma->vm_end, vma);
+	VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
+
+	gup_flags = FOLL_TOUCH | FOLL_POPULATE | FOLL_MLOCK;
+	if (vma->vm_flags & VM_LOCKONFAULT)
+		gup_flags &= ~FOLL_POPULATE;
+	/*
+	 * We want to touch writable mappings with a write fault in order
+	 * to break COW, except for shared mappings because these don't COW
+	 * and we would not want to dirty them for nothing.
+	 */
+	if ((vma->vm_flags & (VM_WRITE | VM_SHARED)) = VM_WRITE)
+		gup_flags |= FOLL_WRITE;
+
+	/*
+	 * We want mlock to succeed for regions that have any permissions
+	 * other than PROT_NONE.
+	 */
+	if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
+		gup_flags |= FOLL_FORCE;
+
+	/*
+	 * We made sure addr is within a VMA, so the following will
+	 * not result in a stack expansion that recurses back here.
+	 */
+	return __get_user_pages(current, mm, start, nr_pages, gup_flags,
+				NULL, NULL, nonblocking);
+}
+
+/*
+ * __mm_populate - populate and/or mlock pages within a range of address space.
+ *
+ * This is used to implement mlock() and the MAP_POPULATE / MAP_LOCKED mmap
+ * flags. VMAs must be already marked with the desired vm_flags, and
+ * mmap_sem must not be held.
+ */
+int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
+{
+	struct mm_struct *mm = current->mm;
+	unsigned long end, nstart, nend;
+	struct vm_area_struct *vma = NULL;
+	int locked = 0;
+	long ret = 0;
+
+	end = start + len;
+
+	for (nstart = start; nstart < end; nstart = nend) {
+		/*
+		 * We want to fault in pages for [nstart; end) address range.
+		 * Find first corresponding VMA.
+		 */
+		if (!locked) {
+			locked = 1;
+			down_read(&mm->mmap_sem);
+			vma = find_vma(mm, nstart);
+		} else if (nstart >= vma->vm_end)
+			vma = vma->vm_next;
+		if (!vma || vma->vm_start >= end)
+			break;
+		/*
+		 * Set [nstart; nend) to intersection of desired address
+		 * range with the first VMA. Also, skip undesirable VMA types.
+		 */
+		nend = min(end, vma->vm_end);
+		if (vma->vm_flags & (VM_IO | VM_PFNMAP))
+			continue;
+		if (nstart < vma->vm_start)
+			nstart = vma->vm_start;
+		/*
+		 * Now fault in a range of pages. populate_vma_page_range()
+		 * double checks the vma flags, so that it won't mlock pages
+		 * if the vma was already munlocked.
+		 */
+		ret = populate_vma_page_range(vma, nstart, nend, &locked);
+		if (ret < 0) {
+			if (ignore_errors) {
+				ret = 0;
+				continue;	/* continue at next VMA */
+			}
+			break;
+		}
+		nend = nstart + ret * PAGE_SIZE;
+		ret = 0;
+	}
+	if (locked)
+		up_read(&mm->mmap_sem);
+	return ret;	/* 0 or negative error code */
+}
+
+/**
+ * get_dump_page() - pin user page in memory while writing it to core dump
+ * @addr: user address
+ *
+ * Returns struct page pointer of user page pinned for dump,
+ * to be freed afterwards by put_page().
+ *
+ * Returns NULL on any kind of failure - a hole must then be inserted into
+ * the corefile, to preserve alignment with its headers; and also returns
+ * NULL wherever the ZERO_PAGE, or an anonymous pte_none, has been found -
+ * allowing a hole to be left in the corefile to save diskspace.
+ *
+ * Called without mmap_sem, but after all other threads have been killed.
+ */
+#ifdef CONFIG_ELF_CORE
+struct page *get_dump_page(unsigned long addr)
+{
+	struct vm_area_struct *vma;
+	struct page *page;
+
+	if (__get_user_pages(current, current->mm, addr, 1,
+			     FOLL_FORCE | FOLL_DUMP | FOLL_GET, &page, &vma,
+			     NULL) < 1)
+		return NULL;
+	flush_cache_page(vma, addr, page_to_pfn(page));
+	return page;
+}
+#endif /* CONFIG_ELF_CORE */
+
 #if defined(CONFIG_FS_DAX) || defined (CONFIG_CMA)
 static bool check_dax_vmas(struct vm_area_struct **vmas, long nr_pages)
 {
@@ -1503,152 +1570,85 @@ long get_user_pages(unsigned long start, unsigned long nr_pages,
 }
 EXPORT_SYMBOL(get_user_pages);
 
-/**
- * populate_vma_page_range() -  populate a range of pages in the vma.
- * @vma:   target vma
- * @start: start address
- * @end:   end address
- * @nonblocking:
- *
- * This takes care of mlocking the pages too if VM_LOCKED is set.
+/*
+ * We can leverage the VM_FAULT_RETRY functionality in the page fault
+ * paths better by using either get_user_pages_locked() or
+ * get_user_pages_unlocked().
  *
- * return 0 on success, negative error code on error.
+ * get_user_pages_locked() is suitable to replace the form:
  *
- * vma->vm_mm->mmap_sem must be held.
+ *      down_read(&mm->mmap_sem);
+ *      do_something()
+ *      get_user_pages(tsk, mm, ..., pages, NULL);
+ *      up_read(&mm->mmap_sem);
  *
- * If @nonblocking is NULL, it may be held for read or write and will
- * be unperturbed.
+ *  to:
  *
- * If @nonblocking is non-NULL, it must held for read only and may be
- * released.  If it's released, *@nonblocking will be set to 0.
+ *      int locked = 1;
+ *      down_read(&mm->mmap_sem);
+ *      do_something()
+ *      get_user_pages_locked(tsk, mm, ..., pages, &locked);
+ *      if (locked)
+ *          up_read(&mm->mmap_sem);
  */
-long populate_vma_page_range(struct vm_area_struct *vma,
-		unsigned long start, unsigned long end, int *nonblocking)
+long get_user_pages_locked(unsigned long start, unsigned long nr_pages,
+			   unsigned int gup_flags, struct page **pages,
+			   int *locked)
 {
-	struct mm_struct *mm = vma->vm_mm;
-	unsigned long nr_pages = (end - start) / PAGE_SIZE;
-	int gup_flags;
-
-	VM_BUG_ON(start & ~PAGE_MASK);
-	VM_BUG_ON(end   & ~PAGE_MASK);
-	VM_BUG_ON_VMA(start < vma->vm_start, vma);
-	VM_BUG_ON_VMA(end   > vma->vm_end, vma);
-	VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
-
-	gup_flags = FOLL_TOUCH | FOLL_POPULATE | FOLL_MLOCK;
-	if (vma->vm_flags & VM_LOCKONFAULT)
-		gup_flags &= ~FOLL_POPULATE;
-	/*
-	 * We want to touch writable mappings with a write fault in order
-	 * to break COW, except for shared mappings because these don't COW
-	 * and we would not want to dirty them for nothing.
-	 */
-	if ((vma->vm_flags & (VM_WRITE | VM_SHARED)) = VM_WRITE)
-		gup_flags |= FOLL_WRITE;
-
 	/*
-	 * We want mlock to succeed for regions that have any permissions
-	 * other than PROT_NONE.
+	 * FIXME: Current FOLL_LONGTERM behavior is incompatible with
+	 * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on
+	 * vmas.  As there are no users of this flag in this call we simply
+	 * disallow this option for now.
 	 */
-	if (vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC))
-		gup_flags |= FOLL_FORCE;
+	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
+		return -EINVAL;
 
-	/*
-	 * We made sure addr is within a VMA, so the following will
-	 * not result in a stack expansion that recurses back here.
-	 */
-	return __get_user_pages(current, mm, start, nr_pages, gup_flags,
-				NULL, NULL, nonblocking);
+	return __get_user_pages_locked(current, current->mm, start, nr_pages,
+				       pages, NULL, locked,
+				       gup_flags | FOLL_TOUCH);
 }
+EXPORT_SYMBOL(get_user_pages_locked);
 
 /*
- * __mm_populate - populate and/or mlock pages within a range of address space.
+ * get_user_pages_unlocked() is suitable to replace the form:
  *
- * This is used to implement mlock() and the MAP_POPULATE / MAP_LOCKED mmap
- * flags. VMAs must be already marked with the desired vm_flags, and
- * mmap_sem must not be held.
+ *      down_read(&mm->mmap_sem);
+ *      get_user_pages(tsk, mm, ..., pages, NULL);
+ *      up_read(&mm->mmap_sem);
+ *
+ *  with:
+ *
+ *      get_user_pages_unlocked(tsk, mm, ..., pages);
+ *
+ * It is functionally equivalent to get_user_pages_fast so
+ * get_user_pages_fast should be used instead if specific gup_flags
+ * (e.g. FOLL_FORCE) are not required.
  */
-int __mm_populate(unsigned long start, unsigned long len, int ignore_errors)
+long get_user_pages_unlocked(unsigned long start, unsigned long nr_pages,
+			     struct page **pages, unsigned int gup_flags)
 {
 	struct mm_struct *mm = current->mm;
-	unsigned long end, nstart, nend;
-	struct vm_area_struct *vma = NULL;
-	int locked = 0;
-	long ret = 0;
+	int locked = 1;
+	long ret;
 
-	end = start + len;
+	/*
+	 * FIXME: Current FOLL_LONGTERM behavior is incompatible with
+	 * FAULT_FLAG_ALLOW_RETRY because of the FS DAX check requirement on
+	 * vmas.  As there are no users of this flag in this call we simply
+	 * disallow this option for now.
+	 */
+	if (WARN_ON_ONCE(gup_flags & FOLL_LONGTERM))
+		return -EINVAL;
 
-	for (nstart = start; nstart < end; nstart = nend) {
-		/*
-		 * We want to fault in pages for [nstart; end) address range.
-		 * Find first corresponding VMA.
-		 */
-		if (!locked) {
-			locked = 1;
-			down_read(&mm->mmap_sem);
-			vma = find_vma(mm, nstart);
-		} else if (nstart >= vma->vm_end)
-			vma = vma->vm_next;
-		if (!vma || vma->vm_start >= end)
-			break;
-		/*
-		 * Set [nstart; nend) to intersection of desired address
-		 * range with the first VMA. Also, skip undesirable VMA types.
-		 */
-		nend = min(end, vma->vm_end);
-		if (vma->vm_flags & (VM_IO | VM_PFNMAP))
-			continue;
-		if (nstart < vma->vm_start)
-			nstart = vma->vm_start;
-		/*
-		 * Now fault in a range of pages. populate_vma_page_range()
-		 * double checks the vma flags, so that it won't mlock pages
-		 * if the vma was already munlocked.
-		 */
-		ret = populate_vma_page_range(vma, nstart, nend, &locked);
-		if (ret < 0) {
-			if (ignore_errors) {
-				ret = 0;
-				continue;	/* continue at next VMA */
-			}
-			break;
-		}
-		nend = nstart + ret * PAGE_SIZE;
-		ret = 0;
-	}
+	down_read(&mm->mmap_sem);
+	ret = __get_user_pages_locked(current, mm, start, nr_pages, pages, NULL,
+				      &locked, gup_flags | FOLL_TOUCH);
 	if (locked)
 		up_read(&mm->mmap_sem);
-	return ret;	/* 0 or negative error code */
-}
-
-/**
- * get_dump_page() - pin user page in memory while writing it to core dump
- * @addr: user address
- *
- * Returns struct page pointer of user page pinned for dump,
- * to be freed afterwards by put_page().
- *
- * Returns NULL on any kind of failure - a hole must then be inserted into
- * the corefile, to preserve alignment with its headers; and also returns
- * NULL wherever the ZERO_PAGE, or an anonymous pte_none, has been found -
- * allowing a hole to be left in the corefile to save diskspace.
- *
- * Called without mmap_sem, but after all other threads have been killed.
- */
-#ifdef CONFIG_ELF_CORE
-struct page *get_dump_page(unsigned long addr)
-{
-	struct vm_area_struct *vma;
-	struct page *page;
-
-	if (__get_user_pages(current, current->mm, addr, 1,
-			     FOLL_FORCE | FOLL_DUMP | FOLL_GET, &page, &vma,
-			     NULL) < 1)
-		return NULL;
-	flush_cache_page(vma, addr, page_to_pfn(page));
-	return page;
+	return ret;
 }
-#endif /* CONFIG_ELF_CORE */
+EXPORT_SYMBOL(get_user_pages_unlocked);
 
 /*
  * Fast GUP
Signature · 1 line
2.20.1
#33 lore raw

PATCH 12/16 mm: consolidate the get_user_pages* implementations

In reply to Christoph Hellwig

Always build mm/gup.c so that we don't have to provide separate nommu stubs. Also merge the get_user_pages_fast and __get_user_pages_fast stubs when HAVE_FAST_GUP into the main implementations, which will never call the fast path if HAVE_FAST_GUP is not set.

This also ensures the new put_user_pages* helpers are available for nommu, as those are currently missing, which would create a problem as soon as we actually grew users for it.

---
 mm/Kconfig  |  1 +
 mm/Makefile |  4 +--
 mm/gup.c    | 67 +++++++++++++++++++++++++++++++++++++---
 mm/nommu.c  | 88 -----------------------------------------------------
 mm/util.c   | 47 ----------------------------
 5 files changed, 65 insertions(+), 142 deletions(-)
mm/Kconfig +1 -0
index 98dffb0f2447..5c41409557da 100644
@@ -133,6 +133,7 @@ config HAVE_MEMBLOCK_PHYS_MAP
 	bool
 
 config HAVE_FAST_GUP
+	depends on MMU
 	bool
 
 config ARCH_KEEP_MEMBLOCK
mm/Makefile +2 -2
index ac5e5ba78874..dc0746ca1109 100644
@@ -22,7 +22,7 @@ KCOV_INSTRUMENT_mmzone.o := n
 KCOV_INSTRUMENT_vmstat.o := n
 
 mmu-y			:= nommu.o
-mmu-$(CONFIG_MMU)	:= gup.o highmem.o memory.o mincore.o \
+mmu-$(CONFIG_MMU)	:= highmem.o memory.o mincore.o \
 			   mlock.o mmap.o mmu_gather.o mprotect.o mremap.o \
 			   msync.o page_vma_mapped.o pagewalk.o \
 			   pgtable-generic.o rmap.o vmalloc.o
@@ -39,7 +39,7 @@ obj-y			:= filemap.o mempool.o oom_kill.o fadvise.o \
 			   mm_init.o mmu_context.o percpu.o slab_common.o \
 			   compaction.o vmacache.o \
 			   interval_tree.o list_lru.o workingset.o \
-			   debug.o $(mmu-y)
+			   debug.o gup.o $(mmu-y)
 
 # Give 'page_alloc' its own module-parameter namespace
 page-alloc-y := page_alloc.o
mm/gup.c +62 -5

118 lines not on this page · raw message

mm/nommu.c +0 -88

94 lines not on this page · raw message

mm/util.c +0 -47

53 lines not on this page · raw message

Signature · 1 line
2.20.1
#34 lore raw

PATCH 13/16 mm: validate get_user_pages_fast flags

In reply to Christoph Hellwig

We can only deal with FOLL_WRITE and/or FOLL_LONGTERM in get_user_pages_fast, so reject all other flags.

---
 mm/gup.c | 3 +++
 1 file changed, 3 insertions(+)
mm/gup.c +3 -0
index 0e83dba98dfd..37a2083b1ed8 100644
@@ -2317,6 +2317,9 @@ int get_user_pages_fast(unsigned long start, int nr_pages,
 	unsigned long addr, len, end;
 	int nr = 0, ret = 0;
 
+	if (WARN_ON_ONCE(gup_flags & ~(FOLL_WRITE | FOLL_LONGTERM)))
+		return -EINVAL;
+
 	start = untagged_addr(start) & PAGE_MASK;
 	addr = start;
 	len = (unsigned long) nr_pages << PAGE_SHIFT;
Signature · 1 line
2.20.1
#35 lore raw

PATCH 14/16 mm: move the powerpc hugepd code to mm/gup.c

In reply to Christoph Hellwig

While only powerpc supports the hugepd case, the code is pretty generic and I'd like to keep all GUP internals in one place.

---
 arch/powerpc/Kconfig          |  1 +
 arch/powerpc/mm/hugetlbpage.c | 72 ------------------------------
 include/linux/hugetlb.h       | 18 --------
 mm/Kconfig                    | 10 +++++
 mm/gup.c                      | 82 +++++++++++++++++++++++++++++++++++
 5 files changed, 93 insertions(+), 90 deletions(-)
arch/powerpc/Kconfig +1 -0
index 992a04796e56..4f1b00979cde 100644
@@ -125,6 +125,7 @@ config PPC
 	select ARCH_HAS_FORTIFY_SOURCE
 	select ARCH_HAS_GCOV_PROFILE_ALL
 	select ARCH_HAS_KCOV
+	select ARCH_HAS_HUGEPD			if HUGETLB_PAGE
 	select ARCH_HAS_MMIOWB			if PPC64
 	select ARCH_HAS_PHYS_TO_DMA
 	select ARCH_HAS_PMEM_API                if PPC64
arch/powerpc/mm/hugetlbpage.c +0 -72

81 lines not on this page · raw message

include/linux/hugetlb.h +0 -18
index edf476c8cfb9..0f91761e2c53 100644
@@ -16,29 +16,11 @@ struct user_struct;
 struct mmu_gather;
 
 #ifndef is_hugepd
-/*
- * Some architectures requires a hugepage directory format that is
- * required to support multiple hugepage sizes. For example
- * a4fe3ce76 "powerpc/mm: Allow more flexible layouts for hugepage pagetables"
- * introduced the same on powerpc. This allows for a more flexible hugepage
- * pagetable layout.
- */
 typedef struct { unsigned long pd; } hugepd_t;
 #define is_hugepd(hugepd) (0)
 #define __hugepd(x) ((hugepd_t) { (x) })
-static inline int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
-			      unsigned pdshift, unsigned long end,
-			      int write, struct page **pages, int *nr)
-{
-	return 0;
-}
-#else
-extern int gup_huge_pd(hugepd_t hugepd, unsigned long addr,
-		       unsigned pdshift, unsigned long end,
-		       int write, struct page **pages, int *nr);
 #endif
 
-
 #ifdef CONFIG_HUGETLB_PAGE
 
 #include <linux/mempolicy.h>
mm/Kconfig +10 -0
index 5c41409557da..44be3f01a2b2 100644
@@ -769,4 +769,14 @@ config GUP_GET_PTE_LOW_HIGH
 config ARCH_HAS_PTE_SPECIAL
 	bool
 
+#
+# Some architectures require a special hugepage directory format that is
+# required to support multiple hugepage sizes. For example a4fe3ce76
+# "powerpc/mm: Allow more flexible layouts for hugepage pagetables"
+# introduced it on powerpc.  This allows for a more flexible hugepage
+# pagetable layouts.
+#
+config ARCH_HAS_HUGEPD
+	bool
+
 endmenu
mm/gup.c +82 -0

88 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#36 lore raw

Re: [PATCH 14/16] mm: move the powerpc hugepd code to mm/gup.c

Quoted 1 line · On Tue, 25 Jun 2019 16:37:13 +0200 Christoph Hellwig <[email protected]> wrote:

+static int gup_huge_pd(hugepd_t hugepd

Naming nitlet: we have hugepd and we also have huge_pd. We have hugepte and we also have huge_pte. It make things a bit hard to remember and it would be nice to make it all consistent sometime.

We're consistent with huge_pud and almost consistent with huge_pmd.

To be fully consistent I guess we should make all of them have the underscore. Or not have it.

#37 lore raw

Re: [PATCH 14/16] mm: move the powerpc hugepd code to mm/gup.c

Quoted 4 lines · Andrew Morton
Quoted 1 line · On Tue, 25 Jun 2019 16:37:13 +0200 Christoph Hellwig <[email protected]> wrote:

+static int gup_huge_pd(hugepd_t hugepd

Quoted 8 lines

Naming nitlet: we have hugepd and we also have huge_pd. We have hugepte and we also have huge_pte. It make things a bit hard to remember and it would be nice to make it all consistent sometime.

We're consistent with huge_pud and almost consistent with huge_pmd.

To be fully consistent I guess we should make all of them have the underscore. Or not have it.

Either way is fine with me. Feel free to fix up per your preference.

#38 lore raw

PATCH 15/16 mm: switch gup_hugepte to use try_get_compound_head

In reply to Christoph Hellwig

This applies the overflow fixes from 8fde12ca79aff ("mm: prevent get_user_pages() from overflowing page refcount") to the powerpc hugepd code and brings it back in sync with the other GUP cases.

---
 mm/gup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
mm/gup.c +2 -1
index 7077549bc8ea..e06447cff635 100644
@@ -2006,7 +2006,8 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
 		refs++;
 	} while (addr += PAGE_SIZE, addr != end);
 
-	if (!page_cache_add_speculative(head, refs)) {
+	head = try_get_compound_head(head, refs);
+	if (!head) {
 		*nr -= refs;
 		return 0;
 	}
Signature · 1 line
2.20.1
#39 lore raw

PATCH 16/16 mm: mark the page referenced in gup_hugepte

In reply to Christoph Hellwig

All other get_user_page_fast cases mark the page referenced, so do this here as well.

---
 mm/gup.c | 1 +
 1 file changed, 1 insertion(+)
mm/gup.c +1 -0
index e06447cff635..d9d022d835ca 100644
@@ -2020,6 +2020,7 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
 		return 0;
 	}
 
+	SetPageReferenced(head);
 	return 1;
 }
 
Signature · 1 line
2.20.1