Skip to contentSkip to conversation

Use killable vma write locking in most places

PATCH Superseded Suren Baghdasaryan 5 participants 15 messages Feb 17 – Feb 18

Subsystems (14)
Memory management KVM PowerPC MM core +10 more subsystems

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Suren Baghdasaryan

author reviewer
#0 lore raw

v2 cover Use killable vma write locking in most places

Now that we have vma_start_write_killable() we can replace most of the vma_start_write() calls with it, improving reaction time to the kill signal.

There are several places which are left untouched by this patchset:

1. free_pgtables() because function should free page tables even if a fatal signal is pending.

2. userfaultd code, where some paths calling vma_start_write() can handle EINTR and some can't without a deeper code refactoring.

3. vm_flags_{set|mod|clear} require refactoring that involves moving vma_start_write() out of these functions and replacing it with vma_assert_write_locked(), then callers of these functions should lock the vma themselves using vma_start_write_killable() whenever possible.

A cleanup patch is added in the beginning to make later changes more readable. The second patch contains most of the changes and the last patch contains the changes associated with process_vma_walk_lock() error handling.

Changes since v1 [1]:
- Moved vma_start_write_killable() inside set_mempolicy_home_node() to be done before mpol_dup(new), per Jann Horn
- Added error propagation for the missing PGWALK_WRLOCK users and split it into a separate patch, per Jann Horn
- Moved vma_start_write_killable() inside __split_vma() to be done before new->vm_ops->open(), per Jann Horn
- Added a separate patch to change flow control in vma_expand(), per Jann Horn
- Brought back signal_pending() in mm_take_all_locks, per Jann Horn
- Moved vma_start_write_killable() inside __mmap_new_vma() to be done before __mmap_new_file_vma(), per Jann Horn
- Added Reviewed-by for powerpc, per Ritesh Harjani
- Added s390 reviewers and the list due to changes in the last patch

[1] https://lore.kernel.org/all/[email protected]/

Suren Baghdasaryan (3):
mm/vma: cleanup error handling path in vma_expand()
mm: replace vma_start_write() with vma_start_write_killable()
mm: use vma_start_write_killable() in process_vma_walk_lock()

 arch/powerpc/kvm/book3s_hv_uvmem.c |   5 +-
 arch/s390/kvm/kvm-s390.c           |   5 +-
 arch/s390/mm/gmap.c                |  13 +++-
 fs/proc/task_mmu.c                 |   7 +-
 include/linux/mempolicy.h          |   5 +-
 mm/khugepaged.c                    |   5 +-
 mm/madvise.c                       |   4 +-
 mm/memory.c                        |   2 +
 mm/mempolicy.c                     |  23 +++++--
 mm/mlock.c                         |  20 ++++--
 mm/mprotect.c                      |   4 +-
 mm/mremap.c                        |   4 +-
 mm/pagewalk.c                      |  20 ++++--
 mm/vma.c                           | 105 ++++++++++++++++++++---------
 mm/vma_exec.c                      |   6 +-
 15 files changed, 164 insertions(+), 64 deletions(-)

base-commit: b08472d036a36893ecf68296d87beb58d21f4357

Signature · 1 line
2.53.0.273.g2a3d683680-goog
author reviewer
#1 lore raw

PATCH v2 1/3 mm/vma: cleanup error handling path in vma_expand()

vma_expand() error handling is a bit confusing with "if (ret) return ret;" mixed with "if (!ret && ...) ret = ...;". Simplify the code to check for errors and return immediately after an operation that might fail. This also makes later changes to this function more readable.

No functional change intended.

---
 mm/vma.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
mm/vma.c +8 -4
index be64f781a3aa..bb4d0326fecb 100644
@@ -1186,12 +1186,16 @@ int vma_expand(struct vma_merge_struct *vmg)
 	 * Note that, by convention, callers ignore OOM for this case, so
 	 * we don't need to account for vmg->give_up_on_mm here.
 	 */
-	if (remove_next)
+	if (remove_next) {
 		ret = dup_anon_vma(target, next, &anon_dup);
-	if (!ret && vmg->copied_from)
+		if (ret)
+			return ret;
+	}
+	if (vmg->copied_from) {
 		ret = dup_anon_vma(target, vmg->copied_from, &anon_dup);
-	if (ret)
-		return ret;
+		if (ret)
+			return ret;
+	}
 
 	if (remove_next) {
 		vma_start_write(next);
Signature · 1 line
2.53.0.273.g2a3d683680-goog
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] mm/vma: cleanup error handling path in vma_expand()

Quoted 9 lines · Suren Baghdasaryan

vma_expand() error handling is a bit confusing with "if (ret) return ret;" mixed with "if (!ret && ...) ret = ...;". Simplify the code to check for errors and return immediately after an operation that might fail. This also makes later changes to this function more readable.

No functional change intended.

Quoted 32 lines
---
 mm/vma.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
mm/vma.c +8 -4
index be64f781a3aa..bb4d0326fecb 100644
@@ -1186,12 +1186,16 @@ int vma_expand(struct vma_merge_struct *vmg)
 	 * Note that, by convention, callers ignore OOM for this case, so
 	 * we don't need to account for vmg->give_up_on_mm here.
 	 */
