Commit 64667988 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

ipmr: ipmr_cache_report() changes

ipmr_cache_report() first argument can be marked const, and we change
the caller convention about which lock needs to be held.

Instead of read_lock(&mrt_lock), we can use rcu_read_lock().
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 0b490b51
...@@ -106,7 +106,7 @@ static void ipmr_free_table(struct mr_table *mrt); ...@@ -106,7 +106,7 @@ static void ipmr_free_table(struct mr_table *mrt);
static void ip_mr_forward(struct net *net, struct mr_table *mrt, static void ip_mr_forward(struct net *net, struct mr_table *mrt,
struct net_device *dev, struct sk_buff *skb, struct net_device *dev, struct sk_buff *skb,
struct mfc_cache *cache, int local); struct mfc_cache *cache, int local);
static int ipmr_cache_report(struct mr_table *mrt, static int ipmr_cache_report(const struct mr_table *mrt,
struct sk_buff *pkt, vifi_t vifi, int assert); struct sk_buff *pkt, vifi_t vifi, int assert);
static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc, static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc,
int cmd); int cmd);
...@@ -507,11 +507,15 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -507,11 +507,15 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)
return err; return err;
} }
read_lock(&mrt_lock);
dev->stats.tx_bytes += skb->len; dev->stats.tx_bytes += skb->len;
dev->stats.tx_packets++; dev->stats.tx_packets++;
ipmr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, IGMPMSG_WHOLEPKT); rcu_read_lock();
read_unlock(&mrt_lock);
/* Pairs with WRITE_ONCE() in vif_add() and vif_delete() */
ipmr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num),
IGMPMSG_WHOLEPKT);
rcu_read_unlock();
kfree_skb(skb); kfree_skb(skb);
return NETDEV_TX_OK; return NETDEV_TX_OK;
} }
...@@ -665,9 +669,10 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify, ...@@ -665,9 +669,10 @@ static int vif_delete(struct mr_table *mrt, int vifi, int notify,
vifi, mrt->id); vifi, mrt->id);
RCU_INIT_POINTER(v->dev, NULL); RCU_INIT_POINTER(v->dev, NULL);
if (vifi == mrt->mroute_reg_vif_num) if (vifi == mrt->mroute_reg_vif_num) {
mrt->mroute_reg_vif_num = -1; /* Pairs with READ_ONCE() in ipmr_cache_report() and reg_vif_xmit() */
WRITE_ONCE(mrt->mroute_reg_vif_num, -1);
}
if (vifi + 1 == mrt->maxvif) { if (vifi + 1 == mrt->maxvif) {
int tmp; int tmp;
...@@ -895,8 +900,10 @@ static int vif_add(struct net *net, struct mr_table *mrt, ...@@ -895,8 +900,10 @@ static int vif_add(struct net *net, struct mr_table *mrt,
write_lock_bh(&mrt_lock); write_lock_bh(&mrt_lock);
rcu_assign_pointer(v->dev, dev); rcu_assign_pointer(v->dev, dev);
netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC);
if (v->flags & VIFF_REGISTER) if (v->flags & VIFF_REGISTER) {
mrt->mroute_reg_vif_num = vifi; /* Pairs with READ_ONCE() in ipmr_cache_report() and reg_vif_xmit() */
WRITE_ONCE(mrt->mroute_reg_vif_num, vifi);
}
if (vifi+1 > mrt->maxvif) if (vifi+1 > mrt->maxvif)
mrt->maxvif = vifi+1; mrt->maxvif = vifi+1;
write_unlock_bh(&mrt_lock); write_unlock_bh(&mrt_lock);
...@@ -1005,9 +1012,9 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt, ...@@ -1005,9 +1012,9 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt,
/* Bounce a cache query up to mrouted and netlink. /* Bounce a cache query up to mrouted and netlink.
* *
* Called under mrt_lock. * Called under rcu_read_lock().
*/ */
static int ipmr_cache_report(struct mr_table *mrt, static int ipmr_cache_report(const struct mr_table *mrt,
struct sk_buff *pkt, vifi_t vifi, int assert) struct sk_buff *pkt, vifi_t vifi, int assert)
{ {
const int ihl = ip_hdrlen(pkt); const int ihl = ip_hdrlen(pkt);
...@@ -1042,8 +1049,11 @@ static int ipmr_cache_report(struct mr_table *mrt, ...@@ -1042,8 +1049,11 @@ static int ipmr_cache_report(struct mr_table *mrt,
msg->im_vif = vifi; msg->im_vif = vifi;
msg->im_vif_hi = vifi >> 8; msg->im_vif_hi = vifi >> 8;
} else { } else {
msg->im_vif = mrt->mroute_reg_vif_num; /* Pairs with WRITE_ONCE() in vif_add() and vif_delete() */
msg->im_vif_hi = mrt->mroute_reg_vif_num >> 8; int vif_num = READ_ONCE(mrt->mroute_reg_vif_num);
msg->im_vif = vif_num;
msg->im_vif_hi = vif_num >> 8;
} }
ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2;
ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) +
...@@ -1068,10 +1078,8 @@ static int ipmr_cache_report(struct mr_table *mrt, ...@@ -1068,10 +1078,8 @@ static int ipmr_cache_report(struct mr_table *mrt,
skb->transport_header = skb->network_header; skb->transport_header = skb->network_header;
} }
rcu_read_lock();
mroute_sk = rcu_dereference(mrt->mroute_sk); mroute_sk = rcu_dereference(mrt->mroute_sk);
if (!mroute_sk) { if (!mroute_sk) {
rcu_read_unlock();
kfree_skb(skb); kfree_skb(skb);
return -EINVAL; return -EINVAL;
} }
...@@ -1080,7 +1088,7 @@ static int ipmr_cache_report(struct mr_table *mrt, ...@@ -1080,7 +1088,7 @@ static int ipmr_cache_report(struct mr_table *mrt,
/* Deliver to mrouted */ /* Deliver to mrouted */
ret = sock_queue_rcv_skb(mroute_sk, skb); ret = sock_queue_rcv_skb(mroute_sk, skb);
rcu_read_unlock();
if (ret < 0) { if (ret < 0) {
net_warn_ratelimited("mroute: pending queue full, dropping entries\n"); net_warn_ratelimited("mroute: pending queue full, dropping entries\n");
kfree_skb(skb); kfree_skb(skb);
...@@ -1090,6 +1098,7 @@ static int ipmr_cache_report(struct mr_table *mrt, ...@@ -1090,6 +1098,7 @@ static int ipmr_cache_report(struct mr_table *mrt,
} }
/* Queue a packet for resolution. It gets locked cache entry! */ /* Queue a packet for resolution. It gets locked cache entry! */
/* Called under rcu_read_lock() */
static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi,
struct sk_buff *skb, struct net_device *dev) struct sk_buff *skb, struct net_device *dev)
{ {
...@@ -1830,7 +1839,9 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, ...@@ -1830,7 +1839,9 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt,
vif->bytes_out += skb->len; vif->bytes_out += skb->len;
vif_dev->stats.tx_bytes += skb->len; vif_dev->stats.tx_bytes += skb->len;
vif_dev->stats.tx_packets++; vif_dev->stats.tx_packets++;
rcu_read_lock();
ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT);
rcu_read_unlock();
goto out_free; goto out_free;
} }
...@@ -1980,10 +1991,12 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt, ...@@ -1980,10 +1991,12 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt,
c->_c.mfc_un.res.last_assert + c->_c.mfc_un.res.last_assert +
MFC_ASSERT_THRESH)) { MFC_ASSERT_THRESH)) {
c->_c.mfc_un.res.last_assert = jiffies; c->_c.mfc_un.res.last_assert = jiffies;
rcu_read_lock();
ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF); ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF);
if (mrt->mroute_do_wrvifwhole) if (mrt->mroute_do_wrvifwhole)
ipmr_cache_report(mrt, skb, true_vifi, ipmr_cache_report(mrt, skb, true_vifi,
IGMPMSG_WRVIFWHOLE); IGMPMSG_WRVIFWHOLE);
rcu_read_unlock();
} }
goto dont_forward; goto dont_forward;
} }
......
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