xref: /linux/include/net/xdp.h (revision fcc680a647ba77370480fe753664cc10d572b240)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* include/net/xdp.h
3  *
4  * Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc.
5  */
6 #ifndef __LINUX_NET_XDP_H__
7 #define __LINUX_NET_XDP_H__
8 
9 #include <linux/bitfield.h>
10 #include <linux/filter.h>
11 #include <linux/netdevice.h>
12 #include <linux/skbuff.h> /* skb_shared_info */
13 
14 #include <net/page_pool/types.h>
15 
16 /**
17  * DOC: XDP RX-queue information
18  *
19  * The XDP RX-queue info (xdp_rxq_info) is associated with the driver
20  * level RX-ring queues.  It is information that is specific to how
21  * the driver has configured a given RX-ring queue.
22  *
23  * Each xdp_buff frame received in the driver carries a (pointer)
24  * reference to this xdp_rxq_info structure.  This provides the XDP
25  * data-path read-access to RX-info for both kernel and bpf-side
26  * (limited subset).
27  *
28  * For now, direct access is only safe while running in NAPI/softirq
29  * context.  Contents are read-mostly and must not be updated during
30  * driver NAPI/softirq poll.
31  *
32  * The driver usage API is a register and unregister API.
33  *
34  * The struct is not directly tied to the XDP prog.  A new XDP prog
35  * can be attached as long as it doesn't change the underlying
36  * RX-ring.  If the RX-ring does change significantly, the NIC driver
37  * naturally needs to stop the RX-ring before purging and reallocating
38  * memory.  In that process the driver MUST call unregister (which
39  * also applies for driver shutdown and unload).  The register API is
40  * also mandatory during RX-ring setup.
41  */
42 
43 enum xdp_mem_type {
44 	MEM_TYPE_PAGE_SHARED = 0, /* Split-page refcnt based model */
45 	MEM_TYPE_PAGE_ORDER0,     /* Orig XDP full page model */
46 	MEM_TYPE_PAGE_POOL,
47 	MEM_TYPE_XSK_BUFF_POOL,
48 	MEM_TYPE_MAX,
49 };
50 
51 /* XDP flags for ndo_xdp_xmit */
52 #define XDP_XMIT_FLUSH		(1U << 0)	/* doorbell signal consumer */
53 #define XDP_XMIT_FLAGS_MASK	XDP_XMIT_FLUSH
54 
55 struct xdp_mem_info {
56 	u32 type; /* enum xdp_mem_type, but known size type */
57 	u32 id;
58 };
59 
60 struct page_pool;
61 
62 struct xdp_rxq_info {
63 	struct net_device *dev;
64 	u32 queue_index;
65 	u32 reg_state;
66 	struct xdp_mem_info mem;
67 	unsigned int napi_id;
68 	u32 frag_size;
69 } ____cacheline_aligned; /* perf critical, avoid false-sharing */
70 
71 struct xdp_txq_info {
72 	struct net_device *dev;
73 };
74 
75 enum xdp_buff_flags {
76 	XDP_FLAGS_HAS_FRAGS		= BIT(0), /* non-linear xdp buff */
77 	XDP_FLAGS_FRAGS_PF_MEMALLOC	= BIT(1), /* xdp paged memory is under
78 						   * pressure
79 						   */
80 };
81 
82 struct xdp_buff {
83 	void *data;
84 	void *data_end;
85 	void *data_meta;
86 	void *data_hard_start;
87 	struct xdp_rxq_info *rxq;
88 	struct xdp_txq_info *txq;
89 	u32 frame_sz; /* frame size to deduce data_hard_end/reserved tailroom*/
90 	u32 flags; /* supported values defined in xdp_buff_flags */
91 };
92 
93 static __always_inline bool xdp_buff_has_frags(const struct xdp_buff *xdp)
94 {
95 	return !!(xdp->flags & XDP_FLAGS_HAS_FRAGS);
96 }
97 
98 static __always_inline void xdp_buff_set_frags_flag(struct xdp_buff *xdp)
99 {
100 	xdp->flags |= XDP_FLAGS_HAS_FRAGS;
101 }
102 
103 static __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp)
104 {
105 	xdp->flags &= ~XDP_FLAGS_HAS_FRAGS;
106 }
107 
108 static __always_inline bool
109 xdp_buff_is_frag_pfmemalloc(const struct xdp_buff *xdp)
110 {
111 	return !!(xdp->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
112 }
113 
114 static __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)
115 {
116 	xdp->flags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;
117 }
118 
119 static __always_inline void
120 xdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)
121 {
122 	xdp->frame_sz = frame_sz;
123 	xdp->rxq = rxq;
124 	xdp->flags = 0;
125 }
126 
127 static __always_inline void
128 xdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,
129 		 int headroom, int data_len, const bool meta_valid)
130 {
131 	unsigned char *data = hard_start + headroom;
132 
133 	xdp->data_hard_start = hard_start;
134 	xdp->data = data;
135 	xdp->data_end = data + data_len;
136 	xdp->data_meta = meta_valid ? data : data + 1;
137 }
138 
139 /* Reserve memory area at end-of data area.
140  *
141  * This macro reserves tailroom in the XDP buffer by limiting the
142  * XDP/BPF data access to data_hard_end.  Notice same area (and size)
143  * is used for XDP_PASS, when constructing the SKB via build_skb().
144  */
145 #define xdp_data_hard_end(xdp)				\
146 	((xdp)->data_hard_start + (xdp)->frame_sz -	\
147 	 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
148 
149 static inline struct skb_shared_info *
150 xdp_get_shared_info_from_buff(const struct xdp_buff *xdp)
151 {
152 	return (struct skb_shared_info *)xdp_data_hard_end(xdp);
153 }
154 
155 static __always_inline unsigned int
156 xdp_get_buff_len(const struct xdp_buff *xdp)
157 {
158 	unsigned int len = xdp->data_end - xdp->data;
159 	const struct skb_shared_info *sinfo;
160 
161 	if (likely(!xdp_buff_has_frags(xdp)))
162 		goto out;
163 
164 	sinfo = xdp_get_shared_info_from_buff(xdp);
165 	len += sinfo->xdp_frags_size;
166 out:
167 	return len;
168 }
169 
170 struct xdp_frame {
171 	void *data;
172 	u16 len;
173 	u16 headroom;
174 	u32 metasize; /* uses lower 8-bits */
175 	/* Lifetime of xdp_rxq_info is limited to NAPI/enqueue time,
176 	 * while mem info is valid on remote CPU.
177 	 */
178 	struct xdp_mem_info mem;
179 	struct net_device *dev_rx; /* used by cpumap */
180 	u32 frame_sz;
181 	u32 flags; /* supported values defined in xdp_buff_flags */
182 };
183 
184 static __always_inline bool xdp_frame_has_frags(const struct xdp_frame *frame)
185 {
186 	return !!(frame->flags & XDP_FLAGS_HAS_FRAGS);
187 }
188 
189 static __always_inline bool
190 xdp_frame_is_frag_pfmemalloc(const struct xdp_frame *frame)
191 {
192 	return !!(frame->flags & XDP_FLAGS_FRAGS_PF_MEMALLOC);
193 }
194 
195 #define XDP_BULK_QUEUE_SIZE	16
196 struct xdp_frame_bulk {
197 	int count;
198 	netmem_ref q[XDP_BULK_QUEUE_SIZE];
199 };
200 
201 static __always_inline void xdp_frame_bulk_init(struct xdp_frame_bulk *bq)
202 {
203 	bq->count = 0;
204 }
205 
206 static inline struct skb_shared_info *
207 xdp_get_shared_info_from_frame(const struct xdp_frame *frame)
208 {
209 	void *data_hard_start = frame->data - frame->headroom - sizeof(*frame);
210 
211 	return (struct skb_shared_info *)(data_hard_start + frame->frame_sz -
212 				SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
213 }
214 
215 struct xdp_cpumap_stats {
216 	unsigned int redirect;
217 	unsigned int pass;
218 	unsigned int drop;
219 };
220 
221 /* Clear kernel pointers in xdp_frame */
222 static inline void xdp_scrub_frame(struct xdp_frame *frame)
223 {
224 	frame->data = NULL;
225 	frame->dev_rx = NULL;
226 }
227 
228 static inline void
229 xdp_update_skb_shared_info(struct sk_buff *skb, u8 nr_frags,
230 			   unsigned int size, unsigned int truesize,
231 			   bool pfmemalloc)
232 {
233 	skb_shinfo(skb)->nr_frags = nr_frags;
234 
235 	skb->len += size;
236 	skb->data_len += size;
237 	skb->truesize += truesize;
238 	skb->pfmemalloc |= pfmemalloc;
239 }
240 
241 /* Avoids inlining WARN macro in fast-path */
242 void xdp_warn(const char *msg, const char *func, const int line);
243 #define XDP_WARN(msg) xdp_warn(msg, __func__, __LINE__)
244 
245 struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp);
246 struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
247 					   struct sk_buff *skb,
248 					   struct net_device *dev);
249 struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
250 					 struct net_device *dev);
251 int xdp_alloc_skb_bulk(void **skbs, int n_skb, gfp_t gfp);
252 struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
253 
254 static inline
255 void xdp_convert_frame_to_buff(const struct xdp_frame *frame,
256 			       struct xdp_buff *xdp)
257 {
258 	xdp->data_hard_start = frame->data - frame->headroom - sizeof(*frame);
259 	xdp->data = frame->data;
260 	xdp->data_end = frame->data + frame->len;
261 	xdp->data_meta = frame->data - frame->metasize;
262 	xdp->frame_sz = frame->frame_sz;
263 	xdp->flags = frame->flags;
264 }
265 
266 static inline
267 int xdp_update_frame_from_buff(const struct xdp_buff *xdp,
268 			       struct xdp_frame *xdp_frame)
269 {
270 	int metasize, headroom;
271 
272 	/* Assure headroom is available for storing info */
273 	headroom = xdp->data - xdp->data_hard_start;
274 	metasize = xdp->data - xdp->data_meta;
275 	metasize = metasize > 0 ? metasize : 0;
276 	if (unlikely((headroom - metasize) < sizeof(*xdp_frame)))
277 		return -ENOSPC;
278 
279 	/* Catch if driver didn't reserve tailroom for skb_shared_info */
280 	if (unlikely(xdp->data_end > xdp_data_hard_end(xdp))) {
281 		XDP_WARN("Driver BUG: missing reserved tailroom");
282 		return -ENOSPC;
283 	}
284 
285 	xdp_frame->data = xdp->data;
286 	xdp_frame->len  = xdp->data_end - xdp->data;
287 	xdp_frame->headroom = headroom - sizeof(*xdp_frame);
288 	xdp_frame->metasize = metasize;
289 	xdp_frame->frame_sz = xdp->frame_sz;
290 	xdp_frame->flags = xdp->flags;
291 
292 	return 0;
293 }
294 
295 /* Convert xdp_buff to xdp_frame */
296 static inline
297 struct xdp_frame *xdp_convert_buff_to_frame(struct xdp_buff *xdp)
298 {
299 	struct xdp_frame *xdp_frame;
300 
301 	if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL)
302 		return xdp_convert_zc_to_xdp_frame(xdp);
303 
304 	/* Store info in top of packet */
305 	xdp_frame = xdp->data_hard_start;
306 	if (unlikely(xdp_update_frame_from_buff(xdp, xdp_frame) < 0))
307 		return NULL;
308 
309 	/* rxq only valid until napi_schedule ends, convert to xdp_mem_info */
310 	xdp_frame->mem = xdp->rxq->mem;
311 
312 	return xdp_frame;
313 }
314 
315 void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,
316 		  struct xdp_buff *xdp);
317 void xdp_return_frame(struct xdp_frame *xdpf);
318 void xdp_return_frame_rx_napi(struct xdp_frame *xdpf);
319 void xdp_return_buff(struct xdp_buff *xdp);
320 void xdp_return_frame_bulk(struct xdp_frame *xdpf,
321 			   struct xdp_frame_bulk *bq);
322 
323 static inline void xdp_flush_frame_bulk(struct xdp_frame_bulk *bq)
324 {
325 	if (unlikely(!bq->count))
326 		return;
327 
328 	page_pool_put_netmem_bulk(bq->q, bq->count);
329 	bq->count = 0;
330 }
331 
332 static __always_inline unsigned int
333 xdp_get_frame_len(const struct xdp_frame *xdpf)
334 {
335 	const struct skb_shared_info *sinfo;
336 	unsigned int len = xdpf->len;
337 
338 	if (likely(!xdp_frame_has_frags(xdpf)))
339 		goto out;
340 
341 	sinfo = xdp_get_shared_info_from_frame(xdpf);
342 	len += sinfo->xdp_frags_size;
343 out:
344 	return len;
345 }
346 
347 int __xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
348 		       struct net_device *dev, u32 queue_index,
349 		       unsigned int napi_id, u32 frag_size);
350 static inline int
351 xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
352 		 struct net_device *dev, u32 queue_index,
353 		 unsigned int napi_id)
354 {
355 	return __xdp_rxq_info_reg(xdp_rxq, dev, queue_index, napi_id, 0);
356 }
357 
358 void xdp_rxq_info_unreg(struct xdp_rxq_info *xdp_rxq);
359 void xdp_rxq_info_unused(struct xdp_rxq_info *xdp_rxq);
360 bool xdp_rxq_info_is_reg(struct xdp_rxq_info *xdp_rxq);
361 int xdp_rxq_info_reg_mem_model(struct xdp_rxq_info *xdp_rxq,
362 			       enum xdp_mem_type type, void *allocator);
363 void xdp_rxq_info_unreg_mem_model(struct xdp_rxq_info *xdp_rxq);
364 int xdp_reg_mem_model(struct xdp_mem_info *mem,
365 		      enum xdp_mem_type type, void *allocator);
366 void xdp_unreg_mem_model(struct xdp_mem_info *mem);
367 int xdp_reg_page_pool(struct page_pool *pool);
368 void xdp_unreg_page_pool(const struct page_pool *pool);
369 void xdp_rxq_info_attach_page_pool(struct xdp_rxq_info *xdp_rxq,
370 				   const struct page_pool *pool);
371 
372 /**
373  * xdp_rxq_info_attach_mem_model - attach registered mem info to RxQ info
374  * @xdp_rxq: XDP RxQ info to attach the memory info to
375  * @mem: already registered memory info
376  *
377  * If the driver registers its memory providers manually, it must use this
378  * function instead of xdp_rxq_info_reg_mem_model().
379  */
380 static inline void
381 xdp_rxq_info_attach_mem_model(struct xdp_rxq_info *xdp_rxq,
382 			      const struct xdp_mem_info *mem)
383 {
384 	xdp_rxq->mem = *mem;
385 }
386 
387 /**
388  * xdp_rxq_info_detach_mem_model - detach registered mem info from RxQ info
389  * @xdp_rxq: XDP RxQ info to detach the memory info from
390  *
391  * If the driver registers its memory providers manually and then attaches it
392  * via xdp_rxq_info_attach_mem_model(), it must call this function before
393  * xdp_rxq_info_unreg().
394  */
395 static inline void xdp_rxq_info_detach_mem_model(struct xdp_rxq_info *xdp_rxq)
396 {
397 	xdp_rxq->mem = (struct xdp_mem_info){ };
398 }
399 
400 /* Drivers not supporting XDP metadata can use this helper, which
401  * rejects any room expansion for metadata as a result.
402  */
403 static __always_inline void
404 xdp_set_data_meta_invalid(struct xdp_buff *xdp)
405 {
406 	xdp->data_meta = xdp->data + 1;
407 }
408 
409 static __always_inline bool
410 xdp_data_meta_unsupported(const struct xdp_buff *xdp)
411 {
412 	return unlikely(xdp->data_meta > xdp->data);
413 }
414 
415 static inline bool xdp_metalen_invalid(unsigned long metalen)
416 {
417 	unsigned long meta_max;
418 
419 	meta_max = type_max(typeof_member(struct skb_shared_info, meta_len));
420 	BUILD_BUG_ON(!__builtin_constant_p(meta_max));
421 
422 	return !IS_ALIGNED(metalen, sizeof(u32)) || metalen > meta_max;
423 }
424 
425 struct xdp_attachment_info {
426 	struct bpf_prog *prog;
427 	u32 flags;
428 };
429 
430 struct netdev_bpf;
431 void xdp_attachment_setup(struct xdp_attachment_info *info,
432 			  struct netdev_bpf *bpf);
433 
434 #define DEV_MAP_BULK_SIZE XDP_BULK_QUEUE_SIZE
435 
436 /* Define the relationship between xdp-rx-metadata kfunc and
437  * various other entities:
438  * - xdp_rx_metadata enum
439  * - netdev netlink enum (Documentation/netlink/specs/netdev.yaml)
440  * - kfunc name
441  * - xdp_metadata_ops field
442  */
443 #define XDP_METADATA_KFUNC_xxx	\
444 	XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_TIMESTAMP, \
445 			   NETDEV_XDP_RX_METADATA_TIMESTAMP, \
446 			   bpf_xdp_metadata_rx_timestamp, \
447 			   xmo_rx_timestamp) \
448 	XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_HASH, \
449 			   NETDEV_XDP_RX_METADATA_HASH, \
450 			   bpf_xdp_metadata_rx_hash, \
451 			   xmo_rx_hash) \
452 	XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_VLAN_TAG, \
453 			   NETDEV_XDP_RX_METADATA_VLAN_TAG, \
454 			   bpf_xdp_metadata_rx_vlan_tag, \
455 			   xmo_rx_vlan_tag) \
456 
457 enum xdp_rx_metadata {
458 #define XDP_METADATA_KFUNC(name, _, __, ___) name,
459 XDP_METADATA_KFUNC_xxx
460 #undef XDP_METADATA_KFUNC
461 MAX_XDP_METADATA_KFUNC,
462 };
463 
464 enum xdp_rss_hash_type {
465 	/* First part: Individual bits for L3/L4 types */
466 	XDP_RSS_L3_IPV4		= BIT(0),
467 	XDP_RSS_L3_IPV6		= BIT(1),
468 
469 	/* The fixed (L3) IPv4 and IPv6 headers can both be followed by
470 	 * variable/dynamic headers, IPv4 called Options and IPv6 called
471 	 * Extension Headers. HW RSS type can contain this info.
472 	 */
473 	XDP_RSS_L3_DYNHDR	= BIT(2),
474 
475 	/* When RSS hash covers L4 then drivers MUST set XDP_RSS_L4 bit in
476 	 * addition to the protocol specific bit.  This ease interaction with
477 	 * SKBs and avoids reserving a fixed mask for future L4 protocol bits.
478 	 */
479 	XDP_RSS_L4		= BIT(3), /* L4 based hash, proto can be unknown */
480 	XDP_RSS_L4_TCP		= BIT(4),
481 	XDP_RSS_L4_UDP		= BIT(5),
482 	XDP_RSS_L4_SCTP		= BIT(6),
483 	XDP_RSS_L4_IPSEC	= BIT(7), /* L4 based hash include IPSEC SPI */
484 	XDP_RSS_L4_ICMP		= BIT(8),
485 
486 	/* Second part: RSS hash type combinations used for driver HW mapping */
487 	XDP_RSS_TYPE_NONE            = 0,
488 	XDP_RSS_TYPE_L2              = XDP_RSS_TYPE_NONE,
489 
490 	XDP_RSS_TYPE_L3_IPV4         = XDP_RSS_L3_IPV4,
491 	XDP_RSS_TYPE_L3_IPV6         = XDP_RSS_L3_IPV6,
492 	XDP_RSS_TYPE_L3_IPV4_OPT     = XDP_RSS_L3_IPV4 | XDP_RSS_L3_DYNHDR,
493 	XDP_RSS_TYPE_L3_IPV6_EX      = XDP_RSS_L3_IPV6 | XDP_RSS_L3_DYNHDR,
494 
495 	XDP_RSS_TYPE_L4_ANY          = XDP_RSS_L4,
496 	XDP_RSS_TYPE_L4_IPV4_TCP     = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
497 	XDP_RSS_TYPE_L4_IPV4_UDP     = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
498 	XDP_RSS_TYPE_L4_IPV4_SCTP    = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
499 	XDP_RSS_TYPE_L4_IPV4_IPSEC   = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
500 	XDP_RSS_TYPE_L4_IPV4_ICMP    = XDP_RSS_L3_IPV4 | XDP_RSS_L4 | XDP_RSS_L4_ICMP,
501 
502 	XDP_RSS_TYPE_L4_IPV6_TCP     = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_TCP,
503 	XDP_RSS_TYPE_L4_IPV6_UDP     = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_UDP,
504 	XDP_RSS_TYPE_L4_IPV6_SCTP    = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_SCTP,
505 	XDP_RSS_TYPE_L4_IPV6_IPSEC   = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_IPSEC,
506 	XDP_RSS_TYPE_L4_IPV6_ICMP    = XDP_RSS_L3_IPV6 | XDP_RSS_L4 | XDP_RSS_L4_ICMP,
507 
508 	XDP_RSS_TYPE_L4_IPV6_TCP_EX  = XDP_RSS_TYPE_L4_IPV6_TCP  | XDP_RSS_L3_DYNHDR,
509 	XDP_RSS_TYPE_L4_IPV6_UDP_EX  = XDP_RSS_TYPE_L4_IPV6_UDP  | XDP_RSS_L3_DYNHDR,
510 	XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
511 };
512 
513 struct xdp_metadata_ops {
514 	int	(*xmo_rx_timestamp)(const struct xdp_md *ctx, u64 *timestamp);
515 	int	(*xmo_rx_hash)(const struct xdp_md *ctx, u32 *hash,
516 			       enum xdp_rss_hash_type *rss_type);
517 	int	(*xmo_rx_vlan_tag)(const struct xdp_md *ctx, __be16 *vlan_proto,
518 				   u16 *vlan_tci);
519 };
520 
521 #ifdef CONFIG_NET
522 u32 bpf_xdp_metadata_kfunc_id(int id);
523 bool bpf_dev_bound_kfunc_id(u32 btf_id);
524 void xdp_set_features_flag(struct net_device *dev, xdp_features_t val);
525 void xdp_features_set_redirect_target(struct net_device *dev, bool support_sg);
526 void xdp_features_clear_redirect_target(struct net_device *dev);
527 #else
528 static inline u32 bpf_xdp_metadata_kfunc_id(int id) { return 0; }
529 static inline bool bpf_dev_bound_kfunc_id(u32 btf_id) { return false; }
530 
531 static inline void
532 xdp_set_features_flag(struct net_device *dev, xdp_features_t val)
533 {
534 }
535 
536 static inline void
537 xdp_features_set_redirect_target(struct net_device *dev, bool support_sg)
538 {
539 }
540 
541 static inline void
542 xdp_features_clear_redirect_target(struct net_device *dev)
543 {
544 }
545 #endif
546 
547 static inline void xdp_clear_features_flag(struct net_device *dev)
548 {
549 	xdp_set_features_flag(dev, 0);
550 }
551 
552 static __always_inline u32 bpf_prog_run_xdp(const struct bpf_prog *prog,
553 					    struct xdp_buff *xdp)
554 {
555 	/* Driver XDP hooks are invoked within a single NAPI poll cycle and thus
556 	 * under local_bh_disable(), which provides the needed RCU protection
557 	 * for accessing map entries.
558 	 */
559 	u32 act = __bpf_prog_run(prog, xdp, BPF_DISPATCHER_FUNC(xdp));
560 
561 	if (static_branch_unlikely(&bpf_master_redirect_enabled_key)) {
562 		if (act == XDP_TX && netif_is_bond_slave(xdp->rxq->dev))
563 			act = xdp_master_redirect(xdp);
564 	}
565 
566 	return act;
567 }
568 #endif /* __LINUX_NET_XDP_H__ */
569