diff options
author | Marcelo Cerri <mhcerri@linux.vnet.ibm.com> | 2013-08-29 10:36:34 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-09-02 06:32:53 -0400 |
commit | 884d981b04f3c00f61f4efaf9a93103e01260685 (patch) | |
tree | 080a87c9c17b9a754cfc69d12a77328f8ae698ae /drivers/crypto | |
parent | 2d290f0240c682a5dddf6b9ba39460c82f9fdff1 (diff) |
crypto: nx - fix limits to sg lists for AES-CTR
This patch updates the nx-aes-ctr implementation to perform several
hyper calls if needed in order to always respect the length limits for
scatter/gather lists.
Two different limits are considered:
- "ibm,max-sg-len": maximum number of bytes of each scatter/gather
list.
- "ibm,max-sync-cop":
- The total number of bytes that a scatter/gather list can hold.
- The maximum number of elements that a scatter/gather list can have.
Reviewed-by: Joy Latten <jmlatten@linux.vnet.ibm.com>
Signed-off-by: Marcelo Cerri <mhcerri@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r-- | drivers/crypto/nx/nx-aes-ctr.c | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/drivers/crypto/nx/nx-aes-ctr.c b/drivers/crypto/nx/nx-aes-ctr.c index 80dee8d58659..a37d009dc75c 100644 --- a/drivers/crypto/nx/nx-aes-ctr.c +++ b/drivers/crypto/nx/nx-aes-ctr.c | |||
@@ -89,33 +89,45 @@ static int ctr_aes_nx_crypt(struct blkcipher_desc *desc, | |||
89 | struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); | 89 | struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); |
90 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; | 90 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
91 | unsigned long irq_flags; | 91 | unsigned long irq_flags; |
92 | unsigned int processed = 0, to_process; | ||
93 | u32 max_sg_len; | ||
92 | int rc; | 94 | int rc; |
93 | 95 | ||
94 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); | 96 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); |
95 | 97 | ||
96 | if (nbytes > nx_ctx->ap->databytelen) { | 98 | max_sg_len = min_t(u32, nx_driver.of.max_sg_len/sizeof(struct nx_sg), |
97 | rc = -EINVAL; | 99 | nx_ctx->ap->sglen); |
98 | goto out; | ||
99 | } | ||
100 | 100 | ||
101 | rc = nx_build_sg_lists(nx_ctx, desc, dst, src, nbytes, 0, | 101 | do { |
102 | csbcpb->cpb.aes_ctr.iv); | 102 | to_process = min_t(u64, nbytes - processed, |
103 | if (rc) | 103 | nx_ctx->ap->databytelen); |
104 | goto out; | 104 | to_process = min_t(u64, to_process, |
105 | NX_PAGE_SIZE * (max_sg_len - 1)); | ||
106 | to_process = to_process & ~(AES_BLOCK_SIZE - 1); | ||
105 | 107 | ||
106 | if (!nx_ctx->op.inlen || !nx_ctx->op.outlen) { | 108 | rc = nx_build_sg_lists(nx_ctx, desc, dst, src, to_process, |
107 | rc = -EINVAL; | 109 | processed, csbcpb->cpb.aes_ctr.iv); |
108 | goto out; | 110 | if (rc) |
109 | } | 111 | goto out; |
112 | |||
113 | if (!nx_ctx->op.inlen || !nx_ctx->op.outlen) { | ||
114 | rc = -EINVAL; | ||
115 | goto out; | ||
116 | } | ||
117 | |||
118 | rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, | ||
119 | desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); | ||
120 | if (rc) | ||
121 | goto out; | ||
122 | |||
123 | memcpy(desc->info, csbcpb->cpb.aes_cbc.cv, AES_BLOCK_SIZE); | ||
110 | 124 | ||
111 | rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, | 125 | atomic_inc(&(nx_ctx->stats->aes_ops)); |
112 | desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); | 126 | atomic64_add(csbcpb->csb.processed_byte_count, |
113 | if (rc) | 127 | &(nx_ctx->stats->aes_bytes)); |
114 | goto out; | ||
115 | 128 | ||
116 | atomic_inc(&(nx_ctx->stats->aes_ops)); | 129 | processed += to_process; |
117 | atomic64_add(csbcpb->csb.processed_byte_count, | 130 | } while (processed < nbytes); |
118 | &(nx_ctx->stats->aes_bytes)); | ||
119 | out: | 131 | out: |
120 | spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); | 132 | spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); |
121 | return rc; | 133 | return rc; |