From patchwork Wed Mar 1 02:51:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155470 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 88631C7EE33 for ; Wed, 1 Mar 2023 02:53:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZD-0007aJ-PO; Tue, 28 Feb 2023 21:51:43 -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 1pXCZC-0007Zu-3W for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:42 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCZ9-0001bC-8h for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:41 -0500 Received: by mail-pl1-x630.google.com with SMTP id p20so11330187plw.13 for ; Tue, 28 Feb 2023 18:51:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639095; 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=hGecBk73OrCf22ApQpukoMa8+9NpH2PsLgL3BgKMtMI=; b=RH96rGPw+7N6mSjbsgNC/JwCVyHvqq0JrD0S04hJ7j2Veh8/g3B61FcIYqvLOYjwdd jazMzRG7UH+ilyqgMpOhbj/X4PgpjTk861MfKEJQ1uodXH/uv/de6rX3eWEot9a00ver ODyJS8N+8MXqRhpxy1l2OBgKuaHZAmWWRS71ezjm51ZV6UkX7+4SrrjXzY3YIrz/2mkY 1cugUhIycjTQrOyczp9YTfFiltA84q4yj8oxZAILkTGDjhRYYX2GjjCUceC1R1TGVcCR p7MNWFtgSf5OrYLU09VUJhvoSOWRidz2wAiQgRk3O7EJSNz6QxmDNXrvm60dvao1fpT4 ROKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639095; 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=hGecBk73OrCf22ApQpukoMa8+9NpH2PsLgL3BgKMtMI=; b=1PURyIuw6PDFJXfjoYh16ODWwTuTkoJlQ4V5C5Dihho4XC2i0W3+jS1SQy4EMjuW7M P/pJZSREzV8Sg7Hz+9z+TCBBMz28fPv0u0B8utrUrFTAsHzW5st11CcqJ9pO1xyF6YrN wsvmv6yvCTEt2jKhzBtz8oyDa+DoWNFq//lZG7QtHNh63mLMVF5I38dZI0zlLAH1dOpc 9/JsIAV+MkM7G15L6vxjJwGYbc9ueRmFpLUBD4YR/bvC2bVqejjT6cD6c50hefuHmJxQ iGGvdLuIASVtN6pclT2BVdzLhRR88pHPsoxcF1L8Cc6+OrutmUWaj3EAwNfbddUIUXbK VzZA== X-Gm-Message-State: AO0yUKW1CMIG5XMQIOyCv7GO/pGR2soeWOMfnSrjZGHHzrfXu6MPYC/A DNpDnmUCSfYWLY2OLdOUKDg7AA== X-Google-Smtp-Source: AK7set+SRIzL6qtxoiu/wZx07v6kTsqclkDSyZXArd8UJ7Y8k0wvJU6ZPT7hpm+3qfgVvUACnOdT6A== X-Received: by 2002:a17:902:dad1:b0:19c:d32a:befc with SMTP id q17-20020a170902dad100b0019cd32abefcmr5283094plx.15.1677639095072; Tue, 28 Feb 2023 18:51:35 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:34 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 01/12] cryptodev: Introduce cryptodev.json Date: Wed, 1 Mar 2023 10:51:13 +0800 Message-Id: <20230301025124.3605557-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 e96e9dbfe6..7651cb0ace 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2870,6 +2870,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 74ea0ad63d..93523732f3 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -127,7 +127,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 @@ -195,7 +195,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 Wed Mar 1 02:51:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155465 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 4D54BC64EC4 for ; Wed, 1 Mar 2023 02:53:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZE-0007ar-Sn; Tue, 28 Feb 2023 21:51:44 -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 1pXCZC-0007Zv-3d for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:42 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCZ9-0001bp-SO for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:41 -0500 Received: by mail-pj1-x1036.google.com with SMTP id h11-20020a17090a2ecb00b00237c740335cso10537633pjs.3 for ; Tue, 28 Feb 2023 18:51:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639098; 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=TQ32YeQqlpU2SWIdN54pZOPXYyq3HccNCuZQDJ1KcrAThiR2sJFLqXjOBPQp26Lqrc pUkAUMKar1UgyNKIeFKLS8D6Yc7OM8HVMlz8GVzWXmnTP3nMYNFqLJ4jzsGZoCUjcaGT RLidqstNoNp6O/E5arOa2/2AkIAbniq8AOtAwYE7bMGifsqP77xCyBLReH8FBY8wRxwf mG0WgXMAOf7QggpbtuZKQR3YYBJ0/ZcsLACuVoSKkRpVgo4u4EEsen5oiAVSmW8YZY6a hrqGisQw0IObQ4keq6NCydVGHBmS7W0IziQANcnhZiHwTtIeBsMWgcrTJbllZYDFrVOa Lrlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639098; 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=JCDONNj9ceucfopJjk2sZ0c8bT8HkuepSnT9whVA8D7D4kDLdb2+yA6MpT/cx29DMf 9SbXteiWLc2uiPYtJgpQlJs4ZhpLXCKQsDS5YclXTLvvwrLzkn/6CEx+9zuZxD+rXBy2 6MQHEjiBdCSz2qbu1AfQmnsEZneaUS6faG7jekzaNw9+MI/BidkPiLedtu5L7vN5URDJ OBDJ5gE13s1W//jd3S3Nfr8/sKdfo6j1JsjzHtwZ9ISSIwG/fxwwnzO9i1Oo6s8P1A8n 8TgPud5GZuA6zb7BlU/6T+imvMgRD45cvwnn64dLqsnWqXxUXvrLkifftdsWDRJQiVKB I3UA== X-Gm-Message-State: AO0yUKWiRN4RZ0zmKEJI5aGgQsxST6X/OLoP0F6A520UEo2AsPdaafzu GtjbJwKAff1YbZAr+rgsFhnoeA== X-Google-Smtp-Source: AK7set9rXSA2n2kAlK4YFIgncecUvOXMzrn8gt2c5qw0X4VshUU6snYxCy+M6SjftzLvCSXkMHoUlw== X-Received: by 2002:a17:903:1c4:b0:19c:bcae:b45a with SMTP id e4-20020a17090301c400b0019cbcaeb45amr6642615plh.65.1677639098435; Tue, 28 Feb 2023 18:51:38 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:37 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 02/12] cryptodev: Remove 'name' & 'model' fields Date: Wed, 1 Mar 2023 10:51:14 +0800 Message-Id: <20230301025124.3605557-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Wed Mar 1 02:51:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155463 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 E8537C64EC4 for ; Wed, 1 Mar 2023 02:52:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZG-0007bc-FP; Tue, 28 Feb 2023 21:51:46 -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 1pXCZE-0007b1-Ru for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:44 -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 1pXCZC-0001d3-UC for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:44 -0500 Received: by mail-pl1-x634.google.com with SMTP id p6so11711410plf.0 for ; Tue, 28 Feb 2023 18:51:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639102; 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=a2XlI5SfjW3Ta+CYw+U45UBXQWGaO1EkwQJT+COJfHKw+QjlHjG7QZ/eSWqvz8TQYD vXkiHj1b9ukibFivgh9XqZP08hKBTyRcm9hK6zuRHGKr6ywB7cXdPHgHiYFWXxXsWkQV GP6GjQvfxK3o5TWxPMydI1S+c+bl8u/z7yuVARfxKRvdLsHaablDfbTHbmAYLCg31ppO rZVYODaeyc3itpCPfGvAZ5OGGZ/JxetQmgqYhFS7p1XVWtnTNOmU3OjHLJPMVt+EDjqE oIQnUhDCGGEUvE1AOx4b0zQINaEb1C62ijrcm/oIt/q3CvP3KLRE3IIgsh+ls8A2ab9+ Q3PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639102; 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=Rjb4S3hxReaCHfU8T9nSALIIa+Jt+M+82PDJ0Ez1LBr8qc6oqa9v4M6Gc+DBaZSUWL r7/Q1Tzck2VV/Og97AnoSS2bpCde8xwivEqU7D0zqhEqNaqhWNY3KAql27ImDkegebdB lyrXH6uzEofgD69mNx4ZBSNZbYHlQT0li2svGE6ZiBzwXUKUDQxQ9gJ40V+UvIxCKtvG NHDA/4PI3kX9rxbXMxiwMjb/27599XBm70ZOnT+Wa++ITH0bbGZT827qkWPWMoi7tXig RL97VZrnUAca85KuPH0KEF/QuSDOSITZk1wSMXUhz6bxYRWEWMOjyPC2+dhI5OqVK0+K JxdA== X-Gm-Message-State: AO0yUKUqsOzxi1SkhsiPQw2X+1q7FahcXGBfyQq06OdmRJatvIpRuskU +vm4nTUkHwHcUaN23C6cA0f6XED2vAPHPCO9 X-Google-Smtp-Source: AK7set/OhYsyQJctcsuof966ghM7LAP1Zi2nSfnT3vCTwWfbiynL4SsRSqpWLY2n5/RYo8PZHCCmJA== X-Received: by 2002:a17:902:c94f:b0:19c:d663:a31b with SMTP id i15-20020a170902c94f00b0019cd663a31bmr5452944pla.24.1677639101685; Tue, 28 Feb 2023 18:51:41 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:41 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 03/12] cryptodev: Introduce cryptodev alg type in QAPI Date: Wed, 1 Mar 2023 10:51:15 +0800 Message-Id: <20230301025124.3605557-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Wed Mar 1 02:51:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155460 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 37155C64EC7 for ; Wed, 1 Mar 2023 02:52:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZK-0007c7-9V; Tue, 28 Feb 2023 21:51:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXCZI-0007bj-0o for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:48 -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 1pXCZG-0001dm-7O for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:47 -0500 Received: by mail-pl1-x631.google.com with SMTP id v11so9021123plz.8 for ; Tue, 28 Feb 2023 18:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639105; 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=aeJKHCTm7YgP2RTsEbaEM8/kyQRRj6F0RmgfQt0eMvfXqn+E2BDmi6FGuXpGm6ScMZ CgHoFovEp1es/t47Eeg5NCkaf37GB/Fe53f6c/sVE/+ZCASwHMICs2hREHD2DuRI3KP0 lqjkQZWiY3tjJ/kM6VSP9suNzZ+ALYyZ9YiqzTv4CBHeM43N26VblLIO4XqnXRNbgDNS uogtPsJS7Z0xFmSKyq5++Ci1mxPOoQiekOXDauDYJSa+s/k9mIIqfDOhOX32jwmwV0Rp TPLMlEki8LWFbvW13e8DOOUFDXemv8pj67VeA4lun+i+JQzetW1KOoMNUeL547EngNJD H+Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639105; 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=dzLvNIadaDVUaqD72U58P5XrbbuS+jiB5TYwM3L8UCitpPYYtZ2OB6iGOWLaklGoJ9 YZF3xa37ISbuIdnJODz1yrXjzNtfZz0CzWrkjRQRBp4BuGY9fziw/esY+L1yn0GiH27V jtqkLAVw2HeEetfKsK/DwtC4Dg8XTrpu8Hc7lvgQ3Nz+NBEeiHOgp7Qu2Lc+9cu8EwV7 eFCNWbtziuNYdg3LWxGRRITPwil/ERYJ02O7VTZd04/84YyGjbGIEJRa9OOxDi67X/eh E95Kh7DJAT3gCcKqgk9co9u4ZcqBcKRP3lrvw/2ecWu9K5uceUsE+qusQdtyTxQyXFQP QUww== X-Gm-Message-State: AO0yUKUaml56kEBvReU/hNt4viHAJAVHzpsQmRt1nqsraV1kfnRpyi8u CeySy4RBVLZeFa8meBknOjlTDQ== X-Google-Smtp-Source: AK7set9x9Mzo9zgeBtrEBvQ64r21Av6UKiuz4R6YXEVYrOBfd5nlMKxg+1iyAMAjhTjOMCcZykDZKQ== X-Received: by 2002:a17:902:e5c9:b0:19e:2d25:897e with SMTP id u9-20020a170902e5c900b0019e2d25897emr6019772plf.13.1677639104976; Tue, 28 Feb 2023 18:51:44 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:44 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 04/12] cryptodev: Introduce server type in QAPI Date: Wed, 1 Mar 2023 10:51:16 +0800 Message-Id: <20230301025124.3605557-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Wed Mar 1 02:51:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155466 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 90F62C6FA8E for ; Wed, 1 Mar 2023 02:53:13 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZP-0007fB-Rj; Tue, 28 Feb 2023 21:51:55 -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 1pXCZL-0007cR-Ho for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:51 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCZJ-0001ff-PI for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:51 -0500 Received: by mail-pj1-x1033.google.com with SMTP id m8-20020a17090a4d8800b002377bced051so15818037pjh.0 for ; Tue, 28 Feb 2023 18:51:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639108; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tZu7/hI7aL4wyGXCzAEJ1jd1KuiZ9b0q9eR9U/i2mso=; b=WNukf6DFFZqK72b8MjjDaH9hMX2eLR4XHKXxesvoqWmY2N2UPeVlaKPLrGv/atjevf EG/ZXpH6MSGNIT4mb1VTo/Lk23gktQqIHftylHwdyD2sg6Jmhhewc2UOjLm3u8X2YPJA Exoivh4YQSQqFcCPYbaZLKIw/cXH6MpslIBzHuotlhaJdcApx7ZGbbQFb/NyPY5z0vXf WYNYNOHtfAQKHNPgte3234roL/Oxdr//Zxyo1S4RvxoV0zIqXaD1nA91RaJ9LKM0K/Jg rjADB45zt1yxiudf+xuArCSwdNJCoLqGT9e9p65R6/01WQwvoLYhSLgpnewj8OWgC8UR 6jCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639108; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tZu7/hI7aL4wyGXCzAEJ1jd1KuiZ9b0q9eR9U/i2mso=; b=DWesdpMGqjTVs9ELahdQWvrcOkzY9ooxiSG6EBo86Pu3+ve9flWiPe239OlDIPRTOs Q3q7Jnv+kI2JY2siOLJeuVFxOhZ8X9bwPPmVTEmAv2EYWPWcB9hukXGsLTrFwff9vo12 2BNn9PFeMS/c+ULf2xUxgTmhbMuI/ci2LmfeLIFOtWRpELrdDfsJKReEFZbOpnJE85ZC jCLbi7gB1lHU/mxF8SoK02QIvfmTegTeruSj53R4f1fJSeyJVSmjxufqkhLupJy6zWAV pnt8FMI+x7H7etXikNmwujkRsXqx53voI3Eign8/ybKI21WrGbsuHqskzRyztrzdI1y+ 6gQQ== X-Gm-Message-State: AO0yUKXzaaV773wfGe6oKDAOaxIXjiWRZaw1hj+08erwAXoY9VM0QCSC sE53N2euC+T7JSiWvARgVDc4FA== X-Google-Smtp-Source: AK7set8JbAtFOBt64NT0oRd8wUMtqlXSg6MaPB31khkdBo5yyFMFENRbXpEe1j19tBKTrV05crudaQ== X-Received: by 2002:a17:903:27cd:b0:19d:e25:7ad9 with SMTP id km13-20020a17090327cd00b0019d0e257ad9mr3986732plb.64.1677639108273; Tue, 28 Feb 2023 18:51:48 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:47 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 05/12] cryptodev: Introduce 'query-cryptodev' QMP command Date: Wed, 1 Mar 2023 10:51:17 +0800 Message-Id: <20230301025124.3605557-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Reviewed-by: Daniel P. Berrangé --- backends/cryptodev.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ qapi/cryptodev.json | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index c2a053db0e..3a45d19823 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "sysemu/cryptodev.h" #include "qapi/error.h" +#include "qapi/qapi-commands-cryptodev.h" #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -33,6 +34,50 @@ static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; +static int qmp_query_cryptodev_foreach(Object *obj, void *data) +{ + CryptoDevBackend *backend; + QCryptodevInfoList **infolist = data; + uint32_t services, i; + + if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) { + return 0; + } + + QCryptodevInfo *info = g_new0(QCryptodevInfo, 1); + info->id = g_strdup(object_get_canonical_path_component(obj)); + + backend = CRYPTODEV_BACKEND(obj); + services = backend->conf.crypto_services; + for (i = 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) { + if (services & (1 << i)) { + QAPI_LIST_PREPEND(info->service, i); + } + } + + for (i = 0; i < backend->conf.peers.queues; i++) { + CryptoDevBackendClient *cc = backend->conf.peers.ccs[i]; + QCryptodevBackendClient *client = g_new0(QCryptodevBackendClient, 1); + + client->queue = cc->queue_index; + client->type = cc->type; + QAPI_LIST_PREPEND(info->client, client); + } + + QAPI_LIST_PREPEND(*infolist, info); + + return 0; +} + +QCryptodevInfoList *qmp_query_cryptodev(Error **errp) +{ + QCryptodevInfoList *list = NULL; + Object *objs = container_get(object_get_root(), "/objects"); + + object_child_foreach(objs, qmp_query_cryptodev_foreach, &list); + + return list; +} CryptoDevBackendClient *cryptodev_backend_new_client(void) { diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index 8732a30524..f33f96a692 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -43,3 +43,47 @@ { 'enum': 'QCryptodevBackendType', 'prefix': 'QCRYPTODEV_BACKEND_TYPE', 'data': ['builtin', 'vhost-user', 'lkcf']} + +## +# @QCryptodevBackendClient: +# +# Information about a queue of crypto device. +# +# @queue: the queue index of the crypto device +# +# @type: the type of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendClient', + 'data': { 'queue': 'uint32', + 'type': 'QCryptodevBackendType' } } + +## +# @QCryptodevInfo: +# +# Information about a crypto device. +# +# @id: the id of the crypto device +# +# @service: supported service types of a crypto device +# +# @client: the additional infomation of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevInfo', + 'data': { 'id': 'str', + 'service': ['QCryptodevBackendServiceType'], + 'client': ['QCryptodevBackendClient'] } } + +## +# @query-cryptodev: +# +# Returns information about current crypto devices. +# +# Returns: a list of @QCryptodevInfo +# +# Since: 8.0 +## +{ 'command': 'query-cryptodev', 'returns': ['QCryptodevInfo']} From patchwork Wed Mar 1 02:51:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155462 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 181CAC64EC7 for ; Wed, 1 Mar 2023 02:52:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZS-0007ko-E4; Tue, 28 Feb 2023 21:51: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 1pXCZO-0007fG-NL for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:55 -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 1pXCZN-0001i1-4f for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:54 -0500 Received: by mail-pj1-x102d.google.com with SMTP id q31-20020a17090a17a200b0023750b69614so11561813pja.5 for ; Tue, 28 Feb 2023 18:51:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639111; 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=Kpe8LKMkr7a/72dm8WtgxXk9hJckHktFFz/LSwFlRa/F08XanOuEOxn+RO4dAq3dQF kFZSqQbeihLfy0x26bIIl2AEDa/gugY133xtmDioxPoRI6DPsvgSLXmw921tgZyyVCiD Y9HqMhOuypmfBSrVCoJldkEuVAedFCKfskX2HmGugUlHdcXz2ASu7F7oyKERkUSpUYdM 4ic4+QSdtgRCxAiohi8n0FKVSGHNDF/V+CdLOi+hZN8/f+yWiuqLrU7VIN0rP13ykKnY +gUlkqqZKubq8QDvBxS/Q1jOb0qZmmTJmev2Svi5At4ZkgF17gVH2011BTaEq7khf7JR 9gbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639111; 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=rkUTYemD/ka6vDTi+0Mpcz9r4wdJoHkBnFoUBMEj0GIeOvS0KjRWZlBJGAFEGXc9Ah dr7r7AtJK9nVzxcAxmEVwNlx3SrY1CGEhQwz0zhAEnOh7brXLtH8zxSTxNrdUi/jlW7W q+SRJZH2jcges/IwqxMinPiLj0TdjkgbxhHhd3VWJFOEbt+Wo3ArTtuXIic8FQcycnLF rMk8/SLPFz9o8QUy9VE4YthHLcjloc6mGn41W+r8fJUJ/3VOEWjCVOgwwX0VKJOrvmA9 GbPDGLXdlvL53BRGBVPYFnCQ22nsjiIQMJIB4bzkpoTlqFamSG1uOiL/JySa3ZBL/B0r 5mKA== X-Gm-Message-State: AO0yUKX4FmQihgXBqSqaa4VSxZaAt3M7HsFjlL1OUFbFX4SoYeH1443v f1U0v8BGoxHj+frykqhRQJZ5CA== X-Google-Smtp-Source: AK7set8FzHHs37NfCiEvRKqVCIMwYWU26W1gA4wRDubZxGglk8B8nVVIUX2QBxjg2+Xp3YChgSc8kQ== X-Received: by 2002:a17:902:e5d2:b0:19c:ff5d:1fd2 with SMTP id u18-20020a170902e5d200b0019cff5d1fd2mr6014361plf.8.1677639111473; Tue, 28 Feb 2023 18:51:51 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:51 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 06/12] cryptodev-builtin: Detect akcipher capability Date: Wed, 1 Mar 2023 10:51:18 +0800 Message-Id: <20230301025124.3605557-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Wed Mar 1 02:51:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155469 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 33813C6FA8E for ; Wed, 1 Mar 2023 02:53:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZX-0007t5-An; Tue, 28 Feb 2023 21:52:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXCZR-0007jm-Fu for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:58 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCZP-0001ff-PS for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:51:57 -0500 Received: by mail-pj1-x1033.google.com with SMTP id m8-20020a17090a4d8800b002377bced051so15818220pjh.0 for ; Tue, 28 Feb 2023 18:51:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639115; 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=hW0/TnVbaKXVVnYFWE4r3/RgtfUxjdrwB+uyh9EgFgI=; b=E8H3miMVEdcYhb3G8BNVEUvhRUwP/DR6jrPUidud8osfIBKnKeTmI688nhcpbEReRV tx3717YB7hSD+fgLr2zeGpYvlOe2i9ZzyrCGryU6RRDaYpUbKjRbUs095OSzGYTBUxbw oBWOwJc1Eij/qWN/dprzrwH5ikE3WhZqhcrljxFIJzUJxn614t2IxtyrdKCVdsZ1qYtR XPq0eceQv3J0swnHcZ3C+nBLqI4OZnVELoLQngwIM5/RnXe3wKJ02tMpGlGwkcOjyd3X Tjdg/Yzdc40UuT3z+1jDLmnjmg3a0c/XnvQTRuZsO1rQwvHMJP3CAkqWOGf05iCKtUnJ DhWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639115; 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=hW0/TnVbaKXVVnYFWE4r3/RgtfUxjdrwB+uyh9EgFgI=; b=yTVhG8ZMNnSQxQbqmJrKWElM+sM9EItddhj/ACi0ppQ02LJDbb8C4J8755IRzDz8lD QL+iSbB5Cj0/pWv0u4nhhQOfH7+pa3Snhmf7gi3E5EpbOqMIvvQOCs+lQNL8fv21ecZ/ atu8QR5N+t5qSfoMqFhnjLguWZYxn12fta0m/QrKDWYSEQTQ7t4mlsjbGQjR9dbem7OV jqYOlfAh3x7/OFlp/CTYd3FjO7Pp2b6v2kWmRcgQqC+dEMbp7xbtoQsfy8RI4xLSBLFL e1330hmibb+wYQcgZcYQhYXyGIDAv1NzSXX4gfJ3DehsuB76IXh/rkBPegTGeeqZYivA KgVg== X-Gm-Message-State: AO0yUKUB/2cdOocWLq6EYwF+mmqePDdhjtpYxkSrIy3zsAgf7PgsKcJh MU2rlGgs1Uj4pamwkRrQ+sVVtgT246RmG1uw X-Google-Smtp-Source: AK7set9F1O4p36QLhTELHV14u1Z4YzNJYUC3q6Cx8eSHZppf3sfxWYtaRUWCPbznOvD0AZgQHl+X3A== X-Received: by 2002:a17:902:f545:b0:19a:8304:21eb with SMTP id h5-20020a170902f54500b0019a830421ebmr16097479plf.6.1677639114690; Tue, 28 Feb 2023 18:51:54 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:54 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 07/12] hmp: add cryptodev info command Date: Wed, 1 Mar 2023 10:51:19 +0800 Message-Id: <20230301025124.3605557-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Reviewed-by: Daniel P. Berrangé Acked-by: Dr. David Alan Gilbert Acked-by: Dr. David Alan Gilbert --- backends/cryptodev-hmp-cmds.c | 54 +++++++++++++++++++++++++++++++++++ backends/meson.build | 1 + hmp-commands-info.hx | 14 +++++++++ include/monitor/hmp.h | 1 + 4 files changed, 70 insertions(+) create mode 100644 backends/cryptodev-hmp-cmds.c diff --git a/backends/cryptodev-hmp-cmds.c b/backends/cryptodev-hmp-cmds.c new file mode 100644 index 0000000000..4f7220bb13 --- /dev/null +++ b/backends/cryptodev-hmp-cmds.c @@ -0,0 +1,54 @@ +/* + * HMP commands related to cryptodev + * + * Copyright (c) 2023 Bytedance.Inc + * + * Authors: + * zhenwei pi + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" +#include "qapi/qapi-commands-cryptodev.h" +#include "qapi/qmp/qdict.h" + + +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict) +{ + QCryptodevInfoList *il; + QCryptodevBackendServiceTypeList *sl; + QCryptodevBackendClientList *cl; + + for (il = qmp_query_cryptodev(NULL); il; il = il->next) { + g_autofree char *services = NULL; + QCryptodevInfo *info = il->value; + char *tmp_services; + + /* build a string like 'service=[akcipher|mac|hash|cipher]' */ + for (sl = info->service; sl; sl = sl->next) { + const char *service = QCryptodevBackendServiceType_str(sl->value); + + if (!services) { + services = g_strdup(service); + } else { + tmp_services = g_strjoin("|", services, service, NULL); + g_free(services); + services = tmp_services; + } + } + monitor_printf(mon, "%s: service=[%s]\n", info->id, services); + + for (cl = info->client; cl; cl = cl->next) { + QCryptodevBackendClient *client = cl->value; + monitor_printf(mon, " queue %" PRIu32 ": type=%s\n", + client->queue, + QCryptodevBackendType_str(client->type)); + } + } + + qapi_free_QCryptodevInfoList(il); +} diff --git a/backends/meson.build b/backends/meson.build index 954e658b25..b369e0a9d0 100644 --- a/backends/meson.build +++ b/backends/meson.build @@ -1,5 +1,6 @@ softmmu_ss.add([files( 'cryptodev-builtin.c', + 'cryptodev-hmp-cmds.c', 'cryptodev.c', 'hostmem-ram.c', 'hostmem.c', 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 2220f14fc9..e6cf0b7aa7 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -178,5 +178,6 @@ void hmp_ioport_read(Monitor *mon, const QDict *qdict); void hmp_ioport_write(Monitor *mon, const QDict *qdict); void hmp_boot_set(Monitor *mon, const QDict *qdict); void hmp_info_mtree(Monitor *mon, const QDict *qdict); +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict); #endif From patchwork Wed Mar 1 02:51:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155467 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 3C540C64EC7 for ; Wed, 1 Mar 2023 02:53:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZb-0007wi-QA; Tue, 28 Feb 2023 21:52:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXCZW-0007tC-73 for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:03 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCZU-0001lL-9d for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:01 -0500 Received: by mail-pl1-x633.google.com with SMTP id u5so9153409plq.7 for ; Tue, 28 Feb 2023 18:51:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZihvElP/m4HGVNphM2HN0ULRg0VcC4xnUtHDZg/U3cM=; b=BbhCkDKPQ3Au61LnkiEiP4DKzWSzaWArzSpOa+9QCqqi7IAhkWfudpqjyjU8/Zh448 oIr0/gbq5KdtevjJKyapwYq8ipgje9j1PsdTvgLtdoN8uZ8iVrxh2hcXWho8RG8v7AJe N0ByosOM+Omo9xY5IwhJh7sw1ys0pLwm9IWRN//o7Sf5TnvU886JNNDYRk6KhBC/j6Oz OW0YbkKLrAAbBMXoTo8+logX17iSK3SS8z0Ry8VCd5bJ5psvzREA/bvxs4TuK7zoDp83 iYyLhyNBhcn0Mncc8ypSy/sK6KKt0q/pOx592ORWCEdLW62rkUcxl5ZI3GcCoJaT5GXz rv8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZihvElP/m4HGVNphM2HN0ULRg0VcC4xnUtHDZg/U3cM=; b=QGVneUavrO8fbVUI4cu4TIGkJIi5yDsQC5IAASrxOxWVZkiSb12EQG8nE0xoEy2+fb 90yD42ASqXUBsY6erVuiAs9q0H99D131kamhRuI2WyQwr94+vrC3ZM4Lg3d6NbUJFym1 FnRDwFdBvZ6/dd3ojR3JVRrF77xa+Sh5gSqrq2lIemlrW/bSWzkbg5OdStZAWCXWiBex PkH8VfnWMWGut76e9Obw7siamqXx0DXKemkPapebDRNFeZRSTR8eFluhAphm6VApVF5v +KICOiTVpN3IzosJcl3a2gtU7FeqWjO18h1pJeefSFJFMEX586OOy13I5CO/KEHwc23f MohA== X-Gm-Message-State: AO0yUKW0aKMMmoNPS6Wcg0BMrNJ+IUpmKeb10Q+FK0qhSnzHllM7GL60 TfZEh0dG5ecwxfIUJBzX5rfwOg== X-Google-Smtp-Source: AK7set/KiVJ4EgbIgnOEVzm5Ji2AXrrwYQIt/ztE9du/vT8+ne6ylFOEBvQqpjBU1f3PsPqlWSSm/g== X-Received: by 2002:a17:903:40c6:b0:19c:d6d0:7887 with SMTP id t6-20020a17090340c600b0019cd6d07887mr4269856pld.30.1677639117963; Tue, 28 Feb 2023 18:51:57 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:51:57 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 08/12] cryptodev: Use CryptoDevBackendOpInfo for operation Date: Wed, 1 Mar 2023 10:51:20 +0800 Message-Id: <20230301025124.3605557-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Reviewed-by: Daniel P. Berrangé --- backends/cryptodev-builtin.c | 9 +++------ backends/cryptodev-lkcf.c | 9 +++------ backends/cryptodev.c | 18 +++++------------- hw/virtio/virtio-crypto.c | 7 ++++--- include/sysemu/cryptodev.h | 26 ++++++++++---------------- 5 files changed, 25 insertions(+), 44 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index c45b5906c5..39d0455280 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -539,10 +539,7 @@ static int cryptodev_builtin_asym_operation( static int cryptodev_builtin_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendBuiltin *builtin = CRYPTODEV_BACKEND_BUILTIN(backend); @@ -574,8 +571,8 @@ static int cryptodev_builtin_operation( if (local_error) { error_report_err(local_error); } - if (cb) { - cb(opaque, status); + if (op_info->cb) { + op_info->cb(op_info->opaque, status); } return 0; } diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index edec99f104..45aba1ff67 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -469,10 +469,7 @@ static void *cryptodev_lkcf_worker(void *arg) static int cryptodev_lkcf_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendLKCF *lkcf = CRYPTODEV_BACKEND_LKCF(backend); @@ -495,8 +492,8 @@ static int cryptodev_lkcf_operation( task = g_new0(CryptoDevLKCFTask, 1); task->op_info = op_info; - task->cb = cb; - task->opaque = opaque; + task->cb = op_info->cb; + task->opaque = op_info->opaque; task->sess = sess; task->lkcf = lkcf; task->status = -VIRTIO_CRYPTO_ERR; diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 3a45d19823..ba7b0bc770 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -143,29 +143,22 @@ int cryptodev_backend_close_session( static int cryptodev_backend_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(backend); if (bc->do_op) { - return bc->do_op(backend, op_info, queue_index, cb, opaque); + return bc->do_op(backend, op_info); } return -VIRTIO_CRYPTO_NOTSUPP; } int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, - void *opaque1, - uint32_t queue_index, - CryptoDevCompletionFunc cb, void *opaque2) + CryptoDevBackendOpInfo *op_info) { - VirtIOCryptoReq *req = opaque1; - CryptoDevBackendOpInfo *op_info = &req->op_info; - QCryptodevBackendAlgType algtype = req->flags; + QCryptodevBackendAlgType algtype = op_info->algtype; if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { @@ -173,8 +166,7 @@ int cryptodev_backend_crypto_operation( return -VIRTIO_CRYPTO_NOTSUPP; } - return cryptodev_backend_operation(backend, op_info, queue_index, - cb, opaque2); + return cryptodev_backend_operation(backend, op_info); } static void diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index e4f0de4d1c..802e1b9659 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -871,6 +871,9 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) opcode = ldl_le_p(&req.header.opcode); op_info->session_id = ldq_le_p(&req.header.session_id); op_info->op_code = opcode; + op_info->queue_index = queue_index; + op_info->cb = virtio_crypto_req_complete; + op_info->opaque = request; switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: @@ -898,9 +901,7 @@ check_result: virtio_crypto_req_complete(request, -VIRTIO_CRYPTO_NOTSUPP); } else { ret = cryptodev_backend_crypto_operation(vcrypto->cryptodev, - request, queue_index, - virtio_crypto_req_complete, - request); + op_info); if (ret < 0) { virtio_crypto_req_complete(request, ret); } diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 16f01dd48a..048a627035 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -174,9 +174,14 @@ typedef struct CryptoDevBackendAsymOpInfo { uint8_t *dst; } CryptoDevBackendAsymOpInfo; +typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); + typedef struct CryptoDevBackendOpInfo { QCryptodevBackendAlgType algtype; uint32_t op_code; + uint32_t queue_index; + CryptoDevCompletionFunc cb; + void *opaque; /* argument for cb */ uint64_t session_id; union { CryptoDevBackendSymOpInfo *sym_op_info; @@ -184,7 +189,6 @@ typedef struct CryptoDevBackendOpInfo { } u; } CryptoDevBackendOpInfo; -typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); struct CryptoDevBackendClass { ObjectClass parent_class; @@ -204,10 +208,7 @@ struct CryptoDevBackendClass { void *opaque); int (*do_op)(CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque); + CryptoDevBackendOpInfo *op_info); }; struct CryptoDevBackendClient { @@ -335,24 +336,17 @@ int cryptodev_backend_close_session( /** * cryptodev_backend_crypto_operation: * @backend: the cryptodev backend object - * @opaque1: pointer to a VirtIOCryptoReq object - * @queue_index: queue index of cryptodev backend client - * @errp: pointer to a NULL-initialized error object - * @cb: callbacks when operation is completed - * @opaque2: parameter passed to cb + * @op_info: pointer to a CryptoDevBackendOpInfo object * - * Do crypto operation, such as encryption and - * decryption + * Do crypto operation, such as encryption, decryption, signature and + * verification * * Returns: 0 for success and cb will be called when creation is completed, * negative value for error, and cb will not be called. */ int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, - void *opaque1, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque2); + CryptoDevBackendOpInfo *op_info); /** * cryptodev_backend_set_used: From patchwork Wed Mar 1 02:51:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155461 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 7C7CCC64EC4 for ; Wed, 1 Mar 2023 02:52:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZi-00082T-SL; Tue, 28 Feb 2023 21:52:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXCZZ-0007vs-4z for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:05 -0500 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCZX-0001lm-7B for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:04 -0500 Received: by mail-pj1-x102a.google.com with SMTP id x34so11945909pjj.0 for ; Tue, 28 Feb 2023 18:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Yevz87RZmt+inxiebXb+NEQnBTenjq4dQ5kejtSes+I=; b=PS6RQSp835f9hfJLe2FY4Ndt4wh9Wg6uJypqod6iBUpmqDPJFhvDE4k55Op8zOJ64l mSPOjjlWgQCOk6yg7mBCw69XOnmqAEy1dv3e4RexQupLR2+oa8c7u/2Ilpnpq7GwumKx c41dGWZTvExhUM/bDsNVp5UaS9Op5QTwffsaRx2hc44CBJPtipfDpkkFhLVp0u+iL7Xe qGoB9Y0Nfu5gbu4FQxbdGkso9hakdzt6nnxwvzjaYUdRxfbZ7Hb6UTHS22jhPrm98J0f vYdBHj2fUqDbT2CBbgqp2iAM0D6zECWf8FIMw4ebppnMdZMPNQg9WyQuNZuByFX0qhtC Mmmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yevz87RZmt+inxiebXb+NEQnBTenjq4dQ5kejtSes+I=; b=1IEJWdXr+lP6XfOKuU9iGogkWB2vTBWkfP01EvMpycnocoS9rJbReAo4cGvcXNyQ0S c7mIUZbUZl0hLHfrYcaGIz5BSWkj0YChJ6rdDyHHfnDik4bBIQ5vjgGc5pW/n5wtBnGp PxbiHLeQBg7qHTX660gEkoOYxtCpdJFePgJ0k6BxQU0lTcaE9c1mODI7dyxUX8mxgPOV WMeeIOTdWTTSrFf89QFfQdaHL1OJHT+gbmlh08msaow0OF6FHcxcX9cyaACo/HLxOrUj tB88BlYVwM4lNhqEAvUa7qCCGA67Z5cVj3vwJG2dpemCQkDDD3J1aS8+lDny2KYMfl9G I5Jg== X-Gm-Message-State: AO0yUKUeNKqMiEPHge4DpxhJJPavpydARf5R2PRPdRp41631dK4ZbTLh F+V1jtsFIZerdc1tweOdGBPRng== X-Google-Smtp-Source: AK7set8r9yBBr1P9C1qvmFTdUYG2SkDG4DVE+HJ492iWsRj5YbLJd3+Z6DG0F1f6v8K12C66CFaLXg== X-Received: by 2002:a17:903:42c4:b0:19c:f84b:58bf with SMTP id jy4-20020a17090342c400b0019cf84b58bfmr4159938plb.48.1677639121802; Tue, 28 Feb 2023 18:52:01 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:52:00 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 09/12] cryptodev: Account statistics Date: Wed, 1 Mar 2023 10:51:21 +0800 Message-Id: <20230301025124.3605557-10-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Account OPS/BPS for crypto device, this will be used for 'query-stats' QEMU monitor command and QoS in the next step. Note that a crypto device may support symmetric mode, asymmetric mode, both symmetric and asymmetric mode. So we use two structure to describe the statistics of a crypto device. Signed-off-by: zhenwei pi --- backends/cryptodev.c | 68 +++++++++++++++++++++++++++++++++++--- include/sysemu/cryptodev.h | 31 +++++++++++++++++ qapi/cryptodev.json | 54 ++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 5 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index ba7b0bc770..cc824e9665 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -107,6 +107,9 @@ void cryptodev_backend_cleanup( if (bc->cleanup) { bc->cleanup(backend, errp); } + + g_free(backend->sym_stat); + g_free(backend->asym_stat); } int cryptodev_backend_create_session( @@ -154,16 +157,61 @@ static int cryptodev_backend_operation( return -VIRTIO_CRYPTO_NOTSUPP; } +static int cryptodev_backend_account(CryptoDevBackend *backend, + CryptoDevBackendOpInfo *op_info) +{ + enum QCryptodevBackendAlgType algtype = op_info->algtype; + int len; + + if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) { + CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info; + len = asym_op_info->src_len; + switch (op_info->op_code) { + case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT: + QCryptodevAsymStatIncEncrypt(backend, len); + break; + case VIRTIO_CRYPTO_AKCIPHER_DECRYPT: + QCryptodevAsymStatIncDecrypt(backend, len); + break; + case VIRTIO_CRYPTO_AKCIPHER_SIGN: + QCryptodevAsymStatIncSign(backend, len); + break; + case VIRTIO_CRYPTO_AKCIPHER_VERIFY: + QCryptodevAsymStatIncVerify(backend, len); + break; + default: + return -VIRTIO_CRYPTO_NOTSUPP; + } + } else if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) { + CryptoDevBackendSymOpInfo *sym_op_info = op_info->u.sym_op_info; + len = sym_op_info->src_len; + switch (op_info->op_code) { + case VIRTIO_CRYPTO_CIPHER_ENCRYPT: + QCryptodevSymStatIncEncrypt(backend, len); + break; + case VIRTIO_CRYPTO_CIPHER_DECRYPT: + QCryptodevSymStatIncDecrypt(backend, len); + break; + default: + return -VIRTIO_CRYPTO_NOTSUPP; + } + } else { + error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); + return -VIRTIO_CRYPTO_NOTSUPP; + } + + return len; +} + int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, CryptoDevBackendOpInfo *op_info) { - QCryptodevBackendAlgType algtype = op_info->algtype; + int ret; - if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) - && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { - error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); - return -VIRTIO_CRYPTO_NOTSUPP; + ret = cryptodev_backend_account(backend, op_info); + if (ret < 0) { + return ret; } return cryptodev_backend_operation(backend, op_info); @@ -202,10 +250,20 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp) { CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc); CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc); + uint32_t services; if (bc->init) { bc->init(backend, errp); } + + services = backend->conf.crypto_services; + if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) { + backend->sym_stat = g_new0(QCryptodevBackendSymStat, 1); + } + + if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) { + backend->asym_stat = g_new0(QCryptodevBackendAsymStat, 1); + } } void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used) diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 048a627035..15e8c04dcf 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -253,8 +253,39 @@ struct CryptoDevBackend { /* Tag the cryptodev backend is used by virtio-crypto or not */ bool is_used; CryptoDevBackendConf conf; + QCryptodevBackendSymStat *sym_stat; + QCryptodevBackendAsymStat *asym_stat; }; +#define QCryptodevSymStatInc(be, op, bytes) do { \ + be->sym_stat->op##_bytes += (bytes); \ + be->sym_stat->op##_ops += 1; \ +} while (/*CONSTCOND*/0) + +#define QCryptodevSymStatIncEncrypt(be, bytes) \ + QCryptodevSymStatInc(be, encrypt, bytes) + +#define QCryptodevSymStatIncDecrypt(be, bytes) \ + QCryptodevSymStatInc(be, decrypt, bytes) + +#define QCryptodevAsymStatInc(be, op, bytes) do { \ + be->asym_stat->op##_bytes += (bytes); \ + be->asym_stat->op##_ops += 1; \ +} while (/*CONSTCOND*/0) + +#define QCryptodevAsymStatIncEncrypt(be, bytes) \ + QCryptodevAsymStatInc(be, encrypt, bytes) + +#define QCryptodevAsymStatIncDecrypt(be, bytes) \ + QCryptodevAsymStatInc(be, decrypt, bytes) + +#define QCryptodevAsymStatIncSign(be, bytes) \ + QCryptodevAsymStatInc(be, sign, bytes) + +#define QCryptodevAsymStatIncVerify(be, bytes) \ + QCryptodevAsymStatInc(be, verify, bytes) + + /** * cryptodev_backend_new_client: * diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index f33f96a692..54d7f9cb58 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -87,3 +87,57 @@ # Since: 8.0 ## { 'command': 'query-cryptodev', 'returns': ['QCryptodevInfo']} + +## +# @QCryptodevBackendSymStat: +# +# The statistics of symmetric operation. +# +# @encrypt-ops: the operations of symmetric encryption +# +# @decrypt-ops: the operations of symmetric decryption +# +# @encrypt-bytes: the bytes of symmetric encryption +# +# @decrypt-bytes: the bytes of symmetric decryption +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendSymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int' } } + +## +# @QCryptodevBackendAsymStat: +# +# The statistics of asymmetric operation. +# +# @encrypt-ops: the operations of asymmetric encryption +# +# @decrypt-ops: the operations of asymmetric decryption +# +# @sign-ops: the operations of asymmetric signature +# +# @verify-ops: the operations of asymmetric verification +# +# @encrypt-bytes: the bytes of asymmetric encryption +# +# @decrypt-bytes: the bytes of asymmetric decryption +# +# @sign-bytes: the bytes of asymmetric signature +# +# @verify-bytes: the bytes of asymmetric verification +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendAsymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'sign-ops': 'int', + 'verify-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int', + 'sign-bytes': 'int', + 'verify-bytes': 'int' } } From patchwork Wed Mar 1 02:51: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: 13155472 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 4428FC64EC4 for ; Wed, 1 Mar 2023 02:53:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZj-00082s-Fl; Tue, 28 Feb 2023 21:52:15 -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 1pXCZc-0007zu-6d for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:09 -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 1pXCZa-0001d3-35 for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:07 -0500 Received: by mail-pl1-x634.google.com with SMTP id p6so11712080plf.0 for ; Tue, 28 Feb 2023 18:52:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639125; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=INrx0BfaOa4IFJ+qXVprp2CmsCQfySfcHiPFFgrxkcs=; b=kJgz+KxRsEkDyWWeKqaQFGR7ZEWdrWDpF6W4sQClAG75FaUfAwsdFnK72gDkXeKkTo cb1wuCjZqUbII6C3+fVqOEN+l3mdt/foVefoDs+kmIAPv9qzdcgi7xj3dWBi6D4O7tkd 7aWssaeugcJzE8F/9UenK9zF0QLA+go9S2AQhlT0Uf4DlGHUDBKnALwwCk4bx+Z8C7Xs kjdoE9Wqa6E+sGQF8g/j5ZUQUZkRmrKEJpIPj5TP1LwOd3LlEmGHe+6oambEtkA/v3AS COtAfEJAfZsZshJO1FRjTCUsa96II42X48KfO/B060XUn2Ss2LGX8bn4pKqtyKhH/1bG 3ouA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639125; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=INrx0BfaOa4IFJ+qXVprp2CmsCQfySfcHiPFFgrxkcs=; b=cyVtLBCDYv3sketv6Rllx4JfnKkA77MxEZXBuQamZl7l6o3PYaTjHNyIzJeCw539oa 3HxZwCJQsb+PLU0FRZ/ur366TCv7M13r19N8TyQjKJTij9RZEX3kW47QLV9bLycgCuTg b6YtfwEvGSIFmnJFtOoyOSN5EGa9YcFvXaQJXXh9pYUKluiK9oKeWe0b+eU/kZa7Q7QM R5RMp5VBSWmhtBOukEXeKXliDTio82mhG/pYOpNjdSnl0KCANAHRALml35AB0q1i0Omj ygVJVjqDMlEyPIY/mylXWDBD3NYHPqJLwxK9iaUXL0UhptlHWv5w7lj6bbUAxxYbWuPD 3jAA== X-Gm-Message-State: AO0yUKXqke8Cp7vS/FHq+qJAhybnt+RpoCEFU7JYgAMqMLWVoTaN/mmw Mm3Gnk/WA53KErLY152I3GiGQQ== X-Google-Smtp-Source: AK7set+8iiCCRDGWOFiRgA2L4wKrsa2gtpAzy2tokjGnvrvxTI6xsS86d6euU4cquNFNY5gbQMlJqg== X-Received: by 2002:a17:902:e80a:b0:19b:afb:b92e with SMTP id u10-20020a170902e80a00b0019b0afbb92emr5767880plg.40.1677639125368; Tue, 28 Feb 2023 18:52:05 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:52:04 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 10/12] cryptodev: support QoS Date: Wed, 1 Mar 2023 10:51:22 +0800 Message-Id: <20230301025124.3605557-11-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Reviewed-by: Daniel P. Berrangé --- backends/cryptodev.c | 138 +++++++++++++++++++++++++++++++++++++ include/sysemu/cryptodev.h | 7 ++ qapi/qom.json | 8 ++- 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index cc824e9665..09ffdd345f 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -28,6 +28,7 @@ #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/main-loop.h" #include "qom/object_interfaces.h" #include "hw/virtio/virtio-crypto.h" @@ -203,17 +204,53 @@ static int cryptodev_backend_account(CryptoDevBackend *backend, return len; } +static void cryptodev_backend_throttle_timer_cb(void *opaque) +{ + CryptoDevBackend *backend = (CryptoDevBackend *)opaque; + CryptoDevBackendOpInfo *op_info, *tmpop; + int ret; + + QTAILQ_FOREACH_SAFE(op_info, &backend->opinfos, next, tmpop) { + QTAILQ_REMOVE(&backend->opinfos, op_info, next); + ret = cryptodev_backend_account(backend, op_info); + if (ret < 0) { + op_info->cb(op_info->opaque, ret); + continue; + } + + throttle_account(&backend->ts, true, ret); + cryptodev_backend_operation(backend, op_info); + if (throttle_enabled(&backend->tc) && + throttle_schedule_timer(&backend->ts, &backend->tt, true)) { + break; + } + } +} + int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, CryptoDevBackendOpInfo *op_info) { int ret; + if (!throttle_enabled(&backend->tc)) { + goto do_account; + } + + if (throttle_schedule_timer(&backend->ts, &backend->tt, true) || + !QTAILQ_EMPTY(&backend->opinfos)) { + QTAILQ_INSERT_TAIL(&backend->opinfos, op_info, next); + return 0; + } + +do_account: ret = cryptodev_backend_account(backend, op_info); if (ret < 0) { return ret; } + throttle_account(&backend->ts, true, ret); + return cryptodev_backend_operation(backend, op_info); } @@ -245,12 +282,98 @@ cryptodev_backend_set_queues(Object *obj, Visitor *v, const char *name, backend->conf.peers.queues = value; } +static void cryptodev_backend_set_throttle(CryptoDevBackend *backend, int field, + uint64_t value, Error **errp) +{ + uint64_t orig = backend->tc.buckets[field].avg; + bool enabled = throttle_enabled(&backend->tc); + + if (orig == value) { + return; + } + + backend->tc.buckets[field].avg = value; + if (!throttle_enabled(&backend->tc)) { + throttle_timers_destroy(&backend->tt); + cryptodev_backend_throttle_timer_cb(backend); /* drain opinfos */ + return; + } + + if (!throttle_is_valid(&backend->tc, errp)) { + backend->tc.buckets[field].avg = orig; /* revert change */ + return; + } + + if (!enabled) { + throttle_init(&backend->ts); + throttle_timers_init(&backend->tt, qemu_get_aio_context(), + QEMU_CLOCK_REALTIME, + cryptodev_backend_throttle_timer_cb, /* FIXME */ + cryptodev_backend_throttle_timer_cb, backend); + } + + throttle_config(&backend->ts, QEMU_CLOCK_REALTIME, &backend->tc); +} + +static void cryptodev_backend_get_bps(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value = backend->tc.buckets[THROTTLE_BPS_TOTAL].avg; + + visit_type_uint64(v, name, &value, errp); +} + +static void cryptodev_backend_set_bps(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, errp); +} + +static void cryptodev_backend_get_ops(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value = backend->tc.buckets[THROTTLE_OPS_TOTAL].avg; + + visit_type_uint64(v, name, &value, errp); +} + +static void cryptodev_backend_set_ops(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, errp); +} + static void cryptodev_backend_complete(UserCreatable *uc, Error **errp) { CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc); CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc); uint32_t services; + uint64_t value; + + QTAILQ_INIT(&backend->opinfos); + value = backend->tc.buckets[THROTTLE_OPS_TOTAL].avg; + cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, errp); + value = backend->tc.buckets[THROTTLE_BPS_TOTAL].avg; + cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, errp); if (bc->init) { bc->init(backend, errp); @@ -294,8 +417,12 @@ cryptodev_backend_can_be_deleted(UserCreatable *uc) static void cryptodev_backend_instance_init(Object *obj) { + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + /* Initialize devices' queues property to 1 */ object_property_set_int(obj, "queues", 1, NULL); + + throttle_config_init(&backend->tc); } static void cryptodev_backend_finalize(Object *obj) @@ -303,6 +430,9 @@ static void cryptodev_backend_finalize(Object *obj) CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); cryptodev_backend_cleanup(backend, NULL); + if (throttle_enabled(&backend->tc)) { + throttle_timers_destroy(&backend->tt); + } } static void @@ -318,6 +448,14 @@ cryptodev_backend_class_init(ObjectClass *oc, void *data) cryptodev_backend_get_queues, cryptodev_backend_set_queues, NULL, NULL); + object_class_property_add(oc, "throttle-bps", "uint64", + cryptodev_backend_get_bps, + cryptodev_backend_set_bps, + NULL, NULL); + object_class_property_add(oc, "throttle-ops", "uint64", + cryptodev_backend_get_ops, + cryptodev_backend_set_ops, + NULL, NULL); } static const TypeInfo cryptodev_backend_info = { diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 15e8c04dcf..113eec4caf 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -24,6 +24,7 @@ #define CRYPTODEV_H #include "qemu/queue.h" +#include "qemu/throttle.h" #include "qom/object.h" #include "qapi/qapi-types-cryptodev.h" @@ -187,6 +188,7 @@ typedef struct CryptoDevBackendOpInfo { CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendAsymOpInfo *asym_op_info; } u; + QTAILQ_ENTRY(CryptoDevBackendOpInfo) next; } CryptoDevBackendOpInfo; struct CryptoDevBackendClass { @@ -255,6 +257,11 @@ struct CryptoDevBackend { CryptoDevBackendConf conf; QCryptodevBackendSymStat *sym_stat; QCryptodevBackendAsymStat *asym_stat; + + ThrottleState ts; + ThrottleTimers tt; + ThrottleConfig tc; + QTAILQ_HEAD(, CryptoDevBackendOpInfo) opinfos; }; #define QCryptodevSymStatInc(be, op, bytes) do { \ diff --git a/qapi/qom.json b/qapi/qom.json index 30e76653ad..a877b879b9 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -278,10 +278,16 @@ # cryptodev-backend and must be 1 for cryptodev-backend-builtin. # (default: 1) # +# @throttle-bps: limit total bytes per second (Since 8.0) +# +# @throttle-ops: limit total operations per second (Since 8.0) +# # Since: 2.8 ## { 'struct': 'CryptodevBackendProperties', - 'data': { '*queues': 'uint32' } } + 'data': { '*queues': 'uint32', + '*throttle-bps': 'uint64', + '*throttle-ops': 'uint64' } } ## # @CryptodevVhostUserProperties: From patchwork Wed Mar 1 02:51: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: 13155471 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 86AA8C7EE32 for ; Wed, 1 Mar 2023 02:53:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZj-00082a-6V; Tue, 28 Feb 2023 21:52:15 -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 1pXCZg-00080G-1E for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:12 -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 1pXCZe-0001nK-0o for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:11 -0500 Received: by mail-pj1-x102f.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so11254265pjg.4 for ; Tue, 28 Feb 2023 18:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639129; 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=GbgEvrqH7D2h3weUsC/mv9R1HaMrDMQO1h7Eqp1HmGU=; b=dsR+cdWWemrSMw/8dVA8IiTPoj8oSpfXIOzwqmwNTTZbULj/XejjiDhzkccfbpEa7E /w6GezgEPVv+RTKnpyu1RyC6+7oL1YH+G6JtBmlPhsd0QJ4JnfDmGpcNXQH5VUrEk5BD EVT9zdpY4/uZkrMowLg7mNY+2BvPErSPHYYTnXaK3g92gEXOnM7EXV79BdvrTrnnMJth T+MfN5QNJEiVsw5nnjlzoNdLSa1t6dQIp4JxM+twoIDg+WGzz9IDUJXaHI1z8sRQLFIm bSMpCuxdnRbm9iOjcNeZfzG5NIBpDhkawbZjvbgZmzl39Oz47Qvt05EfsdXumcPJUIDq atrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639129; 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=GbgEvrqH7D2h3weUsC/mv9R1HaMrDMQO1h7Eqp1HmGU=; b=hfYrWa0gafcQBoUC5y9DAKJ7iPWxxk80/SHhu0Upxp9tsx5mCxmHKCu9yNPbYgZI0V EehKAWxWffpeChaBinNT0PhuU08oj1VMM56yzT9kiZuQbHD5INGI9rB1qYFJevCTBM+w WcwK4FehJ4J65zvrKCiKuiLiw8FzgPLzRYjgDSU92Y3wA/stW9NKfS8+eg121GWJV81N HLsKSKTaJES8j9BB4FTInK/rpBaSdGJ3Zh2RSL4kiOBdILePcq5ZpQzanmfY4AcEVn4+ wu3tOluz2dz74cyYaTnWT1HLD/SxrAZqIHjmZWbydMnrj2C0ZUyHWNscig53AMEv53ep cyPQ== X-Gm-Message-State: AO0yUKWHOvUr6pzGlzzGq/H1EarMZmfVWaFMbRoAHQejJTWL8BdXm2kf cMqSTPm+UqmLDo3ggZrviDIuEQ== X-Google-Smtp-Source: AK7set8X79cb5t15NeE/MWXM/3sP3VNmiSTzlSezc8nq937eQuQIetPunFU6/J2jHc2lEMcq8OMm/A== X-Received: by 2002:a17:902:d488:b0:19e:2e6b:1448 with SMTP id c8-20020a170902d48800b0019e2e6b1448mr6294530plg.2.1677639128725; Tue, 28 Feb 2023 18:52:08 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:52:08 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 11/12] cryptodev: Support query-stats QMP command Date: Wed, 1 Mar 2023 10:51:23 +0800 Message-Id: <20230301025124.3605557-12-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 Reviewed-by: Daniel P. Berrangé --- backends/cryptodev.c | 155 +++++++++++++++++++++++++++++++++++++++++ qapi/stats.json | 10 ++- stats/stats-hmp-cmds.c | 5 ++ stats/stats-qmp-cmds.c | 2 + 4 files changed, 170 insertions(+), 2 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 09ffdd345f..d8a54c0236 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -23,8 +23,10 @@ #include "qemu/osdep.h" #include "sysemu/cryptodev.h" +#include "sysemu/stats.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,28 @@ #include "qom/object_interfaces.h" #include "hw/virtio/virtio-crypto.h" +#define SYM_ENCRYPT_OPS_STR "sym-encrypt-ops" +#define SYM_DECRYPT_OPS_STR "sym-decrypt-ops" +#define SYM_ENCRYPT_BYTES_STR "sym-encrypt-bytes" +#define SYM_DECRYPT_BYTES_STR "sym-decrypt-bytes" + +#define ASYM_ENCRYPT_OPS_STR "asym-encrypt-ops" +#define ASYM_DECRYPT_OPS_STR "asym-decrypt-ops" +#define ASYM_SIGN_OPS_STR "asym-sign-ops" +#define ASYM_VERIFY_OPS_STR "asym-verify-ops" +#define ASYM_ENCRYPT_BYTES_STR "asym-encrypt-bytes" +#define ASYM_DECRYPT_BYTES_STR "asym-decrypt-bytes" +#define ASYM_SIGN_BYTES_STR "asym-sign-bytes" +#define ASYM_VERIFY_BYTES_STR "asym-verify-bytes" + +typedef struct StatsArgs { + union StatsResultsType { + StatsResultList **stats; + StatsSchemaList **schema; + } result; + strList *names; + Error **errp; +} StatsArgs; static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; @@ -435,6 +459,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_STR, + &sym_stat->encrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add(SYM_DECRYPT_OPS_STR, + &sym_stat->decrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add(SYM_ENCRYPT_BYTES_STR, + &sym_stat->encrypt_bytes, stats_list); + stats_list = cryptodev_backend_stats_add(SYM_DECRYPT_BYTES_STR, + &sym_stat->decrypt_bytes, stats_list); + } + + asym_stat = backend->asym_stat; + if (asym_stat) { + stats_list = cryptodev_backend_stats_add(ASYM_ENCRYPT_OPS_STR, + &asym_stat->encrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add(ASYM_DECRYPT_OPS_STR, + &asym_stat->decrypt_ops, stats_list); + stats_list = cryptodev_backend_stats_add(ASYM_SIGN_OPS_STR, + &asym_stat->sign_ops, stats_list); + stats_list = cryptodev_backend_stats_add(ASYM_VERIFY_OPS_STR, + &asym_stat->verify_ops, stats_list); + stats_list = cryptodev_backend_stats_add(ASYM_ENCRYPT_BYTES_STR, + &asym_stat->encrypt_bytes, stats_list); + stats_list = cryptodev_backend_stats_add(ASYM_DECRYPT_BYTES_STR, + &asym_stat->decrypt_bytes, stats_list); + stats_list = cryptodev_backend_stats_add(ASYM_SIGN_BYTES_STR, + &asym_stat->sign_bytes, stats_list); + stats_list = cryptodev_backend_stats_add(ASYM_VERIFY_BYTES_STR, + &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_STR, SYM_DECRYPT_OPS_STR, + SYM_ENCRYPT_BYTES_STR, SYM_DECRYPT_BYTES_STR }; + const char *asym_stats[] = { ASYM_ENCRYPT_OPS_STR, ASYM_DECRYPT_OPS_STR, + ASYM_SIGN_OPS_STR, ASYM_VERIFY_OPS_STR, + ASYM_ENCRYPT_BYTES_STR, ASYM_DECRYPT_BYTES_STR, + ASYM_SIGN_BYTES_STR, ASYM_VERIFY_BYTES_STR }; + + 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 +608,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/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 8.0 +# # Since: 7.1 ## { 'enum': 'StatsTarget', - 'data': [ 'vm', 'vcpu' ] } + 'data': [ 'vm', 'vcpu', 'cryptodev' ] } ## # @StatsRequest: diff --git a/stats/stats-hmp-cmds.c b/stats/stats-hmp-cmds.c index 531e35d128..1f91bf8bd5 100644 --- a/stats/stats-hmp-cmds.c +++ b/stats/stats-hmp-cmds.c @@ -155,6 +155,8 @@ static StatsFilter *stats_filter(StatsTarget target, const char *names, filter->u.vcpu.vcpus = vcpu_list; break; } + case STATS_TARGET_CRYPTODEV: + break; default: break; } @@ -226,6 +228,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/stats/stats-qmp-cmds.c b/stats/stats-qmp-cmds.c index bc973747fb..e214b964fd 100644 --- a/stats/stats-qmp-cmds.c +++ b/stats/stats-qmp-cmds.c @@ -64,6 +64,8 @@ static bool invoke_stats_cb(StatsCallbacks *entry, targets = filter->u.vcpu.vcpus; } break; + case STATS_TARGET_CRYPTODEV: + break; default: abort(); } From patchwork Wed Mar 1 02:51:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13155464 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 015DBC6FA8E for ; Wed, 1 Mar 2023 02:52:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCZk-00089w-U1; Tue, 28 Feb 2023 21:52:16 -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 1pXCZi-000829-Ci for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:14 -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 1pXCZg-0001nK-NB for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:52:14 -0500 Received: by mail-pj1-x102f.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so11254357pjg.4 for ; Tue, 28 Feb 2023 18:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677639132; 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=CoSIyarAIU04vw264hmDOARNwoMR9ygoAxd2VOTLPP4=; b=JfNVdEvO2xGf+jF62ZN4lAERV1WgCyiaBgdFY6brdDHjZVf4X860XHIGPwXJaEddbh BxjTnV1qyxZxDvDuMB+iK7jWbJkK+5WVtCsPbQy7Q7EGVh5LdHDkv2iwCgTNh1tN3YSC 7FsODMd5LJDVqfiLOqPiKKOUr8DEZDqK5y3xVaxigj4okjTKu0g9PY6JvIOK9xBetvML Ib9qgjRX/3I3uZTYm/cu6RAhgdby8ZKQgLgkF6jFoNK044S1Hl8oulcnaaSsis+eECpo bevvto46v2hev0qG1oxBYQbzFzOp0zqjnECwFLg/iKVuBws65Xz2nh7Ic2evxnZIVXUf /CnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677639132; 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=CoSIyarAIU04vw264hmDOARNwoMR9ygoAxd2VOTLPP4=; b=y9jZcfrA+jf5/hDUPSzf1K4OO7ju52ur/DQTPY390zATBi0Fd0NwdQiUDbJngPpZMO /EOL/gEPItV/7oY3noOo9WwqgQG51oTHtFqU9x4SwXN6rhYaiMci55TpEPHhCai5olHR 9OHazP1VWbRVpexxe23UBYoAuVdjFiRBLHBDyOomOA2xy4mjkHCx+3FywUHJKa65yrkn qHSM24LcVZ74b+kKACZREoQ44DozX/ymhecgos+7TcSKiCc5DqUQTMhUBuKtIbkReb9y XpL+AL5DqodooA40OBlilOuYtu5h54kmkAPZWcPq5bG5QW/0oRzLBcRRm/COMH/hRvn2 1f2A== X-Gm-Message-State: AO0yUKX7jFOM07OzrMKrgVxgBrfngfSBMLleOUnZA/0IqS3ZpREj3S0e T4BWBgeJ+O7jjtEj79EpaU0NUg== X-Google-Smtp-Source: AK7set8dingixSEX8cA21c/DVsVdM9T5vJs0vfrRhirRE46e8GBTR4UVuUBPiWf9UNLW/cfqKrQLig== X-Received: by 2002:a17:902:c401:b0:19c:d5f9:337f with SMTP id k1-20020a170902c40100b0019cd5f9337fmr6445854plk.5.1677639131961; Tue, 28 Feb 2023 18:52:11 -0800 (PST) Received: from libai.bytedance.net ([61.213.176.5]) by smtp.gmail.com with ESMTPSA id ix1-20020a170902f80100b0019ab58f47a6sm7218743plb.105.2023.02.28.18.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:52:11 -0800 (PST) From: zhenwei pi To: mst@redhat.com, arei.gonglei@huawei.com Cc: dgilbert@redhat.com, pbonzini@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com, zhenwei pi Subject: [PATCH v5 12/12] MAINTAINERS: add myself as the maintainer for cryptodev Date: Wed, 1 Mar 2023 10:51:24 +0800 Message-Id: <20230301025124.3605557-13-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025124.3605557-1-pizhenwei@bytedance.com> References: <20230301025124.3605557-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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-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 7651cb0ace..0bac2e8bcf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2867,6 +2867,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