Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Jesper Dangaard Brouer <jbrouer@redhat.com>
Cc: Alexander Duyck <alexander.duyck@gmail.com>,
	Yunsheng Lin <linyunsheng@huawei.com>,
	brouer@redhat.com, David Miller <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Russell King - ARM Linux <linux@armlinux.org.uk>,
	Marcin Wojtas <mw@semihalf.com>,
	linuxarm@openeuler.org, yisen.zhuang@huawei.com,
	Salil Mehta <salil.mehta@huawei.com>,
	thomas.petazzoni@bootlin.com, hawk@kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Will Deacon <will@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	fenghua.yu@intel.com, guro@fb.com, Peter Xu <peterx@redhat.com>,
	Feng Tang <feng.tang@intel.com>, Jason Gunthorpe <jgg@ziepe.ca>,
	Matteo Croce <mcroce@microsoft.com>,
	Hugh Dickins <hughd@google.com>,
	Jonathan Lemon <jonathan.lemon@gmail.com>,
	Alexander Lobakin <alobakin@pm.me>,
	Willem de Bruijn <willemb@google.com>,
	wenxu@ucloud.cn, Cong Wang <cong.wang@bytedance.com>,
	Kevin Hao <haokexin@gmail.com>,
	nogikh@google.com, Marco Elver <elver@google.com>,
	Yonghong Song <yhs@fb.com>,
	kpsingh@kernel.org, andrii@kernel.org,
	Martin KaFai Lau <kafai@fb.com>,
	songliubraving@fb.com, Netdev <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH rfc v3 2/4] page_pool: add interface for getting and setting pagecnt_bias
Date: Mon, 12 Jul 2021 21:08:02 +0300	[thread overview]
Message-ID: <YOyFAkahxxMKNeGb@enceladus> (raw)
In-Reply-To: <2d9a3d29-8e6b-8462-c410-6b7fd4518c9d@redhat.com>

[...]
> > > +static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
> > >   {
> > > +       if (WARN_ON(addr & ~PAGE_MASK))
> > > +               return false;
> > > +
> > >          page->dma_addr[0] = addr;
> > >          if (sizeof(dma_addr_t) > sizeof(unsigned long))
> > >                  page->dma_addr[1] = upper_32_bits(addr);
> > > +
> > > +       return true;
> > > +}
> > > +
> > 
> > Rather than making this a part of the check here it might make more
> > sense to pull this out and perform the WARN_ON after the check for
> > dma_mapping_error.
> 
> I need to point out that I don't like WARN_ON and BUG_ON code in fast-path
> code, because compiler adds 'ud2' assembler instructions that influences the
> instruction-cache fetching in the CPU.  Yes, I have seen a measuresable
> impact from this before.
> 
> 
> > Also it occurs to me that we only really have to do this in the case
> > where dma_addr_t is larger than the size of a long. Otherwise we could
> > just have the code split things so that dma_addr[0] is the dma_addr
> > and dma_addr[1] is our pagecnt_bias value in which case we could
> > probably just skip the check.
> 
> The dance to get 64-bit DMA addr on 32-bit systems is rather ugly and
> confusing, sadly.  We could take advantage of this, I just hope this will
> not make it uglier.

Note here that we can only use this because dma_addr is not aliased to
compound page anymore (after the initial page_pool recycling patchset). 
We must keep this in mind if we even restructure struct page.

Can we do something more radical for this? The 64/32 bit dance is only
there for 32 bit systems with 64 bit dma.  Since the last time we asked
about this no one seemed to care about these, and I really doubt we'll get
an ethernet driver for them (that needs recycling....), can we *only* support 
frag allocation and recycling for 'normal' systems? We could always just r
e-purpose dma_addr[1] for those.

Regards
/Ilias

