From patchwork Tue Nov 22 14:07:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052416 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 AC7ADC43217 for ; Tue, 22 Nov 2022 14:09:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTt7-0008Qq-3d; Tue, 22 Nov 2022 09:04:37 -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 1oxTt4-0008QL-CZ for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:34 -0500 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTt2-00061b-F2 for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:34 -0500 Received: by mail-pj1-x1029.google.com with SMTP id v3-20020a17090ac90300b00218441ac0f6so1617735pjt.0 for ; Tue, 22 Nov 2022 06:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=upOk1cGisgMNYeCZpXZKpnoG2v3kRWP3UR8ECMzDAoM=; b=10w6f4hClSaSMa9V6gwjtQ+wdehIC5Bd3wgdjLFgOZlUuM3OYr0tbJOg9hnlJ0a3c3 WfWnoPyoguRTSXnvqHQAeSfmdhm/safZLDapnG6BBl1S7qgfc8iJjMc0Dx26NgUetJUR tCq/D/GS5a5SDC5plYBHaNtaU4yntJWLvYefRPx4ts6+JFRzKlkDrYCPf7Tv0FudhDhq YEyRtP+IV36YSpCO1hk5ZxgsmUExt+Jl+FO7Mep2iP5dgEJTF7N0iTKdPlUJUyEy00v4 Tbvp1yxDS71o0X/ND7XOSsCVJeX64q0aVV5cklXdpQF+hfTk7euiFV4aw7g1JbsafsTi 0K3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=upOk1cGisgMNYeCZpXZKpnoG2v3kRWP3UR8ECMzDAoM=; b=fKqxwAF9g7hELDf7QRteF5X0iidXTNkPca9aXmQRPonh+W4Z5x9vYBkxTNbQLa5zfO LrS+HLvFjZn50GkTWUH5sDxKWbBZH7V6FmwtLPjMVzO2RiwU6Xu6BRhJqyrO+yxMaWfD mRU8BVDMa7fj0VT6MNcvOonGSf4g6l8ouTVuI0si5GR0Cp0oJNlVNA0+y7i8hTkrHIqC mTSINJTRkukglLr2/O4xiP7QJW+1mtebQbtkHNnIa+Yal4ClkVjAQyNGXYkQEQ2L1GMU dS5WyrHSDyl34w99EaFYWkgpfFiZJlYkcvjyfRPcwKc6Emf5pQuQttp2pOAWK+2QXIaE v7hg== X-Gm-Message-State: ANoB5pnwIfGe0aOd8AyUUGra7VWxobgf4ENDzymacbyqPk3VBVfPfeEB TbSd2q6t9O4w/4jGDfn5emy3tA== X-Google-Smtp-Source: AA0mqf5jeCiNJAy9tm0jlG7I63ypk9YBeytk3aUEiVfWGQqEVY9RErQYfVIiT6wAx81hCd0CkxYGaA== X-Received: by 2002:a17:902:c385:b0:186:944a:2560 with SMTP id g5-20020a170902c38500b00186944a2560mr4951542plg.84.1669125870795; Tue, 22 Nov 2022 06:04:30 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:04:30 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 01/11] cryptodev: Introduce cryptodev.json Date: Tue, 22 Nov 2022 22:07:46 +0800 Message-Id: <20221122140756.686982-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1029.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce QCryptodevBackendType in cryptodev.json, also apply this to related codes. Then we can drop 'enum CryptoDevBackendOptionsType'. Signed-off-by: zhenwei pi Reviewed-by: Daniel P. Berrangé --- MAINTAINERS | 1 + backends/cryptodev-builtin.c | 2 +- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 4 ++-- backends/cryptodev-vhost.c | 4 ++-- include/sysemu/cryptodev.h | 11 ++--------- qapi/cryptodev.json | 20 ++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 9 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 qapi/cryptodev.json diff --git a/MAINTAINERS b/MAINTAINERS index caba73ec41..3f698cb0e9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2830,6 +2830,7 @@ M: Gonglei S: Maintained F: include/sysemu/cryptodev*.h F: backends/cryptodev*.c +F: qapi/cryptodev.json Python library M: John Snow diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index cda6ca3b71..8c7c10847d 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -76,7 +76,7 @@ static void cryptodev_builtin_init( "cryptodev-builtin", NULL); cc->info_str = g_strdup_printf("cryptodev-builtin0"); cc->queue_index = 0; - cc->type = CRYPTODEV_BACKEND_TYPE_BUILTIN; + cc->type = QCRYPTODEV_BACKEND_TYPE_BUILTIN; backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 133bd706a4..91e02c0df9 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -226,7 +226,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp) cc = cryptodev_backend_new_client("cryptodev-lkcf", NULL); cc->info_str = g_strdup_printf("cryptodev-lkcf0"); cc->queue_index = 0; - cc->type = CRYPTODEV_BACKEND_TYPE_LKCF; + cc->type = QCRYPTODEV_BACKEND_TYPE_LKCF; backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c index ab3028e045..c165a1b1d6 100644 --- a/backends/cryptodev-vhost-user.c +++ b/backends/cryptodev-vhost-user.c @@ -67,7 +67,7 @@ cryptodev_vhost_user_get_vhost( { CryptoDevBackendVhostUser *s = CRYPTODEV_BACKEND_VHOST_USER(b); - assert(cc->type == CRYPTODEV_BACKEND_TYPE_VHOST_USER); + assert(cc->type == QCRYPTODEV_BACKEND_TYPE_VHOST_USER); assert(queue < MAX_CRYPTO_QUEUE_NUM); return s->vhost_crypto[queue]; @@ -203,7 +203,7 @@ static void cryptodev_vhost_user_init( cc->info_str = g_strdup_printf("cryptodev-vhost-user%zu to %s ", i, chr->label); cc->queue_index = i; - cc->type = CRYPTODEV_BACKEND_TYPE_VHOST_USER; + cc->type = QCRYPTODEV_BACKEND_TYPE_VHOST_USER; backend->conf.peers.ccs[i] = cc; diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index bc13e466b4..0715014552 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -128,7 +128,7 @@ cryptodev_get_vhost(CryptoDevBackendClient *cc, switch (cc->type) { #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX) - case CRYPTODEV_BACKEND_TYPE_VHOST_USER: + case QCRYPTODEV_BACKEND_TYPE_VHOST_USER: vhost_crypto = cryptodev_vhost_user_get_vhost(cc, b, queue); break; #endif @@ -196,7 +196,7 @@ int cryptodev_vhost_start(VirtIODevice *dev, int total_queues) * because vhost user doesn't interrupt masking/unmasking * properly. */ - if (cc->type == CRYPTODEV_BACKEND_TYPE_VHOST_USER) { + if (cc->type == QCRYPTODEV_BACKEND_TYPE_VHOST_USER) { dev->use_guest_notifier_mask = false; } } diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index cf9b3f07fe..8d2adda974 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -25,6 +25,7 @@ #include "qemu/queue.h" #include "qom/object.h" +#include "qapi/qapi-types-cryptodev.h" /** * CryptoDevBackend: @@ -215,16 +216,8 @@ struct CryptoDevBackendClass { void *opaque); }; -typedef enum CryptoDevBackendOptionsType { - CRYPTODEV_BACKEND_TYPE_NONE = 0, - CRYPTODEV_BACKEND_TYPE_BUILTIN = 1, - CRYPTODEV_BACKEND_TYPE_VHOST_USER = 2, - CRYPTODEV_BACKEND_TYPE_LKCF = 3, - CRYPTODEV_BACKEND_TYPE__MAX, -} CryptoDevBackendOptionsType; - struct CryptoDevBackendClient { - CryptoDevBackendOptionsType type; + QCryptodevBackendType type; char *model; char *name; char *info_str; diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json new file mode 100644 index 0000000000..b65edbe183 --- /dev/null +++ b/qapi/cryptodev.json @@ -0,0 +1,20 @@ +# -*- Mode: Python -*- +# vim: filetype=python +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. + +## +# @QCryptodevBackendType: +# +# The crypto device backend type +# +# @builtin: the QEMU builtin support +# @vhost-user: vhost-user +# @lkcf: Linux kernel cryptographic framework +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendType', + 'prefix': 'QCRYPTODEV_BACKEND_TYPE', + 'data': ['builtin', 'vhost-user', 'lkcf']} diff --git a/qapi/meson.build b/qapi/meson.build index 9a36c15c04..b5069f34f8 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -56,6 +56,7 @@ if have_system qapi_all_modules += [ 'acpi', 'audio', + 'cryptodev', 'qdev', 'pci', 'rdma', diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index f000b90744..1e923945db 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -95,3 +95,4 @@ { 'include': 'pci.json' } { 'include': 'stats.json' } { 'include': 'virtio.json' } +{ 'include': 'cryptodev.json' } From patchwork Tue Nov 22 14:07:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052404 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 6D0B5C4167E for ; Tue, 22 Nov 2022 14:05:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtC-0008RY-EY; Tue, 22 Nov 2022 09:04:42 -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 1oxTt9-0008R9-Uf for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:39 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTt7-000624-12 for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:39 -0500 Received: by mail-pl1-x629.google.com with SMTP id w4so4935507plp.1 for ; Tue, 22 Nov 2022 06:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4CdbmP/FiE6kgxBu7MfFEjij+I+GqUpVV/I8WAQPEbM=; b=Kv6dcGYNbp3nFT+LYvs+cVTQ5qEjqfWw2giibv0oIRIemfdkTBvmpNZzZqE2vhV2Q1 pR8dTb7mmP/448P29xlc7TeZi6LRXoAqPANBUEpViLAjP4b8jbc+YivuYFeaN9zVrdCT A48ko1ujQYT4FG+3eKJRafcyOqAODIWyGTycXqRgUMfn/1Qd3mVzTtGCkd4AQoK/UJqL gtPqUzL3zaYn+NeDs7jDOIm8ZidPdDs2c7pc5o/RH7BaRiWv8wOMHZh0Ht5sisKk2iPs v00I6oVwKRPFyrWzrG8eawCx8MZWtRg1aVYP3w1d1vxeNEaNO6hFEoJ6pRR6tMKaP38T P/GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4CdbmP/FiE6kgxBu7MfFEjij+I+GqUpVV/I8WAQPEbM=; b=7htloH6BU+Infnc7BYo5WaKSwi0XwAoYkfbLBBt995M/wW/BcvfC2OA+LGOyMhilKU FTORYVejmSlCtJXJD7Mkd9lL85F7gXs4+7eyhdNlR63hZs382nwoPyeW2AxZF1RdZytQ vxX9llmodfyKkdd8c2q7eEz0pOMNutYGV3Ws6hc0fi/IFKI6VTQXddiAoYzqvREohtv2 mLqElde5VCWsEO+FYeDFNFV3UdLqmevgo6YhwO+2DzwS2L/1cH7KtV3H694PcwUQ82rm 8xeuAD6f0ws/6F/VtDmT80rM6u4KsHZhtLqzeXRU9AFO/lXOWAWBhKsHWjaHlitgnso9 YTCQ== X-Gm-Message-State: ANoB5pmCclshM9kCD0vdPEHBzsS5iRRcNW3eMtikirEOeMAA3LINJGEN ANZiJ731Ex7XKpStyr3qW+lVrw== X-Google-Smtp-Source: AA0mqf7i5xlhPE6HgLBsJNhJCc4emM9wsqYAlelwsSxJQCpa305Vg2W9wgQ4tjlXBjfV8h2o65w0Nw== X-Received: by 2002:a17:902:e94e:b0:186:5613:becf with SMTP id b14-20020a170902e94e00b001865613becfmr4171792pll.46.1669125875011; Tue, 22 Nov 2022 06:04:35 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:04:34 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 02/11] cryptodev: Remove 'name' & 'model' fields Date: Tue, 22 Nov 2022 22:07:47 +0800 Message-Id: <20221122140756.686982-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org We have already used qapi to generate crypto device types, this allows to convert type to a string 'model', so the 'model' field is not needed. And the 'name' field is not used by any backend driver, drop it. Signed-off-by: zhenwei pi Reviewed-by: Daniel P. Berrangé --- 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 Tue Nov 22 14:07:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052405 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 6A00AC43217 for ; Tue, 22 Nov 2022 14:05:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtN-0008T9-W8; Tue, 22 Nov 2022 09:04:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxTtC-0008Ra-Hm for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:42 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTtA-00062P-Lp for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:42 -0500 Received: by mail-pj1-x102c.google.com with SMTP id q96-20020a17090a1b6900b00218b8f9035cso5237227pjq.5 for ; Tue, 22 Nov 2022 06:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5b3RVuXlvvZql99mll6PolNwr4wkN22sgLcd1hY141Y=; b=KG+ksbaSOxujlk8Dpe1wlVFOhjhvYhYQqOvHtllIIS5oZzTIwY7+FEje32F/560f8t 6msKSd0jzKLZw7CXsybFEFhCY0it+BnXCo2JU500oU2B4/G8CzP8gTDWiacGMafvwE05 VdD1G10NhC+dC8xxWLCzUxTT0+H30QroUCu3GoI6VET9ztT3Y6XFFAWQGf8TNoR162FJ O7KNdhkGOe5Zdgrf3q1EIC+3EPPjPpd2GTxiMBudxqb+FZ7zaUMX7rOaAfkxRLTzoJsZ 4IGDDX4hUp2SV834fqYE9Vd0skIbwRO7p85euGjj6MXy0f1qVndZJsVqHNtSbZUn22v6 y3tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5b3RVuXlvvZql99mll6PolNwr4wkN22sgLcd1hY141Y=; b=c8vRYZ6eRz2TLbAJufSCuokd7vRwqZkbZ4pe3YfCIVpo6XDfeTSr/eV3lKUB03bvOt 5WjiMurLkmFj4qvEqURJk6GjtE7rxuWapYryoskGAz0/7QNE7dkkE5tpZLkdB2UgP7K4 5VDxUeTAP6rF6CNfn4ZZ/NurHbSL5FNuo5g9vTPsIWVJe/shkW0mQl53sZ8r2lr5DwR4 xokNVL7Y0stPu55O0+fgb6XIj4RnTM+MjgcHezqdIaenaWKOMZ6muslleeySXt03KHMN m9rtmpugP2d/QCzwxUWXFkXmS6J/6BafLsz3TQiQZqfPeOMSWWVQHU0ORW3ObZKGfzwd njiw== X-Gm-Message-State: ANoB5pm6n4AXBVvp1mWPvTPQogr24ujeBbHpLwCC7ZVZ6Zqfxu7/95OY /KBF7EknL3YS9S4NBqQ0ETT0Bg== X-Google-Smtp-Source: AA0mqf54se8k2C0f+ZbekaT1nKFZ2Uf2gM5veD+QU7xKYm9mr+3GFUenNao7SUdxdcvH/8ncb9DUuw== X-Received: by 2002:a17:902:b40b:b0:188:75bb:36d4 with SMTP id x11-20020a170902b40b00b0018875bb36d4mr4796836plr.55.1669125879194; Tue, 22 Nov 2022 06:04:39 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:04:38 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 03/11] cryptodev: Introduce cryptodev alg type in QAPI Date: Tue, 22 Nov 2022 22:07:48 +0800 Message-Id: <20221122140756.686982-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce cryptodev alg type in cryptodev.json, then apply this to related codes, and drop 'enum CryptoDevBackendAlgType'. There are two options: 1, { 'enum': 'QCryptodevBackendAlgType', 'prefix': 'CRYPTODEV_BACKEND_ALG', 'data': ['sym', 'asym']} Then we can keep 'CRYPTODEV_BACKEND_ALG_SYM' and avoid lots of changes. 2, changes in this patch(with prefix 'QCRYPTODEV_BACKEND_ALG'). To avoid breaking the rule of QAPI, use 2 here. Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 6 +++--- backends/cryptodev-lkcf.c | 4 ++-- backends/cryptodev.c | 6 +++--- hw/virtio/virtio-crypto.c | 14 +++++++------- include/sysemu/cryptodev.h | 8 +------- qapi/cryptodev.json | 14 ++++++++++++++ 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 08895271eb..5fb7b8f43f 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -537,7 +537,7 @@ static int cryptodev_builtin_operation( CryptoDevBackendBuiltinSession *sess; CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendAsymOpInfo *asym_op_info; - enum CryptoDevBackendAlgType algtype = op_info->algtype; + enum QCryptodevBackendAlgType algtype = op_info->algtype; int status = -VIRTIO_CRYPTO_ERR; Error *local_error = NULL; @@ -549,11 +549,11 @@ static int cryptodev_builtin_operation( } sess = builtin->sessions[op_info->session_id]; - if (algtype == CRYPTODEV_BACKEND_ALG_SYM) { + if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) { sym_op_info = op_info->u.sym_op_info; status = cryptodev_builtin_sym_operation(sess, sym_op_info, &local_error); - } else if (algtype == CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) { asym_op_info = op_info->u.asym_op_info; status = cryptodev_builtin_asym_operation(sess, op_info->op_code, asym_op_info, &local_error); diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index de3d1867c5..919bf05b75 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -477,7 +477,7 @@ static int cryptodev_lkcf_operation( CryptoDevBackendLKCF *lkcf = CRYPTODEV_BACKEND_LKCF(backend); CryptoDevBackendLKCFSession *sess; - enum CryptoDevBackendAlgType algtype = op_info->algtype; + enum QCryptodevBackendAlgType algtype = op_info->algtype; CryptoDevLKCFTask *task; if (op_info->session_id >= MAX_SESSIONS || @@ -488,7 +488,7 @@ static int cryptodev_lkcf_operation( } sess = lkcf->sess[op_info->session_id]; - if (algtype != CRYPTODEV_BACKEND_ALG_ASYM) { + if (algtype != QCRYPTODEV_BACKEND_ALG_ASYM) { error_report("algtype not supported: %u", algtype); return -VIRTIO_CRYPTO_NOTSUPP; } diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 81941af816..d3caded920 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -120,10 +120,10 @@ int cryptodev_backend_crypto_operation( { VirtIOCryptoReq *req = opaque1; CryptoDevBackendOpInfo *op_info = &req->op_info; - enum CryptoDevBackendAlgType algtype = req->flags; + enum QCryptodevBackendAlgType algtype = req->flags; - if ((algtype != CRYPTODEV_BACKEND_ALG_SYM) - && (algtype != CRYPTODEV_BACKEND_ALG_ASYM)) { + if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM) + && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) { error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype); return -VIRTIO_CRYPTO_NOTSUPP; } diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 97da74e719..e0a7e2cbd8 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -462,7 +462,7 @@ static void virtio_crypto_init_request(VirtIOCrypto *vcrypto, VirtQueue *vq, req->in_iov = NULL; req->in_num = 0; req->in_len = 0; - req->flags = CRYPTODEV_BACKEND_ALG__MAX; + req->flags = QCRYPTODEV_BACKEND_ALG__MAX; memset(&req->op_info, 0x00, sizeof(req->op_info)); } @@ -472,7 +472,7 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req) return; } - if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { + if (req->flags == QCRYPTODEV_BACKEND_ALG_SYM) { size_t max_len; CryptoDevBackendSymOpInfo *op_info = req->op_info.u.sym_op_info; @@ -485,7 +485,7 @@ static void virtio_crypto_free_request(VirtIOCryptoReq *req) /* Zeroize and free request data structure */ memset(op_info, 0, sizeof(*op_info) + max_len); g_free(op_info); - } else if (req->flags == CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (req->flags == QCRYPTODEV_BACKEND_ALG_ASYM) { CryptoDevBackendAsymOpInfo *op_info = req->op_info.u.asym_op_info; if (op_info) { g_free(op_info->src); @@ -570,10 +570,10 @@ static void virtio_crypto_req_complete(void *opaque, int ret) VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto); uint8_t status = -ret; - if (req->flags == CRYPTODEV_BACKEND_ALG_SYM) { + if (req->flags == QCRYPTODEV_BACKEND_ALG_SYM) { virtio_crypto_sym_input_data_helper(vdev, req, status, req->op_info.u.sym_op_info); - } else if (req->flags == CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (req->flags == QCRYPTODEV_BACKEND_ALG_ASYM) { virtio_crypto_akcipher_input_data_helper(vdev, req, status, req->op_info.u.asym_op_info); } @@ -875,7 +875,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: case VIRTIO_CRYPTO_CIPHER_DECRYPT: - op_info->algtype = request->flags = CRYPTODEV_BACKEND_ALG_SYM; + op_info->algtype = request->flags = QCRYPTODEV_BACKEND_ALG_SYM; ret = virtio_crypto_handle_sym_req(vcrypto, &req.u.sym_req, op_info, out_iov, out_num); @@ -885,7 +885,7 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) case VIRTIO_CRYPTO_AKCIPHER_DECRYPT: case VIRTIO_CRYPTO_AKCIPHER_SIGN: case VIRTIO_CRYPTO_AKCIPHER_VERIFY: - op_info->algtype = request->flags = CRYPTODEV_BACKEND_ALG_ASYM; + op_info->algtype = request->flags = QCRYPTODEV_BACKEND_ALG_ASYM; ret = virtio_crypto_handle_asym_req(vcrypto, &req.u.akcipher_req, op_info, out_iov, out_num); diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index af152d09db..f68a4baf13 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -49,12 +49,6 @@ typedef struct CryptoDevBackendPeers CryptoDevBackendPeers; typedef struct CryptoDevBackendClient CryptoDevBackendClient; -enum CryptoDevBackendAlgType { - CRYPTODEV_BACKEND_ALG_SYM, - CRYPTODEV_BACKEND_ALG_ASYM, - CRYPTODEV_BACKEND_ALG__MAX, -}; - /** * CryptoDevBackendSymSessionInfo: * @@ -181,7 +175,7 @@ typedef struct CryptoDevBackendAsymOpInfo { } CryptoDevBackendAsymOpInfo; typedef struct CryptoDevBackendOpInfo { - enum CryptoDevBackendAlgType algtype; + enum QCryptodevBackendAlgType algtype; uint32_t op_code; uint64_t session_id; union { diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index b65edbe183..ebb6852035 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -4,6 +4,20 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. +## +# @QCryptodevBackendAlgType: +# +# The supported algorithm types of a crypto device. +# +# @sym: symmetric encryption +# @asym: asymmetric Encryption +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendAlgType', + 'prefix': 'QCRYPTODEV_BACKEND_ALG', + 'data': ['sym', 'asym']} + ## # @QCryptodevBackendType: # From patchwork Tue Nov 22 14:07:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052414 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 2C4AEC433FE for ; Tue, 22 Nov 2022 14:08:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtP-0008Tb-4y; Tue, 22 Nov 2022 09:04: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 1oxTtH-0008SB-8y for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:51 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTtF-00062w-6A for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:46 -0500 Received: by mail-pj1-x1032.google.com with SMTP id g5so4837470pjp.4 for ; Tue, 22 Nov 2022 06:04:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YmrV4HXUD+cr3ZkF2B4NOpr4JL1AftClmiGHOy+sBW8=; b=JgvnBdQOOyUNQwkoCoSaQjAjNtabEXxG/5xN/Od5sMHi487+Up/DoNt3zuQvBuns1b 76OJtlipcfsBh0NHdpSY1372+DbmB5ynTTWH8TV8NzkVRTChQ+qL2d1ldDoUNuQ146Xy J2fooDxWe1eOJnU8X3xh8tsxJIUlMOaWhgLZcKPd5JFi3z7PjWM7pd0py0ppauV7X1fr K+oSk3cbXJ5u1wP8Jm0IeWlMTC9bRO2Qu3dQi7KNw0fNtX4APMtTRfXooJMspF2hGccF rS/xQ8a0Ou4sBC9aF3BKLMPAG7TncI0/Bu+lGlKPGUqXbw3iz1xCfZHKHZjGOBVpogOG COgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YmrV4HXUD+cr3ZkF2B4NOpr4JL1AftClmiGHOy+sBW8=; b=LZvFVDhAzt8/9/VqdXY8th1mIOOGt/nzmJEe5K7kR7OG1MO11zVFhXmEo4SB/KJrxz F3VR6RgrZQlxWbw/QVV2BR2xSadeOsnaI8dczrSCVWF+fzvyiPFTLuE2UfF5h0Rdxo4B CIpctcbzK4dEwvI4rqF3Nh/5n8m/AOxaK7hlQvDDlwZ3hF9Qy0wYylirMyl4/JdXOabr gofDgCE6FaXoYOOSxz506Vtodc7LONe4qD597W0nBBrFcB5lu1oaWYnKMeu8gf6U5Fqp eJNkxO8wfuSImb0L0u+O+iUiFWr+5HWNPl7NEiEptlyKlbi+k5SsfOuRxEWYHK/4nyC8 FGAQ== X-Gm-Message-State: ANoB5pkjVebTCF137XNv1ux3eMmzyzv1RLJXvTxQ54PKojL4V16cYtpu 2oLpouWLShPBTtLRDMJgMURwfg== X-Google-Smtp-Source: AA0mqf67vs4Y7B4QLDQ4whrHUb6t+Q2WyX9BXWBuXYoSezg2cATUCaw35LI0EMXmdOGvT7NLnbfkSQ== X-Received: by 2002:a17:902:ab59:b0:188:dcfb:5993 with SMTP id ij25-20020a170902ab5900b00188dcfb5993mr4362975plb.172.1669125883528; Tue, 22 Nov 2022 06:04:43 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:04:43 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 04/11] cryptodev: Introduce server type in QAPI Date: Tue, 22 Nov 2022 22:07:49 +0800 Message-Id: <20221122140756.686982-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce cryptodev service type in cryptodev.json, then apply this to related codes. Now we can remove VIRTIO_CRYPTO_SERVICE_xxx dependence from QEMU cryptodev. Signed-off-by: zhenwei pi Reviewed-by: Daniel P. Berrangé --- backends/cryptodev-builtin.c | 8 ++++---- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 6 +++--- hw/virtio/virtio-crypto.c | 27 +++++++++++++++++++++++++-- qapi/cryptodev.json | 11 +++++++++++ 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 5fb7b8f43f..4987abb7d6 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -79,10 +79,10 @@ static void cryptodev_builtin_init( backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_CIPHER | - 1u << VIRTIO_CRYPTO_SERVICE_HASH | - 1u << VIRTIO_CRYPTO_SERVICE_MAC | - 1u << VIRTIO_CRYPTO_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER | + 1u << QCRYPTODEV_BACKEND_SERVICE_HASH | + 1u << QCRYPTODEV_BACKEND_SERVICE_MAC | + 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1; backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 919bf05b75..31ec712849 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -230,7 +230,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp) backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; lkcf->running = true; diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c index 580bd1abb0..b1d9eb735f 100644 --- a/backends/cryptodev-vhost-user.c +++ b/backends/cryptodev-vhost-user.c @@ -221,9 +221,9 @@ static void cryptodev_vhost_user_init( cryptodev_vhost_user_event, NULL, s, NULL, true); backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_CIPHER | - 1u << VIRTIO_CRYPTO_SERVICE_HASH | - 1u << VIRTIO_CRYPTO_SERVICE_MAC; + 1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER | + 1u << QCRYPTODEV_BACKEND_SERVICE_HASH | + 1u << QCRYPTODEV_BACKEND_SERVICE_MAC; backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1; diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index e0a7e2cbd8..87d9582bc1 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -997,12 +997,35 @@ static void virtio_crypto_reset(VirtIODevice *vdev) } } +static uint32_t virtio_crypto_init_services(uint32_t qservices) +{ + uint32_t vservices = 0; + + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_CIPHER); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_HASH)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_HASH); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_MAC)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_MAC); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AEAD)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_AEAD); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_AKCIPHER); + } + + return vservices; +} + static void virtio_crypto_init_config(VirtIODevice *vdev) { VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); - vcrypto->conf.crypto_services = - vcrypto->conf.cryptodev->conf.crypto_services; + vcrypto->conf.crypto_services = virtio_crypto_init_services( + vcrypto->conf.cryptodev->conf.crypto_services); vcrypto->conf.cipher_algo_l = vcrypto->conf.cryptodev->conf.cipher_algo_l; vcrypto->conf.cipher_algo_h = diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index ebb6852035..8732a30524 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -18,6 +18,17 @@ 'prefix': 'QCRYPTODEV_BACKEND_ALG', 'data': ['sym', 'asym']} +## +# @QCryptodevBackendServiceType: +# +# The supported service types of a crypto device. +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendServiceType', + 'prefix': 'QCRYPTODEV_BACKEND_SERVICE', + 'data': ['cipher', 'hash', 'mac', 'aead', 'akcipher']} + ## # @QCryptodevBackendType: # From patchwork Tue Nov 22 14:07:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052408 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 2A4CAC4332F for ; Tue, 22 Nov 2022 14:06:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtR-0008Tj-FQ; Tue, 22 Nov 2022 09:04:57 -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 1oxTtN-0008TD-Lm for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:53 -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 1oxTtL-00063S-Q7 for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:53 -0500 Received: by mail-pl1-x630.google.com with SMTP id p12so13729944plq.4 for ; Tue, 22 Nov 2022 06:04:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TlcaU38pdb3CtWEh3sr5SMbpseSZUCKSQHY6AQe8NOY=; b=SRbORjOaNpJev9fOFUEoDOrg0qem5ACUxsgC3QN6oLXkFrcapiqoL+3oZSJjDrT/YJ hOws4M9hhrz4ERh/w9YncU4HGu2+rQcycogQJeYFUYyn7x5dRLGazAqCaGMpic++cZ8/ 1T4jc16Vs90Eo/bq/T3eZHZ1T4dmOsGvP6cWO7fMCWrpTo90qs4h68NNMmwt6d+EoeDH DEc0pVsUjSkaEqEDdsuajjySKxTMoOyE9bKhkDa3y3DO3WjAbfxl+VSOiPVFmDTxeZ3r Vh4wHGwadiRYosIdyzUNa1c2R5mtqPdPbVjsAdFKa/hx3ZDPf/y09GFTOsvwXCUB/plf E4PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TlcaU38pdb3CtWEh3sr5SMbpseSZUCKSQHY6AQe8NOY=; b=ybhj1O6zhCF6IvUkfckzNW00DtxcujkdLuepQp7nVgw6aXzoMcad3Vnffwfo+fOpZy Vmt/4A4KqkIxgeTk6eW2U1NwRvOnZz5mhpr7zk+6ROPFV9DyxqLWJokdKGuMNHMGJTJh M3gnTPjasB+lwSDWI5BoWAuCsJlho5SloOX3zLBvBG0JQzfI/bJ5uKnsWEK2mz9Werid 2FawzHe/3OCKjHWwqK4sxN61ARJvSDDRffuybZtsMXKPDjvJeJ1TsufMqCTtDb/psUEt YlGX1jYv/Qdcbb4c58mas0VWle9TmlEOsBZxuh6/oxJ1XFyqSPTVZpLe9M+hOemFjHIl NPvw== X-Gm-Message-State: ANoB5pn1ZN9t4GV4HumfC+WuG4nzh6F3bYDdJnJ3+ompO0LzJhghOONr P9oenqmtIIu7JSjFo3OGhSCvNw== X-Google-Smtp-Source: AA0mqf5fv7+IsVL8ufONS90oYYapUD6XjjrRHyYzuAQ7ObOSPa22tQrPPSpuo3UwGw3H5aMDH6o3vg== X-Received: by 2002:a17:902:bc84:b0:17f:700a:2cd3 with SMTP id bb4-20020a170902bc8400b0017f700a2cd3mr4826606plb.36.1669125888125; Tue, 22 Nov 2022 06:04:48 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:04:47 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 05/11] cryptodev: Introduce 'query-cryptodev' QMP command Date: Tue, 22 Nov 2022 22:07:50 +0800 Message-Id: <20221122140756.686982-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now we have a QMP command to query crypto devices: virsh qemu-monitor-command vm '{"execute": "query-cryptodev"}' | jq { "return": [ { "service": [ "akcipher", "mac", "hash", "cipher" ], "id": "cryptodev1", "client": [ { "queue": 0, "type": "builtin", "info": "cryptodev-builtin0" } ] }, { "service": [ "akcipher" ], "id": "cryptodev0", "client": [ { "queue": 0, "type": "lkcf", "info": "cryptodev-lkcf0" } ] } ], "id": "libvirt-415" } Signed-off-by: zhenwei pi --- backends/cryptodev.c | 49 ++++++++++++++++++++++++++++++++++++++++++++ qapi/cryptodev.json | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index d3caded920..bf2f3234c9 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "sysemu/cryptodev.h" #include "qapi/error.h" +#include "qapi/qapi-commands-cryptodev.h" #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -33,6 +34,54 @@ static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; +static int qmp_query_cryptodev_foreach(Object *obj, void *data) +{ + CryptoDevBackend *backend; + CryptodevInfoList **infolist = data; + uint32_t services; + + if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) { + return 0; + } + + CryptodevInfo *info = g_new0(CryptodevInfo, 1); + info->id = g_strdup(object_get_canonical_path_component(obj)); + + backend = CRYPTODEV_BACKEND(obj); + services = backend->conf.crypto_services; + for (uint32_t i = 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) { + if (services & (1 << i)) { + QAPI_LIST_PREPEND(info->service, i); + } + } + + for (uint32_t i = 0; i < backend->conf.peers.queues; i++) { + CryptoDevBackendClient *cc = backend->conf.peers.ccs[i]; + CryptodevBackendClient *client = g_new0(CryptodevBackendClient, 1); + + client->queue = cc->queue_index; + client->type = cc->type; + if (cc->info_str) { + client->has_info = true; + client->info = strdup(cc->info_str); + } + QAPI_LIST_PREPEND(info->client, client); + } + + QAPI_LIST_PREPEND(*infolist, info); + + return 0; +} + +CryptodevInfoList *qmp_query_cryptodev(Error **errp) +{ + CryptodevInfoList *list = NULL; + Object *objs = container_get(object_get_root(), "/objects"); + + object_child_foreach(objs, qmp_query_cryptodev_foreach, &list); + + return list; +} CryptoDevBackendClient *cryptodev_backend_new_client(void) { diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index 8732a30524..4cc4f4f0ed 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -43,3 +43,46 @@ { 'enum': 'QCryptodevBackendType', 'prefix': 'QCRYPTODEV_BACKEND_TYPE', 'data': ['builtin', 'vhost-user', 'lkcf']} + +## +# @CryptodevBackendClient: +# +# Information about a queue of crypto device. +# +# @type: the type of the crypto device +# +# @info: the additional infomation of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'CryptodevBackendClient', + 'data': { 'queue': 'int', + 'type': 'QCryptodevBackendType', + '*info': 'str' } } + +## +# @CryptodevInfo: +# +# Information about a crypto device. +# +# @service: supported service types of a crypto device +# +# @client: the additional infomation of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'CryptodevInfo', + 'data': { 'id': 'str', + 'service': ['QCryptodevBackendServiceType'], + 'client': ['CryptodevBackendClient'] } } + +## +# @query-cryptodev: +# +# Returns information about current crypto devices. +# +# Returns: a list of @CryptodevInfo +# +# Since: 8.0 +## +{ 'command': 'query-cryptodev', 'returns': ['CryptodevInfo']} From patchwork Tue Nov 22 14:07:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052410 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 3F45FC4332F for ; Tue, 22 Nov 2022 14:06:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtt-0000EP-8z; Tue, 22 Nov 2022 09:05:25 -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 1oxTtW-0008UW-51 for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:03 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTtU-00064Q-2V for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:01 -0500 Received: by mail-pf1-x42e.google.com with SMTP id x66so5842654pfx.3 for ; Tue, 22 Nov 2022 06:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Nk2S/0t4kPRq2X2uMrWAJJPsOZ3LfTygDOI9mP3SmW4=; b=p5kKRPrJUBRfABTiZpd5REEhjWcNcxtuyI7BcIZwp1gyZAPAaCFqyXl1Ib51rK4t9F ANPwA9mNgwqHm6UILYyAs9oERQyBUsKOwY5zWJmhIVwzxeNYDmUT3g2T75buQ/r/IL1N 6Giur5j46xhT6fsi6DQ3QS61YShgOqUvaq92CsGFQa5NgjNpyUzLyFD7iaq5yJTL3mY3 N/oS1LM8R6G31c3Oc3c5NdkPaaqj5NzjQCS62qpQ1OTk0gxlnVdIBVGmnopDTuMKNMCD SCNLxD9lNsyrkOOtw9jSxkJmyK/UYxppBoWXybooerJb0F4zruGGppUyJli72nBA519d x4OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nk2S/0t4kPRq2X2uMrWAJJPsOZ3LfTygDOI9mP3SmW4=; b=hp4iXVVHtxUI8OKgrVUaT7eOyQwt0qwNQC7TCc/dUMD76V73J+g06DX9d2snBTkPJY a85BBSqKEAmHN5ewcWnIR2k3g9GAKAxouBdzBKPSejCW69CMTL0uPyqNeL49QK7XkcBK sJvbHFNTtalk9mfA5Q1SC2BQmsMUsvkeB4N6i2VXEeqJatqWymtBo/IOCLA5BoyeNWhN Zn3c4Rmdb39Ke1rfKV7qml+mkM3XJFn/SI8p49dJYQKHbUXNLTYo+T06jUEPtJXoU3qb GBmQ60dVloUTQ04h548IbGIK8UAZ+rtxHj2AoxZphQq3S+PkaAJ5y0ufBCng49NuYCqz s/8g== X-Gm-Message-State: ANoB5pkhLALXA9Foga9DU/zoNpViGAl4PMqxmriIIdBcn7dOH5oq7rSP ep6dSt8BJb8k0M5P0ioeNRk8OA== X-Google-Smtp-Source: AA0mqf5w2iXdFTgEjzjODe5bqUx/AeEKmsYWHohzNg+C2U4rvkJozZMlWQCLcI0yFfKh059acS6WNA== X-Received: by 2002:a63:4f47:0:b0:461:a261:eb50 with SMTP id p7-20020a634f47000000b00461a261eb50mr12289880pgl.311.1669125892327; Tue, 22 Nov 2022 06:04:52 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:04:51 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 06/11] cryptodev: Support statistics Date: Tue, 22 Nov 2022 22:07:51 +0800 Message-Id: <20221122140756.686982-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce cryptodev statistics in QAPI, and record OPS/Bandwidth for each crypto device. Example of this feature: virsh qemu-monitor-command vm '{"execute": "query-cryptodev"}' | jq { "return": [ { "service": [ "akcipher", "mac", "hash", "cipher" ], "asym-stat": { "encrypt-ops": 0, "verify-bytes": 0, "sign-ops": 0, "verify-ops": 0, "sign-bytes": 0, "decrypt-bytes": 0, "decrypt-ops": 0, "encrypt-bytes": 0 }, "sym-stat": { "encrypt-ops": 40, "decrypt-bytes": 5376, "decrypt-ops": 40, "encrypt-bytes": 5376 }, "id": "cryptodev1", "client": [ { "queue": 0, "type": "builtin", "info": "cryptodev-builtin0" } ] }, { "service": [ "akcipher" ], "asym-stat": { "encrypt-ops": 54, "verify-bytes": 8704, "sign-ops": 17, "verify-ops": 34, "sign-bytes": 340, "decrypt-bytes": 9215, "decrypt-ops": 36, "encrypt-bytes": 13294 }, "id": "cryptodev0", "client": [ { "queue": 0, "type": "lkcf", "info": "cryptodev-lkcf0" } ] } ], "id": "libvirt-424" } Signed-off-by: zhenwei pi --- backends/cryptodev.c | 81 +++++++++++++++++++++++++++++++++++--- include/sysemu/cryptodev.h | 30 ++++++++++++++ qapi/cryptodev.json | 58 ++++++++++++++++++++++++++- 3 files changed, 162 insertions(+), 7 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index bf2f3234c9..d623bf3bff 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -48,6 +48,18 @@ static int qmp_query_cryptodev_foreach(Object *obj, void *data) info->id = g_strdup(object_get_canonical_path_component(obj)); backend = CRYPTODEV_BACKEND(obj); + if (backend->sym_stat) { + info->has_sym_stat = true; + info->sym_stat = g_memdup2(backend->sym_stat, + sizeof(QCryptodevBackendSymStat)); + } + + if (backend->asym_stat) { + info->has_asym_stat = true; + info->asym_stat = g_memdup2(backend->asym_stat, + sizeof(QCryptodevBackendAsymStat)); + } + services = backend->conf.crypto_services; for (uint32_t i = 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) { if (services & (1 << i)) { @@ -111,6 +123,9 @@ void cryptodev_backend_cleanup( if (bc->cleanup) { bc->cleanup(backend, errp); } + + g_free(backend->sym_stat); + g_free(backend->asym_stat); } int cryptodev_backend_create_session( @@ -161,6 +176,52 @@ 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, void *opaque1, @@ -169,14 +230,12 @@ int cryptodev_backend_crypto_operation( { VirtIOCryptoReq *req = opaque1; CryptoDevBackendOpInfo *op_info = &req->op_info; - enum QCryptodevBackendAlgType algtype = req->flags; + 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, queue_index, cb, opaque2); } @@ -214,10 +273,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 f68a4baf13..c154c52039 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -252,8 +252,38 @@ struct CryptoDevBackend { /* Tag the cryptodev backend is used by virtio-crypto or not */ bool is_used; CryptoDevBackendConf conf; + QCryptodevBackendSymStat *sym_stat; + QCryptodevBackendAsymStat *asym_stat; }; +#define QCryptodevSymStatInc(be, op, bytes) do { \ + be->sym_stat->op##_bytes += (bytes); \ + be->sym_stat->op##_ops += 1; \ +} while (/*CONSTCOND*/0) + +#define QCryptodevSymStatIncEncrypt(be, bytes) \ + QCryptodevSymStatInc(be, encrypt, bytes) + +#define QCryptodevSymStatIncDecrypt(be, bytes) \ + QCryptodevSymStatInc(be, decrypt, bytes) + +#define QCryptodevAsymStatInc(be, op, bytes) do { \ + be->asym_stat->op##_bytes += (bytes); \ + be->asym_stat->op##_ops += 1; \ +} while (/*CONSTCOND*/0) + +#define QCryptodevAsymStatIncEncrypt(be, bytes) \ + QCryptodevAsymStatInc(be, encrypt, bytes) + +#define QCryptodevAsymStatIncDecrypt(be, bytes) \ + QCryptodevAsymStatInc(be, decrypt, bytes) + +#define QCryptodevAsymStatIncSign(be, bytes) \ + QCryptodevAsymStatInc(be, sign, bytes) + +#define QCryptodevAsymStatIncVerify(be, bytes) \ + QCryptodevAsymStatInc(be, verify, bytes) + /** * cryptodev_backend_new_client: * diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index 4cc4f4f0ed..f01f2d017a 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -60,6 +60,60 @@ 'type': 'QCryptodevBackendType', '*info': 'str' } } +## +# @QCryptodevBackendSymStat: +# +# The statistics of symmetric operation. +# +# @encrypt-ops: the operations of symmetric encryption +# +# @decrypt-ops: the operations of symmetric decryption +# +# @encrypt-bytes: the bytes of symmetric encryption +# +# @decrypt-bytes: the bytes of symmetric decryption +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendSymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int' } } + +## +# @QCryptodevBackendAsymStat: +# +# The statistics of asymmetric operation. +# +# @encrypt-ops: the operations of asymmetric encryption +# +# @decrypt-ops: the operations of asymmetric decryption +# +# @sign-ops: the operations of asymmetric signature +# +# @verify-ops: the operations of asymmetric verification +# +# @encrypt-bytes: the bytes of asymmetric encryption +# +# @decrypt-bytes: the bytes of asymmetric decryption +# +# @sign-bytes: the bytes of asymmetric signature +# +# @verify-bytes: the bytes of asymmetric verification +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendAsymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'sign-ops': 'int', + 'verify-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int', + 'sign-bytes': 'int', + 'verify-bytes': 'int' } } + ## # @CryptodevInfo: # @@ -74,7 +128,9 @@ { 'struct': 'CryptodevInfo', 'data': { 'id': 'str', 'service': ['QCryptodevBackendServiceType'], - 'client': ['CryptodevBackendClient'] } } + 'client': ['CryptodevBackendClient'], + '*sym-stat': 'QCryptodevBackendSymStat', + '*asym-stat': 'QCryptodevBackendAsymStat' } } ## # @query-cryptodev: From patchwork Tue Nov 22 14:07:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052407 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 53F44C433FE for ; Tue, 22 Nov 2022 14:05:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtc-0008Vo-6B; Tue, 22 Nov 2022 09:05:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxTtT-0008UG-Km for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:03 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTtR-00064E-Sx for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:04:59 -0500 Received: by mail-pj1-x102c.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso13843881pjt.0 for ; Tue, 22 Nov 2022 06:04:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XVeROiFzRvm73KuR37epkqeC5/pERblDH+LuVEv9GPU=; b=ctf7rxnqBUja/es1adM7Bxlco3UIGEBaBwjgAqy/Zms2p2HsYOrAlnMen9+4D9o2B5 Grql04WH/XPRxLWk0xHZQy5trjGNpTAw2nK3rvlvc+fa7Ed6YY0BGYHLmBZTynJuFLae YNix7CS0xiBkL0fSazC9kq5JucBx3L3jJ5ZZfpQg9do2vl11pD7ZO+w2WeOGAzqcTdn+ f638/7Dpv40pcx/LyU/WBsTGSCIIMUtitteH91gsmEBoPNiGwtUqcD9WYGQRWFH+CdlB wv4puJgLK7wZQ2WZ6kHUCQeOxw0qalXdu5cBarpqAE+RMi9jSyDGJ/3MD6dr23R8YxCm HyNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XVeROiFzRvm73KuR37epkqeC5/pERblDH+LuVEv9GPU=; b=FEQbe06ViGZZCktF2asOaj8Dp/Z7Hk1kFQ8Gj1YkovrEJGzr0Y0sDpsomFRqgkXv2r ZCnhbRRt8+M36OC/WGx7gJCH4Oo+haE2Hw3L1Tyjysi5LJ7/mjYczd/GxvKZxpXDDCus uSDkpkchhkTon47+loGTqbMETjTu4XmQjzOJ5BYHCOBBqazbcr4yRpjVcgxUWcVGwcx6 XvpwYMKXj6ayw2XACQZTPg889AXC0Qlc/QNXKu67DD39vLzeY+wMdd3S/nLzcIOokB8Q g/N5GiLRyIiZtzs/x17f9UcYG/z48n5UC9szsHhgBCCqCOmmiatkjSOMrewAMucrqyjK xBjA== X-Gm-Message-State: ANoB5plD0G9Eu9KN0IgAQ6jEElVDcVs3AAg7m8N7vydpeK3WSULP0ufF AYF0oY++vj9wDF88xuW/oIB95q7XoRDHhl8O X-Google-Smtp-Source: AA0mqf6KfKma4PZnZozWcEw4gZrV8gSNI2zRblIO3vD5kmHt5GumwerFlp9Gw/nvs/2JgOz9FB9Kdw== X-Received: by 2002:a17:902:b286:b0:17f:8514:cf33 with SMTP id u6-20020a170902b28600b0017f8514cf33mr4589840plr.101.1669125896599; Tue, 22 Nov 2022 06:04:56 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:04:56 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 07/11] cryptodev-builtin: Detect akcipher capability Date: Tue, 22 Nov 2022 22:07:52 +0800 Message-Id: <20221122140756.686982-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Rather than exposing akcipher service/RSA algorithm to virtio crypto device unconditionally, detect akcipher capability from akcipher crypto framework. This avoids unsuccessful requests. Signed-off-by: zhenwei pi Reviewed-by: Daniel P. Berrangé --- 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 4987abb7d6..94a02aeaf1 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 Tue Nov 22 14:07:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052412 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 E5ACEC433FE for ; Tue, 22 Nov 2022 14:07:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtf-0008WC-OS; Tue, 22 Nov 2022 09:05:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxTtY-0008V7-6k for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:04 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTtV-00064e-VJ for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:03 -0500 Received: by mail-pf1-x42e.google.com with SMTP id b185so14447926pfb.9 for ; Tue, 22 Nov 2022 06:05:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rJ13zFBLpczUe+mQf8RhpWx8v5xhOGQCsYHgWUIIHyE=; b=eufY2tbzcu8QIbmUmgfoOHLPaWkolYSCeIZAISGG95FuR3X84ibIXkRunB1xaOF2Sq /THa2HoILygwVJhNLS7vhUsF5AJVri/RT0Bu5epEL4lZtHN7RTrJ3Y4TSkWQ6HuIebFv e9KN6Fj+OdLCpHq9slZM0yxxRtrQPAnM1CTwmO6DTFjX5GFGiQO2Me9LuLp+3Tic4cB2 R80Ag8DbwGoiNrcyrgDN+lW96d9q+tgVVQen6riQ+kNN8eSdh6ByPFdLmHKR4HViQfOi 0K0i+9pluxzb/2mstYpdAQVfqjzCV7pY6keXH/aSjlkRI97T3AKqPgPZurBw3QZZEYI9 foLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rJ13zFBLpczUe+mQf8RhpWx8v5xhOGQCsYHgWUIIHyE=; b=WVaik86E3gyYdxFK4CPcX7IDlANVh2W+hGnIn7xB8WVhYnqp0WTAS4PoBQLnmcJrQ8 3O/Y8+xwTmH7ZL0g15XBuepVYAnoWm5YpJd//DER0q/Uuq/bCP3Aap3+Kxd5zTVWqVis xbjpJ7FsXuX7y7exJhA7p9z4rV0lQpbYffhSXgKjY8ZHVYPML10eI4WpUAseT8bfUG1S GSfCg8bEO3qw+In8ebY2U6ZNTMZmNZ8x24Q60DEgH7tfx/VA0BaXQYoBUueuVVZ3BjET pgv1a0SUIHEuw2KKshXao9DxW0URx80B6xcAI0ke4CJRl1tfhmQgmbgwTGWoC+xArpLA 0hsA== X-Gm-Message-State: ANoB5pkI5Q/BxAW1Iv5cmAC6WllJB89HAWkB/H8E0F39MeeM/BHEbk/o Omq9eehu60IxO76oaUIehnb8jwD4I3uydUqt X-Google-Smtp-Source: AA0mqf4pPk1MLj2ZcCOFzbv4+1IbS2rJnHLywg1T36XBJZ8r2eVqxYU3bz4gWEqTQw7tSxgIAOch5w== X-Received: by 2002:a63:1206:0:b0:43c:76f4:c666 with SMTP id h6-20020a631206000000b0043c76f4c666mr6962853pgl.90.1669125900695; Tue, 22 Nov 2022 06:05:00 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:05:00 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 08/11] hmp: add cryptodev info command Date: Tue, 22 Nov 2022 22:07:53 +0800 Message-Id: <20221122140756.686982-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Example of this command: # virsh qemu-monitor-command vm --hmp info cryptodev cryptodev1: service=[akcipher|mac|hash|cipher] queue 0: type=builtin cryptodev0: service=[akcipher] queue 0: type=lkcf Signed-off-by: zhenwei pi --- hmp-commands-info.hx | 14 ++++++++++++++ include/monitor/hmp.h | 1 + monitor/hmp-cmds.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 754b1e8408..47d63d26db 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -993,3 +993,17 @@ SRST ``info virtio-queue-element`` *path* *queue* [*index*] Display element of a given virtio queue ERST + + { + .name = "cryptodev", + .args_type = "", + .params = "", + .help = "show the crypto devices", + .cmd = hmp_info_cryptodev, + .flags = "p", + }, + +SRST + ``info cryptodev`` + Show the crypto devices. +ERST diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index dfbc0c9a2f..b6b2b49202 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -143,5 +143,6 @@ void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict); void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Error **)); void hmp_info_stats(Monitor *mon, const QDict *qdict); +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict); #endif diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 01b789a79e..d5c9e8977d 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -33,6 +33,7 @@ #include "qapi/qapi-commands-block.h" #include "qapi/qapi-commands-char.h" #include "qapi/qapi-commands-control.h" +#include "qapi/qapi-commands-cryptodev.h" #include "qapi/qapi-commands-machine.h" #include "qapi/qapi-commands-migration.h" #include "qapi/qapi-commands-misc.h" @@ -2761,3 +2762,38 @@ void hmp_virtio_queue_element(Monitor *mon, const QDict *qdict) qapi_free_VirtioQueueElement(e); } + +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict) +{ + CryptodevInfoList *il; + QCryptodevBackendServiceTypeList *sl; + CryptodevBackendClientList *cl; + + for (il = qmp_query_cryptodev(NULL); il; il = il->next) { + g_autofree char *services = NULL; + CryptodevInfo *info = il->value; + char *tmp_services; + + /* build a string like 'service=[akcipher|mac|hash|cipher]' */ + for (sl = info->service; sl; sl = sl->next) { + const char *service = QCryptodevBackendServiceType_str(sl->value); + + if (!services) { + services = g_strdup(service); + } else { + tmp_services = g_strjoin("|", services, service, NULL); + g_free(services); + services = tmp_services; + } + } + monitor_printf(mon, "%s: service=[%s]\n", info->id, services); + + for (cl = info->client; cl; cl = cl->next) { + CryptodevBackendClient *client = cl->value; + monitor_printf(mon, " queue %ld: type=%s\n", client->queue, + QCryptodevBackendType_str(client->type)); + } + } + + qapi_free_CryptodevInfoList(il); +} From patchwork Tue Nov 22 14:07:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052406 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 52E54C4332F for ; Tue, 22 Nov 2022 14:05:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtm-00005W-F1; Tue, 22 Nov 2022 09:05:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxTtc-0008W0-39 for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:08 -0500 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTta-0006G9-4Z for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:07 -0500 Received: by mail-pf1-x42d.google.com with SMTP id v28so14429009pfi.12 for ; Tue, 22 Nov 2022 06:05:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F1R+gQ8CKo1BFlEbEV54FIDLI8zbRmxUy59qfCIPez4=; b=oVjyknO2+YYX90gVrXfsswwvJCfCnq6nlBurOffMBHTCoYFxXmh3Ai1Sce0yluzSRp hieEGCXhO4Xi1ynlVxEuYMNkywvMIYbV5KsL/qzwiIWZIx4Otgqsl+mieyteIsKVHEON P4NO8QgAJyyR+kui2jP2K/KFsYx5Qp46aE2Rb7cMBzUlbLJoTSR7zsdxW3mSjM/8pa46 zOGfdJbBlRBTZmbX30AJRNCbbIbPy8lnf7H+B+Mf3/R7CwRY1PlfcekWamJ0iYnUmyaJ AeFKLK5rrLO58IU5WetJWdKojIIcKSrNGAwJ8aajTZGo5yiRwa07SDnbWCJvPHMnelFH kAXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F1R+gQ8CKo1BFlEbEV54FIDLI8zbRmxUy59qfCIPez4=; b=HGwKS1/CpgU/C0ne+Ma5BgOdtmkpK5tLVYZXIQ2WdKcz8hQjdTTxyLpC9q1RNSZMQK o4ALXBvOb292BQTwVDfdQNh53F3G3hYRS+NfKfTg6B8yV+jL7wgHg48v4MydlVCvsPyg 8NTpFKBXv5QLKkNhi6L84bsdzWybA+mzzSOVpvKUTS9LMad10uiZrFDmkSiJneMC03fd ZC5MZQuJZhtKkvOLOicgN6wiyGSmjiwM44rPkFLTMSyR+NUrm5zGt7wLEFk/5T4mavEu ImX1olysjI3/2c4RYmXcpRANIg0TJ0UuRPAyfuqBMLSwmppc3KZuPunmEOncF8XNiyoI ZAVw== X-Gm-Message-State: ANoB5pnHSt1p4p2xTaLnzubM/rv/xWFh3G+KDrpud2yfbGbql9poRNTs xeE2L5bjpIgFuspKGQiHisjDVRnUm2hcDScC X-Google-Smtp-Source: AA0mqf6yGiZw2JNHqzRU2jAWVxYO6W5paU9eFL5a2FvF1/YhGYhFx7kkDkeCqH0pjySba+7hvHquxg== X-Received: by 2002:a63:234e:0:b0:470:4222:c3ee with SMTP id u14-20020a63234e000000b004704222c3eemr22509957pgm.571.1669125904742; Tue, 22 Nov 2022 06:05:04 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:05:04 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 09/11] cryptodev: Use CryptoDevBackendOpInfo for operation Date: Tue, 22 Nov 2022 22:07:54 +0800 Message-Id: <20221122140756.686982-10-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_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. Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 9 +++------ backends/cryptodev-lkcf.c | 9 +++------ backends/cryptodev.c | 16 ++++------------ hw/virtio/virtio-crypto.c | 7 ++++--- include/sysemu/cryptodev.h | 26 ++++++++++---------------- 5 files changed, 24 insertions(+), 43 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 94a02aeaf1..68b1cbd440 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 31ec712849..0e88f1ecac 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 d623bf3bff..72105df95a 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -162,16 +162,13 @@ 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; } @@ -224,20 +221,15 @@ static int cryptodev_backend_account(CryptoDevBackend *backend, 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; int ret; ret = cryptodev_backend_account(backend, op_info); if (ret < 0) { return ret; } - 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 87d9582bc1..e637fc6ab0 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 c154c52039..ffbce1129c 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 { enum QCryptodevBackendAlgType algtype; uint32_t op_code; + uint32_t queue_index; + CryptoDevCompletionFunc cb; + void *opaque; 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 { @@ -365,24 +366,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 Tue Nov 22 14:07:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052413 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 E57B6C4332F for ; Tue, 22 Nov 2022 14:07:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtu-0000Gl-6h; Tue, 22 Nov 2022 09:05:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxTtg-00004s-Fo for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:13 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTte-0006Gr-0P for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:12 -0500 Received: by mail-pl1-x62d.google.com with SMTP id j12so13727107plj.5 for ; Tue, 22 Nov 2022 06:05:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R2pIUNNN/Jr1yOhRff9xNPmA2IUQiWkT9SHme9njJhc=; b=y3sjtUrq3rQCSpmpbtOJJu20CB3fUYSQg+EImHCgOth0yfLKTAn/ua2I7QBAmuStBv p3GK1RDD7R/OsVb8MNDuDHY0DzgqdDhp1XNpUExUdkZngFmjXK2jDxp6Zf+0VDMTGSX4 3FR/wLxQwQwrDr1NjSIuYTY/jq11S6Xh+iCbxL9ISFE8Y1fNF5BPHUy8wORfqUg23j8y 87cWb1IFy2i0c0//+cNKi60aldE/b/WnSLiexSDJrW2F9BijGWVj23Go/t1MIPsQEjyG 29ETivY7y3gcq0HfejHtcPCXycJgCo94No2rorvAv6uBSDp0q5cfPp4+EhO1CBjCBlVm gvSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R2pIUNNN/Jr1yOhRff9xNPmA2IUQiWkT9SHme9njJhc=; b=XJvdfXg9JpsMNxe8KN+Cu/Lg4fmC2pLWKxOHEv+Tyf36K3agDYuntv0zk6ETqw83rw z9oRZR0PZ6v5gLyO0lKYpqMAGORY8QPzRF1gKxFOs+03NpdpbGOLwt//guEdI518VNXj Z1Oo34Py81g7PBLz//X5d6St7y3XONUwZX14OExKBDUQ3jXBnyF04E4boSIv8Nxw/qSE zAuqYfjGJgXfbZKya864NovBVWEFIDnhEk99BiPwP0t/J9RlKg9CopFN7Y0e5tgFt/ie q0vjDP1e6/p8t0qn42MZlHJspx4nqqPgAE8m3bqw4Eh9SswEnocvNdEM46RnzG8eDCuL Dv5w== X-Gm-Message-State: ANoB5plegsl/KaDQ6Sl//h3bAsHohKKCpsBtE/yfCpMY5Kup+Sj7VKRr TLkBOG+ukDEUdjVWG1t3FReRmQ== X-Google-Smtp-Source: AA0mqf7iE5JNEk1UjSkq6DAmTmSblFRUrPfmGj25ZRJHI4doave0hiWkLlD0N8wXm1VuTxeHXYhGYg== X-Received: by 2002:a17:902:cf08:b0:188:e49e:2657 with SMTP id i8-20020a170902cf0800b00188e49e2657mr8468845plg.151.1669125908606; Tue, 22 Nov 2022 06:05:08 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:05:08 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 10/11] cryptodev: support QoS Date: Tue, 22 Nov 2022 22:07:55 +0800 Message-Id: <20221122140756.686982-11-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add 'throttle-bps' and 'throttle-ops' limitation to set QoS. The two arguments work with both QEMU command line and QMP command. Example of QEMU command line: -object cryptodev-backend-builtin,id=cryptodev1,throttle-bps=1600,\ throttle-ops=100 Example of QMP command: virsh qemu-monitor-command buster --hmp qom-set /objects/cryptodev1 \ throttle-ops 100 or cancel limitation: virsh qemu-monitor-command buster --hmp qom-set /objects/cryptodev1 \ throttle-ops 0 Signed-off-by: zhenwei pi --- backends/cryptodev.c | 140 +++++++++++++++++++++++++++++++++++++ include/sysemu/cryptodev.h | 7 ++ qapi/qom.json | 8 ++- 3 files changed, 154 insertions(+), 1 deletion(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 72105df95a..5bbaa6eecc 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" @@ -219,16 +220,54 @@ 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)) { + ret = cryptodev_backend_account(backend, op_info); + if (ret < 0) { + return ret; + } + return cryptodev_backend_operation(backend, op_info); + } + + if (throttle_schedule_timer(&backend->ts, &backend->tt, true) || + !QTAILQ_EMPTY(&backend->opinfos)) { + QTAILQ_INSERT_TAIL(&backend->opinfos, op_info, next); + return 0; + } + 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); } @@ -260,12 +299,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); @@ -309,8 +434,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) @@ -318,6 +447,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 @@ -333,6 +465,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 ffbce1129c..3382b45c1a 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 Tue Nov 22 14:07:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13052409 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 20FD1C433FE for ; Tue, 22 Nov 2022 14:06:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxTtv-0000Hn-Ey; Tue, 22 Nov 2022 09:05:27 -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 1oxTtn-00005j-R0 for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:20 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxTth-0006HT-UW for qemu-devel@nongnu.org; Tue, 22 Nov 2022 09:05:19 -0500 Received: by mail-pf1-x42e.google.com with SMTP id z26so14465099pff.1 for ; Tue, 22 Nov 2022 06:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+HVZJvWqouMoHUJe7c2mgJ9TYpcYVpH6eT/p7iSAleE=; b=0OOrQ2o1JYGVIn5RoRsJN2YHqKLMWAiBy0NQlvLkxnL2sR6ffGxx/ZcQbZ3aXnFVpa 10BSVSnZ2krkCoQPP3c6LzeQkyZf/mFFrslOYxtTajoS3g1tdhqc37PvccjkdMqVlcxQ 3MA1/iLbFcxqcw+8yUaprkbAkHCizI9VQmKTZuptB/BYgKTYwjgTJNbsuWXythAdk0lU WmwoO46iiGKZXC6OgOkQM5+WbtIugCmPjqlsTPUOMzoXAr5ENk6+zEZHeGZM19u1N1ak 3sHnRZsfTj93m6nGRonP4hCvYjNNf5LXFTZgQSEDWLpwi8/i6ZByDgnzg927Tvh4S67t HJUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+HVZJvWqouMoHUJe7c2mgJ9TYpcYVpH6eT/p7iSAleE=; b=tqxJ9SNErpnfGhQB5Z5q4fq97/FWQ3bkRVGOG7R+RkFRCRTbk3Svv1lTNZlHLRxwCf H0xGmANi6EWeJw5I1ILP5gd0NFLRSssxzeaH0MGktgFuHRGIL1Cis1g1jF1xRc3SeQz1 5CD1k1uF5i8fEU8tqAKHwkbQtP1sMSkxggKVC/B9KJ7Gms9aetLlP1dknjoYdzEbsZXY XsjFxzYc6R9nBFCetuAQ8zTPcY14AWxK0oom/RXIt5Emdc5cNbDuiz2C4CEBTL6wnShN CUtlMlo1Drtit9eRarSBnlNCcv6xPJDu7kv/OjrAiDJEHrTpBm+8jnPXz0ZfLefKTDzn OJyw== X-Gm-Message-State: ANoB5pnp05pWuN+BRls39dyih0QmeeJk5rasVR2usB3/60fdIqotYUsX 8CJqelmgBkPSRA1GbpWF1qxP61kAkbXuYANI X-Google-Smtp-Source: AA0mqf7fNLfQdDeakB7RaDPiz5MJf7CjoPWeUR+/hPwiMhnAkwr/Pmb2hZ5p2yNZak5USKOpwKfqdg== X-Received: by 2002:a63:5409:0:b0:476:e3bb:2340 with SMTP id i9-20020a635409000000b00476e3bb2340mr3528168pgb.530.1669125912788; Tue, 22 Nov 2022 06:05:12 -0800 (PST) Received: from always-T480.www.tendawifi.com ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id p1-20020a170902e74100b00186b280a441sm12097410plf.239.2022.11.22.06.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 06:05:12 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com, pbonzini@redhat.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [for-8.0 v2 11/11] MAINTAINERS: add myself as the maintainer for cryptodev Date: Tue, 22 Nov 2022 22:07:56 +0800 Message-Id: <20221122140756.686982-12-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221122140756.686982-1-pizhenwei@bytedance.com> References: <20221122140756.686982-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=pizhenwei@bytedance.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, 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 Signed-off-by: zhenwei pi --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 3f698cb0e9..d1814f87ef 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2827,6 +2827,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