Skip to contentSkip to conversation

ipipe: mm: Restore unCOW support for copy_pte_range

PATCH In review Jan Kiszka 4 participants 10 messages Mar 5, 2021 – Mar 15, 2021

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 ipipe: mm: Restore unCOW support for copy_pte_range

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor faults after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the complete smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64 isn't in sync with noarch, you will need manual merging). Possibly, it already applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +69 -7
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-		pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
-		unsigned long addr, int *rss)
+	     pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+	     unsigned long addr, int *rss, pmd_t *src_pmd,
+	     struct page *uncow_page)
 {
 	unsigned long vm_flags = vma->vm_flags;
 	pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	 * in the parent and the child
 	 */
 	if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+		if (uncow_page) {
+			struct page *old_page = vm_normal_page(vma, addr, pte);
+			struct vm_fault vmf;
+
+			vmf.vma = vma;
+			vmf.address = addr;
+			vmf.orig_pte = pte;
+			vmf.pmd = src_pmd;
+
+			if (cow_user_page(uncow_page, old_page, &vmf)) {
+				pte = mk_pte(uncow_page, vma->vm_page_prot);
+
+				if (vm_flags & VM_SHARED)
+					pte = pte_mkclean(pte);
+				pte = pte_mkold(pte);
+
+				page_add_new_anon_rmap(uncow_page, vma, addr,
+						       false);
+				rss[!!PageAnon(uncow_page)]++;
+				goto out_set_pte;
+			} else {
+				/* unexpected: source page no longer present */
+				WARN_ON_ONCE(1);
+			}
+		}
+#endif /* CONFIG_IPIPE */
 		ptep_set_wrprotect(src_mm, addr, src_pte);
 		pte = pte_wrprotect(pte);
 	}
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	int progress = 0;
 	int rss[NR_MM_COUNTERS];
 	swp_entry_t entry = (swp_entry_t){0};
-
+	struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+	int do_cow_break = 0;
+again:
+	if (do_cow_break) {
+		uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+		if (uncow_page == NULL)
+			return -ENOMEM;
+		do_cow_break = 0;
+	}
+#else
 again:
+#endif
 	init_rss_vec(rss);
 
 	dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-	if (!dst_pte)
+	if (!dst_pte) {
+		if (uncow_page)
+			put_page(uncow_page);
 		return -ENOMEM;
+	}
 	src_pte = pte_offset_map(src_pmd, addr);
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 			progress++;
 			continue;
 		}
+#ifdef CONFIG_IPIPE
+		if (likely(uncow_page == NULL) && likely(pte_present(*src_pte))) {
+			if (is_cow_mapping(vma->vm_flags) &&
+			    test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+			    ((vma->vm_flags|src_mm->def_flags) & VM_LOCKED)) {
+				arch_leave_lazy_mmu_mode();
+				spin_unlock(src_ptl);
+				pte_unmap(src_pte);
+				add_mm_rss_vec(dst_mm, rss);
+				pte_unmap_unlock(dst_pte, dst_ptl);
+				cond_resched();
+				do_cow_break = 1;
+				goto again;
+			}
+		}
+#endif
 		entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-							vma, addr, rss);
+					 vma, addr, rss, src_pmd, uncow_page);
+		uncow_page = NULL;
 		if (entry.val)
 			break;
 		progress += 8;
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
 	return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-				 struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf)
 {
 	bool ret;
 	void *kaddr;
Signature · 6 lines
2.26.2


-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
author
#1 lore raw
Quoted 141 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor faults after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the complete smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64 isn't in sync with noarch, you will need manual merging). Possibly, it already applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +67 -5
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-		pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
-		unsigned long addr, int *rss)
+	     pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+	     unsigned long addr, int *rss, pmd_t *src_pmd,
+	     struct page *uncow_page)
 {
 	unsigned long vm_flags = vma->vm_flags;
 	pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	 * in the parent and the child
 	 */
 	if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+		if (uncow_page) {
+			struct page *old_page = vm_normal_page(vma, addr, pte);
+			struct vm_fault vmf;
+
+			vmf.vma = vma;
+			vmf.address = addr;
+			vmf.orig_pte = pte;
+			vmf.pmd = src_pmd;
+
+			if (cow_user_page(uncow_page, old_page, &vmf)) {
+				pte = mk_pte(uncow_page, vma->vm_page_prot);
+
+				if (vm_flags & VM_SHARED)
+					pte = pte_mkclean(pte);
+				pte = pte_mkold(pte);
+
+				page_add_new_anon_rmap(uncow_page, vma, addr,
+						       false);
+				rss[!!PageAnon(uncow_page)]++;
+				goto out_set_pte;
+			} else {
+				/* unexpected: source page no longer present */
+				WARN_ON_ONCE(1);
+			}
+		}
+#endif /* CONFIG_IPIPE */
 		ptep_set_wrprotect(src_mm, addr, src_pte);
 		pte = pte_wrprotect(pte);
 	}
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	int progress = 0;
 	int rss[NR_MM_COUNTERS];
 	swp_entry_t entry = (swp_entry_t){0};
-
+	struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+	int do_cow_break = 0;
+again:
+	if (do_cow_break) {
+		uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+		if (uncow_page == NULL)
+			return -ENOMEM;
+		do_cow_break = 0;
+	}
+#else
 again:
+#endif
 	init_rss_vec(rss);
 
 	dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-	if (!dst_pte)
+	if (!dst_pte) {
+		if (uncow_page)
+			put_page(uncow_page);
 		return -ENOMEM;
+	}
 	src_pte = pte_offset_map(src_pmd, addr);
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 			progress++;
 			continue;
 		}
+#ifdef CONFIG_IPIPE
+		if (likely(uncow_page == NULL) && likely(pte_present(*src_pte))) {
+			if (is_cow_mapping(vma->vm_flags) &&
+			    test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+			    ((vma->vm_flags|src_mm->def_flags) & VM_LOCKED)) {
+				arch_leave_lazy_mmu_mode();
+				spin_unlock(src_ptl);
+				pte_unmap(src_pte);
+				add_mm_rss_vec(dst_mm, rss);
+				pte_unmap_unlock(dst_pte, dst_ptl);
+				cond_resched();
+				do_cow_break = 1;
+				goto again;
+			}
+		}
+#endif
 		entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-							vma, addr, rss);
