Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH Crypto 0/2] Fixes issues during driver registration
@ 2020-03-16  6:03 Ayush Sawal
  2020-03-16  6:03 ` [PATCH Crypto 1/2] chcr: Fixes a hang issue " Ayush Sawal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ayush Sawal @ 2020-03-16  6:03 UTC (permalink / raw)
  To: herbert, linux-crypto; +Cc: manojmalviya, Ayush Sawal

Patch 1: Avoid the accessing of wrong u_ctx pointer.
Patch 2: Fixes a deadlock between rtnl_lock and uld_mutex.

Ayush Sawal (2):
  chcr: Fixes a hang issue during driver registration
  chcr: Fixes a deadlock between rtnl_lock and uld_mutex

 drivers/crypto/chelsio/chcr_core.c  | 34 +++++++++++++++++++++++------
 drivers/crypto/chelsio/chcr_ipsec.c |  2 --
 2 files changed, 27 insertions(+), 9 deletions(-)

-- 
2.26.0.rc1.11.g30e9940


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH Crypto 1/2] chcr: Fixes a hang issue during driver registration
  2020-03-16  6:03 [PATCH Crypto 0/2] Fixes issues during driver registration Ayush Sawal
@ 2020-03-16  6:03 ` Ayush Sawal
  2020-03-16  6:03 ` [PATCH Crypto 2/2] chcr: Fixes a deadlock between rtnl_lock and uld_mutex Ayush Sawal
  2020-03-27  4:54 ` [PATCH Crypto 0/2] Fixes issues during driver registration Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Ayush Sawal @ 2020-03-16  6:03 UTC (permalink / raw)
  To: herbert, linux-crypto; +Cc: manojmalviya, Ayush Sawal

This issue occurs only when multiadapters are present.Hang
happens because assign_chcr_device returns u_ctx pointer of
adapter which is not yet initialized as for this adapter cxgb_up
is not been called yet.

The last_dev pointer is used to determine u_ctx pointer and it
is initialized two times in chcr_uld_add in chcr_dev_add respectively.

The fix here is don't initialize the last_dev pointer during
chcr_uld_add. Only assign to value to it when the adapter's
initialization is completed i.e in chcr_dev_add.

Fixes: fef4912b66d62 ("crypto: chelsio - Handle PCI shutdown event")
Signed-off-by: Ayush Sawal <ayush.sawal@chelsio.com>
---
 drivers/crypto/chelsio/chcr_core.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_core.c b/drivers/crypto/chelsio/chcr_core.c
index 6e02254c007a..850a3f4e837b 100644
--- a/drivers/crypto/chelsio/chcr_core.c
+++ b/drivers/crypto/chelsio/chcr_core.c
@@ -125,8 +125,6 @@ static void chcr_dev_init(struct uld_ctx *u_ctx)
 	atomic_set(&dev->inflight, 0);
 	mutex_lock(&drv_data.drv_mutex);
 	list_add_tail(&u_ctx->entry, &drv_data.inact_dev);
-	if (!drv_data.last_dev)
-		drv_data.last_dev = u_ctx;
 	mutex_unlock(&drv_data.drv_mutex);
 }
 
