From patchwork Mon Oct 24 16:40:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 9392981 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8197A60231 for ; Mon, 24 Oct 2016 18:41:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F50C288F1 for ; Mon, 24 Oct 2016 18:41:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CBB328A41; Mon, 24 Oct 2016 18:41:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 531EC288F1 for ; Mon, 24 Oct 2016 18:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934500AbcJXSlC (ORCPT ); Mon, 24 Oct 2016 14:41:02 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36513 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934166AbcJXSlB (ORCPT ); Mon, 24 Oct 2016 14:41:01 -0400 Received: by mail-qk0-f196.google.com with SMTP id z190so13754011qkc.3 for ; Mon, 24 Oct 2016 11:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=HwJbooNj0iP/PbH5Zt/nnC5MyypZSndW5LEWO9ko5ZE=; b=nf+3xxT41Fd14jvwRqJURAvOxxVNr0KWUUrShS+sei3xzL+Wq1mFiGhP2FZwXCE9QD 63uEfVIYZyGGrHhLU7nkdoEPeuTFG3Hd7hQfMMqa2RrmdbzXzxWlgcIU9DawXyIwot8+ BWeFBdzKKK8vVlaCIhS9ltHUHFWl/7kjs++gVpxJzUMbbweaUaFZ6fC1N3h+2CAXUbO4 Bp7SZqw8ibdVyXSj9xwcvNMayPUa+ySTOtcnqEkRx0t5ZMfMTCLaHPTQarMcEmy5aUl9 xj4v5cpl+7AVmk8csLcbVIMARysaHjjLebjpzX3zIBLYQZSGWFgHGw42ra6ECg/0NZQR JgMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HwJbooNj0iP/PbH5Zt/nnC5MyypZSndW5LEWO9ko5ZE=; b=C9ymKWbvjirLx0JVAKMzNXKUCGJrE6tnfa5IxX+dzjALbHQmJqAT4RLYtuGs/dzmJj LsXCzjjM+4BSPCxQaC7OA6qFxurwYDzbrrUTrM4emD5bpclrkwUUOZ7aPrYgVGb9N1ca zI6V8Y2G8Q1xrnjwn0aZKni7cyfmSc4X1MRVVcxsYJQGt4eX4V99ykPfSP8O//NZ+GAr IUZwFjcuWVHXiqipTrSkKJjTroJyEnQT0Vs5/QqmrCj+DKSXFEygN0iR0S5qf2tofWLM OpHipSGeKIRlaX1b7yspmyBFI5cBr3IZxMpQHsWyfyTSnGjPtGJwpJzGZ96QCZY3L+CL JGAQ== X-Gm-Message-State: ABUngve+jpjcQb+XoYjT3Wh+myQUg27JO3E0Bnfl8+QM/z2farvIznYCaTJSYxR4RYpNaQ== X-Received: by 10.55.185.67 with SMTP id j64mr15958953qkf.87.1477334459994; Mon, 24 Oct 2016 11:40:59 -0700 (PDT) Received: from localhost.localdomain ([187.180.184.146]) by smtp.gmail.com with ESMTPSA id u4sm9037421qka.9.2016.10.24.11.40.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Oct 2016 11:40:59 -0700 (PDT) From: Fabio Estevam To: herbert@gondor.apana.org.au Cc: marex@denx.de, gianfranco.costamagna@abinsula.com, linux-crypto@vger.kernel.org, Fabio Estevam Subject: [PATCH] crypto: mxs-dcp - Remove hash support Date: Mon, 24 Oct 2016 14:40:26 -0200 Message-Id: <1477327226-2904-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Fabio Estevam mxs-dcp driver does not probe for a long time: mxs-dcp 80028000.dcp: Failed to register sha1 hash! mxs-dcp: probe of 80028000.dcp failed with error -22 There were some previous attempts to fix this, and the following feedback was given by Herbert Xu's [1]: "This driver is hopelessly broken as its request context doesn't contain the hash state at all. Unless someone can fix that we should probably just remove the hash implementations altogether." [1] http://www.spinics.net/lists/linux-crypto/msg18187.html So remove the hash support for now. Signed-off-by: Fabio Estevam Tested-by: Gianfranco Costamagna ' --- drivers/crypto/mxs-dcp.c | 367 +---------------------------------------------- 1 file changed, 2 insertions(+), 365 deletions(-) diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c index 625ee50..b1b1dda 100644 --- a/drivers/crypto/mxs-dcp.c +++ b/drivers/crypto/mxs-dcp.c @@ -498,278 +498,6 @@ static void mxs_dcp_aes_fallback_exit(struct crypto_tfm *tfm) crypto_free_skcipher(actx->fallback); } -/* - * Hashing (SHA1/SHA256) - */ -static int mxs_dcp_run_sha(struct ahash_request *req) -{ - struct dcp *sdcp = global_sdcp; - int ret; - - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); - struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm); - struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req); - struct hash_alg_common *halg = crypto_hash_alg_common(tfm); - - struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan]; - - dma_addr_t digest_phys = 0; - dma_addr_t buf_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_in_buf, - DCP_BUF_SZ, DMA_TO_DEVICE); - - /* Fill in the DMA descriptor. */ - desc->control0 = MXS_DCP_CONTROL0_DECR_SEMAPHORE | - MXS_DCP_CONTROL0_INTERRUPT | - MXS_DCP_CONTROL0_ENABLE_HASH; - if (rctx->init) - desc->control0 |= MXS_DCP_CONTROL0_HASH_INIT; - - desc->control1 = actx->alg; - desc->next_cmd_addr = 0; - desc->source = buf_phys; - desc->destination = 0; - desc->size = actx->fill; - desc->payload = 0; - desc->status = 0; - - /* Set HASH_TERM bit for last transfer block. */ - if (rctx->fini) { - digest_phys = dma_map_single(sdcp->dev, req->result, - halg->digestsize, DMA_FROM_DEVICE); - desc->control0 |= MXS_DCP_CONTROL0_HASH_TERM; - desc->payload = digest_phys; - } - - ret = mxs_dcp_start_dma(actx); - - if (rctx->fini) - dma_unmap_single(sdcp->dev, digest_phys, halg->digestsize, - DMA_FROM_DEVICE); - - dma_unmap_single(sdcp->dev, buf_phys, DCP_BUF_SZ, DMA_TO_DEVICE); - - return ret; -} - -static int dcp_sha_req_to_buf(struct crypto_async_request *arq) -{ - struct dcp *sdcp = global_sdcp; - - struct ahash_request *req = ahash_request_cast(arq); - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); - struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm); - struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req); - struct hash_alg_common *halg = crypto_hash_alg_common(tfm); - const int nents = sg_nents(req->src); - - uint8_t *in_buf = sdcp->coh->sha_in_buf; - - uint8_t *src_buf; - - struct scatterlist *src; - - unsigned int i, len, clen; - int ret; - - int fin = rctx->fini; - if (fin) - rctx->fini = 0; - - for_each_sg(req->src, src, nents, i) { - src_buf = sg_virt(src); - len = sg_dma_len(src); - - do { - if (actx->fill + len > DCP_BUF_SZ) - clen = DCP_BUF_SZ - actx->fill; - else - clen = len; - - memcpy(in_buf + actx->fill, src_buf, clen); - len -= clen; - src_buf += clen; - actx->fill += clen; - - /* - * If we filled the buffer and still have some - * more data, submit the buffer. - */ - if (len && actx->fill == DCP_BUF_SZ) { - ret = mxs_dcp_run_sha(req); - if (ret) - return ret; - actx->fill = 0; - rctx->init = 0; - } - } while (len); - } - - if (fin) { - rctx->fini = 1; - - /* Submit whatever is left. */ - if (!req->result) - return -EINVAL; - - ret = mxs_dcp_run_sha(req); - if (ret) - return ret; - - actx->fill = 0; - - /* For some reason, the result is flipped. */ - for (i = 0; i < halg->digestsize / 2; i++) { - swap(req->result[i], - req->result[halg->digestsize - i - 1]); - } - } - - return 0; -} - -static int dcp_chan_thread_sha(void *data) -{ - struct dcp *sdcp = global_sdcp; - const int chan = DCP_CHAN_HASH_SHA; - - struct crypto_async_request *backlog; - struct crypto_async_request *arq; - - struct dcp_sha_req_ctx *rctx; - - struct ahash_request *req; - int ret, fini; - - do { - __set_current_state(TASK_INTERRUPTIBLE); - - mutex_lock(&sdcp->mutex[chan]); - backlog = crypto_get_backlog(&sdcp->queue[chan]); - arq = crypto_dequeue_request(&sdcp->queue[chan]); - mutex_unlock(&sdcp->mutex[chan]); - - if (backlog) - backlog->complete(backlog, -EINPROGRESS); - - if (arq) { - req = ahash_request_cast(arq); - rctx = ahash_request_ctx(req); - - ret = dcp_sha_req_to_buf(arq); - fini = rctx->fini; - arq->complete(arq, ret); - if (!fini) - continue; - } - - schedule(); - } while (!kthread_should_stop()); - - return 0; -} - -static int dcp_sha_init(struct ahash_request *req) -{ - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); - struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm); - - struct hash_alg_common *halg = crypto_hash_alg_common(tfm); - - /* - * Start hashing session. The code below only inits the - * hashing session context, nothing more. - */ - memset(actx, 0, sizeof(*actx)); - - if (strcmp(halg->base.cra_name, "sha1") == 0) - actx->alg = MXS_DCP_CONTROL1_HASH_SELECT_SHA1; - else - actx->alg = MXS_DCP_CONTROL1_HASH_SELECT_SHA256; - - actx->fill = 0; - actx->hot = 0; - actx->chan = DCP_CHAN_HASH_SHA; - - mutex_init(&actx->mutex); - - return 0; -} - -static int dcp_sha_update_fx(struct ahash_request *req, int fini) -{ - struct dcp *sdcp = global_sdcp; - - struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req); - struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); - struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm); - - int ret; - - /* - * Ignore requests that have no data in them and are not - * the trailing requests in the stream of requests. - */ - if (!req->nbytes && !fini) - return 0; - - mutex_lock(&actx->mutex); - - rctx->fini = fini; - - if (!actx->hot) { - actx->hot = 1; - rctx->init = 1; - } - - mutex_lock(&sdcp->mutex[actx->chan]); - ret = crypto_enqueue_request(&sdcp->queue[actx->chan], &req->base); - mutex_unlock(&sdcp->mutex[actx->chan]); - - wake_up_process(sdcp->thread[actx->chan]); - mutex_unlock(&actx->mutex); - - return -EINPROGRESS; -} - -static int dcp_sha_update(struct ahash_request *req) -{ - return dcp_sha_update_fx(req, 0); -} - -static int dcp_sha_final(struct ahash_request *req) -{ - ahash_request_set_crypt(req, NULL, req->result, 0); - req->nbytes = 0; - return dcp_sha_update_fx(req, 1); -} - -static int dcp_sha_finup(struct ahash_request *req) -{ - return dcp_sha_update_fx(req, 1); -} - -static int dcp_sha_digest(struct ahash_request *req) -{ - int ret; - - ret = dcp_sha_init(req); - if (ret) - return ret; - - return dcp_sha_finup(req); -} - -static int dcp_sha_cra_init(struct crypto_tfm *tfm) -{ - crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), - sizeof(struct dcp_sha_req_ctx)); - return 0; -} - -static void dcp_sha_cra_exit(struct crypto_tfm *tfm) -{ -} - /* AES 128 ECB and AES 128 CBC */ static struct crypto_alg dcp_aes_algs[] = { { @@ -822,54 +550,6 @@ static struct crypto_alg dcp_aes_algs[] = { }, }; -/* SHA1 */ -static struct ahash_alg dcp_sha1_alg = { - .init = dcp_sha_init, - .update = dcp_sha_update, - .final = dcp_sha_final, - .finup = dcp_sha_finup, - .digest = dcp_sha_digest, - .halg = { - .digestsize = SHA1_DIGEST_SIZE, - .base = { - .cra_name = "sha1", - .cra_driver_name = "sha1-dcp", - .cra_priority = 400, - .cra_alignmask = 63, - .cra_flags = CRYPTO_ALG_ASYNC, - .cra_blocksize = SHA1_BLOCK_SIZE, - .cra_ctxsize = sizeof(struct dcp_async_ctx), - .cra_module = THIS_MODULE, - .cra_init = dcp_sha_cra_init, - .cra_exit = dcp_sha_cra_exit, - }, - }, -}; - -/* SHA256 */ -static struct ahash_alg dcp_sha256_alg = { - .init = dcp_sha_init, - .update = dcp_sha_update, - .final = dcp_sha_final, - .finup = dcp_sha_finup, - .digest = dcp_sha_digest, - .halg = { - .digestsize = SHA256_DIGEST_SIZE, - .base = { - .cra_name = "sha256", - .cra_driver_name = "sha256-dcp", - .cra_priority = 400, - .cra_alignmask = 63, - .cra_flags = CRYPTO_ALG_ASYNC, - .cra_blocksize = SHA256_BLOCK_SIZE, - .cra_ctxsize = sizeof(struct dcp_async_ctx), - .cra_module = THIS_MODULE, - .cra_init = dcp_sha_cra_init, - .cra_exit = dcp_sha_cra_exit, - }, - }, -}; - static irqreturn_t mxs_dcp_irq(int irq, void *context) { struct dcp *sdcp = context; @@ -984,20 +664,12 @@ static int mxs_dcp_probe(struct platform_device *pdev) crypto_init_queue(&sdcp->queue[i], 50); } - /* Create the SHA and AES handler threads. */ - sdcp->thread[DCP_CHAN_HASH_SHA] = kthread_run(dcp_chan_thread_sha, - NULL, "mxs_dcp_chan/sha"); - if (IS_ERR(sdcp->thread[DCP_CHAN_HASH_SHA])) { - dev_err(dev, "Error starting SHA thread!\n"); - return PTR_ERR(sdcp->thread[DCP_CHAN_HASH_SHA]); - } - + /* Create the AES handler threads. */ sdcp->thread[DCP_CHAN_CRYPTO] = kthread_run(dcp_chan_thread_aes, NULL, "mxs_dcp_chan/aes"); if (IS_ERR(sdcp->thread[DCP_CHAN_CRYPTO])) { dev_err(dev, "Error starting SHA thread!\n"); - ret = PTR_ERR(sdcp->thread[DCP_CHAN_CRYPTO]); - goto err_destroy_sha_thread; + return PTR_ERR(sdcp->thread[DCP_CHAN_CRYPTO]); } /* Register the various crypto algorithms. */ @@ -1013,39 +685,10 @@ static int mxs_dcp_probe(struct platform_device *pdev) } } - if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA1) { - ret = crypto_register_ahash(&dcp_sha1_alg); - if (ret) { - dev_err(dev, "Failed to register %s hash!\n", - dcp_sha1_alg.halg.base.cra_name); - goto err_unregister_aes; - } - } - - if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA256) { - ret = crypto_register_ahash(&dcp_sha256_alg); - if (ret) { - dev_err(dev, "Failed to register %s hash!\n", - dcp_sha256_alg.halg.base.cra_name); - goto err_unregister_sha1; - } - } - return 0; -err_unregister_sha1: - if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA1) - crypto_unregister_ahash(&dcp_sha1_alg); - -err_unregister_aes: - if (sdcp->caps & MXS_DCP_CAPABILITY1_AES128) - crypto_unregister_algs(dcp_aes_algs, ARRAY_SIZE(dcp_aes_algs)); - err_destroy_aes_thread: kthread_stop(sdcp->thread[DCP_CHAN_CRYPTO]); - -err_destroy_sha_thread: - kthread_stop(sdcp->thread[DCP_CHAN_HASH_SHA]); return ret; } @@ -1053,12 +696,6 @@ static int mxs_dcp_remove(struct platform_device *pdev) { struct dcp *sdcp = platform_get_drvdata(pdev); - if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA256) - crypto_unregister_ahash(&dcp_sha256_alg); - - if (sdcp->caps & MXS_DCP_CAPABILITY1_SHA1) - crypto_unregister_ahash(&dcp_sha1_alg); - if (sdcp->caps & MXS_DCP_CAPABILITY1_AES128) crypto_unregister_algs(dcp_aes_algs, ARRAY_SIZE(dcp_aes_algs));