Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 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) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 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 | |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame^] | 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) |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 19 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 20 | /* |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 21 | * Note the allocation or reception of a socket buffer. |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 22 | */ |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 23 | void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 24 | { |
| 25 | const void *here = __builtin_return_address(0); |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame^] | 26 | int n = atomic_inc_return(select_skb_count(skb)); |
Reshetova, Elena | 6335479 | 2017-06-30 13:07:58 +0300 | [diff] [blame] | 27 | trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* |
| 31 | * Note the re-emergence of a socket buffer from a queue or buffer. |
| 32 | */ |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 33 | void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 34 | { |
| 35 | const void *here = __builtin_return_address(0); |
| 36 | if (skb) { |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame^] | 37 | int n = atomic_read(select_skb_count(skb)); |
Reshetova, Elena | 6335479 | 2017-06-30 13:07:58 +0300 | [diff] [blame] | 38 | trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | * Note the addition of a ref on a socket buffer. |
| 44 | */ |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 45 | void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 46 | { |
| 47 | const void *here = __builtin_return_address(0); |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame^] | 48 | int n = atomic_inc_return(select_skb_count(skb)); |
Reshetova, Elena | 6335479 | 2017-06-30 13:07:58 +0300 | [diff] [blame] | 49 | trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 50 | skb_get(skb); |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * Note the destruction of a socket buffer. |
| 55 | */ |
David Howells | 71f3ca4 | 2016-09-17 10:49:14 +0100 | [diff] [blame] | 56 | void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 57 | { |
| 58 | const void *here = __builtin_return_address(0); |
| 59 | if (skb) { |
| 60 | int n; |
| 61 | CHECK_SLAB_OKAY(&skb->users); |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame^] | 62 | n = atomic_dec_return(select_skb_count(skb)); |
Reshetova, Elena | 6335479 | 2017-06-30 13:07:58 +0300 | [diff] [blame] | 63 | trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here); |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 64 | kfree_skb(skb); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Clear a queue of socket buffers. |
| 70 | */ |
| 71 | void rxrpc_purge_queue(struct sk_buff_head *list) |
| 72 | { |
| 73 | const void *here = __builtin_return_address(0); |
| 74 | struct sk_buff *skb; |
| 75 | while ((skb = skb_dequeue((list))) != NULL) { |
David Howells | 987db9f | 2019-08-19 09:25:38 +0100 | [diff] [blame^] | 76 | int n = atomic_dec_return(select_skb_count(skb)); |
| 77 | trace_rxrpc_skb(skb, rxrpc_skb_purged, |
Reshetova, Elena | 6335479 | 2017-06-30 13:07:58 +0300 | [diff] [blame] | 78 | refcount_read(&skb->users), n, here); |
David Howells | df844fd | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 79 | kfree_skb(skb); |
| 80 | } |
| 81 | } |