Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp700746rdb; Tue, 31 Oct 2023 22:49:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFr7jhRZRoUac7dR3h37rABL9f2KfSUq3oy3edmsSSN0J7a1OdzwX47nFJmYS1IV7XGyDGG X-Received: by 2002:aca:100f:0:b0:3ae:4cb2:fb43 with SMTP id 15-20020aca100f000000b003ae4cb2fb43mr14516608oiq.21.1698817756321; Tue, 31 Oct 2023 22:49:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698817756; cv=none; d=google.com; s=arc-20160816; b=aFyItBmEL2u/1G/U8JA5CL572L3orHZ7lfMQeLkxG1T4HPzxOkr2oVjEZqZ/h4PH5p B2iRZjmfZb+MvoyhqXc785gva5N6JGUstfUHCY8epd4CO9NRnHEjPjgctonf2GLBz8Mt 5dTP/gWaEcNhksL6J8PrbTLPLHMZ/Iyxt4OIp3fgINUsTiX64nJXlsBMN7uHuibVo5G0 SiUW+ngwkqY4I0vr9Qm8c4zsO2NZ0PDmjP8OKD1O3+TEtqDIY2k2xHvfiwuVGg9/26WY +5Omom6JA5PrDCKjxP+KHJIJk1pPmzDso267zEpNCLfPtxotl/UdBanflZOi21nvZo+4 TR5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GjeDyhaf5Fpvyijb22qobyU1+HX6TXxYcr1CsBe0aNw=; fh=YYBNzDCoW64hRBFWWhbx6ikwAUNpFc96vwP5/ugyPNs=; b=Rcb2/wWVLqt3RtOTInvPVCA4anuA0KAl2U+Gs4UjantazaTGGANfhC+SQWYt1OGrb6 07RXrE1NvYsVFabvV1/oYfgXh7XcXQyYIJQQtlFgJubXLdAemkia9PxaThqWtyWDNA0v E3Q4jFlxDBTFj3+7oQwjGJ60nfxsRzc6/26wTpfv/UgUD5Xfrqnz/33JdbXPE9oT7gWN yESF3ETlYxSzUcexRqPu+csvPKZ6P+VNHeH0MnYbYrhHzfTn0PVlquUHxhPk0Tdwebks jkMHe9+kBthSf4aVPI1J+Pd8aiLY0E147oudGul3jE6E47e51vtsfMuX3A5tkw92+eG4 rx3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C5gHrrqz; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id b190-20020a62cfc7000000b006c0fe2dfec1si890358pfg.72.2023.10.31.22.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 22:49:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C5gHrrqz; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BD6058079724; Tue, 31 Oct 2023 22:49:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347606AbjKAFtE (ORCPT + 99 others); Wed, 1 Nov 2023 01:49:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376765AbjKAFtD (ORCPT ); Wed, 1 Nov 2023 01:49:03 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D646F1 for ; Tue, 31 Oct 2023 22:48:58 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7E2EC433C8; Wed, 1 Nov 2023 05:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698817738; bh=V9HLWURTd89l/w6rZz7bQqntg5RFNATOGPPwC8zy0QE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=C5gHrrqzJ6mkkOv17oZFXdzA2N+30SceNMsFu2oAnt48hDpDoxrmhmZWfPN86b5jZ MMkDBW3lczfb9V9ODfZ4rne3BrHD6ZUs2erhvmmAEdZbrFPuXWxIyjUEdyrMAs8SKJ USl+qU7OGoTKr5nZkpaJbDVRBcwAtCxuiMKjEnz3fMV8z5omIlwvfrhfqkXjDUT/G7 aHK/ZRDZ5rcTbcalk2VvIEeB8J8ezN34l9QAnOoa3+YxwRv2kxZeZAzC6DgO6imYV6 w89hQo15b/VT22oW2iBeWiIIxpaKQC0wGH/JCNsk9g9owfuvyxt78Z4grgvnxvGBsJ AoVn/1noAFp6Q== Date: Tue, 31 Oct 2023 22:48:56 -0700 From: Eric Biggers To: Herbert Xu Cc: agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev, linux-crypto@vger.kernel.org, gilad@benyossef.com, samitolvanen@google.com Subject: Re: [PATCH] dm-verity: hash blocks with shash import+finup when possible Message-ID: <20231101054856.GA140941@sol.localdomain> References: <20231030023351.6041-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 31 Oct 2023 22:49:13 -0700 (PDT) On Wed, Nov 01, 2023 at 12:51:15PM +0800, Herbert Xu wrote: > Eric Biggers wrote: > > > > + driver_name = crypto_ahash_driver_name(ahash); > > + if (v->version >= 1 /* salt prepended, not appended? */ && > > + 1 << v->data_dev_block_bits <= PAGE_SIZE) { > > + shash = crypto_alloc_shash(alg_name, 0, 0); > > I'm sorry but this is disgusting. > > Can't we do the same optimisation for the ahash import+finup path? That would provide the import+finup optimization, but it would retain the overhead of ahash compared to shash. That overhead includes a small amount of extra CPU time as well as the bio size being increased by sizeof(struct ahash_request). It's a small difference, but dm-verity performance is really important. Note that dm-verity also has to use an ugly and error-prone workaround to use ahash at all, since its hash blocks can be cached in vmalloc memory; see verity_hash_update(). shash handles vmalloc memory much more naturally, since no translation from vmalloc address to page to linear address is needed. I'm thinking that avoiding the extra overhead of ahash, combined with avoiding the workaround for vmalloc memory, makes it worthwhile to use shash for the import+export code path. If it was just ahash vs. shash by itself, we wouldn't bother, but the fact that we can combine the two optimizations seems attractive. > > On a side note, if we're going to use shash for bulk data then we > should reintroduce the can/cannot sleep flag. This patch limits the use of shash to blocks of at most PAGE_SIZE (*), which is the same as what ahash does internally. (*) Except when the data block size is <= PAGE_SIZE but the hash block size is > PAGE_SIZE. I think that's an uncommon configuration that's not worth worrying too much about, but it could be excluded from the shash-based code. - Eric