Skip to content

Commit 59b59a9

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
fscrypt: Change fscrypt_encrypt_pagecache_blocks() to take a folio
ext4 and ceph already have a folio to pass; f2fs needs to be properly converted but this will do for now. This removes a reference to page->index and page->mapping as well as removing a call to compound_head(). Signed-off-by: "Matthew Wilcox (Oracle)" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Eric Biggers <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent efbdd92 commit 59b59a9

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

fs/ceph/addr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static int write_folio_nounlock(struct folio *folio,
786786
ceph_fscache_write_to_cache(inode, page_off, len, caching);
787787

788788
if (IS_ENCRYPTED(inode)) {
789-
bounce_page = fscrypt_encrypt_pagecache_blocks(&folio->page,
789+
bounce_page = fscrypt_encrypt_pagecache_blocks(folio,
790790
CEPH_FSCRYPT_BLOCK_SIZE, 0,
791791
GFP_NOFS);
792792
if (IS_ERR(bounce_page)) {
@@ -1248,7 +1248,7 @@ static inline int move_dirty_folio_in_page_array(struct address_space *mapping,
12481248
gfp_t gfp_flags = ceph_wbc->locked_pages ? GFP_NOWAIT : GFP_NOFS;
12491249

12501250
if (IS_ENCRYPTED(inode)) {
1251-
pages[index] = fscrypt_encrypt_pagecache_blocks(&folio->page,
1251+
pages[index] = fscrypt_encrypt_pagecache_blocks(folio,
12521252
PAGE_SIZE,
12531253
0,
12541254
gfp_flags);

fs/crypto/crypto.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ int fscrypt_crypt_data_unit(const struct fscrypt_inode_info *ci,
153153
}
154154

155155
/**
156-
* fscrypt_encrypt_pagecache_blocks() - Encrypt data from a pagecache page
157-
* @page: the locked pagecache page containing the data to encrypt
156+
* fscrypt_encrypt_pagecache_blocks() - Encrypt data from a pagecache folio
157+
* @folio: the locked pagecache folio containing the data to encrypt
158158
* @len: size of the data to encrypt, in bytes
159159
* @offs: offset within @page of the data to encrypt, in bytes
160160
* @gfp_flags: memory allocation flags; see details below
@@ -177,23 +177,21 @@ int fscrypt_crypt_data_unit(const struct fscrypt_inode_info *ci,
177177
*
178178
* Return: the new encrypted bounce page on success; an ERR_PTR() on failure
179179
*/
180-
struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
181-
unsigned int len,
182-
unsigned int offs,
183-
gfp_t gfp_flags)
184-
180+
struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio,
181+
size_t len, size_t offs, gfp_t gfp_flags)
185182
{
186-
const struct inode *inode = page->mapping->host;
183+
const struct inode *inode = folio->mapping->host;
187184
const struct fscrypt_inode_info *ci = inode->i_crypt_info;
188185
const unsigned int du_bits = ci->ci_data_unit_bits;
189186
const unsigned int du_size = 1U << du_bits;
190187
struct page *ciphertext_page;
191-
u64 index = ((u64)page->index << (PAGE_SHIFT - du_bits)) +
188+
u64 index = ((u64)folio->index << (PAGE_SHIFT - du_bits)) +
192189
(offs >> du_bits);
193190
unsigned int i;
194191
int err;
195192

196-
if (WARN_ON_ONCE(!PageLocked(page)))
193+
VM_BUG_ON_FOLIO(folio_test_large(folio), folio);
194+
if (WARN_ON_ONCE(!folio_test_locked(folio)))
197195
return ERR_PTR(-EINVAL);
198196

199197
if (WARN_ON_ONCE(len <= 0 || !IS_ALIGNED(len | offs, du_size)))
@@ -205,15 +203,15 @@ struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
205203

206204
for (i = offs; i < offs + len; i += du_size, index++) {
207205
err = fscrypt_crypt_data_unit(ci, FS_ENCRYPT, index,
208-
page, ciphertext_page,
206+
&folio->page, ciphertext_page,
209207
du_size, i, gfp_flags);
210208
if (err) {
211209
fscrypt_free_bounce_page(ciphertext_page);
212210
return ERR_PTR(err);
213211
}
214212
}
215213
SetPagePrivate(ciphertext_page);
216-
set_page_private(ciphertext_page, (unsigned long)page);
214+
set_page_private(ciphertext_page, (unsigned long)folio);
217215
return ciphertext_page;
218216
}
219217
EXPORT_SYMBOL(fscrypt_encrypt_pagecache_blocks);

fs/ext4/page-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ int ext4_bio_write_folio(struct ext4_io_submit *io, struct folio *folio,
522522
if (io->io_bio)
523523
gfp_flags = GFP_NOWAIT | __GFP_NOWARN;
524524
retry_encrypt:
525-
bounce_page = fscrypt_encrypt_pagecache_blocks(&folio->page,
525+
bounce_page = fscrypt_encrypt_pagecache_blocks(folio,
526526
enc_bytes, 0, gfp_flags);
527527
if (IS_ERR(bounce_page)) {
528528
ret = PTR_ERR(bounce_page);

fs/f2fs/data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ int f2fs_encrypt_one_page(struct f2fs_io_info *fio)
25002500
return 0;
25012501

25022502
retry_encrypt:
2503-
fio->encrypted_page = fscrypt_encrypt_pagecache_blocks(page,
2503+
fio->encrypted_page = fscrypt_encrypt_pagecache_blocks(page_folio(page),
25042504
PAGE_SIZE, 0, gfp_flags);
25052505
if (IS_ERR(fio->encrypted_page)) {
25062506
/* flush pending IOs and wait for a while in the ENOMEM case */

include/linux/fscrypt.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,8 @@ static inline void fscrypt_prepare_dentry(struct dentry *dentry,
310310
/* crypto.c */
311311
void fscrypt_enqueue_decrypt_work(struct work_struct *);
312312

313-
struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
314-
unsigned int len,
315-
unsigned int offs,
316-
gfp_t gfp_flags);
313+
struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio,
314+
size_t len, size_t offs, gfp_t gfp_flags);
317315
int fscrypt_encrypt_block_inplace(const struct inode *inode, struct page *page,
318316
unsigned int len, unsigned int offs,
319317
u64 lblk_num, gfp_t gfp_flags);
@@ -480,10 +478,8 @@ static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
480478
{
481479
}
482480

483-
static inline struct page *fscrypt_encrypt_pagecache_blocks(struct page *page,
484-
unsigned int len,
485-
unsigned int offs,
486-
gfp_t gfp_flags)
481+
static inline struct page *fscrypt_encrypt_pagecache_blocks(struct folio *folio,
482+
size_t len, size_t offs, gfp_t gfp_flags)
487483
{
488484
return ERR_PTR(-EOPNOTSUPP);
489485
}

0 commit comments

Comments
 (0)