Skip to contentSkip to conversation

dovetail: mm: fix logic of COW-disabling check

PATCH Superseded Philippe Gerum 2 participants 5 messages Jan 9, 2022

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 dovetail: mm: fix logic of COW-disabling check

From: Philippe Gerum <[email protected]>

COW-disabling for a dovetailed process does not depend on the pinning status of the source mm considered by copy_present_page(). Decouple both checks, which fixes the following kernel splat on fork() from a dovetailed task:

[   18.376448] ------------[ cut here ]------------
[   18.376915] kernel BUG at mm/rmap.c:1049!
[   18.377259] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI IRQ_PIPELINE
[   18.377262] CPU: 0 PID: 121 Comm: smokey Not tainted 5.15.9+ #12
[   18.377264] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-4.fc34 04/01/2014
[   18.377265] IRQ stage: Linux
[   18.377266] RIP: 0010:__page_set_anon_rmap+0x59/0x70
[   18.377271] Code: c9 74 22 48 83 c0 01 48 89 43 18 f6 47 52 40 75 1b 48 2b 17 48 c1 ea 0c 48 03 97 98 00 00 00 48 89 53 20 5b c3 48 8b 00 eb d9 <0f> 0b 48 89 d6 e8 ad c6 01 00 48 89 c2 eb e6 0f 1f 84 00 00 00 00
[   18.377273] RSP: 0018:ffffc90000b0bb50 EFLAGS: 00010246
[   18.377275] RAX: 0000000000000000 RBX: 000000010498f000 RCX: 0000000000000001
[   18.377276] RDX: 00007fe623795000 RSI: ffff888102ab5398 RDI: ffffea00041263c0
[   18.377277] RBP: 0000000000000000 R08: 0000000000000000 R09: ffff8881029da958
[   18.377277] R10: 0000000000000000 R11: 0000000000000000 R12: ffff888102aa3ca8
[   18.377278] R13: ffff888102abaca8 R14: ffffea00041263c0 R15: 00007fe623795000
[   18.377281] FS:  00007fe623815740(0000) GS:ffff888237c00000(0000) knlGS:0000000000000000
[   18.377284] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   18.377285] CR2: 00007ffef0186000 CR3: 0000000102320000 CR4: 00000000000406f0
[   18.377286] Call Trace:
[   18.377287]  <TASK>
[   18.377287]  copy_pte_range+0x646/0x8c0
[   18.377292]  copy_pud_range+0x20a/0x2b0
[   18.377294]  copy_page_range+0x10f/0x2e0
[   18.377297]  ? dup_mmap+0x232/0x4e0
[   18.377300]  dup_mmap+0x3a6/0x4e0
[   18.377303]  dup_mm.isra.0+0x52/0xf0
[   18.377304]  copy_process+0x169e/0x1920
[   18.377307]  kernel_clone+0x4f/0x3e0
[   18.377309]  ? cobalt_thread_setschedparam_ex+0x200/0x200
[   18.377312]  ? rcu_read_lock_sched_held+0x57/0x80
[   18.377315]  ? handle_root_syscall+0x269/0x440
[   18.377319]  __do_sys_clone+0x52/0x60
[   18.377321]  do_syscall_64+0x4d/0xa0
[   18.377324]  entry_SYSCALL_64_after_hwframe+0x44/0xae
---
 include/linux/mm.h | 9 +++++++++
 mm/memory.c        | 8 +-------
 2 files changed, 10 insertions(+), 7 deletions(-)
include/linux/mm.h +9 -0
index a4cfbaef94635ce..db6bb27a008ce8f 100644
@@ -1346,6 +1346,15 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
 	if (!is_cow_mapping(vma->vm_flags))
 		return false;
 
+	/*
+	 * Dovetail: If the source mm belongs to a dovetailed process,
+	 * we don't want to impose the COW-induced latency on it: make
+	 * sure the child gets its own copy of the page.
+	 */
+	if (IS_ENABLED(CONFIG_DOVETAIL) &&
+	    test_bit(MMF_DOVETAILED, &vma->vm_mm->flags))
+		return true;
+
 	if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))
 		return false;
 
mm/memory.c +1 -7
index 0e3e2228f67ff8f..c0d89177e2c359d 100644
@@ -899,14 +899,8 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma
 	 * seen pinning", along with the (inexact) check of
 	 * the page count. That might give false positives for
 	 * for pinning, but it will work correctly.
