]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fscrypt: make the bounce page pool opt-in instead of opt-out
authorEric Biggers <ebiggers@google.com>
Mon, 25 Sep 2023 05:54:48 +0000 (22:54 -0700)
committerEric Biggers <ebiggers@google.com>
Mon, 25 Sep 2023 06:03:09 +0000 (23:03 -0700)
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>
fs/ceph/crypto.c
fs/crypto/crypto.c
fs/ext4/crypto.c
fs/f2fs/super.c
fs/ubifs/crypto.c
include/linux/fscrypt.h

index e4d5cd56a80b9aa6c1b04089af0cd636b566d943..cc63f1e6fdef68d9e4ebd7df048a20899f9236e8 100644 (file)
@@ -133,6 +133,7 @@ static const union fscrypt_policy *ceph_get_dummy_policy(struct super_block *sb)
 }
 
 static struct fscrypt_operations ceph_fscrypt_ops = {
+       .needs_bounce_pages     = 1,
        .get_context            = ceph_crypt_get_context,
        .set_context            = ceph_crypt_set_context,
        .get_dummy_policy       = ceph_get_dummy_policy,
index 6a837e4b80dcb3a052508d7e64bca409956236d1..aed0c5ea75781a14d252ceeaa1bb8699364ce9ba 100644 (file)
@@ -49,6 +49,13 @@ EXPORT_SYMBOL(fscrypt_enqueue_decrypt_work);
 
 struct page *fscrypt_alloc_bounce_page(gfp_t gfp_flags)
 {
+       if (WARN_ON_ONCE(!fscrypt_bounce_page_pool)) {
+               /*
+                * Oops, the filesystem called a function that uses the bounce
+                * page pool, but it didn't set needs_bounce_pages.
+                */
+               return NULL;
+       }
        return mempool_alloc(fscrypt_bounce_page_pool, gfp_flags);
 }
 
@@ -325,7 +332,7 @@ int fscrypt_initialize(struct super_block *sb)
                return 0;
 
        /* No need to allocate a bounce page pool if this FS won't use it. */
-       if (sb->s_cop->flags & FS_CFLG_OWN_PAGES)
+       if (!sb->s_cop->needs_bounce_pages)
                return 0;
 
        mutex_lock(&fscrypt_init_mutex);
index 99a4769a53f633fbf3bf3f7e2623b93d45242e33..5cd7bcfae46b20ece23d679e3af69c25ddd8c650 100644 (file)
@@ -240,6 +240,7 @@ static void ext4_get_ino_and_lblk_bits(struct super_block *sb,
 }
 
 const struct fscrypt_operations ext4_cryptops = {
+       .needs_bounce_pages     = 1,
        .legacy_key_prefix      = "ext4:",
        .get_context            = ext4_get_context,
        .set_context            = ext4_set_context,
index f60062b558fd1957c5e80f495e0cc2f70a492feb..55aa0ed531f22429ea38b901756bcc9c06204054 100644 (file)
@@ -3231,6 +3231,7 @@ static struct block_device **f2fs_get_devices(struct super_block *sb,
 }
 
 static const struct fscrypt_operations f2fs_cryptops = {
+       .needs_bounce_pages     = 1,
        .legacy_key_prefix      = "f2fs:",
        .get_context            = f2fs_get_context,
        .set_context            = f2fs_set_context,
index 1be3e11da3b3e6f219fca56877081dbd19cd61a0..921f9033d0d2d29cd111a1db4b7fc9bcc72cc40f 100644 (file)
@@ -88,7 +88,6 @@ int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
 }
 
 const struct fscrypt_operations ubifs_crypt_operations = {
-       .flags                  = FS_CFLG_OWN_PAGES,
        .legacy_key_prefix      = "ubifs:",
        .get_context            = ubifs_crypt_get_context,
        .set_context            = ubifs_crypt_set_context,
index b0037566ce308dfe925f0fd7e00717b9b7893ec7..4505078e89b7e97a8cb0cea664945bddfcea5431 100644 (file)
@@ -59,18 +59,20 @@ struct fscrypt_name {
 
 #ifdef CONFIG_FS_ENCRYPTION
 
-/*
- * If set, the fscrypt bounce page pool won't be allocated (unless another
- * filesystem needs it).  Set this if the filesystem always uses its own bounce
- * pages for writes and therefore won't need the fscrypt bounce page pool.
- */
-#define FS_CFLG_OWN_PAGES (1U << 1)
-
 /* Crypto operations for filesystems */
 struct fscrypt_operations {
 
-       /* Set of optional flags; see above for allowed flags */
-       unsigned int flags;
+       /*
+        * If set, then fs/crypto/ will allocate a global bounce page pool the
+        * first time an encryption key is set up for a file.  The bounce page
+        * pool is required by the following functions:
+        *
+        * - fscrypt_encrypt_pagecache_blocks()
+        * - fscrypt_zeroout_range() for files not using inline crypto
+        *
+        * If the filesystem doesn't use those, it doesn't need to set this.
+        */
+       unsigned int needs_bounce_pages : 1;
 
        /*
         * This field exists only for backwards compatibility reasons and should