From patchwork Thu Dec 22 03:12:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9484189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 23ABA6016C for ; Thu, 22 Dec 2016 03:14:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 184072808C for ; Thu, 22 Dec 2016 03:14:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A64728424; Thu, 22 Dec 2016 03:14:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 76F172808C for ; Thu, 22 Dec 2016 03:14:24 +0000 (UTC) Received: from localhost ([::1]:60177 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cJtpn-0006Mh-En for patchwork-qemu-devel@patchwork.kernel.org; Wed, 21 Dec 2016 22:14:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48225) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cJtpE-0006Kv-ML for qemu-devel@nongnu.org; Wed, 21 Dec 2016 22:13:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cJtpB-0000MO-H9 for qemu-devel@nongnu.org; Wed, 21 Dec 2016 22:13:48 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:48727) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cJtp4-0000F2-2J for qemu-devel@nongnu.org; Wed, 21 Dec 2016 22:13:45 -0500 Received: from 172.24.1.136 (EHLO szxeml422-hub.china.huawei.com) ([172.24.1.136]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DWT72944; Thu, 22 Dec 2016 11:13:03 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml422-hub.china.huawei.com (10.82.67.152) with Microsoft SMTP Server id 14.3.235.1; Thu, 22 Dec 2016 11:12:56 +0800 From: Gonglei To: Date: Thu, 22 Dec 2016 11:12:38 +0800 Message-ID: <1482376362-13804-2-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.8.2.windows.1 In-Reply-To: <1482376362-13804-1-git-send-email-arei.gonglei@huawei.com> References: <1482376362-13804-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH RESEND 1/5] cryptodev: introduce a new is_used property 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: Gonglei , mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This property is used to Tag the cryptodev backend is used by virtio-crypto or not. Making cryptodev can't be hot unplugged when it's in use. Cleanup resources when cryptodev is finalized. Signed-off-by: Gonglei --- backends/cryptodev.c | 19 +++++++++++++++++++ hw/virtio/virtio-crypto.c | 2 ++ include/sysemu/cryptodev.h | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/backends/cryptodev.c b/backends/cryptodev.c index 4a49f97..6a66c27 100644 --- a/backends/cryptodev.c +++ b/backends/cryptodev.c @@ -197,6 +197,22 @@ out: error_propagate(errp, local_err); } +void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used) +{ + backend->is_used = used; +} + +bool cryptodev_backend_is_used(CryptoDevBackend *backend) +{ + return backend->is_used; +} + +static bool +cryptodev_backend_can_be_deleted(UserCreatable *uc, Error **errp) +{ + return !cryptodev_backend_is_used(CRYPTODEV_BACKEND(uc)); +} + static void cryptodev_backend_instance_init(Object *obj) { object_property_add(obj, "queues", "int", @@ -209,7 +225,9 @@ static void cryptodev_backend_instance_init(Object *obj) static void cryptodev_backend_finalize(Object *obj) { + CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj); + cryptodev_backend_cleanup(backend, NULL); } static void @@ -218,6 +236,7 @@ cryptodev_backend_class_init(ObjectClass *oc, void *data) UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); ucc->complete = cryptodev_backend_complete; + ucc->can_be_deleted = cryptodev_backend_can_be_deleted; QTAILQ_INIT(&crypto_clients); } diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index 2f2467e..117f55a 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -799,6 +799,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp) } virtio_crypto_init_config(vdev); + cryptodev_backend_set_used(vcrypto->cryptodev, true); } static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp) @@ -818,6 +819,7 @@ static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp) g_free(vcrypto->vqs); virtio_cleanup(vdev); + cryptodev_backend_set_used(vcrypto->cryptodev, false); } static const VMStateDescription vmstate_virtio_crypto = { diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h index 84526c0..461389d 100644 --- a/include/sysemu/cryptodev.h +++ b/include/sysemu/cryptodev.h @@ -202,6 +202,8 @@ struct CryptoDevBackend { Object parent_obj; bool ready; + /* Tag the cryptodev backend is used by virtio-crypto or not */ + bool is_used; CryptoDevBackendConf conf; }; @@ -295,4 +297,25 @@ int cryptodev_backend_crypto_operation( void *opaque, uint32_t queue_index, Error **errp); +/** + * cryptodev_backend_set_used: + * @backend: the cryptodev backend object + * @used: ture or false + * + * Set the cryptodev backend is used by virtio-crypto or not + */ +void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used); + +/** + * cryptodev_backend_is_used: + * @backend: the cryptodev backend object + * + * Return the status that the cryptodev backend is used + * by virtio-crypto or not + * + * Returns: true on used, or false on not used + */ +bool cryptodev_backend_is_used(CryptoDevBackend *backend); + + #endif /* CRYPTODEV_H */