From: Jakub Kicinski <kuba@kernel.org>
To: David Wei <dw@davidwei.uk>
Cc: Jiri Pirko <jiri@resnulli.us>,
Sabrina Dubroca <sd@queasysnail.net>,
netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH net-next v8 1/4] netdevsim: allow two netdevsim ports to be connected
Date: Wed, 31 Jan 2024 16:57:39 -0800 [thread overview]
Message-ID: <20240131165739.53cf301e@kernel.org> (raw)
In-Reply-To: <20240130214620.3722189-2-dw@davidwei.uk>
On Tue, 30 Jan 2024 13:46:17 -0800 David Wei wrote:
> + err = -EINVAL;
> + rtnl_lock();
> + ns_a = get_net_ns_by_id(current->nsproxy->net_ns, netnsid_a);
I think we should support local netns, i.e. the one which we are
currently in. But by definition it has no id. How about we make the
netns id signed and make -1 mean "use current->nsproxy->net_ns
directly"?
Also you can look up the netns before taking rtnl_lock, they are
not protected by rtnl_lock.
> + if (!ns_a) {
> + pr_err("Could not find netns with id: %u\n", netnsid_a);
> + goto out_unlock_rtnl;
> + }
> +
> + dev_a = __dev_get_by_index(ns_a, ifidx_a);
> + if (!dev_a) {
> + pr_err("Could not find device with ifindex %u in netnsid %u\n", ifidx_a, netnsid_a);
> + goto out_put_netns_a;
> + }
> +
> + if (!netdev_is_nsim(dev_a)) {
> + pr_err("Device with ifindex %u in netnsid %u is not a netdevsim\n", ifidx_a, netnsid_a);
> + goto out_put_netns_a;
> + }
> +
> + ns_b = get_net_ns_by_id(current->nsproxy->net_ns, netnsid_b);
> + if (!ns_b) {
> + pr_err("Could not find netns with id: %u\n", netnsid_b);
> + goto out_put_netns_a;
> + }
> +
> + dev_b = __dev_get_by_index(ns_b, ifidx_b);
> + if (!dev_b) {
> + pr_err("Could not find device with ifindex %u in netnsid %u\n", ifidx_b, netnsid_b);
> + goto out_put_netns_b;
> + }
> +
> + if (!netdev_is_nsim(dev_b)) {
> + pr_err("Device with ifindex %u in netnsid %u is not a netdevsim\n", ifidx_b, netnsid_b);
> + goto out_put_netns_b;
> + }
You're missing if dev_a == dev_b return goto out..; ?
Actually I can't think of a reason why looping would explode.
Could you test it and if it indeed doesn't splat add a comment
here that loops are okay?
> + err = 0;
> + nsim_a = netdev_priv(dev_a);
> + peer = rtnl_dereference(nsim_a->peer);
> + if (peer) {
> + pr_err("Netdevsim %u:%u is already linked\n", netnsid_a, ifidx_a);
> + goto out_put_netns_b;
> + }
> +
> + nsim_b = netdev_priv(dev_b);
> + peer = rtnl_dereference(nsim_b->peer);
> + if (peer) {
> + pr_err("Netdevsim %u:%u is already linked\n", netnsid_b, ifidx_b);
> + goto out_put_netns_b;
> + }
> +
> + rcu_assign_pointer(nsim_a->peer, nsim_b);
> + rcu_assign_pointer(nsim_b->peer, nsim_a);
> @@ -333,6 +333,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
> goto err_phc_destroy;
>
> rtnl_lock();
> + RCU_INIT_POINTER(ns->peer, NULL);
since you have to repost - pretty sure ns is zalloc'ed so you don't
have to do this?
> err = nsim_bpf_init(ns);
> if (err)
> goto err_utn_destroy;
next prev parent reply other threads:[~2024-02-01 0:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 21:46 [PATCH net-next v8 0/5] netdevsim: link and forward skbs between ports David Wei
2024-01-30 21:46 ` [PATCH net-next v8 1/4] netdevsim: allow two netdevsim ports to be connected David Wei
2024-02-01 0:57 ` Jakub Kicinski [this message]
2024-01-30 21:46 ` [PATCH net-next v8 2/4] netdevsim: forward skbs from one connected port to another David Wei
2024-01-30 21:46 ` [PATCH net-next v8 3/4] netdevsim: add selftest for forwarding skb between connected ports David Wei
2024-01-30 21:46 ` [PATCH net-next v8 4/4] netdevsim: add Makefile for selftests David Wei
2024-02-05 15:32 ` Jakub Kicinski
2024-02-01 0:44 ` [PATCH net-next v8 0/5] netdevsim: link and forward skbs between ports Jakub Kicinski
2024-02-01 4:48 ` David Wei
2024-02-05 15:40 ` patchwork-bot+netdevbpf
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=20240131165739.53cf301e@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=dw@davidwei.uk \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
/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).