Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3630726pxb; Mon, 24 Jan 2022 13:58:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJ2q/FyL1eKSjy/mZgxAjSkv23au36mNwizXnEW9RSPQX7IdGy0m8IAd9xYuenVBLytIw6 X-Received: by 2002:a17:902:8546:b0:14b:735f:1bc2 with SMTP id d6-20020a170902854600b0014b735f1bc2mr497978plo.172.1643061487893; Mon, 24 Jan 2022 13:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061487; cv=none; d=google.com; s=arc-20160816; b=N6RGU6fFOuQqSB+GX3VyJWwMo/l1vkYPFRtCk4e6jX8PQKMweeHJah+B2KWS33krgb suFSNYKnNwPvTOtKbQ8c7VHH0RJcr+kyLLLwEQkyVKZ4rdgfWZA2uus7dq/9kO/2Bb3l OV25H+eg1/dcO/b/YEmmsiqoLw51RNEBvcz9v3cMhjsIf1ILSbXdPMySjBgcvFN4KX4e O4/O9AkdWoWSPIXOE/7KOtKYpoPxMlgDdYwV+03tuCQcrf5QwsGivcV2U8GnviwHtKn5 dV331EAeUleHad/DG4pR6mHq+tPzXYxfyIsSrGEiBhqlKzp6Z7Q5QDVipuLvE1kGtJJi H8bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7ae8sNy1NQVUhgB9CIKxQCZKksRiHEDEWfhsoMf2Pas=; b=SRNaCdbrwAtapd7lb0AhqGlI9DeBpcYsnXU00noICk/1A9lVOYxDhLa0n99CI5UMw6 AEV+KzQOAi/LGPAKqrTGvZ4WhhDzDRbinZYGxRq5peaRJWwGGVHSbF9m7JSixSGUM4G1 6tvKYb82oStQdQ1e2aDTMuapErzjBGVkqGm7eXN1qujRu8URX6R3IPWMwr/ihMihbmaQ Sp63jZVfi73c+nJ5cPRwvAE82q1sXoCs001lzXm30OygoUeHXLlvm7RwxMX9hulCGRMO VXh9T50CgXuK/9B45N3j3yDEXTkckIYnzj9V6P98TEzzswpA/dnXEQEJCiqfLMI8UWTi Ic1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qJn3qcG2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me15si567171pjb.98.2022.01.24.13.57.55; Mon, 24 Jan 2022 13:58:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qJn3qcG2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1457230AbiAXVlO (ORCPT + 99 others); Mon, 24 Jan 2022 16:41:14 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:55874 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445481AbiAXVDj (ORCPT ); Mon, 24 Jan 2022 16:03:39 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F37F36135E; Mon, 24 Jan 2022 21:03:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC0BFC340E5; Mon, 24 Jan 2022 21:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058217; bh=+GukFv+UmmsfgFRsXbDyesdwasvKERbn/wIBoWXygSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJn3qcG2H4QbqJYIXyg12LovNdCqxZB1wk+Y7sDIeV8q2SQTYtd7AIobTSsmy7nlD +92qgXUkdPzQY9Lo9a0YoUk7Xh8g6aiAqzDMDHKb/xpSJ0EN+hIHGUW9QJfvGTovTK lEt8l6HyAoA8/cIIrnBl5p4E1jSpRcJFyBf8ZoAs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gaurav Jain , =?UTF-8?q?Horia=20Geant=C4=83?= , Herbert Xu , Sasha Levin Subject: [PATCH 5.16 0217/1039] crypto: caam - save caam memory to support crypto engine retry mechanism. Date: Mon, 24 Jan 2022 19:33:26 +0100 Message-Id: <20220124184132.637954486@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gaurav Jain [ Upstream commit 087e1d715bccf25dc0e83294576e416b0386ba20 ] When caam queue is full (-ENOSPC), caam frees descriptor memory. crypto-engine checks if retry support is true and h/w queue is full(-ENOSPC), then requeue the crypto request. During processing the requested descriptor again, caam gives below error. (caam_jr 30902000.jr: 40000006: DECO: desc idx 0: Invalid KEY Command). This patch adds a check to return when caam input ring is full and retry support is true. so descriptor memory is not freed and requeued request can be processed again. Fixes: 2d653936eb2cf ("crypto: caam - enable crypto-engine retry mechanism") Signed-off-by: Gaurav Jain Reviewed-by: Horia Geantă Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/caam/caamalg.c | 6 ++++++ drivers/crypto/caam/caamhash.c | 3 +++ drivers/crypto/caam/caampkc.c | 3 +++ 3 files changed, 12 insertions(+) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 8697ae53b0633..d3d8bb0a69900 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -1533,6 +1533,9 @@ static int aead_do_one_req(struct crypto_engine *engine, void *areq) ret = caam_jr_enqueue(ctx->jrdev, desc, aead_crypt_done, req); + if (ret == -ENOSPC && engine->retry_support) + return ret; + if (ret != -EINPROGRESS) { aead_unmap(ctx->jrdev, rctx->edesc, req); kfree(rctx->edesc); @@ -1762,6 +1765,9 @@ static int skcipher_do_one_req(struct crypto_engine *engine, void *areq) ret = caam_jr_enqueue(ctx->jrdev, desc, skcipher_crypt_done, req); + if (ret == -ENOSPC && engine->retry_support) + return ret; + if (ret != -EINPROGRESS) { skcipher_unmap(ctx->jrdev, rctx->edesc, req); kfree(rctx->edesc); diff --git a/drivers/crypto/caam/caamhash.c b/drivers/crypto/caam/caamhash.c index e8a6d8bc43b5d..36ef738e4a181 100644 --- a/drivers/crypto/caam/caamhash.c +++ b/drivers/crypto/caam/caamhash.c @@ -765,6 +765,9 @@ static int ahash_do_one_req(struct crypto_engine *engine, void *areq) ret = caam_jr_enqueue(jrdev, desc, state->ahash_op_done, req); + if (ret == -ENOSPC && engine->retry_support) + return ret; + if (ret != -EINPROGRESS) { ahash_unmap(jrdev, state->edesc, req, 0); kfree(state->edesc); diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c index bf6275ffc4aad..8867275767101 100644 --- a/drivers/crypto/caam/caampkc.c +++ b/drivers/crypto/caam/caampkc.c @@ -380,6 +380,9 @@ static int akcipher_do_one_req(struct crypto_engine *engine, void *areq) ret = caam_jr_enqueue(jrdev, desc, req_ctx->akcipher_op_done, req); + if (ret == -ENOSPC && engine->retry_support) + return ret; + if (ret != -EINPROGRESS) { rsa_pub_unmap(jrdev, req_ctx->edesc, req); rsa_io_unmap(jrdev, req_ctx->edesc, req); -- 2.34.1