From patchwork Fri Nov 11 06:45:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhenwei pi X-Patchwork-Id: 13039744 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCA3EC433FE for ; Fri, 11 Nov 2022 06:49:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otNp4-0006ZL-PO; Fri, 11 Nov 2022 01:47:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otNoy-0006W7-RB for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:26 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otNow-0008Ek-S0 for qemu-devel@nongnu.org; Fri, 11 Nov 2022 01:47:24 -0500 Received: by mail-pj1-x1032.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so3983366pji.0 for ; Thu, 10 Nov 2022 22:47:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YmrV4HXUD+cr3ZkF2B4NOpr4JL1AftClmiGHOy+sBW8=; b=6YzjxH1gk2p68f8uZ7C7Bi+7W4Gd8LQ+3ppOOfVdzSExCDYUApP15Nr4sUnK8+XDjK YFV9KpazxhsNGeZ92D8FxKP3UNzu8Y7jJtprXVWnuwxZ2Qqs29cIuq46xu/IL4N53bqE 7og7q5yOgOL1WtOG/+NVVmzYAOY1IcCOQItQowWRBJCxbHeKwAmt9kxaYKkttYXT7mYk Zrj7VHHE51L/H1uWa/NpbsST1ZyK4PnO26OltnrZfpuokkfOIlPI1GcJZBHtECBvG1Fr OGajyQ2tawSPmn5Ix9Zg3eZG9whFb71SLIKRc4C/SvbGH3azcVXlg+c83WLLAJBYslCd mi9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YmrV4HXUD+cr3ZkF2B4NOpr4JL1AftClmiGHOy+sBW8=; b=i0iAIZzXWX5B/ps06qjrUAftZT4i4DrPAwm5KLpQUr07UUeBRpMuGWVafZgr/Hv+qF l6xiqVTQ8BpdUbWSzkx3w1J3LDJNTGOvMEc0eTj9Qe2y3FnHY9IXgnK70UoeO+E0em+L v1qRpao4Acgc/uJ0IaEmZ8r2oEESFPqaIZefgVivBM07cwLcdnwidPrfbebu4o7lR9zk g4AJ6gBNRJofZXLT51UMKr+8xI6JVOiCHxqxUC8kI4WmxHwZv7Jl3GNsVnFVpxqaMvVa tYPguf9dJoZGV/mEfe9tHIwPgKSToDcbWyVZnIjwq3oohKG5VT9J3lDc6CmRdNf2qP9u zyvA== X-Gm-Message-State: ANoB5pkxNOXebhPenBIYEXGI35fGp+aTgGLmsRvjBe7JrWYRjrm9g99s l+El130Ehi+dblbQXuDFxHGEIQ== X-Google-Smtp-Source: AA0mqf62DzD7avNc5acIT6P2uWjPxXOJ6GmQNDOAcJeTJl1/rLKCgow7ONZTRplhQ0fv6R/5UWi9Nw== X-Received: by 2002:a17:90b:280b:b0:213:7d3d:a769 with SMTP id qb11-20020a17090b280b00b002137d3da769mr490551pjb.22.1668149239475; Thu, 10 Nov 2022 22:47:19 -0800 (PST) Received: from always-x1.bytedance.net ([63.216.146.186]) by smtp.gmail.com with ESMTPSA id u10-20020a170902e5ca00b0017f64ab80e5sm841022plf.179.2022.11.10.22.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 22:47:19 -0800 (PST) From: zhenwei pi To: arei.gonglei@huawei.com, dgilbert@redhat.com, mst@redhat.com, eblake@redhat.com, armbru@redhat.com, michael.roth@amd.com Cc: qemu-devel@nongnu.org, zhenwei pi Subject: [PATCH for 8.0 4/8] cryptodev: Introduce server type in QAPI Date: Fri, 11 Nov 2022 14:45:49 +0800 Message-Id: <20221111064553.246932-5-pizhenwei@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221111064553.246932-1-pizhenwei@bytedance.com> References: <20221111064553.246932-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=pizhenwei@bytedance.com; helo=mail-pj1-x1032.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Introduce cryptodev service type in cryptodev.json, then apply this to related codes. Now we can remove VIRTIO_CRYPTO_SERVICE_xxx dependence from QEMU cryptodev. Signed-off-by: zhenwei pi --- backends/cryptodev-builtin.c | 8 ++++---- backends/cryptodev-lkcf.c | 2 +- backends/cryptodev-vhost-user.c | 6 +++--- hw/virtio/virtio-crypto.c | 27 +++++++++++++++++++++++++-- qapi/cryptodev.json | 11 +++++++++++ 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c index 5fb7b8f43f..4987abb7d6 100644 --- a/backends/cryptodev-builtin.c +++ b/backends/cryptodev-builtin.c @@ -79,10 +79,10 @@ static void cryptodev_builtin_init( backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_CIPHER | - 1u << VIRTIO_CRYPTO_SERVICE_HASH | - 1u << VIRTIO_CRYPTO_SERVICE_MAC | - 1u << VIRTIO_CRYPTO_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER | + 1u << QCRYPTODEV_BACKEND_SERVICE_HASH | + 1u << QCRYPTODEV_BACKEND_SERVICE_MAC | + 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1; backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; diff --git a/backends/cryptodev-lkcf.c b/backends/cryptodev-lkcf.c index 919bf05b75..31ec712849 100644 --- a/backends/cryptodev-lkcf.c +++ b/backends/cryptodev-lkcf.c @@ -230,7 +230,7 @@ static void cryptodev_lkcf_init(CryptoDevBackend *backend, Error **errp) backend->conf.peers.ccs[0] = cc; backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_AKCIPHER; + 1u << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER; backend->conf.akcipher_algo = 1u << VIRTIO_CRYPTO_AKCIPHER_RSA; lkcf->running = true; diff --git a/backends/cryptodev-vhost-user.c b/backends/cryptodev-vhost-user.c index 580bd1abb0..b1d9eb735f 100644 --- a/backends/cryptodev-vhost-user.c +++ b/backends/cryptodev-vhost-user.c @@ -221,9 +221,9 @@ static void cryptodev_vhost_user_init( cryptodev_vhost_user_event, NULL, s, NULL, true); backend->conf.crypto_services = - 1u << VIRTIO_CRYPTO_SERVICE_CIPHER | - 1u << VIRTIO_CRYPTO_SERVICE_HASH | - 1u << VIRTIO_CRYPTO_SERVICE_MAC; + 1u << QCRYPTODEV_BACKEND_SERVICE_CIPHER | + 1u << QCRYPTODEV_BACKEND_SERVICE_HASH | + 1u << QCRYPTODEV_BACKEND_SERVICE_MAC; backend->conf.cipher_algo_l = 1u << VIRTIO_CRYPTO_CIPHER_AES_CBC; backend->conf.hash_algo = 1u << VIRTIO_CRYPTO_HASH_SHA1; diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index e0a7e2cbd8..87d9582bc1 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -997,12 +997,35 @@ static void virtio_crypto_reset(VirtIODevice *vdev) } } +static uint32_t virtio_crypto_init_services(uint32_t qservices) +{ + uint32_t vservices = 0; + + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_CIPHER); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_HASH)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_HASH); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_MAC)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_MAC); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AEAD)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_AEAD); + } + if (qservices & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) { + vservices |= (1 << VIRTIO_CRYPTO_SERVICE_AKCIPHER); + } + + return vservices; +} + static void virtio_crypto_init_config(VirtIODevice *vdev) { VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev); - vcrypto->conf.crypto_services = - vcrypto->conf.cryptodev->conf.crypto_services; + vcrypto->conf.crypto_services = virtio_crypto_init_services( + vcrypto->conf.cryptodev->conf.crypto_services); vcrypto->conf.cipher_algo_l = vcrypto->conf.cryptodev->conf.cipher_algo_l; vcrypto->conf.cipher_algo_h = diff --git a/qapi/cryptodev.json b/qapi/cryptodev.json index ebb6852035..8732a30524 100644 --- a/qapi/cryptodev.json +++ b/qapi/cryptodev.json @@ -18,6 +18,17 @@ 'prefix': 'QCRYPTODEV_BACKEND_ALG', 'data': ['sym', 'asym']} +## +# @QCryptodevBackendServiceType: +# +# The supported service types of a crypto device. +# +# Since: 8.0 +## +{ 'enum': 'QCryptodevBackendServiceType', + 'prefix': 'QCRYPTODEV_BACKEND_SERVICE', + 'data': ['cipher', 'hash', 'mac', 'aead', 'akcipher']} + ## # @QCryptodevBackendType: #