mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Sahil Malhotra (OSS)" <sahil.malhotra@oss.nxp.com>
To: Changwei Zou <changwei.zou@canonical.com>,
	Horia Geanta <horia.geanta@nxp.com>,
	Pankaj Gupta <pankaj.gupta@nxp.com>,
	"gaurav.jain@nxp.com" <gaurav.jain@nxp.com>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"davem@davemloft.net" <davem@davemloft.net>
Cc: "linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"lukas@wunner.de" <lukas@wunner.de>
Subject: RE: [EXT] [PATCH 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers
Date: Tue, 29 Sep 2026 11:52:48 +0000	[thread overview]
Message-ID: <DB9PR04MB8139B1C5A2502C01DD260393828C2@DB9PR04MB8139.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20260821045555.806471-3-changwei.zou@canonical.com>

Hi Changwei,

Please find my comment inline.


NXP Confidential
> -----Original Message-----
> From: Changwei Zou <changwei.zou@canonical.com>
> Sent: 21 August 2026 10:26
> To: Horia Geanta <horia.geanta@nxp.com>; Pankaj Gupta
> <pankaj.gupta@nxp.com>; gaurav.jain@nxp.com;
> herbert@gondor.apana.org.au; davem@davemloft.net
> Cc: linux-crypto@vger.kernel.org; linux-kernel@vger.kernel.org;
> lukas@wunner.de; changwei.zou@canonical.com
> Subject: [EXT] [PATCH 2/2] crypto: caam - Use bounce buffer for unaligned
> RSA destination buffers
>
> Caution: This is an external email. Please take care when clicking links or
> opening attachments. When in doubt, report the message using the 'Report
> this email' button
>
>
> The rsa-caam driver directly DMA-maps the destination buffer supplied by the
> caller via req->dst without checking whether it meets the cacheline alignment
> requirements of DMA-incoherent hardware such as i.MX8.
>
> On CPUs with non-coherent DMA caches, if the destination buffer shares a
> cacheline with other data (i.e. it is not cacheline-aligned), cache
> writeback/invalidation during DMA can corrupt adjacent memory or cause
> stale data to be read back. This manifests as intermittent -EKEYREJECTED errors
> when loading signed kernel modules.
>
> When any segment of req->dst is not cacheline-aligned in either its start offset
> or length, allocate a single contiguous aligned bounce buffer covering the full
> dst_len rounded up to a cacheline multiple, redirect the operation to it, and
> copy the result back to the original destination once the hardware has
> completed successfully.
>
> Introduce a helper sg_is_dma_aligned() that checks both sg->offset and
> sg->length for cacheline alignment. Checking sg->offset suffices for
> the start address since physical pages are always page-aligned and PAGE_SIZE
> is a multiple of dma_get_cache_alignment(). sg->length is also checked to
> ensure the buffer end does not share a cacheline with adjacent memory.
>
> The intermittent error 'Key was rejected by service' on i.MX8 with CAAM can
> be triggered when loading signed kernel modules:
>
>     for i in $(seq 1 100); do
>         sudo modprobe xfs 2>&1 && echo "SUCCESS on attempt $i" \
>         && sudo rmmod xfs || echo "FAILED on attempt $i"
>     done
>
> Signed-off-by: Changwei Zou <changwei.zou@canonical.com>
> Assisted-by: OpenCode:claude-sonnet-4.6
> ---
>  drivers/crypto/caam/caampkc.c | 77
> ++++++++++++++++++++++++++++++++++-
>  drivers/crypto/caam/caampkc.h |  6 +++
>  2 files changed, 82 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/crypto/caam/caampkc.c b/drivers/crypto/caam/caampkc.c
> index 840271840cce..11c6b07f5dad 100644
> --- a/drivers/crypto/caam/caampkc.c
> +++ b/drivers/crypto/caam/caampkc.c
> @@ -59,6 +59,40 @@ static void rsa_io_unmap(struct device *dev, struct
> rsa_edesc *edesc,
>                                  DMA_TO_DEVICE);  }
>
> +static int do_rsa_bounce_buf(struct akcipher_request *req, int req_err)
> +{
> +       struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
> +       int nents, err = 0;
> +
> +       if (!req_ctx->bounce_buf)
> +               return 0;
Please add this check in rsa_bounce_buf_done() and return from there only.
We need not to come here to return.


> +
> +       /* Only copy back to the original destination on success */
> +       if (!req_err) {
> +               nents = sg_nents_for_len(req_ctx->orig_dst, req->dst_len);
> +               if (nents < 0)
> +                       err = nents;
> +               else if (sg_copy_from_buffer(req_ctx->orig_dst, nents,
> +                                            req_ctx->bounce_buf,
> +                                            req->dst_len) != req->dst_len)
> +                       err = -EFAULT;
> +       }
> +


  reply	other threads:[~2026-09-29 11:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  4:55 [PATCH 0/2] crypto: caam - Fix rsa-caam unmap and DMA alignment Changwei Zou
2026-08-21  4:55 ` [PATCH 1/2] crypto: caam - Fix wrong unmap operations Changwei Zou
2026-09-29 15:19   ` [EXT] " Sahil Malhotra (OSS)
2026-10-05  2:19     ` Changwei Zou
2026-08-21  4:55 ` [PATCH 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers Changwei Zou
2026-09-29 11:52   ` Sahil Malhotra (OSS) [this message]
2026-09-29 12:28   ` Kepplinger-Novakovic Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB9PR04MB8139B1C5A2502C01DD260393828C2@DB9PR04MB8139.eurprd04.prod.outlook.com \
    --to=sahil.malhotra@oss.nxp.com \
    --cc=changwei.zou@canonical.com \
    --cc=davem@davemloft.net \
    --cc=gaurav.jain@nxp.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=pankaj.gupta@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®