From: Mikulas Patocka <mpatocka@redhat.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>,
Harald Freudenberger <freude@linux.ibm.com>,
linux-crypto@vger.kernel.org, dm-devel@lists.linux.dev,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
Helge Deller <deller@gmx.de>,
John David Anglin <dave.anglin@bell.net>,
linux-parisc@vger.kernel.org
Subject: Re: crypto ahash requests on the stack
Date: Mon, 1 Sep 2025 14:04:38 +0200 (CEST) [thread overview]
Message-ID: <90c8cedd-cdad-c528-2771-829a66e08e33@redhat.com> (raw)
In-Reply-To: <aK7Rl7YC1bTlZWcL@gondor.apana.org.au>
On Wed, 27 Aug 2025, Herbert Xu wrote:
> On Mon, Aug 25, 2025 at 04:23:59PM +0200, Mikulas Patocka wrote:
> >
> > I'd like to ask about this condition in crypto_ahash_digest:
> > if (ahash_req_on_stack(req) && ahash_is_async(tfm))
> > return -EAGAIN;
> >
> > Can it be removed? Or, is there some reason why you can't have
> > asynchronous requests on the stack (such as inability of doing DMA to
> > virtually mapped stack)?
>
> Right, in general you can't use stack requests for async hash
> because they may DMA to the request memory.
Thanks for the confirmation.
BTW. what happens if you have an architecture that needs cacheline-aligned
DMA accesses? For example, on parisc, some microarchitectures have
128-byte cache line. As caches on parisc are not DMA-coherent, you must
not touch the 128-byte region around the area where you are doing DMA.
Normally, this problem is solved by tweaking kmalloc, so that the minimum
allocation size and alignment is 128 bytes. But if you do DMA into struct
ahash_request, and struct ahash_request may be embedded in other
structures, and doesn't have 128-byte alignment, it could break.
> So what I can do is bypass the ahash_req_on_stack for Harald's
> driver by changing the ahash_is_async test to something more
> specific about DMA. Let me write that up and I'll have something
> for you to test in a couple of days.
>
> Cheers,
I reworked my patchset so that it places asynchronous requests after the
dm_integrity_io structure (that is allocated in directly mapped memory),
so there are no longer any needs to change the crypto code.
Maybe I should allocate the ahash requests with kmalloc, to solve the
DMA-into-request problem.
Mikulas
parent reply other threads:[~2025-09-01 12:04 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <aK7Rl7YC1bTlZWcL@gondor.apana.org.au>]
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=90c8cedd-cdad-c528-2771-829a66e08e33@redhat.com \
--to=mpatocka@redhat.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=dave.anglin@bell.net \
--cc=davem@davemloft.net \
--cc=deller@gmx.de \
--cc=dm-devel@lists.linux.dev \
--cc=freude@linux.ibm.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-parisc@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;
as well as URLs for NNTP newsgroup(s).