From: Jaegeuk Kim Subject: Re: [PATCH] f2fs: Use crypto crc32 functions Date: Wed, 2 Mar 2016 10:21:36 -0800 Message-ID: <20160302182136.GB9395@jaegeuk.gateway> References: <1456787577-59946-1-git-send-email-kmok@cyngn.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1abBP7-0001a8-LQ for linux-f2fs-devel@lists.sourceforge.net; Wed, 02 Mar 2016 18:21:45 +0000 Received: from mail.kernel.org ([198.145.29.136]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1abBP6-0000Jw-B4 for linux-f2fs-devel@lists.sourceforge.net; Wed, 02 Mar 2016 18:21:45 +0000 Content-Disposition: inline In-Reply-To: <1456787577-59946-1-git-send-email-kmok@cyngn.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: Keith Mok Cc: Keith Mok , linux-f2fs-devel@lists.sourceforge.net Hi Keith, > +static inline __u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, > + unsigned int length) > +{ > + struct { > + struct shash_desc shash; > + char ctx[4]; > + } desc; > + int err; > + > + BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); I can't accept this and the below BUG_ON, since this hits during the checkpoint procedure which is very critical for entire filesystem. How about calling back the original method for the error cases? Thanks, > + > + desc.shash.tfm = sbi->s_chksum_driver; > + desc.shash.flags = 0; > + *(u32 *)desc.ctx = F2FS_SUPER_MAGIC; > + > + err = crypto_shash_update(&desc.shash, address, length); > + BUG_ON(err); > + > + return *(__u32 *)desc.ctx; > +} > + > +static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, > + void *buf, size_t buf_size) > +{ > + return f2fs_crc32(sbi, buf, buf_size) == blk_crc; > +} > + > static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) > { > return container_of(inode, struct f2fs_inode_info, vfs_inode); > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > index 6134832..9630865 100644 > --- a/fs/f2fs/super.c > +++ b/fs/f2fs/super.c > @@ -574,6 +574,8 @@ static void f2fs_put_super(struct super_block *sb) > wait_for_completion(&sbi->s_kobj_unregister); > > sb->s_fs_info = NULL; > + if (sbi->s_chksum_driver) > + crypto_free_shash(sbi->s_chksum_driver); > kfree(sbi->raw_super); > kfree(sbi); > } > @@ -1254,6 +1256,15 @@ try_onemore: > if (!sbi) > return -ENOMEM; > > + /* Load the checksum driver */ > + sbi->s_chksum_driver = crypto_alloc_shash("crc32", 0, 0); > + if (IS_ERR(sbi->s_chksum_driver)) { > + f2fs_msg(sb, KERN_ERR, "Cannot load crc32 driver."); > + err = PTR_ERR(sbi->s_chksum_driver); > + sbi->s_chksum_driver = NULL; > + goto free_sbi; > + } > + > /* set a block size */ > if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { > f2fs_msg(sb, KERN_ERR, "unable to set blocksize"); > @@ -1506,6 +1517,8 @@ free_options: > free_sb_buf: > kfree(raw_super); > free_sbi: > + if (sbi->s_chksum_driver) > + crypto_free_shash(sbi->s_chksum_driver); > kfree(sbi); > > /* give only one another chance */ > -- > 2.5.1 ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140