+					 vma, addr, rss, src_pmd, uncow_page);
+		uncow_page = NULL;
 		if (entry.val)
 			break;
 		progress += 8;

mm/memory.c static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, · line 2417

Quoted 10 lines
mm/memory.c +2 -2
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
 	return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-				 struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf)
 {
 	bool ret;
 	void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are gone, see

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with other topics. Any comments?

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#2 lore raw

Am Sat, 6 Mar 2021 14:14:30 +0100
schrieb Jan Kiszka via Xenomai <[email protected]>:

Quoted 175 lines · Jan Kiszka via Xenomai
Quoted 168 lines

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor faults after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the complete smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64 isn't in sync with noarch, you will need manual merging). Possibly, it already applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76

++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-)

mm/memory.c +6 -2
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct
 vm_area_struct *vma, unsigned long addr, 
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-		pte_t *dst_pte, pte_t *src_pte, struct
 vm_area_struct *vma,
-		unsigned long addr, int *rss)
+	     pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct
 *vma,
+	     unsigned long addr, int *rss, pmd_t *src_pmd,
+	     struct page *uncow_page)
 {
mm/memory.c +12 -0
 	unsigned long vm_flags = vma->vm_flags;
 	pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm,
 struct mm_struct *src_mm,
 	 * in the parent and the child
 	 */
 	if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+		if (uncow_page) {
+			struct page *old_page =
 vm_normal_page(vma, addr, pte);
+			struct vm_fault vmf;
+
+			vmf.vma = vma;
+			vmf.address = addr;
+			vmf.orig_pte = pte;
+			vmf.pmd = src_pmd;
+
+			if (cow_user_page(uncow_page, old_page,
 &vmf)) {
+				pte = mk_pte(uncow_page,

vma->vm_page_prot); +

mm/memory.c +5 -0
+				if (vm_flags & VM_SHARED)
+					pte = pte_mkclean(pte);
+				pte = pte_mkold(pte);
+
+				page_add_new_anon_rmap(uncow_page,

vma, addr,

mm/memory.c +5 -0
+						       false);
+				rss[!!PageAnon(uncow_page)]++;
+				goto out_set_pte;
+			} else {
+				/* unexpected: source page no

longer present */

mm/memory.c +20 -2
+				WARN_ON_ONCE(1);
+			}
+		}
+#endif /* CONFIG_IPIPE */
 		ptep_set_wrprotect(src_mm, addr, src_pte);
 		pte = pte_wrprotect(pte);
 	}
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct
 *dst_mm, struct mm_struct *src_mm, int progress = 0;
 	int rss[NR_MM_COUNTERS];
 	swp_entry_t entry = (swp_entry_t){0};
-
+	struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+	int do_cow_break = 0;
+again:
+	if (do_cow_break) {
+		uncow_page = alloc_page_vma(GFP_HIGHUSER, vma,
 addr);
+		if (uncow_page == NULL)
+			return -ENOMEM;
+		do_cow_break = 0;
+	}
+#else
 again:
+#endif
 	init_rss_vec(rss);
 
 	dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr,
 &dst_ptl);
-	if (!dst_pte)
+	if (!dst_pte) {
+		if (uncow_page)
+			put_page(uncow_page);
 		return -ENOMEM;
+	}
 	src_pte = pte_offset_map(src_pmd, addr);
mm/memory.c +4 -0
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct
 *dst_mm, struct mm_struct *src_mm, progress++;
 			continue;
 		}
+#ifdef CONFIG_IPIPE
+		if (likely(uncow_page == NULL) &&
 likely(pte_present(*src_pte))) {
+			if (is_cow_mapping(vma->vm_flags) &&
+			    test_bit(MMF_VM_PINNED,

&src_mm->flags) &&

mm/memory.c +1 -0
+			    ((vma->vm_flags|src_mm->def_flags) &

VM_LOCKED)) {

mm/memory.c +11 -0
+				arch_leave_lazy_mmu_mode();
+				spin_unlock(src_ptl);
+				pte_unmap(src_pte);
+				add_mm_rss_vec(dst_mm, rss);
+				pte_unmap_unlock(dst_pte, dst_ptl);
+				cond_resched();
+				do_cow_break = 1;
+				goto again;
+			}
+		}
+#endif
 		entry.val = copy_one_pte(dst_mm, src_mm, dst_pte,

src_pte,

mm/memory.c +0 -1
-							vma, addr,

rss);

mm/memory.c +1 -0
+					 vma, addr, rss, src_pmd,

uncow_page);

mm/memory.c +3 -2
+		uncow_page = NULL;
 		if (entry.val)
 			break;
 		progress += 8;
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct
 mm_struct *mm, pmd_t *pmd, return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page
 *src,
-				 struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf)
 {
 	bool ret;
Quoted 2 lines

void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are gone, see

Quoted 4 lines

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with other topics. Any comments?

Did not yet test myself, but that looks like bringing back the patch that my bisect found. So i assume it will work, and that code is well known and tested.

So i would say, go ahead. Will allow me to release for my customer.

Thanks,
Henning

Quoted 2 lines

Jan

#3 lore raw
In reply to Jan Kiszka
Quoted 156 lines · Jan Kiszka
Quoted 142 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor faults after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the complete smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64 isn't in sync with noarch, you will need manual merging). Possibly, it already applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +33 -2
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-		pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
-		unsigned long addr, int *rss)
+	     pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+	     unsigned long addr, int *rss, pmd_t *src_pmd,
+	     struct page *uncow_page)
 {
 	unsigned long vm_flags = vma->vm_flags;
 	pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	 * in the parent and the child
 	 */
 	if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+		if (uncow_page) {
+			struct page *old_page = vm_normal_page(vma, addr, pte);
+			struct vm_fault vmf;
+
+			vmf.vma = vma;
+			vmf.address = addr;
+			vmf.orig_pte = pte;
+			vmf.pmd = src_pmd;
+
+			if (cow_user_page(uncow_page, old_page, &vmf)) {
+				pte = mk_pte(uncow_page, vma->vm_page_prot);
+
+				if (vm_flags & VM_SHARED)
+					pte = pte_mkclean(pte);
+				pte = pte_mkold(pte);
+
+				page_add_new_anon_rmap(uncow_page, vma, addr,
 
+						       false);
+				rss[!!PageAnon(uncow_page)]++;
+				goto out_set_pte;
+			} else {
+				/* unexpected: source page no longer present */
+				WARN_ON_ONCE(1);
+			}
+		}
+#endif /* CONFIG_IPIPE */
 		ptep_set_wrprotect(src_mm, addr, src_pte);
 		pte = pte_wrprotect(pte);
mm/memory.c +34 -3
 	}
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	int progress = 0;
 	int rss[NR_MM_COUNTERS];
 	swp_entry_t entry = (swp_entry_t){0};
