From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796208111; b=aMFhqfeu0z5BzkFXRVuZ2FNwu4DjgtSZadyH4vRLCwIoKpvJ6irDW6n3gCwJx+r0IW0S 18mlTnu4iXHNRVKs2XYlV+crCcJrfGITH8JiwWrGwT0ARwkJxMokryruN3Z5BlqK2XrYW dalf7I2ZtghOEQxnAYtu6EQPGySy5g89BMQ/BNi+FbaLanCcWQZLaKhBA4SuoNEB2c6tE BjCUjCNbTGD996G9CzYuWGADg5gS0HXF7coxdePtfMhAloIaGcy+/SoI2oAxGMoI/yFBE nZ60koxZx1zEfAKqtsqLLQFEQUpuM9x74DyIflEZohdqHnbLAwvelEAWgFHQhd9toGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208111; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=UoMOkgi3TKnnDrPK3DhWjuvRpbzF0dANIFVO3Q11688=; b=VR0tNNxiLLd8t/mTAlozqrls2P5UrErO0aVj0H7Y+uwQCipS9fdXVrRGMcLy/5s2Lp26 FwnrcjZAuyqIlPW7DXkAyBpKZ38qza+Q60TDtWcnFPiHDHG01ds/j1CyZUWhavEbQ2OAq bTXzHAQH3UjaydZrPscw2ZdKslhOSgK//+FZQt/rOiSsTNZuswZbYELTGIrMF5VpCVTv1 4WGDNf4fvzFUZ7i5AmbliRV2Av54Fs4OH+2mpG+9qFcVsh85+xaFrxAq5I6opgrwjywkW Ps8r9qMyPDRXRxOw4Lp42uvgOxWeWPRRI9D5Jt1ntt9fVPBFdt1NLihfTzNgVHKXu1A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P4XiX0LF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4AE1606A687; Wed, 2 Dec 2026 10:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P4XiX0LF Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9F321F00896; Wed, 2 Dec 2026 10:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796208109; bh=UoMOkgi3TKnnDrPK3DhWjuvRpbzF0dANIFVO3Q11688=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=P4XiX0LF6tjzhhtv8d1kVyLGCvPpPh0LyEOBclTU+stPJD+nHkHNlsVEdT92SgfYn U7yR00NeB3l9j/IalHQjejBvb4RnO8tuIOmvxPseGI8CKXrH3HxSW+fZ3q5Z8+maUF g51dlBR/jg4OsokuZrNd5zujkHxb9lzXU0IgMzgY+7xtYpzvpw3G/+TSzyK5QXQkQ2 5IMYjDfm/EflGjPMqqc+TVDoDFabHlch8AwuX86V8Dv+do25Nx4KXe1QqCmULa8ivv xIjBuCATBJLD9TRFNc/t6luX8fT5aXnS1Nto+eZqMkAFFQhd0RZpNvRG8kGYtydjmN WAS9m/3nOLWvA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v15 11/35] crypto: amlogic - Process more than MAXDESCS descriptors Reply-To: sashiko-reviews@lists.linux.dev To: "Jose Nieto" , "Corentin Labbe" , "Herbert Xu" , "David S . Miller" Cc: linux-crypto@vger.kernel.org, linux-amlogic@lists.infradead.org, devicetree@vger.kernel.org, "Neil Armstrong" , "Kevin Hilman" , "Jerome Brunet" , "Martin Blumenstingl" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , "Alexey Romanov" In-Reply-To: <20261202100714.115460-12-jnieto.alaber@gmail.com> References: <20261202100714.115460-1-jnieto.alaber@gmail.com> <20261202100714.115460-12-jnieto.alaber@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 10:41:47 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] crypto: amlogic: bad DMA sync and sg_virt() offset in meson_kick_hardware() -- commit 9ef5ecacd53eb7473d5f6fbe59891e20dfe4da6d Author: Alexey Romanov crypto: amlogic - Process more than MAXDESCS descriptors This commit refactors the Amlogic GXL skcipher driver to split large requests across multiple descriptor batches and adds a platform data field for the number of KEY/IV setup descriptors. > diff --git a/drivers/crypto/amlogic/amlogic-gxl-cipher.c b/drivers/crypto= /amlogic/amlogic-gxl-cipher.c > index c17ce5cc70a87..cb6b959bb1f96 100644 > --- a/drivers/crypto/amlogic/amlogic-gxl-cipher.c > +++ b/drivers/crypto/amlogic/amlogic-gxl-cipher.c [ ... ] > @@ -76,6 +82,213 @@ static int meson_cipher_do_fallback(struct skcipher_r= equest *areq) [ ... ] > +static bool meson_setup_data_descs(struct cipher_ctx *ctx) > +{ [ ... ] > + todo =3D min(ctx->cryptlen, maxlen); > + todo =3D min(todo, ctx->cryptlen); > + todo =3D min(todo, sg_dma_len(ctx->src_sg) - ctx->src_offset); > + todo =3D min(todo, sg_dma_len(ctx->dst_sg) - ctx->dst_offset); > + > + desc->t_src =3D cpu_to_le32(sg_dma_address(ctx->src_sg) + ctx->src_offs= et); > + desc->t_dst =3D cpu_to_le32(sg_dma_address(ctx->dst_sg) + ctx->dst_offs= et); > + > + ctx->cryptlen -=3D todo; > + ctx->src_offset +=3D todo; > + ctx->dst_offset +=3D todo; [ ... ] > +} > + > +static int meson_kick_hardware(struct cipher_ctx *ctx) > +{ > + struct meson_cipher_req_ctx *rctx =3D skcipher_request_ctx(ctx->areq); > + struct crypto_skcipher *tfm =3D crypto_skcipher_reqtfm(ctx->areq); > + struct meson_cipher_tfm_ctx *op =3D crypto_skcipher_ctx(tfm); > + struct skcipher_alg *alg =3D crypto_skcipher_alg(tfm); > + struct meson_alg_template *algt =3D container_of(alg, > + struct meson_alg_template, > + alg.skcipher.base); > + struct meson_dev *mc =3D op->mc; > + unsigned int ivsize =3D crypto_skcipher_ivsize(tfm); > + unsigned int blockmode =3D algt->blockmode; > + enum dma_data_direction new_iv_dir; > + struct scatterlist *sg_head; > + void *new_iv; > + int err; > + > + if (blockmode =3D=3D DESC_OPMODE_CBC) { > + struct scatterlist *sg_current; > + unsigned int offset; > + > + if (rctx->op_dir =3D=3D MESON_ENCRYPT) { > + sg_current =3D ctx->dst_sg; > + sg_head =3D ctx->areq->dst; > + offset =3D ctx->dst_offset; > + new_iv_dir =3D DMA_FROM_DEVICE; > + } else { > + sg_current =3D ctx->src_sg; > + sg_head =3D ctx->areq->src; > + offset =3D ctx->src_offset; > + new_iv_dir =3D DMA_TO_DEVICE; > + } > + > + if (ctx->areq->src =3D=3D ctx->areq->dst) > + new_iv_dir =3D DMA_BIDIRECTIONAL; > + > + offset -=3D ivsize; > + new_iv =3D sg_virt(sg_current) + offset; > + } > + > + if (blockmode =3D=3D DESC_OPMODE_CBC && > + rctx->op_dir =3D=3D MESON_DECRYPT) { > + dma_sync_sg_for_cpu(mc->dev, sg_head, > + sg_nents(sg_head), new_iv_dir); > + memcpy(ctx->areq->iv, new_iv, ivsize); > + } > + > + reinit_completion(&mc->chanlist[rctx->flow].complete); > + meson_dma_start(mc, rctx->flow); > + err =3D wait_for_completion_interruptible_timeout(&mc->chanlist[rctx->f= low].complete, > + msecs_to_jiffies(500)); > + if (err =3D=3D 0) { > + dev_err(mc->dev, "DMA timeout for flow %d\n", rctx->flow); > + return -EINVAL; > + } else if (err < 0) { > + dev_err(mc->dev, "Waiting for DMA completion is failed (%d)\n", err); > + return err; > + } > + > + if (blockmode =3D=3D DESC_OPMODE_CBC && > + rctx->op_dir =3D=3D MESON_ENCRYPT) { > + dma_sync_sg_for_cpu(mc->dev, sg_head, > + sg_nents(sg_head), new_iv_dir); > + memcpy(ctx->areq->iv, new_iv, ivsize); > + } [Severity: Medium] Does meson_kick_hardware() violate the DMA API ownership rules and perform quadratic cache syncs on multi-batch CBC requests? On every batch, dma_sync_sg_for_cpu() walks and syncs the entire scatterlist from sg_head just to read the 16-byte IV, without calling dma_sync_sg_for_device() before meson_dma_start() on the current decrypt batch or subsequent encrypt batches. On MESON_DECRYPT, copying new_iv into ctx->areq->iv before meson_dma_start() also clobbers the caller's IV if wait_for_completion_interruptible_timeout() times out or is interrupted. In addition, ctx->src_offset and ctx->dst_offset are bounded by sg_dma_len() in meson_setup_data_descs(), so indexing sg_virt(sg_current) by offset can read past sg_current->length if dma_map_sg() coalesces segments. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202100714.1154= 60-1-jnieto.alaber@gmail.com?part=3D11