linux-yocto: fix kernel build (TMP)
[scm/bb/meta-tizen.git] / recipes-kernel / linux / linux-yocto / 0001-net-ptp-use-sk_unattached_filter_create-for-BPF.patch
1 From e62d2df084e2849edffb206559725fa81bb569a8 Mon Sep 17 00:00:00 2001
2 From: Daniel Borkmann <dborkman@redhat.com>
3 Date: Fri, 28 Mar 2014 18:58:21 +0100
4 Subject: [PATCH] net: ptp: use sk_unattached_filter_create() for BPF
5
6 This patch migrates an open-coded sk_run_filter() implementation with
7 proper use of the BPF API, that is, sk_unattached_filter_create(). This
8 migration is needed, as we will be internally transforming the filter
9 to a different representation, and therefore needs to be decoupled.
10
11 It is okay to do so as skb_timestamping_init() is called during
12 initialization of the network stack in core initcall via sock_init().
13 This would effectively also allow for PTP filters to be jit compiled if
14 bpf_jit_enable is set.
15
16 For better readability, there are also some newlines introduced, also
17 ptp_classify.h is only in kernel space.
18
19 Joint work with Alexei Starovoitov.
20
21 Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
22 Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
23 Cc: Richard Cochran <richard.cochran@omicron.at>
24 Cc: Jiri Benc <jbenc@redhat.com>
25 Signed-off-by: David S. Miller <davem@davemloft.net>
26 ---
27  include/linux/ptp_classify.h |  4 ----
28  net/core/timestamping.c      | 21 ++++++++++++++-------
29  2 files changed, 14 insertions(+), 11 deletions(-)
30
31 diff --git a/include/linux/ptp_classify.h b/include/linux/ptp_classify.h
32 index 1dc420b..3decfa4 100644
33 --- a/include/linux/ptp_classify.h
34 +++ b/include/linux/ptp_classify.h
35 @@ -27,11 +27,7 @@
36  #include <linux/if_vlan.h>
37  #include <linux/ip.h>
38  #include <linux/filter.h>
39 -#ifdef __KERNEL__
40  #include <linux/in.h>
41 -#else
42 -#include <netinet/in.h>
43 -#endif
44  
45  #define PTP_CLASS_NONE  0x00 /* not a PTP event message */
46  #define PTP_CLASS_V1    0x01 /* protocol version 1 */
47 diff --git a/net/core/timestamping.c b/net/core/timestamping.c
48 index 661b5a4..e43d56a 100644
49 --- a/net/core/timestamping.c
50 +++ b/net/core/timestamping.c
51 @@ -23,16 +23,13 @@
52  #include <linux/skbuff.h>
53  #include <linux/export.h>
54  
55 -static struct sock_filter ptp_filter[] = {
56 -       PTP_FILTER
57 -};
58 +static struct sk_filter *ptp_insns __read_mostly;
59  
60  static unsigned int classify(const struct sk_buff *skb)
61  {
62 -       if (likely(skb->dev &&
63 -                  skb->dev->phydev &&
64 +       if (likely(skb->dev && skb->dev->phydev &&
65                    skb->dev->phydev->drv))
66 -               return sk_run_filter(skb, ptp_filter);
67 +               return SK_RUN_FILTER(ptp_insns, skb);
68         else
69                 return PTP_CLASS_NONE;
70  }
71 @@ -60,11 +57,13 @@ void skb_clone_tx_timestamp(struct sk_buff *skb)
72                 if (likely(phydev->drv->txtstamp)) {
73                         if (!atomic_inc_not_zero(&sk->sk_refcnt))
74                                 return;
75 +
76                         clone = skb_clone(skb, GFP_ATOMIC);
77                         if (!clone) {
78                                 sock_put(sk);
79                                 return;
80                         }
81 +
82                         clone->sk = sk;
83                         phydev->drv->txtstamp(phydev, clone, type);
84                 }
85 @@ -89,12 +88,15 @@ void skb_complete_tx_timestamp(struct sk_buff *skb,
86         }
87  
88         *skb_hwtstamps(skb) = *hwtstamps;
89 +
90         serr = SKB_EXT_ERR(skb);
91         memset(serr, 0, sizeof(*serr));
92         serr->ee.ee_errno = ENOMSG;
93         serr->ee.ee_origin = SO_EE_ORIGIN_TIMESTAMPING;
94         skb->sk = NULL;
95 +
96         err = sock_queue_err_skb(sk, skb);
97 +
98         sock_put(sk);
99         if (err)
100                 kfree_skb(skb);
101 @@ -135,5 +137,10 @@ EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
102  
103  void __init skb_timestamping_init(void)
104  {
105 -       BUG_ON(sk_chk_filter(ptp_filter, ARRAY_SIZE(ptp_filter)));
106 +       static struct sock_filter ptp_filter[] = { PTP_FILTER };
107 +       struct sock_fprog ptp_prog = {
108 +               .len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
109 +       };
110 +
111 +       BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
112  }
113 -- 
114 1.8.1.4
115