-
+	struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+	int do_cow_break = 0;
+again:
+	if (do_cow_break) {
+		uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+		if (uncow_page == NULL)
+			return -ENOMEM;
+		do_cow_break = 0;
+	}
+#else
 again:
+#endif
 	init_rss_vec(rss);
 
 	dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-	if (!dst_pte)
+	if (!dst_pte) {
+		if (uncow_page)
+			put_page(uncow_page);
 		return -ENOMEM;
+	}
 	src_pte = pte_offset_map(src_pmd, addr);
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 			progress++;
 			continue;
 		}
+#ifdef CONFIG_IPIPE
+		if (likely(uncow_page == NULL) && likely(pte_present(*src_pte))) {
+			if (is_cow_mapping(vma->vm_flags) &&
+			    test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+			    ((vma->vm_flags|src_mm->def_flags) & VM_LOCKED)) {
+				arch_leave_lazy_mmu_mode();
+				spin_unlock(src_ptl);
+				pte_unmap(src_pte);
+				add_mm_rss_vec(dst_mm, rss);
+				pte_unmap_unlock(dst_pte, dst_ptl);
+				cond_resched();
+				do_cow_break = 1;
+				goto again;
+			}
+		}
+#endif
 		entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-							vma, addr, rss);
+					 vma, addr, rss, src_pmd, uncow_page);
+		uncow_page = NULL;
 		if (entry.val)
 			break;
 		progress += 8;

mm/memory.c static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, · line 2417

Quoted 10 lines
mm/memory.c +2 -2
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
 	return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-				 struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf)
 {
 	bool ret;
 	void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are gone, see

Quoted 5 lines

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with other topics. Any comments?

Fine with me. This code can be simplified, working on it. I'll channel this through Dovetail.

Signature · 1 line
Philippe.
author
#4 lore raw
Quoted 159 lines · Philippe Gerum
Quoted 156 lines · Jan Kiszka
Quoted 142 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor faults after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the complete smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64 isn't in sync with noarch, you will need manual merging). Possibly, it already applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +33 -2
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-		pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
-		unsigned long addr, int *rss)
+	     pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+	     unsigned long addr, int *rss, pmd_t *src_pmd,
+	     struct page *uncow_page)
 {
 	unsigned long vm_flags = vma->vm_flags;
 	pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	 * in the parent and the child
 	 */
 	if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+		if (uncow_page) {
+			struct page *old_page = vm_normal_page(vma, addr, pte);
+			struct vm_fault vmf;
+
+			vmf.vma = vma;
+			vmf.address = addr;
+			vmf.orig_pte = pte;
+			vmf.pmd = src_pmd;
+
+			if (cow_user_page(uncow_page, old_page, &vmf)) {
+				pte = mk_pte(uncow_page, vma->vm_page_prot);
+
+				if (vm_flags & VM_SHARED)
+					pte = pte_mkclean(pte);
+				pte = pte_mkold(pte);
+
+				page_add_new_anon_rmap(uncow_page, vma, addr,
 
+						       false);
+				rss[!!PageAnon(uncow_page)]++;
+				goto out_set_pte;
+			} else {
+				/* unexpected: source page no longer present */
+				WARN_ON_ONCE(1);
+			}
+		}
+#endif /* CONFIG_IPIPE */
 		ptep_set_wrprotect(src_mm, addr, src_pte);
 		pte = pte_wrprotect(pte);
mm/memory.c +34 -3
 	}
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	int progress = 0;
 	int rss[NR_MM_COUNTERS];
 	swp_entry_t entry = (swp_entry_t){0};
-
+	struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+	int do_cow_break = 0;
+again:
+	if (do_cow_break) {
+		uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+		if (uncow_page == NULL)
+			return -ENOMEM;
+		do_cow_break = 0;
+	}
+#else
 again:
+#endif
 	init_rss_vec(rss);
 
 	dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-	if (!dst_pte)
+	if (!dst_pte) {
+		if (uncow_page)
+			put_page(uncow_page);
 		return -ENOMEM;
+	}
 	src_pte = pte_offset_map(src_pmd, addr);
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 			progress++;
 			continue;
 		}
+#ifdef CONFIG_IPIPE
+		if (likely(uncow_page == NULL) && likely(pte_present(*src_pte))) {
+			if (is_cow_mapping(vma->vm_flags) &&
+			    test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+			    ((vma->vm_flags|src_mm->def_flags) & VM_LOCKED)) {
+				arch_leave_lazy_mmu_mode();
+				spin_unlock(src_ptl);
+				pte_unmap(src_pte);
+				add_mm_rss_vec(dst_mm, rss);
+				pte_unmap_unlock(dst_pte, dst_ptl);
+				cond_resched();
+				do_cow_break = 1;
+				goto again;
+			}
+		}
+#endif
 		entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-							vma, addr, rss);
+					 vma, addr, rss, src_pmd, uncow_page);
+		uncow_page = NULL;
 		if (entry.val)
 			break;
 		progress += 8;

mm/memory.c static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, · line 2417

Quoted 10 lines
mm/memory.c +2 -2
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
 	return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-				 struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf)
 {
 	bool ret;
 	void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are gone, see

Quoted 9 lines
Quoted 5 lines

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with other topics. Any comments?

Fine with me. This code can be simplified, working on it. I'll channel this through Dovetail.

OK, applied.

Greg, you can find updated no-arch branches for 4.19 and 5.4.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#5 lore raw
Quoted 183 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor

faults

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the

complete

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64

isn't

Quoted 1 line
Quoted 1 line
Quoted 1 line

in sync with noarch, you will need manual merging). Possibly, it

