Skip to content

Commit c11171a

Browse files
Sebastian Andrzej Siewiordavem330
authored andcommitted
net: Add netif_rx_any_context()
Quite some drivers make conditional decisions based on in_interrupt() to invoke either netif_rx() or netif_rx_ni(). Conditionals based on in_interrupt() or other variants of preempt count checks in drivers should not exist for various reasons and Linus clearly requested to either split the code pathes or pass an argument to the common functions which provides the context. This is obviously the correct solution, but for some of the affected drivers this needs a major rewrite due to their convoluted structure. As in_interrupt() usage in drivers needs to be phased out, provide netif_rx_any_context() as a stop gap for these drivers. This confines the in_interrupt() conditional to core code which in turn allows to remove the access to this check for driver code and provides one central place to do further modifications once the driver maze is cleaned up. Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f2bf88c commit c11171a

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎include/linux/netdevice.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,7 @@ void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog);
37853785
int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb);
37863786
int netif_rx(struct sk_buff *skb);
37873787
int netif_rx_ni(struct sk_buff *skb);
3788+
int netif_rx_any_context(struct sk_buff *skb);
37883789
int netif_receive_skb(struct sk_buff *skb);
37893790
int netif_receive_skb_core(struct sk_buff *skb);
37903791
void netif_receive_skb_list(struct list_head *head);

‎net/core/dev.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,6 +4841,21 @@ int netif_rx_ni(struct sk_buff *skb)
48414841
}
48424842
EXPORT_SYMBOL(netif_rx_ni);
48434843

4844+
int netif_rx_any_context(struct sk_buff *skb)
4845+
{
4846+
/*
4847+
* If invoked from contexts which do not invoke bottom half
4848+
* processing either at return from interrupt or when softrqs are
4849+
* reenabled, use netif_rx_ni() which invokes bottomhalf processing
4850+
* directly.
4851+
*/
4852+
if (in_interrupt())
4853+
return netif_rx(skb);
4854+
else
4855+
return netif_rx_ni(skb);
4856+
}
4857+
EXPORT_SYMBOL(netif_rx_any_context);
4858+
48444859
static __latent_entropy void net_tx_action(struct softirq_action *h)
48454860
{
48464861
struct softnet_data *sd = this_cpu_ptr(&softnet_data);

0 commit comments

Comments
 (0)