Skip to content

Commit b22800f

Browse files
Sebastian Andrzej Siewiorkuba-moo
authored andcommitted
dev: Use nested-BH locking for softnet_data.process_queue.
softnet_data::process_queue is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. softnet_data::input_queue_head can be updated lockless. This is fine because this value is only update CPU local by the local backlog_napi thread. Add a local_lock_t to softnet_data and use local_lock_nested_bh() for locking of process_queue. This change adds only lockdep coverage and does not alter the functional behaviour for !PREEMPT_RT. Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a8760d0 commit b22800f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,7 @@ static inline bool dev_has_header(const struct net_device *dev)
32023202
struct softnet_data {
32033203
struct list_head poll_list;
32043204
struct sk_buff_head process_queue;
3205+
local_lock_t process_queue_bh_lock;
32053206

32063207
/* stats */
32073208
unsigned int processed;

net/core/dev.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ static RAW_NOTIFIER_HEAD(netdev_chain);
449449
* queue in the local softnet handler.
450450
*/
451451

452-
DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
452+
DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data) = {
453+
.process_queue_bh_lock = INIT_LOCAL_LOCK(process_queue_bh_lock),
454+
};
453455
EXPORT_PER_CPU_SYMBOL(softnet_data);
454456

455457
/* Page_pool has a lockless array/stack to alloc/recycle pages.
@@ -5949,13 +5951,15 @@ static void flush_backlog(struct work_struct *work)
59495951
}
59505952
backlog_unlock_irq_enable(sd);
59515953

5954+
local_lock_nested_bh(&softnet_data.process_queue_bh_lock);
59525955
skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
59535956
if (skb->dev->reg_state == NETREG_UNREGISTERING) {
59545957
__skb_unlink(skb, &sd->process_queue);
59555958
kfree_skb(skb);
59565959
rps_input_queue_head_incr(sd);
59575960
}
59585961
}
5962+
local_unlock_nested_bh(&softnet_data.process_queue_bh_lock);
59595963
local_bh_enable();
59605964
}
59615965

@@ -6077,7 +6081,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
60776081
while (again) {
60786082
struct sk_buff *skb;
60796083

6084+
local_lock_nested_bh(&softnet_data.process_queue_bh_lock);
60806085
while ((skb = __skb_dequeue(&sd->process_queue))) {
6086+
local_unlock_nested_bh(&softnet_data.process_queue_bh_lock);
60816087
rcu_read_lock();
60826088
__netif_receive_skb(skb);
60836089
rcu_read_unlock();
@@ -6086,7 +6092,9 @@ static int process_backlog(struct napi_struct *napi, int quota)
60866092
return work;
60876093
}
60886094

6095+
local_lock_nested_bh(&softnet_data.process_queue_bh_lock);
60896096
}
6097+
local_unlock_nested_bh(&softnet_data.process_queue_bh_lock);
60906098

60916099
backlog_lock_irq_disable(sd);
60926100
if (skb_queue_empty(&sd->input_pkt_queue)) {
@@ -6101,8 +6109,10 @@ static int process_backlog(struct napi_struct *napi, int quota)
61016109
napi->state &= NAPIF_STATE_THREADED;
61026110
again = false;
61036111
} else {
6112+
local_lock_nested_bh(&softnet_data.process_queue_bh_lock);
61046113
skb_queue_splice_tail_init(&sd->input_pkt_queue,
61056114
&sd->process_queue);
6115+
local_unlock_nested_bh(&softnet_data.process_queue_bh_lock);
61066116
}
61076117
backlog_unlock_irq_enable(sd);
61086118
}

0 commit comments

Comments
 (0)