All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] Introduce rtnl_lock_killable()
@ 2018-03-14 19:17 Kirill Tkhai
  2018-03-14 19:17 ` [PATCH net-next 1/2] net: Add rtnl_lock_killable() Kirill Tkhai
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kirill Tkhai @ 2018-03-14 19:17 UTC (permalink / raw)
  To: davem, ktkhai, vyasevic, edumazet, nicolas.dichtel, netdev

rtnl_lock() is widely used mutex in kernel. Some of kernel code
does memory allocations under it. In case of memory deficit this
may invoke OOM killer, but the problem is a killed task can't
exit if it's waiting for the mutex. This may be a reason of deadlock
and panic.

This patchset adds a new primitive, which responds on SIGKILL,
and it allows to use it in the places, where we don't want
to sleep forever. Also, the first place is made to use it.

---

Kirill Tkhai (2):
      net: Add rtnl_lock_killable()
      net: Use rtnl_lock_killable() in register_netdev()


 include/linux/rtnetlink.h |    1 +
 net/core/dev.c            |    3 ++-
 net/core/rtnetlink.c      |    6 ++++++
 3 files changed, 9 insertions(+), 1 deletion(-)

--
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

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

* [PATCH net-next 1/2] net: Add rtnl_lock_killable()
  2018-03-14 19:17 [PATCH net-next 0/2] Introduce rtnl_lock_killable() Kirill Tkhai
@ 2018-03-14 19:17 ` Kirill Tkhai
  2018-03-14 19:17 ` [PATCH net-next 2/2] net: Use rtnl_lock_killable() in register_netdev() Kirill Tkhai
  2018-03-16 16:31 ` [PATCH net-next 0/2] Introduce rtnl_lock_killable() David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Kirill Tkhai @ 2018-03-14 19:17 UTC (permalink / raw)
  To: davem, ktkhai, vyasevic, edumazet, nicolas.dichtel, netdev

rtnl_lock() is widely used mutex in kernel. Some of kernel code
does memory allocations under it. In case of memory deficit this
may invoke OOM killer, but the problem is a killed task can't
exit if it's waiting for the mutex. This may be a reason of deadlock
and panic.

This patch adds a new primitive, which responds on SIGKILL, and
it allows to use it in the places, where we don't want to sleep
forever.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 include/linux/rtnetlink.h |    1 +
 net/core/rtnetlink.c      |    6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 3573b4bf2fdf..562a175c35a9 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -33,6 +33,7 @@ extern void rtnl_lock(void);
 extern void rtnl_unlock(void);
 extern int rtnl_trylock(void);
 extern int rtnl_is_locked(void);
+extern int rtnl_lock_killable(void);
 
 extern wait_queue_head_t netdev_unregistering_wq;
 extern struct rw_semaphore net_sem;
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 67f375cfb982..87079eaa871b 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -75,6 +75,12 @@ void rtnl_lock(void)
 }
 EXPORT_SYMBOL(rtnl_lock);
 
+int rtnl_lock_killable(void)
+{
+	return mutex_lock_killable(&rtnl_mutex);
+}
+EXPORT_SYMBOL(rtnl_lock_killable);
+
 static struct sk_buff *defer_kfree_skb_list;
 void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail)
 {

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

* [PATCH net-next 2/2] net: Use rtnl_lock_killable() in register_netdev()
  2018-03-14 19:17 [PATCH net-next 0/2] Introduce rtnl_lock_killable() Kirill Tkhai
  2018-03-14 19:17 ` [PATCH net-next 1/2] net: Add rtnl_lock_killable() Kirill Tkhai
@ 2018-03-14 19:17 ` Kirill Tkhai
  2018-03-16 16:31 ` [PATCH net-next 0/2] Introduce rtnl_lock_killable() David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Kirill Tkhai @ 2018-03-14 19:17 UTC (permalink / raw)
  To: davem, ktkhai, vyasevic, edumazet, nicolas.dichtel, netdev

This patch adds rtnl_lock_killable() to one of hot path
using rtnl_lock().

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 net/core/dev.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 12a9aad0b057..d8887cc38e7b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8018,7 +8018,8 @@ int register_netdev(struct net_device *dev)
 {
 	int err;
 
-	rtnl_lock();
+	if (rtnl_lock_killable())
+		return -EINTR;
 	err = register_netdevice(dev);
 	rtnl_unlock();
 	return err;

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

* Re: [PATCH net-next 0/2] Introduce rtnl_lock_killable()
  2018-03-14 19:17 [PATCH net-next 0/2] Introduce rtnl_lock_killable() Kirill Tkhai
  2018-03-14 19:17 ` [PATCH net-next 1/2] net: Add rtnl_lock_killable() Kirill Tkhai
  2018-03-14 19:17 ` [PATCH net-next 2/2] net: Use rtnl_lock_killable() in register_netdev() Kirill Tkhai
@ 2018-03-16 16:31 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-03-16 16:31 UTC (permalink / raw)
  To: ktkhai; +Cc: vyasevic, edumazet, nicolas.dichtel, netdev

From: Kirill Tkhai <ktkhai@virtuozzo.com>
Date: Wed, 14 Mar 2018 22:17:11 +0300

> rtnl_lock() is widely used mutex in kernel. Some of kernel code
> does memory allocations under it. In case of memory deficit this
> may invoke OOM killer, but the problem is a killed task can't
> exit if it's waiting for the mutex. This may be a reason of deadlock
> and panic.
> 
> This patchset adds a new primitive, which responds on SIGKILL,
> and it allows to use it in the places, where we don't want
> to sleep forever. Also, the first place is made to use it.

This looks reasonable.  Series applied, thank you.

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

end of thread, other threads:[~2018-03-16 16:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-14 19:17 [PATCH net-next 0/2] Introduce rtnl_lock_killable() Kirill Tkhai
2018-03-14 19:17 ` [PATCH net-next 1/2] net: Add rtnl_lock_killable() Kirill Tkhai
2018-03-14 19:17 ` [PATCH net-next 2/2] net: Use rtnl_lock_killable() in register_netdev() Kirill Tkhai
2018-03-16 16:31 ` [PATCH net-next 0/2] Introduce rtnl_lock_killable() David Miller

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.