mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ralf Lici <ralf@mandelbit.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org, Antoine Tenart <atenart@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH crypto 2/2] crypto: safexcel - Map AEAD buffers with accurate DMA directions
Date: Tue, 20 Oct 2026 14:00:42 +0200	[thread overview]
Message-ID: <20261020120042.359215-1-ralf@mandelbit.com> (raw)
In-Reply-To: <atHquk_AUj2Ys7Su@gondor.apana.org.au>

Hi Herbert,

On Fri, 16 Oct 2026 20:13:30 +1100, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> On Tue, Sep 15, 2026 at 01:32:12PM +0200, Ralf Lici wrote:
> >
> > @@ -748,8 +833,17 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring,
> >  			return -EINVAL;
> >  		}
> >  		if (sreq->nr_src > 0) {
> > -			src_mapped = dma_map_sg(priv->dev, src, sreq->nr_src,
> > -						DMA_BIDIRECTIONAL);
> > +			if (ctx->aead)
> > +				src_mapped =
> > +					safexcel_map_aead(priv->dev, src,
> > +							  sreq->nr_src,
> > +							  sreq->output_offset,
> > +							  sreq->output_len,
> > +							  true);
> > +			else
> > +				src_mapped = dma_map_sg(priv->dev, src,
> > +							sreq->nr_src,
> > +							DMA_BIDIRECTIONAL);
>
> This path doesn't actualy matter because BIDIRECTIONAL is safe
> even if you use it unnecessarily.
>
> > @@ -775,8 +869,17 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring,
> >  		}
> >  
> >  		if (sreq->nr_dst > 0) {
> > -			dst_mapped = dma_map_sg(priv->dev, dst, sreq->nr_dst,
> > -						DMA_FROM_DEVICE);
>
> So this is the really buggy path.  Why don't you just change it to
> BIDRECTIONAL, perhaps with a comment referring to the assoc data?
>

I tried that simplification on the MT7986 before respinning, but
unfortunately mapping the complete AEAD destination DMA_BIDIRECTIONAL
does not fix the corruption.

The relevant ovpn layout is physically:

    [ AAD ][ tag ][ payload ]

and is described to the AEAD implementation in logical order as:

    [ AAD ][ payload ][ tag ]

The entries do not overlap in bytes, but a small AAD entry and an
adjacent output entry can share a cache line. When mapped
DMA_BIDIRECTIONAL on this non-coherent system, the AAD entry is bounced.
After the accelerator has written the output to RAM, unmapping the AAD
copies its unchanged bytes back through the CPU. This dirties the CPU's
stale copy of the cache line corresponding to the memory where part of
the accelerator output now resides. Cache maintenance, while unmapping
the adjacent output entry, can then clean that line and overwrite the
output with stale pre-crypto bytes.

This also affects the in-place path. Although an in-place request uses
the same scatterlist as source and destination, its AAD entry remains
input-only. Mapping the whole list DMA_BIDIRECTIONAL therefore gives
that entry an unnecessary and harmful copyback.

So I don't think the source/in-place handling can be dropped on this
platform. I can add the physical/logical layout and the simplified A/B
result to the next cover letter to make the reason for the finer-grained
mapping clearer.

Thanks!

-- 
Ralf Lici
Mandelbit Srl

      reply	other threads:[~2026-10-20 12:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 11:32 [PATCH crypto 0/2] crypto: safexcel: fix AEAD DMA mapping and cleanup Ralf Lici
2026-09-15 11:32 ` [PATCH crypto 1/2] crypto: safexcel - Avoid unmapping failed DMA mappings Ralf Lici
2026-09-15 11:32 ` [PATCH crypto 2/2] crypto: safexcel - Map AEAD buffers with accurate DMA directions Ralf Lici
2026-09-23  5:30   ` Herbert Xu
2026-09-23  7:26     ` Ralf Lici
2026-09-23  8:32       ` Herbert Xu
2026-09-23  9:13         ` Ralf Lici
2026-09-28  5:12           ` Herbert Xu
2026-09-28 10:25             ` Ralf Lici
2026-10-08  7:53               ` Herbert Xu
2026-10-08  8:21                 ` Ralf Lici
2026-10-16  9:13   ` Herbert Xu
2026-10-20 12:00     ` Ralf Lici [this message]

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=20261020120042.359215-1-ralf@mandelbit.com \
    --to=ralf@mandelbit.com \
    --cc=atenart@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®