2024-04-26 14:46:03

by Matthew Wilcox

[permalink] [raw]
Subject: [PATCH 1/4] mm: Assert the mmap_lock is held in __anon_vma_prepare()

Convert the comment into an assertion.

Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
---
mm/rmap.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/rmap.c b/mm/rmap.c
index 2608c40dffad..619d4d65d99b 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -182,8 +182,6 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
* for the new allocation. At the same time, we do not want
* to do any locking for the common case of already having
* an anon_vma.
- *
- * This must be called with the mmap_lock held for reading.
*/
int __anon_vma_prepare(struct vm_area_struct *vma)
{
@@ -191,6 +189,7 @@ int __anon_vma_prepare(struct vm_area_struct *vma)
struct anon_vma *anon_vma, *allocated;
struct anon_vma_chain *avc;

+ mmap_assert_locked(mm);
might_sleep();

avc = anon_vma_chain_alloc(GFP_KERNEL);
--
2.43.0



2024-04-26 15:27:47

by Suren Baghdasaryan

[permalink] [raw]
Subject: Re: [PATCH 1/4] mm: Assert the mmap_lock is held in __anon_vma_prepare()

On Fri, Apr 26, 2024 at 7:45 AM Matthew Wilcox (Oracle)
<[email protected]> wrote:
>
> Convert the comment into an assertion.
>
> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>

Reviewed-by: Suren Baghdasaryan <[email protected]>

> ---
> mm/rmap.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 2608c40dffad..619d4d65d99b 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -182,8 +182,6 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
> * for the new allocation. At the same time, we do not want
> * to do any locking for the common case of already having
> * an anon_vma.
> - *
> - * This must be called with the mmap_lock held for reading.
> */
> int __anon_vma_prepare(struct vm_area_struct *vma)
> {
> @@ -191,6 +189,7 @@ int __anon_vma_prepare(struct vm_area_struct *vma)
> struct anon_vma *anon_vma, *allocated;
> struct anon_vma_chain *avc;
>
> + mmap_assert_locked(mm);
> might_sleep();
>
> avc = anon_vma_chain_alloc(GFP_KERNEL);
> --
> 2.43.0
>

2024-04-26 17:44:38

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH 1/4] mm: Assert the mmap_lock is held in __anon_vma_prepare()

On 26.04.24 16:45, Matthew Wilcox (Oracle) wrote:
> Convert the comment into an assertion.
>
> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
> ---
> mm/rmap.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 2608c40dffad..619d4d65d99b 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -182,8 +182,6 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
> * for the new allocation. At the same time, we do not want
> * to do any locking for the common case of already having
> * an anon_vma.
> - *
> - * This must be called with the mmap_lock held for reading.
> */
> int __anon_vma_prepare(struct vm_area_struct *vma)
> {
> @@ -191,6 +189,7 @@ int __anon_vma_prepare(struct vm_area_struct *vma)
> struct anon_vma *anon_vma, *allocated;
> struct anon_vma_chain *avc;
>
> + mmap_assert_locked(mm);
> might_sleep();
>
> avc = anon_vma_chain_alloc(GFP_KERNEL);

Reviewed-by: David Hildenbrand <[email protected]>

--
Cheers,

David / dhildenb