Skip to contentSkip to conversation

net: move xmit_recursion to per-task variable on -RT

PATCH In review Sebastian Andrzej Siewior 4 participants 8 messages Jan 13, 2016 – Jan 15, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: move xmit_recursion to per-task variable on -RT

A softirq on -RT can be preempted. That means one task is in __dev_queue_xmit(), gets preempted and another task may enter __dev_queue_xmit() aw well. netperf together with a bridge device will then trigger the recursion alert because each task increments the xmit_recursion variable which is per-CPU.
A virtual device like br0 is required to trigger this warning.

This patch moves the counter to per task instead per-CPU so it counts the recursion properly on -RT.

---
 include/linux/netdevice.h |  9 +++++++++
 include/linux/sched.h     |  3 +++
 net/core/dev.c            | 41 ++++++++++++++++++++++++++++++++++++++---
 3 files changed, 50 insertions(+), 3 deletions(-)
include/linux/netdevice.h +9 -0
index f14e39cb897c..4a8d3429dc12 100644
@@ -2249,11 +2249,20 @@ void netdev_freemem(struct net_device *dev);
 void synchronize_net(void);
 int init_dummy_netdev(struct net_device *dev);
 
+#ifdef CONFIG_PREEMPT_RT_FULL
+static inline int dev_recursion_level(void)
+{
+	return atomic_read(&current->xmit_recursion);
+}
+
+#else
+
 DECLARE_PER_CPU(int, xmit_recursion);
 static inline int dev_recursion_level(void)
 {
 	return this_cpu_read(xmit_recursion);
 }
+#endif
 
 struct net_device *dev_get_by_index(struct net *net, int ifindex);
 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
