From nobody Mon Feb 9 14:50:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499151270893948.7451124607841; Mon, 3 Jul 2017 23:54:30 -0700 (PDT) Received: from localhost ([::1]:38921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSHjB-0005FI-FL for importer@patchew.org; Tue, 04 Jul 2017 02:54:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSHZG-00044d-1h for qemu-devel@nongnu.org; Tue, 04 Jul 2017 02:44:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSHZE-00033a-Pg for qemu-devel@nongnu.org; Tue, 04 Jul 2017 02:44:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47180) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dSHZE-00033L-Fw for qemu-devel@nongnu.org; Tue, 04 Jul 2017 02:44:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69DEF7F6A2 for ; Tue, 4 Jul 2017 06:44:11 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-33.pek2.redhat.com [10.72.12.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id D37C660470; Tue, 4 Jul 2017 06:44:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 69DEF7F6A2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 69DEF7F6A2 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 4 Jul 2017 14:43:36 +0800 Message-Id: <20170704064347.7022-10-famz@redhat.com> In-Reply-To: <20170704064347.7022-1-famz@redhat.com> References: <20170704064347.7022-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 04 Jul 2017 06:44:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 09/20] virtio-crypto: Convert to DEFINE_PROP_LINK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Unlike other object_property_add_link() occurrences in virtio devices, virtio-crypto checks the "in use" state of the linked backend object in addition to qdev_prop_allow_set_link_before_realize. To convert it without needing to specialize DEFINE_PROP_LINK which always uses the qdev callback, move the "in use" check to device realize time. Signed-off-by: Fam Zheng --- hw/s390x/virtio-ccw.c | 3 --- hw/virtio/virtio-crypto-pci.c | 2 -- hw/virtio/virtio-crypto.c | 56 +++++++++++++----------------------= ---- include/hw/virtio/virtio-crypto.h | 3 ++- 4 files changed, 21 insertions(+), 43 deletions(-) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index bd4a9ea..dfc55ba 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -1592,9 +1592,6 @@ static void virtio_ccw_crypto_instance_init(Object *o= bj) ccw_dev->force_revision_1 =3D true; virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_CRYPTO); - - object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev), - "cryptodev", &error_abort); } =20 static void virtio_ccw_crypto_class_init(ObjectClass *klass, void *data) diff --git a/hw/virtio/virtio-crypto-pci.c b/hw/virtio/virtio-crypto-pci.c index 422aca3..bf64996 100644 --- a/hw/virtio/virtio-crypto-pci.c +++ b/hw/virtio/virtio-crypto-pci.c @@ -62,8 +62,6 @@ static void virtio_crypto_initfn(Object *obj) =20 virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_CRYPTO); - object_property_add_alias(obj, "cryptodev", OBJECT(&dev->vdev), - "cryptodev", &error_abort); } =20 static const TypeInfo virtio_crypto_pci_info =3D { diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 2590893..0c44fe1 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -753,22 +753,18 @@ static void virtio_crypto_reset(VirtIODevice *vdev) static void virtio_crypto_init_config(VirtIODevice *vdev) { VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(vdev); + CryptoDevBackend *cryptodev =3D CRYPTODEV_BACKEND(vcrypto->conf.crypto= dev); =20 - vcrypto->conf.crypto_services =3D - 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 - vcrypto->conf.cryptodev->conf.cipher_algo_h; - vcrypto->conf.hash_algo =3D vcrypto->conf.cryptodev->conf.hash_algo; - vcrypto->conf.mac_algo_l =3D vcrypto->conf.cryptodev->conf.mac_algo_l; - vcrypto->conf.mac_algo_h =3D vcrypto->conf.cryptodev->conf.mac_algo_h; - vcrypto->conf.aead_algo =3D vcrypto->conf.cryptodev->conf.aead_algo; - vcrypto->conf.max_cipher_key_len =3D - vcrypto->conf.cryptodev->conf.max_cipher_key_len; - vcrypto->conf.max_auth_key_len =3D - vcrypto->conf.cryptodev->conf.max_auth_key_len; - vcrypto->conf.max_size =3D vcrypto->conf.cryptodev->conf.max_size; + vcrypto->conf.crypto_services =3D cryptodev->conf.crypto_services; + vcrypto->conf.cipher_algo_l =3D cryptodev->conf.cipher_algo_l; + vcrypto->conf.cipher_algo_h =3D cryptodev->conf.cipher_algo_h; + vcrypto->conf.hash_algo =3D cryptodev->conf.hash_algo; + vcrypto->conf.mac_algo_l =3D cryptodev->conf.mac_algo_l; + vcrypto->conf.mac_algo_h =3D cryptodev->conf.mac_algo_h; + vcrypto->conf.aead_algo =3D cryptodev->conf.aead_algo; + vcrypto->conf.max_cipher_key_len =3D cryptodev->conf.max_cipher_key_le= n; + vcrypto->conf.max_auth_key_len =3D cryptodev->conf.max_auth_key_len; + vcrypto->conf.max_size =3D cryptodev->conf.max_size; } =20 static void virtio_crypto_device_realize(DeviceState *dev, Error **errp) @@ -776,11 +772,15 @@ static void virtio_crypto_device_realize(DeviceState = *dev, Error **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(dev); int i; - - vcrypto->cryptodev =3D vcrypto->conf.cryptodev; + vcrypto->cryptodev =3D CRYPTODEV_BACKEND(vcrypto->conf.cryptodev); if (vcrypto->cryptodev =3D=3D NULL) { error_setg(errp, "'cryptodev' parameter expects a valid object"); return; + } else if (cryptodev_backend_is_used(vcrypto->cryptodev)) { + char *path =3D object_get_canonical_path_component(vcrypto->conf.c= ryptodev); + error_setg(errp, "can't use already used cryptodev backend: %s", p= ath); + g_free(path); + return; } =20 vcrypto->max_queues =3D MAX(vcrypto->cryptodev->conf.peers.queues, 1); @@ -845,6 +845,8 @@ static const VMStateDescription vmstate_virtio_crypto = =3D { }; =20 static Property virtio_crypto_properties[] =3D { + DEFINE_PROP_LINK("cryptodev", VirtIOCrypto, conf.cryptodev, + TYPE_CRYPTODEV_BACKEND), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -888,20 +890,6 @@ static void virtio_crypto_class_init(ObjectClass *klas= s, void *data) vdc->reset =3D virtio_crypto_reset; } =20 -static void -virtio_crypto_check_cryptodev_is_used(const Object *obj, const char *name, - Object *val, Error **errp) -{ - if (cryptodev_backend_is_used(CRYPTODEV_BACKEND(val))) { - char *path =3D object_get_canonical_path_component(val); - error_setg(errp, - "can't use already used cryptodev backend: %s", path); - g_free(path); - } else { - qdev_prop_allow_set_link_before_realize(obj, name, val, errp); - } -} - static void virtio_crypto_instance_init(Object *obj) { VirtIOCrypto *vcrypto =3D VIRTIO_CRYPTO(obj); @@ -911,12 +899,6 @@ static void virtio_crypto_instance_init(Object *obj) * Can be overriden with virtio_crypto_set_config_size. */ vcrypto->config_size =3D sizeof(struct virtio_crypto_config); - - object_property_add_link(obj, "cryptodev", - TYPE_CRYPTODEV_BACKEND, - (Object **)&vcrypto->conf.cryptodev, - virtio_crypto_check_cryptodev_is_used, - OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL); } =20 static const TypeInfo virtio_crypto_info =3D { diff --git a/include/hw/virtio/virtio-crypto.h b/include/hw/virtio/virtio-c= rypto.h index a00a0bf..d3db159 100644 --- a/include/hw/virtio/virtio-crypto.h +++ b/include/hw/virtio/virtio-crypto.h @@ -38,7 +38,8 @@ do { \ =20 =20 typedef struct VirtIOCryptoConf { - CryptoDevBackend *cryptodev; + /* CryptoDevBackend pointer to be filled by link property */ + Object *cryptodev; =20 /* Supported service mask */ uint32_t crypto_services; --=20 2.9.4