Commit 2231c5af authored by Ying Xue's avatar Ying Xue Committed by David S. Miller

tipc: use RCU to protect media_ptr pointer

Now the media_ptr pointer is protected with tipc_net_lock write lock
on write side; tipc_net_lock read lock is used to read side. As the
part of effort of eliminating tipc_net_lock, we decide to adjust the
locking policy of media_ptr pointer protection: on write side, RTNL
lock is use while on read side RCU read lock is applied.
Signed-off-by: default avatarYing Xue <ying.xue@windriver.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Reviewed-by: default avatarErik Hugne <erik.hugne@ericsson.com>
Tested-by: default avatarErik Hugne <erik.hugne@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7a2f7d18
...@@ -458,7 +458,7 @@ int tipc_enable_l2_media(struct tipc_bearer *b) ...@@ -458,7 +458,7 @@ int tipc_enable_l2_media(struct tipc_bearer *b)
return -ENODEV; return -ENODEV;
/* Associate TIPC bearer with Ethernet bearer */ /* Associate TIPC bearer with Ethernet bearer */
b->media_ptr = dev; rcu_assign_pointer(b->media_ptr, dev);
memset(b->bcast_addr.value, 0, sizeof(b->bcast_addr.value)); memset(b->bcast_addr.value, 0, sizeof(b->bcast_addr.value));
memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len); memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
b->bcast_addr.media_id = b->media->type_id; b->bcast_addr.media_id = b->media->type_id;
...@@ -477,7 +477,10 @@ int tipc_enable_l2_media(struct tipc_bearer *b) ...@@ -477,7 +477,10 @@ int tipc_enable_l2_media(struct tipc_bearer *b)
*/ */
void tipc_disable_l2_media(struct tipc_bearer *b) void tipc_disable_l2_media(struct tipc_bearer *b)
{ {
struct net_device *dev = (struct net_device *)b->media_ptr; struct net_device *dev;
dev = (struct net_device *)rtnl_dereference(b->media_ptr);
RCU_INIT_POINTER(b->media_ptr, NULL);
RCU_INIT_POINTER(dev->tipc_ptr, NULL); RCU_INIT_POINTER(dev->tipc_ptr, NULL);
dev_put(dev); dev_put(dev);
} }
...@@ -492,8 +495,12 @@ int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b, ...@@ -492,8 +495,12 @@ int tipc_l2_send_msg(struct sk_buff *buf, struct tipc_bearer *b,
struct tipc_media_addr *dest) struct tipc_media_addr *dest)
{ {
struct sk_buff *clone; struct sk_buff *clone;
struct net_device *dev;
int delta; int delta;
struct net_device *dev = (struct net_device *)b->media_ptr;
dev = (struct net_device *)rcu_dereference_rtnl(b->media_ptr);
if (!dev)
return 0;
clone = skb_clone(buf, GFP_ATOMIC); clone = skb_clone(buf, GFP_ATOMIC);
if (!clone) if (!clone)
......
...@@ -128,7 +128,7 @@ struct tipc_media { ...@@ -128,7 +128,7 @@ struct tipc_media {
* care of initializing all other fields. * care of initializing all other fields.
*/ */
struct tipc_bearer { struct tipc_bearer {
void *media_ptr; /* initalized by media */ void __rcu *media_ptr; /* initalized by media */
u32 mtu; /* initalized by media */ u32 mtu; /* initalized by media */
struct tipc_media_addr addr; /* initalized by media */ struct tipc_media_addr addr; /* initalized by media */
char name[TIPC_MAX_BEARER_NAME]; char name[TIPC_MAX_BEARER_NAME];
......
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