Message ID | 20211217023418.731424-1-lixinhai.lxh@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [V3] mm/gup.c: stricter check on THP migration entry during follow_pmd_mask | expand |
Li Xinhai <lixinhai.lxh@gmail.com> writes: > When BUG_ON check for THP migration entry, the exsiting code only check s/exsiting/existing/ Found some misspelling in the comments too. Please fix them with some tool. Best Regards, Huang, Ying > thp_migration_supported case, but not for !thp_migration_supported case. > If !thp_migration_supported() and !pmd_present(), the original code may > dead loop in theory. To make the BUG_ON check consistent, we need catch > both cases. > > Move the BUG_ON check one step eariler, because if the bug happen we > should know it instead of depend on FOLL_MIGRATION been used by caller. > > Because pmdval instead of *pmd is read by the is_pmd_migration_entry() > check, the existing code don't help to avoid useless locking within > pmd_migration_entry_wait(), so remove that check. > > Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com> > Cc: Zi Yan <ziy@nvidia.com> > Cc: "Huang, Ying" <ying.huang@intel.com> > Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> > --- > V2->V3: > mention about the dead loop in commit message. > > V1->V2: > Move the BUG_ON() check before if(!(flags & FOLL_MIGRATION)); and add comments > for it. > > > mm/gup.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > > diff --git a/mm/gup.c b/mm/gup.c > index 2c51e9748a6a..94d0e586ca0b 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -642,12 +642,17 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, > } > retry: > if (!pmd_present(pmdval)) { > + /* > + * Should never reach here, if thp migration is not supported; > + * Otherwise, it must be a thp miration entry. > + */ > + VM_BUG_ON(!thp_migration_supported() || > + !is_pmd_migration_entry(pmdval)); > + > if (likely(!(flags & FOLL_MIGRATION))) > return no_page_table(vma, flags); > - VM_BUG_ON(thp_migration_supported() && > - !is_pmd_migration_entry(pmdval)); > - if (is_pmd_migration_entry(pmdval)) > - pmd_migration_entry_wait(mm, pmd); > + > + pmd_migration_entry_wait(mm, pmd); > pmdval = READ_ONCE(*pmd); > /* > * MADV_DONTNEED may convert the pmd to null because
On 12/17/21 11:01 AM, Huang, Ying wrote: > Li Xinhai <lixinhai.lxh@gmail.com> writes: > >> When BUG_ON check for THP migration entry, the exsiting code only check > > s/exsiting/existing/ > > Found some misspelling in the comments too. Please fix them with some > tool. > Yes, those need be fixed, thanks. > Best Regards, > Huang, Ying > >> thp_migration_supported case, but not for !thp_migration_supported case. >> If !thp_migration_supported() and !pmd_present(), the original code may >> dead loop in theory. To make the BUG_ON check consistent, we need catch >> both cases. >> >> Move the BUG_ON check one step eariler, because if the bug happen we >> should know it instead of depend on FOLL_MIGRATION been used by caller. >> >> Because pmdval instead of *pmd is read by the is_pmd_migration_entry() >> check, the existing code don't help to avoid useless locking within >> pmd_migration_entry_wait(), so remove that check. >> >> Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com> >> Cc: Zi Yan <ziy@nvidia.com> >> Cc: "Huang, Ying" <ying.huang@intel.com> >> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> >> --- >> V2->V3: >> mention about the dead loop in commit message. >> >> V1->V2: >> Move the BUG_ON() check before if(!(flags & FOLL_MIGRATION)); and add comments >> for it. >> >> >> mm/gup.c | 13 +++++++++---- >> 1 file changed, 9 insertions(+), 4 deletions(-) >> >> diff --git a/mm/gup.c b/mm/gup.c >> index 2c51e9748a6a..94d0e586ca0b 100644 >> --- a/mm/gup.c >> +++ b/mm/gup.c >> @@ -642,12 +642,17 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, >> } >> retry: >> if (!pmd_present(pmdval)) { >> + /* >> + * Should never reach here, if thp migration is not supported; >> + * Otherwise, it must be a thp miration entry. >> + */ >> + VM_BUG_ON(!thp_migration_supported() || >> + !is_pmd_migration_entry(pmdval)); >> + >> if (likely(!(flags & FOLL_MIGRATION))) >> return no_page_table(vma, flags); >> - VM_BUG_ON(thp_migration_supported() && >> - !is_pmd_migration_entry(pmdval)); >> - if (is_pmd_migration_entry(pmdval)) >> - pmd_migration_entry_wait(mm, pmd); >> + >> + pmd_migration_entry_wait(mm, pmd); >> pmdval = READ_ONCE(*pmd); >> /* >> * MADV_DONTNEED may convert the pmd to null because
diff --git a/mm/gup.c b/mm/gup.c index 2c51e9748a6a..94d0e586ca0b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -642,12 +642,17 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, } retry: if (!pmd_present(pmdval)) { + /* + * Should never reach here, if thp migration is not supported; + * Otherwise, it must be a thp miration entry. + */ + VM_BUG_ON(!thp_migration_supported() || + !is_pmd_migration_entry(pmdval)); + if (likely(!(flags & FOLL_MIGRATION))) return no_page_table(vma, flags); - VM_BUG_ON(thp_migration_supported() && - !is_pmd_migration_entry(pmdval)); - if (is_pmd_migration_entry(pmdval)) - pmd_migration_entry_wait(mm, pmd); + + pmd_migration_entry_wait(mm, pmd); pmdval = READ_ONCE(*pmd); /* * MADV_DONTNEED may convert the pmd to null because
When BUG_ON check for THP migration entry, the exsiting code only check thp_migration_supported case, but not for !thp_migration_supported case. If !thp_migration_supported() and !pmd_present(), the original code may dead loop in theory. To make the BUG_ON check consistent, we need catch both cases. Move the BUG_ON check one step eariler, because if the bug happen we should know it instead of depend on FOLL_MIGRATION been used by caller. Because pmdval instead of *pmd is read by the is_pmd_migration_entry() check, the existing code don't help to avoid useless locking within pmd_migration_entry_wait(), so remove that check. Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com> Cc: Zi Yan <ziy@nvidia.com> Cc: "Huang, Ying" <ying.huang@intel.com> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> --- V2->V3: mention about the dead loop in commit message. V1->V2: Move the BUG_ON() check before if(!(flags & FOLL_MIGRATION)); and add comments for it. mm/gup.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)