Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp105990lqp; Mon, 10 Jun 2024 20:50:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZf7nHem6nLrlyiX244gJsUxa5uhnSvF+J8ZrmE5kPIiNZLMmO2IZGe6iETpu2dK7xC0G++WIzUPa+mODsmqQBIDSw27Y8I7jJImdisA== X-Google-Smtp-Source: AGHT+IGnWaXuMXnV6lwpPQYp0hHbJjCZvYFrumJu0DBNnVY+Prdk01A5KiJbwV5NUBxLTpYzuxha X-Received: by 2002:ac2:4848:0:b0:52b:c1d4:7df4 with SMTP id 2adb3069b0e04-52bc1d47f25mr6786042e87.56.1718077821001; Mon, 10 Jun 2024 20:50:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718077820; cv=pass; d=google.com; s=arc-20160816; b=EraMTaP7MReGYUd7Q7rJxKC1YeM/6hYcrUq/JPKWYdMTRo8nbRVhfNjyoqiTHxPr5/ 1IXUB2E5XjgfQQ/D89HOuS3iZ1FWzZkpo3mq1kcm/sXtuHHnM3ri00OuVYZXcgNdQNZ9 rINZcGI4PccH9AuJHeKC1rR9otwZa4fMSOLGIn6sCuHpDkqonAc0WZ3WDpNLAMrcLjG3 qwdzGAmn2pbAPprDWgHrmFNBVXFYnCAF2id8a4BdcabEW6exE+ZdNs21w+McZuDxHYd4 bUdlLDXMf0HKU4oWr2LLI6FCTl9HQ7PSl9XIrSC7qivWnrOOgjuo7OxFcjdcD1oSx7jB IXMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=IgsJgTaVSPCEWMInOlem8JJ1qEjkPuiwvUKi8x7g5WQ=; fh=VNAK3rZTmzGmLjsPiuN/ds8cSSZe1Uv1lmlL2pGWyq4=; b=KqUilRteJeA72njuo4loS/Iy5L+akpfUYw9xPzyOtUO01ch0yfdCteRfBPKPa5qpmB kGaXo67UWacmcU22Ok+FqzV8Ons8C6IuSl+maKBvlhJfg+o1b0VOx4+LEAS1rUzsZzJf i5YI3g21fK23NTqhpbR6fOzZn1hFdsKM0dV3izWO79NV3qXA3SaUy7hRgh7w4lvYiy6Y PC7mWr1bxxJAWvEpA4lZfuYJ1Ibu0rxWGgO6grdzJtIHyh/awgIWk0IDXoHk/fgCthaa C/Hsn7As63oXq+KF4dXZybEV2kUjlc3JtuwKC+S0tYFcxYfbI8OmcnvRmxz1zZjotLxz DKZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sJKS3qjX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4884-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-a6f26b6a56dsi121416466b.256.2024.06.10.20.50.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 20:50:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4884-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=sJKS3qjX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4884-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4884-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 B3A391F237D2 for ; Tue, 11 Jun 2024 03:50:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D56FE171082; Tue, 11 Jun 2024 03:49:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sJKS3qjX" 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 8EAB5171078; Tue, 11 Jun 2024 03:49:14 +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=1718077754; cv=none; b=FopazEtbXIYKH9QZQkI+1UsZoyPfNxgSne8a2vx9C1HPNw5V86vx/3H4JKSWgNsB4Dt9AbHCNSJrlZ3O2pTa6LKHNYNNr2eU3kgDE3YMwbp7rRZVgHo6+txAQrFMyvtpx717vlYwPEnmeolAiTgZFl7AdMdBDr5QOQ+HMDuviVg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718077754; c=relaxed/simple; bh=DEFlmsbEWT/xZ+wzMO36ZCGur9JVhR2ovvX1zBGomis=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Se6qHXtm8rKMwu9C13BiyaTJIXeQZwXSuHFeqeDmhjHBPc+/iNlOUcjBrYTY3lVk3ovsmRTQ4G+FLibrwCxK1Ksoa9Wk+xBDHui2Ff0JuiHQLGFPk4w8yVdsyzgDUZzANJAPSbxLu90BFlwRmB4xcn9kjbgVbqbsj05nM8FcJtU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sJKS3qjX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32F4AC4AF50; Tue, 11 Jun 2024 03:49:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718077754; bh=DEFlmsbEWT/xZ+wzMO36ZCGur9JVhR2ovvX1zBGomis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sJKS3qjXL6k4MAmNi697sReT81K1UbDyoXvZjBLFCtBh8hTvdljzHE/wdrfRg9biJ k3YeSo4XmEkpWPggdchydh0NVwVKVSrC61y8wiFXQDUTFO0sDLx2q+w18ypGS6wfq8 PVjreno9PVmneYU1g5Xnqf6ZldU16P3hBn8z6mO+xn5drOUGoBucQ14VuQV6dH3c6Q d6mY4o98iqKcqbCJMTPRm8jMI2UL6ToItw3s4erkbmOITOkEeRvumcQC1E3T+SQ/+a JbCraIQ6kiqfpDQDmMXWe87dS7Aj91QUhKl5kQ2uDZWx/DWr1vMULklP67w5CjmeWF Mot5XbwmumKUA== 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 09/15] dm-verity: make real_digest and want_digest fixed-length Date: Mon, 10 Jun 2024 20:48:16 -0700 Message-ID: <20240611034822.36603-10-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> Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Eric Biggers Change the digest fields in struct dm_verity_io from variable-length to fixed-length, since their maximum length is fixed at HASH_MAX_DIGESTSIZE, i.e. 64 bytes, which is not too big. This is simpler and makes the fields a bit faster to access. (HASH_MAX_DIGESTSIZE did not exist when this code was written, which may explain why it wasn't used.) This makes the verity_io_real_digest() and verity_io_want_digest() functions trivial, but this patch leaves them in place temporarily since most of their callers will go away in a later patch anyway. Signed-off-by: Eric Biggers --- drivers/md/dm-verity-target.c | 3 +-- drivers/md/dm-verity.h | 17 +++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/md/dm-verity-target.c b/drivers/md/dm-verity-target.c index 796d85526696..4ef814a7faf4 100644 --- a/drivers/md/dm-verity-target.c +++ b/drivers/md/dm-verity-target.c @@ -1527,12 +1527,11 @@ static int verity_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->error = "Cannot allocate workqueue"; r = -ENOMEM; goto bad; } - ti->per_io_data_size = sizeof(struct dm_verity_io) + - v->ahash_reqsize + v->digest_size * 2; + ti->per_io_data_size = sizeof(struct dm_verity_io) + v->ahash_reqsize; r = verity_fec_ctr(v); if (r) goto bad; diff --git a/drivers/md/dm-verity.h b/drivers/md/dm-verity.h index 20b1bcf03474..5d3da9f5fc95 100644 --- a/drivers/md/dm-verity.h +++ b/drivers/md/dm-verity.h @@ -89,19 +89,16 @@ struct dm_verity_io { struct work_struct work; struct work_struct bh_work; char *recheck_buffer; + u8 real_digest[HASH_MAX_DIGESTSIZE]; + u8 want_digest[HASH_MAX_DIGESTSIZE]; + /* - * Three variably-size fields follow this struct: - * - * u8 hash_req[v->ahash_reqsize]; - * u8 real_digest[v->digest_size]; - * u8 want_digest[v->digest_size]; - * - * To access them use: verity_io_hash_req(), verity_io_real_digest() - * and verity_io_want_digest(). + * This struct is followed by a variable-sized struct ahash_request of + * size v->ahash_reqsize. To access it, use verity_io_hash_req(). */ }; static inline struct ahash_request *verity_io_hash_req(struct dm_verity *v, struct dm_verity_io *io) @@ -110,17 +107,17 @@ static inline struct ahash_request *verity_io_hash_req(struct dm_verity *v, } static inline u8 *verity_io_real_digest(struct dm_verity *v, struct dm_verity_io *io) { - return (u8 *)(io + 1) + v->ahash_reqsize; + return io->real_digest; } static inline u8 *verity_io_want_digest(struct dm_verity *v, struct dm_verity_io *io) { - return (u8 *)(io + 1) + v->ahash_reqsize + v->digest_size; + return io->want_digest; } extern int verity_for_bv_block(struct dm_verity *v, struct dm_verity_io *io, struct bvec_iter *iter, int (*process)(struct dm_verity *v, -- 2.45.1