From 02c4ecb369ecdb0e8fce53efe978acca5129affe Mon Sep 17 00:00:00 2001 From: Akhil R Date: Wed, 5 Jul 2023 10:21:17 +0530 Subject: [PATCH] crypto: tegra-se-nvhost: Use GFP_ATOMIC if in atomic context Check if the request may sleep and adjust the GFP flag. This fixes the issue of sleep during atomic context in tegra-se driver. Bug 4146804 Signed-off-by: Akhil R Change-Id: I40006fd0898a85ced75f49565106a9b47ed0dfd0 Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2931331 Reviewed-by: Laxman Dewangan GVS: Gerrit_Virtual_Submit --- drivers/crypto/tegra-se-nvhost.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/crypto/tegra-se-nvhost.c b/drivers/crypto/tegra-se-nvhost.c index a53966f1..f0cfa052 100644 --- a/drivers/crypto/tegra-se-nvhost.c +++ b/drivers/crypto/tegra-se-nvhost.c @@ -5261,8 +5261,9 @@ static int tegra_se_ccm_compute_auth(struct aead_request *req, bool encrypt) total += ilen; /* 2.2 - Copy adata and map it */ - adata = dma_alloc_coherent(se_dev->dev, assoclen, - &adata_addr, GFP_KERNEL); + adata = dma_alloc_coherent(se_dev->dev, assoclen, &adata_addr, + (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? + GFP_KERNEL : GFP_ATOMIC); num_sgs = tegra_se_count_sgs(sg, assoclen); sg_copy_to_buffer(sg, num_sgs, adata, assoclen); @@ -5461,7 +5462,7 @@ static int tegra_se_ccm_ctr(struct aead_request *req, bool encrypt) * cryptlen case. */ dst_buf = dma_alloc_coherent(se_dev->dev, cryptlen+1, &dst_buf_dma_addr, - GFP_KERNEL); + (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC); if (!dst_buf) return -ENOMEM; @@ -5994,7 +5995,8 @@ static int tegra_se_gcm_op(struct aead_request *req, bool encrypt) * cryptlen case. */ dst_buf = dma_alloc_coherent(se_dev->dev, cryptlen+1, &dst_buf_dma_addr, - GFP_KERNEL); + (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? + GFP_KERNEL : GFP_ATOMIC); if (!dst_buf) return -ENOMEM;