-	 *
-	 * Dovetail: if the source mm belongs to a Dovetail-enabled
-	 * process, we don't want to impose the COW-induced latency on
-	 * it: make sure the child gets its own copy of the page.
 	 */
-	if (likely(!page_needs_cow_for_dma(src_vma, page) &&
-			(!dovetailing() || !test_bit(MMF_DOVETAILED,
-						&src_vma->vm_mm->flags))))
+	if (likely(!page_needs_cow_for_dma(src_vma, page)))
 		return 1;
 
 	new_page = *prealloc;
Signature · 1 line
2.31.1
#1 lore raw
Quoted 77 lines · Philippe Gerum

From: Philippe Gerum <[email protected]>

COW-disabling for a dovetailed process does not depend on the pinning status of the source mm considered by copy_present_page(). Decouple both checks, which fixes the following kernel splat on fork() from a dovetailed task:

[   18.376448] ------------[ cut here ]------------
[   18.376915] kernel BUG at mm/rmap.c:1049!
[   18.377259] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI IRQ_PIPELINE
[   18.377262] CPU: 0 PID: 121 Comm: smokey Not tainted 5.15.9+ #12
[   18.377264] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-4.fc34 04/01/2014
[   18.377265] IRQ stage: Linux
[   18.377266] RIP: 0010:__page_set_anon_rmap+0x59/0x70
[   18.377271] Code: c9 74 22 48 83 c0 01 48 89 43 18 f6 47 52 40 75 1b 48 2b 17 48 c1 ea 0c 48 03 97 98 00 00 00 48 89 53 20 5b c3 48 8b 00 eb d9 <0f> 0b 48 89 d6 e8 ad c6 01 00 48 89 c2 eb e6 0f 1f 84 00 00 00 00
[   18.377273] RSP: 0018:ffffc90000b0bb50 EFLAGS: 00010246
[   18.377275] RAX: 0000000000000000 RBX: 000000010498f000 RCX: 0000000000000001
[   18.377276] RDX: 00007fe623795000 RSI: ffff888102ab5398 RDI: ffffea00041263c0
[   18.377277] RBP: 0000000000000000 R08: 0000000000000000 R09: ffff8881029da958
[   18.377277] R10: 0000000000000000 R11: 0000000000000000 R12: ffff888102aa3ca8
[   18.377278] R13: ffff888102abaca8 R14: ffffea00041263c0 R15: 00007fe623795000
[   18.377281] FS:  00007fe623815740(0000) GS:ffff888237c00000(0000) knlGS:0000000000000000
[   18.377284] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   18.377285] CR2: 00007ffef0186000 CR3: 0000000102320000 CR4: 00000000000406f0
[   18.377286] Call Trace:
[   18.377287]  <TASK>
[   18.377287]  copy_pte_range+0x646/0x8c0
[   18.377292]  copy_pud_range+0x20a/0x2b0
[   18.377294]  copy_page_range+0x10f/0x2e0
[   18.377297]  ? dup_mmap+0x232/0x4e0
[   18.377300]  dup_mmap+0x3a6/0x4e0
[   18.377303]  dup_mm.isra.0+0x52/0xf0
[   18.377304]  copy_process+0x169e/0x1920
[   18.377307]  kernel_clone+0x4f/0x3e0
[   18.377309]  ? cobalt_thread_setschedparam_ex+0x200/0x200
[   18.377312]  ? rcu_read_lock_sched_held+0x57/0x80
[   18.377315]  ? handle_root_syscall+0x269/0x440
[   18.377319]  __do_sys_clone+0x52/0x60
[   18.377321]  do_syscall_64+0x4d/0xa0
[   18.377324]  entry_SYSCALL_64_after_hwframe+0x44/0xae
---
 include/linux/mm.h | 9 +++++++++
 mm/memory.c        | 8 +-------
 2 files changed, 10 insertions(+), 7 deletions(-)
include/linux/mm.h +9 -0
index a4cfbaef94635ce..db6bb27a008ce8f 100644
@@ -1346,6 +1346,15 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
 	if (!is_cow_mapping(vma->vm_flags))
 		return false;
 
+	/*
+	 * Dovetail: If the source mm belongs to a dovetailed process,
+	 * we don't want to impose the COW-induced latency on it: make
+	 * sure the child gets its own copy of the page.
+	 */
+	if (IS_ENABLED(CONFIG_DOVETAIL) &&
+	    test_bit(MMF_DOVETAILED, &vma->vm_mm->flags))
+		return true;
+
 	if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))
 		return false;
 
