Skip to contentSkip to conversation

mm/mmap: remove unnecessary vp->vma check in vma_prepare

PATCH In review Suren Baghdasaryan 3 participants 7 messages Mar 1, 2023

Subsystems (3)
lore
Share & tools
lore

Suren Baghdasaryan

author reviewer
#0 lore raw

PATCH 1/2 mm/mmap: remove unnecessary vp->vma check in vma_prepare

vp->vma in vma_prepare() is always non-NULL, therefore checking it is not necessary. Remove the extra check.

Fixes e8f071350ea5 ("mm/mmap: write-lock VMAs in vma_prepare before modifying them")

---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

 mm/mmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/mmap.c +1 -2
index 0cd3714c2182..0759d53b470c 100644
@@ -505,8 +505,7 @@ static inline void init_vma_prep(struct vma_prepare *vp,
  */
 static inline void vma_prepare(struct vma_prepare *vp)
 {
-	if (vp->vma)
-		vma_start_write(vp->vma);
+	vma_start_write(vp->vma);
 	if (vp->adj_next)
 		vma_start_write(vp->adj_next);
 	/* vp->insert is always a newly created VMA, no need for locking */
Signature · 1 line
2.39.2.722.g9855ee24e9-goog
author reviewer
#1 lore raw

PATCH 2/2 mm: document FAULT_FLAG_VMA_LOCK flag

FAULT_FLAG_VMA_LOCK flag was introduced without proper description. Fix this by documenting it.

---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

 include/linux/mm_types.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/mm_types.h +1 -0
index 89bbf7d8a312..ef74ea892c5b 100644
@@ -1064,6 +1064,7 @@ typedef struct {
  *                      mapped after the fault.
  * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached.
  *                        We should only access orig_pte if this flag set.
+ * @FAULT_FLAG_VMA_LOCK: The fault is handled under VMA lock.
  *
  * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify
  * whether we would allow page faults to retry by specifying these two
Signature · 1 line
2.39.2.722.g9855ee24e9-goog
#2 lore raw

Re: [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag

Quoted 9 lines · Suren Baghdasaryan

FAULT_FLAG_VMA_LOCK flag was introduced without proper description. Fix this by documenting it.

---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

Okay, that should be squashed then. LGTM.

Signature · 3 lines
Thanks,

David / dhildenb
author reviewer
#3 lore raw

Re: [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag

Quoted 5 lines · David Hildenbrand
Quoted 3 lines · Suren Baghdasaryan

FAULT_FLAG_VMA_LOCK flag was introduced without proper description. Fix this by documenting it.

Quoted 8 lines
Quoted 6 lines

---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

Okay, that should be squashed then. LGTM.

Yeah, both fixes in this patchset could be squashed into the original series without information loss. I'll leave that to Andrew to decide what makes more sense here.
Thanks!

Quoted 6 lines

--
Thanks,

David / dhildenb

Reviewed-by on v1 1/2
#4 lore raw
In reply to Suren Baghdasaryan
Quoted 6 lines · Suren Baghdasaryan

vp->vma in vma_prepare() is always non-NULL, therefore checking it is not necessary. Remove the extra check.

Fixes e8f071350ea5 ("mm/mmap: write-lock VMAs in vma_prepare before modifying them")

It would be great to mention that this simply silences a smatch warning. Otherwise, one might be mislead that this commit fixes an actual BUG ;)

Quoted 13 lines

---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

  mm/mmap.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
mm/mmap.c +0 -0
index 0cd3714c2182..0759d53b470c 100644

mm/mmap.c static inline void init_vma_prep(struct vma_prepare *vp, · line 511

Quoted 9 lines
mm/mmap.c +1 -2
@@ -505,8 +505,7 @@ static inline void init_vma_prep(struct vma_prepare *vp,
   */
  static inline void vma_prepare(struct vma_prepare *vp)
  {
-	if (vp->vma)
-		vma_start_write(vp->vma);
+	vma_start_write(vp->vma);
  	if (vp->adj_next)
  		vma_start_write(vp->adj_next);
  	/* vp->insert is always a newly created VMA, no need for locking */

Yes, that looks correct.

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 1/2
#5 lore raw
In reply to Suren Baghdasaryan
Quoted 19 lines · Suren Baghdasaryan

vp->vma in vma_prepare() is always non-NULL, therefore checking it is not necessary. Remove the extra check.

Fixes e8f071350ea5 ("mm/mmap: write-lock VMAs in vma_prepare before modifying them")

---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

 mm/mmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/mmap.c +0 -0
index 0cd3714c2182..0759d53b470c 100644

mm/mmap.c static inline void init_vma_prep(struct vma_prepare *vp, · line 508

Quoted 6 lines
mm/mmap.c +1 -2
@@ -505,8 +505,7 @@ static inline void init_vma_prep(struct vma_prepare *vp,
  */
 static inline void vma_prepare(struct vma_prepare *vp)
 {
-	if (vp->vma)
-		vma_start_write(vp->vma);
+	vma_start_write(vp->vma);

Would a WARN_ON_ONCE() be worth it? Maybe not since it will be detected rather quickly once we dereference it below, but it might make it more clear as to what happened?

I'm happy either way.

Quoted 6 lines
mm/mmap.c +0 -0
 	if (vp->adj_next)
 		vma_start_write(vp->adj_next);
 	/* vp->insert is always a newly created VMA, no need for locking */
Signature · 1 line
2.39.2.722.g9855ee24e9-goog
author reviewer
#6 lore raw
Quoted 16 lines · Liam R. Howlett
Quoted 14 lines · Suren Baghdasaryan

vp->vma in vma_prepare() is always non-NULL, therefore checking it is not necessary. Remove the extra check.

Fixes e8f071350ea5 ("mm/mmap: write-lock VMAs in vma_prepare before modifying them")

---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

 mm/mmap.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 15 lines

mm/mmap.c static inline void init_vma_prep(struct vma_prepare *vp, · line 508

Quoted 11 lines
mm/mmap.c +1 -2
index 0cd3714c2182..0759d53b470c 100644
@@ -505,8 +505,7 @@ static inline void init_vma_prep(struct vma_prepare *vp,
  */
 static inline void vma_prepare(struct vma_prepare *vp)
 {
-     if (vp->vma)
-             vma_start_write(vp->vma);
+     vma_start_write(vp->vma);

Would a WARN_ON_ONCE() be worth it? Maybe not since it will be detected rather quickly once we dereference it below, but it might make it more clear as to what happened?

WARN_ON_ONCE() seems like an overkill to me. It always follows after init_multi_vma_prep()/init_vma_prep() both of which set the VMA. Risk should be minimal here and as you said, misuse is easily discoverable.

Quoted 11 lines

I'm happy either way.

Quoted 6 lines
mm/mmap.c +0 -1
      if (vp->adj_next)
              vma_start_write(vp->adj_next);
      /* vp->insert is always a newly created VMA, no need for locking */
--

2.39.2.722.g9855ee24e9-goog