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


Reply via email to