mm/memory.c +0 -2
index 0e3e2228f67ff8f..c0d89177e2c359d 100644
@@ -899,14 +899,8 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma
 	 * seen pinning", along with the (inexact) check of
 	 * the page count. That might give false positives for
 	 * for pinning, but it will work correctly.
-	 *
-	 * Dovetail: if the source mm belongs to a Dovetail-enabled

mm/memory.c copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma · line 906

Quoted 10 lines
mm/memory.c +1 -5
-	 * process, we don't want to impose the COW-induced latency on
-	 * it: make sure the child gets its own copy of the page.
 	 */
-	if (likely(!page_needs_cow_for_dma(src_vma, page) &&
-			(!dovetailing() || !test_bit(MMF_DOVETAILED,
-						&src_vma->vm_mm->flags))))
+	if (likely(!page_needs_cow_for_dma(src_vma, page)))
 		return 1;
 
 	new_page = *prealloc;

Maybe rename page_needs_cow_for_dma() along this? Reads weird now because the reason is not "dma" but "realtime".

Eventually, we should think about upstreaming this particular feature, maybe with prctl interface. Conceptually, RT-preempt processes should benefit from it as well.

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#2 lore raw
Quoted 87 lines · Jan Kiszka
Quoted 86 lines · Philippe Gerum

From: Philippe Gerum <[email protected]>

COW-disabling for a dovetailed process does not depend on the pinning status of the source mm considered by copy_present_page(). Decouple both checks, which fixes the following kernel splat on fork() from a dovetailed task:

[   18.376448] ------------[ cut here ]------------
[   18.376915] kernel BUG at mm/rmap.c:1049!
[   18.377259] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI IRQ_PIPELINE
[   18.377262] CPU: 0 PID: 121 Comm: smokey Not tainted 5.15.9+ #12
[   18.377264] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-4.fc34 04/01/2014
[   18.377265] IRQ stage: Linux
[   18.377266] RIP: 0010:__page_set_anon_rmap+0x59/0x70
[   18.377271] Code: c9 74 22 48 83 c0 01 48 89 43 18 f6 47 52 40 75 1b 48 2b 17 48 c1 ea 0c 48 03 97 98 00 00 00 48 89 53 20 5b c3 48 8b 00 eb d9 <0f> 0b 48 89 d6 e8 ad c6 01 00 48 89 c2 eb e6 0f 1f 84 00 00 00 00
[   18.377273] RSP: 0018:ffffc90000b0bb50 EFLAGS: 00010246
[   18.377275] RAX: 0000000000000000 RBX: 000000010498f000 RCX: 0000000000000001
[   18.377276] RDX: 00007fe623795000 RSI: ffff888102ab5398 RDI: ffffea00041263c0
[   18.377277] RBP: 0000000000000000 R08: 0000000000000000 R09: ffff8881029da958
[   18.377277] R10: 0000000000000000 R11: 0000000000000000 R12: ffff888102aa3ca8
[   18.377278] R13: ffff888102abaca8 R14: ffffea00041263c0 R15: 00007fe623795000
[   18.377281] FS:  00007fe623815740(0000) GS:ffff888237c00000(0000) knlGS:0000000000000000
[   18.377284] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   18.377285] CR2: 00007ffef0186000 CR3: 0000000102320000 CR4: 00000000000406f0
[   18.377286] Call Trace:
[   18.377287]  <TASK>
[   18.377287]  copy_pte_range+0x646/0x8c0
[   18.377292]  copy_pud_range+0x20a/0x2b0
[   18.377294]  copy_page_range+0x10f/0x2e0
[   18.377297]  ? dup_mmap+0x232/0x4e0
[   18.377300]  dup_mmap+0x3a6/0x4e0
[   18.377303]  dup_mm.isra.0+0x52/0xf0
[   18.377304]  copy_process+0x169e/0x1920
[   18.377307]  kernel_clone+0x4f/0x3e0
[   18.377309]  ? cobalt_thread_setschedparam_ex+0x200/0x200
[   18.377312]  ? rcu_read_lock_sched_held+0x57/0x80
[   18.377315]  ? handle_root_syscall+0x269/0x440
[   18.377319]  __do_sys_clone+0x52/0x60
[   18.377321]  do_syscall_64+0x4d/0xa0
[   18.377324]  entry_SYSCALL_64_after_hwframe+0x44/0xae
---
 include/linux/mm.h | 9 +++++++++
 mm/memory.c        | 8 +-------
 2 files changed, 10 insertions(+), 7 deletions(-)
