mm/hugetlb: revert use of page_cache_next_miss()
PATCH 1/1 mm/hugetlb: revert use of page_cache_next_miss()
As reported by Ackerley[1], the use of page_cache_next_miss() in hugetlbfs_fallocate() introduces a bug where a second fallocate() call to same offset fails with -EEXIST. Revert this change and go back to the previous method of using get from the page cache and then dropping the reference on success.
hugetlbfs_pagecache_present() was also refactored to use page_cache_next_miss(), revert the usage there as well.
User visible impacts include hugetlb fallocate incorrectly returning EEXIST if pages are already present in the file. In addition, hugetlb pages will not be included in core dumps if they need to be brought in via GUP. userfaultfd UFFDIO_COPY also uses this code and will not notice pages already present in the cache. It may try to allocate a new page and potentially return ENOMEM as opposed to EEXIST.
[1] https://lore.kernel.org/linux-mm/[email protected]/
---
This revert is the safest way to fix 6.3. The upstream fix will either fix page_cache_next_miss() itself or use Ackerley's patch to introduce a new function to check if a page is present in the page cache. Both directions are currently under review so we can use this safe and simple fix for 6.3
fs/hugetlbfs/inode.c | 8 +++----- mm/hugetlb.c | 11 +++++------ 2 files changed, 8 insertions(+), 11 deletions(-)
fs/hugetlbfs/inode.c +3 -5
@@ -821,7 +821,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,*/ struct folio *folio;unsigned long addr; -bool present;cond_resched ();
@@ -845,10 +844,9 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,mutex_lock (&hugetlb_fault_mutex_table[hash]);/* See if already present in mapping to avoid alloc/free */ -rcu_read_lock (); - present =page_cache_next_miss (mapping, index,1 ) != index; -rcu_read_unlock (); -if (present) { + folio =filemap_get_folio (mapping, idx); +if (folio) { +folio_put (folio);mutex_unlock (&hugetlb_fault_mutex_table[hash]);hugetlb_drop_vma_policy (&pseudo_vma);continue ;
mm/hugetlb.c +5 -6
@@ -5666,13 +5666,12 @@ static bool hugetlbfs_pagecache_present(struct hstate *h, {struct address_space *mapping = vma->vm_file->f_mapping;pgoff_t idx =vma_hugecache_offset (h, vma, address); -bool present; - -rcu_read_lock (); - present =page_cache_next_miss (mapping, idx,1 ) != idx; -rcu_read_unlock (); +struct folio *folio; -return present; + folio =filemap_get_folio (mapping, idx); +if (folio) +folio_put (folio); +return folio !=NULL ; } int hugetlb_add_to_page_cache(struct folio *folio, struct address_space *mapping,
Signature · 1 line
2.40.1
Quoted 22 lines · Sidhartha Kumar
As reported by Ackerley[1], the use of
page_cache_next_miss()inhugetlbfs_fallocate()introduces a bug where a secondfallocate()call to same offset fails with-EEXIST. Revert this change and go back to the previous method of using get from the page cache and then dropping the reference on success.
hugetlbfs_pagecache_present()was also refactored to usepage_cache_next_miss(), revert the usage there as well.User visible impacts include hugetlb fallocate incorrectly returning EEXIST if pages are already present in the file. In addition, hugetlb pages will not be included in core dumps if they need to be brought in via GUP. userfaultfd
UFFDIO_COPYalso uses this code and will not notice pages already present in the cache. It may try to allocate a new page and potentially return ENOMEM as opposed to EEXIST.Fixes d0ce0e47b323 ("mm/hugetlb: convert hugetlb fault paths to use alloc_hugetlb_folio()")Cc <[email protected]> #v6.3Reported-by Ackerley Tng <[email protected]>Signed-off-by Sidhartha Kumar <[email protected]>Reviewed-by Mike Kravetz <[email protected]>
Quoted 8 lines
[1] https://lore.kernel.org/linux-mm/[email protected]/
---This revert is the safest way to fix 6.3. The upstream fix will either fix
page_cache_next_miss()itself or use Ackerley's patch to introduce a new function to check if a page is present in the page cache. Both directions are currently under review so we can use this safe and simple fix for 6.3
Is there any specific reason why we don't just wait for the fix for Linus's tree before applying this one, or applying the real fix instead?
thanks,
greg k-h
Quoted 26 lines · Greg KH
Quoted 25 lines · Sidhartha Kumar
As reported by Ackerley[1], the use of
page_cache_next_miss()inhugetlbfs_fallocate()introduces a bug where a secondfallocate()call to same offset fails with-EEXIST. Revert this change and go back to the previous method of using get from the page cache and then dropping the reference on success.
hugetlbfs_pagecache_present()was also refactored to usepage_cache_next_miss(), revert the usage there as well.User visible impacts include hugetlb fallocate incorrectly returning EEXIST if pages are already present in the file. In addition, hugetlb pages will not be included in core dumps if they need to be brought in via GUP. userfaultfd
UFFDIO_COPYalso uses this code and will not notice pages already present in the cache. It may try to allocate a new page and potentially return ENOMEM as opposed to EEXIST.Fixes d0ce0e47b323 ("mm/hugetlb: convert hugetlb fault paths to use alloc_hugetlb_folio()")Cc <[email protected]> #v6.3Reported-by Ackerley Tng <[email protected]>Signed-off-by Sidhartha Kumar <[email protected]>Reviewed-by Mike Kravetz <[email protected]>
Quoted 8 lines
Quoted 5 lines
This revert is the safest way to fix 6.3. The upstream fix will either fix
page_cache_next_miss()itself or use Ackerley's patch to introduce a new function to check if a page is present in the page cache. Both directions are currently under review so we can use this safe and simple fix for 6.3Is there any specific reason why we don't just wait for the fix for Linus's tree before applying this one, or applying the real fix instead?
I missed Andrew's message stating he would prefer the real fix[1].
Sorry for the noise,
Sidhartha Kumar
Quoted 4 lines
thanks,
greg k-h
Quoted 36 lines · Sidhartha Kumar
Quoted 26 lines · Greg KH
Quoted 25 lines · Sidhartha Kumar
As reported by Ackerley[1], the use of
page_cache_next_miss()inhugetlbfs_fallocate()introduces a bug where a secondfallocate()call to same offset fails with-EEXIST. Revert this change and go back to the previous method of using get from the page cache and then dropping the reference on success.
hugetlbfs_pagecache_present()was also refactored to usepage_cache_next_miss(), revert the usage there as well.User visible impacts include hugetlb fallocate incorrectly returning EEXIST if pages are already present in the file. In addition, hugetlb pages will not be included in core dumps if they need to be brought in via GUP. userfaultfd
UFFDIO_COPYalso uses this code and will not notice pages already present in the cache. It may try to allocate a new page and potentially return ENOMEM as opposed to EEXIST.Fixes d0ce0e47b323 ("mm/hugetlb: convert hugetlb fault paths to use alloc_hugetlb_folio()")Cc <[email protected]> #v6.3Reported-by Ackerley Tng <[email protected]>Signed-off-by Sidhartha Kumar <[email protected]>Reviewed-by Mike Kravetz <[email protected]>Quoted 8 lines
Quoted 5 lines
This revert is the safest way to fix 6.3. The upstream fix will either fix
page_cache_next_miss()itself or use Ackerley's patch to introduce a new function to check if a page is present in the page cache. Both directions are currently under review so we can use this safe and simple fix for 6.3Is there any specific reason why we don't just wait for the fix for Linus's tree before applying this one, or applying the real fix instead?
Quoted 6 lines
I missed Andrew's message stating he would prefer the real fix[1].
Sorry for the noise,
Sidhartha Kumar
Great, is that going to Linus's tree soon?
thanks,
greg k-h
Quoted 37 lines · Greg KH
Quoted 36 lines · Sidhartha Kumar
Quoted 34 lines · Greg KH
Quoted 22 lines · Sidhartha Kumar
As reported by Ackerley[1], the use of
page_cache_next_miss()inhugetlbfs_fallocate()introduces a bug where a secondfallocate()call to same offset fails with-EEXIST. Revert this change and go back to the previous method of using get from the page cache and then dropping the reference on success.
hugetlbfs_pagecache_present()was also refactored to usepage_cache_next_miss(), revert the usage there as well.User visible impacts include hugetlb fallocate incorrectly returning EEXIST if pages are already present in the file. In addition, hugetlb pages will not be included in core dumps if they need to be brought in via GUP. userfaultfd
UFFDIO_COPYalso uses this code and will not notice pages already present in the cache. It may try to allocate a new page and potentially return ENOMEM as opposed to EEXIST.Fixes d0ce0e47b323 ("mm/hugetlb: convert hugetlb fault paths to use alloc_hugetlb_folio()")Cc <[email protected]> #v6.3Reported-by Ackerley Tng <[email protected]>Signed-off-by Sidhartha Kumar <[email protected]>Reviewed-by Mike Kravetz <[email protected]>Quoted 8 lines
[1] https://lore.kernel.org/linux-mm/[email protected]/
---This revert is the safest way to fix 6.3. The upstream fix will either fix
page_cache_next_miss()itself or use Ackerley's patch to introduce a new function to check if a page is present in the page cache. Both directions are currently under review so we can use this safe and simple fix for 6.3Is there any specific reason why we don't just wait for the fix for Linus's tree before applying this one, or applying the real fix instead?
Quoted 9 lines
Quoted 6 lines
I missed Andrew's message stating he would prefer the real fix[1].
Sorry for the noise,
Sidhartha KumarGreat, is that going to Linus's tree soon?
Andrew just added it to mm-hotfixes-stable so it should be in Linus's tree soon.
Thanks,
Sidhartha Kumar
Quoted 3 lines
thanks,
greg k-h