2022-03-08 23:17:34

by Christoph Hellwig

[permalink] [raw]
Subject: cleanup bio_kmalloc v2

Hi Jens,

this series finishes off the bio allocation interface cleanups by dealing
with the weirdest member of the famility. bio_kmalloc combines a kmalloc
for the bio and bio_vecs with a hidden bio_init call and magic cleanup
semantics.

This series moves a few callers away from bio_kmalloc and then turns
bio_kmalloc into a simple wrapper for a slab allocation of a bio and the
inline biovecs. The callers need to manually call bio_init instead with
all that entails and the magic that turns bio_put into a kfree goes away
as well, allowing for a proper debug check in bio_put that catches
accidental use on a bio_init()ed bio.

Changes since v1:
- update a pre-existing comment per maintainer suggestion

Diffstat:
block/bio.c | 47 ++++++++++++++-----------------------
block/blk-crypto-fallback.c | 14 ++++++-----
block/blk-map.c | 42 +++++++++++++++++++++------------
drivers/block/pktcdvd.c | 34 +++++++++++---------------
drivers/md/bcache/debug.c | 10 ++++---
drivers/md/dm-bufio.c | 9 +++----
drivers/md/raid1.c | 12 ++++++---
drivers/md/raid10.c | 21 +++++++++++-----
drivers/target/target_core_pscsi.c | 36 ++++------------------------
fs/btrfs/disk-io.c | 8 +++---
fs/btrfs/volumes.c | 11 --------
fs/btrfs/volumes.h | 2 -
fs/squashfs/block.c | 14 +++--------
include/linux/bio.h | 2 -
14 files changed, 116 insertions(+), 146 deletions(-)


2022-03-30 18:20:51

by Jens Axboe

[permalink] [raw]
Subject: Re: cleanup bio_kmalloc v2

On Tue, 8 Mar 2022 07:15:46 +0100, Christoph Hellwig wrote:
> this series finishes off the bio allocation interface cleanups by dealing
> with the weirdest member of the famility. bio_kmalloc combines a kmalloc
> for the bio and bio_vecs with a hidden bio_init call and magic cleanup
> semantics.
>
> This series moves a few callers away from bio_kmalloc and then turns
> bio_kmalloc into a simple wrapper for a slab allocation of a bio and the
> inline biovecs. The callers need to manually call bio_init instead with
> all that entails and the magic that turns bio_put into a kfree goes away
> as well, allowing for a proper debug check in bio_put that catches
> accidental use on a bio_init()ed bio.
>
> [...]

Applied, thanks!

[1/5] btrfs: simplify ->flush_bio handling
commit: 6978ffddd5bba44e6b7614d52868cf4954e0529b
[2/5] squashfs: always use bio_kmalloc in squashfs_bio_read
commit: 88a39feabf25efbaec775ffb48ea240af198994e
[3/5] target/pscsi: remove pscsi_get_bio
commit: bbccc65bd7c1b22f050b65d8171fbdd8d72cf39c
[4/5] block: turn bio_kmalloc into a simple kmalloc wrapper
commit: 57c47b42f4545b5f8fa288f190c0d68f96bc477f
[5/5] pktcdvd: stop using bio_reset
commit: 1292fb59f283e76f55843d94f066c2f0b91dfb7e

Best regards,
--
Jens Axboe


2022-03-31 02:35:44

by Jens Axboe

[permalink] [raw]
Subject: Re: cleanup bio_kmalloc v2

On 3/30/22 8:29 AM, Christoph Hellwig wrote:
> I just noticed this didn't make it into the 5.18 queue. Which is a
> bit sad as it leaves us with a rather inconsistent bio API in 5.18.

Let me take a look, we might still be able to make it...

--
Jens Axboe

2022-03-31 02:53:36

by Christoph Hellwig

[permalink] [raw]
Subject: Re: cleanup bio_kmalloc v2

I just noticed this didn't make it into the 5.18 queue. Which is a
bit sad as it leaves us with a rather inconsistent bio API in 5.18.

2022-04-01 15:02:51

by Qian Cai

[permalink] [raw]
Subject: Re: cleanup bio_kmalloc v2