-	if (remove_next)
+	if (remove_next) {
 		ret = dup_anon_vma(target, next, &anon_dup);
-	if (!ret && vmg->copied_from)
+		if (ret)
+			return ret;
+	}
+	if (vmg->copied_from) {
 		ret = dup_anon_vma(target, vmg->copied_from, &anon_dup);
-	if (ret)
-		return ret;
+		if (ret)
+			return ret;
+	}
 
 	if (remove_next) {
 		vma_start_write(next);
Signature · 1 line
2.53.0.273.g2a3d683680-goog
author reviewer
#3 lore raw

PATCH v2 2/3 mm: replace vma_start_write() with vma_start_write_killable()

In reply to Suren Baghdasaryan

Now that we have vma_start_write_killable() we can replace most of the vma_start_write() calls with it, improving reaction time to the kill signal.

There are several places which are left untouched by this patch:

1. free_pgtables() because function should free page tables even if a fatal signal is pending.

2. process_vma_walk_lock(), which requires changes in its callers and will be handled in the next patch.

3. userfaultd code, where some paths calling vma_start_write() can handle EINTR and some can't without a deeper code refactoring.

4. vm_flags_{set|mod|clear} require refactoring that involves moving vma_start_write() out of these functions and replacing it with vma_assert_write_locked(), then callers of these functions should lock the vma themselves using vma_start_write_killable() whenever possible.

---
 arch/powerpc/kvm/book3s_hv_uvmem.c |  5 +-
 include/linux/mempolicy.h          |  5 +-
 mm/khugepaged.c                    |  5 +-
 mm/madvise.c                       |  4 +-
 mm/memory.c                        |  2 +
 mm/mempolicy.c                     | 23 ++++++--
 mm/mlock.c                         | 20 +++++--
 mm/mprotect.c                      |  4 +-
 mm/mremap.c                        |  4 +-
 mm/vma.c                           | 93 +++++++++++++++++++++---------
 mm/vma_exec.c                      |  6 +-
 11 files changed, 123 insertions(+), 48 deletions(-)
arch/powerpc/kvm/book3s_hv_uvmem.c +4 -1
index 7cf9310de0ec..69750edcf8d5 100644
@@ -410,7 +410,10 @@ static int kvmppc_memslot_page_merge(struct kvm *kvm,
 			ret = H_STATE;
 			break;
 		}
-		vma_start_write(vma);
+		if (vma_start_write_killable(vma)) {
+			ret = H_STATE;
+			break;
+		}
 		/* Copy vm_flags to avoid partial modifications in ksm_madvise */
 		vm_flags = vma->vm_flags;
 		ret = ksm_madvise(vma, vma->vm_start, vma->vm_end,
include/linux/mempolicy.h +3 -2
index 0fe96f3ab3ef..762930edde5a 100644
@@ -137,7 +137,7 @@ bool vma_policy_mof(struct vm_area_struct *vma);
 extern void numa_default_policy(void);
 extern void numa_policy_init(void);
 extern void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new);
-extern void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
+extern int mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new);
 
 extern int huge_node(struct vm_area_struct *vma,
 				unsigned long addr, gfp_t gfp_flags,
@@ -251,8 +251,9 @@ static inline void mpol_rebind_task(struct task_struct *tsk,
 {
 }
 
-static inline void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
+static inline int mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
 {
+	return 0;
 }
 
 static inline int huge_node(struct vm_area_struct *vma,
mm/khugepaged.c +4 -1
index fa1e57fd2c46..392dde66fa86 100644
@@ -1150,7 +1150,10 @@ static enum scan_result collapse_huge_page(struct mm_struct *mm, unsigned long a
 	if (result != SCAN_SUCCEED)
 		goto out_up_write;
 	/* check if the pmd is still valid */
-	vma_start_write(vma);
+	if (vma_start_write_killable(vma)) {
+		result = SCAN_FAIL;
+		goto out_up_write;
+	}
 	result = check_pmd_still_valid(mm, address, pmd);
 	if (result != SCAN_SUCCEED)
 		goto out_up_write;
mm/madvise.c +3 -1
index 8debb2d434aa..b41e64231c31 100644
@@ -173,7 +173,9 @@ static int madvise_update_vma(vm_flags_t new_flags,
 	madv_behavior->vma = vma;
 
 	/* vm_flags is protected by the mmap_lock held in write mode. */
-	vma_start_write(vma);
+	if (vma_start_write_killable(vma))
+		return -EINTR;
+
 	vm_flags_reset(vma, new_flags);
 	if (set_new_anon_name)
 		return replace_anon_vma_name(vma, anon_name);
mm/memory.c +2 -0
index dc0e5da70cdc..29e12f063c7b 100644
@@ -379,6 +379,8 @@ void free_pgd_range(struct mmu_gather *tlb,
  * page tables that should be removed.  This can differ from the vma mappings on
  * some archs that may have mappings that need to be removed outside the vmas.
  * Note that the prev->vm_end and next->vm_start are often used.
+ * We don't use vma_start_write_killable() because page tables should be freed
+ * even if the task is being killed.
  *
  * The vma_end differs from the pg_end when a dup_mmap() failed and the tree has
  * unrelated data to the mm_struct being torn down.
mm/mempolicy.c +18 -5
index dbd48502ac24..5f6302d227f5 100644
@@ -556,17 +556,25 @@ void mpol_rebind_task(struct task_struct *tsk, const nodemask_t *new)
  *
  * Call holding a reference to mm.  Takes mm->mmap_lock during call.
  */
-void mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
+int mpol_rebind_mm(struct mm_struct *mm, nodemask_t *new)
 {
 	struct vm_area_struct *vma;
 	VMA_ITERATOR(vmi, mm, 0);
+	int ret = 0;
+
+	if (mmap_write_lock_killable(mm))
+		return -EINTR;
 
-	mmap_write_lock(mm);
 	for_each_vma(vmi, vma) {
-		vma_start_write(vma);
+		if (vma_start_write_killable(vma)) {
+			ret = -EINTR;
+			break;
+		}
 		mpol_rebind_policy(vma->vm_policy, new);
 	}
 	mmap_write_unlock(mm);
+
+	return ret;
 }
 
 static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {
@@ -1785,9 +1793,15 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
 		return -EINVAL;
 	if (end == start)
 		return 0;
-	mmap_write_lock(mm);
+	if (mmap_write_lock_killable(mm))
+		return -EINTR;
 	prev = vma_prev(&vmi);
 	for_each_vma_range(vmi, vma, end) {
+		if (vma_start_write_killable(vma)) {
+			err = -EINTR;
+			break;
+		}
+
 		/*
 		 * If any vma in the range got policy other than MPOL_BIND
 		 * or MPOL_PREFERRED_MANY we return error. We don't reset
@@ -1808,7 +1822,6 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
 			break;
 		}
 
-		vma_start_write(vma);
 		new->home_node = home_node;
 		err = mbind_range(&vmi, vma, &prev, start, end, new);
 		mpol_put(new);
mm/mlock.c +14 -6
index 2f699c3497a5..2885b858aa0f 100644
@@ -420,7 +420,7 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr,
  * Called for mlock(), mlock2() and mlockall(), to set @vma VM_LOCKED;
  * called for munlock() and munlockall(), to clear VM_LOCKED from @vma.
  */
-static void mlock_vma_pages_range(struct vm_area_struct *vma,
+static int mlock_vma_pages_range(struct vm_area_struct *vma,
 	unsigned long start, unsigned long end, vm_flags_t newflags)
 {
 	static const struct mm_walk_ops mlock_walk_ops = {
@@ -441,7 +441,9 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 	 */
 	if (newflags & VM_LOCKED)
 		newflags |= VM_IO;
-	vma_start_write(vma);
+	if (vma_start_write_killable(vma))
+		return -EINTR;
+
 	vm_flags_reset_once(vma, newflags);
 
 	lru_add_drain();
@@ -452,6 +454,7 @@ static void mlock_vma_pages_range(struct vm_area_struct *vma,
 		newflags &= ~VM_IO;
 		vm_flags_reset_once(vma, newflags);
 	}
+	return 0;
 }
 
 /*
@@ -501,10 +504,12 @@ static int mlock_fixup(struct vma_iterator *vmi, struct vm_area_struct *vma,
 	 */
 	if ((newflags & VM_LOCKED) && (oldflags & VM_LOCKED)) {
 		/* No work to do, and mlocking twice would be wrong */
-		vma_start_write(vma);
+		ret = vma_start_write_killable(vma);
+		if (ret)
+			goto out;
 		vm_flags_reset(vma, newflags);
 	} else {
-		mlock_vma_pages_range(vma, start, end, newflags);
+		ret = mlock_vma_pages_range(vma, start, end, newflags);
 	}
 out:
 	*prev = vma;
@@ -733,9 +738,12 @@ static int apply_mlockall_flags(int flags)
 
 		error = mlock_fixup(&vmi, vma, &prev, vma->vm_start, vma->vm_end,
 				    newflags);
-		/* Ignore errors, but prev needs fixing up. */
-		if (error)
+		/* Ignore errors except EINTR, but prev needs fixing up. */
+		if (error) {
+			if (error == -EINTR)
+				break;
 			prev = vma;
+		}
 		cond_resched();
 	}
 out:
mm/mprotect.c +3 -1
index c0571445bef7..49dbb7156936 100644
@@ -765,7 +765,9 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gather *tlb,
 	 * vm_flags and vm_page_prot are protected by the mmap_lock
 	 * held in write mode.
 	 */
-	vma_start_write(vma);
+	error = vma_start_write_killable(vma);
+	if (error < 0)
+		goto fail;
 	vm_flags_reset_once(vma, newflags);
 	if (vma_wants_manual_pte_write_upgrade(vma))
 		mm_cp_flags |= MM_CP_TRY_CHANGE_WRITABLE;
mm/mremap.c +3 -1
index 2be876a70cc0..aef1e5f373c7 100644
@@ -1286,7 +1286,9 @@ static unsigned long move_vma(struct vma_remap_struct *vrm)
 		return -ENOMEM;
 
 	/* We don't want racing faults. */
-	vma_start_write(vrm->vma);
+	err = vma_start_write_killable(vrm->vma);
+	if (err)
+		return err;
 
 	/* Perform copy step. */
 	err = copy_vma_and_data(vrm, &new_vma);
mm/vma.c +65 -28

247 lines not on this page · raw message

mm/vma_exec.c +4 -2
index 8134e1afca68..a4addc2a8480 100644
@@ -40,6 +40,7 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift)
 	struct vm_area_struct *next;
 	struct mmu_gather tlb;
 	PAGETABLE_MOVE(pmc, vma, vma, old_start, new_start, length);
+	int err;
 
 	BUG_ON(new_start > new_end);
 
@@ -55,8 +56,9 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift)
 	 * cover the whole range: [new_start, old_end)
 	 */
 	vmg.target = vma;
-	if (vma_expand(&vmg))
-		return -ENOMEM;
+	err = vma_expand(&vmg);
+	if (err)
+		return err;
 
 	/*
 	 * move the page tables downwards, on failure we rely on
Signature · 1 line
2.53.0.273.g2a3d683680-goog
#4 lore raw

Re: [PATCH v2 2/3] mm: replace vma_start_write() with vma_start_write_killable()

Quoted 38 lines · Suren Baghdasaryan

Now that we have vma_start_write_killable() we can replace most of the vma_start_write() calls with it, improving reaction time to the kill signal.

There are several places which are left untouched by this patch:

1. free_pgtables() because function should free page tables even if a fatal signal is pending.

2. process_vma_walk_lock(), which requires changes in its callers and will be handled in the next patch.

3. userfaultd code, where some paths calling vma_start_write() can handle EINTR and some can't without a deeper code refactoring.

4. vm_flags_{set|mod|clear} require refactoring that involves moving vma_start_write() out of these functions and replacing it with vma_assert_write_locked(), then callers of these functions should lock the vma themselves using vma_start_write_killable() whenever possible.

---
 arch/powerpc/kvm/book3s_hv_uvmem.c |  5 +-
 include/linux/mempolicy.h          |  5 +-
 mm/khugepaged.c                    |  5 +-
 mm/madvise.c                       |  4 +-
 mm/memory.c                        |  2 +
 mm/mempolicy.c                     | 23 ++++++--
 mm/mlock.c                         | 20 +++++--
 mm/mprotect.c                      |  4 +-
 mm/mremap.c                        |  4 +-
 mm/vma.c                           | 93 +++++++++++++++++++++---------
 mm/vma_exec.c                      |  6 +-
 11 files changed, 123 insertions(+), 48 deletions(-)

...

Quoted 2 lines
mm/mempolicy.c +0 -0

...

Quoted 20 lines

static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {

mm/mempolicy.c +7 -1
@@ -1785,9 +1793,15 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
 		return -EINVAL;
 	if (end == start)
 		return 0;
-	mmap_write_lock(mm);
+	if (mmap_write_lock_killable(mm))
+		return -EINTR;
 	prev = vma_prev(&vmi);
 	for_each_vma_range(vmi, vma, end) {
+		if (vma_start_write_killable(vma)) {
+			err = -EINTR;
+			break;
+		}
+
 		/*
 		 * If any vma in the range got policy other than MPOL_BIND
 		 * or MPOL_PREFERRED_MANY we return error. We don't reset

mm/mempolicy.c SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le · line 1811

Quoted 4 lines
mm/mempolicy.c +0 -1
@@ -1808,7 +1822,6 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
 			break;
 		}
 
-		vma_start_write(vma);

Moving this vma_start_write() up means we will lock all vmas in the range regardless of if they are going to change. Was that your intention?

It might be better to move the locking to later in the loop, prior to the mpol_dup(), but after skipping other vmas?

Quoted 2 lines
mm/mempolicy.c +0 -0
 		new->home_node = home_node;
 		err = mbind_range(&vmi, vma, &prev, start, end, new);

...

Quoted 4 lines
mm/vma.c +0 -0
index bb4d0326fecb..1d21351282cf 100644

...

Quoted 13 lines
mm/vma.c +5 -0
@@ -2532,6 +2556,11 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
 		goto free_vma;
 	}
 
+	/* Lock the VMA since it is modified after insertion into VMA tree */
+	error = vma_start_write_killable(vma);
+	if (error)
+		goto free_iter_vma;
+
 	if (map->file)
 		error = __mmap_new_file_vma(map, vma);
 	else if (map->vm_flags & VM_SHARED)

mm/vma.c static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) · line 2586

Quoted 8 lines
mm/vma.c +0 -2
@@ -2552,8 +2581,6 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
 	WARN_ON_ONCE(!arch_validate_flags(map->vm_flags));
 #endif
 
-	/* Lock the VMA since it is modified after insertion into VMA tree */
-	vma_start_write(vma);
 	vma_iter_store_new(vmi, vma);
 	map->mm->map_count++;
 	vma_link_file(vma, map->hold_file_rmap_lock);

This is a bit of a nit on the placement..

Prior to this change, the write lock on the vma was taken next to where it was inserted in the tree. Now the lock is taken between vma iterator preallocations and part of the vma setup.

Would it make sense to put it closer to the vma allocation itself? I think all that's needed to be set is the mm struct for the locking to work?

...

mm/vma.c int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Quoted 1 line
mm/vma.c +0 -0
@@ -3089,7 +3120,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Good luck testing this one.

Quoted 27 lines
mm/vma.c +6 -4
 	struct mm_struct *mm = vma->vm_mm;
 	struct vm_area_struct *next;
 	unsigned long gap_addr;
-	int error = 0;
+	int error;
 	VMA_ITERATOR(vmi, mm, vma->vm_start);
 
 	if (!(vma->vm_flags & VM_GROWSUP))
@@ -3126,12 +3157,14 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
 
 	/* We must make sure the anon_vma is allocated. */
 	if (unlikely(anon_vma_prepare(vma))) {
-		vma_iter_free(&vmi);
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto free;
 	}
 
 	/* Lock the VMA before expanding to prevent concurrent page faults */
-	vma_start_write(vma);
+	error = vma_start_write_killable(vma);
+	if (error)
+		goto free;
 	/* We update the anon VMA tree. */
 	anon_vma_lock_write(vma->anon_vma);
 

mm/vma.c int expand_upwards(struct vm_area_struct *vma, unsigned long address) · line 3199

Quoted 7 lines
mm/vma.c +1 -0
@@ -3160,6 +3193,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
 		}
 	}
 	anon_vma_unlock_write(vma->anon_vma);
+free:
 	vma_iter_free(&vmi);
 	validate_mm(mm);
 	return error;

Looks okay.

...

author reviewer
#5 lore raw

Re: [PATCH v2 2/3] mm: replace vma_start_write() with vma_start_write_killable()

Quoted 71 lines · Liam R. Howlett
Quoted 38 lines · Suren Baghdasaryan

Now that we have vma_start_write_killable() we can replace most of the vma_start_write() calls with it, improving reaction time to the kill signal.

There are several places which are left untouched by this patch:

1. free_pgtables() because function should free page tables even if a fatal signal is pending.

2. process_vma_walk_lock(), which requires changes in its callers and will be handled in the next patch.

3. userfaultd code, where some paths calling vma_start_write() can handle EINTR and some can't without a deeper code refactoring.

4. vm_flags_{set|mod|clear} require refactoring that involves moving vma_start_write() out of these functions and replacing it with vma_assert_write_locked(), then callers of these functions should lock the vma themselves using vma_start_write_killable() whenever possible.

---
 arch/powerpc/kvm/book3s_hv_uvmem.c |  5 +-
 include/linux/mempolicy.h          |  5 +-
 mm/khugepaged.c                    |  5 +-
 mm/madvise.c                       |  4 +-
 mm/memory.c                        |  2 +
 mm/mempolicy.c                     | 23 ++++++--
 mm/mlock.c                         | 20 +++++--
 mm/mprotect.c                      |  4 +-
 mm/mremap.c                        |  4 +-
 mm/vma.c                           | 93 +++++++++++++++++++++---------
 mm/vma_exec.c                      |  6 +-
 11 files changed, 123 insertions(+), 48 deletions(-)

...

Quoted 2 lines
mm/mempolicy.c +0 -0

...

Quoted 23 lines

static const struct mempolicy_operations mpol_ops[MPOL_MAX] = {

mm/mempolicy.c +7 -1
@@ -1785,9 +1793,15 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
              return -EINVAL;
      if (end == start)
              return 0;
-     mmap_write_lock(mm);
+     if (mmap_write_lock_killable(mm))
+             return -EINTR;
      prev = vma_prev(&vmi);
      for_each_vma_range(vmi, vma, end) {
+             if (vma_start_write_killable(vma)) {
+                     err = -EINTR;
+                     break;
+             }
+
              /*
               * If any vma in the range got policy other than MPOL_BIND
               * or MPOL_PREFERRED_MANY we return error. We don't reset
@@ -1808,7 +1822,6 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le
                      break;
              }
 
Quoted 5 lines

mm/mempolicy.c SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le · line 1811

Quoted 1 line
mm/mempolicy.c +0 -1
-             vma_start_write(vma);

Moving this vma_start_write() up means we will lock all vmas in the range regardless of if they are going to change. Was that your intention?

No, I missed that this would result in unnecessary locks.

Quoted 3 lines

It might be better to move the locking to later in the loop, prior to the mpol_dup(), but after skipping other vmas?

Yes, that's the right place for it. Will move.

Quoted 37 lines
Quoted 3 lines
mm/mempolicy.c +0 -0
              new->home_node = home_node;
              err = mbind_range(&vmi, vma, &prev, start, end, new);

...

Quoted 4 lines
mm/vma.c +0 -0
index bb4d0326fecb..1d21351282cf 100644

...

Quoted 13 lines
mm/vma.c +5 -0
@@ -2532,6 +2556,11 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
              goto free_vma;
      }
 
+     /* Lock the VMA since it is modified after insertion into VMA tree */
+     error = vma_start_write_killable(vma);
+     if (error)
+             goto free_iter_vma;
+
      if (map->file)
              error = __mmap_new_file_vma(map, vma);
      else if (map->vm_flags & VM_SHARED)

mm/vma.c static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) · line 2586

Quoted 8 lines
mm/vma.c +0 -2
@@ -2552,8 +2581,6 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
      WARN_ON_ONCE(!arch_validate_flags(map->vm_flags));
 #endif
 
-     /* Lock the VMA since it is modified after insertion into VMA tree */
-     vma_start_write(vma);
      vma_iter_store_new(vmi, vma);
      map->mm->map_count++;
      vma_link_file(vma, map->hold_file_rmap_lock);

This is a bit of a nit on the placement..

Quoted 7 lines

Prior to this change, the write lock on the vma was taken next to where it was inserted in the tree. Now the lock is taken between vma iterator preallocations and part of the vma setup.

Would it make sense to put it closer to the vma allocation itself? I think all that's needed to be set is the mm struct for the locking to work?

I guess locking the vma before vma_iter_prealloc() would save us unnecessary alloc/free in case of a pending fatal signal. I'll move the lock right after vm_area_alloc() so that the entire vma setup is done on a locked vma.

Quoted 7 lines

...

mm/vma.c int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Quoted 1 line
mm/vma.c +0 -0
@@ -3089,7 +3120,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Good luck testing this one.

Yeah... Any suggestions for tests I should use?

Quoted 27 lines
Quoted 27 lines
mm/vma.c +6 -4
      struct mm_struct *mm = vma->vm_mm;
      struct vm_area_struct *next;
      unsigned long gap_addr;
-     int error = 0;
+     int error;
      VMA_ITERATOR(vmi, mm, vma->vm_start);
 
      if (!(vma->vm_flags & VM_GROWSUP))
@@ -3126,12 +3157,14 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
 
      /* We must make sure the anon_vma is allocated. */
      if (unlikely(anon_vma_prepare(vma))) {
-             vma_iter_free(&vmi);
-             return -ENOMEM;
+             error = -ENOMEM;
+             goto free;
      }
 
      /* Lock the VMA before expanding to prevent concurrent page faults */
-     vma_start_write(vma);
+     error = vma_start_write_killable(vma);
+     if (error)
+             goto free;
      /* We update the anon VMA tree. */
      anon_vma_lock_write(vma->anon_vma);
 
Quoted 10 lines

mm/vma.c int expand_upwards(struct vm_area_struct *vma, unsigned long address) · line 3199

Quoted 8 lines
mm/vma.c +1 -0
@@ -3160,6 +3193,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
              }
      }
      anon_vma_unlock_write(vma->anon_vma);
+free:
      vma_iter_free(&vmi);
      validate_mm(mm);
      return error;

Looks okay.

Thanks for the review, Liam! I'll wait a couple of days and post the v3 with fixes.

Quoted 5 lines

...

#6 lore raw

Re: [PATCH v2 2/3] mm: replace vma_start_write() with vma_start_write_killable()

Quoted 42 lines · Suren Baghdasaryan
Quoted 40 lines · Liam R. Howlett
Quoted 38 lines · Suren Baghdasaryan

Now that we have vma_start_write_killable() we can replace most of the vma_start_write() calls with it, improving reaction time to the kill signal.

There are several places which are left untouched by this patch:

1. free_pgtables() because function should free page tables even if a fatal signal is pending.

2. process_vma_walk_lock(), which requires changes in its callers and will be handled in the next patch.

3. userfaultd code, where some paths calling vma_start_write() can handle EINTR and some can't without a deeper code refactoring.

4. vm_flags_{set|mod|clear} require refactoring that involves moving vma_start_write() out of these functions and replacing it with vma_assert_write_locked(), then callers of these functions should lock the vma themselves using vma_start_write_killable() whenever possible.

---
 arch/powerpc/kvm/book3s_hv_uvmem.c |  5 +-
 include/linux/mempolicy.h          |  5 +-
 mm/khugepaged.c                    |  5 +-
 mm/madvise.c                       |  4 +-
 mm/memory.c                        |  2 +
 mm/mempolicy.c                     | 23 ++++++--
 mm/mlock.c                         | 20 +++++--
 mm/mprotect.c                      |  4 +-
 mm/mremap.c                        |  4 +-
 mm/vma.c                           | 93 +++++++++++++++++++++---------
 mm/vma_exec.c                      |  6 +-
 11 files changed, 123 insertions(+), 48 deletions(-)

...

Quoted 9 lines
Quoted 7 lines

...

Review int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Quoted 1 line
(quoted diff) +0 -0
@@ -3089,7 +3120,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Good luck testing this one.

Yeah... Any suggestions for tests I should use?

I think you have to either isolate it or boot parisc.

To boot parisc, you can use the debian hppa image [1]. The file is a zip file which can be decompressed to a qcow2, initrd, and kernel. You can boot with qemu-system-hppa (debian has this in qemu-system-misc package), there is a readme that has a boot line as well.

Building can be done using the cross-compiler tools for hppa [2] and the make command with CROSS_COMPILE=<path>/bin/hppa64-linux-

Cheers,
Liam

[1]. https://people.debian.org/~gio/dqib/
[2]. https://cdn.kernel.org/pub/tools/crosstool/files/bin/x86_64/15.2.0/

author reviewer
#7 lore raw

Re: [PATCH v2 2/3] mm: replace vma_start_write() with vma_start_write_killable()

Quoted 59 lines · Liam R. Howlett
Quoted 42 lines · Suren Baghdasaryan
Quoted 40 lines · Liam R. Howlett
Quoted 38 lines · Suren Baghdasaryan

Now that we have vma_start_write_killable() we can replace most of the vma_start_write() calls with it, improving reaction time to the kill signal.

There are several places which are left untouched by this patch:

1. free_pgtables() because function should free page tables even if a fatal signal is pending.

2. process_vma_walk_lock(), which requires changes in its callers and will be handled in the next patch.

3. userfaultd code, where some paths calling vma_start_write() can handle EINTR and some can't without a deeper code refactoring.

4. vm_flags_{set|mod|clear} require refactoring that involves moving vma_start_write() out of these functions and replacing it with vma_assert_write_locked(), then callers of these functions should lock the vma themselves using vma_start_write_killable() whenever possible.

---
 arch/powerpc/kvm/book3s_hv_uvmem.c |  5 +-
 include/linux/mempolicy.h          |  5 +-
 mm/khugepaged.c                    |  5 +-
 mm/madvise.c                       |  4 +-
 mm/memory.c                        |  2 +
 mm/mempolicy.c                     | 23 ++++++--
 mm/mlock.c                         | 20 +++++--
 mm/mprotect.c                      |  4 +-
 mm/mremap.c                        |  4 +-
 mm/vma.c                           | 93 +++++++++++++++++++++---------
 mm/vma_exec.c                      |  6 +-
 11 files changed, 123 insertions(+), 48 deletions(-)

...

Quoted 9 lines
Quoted 7 lines

...

Review int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Quoted 1 line
(quoted diff) +0 -0
@@ -3089,7 +3120,7 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)

Good luck testing this one.

Yeah... Any suggestions for tests I should use?

I think you have to either isolate it or boot parisc.

Quoted 7 lines

To boot parisc, you can use the debian hppa image [1]. The file is a zip file which can be decompressed to a qcow2, initrd, and kernel. You can boot with qemu-system-hppa (debian has this in qemu-system-misc package), there is a readme that has a boot line as well.

Building can be done using the cross-compiler tools for hppa [2] and the make command with CROSS_COMPILE=<path>/bin/hppa64-linux-

Ah, I thought you were referring to the difficulty of finding specific tests to verify this change but these instructions are helpful too. Thanks!

Quoted 8 lines

Cheers,
Liam

[1]. https://people.debian.org/~gio/dqib/
[2]. https://cdn.kernel.org/pub/tools/crosstool/files/bin/x86_64/15.2.0/

author reviewer
#8 lore raw

PATCH v2 3/3 mm: use vma_start_write_killable() in process_vma_walk_lock()

In reply to Suren Baghdasaryan

Replace vma_start_write() with vma_start_write_killable() when process_vma_walk_lock() is used with PGWALK_WRLOCK option. Adjust its direct and indirect users to check for a possible error and handle it.

---
 arch/s390/kvm/kvm-s390.c |  5 +++--
 arch/s390/mm/gmap.c      | 13 ++++++++++---
 fs/proc/task_mmu.c       |  7 ++++++-
 mm/pagewalk.c            | 20 ++++++++++++++------
 4 files changed, 33 insertions(+), 12 deletions(-)
arch/s390/kvm/kvm-s390.c +3 -2
index 56a50524b3ee..75aef9c66e03 100644
@@ -958,6 +958,7 @@ static int kvm_s390_get_mem_control(struct kvm *kvm, struct kvm_device_attr *att
 static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *attr)
 {
 	int ret;
+	int err;
 	unsigned int idx;
 	switch (attr->attr) {
 	case KVM_S390_VM_MEM_ENABLE_CMMA:
@@ -990,10 +991,10 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att
 		VM_EVENT(kvm, 3, "%s", "RESET: CMMA states");
 		mutex_lock(&kvm->lock);
 		idx = srcu_read_lock(&kvm->srcu);
-		s390_reset_cmma(kvm->arch.gmap->mm);
+		err = s390_reset_cmma(kvm->arch.gmap->mm);
 		srcu_read_unlock(&kvm->srcu, idx);
 		mutex_unlock(&kvm->lock);
-		ret = 0;
+		ret = (err < 0) ? err : 0;
 		break;
 	case KVM_S390_VM_MEM_LIMIT_SIZE: {
 		unsigned long new_limit;
arch/s390/mm/gmap.c +10 -3
index dd85bcca817d..96054b124db5 100644
@@ -2271,6 +2271,7 @@ int s390_enable_skey(void)
 {
 	struct mm_struct *mm = current->mm;
 	int rc = 0;
+	int err;
 
 	mmap_write_lock(mm);
 	if (mm_uses_skeys(mm))
@@ -2282,7 +2283,9 @@ int s390_enable_skey(void)
 		mm->context.uses_skeys = 0;
 		goto out_up;
 	}
-	walk_page_range(mm, 0, TASK_SIZE, &enable_skey_walk_ops, NULL);
+	err = walk_page_range(mm, 0, TASK_SIZE, &enable_skey_walk_ops, NULL);
+	if (err < 0)
+		rc = err;
 
 out_up:
 	mmap_write_unlock(mm);
@@ -2305,11 +2308,15 @@ static const struct mm_walk_ops reset_cmma_walk_ops = {
 	.walk_lock		= PGWALK_WRLOCK,
 };
 
-void s390_reset_cmma(struct mm_struct *mm)
+int s390_reset_cmma(struct mm_struct *mm)
 {
+	int err;
+
 	mmap_write_lock(mm);
-	walk_page_range(mm, 0, TASK_SIZE, &reset_cmma_walk_ops, NULL);
+	err = walk_page_range(mm, 0, TASK_SIZE, &reset_cmma_walk_ops, NULL);
 	mmap_write_unlock(mm);
+
+	return (err < 0) ? err : 0;
 }
 EXPORT_SYMBOL_GPL(s390_reset_cmma);
 
fs/proc/task_mmu.c +6 -1
index d7d52e259055..91e806d65bd9 100644
@@ -1797,6 +1797,7 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 		struct clear_refs_private cp = {
 			.type = type,
 		};
+		int err;
 
 		if (mmap_write_lock_killable(mm)) {
 			count = -EINTR;
@@ -1824,7 +1825,11 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
 						0, mm, 0, -1UL);
 			mmu_notifier_invalidate_range_start(&range);
 		}
-		walk_page_range(mm, 0, -1, &clear_refs_walk_ops, &cp);
+		err = walk_page_range(mm, 0, -1, &clear_refs_walk_ops, &cp);
+		if (err < 0) {
+			count = err;
+			goto out_unlock;
+		}
 		if (type == CLEAR_REFS_SOFT_DIRTY) {
 			mmu_notifier_invalidate_range_end(&range);
 			flush_tlb_mm(mm);
mm/pagewalk.c +14 -6
index a94c401ab2cf..dc9f7a7709c6 100644
@@ -425,14 +425,13 @@ static inline void process_mm_walk_lock(struct mm_struct *mm,
 		mmap_assert_write_locked(mm);
 }
 
-static inline void process_vma_walk_lock(struct vm_area_struct *vma,
+static inline int process_vma_walk_lock(struct vm_area_struct *vma,
 					 enum page_walk_lock walk_lock)
 {
 #ifdef CONFIG_PER_VMA_LOCK
 	switch (walk_lock) {
 	case PGWALK_WRLOCK:
-		vma_start_write(vma);
-		break;
+		return vma_start_write_killable(vma);
 	case PGWALK_WRLOCK_VERIFY:
 		vma_assert_write_locked(vma);
 		break;
@@ -444,6 +443,7 @@ static inline void process_vma_walk_lock(struct vm_area_struct *vma,
 		break;
 	}
 #endif
+	return 0;
 }
 
 /*
@@ -487,7 +487,9 @@ int walk_page_range_mm_unsafe(struct mm_struct *mm, unsigned long start,
 			if (ops->pte_hole)
 				err = ops->pte_hole(start, next, -1, &walk);
 		} else { /* inside vma */
-			process_vma_walk_lock(vma, ops->walk_lock);
+			err = process_vma_walk_lock(vma, ops->walk_lock);
+			if (err)
+				break;
 			walk.vma = vma;
 			next = min(end, vma->vm_end);
 			vma = find_vma(mm, vma->vm_end);
@@ -704,6 +706,7 @@ int walk_page_range_vma_unsafe(struct vm_area_struct *vma, unsigned long start,
 		.vma		= vma,
 		.private	= private,
 	};
+	int err;
 
 	if (start >= end || !walk.mm)
 		return -EINVAL;
@@ -711,7 +714,9 @@ int walk_page_range_vma_unsafe(struct vm_area_struct *vma, unsigned long start,
 		return -EINVAL;
 
 	process_mm_walk_lock(walk.mm, ops->walk_lock);
-	process_vma_walk_lock(vma, ops->walk_lock);
+	err = process_vma_walk_lock(vma, ops->walk_lock);
+	if (err)
+		return err;
 	return __walk_page_range(start, end, &walk);
 }
 
@@ -734,6 +739,7 @@ int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,
 		.vma		= vma,
 		.private	= private,
 	};
+	int err;
 
 	if (!walk.mm)
 		return -EINVAL;
@@ -741,7 +747,9 @@ int walk_page_vma(struct vm_area_struct *vma, const struct mm_walk_ops *ops,
 		return -EINVAL;
 
 	process_mm_walk_lock(walk.mm, ops->walk_lock);
-	process_vma_walk_lock(vma, ops->walk_lock);
+	err = process_vma_walk_lock(vma, ops->walk_lock);
+	if (err)
+		return err;
 	return __walk_page_range(vma->vm_start, vma->vm_end, &walk);
 }
 
Signature · 1 line
2.53.0.273.g2a3d683680-goog
maintainer
#9 lore raw

Re: [PATCH v2 3/3] mm: use vma_start_write_killable() in process_vma_walk_lock()

Quoted 5 lines · Suren Baghdasaryan

Replace vma_start_write() with vma_start_write_killable() when process_vma_walk_lock() is used with PGWALK_WRLOCK option. Adjust its direct and indirect users to check for a possible error and handle it.

Quoted 7 lines
---
 arch/s390/kvm/kvm-s390.c |  5 +++--
 arch/s390/mm/gmap.c      | 13 ++++++++++---
 fs/proc/task_mmu.c       |  7 ++++++-
 mm/pagewalk.c            | 20 ++++++++++++++------
 4 files changed, 33 insertions(+), 12 deletions(-)

The s390 code modified with this patch does not exist upstream anymore. It has been replaced with Claudio's huge gmap rewrite.

author reviewer
#10 lore raw

Re: [PATCH v2 3/3] mm: use vma_start_write_killable() in process_vma_walk_lock()

Quoted 15 lines · Heiko Carstens
Quoted 5 lines · Suren Baghdasaryan

Replace vma_start_write() with vma_start_write_killable() when process_vma_walk_lock() is used with PGWALK_WRLOCK option. Adjust its direct and indirect users to check for a possible error and handle it.

Quoted 7 lines
---
 arch/s390/kvm/kvm-s390.c |  5 +++--
 arch/s390/mm/gmap.c      | 13 ++++++++++---
 fs/proc/task_mmu.c       |  7 ++++++-
 mm/pagewalk.c            | 20 ++++++++++++++------
 4 files changed, 33 insertions(+), 12 deletions(-)
Quoted 2 lines

The s390 code modified with this patch does not exist upstream anymore. It has been replaced with Claudio's huge gmap rewrite.

Hmm. My patchset is based on mm-new. I guess the code was modified in some other tree. Could you please provide a link to that patchset so I can track it? I'll probably remove this patch from my set until that one is merged.

maintainer
#11 lore raw

Re: [PATCH v2 3/3] mm: use vma_start_write_killable() in process_vma_walk_lock()

Quoted 16 lines · Suren Baghdasaryan
Quoted 15 lines · Heiko Carstens
Quoted 12 lines · Suren Baghdasaryan

Replace vma_start_write() with vma_start_write_killable() when process_vma_walk_lock() is used with PGWALK_WRLOCK option. Adjust its direct and indirect users to check for a possible error and handle it.

---
 arch/s390/kvm/kvm-s390.c |  5 +++--
 arch/s390/mm/gmap.c      | 13 ++++++++++---
 fs/proc/task_mmu.c       |  7 ++++++-
 mm/pagewalk.c            | 20 ++++++++++++++------
 4 files changed, 33 insertions(+), 12 deletions(-)
Quoted 7 lines
Quoted 2 lines

The s390 code modified with this patch does not exist upstream anymore. It has been replaced with Claudio's huge gmap rewrite.

Hmm. My patchset is based on mm-new. I guess the code was modified in some other tree. Could you please provide a link to that patchset so I can track it? I'll probably remove this patch from my set until that one is merged.

This is the corresponding merge commit in Linus' tree:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=b1195183ed42f1522fae3fe44ebee3af437aa000

#12 lore raw

Re: [PATCH v2 3/3] mm: use vma_start_write_killable() in process_vma_walk_lock()

In reply to Suren Baghdasaryan
Quoted 4 lines · Suren Baghdasaryan

Hmm. My patchset is based on mm-new. I guess the code was modified in some other tree. Could you please provide a link to that patchset so I can track it? I'll probably remove this patch from my set until that one is merged.

mm-new is a bad place to be playing; better to base off mm-unstable.

author reviewer
#13 lore raw

Re: [PATCH v2 3/3] mm: use vma_start_write_killable() in process_vma_walk_lock()

Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Suren Baghdasaryan

Hmm. My patchset is based on mm-new. I guess the code was modified in some other tree. Could you please provide a link to that patchset so I can track it? I'll probably remove this patch from my set until that one is merged.

mm-new is a bad place to be playing; better to base off mm-unstable.

Ah, I see. I'll redo my patchset on top of that then. Thanks for the tip!

#14 lore raw

Re: [PATCH v2 3/3] mm: use vma_start_write_killable() in process_vma_walk_lock()

In reply to Suren Baghdasaryan
kernel test robot noticed the following build errors:

Hi Suren,

kernel test robot noticed the following build errors:

[auto build test ERROR on b08472d036a36893ecf68296d87beb58d21f4357]

url:    https://github.com/intel-lab-lkp/linux/commits/Suren-Baghdasaryan/mm-vma-cleanup-error-handling-path-in-vma_expand/20260218-003502
base:   b08472d036a36893ecf68296d87beb58d21f4357
patch link:    https://lore.kernel.org/r/20260217163250.2326001-4-surenb%40google.com
patch subject: [PATCH v2 3/3] mm: use vma_start_write_killable() in process_vma_walk_lock()
config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20260218/[email protected]/config)
compiler: s390-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260218/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> arch/s390/mm/gmap.c:2311:5: error: conflicting types for 's390_reset_cmma'; have 'int(struct mm_struct *)'
    2311 | int s390_reset_cmma(struct mm_struct *mm)
         |     ^~~~~~~~~~~~~~~
   In file included from include/linux/pgtable.h:6,
                    from include/linux/mm.h:32,
                    from include/linux/pagewalk.h:5,
                    from arch/s390/mm/gmap.c:14:
   arch/s390/include/asm/pgtable.h:2020:13: note: previous declaration of 's390_reset_cmma' with type 'void(struct mm_struct *)'
    2020 | extern void s390_reset_cmma(struct mm_struct *mm);
         |             ^~~~~~~~~~~~~~~
   In file included from include/linux/linkage.h:7,
                    from include/linux/printk.h:8,
                    from include/asm-generic/bug.h:31,
                    from arch/s390/include/asm/bug.h:60,
                    from include/linux/bug.h:5,
                    from include/linux/fortify-string.h:6,
                    from include/linux/string.h:386,
                    from include/linux/uuid.h:11,
                    from include/linux/mod_devicetable.h:14,
                    from include/linux/cpufeature.h:12,
                    from arch/s390/mm/gmap.c:11:
   arch/s390/mm/gmap.c:2321:19: error: conflicting types for 's390_reset_cmma'; have 'int(struct mm_struct *)'
    2321 | EXPORT_SYMBOL_GPL(s390_reset_cmma);
         |                   ^~~~~~~~~~~~~~~
   include/linux/export.h:76:28: note: in definition of macro '__EXPORT_SYMBOL'
      76 |         extern typeof(sym) sym;                                 \
         |                            ^~~
   include/linux/export.h:90:41: note: in expansion of macro '_EXPORT_SYMBOL'
      90 | #define EXPORT_SYMBOL_GPL(sym)          _EXPORT_SYMBOL(sym, "GPL")
         |                                         ^~~~~~~~~~~~~~
   arch/s390/mm/gmap.c:2321:1: note: in expansion of macro 'EXPORT_SYMBOL_GPL'
    2321 | EXPORT_SYMBOL_GPL(s390_reset_cmma);
         | ^~~~~~~~~~~~~~~~~
   arch/s390/include/asm/pgtable.h:2020:13: note: previous declaration of 's390_reset_cmma' with type 'void(struct mm_struct *)'
    2020 | extern void s390_reset_cmma(struct mm_struct *mm);
         |             ^~~~~~~~~~~~~~~
--
   arch/s390/kvm/kvm-s390.c: In function 'kvm_s390_set_mem_control':
>> arch/s390/kvm/kvm-s390.c:994:21: error: invalid use of void expression
     994 |                 err = s390_reset_cmma(kvm->arch.gmap->mm);
         |                     ^

vim +2311 arch/s390/mm/gmap.c

2310

> 2311	int s390_reset_cmma(struct mm_struct *mm)

2312 {
2313 int err;
2314
2315 mmap_write_lock(mm);
2316 err = walk_page_range(mm, 0, TASK_SIZE, &reset_cmma_walk_ops, NULL);
2317 mmap_write_unlock(mm);
2318
2319 return (err < 0) ? err : 0;
2320 }
2321 EXPORT_SYMBOL_GPL(s390_reset_cmma);
2322

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki