netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
	pabeni@redhat.com, johannes@sipsolutions.net,
	pablo@netfilter.org, laforge@gnumonks.org, Jason@zx2c4.com,
	leonro@nvidia.com
Subject: Re: [RFC net-next] net: add ndo_alloc_and_init and ndo_release to replace priv_destructor
Date: Wed, 11 May 2022 20:43:28 -0300	[thread overview]
Message-ID: <20220511234328.GO49344@nvidia.com> (raw)
In-Reply-To: <20220511191218.1402380-1-kuba@kernel.org>

On Wed, May 11, 2022 at 12:12:18PM -0700, Jakub Kicinski wrote:
> Old API
> -------
> Our current API includes .ndo_init, .ndo_uninit and .priv_destructor.
> First two are part of netdev_ops the last one is a member of netdevice
> and can be overwritten at will by the drivers.

ipoib runs into this trouble, it would be nice to see it improved, but
I'm not seeing how this helps..

> BTW as far as I can tell there is no strong reason for .ndo_init
> to exist. It gets called early during registration after
> netdev's name gets filled in, and none of the users I checked
> care about the name. They could have as well run the code
> they have in .ndo_init before calling register_netdevice().

Well, exactly. This is sort of where ipoib ends up - and it is
complicated enough that moving everything into ndo_init isn't
something obviously doable - there are several ndo_inits and several
different driver flows involved here.

So, the proposal here seems to be to rename ndo_init but otherwise
keep the lifecycle model the same - and with a now const ops it is
basically hopeless to do anything that needs to be undone before
register_netdev()?

I would be happier if netdev was more like everything else and allowed
a clean alloc/free vs register/unregister pairing. The usual lifecycle
model cast to netdev terms would have the release function set around
alloc_netdev and always called once at free_netdev.

The caller should set the ops and release function after it has
completed initializing whatever its release will undo, similare to how
device_initialize()/put_device works.

IIRC priv_destructor is really only needed when needs_free_netdev is
used, and the real point is to reliably inject code before
free_netdev.

> A common workaround is to set .priv_destructor after
> register_netdevice() succeeds. This works fine in practice but
> is not always correct. Theoretically something may nack the

ipoib does this, but I don't think it has a problem because it does
the priv_destructor action manually on the error path after
register_netdev fails and then leaves priv_destructor NULL'd so that
the later queued unregister doesn't double call it.

> We want an intuitive API, which I think should mean symmetric
> ndo callbacks only. There is no point in having two steps at
> init time so this patch renames .ndo_init as .ndo_alloc_and_init.

What does it alloc? It doesn't alloc the priv, that was done
earlier. It seems like a more confusing name than ndo_init to me.

Jason

  parent reply	other threads:[~2022-05-11 23:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-11 19:12 [RFC net-next] net: add ndo_alloc_and_init and ndo_release to replace priv_destructor Jakub Kicinski
2022-05-11 21:11 ` Jakub Kicinski
2022-05-11 23:43 ` Jason Gunthorpe [this message]
2022-05-13  5:47   ` Leon Romanovsky

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=20220511234328.GO49344@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=Jason@zx2c4.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=laforge@gnumonks.org \
    --cc=leonro@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    /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 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).