All of lore.kernel.org
 help / color / mirror / Atom feed
* + shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch added to mm-unstable branch
@ 2023-02-07  1:04 Andrew Morton
  2023-02-08 22:07 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2023-02-07  1:04 UTC (permalink / raw)
  To: mm-commits, vbabka, surenb, shakeelb, rientjes, quic_pkondeti,
	quic_charante, mhocko, markhemm, hughd, willy, akpm


The patch titled
     Subject: shmem: add shmem_read_folio() and shmem_read_folio_gfp()
has been added to the -mm mm-unstable branch.  Its filename is
     shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch

This patch will later appear in the mm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Subject: shmem: add shmem_read_folio() and shmem_read_folio_gfp()
Date: Mon, 6 Feb 2023 16:25:20 +0000

These are the folio replacements for shmem_read_mapping_page() and
shmem_read_mapping_page_gfp().

Link: https://lkml.kernel.org/r/20230206162520.4029022-2-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mark Hemment <markhemm@googlemail.com>
Cc: Charan Teja Kalla <quic_charante@quicinc.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---


--- a/include/linux/shmem_fs.h~shmem-add-shmem_read_folio-and-shmem_read_folio_gfp
+++ a/include/linux/shmem_fs.h
@@ -109,6 +109,14 @@ enum sgp_type {
 
 int shmem_get_folio(struct inode *inode, pgoff_t index, struct folio **foliop,
 		enum sgp_type sgp);
+struct folio *shmem_read_folio_gfp(struct address_space *mapping,
+		pgoff_t index, gfp_t gfp);
+
+static inline struct folio *shmem_read_folio(struct address_space *mapping,
+		pgoff_t index)
+{
+	return shmem_read_folio_gfp(mapping, index, mapping_gfp_mask(mapping));
+}
 
 static inline struct page *shmem_read_mapping_page(
 				struct address_space *mapping, pgoff_t index)
--- a/mm/shmem.c~shmem-add-shmem_read_folio-and-shmem_read_folio_gfp
+++ a/mm/shmem.c
@@ -4311,9 +4311,9 @@ int shmem_zero_setup(struct vm_area_stru
 }
 
 /**
- * shmem_read_mapping_page_gfp - read into page cache, using specified page allocation flags.
- * @mapping:	the page's address_space
- * @index:	the page index
+ * shmem_read_folio_gfp - read into page cache, using specified page allocation flags.
+ * @mapping:	the folio's address_space
+ * @index:	the folio index
  * @gfp:	the page allocator flags to use if allocating
  *
  * This behaves as a tmpfs "read_cache_page_gfp(mapping, index, gfp)",
@@ -4325,13 +4325,12 @@ int shmem_zero_setup(struct vm_area_stru
  * i915_gem_object_get_pages_gtt() mixes __GFP_NORETRY | __GFP_NOWARN in
  * with the mapping_gfp_mask(), to avoid OOMing the machine unnecessarily.
  */
-struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
-					 pgoff_t index, gfp_t gfp)
+struct folio *shmem_read_folio_gfp(struct address_space *mapping,
+		pgoff_t index, gfp_t gfp)
 {
 #ifdef CONFIG_SHMEM
 	struct inode *inode = mapping->host;
 	struct folio *folio;
-	struct page *page;
 	int error;
 
 	BUG_ON(!shmem_mapping(mapping));
@@ -4341,18 +4340,27 @@ struct page *shmem_read_mapping_page_gfp
 		return ERR_PTR(error);
 
 	folio_unlock(folio);
-	page = folio_file_page(folio, index);
+	return folio;
+#else
+	/*
+	 * The tiny !SHMEM case uses ramfs without swap
+	 */
+	return mapping_read_folio_gfp(mapping, index, gfp);
+#endif
+}
+EXPORT_SYMBOL_GPL(shmem_read_folio_gfp);
+
+struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
+					 pgoff_t index, gfp_t gfp)
+{
+	struct folio *folio = shmem_read_folio_gfp(mapping, index, gfp);
+	struct page *page = folio_file_page(folio, index);
+
 	if (PageHWPoison(page)) {
 		folio_put(folio);
 		return ERR_PTR(-EIO);
 	}
 
 	return page;
-#else
-	/*
-	 * The tiny !SHMEM case uses ramfs without swap
-	 */
-	return read_cache_page_gfp(mapping, index, gfp);
-#endif
 }
 EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp);
_

Patches currently in -mm which might be from willy@infradead.org are

mm-add-memcpy_from_file_folio.patch
filemap-add-mapping_read_folio_gfp.patch
shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch
shmem-fix-w=1-build-warnings-with-config_shmem=n.patch


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

* Re: + shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch added to mm-unstable branch
  2023-02-07  1:04 + shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch added to mm-unstable branch Andrew Morton
