btrfs: compression: inline free_workspace
authorDavid Sterba <dsterba@suse.com>
Fri, 4 Oct 2019 00:57:22 +0000 (02:57 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 18 Nov 2019 11:46:59 +0000 (12:46 +0100)
Replace indirect calls to free_workspace by switch and calls to the
specific callbacks. This is mainly to get rid of the indirection due to
spectre vulnerability mitigations.

Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/lzo.c
fs/btrfs/zlib.c
fs/btrfs/zstd.c

index 2a77c91c194bc72416c07d8250f835156dcbb96b..b2342f99b093e3652d65959b0b9f39c8fbae261a 100644 (file)
@@ -912,7 +912,6 @@ fail:
 
 const struct btrfs_compress_op btrfs_heuristic_compress = {
        .workspace_manager = &heuristic_wsm,
-       .free_workspace = free_heuristic_ws,
 };
 
 static const struct btrfs_compress_op * const btrfs_compress_op[] = {
@@ -939,6 +938,22 @@ static struct list_head *alloc_workspace(int type, unsigned int level)
        }
 }
 
+static void free_workspace(int type, struct list_head *ws)
+{
+       switch (type) {
+       case BTRFS_COMPRESS_NONE: return free_heuristic_ws(ws);
+       case BTRFS_COMPRESS_ZLIB: return zlib_free_workspace(ws);
+       case BTRFS_COMPRESS_LZO:  return lzo_free_workspace(ws);
+       case BTRFS_COMPRESS_ZSTD: return zstd_free_workspace(ws);
+       default:
+               /*
+                * This can't happen, the type is validated several times
+                * before we get here.
+                */
+               BUG();
+       }
+}
+
 static void btrfs_init_workspace_manager(int type)
 {
        const struct btrfs_compress_op *ops = btrfs_compress_op[type];
@@ -976,7 +991,7 @@ static void btrfs_cleanup_workspace_manager(int type)
        while (!list_empty(&wsman->idle_ws)) {
                ws = wsman->idle_ws.next;
                list_del(ws);
-               wsman->ops->free_workspace(ws);
+               free_workspace(type, ws);
                atomic_dec(&wsman->total_ws);
        }
 }
@@ -1111,7 +1126,7 @@ void btrfs_put_workspace(int type, struct list_head *ws)
        }
        spin_unlock(ws_lock);
 
-       wsm->ops->free_workspace(ws);
+       free_workspace(type, ws);
        atomic_dec(total_ws);
 wake:
        cond_wake_up(ws_wait);
index 664b029cd5e47232cf19cbba9f3da4f8129cfb86..14057498dcbb4c01a1cd5ef633d1b5f0e6c5cb5e 100644 (file)
@@ -124,8 +124,6 @@ struct list_head *btrfs_get_workspace(int type, unsigned int level);
 void btrfs_put_workspace(int type, struct list_head *ws);
 
 struct btrfs_compress_op {
-       void (*free_workspace)(struct list_head *workspace);
-
        struct workspace_manager *workspace_manager;
        /* Maximum level supported by the compression algorithm */
        unsigned int max_level;
index 39b2cf80f77c9fdb3dd2840d6c91f24407092c02..aa9cd11f4b78b7a48fdf41c36b36f159d39fcc6d 100644 (file)
@@ -484,7 +484,6 @@ out:
 
 const struct btrfs_compress_op btrfs_lzo_compress = {
        .workspace_manager      = &wsm,
-       .free_workspace         = lzo_free_workspace,
        .max_level              = 1,
        .default_level          = 1,
 };
index c5dfab3ab082e797c03428d2197a112302c87a11..a6c90a003c1221752dfd3129e0dc48971856ea9b 100644 (file)
@@ -400,7 +400,6 @@ next:
 
 const struct btrfs_compress_op btrfs_zlib_compress = {
        .workspace_manager      = &wsm,
-       .free_workspace         = zlib_free_workspace,
        .max_level              = 9,
        .default_level          = BTRFS_ZLIB_DEFAULT_LEVEL,
 };
index 9413f741c2f6dea2f7505fc4a3fa2a119b7c3fdc..9a4871636c6c7abfd3b8915239f0da31205149dd 100644 (file)
@@ -708,7 +708,6 @@ finish:
 const struct btrfs_compress_op btrfs_zstd_compress = {
        /* ZSTD uses own workspace manager */
        .workspace_manager = NULL,
-       .free_workspace = zstd_free_workspace,
        .max_level      = ZSTD_BTRFS_MAX_LEVEL,
        .default_level  = ZSTD_BTRFS_DEFAULT_LEVEL,
 };