* [PATCH] block: pre-initialize struct block_device in bdev_alloc_inode
@ 2021-01-07 18:36 Christoph Hellwig
2021-01-08 3:54 ` Alexey Kardashevskiy
2021-01-08 3:58 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-01-07 18:36 UTC (permalink / raw)
To: axboe; +Cc: aik, linux-block, jack
bdev_evict_inode and bdev_free_inode are also called for the root inode
of bdevfs, for which bdev_alloc is never called. Move the zeroing o
f struct block_device and the initialization of the bd_bdi field into
bdev_alloc_inode to make sure they are initialized for the root inode
as well.
Fixes: e6cb53827ed6 ("block: initialize struct block_device in bdev_alloc")
Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/block_dev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 3e5b02f6606c42..b79ddda11ee317 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -774,8 +774,11 @@ static struct kmem_cache * bdev_cachep __read_mostly;
static struct inode *bdev_alloc_inode(struct super_block *sb)
{
struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL);
+
if (!ei)
return NULL;
+ memset(&ei->bdev, 0, sizeof(ei->bdev));
+ ei->bdev.bd_bdi = &noop_backing_dev_info;
return &ei->vfs_inode;
}
@@ -869,14 +872,12 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
mapping_set_gfp_mask(&inode->i_data, GFP_USER);
bdev = I_BDEV(inode);
- memset(bdev, 0, sizeof(*bdev));
mutex_init(&bdev->bd_mutex);
mutex_init(&bdev->bd_fsfreeze_mutex);
spin_lock_init(&bdev->bd_size_lock);
bdev->bd_disk = disk;
bdev->bd_partno = partno;
bdev->bd_inode = inode;
- bdev->bd_bdi = &noop_backing_dev_info;
#ifdef CONFIG_SYSFS
INIT_LIST_HEAD(&bdev->bd_holder_disks);
#endif
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block: pre-initialize struct block_device in bdev_alloc_inode
2021-01-07 18:36 [PATCH] block: pre-initialize struct block_device in bdev_alloc_inode Christoph Hellwig
@ 2021-01-08 3:54 ` Alexey Kardashevskiy
2021-01-08 3:58 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Alexey Kardashevskiy @ 2021-01-08 3:54 UTC (permalink / raw)
To: Christoph Hellwig, axboe; +Cc: linux-block, jack
On 08/01/2021 05:36, Christoph Hellwig wrote:
> bdev_evict_inode and bdev_free_inode are also called for the root inode
> of bdevfs, for which bdev_alloc is never called. Move the zeroing o
nice wrapping :)
> f struct block_device and the initialization of the bd_bdi field into
> bdev_alloc_inode to make sure they are initialized for the root inode
> as well.
>
> Fixes: e6cb53827ed6 ("block: initialize struct block_device in bdev_alloc")
> Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
> fs/block_dev.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/block_dev.c b/fs/block_dev.c
> index 3e5b02f6606c42..b79ddda11ee317 100644
> --- a/fs/block_dev.c
> +++ b/fs/block_dev.c
> @@ -774,8 +774,11 @@ static struct kmem_cache * bdev_cachep __read_mostly;
> static struct inode *bdev_alloc_inode(struct super_block *sb)
> {
> struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL);
> +
> if (!ei)
> return NULL;
> + memset(&ei->bdev, 0, sizeof(ei->bdev));
> + ei->bdev.bd_bdi = &noop_backing_dev_info;
> return &ei->vfs_inode;
> }
>
> @@ -869,14 +872,12 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno)
> mapping_set_gfp_mask(&inode->i_data, GFP_USER);
>
> bdev = I_BDEV(inode);
> - memset(bdev, 0, sizeof(*bdev));
> mutex_init(&bdev->bd_mutex);
> mutex_init(&bdev->bd_fsfreeze_mutex);
> spin_lock_init(&bdev->bd_size_lock);
> bdev->bd_disk = disk;
> bdev->bd_partno = partno;
> bdev->bd_inode = inode;
> - bdev->bd_bdi = &noop_backing_dev_info;
> #ifdef CONFIG_SYSFS
> INIT_LIST_HEAD(&bdev->bd_holder_disks);
> #endif
>
--
Alexey
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: pre-initialize struct block_device in bdev_alloc_inode
2021-01-07 18:36 [PATCH] block: pre-initialize struct block_device in bdev_alloc_inode Christoph Hellwig
2021-01-08 3:54 ` Alexey Kardashevskiy
@ 2021-01-08 3:58 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-01-08 3:58 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: aik, linux-block, jack
On 1/7/21 11:36 AM, Christoph Hellwig wrote:
> bdev_evict_inode and bdev_free_inode are also called for the root inode
> of bdevfs, for which bdev_alloc is never called. Move the zeroing o
> f struct block_device and the initialization of the bd_bdi field into
> bdev_alloc_inode to make sure they are initialized for the root inode
> as well.
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-09 4:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-07 18:36 [PATCH] block: pre-initialize struct block_device in bdev_alloc_inode Christoph Hellwig
2021-01-08 3:54 ` Alexey Kardashevskiy
2021-01-08 3:58 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).