already

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +0 -0
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
Quoted 7 lines
Quoted 7 lines

mm/memory.c struct page *vm_normal_page_pmd(struct

Quoted 7 lines
mm/memory.c +3 -0
+static bool cow_user_page(struct page *dst, struct page *src,
+                     struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct

vm_area_struct *vma, unsigned long addr,

Quoted 12 lines
Quoted 12 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct

Quoted 12 lines
mm/memory.c +3 -2
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-           pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
-           unsigned long addr, int *rss)
+        pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+        unsigned long addr, int *rss, pmd_t *src_pmd,
+        struct page *uncow_page)
 {
    unsigned long vm_flags = vma->vm_flags;
    pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct

mm_struct *src_mm,

Quoted 6 lines
Quoted 6 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 6 lines
mm/memory.c +3 -0
     * in the parent and the child
     */
    if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+           if (uncow_page) {
+                   struct page *old_page = vm_normal_page(vma, addr,

pte);

Quoted 9 lines
Quoted 9 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 9 lines
mm/memory.c +9 -0
+                   struct vm_fault vmf;
+
+                   vmf.vma = vma;
+                   vmf.address = addr;
+                   vmf.orig_pte = pte;
+                   vmf.pmd = src_pmd;
+
+                   if (cow_user_page(uncow_page, old_page, &vmf)) {
+                           pte = mk_pte(uncow_page,

vma->vm_page_prot);

Quoted 6 lines
Quoted 6 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 6 lines
mm/memory.c +6 -0
+
+                           if (vm_flags & VM_SHARED)
+                                   pte = pte_mkclean(pte);
+                           pte = pte_mkold(pte);
+
+                           page_add_new_anon_rmap(uncow_page, vma,

addr,

Quoted 6 lines
Quoted 6 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 6 lines
mm/memory.c +5 -0
+                                                  false);
+                           rss[!!PageAnon(uncow_page)]++;
+                           goto out_set_pte;
+                   } else {
+                           /* unexpected: source page no longer

present */

Quoted 8 lines
Quoted 8 lines

mm/memory.c static int copy_pte_range(struct mm_struct

Quoted 8 lines
mm/memory.c +4 -0
+                           WARN_ON_ONCE(1);
+                   }
+           }
+#endif /* CONFIG_IPIPE */
            ptep_set_wrprotect(src_mm, addr, src_pte);
            pte = pte_wrprotect(pte);
    }
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct

*dst_mm, struct mm_struct *src_mm,

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
mm/memory.c +12 -1
    int progress = 0;
    int rss[NR_MM_COUNTERS];
    swp_entry_t entry = (swp_entry_t){0};
-
+   struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+   int do_cow_break = 0;
+again:
+   if (do_cow_break) {
+           uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+           if (uncow_page == NULL)
+                   return -ENOMEM;
+           do_cow_break = 0;
+   }
+#else
 again:
+#endif
    init_rss_vec(rss);
 
Quoted 11 lines
Quoted 11 lines

mm/memory.c static int copy_pte_range(struct mm_struct

Quoted 11 lines
mm/memory.c +4 -1
    dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-   if (!dst_pte)
+   if (!dst_pte) {
+           if (uncow_page)
+                   put_page(uncow_page);
            return -ENOMEM;
+   }
    src_pte = pte_offset_map(src_pmd, addr);
    src_ptl = pte_lockptr(src_mm, src_pmd);
    spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct

*dst_mm, struct mm_struct *src_mm,

Quoted 5 lines
Quoted 5 lines

mm/memory.c static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 5 lines
mm/memory.c +2 -0
                    progress++;
                    continue;
            }
+#ifdef CONFIG_IPIPE
+           if (likely(uncow_page == NULL) &&

likely(pte_present(*src_pte))) {

Quoted 3 lines
Quoted 3 lines

mm/memory.c static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 3 lines
mm/memory.c +3 -0
+                   if (is_cow_mapping(vma->vm_flags) &&
+                       test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+                       ((vma->vm_flags|src_mm->def_flags) &

VM_LOCKED)) {

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mm/memory.c +6 -0
+                           arch_leave_lazy_mmu_mode();
+                           spin_unlock(src_ptl);
+                           pte_unmap(src_pte);
+                           add_mm_rss_vec(dst_mm, rss);
+                           pte_unmap_unlock(dst_pte, dst_ptl);
+                           cond_resched();
Quoted 8 lines
Quoted 8 lines

mm/memory.c static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 8 lines
mm/memory.c +6 -1
+                           do_cow_break = 1;
+                           goto again;
+                   }
+           }
+#endif
            entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-                                                   vma, addr, rss);
+                                    vma, addr, rss, src_pmd,

uncow_page);

Quoted 5 lines
Quoted 5 lines

mm/memory.c static inline int pte_unmap_same(struct

Quoted 5 lines
mm/memory.c +1 -0
+           uncow_page = NULL;
            if (entry.val)
                    break;
            progress += 8;
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct

mm_struct *mm, pmd_t *pmd,

Quoted 13 lines
Quoted 13 lines

mm/memory.c static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, · line 2417

Quoted 11 lines
mm/memory.c +2 -2
    return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-                            struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+                     struct vm_fault *vmf)
 {
    bool ret;
    void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are

gone, see

Quoted 7 lines
Quoted 6 lines

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with other topics. Any comments?

Quoted 7 lines
Quoted 3 lines

Fine with me. This code can be simplified, working on it. I'll channel this through Dovetail.

OK, applied.

Greg, you can find updated no-arch branches for 4.19 and 5.4.

Ack

Quoted 11 lines

Jan

--
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux

#6 lore raw
Quoted 195 lines · Greg Gallagher
Quoted 191 lines · Jan Kiszka
Quoted 7 lines · Philippe Gerum
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor

faults

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the

complete

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to

go

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64

isn't

Quoted 1 line
Quoted 1 line
Quoted 1 line

in sync with noarch, you will need manual merging). Possibly, it

