From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id DCBCB1B5AD for ; Wed, 9 Jan 2019 23:56:35 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jan 2019 14:56:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,459,1539673200"; d="scan'208";a="265885222" Received: from silpixa00398673.ir.intel.com (HELO silpixa00398673.ger.corp.intel.com) ([10.237.223.54]) by orsmga004.jf.intel.com with ESMTP; 09 Jan 2019 14:56:31 -0800 From: Fan Zhang To: dev@dpdk.org Cc: akhil.goyal@nxp.com, pablo.de.lara.guarch@intel.com, fiona.trahe@intel.com Date: Wed, 9 Jan 2019 22:56:08 +0000 Message-Id: <20190109225609.20590-12-roy.fan.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190109225609.20590-1-roy.fan.zhang@intel.com> References: <20181221135550.80745-1-roy.fan.zhang@intel.com> <20190109225609.20590-1-roy.fan.zhang@intel.com> Subject: [dpdk-dev] [PATCH v4 11/12] cryptodev: add reference count to session private data X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jan 2019 22:56:36 -0000 This patch adds a refcnt field to every session private data in the cryptodev symmetric session. The counter is used to prevent freeing symmetric session blindly before it is not cleared by every type of crypto device in use. Signed-off-by: Fan Zhang Acked-by: Fiona Trahe --- doc/guides/prog_guide/img/cryptodev_sym_sess.svg | 7 +++++++ doc/guides/rel_notes/release_19_02.rst | 6 ++++++ lib/librte_cryptodev/rte_cryptodev.c | 14 +++++++++----- lib/librte_cryptodev/rte_cryptodev.h | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/doc/guides/prog_guide/img/cryptodev_sym_sess.svg b/doc/guides/prog_guide/img/cryptodev_sym_sess.svg index 20059cc0f..7d7052c38 100644 --- a/doc/guides/prog_guide/img/cryptodev_sym_sess.svg +++ b/doc/guides/prog_guide/img/cryptodev_sym_sess.svg @@ -308,6 +308,13 @@ class="st2" y="189.4823" x="-185.78569">user_data +uint16_t refcnt; dev_ops->sym_session_configure, -ENOTSUP); - if (sess->sess_data[index].data == NULL) { + if (sess->sess_data[index].refcnt == 0) { ret = dev->dev_ops->sym_session_configure(dev, xforms, sess, mp); if (ret < 0) { @@ -1227,6 +1227,7 @@ rte_cryptodev_sym_session_init(uint8_t dev_id, } } + sess->sess_data[index].refcnt++; return 0; } @@ -1372,12 +1373,17 @@ rte_cryptodev_sym_session_clear(uint8_t dev_id, struct rte_cryptodev_sym_session *sess) { struct rte_cryptodev *dev; + uint8_t driver_id; dev = rte_cryptodev_pmd_get_dev(dev_id); if (dev == NULL || sess == NULL) return -EINVAL; + driver_id = dev->driver_id; + if (--sess->sess_data[driver_id].refcnt != 0) + return -EBUSY; + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->sym_session_clear, -ENOTSUP); dev->dev_ops->sym_session_clear(dev, sess); @@ -1407,16 +1413,14 @@ int rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess) { uint8_t i; - void *sess_priv; struct rte_mempool *sess_mp; if (sess == NULL) return -EINVAL; /* Check that all device private data has been freed */ - for (i = 0; i < nb_drivers; i++) { - sess_priv = get_sym_session_private_data(sess, i); - if (sess_priv != NULL) + for (i = 0; i < sess->nb_drivers; i++) { + if (sess->sess_data[i].refcnt != 0) return -EBUSY; } diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h index 4ca7425c6..ec0d1c567 100644 --- a/lib/librte_cryptodev/rte_cryptodev.h +++ b/lib/librte_cryptodev/rte_cryptodev.h @@ -963,6 +963,7 @@ struct rte_cryptodev_sym_session { /**< session user data will be placed after sess_data */ __extension__ struct { void *data; + uint16_t refcnt; } sess_data[0]; /**< Driver specific session material, variable size */ }; -- 2.13.6