All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] can: dev: Move device back to init netns on owning netns delete
@ 2021-03-02 12:24 Martin Willi
  2021-03-03 20:29 ` Marc Kleine-Budde
  2021-03-03 21:16 ` Marc Kleine-Budde
  0 siblings, 2 replies; 5+ messages in thread
From: Martin Willi @ 2021-03-02 12:24 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Marc Kleine-Budde, Wolfgang Grandegger
  Cc: netdev, linux-can

When a non-initial netns is destroyed, the usual policy is to delete
all virtual network interfaces contained, but move physical interfaces
back to the initial netns. This keeps the physical interface visible
on the system.

CAN devices are somewhat special, as they define rtnl_link_ops even
if they are physical devices. If a CAN interface is moved into a
non-initial netns, destroying that netns lets the interface vanish
instead of moving it back to the initial netns. default_device_exit()
skips CAN interfaces due to having rtnl_link_ops set. Reproducer:

  ip netns add foo
  ip link set can0 netns foo
  ip netns delete foo

WARNING: CPU: 1 PID: 84 at net/core/dev.c:11030 ops_exit_list+0x38/0x60
CPU: 1 PID: 84 Comm: kworker/u4:2 Not tainted 5.10.19 #1
Workqueue: netns cleanup_net
[<c010e700>] (unwind_backtrace) from [<c010a1d8>] (show_stack+0x10/0x14)
[<c010a1d8>] (show_stack) from [<c086dc10>] (dump_stack+0x94/0xa8)
[<c086dc10>] (dump_stack) from [<c086b938>] (__warn+0xb8/0x114)
[<c086b938>] (__warn) from [<c086ba10>] (warn_slowpath_fmt+0x7c/0xac)
[<c086ba10>] (warn_slowpath_fmt) from [<c0629f20>] (ops_exit_list+0x38/0x60)
[<c0629f20>] (ops_exit_list) from [<c062a5c4>] (cleanup_net+0x230/0x380)
[<c062a5c4>] (cleanup_net) from [<c0142c20>] (process_one_work+0x1d8/0x438)
[<c0142c20>] (process_one_work) from [<c0142ee4>] (worker_thread+0x64/0x5a8)
[<c0142ee4>] (worker_thread) from [<c0148a98>] (kthread+0x148/0x14c)
[<c0148a98>] (kthread) from [<c0100148>] (ret_from_fork+0x14/0x2c)

To properly restore physical CAN devices to the initial netns on owning
netns exit, introduce a flag on rtnl_link_ops that can be set by drivers.
For CAN devices setting this flag, default_device_exit() considers them
non-virtual, applying the usual namespace move.

The issue was introduced in the commit mentioned below, as at that time
CAN devices did not have a dellink() operation.

