From patchwork Tue Jun 11 03:48:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 13692886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 258D8C25B76 for ; Tue, 11 Jun 2024 03:50:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=s0XjjiqaPuV+AoEfbrQvwWhWXUf23KQ9/NcapwD/+NA=; b=koWdq38zaxWn8l iM3FgI/r/EEtuJREUlCe6uprI/927O/OpotqmMgApZTpnUkp7fkuVNkN2PopoGrIa9q9iV590oSnZ QlpKKBXG/nnol9It6Xo9ozliPrGECHRFJVR1tkknZaNhTnUx8DX91uwXq07je0n3f9yj0CgQIsY9C jb6TILHR+6iha8cemc5UmqOZsItJA2MAKHwXfQlFGk7FL/8dPtIGkFfqb+ZOTmwt61VloYvYyySoF se7yH9sz1UfcBoWrpzjfxY7PHAppKBu6HAhZKoAOecFVU39QPcx7WWL36Ld+AK/CF97nOH+B5hVZT AgurTFgg75Xz/gZ1kKMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGsW7-00000007Iah-1EMA; Tue, 11 Jun 2024 03:49:51 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGsVl-00000007IM0-00PI for linux-arm-kernel@bombadil.infradead.org; Tue, 11 Jun 2024 03:49:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=tJAHgb4DjvNUyUqrSJXOdiwa1ya9JH6k6pIEF9Npo/0=; b=FgoGBfXS/EIOwKJASZ/pOojbBi c75Ix8g8IFBweR8Dys5L3m5kd/mDk0OlybxJNWTetvXUWUGZCAb6TrIJTHxibY62uDc/pwVkVqnjG RS73AEMBtgehMGQc1EgNhdqx9Q6QSZFOMULS+ZW3udaAI37DVOKOoj5Xw6MSCtLaNEKEN9i+4t5u7 MjMeuXF422+03dwnjTRyCsZSvOQQGDmJgUk26NZ1LSh7yXFJ6ELpDA0GwvN04Llbo/Xb94tGDoruL VHzkuGC17f43I3NGhyhMSUyIEyOkn3n1ASEhCIGynCxKE7ighmuUdq1/eSiWi7ILmku+4l9zh+qV8 gLbTE7Jg==; Received: from dfw.source.kernel.org ([139.178.84.217]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGsVb-00000001s03-2Rfg for linux-arm-kernel@lists.infradead.org; Tue, 11 Jun 2024 03:49:27 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C7F0160C83; Tue, 11 Jun 2024 03:49:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 590ADC4AF50; Tue, 11 Jun 2024 03:49:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718077753; bh=f3jNdwOMbg1pJt24bffn98hUVfrBFO/FFHFl9Cbu1ZQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dYba6+VNF8iQw/ODtSbpWlOZaRdh8JYlVCVQfNiszZ6j5PdMbTh9sAGssGTlHhcPo B4t6796LL2JDOenl/C8cBGWf7gbWPf1pXqmzuDKpOmdtjM/+ezJ816r7p/FC8FjYqR 3gdbvoxe5qAHFoZZI3RMeh0+S3XUjZSsmAFb/OHtKFv+CcEs7QAtENIItHSgNz/9mH DWHibLZIoahniLad6WDLVkLwiOZ2TEKgXi+zqQUod2b1wXZy9hUuDw/lDN9a4rnYGu u5Yy7Rq9EgTWVeBUMfdFJQVrzcFtkQn4szuNcDllLpdZ7yvKdpfNwZthhQRCZWe9ih VWdE/CKewz8IQ== From: Eric Biggers To: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev Cc: x86@kernel.org, linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Sami Tolvanen , Bart Van Assche , Herbert Xu Subject: [PATCH v5 07/15] dm-verity: move hash algorithm setup into its own function Date: Mon, 10 Jun 2024 20:48:14 -0700 Message-ID: <20240611034822.36603-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240611034822.36603-1-ebiggers@kernel.org> References: <20240611034822.36603-1-ebiggers@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240611_044925_563387_C49D0276 X-CRM114-Status: GOOD ( 14.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Eric Biggers Move the code that sets up the hash transformation into its own function. No change in behavior. Signed-off-by: Eric Biggers --- drivers/md/dm-verity-target.c | 70 +++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index bb5da66da4c1..88d2a49dca43 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -1224,10 +1224,47 @@ static int verity_parse_opt_args(struct dm_arg_set *as, struct dm_verity *v, } while (argc && !r); return r; } +static int verity_setup_hash_alg(struct dm_verity *v, const char *alg_name) +{ + struct dm_target *ti = v->ti; + struct crypto_ahash *ahash; + + v->alg_name = kstrdup(alg_name, GFP_KERNEL); + if (!v->alg_name) { + ti->error = "Cannot allocate algorithm name"; + return -ENOMEM; + } + + ahash = crypto_alloc_ahash(alg_name, 0, + v->use_bh_wq ? CRYPTO_ALG_ASYNC : 0); + if (IS_ERR(ahash)) { + ti->error = "Cannot initialize hash function"; + return PTR_ERR(ahash); + } + v->tfm = ahash; + + /* + * dm-verity performance can vary greatly depending on which hash + * algorithm implementation is used. Help people debug performance + * problems by logging the ->cra_driver_name. + */ + DMINFO("%s using implementation \"%s\"", alg_name, + crypto_hash_alg_common(ahash)->base.cra_driver_name); + + v->digest_size = crypto_ahash_digestsize(ahash); + if ((1 << v->hash_dev_block_bits) < v->digest_size * 2) { + ti->error = "Digest size too big"; + return -EINVAL; + } + v->ahash_reqsize = sizeof(struct ahash_request) + + crypto_ahash_reqsize(ahash); + return 0; +} + /* * Target parameters: * The current format is version 1. * Vsn 0 is compatible with original Chromium OS releases. * @@ -1348,42 +1385,13 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv) r = -EINVAL; goto bad; } v->hash_start = num_ll; - v->alg_name = kstrdup(argv[7], GFP_KERNEL); - if (!v->alg_name) { - ti->error = "Cannot allocate algorithm name"; - r = -ENOMEM; - goto bad; - } - - v->tfm = crypto_alloc_ahash(v->alg_name, 0, - v->use_bh_wq ? CRYPTO_ALG_ASYNC : 0); - if (IS_ERR(v->tfm)) { - ti->error = "Cannot initialize hash function"; - r = PTR_ERR(v->tfm); - v->tfm = NULL; - goto bad; - } - - /* - * dm-verity performance can vary greatly depending on which hash - * algorithm implementation is used. Help people debug performance - * problems by logging the ->cra_driver_name. - */ - DMINFO("%s using implementation \"%s\"", v->alg_name, - crypto_hash_alg_common(v->tfm)->base.cra_driver_name); - - v->digest_size = crypto_ahash_digestsize(v->tfm); - if ((1 << v->hash_dev_block_bits) < v->digest_size * 2) { - ti->error = "Digest size too big"; - r = -EINVAL; + r = verity_setup_hash_alg(v, argv[7]); + if (r) goto bad; - } - v->ahash_reqsize = sizeof(struct ahash_request) + - crypto_ahash_reqsize(v->tfm); v->root_digest = kmalloc(v->digest_size, GFP_KERNEL); if (!v->root_digest) { ti->error = "Cannot allocate root digest"; r = -ENOMEM;