diff mbox series

[2/2] mm/khugepaged: Fix a NULL vs IS_ERR() bug in collapse_pte_mapped_thp()

Message ID 0882a964-770e-418c-9c34-1a64195baafc@moroto.mountain (mailing list archive)
State New
Headers show
Series [1/2] mm/khugepaged: Fix an uninitialized variable bug | expand

Commit Message

Dan Carpenter Oct. 20, 2023, 2:14 p.m. UTC
This was changed from find_lock_page() which returns NULL to
filemap_lock_folio() which returns error pointers.  Update the
error checking to match.

Fixes: 8f5654d233e3 ("mm/khugepaged: convert collapse_pte_mapped_thp() to use folios")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 mm/khugepaged.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andrew Morton Oct. 20, 2023, 4:36 p.m. UTC | #1
On Fri, 20 Oct 2023 17:14:36 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote:

> This was changed from find_lock_page() which returns NULL to
> filemap_lock_folio() which returns error pointers.  Update the
> error checking to match.
> 
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1508,7 +1508,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
>  
>  	folio = filemap_lock_folio(vma->vm_file->f_mapping,
>  			       linear_page_index(vma, haddr));
> -	if (!folio)
> +	if (IS_ERR(folio))
>  		return SCAN_PAGE_NULL;
>  
>  	if (folio_order(folio) != HPAGE_PMD_ORDER) {

Also doesn't appear applicable to current kernels?
Vishal Moola Oct. 20, 2023, 4:49 p.m. UTC | #2
On Fri, Oct 20, 2023 at 9:36 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Fri, 20 Oct 2023 17:14:36 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> > This was changed from find_lock_page() which returns NULL to
> > filemap_lock_folio() which returns error pointers.  Update the
> > error checking to match.
> >
> > --- a/mm/khugepaged.c
> > +++ b/mm/khugepaged.c
> > @@ -1508,7 +1508,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
> >
> >       folio = filemap_lock_folio(vma->vm_file->f_mapping,
> >                              linear_page_index(vma, haddr));
> > -     if (!folio)
> > +     if (IS_ERR(folio))
> >               return SCAN_PAGE_NULL;
> >
> >       if (folio_order(folio) != HPAGE_PMD_ORDER) {
>
> Also doesn't appear applicable to current kernels?

Thanks for these. Both these fix patches address issues introduced by my
khugepaged folio conversion patchset:
https://lore.kernel.org/linux-mm/20231018203213.50224-1-vishal.moola@gmail.com/T/#t

Andrew already dropped the patchset from current kernels so I can fix a
couple issues, v3 will include all these fixes.
Dan Carpenter Oct. 23, 2023, 4:59 a.m. UTC | #3
On Fri, Oct 20, 2023 at 09:49:15AM -0700, Vishal Moola wrote:
> On Fri, Oct 20, 2023 at 9:36 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Fri, 20 Oct 2023 17:14:36 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote:
> >
> > > This was changed from find_lock_page() which returns NULL to
> > > filemap_lock_folio() which returns error pointers.  Update the
> > > error checking to match.
> > >
> > > --- a/mm/khugepaged.c
> > > +++ b/mm/khugepaged.c
> > > @@ -1508,7 +1508,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
> > >
> > >       folio = filemap_lock_folio(vma->vm_file->f_mapping,
> > >                              linear_page_index(vma, haddr));
> > > -     if (!folio)
> > > +     if (IS_ERR(folio))
> > >               return SCAN_PAGE_NULL;
> > >
> > >       if (folio_order(folio) != HPAGE_PMD_ORDER) {
> >
> > Also doesn't appear applicable to current kernels?
> 
> Thanks for these. Both these fix patches address issues introduced by my
> khugepaged folio conversion patchset:
> https://lore.kernel.org/linux-mm/20231018203213.50224-1-vishal.moola@gmail.com/T/#t
> 
> Andrew already dropped the patchset from current kernels so I can fix a
> couple issues, v3 will include all these fixes.


Only this one was introduced by your patchset.  The other bug is older.
I don't know why it only showed up as a new bug now.  I had guessed that
it was other changes I had made to Smatch which affected this.

regards,
dan carpenter
Dan Carpenter Oct. 23, 2023, 2:16 p.m. UTC | #4
On Mon, Oct 23, 2023 at 07:59:12AM +0300, Dan Carpenter wrote:
> On Fri, Oct 20, 2023 at 09:49:15AM -0700, Vishal Moola wrote:
> > On Fri, Oct 20, 2023 at 9:36 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> > >
> > > On Fri, 20 Oct 2023 17:14:36 +0300 Dan Carpenter <dan.carpenter@linaro.org> wrote:
> > >
> > > > This was changed from find_lock_page() which returns NULL to
> > > > filemap_lock_folio() which returns error pointers.  Update the
> > > > error checking to match.
> > > >
> > > > --- a/mm/khugepaged.c
> > > > +++ b/mm/khugepaged.c
> > > > @@ -1508,7 +1508,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
> > > >
> > > >       folio = filemap_lock_folio(vma->vm_file->f_mapping,
> > > >                              linear_page_index(vma, haddr));
> > > > -     if (!folio)
> > > > +     if (IS_ERR(folio))
> > > >               return SCAN_PAGE_NULL;
> > > >
> > > >       if (folio_order(folio) != HPAGE_PMD_ORDER) {
> > >
> > > Also doesn't appear applicable to current kernels?
> > 
> > Thanks for these. Both these fix patches address issues introduced by my
> > khugepaged folio conversion patchset:
> > https://lore.kernel.org/linux-mm/20231018203213.50224-1-vishal.moola@gmail.com/T/#t
> > 
> > Andrew already dropped the patchset from current kernels so I can fix a
> > couple issues, v3 will include all these fixes.
> 
> 
> Only this one was introduced by your patchset.  The other bug is older.
> I don't know why it only showed up as a new bug now.  I had guessed that
> it was other changes I had made to Smatch which affected this.

Heh.  Nope.  I was wrong.  These were both introduces as part of the
folio conversion patchset.

Thanks for taking care of this, Vishal.

regards,
dan carpenter
diff mbox series

Patch

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index a25f5b7c3e7e..d977eb50704a 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1508,7 +1508,7 @@  int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
 
 	folio = filemap_lock_folio(vma->vm_file->f_mapping,
 			       linear_page_index(vma, haddr));
-	if (!folio)
+	if (IS_ERR(folio))
 		return SCAN_PAGE_NULL;
 
 	if (folio_order(folio) != HPAGE_PMD_ORDER) {