diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-08-08 02:44:56 +0200 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 23:10:10 +0200 |
commit | 6fe893eade864665c0956a2ac2eff78b86dc8145 (patch) | |
tree | 499691b030f7ee84c37fecbd6e087dedaa67536b /fs/bcachefs/super-io.c | |
parent | bcachefs: Convert journal validation to bkey_invalid_flags (diff) | |
download | linux-6fe893eade864665c0956a2ac2eff78b86dc8145.tar.xz linux-6fe893eade864665c0956a2ac2eff78b86dc8145.zip |
bcachefs: Fix for sb buffer being misaligned
On old kernels, kmalloc() may return an allocation that's not naturally
aligned - this resulted in a bug where we allocated a bio with not
enough biovecs. Fix this by using buf_pages().
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/super-io.c')
-rw-r--r-- | fs/bcachefs/super-io.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index beb00f799fe4..a58b9750b6ce 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -203,8 +203,14 @@ int bch2_sb_realloc(struct bch_sb_handle *sb, unsigned u64s) if (dynamic_fault("bcachefs:add:super_realloc")) return -BCH_ERR_ENOMEM_sb_realloc_injected; + new_sb = krealloc(sb->sb, new_buffer_size, GFP_NOFS|__GFP_ZERO); + if (!new_sb) + return -BCH_ERR_ENOMEM_sb_buf_realloc; + + sb->sb = new_sb; + if (sb->have_bio) { - unsigned nr_bvecs = DIV_ROUND_UP(new_buffer_size, PAGE_SIZE); + unsigned nr_bvecs = buf_pages(sb->sb, new_buffer_size); bio = bio_kmalloc(nr_bvecs, GFP_KERNEL); if (!bio) @@ -216,11 +222,6 @@ int bch2_sb_realloc(struct bch_sb_handle *sb, unsigned u64s) sb->bio = bio; } - new_sb = krealloc(sb->sb, new_buffer_size, GFP_NOFS|__GFP_ZERO); - if (!new_sb) - return -BCH_ERR_ENOMEM_sb_buf_realloc; - - sb->sb = new_sb; sb->buffer_size = new_buffer_size; return 0; |