> 
> 
> > > +static inline int page_pool_get_pagecnt_bias(struct page *page)
> > > +{
> > > +       return READ_ONCE(page->dma_addr[0]) & ~PAGE_MASK;
> > > +}
> > > +
> > > +static inline unsigned long *page_pool_pagecnt_bias_ptr(struct page *page)
> > > +{
> > > +       return page->dma_addr;
> > > +}
> > > +
> > > +static inline void page_pool_set_pagecnt_bias(struct page *page, int bias)
> > > +{
> > > +       unsigned long dma_addr_0 = READ_ONCE(page->dma_addr[0]);
> > > +
> > > +       dma_addr_0 &= PAGE_MASK;
> > > +       dma_addr_0 |= bias;
> > > +
> > > +       WRITE_ONCE(page->dma_addr[0], dma_addr_0);
> > >   }
> > > 
> > >   static inline bool is_page_pool_compiled_in(void)
> > > diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> > > index 78838c6..1abefc6 100644
> > > --- a/net/core/page_pool.c
> > > +++ b/net/core/page_pool.c
> > > @@ -198,7 +198,13 @@ static bool page_pool_dma_map(struct page_pool *pool, struct page *page)
> > >          if (dma_mapping_error(pool->p.dev, dma))
> > >                  return false;
> > > 
> > 
> > So instead of adding to the function below you could just add your
> > WARN_ON check here with the unmapping call.
> > 
> > > -       page_pool_set_dma_addr(page, dma);
> > > +       if (unlikely(!page_pool_set_dma_addr(page, dma))) {
> > > +               dma_unmap_page_attrs(pool->p.dev, dma,
> > > +                                    PAGE_SIZE << pool->p.order,
> > > +                                    pool->p.dma_dir,
> > > +                                    DMA_ATTR_SKIP_CPU_SYNC);
> > > +               return false;
> > > +       }
> > > 
> > >          if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV)
> > >                  page_pool_dma_sync_for_device(pool, page, pool->p.max_len);
> > > --
> > > 2.7.4
> > > 
> > 
> 

  reply	other threads:[~2021-07-12 18:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12 12:16 [PATCH rfc v3 0/4] add frag page support in page pool Yunsheng Lin
2021-07-12 12:16 ` [PATCH rfc v3 1/4] page_pool: keep pp info as long as page pool owns the page Yunsheng Lin
2021-07-12 12:16 ` [PATCH rfc v3 2/4] page_pool: add interface for getting and setting pagecnt_bias Yunsheng Lin
2021-07-12 16:02   ` Alexander Duyck
2021-07-12 17:20     ` Jesper Dangaard Brouer
2021-07-12 18:08       ` Ilias Apalodimas [this message]
2021-07-13  6:38         ` Yunsheng Lin
2021-07-12 12:16 ` [PATCH rfc v3 3/4] page_pool: add frag page recycling support in page pool Yunsheng Lin
2021-07-12 19:46   ` Alexander Duyck
2021-07-13  7:20     ` Yunsheng Lin
2021-07-12 12:16 ` [PATCH rfc v3 4/4] net: hns3: support skb's frag page recycling based on " Yunsheng Lin
  -- strict thread matches above, loose matches on Subject: below --
2021-07-12  9:19 [PATCH rfc v3 0/4] add frag page support in " Yunsheng Lin
2021-07-12  9:19 ` [PATCH rfc v3 2/4] page_pool: add interface for getting and setting pagecnt_bias Yunsheng Lin

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=YOyFAkahxxMKNeGb@enceladus \
    --to=ilias.apalodimas@linaro.org \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.duyck@gmail.com \
    --cc=alobakin@pm.me \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=cong.wang@bytedance.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=elver@google.com \
    --cc=feng.tang@intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=guro@fb.com \
    --cc=haokexin@gmail.com \
    --cc=hawk@kernel.org \
    --cc=hughd@google.com \
    --cc=jbrouer@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=john.fastabend@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxarm@openeuler.org \
    --cc=linyunsheng@huawei.com \
    --cc=mcroce@microsoft.com \
    --cc=mw@semihalf.com \
    --cc=netdev@vger.kernel.org \
    --cc=nogikh@google.com \
    --cc=peterx@redhat.com \
    --cc=peterz@infradead.org \
    --cc=salil.mehta@huawei.com \
    --cc=songliubraving@fb.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vbabka@suse.cz \
    --cc=wenxu@ucloud.cn \
    --cc=will@kernel.org \
    --cc=willemb@google.com \
    --cc=willy@infradead.org \
    --cc=yhs@fb.com \
    --cc=yisen.zhuang@huawei.com \
    --subject='Re: [PATCH rfc v3 2/4] page_pool: add interface for getting and setting pagecnt_bias' \
    /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

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).