already

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76

++++++++++++++++++++++++++++++++++++++++++++++++-----

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +0 -0
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
Quoted 7 lines
Quoted 7 lines

mm/memory.c struct page *vm_normal_page_pmd(struct

Quoted 7 lines
mm/memory.c +3 -0
+static bool cow_user_page(struct page *dst, struct page *src,
+                     struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct

vm_area_struct *vma, unsigned long addr,

Quoted 4 lines
Quoted 4 lines

mm/memory.c struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,

Quoted 4 lines
mm/memory.c +0 -1
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-           pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct

*vma,

Quoted 8 lines
Quoted 8 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct

Quoted 8 lines
mm/memory.c +3 -1
-           unsigned long addr, int *rss)
+        pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+        unsigned long addr, int *rss, pmd_t *src_pmd,
+        struct page *uncow_page)
 {
    unsigned long vm_flags = vma->vm_flags;
    pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct

mm_struct *src_mm,

Quoted 6 lines
Quoted 6 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 6 lines
mm/memory.c +3 -0
     * in the parent and the child
     */
    if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+           if (uncow_page) {
+                   struct page *old_page = vm_normal_page(vma, addr,

pte);

Quoted 9 lines
Quoted 9 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 9 lines
mm/memory.c +9 -0
+                   struct vm_fault vmf;
+
+                   vmf.vma = vma;
+                   vmf.address = addr;
+                   vmf.orig_pte = pte;
+                   vmf.pmd = src_pmd;
+
+                   if (cow_user_page(uncow_page, old_page, &vmf)) {
+                           pte = mk_pte(uncow_page,

vma->vm_page_prot);

Quoted 6 lines
Quoted 6 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 6 lines
mm/memory.c +6 -0
+
+                           if (vm_flags & VM_SHARED)
+                                   pte = pte_mkclean(pte);
+                           pte = pte_mkold(pte);
+
+                           page_add_new_anon_rmap(uncow_page, vma,

addr,

Quoted 6 lines
Quoted 6 lines

mm/memory.c copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 6 lines
mm/memory.c +5 -0
+                                                  false);
+                           rss[!!PageAnon(uncow_page)]++;
+                           goto out_set_pte;
+                   } else {
+                           /* unexpected: source page no longer

present */

Quoted 8 lines
Quoted 8 lines

mm/memory.c static int copy_pte_range(struct mm_struct

Quoted 8 lines
mm/memory.c +4 -0
+                           WARN_ON_ONCE(1);
+                   }
+           }
+#endif /* CONFIG_IPIPE */
            ptep_set_wrprotect(src_mm, addr, src_pte);
            pte = pte_wrprotect(pte);
    }
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct

*dst_mm, struct mm_struct *src_mm,

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
mm/memory.c +12 -1
    int progress = 0;
    int rss[NR_MM_COUNTERS];
    swp_entry_t entry = (swp_entry_t){0};
-
+   struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+   int do_cow_break = 0;
+again:
+   if (do_cow_break) {
+           uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+           if (uncow_page == NULL)
+                   return -ENOMEM;
+           do_cow_break = 0;
+   }
+#else
 again:
+#endif
    init_rss_vec(rss);
 
Quoted 11 lines
Quoted 11 lines

mm/memory.c static int copy_pte_range(struct mm_struct

Quoted 11 lines
mm/memory.c +4 -1
    dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-   if (!dst_pte)
+   if (!dst_pte) {
+           if (uncow_page)
+                   put_page(uncow_page);
            return -ENOMEM;
+   }
    src_pte = pte_offset_map(src_pmd, addr);
    src_ptl = pte_lockptr(src_mm, src_pmd);
    spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct

*dst_mm, struct mm_struct *src_mm,

Quoted 5 lines
Quoted 5 lines

mm/memory.c static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 5 lines
mm/memory.c +2 -0
                    progress++;
                    continue;
            }
+#ifdef CONFIG_IPIPE
+           if (likely(uncow_page == NULL) &&

likely(pte_present(*src_pte))) {

Quoted 3 lines
Quoted 3 lines

mm/memory.c static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 3 lines
mm/memory.c +3 -0
+                   if (is_cow_mapping(vma->vm_flags) &&
+                       test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+                       ((vma->vm_flags|src_mm->def_flags) &

VM_LOCKED)) {

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
mm/memory.c +6 -0
+                           arch_leave_lazy_mmu_mode();
+                           spin_unlock(src_ptl);
+                           pte_unmap(src_pte);
+                           add_mm_rss_vec(dst_mm, rss);
+                           pte_unmap_unlock(dst_pte, dst_ptl);
+                           cond_resched();
Quoted 8 lines
Quoted 8 lines

mm/memory.c static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,

Quoted 8 lines
mm/memory.c +6 -1
+                           do_cow_break = 1;
+                           goto again;
+                   }
+           }
+#endif
            entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-                                                   vma, addr, rss);
+                                    vma, addr, rss, src_pmd,

uncow_page);

Quoted 5 lines
Quoted 5 lines

mm/memory.c static inline int pte_unmap_same(struct

Quoted 5 lines
mm/memory.c +1 -0
+           uncow_page = NULL;
            if (entry.val)
                    break;
            progress += 8;
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct

mm_struct *mm, pmd_t *pmd,

Quoted 13 lines
Quoted 13 lines

mm/memory.c static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, · line 2417

Quoted 11 lines
mm/memory.c +2 -2
    return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-                            struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+                     struct vm_fault *vmf)
 {
    bool ret;
    void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are

gone, see

Quoted 4 lines
Quoted 4 lines

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with

other

Quoted 6 lines
Quoted 2 lines

topics. Any comments?

Fine with me. This code can be simplified, working on it. I'll channel this through Dovetail.

Quoted 6 lines
Quoted 6 lines

OK, applied.

Greg, you can find updated no-arch branches for 4.19 and 5.4.

Did this commit go into the no-arch tree? I'll have new arm/arm64 5.4 and

4.19 releases this week (aiming for Wednesday).

Thanks

Greg

author
#7 lore raw
Quoted 223 lines · Greg Gallagher

On Sun, Mar 7, 2021 at 8:09 AM Greg Gallagher <[email protected] <mailto:[email protected]>> wrote:

    On Sun, Mar 7, 2021 at 7:56 AM Jan Kiszka <[email protected]
    <mailto:[email protected]>> wrote:

        On 06.03.21 15:58, Philippe Gerum wrote:
        >
        > Jan Kiszka <[email protected]
        <mailto:[email protected]>> writes:
        >
        >> On 05.03.21 12:38, Jan Kiszka via Xenomai wrote:
        >>> From: Jan Kiszka <[email protected]
        <mailto:[email protected]>>
        >>>
        >>> This is still needed to avoid that a real-time parent seems
        minor faults
        >>> after forking for shared pages until they are finally unshared.
        >>>
        >>> This missing support became visible in Xenomai when running
        the complete
        >>> smokey test suite on certain architectures/config combinations.
        >>>
        >>> Fixes: 0f0b6099c45f ("ipipe: mm: Drop un-COW from
        copy_pte_range")
        >>> Signed-off-by: Jan Kiszka <[email protected]
        <mailto:[email protected]>>
        >>> ---
        >>>
        >>> For discussion. If there is a better pattern in reach, I'm
        happy to go
        >>> that path as well.
        >>>
        >>> Otherwise, this should go into our 4.19 branches (Greg, your
        arm64 isn't
        >>> in sync with noarch, you will need manual merging).
        Possibly, it already
        >>> applies to 5.4 as well, didn't check yet.
        >>>
        >>>  mm/memory.c | 76
        ++++++++++++++++++++++++++++++++++++++++++++++++-----
        >>>  1 file changed, 69 insertions(+), 7 deletions(-)
        >>>
        >>> diff --git a/mm/memory.c b/mm/memory.c
        >>> index 4cc7c72a0b7e..f102f4de2213 100644
        >>> --- a/mm/memory.c
        >>> +++ b/mm/memory.c
        >>> @@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
        >>> 
        >>>  unsigned long highest_memmap_pfn __read_mostly;
        >>> 
        >>> +static bool cow_user_page(struct page *dst, struct page *src,
        >>> +                     struct vm_fault *vmf);
        >>> +
        >>>  /*
        >>>   * CONFIG_MMU architectures set up ZERO_PAGE in their
        paging_init()
        >>>   */
        >>> @@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct
        vm_area_struct *vma, unsigned long addr,
        >>> 
        >>>  static inline unsigned long
        >>>  copy_one_pte(struct mm_struct *dst_mm, struct mm_struct
        *src_mm,
        >>> -           pte_t *dst_pte, pte_t *src_pte, struct
        vm_area_struct *vma,
        >>> -           unsigned long addr, int *rss)
        >>> +        pte_t *dst_pte, pte_t *src_pte, struct
        vm_area_struct *vma,
        >>> +        unsigned long addr, int *rss, pmd_t *src_pmd,
        >>> +        struct page *uncow_page)
        >>>  {
        >>>     unsigned long vm_flags = vma->vm_flags;
        >>>     pte_t pte = *src_pte;
        >>> @@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct
        *dst_mm, struct mm_struct *src_mm,
        >>>      * in the parent and the child
        >>>      */
        >>>     if (is_cow_mapping(vm_flags) && pte_write(pte)) {
        >>> +#ifdef CONFIG_IPIPE
        >>> +           if (uncow_page) {
        >>> +                   struct page *old_page =
        vm_normal_page(vma, addr, pte);
        >>> +                   struct vm_fault vmf;
        >>> +
        >>> +                   vmf.vma = vma;
        >>> +                   vmf.address = addr;
        >>> +                   vmf.orig_pte = pte;
        >>> +                   vmf.pmd = src_pmd;
        >>> +
        >>> +                   if (cow_user_page(uncow_page, old_page,
        &vmf)) {
        >>> +                           pte = mk_pte(uncow_page,
        vma->vm_page_prot);
        >>> +
        >>> +                           if (vm_flags & VM_SHARED)
        >>> +                                   pte = pte_mkclean(pte);
        >>> +                           pte = pte_mkold(pte);
        >>> +
        >>> +                         
         page_add_new_anon_rmap(uncow_page, vma, addr,
        >
        >>> +                                                  false);
        >>> +                           rss[!!PageAnon(uncow_page)]++;
        >>> +                           goto out_set_pte;
        >>> +                   } else {
        >>> +                           /* unexpected: source page no
        longer present */
        >>> +                           WARN_ON_ONCE(1);
        >>> +                   }
        >>> +           }
        >>> +#endif /* CONFIG_IPIPE */
        >>>             ptep_set_wrprotect(src_mm, addr, src_pte);
        >>>             pte = pte_wrprotect(pte);
        >>>     }
        >>> @@ -1083,13 +1114,27 @@ static int copy_pte_range(struct
        mm_struct *dst_mm, struct mm_struct *src_mm,
        >>>     int progress = 0;
        >>>     int rss[NR_MM_COUNTERS];
        >>>     swp_entry_t entry = (swp_entry_t){0};
        >>> -
        >>> +   struct page *uncow_page = NULL;
        >>> +#ifdef CONFIG_IPIPE
        >>> +   int do_cow_break = 0;
        >>> +again:
        >>> +   if (do_cow_break) {
        >>> +           uncow_page = alloc_page_vma(GFP_HIGHUSER, vma,
        addr);
        >>> +           if (uncow_page == NULL)
        >>> +                   return -ENOMEM;
        >>> +           do_cow_break = 0;
        >>> +   }
        >>> +#else
        >>>  again:
        >>> +#endif
        >>>     init_rss_vec(rss);
        >>> 
        >>>     dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr,
        &dst_ptl);
        >>> -   if (!dst_pte)
        >>> +   if (!dst_pte) {
        >>> +           if (uncow_page)
        >>> +                   put_page(uncow_page);
        >>>             return -ENOMEM;
        >>> +   }
        >>>     src_pte = pte_offset_map(src_pmd, addr);
        >>>     src_ptl = pte_lockptr(src_mm, src_pmd);
        >>>     spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
        >>> @@ -1112,8 +1157,25 @@ static int copy_pte_range(struct
        mm_struct *dst_mm, struct mm_struct *src_mm,
        >>>                     progress++;
        >>>                     continue;
        >>>             }
        >>> +#ifdef CONFIG_IPIPE
        >>> +           if (likely(uncow_page == NULL) &&
        likely(pte_present(*src_pte))) {
        >>> +                   if (is_cow_mapping(vma->vm_flags) &&
        >>> +                       test_bit(MMF_VM_PINNED,
        &src_mm->flags) &&
        >>> +                       ((vma->vm_flags|src_mm->def_flags) &
        VM_LOCKED)) {
        >>> +                           arch_leave_lazy_mmu_mode();
        >>> +                           spin_unlock(src_ptl);
        >>> +                           pte_unmap(src_pte);
        >>> +                           add_mm_rss_vec(dst_mm, rss);
        >>> +                           pte_unmap_unlock(dst_pte, dst_ptl);
        >>> +                           cond_resched();
        >>> +                           do_cow_break = 1;
        >>> +                           goto again;
        >>> +                   }
        >>> +           }
        >>> +#endif
        >>>             entry.val = copy_one_pte(dst_mm, src_mm,
        dst_pte, src_pte,
        >>> -                                                   vma,
        addr, rss);
        >>> +                                    vma, addr, rss,
        src_pmd, uncow_page);
        >>> +           uncow_page = NULL;
        >>>             if (entry.val)
        >>>                     break;
        >>>             progress += 8;
        >>> @@ -2348,8 +2410,8 @@ static inline int
        pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
        >>>     return same;
        >>>  }
        >>> 
        >>> -static inline bool cow_user_page(struct page *dst, struct
        page *src,
        >>> -                            struct vm_fault *vmf)
        >>> +static bool cow_user_page(struct page *dst, struct page *src,
        >>> +                     struct vm_fault *vmf)
        >>>  {
        >>>     bool ret;
        >>>     void *kaddr;
        >>>
        >>
        >> With this applied to ipipe-4.19 and 5.4 queues, related
        issues are gone, see
        >>
        >>
        https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670
        <https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670>
        >>
        >> I'm inclined to take this for now so that we can move forward
        with other
        >> topics. Any comments?
        >>
        >
        > Fine with me. This code can be simplified, working on it. I'll
        channel
        > this through Dovetail.
        >

        OK, applied.

        Greg, you can find updated no-arch branches for 4.19 and 5.4.
Quoted 3 lines

Did this commit go into the no-arch tree? I'll have new arm/arm64 5.4 and 4.19 releases this week (aiming for Wednesday).

Yes, but not in the form sent to the list for forward-merging trees (like x86). The noarch trees contains the fix folded into the introducing commits, rebased over the respective stable branches.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
author
#8 lore raw
In reply to Philippe Gerum
Quoted 159 lines · Philippe Gerum
Quoted 156 lines · Jan Kiszka
Quoted 142 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor faults after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the complete smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64 isn't in sync with noarch, you will need manual merging). Possibly, it already applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +33 -2
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-		pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
-		unsigned long addr, int *rss)
+	     pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+	     unsigned long addr, int *rss, pmd_t *src_pmd,
+	     struct page *uncow_page)
 {
 	unsigned long vm_flags = vma->vm_flags;
 	pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	 * in the parent and the child
 	 */
 	if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+		if (uncow_page) {
+			struct page *old_page = vm_normal_page(vma, addr, pte);
+			struct vm_fault vmf;
+
+			vmf.vma = vma;
+			vmf.address = addr;
+			vmf.orig_pte = pte;
+			vmf.pmd = src_pmd;
+
+			if (cow_user_page(uncow_page, old_page, &vmf)) {
+				pte = mk_pte(uncow_page, vma->vm_page_prot);
+
+				if (vm_flags & VM_SHARED)
+					pte = pte_mkclean(pte);
+				pte = pte_mkold(pte);
+
+				page_add_new_anon_rmap(uncow_page, vma, addr,
 
+						       false);
+				rss[!!PageAnon(uncow_page)]++;
+				goto out_set_pte;
+			} else {
+				/* unexpected: source page no longer present */
+				WARN_ON_ONCE(1);
+			}
+		}
+#endif /* CONFIG_IPIPE */
 		ptep_set_wrprotect(src_mm, addr, src_pte);
 		pte = pte_wrprotect(pte);
mm/memory.c +34 -3
 	}
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	int progress = 0;
 	int rss[NR_MM_COUNTERS];
 	swp_entry_t entry = (swp_entry_t){0};
