Skip to content

Commit 1e00235

Browse files
committed
btrfs: compression: inline free_workspace
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>
1 parent a3bbd2a commit 1e00235

5 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎fs/btrfs/compression.c‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)
912912

913913
const struct btrfs_compress_op btrfs_heuristic_compress = {
914914
.workspace_manager = &heuristic_wsm,
915-
.free_workspace = free_heuristic_ws,
916915
};
917916

918917
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)
939938
}
940939
}
941940

941+
static void free_workspace(int type, struct list_head *ws)
942+
{
943+
switch (type) {
944+
case BTRFS_COMPRESS_NONE: return free_heuristic_ws(ws);
945+
case BTRFS_COMPRESS_ZLIB: return zlib_free_workspace(ws);
946+
case BTRFS_COMPRESS_LZO: return lzo_free_workspace(ws);
947+
case BTRFS_COMPRESS_ZSTD: return zstd_free_workspace(ws);
948+
default:
949+
/*
950+
* This can't happen, the type is validated several times
951+
* before we get here.
952+
*/
953+
BUG();
954+
}
955+
}
956+
942957
static void btrfs_init_workspace_manager(int type)
943958
{
944959
const struct btrfs_compress_op *ops = btrfs_compress_op[type];
@@ -976,7 +991,7 @@ static void btrfs_cleanup_workspace_manager(int type)
976991
while (!list_empty(&wsman->idle_ws)) {
977992
ws = wsman->idle_ws.next;
978993
list_del(ws);
979-
wsman->ops->free_workspace(ws);
994+
free_workspace(type, ws);
980995
atomic_dec(&wsman->total_ws);
981996
}
982997
}
@@ -1111,7 +1126,7 @@ void btrfs_put_workspace(int type, struct list_head *ws)
11111126
}
11121127
spin_unlock(ws_lock);
11131128

1114-
wsm->ops->free_workspace(ws);
1129+
free_workspace(type, ws);
11151130
atomic_dec(total_ws);
11161131
wake:
11171132
cond_wake_up(ws_wait);

‎fs/btrfs/compression.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ struct list_head *btrfs_get_workspace(int type, unsigned int level);
124124
void btrfs_put_workspace(int type, struct list_head *ws);
125125

126126
struct btrfs_compress_op {
127-
void (*free_workspace)(struct list_head *workspace);
128-
129127
struct workspace_manager *workspace_manager;
130128
/* Maximum level supported by the compression algorithm */
131129
unsigned int max_level;

‎fs/btrfs/lzo.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,
484484

485485
const struct btrfs_compress_op btrfs_lzo_compress = {
486486
.workspace_manager = &wsm,
487-
.free_workspace = lzo_free_workspace,
488487
.max_level = 1,
489488
.default_level = 1,
490489
};

‎fs/btrfs/zlib.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,
400400

401401
const struct btrfs_compress_op btrfs_zlib_compress = {
402402
.workspace_manager = &wsm,
403-
.free_workspace = zlib_free_workspace,
404403
.max_level = 9,
405404
.default_level = BTRFS_ZLIB_DEFAULT_LEVEL,
406405
};

‎fs/btrfs/zstd.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,
708708
const struct btrfs_compress_op btrfs_zstd_compress = {
709709
/* ZSTD uses own workspace manager */
710710
.workspace_manager = NULL,
711-
.free_workspace = zstd_free_workspace,
712711
.max_level = ZSTD_BTRFS_MAX_LEVEL,
713712
.default_level = ZSTD_BTRFS_DEFAULT_LEVEL,
714713
};

0 commit comments

Comments
 (0)