Blame view

net/rxrpc/skbuff.c 2.58 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
17926a793   David Howells   [AF_RXRPC]: Provi...
2
3
4
5
  /* ar-skbuff.c: socket buffer destruction handling
   *
   * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
   * Written by David Howells (dhowells@redhat.com)
17926a793   David Howells   [AF_RXRPC]: Provi...
6
   */
9b6d53985   Joe Perches   rxrpc: Use pr_<le...
7
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17926a793   David Howells   [AF_RXRPC]: Provi...
8
9
10
11
12
13
  #include <linux/module.h>
  #include <linux/net.h>
  #include <linux/skbuff.h>
  #include <net/sock.h>
  #include <net/af_rxrpc.h>
  #include "ar-internal.h"
987db9f7c   David Howells   rxrpc: Use the tx...
14
15
  #define is_tx_skb(skb) (rxrpc_skb(skb)->rx_flags & RXRPC_SKB_TX_BUFFER)
  #define select_skb_count(skb) (is_tx_skb(skb) ? &rxrpc_n_tx_skbs : &rxrpc_n_rx_skbs)
71f3ca408   David Howells   rxrpc: Improve sk...
16

17926a793   David Howells   [AF_RXRPC]: Provi...
17
  /*
71f3ca408   David Howells   rxrpc: Improve sk...
18
   * Note the allocation or reception of a socket buffer.
df844fd46   David Howells   rxrpc: Use a trac...
19
   */
71f3ca408   David Howells   rxrpc: Improve sk...
20
  void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd46   David Howells   rxrpc: Use a trac...
21
22
  {
  	const void *here = __builtin_return_address(0);
987db9f7c   David Howells   rxrpc: Use the tx...
23
  	int n = atomic_inc_return(select_skb_count(skb));
d0d5c0cd1   David Howells   rxrpc: Use skb_un...
24
25
  	trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
  			rxrpc_skb(skb)->rx_flags, here);
df844fd46   David Howells   rxrpc: Use a trac...
26
27
28
29
30
  }
  
  /*
   * Note the re-emergence of a socket buffer from a queue or buffer.
   */
71f3ca408   David Howells   rxrpc: Improve sk...
31
  void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd46   David Howells   rxrpc: Use a trac...
32
33
34
  {
  	const void *here = __builtin_return_address(0);
  	if (skb) {
987db9f7c   David Howells   rxrpc: Use the tx...
35
  		int n = atomic_read(select_skb_count(skb));
d0d5c0cd1   David Howells   rxrpc: Use skb_un...
36
37
  		trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
  				rxrpc_skb(skb)->rx_flags, here);
df844fd46   David Howells   rxrpc: Use a trac...
38
39
40
41
42
43
  	}
  }
  
  /*
   * Note the addition of a ref on a socket buffer.
   */
71f3ca408   David Howells   rxrpc: Improve sk...
44
  void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd46   David Howells   rxrpc: Use a trac...
45
46
  {
  	const void *here = __builtin_return_address(0);
987db9f7c   David Howells   rxrpc: Use the tx...
47
  	int n = atomic_inc_return(select_skb_count(skb));
d0d5c0cd1   David Howells   rxrpc: Use skb_un...
48
49
  	trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
  			rxrpc_skb(skb)->rx_flags, here);
df844fd46   David Howells   rxrpc: Use a trac...
50
51
52
53
  	skb_get(skb);
  }
  
  /*
d0d5c0cd1   David Howells   rxrpc: Use skb_un...
54
55
56
57
58
59
60
61
62
63
   * Note the dropping of a ref on a socket buffer by the core.
   */
  void rxrpc_eaten_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
  {
  	const void *here = __builtin_return_address(0);
  	int n = atomic_inc_return(&rxrpc_n_rx_skbs);
  	trace_rxrpc_skb(skb, op, 0, n, 0, here);
  }
  
  /*
df844fd46   David Howells   rxrpc: Use a trac...
64
65
   * Note the destruction of a socket buffer.
   */
71f3ca408   David Howells   rxrpc: Improve sk...
66
  void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd46   David Howells   rxrpc: Use a trac...
67
68
69
70
71
  {
  	const void *here = __builtin_return_address(0);
  	if (skb) {
  		int n;
  		CHECK_SLAB_OKAY(&skb->users);
987db9f7c   David Howells   rxrpc: Use the tx...
72
  		n = atomic_dec_return(select_skb_count(skb));
d0d5c0cd1   David Howells   rxrpc: Use skb_un...
73
74
  		trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
  				rxrpc_skb(skb)->rx_flags, here);
df844fd46   David Howells   rxrpc: Use a trac...
75
76
77
78
79
80
81
82
83
84
85
86
  		kfree_skb(skb);
  	}
  }
  
  /*
   * Clear a queue of socket buffers.
   */
  void rxrpc_purge_queue(struct sk_buff_head *list)
  {
  	const void *here = __builtin_return_address(0);
  	struct sk_buff *skb;
  	while ((skb = skb_dequeue((list))) != NULL) {
987db9f7c   David Howells   rxrpc: Use the tx...
87
88
  		int n = atomic_dec_return(select_skb_count(skb));
  		trace_rxrpc_skb(skb, rxrpc_skb_purged,
d0d5c0cd1   David Howells   rxrpc: Use skb_un...
89
90
  				refcount_read(&skb->users), n,
  				rxrpc_skb(skb)->rx_flags, here);
df844fd46   David Howells   rxrpc: Use a trac...
91
92
93
  		kfree_skb(skb);
  	}
  }