From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F011F606A32C for ; Wed, 2 Dec 2026 10:11:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=b6PTJSza; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=kIqT+Z50; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ycpN1qVC DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=pm+qXco7z6N4p3iUr2bWuWoBqaIPb4qSeLxu9KbicHo=; b=b6PTJSzaIc38jNEBqoZSwX4tT+ Sm1lD2hfTC7Q/bU9Og0ifPlgoee47vwBUwFPwZXH8y89QndLkynAIajvCeFOyv5uvermTGCYt/tlV timsTrNB9/ZiUvsGZDDX2C+sGlpj1fTvJC53uA0k9RjNBaTssho9BkkqsZwiWW9O8PnlHvJZ2L2H4 p8CTI6qQk0BG3mi3UmCKqPeGf/9Pf4uOKqdQiKqVt14sbwtyejE4HYL2A4eztHfqXF+6YdGXzZPOI mAaLlECSJ9gMUFjRPaqACHartbDeCPHeQ4u4qRb6G9eNGDN42XNdl+x61F5K/pfCaQ0k8FdBzWdy5 OTw4rsoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYhJ4-0000000B5Oh-0ElU; Wed, 02 Dec 2026 10:11:22 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYhIx-0000000B57W-0pWx for linux-amlogic@bombadil.infradead.org; Wed, 02 Dec 2026 10:11:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=Jo48R/rzPU0am2rQpuYXg3SJslqV2Kyaq0H7/Wb2Q9o=; b=kIqT+Z50pbiJoyOTzr0uGycCA6 0OjcUQCzfR4MiVTMgySlQfYSoZ9bJYW6Q+kdEa1jCZ++Sd322GEmOwEzLPA82X3pu6Ou4so7lLxC0 B/DJLTk4cRkq/M0RXoWxfmQP4W6NLB6xeTt2vMjsyfCglnCbuE6TNGxOcws4dP063X1yKGz+katrl NxnpnJIJZA8sQs8JjRy2ZFLKrQg6DT4QDeFCrYF94+42Ggydsrog3mMCdmLO3wqTvNIQGVwHchG8j zD3pR6S3+nQ6oLDeNpyuqTzPPbGQs2bZtYBJAtZysJ4quD6OubliKkdLjURXqMHD4R26dj0dHteWc zBOwIpcg==; Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by desiato.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYhIr-0000000C8i8-30qX for linux-amlogic@lists.infradead.org; Wed, 02 Dec 2026 10:11:13 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4bba60271d7so66837925e9.2 for ; Wed, 02 Dec 2026 02:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796206268; x=1796811068; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Jo48R/rzPU0am2rQpuYXg3SJslqV2Kyaq0H7/Wb2Q9o=; b=ycpN1qVCcFHvIcUTzZI3CvkqtdTkU+mknftean0f471rxshtMS1RyW+e26AR1bKkDk CUg+wFMu7aAnUn0iOqSdkRZO3PxdgEZtsVs7kzaUY2fdgdLX+BOtZReg45ZpRK9lTIY/ IgNLVLxnIqGMAJNBOtkoXqGuFb4Np0NqLHxl1QGepQWNWAzSQdWI8pa2al0vxcvqZv3t 3daqZOxEoUFDeLfxr5QFbOSLLktkDCByVmM7FzkC1Npx3hd2eEND9YCW0Jdk7It6eU/G cq6HBlta/dpTGdjHFLTIK5QT3vYgaSdbBR+0ObubtrxdYXjgZnlMxhIQGVT5cjHdA10Y sbIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796206268; x=1796811068; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Jo48R/rzPU0am2rQpuYXg3SJslqV2Kyaq0H7/Wb2Q9o=; b=F3w21JzKDV7sHqsUQyeGOVBBYKpxn2ra00USVKxCUT67KdYtY6sDsFBQ2e7EKviFKm csuIvhU+1dnprKA81CiRzNKAgMNPw3uvvFwwJ4XxOVUw2EzsnuRiDA+4rpLRwNMqIxQl qmiAP7ZtTpkcgrZfhK3kYsBvfL4b5BHfce1ueLw/xY2SA9o4eR7nsCM2OkCuPnsA4FBY /VsbLGTgHCwlhkVYdkJ4+4saG++0ToFQaY1GYaI4V/i647e9ONAGw7GueWoocjzTUz7o 7xJ17r1/pRndcOEs7zaXUfVQ1aI/ubwMaq00hCX46os1jp5BgAp2e2GH4KRaIdwy17UX TPHw== X-Forwarded-Encrypted: i=1; AL+hErFdGHfhBCiN8zGdZJaXAado+wHuKf8Pl+I0UESg5+Bc96wrPYUULPtvxggPwcfo3lZaduZKbTYrvs3kHXcR@lists.infradead.org X-Gm-Message-State: APuU4Z9dH9ysDFqAaPVpccpycoJGSbN33r1BXXThJ5x82XoPKJLZW1KK av5wsxHWTQpotZ4gLzIHk57lltIe6BXrIbXC1o0Wkm+/AS60pSd/tvCg X-Gm-Gg: AZFdTZcjO+DsYwnhzLRM9gSqHUpv5o+aDOCtMf3HDLQZ+pNiT916KnKdEHmdW4+mBGn YQBBppYpOWLuO/70XzECL5qUJlF1Wlve1eIpJMH7hiqKmhTA3KtBoRvbZkFqUP6a8Tzy0Bxm3pz 2B57ZvaJZgwy+602+ZGBuZlVRtVlLeRMpclKgdwjspGVhZ+hC4uuaovFyQkRnRBmarX7ZiZGCAE x4hqjY02vOa8KAcFvNK4xlpIlSAXUqT/Si7XY+Zr339tO3pHIojnIbKTs/GQuHxJ3qh3iA0zYdS qmu999HpjZFLPoxbF1Vdw3HvVHOIuR7fZ/s+c40uaobIq8buUoI2oOtuaDlUPK9QCWwPLAuFMV1 xoO/1adfHCCKSnmwTUJSVxh8XJ2AiERBvEbGngF3ZbyZ4ham3O1FMj3Z7AMVYEHRfmDZ2mHjSyb gAeUlha5yyE6MuPy+XYgOfagu/nzzr5FZPzNTbdk0OZNLdYydw8iMc9tOgmFsE++XqPZnAt+UTV f08efzF8MgJuRQAcDN+P0/qPpXIS0rZN/cxpkOIUyOMayolZxA/Kf+tM0f5lRFYmkpV72wGuJos 6MSuEOWJjndypgqF7hIsXirraMj/ZpLCbpsL6wr58f6I2g== X-Received: by 2002:a05:600c:4755:b0:4bb:7033:de79 with SMTP id 5b1f17b1804b1-4bb8881dd02mr826355085e9.35.1796206268157; Wed, 02 Dec 2026 02:11:08 -0800 (PST) Received: from localhost.localdomain ([79.117.198.103]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88402ce9sm899268965e9.0.2026.12.02.02.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 02:11:07 -0800 (PST) From: Jose Nieto To: Corentin Labbe , Herbert Xu , "David S . Miller" Cc: linux-crypto@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Rob Herring , Krzysztof Kozlowski , Conor Dooley Subject: [PATCH v15 34/35] crypto: amlogic: keep the cipher key/IV buffer per request Date: Wed, 2 Dec 2026 11:10:35 +0100 Message-ID: <20261202101036.116145-14-jnieto.alaber@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261202101036.116145-1-jnieto.alaber@gmail.com> References: <20261202100714.115460-1-jnieto.alaber@gmail.com> <20261202101036.116145-1-jnieto.alaber@gmail.com> X-Archived-By: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_101110_595393_8CDDCA3B X-CRM114-Status: GOOD ( 16.25 ) X-Spam-Score: -0.2 (/) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 struct meson_cipher_tfm_ctx is shared by all requests of a transform, but requests are dispatched round-robin across the independent flow engines, so two requests on the same transform can run concurrently on different crypto_engine threads and race on op->keyiv (the CBC IV is rewritten for every request). Move the DMA-mapped key/IV buffer into the per-request context and use the DMA-aligned request context accessors so concurrent requests no longer share it. The per-tfm key is still kept in meson_cipher_tfm_ctx and copied into the request buffer. Signed-off-by: Jose Nieto --- drivers/crypto/amlogic/amlogic-gxl-cipher.c | 20 +++++++++++--------- drivers/crypto/amlogic/amlogic-gxl.h | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto/amlogic/amlogic-gxl-cipher.c index e3a0b75c7daf..3264264514f5 100644 --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c @@ -64,7 +64,7 @@ static int meson_cipher_do_fallback(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); - struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx_dma(areq); int err; #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG struct skcipher_alg *alg = crypto_skcipher_alg(tfm); @@ -145,7 +145,7 @@ static void meson_unmap_scatterlist(struct skcipher_request *areq, struct meson_ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) { - struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx_dma(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt = container_of(alg, @@ -161,7 +161,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) return; if (blockmode == DESC_OPMODE_CBC) { - memcpy(op->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); + memcpy(rctx->keyiv + AES_MAX_KEY_SIZE, ctx->areq->iv, ivsize); dma_sync_single_for_device(mc->dev, ctx->keyiv.addr, ctx->keyiv.len, DMA_TO_DEVICE); } @@ -185,7 +185,7 @@ static void meson_setup_keyiv_descs(struct cipher_ctx *ctx) static bool meson_setup_data_descs(struct cipher_ctx *ctx) { - struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx_dma(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); @@ -228,7 +228,7 @@ static bool meson_setup_data_descs(struct cipher_ctx *ctx) static int meson_kick_hardware(struct cipher_ctx *ctx) { - struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(ctx->areq); + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx_dma(ctx->areq); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(ctx->areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm); @@ -301,7 +301,7 @@ static int meson_cipher(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); - struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx_dma(areq); struct meson_dev *mc = op->mc; struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct meson_alg_template *algt; @@ -336,7 +336,9 @@ static int meson_cipher(struct skcipher_request *areq) if (algt->blockmode == DESC_OPMODE_CBC) ctx.keyiv.len = AES_MAX_KEY_SIZE + ivsize; - ctx.keyiv.addr = dma_map_single(mc->dev, op->keyiv, ctx.keyiv.len, + memcpy(rctx->keyiv, op->keyiv, AES_MAX_KEY_SIZE); + + ctx.keyiv.addr = dma_map_single(mc->dev, rctx->keyiv, ctx.keyiv.len, DMA_TO_DEVICE); err = dma_mapping_error(mc->dev, ctx.keyiv.addr); if (err) { @@ -395,7 +397,7 @@ static int meson_skdecrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); - struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx_dma(areq); struct crypto_engine *engine; int e; @@ -413,7 +415,7 @@ static int meson_skencrypt(struct skcipher_request *areq) { struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct meson_cipher_tfm_ctx *op = crypto_skcipher_ctx_dma(tfm); - struct meson_cipher_req_ctx *rctx = skcipher_request_ctx(areq); + struct meson_cipher_req_ctx *rctx = skcipher_request_ctx_dma(areq); struct crypto_engine *engine; int e; diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h index e76576f05271..2a298763b99b 100644 --- a/drivers/crypto/amlogic/amlogic-gxl.h +++ b/drivers/crypto/amlogic/amlogic-gxl.h @@ -125,10 +125,12 @@ struct meson_dev { /* * struct meson_cipher_req_ctx - context for a skcipher request + * @keyiv: per-request key/IV buffer (DMA-mapped) * @op_dir: direction (encrypt vs decrypt) for this request * @flow: the flow to use for this request */ struct meson_cipher_req_ctx { + u8 keyiv[AES_MAX_KEY_SIZE + AES_BLOCK_SIZE]; u32 op_dir; int flow; struct skcipher_request fallback_req; // keep at the end -- 2.47.3 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic