All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cifs: Fix memory leak when using fscache
@ 2022-07-18 19:06 Matthew Wilcox (Oracle)
  2022-07-19  3:56 ` Steve French
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-07-18 19:06 UTC (permalink / raw)
  To: Steve French, linux-cifs
  Cc: Matthew Wilcox (Oracle), David Howells, Jeff Layton

If we hit the 'index == next_cached' case, we leak a refcount on the
struct page.  Fix this by using readahead_folio() which takes care of
the refcount for you.

Fixes: 0174ee9947bd ("cifs: Implement cache I/O by accessing the cache directly")
Cc: David Howells <dhowells@redhat.com>
Cc: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/cifs/file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index e64cda7a7610..6985710e14c2 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -4459,10 +4459,10 @@ static void cifs_readahead(struct readahead_control *ractl)
 				 * TODO: Send a whole batch of pages to be read
 				 * by the cache.
 				 */
-				page = readahead_page(ractl);
-				last_batch_size = 1 << thp_order(page);
+				struct folio *folio = readahead_folio(ractl);
+				last_batch_size = folio_nr_pages(folio);
 				if (cifs_readpage_from_fscache(ractl->mapping->host,
-							       page) < 0) {
+							       &folio->page) < 0) {
 					/*
 					 * TODO: Deal with cache read failure
 					 * here, but for the moment, delegate
@@ -4470,7 +4470,7 @@ static void cifs_readahead(struct readahead_control *ractl)
 					 */
 					caching = false;
 				}
-				unlock_page(page);
+				folio_unlock(folio);
 				next_cached++;
 				cache_nr_pages--;
 				if (cache_nr_pages == 0)
-- 
2.35.1


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

* Re: [PATCH] cifs: Fix memory leak when using fscache
  2022-07-18 19:06 [PATCH] cifs: Fix memory leak when using fscache Matthew Wilcox (Oracle)
@ 2022-07-19  3:56 ` Steve French
  0 siblings, 0 replies; 2+ messages in thread
From: Steve French @ 2022-07-19  3:56 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle); +Cc: Steve French, CIFS, David Howells, Jeff Layton

tentatively merged into cifs-2.6.git for-next pending testing

On Mon, Jul 18, 2022 at 2:07 PM Matthew Wilcox (Oracle)
<willy@infradead.org> wrote:
>
> If we hit the 'index == next_cached' case, we leak a refcount on the
> struct page.  Fix this by using readahead_folio() which takes care of
> the refcount for you.
>
> Fixes: 0174ee9947bd ("cifs: Implement cache I/O by accessing the cache directly")
> Cc: David Howells <dhowells@redhat.com>
> Cc: Jeff Layton <jlayton@kernel.org>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  fs/cifs/file.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index e64cda7a7610..6985710e14c2 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -4459,10 +4459,10 @@ static void cifs_readahead(struct readahead_control *ractl)
>                                  * TODO: Send a whole batch of pages to be read
>                                  * by the cache.
>                                  */
> -                               page = readahead_page(ractl);
> -                               last_batch_size = 1 << thp_order(page);
> +                               struct folio *folio = readahead_folio(ractl);
> +                               last_batch_size = folio_nr_pages(folio);
>                                 if (cifs_readpage_from_fscache(ractl->mapping->host,
> -                                                              page) < 0) {
> +                                                              &folio->page) < 0) {
>                                         /*
>                                          * TODO: Deal with cache read failure
>                                          * here, but for the moment, delegate
> @@ -4470,7 +4470,7 @@ static void cifs_readahead(struct readahead_control *ractl)
>                                          */
>                                         caching = false;
>                                 }
> -                               unlock_page(page);
> +                               folio_unlock(folio);
>                                 next_cached++;
>                                 cache_nr_pages--;
>                                 if (cache_nr_pages == 0)
> --
> 2.35.1
>


-- 
Thanks,

Steve

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

end of thread, other threads:[~2022-07-19  3:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 19:06 [PATCH] cifs: Fix memory leak when using fscache Matthew Wilcox (Oracle)
2022-07-19  3:56 ` Steve French

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.