linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare
@ 2023-03-01  2:27 Suren Baghdasaryan
  2023-03-01  2:27 ` [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag Suren Baghdasaryan
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Suren Baghdasaryan @ 2023-03-01  2:27 UTC (permalink / raw)
  To: akpm
  Cc: sfr, error27, willy, david, Liam.Howlett, jgg, yuzhao, dhowells,
	hughd, mathieu.desnoyers, pasha.tatashin, laurent.dufour,
	linux-mm, linux-kernel, surenb, kernel test robot

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")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/r/202302281802.J93Nma7q-lkp@intel.com/
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

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

diff --git a/mm/mmap.c b/mm/mmap.c
index 0cd3714c2182..0759d53b470c 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -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 */
-- 
2.39.2.722.g9855ee24e9-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag
  2023-03-01  2:27 [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare Suren Baghdasaryan
@ 2023-03-01  2:27 ` Suren Baghdasaryan
  2023-03-01  8:27   ` David Hildenbrand
  2023-03-01  8:26 ` [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare David Hildenbrand
  2023-03-01 14:10 ` Liam R. Howlett
  2 siblings, 1 reply; 7+ messages in thread
From: Suren Baghdasaryan @ 2023-03-01  2:27 UTC (permalink / raw)
  To: akpm
  Cc: sfr, error27, willy, david, Liam.Howlett, jgg, yuzhao, dhowells,
	hughd, mathieu.desnoyers, pasha.tatashin, laurent.dufour,
	linux-mm, linux-kernel, surenb

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

Fixes: 863be34fc093 ("mm: add FAULT_FLAG_VMA_LOCK flag")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Link: https://lore.kernel.org/all/20230301113648.7c279865@canb.auug.org.au/
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

 include/linux/mm_types.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 89bbf7d8a312..ef74ea892c5b 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -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
-- 
2.39.2.722.g9855ee24e9-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare
  2023-03-01  2:27 [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare Suren Baghdasaryan
  2023-03-01  2:27 ` [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag Suren Baghdasaryan
@ 2023-03-01  8:26 ` David Hildenbrand
  2023-03-01 14:10 ` Liam R. Howlett
  2 siblings, 0 replies; 7+ messages in thread
From: David Hildenbrand @ 2023-03-01  8:26 UTC (permalink / raw)
  To: Suren Baghdasaryan, akpm
  Cc: sfr, error27, willy, Liam.Howlett, jgg, yuzhao, dhowells, hughd,
	mathieu.desnoyers, pasha.tatashin, laurent.dufour, linux-mm,
	linux-kernel, kernel test robot

On 01.03.23 03:27, Suren Baghdasaryan wrote:
> 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")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>

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 ;)

> Link: https://lore.kernel.org/r/202302281802.J93Nma7q-lkp@intel.com/
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> ---
> Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.
> 
>   mm/mmap.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 0cd3714c2182..0759d53b470c 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -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.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag
  2023-03-01  2:27 ` [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag Suren Baghdasaryan
@ 2023-03-01  8:27   ` David Hildenbrand
  2023-03-01 17:57     ` Suren Baghdasaryan
  0 siblings, 1 reply; 7+ messages in thread
From: David Hildenbrand @ 2023-03-01  8:27 UTC (permalink / raw)
  To: Suren Baghdasaryan, akpm
  Cc: sfr, error27, willy, Liam.Howlett, jgg, yuzhao, dhowells, hughd,
	mathieu.desnoyers, pasha.tatashin, laurent.dufour, linux-mm,
	linux-kernel

On 01.03.23 03:27, Suren Baghdasaryan wrote:
> FAULT_FLAG_VMA_LOCK flag was introduced without proper description. Fix
> this by documenting it.
> 
> Fixes: 863be34fc093 ("mm: add FAULT_FLAG_VMA_LOCK flag")
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Link: https://lore.kernel.org/all/20230301113648.7c279865@canb.auug.org.au/
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> ---
> Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.

Okay, that should be squashed then. LGTM.

-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare
  2023-03-01  2:27 [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare Suren Baghdasaryan
  2023-03-01  2:27 ` [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag Suren Baghdasaryan
  2023-03-01  8:26 ` [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare David Hildenbrand
@ 2023-03-01 14:10 ` Liam R. Howlett
  2023-03-01 17:54   ` Suren Baghdasaryan
  2 siblings, 1 reply; 7+ messages in thread
From: Liam R. Howlett @ 2023-03-01 14:10 UTC (permalink / raw)
  To: Suren Baghdasaryan
  Cc: akpm, sfr, error27, willy, david, jgg, yuzhao, dhowells, hughd,
	mathieu.desnoyers, pasha.tatashin, laurent.dufour, linux-mm,
	linux-kernel, kernel test robot

* Suren Baghdasaryan <surenb@google.com> [230228 21:27]:
> 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")
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Link: https://lore.kernel.org/r/202302281802.J93Nma7q-lkp@intel.com/
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> ---
> Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.
> 
>  mm/mmap.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 0cd3714c2182..0759d53b470c 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -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.

Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>

>  	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
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare
  2023-03-01 14:10 ` Liam R. Howlett
@ 2023-03-01 17:54   ` Suren Baghdasaryan
  0 siblings, 0 replies; 7+ messages in thread
From: Suren Baghdasaryan @ 2023-03-01 17:54 UTC (permalink / raw)
  To: Liam R. Howlett, Suren Baghdasaryan, akpm, sfr, error27, willy,
	david, jgg, yuzhao, dhowells, hughd, mathieu.desnoyers,
	pasha.tatashin, laurent.dufour, linux-mm, linux-kernel,
	kernel test robot

On Wed, Mar 1, 2023 at 6:10 AM Liam R. Howlett <Liam.Howlett@oracle.com> wrote:
>
> * Suren Baghdasaryan <surenb@google.com> [230228 21:27]:
> > 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")
> > Reported-by: kernel test robot <lkp@intel.com>
> > Reported-by: Dan Carpenter <error27@gmail.com>
> > Link: https://lore.kernel.org/r/202302281802.J93Nma7q-lkp@intel.com/
> > Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> > ---
> > Fix cleanly apply over mm-unstable, SHA in "Fixes" is from that tree.
> >
> >  mm/mmap.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index 0cd3714c2182..0759d53b470c 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -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.

>
> I'm happy either way.
>
> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
>
> >       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
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag
  2023-03-01  8:27   ` David Hildenbrand
@ 2023-03-01 17:57     ` Suren Baghdasaryan
  0 siblings, 0 replies; 7+ messages in thread
From: Suren Baghdasaryan @ 2023-03-01 17:57 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: akpm, sfr, error27, willy, Liam.Howlett, jgg, yuzhao, dhowells,
	hughd, mathieu.desnoyers, pasha.tatashin, laurent.dufour,
	linux-mm, linux-kernel

On Wed, Mar 1, 2023 at 12:27 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 01.03.23 03:27, Suren Baghdasaryan wrote:
> > FAULT_FLAG_VMA_LOCK flag was introduced without proper description. Fix
> > this by documenting it.
> >
> > Fixes: 863be34fc093 ("mm: add FAULT_FLAG_VMA_LOCK flag")
> > Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > Link: https://lore.kernel.org/all/20230301113648.7c279865@canb.auug.org.au/
> > Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> > ---
> > 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!

>
> --
> Thanks,
>
> David / dhildenb
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-01 17:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01  2:27 [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare Suren Baghdasaryan
2023-03-01  2:27 ` [PATCH 2/2] mm: document FAULT_FLAG_VMA_LOCK flag Suren Baghdasaryan
2023-03-01  8:27   ` David Hildenbrand
2023-03-01 17:57     ` Suren Baghdasaryan
2023-03-01  8:26 ` [PATCH 1/2] mm/mmap: remove unnecessary vp->vma check in vma_prepare David Hildenbrand
2023-03-01 14:10 ` Liam R. Howlett
2023-03-01 17:54   ` Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).