-
+	struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+	int do_cow_break = 0;
+again:
+	if (do_cow_break) {
+		uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+		if (uncow_page == NULL)
+			return -ENOMEM;
+		do_cow_break = 0;
+	}
+#else
 again:
+#endif
 	init_rss_vec(rss);
 
 	dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-	if (!dst_pte)
+	if (!dst_pte) {
+		if (uncow_page)
+			put_page(uncow_page);
 		return -ENOMEM;
+	}
 	src_pte = pte_offset_map(src_pmd, addr);
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 			progress++;
 			continue;
 		}
+#ifdef CONFIG_IPIPE
+		if (likely(uncow_page == NULL) && likely(pte_present(*src_pte))) {
+			if (is_cow_mapping(vma->vm_flags) &&
+			    test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+			    ((vma->vm_flags|src_mm->def_flags) & VM_LOCKED)) {
+				arch_leave_lazy_mmu_mode();
+				spin_unlock(src_ptl);
+				pte_unmap(src_pte);
+				add_mm_rss_vec(dst_mm, rss);
+				pte_unmap_unlock(dst_pte, dst_ptl);
+				cond_resched();
+				do_cow_break = 1;
+				goto again;
+			}
+		}
+#endif
 		entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-							vma, addr, rss);
+					 vma, addr, rss, src_pmd, uncow_page);
+		uncow_page = NULL;
 		if (entry.val)
 			break;
 		progress += 8;

mm/memory.c static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, · line 2417