On Tue, Mar 08, 2022 at 07:15:46AM +0100, Christoph Hellwig wrote:
> Hi Jens,
>
> this series finishes off the bio allocation interface cleanups by dealing
> with the weirdest member of the famility. bio_kmalloc combines a kmalloc
> for the bio and bio_vecs with a hidden bio_init call and magic cleanup
> semantics.
>
> This series moves a few callers away from bio_kmalloc and then turns
> bio_kmalloc into a simple wrapper for a slab allocation of a bio and the
> inline biovecs. The callers need to manually call bio_init instead with
> all that entails and the magic that turns bio_put into a kfree goes away
> as well, allowing for a proper debug check in bio_put that catches
> accidental use on a bio_init()ed bio.

Reverting this series fixed boot crashes.

WARNING: CPU: 1 PID: 2622 at block/bio.c:229 bio_free
Modules linked in: cdc_ether usbnet ipmi_devintf ipmi_msghandler cppc_cpufreq fuse ip_tables x_tables ipv6 btrfs blake2b_generic libcrc32c xor xor_neon raid6_pq zstd_compress dm_mod nouveau crct10dif_ce drm_ttm_helper mlx5_core ttm drm_dp_helper drm_kms_helper nvme mpt3sas xhci_pci nvme_core raid_class drm xhci_pci_renesas
CPU: 1 PID: 2622 Comm: mount Not tainted 5.17.0-next-20220331 #50
pstate: 10400009 (nzcV daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : bio_free
lr : bio_put
sp : ffff8000371b7760
x29: ffff8000371b7760 x28: 0000000000000000 x27: dfff800000000000
x26: ffff08028f93a600 x25: 0000000000000000 x24: ffff08028f92f600
x23: 1ffff00006e36f10 x22: ffff08028fa18510 x21: 1fffe10051f430a2
x20: 0000000000000000 x19: ffff08028fa18500 x18: ffffde03db3e7d2c
x17: ffffde03d55f8bc4 x16: 1fffe10051e75129 x15: 1fffe106cfcfbb46
x14: 1fffe10051e7511c x13: 0000000000000004 x12: ffff700006e36eab
x11: 1ffff00006e36eaa x10: ffff700006e36eaa x9 : ffffde03d5cb9fec
x8 : ffff8000371b7557 x7 : 0000000000000001 x6 : ffff700006e36eaa
x5 : 1ffff00006e36ea9 x4 : 1ffff00006e36ebe x3 : 1fffe10051f430a2
x2 : 1fffe10051f430ae x1 : 0000000000000000 x0 : ffff08028fa18570
Call trace:
bio_free
bio_put
squashfs_read_data
squashfs_read_table
squashfs_fill_super
get_tree_bdev
squashfs_get_tree
vfs_get_tree
do_new_mount
path_mount
__arm64_sys_mount
invoke_syscall
el0_svc_common.constprop.0
do_el0_svc
el0_svc
el0t_64_sync_handler
el0t_64_sync
irq event stamp: 33146
hardirqs last enabled at (33145): free_unref_page
hardirqs last disabled at (33146): el1_dbg
softirqs last enabled at (33122): __do_softirq
softirqs last disabled at (33111): __irq_exit_rcu
---[ end trace 0000000000000000 ]---
Unable to handle kernel paging request at virtual address dfff800000000001
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
Mem abort info:
ESR = 0x96000004
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x04: level 0 translation fault
Data abort info:
ISV = 0, ISS = 0x00000004
CM = 0, WnR = 0
[dfff800000000001] address between user and kernel address ranges
Internal error: Oops: 96000004 [#1] PREEMPT SMP
Modules linked in: cdc_ether usbnet ipmi_devintf ipmi_msghandler cppc_cpufreq fuse ip_tables x_tables ipv6 btrfs blake2b_generic libcrc32c xor xor_neon raid6_pq zstd_compress dm_mod nouveau crct10dif_ce
drm_ttm_helper mlx5_core ttm drm_dp_helper drm_kms_helper nvme mpt3sas xhci_pci nvme_core raid_class drm xhci_pci_renesas
CPU: 1 PID: 2622 Comm: mount Tainted: G W 5.17.0-next-20220331 #50
pc : bio_free
lr : bio_free
sp : ffff8000371b7760
x29: ffff8000371b7760 x28: 0000000000000000 x27: dfff800000000000
x26: ffff08028f93a600 x25: 0000000000000000 x24: ffff08028f92f600
x23: 1ffff00006e36f10 x22: ffff08028fa18548 x21: 00000000000000d0
x20: 0000000000000000 x19: ffff08028fa18500 x18: ffffde03db3e7d2c
x17: ffffde03d55f8bc4 x16: 1fffe10051e75129 x15: 1fffe106cfcfbb46
x14: 1fffe10051e7511c x13: 0000000000000004 x12: ffff700006e36eab
x11: 1ffff00006e36eaa x10: ffff700006e36eaa x9 : ffffde03d5cb9c78
x8 : ffff8000371b7557 x7 : 0000000000000001 x6 : ffff700006e36eaa
x5 : 1ffff00006e36ea9 x4 : 1fffe10051f430ac x3 : 0000000000000001
x2 : 0000000000000003 x1 : dfff800000000000 x0 : 0000000000000008
Call trace:
bio_free
bio_put
squashfs_read_data
squashfs_read_table
squashfs_fill_super
get_tree_bdev
squashfs_get_tree
vfs_get_tree
do_new_mount
path_mount
__arm64_sys_mount
invoke_syscall
el0_svc_common.constprop.0
do_el0_svc
el0_svc
el0t_64_sync_handler
el0t_64_sync
Code: d2d00001 f2fbffe1 52800062 d343fc03 (38e16861)
---[ end trace 0000000000000000 ]---
SMP: stopping secondary CPUs
Kernel Offset: 0x5e03ccd70000 from 0xffff800008000000
PHYS_OFFSET: 0x80000000
CPU features: 0x000,00085c0d,19801c82
Memory Limit: none
---[ end Kernel panic - not syncing: Oops: Fatal exception ]---
>
> Changes since v1:
> - update a pre-existing comment per maintainer suggestion
>
> Diffstat:
> block/bio.c | 47 ++++++++++++++-----------------------
> block/blk-crypto-fallback.c | 14 ++++++-----
> block/blk-map.c | 42 +++++++++++++++++++++------------
> drivers/block/pktcdvd.c | 34 +++++++++++---------------
> drivers/md/bcache/debug.c | 10 ++++---
> drivers/md/dm-bufio.c | 9 +++----
> drivers/md/raid1.c | 12 ++++++---
> drivers/md/raid10.c | 21 +++++++++++-----
> drivers/target/target_core_pscsi.c | 36 ++++------------------------
> fs/btrfs/disk-io.c | 8 +++---
> fs/btrfs/volumes.c | 11 --------
> fs/btrfs/volumes.h | 2 -
> fs/squashfs/block.c | 14 +++--------
> include/linux/bio.h | 2 -
> 14 files changed, 116 insertions(+), 146 deletions(-)

2022-04-01 15:38:22

by Christoph Hellwig

[permalink] [raw]
Subject: Re: cleanup bio_kmalloc v2

This should fix it:

diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index 930eb530fa622..fed99bb3df3be 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -72,6 +72,13 @@ static int copy_bio_to_actor(struct bio *bio,
return copied_bytes;
}

+static void squashfs_bio_free(struct bio *bio)
+{
+ bio_free_pages(bio);
+ bio_uninit(bio);
+ kfree(bio);
+}
+
static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
struct bio **biop, int *block_offset)
{
@@ -118,9 +125,7 @@ static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
return 0;

out_free_bio:
- bio_free_pages(bio);
- bio_uninit(bio);
- kfree(bio);
+ squashfs_bio_free(bio);
return error;
}

@@ -183,8 +188,7 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
data = bvec_virt(bvec);
length |= data[0] << 8;
}
- bio_free_pages(bio);
- bio_put(bio);
+ squashfs_bio_free(bio);

compressed = SQUASHFS_COMPRESSED(length);
length = SQUASHFS_COMPRESSED_SIZE(length);
@@ -217,8 +221,7 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
}

out_free_bio:
- bio_free_pages(bio);
- bio_put(bio);
+ squashfs_bio_free(bio);
out:
if (res < 0) {
ERROR("Failed to read block 0x%llx: %d\n", index, res);

2022-04-02 17:01:59

by Jens Axboe

[permalink] [raw]
Subject: Re: cleanup bio_kmalloc v2

On 3/31/22 10:40 AM, Christoph Hellwig wrote:
> This should fix it:

Let's drop this one for 5.18, it's also causing a few conflicts and
would probably be more suited for 5.19 at this point.

--
Jens Axboe