Skip to content

Commit 40e13e1

Browse files
committed
fscrypt: make the bounce page pool opt-in instead of opt-out
Replace FS_CFLG_OWN_PAGES with a bit flag 'needs_bounce_pages' which has the opposite meaning. I.e., filesystems now opt into the bounce page pool instead of opt out. Make fscrypt_alloc_bounce_page() check that the bounce page pool has been initialized. I believe the opt-in makes more sense, since nothing else in fscrypt_operations is opt-out, and these days filesystems can choose to use blk-crypto which doesn't need the fscrypt bounce page pool. Also, I happen to be planning to add two more flags, and I wanted to fix the "FS_CFLG_" name anyway as it wasn't prefixed with "FSCRYPT_". Link: https://lore.kernel.org/r/20230925055451.59499-3-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 5970fba commit 40e13e1

6 files changed

Lines changed: 22 additions & 11 deletions

File tree

fs/ceph/crypto.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static const union fscrypt_policy *ceph_get_dummy_policy(struct super_block *sb)
133133
}
134134

135135
static struct fscrypt_operations ceph_fscrypt_ops = {
136+
.needs_bounce_pages = 1,
136137
.get_context = ceph_crypt_get_context,
137138
.set_context = ceph_crypt_set_context,
138139
.get_dummy_policy = ceph_get_dummy_policy,

fs/crypto/crypto.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ EXPORT_SYMBOL(fscrypt_enqueue_decrypt_work);
4949

5050
struct page *fscrypt_alloc_bounce_page(gfp_t gfp_flags)
5151
{
52+
if (WARN_ON_ONCE(!fscrypt_bounce_page_pool)) {
53+
/*
54+
* Oops, the filesystem called a function that uses the bounce
55+
* page pool, but it didn't set needs_bounce_pages.
56+
*/
57+
return NULL;
58+
}
5259
return mempool_alloc(fscrypt_bounce_page_pool, gfp_flags);
5360
}
5461

@@ -325,7 +332,7 @@ int fscrypt_initialize(struct super_block *sb)
325332
return 0;
326333

327334
/* No need to allocate a bounce page pool if this FS won't use it. */
328-
if (sb->s_cop->flags & FS_CFLG_OWN_PAGES)
335+
if (!sb->s_cop->needs_bounce_pages)
329336
return 0;
330337

331338
mutex_lock(&fscrypt_init_mutex);

fs/ext4/crypto.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ static void ext4_get_ino_and_lblk_bits(struct super_block *sb,
240240
}
241241

242242
const struct fscrypt_operations ext4_cryptops = {
243+
.needs_bounce_pages = 1,
243244
.legacy_key_prefix = "ext4:",
244245
.get_context = ext4_get_context,
245246
.set_context = ext4_set_context,

fs/f2fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,6 +3231,7 @@ static struct block_device **f2fs_get_devices(struct super_block *sb,
32313231
}
32323232

32333233
static const struct fscrypt_operations f2fs_cryptops = {
3234+
.needs_bounce_pages = 1,
32343235
.legacy_key_prefix = "f2fs:",
32353236
.get_context = f2fs_get_context,
32363237
.set_context = f2fs_set_context,

fs/ubifs/crypto.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
8888
}
8989

9090
const struct fscrypt_operations ubifs_crypt_operations = {
91-
.flags = FS_CFLG_OWN_PAGES,
9291
.legacy_key_prefix = "ubifs:",
9392
.get_context = ubifs_crypt_get_context,
9493
.set_context = ubifs_crypt_set_context,

include/linux/fscrypt.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,20 @@ struct fscrypt_name {
5959

6060
#ifdef CONFIG_FS_ENCRYPTION
6161

62-
/*
63-
* If set, the fscrypt bounce page pool won't be allocated (unless another
64-
* filesystem needs it). Set this if the filesystem always uses its own bounce
65-
* pages for writes and therefore won't need the fscrypt bounce page pool.
66-
*/
67-
#define FS_CFLG_OWN_PAGES (1U << 1)
68-
6962
/* Crypto operations for filesystems */
7063
struct fscrypt_operations {
7164

72-
/* Set of optional flags; see above for allowed flags */
73-
unsigned int flags;
65+
/*
66+
* If set, then fs/crypto/ will allocate a global bounce page pool the
67+
* first time an encryption key is set up for a file. The bounce page
68+
* pool is required by the following functions:
69+
*
70+
* - fscrypt_encrypt_pagecache_blocks()
71+
* - fscrypt_zeroout_range() for files not using inline crypto
72+
*
73+
* If the filesystem doesn't use those, it doesn't need to set this.
74+
*/
75+
unsigned int needs_bounce_pages : 1;
7476

7577
/*
7678
* This field exists only for backwards compatibility reasons and should

0 commit comments

Comments
 (0)