Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: xilinx - Avoid submitting fallback requests to engine

Don't enqueue requests which are supposed to fallback to s/w crypto.

Signed-off-by: Harsh Jain <h.jain@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Harsh Jain and committed by
Herbert Xu
0d120a39 f939b88c

+37 -29
+37 -29
drivers/crypto/xilinx/zynqmp-aes-gcm.c
··· 204 204 { 205 205 struct aead_request *areq = 206 206 container_of(req, struct aead_request, base); 207 - struct crypto_aead *aead = crypto_aead_reqtfm(req); 208 - struct zynqmp_aead_tfm_ctx *tfm_ctx = crypto_aead_ctx(aead); 209 - struct zynqmp_aead_req_ctx *rq_ctx = aead_request_ctx(areq); 210 - struct aead_request *subreq = aead_request_ctx(req); 211 - int need_fallback; 212 207 int err; 213 208 214 - need_fallback = zynqmp_fallback_check(tfm_ctx, areq); 215 - 216 - if (need_fallback) { 217 - aead_request_set_tfm(subreq, tfm_ctx->fbk_cipher); 218 - 219 - aead_request_set_callback(subreq, areq->base.flags, 220 - NULL, NULL); 221 - aead_request_set_crypt(subreq, areq->src, areq->dst, 222 - areq->cryptlen, areq->iv); 223 - aead_request_set_ad(subreq, areq->assoclen); 224 - if (rq_ctx->op == ZYNQMP_AES_ENCRYPT) 225 - err = crypto_aead_encrypt(subreq); 226 - else 227 - err = crypto_aead_decrypt(subreq); 228 - } else { 229 - err = zynqmp_aes_aead_cipher(areq); 230 - } 231 - 209 + err = zynqmp_aes_aead_cipher(areq); 232 210 local_bh_disable(); 233 211 crypto_finalize_aead_request(engine, areq, err); 234 212 local_bh_enable(); ··· 257 279 return crypto_aead_setauthsize(tfm_ctx->fbk_cipher, authsize); 258 280 } 259 281 282 + static int xilinx_aes_fallback_crypt(struct aead_request *req, bool encrypt) 283 + { 284 + struct aead_request *subreq = aead_request_ctx(req); 285 + struct crypto_aead *aead = crypto_aead_reqtfm(req); 286 + struct zynqmp_aead_tfm_ctx *tfm_ctx = crypto_aead_ctx(aead); 287 + 288 + aead_request_set_tfm(subreq, tfm_ctx->fbk_cipher); 289 + aead_request_set_callback(subreq, req->base.flags, NULL, NULL); 290 + aead_request_set_crypt(subreq, req->src, req->dst, 291 + req->cryptlen, req->iv); 292 + aead_request_set_ad(subreq, req->assoclen); 293 + 294 + return encrypt ? crypto_aead_encrypt(subreq) : crypto_aead_decrypt(subreq); 295 + } 296 + 260 297 static int zynqmp_aes_aead_encrypt(struct aead_request *req) 261 298 { 262 - struct zynqmp_aead_drv_ctx *drv_ctx; 263 - struct crypto_aead *aead = crypto_aead_reqtfm(req); 264 - struct aead_alg *alg = crypto_aead_alg(aead); 265 299 struct zynqmp_aead_req_ctx *rq_ctx = aead_request_ctx(req); 300 + struct crypto_aead *aead = crypto_aead_reqtfm(req); 301 + struct zynqmp_aead_tfm_ctx *tfm_ctx = crypto_aead_ctx(aead); 302 + struct aead_alg *alg = crypto_aead_alg(aead); 303 + struct zynqmp_aead_drv_ctx *drv_ctx; 304 + int err; 266 305 267 306 rq_ctx->op = ZYNQMP_AES_ENCRYPT; 268 307 drv_ctx = container_of(alg, struct zynqmp_aead_drv_ctx, aead.base); 308 + err = zynqmp_fallback_check(tfm_ctx, req); 309 + if (err && tfm_ctx->keysrc != ZYNQMP_AES_KUP_KEY) 310 + return -EOPNOTSUPP; 311 + 312 + if (err) 313 + return xilinx_aes_fallback_crypt(req, true); 269 314 270 315 return crypto_transfer_aead_request_to_engine(drv_ctx->engine, req); 271 316 } 272 317 273 318 static int zynqmp_aes_aead_decrypt(struct aead_request *req) 274 319 { 275 - struct zynqmp_aead_drv_ctx *drv_ctx; 276 - struct crypto_aead *aead = crypto_aead_reqtfm(req); 277 - struct aead_alg *alg = crypto_aead_alg(aead); 278 320 struct zynqmp_aead_req_ctx *rq_ctx = aead_request_ctx(req); 321 + struct crypto_aead *aead = crypto_aead_reqtfm(req); 322 + struct zynqmp_aead_tfm_ctx *tfm_ctx = crypto_aead_ctx(aead); 323 + struct aead_alg *alg = crypto_aead_alg(aead); 324 + struct zynqmp_aead_drv_ctx *drv_ctx; 325 + int err; 279 326 280 327 rq_ctx->op = ZYNQMP_AES_DECRYPT; 281 328 drv_ctx = container_of(alg, struct zynqmp_aead_drv_ctx, aead.base); 329 + err = zynqmp_fallback_check(tfm_ctx, req); 330 + if (err && tfm_ctx->keysrc != ZYNQMP_AES_KUP_KEY) 331 + return -EOPNOTSUPP; 332 + if (err) 333 + return xilinx_aes_fallback_crypt(req, false); 282 334 283 335 return crypto_transfer_aead_request_to_engine(drv_ctx->engine, req); 284 336 }