@ 2023-02-08 22:07 ` Matthew Wilcox
  2023-02-09  3:59   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2023-02-08 22:07 UTC (permalink / raw)
  To: Andrew Morton
  Cc: mm-commits, vbabka, surenb, shakeelb, rientjes, quic_pkondeti,
	quic_charante, mhocko, markhemm, hughd

On Mon, Feb 06, 2023 at 05:04:07PM -0800, Andrew Morton wrote:
> +struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
> +					 pgoff_t index, gfp_t gfp)
> +{
> +	struct folio *folio = shmem_read_folio_gfp(mapping, index, gfp);
> +	struct page *page = folio_file_page(folio, index);
> +

Ugh, insufficiently cautious.

This should have been

	struct folio *folio = shmem_read_folio_gfp(mapping, index, gfp);
	struct page *page;

	if (IS_ERR(folio))
		return &folio->page;
	page = folio_file_page(folio, index);

Unfortunately I have to go out now, but that's the solution to the
latest syzbot splat I saw.  I'll do you a proper -fix patch later
if you don't get to it first.

>  	if (PageHWPoison(page)) {
>  		folio_put(folio);
>  		return ERR_PTR(-EIO);
>  	}
>  
>  	return page;
> -#else
> -	/*
> -	 * The tiny !SHMEM case uses ramfs without swap
> -	 */
> -	return read_cache_page_gfp(mapping, index, gfp);
> -#endif
>  }
>  EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp);
> _
> 
> Patches currently in -mm which might be from willy@infradead.org are
> 
> mm-add-memcpy_from_file_folio.patch
> filemap-add-mapping_read_folio_gfp.patch
> shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch
> shmem-fix-w=1-build-warnings-with-config_shmem=n.patch
> 

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

* Re: + shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch added to mm-unstable branch
  2023-02-08 22:07 ` Matthew Wilcox
@ 2023-02-09  3:59   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2023-02-09  3:59 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: mm-commits, vbabka, surenb, shakeelb, rientjes, quic_pkondeti,
	quic_charante, mhocko, markhemm, hughd

On Wed, 8 Feb 2023 22:07:33 +0000 Matthew Wilcox <willy@infradead.org> wrote:

> On Mon, Feb 06, 2023 at 05:04:07PM -0800, Andrew Morton wrote:
> > +struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,
> > +					 pgoff_t index, gfp_t gfp)
> > +{
> > +	struct folio *folio = shmem_read_folio_gfp(mapping, index, gfp);
> > +	struct page *page = folio_file_page(folio, index);
> > +
> 
> Ugh, insufficiently cautious.
> 
> This should have been
> 
> 	struct folio *folio = shmem_read_folio_gfp(mapping, index, gfp);
> 	struct page *page;
> 
> 	if (IS_ERR(folio))
> 		return &folio->page;
> 	page = folio_file_page(folio, index);
> 
> Unfortunately I have to go out now, but that's the solution to the
> latest syzbot splat I saw.  I'll do you a proper -fix patch later
> if you don't get to it first.
> 

No probs, thanks.

(although that trick of doing &randomgarbagepointeroftypefoliostar->page
still makes my brain bleed)



From: Andrew Morton <akpm@linux-foundation.org>
Subject: shmem-add-shmem_read_folio-and-shmem_read_folio_gfp-fix
Date: Wed Feb  8 07:54:45 PM PST 2023

fix shmem_read_mapping_page_gfp(), per Matthew

Link: https://lkml.kernel.org/r/Y+QdJTuzxeBYejw2@casper.infradead.org
Cc: Charan Teja Kalla <quic_charante@quicinc.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Mark Hemment <markhemm@googlemail.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---


--- a/mm/shmem.c~shmem-add-shmem_read_folio-and-shmem_read_folio_gfp-fix
+++ a/mm/shmem.c
@@ -4354,8 +4354,12 @@ struct page *shmem_read_mapping_page_gfp
 					 pgoff_t index, gfp_t gfp)
 {
 	struct folio *folio = shmem_read_folio_gfp(mapping, index, gfp);
-	struct page *page = folio_file_page(folio, index);
+	struct page *page;
 
+	if (IS_ERR(folio))
+		return &folio->page;
+
+	page = folio_file_page(folio, index);
 	if (PageHWPoison(page)) {
 		folio_put(folio);
 		return ERR_PTR(-EIO);
_


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

end of thread, other threads:[~2023-02-09  3:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-07  1:04 + shmem-add-shmem_read_folio-and-shmem_read_folio_gfp.patch added to mm-unstable branch Andrew Morton
2023-02-08 22:07 ` Matthew Wilcox
2023-02-09  3:59   ` Andrew Morton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.