From patchwork Sun Jan 29 02:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120013 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 64421C38142 for ; Sun, 29 Jan 2023 02:59:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxtL-0003iq-I4; Sat, 28 Jan 2023 21:58:03 -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 1pLxtJ-0003ig-Lt for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:01 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtH-00085t-Ex for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:01 -0500 Received: by mail-pl1-x629.google.com with SMTP id z1so965145plg.6 for ; Sat, 28 Jan 2023 18:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=mqHnOSJ5W/7E5DBhJlQGNbCTMOc7nC4cZmZrNCu08Lk=; b=JvSZO7GKwf3ZtqnGFMnMGQqfi6661Yp1HoS44d3nhcB8SA6isY679YWqPDD+zUXJe1 SrOfUiKQouky9rSnVRIPBkbjc2c8QMeG3DvKVcLJvdb+7CplItLxVVVb6EWwbK7sQk2i QgBEktNTPWoBD4x9bOfowXnHewlEyEQL8GqpIYMoZ27X+6u1b+BJFN7C9xBQbe8V0Xq5 prEi+yf6lg4MHfZCrW8KnS2D9D3ZVoN2PcqU0gz+1sa5wlDuSdV+/NE/ftrPx5L0n9bc +jFeAnGx/6DJBwZOxzOdO4e5tmr7jApV6w+YQ+ry11wNRpB53bu59l+fGUz92itXye1h TRvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=mqHnOSJ5W/7E5DBhJlQGNbCTMOc7nC4cZmZrNCu08Lk=; b=rypTaKRKIfr3vqbZuF4RbK9se4giFrzCH+PAEGei2zqWgAdNe3AnxusJVG0miFHDsE qRsaJBzjdS59UTd14fIWDRnpoOyxItv42payBqhLrGPgaELwIUJ8HqC4ax9M75h5rMz3 qQ4oGYedkQk+EMVvfePKPrqDtls4f801cBhmDVzKeLKF/WIA/G7RSrzUo2o3t9WsetDk YMP0ZVMGZhtAgScHpJ5t5jKbZYUglSUoJs3PpWP1SWUzwJU7HmAxIRcwoZmqd9Jvm6uQ KaSfQFlEEKVU4l4f6ggIdbsnbqnLJF+5Uyf99apnYvlNESYTpojHLIQKfwQfaZ/LPPXJ vBGg== X-Gm-Message-State: AO0yUKX+ozocNjtqpySRcyncqSmYmKUa5wEU1nn0nhrb+HHHxXxAnEfG d4DxObBDbRzZ8hISYgz7pDdUGw== X-Google-Smtp-Source: AK7set/O+xOFcH6d97G0b6YreklylfLGdXB9Ol/pbpIGqytBp8nAz7/Rhm3bXpnEY5mio5nolAWVLw== X-Received: by 2002:a17:903:210b:b0:193:6520:739a with SMTP id o11-20020a170903210b00b001936520739amr2899072ple.46.1674961078217; Sat, 28 Jan 2023 18:57:58 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:57:57 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 01/12] cryptodev: Introduce cryptodev.json Date: Sun, 29 Jan 2023 10:57:36 +0800 Message-Id: <20230129025747.682282-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x629.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_PASS=-0.001 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 Introduce QCryptodevBackendType in cryptodev.json, also apply this to related codes. Then we can drop 'enum CryptoDevBackendOptionsType'. Note that `CRYPTODEV_BACKEND_TYPE_NONE` is *NOT* used by anywhere, so drop it(no 'none' enum in QCryptodevBackendType). Reviewed-by: Daniel P. Berrangé Signed-off-by: zhenwei pi --- MAINTAINERS | 1 + backends/cryptodev-builtin.c | 2 +- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 4 ++-- backends/cryptodev-vhost.c | 4 ++-- include/sysemu/cryptodev.h | 11 ++--------- qapi/cryptodev.json | 20 ++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 9 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 qapi/cryptodev.json diff --git a/MAINTAINERS b/MAINTAINERS index c581c11a64..9f6c54b145 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2860,6 +2860,7 @@ M: Gonglei S: Maintained F: include/sysemu/cryptodev*.h F: backends/cryptodev*.c +F: qapi/cryptodev.json Python library M: John Snow diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index cda6ca3b71..8c7c10847d 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -76,7 +76,7 @@ static void cryptodev_builtin_init( "cryptodev-builtin", NULL); cc->info_str = g_strdup_printf("cryptodev-builtin0"); cc->queue_index = 0; - cc->type = CRYPTODEV_BACKEND_TYPE_BUILTIN; + cc->type = QCRYPTODEV_BACKEND_TYPE_BUILTIN; backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 133bd706a4..91e02c0df9 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -226,7 +226,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp) cc = cryptodev_backend_new_client("cryptodev-lkcf", NULL); cc->info_str = g_strdup_printf("cryptodev-lkcf0"); cc->queue_index = 0; - cc->type = CRYPTODEV_BACKEND_TYPE_LKCF; + cc->type = QCRYPTODEV_BACKEND_TYPE_LKCF; backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c index ab3028e045..c165a1b1d6 100644 --- a/backends/cryptodev-vhost-user.c +++ b/backends/cryptodev-vhost-user.c @@ -67,7 +67,7 @@ cryptodev_vhost_user_get_vhost( { CryptoDevBackendVhostUser *s = CRYPTODEV_BACKEND_VHOST_USER(b); - assert(cc->type == CRYPTODEV_BACKEND_TYPE_VHOST_USER); + assert(cc->type == QCRYPTODEV_BACKEND_TYPE_VHOST_USER); assert(queue < MAX_CRYPTO_QUEUE_NUM); return s->vhost_crypto[queue]; @@ -203,7 +203,7 @@ static void cryptodev_vhost_user_init( cc->info_str = g_strdup_printf("cryptodev-vhost-user%zu to %s ", i, chr->label); cc->queue_index = i; - cc->type = CRYPTODEV_BACKEND_TYPE_VHOST_USER; + cc->type = QCRYPTODEV_BACKEND_TYPE_VHOST_USER; backend->conf.peers.ccs[i] = cc; diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 572f87b3be..a2b5a2cb3b 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -128,7 +128,7 @@ cryptodev_get_vhost(CryptoDevBackendClient *cc, switch (cc->type) { #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) - case CRYPTODEV_BACKEND_TYPE_VHOST_USER: + case QCRYPTODEV_BACKEND_TYPE_VHOST_USER: vhost_crypto = cryptodev_vhost_user_get_vhost(cc, b, queue); break; #endif @@ -196,7 +196,7 @@ int cryptodev_vhost_start(VirtIODevice *dev, int total_queues) * because vhost user doesn't interrupt masking/unmasking * properly. */ - if (cc->type == CRYPTODEV_BACKEND_TYPE_VHOST_USER) { + if (cc->type == QCRYPTODEV_BACKEND_TYPE_VHOST_USER) { dev->use_guest_notifier_mask = false; } } diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index cf9b3f07fe..8d2adda974 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -25,6 +25,7 @@ #include "qemu/queue.h" #include "qom/object.h" +#include "qapi/qapi-types-cryptodev.h" /** * CryptoDevBackend: @@ -215,16 +216,8 @@ struct CryptoDevBackendClass { void *opaque); }; -typedef enum CryptoDevBackendOptionsType { - CRYPTODEV_BACKEND_TYPE_NONE = 0, - CRYPTODEV_BACKEND_TYPE_BUILTIN = 1, - CRYPTODEV_BACKEND_TYPE_VHOST_USER = 2, - CRYPTODEV_BACKEND_TYPE_LKCF = 3, - CRYPTODEV_BACKEND_TYPE__MAX, -} CryptoDevBackendOptionsType; - struct CryptoDevBackendClient { - CryptoDevBackendOptionsType type; + QCryptodevBackendType type; char *model; char *name; char *info_str; diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json new file mode 100644 index 0000000000..b65edbe183 --- /dev/null +++ b/qapi/cryptodev.json @@ -0,0 +1,20 @@ +# -*- Mode: Python -*- +# vim: filetype=python +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. + +## +# @QCryptodevBackendType: +# +# The crypto device backend type +# +# @builtin: the QEMU builtin support +# @vhost-user: vhost-user +# @lkcf: Linux kernel cryptographic framework +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendType', + 'prefix': 'QCRYPTODEV_BACKEND_TYPE', + 'data': ['builtin', 'vhost-user', 'lkcf']} diff --git a/qapi/meson.build b/qapi/meson.build index fbdb442fdf..1c37ae7491 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -56,6 +56,7 @@ if have_system qapi_all_modules += [ 'acpi', 'audio', + 'cryptodev', 'qdev', 'pci', 'rdma', diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index f000b90744..1e923945db 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -95,3 +95,4 @@ { 'include': 'pci.json' } { 'include': 'stats.json' } { 'include': 'virtio.json' } +{ 'include': 'cryptodev.json' } From patchwork Sun Jan 29 02:57:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120016 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 80036C38142 for ; Sun, 29 Jan 2023 03:00:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxtO-0003jW-EE; Sat, 28 Jan 2023 21:58:06 -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 1pLxtM-0003j8-Od for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:04 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtK-00086F-UI for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:04 -0500 Received: by mail-pj1-x1032.google.com with SMTP id o13so8262457pjg.2 for ; Sat, 28 Jan 2023 18:58:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=QfbjQB/uupsbnVkLnKgXK2FfdvkN34GzFDspqyb2GhQ=; b=s4Qqh93NPCYKupNt9PTadZuUajpSKX1c9VN9U+wQEoall3rBVkOnpZZcevcA2aFLgS qgzvfpOKbeUKS2rs1/TlarDuh57VJbXgf+FZ0L4MJUYSlg52SANb5tP+lDU2cBXcE1As iRPtVQDeGvCx//Bf4Fayn3ScMhlg3xJWHGm1JK1D0awoQ4UZNembBMFS8XfTWzSRGc86 OrXOOMs+Zn1yYtvJYTLPT5mXk0YsYTOV1+pYodB3LLW4fMrI8oYQvZRNEnNPOlJ00wqR MMQBndMx8XrPZxfjJPSK06cFeONJygjy9XNceQLEDFDyIzwSvHiJu5Zh4sg1R+Sj29hL lTtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=QfbjQB/uupsbnVkLnKgXK2FfdvkN34GzFDspqyb2GhQ=; b=ySWRtk4Ipl03+UKz3GKhAdMyyEJyJ2cff3JRccdcsFkoXvw4RJG55ACgTL6s1/fawW C+17IuZOk+YesvbL1ekkBukN2oWXzoWJe/Ts+k4sldnui/T0w8+Kd2HqUaOGFTwK5dON wz0uujQK2hiurKbzvTwZCNp2xzJCyU8Sznud5htAMo6H8eVAHmS3qyxCbXE8544Dg5Of iA7KGd86kIrcSYAHf9TH/ULxoMQRgi1ftGNWAvb1QIEuy4NkPCT+ljKPTXNhgglBdHnL 7Ut8GJoIMRfRqHsi7bY130KD9C0breIXdc9oOnFE99IWuPrEzaR5hhOay0o2LaPJp892 17lw== X-Gm-Message-State: AFqh2kpT5G0s7fO2C3px/E926SDBzCsBJpCphkeacaP5HiUydfd7goKx auior47EZwX3iJGlqemzVIEWag== X-Google-Smtp-Source: AMrXdXtReVU8K5GoOzp73ElF0EuFMHHRY7itRPwx0tm8/LSKib39It43rRBkeCz/0DM2NNyKpx9UBw== X-Received: by 2002:a17:902:dad2:b0:194:6f0e:987 with SMTP id q18-20020a170902dad200b001946f0e0987mr63036969plx.61.1674961081654; Sat, 28 Jan 2023 18:58:01 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:01 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 02/12] cryptodev: Remove 'name' & 'model' fields Date: Sun, 29 Jan 2023 10:57:37 +0800 Message-Id: <20230129025747.682282-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1032.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_PASS=-0.001 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 We have already used qapi to generate crypto device types, this allows to convert type to a string 'model', so the 'model' field is not needed. And the 'name' field is not used by any backend driver, drop it. Reviewed-by: Daniel P. Berrangé Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 3 +-- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 3 +-- backends/cryptodev.c | 11 +---------- include/sysemu/cryptodev.h | 12 +++--------- 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 8c7c10847d..08895271eb 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -72,8 +72,7 @@ static void cryptodev_builtin_init( return; } - cc = cryptodev_backend_new_client( - "cryptodev-builtin", NULL); + cc = cryptodev_backend_new_client(); cc->info_str = g_strdup_printf("cryptodev-builtin0"); cc->queue_index = 0; cc->type = QCRYPTODEV_BACKEND_TYPE_BUILTIN; diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 91e02c0df9..de3d1867c5 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -223,7 +223,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp) return; } - cc = cryptodev_backend_new_client("cryptodev-lkcf", NULL); + cc = cryptodev_backend_new_client(); cc->info_str = g_strdup_printf("cryptodev-lkcf0"); cc->queue_index = 0; cc->type = QCRYPTODEV_BACKEND_TYPE_LKCF; diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c index c165a1b1d6..580bd1abb0 100644 --- a/backends/cryptodev-vhost-user.c +++ b/backends/cryptodev-vhost-user.c @@ -198,8 +198,7 @@ static void cryptodev_vhost_user_init( s->opened = true; for (i = 0; i < queues; i++) { - cc = cryptodev_backend_new_client( - "cryptodev-vhost-user", NULL); + cc = cryptodev_backend_new_client(); cc->info_str = g_strdup_printf("cryptodev-vhost-user%zu to %s ", i, chr->label); cc->queue_index = i; diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 54ee8c81f5..81941af816 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -34,18 +34,11 @@ static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; -CryptoDevBackendClient * -cryptodev_backend_new_client(const char *model, - const char *name) +CryptoDevBackendClient *cryptodev_backend_new_client(void) { CryptoDevBackendClient *cc; cc = g_new0(CryptoDevBackendClient, 1); - cc->model = g_strdup(model); - if (name) { - cc->name = g_strdup(name); - } - QTAILQ_INSERT_TAIL(&crypto_clients, cc, next); return cc; @@ -55,8 +48,6 @@ void cryptodev_backend_free_client( CryptoDevBackendClient *cc) { QTAILQ_REMOVE(&crypto_clients, cc, next); - g_free(cc->name); - g_free(cc->model); g_free(cc->info_str); g_free(cc); } diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 8d2adda974..af152d09db 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -218,8 +218,6 @@ struct CryptoDevBackendClass { struct CryptoDevBackendClient { QCryptodevBackendType type; - char *model; - char *name; char *info_str; unsigned int queue_index; int vring_enable; @@ -264,11 +262,8 @@ struct CryptoDevBackend { /** * cryptodev_backend_new_client: - * @model: the cryptodev backend model - * @name: the cryptodev backend name, can be NULL * - * Creates a new cryptodev backend client object - * with the @name in the model @model. + * Creates a new cryptodev backend client object. * * The returned object must be released with * cryptodev_backend_free_client() when no @@ -276,9 +271,8 @@ struct CryptoDevBackend { * * Returns: a new cryptodev backend client object */ -CryptoDevBackendClient * -cryptodev_backend_new_client(const char *model, - const char *name); +CryptoDevBackendClient *cryptodev_backend_new_client(void); + /** * cryptodev_backend_free_client: * @cc: the cryptodev backend client object From patchwork Sun Jan 29 02:57:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120011 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 83053C61D97 for ; Sun, 29 Jan 2023 02:59:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxtS-0003kE-Vp; Sat, 28 Jan 2023 21:58: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 1pLxtR-0003jz-HJ for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:09 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtP-00086Q-LO for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:09 -0500 Received: by mail-pj1-x102d.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so8215728pjl.0 for ; Sat, 28 Jan 2023 18:58:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=dMFQWyQMxJuLht08y8UXOs3qr1UwVrlQirzyvap/Nu4=; b=qnMsvoMPG8h3vmvoMGR46TY9vmlmJqAD4GsUi7QmUrBFpzTPDUeA8auy0hQ3Dsa3wc Myc3ormrLbxsblS52JscfbE4XRLd9g8sBuPGAUaPVKu4XkGc/RBcQngfMqAiLOw/Q4DC EH5j/1mezh5oA9pot3yPXdpBsDb16lfTPrEHza3wLG7pLPESrjnHi+y6oVS+5ySR35Tb t9bmpSWoFE/hgge5ucANZfTkNcCFLB6QzQaXLGCgrHOzP/eWrV5amVqMn8/VKi2dEl3S 9QmQk7kPnvjohqImsu7c+NqAV3lAUGfWELk0hvRhme4otWYxipq5bhSb/+ZCKN9ZCaav sVIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=dMFQWyQMxJuLht08y8UXOs3qr1UwVrlQirzyvap/Nu4=; b=QwR9+gHvQsxH9+shHt7hzB6804a0riGh/avUg+vWYClCM6kUoGD/tjqmOBmzWDYOXO L2miQ/LJ2iaP8P2qqUw6o8RLFLz20itIrMPIHVMGmYqYFhUqZLdRIRO3ChRA4BByOKsj vIWqoZJOi6VK9JcqeI9fIu5V6Uxdb+QzQpxo+SviHZ4hvzufEA0bK5GrKYJZZhFdPG6E kK6Y/pxIw+20B30u5jLUt4W3O00aLopjoSwLveX2WWrLz/1xvR5sEDg+Mk8G9ShpZFKT 5ZZTr3BBUAocpJp50/mDC3vZ2zCelS/tPBHS0ZO6eDSbUcBXO3IFV9WxvYY0+gM/k9zG cm3w== X-Gm-Message-State: AO0yUKUei7vDeqaQXXbER0enA+y5CijsFlk5v5rtRpy+kbJHzO7oFPbk 1x0xHVudCyNJp/LE6nJw7cF+IQ== X-Google-Smtp-Source: AK7set+gakgg8SXUeOXwIou136RaRs8lK4UKoPzUyezN9+W7xfTQg5+E+xeRGn8rjSAcV5vkZjbeeA== X-Received: by 2002:a17:903:228b:b0:196:7906:b4e with SMTP id b11-20020a170903228b00b0019679060b4emr1225562plh.19.1674961085291; Sat, 28 Jan 2023 18:58:05 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:04 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 03/12] cryptodev: Introduce cryptodev alg type in QAPI Date: Sun, 29 Jan 2023 10:57:38 +0800 Message-Id: <20230129025747.682282-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102d.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_PASS=-0.001 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 Introduce cryptodev alg type in cryptodev.json, then apply this to related codes, and drop 'enum CryptoDevBackendAlgType'. There are two options: 1, { 'enum': 'QCryptodevBackendAlgType', 'prefix': 'CRYPTODEV_BACKEND_ALG', 'data': ['sym', 'asym']} Then we can keep 'CRYPTODEV_BACKEND_ALG_SYM' and avoid lots of changes. 2, changes in this patch(with prefix 'QCRYPTODEV_BACKEND_ALG'). To avoid breaking the rule of QAPI, use 2 here. Reviewed-by: Daniel P. Berrangé Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 6 +++--- backends/cryptodev-lkcf.c | 4 ++-- backends/cryptodev.c | 6 +++--- hw/virtio/virtio-crypto.c | 14 +++++++------- include/sysemu/cryptodev.h | 8 +------- qapi/cryptodev.json | 14 ++++++++++++++ 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 08895271eb..e70dcd5dad 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -537,7 +537,7 @@ static int cryptodev_builtin_operation( CryptoDevBackendBuiltinSession *sess; CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendAsymOpInfo *asym_op_info; - enum CryptoDevBackendAlgType algtype = op_info->algtype; + QCryptodevBackendAlgType algtype = op_info->algtype; int status = -VIRTIO_CRYPTO_ERR; Error *local_error = NULL; @@ -549,11 +549,11 @@ static int cryptodev_builtin_operation( } sess = builtin->sessions[op_info->session_id]; - if (algtype == CRYPTODEV_BACKEND_ALG_SYM) { + if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) { sym_op_info = op_info->u.sym_op_info; status = cryptodev_builtin_sym_operation(sess, sym_op_info, &local_error); - } else if (algtype == CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) { asym_op_info = op_info->u.asym_op_info; status = cryptodev_builtin_asym_operation(sess, op_info->op_code, asym_op_info, &local_error); diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index de3d1867c5..53a932b58d 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -477,7 +477,7 @@ static int cryptodev_lkcf_operation( CryptoDevBackendLKCF *lkcf = CRYPTODEV_BACKEND_LKCF(backend); CryptoDevBackendLKCFSession *sess; - enum CryptoDevBackendAlgType algtype = op_info->algtype; + QCryptodevBackendAlgType algtype = op_info->algtype; CryptoDevLKCFTask *task; if (op_info->session_id >= MAX_SESSIONS || @@ -488,7 +488,7 @@ static int cryptodev_lkcf_operation( } sess = lkcf->sess[op_info->session_id]; - if (algtype != CRYPTODEV_BACKEND_ALG_ASYM) { + if (algtype != QCRYPTODEV_BACKEND_ALG_ASYM) { error_report("algtype not supported: %u", algtype); return -VIRTIO_CRYPTO_NOTSUPP; } diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 81941af816..c2a053db0e 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -120,10 +120,10 @@ int cryptodev_backend_crypto_operation( { VirtIOCryptoReq *req = opaque1; CryptoDevBackendOpInfo *op_info = &req->op_info; - enum CryptoDevBackendAlgType algtype = req->flags; + QCryptodevBackendAlgType algtype = req->flags; - if ((algtype != CRYPTODEV_BACKEND_ALG_SYM) - && (algtype != CRYPTODEV_BACKEND_ALG_ASYM)) { + if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) + && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); return -VIRTIO_CRYPTO_NOTSUPP; } diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 516425e26a..0d1be0ada9 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -462,7 +462,7 @@ static void virtio_crypto_init_request(VirtIOCrypto *vcrypto, VirtQueue *vq, req->in_iov = NULL; req->in_num = 0; req->in_len = 0; - req->flags = CRYPTODEV_BACKEND_ALG__MAX; + req->flags = QCRYPTODEV_BACKEND_ALG__MAX; memset(&req->op_info, 0x00, sizeof(req->op_info)); } @@ -472,7 +472,7 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req) return; } - if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { + if (req->flags == QCRYPTODEV_BACKEND_ALG_SYM) { size_t max_len; CryptoDevBackendSymOpInfo *op_info = req->op_info.u.sym_op_info; @@ -485,7 +485,7 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req) /* Zeroize and free request data structure */ memset(op_info, 0, sizeof(*op_info) + max_len); g_free(op_info); - } else if (req->flags == CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (req->flags == QCRYPTODEV_BACKEND_ALG_ASYM) { CryptoDevBackendAsymOpInfo *op_info = req->op_info.u.asym_op_info; if (op_info) { g_free(op_info->src); @@ -570,10 +570,10 @@ static void virtio_crypto_req_complete(void *opaque, int ret) VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); uint8_t status = -ret; - if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { + if (req->flags == QCRYPTODEV_BACKEND_ALG_SYM) { virtio_crypto_sym_input_data_helper(vdev, req, status, req->op_info.u.sym_op_info); - } else if (req->flags == CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (req->flags == QCRYPTODEV_BACKEND_ALG_ASYM) { virtio_crypto_akcipher_input_data_helper(vdev, req, status, req->op_info.u.asym_op_info); } @@ -875,7 +875,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT: - op_info->algtype = request->flags = CRYPTODEV_BACKEND_ALG_SYM; + op_info->algtype = request->flags = QCRYPTODEV_BACKEND_ALG_SYM; ret = virtio_crypto_handle_sym_req(vcrypto, &req.u.sym_req, op_info, out_iov, out_num); @@ -885,7 +885,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) case VIRTIO_CRYPTO_AKCIPHER_DECRYPT: case VIRTIO_CRYPTO_AKCIPHER_SIGN: case VIRTIO_CRYPTO_AKCIPHER_VERIFY: - op_info->algtype = request->flags = CRYPTODEV_BACKEND_ALG_ASYM; + op_info->algtype = request->flags = QCRYPTODEV_BACKEND_ALG_ASYM; ret = virtio_crypto_handle_asym_req(vcrypto, &req.u.akcipher_req, op_info, out_iov, out_num); diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index af152d09db..16f01dd48a 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -49,12 +49,6 @@ typedef struct CryptoDevBackendPeers CryptoDevBackendPeers; typedef struct CryptoDevBackendClient CryptoDevBackendClient; -enum CryptoDevBackendAlgType { - CRYPTODEV_BACKEND_ALG_SYM, - CRYPTODEV_BACKEND_ALG_ASYM, - CRYPTODEV_BACKEND_ALG__MAX, -}; - /** * CryptoDevBackendSymSessionInfo: * @@ -181,7 +175,7 @@ typedef struct CryptoDevBackendAsymOpInfo { } CryptoDevBackendAsymOpInfo; typedef struct CryptoDevBackendOpInfo { - enum CryptoDevBackendAlgType algtype; + QCryptodevBackendAlgType algtype; uint32_t op_code; uint64_t session_id; union { diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index b65edbe183..ebb6852035 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -4,6 +4,20 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. +## +# @QCryptodevBackendAlgType: +# +# The supported algorithm types of a crypto device. +# +# @sym: symmetric encryption +# @asym: asymmetric Encryption +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendAlgType', + 'prefix': 'QCRYPTODEV_BACKEND_ALG', + 'data': ['sym', 'asym']} + ## # @QCryptodevBackendType: # From patchwork Sun Jan 29 02:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120018 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 7323DC61D97 for ; Sun, 29 Jan 2023 03:00:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxtW-0003lJ-NS; Sat, 28 Jan 2023 21:58:14 -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 1pLxtV-0003ku-3O for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:13 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtS-00086Y-4J for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:11 -0500 Received: by mail-pj1-x1036.google.com with SMTP id b24-20020a17090a551800b0022beefa7a23so12296995pji.5 for ; Sat, 28 Jan 2023 18:58:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=ihnaClmcpFL3v9tNj7fgQemINsh8688QVm+1j1fBK14=; b=4a2I2wBtM9m5m2n/uPV0kI1JVfAkCdtiYJwSjYfLn5PtB8oSqG1FZUnVa20TUXEwdQ Ww6VzpN8gJtgGt5dtr0D20oimoRZewo9k5cGjbSBMqF4HvNK29soh1vwCKPyM81kcrPU dZBxTMQOARLtws52gC5XePSLZSSIGmOtf2j0BRXw9ZU21X9Jq2WFlFqSSR9BUvTgDXzM hBmzIhpv29rAMONXZWvePncIUO2cPGQ7sWkA+SEH+YwtT8eMzRsgj9xCHLh5Ok9F+VKm gq+e/kH3TvUI2G3BntpdH772trywTJmFEV7LOD9wgL6gsExpcSg3zDQPqMkFNZ6Iswjs W2yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ihnaClmcpFL3v9tNj7fgQemINsh8688QVm+1j1fBK14=; b=hx+D2FXcYQk/f3NfCK1fruqU9BvKuF7V99SiuVvpP92fAeatazEpRGE9t8m1rbkM0f FIJ5GxL9Rkx8SZjBVDz3nwjmgR6bLKSpFsp14BGkpYflZzCWe8ZD07UPSrJzyh0uYCbI ThCrqlSqJdx0YmFd++dWaQNm32ECBWu7iey+9VCuxsG5KlbCM98VRrvtJq99XQlEbkX2 WrCjeK9xspDhayF38vVKLZSr21RzbMLKXq/MdTTKDJLl0uxf0wa3qrvSVBWnutllM8al OuIaF+LVcqjuZ0MQNz/B3HGYI7xQlQCwVzHGX2vJTO0BET7JRb2QHBZ4Tct9kDZLnLuN fQtQ== X-Gm-Message-State: AO0yUKXBbFyAiPpZFe4fgywgQEni2Kj5f9O6UmT6CIuYSQ3fmBf1pzcQ fIhrA5vzrUB3QHjKco7+wfpvxQ== X-Google-Smtp-Source: AK7set/ogTt/KHKo+zhbsjJiVVDJCw9u4aqBNPNC+mkLv4TH1cPdzjd3OD0bcuz9+7Gf2f9Q00C++g== X-Received: by 2002:a17:902:dacf:b0:196:15bc:e200 with SMTP id q15-20020a170902dacf00b0019615bce200mr21398209plx.4.1674961088591; Sat, 28 Jan 2023 18:58:08 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:08 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 04/12] cryptodev: Introduce server type in QAPI Date: Sun, 29 Jan 2023 10:57:39 +0800 Message-Id: <20230129025747.682282-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1036.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_PASS=-0.001 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 Introduce cryptodev service type in cryptodev.json, then apply this to related codes. Now we can remove VIRTIO_CRYPTO_SERVICE_xxx dependence from QEMU cryptodev. Reviewed-by: Daniel P. Berrangé Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 8 ++++---- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 6 +++--- hw/virtio/virtio-crypto.c | 27 +++++++++++++++++++++++++-- qapi/cryptodev.json | 11 +++++++++++ 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index e70dcd5dad..c0fbb650d7 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -79,10 +79,10 @@ static void cryptodev_builtin_init( backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_CIPHER | - 1u << VIRTIO_CRYPTO_SERVICE_HASH | - 1u << VIRTIO_CRYPTO_SERVICE_MAC | - 1u << VIRTIO_CRYPTO_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER | + 1u << QCRYPTODEV_BACKEND_SERVICE_HASH | + 1u << QCRYPTODEV_BACKEND_SERVICE_MAC | + 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1; backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 53a932b58d..edec99f104 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -230,7 +230,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp) backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; lkcf->running = true; diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c index 580bd1abb0..b1d9eb735f 100644 --- a/backends/cryptodev-vhost-user.c +++ b/backends/cryptodev-vhost-user.c @@ -221,9 +221,9 @@ static void cryptodev_vhost_user_init( cryptodev_vhost_user_event, NULL, s, NULL, true); backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_CIPHER | - 1u << VIRTIO_CRYPTO_SERVICE_HASH | - 1u << VIRTIO_CRYPTO_SERVICE_MAC; + 1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER | + 1u << QCRYPTODEV_BACKEND_SERVICE_HASH | + 1u << QCRYPTODEV_BACKEND_SERVICE_MAC; backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1; diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 0d1be0ada9..e4f0de4d1c 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -997,12 +997,35 @@ static void virtio_crypto_reset(VirtIODevice *vdev) } } +static uint32_t virtio_crypto_init_services(uint32_t qservices) +{ + uint32_t vservices = 0; + + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_CIPHER); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_HASH)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_HASH); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_MAC)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_MAC); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AEAD)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_AEAD); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_AKCIPHER); + } + + return vservices; +} + static void virtio_crypto_init_config(VirtIODevice *vdev) { VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); - vcrypto->conf.crypto_services = - vcrypto->conf.cryptodev->conf.crypto_services; + vcrypto->conf.crypto_services = virtio_crypto_init_services( + vcrypto->conf.cryptodev->conf.crypto_services); vcrypto->conf.cipher_algo_l = vcrypto->conf.cryptodev->conf.cipher_algo_l; vcrypto->conf.cipher_algo_h = diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index ebb6852035..8732a30524 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -18,6 +18,17 @@ 'prefix': 'QCRYPTODEV_BACKEND_ALG', 'data': ['sym', 'asym']} +## +# @QCryptodevBackendServiceType: +# +# The supported service types of a crypto device. +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendServiceType', + 'prefix': 'QCRYPTODEV_BACKEND_SERVICE', + 'data': ['cipher', 'hash', 'mac', 'aead', 'akcipher']} + ## # @QCryptodevBackendType: # From patchwork Sun Jan 29 02:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120015 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 6ECEEC61D97 for ; Sun, 29 Jan 2023 03:00:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxta-0003mA-4X; Sat, 28 Jan 2023 21:58:18 -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 1pLxtY-0003ly-6o for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:16 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtW-00086t-Ib for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:15 -0500 Received: by mail-pl1-x630.google.com with SMTP id 5so8518163plo.3 for ; Sat, 28 Jan 2023 18:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=tZu7/hI7aL4wyGXCzAEJ1jd1KuiZ9b0q9eR9U/i2mso=; b=kcdPYlqDoRxf+7O632pX5h0/76jhhOGra5gi/OEgUkrAkK7z80AHwhXuYbkobiYU2L yrQp0/ljqG1asdxbd+Jd6gd49YXMZnCq40FNtblXtgkfGkt+N959oy3CaUu8iwWam60M G4QYcRBJc/IcP5cQfhhiBJx2pkkPXTTCuDZDNxrFfqnGMBSX5mbW8D119e/van1ZjeuY M+mbo/POluZSQAPg+Ban55Xad+OPB5EqTDO/pWTME8jVYOCE0dGHGGy9l7XM9w5pNyc5 E/rR+Wj01TEOh9Fy6i8apMK7o0SRoqcleU0ZZ9fOOn1ZEwoZhuAcKA42wBtLIaNMjWiH Emnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=tZu7/hI7aL4wyGXCzAEJ1jd1KuiZ9b0q9eR9U/i2mso=; b=joyxdubGhIa20xwbWZD04BaHJ4qr5WwDUI3ApKkpO+CAvclIBQw+/ljsV3XCcGLY8O un2LEqSYODJNtjRvYuN6QTIbOabg/yrYGFMcA39H1LJWc3Zr42MSIPJDtudlvWeUQfOO HFBBpeiyOnaF+aIlW+P5wbNZsp2O7XQzUZN9iTV8O7e+iH5IQ/2y0XS/SbctWIM+V28H MAVW8FdhJZ2fSRn62k2XMeauzg4CHSiQrTmlf1cHrCmR6MZNAbP3l4scG6HSWXpnJdnr yYt3g0nSvHEwb/7+NRA2ryXoKbcdByBejBdcWEgSS3yD5fmoIyVzVf/2CvM/8+OcJeia 0Row== X-Gm-Message-State: AO0yUKXm6Xp6rMZaEFvWLo/nd6Jjy0zQXRJzPYJM9pbNYjYfJArHrB6u jA5xF/Kaanx9HCjJw15hnUUozw== X-Google-Smtp-Source: AK7set+t2nR1u2X0Umtxb5ex/Nxxp8gQl1StU5Y7TdFBe1b9OeYGYyPmSeuMWs6MVRmT4AZ8o1hGOA== X-Received: by 2002:a17:903:2312:b0:196:6162:1a76 with SMTP id d18-20020a170903231200b0019661621a76mr6389578plh.0.1674961093195; Sat, 28 Jan 2023 18:58:13 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:11 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 05/12] cryptodev: Introduce 'query-cryptodev' QMP command Date: Sun, 29 Jan 2023 10:57:40 +0800 Message-Id: <20230129025747.682282-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x630.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_PASS=-0.001 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 Now we have a QMP command to query crypto devices: virsh qemu-monitor-command vm '{"execute": "query-cryptodev"}' | jq { "return": [ { "service": [ "akcipher", "mac", "hash", "cipher" ], "id": "cryptodev1", "client": [ { "queue": 0, "type": "builtin" } ] }, { "service": [ "akcipher" ], "id": "cryptodev0", "client": [ { "queue": 0, "type": "lkcf" } ] } ], "id": "libvirt-417" } Signed-off-by: zhenwei pi --- backends/cryptodev.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ qapi/cryptodev.json | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index c2a053db0e..3a45d19823 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "sysemu/cryptodev.h" #include "qapi/error.h" +#include "qapi/qapi-commands-cryptodev.h" #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -33,6 +34,50 @@ static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; +static int qmp_query_cryptodev_foreach(Object *obj, void *data) +{ + CryptoDevBackend *backend; + QCryptodevInfoList **infolist = data; + uint32_t services, i; + + if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) { + return 0; + } + + QCryptodevInfo *info = g_new0(QCryptodevInfo, 1); + info->id = g_strdup(object_get_canonical_path_component(obj)); + + backend = CRYPTODEV_BACKEND(obj); + services = backend->conf.crypto_services; + for (i = 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) { + if (services & (1 << i)) { + QAPI_LIST_PREPEND(info->service, i); + } + } + + for (i = 0; i < backend->conf.peers.queues; i++) { + CryptoDevBackendClient *cc = backend->conf.peers.ccs[i]; + QCryptodevBackendClient *client = g_new0(QCryptodevBackendClient, 1); + + client->queue = cc->queue_index; + client->type = cc->type; + QAPI_LIST_PREPEND(info->client, client); + } + + QAPI_LIST_PREPEND(*infolist, info); + + return 0; +} + +QCryptodevInfoList *qmp_query_cryptodev(Error **errp) +{ + QCryptodevInfoList *list = NULL; + Object *objs = container_get(object_get_root(), "/objects"); + + object_child_foreach(objs, qmp_query_cryptodev_foreach, &list); + + return list; +} CryptoDevBackendClient *cryptodev_backend_new_client(void) { diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index 8732a30524..f33f96a692 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -43,3 +43,47 @@ { 'enum': 'QCryptodevBackendType', 'prefix': 'QCRYPTODEV_BACKEND_TYPE', 'data': ['builtin', 'vhost-user', 'lkcf']} + +## +# @QCryptodevBackendClient: +# +# Information about a queue of crypto device. +# +# @queue: the queue index of the crypto device +# +# @type: the type of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendClient', + 'data': { 'queue': 'uint32', + 'type': 'QCryptodevBackendType' } } + +## +# @QCryptodevInfo: +# +# Information about a crypto device. +# +# @id: the id of the crypto device +# +# @service: supported service types of a crypto device +# +# @client: the additional infomation of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevInfo', + 'data': { 'id': 'str', + 'service': ['QCryptodevBackendServiceType'], + 'client': ['QCryptodevBackendClient'] } } + +## +# @query-cryptodev: +# +# Returns information about current crypto devices. +# +# Returns: a list of @QCryptodevInfo +# +# Since: 8.0 +## +{ 'command': 'query-cryptodev', 'returns': ['QCryptodevInfo']} From patchwork Sun Jan 29 02:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120014 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 4EFE2C61D97 for ; Sun, 29 Jan 2023 03:00:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxtd-0003mn-CT; Sat, 28 Jan 2023 21:58:21 -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 1pLxtb-0003mN-9F for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:19 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtZ-000879-OX for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:19 -0500 Received: by mail-pj1-x102e.google.com with SMTP id m7-20020a17090a71c700b0022c0c070f2eso11626411pjs.4 for ; Sat, 28 Jan 2023 18:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=yRqKF+cPLoJ9eGXHwa7i/EcGRG2Tdd0PF29JhlquWEg52jv8B7KNY0Hl5Rq3uVPq0O xPD0zdFJm+xQ3qa3ezWpyyIu61KQ8Rzr4muMgUYOORTYONXTUPcYzgAnoPtVN3tyo9KM EJZ9BOUwI3oMBqJVKD3xffDTcncyZr7VyUSDiDay9rd885Psw9ynsM90ZTa9VFHMavDQ QJvYB7VMWU0ER+IzztOJtNdwvlNA6d34IIBUudEUcgn4dSrWBm6i6exwem7oPZb3s7ym YNC5f4Wqd+2d6U68LkSURTVAN9NV+VC190hzYS45DVdNwSzypQQDS1Ore6DAyCipAbHl I8ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=Z1crTDvrToynbMh2KlzBmkIKeWzjclyqiLe7aeHxdhQZOP6u3ZZszcxIgjds0U5UbP QzVD8yxWkFtdkuCNMFo/tq/XzxJ+GOcBRy6oRQtqnGUg25r8JQkQ/pvLNOG81bQgEz0q Xw4XmTajc/7b6bceNkMqLGJmUVnrU4P47tru/FU8JOF9/4abXo0pwdlIOrIvrbIy+QCo 8xNz2FLFRAVGvAnKcEMcsy4VvONMds4qNzVRz5PpKpTVlDq2UrxmGVJYjhwM/9gmgEIY 3Qe2sOSkzY/BdN1aIZ3ZntxeD4Z3wvtl1uJuaAuS9XwSf9+/qu0fKEWZRm8wBZ2VYRw4 uJuA== X-Gm-Message-State: AO0yUKUkugThHULfUuUNQI4VriQ2JJLzUgLEWVtoGKg3JquccKniHUrg lMJIvJCFH9JPJXLhz3fByHfrzg== X-Google-Smtp-Source: AK7set9mkNZ/EuQ7EOR1++ObQtxC1DwJSG5ZIh23mtixoMGhYxiMwhlHG0ootFhq4/FcpBTzxt3jgw== X-Received: by 2002:a17:903:22cf:b0:196:1f80:106d with SMTP id y15-20020a17090322cf00b001961f80106dmr18495128plg.9.1674961096528; Sat, 28 Jan 2023 18:58:16 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:15 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 06/12] cryptodev-builtin: Detect akcipher capability Date: Sun, 29 Jan 2023 10:57:41 +0800 Message-Id: <20230129025747.682282-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102e.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_PASS=-0.001 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 Rather than exposing akcipher service/RSA algorithm to virtio crypto device unconditionally, detect akcipher capability from akcipher crypto framework. This avoids unsuccessful requests. Reviewed-by: Daniel P. Berrangé Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index c0fbb650d7..c45b5906c5 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -59,6 +59,19 @@ struct CryptoDevBackendBuiltin { CryptoDevBackendBuiltinSession *sessions[MAX_NUM_SESSIONS]; }; +static void cryptodev_builtin_init_akcipher(CryptoDevBackend *backend) +{ + QCryptoAkCipherOptions opts; + + opts.alg = QCRYPTO_AKCIPHER_ALG_RSA; + opts.u.rsa.padding_alg = QCRYPTO_RSA_PADDING_ALG_RAW; + if (qcrypto_akcipher_supports(&opts)) { + backend->conf.crypto_services |= + (1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER); + backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; + } +} + static void cryptodev_builtin_init( CryptoDevBackend *backend, Error **errp) { @@ -81,11 +94,9 @@ static void cryptodev_builtin_init( backend->conf.crypto_services = 1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER | 1u << QCRYPTODEV_BACKEND_SERVICE_HASH | - 1u << QCRYPTODEV_BACKEND_SERVICE_MAC | - 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_MAC; backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1; - backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; /* * Set the Maximum length of crypto request. * Why this value? Just avoid to overflow when @@ -94,6 +105,7 @@ static void cryptodev_builtin_init( backend->conf.max_size = LONG_MAX - sizeof(CryptoDevBackendOpInfo); backend->conf.max_cipher_key_len = CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_LEN; backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; + cryptodev_builtin_init_akcipher(backend); cryptodev_backend_set_ready(backend, true); } From patchwork Sun Jan 29 02:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120012 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 5A667C61D97 for ; Sun, 29 Jan 2023 02:59:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxtg-0003nK-MS; Sat, 28 Jan 2023 21:58:24 -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 1pLxtf-0003my-06 for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:23 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtd-00089I-DE for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:22 -0500 Received: by mail-pj1-x102e.google.com with SMTP id w6-20020a17090ac98600b0022c58cc7a18so3695715pjt.1 for ; Sat, 28 Jan 2023 18:58:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=hKjVUdlZBN87xHoz70rB2qadFO+xqhalwepeGM+bY0o=; b=GTa4acTd/pshwGlqfjfM/cQjCUt+MCL+WD/CrKvbvIwXOqlj2wNZtTsu46Y74JUbFY z7DJjY4sAhY7DiQZfSINDgHWemTdPIQCbWypvH0s2zJuS6edxM6T7ypRP4qVhve85IzO mSdPS1I5PEHFDsd7TM7mkNOSgCzHA2JQrAmkgj9paWvu4kK3/+LXKdcD7iMxhnE+gQ3n 5r/ECSsex3SxYR4MjRc1EmRhDNa6W4OGZ51vkGJywCKn91g89EtLBXG5exgSMLE9IrRl LN5aNRQ428SfeT8/wkfbvhSjys55KRsRrLdvkJCv/2d3eW9jI/jFccq9OMZPWGujO3on KT9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=hKjVUdlZBN87xHoz70rB2qadFO+xqhalwepeGM+bY0o=; b=7H4fESpZdP+zuAJFazY+x0yAxGbqCLNiT1C3wcr2qFY0/JO2qJj9MOjf3IfFLjsgxO /xE/AYXOA8YSp/yvRfmiNB33esZ1c9Eh8Qvs/dM+SasXVSpgqx4Vq4c6TkG93A9puZc+ 6s6YjJzRzLoHBCAO+TyYPz6GhaXPVbm4UQX562WUoHQuu9eaRzovS85MTJKKZA5b9ShS K2u2x0/uSXGqHaUsGY58cyOoPc9HGWiOXj0tr39wUqSrn3SzMFfksI7ISt9q6PT8scXr 0mYi/ty7ZpIBCrWlhKpB+vyto+0PECt5oJXXo+wCSaJM95MjYUW+m7t7rivAt0a1k+SG FPww== X-Gm-Message-State: AFqh2kq0qV92CY4mETocE2nlC23nlREHMcEZxPTXaKhis4Xa8zdSF7DC gQt+jlwSCOch3hg8lY/ZYNW5aw== X-Google-Smtp-Source: AMrXdXvqOghWLoRM9WznQ5zzIU9J5QbYiNPmNUDfomTdihZ6r22n6bBtWb5uqjtDIVa1V4aKoNbsCw== X-Received: by 2002:a17:902:f546:b0:194:d9d7:88c4 with SMTP id h6-20020a170902f54600b00194d9d788c4mr43493137plf.49.1674961100112; Sat, 28 Jan 2023 18:58:20 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:19 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 07/12] hmp: add cryptodev info command Date: Sun, 29 Jan 2023 10:57:42 +0800 Message-Id: <20230129025747.682282-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102e.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_PASS=-0.001 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 Example of this command: # virsh qemu-monitor-command vm --hmp info cryptodev cryptodev1: service=[akcipher|mac|hash|cipher] queue 0: type=builtin cryptodev0: service=[akcipher] queue 0: type=lkcf Signed-off-by: zhenwei pi --- hmp-commands-info.hx | 14 ++++++++++++++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 754b1e8408..47d63d26db 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -993,3 +993,17 @@ SRST ``info virtio-queue-element`` *path* *queue* [*index*] Display element of a given virtio queue ERST + + { + .name = "cryptodev", + .args_type = "", + .params = "", + .help = "show the crypto devices", + .cmd = hmp_info_cryptodev, + .flags = "p", + }, + +SRST + ``info cryptodev`` + Show the crypto devices. +ERST diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 1b3bdcb446..391a097ffd 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -151,5 +151,6 @@ void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Error **)); void hmp_info_stats(Monitor *mon, const QDict *qdict); void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict); #endif diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 1dba973092..cda52c2526 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -33,6 +33,7 @@ #include "qapi/qapi-commands-block.h" #include "qapi/qapi-commands-char.h" #include "qapi/qapi-commands-control.h" +#include "qapi/qapi-commands-cryptodev.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" @@ -2280,3 +2281,39 @@ void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict) qapi_free_VirtioQueueElement(e); } + +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict) +{ + QCryptodevInfoList *il; + QCryptodevBackendServiceTypeList *sl; + QCryptodevBackendClientList *cl; + + for (il = qmp_query_cryptodev(NULL); il; il = il->next) { + g_autofree char *services = NULL; + QCryptodevInfo *info = il->value; + char *tmp_services; + + /* build a string like 'service=[akcipher|mac|hash|cipher]' */ + for (sl = info->service; sl; sl = sl->next) { + const char *service = QCryptodevBackendServiceType_str(sl->value); + + if (!services) { + services = g_strdup(service); + } else { + tmp_services = g_strjoin("|", services, service, NULL); + g_free(services); + services = tmp_services; + } + } + monitor_printf(mon, "%s: service=[%s]\n", info->id, services); + + for (cl = info->client; cl; cl = cl->next) { + QCryptodevBackendClient *client = cl->value; + monitor_printf(mon, " queue %" PRIu32 ": type=%s\n", + client->queue, + QCryptodevBackendType_str(client->type)); + } + } + + qapi_free_QCryptodevInfoList(il); +} From patchwork Sun Jan 29 02:57:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120007 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 C679FC38142 for ; Sun, 29 Jan 2023 02:59:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxtk-0003q5-AS; Sat, 28 Jan 2023 21:58:28 -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 1pLxti-0003nW-Bd for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:26 -0500 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtg-000879-AN for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:25 -0500 Received: by mail-pj1-x102e.google.com with SMTP id m7-20020a17090a71c700b0022c0c070f2eso11626529pjs.4 for ; Sat, 28 Jan 2023 18:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=ZihvElP/m4HGVNphM2HN0ULRg0VcC4xnUtHDZg/U3cM=; b=0nIfso+AFgeeS7KjJaTee2mLjiCpbgbXN1ZGdGOVI9V/xVRmQiDUSV61u0MYTbtddd bmGiVoFyGo0TxJ3Mvb4BMRXt3kFn4KLu5YnM7ZZcp7gdkdyWn0sa5M28BmMhhIkuROBP QX5mkiQahvFyP1NFTeHXyF8l0kRwtga2a1S8pndmSjYfhfj5Lt9+RE5BUyebaTkyP3CH MA9fwXnYWichp1VrPI/j0tmlwOyDyvEGpqWIlMTfD1HSlb15QCJLSNUsqEAJYrJxxXgT 1oGgXU/4ip/ZI71Y5uoggrqdxEFF68sbyNuoC9JtdhfSZCee+VhbIa5ZV4DwV7qFnUNH BRmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ZihvElP/m4HGVNphM2HN0ULRg0VcC4xnUtHDZg/U3cM=; b=CxW462VLK5uknqyVsokN7xHSiO+lc/TY45NWVGFpaW27D2CBmOWMt5U/6V5U68B2jT VeMNLV2YFgX+Rg6D0mB1lsYkw9YK0+xEUuwlWOC+RRYwYucLokua/0llfijF5hYpMte0 W9nEqY87bZdCJG1t9zWO+l7deYJXOyDaMYdDaRMDS9hooXoctp9X+wvn7Zc6KxzMM6Wq uUl1GCXakkzLTLusisGin6u2NwipjW67+zRgwYWaXihJV8ZS7M6YrNdFncs8jB2vBVQe tcHBDOs4c9G7SBWR6OJ9KagAjz7aqwtA9AXTFzXnI+0LhGOVjyJ/tWq3/oZdDzQjnVT2 mbQA== X-Gm-Message-State: AO0yUKWS7cUtY25j/CGfaE+UUYIWIT0rLb6CooU6w0rTI/h4mcHJX7Kt c/bNxVlJ3uhUp9Slr7Ar0moZYw== X-Google-Smtp-Source: AK7set/YGUFnLXWrpDaIsQeDnmHT9WREpEJADQVxx2Se0BzGL40ZgEGKexOrXwHedV/RYEOXn0F0jA== X-Received: by 2002:a17:902:e482:b0:191:7d3:7fdd with SMTP id i2-20020a170902e48200b0019107d37fddmr2634979ple.60.1674961103598; Sat, 28 Jan 2023 18:58:23 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:22 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 08/12] cryptodev: Use CryptoDevBackendOpInfo for operation Date: Sun, 29 Jan 2023 10:57:43 +0800 Message-Id: <20230129025747.682282-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102e.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_PASS=-0.001 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 Move queue_index, CryptoDevCompletionFunc and opaque into struct CryptoDevBackendOpInfo, then cryptodev_backend_crypto_operation() needs an argument CryptoDevBackendOpInfo *op_info only. And remove VirtIOCryptoReq from cryptodev. It's also possible to hide VirtIOCryptoReq into virtio-crypto.c in the next step. (In theory, VirtIOCryptoReq is a private structure used by virtio-crypto only) Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 9 +++------ backends/cryptodev-lkcf.c | 9 +++------ backends/cryptodev.c | 18 +++++------------- hw/virtio/virtio-crypto.c | 7 ++++--- include/sysemu/cryptodev.h | 26 ++++++++++---------------- 5 files changed, 25 insertions(+), 44 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index c45b5906c5..39d0455280 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -539,10 +539,7 @@ static int cryptodev_builtin_asym_operation( static int cryptodev_builtin_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendBuiltin *builtin = CRYPTODEV_BACKEND_BUILTIN(backend); @@ -574,8 +571,8 @@ static int cryptodev_builtin_operation( if (local_error) { error_report_err(local_error); } - if (cb) { - cb(opaque, status); + if (op_info->cb) { + op_info->cb(op_info->opaque, status); } return 0; } diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index edec99f104..45aba1ff67 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -469,10 +469,7 @@ static void *cryptodev_lkcf_worker(void *arg) static int cryptodev_lkcf_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendLKCF *lkcf = CRYPTODEV_BACKEND_LKCF(backend); @@ -495,8 +492,8 @@ static int cryptodev_lkcf_operation( task = g_new0(CryptoDevLKCFTask, 1); task->op_info = op_info; - task->cb = cb; - task->opaque = opaque; + task->cb = op_info->cb; + task->opaque = op_info->opaque; task->sess = sess; task->lkcf = lkcf; task->status = -VIRTIO_CRYPTO_ERR; diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 3a45d19823..ba7b0bc770 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -143,29 +143,22 @@ int cryptodev_backend_close_session( static int cryptodev_backend_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(backend); if (bc->do_op) { - return bc->do_op(backend, op_info, queue_index, cb, opaque); + return bc->do_op(backend, op_info); } return -VIRTIO_CRYPTO_NOTSUPP; } int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, - void *opaque1, - uint32_t queue_index, - CryptoDevCompletionFunc cb, void *opaque2) + CryptoDevBackendOpInfo *op_info) { - VirtIOCryptoReq *req = opaque1; - CryptoDevBackendOpInfo *op_info = &req->op_info; - QCryptodevBackendAlgType algtype = req->flags; + QCryptodevBackendAlgType algtype = op_info->algtype; if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { @@ -173,8 +166,7 @@ int cryptodev_backend_crypto_operation( return -VIRTIO_CRYPTO_NOTSUPP; } - return cryptodev_backend_operation(backend, op_info, queue_index, - cb, opaque2); + return cryptodev_backend_operation(backend, op_info); } static void diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index e4f0de4d1c..802e1b9659 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -871,6 +871,9 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) opcode = ldl_le_p(&req.header.opcode); op_info->session_id = ldq_le_p(&req.header.session_id); op_info->op_code = opcode; + op_info->queue_index = queue_index; + op_info->cb = virtio_crypto_req_complete; + op_info->opaque = request; switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: @@ -898,9 +901,7 @@ check_result: virtio_crypto_req_complete(request, -VIRTIO_CRYPTO_NOTSUPP); } else { ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev, - request, queue_index, - virtio_crypto_req_complete, - request); + op_info); if (ret < 0) { virtio_crypto_req_complete(request, ret); } diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 16f01dd48a..048a627035 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -174,9 +174,14 @@ typedef struct CryptoDevBackendAsymOpInfo { uint8_t *dst; } CryptoDevBackendAsymOpInfo; +typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); + typedef struct CryptoDevBackendOpInfo { QCryptodevBackendAlgType algtype; uint32_t op_code; + uint32_t queue_index; + CryptoDevCompletionFunc cb; + void *opaque; /* argument for cb */ uint64_t session_id; union { CryptoDevBackendSymOpInfo *sym_op_info; @@ -184,7 +189,6 @@ typedef struct CryptoDevBackendOpInfo { } u; } CryptoDevBackendOpInfo; -typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); struct CryptoDevBackendClass { ObjectClass parent_class; @@ -204,10 +208,7 @@ struct CryptoDevBackendClass { void *opaque); int (*do_op)(CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque); + CryptoDevBackendOpInfo *op_info); }; struct CryptoDevBackendClient { @@ -335,24 +336,17 @@ int cryptodev_backend_close_session( /** * cryptodev_backend_crypto_operation: * @backend: the cryptodev backend object - * @opaque1: pointer to a VirtIOCryptoReq object - * @queue_index: queue index of cryptodev backend client - * @errp: pointer to a NULL-initialized error object - * @cb: callbacks when operation is completed - * @opaque2: parameter passed to cb + * @op_info: pointer to a CryptoDevBackendOpInfo object * - * Do crypto operation, such as encryption and - * decryption + * Do crypto operation, such as encryption, decryption, signature and + * verification * * Returns: 0 for success and cb will be called when creation is completed, * negative value for error, and cb will not be called. */ int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, - void *opaque1, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque2); + CryptoDevBackendOpInfo *op_info); /** * cryptodev_backend_set_used: From patchwork Sun Jan 29 02:57:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120008 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 93E51C61D97 for ; Sun, 29 Jan 2023 02:59:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxto-0003za-Ct; Sat, 28 Jan 2023 21:58:32 -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 1pLxtm-0003r2-Ip for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:30 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtk-0008E1-LM for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:30 -0500 Received: by mail-pl1-x636.google.com with SMTP id be8so8493296plb.7 for ; Sat, 28 Jan 2023 18:58:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=Yevz87RZmt+inxiebXb+NEQnBTenjq4dQ5kejtSes+I=; b=p46tpcL/STmTHPyAnXyIwXSIhSDOrwwZxVp8blc0lwWfnLjbPnfgTtHco3tYt3AO+W N97zq5satkJL0b8kwFWCUUI/6EMweJEdXAd1BGeR+5DqT2SEU9K5JiH8zqBFJhwdfIqt eO6y6FrJJ+FIKc2VX+bymCRcV5SCrg32UEVp318/ZcEiW0oV+VG4erdwhpSyzLqahMPJ 37/DV8opXE3/scc/Gvxg/+rYtewryof2m+Uw1JFCnEjcBpnLXCGtEsKCKj632rBfB5+y UeAagnVjw7IWSLw7zc0m6aBf6kjDNcRvTHmwkQkArJ9RWgNMOGEZBSotbz3SwOYxw9Gn +YrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Yevz87RZmt+inxiebXb+NEQnBTenjq4dQ5kejtSes+I=; b=wRGPYNnzLV5irKcv/zZiAs5IRorMqxjf91vj34tzl1OR4JlHsw7mnXTAjcFtsOv7nr DSe0dgj7fcryq+wS8bBU/XEOH3dPxgWdHcefD+UaFZsnrEetZF12fUZPCzGdRq3gMOaW NoOeZzYBQrnkMD+tcWFdLOUi3pxUvgjNvqbmCQhOKKgHXCXF67TShA5/zqxax1nLId1+ AnwpPk/aqG9daH+RxjSHqgboTU2GnMkIGvdOyPtEJvAvE0h+sBunjFFxh4YIEg6qhvUi 71zVasiEOLdM+k5yKvs77Lvk8qoMeJUAxxzOkT0pHn73AF6ivir7KhVcV4o/HfW/U5h/ TqjA== X-Gm-Message-State: AO0yUKWgyp934TaT0j1D5U1jpNeHTgzw3TjEPOIY/EW2JAZwX5ilyC0q J9xytbNZC331X1wilqYvsCKmNQ== X-Google-Smtp-Source: AK7set+kNp1QO/jy9pC31L9tvb/K2lNpIQAFFMHCowB5cOmHCuXMVMj3qk60G8paGlwNAx+1hRiekw== X-Received: by 2002:a17:902:f142:b0:195:6065:afa3 with SMTP id d2-20020a170902f14200b001956065afa3mr2739836plb.44.1674961107167; Sat, 28 Jan 2023 18:58:27 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:26 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 09/12] cryptodev: Account statistics Date: Sun, 29 Jan 2023 10:57:44 +0800 Message-Id: <20230129025747.682282-10-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x636.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_PASS=-0.001 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 Account OPS/BPS for crypto device, this will be used for 'query-stats' QEMU monitor command and QoS in the next step. Note that a crypto device may support symmetric mode, asymmetric mode, both symmetric and asymmetric mode. So we use two structure to describe the statistics of a crypto device. Signed-off-by: zhenwei pi --- backends/cryptodev.c | 68 +++++++++++++++++++++++++++++++++++--- include/sysemu/cryptodev.h | 31 +++++++++++++++++ qapi/cryptodev.json | 54 ++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 5 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index ba7b0bc770..cc824e9665 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -107,6 +107,9 @@ void cryptodev_backend_cleanup( if (bc->cleanup) { bc->cleanup(backend, errp); } + + g_free(backend->sym_stat); + g_free(backend->asym_stat); } int cryptodev_backend_create_session( @@ -154,16 +157,61 @@ static int cryptodev_backend_operation( return -VIRTIO_CRYPTO_NOTSUPP; } +static int cryptodev_backend_account(CryptoDevBackend *backend, + CryptoDevBackendOpInfo *op_info) +{ + enum QCryptodevBackendAlgType algtype = op_info->algtype; + int len; + + if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) { + CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info; + len = asym_op_info->src_len; + switch (op_info->op_code) { + case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT: + QCryptodevAsymStatIncEncrypt(backend, len); + break; + case VIRTIO_CRYPTO_AKCIPHER_DECRYPT: + QCryptodevAsymStatIncDecrypt(backend, len); + break; + case VIRTIO_CRYPTO_AKCIPHER_SIGN: + QCryptodevAsymStatIncSign(backend, len); + break; + case VIRTIO_CRYPTO_AKCIPHER_VERIFY: + QCryptodevAsymStatIncVerify(backend, len); + break; + default: + return -VIRTIO_CRYPTO_NOTSUPP; + } + } else if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) { + CryptoDevBackendSymOpInfo *sym_op_info = op_info->u.sym_op_info; + len = sym_op_info->src_len; + switch (op_info->op_code) { + case VIRTIO_CRYPTO_CIPHER_ENCRYPT: + QCryptodevSymStatIncEncrypt(backend, len); + break; + case VIRTIO_CRYPTO_CIPHER_DECRYPT: + QCryptodevSymStatIncDecrypt(backend, len); + break; + default: + return -VIRTIO_CRYPTO_NOTSUPP; + } + } else { + error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); + return -VIRTIO_CRYPTO_NOTSUPP; + } + + return len; +} + int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, CryptoDevBackendOpInfo *op_info) { - QCryptodevBackendAlgType algtype = op_info->algtype; + int ret; - if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) - && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { - error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); - return -VIRTIO_CRYPTO_NOTSUPP; + ret = cryptodev_backend_account(backend, op_info); + if (ret < 0) { + return ret; } return cryptodev_backend_operation(backend, op_info); @@ -202,10 +250,20 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp) { CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc); CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc); + uint32_t services; if (bc->init) { bc->init(backend, errp); } + + services = backend->conf.crypto_services; + if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) { + backend->sym_stat = g_new0(QCryptodevBackendSymStat, 1); + } + + if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) { + backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1); + } } void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used) diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 048a627035..15e8c04dcf 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -253,8 +253,39 @@ struct CryptoDevBackend { /* Tag the cryptodev backend is used by virtio-crypto or not */ bool is_used; CryptoDevBackendConf conf; + QCryptodevBackendSymStat *sym_stat; + QCryptodevBackendAsymStat *asym_stat; }; +#define QCryptodevSymStatInc(be, op, bytes) do { \ + be->sym_stat->op##_bytes += (bytes); \ + be->sym_stat->op##_ops += 1; \ +} while (/*CONSTCOND*/0) + +#define QCryptodevSymStatIncEncrypt(be, bytes) \ + QCryptodevSymStatInc(be, encrypt, bytes) + +#define QCryptodevSymStatIncDecrypt(be, bytes) \ + QCryptodevSymStatInc(be, decrypt, bytes) + +#define QCryptodevAsymStatInc(be, op, bytes) do { \ + be->asym_stat->op##_bytes += (bytes); \ + be->asym_stat->op##_ops += 1; \ +} while (/*CONSTCOND*/0) + +#define QCryptodevAsymStatIncEncrypt(be, bytes) \ + QCryptodevAsymStatInc(be, encrypt, bytes) + +#define QCryptodevAsymStatIncDecrypt(be, bytes) \ + QCryptodevAsymStatInc(be, decrypt, bytes) + +#define QCryptodevAsymStatIncSign(be, bytes) \ + QCryptodevAsymStatInc(be, sign, bytes) + +#define QCryptodevAsymStatIncVerify(be, bytes) \ + QCryptodevAsymStatInc(be, verify, bytes) + + /** * cryptodev_backend_new_client: * diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index f33f96a692..54d7f9cb58 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -87,3 +87,57 @@ # Since: 8.0 ## { 'command': 'query-cryptodev', 'returns': ['QCryptodevInfo']} + +## +# @QCryptodevBackendSymStat: +# +# The statistics of symmetric operation. +# +# @encrypt-ops: the operations of symmetric encryption +# +# @decrypt-ops: the operations of symmetric decryption +# +# @encrypt-bytes: the bytes of symmetric encryption +# +# @decrypt-bytes: the bytes of symmetric decryption +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendSymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int' } } + +## +# @QCryptodevBackendAsymStat: +# +# The statistics of asymmetric operation. +# +# @encrypt-ops: the operations of asymmetric encryption +# +# @decrypt-ops: the operations of asymmetric decryption +# +# @sign-ops: the operations of asymmetric signature +# +# @verify-ops: the operations of asymmetric verification +# +# @encrypt-bytes: the bytes of asymmetric encryption +# +# @decrypt-bytes: the bytes of asymmetric decryption +# +# @sign-bytes: the bytes of asymmetric signature +# +# @verify-bytes: the bytes of asymmetric verification +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendAsymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'sign-ops': 'int', + 'verify-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int', + 'sign-bytes': 'int', + 'verify-bytes': 'int' } } From patchwork Sun Jan 29 02:57:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120010 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 D63B8C38142 for ; Sun, 29 Jan 2023 02:59:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxu3-0004VV-SC; Sat, 28 Jan 2023 21:58: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 1pLxu1-0004FZ-Q1 for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:45 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtn-00086t-Mr for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:44 -0500 Received: by mail-pl1-x630.google.com with SMTP id 5so8518401plo.3 for ; Sat, 28 Jan 2023 18:58:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=INrx0BfaOa4IFJ+qXVprp2CmsCQfySfcHiPFFgrxkcs=; b=BjzwK/nKY8dNgzhF6TG4cgJioIHvNA70AL4+l97JFiI4AU4qeb4pdhqZH72tYSM7zk 7w1wOo/wsjKvrBXDN5CNwgAVmGgXLupIKyV4/Sezwye06zsDBEllvCp5IB5C83a0N1pV rXMUvucx6YKSyYPRzwIr+Z7HZN3Mfrt609hfYuQCzFraQQReI2Wcoz9YYJtlgC/cskPk O0hWmXXXqYMAXqx+1iKmytLFzQmZPzxukvPUGp8kvhrhx9N5+6ZNes5uZhzam44RGKbX 2EO1yo9B3yuN7Qz5EY+BL6K4OUrmBjABNZEdZii9K8jo1ZJuH2jr5q5KrgpS9PH/XYtI r/XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=INrx0BfaOa4IFJ+qXVprp2CmsCQfySfcHiPFFgrxkcs=; b=mjinX/Nkr8laJU9sXntMuWyHJnZOrm5jHEvF7y0orsSJTMWQtzSlIPPLo4qnGQB8vK mpTXXxJzxWqUrZ9rt2odDUsj/u9egT9I74z6SXYdQcItS/cE0/vAmlJKUxdv0kO08z3+ uvTjbzBcjtBq9fSs7WtL32+N3XKVuF0VI5je/MopipJ6QKv1vdU6hGx+mZ+juV72odsO 3wAlFUvCKEOQiUfSc/7BjS8NJR38Tpkq5m46h/4pu+kF+z1HqA3ursBeeqnnuSLisq64 uwMNZfu9tl3pnceU6zwtPFx447Kn96iW4KS4khh24kbo138N5pXv29keRotmBRIOJ/P4 H59g== X-Gm-Message-State: AO0yUKX5UtHIev3aNzlpLgwNnbc4hqJEY8Bss6O8jKBt0IYQc2KOPFW/ 5PEc1VL1aXKQeNg7utdsTZN6lw== X-Google-Smtp-Source: AK7set/pC0ji4eDy2p5qqDrHBx50fn47XV9W/P+MhaILK+zyIBHhbh7SYUkm/H5vgD5zSAL3KY0VjQ== X-Received: by 2002:a17:902:ecc4:b0:196:6a26:9c5c with SMTP id a4-20020a170902ecc400b001966a269c5cmr3529979plh.26.1674961110952; Sat, 28 Jan 2023 18:58:30 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:30 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 10/12] cryptodev: support QoS Date: Sun, 29 Jan 2023 10:57:45 +0800 Message-Id: <20230129025747.682282-11-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x630.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_PASS=-0.001 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 Add 'throttle-bps' and 'throttle-ops' limitation to set QoS. The two arguments work with both QEMU command line and QMP command. Example of QEMU command line: -object cryptodev-backend-builtin,id=cryptodev1,throttle-bps=1600,\ throttle-ops=100 Example of QMP command: virsh qemu-monitor-command buster --hmp qom-set /objects/cryptodev1 \ throttle-ops 100 or cancel limitation: virsh qemu-monitor-command buster --hmp qom-set /objects/cryptodev1 \ throttle-ops 0 Signed-off-by: zhenwei pi --- backends/cryptodev.c | 138 +++++++++++++++++++++++++++++++++++++ include/sysemu/cryptodev.h | 7 ++ qapi/qom.json | 8 ++- 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index cc824e9665..09ffdd345f 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -28,6 +28,7 @@ #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/main-loop.h" #include "qom/object_interfaces.h" #include "hw/virtio/virtio-crypto.h" @@ -203,17 +204,53 @@ static int cryptodev_backend_account(CryptoDevBackend *backend, return len; } +static void cryptodev_backend_throttle_timer_cb(void *opaque) +{ + CryptoDevBackend *backend = (CryptoDevBackend *)opaque; + CryptoDevBackendOpInfo *op_info, *tmpop; + int ret; + + QTAILQ_FOREACH_SAFE(op_info, &backend->opinfos, next, tmpop) { + QTAILQ_REMOVE(&backend->opinfos, op_info, next); + ret = cryptodev_backend_account(backend, op_info); + if (ret < 0) { + op_info->cb(op_info->opaque, ret); + continue; + } + + throttle_account(&backend->ts, true, ret); + cryptodev_backend_operation(backend, op_info); + if (throttle_enabled(&backend->tc) && + throttle_schedule_timer(&backend->ts, &backend->tt, true)) { + break; + } + } +} + int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, CryptoDevBackendOpInfo *op_info) { int ret; + if (!throttle_enabled(&backend->tc)) { + goto do_account; + } + + if (throttle_schedule_timer(&backend->ts, &backend->tt, true) || + !QTAILQ_EMPTY(&backend->opinfos)) { + QTAILQ_INSERT_TAIL(&backend->opinfos, op_info, next); + return 0; + } + +do_account: ret = cryptodev_backend_account(backend, op_info); if (ret < 0) { return ret; } + throttle_account(&backend->ts, true, ret); + return cryptodev_backend_operation(backend, op_info); } @@ -245,12 +282,98 @@ cryptodev_backend_set_queues(Object *obj, Visitor *v, const char *name, backend->conf.peers.queues = value; } +static void cryptodev_backend_set_throttle(CryptoDevBackend *backend, int field, + uint64_t value, Error **errp) +{ + uint64_t orig = backend->tc.buckets[field].avg; + bool enabled = throttle_enabled(&backend->tc); + + if (orig == value) { + return; + } + + backend->tc.buckets[field].avg = value; + if (!throttle_enabled(&backend->tc)) { + throttle_timers_destroy(&backend->tt); + cryptodev_backend_throttle_timer_cb(backend); /* drain opinfos */ + return; + } + + if (!throttle_is_valid(&backend->tc, errp)) { + backend->tc.buckets[field].avg = orig; /* revert change */ + return; + } + + if (!enabled) { + throttle_init(&backend->ts); + throttle_timers_init(&backend->tt, qemu_get_aio_context(), + QEMU_CLOCK_REALTIME, + cryptodev_backend_throttle_timer_cb, /* FIXME */ + cryptodev_backend_throttle_timer_cb, backend); + } + + throttle_config(&backend->ts, QEMU_CLOCK_REALTIME, &backend->tc); +} + +static void cryptodev_backend_get_bps(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value = backend->tc.buckets[THROTTLE_BPS_TOTAL].avg; + + visit_type_uint64(v, name, &value, errp); +} + +static void cryptodev_backend_set_bps(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, errp); +} + +static void cryptodev_backend_get_ops(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value = backend->tc.buckets[THROTTLE_OPS_TOTAL].avg; + + visit_type_uint64(v, name, &value, errp); +} + +static void cryptodev_backend_set_ops(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, errp); +} + static void cryptodev_backend_complete(UserCreatable *uc, Error **errp) { CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc); CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc); uint32_t services; + uint64_t value; + + QTAILQ_INIT(&backend->opinfos); + value = backend->tc.buckets[THROTTLE_OPS_TOTAL].avg; + cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, errp); + value = backend->tc.buckets[THROTTLE_BPS_TOTAL].avg; + cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, errp); if (bc->init) { bc->init(backend, errp); @@ -294,8 +417,12 @@ cryptodev_backend_can_be_deleted(UserCreatable *uc) static void cryptodev_backend_instance_init(Object *obj) { + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + /* Initialize devices' queues property to 1 */ object_property_set_int(obj, "queues", 1, NULL); + + throttle_config_init(&backend->tc); } static void cryptodev_backend_finalize(Object *obj) @@ -303,6 +430,9 @@ static void cryptodev_backend_finalize(Object *obj) CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); cryptodev_backend_cleanup(backend, NULL); + if (throttle_enabled(&backend->tc)) { + throttle_timers_destroy(&backend->tt); + } } static void @@ -318,6 +448,14 @@ cryptodev_backend_class_init(ObjectClass *oc, void *data) cryptodev_backend_get_queues, cryptodev_backend_set_queues, NULL, NULL); + object_class_property_add(oc, "throttle-bps", "uint64", + cryptodev_backend_get_bps, + cryptodev_backend_set_bps, + NULL, NULL); + object_class_property_add(oc, "throttle-ops", "uint64", + cryptodev_backend_get_ops, + cryptodev_backend_set_ops, + NULL, NULL); } static const TypeInfo cryptodev_backend_info = { diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 15e8c04dcf..113eec4caf 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -24,6 +24,7 @@ #define CRYPTODEV_H #include "qemu/queue.h" +#include "qemu/throttle.h" #include "qom/object.h" #include "qapi/qapi-types-cryptodev.h" @@ -187,6 +188,7 @@ typedef struct CryptoDevBackendOpInfo { CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendAsymOpInfo *asym_op_info; } u; + QTAILQ_ENTRY(CryptoDevBackendOpInfo) next; } CryptoDevBackendOpInfo; struct CryptoDevBackendClass { @@ -255,6 +257,11 @@ struct CryptoDevBackend { CryptoDevBackendConf conf; QCryptodevBackendSymStat *sym_stat; QCryptodevBackendAsymStat *asym_stat; + + ThrottleState ts; + ThrottleTimers tt; + ThrottleConfig tc; + QTAILQ_HEAD(, CryptoDevBackendOpInfo) opinfos; }; #define QCryptodevSymStatInc(be, op, bytes) do { \ diff --git a/qapi/qom.json b/qapi/qom.json index 30e76653ad..a877b879b9 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -278,10 +278,16 @@ # cryptodev-backend and must be 1 for cryptodev-backend-builtin. # (default: 1) # +# @throttle-bps: limit total bytes per second (Since 8.0) +# +# @throttle-ops: limit total operations per second (Since 8.0) +# # Since: 2.8 ## { 'struct': 'CryptodevBackendProperties', - 'data': { '*queues': 'uint32' } } + 'data': { '*queues': 'uint32', + '*throttle-bps': 'uint64', + '*throttle-ops': 'uint64' } } ## # @CryptodevVhostUserProperties: From patchwork Sun Jan 29 02:57:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120017 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 E4C48C61D97 for ; Sun, 29 Jan 2023 03:00:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxu6-0004ig-A1; Sat, 28 Jan 2023 21:58:50 -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 1pLxu3-0004VL-Nj for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:47 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxtx-0008IP-1U for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:47 -0500 Received: by mail-pj1-x1029.google.com with SMTP id j5so8237528pjn.5 for ; Sat, 28 Jan 2023 18:58:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=+24bzIGttHzFFhmGvBHhsTPYBFiGmTest0gVIDUW5Dk=; b=6g7pm3rHfCKAGwIaX6dooCBhn7HpU8/ifHbE/d2CXJx/nvIsgc9cic4bMj7lm3Var0 aagfi7SsJxb1/HSxZbqdYmiKrPGNW7mfZWuIrR/kFBuk7QxGQgHut+e3itjUpJa1YYBw zqfbqRVdEzMuAjBq0Z/orghrFubvCoBBbdu9Ctsn+dSPw0fBMR4brX5iecipmpsGEHfU n5654e/hSbQ8KPXg86kV8hepUkoCDTw0d6Pyiw4CUBK/9EBLs+obisQMh12p1C1ZpmVX vLHAif63jDQoq284Y7opBccX18W5Dhi7ktM0D3YwdVMB9kxrax4oC6IvC9XhohYUKuqk RHdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=+24bzIGttHzFFhmGvBHhsTPYBFiGmTest0gVIDUW5Dk=; b=zcYK0lWw9dIwjDhneY8fHXRcMhT05jrwVxcyi4PX3Ie+x9zSzi97HNeZqwsN2YKpeB sT9k02ZJo/n+u1jncPVDbwqtodl7RnrUw2Ja0nABD3dL0ZMM5lMgXY5fDKbHLwXEtoFB m155zPOiFR/n8QyI2hJcpnFyThm84jSiq+ScvNT4asMGL2TNxZVCiVVaDIB52YmwOo+G yeCm5mOGpdu6Y47jdTgE2q0k3Y5YbfHxuksbRp6JgH/yYGxijggbkRxDj6xrTpWBUUdg EKGOMEHokgDhTCUpb06AH+n7lp/Xd8IE8yemgrDiuVBTj27W+SQjRnCfDGSnIQMI6DPN mLfw== X-Gm-Message-State: AFqh2krtkLwmXszdOp9Nb//ZSrkoCw7na/uGgK36eGLX3OacOqCpsSgN P4AL9QlraqHQz9YheqxzvEQweQ== X-Google-Smtp-Source: AMrXdXskEq02leYuiiiF0TKwp4fvEFESYwSSYrpbsD7zGr87Ik/tp8R96zRCBInXY7rGP9mbsmN2fA== X-Received: by 2002:a17:902:f542:b0:195:f412:5e6f with SMTP id h2-20020a170902f54200b00195f4125e6fmr36663326plf.48.1674961114377; Sat, 28 Jan 2023 18:58:34 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:33 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 11/12] cryptodev: Support query-stats QMP command Date: Sun, 29 Jan 2023 10:57:46 +0800 Message-Id: <20230129025747.682282-12-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1029.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_PASS=-0.001 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 Now we can use "query-stats" QMP command to query statistics of crypto devices. (Originally this was designed to show statistics by '{"execute": "query-cryptodev"}'. Daniel Berrangé suggested that querying configuration info by "query-cryptodev", and querying runtime performance info by "query-stats". This makes sense!) Example: ~# virsh qemu-monitor-command vm '{"execute": "query-stats", \ "arguments": {"target": "cryptodev"} }' | jq { "return": [ { "provider": "cryptodev", "stats": [ { "name": "asym-verify-bytes", "value": 7680 }, ... { "name": "asym-decrypt-ops", "value": 32 }, { "name": "asym-encrypt-ops", "value": 48 } ], "qom-path": "/objects/cryptodev0" # support asym only }, { "provider": "cryptodev", "stats": [ { "name": "asym-verify-bytes", "value": 0 }, ... { "name": "sym-decrypt-bytes", "value": 5376 }, ... ], "qom-path": "/objects/cryptodev1" # support asym/sym } ], "id": "libvirt-422" } Suggested-by: Daniel P. Berrangé Signed-off-by: zhenwei pi --- backends/cryptodev.c | 141 +++++++++++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 5 ++ monitor/qmp-cmds.c | 2 + qapi/stats.json | 10 ++- 4 files changed, 156 insertions(+), 2 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 09ffdd345f..9d52220772 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -22,9 +22,11 @@ */ #include "qemu/osdep.h" +#include "monitor/stats.h" #include "sysemu/cryptodev.h" #include "qapi/error.h" #include "qapi/qapi-commands-cryptodev.h" +#include "qapi/qapi-types-stats.h" #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -32,6 +34,14 @@ #include "qom/object_interfaces.h" #include "hw/virtio/virtio-crypto.h" +typedef struct StatsArgs { + union StatsResultsType { + StatsResultList **stats; + StatsSchemaList **schema; + } result; + strList *names; + Error **errp; +} StatsArgs; static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; @@ -435,6 +445,134 @@ static void cryptodev_backend_finalize(Object *obj) } } +static StatsList *cryptodev_backend_stats_add(const char *name, int64_t *val, + StatsList *stats_list) +{ + Stats *stats = g_new0(Stats, 1); + + stats->name = g_strdup(name); + stats->value = g_new0(StatsValue, 1); + stats->value->type = QTYPE_QNUM; + stats->value->u.scalar = *val; + + QAPI_LIST_PREPEND(stats_list, stats); + return stats_list; +} + +static int cryptodev_backend_stats_query(Object *obj, void *data) +{ + StatsArgs *stats_args = data; + StatsResultList **stats_results = stats_args->result.stats; + StatsList *stats_list = NULL; + StatsResult *entry; + CryptoDevBackend *backend; + QCryptodevBackendSymStat *sym_stat; + QCryptodevBackendAsymStat *asym_stat; + + if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) { + return 0; + } + + backend = CRYPTODEV_BACKEND(obj); + sym_stat = backend->sym_stat; + if (sym_stat) { + stats_list = cryptodev_backend_stats_add("sym-encrypt-ops", + &sym_stat->encrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add("sym-decrypt-ops", + &sym_stat->decrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add("sym-encrypt-bytes", + &sym_stat->encrypt_bytes, stats_list); + stats_list = cryptodev_backend_stats_add("sym-decrypt-bytes", + &sym_stat->decrypt_bytes, stats_list); + } + + asym_stat = backend->asym_stat; + if (asym_stat) { + stats_list = cryptodev_backend_stats_add("asym-encrypt-ops", + &asym_stat->encrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add("asym-decrypt-ops", + &asym_stat->decrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add("asym-sign-ops", + &asym_stat->sign_ops, stats_list); + stats_list = cryptodev_backend_stats_add("asym-verify-ops", + &asym_stat->verify_ops, stats_list); + stats_list = cryptodev_backend_stats_add("asym-encrypt-bytes", + &asym_stat->encrypt_bytes, stats_list); + stats_list = cryptodev_backend_stats_add("asym-decrypt-bytes", + &asym_stat->decrypt_bytes, stats_list); + stats_list = cryptodev_backend_stats_add("asym-sign-bytes", + &asym_stat->sign_bytes, stats_list); + stats_list = cryptodev_backend_stats_add("asym-verify-bytes", + &asym_stat->verify_bytes, stats_list); + } + + entry = g_new0(StatsResult, 1); + entry->provider = STATS_PROVIDER_CRYPTODEV; + entry->qom_path = g_strdup(object_get_canonical_path(obj)); + entry->stats = stats_list; + QAPI_LIST_PREPEND(*stats_results, entry); + + return 0; +} + +static void cryptodev_backend_stats_cb(StatsResultList **result, + StatsTarget target, + strList *names, strList *targets, + Error **errp) +{ + switch (target) { + case STATS_TARGET_CRYPTODEV: + { + Object *objs = container_get(object_get_root(), "/objects"); + StatsArgs stats_args; + stats_args.result.stats = result; + stats_args.names = names; + stats_args.errp = errp; + + object_child_foreach(objs, cryptodev_backend_stats_query, &stats_args); + break; + } + default: + break; + } +} + +static StatsSchemaValueList *cryptodev_backend_schemas_add(const char *name, + StatsSchemaValueList *list) +{ + StatsSchemaValueList *schema_entry = g_new0(StatsSchemaValueList, 1); + + schema_entry->value = g_new0(StatsSchemaValue, 1); + schema_entry->value->type = STATS_TYPE_CUMULATIVE; + schema_entry->value->name = g_strdup(name); + schema_entry->next = list; + + return schema_entry; +} + +static void cryptodev_backend_schemas_cb(StatsSchemaList **result, + Error **errp) +{ + StatsSchemaValueList *stats_list = NULL; + const char *sym_stats[] = {"sym-encrypt-ops", "sym-decrypt-ops", + "sym-encrypt-bytes", "sym-decrypt-bytes"}; + const char *asym_stats[] = {"asym-encrypt-ops", "asym-decrypt-ops", + "asym-sign-ops", "asym-verify-ops", + "asym-encrypt-bytes", "asym-decrypt-bytes", + "asym-sign-bytes", "asym-verify-bytes"}; + + for (int i = 0; i < ARRAY_SIZE(sym_stats); i++) { + stats_list = cryptodev_backend_schemas_add(sym_stats[i], stats_list); + } + + for (int i = 0; i < ARRAY_SIZE(asym_stats); i++) { + stats_list = cryptodev_backend_schemas_add(asym_stats[i], stats_list); + } + + add_stats_schema(result, STATS_PROVIDER_CRYPTODEV, STATS_TARGET_CRYPTODEV, + stats_list); +} + static void cryptodev_backend_class_init(ObjectClass *oc, void *data) { @@ -456,6 +594,9 @@ cryptodev_backend_class_init(ObjectClass *oc, void *data) cryptodev_backend_get_ops, cryptodev_backend_set_ops, NULL, NULL); + + add_stats_callbacks(STATS_PROVIDER_CRYPTODEV, cryptodev_backend_stats_cb, + cryptodev_backend_schemas_cb); } static const TypeInfo cryptodev_backend_info = { diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index cda52c2526..dda69a1098 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1883,6 +1883,8 @@ static StatsFilter *stats_filter(StatsTarget target, const char *names, filter->u.vcpu.vcpus = vcpu_list; break; } + case STATS_TARGET_CRYPTODEV: + break; default: break; } @@ -1954,6 +1956,9 @@ void hmp_info_stats(Monitor *mon, const QDict *qdict) int cpu_index = monitor_get_cpu_index(mon); filter = stats_filter(target, names, cpu_index, provider); break; + case STATS_TARGET_CRYPTODEV: + filter = stats_filter(target, names, -1, provider); + break; default: abort(); } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index bf22a8c5a6..dd31936f6a 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -385,6 +385,8 @@ static bool invoke_stats_cb(StatsCallbacks *entry, targets = filter->u.vcpu.vcpus; } break; + case STATS_TARGET_CRYPTODEV: + break; default: abort(); } diff --git a/qapi/stats.json b/qapi/stats.json index 57db5b1c74..f9dec18066 100644 --- a/qapi/stats.json +++ b/qapi/stats.json @@ -50,10 +50,14 @@ # # Enumeration of statistics providers. # +# @kvm: since 7.1 +# +# @cryptodev: since 8.0 +# # Since: 7.1 ## { 'enum': 'StatsProvider', - 'data': [ 'kvm' ] } + 'data': [ 'kvm', 'cryptodev' ] } ## # @StatsTarget: @@ -65,10 +69,12 @@ # # @vcpu: statistics that apply to a single virtual CPU. # +# @cryptodev: statistics that apply to a crypto device. +# # Since: 7.1 ## { 'enum': 'StatsTarget', - 'data': [ 'vm', 'vcpu' ] } + 'data': [ 'vm', 'vcpu', 'cryptodev' ] } ## # @StatsRequest: From patchwork Sun Jan 29 02:57:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13120009 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 C2B57C38142 for ; Sun, 29 Jan 2023 02:59:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLxu5-0004dQ-Eh; Sat, 28 Jan 2023 21:58: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 1pLxu3-0004Uc-Ik for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:47 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLxu1-0008Jn-E5 for qemu-devel@nongnu.org; Sat, 28 Jan 2023 21:58:47 -0500 Received: by mail-pl1-x635.google.com with SMTP id d3so8471372plr.10 for ; Sat, 28 Jan 2023 18:58:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; 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=JBPxArb+accoiQR79WRA7abVrBow9EEKwkZ30aFdDp4=; b=rg4SVt83O26E46i6aR0xcklvd2l8wgucQ8rakiKzHiJwv9pCTJlyGZ5o9si1kx7Ydn qKgs7NNd3of/B/EwVjXMh6GWuu6wphw8qvl28sbX7N56SEc6o7z3ImvgwYbS7sop+P+Q NTUOnB+m9ZjKA3SWg+9FwGCnCSMUIrTtHKCWdhI4mtjBgFW8mDQ8gR6Xy4px1mFfwBmA qDXVE4JAXnMxsYgNtvLFEpUI6xAnP+MmI9j6mZ8jxrzIMcMX2AIq60mshiKtX6bYkJL5 3U+93Rl6F604iPVBtAburc1DhVHEUkq6ahTed5NX3H6qM5k+eQPo1tmI99OHNmtLvjyL h8Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JBPxArb+accoiQR79WRA7abVrBow9EEKwkZ30aFdDp4=; b=DueAniIzG9ZNPLLwt6x1MikaRZvHDjTHj46QEcCVWmJMGYV5s5zYoVuF2wiMi/Uow3 YE+e390B2apDq9iRTW6KDaV6gtcnfxHWV/uhHwfzshsyRwEqqVmKLGle3UTW0gmmNWdH 4Zj3L88yqGEqyIdmei3QcV/dhPVM+MGATDdkpfOf0xPfq9xZ2Ju6MKdv6R+r2asuiAh/ esBz/s+dPgGW7loTXvGkYC7sNkDXhusaMeGdKxXs4Y5j65PBUKs95Y3K2gZvJQpfLmN3 +cgQymTsBO/dqPcYWeq/czXvewGTpwFXHiyUaKTsMkoawsQ4NIsp3BNfw9VPikUOKOfh fv1g== X-Gm-Message-State: AFqh2kpmx03ZmMEP0vs/XsANFOneW9VDp6TmhTs1TwwU/r/Ex+r5/95q USaC77fBt3beJSO+UxTnoe45UA== X-Google-Smtp-Source: AMrXdXtm93Xlrm1d5/a0kU/AoLU9aUsmOgAUjTQuAb9k3z1QpR792f6fxbHmCCrV9TnoxlsjxW4Nvg== X-Received: by 2002:a17:902:bd97:b0:193:c79:657a with SMTP id q23-20020a170902bd9700b001930c79657amr44099960pls.5.1674961117991; Sat, 28 Jan 2023 18:58:37 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id x4-20020a170902ea8400b00194c90ca320sm5167084plb.204.2023.01.28.18.58.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Jan 2023 18:58:37 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v4 12/12] MAINTAINERS: add myself as the maintainer for cryptodev Date: Sun, 29 Jan 2023 10:57:47 +0800 Message-Id: <20230129025747.682282-13-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230129025747.682282-1-pizhenwei@bytedance.com> References: <20230129025747.682282-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x635.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_PASS=-0.001 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 I developed the akcipher service, QoS setting, QMP/HMP commands and statistics accounting for crypto device. Making myself as the maintainer for QEMU's cryptodev. Cc: Gonglei Signed-off-by: zhenwei pi --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9f6c54b145..e21a6ee470 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2857,6 +2857,7 @@ T: git https://gitlab.com/ehabkost/qemu.git machine-next Cryptodev Backends M: Gonglei +M: zhenwei pi S: Maintained F: include/sysemu/cryptodev*.h F: backends/cryptodev*.c