-- 
2.26.0.rc1.11.g30e9940


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH Crypto 2/2] chcr: Fixes a deadlock between rtnl_lock and uld_mutex
  2020-03-16  6:03 [PATCH Crypto 0/2] Fixes issues during driver registration Ayush Sawal
  2020-03-16  6:03 ` [PATCH Crypto 1/2] chcr: Fixes a hang issue " Ayush Sawal
@ 2020-03-16  6:03 ` Ayush Sawal
  2020-03-27  4:54 ` [PATCH Crypto 0/2] Fixes issues during driver registration Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Ayush Sawal @ 2020-03-16  6:03 UTC (permalink / raw)
  To: herbert, linux-crypto; +Cc: manojmalviya, Ayush Sawal

The locks are taken in this order during driver registration
(uld_mutex), at: cxgb4_register_uld.part.14+0x49/0xd60 [cxgb4]
(rtnl_mutex), at: rtnetlink_rcv_msg+0x2db/0x400
(uld_mutex), at: cxgb_up+0x3a/0x7b0 [cxgb4]
(rtnl_mutex), at: chcr_add_xfrmops+0x83/0xa0 [chcr](stucked here)

To avoid this now the netdev features are updated after the
cxgb4_register_uld is completed.

Fixes: 6dad4e8ab3ec6 ("chcr: Add support for Inline IPSec")
Signed-off-by: Ayush Sawal <ayush.sawal@chelsio.com>
---
 drivers/crypto/chelsio/chcr_core.c  | 32 ++++++++++++++++++++++++-----
 drivers/crypto/chelsio/chcr_ipsec.c |  2 --
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/drivers/crypto/chelsio/chcr_core.c b/drivers/crypto/chelsio/chcr_core.c
index 850a3f4e837b..7e24c4881c34 100644
--- a/drivers/crypto/chelsio/chcr_core.c
+++ b/drivers/crypto/chelsio/chcr_core.c
@@ -37,6 +37,10 @@ static chcr_handler_func work_handlers[NUM_CPL_CMDS] = {
 	[CPL_FW6_PLD] = cpl_fw6_pld_handler,
 };
 
+#ifdef CONFIG_CHELSIO_IPSEC_INLINE
+static void update_netdev_features(void);
+#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
+
 static struct cxgb4_uld_info chcr_uld_info = {
 	.name = DRV_MODULE_NAME,
 	.nrxq = MAX_ULD_QSETS,
@@ -200,10 +204,6 @@ static void *chcr_uld_add(const struct cxgb4_lld_info *lld)
 	}
 	u_ctx->lldi = *lld;
 	chcr_dev_init(u_ctx);
-#ifdef CONFIG_CHELSIO_IPSEC_INLINE
-	if (lld->crypto & ULP_CRYPTO_IPSEC_INLINE)
-		chcr_add_xfrmops(lld);
-#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
 out:
 	return u_ctx;
 }
@@ -281,6 +281,24 @@ static int chcr_uld_state_change(void *handle, enum cxgb4_state state)
 	return ret;
 }
 
+#ifdef CONFIG_CHELSIO_IPSEC_INLINE
+static void update_netdev_features(void)
+{
+	struct uld_ctx *u_ctx, *tmp;
+
+	mutex_lock(&drv_data.drv_mutex);
+	list_for_each_entry_safe(u_ctx, tmp, &drv_data.inact_dev, entry) {
+		if (u_ctx->lldi.crypto & ULP_CRYPTO_IPSEC_INLINE)
+			chcr_add_xfrmops(&u_ctx->lldi);
+	}
+	list_for_each_entry_safe(u_ctx, tmp, &drv_data.act_dev, entry) {
+		if (u_ctx->lldi.crypto & ULP_CRYPTO_IPSEC_INLINE)
+			chcr_add_xfrmops(&u_ctx->lldi);
+	}
+	mutex_unlock(&drv_data.drv_mutex);
+}
+#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
+
 static int __init chcr_crypto_init(void)
 {
 	INIT_LIST_HEAD(&drv_data.act_dev);
@@ -289,7 +307,11 @@ static int __init chcr_crypto_init(void)
 	mutex_init(&drv_data.drv_mutex);
 	drv_data.last_dev = NULL;
 	cxgb4_register_uld(CXGB4_ULD_CRYPTO, &chcr_uld_info);
-
+#ifdef CONFIG_CHELSIO_IPSEC_INLINE
+	rtnl_lock();
+	update_netdev_features();
+	rtnl_unlock();
+#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
 	return 0;
 }
 
diff --git a/drivers/crypto/chelsio/chcr_ipsec.c b/drivers/crypto/chelsio/chcr_ipsec.c
index 9da0f93a330b..9fd3b9d1ec2f 100644
--- a/drivers/crypto/chelsio/chcr_ipsec.c
+++ b/drivers/crypto/chelsio/chcr_ipsec.c
@@ -99,9 +99,7 @@ void chcr_add_xfrmops(const struct cxgb4_lld_info *lld)
 		netdev->xfrmdev_ops = &chcr_xfrmdev_ops;
 		netdev->hw_enc_features |= NETIF_F_HW_ESP;
 		netdev->features |= NETIF_F_HW_ESP;
-		rtnl_lock();
 		netdev_change_features(netdev);
-		rtnl_unlock();
 	}
 }
 
-- 
2.26.0.rc1.11.g30e9940


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH Crypto 0/2] Fixes issues during driver registration
  2020-03-16  6:03 [PATCH Crypto 0/2] Fixes issues during driver registration Ayush Sawal
  2020-03-16  6:03 ` [PATCH Crypto 1/2] chcr: Fixes a hang issue " Ayush Sawal
  2020-03-16  6:03 ` [PATCH Crypto 2/2] chcr: Fixes a deadlock between rtnl_lock and uld_mutex Ayush Sawal
@ 2020-03-27  4:54 ` Herbert Xu
  2 siblings, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2020-03-27  4:54 UTC (permalink / raw)
  To: Ayush Sawal; +Cc: linux-crypto, manojmalviya

On Mon, Mar 16, 2020 at 11:33:16AM +0530, Ayush Sawal wrote:
> Patch 1: Avoid the accessing of wrong u_ctx pointer.
> Patch 2: Fixes a deadlock between rtnl_lock and uld_mutex.
> 
> Ayush Sawal (2):
>   chcr: Fixes a hang issue during driver registration
>   chcr: Fixes a deadlock between rtnl_lock and uld_mutex
> 
>  drivers/crypto/chelsio/chcr_core.c  | 34 +++++++++++++++++++++++------
>  drivers/crypto/chelsio/chcr_ipsec.c |  2 --
>  2 files changed, 27 insertions(+), 9 deletions(-)

All applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16  6:03 [PATCH Crypto 0/2] Fixes issues during driver registration Ayush Sawal
2020-03-16  6:03 ` [PATCH Crypto 1/2] chcr: Fixes a hang issue " Ayush Sawal
2020-03-16  6:03 ` [PATCH Crypto 2/2] chcr: Fixes a deadlock between rtnl_lock and uld_mutex Ayush Sawal
2020-03-27  4:54 ` [PATCH Crypto 0/2] Fixes issues during driver registration Herbert Xu

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git