Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+7 -6
+7 -6
fs/bcachefs/super-io.c
··· 203 203 if (dynamic_fault("bcachefs:add:super_realloc")) 204 204 return -BCH_ERR_ENOMEM_sb_realloc_injected; 205 205 206 + new_sb = krealloc(sb->sb, new_buffer_size, GFP_NOFS|__GFP_ZERO); 207 + if (!new_sb) 208 + return -BCH_ERR_ENOMEM_sb_buf_realloc; 209 + 210 + sb->sb = new_sb; 211 + 206 212 if (sb->have_bio) { 207 - unsigned nr_bvecs = DIV_ROUND_UP(new_buffer_size, PAGE_SIZE); 213 + unsigned nr_bvecs = buf_pages(sb->sb, new_buffer_size); 208 214 209 215 bio = bio_kmalloc(nr_bvecs, GFP_KERNEL); 210 216 if (!bio) ··· 222 216 sb->bio = bio; 223 217 } 224 218 225 - new_sb = krealloc(sb->sb, new_buffer_size, GFP_NOFS|__GFP_ZERO); 226 - if (!new_sb) 227 - return -BCH_ERR_ENOMEM_sb_buf_realloc; 228 - 229 - sb->sb = new_sb; 230 219 sb->buffer_size = new_buffer_size; 231 220 232 221 return 0;