mm: fix vma_copy for !CONFIG_PER_VMA_LOCK
Subsystems (5)
Suren Baghdasaryan
reviewerPATCH 1/1 mm: fix vma_copy for !CONFIG_PER_VMA_LOCK
vma_copy() function for !CONFIG_PER_VMA_LOCK configuration copies all fields using memcpy() as opposed to CONFIG_PER_VMA_LOCK version which copies only required fields. anon_vma_chain field should not be copied and new vma should instead initialize it to an empty list. Fix this by initializing anon_vma_chain inside vma_copy() function. The version of vma_copy() for CONFIG_PER_VMA_LOCK is fine since it does not change that field and anon_vma_chain of any new vma is already initialized and empty.
---
Applies over mm-unstable
kernel/fork.c | 1 + 1 file changed, 1 insertion(+)
kernel/fork.c +1 -0
@@ -524,6 +524,7 @@ static void vma_copy(const struct vm_area_struct *src, struct vm_area_struct *de* will be reinitialized. */ data_race (memcpy (dest, src,sizeof (*dest))); + INIT_LIST_HEAD(&dest->anon_vma_chain); }#endif /* CONFIG_PER_VMA_LOCK */
base-commit: 6e165f54437931f329d09dca6c19d99af08a36e1
Signature · 1 line
2.47.0.338.g60cca15819-goog
Quoted 34 lines · Suren Baghdasaryan
vma_copy()function for !CONFIG_PER_VMA_LOCK configuration copies all fields usingmemcpy()as opposed toCONFIG_PER_VMA_LOCKversion which copies only required fields.anon_vma_chainfield should not be copied and new vma should instead initialize it to an empty list. Fix this by initializinganon_vma_chaininsidevma_copy()function. The version ofvma_copy()forCONFIG_PER_VMA_LOCKis fine since it does not change that field andanon_vma_chainof any new vma is already initialized and empty.Fixes 85ad413389ae ("mm: make vma cache SLAB_TYPESAFE_BY_RCU")Reported-by kernel test robot <[email protected]>Reported-by Klara Modin <[email protected]>Signed-off-by Suren Baghdasaryan <[email protected]>---
Applies over mm-unstablekernel/fork.c | 1 + 1 file changed, 1 insertion(+)kernel/fork.c +1
-0@@ -524,6 +524,7 @@ static void vma_copy(const struct vm_area_struct *src, struct vm_area_struct *de* will be reinitialized. */ data_race (memcpy (dest, src,sizeof (*dest))); + INIT_LIST_HEAD(&dest->anon_vma_chain); }#endif /* CONFIG_PER_VMA_LOCK */
Quoted 1 line
base-commit:
6e165f54437931f329d09dca6c19d99af08a36e1
This fixes the issue for me.
Thanks,
Quoted 8 lines · Suren Baghdasaryan
vma_copy()function for !CONFIG_PER_VMA_LOCK configuration copies all fields usingmemcpy()as opposed toCONFIG_PER_VMA_LOCKversion which copies only required fields.anon_vma_chainfield should not be copied and new vma should instead initialize it to an empty list. Fix this by initializinganon_vma_chaininsidevma_copy()function. The version ofvma_copy()forCONFIG_PER_VMA_LOCKis fine since it does not change that field andanon_vma_chainof any new vma is already initialized and empty.
I'm wondering if there is sufficient reason to have two implementations to do the copying.
How expensive would it be to simply use the CONFIG_PER_VMA_LOCK variant unconditionally? Is it even measurable in fork() micro-benchmarks?
Signature · 3 lines
Cheers, David / dhildenb
Quoted 8 lines · Suren Baghdasaryan
vma_copy()function for !CONFIG_PER_VMA_LOCK configuration copies all fields usingmemcpy()as opposed toCONFIG_PER_VMA_LOCKversion which copies only required fields.anon_vma_chainfield should not be copied and new vma should instead initialize it to an empty list. Fix this by initializinganon_vma_chaininsidevma_copy()function. The version ofvma_copy()forCONFIG_PER_VMA_LOCKis fine since it does not change that field andanon_vma_chainof any new vma is already initialized and empty.
Yeah ouch, good spot though.
This anon_vma stuff is landmine after landmine...
Quoted 7 lines
Fixes 85ad413389ae ("mm: make vma cache SLAB_TYPESAFE_BY_RCU")Reported-by kernel test robot <[email protected]>Reported-by Klara Modin <[email protected]>Signed-off-by Suren Baghdasaryan <[email protected]>
kernel/fork.c
Quoted 10 lines
---
Applies over mm-unstablekernel/fork.c | 1 + 1 file changed, 1 insertion(+)kernel/fork.c +0
-0
Unrelated to patch but it _really_ truly sucks to have this in kernel/fork.c. Maybe unavoidable given we put a bunch of this kind of logic there, but would be good to change this at some point...
kernel/fork.c static void vma_copy(const struct vm_area_struct *src, struct vm_area_struct *de · line 527
Quoted 5 lines
kernel/fork.c +1
-0@@ -524,6 +524,7 @@ static void vma_copy(const struct vm_area_struct *src, struct vm_area_struct *de* will be reinitialized. */ data_race (memcpy (dest, src,sizeof (*dest))); +INIT_LIST_HEAD (&dest->anon_vma_chain);
Nit, but might be worth a comment here. Though I suppose it's kind of implicit.
Quoted 8 lines
kernel/fork.c +0
-0}#endif /* CONFIG_PER_VMA_LOCK */ base-commit:
6e165f54437931f329d09dca6c19d99af08a36e1--
2.47.0.338.g60cca15819-goog
Suren Baghdasaryan
reviewerQuoted 11 lines · David Hildenbrand
Quoted 8 lines · Suren Baghdasaryan
vma_copy()function for !CONFIG_PER_VMA_LOCK configuration copies all fields usingmemcpy()as opposed toCONFIG_PER_VMA_LOCKversion which copies only required fields.anon_vma_chainfield should not be copied and new vma should instead initialize it to an empty list. Fix this by initializinganon_vma_chaininsidevma_copy()function. The version ofvma_copy()forCONFIG_PER_VMA_LOCKis fine since it does not change that field andanon_vma_chainof any new vma is already initialized and empty.
Quoted 5 lines
I'm wondering if there is sufficient reason to have two implementations to do the copying.
How expensive would it be to simply use the
CONFIG_PER_VMA_LOCKvariant unconditionally? Is it even measurable infork()micro-benchmarks?
Yeah, the benefit if any would be tiny. I'll try measuring the difference and if it's not visible will remove the !CONFIG_PER_VMA_LOCK version.
Thanks!
Quoted 6 lines
--
Cheers,David / dhildenb