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