From patchwork Mon Dec 4 16:06:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478731 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 D9F41C10DCE for ; Mon, 4 Dec 2023 16:10:44 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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" -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, } -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); } -static void block_crypto_close(BlockDriverState *bs) +void block_crypto_close(BlockDriverState *bs) { BlockCrypto *crypto = 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) -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 offset, int64_t bytes, } -static int coroutine_fn GRAPH_RDLOCK +int coroutine_fn GRAPH_RDLOCK block_crypto_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, 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 +#include "crypto/block.h" + #define BLOCK_CRYPTO_OPT_DEF_KEY_SECRET(prefix, helpstr) \ { \ .name = 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); +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 bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); + +void block_crypto_close(BlockDriverState *bs); #endif /* BLOCK_CRYPTO_H */ From patchwork Mon Dec 4 16:06:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478728 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 85CBFC4167B for ; Mon, 4 Dec 2023 16:09:51 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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(QCryptoBlock *block) return block->kdfhash; } +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset) +{ + block->payload_offset = offset; +} 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); G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free) +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset); #endif /* QCRYPTO_BLOCK_H */ From patchwork Mon Dec 4 16:06:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478730 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 F41B4C4167B for ; Mon, 4 Dec 2023 16:10:43 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 = { + .format_name = "gluks", + .instance_size = sizeof(BDRVGLUKSState), + .bdrv_open = gluks_open, + .bdrv_co_create_opts = gluks_co_create_opts, + .bdrv_child_perm = gluks_child_perms, + .bdrv_co_getlength = 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) system_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c')) From patchwork Mon Dec 4 16:06:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478725 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 88D02C10DCE for ; Mon, 4 Dec 2023 16:09:32 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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: } -static QemuOptsList block_crypto_runtime_opts_luks = { +QemuOptsList block_crypto_runtime_opts_luks = { .name = "crypto", .head = QTAILQ_HEAD_INITIALIZER(block_crypto_runtime_opts_luks.head), .desc = { @@ -181,7 +181,7 @@ static QemuOptsList block_crypto_create_opts_luks = { }; -static QemuOptsList block_crypto_amend_opts_luks = { +QemuOptsList block_crypto_amend_opts_luks = { .name = "crypto", .head = QTAILQ_HEAD_INITIALIZER(block_crypto_create_opts_luks.head), .desc = { 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; +static QemuOptsList gluks_create_opts_luks = { + .name = "crypto", + .head = QTAILQ_HEAD_INITIALIZER(gluks_create_opts_luks.head), + .desc = { + 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 = { .bdrv_co_create_opts = gluks_co_create_opts, .bdrv_child_perm = gluks_child_perms, .bdrv_co_getlength = gluks_co_getlength, + + .create_opts = &gluks_create_opts_luks, + .amend_opts = &block_crypto_amend_opts_luks, }; 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 +extern QemuOptsList block_crypto_runtime_opts_luks; +extern QemuOptsList block_crypto_amend_opts_luks; + #endif /* GENERIC_LUKS_H */ From patchwork Mon Dec 4 16:06:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478729 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 8079CC4167B for ; Mon, 4 Dec 2023 16:09:55 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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' } } +## +# @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']} ## # @QCryptoBlockOptionsBase: @@ -246,7 +248,8 @@ 'base': 'QCryptoBlockOptionsBase', 'discriminator': 'format', 'data': { 'qcow': 'QCryptoBlockOptionsQCow', - 'luks': 'QCryptoBlockOptionsLUKS' } } + 'luks': 'QCryptoBlockOptionsLUKS', + 'gluks': 'QCryptoBlockOptionsLUKS' } } ## # @QCryptoBlockCreateOptions: @@ -260,7 +263,8 @@ 'base': 'QCryptoBlockOptionsBase', 'discriminator': 'format', 'data': { 'qcow': 'QCryptoBlockOptionsQCow', - 'luks': 'QCryptoBlockCreateOptionsLUKS' } } + 'luks': 'QCryptoBlockCreateOptionsLUKS', + 'gluks': 'QCryptoBlockCreateOptionsLUKS' } } ## # @QCryptoBlockInfoBase: From patchwork Mon Dec 4 16:06:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478733 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 64ADFC4167B for ; Mon, 4 Dec 2023 16:10:48 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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[] = { [Q_CRYPTO_BLOCK_FORMAT_QCOW] = &qcrypto_block_driver_qcow, [Q_CRYPTO_BLOCK_FORMAT_LUKS] = &qcrypto_block_driver_luks, + [Q_CRYPTO_BLOCK_FORMAT_GLUKS] = &qcrypto_block_driver_luks, }; From patchwork Mon Dec 4 16:06:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478732 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 0486EC10DC1 for ; Mon, 4 Dec 2023 16:10:45 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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" #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" #include "generic-luks.h" @@ -50,10 +56,89 @@ static QemuOptsList gluks_create_opts_luks = { }, }; +static int gluks_read_func(QCryptoBlock *block, + size_t offset, + uint8_t *buf, + size_t buflen, + void *opaque, + Error **errp) +{ + + BlockDriverState *bs = opaque; + BDRVGLUKSState *s = bs->opaque; + ssize_t ret; + + GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + + ret = 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 = bs->opaque; + QemuOpts *opts = NULL; + QCryptoBlockOpenOptions *open_opts = NULL; + QDict *cryptoopts = NULL; + unsigned int cflags = 0; + int ret; + + GLOBAL_STATE_CODE(); + + if (!bdrv_open_child(NULL, options, "file", bs, &child_of_bds, + (BDRV_CHILD_DATA | BDRV_CHILD_PRIMARY), false, errp)) { + return -EINVAL; + } + s->header = 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 = qemu_opts_create(&block_crypto_runtime_opts_luks, + NULL, 0, &error_abort); + if (!qemu_opts_absorb_qdict(opts, options, errp)) { + ret = -EINVAL; + goto cleanup; + } + + cryptoopts = qemu_opts_to_qdict(opts, NULL); + qdict_put_str(cryptoopts, "format", + QCryptoBlockFormat_str(Q_CRYPTO_BLOCK_FORMAT_GLUKS)); + + open_opts = block_crypto_open_opts_init(cryptoopts, errp); + if (!open_opts) { + goto cleanup; + } + + s->crypto.block = qcrypto_block_open(open_opts, NULL, + gluks_read_func, + bs, + cflags, + 1, + errp); + if (!s->crypto.block) { + ret = -EIO; + goto cleanup; + } + + s->header_size = qcrypto_block_get_payload_offset(s->crypto.block); + qcrypto_block_set_payload_offset(s->crypto.block, 0); + + ret = 0; + cleanup: + qobject_unref(cryptoopts); + qapi_free_QCryptoBlockOpenOptions(open_opts); + return ret; } 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 |= BLK_PERM_CONSISTENT_READ; + /* share all permissions */ + shared |= BLK_PERM_ALL; + *nperm = perm; + *nshared = shared; + return; + } + + bdrv_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nshared); } static int64_t coroutine_fn GRAPH_RDLOCK gluks_co_getlength(BlockDriverState *bs) { - return 0; + return bdrv_co_getlength(bs->file->bs); } static BlockDriver bdrv_generic_luks = { @@ -87,8 +183,12 @@ static BlockDriver bdrv_generic_luks = { .bdrv_child_perm = gluks_child_perms, .bdrv_co_getlength = gluks_co_getlength, + .bdrv_close = block_crypto_close, + .bdrv_co_preadv = block_crypto_co_preadv, + .bdrv_co_pwritev = block_crypto_co_pwritev, .create_opts = &gluks_create_opts_luks, .amend_opts = &block_crypto_amend_opts_luks, + .is_format = false, }; static void block_generic_luks_init(void) From patchwork Mon Dec 4 16:06:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13478727 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 A390AC4167B for ; Mon, 4 Dec 2023 16:09:41 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org To create a Gluks header image, use the command as follows: $ qemu-img create --object secret,id=sec0,data=abc123 -f gluks > -o cipher-alg=aes-256,cipher-mode=xts -o key-secret=sec0 > 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 char *fmt, goto out; } + if (!strcmp(fmt, "gluks")) { + qemu_opt_set(opts, "size", "0M", &local_err); + size = 0; + } + if (size == -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 = NULL; + BlockDriverState *bs = NULL; + QDict *cryptoopts; + int ret; + + if (qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) != 0) { + info_report("gluks format image need not size parameter, ignore it"); + } + + cryptoopts = 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 = block_crypto_create_opts_init(cryptoopts, errp); + if (!create_opts) { + ret = -EINVAL; + goto fail; + } + + /* Create protocol layer */ + ret = bdrv_co_create_file(filename, opts, errp); + if (ret < 0) { + goto fail; + } + + bs = bdrv_co_open(filename, NULL, NULL, + BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_PROTOCOL, errp); + if (!bs) { + ret = -EINVAL; + goto fail; + } + /* Create format layer */ + ret = block_crypto_co_create_generic(bs, 0, create_opts, 0, errp); + if (ret < 0) { + goto fail; + } + + ret = 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; } static void