include/linux/sched.h +3 -0
index 04eb2f8bc274..5d36818107b0 100644
@@ -1855,6 +1855,9 @@ struct task_struct {
 	pte_t kmap_pte[KM_TYPE_NR];
 # endif
 #endif
+#ifdef CONFIG_PREEMPT_RT_FULL
+	atomic_t xmit_recursion;
+#endif
 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
 	unsigned long	task_state_change;
 #endif
net/core/dev.c +38 -3

63 lines not on this page · raw message

Signature · 1 line
2.7.0.rc3
#1 lore raw

include/linux/netdevice.h void netdev_freemem(struct net_device *dev); · line 2255

Quoted 4 lines · Sebastian Andrzej Siewior
include/linux/netdevice.h +4 -0
+#ifdef CONFIG_PREEMPT_RT_FULL
+static inline int dev_recursion_level(void)
+{
+	return atomic_read(&current->xmit_recursion);

Why would you need an atomic here. current does hardly race against itself.

Thanks,

tglx

#2 lore raw
Quoted 7 lines · * Thomas Gleixner | 2016-01-13 18:31:46 [+0100]:

Review

Quoted 4 lines · Sebastian Andrzej Siewior
(quoted diff) +4 -0
+#ifdef CONFIG_PREEMPT_RT_FULL
+static inline int dev_recursion_level(void)
+{
+	return atomic_read(&current->xmit_recursion);

Why would you need an atomic here. current does hardly race against itself.

right.

include/linux/netdevice.h +9 -0
@@ -2249,11 +2249,20 @@ void netdev_freemem(struct net_device *d
 void synchronize_net(void);
 int init_dummy_netdev(struct net_device *dev);
 
+#ifdef CONFIG_PREEMPT_RT_FULL
+static inline int dev_recursion_level(void)
+{
+	return current->xmit_recursion;
+}
+
+#else
+
 DECLARE_PER_CPU(int, xmit_recursion);
 static inline int dev_recursion_level(void)
 {
 	return this_cpu_read(xmit_recursion);
 }
+#endif
 
 struct net_device *dev_get_by_index(struct net *net, int ifindex);
 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
include/linux/sched.h +3 -0
@@ -1851,6 +1851,9 @@ struct task_struct {
 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
 	unsigned long	task_state_change;
 #endif
+#ifdef CONFIG_PREEMPT_RT_FULL
+	int xmit_recursion;
+#endif
 	int pagefault_disabled;
 /* CPU-specific state of this task */
 	struct thread_struct thread;
net/core/dev.c +38 -3

63 lines not on this page · raw message

Quoted 3 lines

Thanks,

tglx

Sebastian

#3 lore raw
Quoted 11 lines · Sebastian Andrzej Siewior
Quoted 7 lines · * Thomas Gleixner | 2016-01-13 18:31:46 [+0100]:

include/linux/netdevice.h void netdev_freemem(struct net_device *d

Quoted 4 lines · Sebastian Andrzej Siewior
include/linux/netdevice.h +4 -0
+#ifdef CONFIG_PREEMPT_RT_FULL
+static inline int dev_recursion_level(void)
+{
+	return atomic_read(&current->xmit_recursion);

Why would you need an atomic here. current does hardly race against itself.

right.

We are just adding a second recursion limit solely to openvswitch which has the same problem:

https://patchwork.ozlabs.org/patch/566769/

This time also we depend on rcu_read_lock marking the section being nonpreemptible. Nice would be a more generic solution here which doesn't need to always add something to *current.

Thanks,
Hannes

#4 lore raw
Quoted 8 lines · Hannes Frederic Sowa

We are just adding a second recursion limit solely to openvswitch which has the same problem:

https://patchwork.ozlabs.org/patch/566769/

This time also we depend on rcu_read_lock marking the section being nonpreemptible. Nice would be a more generic solution here which doesn't need to always add something to *current.

Note that rcu_read_lock() does not imply that preemption is disabled.

#5 lore raw
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Hannes Frederic Sowa

We are just adding a second recursion limit solely to openvswitch which has the same problem:

Quoted 8 lines
Quoted 5 lines

https://patchwork.ozlabs.org/patch/566769/

This time also we depend on rcu_read_lock marking the section being nonpreemptible. Nice would be a more generic solution here which doesn't need to always add something to *current.

Note that rcu_read_lock() does not imply that preemption is disabled.

Exactly, it is conditional on CONFIG_PREEMPT_CPU/CONFIG_PREMPT_COUNT but haven't thought about exactly that in this moment.

I will resend this patch with better protection.

Thanks Eric!

#6 lore raw
Quoted 13 lines · Hannes Frederic Sowa
Quoted 12 lines · Eric Dumazet
Quoted 8 lines · Hannes Frederic Sowa

We are just adding a second recursion limit solely to openvswitch which has the same problem:

https://patchwork.ozlabs.org/patch/566769/

This time also we depend on rcu_read_lock marking the section being nonpreemptible. Nice would be a more generic solution here which doesn't need to always add something to *current.

Quoted 4 lines
Quoted 1 line

Note that rcu_read_lock() does not imply that preemption is disabled.

Exactly, it is conditional on CONFIG_PREEMPT_CPU/CONFIG_PREMPT_COUNT but haven't thought about exactly that in this moment.

Wrong. CONFIG_PREEMPT_RCU makes RCU preemptible.

If that is not set then it fiddles with preempt_count when CONFIG_PREEMPT_COUNT=y. If CONFIG_PREEMPT_COUNT=n then you have a non preemptible system anyway.

So you cannot assume that rcu_read_lock() disables preemption.

Thanks,

tglx

#7 lore raw
Quoted 19 lines · Thomas Gleixner
Quoted 13 lines · Hannes Frederic Sowa
Quoted 12 lines · Eric Dumazet
Quoted 8 lines · Hannes Frederic Sowa

We are just adding a second recursion limit solely to openvswitch which has the same problem:

https://patchwork.ozlabs.org/patch/566769/

This time also we depend on rcu_read_lock marking the section being nonpreemptible. Nice would be a more generic solution here which doesn't need to always add something to *current.

Quoted 4 lines
Quoted 1 line

Note that rcu_read_lock() does not imply that preemption is disabled.

Exactly, it is conditional on CONFIG_PREEMPT_CPU/CONFIG_PREMPT_COUNT but haven't thought about exactly that in this moment.

Quoted 7 lines

Wrong. CONFIG_PREEMPT_RCU makes RCU preemptible.

If that is not set then it fiddles with preempt_count when CONFIG_PREEMPT_COUNT=y. If CONFIG_PREEMPT_COUNT=n then you have a non preemptible system anyway.

So you cannot assume that rcu_read_lock() disables preemption.

Sorry for maybe writing it misleading but that is exactly what I wanted to say here. Yes, I agree, I didn't really check because of _bh and rcu_read_lock. This was a mistake. ;)

I already send out an updated patch with added preemption guards.

Thanks,
Hannes