include/linux/mm.h +9 -0
index a4cfbaef94635ce..db6bb27a008ce8f 100644
@@ -1346,6 +1346,15 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
 	if (!is_cow_mapping(vma->vm_flags))
 		return false;
 
+	/*
+	 * Dovetail: If the source mm belongs to a dovetailed process,
+	 * we don't want to impose the COW-induced latency on it: make
+	 * sure the child gets its own copy of the page.
+	 */
+	if (IS_ENABLED(CONFIG_DOVETAIL) &&
+	    test_bit(MMF_DOVETAILED, &vma->vm_mm->flags))
+		return true;
+
 	if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))
 		return false;
 
mm/memory.c +1 -7
index 0e3e2228f67ff8f..c0d89177e2c359d 100644
@@ -899,14 +899,8 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma
 	 * seen pinning", along with the (inexact) check of
 	 * the page count. That might give false positives for
 	 * for pinning, but it will work correctly.
-	 *
-	 * Dovetail: if the source mm belongs to a Dovetail-enabled
-	 * process, we don't want to impose the COW-induced latency on
-	 * it: make sure the child gets its own copy of the page.
 	 */
-	if (likely(!page_needs_cow_for_dma(src_vma, page) &&
-			(!dovetailing() || !test_bit(MMF_DOVETAILED,
-						&src_vma->vm_mm->flags))))
+	if (likely(!page_needs_cow_for_dma(src_vma, page)))
 		return 1;
 
Quoted 5 lines

mm/memory.c copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma · line 906

Quoted 1 line
mm/memory.c +0 -0
 	new_page = *prealloc;

Maybe rename page_needs_cow_for_dma() along this? Reads weird now because the reason is not "dma" but "realtime".

page_needs_cow_for_dma() is an upstream symbol.

Quoted 4 lines

Eventually, we should think about upstreaming this particular feature, maybe with prctl interface. Conceptually, RT-preempt processes should benefit from it as well.

I agree they would.

Signature · 1 line
Philippe.
#3 lore raw
Quoted 90 lines · Philippe Gerum
Quoted 87 lines · Jan Kiszka
Quoted 86 lines · Philippe Gerum

From: Philippe Gerum <[email protected]>

COW-disabling for a dovetailed process does not depend on the pinning status of the source mm considered by copy_present_page(). Decouple both checks, which fixes the following kernel splat on fork() from a dovetailed task:

[   18.376448] ------------[ cut here ]------------
[   18.376915] kernel BUG at mm/rmap.c:1049!
[   18.377259] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI IRQ_PIPELINE
[   18.377262] CPU: 0 PID: 121 Comm: smokey Not tainted 5.15.9+ #12
[   18.377264] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-4.fc34 04/01/2014
[   18.377265] IRQ stage: Linux
[   18.377266] RIP: 0010:__page_set_anon_rmap+0x59/0x70
[   18.377271] Code: c9 74 22 48 83 c0 01 48 89 43 18 f6 47 52 40 75 1b 48 2b 17 48 c1 ea 0c 48 03 97 98 00 00 00 48 89 53 20 5b c3 48 8b 00 eb d9 <0f> 0b 48 89 d6 e8 ad c6 01 00 48 89 c2 eb e6 0f 1f 84 00 00 00 00
[   18.377273] RSP: 0018:ffffc90000b0bb50 EFLAGS: 00010246
[   18.377275] RAX: 0000000000000000 RBX: 000000010498f000 RCX: 0000000000000001
[   18.377276] RDX: 00007fe623795000 RSI: ffff888102ab5398 RDI: ffffea00041263c0
[   18.377277] RBP: 0000000000000000 R08: 0000000000000000 R09: ffff8881029da958
[   18.377277] R10: 0000000000000000 R11: 0000000000000000 R12: ffff888102aa3ca8
[   18.377278] R13: ffff888102abaca8 R14: ffffea00041263c0 R15: 00007fe623795000
[   18.377281] FS:  00007fe623815740(0000) GS:ffff888237c00000(0000) knlGS:0000000000000000
[   18.377284] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   18.377285] CR2: 00007ffef0186000 CR3: 0000000102320000 CR4: 00000000000406f0
[   18.377286] Call Trace:
[   18.377287]  <TASK>
[   18.377287]  copy_pte_range+0x646/0x8c0
[   18.377292]  copy_pud_range+0x20a/0x2b0
[   18.377294]  copy_page_range+0x10f/0x2e0
[   18.377297]  ? dup_mmap+0x232/0x4e0
[   18.377300]  dup_mmap+0x3a6/0x4e0
[   18.377303]  dup_mm.isra.0+0x52/0xf0
[   18.377304]  copy_process+0x169e/0x1920
[   18.377307]  kernel_clone+0x4f/0x3e0
[   18.377309]  ? cobalt_thread_setschedparam_ex+0x200/0x200
[   18.377312]  ? rcu_read_lock_sched_held+0x57/0x80
[   18.377315]  ? handle_root_syscall+0x269/0x440
[   18.377319]  __do_sys_clone+0x52/0x60
[   18.377321]  do_syscall_64+0x4d/0xa0
[   18.377324]  entry_SYSCALL_64_after_hwframe+0x44/0xae
---
 include/linux/mm.h | 9 +++++++++
 mm/memory.c        | 8 +-------
 2 files changed, 10 insertions(+), 7 deletions(-)
