MLK-22039: crypto: caam - use len instead of nents for bulding HW S/G table
authorHoria Geantă <horia.geanta@nxp.com>
Mon, 10 Jun 2019 13:30:58 +0000 (16:30 +0300)
committerHoria Geantă <horia.geanta@nxp.com>
Fri, 5 Jul 2019 15:00:10 +0000 (18:00 +0300)
commit87414e1e091e050e4372c2d7a5613ea7ae4ed3ca
tree1ffd5f8945069a62ac575b88f1ff6c04ac884e5b
parent100197706119e3cb8e8552afb93c46f7ec12f414
MLK-22039: crypto: caam - use len instead of nents for bulding HW S/G table

Currently, conversion of SW S/G table into HW S/G layout relies on
nents returned by sg_nents_for_len(sg, len).
However this leaves the possibility of HW S/G referencing more data
then needed: since buffer length in HW S/G entries is filled using
sg_dma_len(sg), the last entry in HW S/G table might have a length
that is bigger than needed for the crypto request.

This way of S/G table conversion is fine, unless after converting a table
more entries have to be appended to the HW S/G table.
In this case, crypto engine would access data from the S/G entry having
the incorrect length, instead of advancing in the S/G table.
This situation doesn't exist, but the upcoming implementation of
IV update for skcipher algorithms needs to add a S/G entry after
req->dst S/G (corresponding to output IV).

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit 059d73eea6409873446a858dd64a5bec9bf68b70)

backported to imx_4.19.y

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Reviewed-by: Iuliana Prodan <iuliana.prodan@nxp.com>
drivers/crypto/caam/caamalg.c
drivers/crypto/caam/caamalg_qi.c
drivers/crypto/caam/caamhash.c
drivers/crypto/caam/caampkc.c
drivers/crypto/caam/sg_sw_qm.h
drivers/crypto/caam/sg_sw_sec4.h