From patchwork Sat Jan 28 03:56:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119643 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 8B1C8C38142 for ; Sat, 28 Jan 2023 03:58:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcKo-0000My-MA; Fri, 27 Jan 2023 22:56:58 -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 1pLcKn-0000Mi-IS for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:56:57 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcKk-0003mj-Ss for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:56:57 -0500 Received: by mail-pl1-x62b.google.com with SMTP id x5so3377513plr.2 for ; Fri, 27 Jan 2023 19:56:49 -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=OiZ9BQAxmtxtNjSpaLuEC3kUHtUhzhnxUqljnP6PpJHgFLtf6I3HZxNuM9Y+GkM32z g4CL3A+DvnHIgCRNpfAC61eZ97pDgD1bQl/srtBWlOVjdSIqz5dtMSzILLCmj1aIoder edc2zIDcBUJzf3sQMJ08bSxgaLG5a0Db+yQAORfYVgVqCQw17HLFI/kD01DxcHJ1fzta SVgSPpO/TdXC9yxa5jFJnDXWhWoNE9w0sbyhNBGneGPHqXClnKyVaUZpxny67DrKIAIc hbAZ05Q3D9oxsHie+RHDv/IuwfIjHFNvJevJOnJiysMhzOX2vbCTA3++DDTYRQzjkIGn KxEw== 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=5uqNSWbsLGHTSqxSRDSrW/xKLh2qt7+2OqV8OUWa9+BtJCVa6rW5B3qAoWEc03qnmh cl3eaTiGLmHrfl7CsDKov8xwj2IP+xF3pa10yK7KBZ/f6ZyGCQRVGICKgVOEb2b6HYVd cCzEfnWLG1pgdAVpwJQkHWMmUxXzGAkGCfhDPBfOUo7KB3lntosNQYsOVIjMHE155RFT 8HPCmQltcQYFP1sRUOZmvEvXf5gG4yrovxmhyQT1N+DlXJyxiwt2pYPOAQv41NYCTZgP vN4qC7WP4k7Qo4jlyQN75zmsusHRFP11cSztj48KbAeUnvKrZniyuvM6ynPdWtr3K7xb T6Hw== X-Gm-Message-State: AO0yUKVBexfTBn/V4XmE8qlqmwlNIV14jiBPqDdKikwsxaeKOyI0nXkY mPj+YnWVlNZZQo62al1ytWjM/w== X-Google-Smtp-Source: AK7set9SfMLKgZsLvnwVijB6qmExtQ6w3yCMV45k6Q9EvLe8sYVHDLFWGulO8ks3lH3CMLoBk/4zIw== X-Received: by 2002:a17:902:e80c:b0:196:132c:5b7 with SMTP id u12-20020a170902e80c00b00196132c05b7mr19873971plg.1.1674878209053; Fri, 27 Jan 2023 19:56:49 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:56:48 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 01/12] cryptodev: Introduce cryptodev.json Date: Sat, 28 Jan 2023 11:56:22 +0800 Message-Id: <20230128035633.2548315-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62b.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 Sat Jan 28 03:56:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119649 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 77FA2C61D97 for ; Sat, 28 Jan 2023 03:58:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcKq-0000Nr-C4; Fri, 27 Jan 2023 22:57:00 -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 1pLcKo-0000NF-Mh for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:56:58 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcKl-0003mn-68 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:56:58 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9so6814406pll.9 for ; Fri, 27 Jan 2023 19:56:53 -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=sFdPhqG5W1HOkfuqwpb7zlENykplbySHWi969KA2FhkHokxDKCr+XyDWJhU0jCQMga 2/QMcEH3T9SabFsXM8rbQmCcq/vhuPldzKIVy7+Y/kRUq2Wc6Cnuti+FWJo1Mw6uahot g/pztHENJDNjF7NmrBpmTjdKRH0Vo7yxYFLh7UF2ZzJ/iVkeSQJuTzXcngoVb/YKJh4N czLQo34oyNB3D1aks7VArN8Asart/9NWZx+8duocVqyi6B/o1WuaJCiIBEW9kzBp5Djd Vm1LlARGic5x8zVYuNjfuiSML2fAK0xuUMwb7RavCE/NdTnCuHPxHV9KTwavEwG+5Ps0 4hKQ== 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=lzOeFNbgRCxGRoh18CFeA/3/EE+A782KYgopBziIIzoSkOgFUGtUgAtmjG34vhhUBm Rr2naI4eFD+PNH+g/q+n/lws2aSCNNQKvYg6VPqztj5d0jCkwT1rileClwcZNJEmhKwJ kncajUtMDDIiLURZgR/2YcBZuj6cJ4CRnjoDdfyaiNlb8y3WdH9HKNTL9LfyZBMA4QPZ PQaduvMOM6yQCmjFVSnJ0rf/5m5dOq9WtadoBH102Tgd/dVAKEW1cYOlHHimnHNBfdrp mO/OJi98qqYU5YEd/r0aPaoW1IIEktzNx3S1StGhwrnIjgHGlmFDVXf9zv4RANhxQrZD nh+g== X-Gm-Message-State: AO0yUKWr5uHtuLpGJAITyUkDxSahxKC9DLVJg1x0hykrK5FAeFQx/CqW 5UdLg9j6cJEmeaI+bJXwDQF80A== X-Google-Smtp-Source: AK7set9CUYSKZDcE4Maj/CFTO6r30pPeTiulTfVBhWIyHclFlzK8ekFQZdcxBhquXKHXyIYNcl+3Uw== X-Received: by 2002:a17:902:dac8:b0:196:59a0:bffe with SMTP id q8-20020a170902dac800b0019659a0bffemr4417563plx.17.1674878212298; Fri, 27 Jan 2023 19:56:52 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.56.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:56:51 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 02/12] cryptodev: Remove 'name' & 'model' fields Date: Sat, 28 Jan 2023 11:56:23 +0800 Message-Id: <20230128035633.2548315-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62a.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 Sat Jan 28 03:56:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119648 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 110F8C38142 for ; Sat, 28 Jan 2023 03:58:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcKq-0000Nv-M0; Fri, 27 Jan 2023 22:57:00 -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 1pLcKp-0000Na-0O for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:56:59 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcKm-0003mr-R2 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:56:58 -0500 Received: by mail-pj1-x102f.google.com with SMTP id e8-20020a17090a9a8800b0022c387f0f93so5469784pjp.3 for ; Fri, 27 Jan 2023 19:56:56 -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=JdR9JA2p5oPbnIiTO5timMM76VCYh8mpBfJEgHKjROxhCR2kIrpaBbJ3TeC7NMbpAZ gWDBN+6qfxiqO6Iyjn7oUIhuZ0NQzLmJ7E6Jy0brG3fcS+R8Bbqsx+O2EFl57Sf3ZKaD 5QfwZ5MNII3b9IENw91gwoavWGO5mkzPXKAC4EsxIM+F8uTrPwyKuXH0IakPwwovP4dI QjMi6PhW1czuXY0rOYSF6tamaXe9zPxOyjfFdzRVXvWFExbrbg1iAyukPm9gRoQeQ8z6 SOsPZr/cK7LE8h/cfqQr+0fJObQ8d8ltLNKx1in79m7btNTmA4V6fkW2tWf9qZRQD50j aKpA== 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=uysPfNvVIIm51zmZULT48U30uTfKcZiYNRcLeWEQj/hXJDHCfXDJO1BgmtTy3rqqqD vbHqNkZvWnOlFQ7ytpt4y8bBt/oPeze9cqcUHrWW4VEAYiWPxSCfkjwJaDGLsy7hh8W2 fiJu5888zQxbQQPJ9ylAIUtxAWkNcvvb+VDZeXOjAFKrkMBSzw+Cj0A3+HtWabzDJyZU TY/tbyZL4/QmeU+e9t6O9ZpAppkVebhv/AFilh3eCUYaqIldIkM3uLIOdaADYk6pChjx 4dpbiOCKxIvL+LECf5UmCY9tru1WIMXhqVqG9ScqBhMd8YrlqBcprHWRRFcUe93r3FpT NfPQ== X-Gm-Message-State: AO0yUKU3xhpyd32ldSUSIuEvhQG5jNn0dMZ1GOHCaIG0fmp0QjdclaSi tCgIE/YW0uJabWCA7bqnXCfEJw== X-Google-Smtp-Source: AK7set8zkK6YtVPQhExkpZ/T7HGGv4wSSfrR75L7DBBT5eBxXrFCs3EhA3v/BvusbtHOfgysLQh1DQ== X-Received: by 2002:a17:902:c215:b0:194:d4e5:5e5c with SMTP id 21-20020a170902c21500b00194d4e55e5cmr641236pll.37.1674878215466; Fri, 27 Jan 2023 19:56:55 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:56:55 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 03/12] cryptodev: Introduce cryptodev alg type in QAPI Date: Sat, 28 Jan 2023 11:56:24 +0800 Message-Id: <20230128035633.2548315-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102f.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 Sat Jan 28 03:56:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119637 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 60E5DC38142 for ; Sat, 28 Jan 2023 03:57:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcKu-0000Oo-4q; Fri, 27 Jan 2023 22:57:04 -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 1pLcKr-0000OP-L3 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:01 -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 1pLcKp-0003nZ-Un for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:01 -0500 Received: by mail-pj1-x1029.google.com with SMTP id n20-20020a17090aab9400b00229ca6a4636so10550833pjq.0 for ; Fri, 27 Jan 2023 19:56: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=ihnaClmcpFL3v9tNj7fgQemINsh8688QVm+1j1fBK14=; b=sofCBkxdQQTCoNNqVzynHORLQmD2qe4uy0DkC+IvWHCm27pDcBZp/ph3bljwos+3q/ hFRwu8+PY4Zd4Aua+0ZegqlVqfkYAVXN7XOKicicWswQphwu6frkfRFuoREgvCqe4h4B w5sX8aXTyCqIA0t6PWy/VUf69VKDNALAk3dW7snDtAl/SjJtlrPvrU9grIbUJuHLsC8L rsMDASHXPI4AMWGMn63dc1AG9IgkCh6jVkSnB4UQdYGbOthtHJXLtXRXypoDQnq/Jtfm waRKw535ClP/BTDoarXG9/sCiR7EcJJx/Io9yV0rua1TgR/9iQ2Z2bPaXD7XS/YLv7MH Kg+g== 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=hqeaAY0qLO8SoMDeo2nlhIrYnFpnZuA4OK1bdVEB8zRpC79QJNJkmK9/lyx2WlMTuv 7nszxiTL7o0neehekDZX465bQakfN4hcWjXkH/Z/5+hGbJXaq8QOob/GUTtQKfa5CG91 j332vObZkXTYR09i/TbJNg5wCzE6eP/lrWQl8OonjtdtKvRt0iN2kqMXw5mu2KjpPPZw XPIpiPRR6+ejsI4C5AIoIKEMY3e/YgZ69qTta7NpV1Cp4tUCgqJZSu7wGXNjol+NIeK3 wvcqfwlT/zakg2QltonwisNMQkt4aG85RJphVn2cXa7Qpp4NPLHB2VyHpYcspKOQ6icc uPSw== X-Gm-Message-State: AO0yUKWXBR0Wr46HsTXdNlqde8Kn6QUHHBbaC7moNIGtZcwMl8ZVVWue lft9x24dD8Cf1VVdS0Le9khZ1g== X-Google-Smtp-Source: AK7set+ltEIUf8l1UA8CwrZxP6RnscaR5G+c79WUVrQpwUNb44f1eogrkXgFrDAx8mQwASB5laceCA== X-Received: by 2002:a17:902:e185:b0:196:186b:cbed with SMTP id y5-20020a170902e18500b00196186bcbedmr463277pla.45.1674878218704; Fri, 27 Jan 2023 19:56:58 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:56:58 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 04/12] cryptodev: Introduce server type in QAPI Date: Sat, 28 Jan 2023 11:56:25 +0800 Message-Id: <20230128035633.2548315-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-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 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 Sat Jan 28 03:56:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119641 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 29326C27C76 for ; Sat, 28 Jan 2023 03:58:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcKw-0000P5-TL; Fri, 27 Jan 2023 22:57: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 1pLcKv-0000Ox-L2 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:05 -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 1pLcKt-0003nt-Ka for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:05 -0500 Received: by mail-pj1-x102d.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so6522882pjl.0 for ; Fri, 27 Jan 2023 19:57: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=4fD2Ipwpfn+luLoaXelYou1gl0+GAbRSNntBtJbi9rQ=; b=ujPhda06GNaTNJ5rjBT11eZljCHmqsN7s3mxx4Dqf0gjA+nYgohCgNjwc6T1J3oBeB idpSsIoqSbuR6jDsDhosMrqYaKKR4/qbLqaJoE1dCxJvSM6ZAh4ygmyToT7odrwqHQJP sFDN0aXhc9SCDZ8M/if2F8Hg9vb1qdbRlWzNNGPQS20vDYP3JOrgBujhnUWDgytSAZ7H dn6bFCzHqcrF+xBTa1RZAk4ND0EcpnyMSl6tz+JuzxqvkHLLYK64g/5+AiM38Zm/9Vl9 GY1GLotxLD3C+metwXo2OQC66C5kAzDgrkeAEIyUXkELTmF/WQA+M9IeZNYnYxRj0pEM IEqQ== 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=4fD2Ipwpfn+luLoaXelYou1gl0+GAbRSNntBtJbi9rQ=; b=o88SfbKt+5RSPj15mDnJ5X8KZ3e9drl9tOJhkinlJRAv4usdEXONZCOvdo0zpjTLe6 Rj/DVlfEq4q7oct0YDSoR0u7wTst62AhhbRVEJw6dNmBEvkLFmcT8ZsmU0W0ug46xRz/ 9iEEjyK3SL5GcfcpFLUff2N2XpcNzg8HLXAD5QEQj6oTnkEDVHWL+dn3AegfbKtmSSPt roy+eu7WCaYWt7m9xvBv/fuYTs+ErncHB3EM4L1IdSRfxt+rjuJf+y7HI7v5V+DUoRuH 0ytyA6D7s9zKZlNiNuxwuswat/MzvXrk3Z44TdnbSbYYqUIP2gsV+4YO0gLlBMQ/2baf NpvA== X-Gm-Message-State: AO0yUKVd3uYGokYKZX3uP1xvb2Y1Apkfz6thc5thkSb5L+Vtei2Iuv4z qGerKgHK/s4nwuO2QGr/1qQnnw== X-Google-Smtp-Source: AK7set/fHV7IPdAY4wHBLQAKXE97NKN4sNWQ7/ptYvHyQjEkFQ9hbR3Y9bF510xjymU020oGOVwrBw== X-Received: by 2002:a17:902:cecd:b0:196:1512:8e85 with SMTP id d13-20020a170902cecd00b0019615128e85mr19661850plg.60.1674878221944; Fri, 27 Jan 2023 19:57:01 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:01 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 05/12] cryptodev: Introduce 'query-cryptodev' QMP command Date: Sat, 28 Jan 2023 11:56:26 +0800 Message-Id: <20230128035633.2548315-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-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 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..d51eeb5ee4 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; + CryptodevInfoList **infolist = data; + uint32_t services, i; + + 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 (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]; + CryptodevBackendClient *client = g_new0(CryptodevBackendClient, 1); + + client->queue = cc->queue_index; + client->type = cc->type; + 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..940078ace0 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -43,3 +43,47 @@ { 'enum': 'QCryptodevBackendType', 'prefix': 'QCRYPTODEV_BACKEND_TYPE', 'data': ['builtin', 'vhost-user', 'lkcf']} + +## +# @CryptodevBackendClient: +# +# 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': 'CryptodevBackendClient', + 'data': { 'queue': 'uint32', + 'type': 'QCryptodevBackendType' } } + +## +# @CryptodevInfo: +# +# 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': '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 Sat Jan 28 03:56:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119644 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 501BDC38142 for ; Sat, 28 Jan 2023 03:58:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcKz-0000PV-9u; Fri, 27 Jan 2023 22:57:09 -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 1pLcKy-0000PN-4u for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:08 -0500 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcKw-0003o3-JE for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:07 -0500 Received: by mail-pj1-x1035.google.com with SMTP id m7-20020a17090a71c700b0022c0c070f2eso9818827pjs.4 for ; Fri, 27 Jan 2023 19:57: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=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=R1swDsuva29edCr+Mj9nG14W5GIu1esnwVrRzZw/iM0uEm26/eQ45eT+Sh7ZvGzD0y IQ3REXc6XI+NZXUTZinRnxCeRh3VJ1w06qCY97bzqI7kyKY709VzQgD5cSFNqCOtxArj HWLAax2NhIUfUtKzdFQ7sPpJq84wqMjrf5NeEXJ8rXLuEuBWJL5itZos5MBEi5TMrCui gRmCGSlkne3fwbZpcP5ZwepHPL7jzZXddcbmo6UwvqRub25aJzlBSpNDSK2HnheJ3xA2 mJk0oq+6Sy8iKJKee+iL5Y6cMrLDo6I5FxcUjZYQcDBpO0jP6K2okX8lO04DvwflgqXt uBdg== 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=lOYfFIrGoFQgvWuV5EgXoCwnX/u0DDD89h+LwyO5nqUZ+MhsYJycBAYr+bWtwMeBmZ tGgt2pjdJxk4nJG4GUykxbtZPC4gZoKfunehoc6dC4gAFwGG7Drwo9127GD/biq3sJ97 bjw+4p8gni/hlJPxh1SnMexxIJJDRrH5+wx5PC14aVZQB73GLEXph/oXg6sKsKwJTjEN fUjJUGbrNlSX17m3o4d6/7cQ3MbBO+LnNN3IrtG/cV1uZWBMJ+CIckoVD8b6ZCdw4wf4 JwdK5IbEjXFykciwcx8ydsB1+NHvN96TDQ/GI3eqOQW/5f2QneRcPsvcBThcqocC63UU ZWjg== X-Gm-Message-State: AFqh2kplW0M8V6kLv2NbtP0XSvqGH7NvSj8xeH0rXmir2m3ED91ib7c8 2l4+qM3qSK5u5dB0zT+15EJgwUHpi6MAe+i4 X-Google-Smtp-Source: AMrXdXvskJYmBCiLL4FBTM2mONpZkc7+gGGCfYeTd84QOtN2Vxv07J1FhA23dPIYib+mn4jneCL3AA== X-Received: by 2002:a17:902:9a81:b0:190:d273:38a9 with SMTP id w1-20020a1709029a8100b00190d27338a9mr38874035plp.14.1674878225147; Fri, 27 Jan 2023 19:57:05 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:04 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 06/12] cryptodev-builtin: Detect akcipher capability Date: Sat, 28 Jan 2023 11:56:27 +0800 Message-Id: <20230128035633.2548315-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1035.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 Sat Jan 28 03:56:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119646 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 91928C38142 for ; Sat, 28 Jan 2023 03:58:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcL2-0000Q2-FH; Fri, 27 Jan 2023 22:57:12 -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 1pLcL1-0000Pr-8V for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:11 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcKz-0003oN-Ht for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:10 -0500 Received: by mail-pj1-x102f.google.com with SMTP id w6-20020a17090ac98600b0022c58cc7a18so2003315pjt.1 for ; Fri, 27 Jan 2023 19:57: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=8HDlbR/ue9evERBUHAmZzQiWiqejTQP24BQkEB1mCTA=; b=EVbOQK2jtwz3lZm9o/DCGvYGT1Eo2Dzr+aT8gfbU4wMmYjXC7wJfEZ4d5hqKwKNRsh XbUVpR+tEx1dWjXrfTsIRyotkEURwMR0i5VH86UPs7xIaodDOU+Ie1MDNuY+dMBh8OWe OiF6oU21aKOMQvbMAXDMmuHhD++OrKfzjc1vJ281QgovCkHZQ3cjIKn4MXz63jAqrfqv KQa5wxZgNbZr9xacMBMNNVopZTIYyNYdliife2kTyemLceuFxY3ym6GI2pvqdVs421XF 3WKsK+ILYvMULTQTME3Vh+1SyNHXfcYmapvls+aU4e1ejO0QO84GUZWpPASF4FPDUyT+ BzTA== 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=8HDlbR/ue9evERBUHAmZzQiWiqejTQP24BQkEB1mCTA=; b=GTyhzqUb2PufOqboeYvn0bCryeujklExiTeehzxA6DkUBpBDCUW/f2fRCyurrbS4Uk icTXjNmcizhrBkfXlBxbbODVgo1m7DIzyARUhs/rTmiH0baLPobGBOtF3B/QeRlq9LUz 66ZIh5Lr/RIlXsJo65dZ7jvM2AWyOTYvdbx2r00cQnK5PdJo+8YVG2V7C+PmKh6xZ4G+ 33m3lC4K7YZO5XB98s0drlhBPItfuP+OZXNgQrp/H46mBAa6NFOmgUBQWTEFASCpiSSf J6iLd/YsZom1K/Oguf0AtIGd42LqJOys+bbgXbTKXY5B58wMjVxKKK7kus7MBMDVzaOz xATQ== X-Gm-Message-State: AO0yUKWP8sZeHjNqoxTcQWai/fwi+X0stFSLwksScxHUUBy0Q9PmxELV lUdy5EF1JnNoMYJUGq344iLuZg== X-Google-Smtp-Source: AK7set+EM++x0Tg4TwhIolIhDAob7qQrFEyQV+c8dL4YqXASmTjy2KRdnDsSPuW1cPnQc92/WuOKaw== X-Received: by 2002:a17:902:d4c7:b0:196:1608:d755 with SMTP id o7-20020a170902d4c700b001961608d755mr17888110plg.60.1674878228475; Fri, 27 Jan 2023 19:57:08 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:07 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 07/12] hmp: add cryptodev info command Date: Sat, 28 Jan 2023 11:56:28 +0800 Message-Id: <20230128035633.2548315-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102f.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 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..ed316f75c1 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,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 *il; + QCryptodevBackendServiceTypeList *sl; + CryptodevBackendClientList *cl; + + for (il = qmp_query_cryptodev(NULL); il; il = il->next) { + g_autofree char *services = NULL; + CryptodevInfo *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) { + CryptodevBackendClient *client = cl->value; + monitor_printf(mon, " queue %u: type=%s\n", client->queue, + QCryptodevBackendType_str(client->type)); + } + } + + qapi_free_CryptodevInfoList(il); +} From patchwork Sat Jan 28 03:56:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119642 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 E56B2C38142 for ; Sat, 28 Jan 2023 03:58:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcL7-0000QZ-Ga; Fri, 27 Jan 2023 22:57:17 -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 1pLcL5-0000QO-3H for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:15 -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 1pLcL3-0003op-A3 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:14 -0500 Received: by mail-pl1-x634.google.com with SMTP id v23so6855548plo.1 for ; Fri, 27 Jan 2023 19:57:12 -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=Jdzw9QZCIXk+mAQ/QLSP7hBtgxJtl4K9TWjsbz+lY+0=; b=WEd/txoIR9Xz0C9fsw/gPp/6RC3n62IrZUiociP7Bfn2smpY8auzsZ+Ep5uA55kWSd XTTFL/qRjLKFc++CMhI0+pALsuJ4t1TbN/WoNRHbY76r1TjlGhTA91mW4y4p+8+83Ric v61NXnujrlxwO78pfdd/PZUmF3otebKcijGDiTbHOD2/ow625a0ZfnDKpjhiUAh1gE/9 bEn19CbkSMT68BIaGrLKeps7sDU+LgGPe9B9d5NBAIIWniS4Z2URl48X2/ETaaECXJop oZy8dQmXqLfVapzNMNuztuTIaLtMTQ1zLBvIthFFVrGu5pzIE46ORYCpHNBrN10DJAkM mdeA== 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=Jdzw9QZCIXk+mAQ/QLSP7hBtgxJtl4K9TWjsbz+lY+0=; b=xuhGHq3b74VB3dArBfW3cXZKkYR632S7swADhFnHLsFTk1kMHjltQZ9m7u2D2ypHrc WTqB2D0NWGW0VCa2T0M9zlF6AmQSv/SJLSAVK6qYpP/frNmmxMQPByfseniUAj02xvDb Mwk76QQ2KPbeIujqcDCdHjUAaBMdtnjVTd6+omNDDu61vQiZ4mfT+uhOJiL8PGUfPhb1 w3MVe5rxhxFVaPd8PynJyHES6zcRahD7r9edXzFKFplgV2Qz9tfX/bWu4YF4a/Csj/nA bOBcDr7NpdTj+7EEj8dKrDk1clC0ZIfGBQM8kKbdPUCIQfViRKsljT359wmSJ3M6mTPh Xjhg== X-Gm-Message-State: AO0yUKW2ZIJGYcIs8/EvE2X0kgkuznoDIwRq5CMESHDM0cCX7Yh/IQhX FeLFfD2PcidhaTEWflLYahs3uA== X-Google-Smtp-Source: AK7set+11m6is+MkLZA85yZMyj6RWLt/haO9+jeyRmy/De1FxDXPMHR6OQdDW9eq/Renonix6Hjliw== X-Received: by 2002:a17:903:2013:b0:196:37db:b4b7 with SMTP id s19-20020a170903201300b0019637dbb4b7mr6550759pla.62.1674878231883; Fri, 27 Jan 2023 19:57:11 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:11 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 08/12] cryptodev: Use CryptoDevBackendOpInfo for operation Date: Sat, 28 Jan 2023 11:56:29 +0800 Message-Id: <20230128035633.2548315-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-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, 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 d51eeb5ee4..b15b1a24f5 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 Sat Jan 28 03:56:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119638 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 16C0EC27C76 for ; Sat, 28 Jan 2023 03:57:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcL9-0000RK-Vw; Fri, 27 Jan 2023 22:57:20 -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 1pLcL8-0000Qp-B2 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:18 -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 1pLcL6-0003p5-FI for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:18 -0500 Received: by mail-pl1-x635.google.com with SMTP id d3so6803786plr.10 for ; Fri, 27 Jan 2023 19:57:16 -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=23n8jkyycpw055p3C4gV+2Ds+xJ4j1KBu5BFBnOnAJo=; b=ROXNOqCyrhK2Iy/T9NNU0oEppShivCs10ts89Ihm0g49W7w/QTmLXi4mkDV07Dr4I1 JZedWQKla/uskNYLukfaDMcKhzPK+HrDD1MmySCsQr4SELpjw3FxDCX1Hr4MFmweMVtg fMAP2Bj1LedXmuvjPSCSWVyDkmDjHH98eJaa3OZq13kJCOMteeXgECdU4cKd9tCmivpm EJLTU4lG2Qs7p/RCP73LgDw2HmhfVTdWh0W+UiKlPZ720C3Z7Zrs6Lk8jcHVzdRmJyn3 Nr5qUlWx6J7DhxJQXvZlBCdv/LTgjxEa9N4lDGV0Q6Np4K/Xscp2PEb5hJJ99dCCjJj3 P3dw== 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=23n8jkyycpw055p3C4gV+2Ds+xJ4j1KBu5BFBnOnAJo=; b=YQjk5afxuzu9FFBEFjB/0uaRAyqUrqoFPCr3cGhTezrYqVV/vz2R3HUGeff32+iMur TQGUEnMs8aREbJowqHw5meNkznGYcPKRsjXCQJzp2YhJnxr7no9+k11o0vrpydiUI9jy ApyRvUIz8GYOcuSUvLje+jzrNFj8zs6bTgg+Rc1zocaF/jdvhw1QoJorR45UuiDmmy9h G/xuwE3ha8rdmkPMn33sxWTEwJMd+AgMR6E/WBjoUyLR4jPrS1Nqrfurch/gWkWl9K11 +N3Ar1cSmoR5xLFloUn4oAPRr9WlXJP7kL2AisFtvZ64lgje2ZBlDQnWSDqRkl/X/5xi xo2Q== X-Gm-Message-State: AO0yUKWlTYGLRCMfiCckGwoG//G1FAiRA4GHLnzlwyQQ1aQjdk3Bg+O0 sraSw9qXNrHVBmvY0ttbRiwvzjosLA/zcxTg X-Google-Smtp-Source: AK7set8c6Mxm9RVIUzFyWerLuCMY0yupe5aaadx97R8BowsauNc/71JAx77jSap/5xF8BJQpf2LiFA== X-Received: by 2002:a17:902:d508:b0:194:d7df:cfad with SMTP id b8-20020a170902d50800b00194d7dfcfadmr938727plg.18.1674878235019; Fri, 27 Jan 2023 19:57:15 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:14 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 09/12] cryptodev: Account statistics Date: Sat, 28 Jan 2023 11:56:30 +0800 Message-Id: <20230128035633.2548315-10-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-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 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 b15b1a24f5..9c8ba6f29f 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 940078ace0..5f0e8915c2 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -87,3 +87,57 @@ # Since: 8.0 ## { 'command': 'query-cryptodev', 'returns': ['CryptodevInfo']} + +## +# @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 Sat Jan 28 03:56:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119639 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 0298AC38142 for ; Sat, 28 Jan 2023 03:57:59 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcLC-0000RV-Hl; Fri, 27 Jan 2023 22:57:22 -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 1pLcLB-0000RM-Hg for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:21 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcL9-0003pF-Lf for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:21 -0500 Received: by mail-pl1-x631.google.com with SMTP id jl3so6823715plb.8 for ; Fri, 27 Jan 2023 19:57:19 -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=zksQYXXIDJBPnsRDJDs+M4hEapPR4KCQMDs5uvODmZs=; b=JyX3QAa6DGE4N83XrHqTVGjTTE8W+Vr5hzpoNMNxVAKSFllFFht2PF7zsF0H3YNkrC YCmrXOyY0J1h63ZFqzkS6JMZK6NajiQmDxX2Cz2RcFGspLlDRtUI+rgAwvnYXjzYj7eS LWOrbigL4JpYY1C2fIv6gm8zxmgsaC5WhX2rE7ecyGKFrzi3+885CpL6sLR2j0CDCun6 PNMVnP0NlSC8vZWmXgGUuzjsSWDNOl770Ujgww/kMq4lLYc9xTcqHACfNBtNJzSd5Mcz +6DIYBPUyDTzBtPqiipfGIbTtuMNy11lF7e12IAlYsgntus/AfY5SUYeSxLE7h1t5m8h sHYQ== 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=zksQYXXIDJBPnsRDJDs+M4hEapPR4KCQMDs5uvODmZs=; b=tchICyw7gFrwgGM5WZ5uBNBPr1u5Bzktmmq2T4/2B15r06ywcYToODzvlZEu//Vorj iQhkKOSiFDtdX8VM3xtFTVY9FGzgZjUuR5tsh36bQqovyIxadI9kcuL+Ij2fBaU6BhbT hpEof1TzTIUGxylzA3U+DdkvXfgb7RT3WsTh1Jn10NolWj0V5QvyaazMB1b+jN7eTnL/ 4MGyDnU9w1sVZEmIGkBj8p2TBFTb061ZiATZo1OduoWhRBBobqr4lIhIZrwabRd0ieVC 60zf6fyuCssXXaeFeSYxl3UcU7xn3/Dm5BvuPMxMKSI25OBwUg5p3WbbQtsYEUjhHKTv fNoA== X-Gm-Message-State: AFqh2kplmUILErYNoxrbbkpcM2Fqja23Jo1QIElIPbNn7SkklJBMhUfR /L8VlGL2LJbe8xvPQSVUZfpTo8KoKCHmEIR1 X-Google-Smtp-Source: AMrXdXszJUxDP1wvSIAZqHZss3fp4R0t5ge53ZFvIx36+ZN0M9w74s6dZxE6P4sZnQsvWCBSr7m+ZQ== X-Received: by 2002:a17:903:1355:b0:194:4339:112e with SMTP id jl21-20020a170903135500b001944339112emr36261658plb.60.1674878238405; Fri, 27 Jan 2023 19:57:18 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:17 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 10/12] cryptodev: support QoS Date: Sat, 28 Jan 2023 11:56:31 +0800 Message-Id: <20230128035633.2548315-11-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x631.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 9c8ba6f29f..c288d5a016 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 Sat Jan 28 03:56:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119645 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 74852C61D97 for ; Sat, 28 Jan 2023 03:58:21 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcLG-0000S3-1f; Fri, 27 Jan 2023 22:57:26 -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 1pLcLE-0000Rq-NC for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:24 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcLC-0003pP-Q5 for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:24 -0500 Received: by mail-pl1-x62a.google.com with SMTP id z13so6834507plg.6 for ; Fri, 27 Jan 2023 19:57:22 -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=895AVhM/R+Esm94BaiVSLbfczrhT5dKN2jxCxe7qWGc=; b=Ku/dJa8O9lzzDMPjeMonSCMlQ6zsEwjD7AIfLx0cZYkCCN+EnaDdW21pNUiE+7T75h /tr+r5dJtRsWj3miez0Seuxkfkk836IUH85TzPrm1m64WGkLqmaBmPvDaq/S3KrzFuSe yRgt8ih42ncn/LcxCudambUUA/7wWdklWEy7AGBkd6+Te/UYFFpv0hxuIv7N8PTH49VE //zP7lLpRhjDb0K2H1VfsxmYjY+PplveZ3uBeMPSRFubRWzGRMl/QrphZg523/Vjru/W 7jGKBZfbXds3NvOiQpQxEKgTuuQXTmM2ONp13L347nAJOGN4PMXNJrn0amCrGb3m+6Xt 08rQ== 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=895AVhM/R+Esm94BaiVSLbfczrhT5dKN2jxCxe7qWGc=; b=hp/mq7fQOHikWSAa6+4chvbc5QuSfO3WHEPRk32w2mAgaADZxoIT7F6kZ2vA049aJr HLsmX6qHp4Y+LLdIvGuKgYAUDMGXXlnWWK7tPddog7vdx21O/KzX+gYWiAiaZMoyt3XZ 0Df2DlSBtjPW4Dab3IyEazNAu7KbmUXPMieZDG5HMOrKDyR9U3oOamtJRy1HhGpl07bZ o/mcqOzQS5rCbbofZCxu/7YJFe9tUdaJpp5Mbae/3DEyKFFcjCfGiPvsdi4A1ohnVg2l vFhsEH2EfEk9fOS1etpffYuIkeJk6tPBL1DgllFTF5NZzmVFHXnRh46tICuVmeotPxW8 5VtA== X-Gm-Message-State: AO0yUKXLD0XkAUZYSF4PsgwBPXGBR/CYA4DMl2HZTL5U2bJUEnyPviX7 BOau0GaNTsNNVsfgnMhFY4qFHQ== X-Google-Smtp-Source: AK7set8JrvB7NxSL8i8IcVEieHttjueyatd6rn163pmbIu/ujfO9FHqBWa/fXt8FfOuhbH4TKlYPLQ== X-Received: by 2002:a17:902:d48c:b0:196:2b0d:fece with SMTP id c12-20020a170902d48c00b001962b0dfecemr15504075plg.15.1674878241585; Fri, 27 Jan 2023 19:57:21 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:21 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 11/12] cryptodev: Support query-stats QMP command Date: Sat, 28 Jan 2023 11:56:32 +0800 Message-Id: <20230128035633.2548315-12-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62a.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 c288d5a016..051e13ea5b 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 ed316f75c1..7c4e25c74e 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 Sat Jan 28 03:56:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13119647 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 087B1C38142 for ; Sat, 28 Jan 2023 03:58:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pLcLI-0000SP-26; Fri, 27 Jan 2023 22:57: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 1pLcLG-0000SG-UK for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:26 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pLcLF-0003pF-Ck for qemu-devel@nongnu.org; Fri, 27 Jan 2023 22:57:26 -0500 Received: by mail-pl1-x631.google.com with SMTP id jl3so6823832plb.8 for ; Fri, 27 Jan 2023 19:57:25 -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=70SrjzOTxntri0Seh1EVuPGUxuRQfnbsTm0LYu7dwUvuCXI1aM6Cy+SJRlywV8tGCb 5lek/BlLceJiMzQsWOxXKKCyYyVS9idLCwcLdQNWbwhirMDf8k5TxOzMUmd/qV1a0IbP oHbRSYi0KFkdFNleXWETkNWfpzhBIvGEQt1Kuejif9Eano03B/LX+JanJRT+OhZy4nrU npjts9gjPUmSM6S+IRwJuDVC8uJy99UYqdYsWjyz9Br68xiRLDKW1Orh+712WtZUw1cM fLpdTutOwWz2d3K+noh19ge9lCMhPpSRCDZAiyOIJlwKwspmxi9OlWN37QHJSi/yPhIB 9fjQ== 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=MqbbCSTS459IVFi1iIyRlF1sefgcfAtKlG8t/hC3UK4B3uguhYaq+K8Q4QydhBXN+e 1tJbBFyvpUqqEhdUqBP0zRDgr5mU4/ez4i9vXt4kJODt4OGUBiC/yqP9lzFVdHqlbvaA jC3XwHvnSGot0IRDb01Vcs1mg9kx2Eo8kFv/Gse2lVz4R/ctowkOVe2jNCyz64EKqVv7 6qgMhWox8Be7uQGo+HqTtS137TM9NiV439/Ey5Kk7AkwVeGBBYWnzN6lV+vuK/fqzSHl Pr6XQXIXfhEKAuKgrLKq+BACgV3ozGOBdg3GtG+iYwAgPkTeGOxK3u2UE8MDcxo8Z9Ij 9jrw== X-Gm-Message-State: AO0yUKWQYuC/cgm/QtTe40FK0BvCQ3OUrlCip57KrixPUfPBwj3z3xGr JwYrvdcAbRumOGSelTB5571O7A== X-Google-Smtp-Source: AK7set/ZgkeFL04TX31rxV7E42iH/F7JJUzeanmGrtGLg6gm2EaZ4FVQaaKplWpu0N6glkdo55ufpQ== X-Received: by 2002:a17:903:2288:b0:194:7c28:3fa4 with SMTP id b8-20020a170903228800b001947c283fa4mr814737plh.19.1674878244779; Fri, 27 Jan 2023 19:57:24 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b00186c3afb49esm3594662plb.209.2023.01.27.19.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 19:57:24 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com, berrange@redhat.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 12/12] MAINTAINERS: add myself as the maintainer for cryptodev Date: Sat, 28 Jan 2023 11:56:33 +0800 Message-Id: <20230128035633.2548315-13-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230128035633.2548315-1-pizhenwei@bytedance.com> References: <20230128035633.2548315-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x631.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