Re: [PATCH v11 3/3] crypto: Add Inside Secure SafeXcel EIP-93 crypto engine support
From: Christian Marangi (Ansuel)
Date: Tue Apr 01 2025 - 07:21:12 EST
Il giorno mar 1 apr 2025 alle ore 12:57 Herbert Xu
<herbert@xxxxxxxxxxxxxxxxxxx> ha scritto:
>
> On Tue, Apr 01, 2025 at 12:54:05PM +0200, Christian Marangi (Ansuel) wrote:
> > Il giorno mar 1 apr 2025 alle ore 12:08 Herbert Xu
> > <herbert@xxxxxxxxxxxxxxxxxxx> ha scritto:
> > >
> > > On Tue, Jan 14, 2025 at 01:36:36PM +0100, Christian Marangi wrote:
> > > >
> > > > +static int eip93_send_hash_req(struct crypto_async_request *async, u8 *data,
> > > > + dma_addr_t *data_dma, u32 len, bool last)
> > > > +{
> > >
> > > ...
> > >
> > > > +again:
> > > > + ret = eip93_put_descriptor(eip93, &cdesc);
> > > > + if (ret) {
> > > > + usleep_range(EIP93_RING_BUSY_DELAY,
> > > > + EIP93_RING_BUSY_DELAY * 2);
> > > > + goto again;
> > > > + }
> > > > +
> > > > + /* Writing new descriptor count starts DMA action */
> > > > + writel(1, eip93->base + EIP93_REG_PE_CD_COUNT);
> > >
> > > Why is there no locking here? Shouldn't this be under ring->write_lock?
> > >
> >
> > Hi Herbert,
> > this is really to tell DMA that there is new packet to process and
> > gets decreased instantly.
> > The lock is used to track what descriptor index should be used in the
> > ring in the put and get
> > functions.
>
> AFAICS it's not safe to call eip93_put_descriptor simultaneously
> since it doesn't use atomics. Without locking in eip93_send_hash_req
> two threads hashing into two separate eip93 requests will be calling
> eip93_put_descriptor at the same time.
>
Sorry but isn't it enough to acquire lock before eip93_put_descriptor to
prevent 2 thread?
Or you are suggesting that also
writel(1, eip93->base + EIP93_REG_PE_CD_COUNT);
should be done atomically?
Maybe I can better handle that writel(1) by using atomic_t
value and atomic_inc/dec?