Quoted 10 lines
mm/memory.c +2 -2
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
 	return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-				 struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf)
 {
 	bool ret;
 	void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are gone, see

Quoted 9 lines
Quoted 5 lines

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with other topics. Any comments?

Fine with me. This code can be simplified, working on it. I'll channel this through Dovetail.

This didn't make into dovetail/v5.10 yet, did it? Asking because smokey triggers tones of primary mode migrations over dovetail.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#9 lore raw
Quoted 166 lines · Jan Kiszka
Quoted 165 lines · Philippe Gerum
Quoted 161 lines · Jan Kiszka
Quoted 142 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

This is still needed to avoid that a real-time parent seems minor faults after forking for shared pages until they are finally unshared.

This missing support became visible in Xenomai when running the complete smokey test suite on certain architectures/config combinations.

Fixes 0f0b6099c45f ("ipipe: mm: Drop un-COW from copy_pte_range")

---

For discussion. If there is a better pattern in reach, I'm happy to go that path as well.

Otherwise, this should go into our 4.19 branches (Greg, your arm64 isn't in sync with noarch, you will need manual merging). Possibly, it already applies to 5.4 as well, didn't check yet.

 mm/memory.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 7 deletions(-)
mm/memory.c +33 -2
index 4cc7c72a0b7e..f102f4de2213 100644
@@ -141,6 +141,9 @@ EXPORT_SYMBOL(zero_pfn);
 
 unsigned long highest_memmap_pfn __read_mostly;
 
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf);
+
 /*
  * CONFIG_MMU architectures set up ZERO_PAGE in their paging_init()
  */
@@ -957,8 +960,9 @@ struct page *vm_normal_page_pmd(struct vm_area_struct *vma, unsigned long addr,
 
 static inline unsigned long
 copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
-		pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
-		unsigned long addr, int *rss)
+	     pte_t *dst_pte, pte_t *src_pte, struct vm_area_struct *vma,
+	     unsigned long addr, int *rss, pmd_t *src_pmd,
+	     struct page *uncow_page)
 {
 	unsigned long vm_flags = vma->vm_flags;
 	pte_t pte = *src_pte;
@@ -1036,6 +1040,33 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	 * in the parent and the child
 	 */
 	if (is_cow_mapping(vm_flags) && pte_write(pte)) {
+#ifdef CONFIG_IPIPE
+		if (uncow_page) {
+			struct page *old_page = vm_normal_page(vma, addr, pte);
+			struct vm_fault vmf;
+
+			vmf.vma = vma;
+			vmf.address = addr;
+			vmf.orig_pte = pte;
+			vmf.pmd = src_pmd;
+
+			if (cow_user_page(uncow_page, old_page, &vmf)) {
+				pte = mk_pte(uncow_page, vma->vm_page_prot);
+
+				if (vm_flags & VM_SHARED)
+					pte = pte_mkclean(pte);
+				pte = pte_mkold(pte);
+
+				page_add_new_anon_rmap(uncow_page, vma, addr,
 
+						       false);
+				rss[!!PageAnon(uncow_page)]++;
+				goto out_set_pte;
+			} else {
+				/* unexpected: source page no longer present */
+				WARN_ON_ONCE(1);
+			}
+		}
+#endif /* CONFIG_IPIPE */
 		ptep_set_wrprotect(src_mm, addr, src_pte);
 		pte = pte_wrprotect(pte);
mm/memory.c +34 -3
 	}
@@ -1083,13 +1114,27 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 	int progress = 0;
 	int rss[NR_MM_COUNTERS];
 	swp_entry_t entry = (swp_entry_t){0};
-
+	struct page *uncow_page = NULL;
+#ifdef CONFIG_IPIPE
+	int do_cow_break = 0;
+again:
+	if (do_cow_break) {
+		uncow_page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
+		if (uncow_page == NULL)
+			return -ENOMEM;
+		do_cow_break = 0;
+	}
+#else
 again:
+#endif
 	init_rss_vec(rss);
 
 	dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
-	if (!dst_pte)
+	if (!dst_pte) {
+		if (uncow_page)
+			put_page(uncow_page);
 		return -ENOMEM;
+	}
 	src_pte = pte_offset_map(src_pmd, addr);
 	src_ptl = pte_lockptr(src_mm, src_pmd);
 	spin_lock_nested(src_ptl, SINGLE_DEPTH_NESTING);
@@ -1112,8 +1157,25 @@ static int copy_pte_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
 			progress++;
 			continue;
 		}
+#ifdef CONFIG_IPIPE
+		if (likely(uncow_page == NULL) && likely(pte_present(*src_pte))) {
+			if (is_cow_mapping(vma->vm_flags) &&
+			    test_bit(MMF_VM_PINNED, &src_mm->flags) &&
+			    ((vma->vm_flags|src_mm->def_flags) & VM_LOCKED)) {
+				arch_leave_lazy_mmu_mode();
+				spin_unlock(src_ptl);
+				pte_unmap(src_pte);
+				add_mm_rss_vec(dst_mm, rss);
+				pte_unmap_unlock(dst_pte, dst_ptl);
+				cond_resched();
+				do_cow_break = 1;
+				goto again;
+			}
+		}
+#endif
 		entry.val = copy_one_pte(dst_mm, src_mm, dst_pte, src_pte,
-							vma, addr, rss);
+					 vma, addr, rss, src_pmd, uncow_page);
+		uncow_page = NULL;
 		if (entry.val)
 			break;
 		progress += 8;

mm/memory.c static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, · line 2417

Quoted 10 lines
mm/memory.c +2 -2
@@ -2348,8 +2410,8 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd,
 	return same;
 }
 
-static inline bool cow_user_page(struct page *dst, struct page *src,
-				 struct vm_fault *vmf)
+static bool cow_user_page(struct page *dst, struct page *src,
+			  struct vm_fault *vmf)
 {
 	bool ret;
 	void *kaddr;

With this applied to ipipe-4.19 and 5.4 queues, related issues are gone, see

https://source.denx.de/Xenomai/xenomai-images/-/pipelines/6670

I'm inclined to take this for now so that we can move forward with other topics. Any comments?

Quoted 8 lines
Quoted 3 lines

Fine with me. This code can be simplified, working on it. I'll channel this through Dovetail.

This didn't make into dovetail/v5.10 yet, did it? Asking because smokey triggers tones of primary mode migrations over dovetail.

Jan

No, it did not.

Signature · 1 line
Philippe.