diff mbox series

[1/5] ceph: Do not look at the index of an encrypted page

Message ID 20241129055058.858940-2-willy@infradead.org (mailing list archive)
State New
Headers show
Series Remove accesses to page->index from ceph | expand

Commit Message

Matthew Wilcox Nov. 29, 2024, 5:50 a.m. UTC
If the pages array contains encrypted pages, we cannot look at
page->index because that field is uninitialised.  Instead, use the new
ceph_fscrypt_pagecache_folio() to get the pagecache folio and look at
the index of that.

Fixes: 4de77f25fd85 (ceph: use osd_req_op_extent_osd_iter for netfs reads)
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/ceph/addr.c   | 5 ++++-
 fs/ceph/crypto.h | 7 +++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

Comments

Jeff Layton Nov. 29, 2024, 1:26 p.m. UTC | #1
On Fri, 2024-11-29 at 05:50 +0000, Matthew Wilcox (Oracle) wrote:
> If the pages array contains encrypted pages, we cannot look at
> page->index because that field is uninitialised.  Instead, use the new
> ceph_fscrypt_pagecache_folio() to get the pagecache folio and look at
> the index of that.
> 
> Fixes: 4de77f25fd85 (ceph: use osd_req_op_extent_osd_iter for netfs reads)

This commit may be a better candidate for the fixes tag:

     d55207717ded ceph: add encryption support to writepage and writepages


> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  fs/ceph/addr.c   | 5 ++++-
>  fs/ceph/crypto.h | 7 +++++++
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
> index 4c82348fe1e6..284a6244fcdf 100644
> --- a/fs/ceph/addr.c
> +++ b/fs/ceph/addr.c
> @@ -1346,8 +1346,11 @@ static int ceph_writepages_start(struct address_space *mapping,
>  			memset(data_pages + i, 0,
>  			       locked_pages * sizeof(*pages));
>  		} else {
> +			struct folio *folio;
> +
>  			BUG_ON(num_ops != req->r_num_ops);
> -			index = pages[i - 1]->index + 1;
> +			folio = ceph_fscrypt_pagecache_folio(pages[i - 1]);
> +			index = folio->index + 1;
>  			/* request message now owns the pages array */
>  			pages = NULL;
>  		}
> diff --git a/fs/ceph/crypto.h b/fs/ceph/crypto.h
> index 47e0c319fc68..7d75c4874aa8 100644
> --- a/fs/ceph/crypto.h
> +++ b/fs/ceph/crypto.h
> @@ -280,6 +280,13 @@ static inline struct page *ceph_fscrypt_pagecache_page(struct page *page)
>  }
>  #endif /* CONFIG_FS_ENCRYPTION */
>  
> +static inline struct folio *ceph_fscrypt_pagecache_folio(struct page *page)
> +{
> +	if (fscrypt_is_bounce_page(page))
> +		page = fscrypt_pagecache_page(page);
> +	return page_folio(page);
> +}
> +
>  static inline loff_t ceph_fscrypt_page_offset(struct page *page)
>  {
>  	return page_offset(ceph_fscrypt_pagecache_page(page));

Patch looks good though:

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Matthew Wilcox Nov. 29, 2024, 2:40 p.m. UTC | #2
On Fri, Nov 29, 2024 at 08:26:42AM -0500, Jeff Layton wrote:
> On Fri, 2024-11-29 at 05:50 +0000, Matthew Wilcox (Oracle) wrote:
> > If the pages array contains encrypted pages, we cannot look at
> > page->index because that field is uninitialised.  Instead, use the new
> > ceph_fscrypt_pagecache_folio() to get the pagecache folio and look at
> > the index of that.
> > 
> > Fixes: 4de77f25fd85 (ceph: use osd_req_op_extent_osd_iter for netfs reads)
> 
> This commit may be a better candidate for the fixes tag:
> 
>      d55207717ded ceph: add encryption support to writepage and writepages

... that's the commit i had intended to use.  Not sure what I
fat-fingered to make this happen.
diff mbox series

Patch

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 4c82348fe1e6..284a6244fcdf 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1346,8 +1346,11 @@  static int ceph_writepages_start(struct address_space *mapping,
 			memset(data_pages + i, 0,
 			       locked_pages * sizeof(*pages));
 		} else {
+			struct folio *folio;
+
 			BUG_ON(num_ops != req->r_num_ops);
-			index = pages[i - 1]->index + 1;
+			folio = ceph_fscrypt_pagecache_folio(pages[i - 1]);
+			index = folio->index + 1;
 			/* request message now owns the pages array */
 			pages = NULL;
 		}
diff --git a/fs/ceph/crypto.h b/fs/ceph/crypto.h
index 47e0c319fc68..7d75c4874aa8 100644
--- a/fs/ceph/crypto.h
+++ b/fs/ceph/crypto.h
@@ -280,6 +280,13 @@  static inline struct page *ceph_fscrypt_pagecache_page(struct page *page)
 }
 #endif /* CONFIG_FS_ENCRYPTION */
 
+static inline struct folio *ceph_fscrypt_pagecache_folio(struct page *page)
+{
+	if (fscrypt_is_bounce_page(page))
+		page = fscrypt_pagecache_page(page);
+	return page_folio(page);
+}
+
 static inline loff_t ceph_fscrypt_page_offset(struct page *page)
 {
 	return page_offset(ceph_fscrypt_pagecache_page(page));