12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 28c3e34a4SDavid Howells /* ar-skbuff.c: socket buffer destruction handling 38c3e34a4SDavid Howells * 48c3e34a4SDavid Howells * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 58c3e34a4SDavid Howells * Written by David Howells (dhowells@redhat.com) 68c3e34a4SDavid Howells */ 78c3e34a4SDavid Howells 88c3e34a4SDavid Howells #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 98c3e34a4SDavid Howells 108c3e34a4SDavid Howells #include <linux/module.h> 118c3e34a4SDavid Howells #include <linux/net.h> 128c3e34a4SDavid Howells #include <linux/skbuff.h> 138c3e34a4SDavid Howells #include <net/sock.h> 148c3e34a4SDavid Howells #include <net/af_rxrpc.h> 158c3e34a4SDavid Howells #include "ar-internal.h" 168c3e34a4SDavid Howells 17*987db9f7SDavid Howells #define is_tx_skb(skb) (rxrpc_skb(skb)->rx_flags & RXRPC_SKB_TX_BUFFER) 18*987db9f7SDavid Howells #define select_skb_count(skb) (is_tx_skb(skb) ? &rxrpc_n_tx_skbs : &rxrpc_n_rx_skbs) 1971f3ca40SDavid Howells 208c3e34a4SDavid Howells /* 2171f3ca40SDavid Howells * Note the allocation or reception of a socket buffer. 22df844fd4SDavid Howells */ 2371f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 24df844fd4SDavid Howells { 25df844fd4SDavid Howells const void *here = __builtin_return_address(0); 26*987db9f7SDavid Howells int n = atomic_inc_return(select_skb_count(skb)); 2763354797SReshetova, Elena trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 28df844fd4SDavid Howells } 29df844fd4SDavid Howells 30df844fd4SDavid Howells /* 31df844fd4SDavid Howells * Note the re-emergence of a socket buffer from a queue or buffer. 32df844fd4SDavid Howells */ 3371f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 34df844fd4SDavid Howells { 35df844fd4SDavid Howells const void *here = __builtin_return_address(0); 36df844fd4SDavid Howells if (skb) { 37*987db9f7SDavid Howells int n = atomic_read(select_skb_count(skb)); 3863354797SReshetova, Elena trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 39df844fd4SDavid Howells } 40df844fd4SDavid Howells } 41df844fd4SDavid Howells 42df844fd4SDavid Howells /* 43df844fd4SDavid Howells * Note the addition of a ref on a socket buffer. 44df844fd4SDavid Howells */ 4571f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 46df844fd4SDavid Howells { 47df844fd4SDavid Howells const void *here = __builtin_return_address(0); 48*987db9f7SDavid Howells int n = atomic_inc_return(select_skb_count(skb)); 4963354797SReshetova, Elena trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 50df844fd4SDavid Howells skb_get(skb); 51df844fd4SDavid Howells } 52df844fd4SDavid Howells 53df844fd4SDavid Howells /* 54df844fd4SDavid Howells * Note the destruction of a socket buffer. 55df844fd4SDavid Howells */ 5671f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) 57df844fd4SDavid Howells { 58df844fd4SDavid Howells const void *here = __builtin_return_address(0); 59df844fd4SDavid Howells if (skb) { 60df844fd4SDavid Howells int n; 61df844fd4SDavid Howells CHECK_SLAB_OKAY(&skb->users); 62*987db9f7SDavid Howells n = atomic_dec_return(select_skb_count(skb)); 6363354797SReshetova, Elena trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); 64df844fd4SDavid Howells kfree_skb(skb); 65df844fd4SDavid Howells } 66df844fd4SDavid Howells } 67df844fd4SDavid Howells 68df844fd4SDavid Howells /* 69df844fd4SDavid Howells * Clear a queue of socket buffers. 70df844fd4SDavid Howells */ 71df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *list) 72df844fd4SDavid Howells { 73df844fd4SDavid Howells const void *here = __builtin_return_address(0); 74df844fd4SDavid Howells struct sk_buff *skb; 75df844fd4SDavid Howells while ((skb = skb_dequeue((list))) != NULL) { 76*987db9f7SDavid Howells int n = atomic_dec_return(select_skb_count(skb)); 77*987db9f7SDavid Howells trace_rxrpc_skb(skb, rxrpc_skb_purged, 7863354797SReshetova, Elena refcount_read(&skb->users), n, here); 79df844fd4SDavid Howells kfree_skb(skb); 80df844fd4SDavid Howells } 81df844fd4SDavid Howells } 82