blob: 0348d2bf6f7d8e85ea075c992a5b5368ca0362a0 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells17926a72007-04-26 15:48:28 -07002/* 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 Howells17926a72007-04-26 15:48:28 -07006 */
7
Joe Perches9b6d5392016-06-02 12:08:52 -07008#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
David Howells17926a72007-04-26 15:48:28 -070010#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 Howells987db9f2019-08-19 09:25:38 +010017#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 Howells71f3ca42016-09-17 10:49:14 +010019
David Howells17926a72007-04-26 15:48:28 -070020/*
David Howells71f3ca42016-09-17 10:49:14 +010021 * Note the allocation or reception of a socket buffer.
David Howellsdf844fd2016-08-23 15:27:24 +010022 */
David Howells71f3ca42016-09-17 10:49:14 +010023void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010024{
25 const void *here = __builtin_return_address(0);
David Howells987db9f2019-08-19 09:25:38 +010026 int n = atomic_inc_return(select_skb_count(skb));
David Howellsd0d5c0c2019-08-27 10:13:46 +010027 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
28 rxrpc_skb(skb)->rx_flags, here);
David Howellsdf844fd2016-08-23 15:27:24 +010029}
30
31/*
32 * Note the re-emergence of a socket buffer from a queue or buffer.
33 */
David Howells71f3ca42016-09-17 10:49:14 +010034void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010035{
36 const void *here = __builtin_return_address(0);
37 if (skb) {
David Howells987db9f2019-08-19 09:25:38 +010038 int n = atomic_read(select_skb_count(skb));
David Howellsd0d5c0c2019-08-27 10:13:46 +010039 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
40 rxrpc_skb(skb)->rx_flags, here);
David Howellsdf844fd2016-08-23 15:27:24 +010041 }
42}
43
44/*
45 * Note the addition of a ref on a socket buffer.
46 */
David Howells71f3ca42016-09-17 10:49:14 +010047void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010048{
49 const void *here = __builtin_return_address(0);
David Howells987db9f2019-08-19 09:25:38 +010050 int n = atomic_inc_return(select_skb_count(skb));
David Howellsd0d5c0c2019-08-27 10:13:46 +010051 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
52 rxrpc_skb(skb)->rx_flags, here);
David Howellsdf844fd2016-08-23 15:27:24 +010053 skb_get(skb);
54}
55
56/*
David Howellsd0d5c0c2019-08-27 10:13:46 +010057 * Note the dropping of a ref on a socket buffer by the core.
58 */
59void rxrpc_eaten_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
60{
61 const void *here = __builtin_return_address(0);
62 int n = atomic_inc_return(&rxrpc_n_rx_skbs);
63 trace_rxrpc_skb(skb, op, 0, n, 0, here);
64}
65
66/*
David Howellsdf844fd2016-08-23 15:27:24 +010067 * Note the destruction of a socket buffer.
68 */
David Howells71f3ca42016-09-17 10:49:14 +010069void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010070{
71 const void *here = __builtin_return_address(0);
72 if (skb) {
73 int n;
74 CHECK_SLAB_OKAY(&skb->users);
David Howells987db9f2019-08-19 09:25:38 +010075 n = atomic_dec_return(select_skb_count(skb));
David Howellsd0d5c0c2019-08-27 10:13:46 +010076 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
77 rxrpc_skb(skb)->rx_flags, here);
David Howellsdf844fd2016-08-23 15:27:24 +010078 kfree_skb(skb);
79 }
80}
81
82/*
83 * Clear a queue of socket buffers.
84 */
85void rxrpc_purge_queue(struct sk_buff_head *list)
86{
87 const void *here = __builtin_return_address(0);
88 struct sk_buff *skb;
89 while ((skb = skb_dequeue((list))) != NULL) {
David Howells987db9f2019-08-19 09:25:38 +010090 int n = atomic_dec_return(select_skb_count(skb));
91 trace_rxrpc_skb(skb, rxrpc_skb_purged,
David Howellsd0d5c0c2019-08-27 10:13:46 +010092 refcount_read(&skb->users), n,
93 rxrpc_skb(skb)->rx_flags, here);
David Howellsdf844fd2016-08-23 15:27:24 +010094 kfree_skb(skb);
95 }
96}