All of lore.kernel.org
 help / color / mirror / Atom feed
From: Byungchul Park <byungchul@sk.com>
To: Mina Almasry <almasrymina@google.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, hawk@kernel.org,
	toke@redhat.com, asml.silence@gmail.com, kernel_team@skhynix.com
Subject: Re: [RFC net-next] netmem: replace __netmem_clear_lsb() with netmem_to_nmdesc()
Date: Tue, 29 Jul 2025 10:10:24 +0900	[thread overview]
Message-ID: <20250729011024.GD56089@system.software.com> (raw)
In-Reply-To: <CAHS8izPv8zmPaxzCSPAnybiCc0KrqjEZA+x5wpFOE8u=_nM1WA@mail.gmail.com>

On Mon, Jul 28, 2025 at 10:44:31AM -0700, Mina Almasry wrote:
> On Sun, Jul 27, 2025 at 9:21 PM Byungchul Park <byungchul@sk.com> wrote:
> >
> > Now that we have struct netmem_desc, it'd better access the pp fields
> > via struct netmem_desc rather than struct net_iov.
> >
> > Introduce netmem_to_nmdesc() for safely converting netmem_ref to
> > netmem_desc regardless of the type underneath e.i. netmem_desc, net_iov.
> >
> > While at it, remove __netmem_clear_lsb() and make netmem_to_nmdesc()
> > used instead.
> >
> > Signed-off-by: Byungchul Park <byungchul@sk.com>
> 
> Thank you for working on paying this tech debt!

I thought it was appropriate to organize the code I modified to some
extent.

> > ---
> >  include/net/netmem.h   | 33 ++++++++++++++++-----------------
> >  net/core/netmem_priv.h | 16 ++++++++--------
> >  2 files changed, 24 insertions(+), 25 deletions(-)
> >
> > diff --git a/include/net/netmem.h b/include/net/netmem.h
> > index f7dacc9e75fd..33ae444a9745 100644
> > --- a/include/net/netmem.h
> > +++ b/include/net/netmem.h
> > @@ -265,24 +265,23 @@ static inline struct netmem_desc *__netmem_to_nmdesc(netmem_ref netmem)
> >         return (__force struct netmem_desc *)netmem;
> >  }
> >
> > -/* __netmem_clear_lsb - convert netmem_ref to struct net_iov * for access to
> > - * common fields.
> > - * @netmem: netmem reference to extract as net_iov.
> > +/* netmem_to_nmdesc - convert netmem_ref to struct netmem_desc * for
> > + * access to common fields.
> > + * @netmem: netmem reference to get netmem_desc.
> >   *
> > - * All the sub types of netmem_ref (page, net_iov) have the same pp, pp_magic,
> > - * dma_addr, and pp_ref_count fields at the same offsets. Thus, we can access
> > - * these fields without a type check to make sure that the underlying mem is
> > - * net_iov or page.
> > + * All the sub types of netmem_ref (netmem_desc, net_iov) have the same
> > + * pp, pp_magic, dma_addr, and pp_ref_count fields via netmem_desc.
> >   *
> > - * The resulting value of this function can only be used to access the fields
> > - * that are NET_IOV_ASSERT_OFFSET'd. Accessing any other fields will result in
> > - * undefined behavior.
> > - *
> 
> I think instead of removing this warning, we want to add an
> NET_IOV_ASSERT_OFFSET that asserts that net_iov->netmem_desc and
> page->netmem_desc are in the same offset, and then add a note here
> that this works because we assert that the netmem_desc offset in both
> net_iov and page are the same.

It doesn't have to have the same offset.  Why do you want it?  Is it for
some optimizaiton?  Or I think it's unnecessary constraint.

> > - * Return: the netmem_ref cast to net_iov* regardless of its underlying type.
> > + * Return: the pointer to struct netmem_desc * regardless of its
> > + * underlying type.
> >   */
> > -static inline struct net_iov *__netmem_clear_lsb(netmem_ref netmem)
> > +static inline struct netmem_desc *netmem_to_nmdesc(netmem_ref netmem)
> >  {
> > -       return (struct net_iov *)((__force unsigned long)netmem & ~NET_IOV);
> > +       if (netmem_is_net_iov(netmem))
> > +               return &((struct net_iov *)((__force unsigned long)netmem &
> > +                                           ~NET_IOV))->desc;
> > +
> > +       return __netmem_to_nmdesc(netmem);
> 
> The if statement generates overhead. I'd rather avoid it. We can
> implement netmem_to_nmdesc like this, no?
> 
> netmem_to_nmdesc(netmem_ref netmem)
> {
>   return (struct netmem_desc)((__force unsigned long)netmem & ~NET_IOV);
> }

I see.  You want this kind of optimization.  I will do this way if you
want.

> Because netmem_desc is the first element in both net_iov and page for
> the moment. (yes I know that will change eventually, but we don't have
> to incur overhead of an extra if statement until netmem_desc is
> removed from page, right?)

Okay.

	Byungchul
> 
> 
> --
> Thanks,
> Mina

      parent reply	other threads:[~2025-07-29  1:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28  4:20 [RFC net-next] netmem: replace __netmem_clear_lsb() with netmem_to_nmdesc() Byungchul Park
2025-07-28  5:35 ` Byungchul Park
2025-07-28 17:44 ` Mina Almasry
2025-07-28 18:46   ` Pavel Begunkov
2025-07-28 18:58     ` Pavel Begunkov
2025-07-29  1:17       ` Byungchul Park
2025-07-29  9:11         ` Pavel Begunkov
2025-07-29  1:10   ` Byungchul Park [this message]

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=20250729011024.GD56089@system.software.com \
    --to=byungchul@sk.com \
    --cc=almasrymina@google.com \
    --cc=asml.silence@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=kernel_team@skhynix.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=toke@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.