Fixes: e008b5fc8dc7 ("net: Simplfy default_device_exit and improve batching.")
Signed-off-by: Martin Willi <martin@strongswan.org>
---
 drivers/net/can/dev/netlink.c | 1 +
 include/net/rtnetlink.h       | 2 ++
 net/core/dev.c                | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index 867f6be31230..f5d79e6e5483 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -355,6 +355,7 @@ static void can_dellink(struct net_device *dev, struct list_head *head)
 
 struct rtnl_link_ops can_link_ops __read_mostly = {
 	.kind		= "can",
+	.netns_refund	= true,
 	.maxtype	= IFLA_CAN_MAX,
 	.policy		= can_policy,
 	.setup		= can_setup,
diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index e2091bb2b3a8..4da61c950e93 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -33,6 +33,7 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
  *
  *	@list: Used internally
  *	@kind: Identifier
+ *	@netns_refund: Physical device, move to init_net on netns exit
  *	@maxtype: Highest device specific netlink attribute number
  *	@policy: Netlink policy for device specific attribute validation
  *	@validate: Optional validation function for netlink/changelink parameters
@@ -64,6 +65,7 @@ struct rtnl_link_ops {
 	size_t			priv_size;
 	void			(*setup)(struct net_device *dev);
 
+	bool			netns_refund;
 	unsigned int		maxtype;
 	const struct nla_policy	*policy;
 	int			(*validate)(struct nlattr *tb[],
diff --git a/net/core/dev.c b/net/core/dev.c
index 6c5967e80132..a142a207fc1d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11346,7 +11346,7 @@ static void __net_exit default_device_exit(struct net *net)
 			continue;
 
 		/* Leave virtual devices for the generic cleanup */
-		if (dev->rtnl_link_ops)
+		if (dev->rtnl_link_ops && !dev->rtnl_link_ops->netns_refund)
 			continue;
 
 		/* Push remaining network devices to init_net */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] can: dev: Move device back to init netns on owning netns delete
  2021-03-02 12:24 [PATCH net] can: dev: Move device back to init netns on owning netns delete Martin Willi
@ 2021-03-03 20:29 ` Marc Kleine-Budde
  2021-03-03 21:12   ` [PATCH net] can: dev: Move device back to init netns on owning netns delete,Re: " David Miller
  2021-03-03 21:16 ` Marc Kleine-Budde
  1 sibling, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2021-03-03 20:29 UTC (permalink / raw)
  To: Martin Willi, David S . Miller, Jakub Kicinski, Wolfgang Grandegger
  Cc: netdev, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 2567 bytes --]

On 3/2/21 1:24 PM, Martin Willi wrote:
> When a non-initial netns is destroyed, the usual policy is to delete
> all virtual network interfaces contained, but move physical interfaces
> back to the initial netns. This keeps the physical interface visible
> on the system.
> 
> CAN devices are somewhat special, as they define rtnl_link_ops even
> if they are physical devices. If a CAN interface is moved into a
> non-initial netns, destroying that netns lets the interface vanish
> instead of moving it back to the initial netns. default_device_exit()
> skips CAN interfaces due to having rtnl_link_ops set. Reproducer:
> 
>   ip netns add foo
>   ip link set can0 netns foo
>   ip netns delete foo
> 
> WARNING: CPU: 1 PID: 84 at net/core/dev.c:11030 ops_exit_list+0x38/0x60
> CPU: 1 PID: 84 Comm: kworker/u4:2 Not tainted 5.10.19 #1
> Workqueue: netns cleanup_net
> [<c010e700>] (unwind_backtrace) from [<c010a1d8>] (show_stack+0x10/0x14)
> [<c010a1d8>] (show_stack) from [<c086dc10>] (dump_stack+0x94/0xa8)
> [<c086dc10>] (dump_stack) from [<c086b938>] (__warn+0xb8/0x114)
> [<c086b938>] (__warn) from [<c086ba10>] (warn_slowpath_fmt+0x7c/0xac)
> [<c086ba10>] (warn_slowpath_fmt) from [<c0629f20>] (ops_exit_list+0x38/0x60)
> [<c0629f20>] (ops_exit_list) from [<c062a5c4>] (cleanup_net+0x230/0x380)
> [<c062a5c4>] (cleanup_net) from [<c0142c20>] (process_one_work+0x1d8/0x438)
> [<c0142c20>] (process_one_work) from [<c0142ee4>] (worker_thread+0x64/0x5a8)
> [<c0142ee4>] (worker_thread) from [<c0148a98>] (kthread+0x148/0x14c)
> [<c0148a98>] (kthread) from [<c0100148>] (ret_from_fork+0x14/0x2c)
> 
> To properly restore physical CAN devices to the initial netns on owning
> netns exit, introduce a flag on rtnl_link_ops that can be set by drivers.
> For CAN devices setting this flag, default_device_exit() considers them
> non-virtual, applying the usual namespace move.
> 
> The issue was introduced in the commit mentioned below, as at that time
> CAN devices did not have a dellink() operation.
> 
> Fixes: e008b5fc8dc7 ("net: Simplfy default_device_exit and improve batching.")
> Signed-off-by: Martin Willi <martin@strongswan.org>

Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>

David, Jakub are you taking this patch?

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] can: dev: Move device back to init netns on owning netns delete,Re: [PATCH net] can: dev: Move device back to init netns on owning netns delete
  2021-03-03 20:29 ` Marc Kleine-Budde
@ 2021-03-03 21:12   ` David Miller
  2021-03-03 21:14     ` Marc Kleine-Budde
  0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2021-03-03 21:12 UTC (permalink / raw)
  To: mkl; +Cc: martin, kuba, wg, netdev, linux-can

From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Wed, 3 Mar 2021 21:29:39 +0100

> Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
> 
> David, Jakub are you taking this patch?

Nope, please take via the can tree, thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] can: dev: Move device back to init netns on owning netns delete,Re: [PATCH net] can: dev: Move device back to init netns on owning netns delete
  2021-03-03 21:12   ` [PATCH net] can: dev: Move device back to init netns on owning netns delete,Re: " David Miller
@ 2021-03-03 21:14     ` Marc Kleine-Budde
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2021-03-03 21:14 UTC (permalink / raw)
  To: David Miller; +Cc: martin, kuba, wg, netdev, linux-can

[-- Attachment #1: Type: text/plain, Size: 593 bytes --]

On 03.03.2021 13:12:31, David Miller wrote:
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Date: Wed, 3 Mar 2021 21:29:39 +0100
> 
> > Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
> > 
> > David, Jakub are you taking this patch?
> 
> Nope, please take via the can tree, thanks!

Will do.

Thanks,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] can: dev: Move device back to init netns on owning netns delete
  2021-03-02 12:24 [PATCH net] can: dev: Move device back to init netns on owning netns delete Martin Willi
  2021-03-03 20:29 ` Marc Kleine-Budde
@ 2021-03-03 21:16 ` Marc Kleine-Budde
  1 sibling, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2021-03-03 21:16 UTC (permalink / raw)
  To: Martin Willi
  Cc: David S . Miller, Jakub Kicinski, Wolfgang Grandegger, netdev, linux-can

[-- Attachment #1: Type: text/plain, Size: 2506 bytes --]

On 02.03.2021 13:24:23, Martin Willi wrote:
> When a non-initial netns is destroyed, the usual policy is to delete
> all virtual network interfaces contained, but move physical interfaces
> back to the initial netns. This keeps the physical interface visible
> on the system.
> 
> CAN devices are somewhat special, as they define rtnl_link_ops even
> if they are physical devices. If a CAN interface is moved into a
> non-initial netns, destroying that netns lets the interface vanish
> instead of moving it back to the initial netns. default_device_exit()
> skips CAN interfaces due to having rtnl_link_ops set. Reproducer:
> 
>   ip netns add foo
>   ip link set can0 netns foo
>   ip netns delete foo
> 
> WARNING: CPU: 1 PID: 84 at net/core/dev.c:11030 ops_exit_list+0x38/0x60
> CPU: 1 PID: 84 Comm: kworker/u4:2 Not tainted 5.10.19 #1
> Workqueue: netns cleanup_net
> [<c010e700>] (unwind_backtrace) from [<c010a1d8>] (show_stack+0x10/0x14)
> [<c010a1d8>] (show_stack) from [<c086dc10>] (dump_stack+0x94/0xa8)
> [<c086dc10>] (dump_stack) from [<c086b938>] (__warn+0xb8/0x114)
> [<c086b938>] (__warn) from [<c086ba10>] (warn_slowpath_fmt+0x7c/0xac)
> [<c086ba10>] (warn_slowpath_fmt) from [<c0629f20>] (ops_exit_list+0x38/0x60)
> [<c0629f20>] (ops_exit_list) from [<c062a5c4>] (cleanup_net+0x230/0x380)
> [<c062a5c4>] (cleanup_net) from [<c0142c20>] (process_one_work+0x1d8/0x438)
> [<c0142c20>] (process_one_work) from [<c0142ee4>] (worker_thread+0x64/0x5a8)
> [<c0142ee4>] (worker_thread) from [<c0148a98>] (kthread+0x148/0x14c)
> [<c0148a98>] (kthread) from [<c0100148>] (ret_from_fork+0x14/0x2c)
> 
> To properly restore physical CAN devices to the initial netns on owning
> netns exit, introduce a flag on rtnl_link_ops that can be set by drivers.
> For CAN devices setting this flag, default_device_exit() considers them
> non-virtual, applying the usual namespace move.
> 
> The issue was introduced in the commit mentioned below, as at that time
> CAN devices did not have a dellink() operation.
> 
> Fixes: e008b5fc8dc7 ("net: Simplfy default_device_exit and improve batching.")
> Signed-off-by: Martin Willi <martin@strongswan.org>

applied to linux-can/testing

Thanks,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-04  0:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 12:24 [PATCH net] can: dev: Move device back to init netns on owning netns delete Martin Willi
2021-03-03 20:29 ` Marc Kleine-Budde
2021-03-03 21:12   ` [PATCH net] can: dev: Move device back to init netns on owning netns delete,Re: " David Miller
2021-03-03 21:14     ` Marc Kleine-Budde
2021-03-03 21:16 ` Marc Kleine-Budde

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.