lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191116131741.2657e1bb@carbon>
Date:   Sat, 16 Nov 2019 13:17:41 +0100
From:   Jesper Dangaard Brouer <brouer@...hat.com>
To:     Lorenzo Bianconi <lorenzo@...nel.org>
Cc:     netdev@...r.kernel.org, davem@...emloft.net,
        ilias.apalodimas@...aro.org, lorenzo.bianconi@...hat.com,
        mcroce@...hat.com, brouer@...hat.com
Subject: Re: [PATCH v3 net-next 2/3] net: page_pool: add the possibility to
 sync DMA memory for device

On Sat, 16 Nov 2019 13:36:30 +0200
Lorenzo Bianconi <lorenzo@...nel.org> wrote:

> > On Fri, 15 Nov 2019 21:01:38 +0200
> > Lorenzo Bianconi <lorenzo@...nel.org> wrote:
> >   
> > >  static bool __page_pool_recycle_into_ring(struct page_pool *pool,
> > > -				   struct page *page)
> > > +					  struct page *page,
> > > +					  unsigned int dma_sync_size)
> > >  {
> > >  	int ret;
> > >  	/* BH protection not needed if current is serving softirq */
> > > @@ -264,6 +285,9 @@ static bool __page_pool_recycle_into_ring(struct page_pool *pool,
> > >  	else
> > >  		ret = ptr_ring_produce_bh(&pool->ring, page);
> > >  
> > > +	if (ret == 0 && (pool->p.flags & PP_FLAG_DMA_SYNC_DEV))
> > > +		page_pool_dma_sync_for_device(pool, page, dma_sync_size);
> > > +
> > >  	return (ret == 0) ? true : false;
> > >  }  
> > 
> > 
> > I do wonder if we should DMA-sync-for-device BEFORE putting page into
> > ptr_ring, as this is a channel between several concurrent CPUs.  
> 
> Hi Jesper,
> 
> in this way we can end up syncing the DMA page even if it is unmapped in
> __page_pool_clean_page (e.g. if the ptr_ring is full), right?

Yes.  The call __page_pool_clean_page() will do a dma_unmap_page, so it
should still be safe/correct.   I can see, that it is not optimal
performance wise, in-case the ptr_ring is full, as DMA-sync-for-device
is wasted work.

I don't know if you can find an argument, that proves that it cannot
happen, that a remote CPU can dequeue/consume the page from ptr_ring
and give it to the device, while you (the CPU the enqueued) are still
doing the DMA-sync-for-device.

 
> > > @@ -273,18 +297,22 @@ static bool __page_pool_recycle_into_ring(struct page_pool *pool,
> > >   * Caller must provide appropriate safe context.
> > >   */
> > >  static bool __page_pool_recycle_direct(struct page *page,
> > > -				       struct page_pool *pool)
> > > +				       struct page_pool *pool,
> > > +				       unsigned int dma_sync_size)
> > >  {
> > >  	if (unlikely(pool->alloc.count == PP_ALLOC_CACHE_SIZE))
> > >  		return false;
> > >  
> > >  	/* Caller MUST have verified/know (page_ref_count(page) == 1) */
> > >  	pool->alloc.cache[pool->alloc.count++] = page;
> > > +
> > > +	if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV)
> > > +		page_pool_dma_sync_for_device(pool, page, dma_sync_size);
> > >  	return true;
> > >  }  
> > 
> > We know __page_pool_recycle_direct() is concurrency safe, and only a
> > single (NAPI processing) CPU can enter. (So, the DMA-sync order is not
> > wrong here, but it could be swapped)  
> 
> do you mean move it before putting the page in the cache?
> 
> pool->alloc.cache[pool->alloc.count++] = page;

Yes, but here the order doesn't matter.

If you choose to do the DMA-sync-for-device earlier/before, then look
at the code, and see of it makes sense to do it in __page_pool_put_page() ?
(I've not checked the details)

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