(3/5) Remove brlock from bridge
Subsystems (3)
PATCH 1/1 (3/5) Remove brlock from bridge
Remove brlock dependency from bridge code.
Changed from earlier version to use RCU for list of bridges and use deferred free for deletion of bridge ports. This avoids the possible race where a receive frame is in process on a bridge port and port is deleted.
Fixed some existing race conditions in the ioctl() processing path where bridge data was referenced without a lock.
This code still needs more testing before final 2.5 inclusion.
net/bridge/br.c +3 -3
@@ -21,7 +21,6 @@#include <linux/etherdevice.h> #include <linux/init.h> #include <linux/if_bridge.h> -#include <linux/brlock.h> #include <asm/uaccess.h> #include "br_private.h"
@@ -73,14 +72,15 @@unregister_netdevice_notifier (&br_device_notifier);br_call_ioctl_atomic (__br_clear_ioctl_hook); -br_write_lock_bh (BR_NETPROTO_LOCK ); br_handle_frame_hook =NULL ; -br_write_unlock_bh (BR_NETPROTO_LOCK );#if defined(CONFIG_ATM_LANE ) || defined(CONFIG_ATM_LANE_MODULE ) br_fdb_get_hook =NULL ; br_fdb_put_hook =NULL ;#endif + +/* netif_receive_skb uses RCU */ +synchronize_kernel (); }EXPORT_SYMBOL (br_should_route_hook);
net/bridge/br_if.c +85 -75
251 lines not on this page · raw message
net/bridge/br_input.c +4 -1
@@ -149,7 +149,10 @@ goto handle_special_frame;if (p->state ==BR_STATE_FORWARDING ) { -if (br_should_route_hook &&br_should_route_hook (&skb)) { +int (*curhook)(struct sk_buff **) = br_should_route_hook; + +barrier ();/* prevent compiler RCU problems */ +if (curhook &&curhook (&skb)) {read_unlock (&br->lock);return -1 ; }
net/bridge/br_ioctl.c +13 -2
@@ -126,8 +126,10 @@struct __port_info p;struct net_bridge_port *pt; +read_lock (&br->lock);if ((pt =br_get_port (br, arg1)) ==NULL )return -EINVAL ; +read_unlock (&br->lock);memset (&p,0 ,sizeof (struct __port_info ));memcpy (&p.designated_root, &pt->designated_root,8 );
@@ -161,9 +163,14 @@ {struct net_bridge_port *p; -if ((p =br_get_port (br, arg0)) ==NULL ) +read_lock (&br->lock); +if ((p =br_get_port (br, arg0)) ==NULL ) { +read_unlock (&br->lock);return -EINVAL ; + + }br_stp_set_port_priority (p, arg1); +read_unlock (&br->lock);return 0 ; }
@@ -171,9 +178,13 @@ {struct net_bridge_port *p; -if ((p =br_get_port (br, arg0)) ==NULL ) +read_lock (&br->lock); +if ((p =br_get_port (br, arg0)) ==NULL ) { +read_unlock (&br->lock);return -EINVAL ; + }br_stp_set_path_cost (p, arg1); +read_unlock (&br->lock);return 0 ; }
net/bridge/br_private.h +2 -1
@@ -75,11 +75,12 @@struct br_timer forward_delay_timer;struct br_timer hold_timer;struct br_timer message_age_timer; +struct rcu_head rcu; };struct net_bridge { -struct net_bridge *next; +struct list_head bridge_list;rwlock_t lock;struct net_bridge_port *port_list;struct net_device dev;
net/bridge/netfilter/ebtable_broute.c +3 -5
@@ -14,7 +14,6 @@#include <linux/netfilter_bridge/ebtables.h> #include <linux/module.h> #include <linux/if_bridge.h> -#include <linux/brlock.h> // EBT_ACCEPT means the frame will be bridged // EBT_DROP means the frame will be routed
@@ -68,18 +67,17 @@ ret =ebt_register_table (&broute_table);if (ret <0 )return ret; -br_write_lock_bh (BR_NETPROTO_LOCK );// see br_input.c br_should_route_hook = ebt_broute; -br_write_unlock_bh (BR_NETPROTO_LOCK ); +synchronize_kernel (); +return ret; } static void __exit fini(void) { -br_write_lock_bh (BR_NETPROTO_LOCK ); br_should_route_hook =NULL ; -br_write_unlock_bh (BR_NETPROTO_LOCK ); +synchronize_kernel ();ebt_unregister_table (&broute_table); }
+static void __br_del_if(struct net_bridge_port *p) +{
- }
-
- pptr = &((*pptr)->next);
- }
+ br_fdb_delete_by_port(p->br, p);
- br_fdb_delete_by_port(br, p); - kfree(p); - dev_put(dev); - - return 0; + /* defer actual free till after receive BH has completed */ + call_rcu(&p->rcu, (void (*)(void *)) kfree, p);
}
Missing dev_put? Perhaps you'd want to register a callback which also decrements the reference count.
Zwane