Skip to content

Commit

Permalink
net: remove enum skb_free_reason
Browse files Browse the repository at this point in the history
enum skb_drop_reason is more generic, we can adopt it instead.

Provide dev_kfree_skb_irq_reason() and dev_kfree_skb_any_reason().

This means drivers can use more precise drop reasons if they want to.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Yunsheng Lin <linyunsheng@huawei.com>
Link: https://lore.kernel.org/r/20230306204313.10492-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Eric Dumazet authored and kuba-moo committed Mar 8, 2023
1 parent 0194b64 commit 40bbae5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
18 changes: 7 additions & 11 deletions include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <linux/rbtree.h>
#include <net/net_trackers.h>
#include <net/net_debug.h>
#include <net/dropreason.h>

struct netpoll_info;
struct device;
Expand Down Expand Up @@ -3804,13 +3805,8 @@ static inline unsigned int get_netdev_rx_queue_index(

int netif_get_num_default_rss_queues(void);

enum skb_free_reason {
SKB_REASON_CONSUMED,
SKB_REASON_DROPPED,
};

void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
void dev_kfree_skb_irq_reason(struct sk_buff *skb, enum skb_drop_reason reason);
void dev_kfree_skb_any_reason(struct sk_buff *skb, enum skb_drop_reason reason);

/*
* It is not allowed to call kfree_skb() or consume_skb() from hardware
Expand All @@ -3833,22 +3829,22 @@ void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
*/
static inline void dev_kfree_skb_irq(struct sk_buff *skb)
{
__dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
dev_kfree_skb_irq_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED);
}

static inline void dev_consume_skb_irq(struct sk_buff *skb)
{
__dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
dev_kfree_skb_irq_reason(skb, SKB_CONSUMED);
}

static inline void dev_kfree_skb_any(struct sk_buff *skb)
{
__dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
dev_kfree_skb_any_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED);
}

static inline void dev_consume_skb_any(struct sk_buff *skb)
{
__dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
dev_kfree_skb_any_reason(skb, SKB_CONSUMED);
}

u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
Expand Down
20 changes: 9 additions & 11 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3075,7 +3075,7 @@ void __netif_schedule(struct Qdisc *q)
EXPORT_SYMBOL(__netif_schedule);

struct dev_kfree_skb_cb {
enum skb_free_reason reason;
enum skb_drop_reason reason;
};

static struct dev_kfree_skb_cb *get_kfree_skb_cb(const struct sk_buff *skb)
Expand Down Expand Up @@ -3108,7 +3108,7 @@ void netif_tx_wake_queue(struct netdev_queue *dev_queue)
}
EXPORT_SYMBOL(netif_tx_wake_queue);

void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason)
void dev_kfree_skb_irq_reason(struct sk_buff *skb, enum skb_drop_reason reason)
{
unsigned long flags;

Expand All @@ -3128,18 +3128,16 @@ void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason)
raise_softirq_irqoff(NET_TX_SOFTIRQ);
local_irq_restore(flags);
}
EXPORT_SYMBOL(__dev_kfree_skb_irq);
EXPORT_SYMBOL(dev_kfree_skb_irq_reason);

void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason)
void dev_kfree_skb_any_reason(struct sk_buff *skb, enum skb_drop_reason reason)
{
if (in_hardirq() || irqs_disabled())
__dev_kfree_skb_irq(skb, reason);
else if (unlikely(reason == SKB_REASON_DROPPED))
kfree_skb(skb);
dev_kfree_skb_irq_reason(skb, reason);
else
consume_skb(skb);
kfree_skb_reason(skb, reason);
}
EXPORT_SYMBOL(__dev_kfree_skb_any);
EXPORT_SYMBOL(dev_kfree_skb_any_reason);


/**
Expand Down Expand Up @@ -5020,11 +5018,11 @@ static __latent_entropy void net_tx_action(struct softirq_action *h)
clist = clist->next;

WARN_ON(refcount_read(&skb->users));
if (likely(get_kfree_skb_cb(skb)->reason == SKB_REASON_CONSUMED))
if (likely(get_kfree_skb_cb(skb)->reason == SKB_CONSUMED))
trace_consume_skb(skb, net_tx_action);
else
trace_kfree_skb(skb, net_tx_action,
SKB_DROP_REASON_NOT_SPECIFIED);
get_kfree_skb_cb(skb)->reason);

if (skb->fclone != SKB_FCLONE_UNAVAILABLE)
__kfree_skb(skb);
Expand Down

0 comments on commit 40bbae5

Please sign in to comment.