All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tero Kristo <t-kristo@ti.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
	<linux-crypto@vger.kernel.org>
Cc: <linux-omap@vger.kernel.org>, <ard.biesheuvel@kernel.org>
Subject: [PATCHv2 17/22] crypto: omap-aes-gcm: fix failure with assocdata only
Date: Tue, 5 Nov 2019 16:01:06 +0200	[thread overview]
Message-ID: <20191105140111.20285-18-t-kristo@ti.com> (raw)
In-Reply-To: <20191105140111.20285-1-t-kristo@ti.com>

If we only have assocdata with an omap-aes-gcm, it currently just
completes it directly without passing it over to the crypto HW. This
produces wrong results.

Fix by passing the request down to the crypto HW, and fix the DMA
support code to accept a case where we don't expect any output data.
In the case where only assocdata is provided, it just passes through
the accelerator and provides authentication results, without any
encrypted/decrypted buffer via DMA.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
---
 drivers/crypto/omap-aes-gcm.c |  2 +-
 drivers/crypto/omap-aes.c     | 67 +++++++++++++++++++++--------------
 2 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/drivers/crypto/omap-aes-gcm.c b/drivers/crypto/omap-aes-gcm.c
index 6da05149b195..e92000846f16 100644
--- a/drivers/crypto/omap-aes-gcm.c
+++ b/drivers/crypto/omap-aes-gcm.c
@@ -244,7 +244,7 @@ static int omap_aes_gcm_handle_queue(struct omap_aes_dev *dd,
 
 	err = omap_aes_write_ctrl(dd);
 	if (!err) {
-		if (dd->in_sg_len && dd->out_sg_len)
+		if (dd->in_sg_len)
 			err = omap_aes_crypt_dma_start(dd);
 		else
 			omap_aes_gcm_dma_out_callback(dd);
diff --git a/drivers/crypto/omap-aes.c b/drivers/crypto/omap-aes.c
index d63ab370030e..758c93908fa5 100644
--- a/drivers/crypto/omap-aes.c
+++ b/drivers/crypto/omap-aes.c
@@ -269,13 +269,14 @@ static int omap_aes_crypt_dma(struct omap_aes_dev *dd,
 			      struct scatterlist *out_sg,
 			      int in_sg_len, int out_sg_len)
 {
-	struct dma_async_tx_descriptor *tx_in, *tx_out;
+	struct dma_async_tx_descriptor *tx_in, *tx_out = NULL, *cb_desc;
 	struct dma_slave_config cfg;
 	int ret;
 
 	if (dd->pio_only) {
 		scatterwalk_start(&dd->in_walk, dd->in_sg);
-		scatterwalk_start(&dd->out_walk, dd->out_sg);
+		if (out_sg_len)
+			scatterwalk_start(&dd->out_walk, dd->out_sg);
 
 		/* Enable DATAIN interrupt and let it take
 		   care of the rest */
@@ -312,34 +313,45 @@ static int omap_aes_crypt_dma(struct omap_aes_dev *dd,
 
 	/* No callback necessary */
 	tx_in->callback_param = dd;
+	tx_in->callback = NULL;
 
 	/* OUT */
-	ret = dmaengine_slave_config(dd->dma_lch_out, &cfg);
-	if (ret) {
-		dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n",
-			ret);
-		return ret;
-	}
+	if (out_sg_len) {
+		ret = dmaengine_slave_config(dd->dma_lch_out, &cfg);
+		if (ret) {
+			dev_err(dd->dev, "can't configure OUT dmaengine slave: %d\n",
+				ret);
+			return ret;
+		}
 
-	tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg, out_sg_len,
-					DMA_DEV_TO_MEM,
-					DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
-	if (!tx_out) {
-		dev_err(dd->dev, "OUT prep_slave_sg() failed\n");
-		return -EINVAL;
+		tx_out = dmaengine_prep_slave_sg(dd->dma_lch_out, out_sg,
+						 out_sg_len,
+						 DMA_DEV_TO_MEM,
+						 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+		if (!tx_out) {
+			dev_err(dd->dev, "OUT prep_slave_sg() failed\n");
+			return -EINVAL;
+		}
+
+		cb_desc = tx_out;
+	} else {
+		cb_desc = tx_in;
 	}
 
 	if (dd->flags & FLAGS_GCM)
-		tx_out->callback = omap_aes_gcm_dma_out_callback;
+		cb_desc->callback = omap_aes_gcm_dma_out_callback;
 	else
-		tx_out->callback = omap_aes_dma_out_callback;
-	tx_out->callback_param = dd;
+		cb_desc->callback = omap_aes_dma_out_callback;
+	cb_desc->callback_param = dd;
+
 
 	dmaengine_submit(tx_in);
-	dmaengine_submit(tx_out);
+	if (tx_out)
+		dmaengine_submit(tx_out);
 
 	dma_async_issue_pending(dd->dma_lch_in);
-	dma_async_issue_pending(dd->dma_lch_out);
+	if (out_sg_len)
+		dma_async_issue_pending(dd->dma_lch_out);
 
 	/* start DMA */
 	dd->pdata->trigger(dd, dd->total);
@@ -361,11 +373,13 @@ int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
 			return -EINVAL;
 		}
 
-		err = dma_map_sg(dd->dev, dd->out_sg, dd->out_sg_len,
-				 DMA_FROM_DEVICE);
-		if (!err) {
-			dev_err(dd->dev, "dma_map_sg() error\n");
-			return -EINVAL;
+		if (dd->out_sg_len) {
+			err = dma_map_sg(dd->dev, dd->out_sg, dd->out_sg_len,
+					 DMA_FROM_DEVICE);
+			if (!err) {
+				dev_err(dd->dev, "dma_map_sg() error\n");
+				return -EINVAL;
+			}
 		}
 	}
 
@@ -373,8 +387,9 @@ int omap_aes_crypt_dma_start(struct omap_aes_dev *dd)
 				 dd->out_sg_len);
 	if (err && !dd->pio_only) {
 		dma_unmap_sg(dd->dev, dd->in_sg, dd->in_sg_len, DMA_TO_DEVICE);
-		dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len,
-			     DMA_FROM_DEVICE);
+		if (dd->out_sg_len)
+			dma_unmap_sg(dd->dev, dd->out_sg, dd->out_sg_len,
+				     DMA_FROM_DEVICE);
 	}
 
 	return err;
-- 
2.17.1

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

  parent reply	other threads:[~2019-11-05 14:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-05 14:00 [PATCHv2 00/22] crypto: omap-sham: fixes towards 5.5 Tero Kristo
2019-11-05 14:00 ` [PATCHv2 01/22] crypto: omap-sham: split up data to multiple sg elements with huge data Tero Kristo
2019-11-05 14:00 ` [PATCHv2 02/22] crypto: omap-sham: remove the sysfs group during driver removal Tero Kristo
2019-11-05 14:00 ` [PATCHv2 03/22] crypto: omap-aes: " Tero Kristo
2019-11-05 14:00 ` [PATCHv2 04/22] crypto: omap-des: add IV output handling Tero Kristo
2019-11-05 14:00 ` [PATCHv2 05/22] crypto: omap-aes: " Tero Kristo
2019-11-05 14:00 ` [PATCHv2 06/22] crypto: omap-sham: fix buffer handling for split test cases Tero Kristo
2019-11-05 14:00 ` [PATCHv2 07/22] crypto: omap-aes-gcm: fix corner case with only auth data Tero Kristo
2019-11-05 14:00 ` [PATCHv2 08/22] crypto: omap-sham: fix split update cases with cryptomgr tests Tero Kristo
2019-11-05 14:00 ` [PATCHv2 09/22] crypto: add timeout to crypto_wait_req Tero Kristo
2019-11-15  5:29   ` Herbert Xu
2019-11-15  7:44     ` Tero Kristo
2019-11-15  9:10       ` Herbert Xu
2019-11-05 14:00 ` [PATCHv2 10/22] crypto: omap-aes: fixup aligned data cleanup Tero Kristo
2019-11-05 14:01 ` [PATCHv2 11/22] crypto: omap-aes - reject invalid input sizes for block modes Tero Kristo
2019-11-05 14:01 ` [PATCHv2 12/22] crypto: omap-aes-ctr - set blocksize to 1 Tero Kristo
2019-11-05 14:01 ` [PATCHv2 13/22] crypto: omap-aes-gcm - deal with memory allocation failure Tero Kristo
2019-11-05 14:01 ` [PATCHv2 14/22] crypto: omap-aes-gcm - add missing .setauthsize hooks Tero Kristo
2019-11-05 14:01 ` [PATCHv2 15/22] crypto: omap-aes-gcm - check length of assocdata in RFC4106 mode Tero Kristo
2019-11-05 14:01 ` [PATCHv2 16/22] crypto: omap-aes-gcm - use the AES library to encrypt the tag Tero Kristo
2019-11-05 14:01 ` Tero Kristo [this message]
2019-11-05 14:01 ` [PATCHv2 18/22] crypto: omap-sham: fix unaligned sg list handling Tero Kristo
2019-11-05 14:01 ` [PATCHv2 19/22] crypto: omap-aes-gcm: convert to use crypto engine Tero Kristo
2019-11-05 14:01 ` [PATCHv2 20/22] crypto: omap-des: avoid unnecessary spam with bad cryptlen Tero Kristo
2019-11-05 14:01 ` [PATCHv2 21/22] crypto: omap-des: handle NULL cipher request Tero Kristo
2019-11-05 14:01 ` [PATCHv2 22/22] crypto: omap-crypto: copy the temporary data to output buffer properly Tero Kristo
2019-12-11  8:06 ` [PATCHv2 00/22] crypto: omap-sham: fixes towards 5.5 Tero Kristo
2019-12-11  8:12   ` Herbert Xu
2019-12-11  8:40     ` Tero Kristo
2019-12-11  9:42 ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191105140111.20285-18-t-kristo@ti.com \
    --to=t-kristo@ti.com \
    --cc=ard.biesheuvel@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.