include/linux/mm.h +9 -0
index a4cfbaef94635ce..db6bb27a008ce8f 100644
@@ -1346,6 +1346,15 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
 	if (!is_cow_mapping(vma->vm_flags))
 		return false;
 
+	/*
+	 * Dovetail: If the source mm belongs to a dovetailed process,
+	 * we don't want to impose the COW-induced latency on it: make
+	 * sure the child gets its own copy of the page.
+	 */
+	if (IS_ENABLED(CONFIG_DOVETAIL) &&
+	    test_bit(MMF_DOVETAILED, &vma->vm_mm->flags))
+		return true;
+
 	if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))
 		return false;
 
mm/memory.c +1 -7
index 0e3e2228f67ff8f..c0d89177e2c359d 100644
@@ -899,14 +899,8 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma
 	 * seen pinning", along with the (inexact) check of
 	 * the page count. That might give false positives for
 	 * for pinning, but it will work correctly.
-	 *
-	 * Dovetail: if the source mm belongs to a Dovetail-enabled
-	 * process, we don't want to impose the COW-induced latency on
-	 * it: make sure the child gets its own copy of the page.
 	 */
-	if (likely(!page_needs_cow_for_dma(src_vma, page) &&
-			(!dovetailing() || !test_bit(MMF_DOVETAILED,
-						&src_vma->vm_mm->flags))))
+	if (likely(!page_needs_cow_for_dma(src_vma, page)))
 		return 1;
 
Quoted 8 lines
Quoted 5 lines

mm/memory.c copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma · line 906

Quoted 1 line
mm/memory.c +0 -0
 	new_page = *prealloc;

Maybe rename page_needs_cow_for_dma() along this? Reads weird now because the reason is not "dma" but "realtime".

page_needs_cow_for_dma() is an upstream symbol.

Yes, and your are patching upstream, expanding the semantic of this function, thus have the right to rename it. Maybe just drop the "for_dma"?

Quoted 7 lines
Quoted 4 lines

Eventually, we should think about upstreaming this particular feature, maybe with prctl interface. Conceptually, RT-preempt processes should benefit from it as well.

I agree they would.

I'll discuss this internally. We have a bit bandwidth for general RT enhancement topics. Would just need a generic test case and some numbers, I suppose.

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#4 lore raw
Quoted 97 lines · Jan Kiszka
Quoted 96 lines · Philippe Gerum
Quoted 92 lines · Jan Kiszka
Quoted 77 lines · Philippe Gerum

From: Philippe Gerum <[email protected]>

COW-disabling for a dovetailed process does not depend on the pinning status of the source mm considered by copy_present_page(). Decouple both checks, which fixes the following kernel splat on fork() from a dovetailed task:

