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: hisilicon/zip - support fallback for zip

When the hardware queue resource busy(no shareable queue)
or memery alloc fail in initialization of acomp_alg, use
soft algorithm to complete the work.

Fixes: 1a9e6f59caee ("crypto: hisilicon/zip - remove zlib and gzip")
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Chenghai Huang and committed by
Herbert Xu
73398f85 2a75dece

+43 -8
+1
drivers/crypto/hisilicon/Kconfig
··· 57 57 depends on UACCE || UACCE=n 58 58 depends on ACPI 59 59 select CRYPTO_DEV_HISI_QM 60 + select CRYPTO_DEFLATE 60 61 help 61 62 Support for HiSilicon ZIP Driver 62 63
+42 -8
drivers/crypto/hisilicon/zip/zip_crypto.c
··· 84 84 struct hisi_zip_ctx { 85 85 struct hisi_zip_qp_ctx qp_ctx[HZIP_CTX_Q_NUM]; 86 86 const struct hisi_zip_sqe_ops *ops; 87 + bool fallback; 87 88 }; 88 89 89 90 static int sgl_sge_nr_set(const char *val, const struct kernel_param *kp) ··· 110 109 static u16 sgl_sge_nr = HZIP_SGL_SGE_NR; 111 110 module_param_cb(sgl_sge_nr, &sgl_sge_nr_ops, &sgl_sge_nr, 0444); 112 111 MODULE_PARM_DESC(sgl_sge_nr, "Number of sge in sgl(1-255)"); 112 + 113 + static int hisi_zip_fallback_do_work(struct acomp_req *acomp_req, bool is_decompress) 114 + { 115 + ACOMP_FBREQ_ON_STACK(fbreq, acomp_req); 116 + int ret; 117 + 118 + if (!is_decompress) 119 + ret = crypto_acomp_compress(fbreq); 120 + else 121 + ret = crypto_acomp_decompress(fbreq); 122 + if (ret) { 123 + pr_err("failed to do fallback work, ret=%d\n", ret); 124 + return ret; 125 + } 126 + 127 + acomp_req->dlen = fbreq->dlen; 128 + return ret; 129 + } 113 130 114 131 static struct hisi_zip_req *hisi_zip_create_req(struct hisi_zip_qp_ctx *qp_ctx, 115 132 struct acomp_req *req) ··· 332 313 { 333 314 struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); 334 315 struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_COMP]; 335 - struct device *dev = &qp_ctx->qp->qm->pdev->dev; 336 316 struct hisi_zip_req *req; 317 + struct device *dev; 337 318 int ret; 319 + 320 + if (ctx->fallback) 321 + return hisi_zip_fallback_do_work(acomp_req, 0); 322 + 323 + dev = &qp_ctx->qp->qm->pdev->dev; 338 324 339 325 req = hisi_zip_create_req(qp_ctx, acomp_req); 340 326 if (IS_ERR(req)) ··· 358 334 { 359 335 struct hisi_zip_ctx *ctx = crypto_tfm_ctx(acomp_req->base.tfm); 360 336 struct hisi_zip_qp_ctx *qp_ctx = &ctx->qp_ctx[HZIP_QPC_DECOMP]; 361 - struct device *dev = &qp_ctx->qp->qm->pdev->dev; 362 337 struct hisi_zip_req *req; 338 + struct device *dev; 363 339 int ret; 340 + 341 + if (ctx->fallback) 342 + return hisi_zip_fallback_do_work(acomp_req, 1); 343 + 344 + dev = &qp_ctx->qp->qm->pdev->dev; 364 345 365 346 req = hisi_zip_create_req(qp_ctx, acomp_req); 366 347 if (IS_ERR(req)) ··· 544 515 ret = hisi_zip_ctx_init(ctx, COMP_NAME_TO_TYPE(alg_name), tfm->base.node); 545 516 if (ret) { 546 517 pr_err("failed to init ctx (%d)!\n", ret); 547 - return ret; 518 + goto switch_to_soft; 548 519 } 549 520 550 521 dev = &ctx->qp_ctx[0].qp->qm->pdev->dev; ··· 569 540 hisi_zip_release_req_q(ctx); 570 541 err_ctx_exit: 571 542 hisi_zip_ctx_exit(ctx); 572 - return ret; 543 + switch_to_soft: 544 + ctx->fallback = true; 545 + return 0; 573 546 } 574 547 575 548 static void hisi_zip_acomp_exit(struct crypto_acomp *tfm) 576 549 { 577 550 struct hisi_zip_ctx *ctx = crypto_tfm_ctx(&tfm->base); 578 551 579 - hisi_zip_release_sgl_pool(ctx); 580 - hisi_zip_release_req_q(ctx); 581 - hisi_zip_ctx_exit(ctx); 552 + if (!ctx->fallback) { 553 + hisi_zip_release_sgl_pool(ctx); 554 + hisi_zip_release_req_q(ctx); 555 + hisi_zip_ctx_exit(ctx); 556 + } 582 557 } 583 558 584 559 static struct acomp_alg hisi_zip_acomp_deflate = { ··· 593 560 .base = { 594 561 .cra_name = "deflate", 595 562 .cra_driver_name = "hisi-deflate-acomp", 596 - .cra_flags = CRYPTO_ALG_ASYNC, 563 + .cra_flags = CRYPTO_ALG_ASYNC | 564 + CRYPTO_ALG_NEED_FALLBACK, 597 565 .cra_module = THIS_MODULE, 598 566 .cra_priority = HZIP_ALG_PRIORITY, 599 567 .cra_ctxsize = sizeof(struct hisi_zip_ctx),