Skip to content

Commit baebdf4

Browse files
Sebastian Andrzej Siewiordavem330
authored andcommitted
net: dev: Makes sure netif_rx() can be invoked in any context.
Dave suggested a while ago (eleven years by now) "Let's make netif_rx() work in all contexts and get rid of netif_rx_ni()". Eric agreed and pointed out that modern devices should use netif_receive_skb() to avoid the overhead. In the meantime someone added another variant, netif_rx_any_context(), which behaves as suggested. netif_rx() must be invoked with disabled bottom halves to ensure that pending softirqs, which were raised within the function, are handled. netif_rx_ni() can be invoked only from process context (bottom halves must be enabled) because the function handles pending softirqs without checking if bottom halves were disabled or not. netif_rx_any_context() invokes on the former functions by checking in_interrupts(). netif_rx() could be taught to handle both cases (disabled and enabled bottom halves) by simply disabling bottom halves while invoking netif_rx_internal(). The local_bh_enable() invocation will then invoke pending softirqs only if the BH-disable counter drops to zero. Eric is concerned about the overhead of BH-disable+enable especially in regard to the loopback driver. As critical as this driver is, it will receive a shortcut to avoid the additional overhead which is not needed. Add a local_bh_disable() section in netif_rx() to ensure softirqs are handled if needed. Provide __netif_rx() which does not disable BH and has a lockdep assert to ensure that interrupts are disabled. Use this shortcut in the loopback driver and in drivers/net/*.c. Make netif_rx_ni() and netif_rx_any_context() invoke netif_rx() so they can be removed once they are no more users left. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Reviewed-by: Toke Høiland-Jørgensen <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f234ae2 commit baebdf4

File tree

16 files changed

+60
-73
lines changed

16 files changed

+60
-73
lines changed

drivers/net/amt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
23732373
skb->pkt_type = PACKET_MULTICAST;
23742374
skb->ip_summed = CHECKSUM_NONE;
23752375
len = skb->len;
2376-
if (netif_rx(skb) == NET_RX_SUCCESS) {
2376+
if (__netif_rx(skb) == NET_RX_SUCCESS) {
23772377
amt_update_gw_status(amt, AMT_STATUS_RECEIVED_QUERY, true);
23782378
dev_sw_netstats_rx_add(amt->dev, len);
23792379
} else {
@@ -2470,7 +2470,7 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
24702470
skb->pkt_type = PACKET_MULTICAST;
24712471
skb->ip_summed = CHECKSUM_NONE;
24722472
len = skb->len;
2473-
if (netif_rx(skb) == NET_RX_SUCCESS) {
2473+
if (__netif_rx(skb) == NET_RX_SUCCESS) {
24742474
amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_UPDATE,
24752475
true);
24762476
dev_sw_netstats_rx_add(amt->dev, len);

drivers/net/geneve.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev,
925925
}
926926

927927
skb->protocol = eth_type_trans(skb, geneve->dev);
928-
netif_rx(skb);
928+
__netif_rx(skb);
929929
dst_release(&rt->dst);
930930
return -EMSGSIZE;
931931
}
@@ -1021,7 +1021,7 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
10211021
}
10221022

10231023
skb->protocol = eth_type_trans(skb, geneve->dev);
1024-
netif_rx(skb);
1024+
__netif_rx(skb);
10251025
dst_release(dst);
10261026
return -EMSGSIZE;
10271027
}

drivers/net/gtp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb,
207207

208208
dev_sw_netstats_rx_add(pctx->dev, skb->len);
209209

210-
netif_rx(skb);
210+
__netif_rx(skb);
211211
return 0;
212212

213213
err:

drivers/net/loopback.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,
7878

7979
skb_orphan(skb);
8080

81-
/* Before queueing this packet to netif_rx(),
81+
/* Before queueing this packet to __netif_rx(),
8282
* make sure dst is refcounted.
8383
*/
8484
skb_dst_force(skb);
8585

8686
skb->protocol = eth_type_trans(skb, dev);
8787

8888
len = skb->len;
89-
if (likely(netif_rx(skb) == NET_RX_SUCCESS))
89+
if (likely(__netif_rx(skb) == NET_RX_SUCCESS))
9090
dev_lstats_add(dev, len);
9191

9292
return NETDEV_TX_OK;

drivers/net/macsec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
10331033
else
10341034
nskb->pkt_type = PACKET_MULTICAST;
10351035

1036-
netif_rx(nskb);
1036+
__netif_rx(nskb);
10371037
}
10381038
continue;
10391039
}
@@ -1056,7 +1056,7 @@ static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
10561056

10571057
nskb->dev = ndev;
10581058

1059-
if (netif_rx(nskb) == NET_RX_SUCCESS) {
1059+
if (__netif_rx(nskb) == NET_RX_SUCCESS) {
10601060
u64_stats_update_begin(&secy_stats->syncp);
10611061
secy_stats->stats.InPktsUntagged++;
10621062
u64_stats_update_end(&secy_stats->syncp);
@@ -1288,7 +1288,7 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
12881288

12891289
macsec_reset_skb(nskb, macsec->secy.netdev);
12901290

1291-
ret = netif_rx(nskb);
1291+
ret = __netif_rx(nskb);
12921292
if (ret == NET_RX_SUCCESS) {
12931293
u64_stats_update_begin(&secy_stats->syncp);
12941294
secy_stats->stats.InPktsUnknownSCI++;

drivers/net/macvlan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static void macvlan_forward_source_one(struct sk_buff *skb,
410410
if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, dev->dev_addr))
411411
nskb->pkt_type = PACKET_HOST;
412412

413-
ret = netif_rx(nskb);
413+
ret = __netif_rx(nskb);
414414
macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, false);
415415
}
416416

@@ -468,7 +468,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
468468
/* forward to original port. */
469469
vlan = src;
470470
ret = macvlan_broadcast_one(skb, vlan, eth, 0) ?:
471-
netif_rx(skb);
471+
__netif_rx(skb);
472472
handle_res = RX_HANDLER_CONSUMED;
473473
goto out;
474474
}

drivers/net/mhi_net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev,
225225
u64_stats_inc(&mhi_netdev->stats.rx_packets);
226226
u64_stats_add(&mhi_netdev->stats.rx_bytes, skb->len);
227227
u64_stats_update_end(&mhi_netdev->stats.rx_syncp);
228-
netif_rx(skb);
228+
__netif_rx(skb);
229229
}
230230

231231
/* Refill if RX buffers queue becomes low */

drivers/net/ntb_netdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
119119
skb->protocol = eth_type_trans(skb, ndev);
120120
skb->ip_summed = CHECKSUM_NONE;
121121

122-
if (netif_rx(skb) == NET_RX_DROP) {
122+
if (__netif_rx(skb) == NET_RX_DROP) {
123123
ndev->stats.rx_errors++;
124124
ndev->stats.rx_dropped++;
125125
} else {

drivers/net/rionet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static int rionet_rx_clean(struct net_device *ndev)
109109
skb_put(rnet->rx_skb[i], RIO_MAX_MSG_SIZE);
110110
rnet->rx_skb[i]->protocol =
111111
eth_type_trans(rnet->rx_skb[i], ndev);
112-
error = netif_rx(rnet->rx_skb[i]);
112+
error = __netif_rx(rnet->rx_skb[i]);
113113

114114
if (error == NET_RX_DROP) {
115115
ndev->stats.rx_dropped++;

drivers/net/sb1000.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ printk("cm0: IP identification: %02x%02x fragment offset: %02x%02x\n", buffer[3
872872

873873
/* datagram completed: send to upper level */
874874
skb_trim(skb, dlen);
875-
netif_rx(skb);
875+
__netif_rx(skb);
876876
stats->rx_bytes+=dlen;
877877
stats->rx_packets++;
878878
lp->rx_skb[ns] = NULL;

0 commit comments

Comments
 (0)