[   18.376448] ------------[ cut here ]------------
[   18.376915] kernel BUG at mm/rmap.c:1049!
[   18.377259] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI IRQ_PIPELINE
[   18.377262] CPU: 0 PID: 121 Comm: smokey Not tainted 5.15.9+ #12
[   18.377264] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-4.fc34 04/01/2014
[   18.377265] IRQ stage: Linux
[   18.377266] RIP: 0010:__page_set_anon_rmap+0x59/0x70
[   18.377271] Code: c9 74 22 48 83 c0 01 48 89 43 18 f6 47 52 40 75 1b 48 2b 17 48 c1 ea 0c 48 03 97 98 00 00 00 48 89 53 20 5b c3 48 8b 00 eb d9 <0f> 0b 48 89 d6 e8 ad c6 01 00 48 89 c2 eb e6 0f 1f 84 00 00 00 00
[   18.377273] RSP: 0018:ffffc90000b0bb50 EFLAGS: 00010246
[   18.377275] RAX: 0000000000000000 RBX: 000000010498f000 RCX: 0000000000000001
[   18.377276] RDX: 00007fe623795000 RSI: ffff888102ab5398 RDI: ffffea00041263c0
[   18.377277] RBP: 0000000000000000 R08: 0000000000000000 R09: ffff8881029da958
[   18.377277] R10: 0000000000000000 R11: 0000000000000000 R12: ffff888102aa3ca8
[   18.377278] R13: ffff888102abaca8 R14: ffffea00041263c0 R15: 00007fe623795000
[   18.377281] FS:  00007fe623815740(0000) GS:ffff888237c00000(0000) knlGS:0000000000000000
[   18.377284] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   18.377285] CR2: 00007ffef0186000 CR3: 0000000102320000 CR4: 00000000000406f0
[   18.377286] Call Trace:
[   18.377287]  <TASK>
[   18.377287]  copy_pte_range+0x646/0x8c0
[   18.377292]  copy_pud_range+0x20a/0x2b0
[   18.377294]  copy_page_range+0x10f/0x2e0
[   18.377297]  ? dup_mmap+0x232/0x4e0
[   18.377300]  dup_mmap+0x3a6/0x4e0
[   18.377303]  dup_mm.isra.0+0x52/0xf0
[   18.377304]  copy_process+0x169e/0x1920
[   18.377307]  kernel_clone+0x4f/0x3e0
[   18.377309]  ? cobalt_thread_setschedparam_ex+0x200/0x200
[   18.377312]  ? rcu_read_lock_sched_held+0x57/0x80
[   18.377315]  ? handle_root_syscall+0x269/0x440
[   18.377319]  __do_sys_clone+0x52/0x60
[   18.377321]  do_syscall_64+0x4d/0xa0
[   18.377324]  entry_SYSCALL_64_after_hwframe+0x44/0xae
---
 include/linux/mm.h | 9 +++++++++
 mm/memory.c        | 8 +-------
 2 files changed, 10 insertions(+), 7 deletions(-)
include/linux/mm.h +9 -0
index a4cfbaef94635ce..db6bb27a008ce8f 100644
@@ -1346,6 +1346,15 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma,
 	if (!is_cow_mapping(vma->vm_flags))
 		return false;
 
+	/*
+	 * Dovetail: If the source mm belongs to a dovetailed process,
+	 * we don't want to impose the COW-induced latency on it: make
+	 * sure the child gets its own copy of the page.
+	 */
+	if (IS_ENABLED(CONFIG_DOVETAIL) &&
+	    test_bit(MMF_DOVETAILED, &vma->vm_mm->flags))
+		return true;
+
 	if (!test_bit(MMF_HAS_PINNED, &vma->vm_mm->flags))
 		return false;
 
mm/memory.c +0 -2
index 0e3e2228f67ff8f..c0d89177e2c359d 100644
@@ -899,14 +899,8 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma
 	 * seen pinning", along with the (inexact) check of
 	 * the page count. That might give false positives for
 	 * for pinning, but it will work correctly.
-	 *
-	 * Dovetail: if the source mm belongs to a Dovetail-enabled

mm/memory.c copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma · line 906

Quoted 10 lines
mm/memory.c +1 -5
-	 * process, we don't want to impose the COW-induced latency on
-	 * it: make sure the child gets its own copy of the page.
 	 */
-	if (likely(!page_needs_cow_for_dma(src_vma, page) &&
-			(!dovetailing() || !test_bit(MMF_DOVETAILED,
-						&src_vma->vm_mm->flags))))
+	if (likely(!page_needs_cow_for_dma(src_vma, page)))
 		return 1;
 
 	new_page = *prealloc;

Maybe rename page_needs_cow_for_dma() along this? Reads weird now because the reason is not "dma" but "realtime".

Quoted 6 lines
Quoted 2 lines

page_needs_cow_for_dma() is an upstream symbol.

Yes, and your are patching upstream, expanding the semantic of this function, thus have the right to rename it. Maybe just drop the "for_dma"?

Makes sense. I'll issue v5 then.

Quoted 13 lines
Quoted 7 lines
Quoted 4 lines

Eventually, we should think about upstreaming this particular feature, maybe with prctl interface. Conceptually, RT-preempt processes should benefit from it as well.

I agree they would.

I'll discuss this internally. We have a bit bandwidth for general RT enhancement topics. Would just need a generic test case and some numbers, I suppose.

Jan

Signature · 1 line
Philippe.