Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp248757lqh; Thu, 30 May 2024 23:13:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDvQ83LYq9hPDA+YABRuc7PAZWF4DmuYOhVaPKHJZbJDfsWpx8khhVI0tNwIipaGg22Eup7u/3NEWjUykYSuJI/31/MUDra2fuDxhKKQ== X-Google-Smtp-Source: AGHT+IE8HzNAHAMTvINLliotwXE0Cb23m9N13p+fzAUPWOVx3CxJ/bPjvAVo0XMCrCtnBvnJ6cKH X-Received: by 2002:a17:907:7b86:b0:a68:6032:463c with SMTP id a640c23a62f3a-a6860326209mr41866866b.18.1717136036100; Thu, 30 May 2024 23:13:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717136036; cv=pass; d=google.com; s=arc-20160816; b=Ni8LAtkyJFyWq6oTpP/QZFJzHgWVDuTaaj3TxFn5aCfOpSMssTMvD2EIR9Y2rLw7kz MYd/smgV5Gkh3kM6v7/y2kYuqvU1MU66gn67MoO4E2HeTqJBPTFre/wHBmO9GFQq4TEL ziBj2A6MCSLgcGY9ogdBsTwuejV0Ne31b6ppf97uf/dMkTuzFGr9TFVhagfgR1DOcic2 bWm68ddTsPocvPiE7oAoUeyyLh632V5FBmYRskgEqFDsbIyCLZxtdMRLRFTbKl0G0IVt x2VWHEb8D9QJeiCiONO0xQKtoonP3JyeFXUF/H0GszLVbY1Hj6ZNwUDJMm3zO50svXfy ULaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mSbZA1EHrdli+gIlTeK/7nl8cg273jGihK3zg5E4gEc=; fh=BVP83eNr+oWatb4qMBZYyHe7HobjerBKYantRajwKl4=; b=u6xMQ8FaBzrgeQgDrihufCs3qn6nOhyT6bx5TtACWJlvOqJMWzjmGYaCdK6jDj/kXC vKJJirjKpe3xKJ2BfqQFiwoSq9xrEGCg92ipg8BkHFgpRebsHc6ajJdKOBY4v8rwfoE0 W91lMpX4qIZ5GTo9nEQ8csWVb6HgTDuP1skQ8DYJ8/BUYkcGu/7W1Ac5LwEtAZzztleX 7rIjSvtFbtowGWKLrlnuOCfwNwFD49ihhSu+n3ikwFyXon/kVBgSsKyMmZAnZOgOUTDi 4gXjutyu3o5iBnkTo1HR90ukR+SFDWb7Jnautu9g/DHXIEoTW8msvH7q6RAn4uI4SUr+ 4WZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nPzdf9Cu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4580-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4580-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a67ea886209si56111466b.512.2024.05.30.23.13.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 23:13:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4580-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nPzdf9Cu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4580-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4580-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A80291F24239 for ; Fri, 31 May 2024 06:13:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D24A57D3E3; Fri, 31 May 2024 06:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nPzdf9Cu" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8792033CA; Fri, 31 May 2024 06:13:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717136030; cv=none; b=KOLUjWSvZwtRHZa6MudK+REUo48PhJznZuNNyQpjs9T2BTooEHga3cgXnv4udivq50ysBLFBri10bi+v73+h8yUHJMZYKDs3mVAgQNbLQczrR+SL8fd4GSUkf74fJrNvzSs3gk3t5zo44W+lP5yctLw+v/3WqlRvSCwtm0sj6JE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717136030; c=relaxed/simple; bh=RwsGqrGzZfc9T/Pyy9DhR5luwagmo4FWO+rh19v6NW4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VHbs4nXaF3cutW/syWhSnzEJ7xmMX+IKHBpY1sUE5gZKZ0W4W4aKZ7677CC5lgjGsK3kNECmENd0+od/1mn7iwTcNuO8FxaCAZ98+sci1iHL4HiXEaUNaTj0O1Wxab2s2I8dTSRHjk/i1f8+w0wAtChLI4MYK8W9hCzb7r9dHBI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nPzdf9Cu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B58E6C116B1; Fri, 31 May 2024 06:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717136030; bh=RwsGqrGzZfc9T/Pyy9DhR5luwagmo4FWO+rh19v6NW4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nPzdf9Cu3FvihQInblNSELG24n3AUYO8ACQqjIF71UQEdW0RAKQXMUtjS8K8Shc7a YAiTOZcRYARi8CC4DQCCjmcDoenzTNkHYLftgLTMQ2AeGte60hnswj4r3bQ/oQSre1 dIzVSG/Xe3+H2tEkNr+X1bQKk9kMJwuHnYepOaMySGo1mknj9DWP6koxt8/erQlXIU AlnmPkKU7U15QlDoIE2B0kaH19jThQ3TZJBKNjmMZMoVJHBP37Rx1vO6mABI5xJXh0 auEsg/ljvHUxhtelB7bkSs6AGGs8Pi7TX8rue/+b27ltXRDmQty1pb2CJgAIVLnykb 5vMMJxUEyUGxg== Date: Thu, 30 May 2024 23:13:48 -0700 From: Eric Biggers To: Herbert Xu Cc: linux-crypto@vger.kernel.org, fsverity@lists.linux.dev, dm-devel@lists.linux.dev, x86@kernel.org, linux-arm-kernel@lists.infradead.org, ardb@kernel.org, samitolvanen@google.com, bvanassche@acm.org Subject: Re: [PATCH v3 6/8] fsverity: improve performance by using multibuffer hashing Message-ID: <20240531061348.GG6505@sol.localdomain> References: <20240507002343.239552-7-ebiggers@kernel.org> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, May 31, 2024 at 12:50:20PM +0800, Herbert Xu wrote: > Eric Biggers wrote: > > > > + if (multibuffer) { > > + if (ctx->pending_data) { > > + /* Hash and verify two data blocks. */ > > + err = fsverity_hash_2_blocks(params, > > + inode, > > + ctx->pending_data, > > + data, > > + ctx->hash1, > > + ctx->hash2); > > + kunmap_local(data); > > + kunmap_local(ctx->pending_data); > > + ctx->pending_data = NULL; > > + if (err != 0 || > > + !verify_data_block(inode, vi, ctx->hash1, > > + ctx->pending_pos, > > + ctx->max_ra_pages) || > > + !verify_data_block(inode, vi, ctx->hash2, > > + pos, ctx->max_ra_pages)) > > + return false; > > + } else { > > + /* Wait and see if there's another block. */ > > + ctx->pending_data = data; > > + ctx->pending_pos = pos; > > + } > > + } else { > > + /* Hash and verify one data block. */ > > + err = fsverity_hash_block(params, inode, data, > > + ctx->hash1); > > + kunmap_local(data); > > + if (err != 0 || > > + !verify_data_block(inode, vi, ctx->hash1, > > + pos, ctx->max_ra_pages)) > > + return false; > > + } > > + pos += block_size; > > I think this complexity is gross. Look at how we did GSO in > networking. There should be a unified code-path for aggregated > data and simple data, not an aggregated path versus a simple path. > > I think ultimately it stems from the fact that this code went from > ahash to shash. What were the issues back then? If it's just vmalloc > we should fix ahash to support that, rather than making users of the > Crypto API go through contortions like this. It can't be asynchronous, period. As I've explained, that would be far too complex, and it would also defeat the purpose because it would make performance worse. Messages *must* be queued up and hashed in the caller's context. What could make sense would be some helper functions and an associated struct for queueing up messages for a particular crypto_shash, up to its mb_max_msgs value, and then flushing them and retrieving the digests. These would be provided by the crypto API. I think this would address your concern, in that the users (fsverity and dm-verity) would have a unified code path for multiple vs. single blocks. I didn't think it would be worthwhile to go there yet, given that fsverity and dm-verity just want 2x or 1x, and it ends up being simpler and more efficient to handle those cases directly. But we could go with the more general queueing helper functions instead if you feel they should be included from the start. - Eric