1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* ar-skbuff.c: socket buffer destruction handling 3 * 4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 5 * Written by David Howells (dhowells@redhat.com) 6 */ 7 8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9 10 #include <linux/module.h> 11 #include <linux/net.h> 12 #include <linux/skbuff.h> 13 #include <net/sock.h> 14 #include <net/af_rxrpc.h> 15 #include "ar-internal.h" 16 17 #define select_skb_count(skb) (&rxrpc_n_rx_skbs) 18 19 /* 20 * Note the allocation or reception of a socket buffer. 21 */ 22 void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 23 { 24 const void *here = __builtin_return_address(0); 25 int n = atomic_inc_return(select_skb_count(skb)); 26 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 27 } 28 29 /* 30 * Note the re-emergence of a socket buffer from a queue or buffer. 31 */ 32 void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 33 { 34 const void *here = __builtin_return_address(0); 35 if (skb) { 36 int n = atomic_read(select_skb_count(skb)); 37 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 38 } 39 } 40 41 /* 42 * Note the addition of a ref on a socket buffer. 43 */ 44 void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 45 { 46 const void *here = __builtin_return_address(0); 47 int n = atomic_inc_return(select_skb_count(skb)); 48 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 49 skb_get(skb); 50 } 51 52 /* 53 * Note the dropping of a ref on a socket buffer by the core. 54 */ 55 void rxrpc_eaten_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 56 { 57 const void *here = __builtin_return_address(0); 58 int n = atomic_inc_return(&rxrpc_n_rx_skbs); 59 trace_rxrpc_skb(skb, op, 0, n, here); 60 } 61 62 /* 63 * Note the destruction of a socket buffer. 64 */ 65 void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 66 { 67 const void *here = __builtin_return_address(0); 68 if (skb) { 69 int n; 70 n = atomic_dec_return(select_skb_count(skb)); 71 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 72 kfree_skb(skb); 73 } 74 } 75 76 /* 77 * Clear a queue of socket buffers. 78 */ 79 void rxrpc_purge_queue(struct sk_buff_head *list) 80 { 81 const void *here = __builtin_return_address(0); 82 struct sk_buff *skb; 83 while ((skb = skb_dequeue((list))) != NULL) { 84 int n = atomic_dec_return(select_skb_count(skb)); 85 trace_rxrpc_skb(skb, rxrpc_skb_purged, 86 refcount_read(&skb->users), n, here); 87 kfree_skb(skb); 88 } 89 } 90