From 5e405595e5bf4c09fab9ca1e7dbe5b62872757b5 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 24 Aug 2017 16:42:48 -0700 Subject: ext4: perform dax_device lookup at mount The ->iomap_begin() operation is a hot path, so cache the fs_dax_get_by_host() result at mount time to avoid the incurring the hash lookup overhead on a per-i/o basis. Cc: "Theodore Ts'o" Cc: Andreas Dilger Reviewed-by: Jan Kara Reported-by: Christoph Hellwig Signed-off-by: Dan Williams --- fs/ext4/super.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'fs/ext4/super.c') diff --git a/fs/ext4/super.c b/fs/ext4/super.c index d61a70e2193a..3e58f952eddc 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -951,6 +951,7 @@ static void ext4_put_super(struct super_block *sb) if (sbi->s_chksum_driver) crypto_free_shash(sbi->s_chksum_driver); kfree(sbi->s_blockgroup_lock); + fs_put_dax(sbi->s_daxdev); kfree(sbi); } @@ -3377,6 +3378,7 @@ static void ext4_set_resv_clusters(struct super_block *sb) static int ext4_fill_super(struct super_block *sb, void *data, int silent) { + struct dax_device *dax_dev = fs_dax_get_by_bdev(sb->s_bdev); char *orig_data = kstrdup(data, GFP_KERNEL); struct buffer_head *bh; struct ext4_super_block *es = NULL; @@ -3399,6 +3401,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; ext4_group_t first_not_zeroed; + sbi->s_daxdev = dax_dev; if ((data && !orig_data) || !sbi) goto out_free_base; @@ -4378,6 +4381,7 @@ out_fail: out_free_base: kfree(sbi); kfree(orig_data); + fs_put_dax(dax_dev); return err ? err : ret; } -- cgit From aed9eb1b21e85a846c805bc299bbb9d039d4a95b Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 5 Sep 2017 17:51:23 +0100 Subject: ext4: fix null pointer dereference on sbi In the case of a kzalloc failure when allocating sbi we end up with a null pointer dereference on sbi when assigning sbi->s_daxdev. Fix this by moving the assignment of sbi->s_daxdev to after the null pointer check of sbi. Detected by CoverityScan CID#1455379 ("Dereference before null check") Fixes: 5e405595e5bf ("ext4: perform dax_device lookup at mount") Signed-off-by: Colin Ian King Signed-off-by: Dan Williams --- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs/ext4/super.c') diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 3e58f952eddc..55772b2d05ee 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3401,10 +3401,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO; ext4_group_t first_not_zeroed; - sbi->s_daxdev = dax_dev; if ((data && !orig_data) || !sbi) goto out_free_base; + sbi->s_daxdev = dax_dev; sbi->s_blockgroup_lock = kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); if (!sbi->s_blockgroup_lock) -- cgit