From patchwork Fri Nov 11 06:45:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039746 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 AE745C4332F for ; Fri, 11 Nov 2022 06:49:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNpA-0006as-4h; Fri, 11 Nov 2022 01:47:36 -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 1otNoo-0006Up-KC for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:18 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNok-0008Di-OU for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:13 -0500 Received: by mail-pj1-x1033.google.com with SMTP id l6so3714106pjj.0 for ; Thu, 10 Nov 2022 22:47:10 -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=upOk1cGisgMNYeCZpXZKpnoG2v3kRWP3UR8ECMzDAoM=; b=w6ul19p/lyL1NaIR/HKmUw5YkVI+dZfLDSxo7j9NQBerDPMSW0QkYkBHXo/gF9ON5z 9yo3WC/4HicWMOIU0oZpLqjjL7SWsFaZQG4Y+po3LkmNht2q9ex8rDUVZDrio6UPSkDg kqEH6nJPjyBYc71nbnZJj81Uh7bIP97e/QQqRFTqFe1wyBlZ1wcYjWKW4vJT4A9dIPzv Gq0ZxQ6PB4WqvF1jIic+aolgLkvCWpVDT9Y1yVddawRH2K7uqGkaKa6Q62TbeLrW9tfI cA0MXe/A56dHIiDmRsbRJEouMqXqk+hceP4Er4dYC36iAfIf3A2PEsEJcL6Id5k+zzsN 66zQ== 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=upOk1cGisgMNYeCZpXZKpnoG2v3kRWP3UR8ECMzDAoM=; b=kDEvcx76pBNSf2z+Z8t8kYaW2Lh7vrqjU5jM2J/fOLXQuFF677cX4ecMhwaDtjE98V tOdwP6vvg6S+EkufDT6D7cRumBvzoMJRFQPcr3o1VFvujShu76zdiqnE3KOp34IW8Ksn D432DCgtqLEG0hs3drYvMNwb8gm2n131ZCshJ8pRsyDFHNkjKQHgNveh034RnjbVSq6A NTBtxom0TH7oolYHoIONfGtdtb0yW3Wf8jCN1/vC7tq5bLFdMzzq8wbm0uW/t69+hcUT K4PbxHYGB0llCiKd2P6uZlzoAIqvMGaQesrDv08KYnELwrqmC/A7vRmSjp9zPL1GOulg rAyQ== X-Gm-Message-State: ANoB5pmV+FW7RIg0jyz3LLYcbW9GConUusltAbRcWBpnkb61G/lNNgJ8 RSz1H+YCxey7mG1j7mWR/QNNog== X-Google-Smtp-Source: AA0mqf40f8JCcLTx3gJ7pJvwqCJhhXR5NxcgYDaC/ZaMQmv3bHt+dfXImNmnwllmcUsgFWK+dUTCzw== X-Received: by 2002:a17:903:41d0:b0:188:5e78:be0 with SMTP id u16-20020a17090341d000b001885e780be0mr1313747ple.18.1668149229103; Thu, 10 Nov 2022 22:47:09 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:08 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 1/8] cryptodev: Introduce cryptodev.json Date: Fri, 11 Nov 2022 14:45:46 +0800 Message-Id: <20221111064553.246932-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1033.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'. 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 caba73ec41..3f698cb0e9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2830,6 +2830,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 bc13e466b4..0715014552 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 9a36c15c04..b5069f34f8 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 Fri Nov 11 06:45:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039758 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 6EF3CC43217 for ; Fri, 11 Nov 2022 06:57:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNp2-0006Xd-64; Fri, 11 Nov 2022 01:47: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 1otNoq-0006V1-MB for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:18 -0500 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNoo-0008E6-RX for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:16 -0500 Received: by mail-pf1-x429.google.com with SMTP id k22so4154116pfd.3 for ; Thu, 10 Nov 2022 22:47:13 -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=4CdbmP/FiE6kgxBu7MfFEjij+I+GqUpVV/I8WAQPEbM=; b=Dq9vGw2Eg6fhEJOVvNPr2Z8Y/tie2EZe7lqozp0f7tz1nun/thwFfRMQbjGlMNmMB2 1CfFF1zznDLbn0df+BPKv8vAfN+/48JYbHqgorGiX2PF84YzWLdpaPQHpfSVZkzZOXOV beToxjrDx64K9dfmZQkKyS+RXFqf27n3DXwp5RFE1vahUpwZI9B0V4SHqPbvwY77u252 Oxtr1oC5LtTIR5eh/W4ZHCmH8UVP+0iDa7O4SRHspzepakD614Ty2uRtZgtt7RA+L1k6 uYZMeewBW98o3YA5lQZyYfxVLIFMKUxOGsvAYj0QQZurSlw2Z78eodBWJ4qfkoQ13EFr yLZg== 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=4CdbmP/FiE6kgxBu7MfFEjij+I+GqUpVV/I8WAQPEbM=; b=Z+Z7n+zPGcgJHveQjaY9OiyHv34q4U212JD1fU7UCZ0ZwukS0zMUtqJuBw50S1Xoy0 /Pm0eFNqgEUSJXhanvIjIlNdYf7OuxcT/W9mPEeEicySFCbzdvyuBkJUPkDgLuQJzG44 w8hGRc22Gk5tEQx8pzeLMt8uYdKTtdlryFTqSAujuqBcmeoVv9QjC+Ug/4LZ6e9T6Om8 B1AdNYr5UZkucyFF8jVIaOrgtDQZUMnen6stxPmXpIaupDzwbYVWreBU1SNrRh7sBw+0 9RpEZKR+i1Ir4Uja0nQhs6q+TLWfwQpfHMMFHU4P1k8+Lq9LimPG1Q2iQ/NEUXLYEY4z eSvw== X-Gm-Message-State: ANoB5pn14GbhqvbyVwuT2b6PROmD2l61JqZftgnjkKRuJIj4m2niupk5 XTABcMOVaxQat8nfH/yP9SCEZA== X-Google-Smtp-Source: AA0mqf41Lfth+kZ4oVj/Z67Mu8iENf1i/esBybH8+7PexMOwQXOwbJbF0aoMFS+ZKKTw092wzq2nag== X-Received: by 2002:a65:5541:0:b0:470:1e64:f586 with SMTP id t1-20020a655541000000b004701e64f586mr500650pgr.249.1668149232580; Thu, 10 Nov 2022 22:47:12 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:12 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 2/8] cryptodev: Remove 'name' & 'model' fields Date: Fri, 11 Nov 2022 14:45:47 +0800 Message-Id: <20221111064553.246932-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x429.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. 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 Fri Nov 11 06:45:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039742 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 47686C433FE for ; Fri, 11 Nov 2022 06:48:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNp3-0006ZF-8B; Fri, 11 Nov 2022 01:47:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otNoy-0006W8-RB for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:26 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNos-0008EQ-Hn for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:24 -0500 Received: by mail-pf1-x433.google.com with SMTP id z26so4163372pff.1 for ; Thu, 10 Nov 2022 22:47: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=5b3RVuXlvvZql99mll6PolNwr4wkN22sgLcd1hY141Y=; b=4bEQxvY/GyZpqN4PbR5RK3896/kp1zGT4rQUixV69ebj4OJVObK6xQKHlz+woXg7q+ GFhDT28Z9Xkz4bKZD8WIQk7F9oYkHpOaE+5STKxrsEsv1AniPs3yLZXwfOMcbRq/DM0f k4dcRDWdmWnZjNUTecsJs3DRLYL+V/fyQYoSjhcxsjALoIih5efe/h4f1lBOrG7bp9Qt oByQ4p9Ho9fhSEUpkQRMVXjyA/QDOHAMLG0SFKMsXCrihCiSnIhrpUfYgy+8xo8GgKsa /bPQDKzJ02Mj1EuGWK1HnvYXSxxTwfnDaczErNySXhI/+eghCrItFFLlPE1U2MzXv+qk 58xg== 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=5b3RVuXlvvZql99mll6PolNwr4wkN22sgLcd1hY141Y=; b=zUGck1XCA1dd8ZcN9NdV1vM2cOFFen3wMR/R+cS9BL6vpIHg29CbmdO2yKhpdeg/I1 JAMYKsb5mlfuYiq3J3fGvHyawjeT0D4Fss/H99UWItftjDq+qBOORpFSHMuqkJPp/MrG YLO1q88JAME1AS9D5vLnsr4JXQJUUhb5Sh/0wlORp5nj+AGsoD0IUgMGuz1Vk8un+qt8 6JGAsu6H3X6yJclSE6O/7h7xO3ENZErrPjDun++fcrgfQvowxjXOsj/woxgu8ggnPy7q mcnuZPVo8bh/jHBpQG9gYj62KRxCmZybdUa2a4CfuZNyWrjMZnlCMBdohjUlWZp+MsLP XUQA== X-Gm-Message-State: ANoB5pluUxjH9NUtcHD99ZyH0AYEDCafBK+BMIT83PxKZcaEwi8uSu5F a89p3bWKqViuG3CP2Hb+tU7NMA== X-Google-Smtp-Source: AA0mqf791CqA6StnJcZDrJK55uxWBYANXXvJj/v/fpiDniXWvDVEg2pJykEL7Ct5m4YifzGaWa3LRg== X-Received: by 2002:aa7:9839:0:b0:56b:d363:a31b with SMTP id q25-20020aa79839000000b0056bd363a31bmr1198312pfl.78.1668149236045; Thu, 10 Nov 2022 22:47:16 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:15 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 3/8] cryptodev: Introduce cryptodev alg type in QAPI Date: Fri, 11 Nov 2022 14:45:48 +0800 Message-Id: <20221111064553.246932-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_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. 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..5fb7b8f43f 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; + enum 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..919bf05b75 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; + enum 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..d3caded920 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; + enum 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 97da74e719..e0a7e2cbd8 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..f68a4baf13 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; + enum 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 Fri Nov 11 06:45:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039744 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 DCA3EC433FE for ; Fri, 11 Nov 2022 06:49:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNp4-0006ZL-PO; Fri, 11 Nov 2022 01:47:34 -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 1otNoy-0006W7-RB for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:26 -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 1otNow-0008Ek-S0 for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:24 -0500 Received: by mail-pj1-x1032.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so3983366pji.0 for ; Thu, 10 Nov 2022 22:47:20 -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=YmrV4HXUD+cr3ZkF2B4NOpr4JL1AftClmiGHOy+sBW8=; b=6YzjxH1gk2p68f8uZ7C7Bi+7W4Gd8LQ+3ppOOfVdzSExCDYUApP15Nr4sUnK8+XDjK YFV9KpazxhsNGeZ92D8FxKP3UNzu8Y7jJtprXVWnuwxZ2Qqs29cIuq46xu/IL4N53bqE 7og7q5yOgOL1WtOG/+NVVmzYAOY1IcCOQItQowWRBJCxbHeKwAmt9kxaYKkttYXT7mYk Zrj7VHHE51L/H1uWa/NpbsST1ZyK4PnO26OltnrZfpuokkfOIlPI1GcJZBHtECBvG1Fr OGajyQ2tawSPmn5Ix9Zg3eZG9whFb71SLIKRc4C/SvbGH3azcVXlg+c83WLLAJBYslCd mi9g== 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=YmrV4HXUD+cr3ZkF2B4NOpr4JL1AftClmiGHOy+sBW8=; b=i0iAIZzXWX5B/ps06qjrUAftZT4i4DrPAwm5KLpQUr07UUeBRpMuGWVafZgr/Hv+qF l6xiqVTQ8BpdUbWSzkx3w1J3LDJNTGOvMEc0eTj9Qe2y3FnHY9IXgnK70UoeO+E0em+L v1qRpao4Acgc/uJ0IaEmZ8r2oEESFPqaIZefgVivBM07cwLcdnwidPrfbebu4o7lR9zk g4AJ6gBNRJofZXLT51UMKr+8xI6JVOiCHxqxUC8kI4WmxHwZv7Jl3GNsVnFVpxqaMvVa tYPguf9dJoZGV/mEfe9tHIwPgKSToDcbWyVZnIjwq3oohKG5VT9J3lDc6CmRdNf2qP9u zyvA== X-Gm-Message-State: ANoB5pkxNOXebhPenBIYEXGI35fGp+aTgGLmsRvjBe7JrWYRjrm9g99s l+El130Ehi+dblbQXuDFxHGEIQ== X-Google-Smtp-Source: AA0mqf62DzD7avNc5acIT6P2uWjPxXOJ6GmQNDOAcJeTJl1/rLKCgow7ONZTRplhQ0fv6R/5UWi9Nw== X-Received: by 2002:a17:90b:280b:b0:213:7d3d:a769 with SMTP id qb11-20020a17090b280b00b002137d3da769mr490551pjb.22.1668149239475; Thu, 10 Nov 2022 22:47:19 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:19 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 4/8] cryptodev: Introduce server type in QAPI Date: Fri, 11 Nov 2022 14:45:49 +0800 Message-Id: <20221111064553.246932-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-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 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. 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 5fb7b8f43f..4987abb7d6 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 919bf05b75..31ec712849 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 e0a7e2cbd8..87d9582bc1 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 Fri Nov 11 06:45:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039743 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 6CECCC4332F for ; Fri, 11 Nov 2022 06:48:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNpF-0006dH-Ir; Fri, 11 Nov 2022 01:47:41 -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 1otNpD-0006cn-S9 for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:39 -0500 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNoy-0008FK-Az for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:39 -0500 Received: by mail-pl1-x634.google.com with SMTP id l2so3508991pld.13 for ; Thu, 10 Nov 2022 22:47: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=TlcaU38pdb3CtWEh3sr5SMbpseSZUCKSQHY6AQe8NOY=; b=Waw6F4ERLtitFcl3841EyuKb7ief+RC8M7ShiuPypYX5hAEYCY3Bp6nJQmrv18hJKX iHqHZke0TDuoSAF0QJJN5To55DrTRRGnoR0qoKJJwXVG1d/PKamxBLbRALiQ7s1T/P7H VtWU72Twpuh2+UbT16N+XWQtZTZrKGKAl+fdm9Cy3QWgGDyXRDh0DNDg5jhvoUxiXrje 4EPwoEGGRUyZum0dvEAgzcszcGJYaYx0BFDZIhVxI1dvB3d/ahpBLsd01LXBlTJKFtig cyoUqblgdUt3iW4LGGpoafh8dozJ49l8w+jU6l+p8Mb/kIdmRnyG8DTa4NmAUadXqnSD Rrdg== 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=TlcaU38pdb3CtWEh3sr5SMbpseSZUCKSQHY6AQe8NOY=; b=CJQM0v8akA3GG9vJ48JsNcEZ87iCMkwrXTt1ez4fO0LvU3R3HfjO9wgXj7XhpNr1OO 0ZDQJcAikIsWZTze+j528JS3aEb7UW+tWgYnykmBU29m55R4i75v7fKJOeeqwTF1bfqu W7vFeb1Vm4SDM5m44qqMXIQdBabrT4KC04keCRc/IFpo83CBGwDJ2ASNkrMhJcSCVSv4 nIkuSNlbPb+2SYhIuLgX5N2jQsrSh1uUxsarFhtLYE4SICEK6AWTcnkhufYUeT/hQaeP cMFJAM+FHhwWbL39wukrqOzQv5z+6+cxzkh9rKYFbFzLZKRT02Jbh95kFVa4nL+fAMPJ lgAA== X-Gm-Message-State: ANoB5pltTVeof3Hn+Ypj5ufWwlI5LNCljgTkdth3hSvRTj53Jv2FvLk/ W+L8AdvRNg5RQ+HHWQwcmfUYJA== X-Google-Smtp-Source: AA0mqf4OkzTp8O98cri+hCRpo06eJbZ8u4yoKrj14I0VTtAKM2I7iWG/ahz7yPjR6qxxX8WCk/hbOA== X-Received: by 2002:a17:903:248b:b0:186:898a:f33d with SMTP id p11-20020a170903248b00b00186898af33dmr1366483plw.33.1668149242897; Thu, 10 Nov 2022 22:47:22 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:22 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 5/8] cryptodev: Introduce 'query-cryptodev' QMP command Date: Fri, 11 Nov 2022 14:45:50 +0800 Message-Id: <20221111064553.246932-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x634.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_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", "info": "cryptodev-builtin0" } ] }, { "service": [ "akcipher" ], "id": "cryptodev0", "client": [ { "queue": 0, "type": "lkcf", "info": "cryptodev-lkcf0" } ] } ], "id": "libvirt-415" } Signed-off-by: zhenwei pi --- backends/cryptodev.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ qapi/cryptodev.json | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index d3caded920..bf2f3234c9 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,54 @@ static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; +static int qmp_query_cryptodev_foreach(Object *obj, void *data) +{ + CryptoDevBackend *backend; + CryptodevInfoList **infolist = data; + uint32_t services; + + if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) { + return 0; + } + + CryptodevInfo *info = g_new0(CryptodevInfo, 1); + info->id = g_strdup(object_get_canonical_path_component(obj)); + + backend = CRYPTODEV_BACKEND(obj); + services = backend->conf.crypto_services; + for (uint32_t i = 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) { + if (services & (1 << i)) { + QAPI_LIST_PREPEND(info->service, i); + } + } + + for (uint32_t i = 0; i < backend->conf.peers.queues; i++) { + CryptoDevBackendClient *cc = backend->conf.peers.ccs[i]; + CryptodevBackendClient *client = g_new0(CryptodevBackendClient, 1); + + client->queue = cc->queue_index; + client->type = cc->type; + if (cc->info_str) { + client->has_info = true; + client->info = strdup(cc->info_str); + } + QAPI_LIST_PREPEND(info->client, client); + } + + QAPI_LIST_PREPEND(*infolist, info); + + return 0; +} + +CryptodevInfoList *qmp_query_cryptodev(Error **errp) +{ + CryptodevInfoList *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..4cc4f4f0ed 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -43,3 +43,46 @@ { 'enum': 'QCryptodevBackendType', 'prefix': 'QCRYPTODEV_BACKEND_TYPE', 'data': ['builtin', 'vhost-user', 'lkcf']} + +## +# @CryptodevBackendClient: +# +# Information about a queue of crypto device. +# +# @type: the type of the crypto device +# +# @info: the additional infomation of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'CryptodevBackendClient', + 'data': { 'queue': 'int', + 'type': 'QCryptodevBackendType', + '*info': 'str' } } + +## +# @CryptodevInfo: +# +# Information about a crypto device. +# +# @service: supported service types of a crypto device +# +# @client: the additional infomation of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'CryptodevInfo', + 'data': { 'id': 'str', + 'service': ['QCryptodevBackendServiceType'], + 'client': ['CryptodevBackendClient'] } } + +## +# @query-cryptodev: +# +# Returns information about current crypto devices. +# +# Returns: a list of @CryptodevInfo +# +# Since: 8.0 +## +{ 'command': 'query-cryptodev', 'returns': ['CryptodevInfo']} From patchwork Fri Nov 11 06:45:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039747 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 B7790C4332F for ; Fri, 11 Nov 2022 06:50:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNpC-0006cM-LB; Fri, 11 Nov 2022 01:47:38 -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 1otNp3-0006ZA-3J for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:29 -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 1otNp1-0008Ek-47 for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:28 -0500 Received: by mail-pj1-x1032.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so3983563pji.0 for ; Thu, 10 Nov 2022 22:47:26 -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=oegg7BK5065V6mlSTrWcn4r0kskoFmAwsjwPQknjsec=; b=U1yoA2d0EzDgiwjxxPjzrGnbhWky7/1N4ZykB2TFok1rVRfMo/61kQHZ3Aw2E7gqyl hK90jdybDE7RD9EQvP1BswXF4vIi2Js5FCNjwq1haoCB7pGf5Ke2ezxjgNkzkbi1/MxZ zrY+XZd2zxwHcMp1NUKFapju1veVH2jucY80zFaz5dmV+fNPSvvH2CcLi9orma1rbiDo wP37iQQa01Y2uD0d2au11mT/oI814gNnd6PSFkbiQZr7nC1PmWzKUNMOyuNNMvOdYyTE JMUz9aYODzy2i23nui06jA1BIhfiGzPq2s/R69M58DO0ZtbmGRNJq4z1SjGBaDzC/oB7 HR+w== 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=oegg7BK5065V6mlSTrWcn4r0kskoFmAwsjwPQknjsec=; b=TMW4Uzob+37DSlnw+v5VTalcUIVMJgESJVQNeiwAJ3amdUimnAXAnLS2MiT+HqwkMd t6Mrh0n8Vg6N9GKm6A1aSpizjlGa0++rBV3KSEbxAKY427dbCmIUJ5XIyozzSWOK0j7F 0Ses45qc6q+yFL+wRZo9J5nJxkTk3Oo25Wu0UVKOL4kyKaD6ProGkovfr4OeiDN+/eJx VWvCisPXA5eI5SiNe0Qr3ao7H+hdpEIGJRQ9gWvM5miLVJlQE/4nCrzwU/7MW3iXNAH4 Sej3NebdKzFotIWfvhE45hZxu2/McAakLAlu6Yr+pT4BC0l6puwt9dD0Hi3DRdiDLKT1 b+Uw== X-Gm-Message-State: ANoB5pmKMGvb0SASVACAvtIG9UOzHK09IBYrv0unyf0YVByxiOPHxpjo sUIl4s+xGiwoAovh9/eyVBCogg== X-Google-Smtp-Source: AA0mqf455cWZJCAzw5cdkGfIRqhuKZKbSe8TGtbLnRCG39zT9hQgww2ugE0ylqr5IMRg8BGf3Q0a1Q== X-Received: by 2002:a17:902:db01:b0:186:6d69:6e01 with SMTP id m1-20020a170902db0100b001866d696e01mr1135444plx.160.1668149246354; Thu, 10 Nov 2022 22:47:26 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:25 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 6/8] cryptodev: Support statistics Date: Fri, 11 Nov 2022 14:45:51 +0800 Message-Id: <20221111064553.246932-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-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 Introduce cryptodev statistics in QAPI, and record OPS/Bandwidth for each crypto device. Example of this feature: virsh qemu-monitor-command vm '{"execute": "query-cryptodev"}' | jq { "return": [ { "service": [ "akcipher", "mac", "hash", "cipher" ], "asym-stat": { "encrypt-ops": 0, "verify-bytes": 0, "sign-ops": 0, "verify-ops": 0, "sign-bytes": 0, "decrypt-bytes": 0, "decrypt-ops": 0, "encrypt-bytes": 0 }, "sym-stat": { "encrypt-ops": 40, "decrypt-bytes": 5376, "decrypt-ops": 40, "encrypt-bytes": 5376 }, "id": "cryptodev1", "client": [ { "queue": 0, "type": "builtin", "info": "cryptodev-builtin0" } ] }, { "service": [ "akcipher" ], "asym-stat": { "encrypt-ops": 54, "verify-bytes": 8704, "sign-ops": 17, "verify-ops": 34, "sign-bytes": 340, "decrypt-bytes": 9215, "decrypt-ops": 36, "encrypt-bytes": 13294 }, "id": "cryptodev0", "client": [ { "queue": 0, "type": "lkcf", "info": "cryptodev-lkcf0" } ] } ], "id": "libvirt-424" } Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 8 ++++- backends/cryptodev-lkcf.c | 1 + backends/cryptodev.c | 37 +++++++++++++++++++++-- include/sysemu/cryptodev.h | 30 +++++++++++++++++++ qapi/cryptodev.json | 58 +++++++++++++++++++++++++++++++++++- 5 files changed, 130 insertions(+), 4 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 4987abb7d6..a548c66e39 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -95,6 +95,9 @@ static void cryptodev_builtin_init( backend->conf.max_cipher_key_len = CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_LEN; backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; + backend->sym_stat = g_new0(QCryptodevBackendSymStat, 1); + backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1); + cryptodev_backend_set_ready(backend, true); } @@ -433,6 +436,7 @@ static int cryptodev_builtin_close_session( } static int cryptodev_builtin_sym_operation( + CryptoDevBackend *backend, CryptoDevBackendBuiltinSession *sess, CryptoDevBackendSymOpInfo *op_info, Error **errp) { @@ -458,12 +462,14 @@ static int cryptodev_builtin_sym_operation( if (ret < 0) { return -VIRTIO_CRYPTO_ERR; } + QCryptodevSymStatIncEncrypt(backend, op_info->src_len); } else { ret = qcrypto_cipher_decrypt(sess->cipher, op_info->src, op_info->dst, op_info->src_len, errp); if (ret < 0) { return -VIRTIO_CRYPTO_ERR; } + QCryptodevSymStatIncDecrypt(backend, op_info->src_len); } return VIRTIO_CRYPTO_OK; @@ -551,7 +557,7 @@ static int cryptodev_builtin_operation( sess = builtin->sessions[op_info->session_id]; if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) { sym_op_info = op_info->u.sym_op_info; - status = cryptodev_builtin_sym_operation(sess, sym_op_info, + status = cryptodev_builtin_sym_operation(backend, sess, sym_op_info, &local_error); } else if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) { asym_op_info = op_info->u.asym_op_info; diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 31ec712849..609a39bb7e 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -233,6 +233,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp) 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; lkcf->running = true; + backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1); QSIMPLEQ_INIT(&lkcf->requests); QSIMPLEQ_INIT(&lkcf->responses); diff --git a/backends/cryptodev.c b/backends/cryptodev.c index bf2f3234c9..b93b1d25f2 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -48,6 +48,18 @@ static int qmp_query_cryptodev_foreach(Object *obj, void *data) info->id = g_strdup(object_get_canonical_path_component(obj)); backend = CRYPTODEV_BACKEND(obj); + if (backend->sym_stat) { + info->has_sym_stat = true; + info->sym_stat = g_memdup2(backend->sym_stat, + sizeof(QCryptodevBackendSymStat)); + } + + if (backend->asym_stat) { + info->has_asym_stat = true; + info->asym_stat = g_memdup2(backend->asym_stat, + sizeof(QCryptodevBackendAsymStat)); + } + services = backend->conf.crypto_services; for (uint32_t i = 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) { if (services & (1 << i)) { @@ -111,6 +123,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( @@ -171,8 +186,26 @@ int cryptodev_backend_crypto_operation( CryptoDevBackendOpInfo *op_info = &req->op_info; enum QCryptodevBackendAlgType algtype = req->flags; - if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) - && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { + /* symmetric statistics need to be recorded in driver */ + if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) { + CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info; + switch (op_info->op_code) { + case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT: + QCryptodevAsymStatIncEncrypt(backend, asym_op_info->src_len); + break; + case VIRTIO_CRYPTO_AKCIPHER_DECRYPT: + QCryptodevAsymStatIncDecrypt(backend, asym_op_info->src_len); + break; + case VIRTIO_CRYPTO_AKCIPHER_SIGN: + QCryptodevAsymStatIncSign(backend, asym_op_info->src_len); + break; + case VIRTIO_CRYPTO_AKCIPHER_VERIFY: + QCryptodevAsymStatIncVerify(backend, asym_op_info->src_len); + break; + default: + return -VIRTIO_CRYPTO_NOTSUPP; + } + } else if (algtype != QCRYPTODEV_BACKEND_ALG_SYM) { error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); return -VIRTIO_CRYPTO_NOTSUPP; } diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index f68a4baf13..c154c52039 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -252,8 +252,38 @@ 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 4cc4f4f0ed..f01f2d017a 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -60,6 +60,60 @@ 'type': 'QCryptodevBackendType', '*info': 'str' } } +## +# @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' } } + ## # @CryptodevInfo: # @@ -74,7 +128,9 @@ { 'struct': 'CryptodevInfo', 'data': { 'id': 'str', 'service': ['QCryptodevBackendServiceType'], - 'client': ['CryptodevBackendClient'] } } + 'client': ['CryptodevBackendClient'], + '*sym-stat': 'QCryptodevBackendSymStat', + '*asym-stat': 'QCryptodevBackendAsymStat' } } ## # @query-cryptodev: From patchwork Fri Nov 11 06:45:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039756 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 5D9D9C433FE for ; Fri, 11 Nov 2022 06:52:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNpC-0006bz-1m; Fri, 11 Nov 2022 01:47:38 -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 1otNpA-0006bG-A1 for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:36 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNp8-0008Hw-Nq for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:36 -0500 Received: by mail-pl1-x62d.google.com with SMTP id v17so3555180plo.1 for ; Thu, 10 Nov 2022 22:47:30 -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=O2Pju8ej4HqpDpyXMdvM9rPS2/OxpZbKPNF6rcjhplM=; b=QKOTzlkb85CmuxquvzSVVv/w/JnsMWNtZ5YX93d5ERKjt0AAIWwzFzdpvRXb+BnrLR ikLao7ambBtJrG9zsbx6C3Sz4+TUPVmR25l1RBp8IMDQzFMGs9G23Q9czf1Kh9W6Y1y5 7tfK699+xB3W9CBSsmVLQ6HT/lklz73PFx9HA0RNJGwHa243fCfvD7hc3S6T0cvVRjUo A8UYqSbSIxhDzwH58tz5r151yJmTfr975lCdMiATaRJOVWrMlFZDw5zRc/mXzdO8CSTr xfcYdP0A6EgpSl7Ophvh05jxHs+D6AfLN4u63/sBVIaAyeUBT/FgdVtYwyllWSvVTudq 4Y3w== 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=O2Pju8ej4HqpDpyXMdvM9rPS2/OxpZbKPNF6rcjhplM=; b=pzAz4tWDDISpEE4lh/1pXqJChFDDr6oZOUjO2Odp9WBbxLM2h+FhCJE4laH8EwGSym f592chB+7feSPBnNerUqxd7onbrsmtbkroFWNleri3nsdBz1dcoECAo0Idjix2AsxB3F TgXwj+tB4u3iVGQCZegalAcKcfAeLv0oQuHbAq7Pojddh0Llv0sp+vsw/ZRw7Y4nTJEW yMNjtwAOHMse6F+QdQ/U3ne7ULeCYhiwAlX4a/J/+6opjFREpQiRqddDOjDRJFVBGJ7L oUMljj0/cq2kiQgiBlB9olT8wIgNiI/feqKXZSHsPWpVK193WHRZKGhCGEs8hn0br3qk 7C5A== X-Gm-Message-State: ANoB5pmkID3BVSCVPNOo7J0Sv/UbshCkO81XbItZJQR+7hajsM2wXknw xVQr+RiNGKl7bNl8f9glBQO6+w== X-Google-Smtp-Source: AA0mqf4+aKHxgzk4IWqAF1etpHrCWr60fv9xAIETKRktFLXwF8BaGMtKlx2Ocyq2NkwE6qnwxrEy9w== X-Received: by 2002:a17:90b:4ccf:b0:212:dc2f:b987 with SMTP id nd15-20020a17090b4ccf00b00212dc2fb987mr410557pjb.173.1668149249833; Thu, 10 Nov 2022 22:47:29 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:29 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 7/8] cryptodev-builtin: Detect akcipher capability Date: Fri, 11 Nov 2022 14:45:52 +0800 Message-Id: <20221111064553.246932-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62d.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. Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index a548c66e39..9e94d2bfcc 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -59,6 +59,25 @@ struct CryptoDevBackendBuiltin { CryptoDevBackendBuiltinSession *sessions[MAX_NUM_SESSIONS]; }; +static void cryptodev_builtin_init_akcipher(CryptoDevBackend *backend) +{ + QCryptoAkCipherOptions opts; + bool supported = false; + + 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; + supported = true; + } + + if (supported) { + backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1); + } +} + static void cryptodev_builtin_init( CryptoDevBackend *backend, Error **errp) { @@ -81,11 +100,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 @@ -96,7 +113,7 @@ static void cryptodev_builtin_init( backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; backend->sym_stat = g_new0(QCryptodevBackendSymStat, 1); - backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1); + cryptodev_builtin_init_akcipher(backend); cryptodev_backend_set_ready(backend, true); } From patchwork Fri Nov 11 06:45:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039757 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 670A7C433FE for ; Fri, 11 Nov 2022 06:54:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNpD-0006cl-Oz; Fri, 11 Nov 2022 01:47:39 -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 1otNpA-0006bI-Fh for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:36 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNp8-0008IF-PP for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:36 -0500 Received: by mail-pg1-x52a.google.com with SMTP id q1so3688902pgl.11 for ; Thu, 10 Nov 2022 22:47:34 -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=LIesySo8KfoPYYuDv0hxnDo5m8+fU1mYrZHcG45Uhwg=; b=DvxJSz3/wEEDnYyPM11np5qTIqJRVVKV5lO4npjlMzcxeJj4dJ/zRUfILwgUoVEVKB LC+LJBkEU3ZCyiI3uvRskb/tnKEuEDmpKRrVH0aGitrV2ZDlysDvgZugB3QcGb96vW0Q /jy3/aIVq8jyZMfLk18coxAFVLR+b91vSf1u8pTbw3V/ApT1qoGVEUf7U9pAvN8VLTMF aPHZrMoBMkrwq6/gMzT5Dc89fanSMq//LxhxIzzhlcwPjOCmbWhJhXAvWDarbYn0sK5z pTIHqwkQpD+an9lBK/CUuJnOhaE5nflpoXzNmOMK4u84JTdzydVrvlN9EbtO1QyUtoUt 5FFg== 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=LIesySo8KfoPYYuDv0hxnDo5m8+fU1mYrZHcG45Uhwg=; b=m05BA6LChY90lhUfFJ08GiY+jD1YxoMJTfF0aVBZ4yFyXD8eIK0gCueg3ZdfJySzI7 bH4IY5rmDbwjWGp0M/uxOOmE415+L12+fVN+kGliHVASJuYmhXop4kFL8GmXUTwjI5CU IQPvz4HlZR4A8x9Ff9zEGso2kSvIEysfgaYGp5zYesPK14wlMccMggqGKU9qXW4wn8pc ZTcRkWSduj+bSBwD9LNvBW9Ae7UGpxRU+ptp3l9nrlWN9QVqRd2Lth7CFE9Fj+78O8L4 RYKK2o1paMGOPleSGRrBwKCGHwCA4Q3bakuXWdKPbW70byT8SrNBAxYTiyaZ5KpgmEMZ nILQ== X-Gm-Message-State: ANoB5pmEe8zfAzig0HAuhsdnKVqIpuLEGlNzv2WtmXJ0zMVgLoobmPYZ YdlAnyzpplhyANq2mqSHlY86BA== X-Google-Smtp-Source: AA0mqf5/X0Em3V8ifIs2J93d/ILyfxzdwhf2FYzSr+0t/l42WHc+BzTwWqjiJKAQjGRUM7Z3LyomTw== X-Received: by 2002:a63:2210:0:b0:458:6031:ba1 with SMTP id i16-20020a632210000000b0045860310ba1mr447725pgi.524.1668149253343; Thu, 10 Nov 2022 22:47:33 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:32 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 8/8] hmp: add cryptodev info command Date: Fri, 11 Nov 2022 14:45:53 +0800 Message-Id: <20221111064553.246932-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=pizhenwei@bytedance.com; helo=mail-pg1-x52a.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 | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 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 dfbc0c9a2f..b6b2b49202 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -143,5 +143,6 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict); void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Error **)); void hmp_info_stats(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 01b789a79e..3f1054aa1e 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" @@ -2761,3 +2762,38 @@ void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict) qapi_free_VirtioQueueElement(e); } + +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict) +{ + CryptodevInfoList *info_list; + CryptodevInfo *info; + QCryptodevBackendServiceTypeList *service_list; + CryptodevBackendClientList *client_list; + CryptodevBackendClient *client; + char services[128] = {}; + int len; + + info_list = qmp_query_cryptodev(NULL); + for ( ; info_list; info_list = info_list->next) { + info = info_list->value; + + service_list = info->service; + for (len = 0; service_list; service_list = service_list->next) { + len += snprintf(services + len, sizeof(services) - len, "%s|", + QCryptodevBackendServiceType_str(service_list->value)); + } + if (len) { + services[len - 1] = '\0'; /* strip last char '|' */ + } + monitor_printf(mon, "%s: service=[%s]\n", info->id, services); + + client_list = info->client; + for ( ; client_list; client_list = client_list->next) { + client = client_list->value; + monitor_printf(mon, " queue %ld: type=%s\n", client->queue, + QCryptodevBackendType_str(client->type)); + } + } + + qapi_free_CryptodevInfoList(info_list); +}