From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706245; cv=none; d=zohomail.com; s=zohoarc; b=GlU1FqkA5zEDSe/SSfTmNp6B5Ol3pOCQpeHp6WmkRm2K3+9G6SSoA8n+cVFoxMQmzyxz+YqiQpoxnDZ4BBTLfKYFBSzkAQ+PO/pJzQUC142ZMU4DYI+Va4KfOQEKTsqd737Wq813/kAr4x7evHM+5bf/qaR5XnU6irOiFwFkPLo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706245; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mU32fUdqbOP78qIBgbT8+B9YhjVGKgxYqP5o3Z/rxlM=; b=GTo/wVZALqithA6ZQlRUWS/CYsoj5HtRiPbRH3bWts/+nIN3qdE8rz5iLWkwIVySMkKWOukkanCeUe8tJwU2b+XzvfRCWw3A+62QuCJ+SKFPBSZ3nMoaqTFroFgCXlj1973PbKeriLb5PHtNJTps/Uag+QZl4MjdTBqulz6kUfA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706245203698.0404459421565; Mon, 4 Dec 2023 08:10:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABV1-0006i8-FE; Mon, 04 Dec 2023 11:08:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABUy-0006fs-Hu for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:08:44 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABUw-0005H0-9b for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:08:44 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6cbe716b511so3482859b3a.3 for ; Mon, 04 Dec 2023 08:06:42 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706000; x=1702310800; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mU32fUdqbOP78qIBgbT8+B9YhjVGKgxYqP5o3Z/rxlM=; b=YJvREbR4LGD8E2B9rcSGjavqB2CySTxtInb/+LBL17jYZF64Zs1rx5fn3o0mq8XJg4 eEQAkkYzka7TshEevHqKMjcG1oPz2c5HgS+ikZvkplM/jfgJIwSR01THYJflNbCPI5Ro 8ogwlbQbtUd8ysRmJiB0qm01rSts/Bumy6sWR0ITOhqLtR6pXfaGiL3HGzglyYe1YMr9 0E/NtOp2isf0oyrhmSgKKVTOFQCvcuH6it9KsiPPEVJ/NrvIj+oZvGrYVymreE7EBBfp K2SsI4JDlB2RSgSuH3FQ3oDmqgYaQTWfZE3mG4RxxY+Ll9G7NLCcm8tbMPN2sRqS5OFU yHbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706000; x=1702310800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mU32fUdqbOP78qIBgbT8+B9YhjVGKgxYqP5o3Z/rxlM=; b=RNEUGzlYthLNQ4/ZIrLOvpC/ZX1Cehk80kfnQkwO/A6SgTb0RjFlammd72ZzGnwyKk h1IXx6q7CRy2oUn3b5hUlPe9UULzsTv8qvc1pE0aj7MhxhHFwzIc9TONVpsV1Ef1W7RF h4mUkuacMv7nPrtRqmIUhgFzV7MJ85VNZQxVtSumW0kfzZykJcVfwjB8A+6AuVyMgh24 GjthhAnVsb/tcVQHlNL3JMSGCapdWrPdqjIAnCiJM2B+Ly78BVoRqd92Fy3gGybT7G7d iblaIva9X7pQTxMfeiVJ3631/p18JlnIJYh3LU5oq4qC5uRwuUmSIHDqUysxJfLf4kf7 Sr2w== X-Gm-Message-State: AOJu0YwNdqVIlYIrYzdldgKG3QLUndlamM3GfloZ2hdyGAksW0FK0XUy TKLbFhboRWztdpR8yxHc+E5WhZiasD17zwP7sK6jkR83 X-Google-Smtp-Source: AGHT+IG1BaMexBswks70YdFD62Y1bkRyYevOfk91XEQlhbBfsDFETnfo7CVxFcuHrwOh6YszZ98eaw== X-Received: by 2002:a05:6a20:2694:b0:18f:97c:8272 with SMTP id h20-20020a056a20269400b0018f097c8272mr1631670pze.124.1701705999775; Mon, 04 Dec 2023 08:06:39 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 1/8] crypto: Export util functions and structures Date: Tue, 5 Dec 2023 00:06:18 +0800 Message-Id: <028c7b2b533b76a729b123170d6109a9d1b7ced9.1701705003.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::433; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706246169100009 Content-Type: text/plain; charset="utf-8" Luks driver logic is primarily reused by Gluk, which, therefore, exports several pre-existing functions and structures. Signed-off-by: Hyman Huang --- block/crypto.c | 16 ++++------------ block/crypto.h | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 921933a5e5..6afae1de2e 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -34,14 +34,6 @@ #include "qemu/memalign.h" #include "crypto.h" =20 -typedef struct BlockCrypto BlockCrypto; - -struct BlockCrypto { - QCryptoBlock *block; - bool updating_keys; -}; - - static int block_crypto_probe_generic(QCryptoBlockFormat format, const uint8_t *buf, int buf_size, @@ -321,7 +313,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, } =20 =20 -static int coroutine_fn GRAPH_UNLOCKED +int coroutine_fn GRAPH_UNLOCKED block_crypto_co_create_generic(BlockDriverState *bs, int64_t size, QCryptoBlockCreateOptions *opts, PreallocMode prealloc, Error **errp) @@ -385,7 +377,7 @@ block_crypto_co_truncate(BlockDriverState *bs, int64_t = offset, bool exact, return bdrv_co_truncate(bs->file, offset, exact, prealloc, 0, errp); } =20 -static void block_crypto_close(BlockDriverState *bs) +void block_crypto_close(BlockDriverState *bs) { BlockCrypto *crypto =3D bs->opaque; qcrypto_block_free(crypto->block); @@ -404,7 +396,7 @@ static int block_crypto_reopen_prepare(BDRVReopenState = *state, */ #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024) =20 -static int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_RDLOCK block_crypto_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -466,7 +458,7 @@ block_crypto_co_preadv(BlockDriverState *bs, int64_t of= fset, int64_t bytes, } =20 =20 -static int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_RDLOCK block_crypto_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t byte= s, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/crypto.h b/block/crypto.h index 72e792c9af..06465009f0 100644 --- a/block/crypto.h +++ b/block/crypto.h @@ -21,6 +21,8 @@ #ifndef BLOCK_CRYPTO_H #define BLOCK_CRYPTO_H =20 +#include "crypto/block.h" + #define BLOCK_CRYPTO_OPT_DEF_KEY_SECRET(prefix, helpstr) \ { \ .name =3D prefix BLOCK_CRYPTO_OPT_QCOW_KEY_SECRET, \ @@ -131,4 +133,25 @@ block_crypto_amend_opts_init(QDict *opts, Error **errp= ); QCryptoBlockOpenOptions * block_crypto_open_opts_init(QDict *opts, Error **errp); =20 +typedef struct BlockCrypto BlockCrypto; + +struct BlockCrypto { + QCryptoBlock *block; + bool updating_keys; +}; + +int coroutine_fn GRAPH_UNLOCKED +block_crypto_co_create_generic(BlockDriverState *bs, int64_t size, + QCryptoBlockCreateOptions *opts, + PreallocMode prealloc, Error **errp); + +int coroutine_fn GRAPH_RDLOCK +block_crypto_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); + +int coroutine_fn GRAPH_RDLOCK +block_crypto_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t byte= s, + QEMUIOVector *qiov, BdrvRequestFlags flags); + +void block_crypto_close(BlockDriverState *bs); #endif /* BLOCK_CRYPTO_H */ --=20 2.39.1 From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706191; cv=none; d=zohomail.com; s=zohoarc; b=WcLn/+UsL+GFSTS2YYDvVDZNg+KtKLFUwtoDPSOXkDgZybkpkmal2f5z1tTK32tuOAPvJyuxriobYFhBbih9CmRMdXE75MVeNV0ShNyac1Do7SbcpOQZ8/l94T2AiVDe0zFc2F5eHF1hYROGihnQHEZtlKNmySWO+2MJlibjF5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706191; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/KbFsOHJJ/ll0h14k1paX0fqVNBTjtrk/tR4NFD8wo4=; b=XXxMgOS4KIKNdGPgspLvpOVv+EDGCAD8GevMOhxMPJ+CF36xwGhM9tZkrmqOc1j0Q48XOamAsJaPExatuzb4cgQf4W/qfyl53WVgMVPPE4J8enIxqMda2V/MIW1rk6Lj4Gg5NOUIk51FuNaicsmudwakIIEd74GC5nVgLgroJXE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706191696418.68130985937216; Mon, 4 Dec 2023 08:09:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABV3-0006j1-76; Mon, 04 Dec 2023 11:08:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABV1-0006iG-Mn for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:08:47 -0500 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABV0-0005HN-6C for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:08:47 -0500 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6ce5513b727so596816b3a.3 for ; Mon, 04 Dec 2023 08:06:45 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:06:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706004; x=1702310804; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/KbFsOHJJ/ll0h14k1paX0fqVNBTjtrk/tR4NFD8wo4=; b=MMzKAm7In7wndw3JZN0IEkItsPZCjZwO7ZhRzI+x4NE/RiF1kKgQ38+bcJs1ADZcyR Xkg3yoZa8lB4BhOu0bJgyzmcx1STx+LX3ZPdE5/SuT+cNsGJl1770CcHys8onOnbOL8/ 9KgOEf3t1A1NKfgHcjVreZ+4tJc4wxpwIS2rT5SYBRkx0WTbC/AYchm0LLOGjq4uAVnI 8fqbjbtZr3LsEw7+T2fD5Uy6ruy+VgFvHBmAFEtBjJYIyvcQDYSnaOpLzT1P+tHJuPnf E+G3LpY2BoJbcbZphrvz/ut5M4DOarDyV5qCzTl1gf4NmTq4C/ewumywFPyWeHNSNFim CTWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706004; x=1702310804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/KbFsOHJJ/ll0h14k1paX0fqVNBTjtrk/tR4NFD8wo4=; b=PAmQ48jjXrXNwJfITOvXnw9dxRN1Kga9s6ESrwfCCotYhBG6YlA3SRbKFDFsmo2zB8 BjepwLoOgLRFzvYQ88veJXCEvBft3L0DG25yFOc8oDie3pVN9c1scfeJg9XbZz1XAqml u4415VRwvgjTiNKF+Qx1/r12biKD7pvtjDwtx0gIzqueHb8oZaOS+8W47loY2nW+ZxGV y6M+mNkKVAuvtcYuNIxzvGqnHIcgZbp+JgIp2QnPmKXq2EA+VpN0z4KEgG20XkxTvabo lezyg+URxv3NbDvz5A5u10W9IbZCPeiUg8qEHJDY3uv7x0BSeOH5MBXlh+yVlufLktuE sAIQ== X-Gm-Message-State: AOJu0YxT4ifz8we+FC1fUpZopAPWsWTZYC8jhBjdK/tCUwBVLGxEBLSZ fkfpJWQttTn15qUQTDyR/roz+2Z4XtvyOxcbPZwW1ku+ X-Google-Smtp-Source: AGHT+IEtft1044g7h5cv0B0ZarKnvXJOUbattWjsKGoqb50fFxNA9SWjd8lXLKgtmhMojJgjrCicIw== X-Received: by 2002:a05:6a20:7d90:b0:18c:159b:7f9 with SMTP id v16-20020a056a207d9000b0018c159b07f9mr2234263pzj.9.1701706004119; Mon, 04 Dec 2023 08:06:44 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 2/8] crypto: Introduce payload offset set function Date: Tue, 5 Dec 2023 00:06:19 +0800 Message-Id: <1741fb5af5602d351d385cbd15394afc154cbc84.1701705003.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::42c; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706193346100001 Content-Type: text/plain; charset="utf-8" Implement the payload offset set function for Gluks. Signed-off-by: Hyman Huang --- crypto/block.c | 4 ++++ include/crypto/block.h | 1 + 2 files changed, 5 insertions(+) diff --git a/crypto/block.c b/crypto/block.c index 7bb4b74a37..3dcf22a69f 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -319,6 +319,10 @@ QCryptoHashAlgorithm qcrypto_block_get_kdf_hash(QCrypt= oBlock *block) return block->kdfhash; } =20 +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset) +{ + block->payload_offset =3D offset; +} =20 uint64_t qcrypto_block_get_payload_offset(QCryptoBlock *block) { diff --git a/include/crypto/block.h b/include/crypto/block.h index 4f63a37872..b47a90c529 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -312,4 +312,5 @@ void qcrypto_block_free(QCryptoBlock *block); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free) =20 +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset= ); #endif /* QCRYPTO_BLOCK_H */ --=20 2.39.1 From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706244; cv=none; d=zohomail.com; s=zohoarc; b=hZTgFqXL2/KsbQY6o7ncmFoWPf6LKZiohws4MY4dyp4k2iiDR4PrsrjFtU+RlniDihowbbrv6J2gQfR9JSAaDZi44Nbm+CuWuprM7hEb9ahSINlvYhWG26453k8WgS1P7Ua18o/+t2X2ht+6mPg3Sg9H7H8aLukc6xKgZSxM6yg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706244; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Paa1v9lX7auJnjKurBVZBYxHkzxsBjXqa29SVbISB48=; b=GC3zEUP4EPdDpbKSv3vqYNaIcfMU2CQdvc74+D5kHww3GiRXEqbKNlLvmFkENwOQPnPwgHzG3hkg34XoyhCHTLeHxvd7SU62QlQKY4z6tKvt7gs9SHxYPlQTNrze8vvWiIbbDMvf5cZTUfvDmPgzNGqi1RBXVtUN7Q6AIk/f4c4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706244457882.8858747401508; Mon, 4 Dec 2023 08:10:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABV8-0006kn-43; Mon, 04 Dec 2023 11:08:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABV5-0006kB-Js for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:08:51 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABV3-0005HY-R9 for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:08:51 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ce3efb78e2so1773900b3a.1 for ; Mon, 04 Dec 2023 08:06:49 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:06:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706008; x=1702310808; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Paa1v9lX7auJnjKurBVZBYxHkzxsBjXqa29SVbISB48=; b=U7YsT0RBX94pAoDNw18ebKp9J1sSCGVz7EmkDPxGljVSAt/eqD2+GZnZ2KhxtLPR6b bu3+vxT2wVaqAkW9IRTdrRTXPmZULePUMPOaVMocMqpUh6fWdeiOs3UML4ck1ybca5Mf 54uhOorcCv8VawcJh62fq3oDW0Dha95gTgQxysaJEWsEqFQP1366Z3UxmUQhR1BpyGFW SHbYcjDP4ZMHUb3l7CHR0eNkiU3EHlPNlxEf6V4nl0UNUJqo4A5601tw12BO2E6BsPfP uDfp5eHtDLbTB5MDINc8K1kApEhu7PapiD9Q4iX7ljXtfBsmLtYvWTL1rYy2hD7GQn6G jB2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706008; x=1702310808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Paa1v9lX7auJnjKurBVZBYxHkzxsBjXqa29SVbISB48=; b=tzyx04TUxwITKIDBLlrgQyr3FO/2zwf5/cy0tvRL+dxODu/eOJoztQ6eBnW5aviqwQ 2Ah/nPAqyWJb1nwlyeWcI/KKTCeokrC0BxyMNCNuyW80tBJa/f0NcWhMuphMRi1/wrVg Vzl77Pa2njdyL6LKXKiV0Rjp0Xu+4KtD1P+0iX1NIJMrwIvkVTo/RcJzISUDeK0I6r2K 6dXPgmBPRE5XLbc8QjkiaZIZ0qzlE0ubKOhfG9mu2+/7Ou2pJWtrSHuZxaO8GRULYP0d 9h/lPaGWPp0q178tvuLlt3yGYS2LboMQDJIgWIXyLux28NOyocoFasZjP9lPK1lPUaSB qLNw== X-Gm-Message-State: AOJu0YwHgP+PS2+YXzKQqob6gwrLpSNybM+c3pI4EPCZDIArgO/kSktU 1mu51YjkMAIWfb+y+EkOpeS2gFI9KYKdE/9n3m8j/jKD X-Google-Smtp-Source: AGHT+IGtjxyGHy5eOaXkwD5tMHenm76xoijZUWzR3057CdomPVltOfsQFLGSwMDhG15BOi4S0+GXyw== X-Received: by 2002:a05:6a21:9981:b0:18f:97c:9766 with SMTP id ve1-20020a056a21998100b0018f097c9766mr6194014pzb.78.1701706007923; Mon, 04 Dec 2023 08:06:47 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 3/8] Gluks: Add the basic framework Date: Tue, 5 Dec 2023 00:06:20 +0800 Message-Id: <86633da8871fc0aceb1d0667ad05e15494585a70.1701705003.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::433; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706246165100008 Content-Type: text/plain; charset="utf-8" Gluks would be a built-in format in the QEMU block layer. Signed-off-by: Hyman Huang --- block/generic-luks.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ block/generic-luks.h | 26 ++++++++++++++ block/meson.build | 1 + 3 files changed, 108 insertions(+) create mode 100644 block/generic-luks.c create mode 100644 block/generic-luks.h diff --git a/block/generic-luks.c b/block/generic-luks.c new file mode 100644 index 0000000000..f23e202991 --- /dev/null +++ b/block/generic-luks.c @@ -0,0 +1,81 @@ +/* + * QEMU block driver for the generic luks encryption + * + * Copyright (c) 2024 SmartX Inc + * + * Author: Hyman Huang + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#include "qemu/osdep.h" + +#include "block/block_int.h" +#include "block/crypto.h" +#include "crypto/block.h" + +#include "generic-luks.h" + +/* BDRVGLUKSState holds the state of one generic LUKS instance */ +typedef struct BDRVGLUKSState { + BlockCrypto crypto; + BdrvChild *header; /* LUKS header node */ + uint64_t header_size; /* In bytes */ +} BDRVGLUKSState; + +static int gluks_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) +{ + return 0; +} + +static int coroutine_fn GRAPH_UNLOCKED +gluks_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) +{ + return 0; +} + +static void +gluks_child_perms(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + +} + +static int64_t coroutine_fn GRAPH_RDLOCK +gluks_co_getlength(BlockDriverState *bs) +{ + return 0; +} + +static BlockDriver bdrv_generic_luks =3D { + .format_name =3D "gluks", + .instance_size =3D sizeof(BDRVGLUKSState), + .bdrv_open =3D gluks_open, + .bdrv_co_create_opts =3D gluks_co_create_opts, + .bdrv_child_perm =3D gluks_child_perms, + .bdrv_co_getlength =3D gluks_co_getlength, +}; + +static void block_generic_luks_init(void) +{ + bdrv_register(&bdrv_generic_luks); +} + +block_init(block_generic_luks_init); diff --git a/block/generic-luks.h b/block/generic-luks.h new file mode 100644 index 0000000000..2aae866fa4 --- /dev/null +++ b/block/generic-luks.h @@ -0,0 +1,26 @@ +/* + * QEMU block driver for the generic luks encryption + * + * Copyright (c) 2024 SmartX Inc + * + * Author: Hyman Huang + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#ifndef GENERIC_LUKS_H +#define GENERIC_LUKS_H + +#endif /* GENERIC_LUKS_H */ diff --git a/block/meson.build b/block/meson.build index 59ff6d380c..74f2da7bed 100644 --- a/block/meson.build +++ b/block/meson.build @@ -39,6 +39,7 @@ block_ss.add(files( 'throttle.c', 'throttle-groups.c', 'write-threshold.c', + 'generic-luks.c', ), zstd, zlib, gnutls) =20 system_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c')) --=20 2.39.1 From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706172; cv=none; d=zohomail.com; s=zohoarc; b=M+lCOvy99K6awuucma57YDINPOMdbbm24VRyblAHZGzVLv93utAKxBXuSmX9ZzL8r3atCYES4smVdEyZj1jRs/SntuCp+Rz153hMPJ3meFZs0R7HmlI4yRlpsgWOfQv/bG62bbCQkRvX8wcQSCDf7tXXGl7QRueWF1f7Get3Bag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706172; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=k1QeiOhFy3aR8sUUfQkgHk63IJyiyAt+CbeADuDdbL0=; b=H57Z6OoM6RjjD1OEFOD1oHCsPz3wrJLxg5XZysyaOCQRNm15u/hexJj6S12TZQhpUyTRAh5OVv5DjRoJ1BfwWeSnxlCSV6t6DveeVx/4s/avQV4ed+70Z5/4KwHibW6XXmzJqDUL+aBwe1HS8BBtLViomQJQdkzSfJSDsMO8oeA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706172781414.6075260130008; Mon, 4 Dec 2023 08:09:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABVJ-0006sF-UL; Mon, 04 Dec 2023 11:09:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABVH-0006pa-MV for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:03 -0500 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABV8-0005Hm-RB for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:03 -0500 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ce3efb78e2so1773994b3a.1 for ; Mon, 04 Dec 2023 08:06:54 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:06:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706013; x=1702310813; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k1QeiOhFy3aR8sUUfQkgHk63IJyiyAt+CbeADuDdbL0=; b=jabphSQR0piJnaKvIWeDcDtPxMEZAHMSDJ09P8H0NK9MCghtkuuxDl3Ri3JvPjjlUn r93GXvBjOGWASBZG8KlDfxGH59SMwHDA12KT9eIzHEHhUjGLdR3UBsymwtkqkHEzMrc+ NgZZM+QoHjaUqhV12LrbEK6XAUrddxMaGC3+G3QGieisF2TilBNGk4tRaMZ5uXNKvL9v MhiZIxnbTU9E/ukQcyY+aq05/ZI36pDbfhMKyzSXRQDC3XgGfj3yxAcSaDsGYrvE14UP A7tkTwSbJ8krlrqeTL9AyJ0zOvuqimC/VmNaqFP/SDnibU1Zae2LXSy0aEvlMPkNMs+U n9cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706013; x=1702310813; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k1QeiOhFy3aR8sUUfQkgHk63IJyiyAt+CbeADuDdbL0=; b=U+/LqBGoLCqcDVWJ81Hk241Gfppvppt4s1VpFJeuwR+mOG5oov+Nt0KC7Fo5fJBfqC p7rryXwmTdA16TcVScC3R/r1XQgRdz4iJ3QNRZ1rOTc34wiXFCvR/AdpEaOleEUaN1IL B428aKUCvsMO1wQFgkcoVC157plPlwu7agVC6EvijyDiidCbYX99n4EoUp8yvc/iLxWd skgLkPbrtWAvTlVROsoyZJjhHEh2sb9HA9xWV23B+KFnN4BLMio52MOQcsiM/NRviajo wi75+Kdee57JNGXmBOdAZWKmeRepDtgEV65PdkfLa3PmxmxpoNfIHNllqzKNoWk/7YRx qPbw== X-Gm-Message-State: AOJu0YzbZOmekhvITh8b9kblFUDkqjcOy2dyLMPU9t/2GmLfS5PRKkZX flSTktwK6e9oYvgsVxFZcA04n0WmmB7MDno4nV8rLsaL X-Google-Smtp-Source: AGHT+IGdBS90NTg8Ug8m0G305HsVDpnrwP4uMHSmgOGJGA2h6QwXbx9fykdVNFp8Y0lJbZ5Xi8qP9Q== X-Received: by 2002:a05:6a00:1150:b0:6ce:2732:583 with SMTP id b16-20020a056a00115000b006ce27320583mr5056556pfm.52.1701706012830; Mon, 04 Dec 2023 08:06:52 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 4/8] Gluks: Introduce Gluks options Date: Tue, 5 Dec 2023 00:06:21 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706174860100007 Content-Type: text/plain; charset="utf-8" Similar to Luks, the Gluks format primarily recycles the Luks choices with the exception of the "size" option. Signed-off-by: Hyman Huang --- block/crypto.c | 4 ++-- block/generic-luks.c | 18 ++++++++++++++++++ block/generic-luks.h | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 6afae1de2e..6f8528dccc 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -150,7 +150,7 @@ error: } =20 =20 -static QemuOptsList block_crypto_runtime_opts_luks =3D { +QemuOptsList block_crypto_runtime_opts_luks =3D { .name =3D "crypto", .head =3D QTAILQ_HEAD_INITIALIZER(block_crypto_runtime_opts_luks.head), .desc =3D { @@ -181,7 +181,7 @@ static QemuOptsList block_crypto_create_opts_luks =3D { }; =20 =20 -static QemuOptsList block_crypto_amend_opts_luks =3D { +QemuOptsList block_crypto_amend_opts_luks =3D { .name =3D "crypto", .head =3D QTAILQ_HEAD_INITIALIZER(block_crypto_create_opts_luks.head), .desc =3D { diff --git a/block/generic-luks.c b/block/generic-luks.c index f23e202991..ebc0365d40 100644 --- a/block/generic-luks.c +++ b/block/generic-luks.c @@ -35,6 +35,21 @@ typedef struct BDRVGLUKSState { uint64_t header_size; /* In bytes */ } BDRVGLUKSState; =20 +static QemuOptsList gluks_create_opts_luks =3D { + .name =3D "crypto", + .head =3D QTAILQ_HEAD_INITIALIZER(gluks_create_opts_luks.head), + .desc =3D { + BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME(""), + { /* end of list */ } + }, +}; + static int gluks_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -71,6 +86,9 @@ static BlockDriver bdrv_generic_luks =3D { .bdrv_co_create_opts =3D gluks_co_create_opts, .bdrv_child_perm =3D gluks_child_perms, .bdrv_co_getlength =3D gluks_co_getlength, + + .create_opts =3D &gluks_create_opts_luks, + .amend_opts =3D &block_crypto_amend_opts_luks, }; =20 static void block_generic_luks_init(void) diff --git a/block/generic-luks.h b/block/generic-luks.h index 2aae866fa4..f18adf41ea 100644 --- a/block/generic-luks.h +++ b/block/generic-luks.h @@ -23,4 +23,7 @@ #ifndef GENERIC_LUKS_H #define GENERIC_LUKS_H =20 +extern QemuOptsList block_crypto_runtime_opts_luks; +extern QemuOptsList block_crypto_amend_opts_luks; + #endif /* GENERIC_LUKS_H */ --=20 2.39.1 From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706197; cv=none; d=zohomail.com; s=zohoarc; b=gZzHleRrlf7Gef26PO1yFa2Rlr2mnE9RdX5J+ijKtluBMr2KyYyMPAtKG/QLbqWRkD9muAgaBH9VAC5YS8zMnxsq1YaDadYIJgnEBe2nz8xoV0IQv+zhxHeSJSqdyyeGf+/89RHxHlgGVhrwU068qu78w1rf6qJAIywlua03S9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706197; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=77C9fyBK+wCjHbA0j2qTNKB4ASsAQiztQYgybK7k++I=; b=Bf2G2yjrhWN8yi+V4B5LD95o6xwHV11CH5ev0DJaWvCk0C4YPXvQMi64QVDnvPC7cXGTVvk4E1OJ8NwsCofIc9tgrwhGatD+sFQiskQWfDiZMdx0BTPgYaBlnZK/XmmTgjMMF3yQgGb6KmvbQH413CsMUC3u/xBUUwtvSbie5iI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706197225762.5335467903017; Mon, 4 Dec 2023 08:09:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABVX-0006wM-OR; Mon, 04 Dec 2023 11:09:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABVV-0006vY-Gm for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:17 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABVD-0005IQ-8M for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:17 -0500 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6cb55001124so4270346b3a.0 for ; Mon, 04 Dec 2023 08:06:58 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706018; x=1702310818; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=77C9fyBK+wCjHbA0j2qTNKB4ASsAQiztQYgybK7k++I=; b=1Z7oHjtEyvRQ8V/KsmHMRV4Nju+keGOinh0s+3ElEBauUBL2GZ+Zj9rr7VuHaXUlJm xPPDSyLO9DiCYJ0yc66vTxKL9kzYRJz4tv8SJablzvpX1cMBYV7IsDB3CKDeUfMjciqV BZjt2gw+rejhr1kHt1RDOmDVxsi6HW2CsxzqTmvtNReyUxgxtLHa9+SBVPnOrjJxWKPi 5wpTTjxYs4aBQQybZy9FhixWrF1SNGeJseMDf8R6Y2Wt1hV3fJWdYWFFGFlm8KLx/u8t UAzznTPZaRFYI/UdgldfHNqP+/Vb3OVfn+UwRorcrC27cDWHZsMkE6IO6Ki2cOMNz6oe 7c4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706018; x=1702310818; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=77C9fyBK+wCjHbA0j2qTNKB4ASsAQiztQYgybK7k++I=; b=AdK1+AYczoxuPwg74soPSvkSMzKXwROx3+id+kq0Ygu8x+4gk/0OQotP2A6gpn5OSj uwQHguzppezGOCPE543yuS9atUMsyWbRdoqXEEH1Ur/UiM1uCiMS0FLVtD88XSPDWR+V ccDbQeDsxKTKwePdtOkqcL41faO9JPbWeZPvCUaokKQlNJgbuQEU63++Mqea2Drc0iiv JQXIBw4JCX85IBsXEbfiIDCSBygT1FjltdUUzSDKTSFIA+nw28pt7WvgqusAzppc5PxS t61Hr+uW9kCBfFHxU5EvuYn9VNJGbLXjyMVbPfjx+voCLvLyRwfhXclljWAIIyMolfJn BZQw== X-Gm-Message-State: AOJu0YyH8YNNEKKbBQDrmboklGhH9Ex2Fgme1oayGbtLAWEeHf1p5gZM 9oJYOZxWzXPYkZ9OWgWxBxriqENDOl+rD1cgAaiGw2Ta X-Google-Smtp-Source: AGHT+IEqHaQzs6HU2aZxrQNo9kCWPDV1YIaMDi0HAkWOowjgkc4i+LeTjSOkDfqtvvOvSRpMRX73VQ== X-Received: by 2002:a05:6a20:138b:b0:18f:97c:3864 with SMTP id hn11-20020a056a20138b00b0018f097c3864mr3406251pzc.62.1701706017473; Mon, 04 Dec 2023 08:06:57 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 5/8] qapi: Introduce Gluks types to qapi Date: Tue, 5 Dec 2023 00:06:22 +0800 Message-Id: <356796b03a257593357fe660e49b17e2057009ef.1701705003.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::432; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706199450100003 Content-Type: text/plain; charset="utf-8" Primarily using the Luks types again, Gluks adds an extra option called "header", which points to the Luks header node's description. Signed-off-by: Hyman Huang --- qapi/block-core.json | 22 +++++++++++++++++++++- qapi/crypto.json | 10 +++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index ca390c5700..e2208f6891 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3185,12 +3185,14 @@ # # @snapshot-access: Since 7.0 # +# @gluks: Since 9.0 +# # Since: 2.9 ## { 'enum': 'BlockdevDriver', 'data': [ 'blkdebug', 'blklogwrites', 'blkreplay', 'blkverify', 'bochs', 'cloop', 'compress', 'copy-before-write', 'copy-on-read', 'dmg= ', - 'file', 'snapshot-access', 'ftp', 'ftps', 'gluster', + 'file', 'snapshot-access', 'ftp', 'ftps', 'gluks', 'gluster', {'name': 'host_cdrom', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, {'name': 'host_device', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, 'http', 'https', @@ -3957,6 +3959,23 @@ '*debug': 'int', '*logfile': 'str' } } =20 +## +# @BlockdevOptionsGLUKS: +# +# Driver specific block device options for GLUKS. +# +# @header: reference to the definition of the luks header node. +# +# @key-secret: the ID of a QCryptoSecret object providing the +# decryption key. +# +# Since: 9.0 +## +{ 'struct': 'BlockdevOptionsGLUKS', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { 'header': 'BlockdevRef', + 'key-secret': 'str' } } + ## # @BlockdevOptionsIoUring: # @@ -4680,6 +4699,7 @@ 'file': 'BlockdevOptionsFile', 'ftp': 'BlockdevOptionsCurlFtp', 'ftps': 'BlockdevOptionsCurlFtps', + 'gluks': 'BlockdevOptionsGLUKS', 'gluster': 'BlockdevOptionsGluster', 'host_cdrom': { 'type': 'BlockdevOptionsFile', 'if': 'HAVE_HOST_BLOCK_DEVICE' }, diff --git a/qapi/crypto.json b/qapi/crypto.json index fd3d46ebd1..9afb242b5b 100644 --- a/qapi/crypto.json +++ b/qapi/crypto.json @@ -154,11 +154,13 @@ # # @luks: LUKS encryption format. Recommended for new images # +# @gluks: generic LUKS encryption format. (since 9.0) +# # Since: 2.6 ## { 'enum': 'QCryptoBlockFormat', # 'prefix': 'QCRYPTO_BLOCK_FORMAT', - 'data': ['qcow', 'luks']} + 'data': ['qcow', 'luks', 'gluks']} =20 ## # @QCryptoBlockOptionsBase: @@ -246,7 +248,8 @@ 'base': 'QCryptoBlockOptionsBase', 'discriminator': 'format', 'data': { 'qcow': 'QCryptoBlockOptionsQCow', - 'luks': 'QCryptoBlockOptionsLUKS' } } + 'luks': 'QCryptoBlockOptionsLUKS', + 'gluks': 'QCryptoBlockOptionsLUKS' } } =20 ## # @QCryptoBlockCreateOptions: @@ -260,7 +263,8 @@ 'base': 'QCryptoBlockOptionsBase', 'discriminator': 'format', 'data': { 'qcow': 'QCryptoBlockOptionsQCow', - 'luks': 'QCryptoBlockCreateOptionsLUKS' } } + 'luks': 'QCryptoBlockCreateOptionsLUKS', + 'gluks': 'QCryptoBlockCreateOptionsLUKS' } } =20 ## # @QCryptoBlockInfoBase: --=20 2.39.1 From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706248; cv=none; d=zohomail.com; s=zohoarc; b=dattNB7Pqh+WxdBv5oEiEvvQtoVQraiPlOhAr5yFsCNtwSL+hR0pyjotLbc4jqWhtVowKuJ2zcMkZ4w2wqmPVhKGiaOAFH6uHQQ+f1gd/78/YWiOormK/Ym7LGWiIOWmhNF2rWG0KmWiY5u6HPDqV9XHQz1K0p9J/ojAybl/BA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706248; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dBpAjTXt7ctAaHcqbiNioxefPHK0eHAWmtGb+772ldc=; b=OYChnzVleHVjDYC5kqLxUAHN+8EEgKs2cObTT7O53ctaBsEkDDGH3BIHam8lFFn+bH1CJNvh9F7xdDyB+B3tNh5kgxZ3r2qipxoHS646c80c1rgw5k2U8mXGaWKvQCNTc4sLAhlGCivMdqhoScdOtNMk5LBNU5vO42GcG0PlQIg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706248564241.95564625391023; Mon, 4 Dec 2023 08:10:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABVL-0006sq-HQ; Mon, 04 Dec 2023 11:09:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABVK-0006sX-F6 for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:06 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABVH-0005Ij-S6 for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:06 -0500 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6cb74a527ceso3263592b3a.2 for ; Mon, 04 Dec 2023 08:07:03 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:07:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706022; x=1702310822; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dBpAjTXt7ctAaHcqbiNioxefPHK0eHAWmtGb+772ldc=; b=cwDshzxW/ZakmLRNGti5JYkx5n/VKc92H1PT6wmX77iLynEIgyxmIT5Pb+Cxw86jDW a89+hqbB2qYPJ+lZgsCDluXqW4goe+Q1HBbGaeICEDEXmEQgqzsx1p0i6Lf4r8BBZ+xz gzOSQGuqG8XcPwHa4g+uxUa/BYga4mnhIsFBt28wW01CjS5CQBGiGBwOe1uBgTQ3JNsf XI+n+FeqCLbK+Bqtp+BXd9SCQan9HQaBtww85F34SK3CV3vfwIXJ3yeZeCQA8qXfebGy SpOTPY6mxdeSfIHWtqtJWBE65av42PHqJq3fDDuQuD21tGrhhvFu4O9REsrOgxgSCpVK vHrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706022; x=1702310822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dBpAjTXt7ctAaHcqbiNioxefPHK0eHAWmtGb+772ldc=; b=lYimtJAv90sZou0jtY18qcyA76q59pWD2rAWWVjYbBNARKkAGbo2hRnybEOeSJsaZr B0PACK44bBg8J2RFRQT21wyoHPyeLXnF3zagucneVO1H35/enTx9uXFst1YXJVq6bty6 1eYS62zeqfKA/v7ABlu3DD8bB9vqLL3Wi6tnTZ5xfPB/EUBiXjNdW3jShZohh8Gsas66 JMZkBdQA3cfMSG/Xex1Iy4iFYAS+wpW7l2Uy7ePOeUvaF2ZvELYQolBGC+ZTweEJdkZV J/kcbiirvhyGDwon9YG6JUAmZO1nJiT76sSA0xIYaNZBSj6M/KnSupcupZIhqPiYvMql NMBg== X-Gm-Message-State: AOJu0YxCaHxSPeXGZiMbW6B7vSMogyRqsC8Cyy64VjZZxQQgGQi2z4QX 6MIzOh2rHAZ0FSAZiIcF6onXORn+hCD7UjeL7FulLuCq X-Google-Smtp-Source: AGHT+IF/iF39mUbJyVW230AwrwMvDurk5qEhqfiEn6sYlLr8Gfn5PjzFt90U7IRxokhohLAZTq1koQ== X-Received: by 2002:aa7:8893:0:b0:6ce:7d6:c317 with SMTP id z19-20020aa78893000000b006ce07d6c317mr4757527pfe.15.1701706021959; Mon, 04 Dec 2023 08:07:01 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 6/8] crypto: Provide the Luks crypto driver to Gluks Date: Tue, 5 Dec 2023 00:06:23 +0800 Message-Id: <4ff114944abe5e1d90933e715ee245cea5d619fd.1701705003.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::42d; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706250238100003 Content-Type: text/plain; charset="utf-8" Hooks up the Luks crypto driver for Gluks. Signed-off-by: Hyman Huang --- crypto/block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/crypto/block.c b/crypto/block.c index 3dcf22a69f..7e695c0a04 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -27,6 +27,7 @@ static const QCryptoBlockDriver *qcrypto_block_drivers[] =3D { [Q_CRYPTO_BLOCK_FORMAT_QCOW] =3D &qcrypto_block_driver_qcow, [Q_CRYPTO_BLOCK_FORMAT_LUKS] =3D &qcrypto_block_driver_luks, + [Q_CRYPTO_BLOCK_FORMAT_GLUKS] =3D &qcrypto_block_driver_luks, }; =20 =20 --=20 2.39.1 From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706245; cv=none; d=zohomail.com; s=zohoarc; b=NH7eHp0L2Z2+7pO/wV/gwfJr37dd2TGXkURc/1CUnJtGoluaDDZYf69M9+iap4Hc7qtE8JJwbao2bhexOulV3Gn+lCB9IYtNLdy5EVkoCokMjdoHGgXHbWbGL2dMTw8DkS2bD2S/ejsTVI/TYCZmJls/c7KYStlVz+wluZmZaLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706245; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=curXvDp0ioN47tzvE2UhnUysHr4g1/8N1rFgo2OTs0o=; b=QoN+W3TH6UTqzaJaEX3h3CEVuhIY+l9yqJTp20MJFSgjQp2n3AGh+SxMTLtGvp44iYyRDdF8As6Wt8sBb2PxHy4W0ScwhFdq6CbTmoJDJgnyXaA1j7l4Kj4bOm4GKxZVhxMa2Mm1zbGj/Mj35KqTt6uzlp28oybQxEkj+/UGxBs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706245176752.421351795851; Mon, 4 Dec 2023 08:10:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABVP-0006uA-3o; Mon, 04 Dec 2023 11:09:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABVN-0006tj-E3 for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:09 -0500 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABVL-0005JB-JT for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:09 -0500 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6ce3534bf44so1281469b3a.1 for ; Mon, 04 Dec 2023 08:07:07 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706026; x=1702310826; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=curXvDp0ioN47tzvE2UhnUysHr4g1/8N1rFgo2OTs0o=; b=nZVR3CrGUjiZHaArqr/Un5P9d0LejVZJanFS3zsA0Qox6gTcOad5UVG2R1LUj3dEvj wQZFDkMPo2VCYH6ANULh097lT5okIJfi7vCFkrI95wDA0IttX8uKqzW2bQg0zGM0iXl+ 92dqEBkfl1kswHWb1kymu7QVqQTLS1JoKjQ6rMqCozeyj/vunc3wIH5v7Y5+iwD/CQR+ BXlPcv/yUnmikKkIFX55jAex6fE6Ph1dlDTRl48vyTqF5IGygFBqNmYwSOng9y5ZFuJ6 KW7zo5GbnTFALzr9xAu1FEIRW2ySw+HVkJFALaldUF8ixZ34x03dKSXLkkd/CnblNp0v VtBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706026; x=1702310826; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=curXvDp0ioN47tzvE2UhnUysHr4g1/8N1rFgo2OTs0o=; b=TPkSiJ8W/Gd3rc60dVlycr2mkObuu0kWt/m6fA29jtX1Z7qoU9KyYUpU/Zy1DTA3yg a5HLMsts8FXo4f5tlfQpz2ik45UkAJ2FjkVayD069DTm3P4Bc8MgbXuDhzlAUVmmGLig FHZZvLlVdCSbo8EI6LwZlcqDpd7b7eoZLLsPSu8Q3pdvQyHReAE0xuoDv7/t5jMutm3d +SPWDvThVoELN7ezXqHV5SMkMRj+AjKijv3EKkZklsm+ktwkESmSTas702WFx/ndDnD4 tM4aDmK6QE/P/o65oRWqTiuUAfbSv78lznn908/mcVK/etq8uwlEnuz2fosHv9HAFBFU h/Jg== X-Gm-Message-State: AOJu0YzjooYLhmr60AhnEOknObIB0wCI0nI6tTdSCY9OWSfnNZeBLXuv x7PaM63td2WkxwXmdM2ZJhGEnKN+e22YWxuKVbeXFUly X-Google-Smtp-Source: AGHT+IGt4SNvnbcsvJibYv0gG/z0Pbgh7veSbdcdt4YsJ5Yapgp4n0b3xKIKzyTEEks9cfTC2n0eBA== X-Received: by 2002:a05:6a20:3ca6:b0:18b:e5e6:576c with SMTP id b38-20020a056a203ca600b0018be5e6576cmr5046995pzj.3.1701706025666; Mon, 04 Dec 2023 08:07:05 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 7/8] Gluks: Implement the fundamental block layer driver hooks Date: Tue, 5 Dec 2023 00:06:24 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::432; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706246153100007 Content-Type: text/plain; charset="utf-8" Signed-off-by: Hyman Huang --- block/generic-luks.c | 104 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/block/generic-luks.c b/block/generic-luks.c index ebc0365d40..32cbedc86f 100644 --- a/block/generic-luks.c +++ b/block/generic-luks.c @@ -23,8 +23,14 @@ #include "qemu/osdep.h" =20 #include "block/block_int.h" +#include "block/block-io.h" #include "block/crypto.h" +#include "block/qdict.h" #include "crypto/block.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "qemu/option.h" =20 #include "generic-luks.h" =20 @@ -50,10 +56,89 @@ static QemuOptsList gluks_create_opts_luks =3D { }, }; =20 +static int gluks_read_func(QCryptoBlock *block, + size_t offset, + uint8_t *buf, + size_t buflen, + void *opaque, + Error **errp) +{ + + BlockDriverState *bs =3D opaque; + BDRVGLUKSState *s =3D bs->opaque; + ssize_t ret; + + GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + + ret =3D bdrv_pread(s->header, offset, buflen, buf, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not read generic luks header"); + return ret; + } + return 0; +} + static int gluks_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { - return 0; + BDRVGLUKSState *s =3D bs->opaque; + QemuOpts *opts =3D NULL; + QCryptoBlockOpenOptions *open_opts =3D NULL; + QDict *cryptoopts =3D NULL; + unsigned int cflags =3D 0; + int ret; + + GLOBAL_STATE_CODE(); + + if (!bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + (BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY), false, er= rp)) { + return -EINVAL; + } + s->header =3D bdrv_open_child(NULL, options, "header", bs, + &child_of_bds, BDRV_CHILD_METADATA, false, + errp); + if (!s->header) { + return -EINVAL; + } + + GRAPH_RDLOCK_GUARD_MAINLOOP(); + + opts =3D qemu_opts_create(&block_crypto_runtime_opts_luks, + NULL, 0, &error_abort); + if (!qemu_opts_absorb_qdict(opts, options, errp)) { + ret =3D -EINVAL; + goto cleanup; + } + + cryptoopts =3D qemu_opts_to_qdict(opts, NULL); + qdict_put_str(cryptoopts, "format", + QCryptoBlockFormat_str(Q_CRYPTO_BLOCK_FORMAT_GLUKS)); + + open_opts =3D block_crypto_open_opts_init(cryptoopts, errp); + if (!open_opts) { + goto cleanup; + } + + s->crypto.block =3D qcrypto_block_open(open_opts, NULL, + gluks_read_func, + bs, + cflags, + 1, + errp); + if (!s->crypto.block) { + ret =3D -EIO; + goto cleanup; + } + + s->header_size =3D qcrypto_block_get_payload_offset(s->crypto.block); + qcrypto_block_set_payload_offset(s->crypto.block, 0); + + ret =3D 0; + cleanup: + qobject_unref(cryptoopts); + qapi_free_QCryptoBlockOpenOptions(open_opts); + return ret; } =20 static int coroutine_fn GRAPH_UNLOCKED @@ -70,13 +155,24 @@ gluks_child_perms(BlockDriverState *bs, BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { + if (role & BDRV_CHILD_METADATA) { + /* assign read permission only */ + perm |=3D BLK_PERM_CONSISTENT_READ; + /* share all permissions */ + shared |=3D BLK_PERM_ALL; =20 + *nperm =3D perm; + *nshared =3D shared; + return; + } + + bdrv_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nsh= ared); } =20 static int64_t coroutine_fn GRAPH_RDLOCK gluks_co_getlength(BlockDriverState *bs) { - return 0; + return bdrv_co_getlength(bs->file->bs); } =20 static BlockDriver bdrv_generic_luks =3D { @@ -87,8 +183,12 @@ static BlockDriver bdrv_generic_luks =3D { .bdrv_child_perm =3D gluks_child_perms, .bdrv_co_getlength =3D gluks_co_getlength, =20 + .bdrv_close =3D block_crypto_close, + .bdrv_co_preadv =3D block_crypto_co_preadv, + .bdrv_co_pwritev =3D block_crypto_co_pwritev, .create_opts =3D &gluks_create_opts_luks, .amend_opts =3D &block_crypto_amend_opts_luks, + .is_format =3D false, }; =20 static void block_generic_luks_init(void) --=20 2.39.1 From nobody Wed Nov 27 02:34:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1701706181; cv=none; d=zohomail.com; s=zohoarc; b=Wc3tf+8+w6CXS+i19q1X66skHakl9pW3zwaJA3TXIsqkuteJIKh5OcefZY91h32NCmvn3MapDlR7ezQSL/m3Sn+9b9nkurX0jyq7YYMuV9toES7rMD52XUj9l4gJogVmLrIuC6iJRmWJUOPnbMcsbaV4qwJlD7EDyv+RLP2J8gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701706181; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K308th+gf/50+1Zu21hN3IC2Z/G4dmfKfM5g4fUEH6c=; b=j79/77Z0m19smajYOLqBlAsX0ybzPtcr2ecuvONjVuCbQChON0b5/Yt+XY63rHxl3nGaikR8RRc7GrsFOpVkLzybyFo0cLRB/w71KvtcrJfpr2pYtQabahGfjbpVk/ZSLU6M2cnfkr6xNs040JZi4Y7tD2AT1E4XD5Km5gY3Kl0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701706181781626.01703207062; Mon, 4 Dec 2023 08:09:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rABVh-0007AI-Rx; Mon, 04 Dec 2023 11:09:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rABVg-00071D-2N for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:28 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rABVV-0005Ji-KH for qemu-devel@nongnu.org; Mon, 04 Dec 2023 11:09:27 -0500 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6ce3935ffedso1943381b3a.1 for ; Mon, 04 Dec 2023 08:07:15 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m17-20020aa78a11000000b006be4bb0d2dcsm7993064pfa.149.2023.12.04.08.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 08:07:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701706034; x=1702310834; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K308th+gf/50+1Zu21hN3IC2Z/G4dmfKfM5g4fUEH6c=; b=vvEFX9KJEGQa9NSLLNW4h/OV7ImLt1XKllk/WjgmltHt06SgfSr9HgojXxYxTM6hee fzl31Qqa6SONgF/dC0IB/eqlc0RhQt+JqR2WePlL8dnuhAPEibQcN2E4Hfps2cKnSzZx 7sPmtbIjwjilw6KS+EuAAthLtuASEj/rNNJo19sjCjNqflxwnSIfP/WnV6P0xvTr4cj9 SzgZM2ZbYQfvwAaHu2P8cLX646682laEiGRipSAFBISCjhGJFKrDcedh4pt/GMXZCmuk u/+ocFAeo3/ry7D4Qv5yy7Z/kRDSvUz1+2pHDtsX7AEGInjEQxS2yIRGn1B5XV+d0Zbl HF4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701706034; x=1702310834; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=K308th+gf/50+1Zu21hN3IC2Z/G4dmfKfM5g4fUEH6c=; b=sqVqdr0GUvkvDAQwM+whTAYRgScAYPcH50FMqxNJUNR9F64xX+RKwiQIZadTSsqZs7 aTXts9ynhxao4piR65wMugxS0hSwPl4akRsVDMOB44xtQm/1EjCuONjZvgC5Gc40OjNv 0vOMLRfUWdzo/CKxv8PI7zwpHt70akdj8h/+1AVsSTE4Pf61vmMoW/0uKntdmckZEz0a c6dBkUomS8hk7t4xNK6m9vY9VqHYJwTEuMQLTwszqJuhqvdLerCupuVeJHTwAZBywkZM /fohLTZXr/VCO7G90R2zIptc8JGmNYgs9uar4XYZRCwSgQ5xUKRPvsK3HBwo8TW6TErC CSig== X-Gm-Message-State: AOJu0YyK5Uk27Az+Wu6gIvV/k9mwq5lVE+UemjrO7gPeMVYiBKhGK9iH ArlRbgV5DkabFiEZ2crX8b8z2wMAWjGoi2AyP1ihMsF2 X-Google-Smtp-Source: AGHT+IFuoohNsIWLnbNkgzKWJKAg/syTxau9+Dpd5ZaHRmTXmnNWtVP3nlwNodGZVYm/qWmfExajsg== X-Received: by 2002:a05:6a20:daa4:b0:18b:8475:410a with SMTP id iy36-20020a056a20daa400b0018b8475410amr5663958pzb.7.1701706033888; Mon, 04 Dec 2023 08:07:13 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [RFC 8/8] block: Support Gluks format image creation using qemu-img Date: Tue, 5 Dec 2023 00:06:25 +0800 Message-Id: <609e4a2182edc0e0ab3e5942de7dd0e9f16602e6.1701705003.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::42e; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1701706183039100001 Content-Type: text/plain; charset="utf-8" To create a Gluks header image, use the command as follows: $ qemu-img create --object secret,id=3Dsec0,data=3Dabc123 -f gluks > -o cipher-alg=3Daes-256,cipher-mode=3Dxts -o key-secret=3Dsec0 > cipher.gluks Signed-off-by: Hyman Huang --- block.c | 5 +++++ block/generic-luks.c | 53 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index bfb0861ec6..cc9a517a25 100644 --- a/block.c +++ b/block.c @@ -7517,6 +7517,11 @@ void bdrv_img_create(const char *filename, const cha= r *fmt, goto out; } =20 + if (!strcmp(fmt, "gluks")) { + qemu_opt_set(opts, "size", "0M", &local_err); + size =3D 0; + } + if (size =3D=3D -1) { error_setg(errp, "Image creation needs a size parameter"); goto out; diff --git a/block/generic-luks.c b/block/generic-luks.c index 32cbedc86f..579f01c4b0 100644 --- a/block/generic-luks.c +++ b/block/generic-luks.c @@ -145,7 +145,58 @@ static int coroutine_fn GRAPH_UNLOCKED gluks_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opts, Error **errp) { - return 0; + QCryptoBlockCreateOptions *create_opts =3D NULL; + BlockDriverState *bs =3D NULL; + QDict *cryptoopts; + int ret; + + if (qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) !=3D 0) { + info_report("gluks format image need not size parameter, ignore it= "); + } + + cryptoopts =3D qemu_opts_to_qdict_filtered(opts, NULL, + &gluks_create_opts_luks, + true); + + qdict_put_str(cryptoopts, "format", + QCryptoBlockFormat_str(Q_CRYPTO_BLOCK_FORMAT_GLUKS)); + + create_opts =3D block_crypto_create_opts_init(cryptoopts, errp); + if (!create_opts) { + ret =3D -EINVAL; + goto fail; + } + + /* Create protocol layer */ + ret =3D bdrv_co_create_file(filename, opts, errp); + if (ret < 0) { + goto fail; + } + + bs =3D bdrv_co_open(filename, NULL, NULL, + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp); + if (!bs) { + ret =3D -EINVAL; + goto fail; + } + /* Create format layer */ + ret =3D block_crypto_co_create_generic(bs, 0, create_opts, 0, errp); + if (ret < 0) { + goto fail; + } + + ret =3D 0; +fail: + /* + * If an error occurred, delete 'filename'. Even if the file existed + * beforehand, it has been truncated and corrupted in the process. + */ + if (ret) { + bdrv_graph_co_rdlock(); + bdrv_co_delete_file_noerr(bs); + bdrv_graph_co_rdunlock(); + } + return ret; } =20 static void --=20 2.39.1