From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674119631; cv=none; d=zohomail.com; s=zohoarc; b=Loiha1pSp+z7iyS0DMqmJ5Ft+iClowPBQojSD5iZ6nGsXjs8Pf8lPYtoQ1tGyCvsLW0qEZpUT77q75Rp17DCSr0uH4jemgUTYRJaJzdN2f1LfkAiuXtWwzakvbqCADgLuXQvGUO1Yi1a57ABtXTIsqxU1mLOJO/jaJrhyeBKiwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674119631; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hjFn9a0xpaAGk/jIa/89xQyXjHLDxYzq+jbq8vof9l4=; b=V/1VOda+ASHQqdTnVMt10ULYnXeWw+deaVY7iEVIZwSRlv867kY+tMnjwa6XJloHGsteblDgsOQZx4tsQKgtcf8yXM7jSW5dVco96vMdP4Fz8GPHgghH+pw/Mr7V3pV+eMMJMw37dlkgrKlBqbzpq0fkW+E8A3Q5llffPPrlTz4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167411963140878.45317304356593; Thu, 19 Jan 2023 01:13:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8E-00062R-6p; Thu, 19 Jan 2023 02:14: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 1pIP8A-00060t-I0 for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:39 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP87-0002FN-8N for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:37 -0500 Received: by mail-pj1-x102d.google.com with SMTP id x2-20020a17090a46c200b002295ca9855aso4981294pjg.2 for ; Wed, 18 Jan 2023 23:14:30 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:29 -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=hjFn9a0xpaAGk/jIa/89xQyXjHLDxYzq+jbq8vof9l4=; b=WVBrMCyL/g9wFXNBxFcIUibS2E0ZDh9f2ho9x8uLQ8BmOBML6CrgFiRzlNqvvwvkYd OX2nDZpvYaTHtI9cvhu881fSx5NXySvP7t0n7a/wviPH+AWKv5DWuJZs0JS92kdIAQEM wGjKWPr1VC+sKlHvm8yf41xNcE5sbjTeDqmfcftLm2bma0P62Zu2mQ+uatn0v6FeHBMN fmozXIux1jyHBvmkkNhwK8l8LtXVnYkGhEOT9BneJE9rbZBNPZb3bEP+v26AEHisllv8 +TypGEkyzaHQZx05YgM6HbjHXqQ6ceUpfQ3QokgtTVUIAr+afetd1/gfPPQR6PPic6Ce g2uw== 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=hjFn9a0xpaAGk/jIa/89xQyXjHLDxYzq+jbq8vof9l4=; b=IWLmUO8gYTTkg0Q94ibycUhgJ38rTegr6ArVovHwlt/Pa3RQcoees74fpjP3udYIf6 GxklT7CTrFGpr2AGIotKll+V4JV3YlHgEU2cVSNAOKRttm1p1BNcgbuwK2OEdedAbDBY /7uXzQIzIi/Q2FS494YbqJJcMDgDCtaoFy0tjEARHQYaGl0NiEgtfQQkc6E7qO8ARfKE 6MMSIZidPFlfWxTssjfwHXSMjbhX/VPauP9rRO5/Hz6ko2rrB7oK3dM2fcHO7yrQMBTG phEtYaVRyJdCEGyAMVZn/pIY8IQcvNTmv+G3DD3EZmSfBrK2S23ZZHtyM6/fUgfsu5Ef 8KNQ== X-Gm-Message-State: AFqh2kpTAXSHQ39txmc4jyZhnjuNaSOuAJCeVY1j8PVYmXtme9QLP//k vslOj/BeaEOCxQyJE7RsKRZI2w== X-Google-Smtp-Source: AMrXdXvmSFn11BBAd5dncVHcoNW1aiCriUa4TdCySSfaPB+ebW03m4jFKPfTxJBcS7RdUFMK+VHoEQ== X-Received: by 2002:a17:902:ebc9:b0:194:85da:16 with SMTP id p9-20020a170902ebc900b0019485da0016mr11143552plg.13.1674112469716; Wed, 18 Jan 2023 23:14:29 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 01/12] cryptodev: Introduce cryptodev.json Date: Thu, 19 Jan 2023 15:14:08 +0800 Message-Id: <20230119071419.3585771-2-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674119633742100001 Introduce QCryptodevBackendType in cryptodev.json, also apply this to related codes. Then we can drop 'enum CryptoDevBackendOptionsType'. Note that `CRYPTODEV_BACKEND_TYPE_NONE` is *NOT* used by anywhere, so drop it(no 'none' enum in QCryptodevBackendType). Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: zhenwei pi --- MAINTAINERS | 1 + backends/cryptodev-builtin.c | 2 +- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 4 ++-- backends/cryptodev-vhost.c | 4 ++-- include/sysemu/cryptodev.h | 11 ++--------- qapi/cryptodev.json | 20 ++++++++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + 9 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 qapi/cryptodev.json diff --git a/MAINTAINERS b/MAINTAINERS index 0fe50d01e3..5ec5aebadb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2861,6 +2861,7 @@ M: Gonglei S: Maintained F: include/sysemu/cryptodev*.h F: backends/cryptodev*.c +F: qapi/cryptodev.json =20 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 =3D g_strdup_printf("cryptodev-builtin0"); cc->queue_index =3D 0; - cc->type =3D CRYPTODEV_BACKEND_TYPE_BUILTIN; + cc->type =3D QCRYPTODEV_BACKEND_TYPE_BUILTIN; backend->conf.peers.ccs[0] =3D cc; =20 backend->conf.crypto_services =3D 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 *backe= nd, Error **errp) cc =3D cryptodev_backend_new_client("cryptodev-lkcf", NULL); cc->info_str =3D g_strdup_printf("cryptodev-lkcf0"); cc->queue_index =3D 0; - cc->type =3D CRYPTODEV_BACKEND_TYPE_LKCF; + cc->type =3D QCRYPTODEV_BACKEND_TYPE_LKCF; backend->conf.peers.ccs[0] =3D cc; =20 backend->conf.crypto_services =3D diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-use= r.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 =3D CRYPTODEV_BACKEND_VHOST_USER(b); - assert(cc->type =3D=3D CRYPTODEV_BACKEND_TYPE_VHOST_USER); + assert(cc->type =3D=3D QCRYPTODEV_BACKEND_TYPE_VHOST_USER); assert(queue < MAX_CRYPTO_QUEUE_NUM); =20 return s->vhost_crypto[queue]; @@ -203,7 +203,7 @@ static void cryptodev_vhost_user_init( cc->info_str =3D g_strdup_printf("cryptodev-vhost-user%zu to %s ", i, chr->label); cc->queue_index =3D i; - cc->type =3D CRYPTODEV_BACKEND_TYPE_VHOST_USER; + cc->type =3D QCRYPTODEV_BACKEND_TYPE_VHOST_USER; =20 backend->conf.peers.ccs[i] =3D cc; =20 diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c index 572f87b3be..a2b5a2cb3b 100644 --- a/backends/cryptodev-vhost.c +++ b/backends/cryptodev-vhost.c @@ -128,7 +128,7 @@ cryptodev_get_vhost(CryptoDevBackendClient *cc, =20 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 =3D 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 =3D=3D CRYPTODEV_BACKEND_TYPE_VHOST_USER) { + if (cc->type =3D=3D QCRYPTODEV_BACKEND_TYPE_VHOST_USER) { dev->use_guest_notifier_mask =3D 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 @@ =20 #include "qemu/queue.h" #include "qom/object.h" +#include "qapi/qapi-types-cryptodev.h" =20 /** * CryptoDevBackend: @@ -215,16 +216,8 @@ struct CryptoDevBackendClass { void *opaque); }; =20 -typedef enum CryptoDevBackendOptionsType { - CRYPTODEV_BACKEND_TYPE_NONE =3D 0, - CRYPTODEV_BACKEND_TYPE_BUILTIN =3D 1, - CRYPTODEV_BACKEND_TYPE_VHOST_USER =3D 2, - CRYPTODEV_BACKEND_TYPE_LKCF =3D 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=3Dpython +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. + +## +# @QCryptodevBackendType: +# +# The crypto device backend type +# +# @builtin: the QEMU builtin support +# @vhost-user: vhost-user +# @lkcf: Linux kernel cryptographic framework +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendType', + 'prefix': 'QCRYPTODEV_BACKEND_TYPE', + 'data': ['builtin', 'vhost-user', 'lkcf']} diff --git a/qapi/meson.build b/qapi/meson.build index fbdb442fdf..1c37ae7491 100644 --- a/qapi/meson.build +++ b/qapi/meson.build @@ -56,6 +56,7 @@ if have_system qapi_all_modules +=3D [ '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' } --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674119643; cv=none; d=zohomail.com; s=zohoarc; b=GJejaHv9wbecqY4VVvxKkZp9hlTE2r2+aJaJ89Jo8uej57rQ0MBmH1mt4izxBeGqO/x+LbQwAYkSWmTuGp4hqbeJjcuLuJlxzUFGZCjqNL7+eckty1OCnicelZ2QrL5pkGX/ADVgA1GYNjHg4fWL0ttNbSk2piDmO7cnArrf1tU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674119643; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QfbjQB/uupsbnVkLnKgXK2FfdvkN34GzFDspqyb2GhQ=; b=T2dvT4nftCoMl5VhmNt+fwb7p+Pc1egF40qDwkUedW5CB40IWcnm65/kSDjQR0S6lNGPTptIawoGrALYcn5Pa81Yqe19ryBz78/lrl6etX/f29OAiEKKLI+VXE2eY/zeLrEQWH3IOQVqYpDJdLs/k9UkvkDf8ptr/GbqXngfJ64= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674119643613714.811815116088; Thu, 19 Jan 2023 01:14:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8E-00062v-JH; Thu, 19 Jan 2023 02:14: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 1pIP8B-00061Q-Vn for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:39 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8A-0002FT-A9 for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:39 -0500 Received: by mail-pl1-x62c.google.com with SMTP id 20so1523540plo.3 for ; Wed, 18 Jan 2023 23:14:34 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14: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=QfbjQB/uupsbnVkLnKgXK2FfdvkN34GzFDspqyb2GhQ=; b=hSQOwSkthTrh+s5cEsiG3q2Pp/kiTAYKVq4idbm+wG4liKTzNDa7nT0ve15nzTvCNy EJr4k9Zh+gjkYtR9Q3JWVDMerB1rrDT41Nh74xH5XTeUo8QK5q0SKpalzWcj2fHL5Lu3 CQdS0m01qXCRHb3ef40iK4sL3Wp6pawxC0ypHVAycT2M8jZsJquUvByT4iqtrWmF8pXM c/ZkBE/P1osS+vyjA/s75fbcRwHlYMvLv8R8IcmzRT4wmZcDVfeI6y7gGW7em5FJtM7d 2av+mhh1luQXyZUpr7UTOEFUJmi8WvjcHozrB0CtjidJRySoueOaOQcei+QvFTFCvGi8 0lqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QfbjQB/uupsbnVkLnKgXK2FfdvkN34GzFDspqyb2GhQ=; b=CMYM00XCLGIyUs/nCrohl/1A9tyeN5vg+j3YQgSpAW+OKmjNFr9qk08wg20G4PC4YL XAT+i/+fo4JVrRpV2/M5yyjreZ6DcICTWD/2m5xfrSUbXC+ofIiQN2MRzRUxwkimnOUv v9HjUzPPSmzIoAExSP6AWAgJSDevBJs4+18JjbytA631qWVo+NEVoHBRAleyA89AL14r 1cZIG1QfI1ekieax9HGMWR4NBWjSaX9uComUnJIUzNQV6EdLy7ISCslbh9UNBxCZ5eUi CO1FD7YLuRnehzNwshVSjVW3GOoCiWpovZWJQXVO5WOba8cN7gh6FFMdKdmyzYXPrzbY G9kw== X-Gm-Message-State: AFqh2kpy2eEg7Ontp17ZWDVx0E2FLx0Y2lJWU7Gt0gUCVP28ubrnlcru LIpeI4MlCDTTBjR7/NyZL/3wxQ== X-Google-Smtp-Source: AMrXdXszpXMW3kQMdX/30aRaIvpHSu3LVNQh9bKP3ZngM2jGOMpVY+gD3i1tjl/88RUlsUZ1yc6VKA== X-Received: by 2002:a17:902:d411:b0:192:f12a:42de with SMTP id b17-20020a170902d41100b00192f12a42demr8919266ple.42.1674112472904; Wed, 18 Jan 2023 23:14:32 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 02/12] cryptodev: Remove 'name' & 'model' fields Date: Thu, 19 Jan 2023 15:14:09 +0800 Message-Id: <20230119071419.3585771-3-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674119645192100003 We have already used qapi to generate crypto device types, this allows to convert type to a string 'model', so the 'model' field is not needed. And the 'name' field is not used by any backend driver, drop it. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 3 +-- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 3 +-- backends/cryptodev.c | 11 +---------- include/sysemu/cryptodev.h | 12 +++--------- 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 8c7c10847d..08895271eb 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -72,8 +72,7 @@ static void cryptodev_builtin_init( return; } =20 - cc =3D cryptodev_backend_new_client( - "cryptodev-builtin", NULL); + cc =3D cryptodev_backend_new_client(); cc->info_str =3D g_strdup_printf("cryptodev-builtin0"); cc->queue_index =3D 0; cc->type =3D 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 *backe= nd, Error **errp) return; } =20 - cc =3D cryptodev_backend_new_client("cryptodev-lkcf", NULL); + cc =3D cryptodev_backend_new_client(); cc->info_str =3D g_strdup_printf("cryptodev-lkcf0"); cc->queue_index =3D 0; cc->type =3D QCRYPTODEV_BACKEND_TYPE_LKCF; diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-use= r.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 =3D true; =20 for (i =3D 0; i < queues; i++) { - cc =3D cryptodev_backend_new_client( - "cryptodev-vhost-user", NULL); + cc =3D cryptodev_backend_new_client(); cc->info_str =3D g_strdup_printf("cryptodev-vhost-user%zu to %s ", i, chr->label); cc->queue_index =3D 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; =20 =20 -CryptoDevBackendClient * -cryptodev_backend_new_client(const char *model, - const char *name) +CryptoDevBackendClient *cryptodev_backend_new_client(void) { CryptoDevBackendClient *cc; =20 cc =3D g_new0(CryptoDevBackendClient, 1); - cc->model =3D g_strdup(model); - if (name) { - cc->name =3D g_strdup(name); - } - QTAILQ_INSERT_TAIL(&crypto_clients, cc, next); =20 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 { =20 struct CryptoDevBackendClient { QCryptodevBackendType type; - char *model; - char *name; char *info_str; unsigned int queue_index; int vring_enable; @@ -264,11 +262,8 @@ struct CryptoDevBackend { =20 /** * 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 --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674123528; cv=none; d=zohomail.com; s=zohoarc; b=NxvKdbm3/IK3Y67D7Xvo/k6Jbnxx3potdGf4B5+z0helckJ9gS/A38B/NuYwxYbde6xa0p1zoo5rf0KWPVGtfAgIe25uOMihSXj44ONwP/FE5c+ZdCVBFdlZbDhnU4O+rrcFVT/mlSueXGkOlHzGYWTrQ8T0FHLHWdrn+M8femY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674123528; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dMFQWyQMxJuLht08y8UXOs3qr1UwVrlQirzyvap/Nu4=; b=dcYXitPtxNysyVb4xAmQ2i2mW5oT8j16F1bIP0lkRWNHtHpy2BHJJEIqZuMPUlldPqEIPHhDmr1ter06VpHow0nAoy3a4ZwD5WpXKU22B+FAkkJk8qimtD6mYD4CBY32yt0TrqmC8503fLHSMSh3Ueyy+/QK9fRFVYowHr3aAg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674123528758527.4792672120109; Thu, 19 Jan 2023 02:18:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8H-00063s-96; Thu, 19 Jan 2023 02:14:45 -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 1pIP8C-00061l-94 for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:40 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8A-0002Fa-AP for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:40 -0500 Received: by mail-pl1-x632.google.com with SMTP id k18so1512102pll.5 for ; Wed, 18 Jan 2023 23:14:37 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dMFQWyQMxJuLht08y8UXOs3qr1UwVrlQirzyvap/Nu4=; b=RxuKbB42GKBQjdVAEgf34MYFESSoneDHWtPnSrkQzbUUC2/SdPq3P3S53CLs14EAYg 9/wc8qNUdXe7OMxneYq0xMsAQCABDgaGdb2FjUd4He12diJFbPCIxWCjJhpbXttcU/SN 8yQBFmZ4gKqcgQdvppuRenktFbRcDXMYw5KDHUdYL0xNUhNU2/SrLJ1d9DS4YRuhPWSf Mx64dWveqpe6rxEdE4+k0vczVovNQqyRQwEewSyUm37S75YHAUlr8uFYBUnsBKcaB56y y8pkz2tMj8a9TdyBA9A+2P7ITtA297xWr4fVp4bsHyVp8ddGGPuiJqoCIBBawiMW0YZy uVsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dMFQWyQMxJuLht08y8UXOs3qr1UwVrlQirzyvap/Nu4=; b=kKzmNKJIPE49ut/0LS/YydHyDdFFQQaJYQ/L5kIhlBehSxdNFlPqDXmVUTlv6pskIX ypfhOBKoD+gTWhefvCzWG8Ra18laJ8NAOMccggFm2mOZ0Ffz4L1uESDSaT9elEBQo4Pp Yv1YN/J529jg1xZBZSxtaBzLi7dIuFDXfjYdoYzKpP+RaJnKOE9wSYY/JNRBbt3/O21+ 1fQ5/nlgHW+P+6KVgPa+5Azo2Kp5r+iG0bxBjvPU8HVPPPWKwDRFMW+dQPO8cjksqny4 qDYuoLVOAorgKoRsZPU34mAsBjdHQNq3EPTolFoI1NHFioaA0NTpQ7kptCmPMeclAE6s 8ceA== X-Gm-Message-State: AFqh2kos6/4tSjS/gKRNAKumQ460TMdPUtu1ZkQwxl/h3LZgiEd7MQTL mLFotTlxzQuzGLrLpHb0o1mBNQ== X-Google-Smtp-Source: AMrXdXu/0gDye7/Np3jJPLwMq2aeZRhXT2xg89WdB44yZ1desVJZY9efBpZCoPjNcF2O0WWVyHZbXA== X-Received: by 2002:a17:902:eb11:b0:18f:6cb:1730 with SMTP id l17-20020a170902eb1100b0018f06cb1730mr9479537plb.26.1674112476111; Wed, 18 Jan 2023 23:14:36 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 03/12] cryptodev: Introduce cryptodev alg type in QAPI Date: Thu, 19 Jan 2023 15:14:10 +0800 Message-Id: <20230119071419.3585771-4-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x632.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674123529734100001 Introduce cryptodev alg type in cryptodev.json, then apply this to related codes, and drop 'enum CryptoDevBackendAlgType'. There are two options: 1, { 'enum': 'QCryptodevBackendAlgType', 'prefix': 'CRYPTODEV_BACKEND_ALG', 'data': ['sym', 'asym']} Then we can keep 'CRYPTODEV_BACKEND_ALG_SYM' and avoid lots of changes. 2, changes in this patch(with prefix 'QCRYPTODEV_BACKEND_ALG'). To avoid breaking the rule of QAPI, use 2 here. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 6 +++--- backends/cryptodev-lkcf.c | 4 ++-- backends/cryptodev.c | 6 +++--- hw/virtio/virtio-crypto.c | 14 +++++++------- include/sysemu/cryptodev.h | 8 +------- qapi/cryptodev.json | 14 ++++++++++++++ 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 08895271eb..e70dcd5dad 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -537,7 +537,7 @@ static int cryptodev_builtin_operation( CryptoDevBackendBuiltinSession *sess; CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendAsymOpInfo *asym_op_info; - enum CryptoDevBackendAlgType algtype =3D op_info->algtype; + QCryptodevBackendAlgType algtype =3D op_info->algtype; int status =3D -VIRTIO_CRYPTO_ERR; Error *local_error =3D NULL; =20 @@ -549,11 +549,11 @@ static int cryptodev_builtin_operation( } =20 sess =3D builtin->sessions[op_info->session_id]; - if (algtype =3D=3D CRYPTODEV_BACKEND_ALG_SYM) { + if (algtype =3D=3D QCRYPTODEV_BACKEND_ALG_SYM) { sym_op_info =3D op_info->u.sym_op_info; status =3D cryptodev_builtin_sym_operation(sess, sym_op_info, &local_error); - } else if (algtype =3D=3D CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (algtype =3D=3D QCRYPTODEV_BACKEND_ALG_ASYM) { asym_op_info =3D op_info->u.asym_op_info; status =3D cryptodev_builtin_asym_operation(sess, op_info->op_code, asym_op_info, &local_err= or); diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index de3d1867c5..53a932b58d 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -477,7 +477,7 @@ static int cryptodev_lkcf_operation( CryptoDevBackendLKCF *lkcf =3D CRYPTODEV_BACKEND_LKCF(backend); CryptoDevBackendLKCFSession *sess; - enum CryptoDevBackendAlgType algtype =3D op_info->algtype; + QCryptodevBackendAlgType algtype =3D op_info->algtype; CryptoDevLKCFTask *task; =20 if (op_info->session_id >=3D MAX_SESSIONS || @@ -488,7 +488,7 @@ static int cryptodev_lkcf_operation( } =20 sess =3D lkcf->sess[op_info->session_id]; - if (algtype !=3D CRYPTODEV_BACKEND_ALG_ASYM) { + if (algtype !=3D QCRYPTODEV_BACKEND_ALG_ASYM) { error_report("algtype not supported: %u", algtype); return -VIRTIO_CRYPTO_NOTSUPP; } diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 81941af816..c2a053db0e 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -120,10 +120,10 @@ int cryptodev_backend_crypto_operation( { VirtIOCryptoReq *req =3D opaque1; CryptoDevBackendOpInfo *op_info =3D &req->op_info; - enum CryptoDevBackendAlgType algtype =3D req->flags; + QCryptodevBackendAlgType algtype =3D req->flags; =20 - if ((algtype !=3D CRYPTODEV_BACKEND_ALG_SYM) - && (algtype !=3D CRYPTODEV_BACKEND_ALG_ASYM)) { + if ((algtype !=3D QCRYPTODEV_BACKEND_ALG_SYM) + && (algtype !=3D QCRYPTODEV_BACKEND_ALG_ASYM)) { error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtyp= e); return -VIRTIO_CRYPTO_NOTSUPP; } diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 516425e26a..0d1be0ada9 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -462,7 +462,7 @@ static void virtio_crypto_init_request(VirtIOCrypto *vc= rypto, VirtQueue *vq, req->in_iov =3D NULL; req->in_num =3D 0; req->in_len =3D 0; - req->flags =3D CRYPTODEV_BACKEND_ALG__MAX; + req->flags =3D QCRYPTODEV_BACKEND_ALG__MAX; memset(&req->op_info, 0x00, sizeof(req->op_info)); } =20 @@ -472,7 +472,7 @@ static void virtio_crypto_free_request(VirtIOCryptoReq = *req) return; } =20 - if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_SYM) { + if (req->flags =3D=3D QCRYPTODEV_BACKEND_ALG_SYM) { size_t max_len; CryptoDevBackendSymOpInfo *op_info =3D req->op_info.u.sym_op_info; =20 @@ -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 =3D=3D CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (req->flags =3D=3D QCRYPTODEV_BACKEND_ALG_ASYM) { CryptoDevBackendAsymOpInfo *op_info =3D req->op_info.u.asym_op_inf= o; if (op_info) { g_free(op_info->src); @@ -570,10 +570,10 @@ static void virtio_crypto_req_complete(void *opaque, = int ret) VirtIODevice *vdev =3D VIRTIO_DEVICE(vcrypto); uint8_t status =3D -ret; =20 - if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_SYM) { + if (req->flags =3D=3D QCRYPTODEV_BACKEND_ALG_SYM) { virtio_crypto_sym_input_data_helper(vdev, req, status, req->op_info.u.sym_op_info); - } else if (req->flags =3D=3D CRYPTODEV_BACKEND_ALG_ASYM) { + } else if (req->flags =3D=3D 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 =3D request->flags =3D CRYPTODEV_BACKEND_ALG_SYM; + op_info->algtype =3D request->flags =3D QCRYPTODEV_BACKEND_ALG_SYM; ret =3D 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 =3D request->flags =3D CRYPTODEV_BACKEND_ALG_ASYM; + op_info->algtype =3D request->flags =3D QCRYPTODEV_BACKEND_ALG_ASY= M; ret =3D virtio_crypto_handle_asym_req(vcrypto, &req.u.akcipher_req, op_info, out_iov, out_num); diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index af152d09db..16f01dd48a 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -49,12 +49,6 @@ typedef struct CryptoDevBackendPeers CryptoDevBackendPee= rs; typedef struct CryptoDevBackendClient CryptoDevBackendClient; =20 -enum CryptoDevBackendAlgType { - CRYPTODEV_BACKEND_ALG_SYM, - CRYPTODEV_BACKEND_ALG_ASYM, - CRYPTODEV_BACKEND_ALG__MAX, -}; - /** * CryptoDevBackendSymSessionInfo: * @@ -181,7 +175,7 @@ typedef struct CryptoDevBackendAsymOpInfo { } CryptoDevBackendAsymOpInfo; =20 typedef struct CryptoDevBackendOpInfo { - enum CryptoDevBackendAlgType algtype; + QCryptodevBackendAlgType algtype; uint32_t op_code; uint64_t session_id; union { diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index b65edbe183..ebb6852035 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -4,6 +4,20 @@ # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. =20 +## +# @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: # --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674123602; cv=none; d=zohomail.com; s=zohoarc; b=oAhn7aC/jlRVRdb7f/X+vZIh3fYXsAT59FZXvgazVqiHtqVjbqjSSGsrjmGhOvbr6+Cn9ZCqX/TE+2CEr6xYmNOaXKVQSMGFPq3Hpj/iWOIWwqJs5Ij9JPpuB3YzCfId1phnhCPjQ48FrcbAqJY9I7BTpj8mXwPAquOdo4EOFnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674123602; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ihnaClmcpFL3v9tNj7fgQemINsh8688QVm+1j1fBK14=; b=DARLbGHkSuNhEShnxpleGotngVTUNB7cd3tN75qWu+Tu0SsoH9k7qrIbYKrlQfTmmetLLzFeaWf/nShTGD+j6NsoVzC8zUhAPcjqBVfCqrRMGGMkE+3PKFsh9pb2vpKKBa0J7vuyfZ4lzEbsi8LaqXf/cCuC9+kTMXm3Yha5myQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674123602531767.9746533806397; Thu, 19 Jan 2023 02:20:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8I-00065F-Sw; Thu, 19 Jan 2023 02:14:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIP8G-000645-MH for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:44 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8D-0002Fq-0J for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:43 -0500 Received: by mail-pl1-x635.google.com with SMTP id k18so1512217pll.5 for ; Wed, 18 Jan 2023 23:14:40 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ihnaClmcpFL3v9tNj7fgQemINsh8688QVm+1j1fBK14=; b=h8hd9mR4TOfK59bAn53ryZ7rZeh5Ta5ivH+DT1JAFpcw3Ta3pZXJwKDRShuUVt6MG2 Ijb4rmQr40MYaOBisx9ordQJEBBfXWpVQpx/QkXhmBm5Bc/PiDX7wa0hCF0J5G9Gwx5n 77bbCRDJz/+kB/T35CC/BB3y7mniTtwEmlch/o9RTFb1XkcfZwjqk8xM2ldpIlWzv5nX tDodOaY4UDgU0KC2IfHFIKE0rQ4Lgrgndr/jOYyFSf4Mk70JTrMs9wfTqtTpexrT0ocX yeZDdI/AW73vkAPiwAOCYuOih0nxv76z1aBCUW2DFd+ijh9g/Rlu91dOBWNGVBNSt+l1 ZnEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ihnaClmcpFL3v9tNj7fgQemINsh8688QVm+1j1fBK14=; b=Phz32OlRPwnrPIs5Fn2QQkDT2izWLDobGQ957A/Bv8QKb8vLKi2cdmEP9Axbu2+xdq 43qhwSFfsMuTGBUqak9FXVG2ottBDni27VYdnD5bMAi6bXAJRxamYZQWrJQFAK8TnvCk pNPxIdXTJUG3ADSfesIFglkAo2m4j0FjMYNnTaU5yXbAhTc59oRRT4XQHBzoDdDXE3jO CVEyUWlnmoWKKjCMEaZruIiAJNYLNBUYNqBREN2uQTYlLarX1LZZURRsXfBJ24Ye3Ppr sKGdMH4lXnQvDA/gqvp0p5kNN4v/eh3W8RWAu0m2uP11QiqieX4Ll8QkPkAc2gr4pzuD JDHg== X-Gm-Message-State: AFqh2kpBBp8fFwO85EvjxeewagFs3hScadNvM3/sy3rLDEDfqN7a/WLx GE30XuafDOB+1ahOtPoQs7OtjQ== X-Google-Smtp-Source: AMrXdXvvKoA0OmkfPOczIylXaGpyuNqdArjf//iN4lq4D0XirClA39B83yGS/8t8hpoSbKNa2m5M3A== X-Received: by 2002:a17:902:e5d2:b0:194:52ed:7a16 with SMTP id u18-20020a170902e5d200b0019452ed7a16mr12330322plf.24.1674112479247; Wed, 18 Jan 2023 23:14:39 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 04/12] cryptodev: Introduce server type in QAPI Date: Thu, 19 Jan 2023 15:14:11 +0800 Message-Id: <20230119071419.3585771-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674123606114100001 Introduce cryptodev service type in cryptodev.json, then apply this to related codes. Now we can remove VIRTIO_CRYPTO_SERVICE_xxx dependence from QEMU cryptodev. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 8 ++++---- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 6 +++--- hw/virtio/virtio-crypto.c | 27 +++++++++++++++++++++++++-- qapi/cryptodev.json | 11 +++++++++++ 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index e70dcd5dad..c0fbb650d7 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -79,10 +79,10 @@ static void cryptodev_builtin_init( backend->conf.peers.ccs[0] =3D cc; =20 backend->conf.crypto_services =3D - 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 =3D 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo =3D 1u << VIRTIO_CRYPTO_HASH_SHA1; backend->conf.akcipher_algo =3D 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 53a932b58d..edec99f104 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -230,7 +230,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backe= nd, Error **errp) backend->conf.peers.ccs[0] =3D cc; =20 backend->conf.crypto_services =3D - 1u << VIRTIO_CRYPTO_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.akcipher_algo =3D 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; lkcf->running =3D true; =20 diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-use= r.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); =20 backend->conf.crypto_services =3D - 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 =3D 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo =3D 1u << VIRTIO_CRYPTO_HASH_SHA1; =20 diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 0d1be0ada9..e4f0de4d1c 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -997,12 +997,35 @@ static void virtio_crypto_reset(VirtIODevice *vdev) } } =20 +static uint32_t virtio_crypto_init_services(uint32_t qservices) +{ + uint32_t vservices =3D 0; + + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) { + vservices |=3D (1 << VIRTIO_CRYPTO_SERVICE_CIPHER); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_HASH)) { + vservices |=3D (1 << VIRTIO_CRYPTO_SERVICE_HASH); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_MAC)) { + vservices |=3D (1 << VIRTIO_CRYPTO_SERVICE_MAC); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AEAD)) { + vservices |=3D (1 << VIRTIO_CRYPTO_SERVICE_AEAD); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) { + vservices |=3D (1 << VIRTIO_CRYPTO_SERVICE_AKCIPHER); + } + + return vservices; +} + static void virtio_crypto_init_config(VirtIODevice *vdev) { VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(vdev); =20 - vcrypto->conf.crypto_services =3D - vcrypto->conf.cryptodev->conf.crypto_services; + vcrypto->conf.crypto_services =3D virtio_crypto_init_services( + vcrypto->conf.cryptodev->conf.crypto_services); vcrypto->conf.cipher_algo_l =3D vcrypto->conf.cryptodev->conf.cipher_algo_l; vcrypto->conf.cipher_algo_h =3D 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']} =20 +## +# @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: # --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674120288; cv=none; d=zohomail.com; s=zohoarc; b=KQvuKZJ59TwOhKP6+Av6BT17rHBnDV3jQ7uGVIm2AJCWhJr99w5iA+CSL4vnVnr1dx2QqZ9DH0hAPZB+PxpdrQxcpQIpBvq9XzwLlccMzYXJUrW34KW3F7usCKbV+1xQXuFKwM2jvBMBKghwh1OU/hzxvjyRq9jt3/OhbVoPbYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674120288; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=x+hVdTPrWVAwZzOg9SAFFEr8aXe+lGZ7gpPp7jgQYJI=; b=bUrimHb9snWZ10iskd0Yrf844TR/g3pO+aYSDc8Ejy+u6w2DCx8kIwkf01m1MDZISUFh/V2LA3YgDPwpy54IsxE/nzdrwv34Z/mIJ0S6emyVsPaeCzoalztUhanz0TRPUpJlLWjVSmeOdc2iQtMIx8tW3wTh1hj4YYpPjES2WhQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167412028807185.24241215345444; Thu, 19 Jan 2023 01:24:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8M-00066z-2b; Thu, 19 Jan 2023 02:14:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIP8J-00065k-Oe for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:47 -0500 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8H-0002GG-AN for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:47 -0500 Received: by mail-pj1-x102f.google.com with SMTP id s13-20020a17090a6e4d00b0022900843652so4991300pjm.1 for ; Wed, 18 Jan 2023 23:14:43 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:41 -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=x+hVdTPrWVAwZzOg9SAFFEr8aXe+lGZ7gpPp7jgQYJI=; b=i1wirrMnTVeM/xlRqyyBRhLBxCfu+UEesRcVvfo31MQ6nME5NFG6pDZew0aIug5byt 8OBw2uhBVR+8VzRscItBFOJSaxBivrVhcUjGO5K41/8LTEo2x795aJX8RLmjEO6DX697 JwGTVIcoCYPfRmeZNtQFNGwREWjXxea0II/08CuP+IcWlqCqx7ZSmW1FJVyfGV6y9+5Q wR/Vi1AJCHSvNvJDwHj/9oJ7pYwFkU332ywzFOwM9xpcYTnGX4H35hU51QZIK5ya5B9v xGWhi5jMz9oHt/H2zAJR9+fH5pjpz0Vg4exQ4erYUetrSqOBEZUUoQlSg+Tylw7J18Qd HRRw== 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=x+hVdTPrWVAwZzOg9SAFFEr8aXe+lGZ7gpPp7jgQYJI=; b=RwWm8j0gatQ1SazrT3wPgfP9L/MQEd9e/TNG3o53CvbHQXerOHGdydvZz91JgERc0L Z6vEF59D2PhMYAz9q9gCcz+J7qBPGorK4RqDl3jOZ5gy8EmJtBUtVt8BjVSWbm1giLQM Ckz7sfYJU6ylheV3eE7e5ejU9wOmnGDQI+uKa+JZ8PcmRBgLFenEk93XPYs3YbieGoz/ ltj5k2efUa/wXYBrvqvvjHTMFiSwNTlb0xqR2+01Z1M2GkUzyZ8TSA0kCOmR4t97R0+B Bya7P/DxHLGE7rdtKXHIPDBFV+oh6HSKJLdoCtOu9KGagm80gno7KFxYYfixbJ+5wZkY F0lA== X-Gm-Message-State: AFqh2kpkpCZXO6YEQH0xPKyEPX+2bAjf7FLoyaGB1YuCcUdQIMyBv5OI /cARlehliJn25/+MGRi2XfBipw== X-Google-Smtp-Source: AMrXdXveJzrcL3i3elBHFJPZmqcByMS6D81CHKAEONqiOI9Cp0dKU9hDmXNH1vpQQk6EDdoCkKodEg== X-Received: by 2002:a17:902:f54c:b0:192:fc9c:a238 with SMTP id h12-20020a170902f54c00b00192fc9ca238mr11504452plf.66.1674112482362; Wed, 18 Jan 2023 23:14:42 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 05/12] cryptodev: Introduce 'query-cryptodev' QMP command Date: Thu, 19 Jan 2023 15:14:12 +0800 Message-Id: <20230119071419.3585771-6-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674120290069100001 Content-Type: text/plain; charset="utf-8" Now we have a QMP command to query crypto devices: virsh qemu-monitor-command vm '{"execute": "query-cryptodev"}' | jq { "return": [ { "service": [ "akcipher", "mac", "hash", "cipher" ], "id": "cryptodev1", "client": [ { "queue": 0, "type": "builtin" } ] }, { "service": [ "akcipher" ], "id": "cryptodev0", "client": [ { "queue": 0, "type": "lkcf" } ] } ], "id": "libvirt-417" } Signed-off-by: zhenwei pi --- backends/cryptodev.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ qapi/cryptodev.json | 44 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index c2a053db0e..d51eeb5ee4 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "sysemu/cryptodev.h" #include "qapi/error.h" +#include "qapi/qapi-commands-cryptodev.h" #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -33,6 +34,50 @@ =20 static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; =20 +static int qmp_query_cryptodev_foreach(Object *obj, void *data) +{ + CryptoDevBackend *backend; + CryptodevInfoList **infolist =3D data; + uint32_t services, i; + + if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) { + return 0; + } + + CryptodevInfo *info =3D g_new0(CryptodevInfo, 1); + info->id =3D g_strdup(object_get_canonical_path_component(obj)); + + backend =3D CRYPTODEV_BACKEND(obj); + services =3D backend->conf.crypto_services; + for (i =3D 0; i < QCRYPTODEV_BACKEND_SERVICE__MAX; i++) { + if (services & (1 << i)) { + QAPI_LIST_PREPEND(info->service, i); + } + } + + for (i =3D 0; i < backend->conf.peers.queues; i++) { + CryptoDevBackendClient *cc =3D backend->conf.peers.ccs[i]; + CryptodevBackendClient *client =3D g_new0(CryptodevBackendClient, = 1); + + client->queue =3D cc->queue_index; + client->type =3D cc->type; + QAPI_LIST_PREPEND(info->client, client); + } + + QAPI_LIST_PREPEND(*infolist, info); + + return 0; +} + +CryptodevInfoList *qmp_query_cryptodev(Error **errp) +{ + CryptodevInfoList *list =3D NULL; + Object *objs =3D container_get(object_get_root(), "/objects"); + + object_child_foreach(objs, qmp_query_cryptodev_foreach, &list); + + return list; +} =20 CryptoDevBackendClient *cryptodev_backend_new_client(void) { diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index 8732a30524..6c6509cd3f 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -43,3 +43,47 @@ { 'enum': 'QCryptodevBackendType', 'prefix': 'QCRYPTODEV_BACKEND_TYPE', 'data': ['builtin', 'vhost-user', 'lkcf']} + +## +# @CryptodevBackendClient: +# +# Information about a queue of crypto device. +# +# @queue: the queue index of the crypto device +# +# @type: the type of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'CryptodevBackendClient', + 'data': { 'queue': 'int', + 'type': 'QCryptodevBackendType' } } + +## +# @CryptodevInfo: +# +# Information about a crypto device. +# +# @id: the id of the crypto device +# +# @service: supported service types of a crypto device +# +# @client: the additional infomation of the crypto device +# +# Since: 8.0 +## +{ 'struct': 'CryptodevInfo', + 'data': { 'id': 'str', + 'service': ['QCryptodevBackendServiceType'], + 'client': ['CryptodevBackendClient'] } } + +## +# @query-cryptodev: +# +# Returns information about current crypto devices. +# +# Returns: a list of @CryptodevInfo +# +# Since: 8.0 +## +{ 'command': 'query-cryptodev', 'returns': ['CryptodevInfo']} --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674120016; cv=none; d=zohomail.com; s=zohoarc; b=Umznelj7SXe/7L5Ic1YeSru0GtD4VuOKMYNh2IG9HcKWxCbz6riI9zJKw7n9IfYIDQ4fD8d7y4lkBzPpTQImRICky7bBMHLese0CtQXCo1Slcrt9cvoRPUnNrolFtdoQAshEzmku9by7h/3jmXF9BB/W5xXess3xN3kWWonzfRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674120016; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=hFw02JIp7jo43EbHrKKtyDXum24BCfnqKN5vaIC8SVmMTRngBYwZNI1bGA9gSL2ZiDvKsEHHmWMileUspi9zqGOt42psVtiIR6IBTfV6AzhCzVs75Evxubw+pWgZ05DMkfm0t48Yf9yDbMFr0DirrD+wu8YdY8hJDaqLUCA0LOI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167412001645628.883687742347092; Thu, 19 Jan 2023 01:20:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8M-000677-Cy; Thu, 19 Jan 2023 02:14:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIP8K-00066F-NU for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:48 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8I-0002GV-Um for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:48 -0500 Received: by mail-pj1-x1030.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so1023448pjl.0 for ; Wed, 18 Jan 2023 23:14:46 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=3D7MIjXLiLtJi1lFTm9scaUgzt7Dh8edppItpSH87bvmhEK8MpjiUDeCzwYWQsGQZf EGMr/kZgDRrb6X/K694JqfylDcUfW5qYU8roScGooz3x44iDxOY6+4HksEBExkFUdJXa fUS2/VQZ6vowHFj1p8MMfmhlR46UYaAKYwM/0ujDcfR5jssV1TV2XMsvYa1Wm1ZlYd9L jQRepKrNtWVk2EHooudBrnC4WjDdXxw/Sl2uj3glo2DaczT0BnWsyuHvVzpG6HcexIHl URNc4J5tPsOZsl589a8vCpP3s0BSqYXY+Cy4ErZ93MPk20nTQlRUQxKGs2CJtvCyCOL1 v/Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=apL1WJYFS+wRnFE1AVrV2YJrrdnc+DLo0evEaR25zXg=; b=MLdyIy2BYvNNoYX3YDuR68WUJg8K3fZlecOE1UJCkmsQKy+/UpnwvuS3YhVBOOCW6a X3INF+PgdlebqNP6HLxwY0VkyK1+rdS5q1+n3/wGRfR6TkBiwHUMEmaf+CabZHc+ZuQ2 UbDF+9YIsPlRKGR1KFc47hyEEMSTMZyW6gF7trPYXuly5lvCHEQ9A67xWM1JWgfI6WkV s0C0Sa7pLJt77r+lxFsKxuDB7hn56zCWANzwjf6qO/CJmcXMCQmKX2Ph9HKPkKc2SQS5 e36wwcxz0plH9/8Hf9zniPUs9dLBmK6GAvW+2B5u21g7/rMDL/qYoBpzTEKyWGtLy2dn upZA== X-Gm-Message-State: AFqh2krtBm+TxXRuvcmkaV1+eb9xoXpZIeaKR1iMX73+jYw57EgRuwF6 c6WEDuH79BPvi01+P6FlCIhyDw== X-Google-Smtp-Source: AMrXdXtU0or2wiYw3dLPnOQWEOoNs70ts2qrBISfjnF1tNIcRLDd9PQsGiES/7aXQAN4bKBv6xMXsQ== X-Received: by 2002:a17:902:c10d:b0:194:9cb0:12e2 with SMTP id 13-20020a170902c10d00b001949cb012e2mr10144470pli.36.1674112485437; Wed, 18 Jan 2023 23:14:45 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 06/12] cryptodev-builtin: Detect akcipher capability Date: Thu, 19 Jan 2023 15:14:13 +0800 Message-Id: <20230119071419.3585771-7-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1030.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674120017206100001 Rather than exposing akcipher service/RSA algorithm to virtio crypto device unconditionally, detect akcipher capability from akcipher crypto framework. This avoids unsuccessful requests. Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index c0fbb650d7..c45b5906c5 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -59,6 +59,19 @@ struct CryptoDevBackendBuiltin { CryptoDevBackendBuiltinSession *sessions[MAX_NUM_SESSIONS]; }; =20 +static void cryptodev_builtin_init_akcipher(CryptoDevBackend *backend) +{ + QCryptoAkCipherOptions opts; + + opts.alg =3D QCRYPTO_AKCIPHER_ALG_RSA; + opts.u.rsa.padding_alg =3D QCRYPTO_RSA_PADDING_ALG_RAW; + if (qcrypto_akcipher_supports(&opts)) { + backend->conf.crypto_services |=3D + (1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER); + backend->conf.akcipher_algo =3D 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 =3D 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 =3D 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo =3D 1u << VIRTIO_CRYPTO_HASH_SHA1; - backend->conf.akcipher_algo =3D 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 =3D LONG_MAX - sizeof(CryptoDevBackendOpInfo); backend->conf.max_cipher_key_len =3D CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_= LEN; backend->conf.max_auth_key_len =3D CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN; + cryptodev_builtin_init_akcipher(backend); =20 cryptodev_backend_set_ready(backend, true); } --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674120317; cv=none; d=zohomail.com; s=zohoarc; b=NpsEzD0L8NNveBX480b4/6yvYZjEqmRI1O7CqxhRz77QgbpXbVgCD3Vn7GKnTJ3lobeo6WAUpoAzeerTYehIxv+wa7+cfzHfzf2S5gsye3scnAc0jo9KrOyKXhqo/nvMnhuqTykhkScuHq0GLjFoS2iAeO88pOnu82MJ7rPZtFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674120317; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=d7GjFcohFv4eNP+TegsfHNvLcNXFVf2rYI0Dx/A9oLc=; b=PKGKNZHHWS+T2Alhi/vTRADoj584qgPA2Jrz5ZjE3XnIC++D0dvIgjSg+dQHNdA3NwHwzCFu48CsaJDXkTFBOkXLm71hwxJaImeRbE9ka0TGJSCxPQ1Yabr+LHYQIBh8VFxat0EmfSH3rxC5AzCD9O2dxhUVIfECd1T4EZ0RKzs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674120317604722.7206057820558; Thu, 19 Jan 2023 01:25:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8O-00068c-Px; Thu, 19 Jan 2023 02:14:52 -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 1pIP8N-00067g-62 for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:51 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8L-0002GV-6l for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:50 -0500 Received: by mail-pj1-x1030.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so1023527pjl.0 for ; Wed, 18 Jan 2023 23:14:48 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:48 -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=d7GjFcohFv4eNP+TegsfHNvLcNXFVf2rYI0Dx/A9oLc=; b=diHLy9zOojBBOVg+HWEzys9NUPN1ff36AbCWBm/DnT3FXTcll61h5f/3Lp557pGG+H 34IE9+b11aJhPOO0OvSCwPgswJayuSRYJGcwiCUlBkELVm4ykU2MOsIRPR1F9Iz926/0 MEPnx43EZd6dM1abbtpfa9+J0dYa/7s0wL5ff1QzbvzES7KCMAE8IbV1xUSX4tyXjaeJ XTznHIVRYDgI/dTLEGzjyRkrsXbqyukvCbQ/fjgBDMnKI3mZDqb2B79KNNE1Tz7O3bAd YdETiWC8AxQIKqRBoTHeB2v0VwXTG5OY8Rs3S0CzBBN7ul1qBAjaSvuKWfxt0p0OeOkW dKPw== 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=d7GjFcohFv4eNP+TegsfHNvLcNXFVf2rYI0Dx/A9oLc=; b=5tv49YVJDSVXSYtvgq3V4bNIk7L+IyAw6GgNjU4eSHUg9CqH475Afk4FBejtkrT5q5 ys+X3kldx4drE4vyfQzcVdAwz5Wq9J1Atsv0t21FYIp4J7uI6xDED5M2nfAfE6gSaBQY JBWVcqcEqZ0t/RE0zMLDWtUfVG/r/4Taj0+h60yVmmwB9qYhNALlub3wy47RQw47NWlP 10cjemzmr7CuPEszqnBK01ygWdjoepgIvGXFUv7ShFiNG05BkXuNWJCeqhCwV4N+A7sj KCcBkEofn+loru7zc+2nETqohPXqE6Jw3l73oubyl+o+tB4/bcG3gLpO0998iaY2nLGu 2Qog== X-Gm-Message-State: AFqh2kpRqw5V+zCpmmOp4auZ3msaaPUpVFDJ9zW7s3ZFFJ6p0JkjIMDE x3LlC3IKgUCY8+PxLsGG+ZmOog== X-Google-Smtp-Source: AMrXdXtjdN9U0njFTniKnIhcVUpxiJwOzHvmxVGge+T+d0xc+0K6T67odGuelANJkkYotxudy7xNsQ== X-Received: by 2002:a17:902:9a97:b0:193:2a8c:28cb with SMTP id w23-20020a1709029a9700b001932a8c28cbmr10218978plp.21.1674112488506; Wed, 18 Jan 2023 23:14:48 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 07/12] hmp: add cryptodev info command Date: Thu, 19 Jan 2023 15:14:14 +0800 Message-Id: <20230119071419.3585771-8-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1030.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674120319044100002 Content-Type: text/plain; charset="utf-8" Example of this command: # virsh qemu-monitor-command vm --hmp info cryptodev cryptodev1: service=3D[akcipher|mac|hash|cipher] queue 0: type=3Dbuiltin cryptodev0: service=3D[akcipher] queue 0: type=3Dlkcf 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 =3D "cryptodev", + .args_type =3D "", + .params =3D "", + .help =3D "show the crypto devices", + .cmd =3D hmp_info_cryptodev, + .flags =3D "p", + }, + +SRST + ``info cryptodev`` + Show the crypto devices. +ERST diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 27f86399f7..e193d01419 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -144,5 +144,6 @@ void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Erro= r **)); void hmp_info_stats(Monitor *mon, const QDict *qdict); void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict); +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index ed78a87ddd..13c882676f 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" @@ -2644,3 +2645,38 @@ void hmp_virtio_queue_element(Monitor *mon, const QD= ict *qdict) =20 qapi_free_VirtioQueueElement(e); } + +void hmp_info_cryptodev(Monitor *mon, const QDict *qdict) +{ + CryptodevInfoList *il; + QCryptodevBackendServiceTypeList *sl; + CryptodevBackendClientList *cl; + + for (il =3D qmp_query_cryptodev(NULL); il; il =3D il->next) { + g_autofree char *services =3D NULL; + CryptodevInfo *info =3D il->value; + char *tmp_services; + + /* build a string like 'service=3D[akcipher|mac|hash|cipher]' */ + for (sl =3D info->service; sl; sl =3D sl->next) { + const char *service =3D QCryptodevBackendServiceType_str(sl->v= alue); + + if (!services) { + services =3D g_strdup(service); + } else { + tmp_services =3D g_strjoin("|", services, service, NULL); + g_free(services); + services =3D tmp_services; + } + } + monitor_printf(mon, "%s: service=3D[%s]\n", info->id, services); + + for (cl =3D info->client; cl; cl =3D cl->next) { + CryptodevBackendClient *client =3D cl->value; + monitor_printf(mon, " queue %ld: type=3D%s\n", client->queu= e, + QCryptodevBackendType_str(client->type)); + } + } + + qapi_free_CryptodevInfoList(il); +} --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674115223; cv=none; d=zohomail.com; s=zohoarc; b=CKoEFtHZlAlMz72KSxT5q4adA/bIMsN+r7/v2MSkbBpowqGypoH/k2fV5JMb5KISDL6W8/zGezmOZ3qwu0ku07aU+YPUF8FhqZRDRjtpjr6DSkLwYdVWWte8QvjUORzgb9u7zTx3iY2Eepb2mr+5tbVXt/BYnMgCdnatUvN1pf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674115223; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Jdzw9QZCIXk+mAQ/QLSP7hBtgxJtl4K9TWjsbz+lY+0=; b=T8EWoVCksHA2TMZkqk0pY1rg79gUFOywEkr6YkVEVN7hjnn02FJ7HA5b4ag5+agzAyVFqLXwnqDC0bhGMzDfDA/+0PJbYD4uybI68Z5axRrUQp3etEIyNooDiwmMpFZNcDXj0CIA5y/jnubS7vNpr9n1kN6ewV/jMZC5k+eZB4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674115222982784.9795136601809; Thu, 19 Jan 2023 00:00:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8S-0006AE-0m; Thu, 19 Jan 2023 02:14:56 -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 1pIP8Q-00069P-3S for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:54 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8O-0002FT-7j for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:53 -0500 Received: by mail-pl1-x62c.google.com with SMTP id 20so1524192plo.3 for ; Wed, 18 Jan 2023 23:14:51 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Jdzw9QZCIXk+mAQ/QLSP7hBtgxJtl4K9TWjsbz+lY+0=; b=wpIZ/wBkbec43S1+Sd4TZ5b/Tqv69dL29Syv4ilJGN/RjLwR2RsqFRZLM6b/0mjYUq x9qMwYR3wHBZNS1eGw2DRmLHNZ3Zc9nWtDJC4CW/weD7G0ZqjjPGarQOJ7WVYMv1f8g1 cq+9vtXNeqdWcE5bBmLCZlqwVBTlERdk5nYAHzbfWQJnrqhNe9ANUW1nITd43d+WDe+5 0ndnWh9qph7EVU4IXA8WaIM4b61TzXfcbvkUbYIQKU4oNe0Inq01LOYQi8Rx0zmP0LD1 VcDEGAJeJWOs0wk09mkLR8B/1oFdTHr4IwhssPgknA99ROeON7vntJyQGoe2WmXIOKhF vCaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jdzw9QZCIXk+mAQ/QLSP7hBtgxJtl4K9TWjsbz+lY+0=; b=KivZq1ifrc9WGLX/HjUR0xHDgsFTXgtbqcgOCNovdFJiahSLlEZiLdZvbs/RkCx8yi UHQ8qwJXex3Bojah1KOlMvPf6uvWBEb4LTOqXJMfFLWMC++nUKpwUBMa6vg+RbJDPbJE j2z3sXQNJ91BW2Ym5gcrA/7ZTknK+K5faVEjzw62IeTPAnhcGLK7g+fc4nnHePg1mCh9 /HJUCLfYWz+ZEHqoLvKXbS7CkMbl1WB8cz6B2lW8jiBzZMvWDXBsdbcpQ1P4gOfnCI85 idPA6LldOe1viRqUYy7rXLfTa456yWyivIVSaRnVBS0Yhbl5bFPUoyUXvXJIhISXbDU1 yiXw== X-Gm-Message-State: AFqh2kraRQFtNu8lDR9tZt7gZDuZV9+eV1LJZIg8TVszuHS8BVMb+nhK b2Hg+moZb+YQyAIpsHfIwWIRTw== X-Google-Smtp-Source: AMrXdXt7jIlS5GcR7KMqKmonaBEn0qK0eugj5TLIpqnzrGTgbsgqc8pO8+05Z6LJvb4/L880+i24WA== X-Received: by 2002:a17:902:d543:b0:189:ea22:6d6a with SMTP id z3-20020a170902d54300b00189ea226d6amr11438427plf.60.1674112491599; Wed, 18 Jan 2023 23:14:51 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 08/12] cryptodev: Use CryptoDevBackendOpInfo for operation Date: Thu, 19 Jan 2023 15:14:15 +0800 Message-Id: <20230119071419.3585771-9-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674115224627100002 Content-Type: text/plain; charset="utf-8" Move queue_index, CryptoDevCompletionFunc and opaque into struct CryptoDevBackendOpInfo, then cryptodev_backend_crypto_operation() needs an argument CryptoDevBackendOpInfo *op_info only. And remove VirtIOCryptoReq from cryptodev. It's also possible to hide VirtIOCryptoReq into virtio-crypto.c in the next step. (In theory, VirtIOCryptoReq is a private structure used by virtio-crypto only) Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 9 +++------ backends/cryptodev-lkcf.c | 9 +++------ backends/cryptodev.c | 18 +++++------------- hw/virtio/virtio-crypto.c | 7 ++++--- include/sysemu/cryptodev.h | 26 ++++++++++---------------- 5 files changed, 25 insertions(+), 44 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index c45b5906c5..39d0455280 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -539,10 +539,7 @@ static int cryptodev_builtin_asym_operation( =20 static int cryptodev_builtin_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendBuiltin *builtin =3D CRYPTODEV_BACKEND_BUILTIN(backend); @@ -574,8 +571,8 @@ static int cryptodev_builtin_operation( if (local_error) { error_report_err(local_error); } - if (cb) { - cb(opaque, status); + if (op_info->cb) { + op_info->cb(op_info->opaque, status); } return 0; } diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index edec99f104..45aba1ff67 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -469,10 +469,7 @@ static void *cryptodev_lkcf_worker(void *arg) =20 static int cryptodev_lkcf_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendLKCF *lkcf =3D CRYPTODEV_BACKEND_LKCF(backend); @@ -495,8 +492,8 @@ static int cryptodev_lkcf_operation( =20 task =3D g_new0(CryptoDevLKCFTask, 1); task->op_info =3D op_info; - task->cb =3D cb; - task->opaque =3D opaque; + task->cb =3D op_info->cb; + task->opaque =3D op_info->opaque; task->sess =3D sess; task->lkcf =3D lkcf; task->status =3D -VIRTIO_CRYPTO_ERR; diff --git a/backends/cryptodev.c b/backends/cryptodev.c index d51eeb5ee4..b15b1a24f5 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -143,29 +143,22 @@ int cryptodev_backend_close_session( =20 static int cryptodev_backend_operation( CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque) + CryptoDevBackendOpInfo *op_info) { CryptoDevBackendClass *bc =3D CRYPTODEV_BACKEND_GET_CLASS(backend); =20 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; } =20 int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, - void *opaque1, - uint32_t queue_index, - CryptoDevCompletionFunc cb, void *opaque2) + CryptoDevBackendOpInfo *op_info) { - VirtIOCryptoReq *req =3D opaque1; - CryptoDevBackendOpInfo *op_info =3D &req->op_info; - QCryptodevBackendAlgType algtype =3D req->flags; + QCryptodevBackendAlgType algtype =3D op_info->algtype; =20 if ((algtype !=3D QCRYPTODEV_BACKEND_ALG_SYM) && (algtype !=3D QCRYPTODEV_BACKEND_ALG_ASYM)) { @@ -173,8 +166,7 @@ int cryptodev_backend_crypto_operation( return -VIRTIO_CRYPTO_NOTSUPP; } =20 - return cryptodev_backend_operation(backend, op_info, queue_index, - cb, opaque2); + return cryptodev_backend_operation(backend, op_info); } =20 static void diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index e4f0de4d1c..802e1b9659 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -871,6 +871,9 @@ virtio_crypto_handle_request(VirtIOCryptoReq *request) opcode =3D ldl_le_p(&req.header.opcode); op_info->session_id =3D ldq_le_p(&req.header.session_id); op_info->op_code =3D opcode; + op_info->queue_index =3D queue_index; + op_info->cb =3D virtio_crypto_req_complete; + op_info->opaque =3D request; =20 switch (opcode) { case VIRTIO_CRYPTO_CIPHER_ENCRYPT: @@ -898,9 +901,7 @@ check_result: virtio_crypto_req_complete(request, -VIRTIO_CRYPTO_NOTSUPP); } else { ret =3D cryptodev_backend_crypto_operation(vcrypto->cryptodev, - request, queue_index, - virtio_crypto_req_complete, - request); + op_info); if (ret < 0) { virtio_crypto_req_complete(request, ret); } diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 16f01dd48a..048a627035 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -174,9 +174,14 @@ typedef struct CryptoDevBackendAsymOpInfo { uint8_t *dst; } CryptoDevBackendAsymOpInfo; =20 +typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); + typedef struct CryptoDevBackendOpInfo { QCryptodevBackendAlgType algtype; uint32_t op_code; + uint32_t queue_index; + CryptoDevCompletionFunc cb; + void *opaque; /* argument for cb */ uint64_t session_id; union { CryptoDevBackendSymOpInfo *sym_op_info; @@ -184,7 +189,6 @@ typedef struct CryptoDevBackendOpInfo { } u; } CryptoDevBackendOpInfo; =20 -typedef void (*CryptoDevCompletionFunc) (void *opaque, int ret); struct CryptoDevBackendClass { ObjectClass parent_class; =20 @@ -204,10 +208,7 @@ struct CryptoDevBackendClass { void *opaque); =20 int (*do_op)(CryptoDevBackend *backend, - CryptoDevBackendOpInfo *op_info, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque); + CryptoDevBackendOpInfo *op_info); }; =20 struct CryptoDevBackendClient { @@ -335,24 +336,17 @@ int cryptodev_backend_close_session( /** * cryptodev_backend_crypto_operation: * @backend: the cryptodev backend object - * @opaque1: pointer to a VirtIOCryptoReq object - * @queue_index: queue index of cryptodev backend client - * @errp: pointer to a NULL-initialized error object - * @cb: callbacks when operation is completed - * @opaque2: parameter passed to cb + * @op_info: pointer to a CryptoDevBackendOpInfo object * - * Do crypto operation, such as encryption and - * decryption + * Do crypto operation, such as encryption, decryption, signature and + * verification * * Returns: 0 for success and cb will be called when creation is completed, * negative value for error, and cb will not be called. */ int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, - void *opaque1, - uint32_t queue_index, - CryptoDevCompletionFunc cb, - void *opaque2); + CryptoDevBackendOpInfo *op_info); =20 /** * cryptodev_backend_set_used: --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674118137; cv=none; d=zohomail.com; s=zohoarc; b=ZqFfrGcgZClcE2OP8c9rubAN5rrYV/dzuaC8WLbUsJ6s+xux+QSyZUqk0dV+hzBbNTDVvQXpNrlShT2YQiEFFY/81N0+V9mE/ag7U4ZQjO9VVaUUwBxdz4NC1M0wnIRMvUQXjRfj1C9uugJKFDMa3Oc/0Auus3vbgj0bxgroHZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674118137; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CZSuifELk3Va4o8yDu4MXRSk8LKQ9sH66poU+fCNP+U=; b=KU1dGFIYTrDewLcltWUJcLm3RPpt3CxALMU1gGnSW3vRbadHUcM6m4n2Sv/EZz7gcmmn/W1moPUCZZhzklAQPv578U9pox+GU3pf6P1snsPcxJBCV8E7AtocQlruketLcGmt99JH8NCWJsZ3DIaoC3V8VlUajeUqvtqZJ9Q8Ats= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674118137919939.3654894227651; Thu, 19 Jan 2023 00:48:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8c-0006HO-Jj; Thu, 19 Jan 2023 02:15:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIP8U-0006BT-TO for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:58 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8S-0002HE-CV for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:14:57 -0500 Received: by mail-pl1-x62a.google.com with SMTP id g23so1472881plq.12 for ; Wed, 18 Jan 2023 23:14:56 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14:54 -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=CZSuifELk3Va4o8yDu4MXRSk8LKQ9sH66poU+fCNP+U=; b=Fi/qvwlvdEr2URqOwaesocDhpYvQN5m0FpgwaSY78RDfxXLsIwc3PVcHtWc7ZxcieG UnG4TWEnsfXu/wSluFGDDpKvLZLQjV9SLidSSLNPXnxxPTV1Nl03NdOp+DBIG1qBYFyd aaRWdmOCL3B6CH3tlN9mKvRH3sGE9hRCqUmpUVdWOrvZ0eFsVJU17T6IEzl11iUFmBla 5E+GETBsnCH4u1SpSqTMxxcBCGJ21H8o907yK+GNyxbMRA+Y9KBXOtlLv/m4lS3I2kaE zhXdi9lU6765+z+EMcqMO6DCNCybzl0wQO5V5asyF1WXDO61xCPHQ3to2rBgaF4iJI7H ufvg== 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=CZSuifELk3Va4o8yDu4MXRSk8LKQ9sH66poU+fCNP+U=; b=agxhNkVJSKwHtq0/oWPihoLzYstmJ3esFNiBoyVxNmK80zRqCjkYdom59mZb9wwGkX 2Izbg3EH4I4EqiwZZEwRV83a05ESqGW4l0LBPaxZsZbEQ14OG0iWAHR03Gfy55Btz01f 2Oahr53s/s+fhxMdHfzFDAJpSj9bm/fHRxnOC5E62uWdzmF7Q2NRKJy0BCtCEEIS7BHE vUz7JQ83J5UpRwns0QgzHK4AfwzmPKdXWszZlze2PMck1krzkBhmnlTn479pnB+GtITU WYyAHyknZOhLOA4C6p+H82il8X1C11JEBCxY46wcsvNIpJX4NLQ2bT66dUi17Ns63pKy ISRw== X-Gm-Message-State: AFqh2kqNbAqPix40etLbEA1Q6CA4qwq+VlUWKdo9Q0qns3vhZFp48zSA JH5RuljayKt06Vlr2qQaQ2IGDQ== X-Google-Smtp-Source: AMrXdXuAUEfAWCFroa9s2VTHXzV4kSLkdJdI9UJRJUMnMEY4ddyb5cNwiEsGWnyy43oZqnClX9Zgow== X-Received: by 2002:a17:903:3285:b0:194:5e49:d941 with SMTP id jh5-20020a170903328500b001945e49d941mr10349945plb.47.1674112494785; Wed, 18 Jan 2023 23:14:54 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 09/12] cryptodev: Account statistics Date: Thu, 19 Jan 2023 15:14:16 +0800 Message-Id: <20230119071419.3585771-10-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62a.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674118140900100003 Content-Type: text/plain; charset="utf-8" Account OPS/BPS for crypto device, this will be used for 'query-stats' QEMU monitor command and QoS in the next step. Note that a crypto device may support symmetric mode, asymmetric mode, both symmetric and asymmetric mode. So we use two structure to describe the statistics of a crypto device. Signed-off-by: zhenwei pi --- backends/cryptodev.c | 68 +++++++++++++++++++++++++++++++++++--- include/sysemu/cryptodev.h | 31 +++++++++++++++++ qapi/cryptodev.json | 54 ++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 5 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index b15b1a24f5..9c8ba6f29f 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -107,6 +107,9 @@ void cryptodev_backend_cleanup( if (bc->cleanup) { bc->cleanup(backend, errp); } + + g_free(backend->sym_stat); + g_free(backend->asym_stat); } =20 int cryptodev_backend_create_session( @@ -154,16 +157,61 @@ static int cryptodev_backend_operation( return -VIRTIO_CRYPTO_NOTSUPP; } =20 +static int cryptodev_backend_account(CryptoDevBackend *backend, + CryptoDevBackendOpInfo *op_info) +{ + enum QCryptodevBackendAlgType algtype =3D op_info->algtype; + int len; + + if (algtype =3D=3D QCRYPTODEV_BACKEND_ALG_ASYM) { + CryptoDevBackendAsymOpInfo *asym_op_info =3D op_info->u.asym_op_in= fo; + len =3D 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 =3D=3D QCRYPTODEV_BACKEND_ALG_SYM) { + CryptoDevBackendSymOpInfo *sym_op_info =3D op_info->u.sym_op_info; + len =3D 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 "", algtyp= e); + return -VIRTIO_CRYPTO_NOTSUPP; + } + + return len; +} + int cryptodev_backend_crypto_operation( CryptoDevBackend *backend, CryptoDevBackendOpInfo *op_info) { - QCryptodevBackendAlgType algtype =3D op_info->algtype; + int ret; =20 - if ((algtype !=3D QCRYPTODEV_BACKEND_ALG_SYM) - && (algtype !=3D QCRYPTODEV_BACKEND_ALG_ASYM)) { - error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtyp= e); - return -VIRTIO_CRYPTO_NOTSUPP; + ret =3D cryptodev_backend_account(backend, op_info); + if (ret < 0) { + return ret; } =20 return cryptodev_backend_operation(backend, op_info); @@ -202,10 +250,20 @@ cryptodev_backend_complete(UserCreatable *uc, Error *= *errp) { CryptoDevBackend *backend =3D CRYPTODEV_BACKEND(uc); CryptoDevBackendClass *bc =3D CRYPTODEV_BACKEND_GET_CLASS(uc); + uint32_t services; =20 if (bc->init) { bc->init(backend, errp); } + + services =3D backend->conf.crypto_services; + if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) { + backend->sym_stat =3D g_new0(QCryptodevBackendSymStat, 1); + } + + if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) { + backend->asym_stat =3D g_new0(QCryptodevBackendAsymStat, 1); + } } =20 void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used) diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 048a627035..15e8c04dcf 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -253,8 +253,39 @@ struct CryptoDevBackend { /* Tag the cryptodev backend is used by virtio-crypto or not */ bool is_used; CryptoDevBackendConf conf; + QCryptodevBackendSymStat *sym_stat; + QCryptodevBackendAsymStat *asym_stat; }; =20 +#define QCryptodevSymStatInc(be, op, bytes) do { \ + be->sym_stat->op##_bytes +=3D (bytes); \ + be->sym_stat->op##_ops +=3D 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 +=3D (bytes); \ + be->asym_stat->op##_ops +=3D 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 6c6509cd3f..dbd8fa71f9 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -87,3 +87,57 @@ # Since: 8.0 ## { 'command': 'query-cryptodev', 'returns': ['CryptodevInfo']} + +## +# @QCryptodevBackendSymStat: +# +# The statistics of symmetric operation. +# +# @encrypt-ops: the operations of symmetric encryption +# +# @decrypt-ops: the operations of symmetric decryption +# +# @encrypt-bytes: the bytes of symmetric encryption +# +# @decrypt-bytes: the bytes of symmetric decryption +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendSymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int' } } + +## +# @QCryptodevBackendAsymStat: +# +# The statistics of asymmetric operation. +# +# @encrypt-ops: the operations of asymmetric encryption +# +# @decrypt-ops: the operations of asymmetric decryption +# +# @sign-ops: the operations of asymmetric signature +# +# @verify-ops: the operations of asymmetric verification +# +# @encrypt-bytes: the bytes of asymmetric encryption +# +# @decrypt-bytes: the bytes of asymmetric decryption +# +# @sign-bytes: the bytes of asymmetric signature +# +# @verify-bytes: the bytes of asymmetric verification +# +# Since: 8.0 +## +{ 'struct': 'QCryptodevBackendAsymStat', + 'data': { 'encrypt-ops': 'int', + 'decrypt-ops': 'int', + 'sign-ops': 'int', + 'verify-ops': 'int', + 'encrypt-bytes': 'int', + 'decrypt-bytes': 'int', + 'sign-bytes': 'int', + 'verify-bytes': 'int' } } --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674117678; cv=none; d=zohomail.com; s=zohoarc; b=W+oqYs4pQElDqWF+oP3FY1jbPCoxVxOHAjEhOpFYIjl9zbNS2fhaG+vVWni8eoO/FH3q195G65Tkkrt8l2IaRw8IxFuupmG6/xkQ33n2Q9ba9hYw4bWXDlPr0bVBsXtWjIwWjuNt498CW17WQA40IZcjtkopMA+dbZnkiHOqWmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674117678; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zksQYXXIDJBPnsRDJDs+M4hEapPR4KCQMDs5uvODmZs=; b=HgCbCH0AzOjbzsZbTy0nkhaES+tZL/LOrpsg1sBemLi+qk47NpqyztS94dpjMqAqpVcit+XCh1wsIujLzLLHq0un8HmD4TBgboI/BJIXES6GlM4wCyvvIZaJ19yGd1ZlnAlDJpXHyCysYa08Hjzz7Vx9Q7e/B6fxZujWZZ4mNNA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674117678153547.0897724394893; Thu, 19 Jan 2023 00:41:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP8o-0006O4-FP; Thu, 19 Jan 2023 02:15:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIP8W-0006GD-HD for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:15:00 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8U-0002GV-Le for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:15:00 -0500 Received: by mail-pj1-x1030.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so1023857pjl.0 for ; Wed, 18 Jan 2023 23:14:58 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:14: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=zksQYXXIDJBPnsRDJDs+M4hEapPR4KCQMDs5uvODmZs=; b=nSLIDHhwfoXOQ5r2W16rg2Qwo+eXzlRu4Lk8oeUIMZ8qE3JUZkUCCKxHJTkF6Yk6ha 79967aMAkow4RgQc203VFn8JXCoxrv7GVptyO5J1gEPNfl4zplOdRU13ofGOQ7N5G2DK 1KkfagflfmtEUgHWSC0936TVc3XzSJDfThl/fzS7hWiM0g3i8w5mVBpMG239EDYCyC/I JHvrcxM9fJj3lylXSpETGpM0Y5QyiukK0le17ssFIKzweTo6iGJZ5b+OeAZHIbws0R2o fW30V9bYfv3N+vdlt0AodT56qxNThpjiKAAZZAbdF888Bg0BzLPsTwe1QNhEBeFEascT mQ1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zksQYXXIDJBPnsRDJDs+M4hEapPR4KCQMDs5uvODmZs=; b=Jpjnc/E+EY8afZHUvsFi624sybtcTxNg/XcuRXua0bl/xVhGDXDe9RLhm01SPyaNKN GXHfJAzrTQpNTcOI6sWmzt6CY0G3bgOgvXlna5dZ+qcQIFX3vLEGIy3miA5yAh6lSdXv 8znme+sk3cxFgCzB4o3UQ7HS5jYNf5y9yg2l4uAPgxX4fSgjd3lpaLZnapuCLjY/QqQ5 kcENSiALgjeC/cs4QAHcF9r7OGUyL+iHJwpsvm6i5nl+zrbnqsXcil1V6aDzmu7iPHku EBlY7O/ICvJdNDxzzAgDVBn1K8Pc11ggIM6LunBY+5zmNFz2z0HIedh5D1hu0Pngif44 un7Q== X-Gm-Message-State: AFqh2kpjuZsfp6HLWSHIKYmWukTHN3C4DaZM1TAAYJ7vaDBiSUPWBllu 47VpxoCwMBc4hqNCRouNyQ8lug== X-Google-Smtp-Source: AMrXdXuv3mUiYxfruK2LHxLGlctoOnJVFiRlFQo2pUukSyHGbcui3TGGtCS1pt/eLGJQEvALPswEhg== X-Received: by 2002:a17:902:744c:b0:186:a43b:a5 with SMTP id e12-20020a170902744c00b00186a43b00a5mr9695171plt.13.1674112497944; Wed, 18 Jan 2023 23:14:57 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 10/12] cryptodev: support QoS Date: Thu, 19 Jan 2023 15:14:17 +0800 Message-Id: <20230119071419.3585771-11-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1030.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674117680738100001 Content-Type: text/plain; charset="utf-8" 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=3Dcryptodev1,throttle-bps=3D1600,\ throttle-ops=3D100 Example of QMP command: virsh qemu-monitor-command buster --hmp qom-set /objects/cryptodev1 \ throttle-ops 100 or cancel limitation: virsh qemu-monitor-command buster --hmp qom-set /objects/cryptodev1 \ throttle-ops 0 Signed-off-by: zhenwei pi --- backends/cryptodev.c | 138 +++++++++++++++++++++++++++++++++++++ include/sysemu/cryptodev.h | 7 ++ qapi/qom.json | 8 ++- 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 9c8ba6f29f..c288d5a016 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -28,6 +28,7 @@ #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "qemu/main-loop.h" #include "qom/object_interfaces.h" #include "hw/virtio/virtio-crypto.h" =20 @@ -203,17 +204,53 @@ static int cryptodev_backend_account(CryptoDevBackend= *backend, return len; } =20 +static void cryptodev_backend_throttle_timer_cb(void *opaque) +{ + CryptoDevBackend *backend =3D (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 =3D 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; =20 + if (!throttle_enabled(&backend->tc)) { + goto do_account; + } + + if (throttle_schedule_timer(&backend->ts, &backend->tt, true) || + !QTAILQ_EMPTY(&backend->opinfos)) { + QTAILQ_INSERT_TAIL(&backend->opinfos, op_info, next); + return 0; + } + +do_account: ret =3D cryptodev_backend_account(backend, op_info); if (ret < 0) { return ret; } =20 + throttle_account(&backend->ts, true, ret); + return cryptodev_backend_operation(backend, op_info); } =20 @@ -245,12 +282,98 @@ cryptodev_backend_set_queues(Object *obj, Visitor *v,= const char *name, backend->conf.peers.queues =3D value; } =20 +static void cryptodev_backend_set_throttle(CryptoDevBackend *backend, int = field, + uint64_t value, Error **errp) +{ + uint64_t orig =3D backend->tc.buckets[field].avg; + bool enabled =3D throttle_enabled(&backend->tc); + + if (orig =3D=3D value) { + return; + } + + backend->tc.buckets[field].avg =3D 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 =3D 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 =3D CRYPTODEV_BACKEND(obj); + uint64_t value =3D 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 =3D CRYPTODEV_BACKEND(obj); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, err= p); +} + +static void cryptodev_backend_get_ops(Object *obj, Visitor *v, const char = *name, + void *opaque, Error **errp) +{ + CryptoDevBackend *backend =3D CRYPTODEV_BACKEND(obj); + uint64_t value =3D 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 =3D CRYPTODEV_BACKEND(obj); + uint64_t value; + + if (!visit_type_uint64(v, name, &value, errp)) { + return; + } + + cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, err= p); +} + static void cryptodev_backend_complete(UserCreatable *uc, Error **errp) { CryptoDevBackend *backend =3D CRYPTODEV_BACKEND(uc); CryptoDevBackendClass *bc =3D CRYPTODEV_BACKEND_GET_CLASS(uc); uint32_t services; + uint64_t value; + + QTAILQ_INIT(&backend->opinfos); + value =3D backend->tc.buckets[THROTTLE_OPS_TOTAL].avg; + cryptodev_backend_set_throttle(backend, THROTTLE_OPS_TOTAL, value, err= p); + value =3D backend->tc.buckets[THROTTLE_BPS_TOTAL].avg; + cryptodev_backend_set_throttle(backend, THROTTLE_BPS_TOTAL, value, err= p); =20 if (bc->init) { bc->init(backend, errp); @@ -294,8 +417,12 @@ cryptodev_backend_can_be_deleted(UserCreatable *uc) =20 static void cryptodev_backend_instance_init(Object *obj) { + CryptoDevBackend *backend =3D CRYPTODEV_BACKEND(obj); + /* Initialize devices' queues property to 1 */ object_property_set_int(obj, "queues", 1, NULL); + + throttle_config_init(&backend->tc); } =20 static void cryptodev_backend_finalize(Object *obj) @@ -303,6 +430,9 @@ static void cryptodev_backend_finalize(Object *obj) CryptoDevBackend *backend =3D CRYPTODEV_BACKEND(obj); =20 cryptodev_backend_cleanup(backend, NULL); + if (throttle_enabled(&backend->tc)) { + throttle_timers_destroy(&backend->tt); + } } =20 static void @@ -318,6 +448,14 @@ cryptodev_backend_class_init(ObjectClass *oc, void *da= ta) 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); } =20 static const TypeInfo cryptodev_backend_info =3D { diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 15e8c04dcf..113eec4caf 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -24,6 +24,7 @@ #define CRYPTODEV_H =20 #include "qemu/queue.h" +#include "qemu/throttle.h" #include "qom/object.h" #include "qapi/qapi-types-cryptodev.h" =20 @@ -187,6 +188,7 @@ typedef struct CryptoDevBackendOpInfo { CryptoDevBackendSymOpInfo *sym_op_info; CryptoDevBackendAsymOpInfo *asym_op_info; } u; + QTAILQ_ENTRY(CryptoDevBackendOpInfo) next; } CryptoDevBackendOpInfo; =20 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; }; =20 #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' } } =20 ## # @CryptodevVhostUserProperties: --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674113559; cv=none; d=zohomail.com; s=zohoarc; b=ipa2HimuKi8FJvADvFzteZCVwWt/5CbtGjfs5Wpf3IaSccvQChDGbtZFI4Lwh05OnTruRx6FW6yiBhRHW4dM2BLgFdkr8s0An+pmJHSNjIYIDKMF9ACr/1+yIplJca9hKvMN0C2U8Dt0SDX683LATmNTv45FAHHQtc7e52xTeZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674113559; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cyy1nzWMbZlwAYAx/5lPDc1+TmEG1YjXx72T7BJvI30=; b=kSNntOnfEvP4SmVdL/ZV+NoAwvjrdHWUfh7iK/y+GKhD1pktJ4vpFXEkaFxzSeYXrWfqgfxkFWPYpYDoXOvZQ7hgdix9IKLkC2vrXreZHdwPuZwGyWh2U8/fNEzO6aOQdsA79HaU43AQRA1X4GajIGJ7nAGIzCOxeY9Nxyx1V4k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674113559046198.77489454406646; Wed, 18 Jan 2023 23:32:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP91-0006f8-Re; Thu, 19 Jan 2023 02:15:31 -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 1pIP8a-0006IH-DC for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:15:06 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8Y-0002Hg-A1 for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:15:04 -0500 Received: by mail-pl1-x62c.google.com with SMTP id p24so1479958plw.11 for ; Wed, 18 Jan 2023 23:15:01 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:15:00 -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=cyy1nzWMbZlwAYAx/5lPDc1+TmEG1YjXx72T7BJvI30=; b=3Bm1tVsc3nf76ymugqR3XuvkD4h4Jiproj/0EOz3Nl7KWZOQGFxa02hqmF2yJvG/2/ CfR30K5fxKt48kiRPIdIornpwEjZibWeX1qwj9OkD+0M2gQfMJNFTihlvxjU+uWmT6Zw r9n/8sy+lQzikV2cqCgWkX6isZVlz5qofUjLV0/j0/R6DWu+/UA07eThrDPMwMGs4/CO RU00r35kMWkDF4tD20HgozrCnAzc4gniCfSLJyz5ctrQC9ftl2V5RTAtWtY2KDYNekx1 mccifCfrK6v5t5dQ7CwOEc8NllLBpfxlIpTscgUJIuev4b3OJmdFR8pQ1eGUYT+S91P6 3kFg== 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=cyy1nzWMbZlwAYAx/5lPDc1+TmEG1YjXx72T7BJvI30=; b=o45nVlybHJ997EEQCMtkB3etXcLoTU1VSUnmxr/Tqe6c6FgbVqrVnpNoc5KrpoR6Ku Ms30TD9UP5izJlZC9BsK6C3b1b/GJ/InJkIj8m2tfqHf1IgqLigGlv/mD7VQgcD9NWeA d8FxCGz5DOkHHwNpteHGWAI2T/pMhQPJwqPLewGZeFG59U+KA6fI0w1Qfp3oexUoHNSq bkmtCKw0i19HttgY+H0QyQq7WvC49xJ/vlEHWazPVBryTMKIb0hDK2PVbAOjexykuv4e 4jk7406b8QzxfmKpyWv9uSVigkK3o9YNXzN5CpyU741YB091JFipIMMOGoDDTfw+QV6e BVBw== X-Gm-Message-State: AFqh2kpIJCs7c6MxnlwNNRV8wG8exT+t12acmpa4eXwlNYPkzGpFz7Xo Lr6CxEHVnyDA7SmcABSeWfy6zg== X-Google-Smtp-Source: AMrXdXvH0AHpOnPOofryqmoQv3mE5IpGttRiwCkLF90thdnvI4SG7SjIPWANzBhmhSOA9WEokRnLhA== X-Received: by 2002:a17:902:8688:b0:194:77d3:627f with SMTP id g8-20020a170902868800b0019477d3627fmr9318302plo.69.1674112501148; Wed, 18 Jan 2023 23:15:01 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 11/12] cryptodev: Support query-stats QMP command Date: Thu, 19 Jan 2023 15:14:18 +0800 Message-Id: <20230119071419.3585771-12-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pizhenwei@bytedance.com; helo=mail-pl1-x62c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674113560755100003 Now we can use "query-stats" QMP command to query statistics of crypto devices. (Originally this was designed to show statistics by '{"execute": "query-cryptodev"}'. Daniel Berrang=C3=A9 suggested that querying configuration info by "query-cryptodev", and querying runtime performance info by "query-stats". This makes sense!) Example: ~# virsh qemu-monitor-command vm '{"execute": "query-stats", \ "arguments": {"target": "cryptodev"} }' | jq { "return": [ { "provider": "cryptodev", "stats": [ { "name": "asym-verify-bytes", "value": 7680 }, ... { "name": "asym-decrypt-ops", "value": 32 }, { "name": "asym-encrypt-ops", "value": 48 } ], "qom-path": "/objects/cryptodev0" # support asym only }, { "provider": "cryptodev", "stats": [ { "name": "asym-verify-bytes", "value": 0 }, ... { "name": "sym-decrypt-bytes", "value": 5376 }, ... ], "qom-path": "/objects/cryptodev1" # support asym/sym } ], "id": "libvirt-422" } Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: zhenwei pi --- backends/cryptodev.c | 141 +++++++++++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 5 ++ monitor/qmp-cmds.c | 2 + qapi/stats.json | 10 ++- 4 files changed, 156 insertions(+), 2 deletions(-) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index c288d5a016..051e13ea5b 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -22,9 +22,11 @@ */ =20 #include "qemu/osdep.h" +#include "monitor/stats.h" #include "sysemu/cryptodev.h" #include "qapi/error.h" #include "qapi/qapi-commands-cryptodev.h" +#include "qapi/qapi-types-stats.h" #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -32,6 +34,14 @@ #include "qom/object_interfaces.h" #include "hw/virtio/virtio-crypto.h" =20 +typedef struct StatsArgs { + union StatsResultsType { + StatsResultList **stats; + StatsSchemaList **schema; + } result; + strList *names; + Error **errp; +} StatsArgs; =20 static QTAILQ_HEAD(, CryptoDevBackendClient) crypto_clients; =20 @@ -435,6 +445,134 @@ static void cryptodev_backend_finalize(Object *obj) } } =20 +static StatsList *cryptodev_backend_stats_add(const char *name, int64_t *v= al, + StatsList *stats_list) +{ + Stats *stats =3D g_new0(Stats, 1); + + stats->name =3D g_strdup(name); + stats->value =3D g_new0(StatsValue, 1); + stats->value->type =3D QTYPE_QNUM; + stats->value->u.scalar =3D *val; + + QAPI_LIST_PREPEND(stats_list, stats); + return stats_list; +} + +static int cryptodev_backend_stats_query(Object *obj, void *data) +{ + StatsArgs *stats_args =3D data; + StatsResultList **stats_results =3D stats_args->result.stats; + StatsList *stats_list =3D NULL; + StatsResult *entry; + CryptoDevBackend *backend; + QCryptodevBackendSymStat *sym_stat; + QCryptodevBackendAsymStat *asym_stat; + + if (!object_dynamic_cast(obj, TYPE_CRYPTODEV_BACKEND)) { + return 0; + } + + backend =3D CRYPTODEV_BACKEND(obj); + sym_stat =3D backend->sym_stat; + if (sym_stat) { + stats_list =3D cryptodev_backend_stats_add("sym-encrypt-ops", + &sym_stat->encrypt_ops, stats_list); + stats_list =3D cryptodev_backend_stats_add("sym-decrypt-ops", + &sym_stat->decrypt_ops, stats_list); + stats_list =3D cryptodev_backend_stats_add("sym-encrypt-bytes", + &sym_stat->encrypt_bytes, stats_list); + stats_list =3D cryptodev_backend_stats_add("sym-decrypt-bytes", + &sym_stat->decrypt_bytes, stats_list); + } + + asym_stat =3D backend->asym_stat; + if (asym_stat) { + stats_list =3D cryptodev_backend_stats_add("asym-encrypt-ops", + &asym_stat->encrypt_ops, stats_list); + stats_list =3D cryptodev_backend_stats_add("asym-decrypt-ops", + &asym_stat->decrypt_ops, stats_list); + stats_list =3D cryptodev_backend_stats_add("asym-sign-ops", + &asym_stat->sign_ops, stats_list); + stats_list =3D cryptodev_backend_stats_add("asym-verify-ops", + &asym_stat->verify_ops, stats_list); + stats_list =3D cryptodev_backend_stats_add("asym-encrypt-bytes", + &asym_stat->encrypt_bytes, stats_list); + stats_list =3D cryptodev_backend_stats_add("asym-decrypt-bytes", + &asym_stat->decrypt_bytes, stats_list); + stats_list =3D cryptodev_backend_stats_add("asym-sign-bytes", + &asym_stat->sign_bytes, stats_list); + stats_list =3D cryptodev_backend_stats_add("asym-verify-bytes", + &asym_stat->verify_bytes, stats_list); + } + + entry =3D g_new0(StatsResult, 1); + entry->provider =3D STATS_PROVIDER_CRYPTODEV; + entry->qom_path =3D g_strdup(object_get_canonical_path(obj)); + entry->stats =3D stats_list; + QAPI_LIST_PREPEND(*stats_results, entry); + + return 0; +} + +static void cryptodev_backend_stats_cb(StatsResultList **result, + StatsTarget target, + strList *names, strList *targets, + Error **errp) +{ + switch (target) { + case STATS_TARGET_CRYPTODEV: + { + Object *objs =3D container_get(object_get_root(), "/objects"); + StatsArgs stats_args; + stats_args.result.stats =3D result; + stats_args.names =3D names; + stats_args.errp =3D errp; + + object_child_foreach(objs, cryptodev_backend_stats_query, &stats_a= rgs); + break; + } + default: + break; + } +} + +static StatsSchemaValueList *cryptodev_backend_schemas_add(const char *nam= e, + StatsSchemaValueList *list) +{ + StatsSchemaValueList *schema_entry =3D g_new0(StatsSchemaValueList, 1); + + schema_entry->value =3D g_new0(StatsSchemaValue, 1); + schema_entry->value->type =3D STATS_TYPE_CUMULATIVE; + schema_entry->value->name =3D g_strdup(name); + schema_entry->next =3D list; + + return schema_entry; +} + +static void cryptodev_backend_schemas_cb(StatsSchemaList **result, + Error **errp) +{ + StatsSchemaValueList *stats_list =3D NULL; + const char *sym_stats[] =3D {"sym-encrypt-ops", "sym-decrypt-ops", + "sym-encrypt-bytes", "sym-decrypt-bytes"}; + const char *asym_stats[] =3D {"asym-encrypt-ops", "asym-decrypt-ops", + "asym-sign-ops", "asym-verify-ops", + "asym-encrypt-bytes", "asym-decrypt-bytes", + "asym-sign-bytes", "asym-verify-bytes"}; + + for (int i =3D 0; i < ARRAY_SIZE(sym_stats); i++) { + stats_list =3D cryptodev_backend_schemas_add(sym_stats[i], stats_l= ist); + } + + for (int i =3D 0; i < ARRAY_SIZE(asym_stats); i++) { + stats_list =3D cryptodev_backend_schemas_add(asym_stats[i], stats_= list); + } + + add_stats_schema(result, STATS_PROVIDER_CRYPTODEV, STATS_TARGET_CRYPTO= DEV, + stats_list); +} + static void cryptodev_backend_class_init(ObjectClass *oc, void *data) { @@ -456,6 +594,9 @@ cryptodev_backend_class_init(ObjectClass *oc, void *dat= a) cryptodev_backend_get_ops, cryptodev_backend_set_ops, NULL, NULL); + + add_stats_callbacks(STATS_PROVIDER_CRYPTODEV, cryptodev_backend_stats_= cb, + cryptodev_backend_schemas_cb); } =20 static const TypeInfo cryptodev_backend_info =3D { diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 13c882676f..41f569f736 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -2247,6 +2247,8 @@ static StatsFilter *stats_filter(StatsTarget target, = const char *names, filter->u.vcpu.vcpus =3D vcpu_list; break; } + case STATS_TARGET_CRYPTODEV: + break; default: break; } @@ -2318,6 +2320,9 @@ void hmp_info_stats(Monitor *mon, const QDict *qdict) int cpu_index =3D monitor_get_cpu_index(mon); filter =3D stats_filter(target, names, cpu_index, provider); break; + case STATS_TARGET_CRYPTODEV: + filter =3D stats_filter(target, names, -1, provider); + break; default: abort(); } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 2932b3f3a5..4ab07ca9e5 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -496,6 +496,8 @@ static bool invoke_stats_cb(StatsCallbacks *entry, targets =3D filter->u.vcpu.vcpus; } break; + case STATS_TARGET_CRYPTODEV: + break; default: abort(); } diff --git a/qapi/stats.json b/qapi/stats.json index 57db5b1c74..f9dec18066 100644 --- a/qapi/stats.json +++ b/qapi/stats.json @@ -50,10 +50,14 @@ # # Enumeration of statistics providers. # +# @kvm: since 7.1 +# +# @cryptodev: since 8.0 +# # Since: 7.1 ## { 'enum': 'StatsProvider', - 'data': [ 'kvm' ] } + 'data': [ 'kvm', 'cryptodev' ] } =20 ## # @StatsTarget: @@ -65,10 +69,12 @@ # # @vcpu: statistics that apply to a single virtual CPU. # +# @cryptodev: statistics that apply to a crypto device. +# # Since: 7.1 ## { 'enum': 'StatsTarget', - 'data': [ 'vm', 'vcpu' ] } + 'data': [ 'vm', 'vcpu', 'cryptodev' ] } =20 ## # @StatsRequest: --=20 2.34.1 From nobody Sat May 18 10:08:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1674119991; cv=none; d=zohomail.com; s=zohoarc; b=cd94flYqi6ON9fShOMmXZr7hI57Oe4GWQrex4dZWhLtBpO2jnlY3Y7+V0DrIz54Oca5jSSKaMte2kIhWiDfGkOX5LD5fBPXfQUEozi7yceJpHMg2bHilkvWVofLr1iEeABmXC8VNQhOMAhR6lnTZr8jdZJa+WOQjR6+cC5eDW5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674119991; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sJQjtNov5mk1r72UjvpVU8akaXUCzzt2OYWGCXBa4Pg=; b=XxX0Nba+3Si0AwM9FKU4lri47NcMC+lD/xZY1dt1kyDBwFnGHHtVq4dP6yFk8mYL1h32nAf2zilEFq49ebmTBFFW3lWMTDfx59gKxxT3fNMfIt16Gj3+r7iWEWJZzdLJHTzbn/iqTg2FkBeCUE1B4a3Ay7CxkqUKPQoNe2G1SzI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674119991313305.9158043657395; Thu, 19 Jan 2023 01:19:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIP96-0006wy-Iz; Thu, 19 Jan 2023 02:15:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIP8d-0006Lc-5y for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:15:10 -0500 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pIP8b-0002T8-H1 for qemu-devel@nongnu.org; Thu, 19 Jan 2023 02:15:06 -0500 Received: by mail-pj1-x1036.google.com with SMTP id o7-20020a17090a0a0700b00226c9b82c3aso981664pjo.3 for ; Wed, 18 Jan 2023 23:15:05 -0800 (PST) Received: from always-pc.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id e4-20020a170902ef4400b0016d72804664sm24266631plx.205.2023.01.18.23.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 23:15:03 -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=sJQjtNov5mk1r72UjvpVU8akaXUCzzt2OYWGCXBa4Pg=; b=JBciYpY5MJw+yVi9oUcyQkeAS+QQ4ppkzv0yh4O3lBoQp+nOlKWqK3TxtqwUq0pjWT mgknuI1dvGTcx+C7IBdzuF1uqaNlajWhJVZrwHznr7Al3WPZdjZ2f0VPPhsrC+Skc5c3 H55nseLwA6zN0EY0WwdGeu7EUdGl3VOsGwxA7kuq/PTB2y0njjpGZlRHM6deKf/IV4Zi B8Z9RbztoaYl+GJNEPSMqYbJP1a/9+Y5mRhcjuB8TWZhzb0N/HdGiYTZhIv9DcPhoXtF 9Ka9c3BphkiznLhp4Y33IO4meiBSI6iLrOXfdbZoJEBrh5sONx+rBZ96Hi2pDvFBQrSd ikbA== 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=sJQjtNov5mk1r72UjvpVU8akaXUCzzt2OYWGCXBa4Pg=; b=HiHwG3jdNiNDRyAXCgO6C/NxXYIwTm6nyLCi6sgNjusZZQUR8iITlFUeNUrGn2i1xD /togqaTMuok60nU9HLIocZ5RAspo0dDA5uwTlgyJszAFXn8Vv7i09CQQFtjyTXl83SOP ugs85hgf5J0gtHa8ESenfHrLUG4ck+6nZ253BZqijwphZtlbQov/WFncE2LOgl7GksXa 6z6mPP8cveNEwai/XRwpU+BxVPO23UIRktkcwLi23lOTAwNcHEoogCNCUxHOQ4JwR24G UyKh8MFyp1CNt5VmOTlyDRbo5ytH9mVc0+CJP3RYYxI5OwjyN3JoCGvtiA2DjjivLgbZ sO1A== X-Gm-Message-State: AFqh2kqvsDirda2hJsKwfyoSzR84LNngqpVrKaAQYiaoJJFYq0M0qUP6 jtWdGbVe2JpKLQKZb/q8zUk1s6PJjeuiRN/M X-Google-Smtp-Source: AMrXdXtB4KLaam3H27BUCuH5QPnuU8KTdVpu+cH1nNdWx6CfTahh7TnZJaPEOjtXsP+hoO/hnSvZ5w== X-Received: by 2002:a17:902:7042:b0:189:7548:2096 with SMTP id h2-20020a170902704200b0018975482096mr9511764plt.45.1674112504231; Wed, 18 Jan 2023 23:15:04 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, mst@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com, berrange@redhat.com Cc: armbru@redhat.com, qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH v3 12/12] MAINTAINERS: add myself as the maintainer for cryptodev Date: Thu, 19 Jan 2023 15:14:19 +0800 Message-Id: <20230119071419.3585771-13-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230119071419.3585771-1-pizhenwei@bytedance.com> References: <20230119071419.3585771-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1036.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bytedance-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674119993104100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: zhenwei pi --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 5ec5aebadb..0f8ffe2f64 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2858,6 +2858,7 @@ T: git https://gitlab.com/ehabkost/qemu.git machine-n= ext =20 Cryptodev Backends M: Gonglei +M: zhenwei pi S: Maintained F: include/sysemu/cryptodev*.h F: backends/cryptodev*.c --=20 2.34.1