Commit cec4a69c authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Greg Kroah-Hartman

Staging: batman-adv: Use forw_bcast_list_lock always with disabled interrupts

forw_bcast_list_lock is spin_locked in both process and softirq context.
SoftIRQ calls the spinlock with disabled IRQ and normal process context
with enabled IRQs.

When process context is inside an spin_locked area protected by
forw_bcast_list_lock and gets interrupted by an IRQ, it could happen
that something tries to lock forw_bcast_list_lock again in SoftIRQ
context. It cannot proceed further since the lock is already taken
somewhere else, but no reschedule will happen inside the SoftIRQ
context. This leads to an complete kernel hang without any chance of
resurrection.

All functions called in process context must disable IRQs when they try
to get get that lock to to prevent any reschedule due to IRQs.
Signed-off-by: default avatarSven Eckelmann <sven.eckelmann@gmx.de>
Acked-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5ea84fa3
...@@ -338,12 +338,13 @@ static void forw_packet_free(struct forw_packet *forw_packet) ...@@ -338,12 +338,13 @@ static void forw_packet_free(struct forw_packet *forw_packet)
static void _add_bcast_packet_to_list(struct forw_packet *forw_packet, static void _add_bcast_packet_to_list(struct forw_packet *forw_packet,
unsigned long send_time) unsigned long send_time)
{ {
unsigned long flags;
INIT_HLIST_NODE(&forw_packet->list); INIT_HLIST_NODE(&forw_packet->list);
/* add new packet to packet list */ /* add new packet to packet list */
spin_lock(&forw_bcast_list_lock); spin_lock_irqsave(&forw_bcast_list_lock, flags);
hlist_add_head(&forw_packet->list, &forw_bcast_list); hlist_add_head(&forw_packet->list, &forw_bcast_list);
spin_unlock(&forw_bcast_list_lock); spin_unlock_irqrestore(&forw_bcast_list_lock, flags);
/* start timer for this packet */ /* start timer for this packet */
INIT_DELAYED_WORK(&forw_packet->delayed_work, INIT_DELAYED_WORK(&forw_packet->delayed_work,
...@@ -382,10 +383,11 @@ void send_outstanding_bcast_packet(struct work_struct *work) ...@@ -382,10 +383,11 @@ void send_outstanding_bcast_packet(struct work_struct *work)
container_of(work, struct delayed_work, work); container_of(work, struct delayed_work, work);
struct forw_packet *forw_packet = struct forw_packet *forw_packet =
container_of(delayed_work, struct forw_packet, delayed_work); container_of(delayed_work, struct forw_packet, delayed_work);
unsigned long flags;
spin_lock(&forw_bcast_list_lock); spin_lock_irqsave(&forw_bcast_list_lock, flags);
hlist_del(&forw_packet->list); hlist_del(&forw_packet->list);
spin_unlock(&forw_bcast_list_lock); spin_unlock_irqrestore(&forw_bcast_list_lock, flags);
/* rebroadcast packet */ /* rebroadcast packet */
rcu_read_lock(); rcu_read_lock();
...@@ -436,24 +438,25 @@ void purge_outstanding_packets(void) ...@@ -436,24 +438,25 @@ void purge_outstanding_packets(void)
{ {
struct forw_packet *forw_packet; struct forw_packet *forw_packet;
struct hlist_node *tmp_node, *safe_tmp_node; struct hlist_node *tmp_node, *safe_tmp_node;
unsigned long flags;
bat_dbg(DBG_BATMAN, "purge_outstanding_packets()\n"); bat_dbg(DBG_BATMAN, "purge_outstanding_packets()\n");
/* free bcast list */ /* free bcast list */
spin_lock(&forw_bcast_list_lock); spin_lock_irqsave(&forw_bcast_list_lock, flags);
hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node, hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
&forw_bcast_list, list) { &forw_bcast_list, list) {
spin_unlock(&forw_bcast_list_lock); spin_unlock_irqrestore(&forw_bcast_list_lock, flags);
/** /**
* send_outstanding_bcast_packet() will lock the list to * send_outstanding_bcast_packet() will lock the list to
* delete the item from the list * delete the item from the list
*/ */
cancel_delayed_work_sync(&forw_packet->delayed_work); cancel_delayed_work_sync(&forw_packet->delayed_work);
spin_lock(&forw_bcast_list_lock); spin_lock_irqsave(&forw_bcast_list_lock, flags);
} }
spin_unlock(&forw_bcast_list_lock); spin_unlock_irqrestore(&forw_bcast_list_lock, flags);
/* free batman packet list */ /* free batman packet list */
spin_lock(&forw_bat_list_lock); spin_lock(&forw_bat_list_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment