2018-05-18 19:00:21 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/* AF_XDP internal functions
|
2018-05-02 18:01:23 +07:00
|
|
|
* Copyright(c) 2018 Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_XDP_SOCK_H
|
|
|
|
#define _LINUX_XDP_SOCK_H
|
|
|
|
|
2018-06-04 19:05:51 +07:00
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/if_xdp.h>
|
2018-05-02 18:01:23 +07:00
|
|
|
#include <linux/mutex.h>
|
2018-06-04 19:05:57 +07:00
|
|
|
#include <linux/spinlock.h>
|
2018-06-04 19:05:51 +07:00
|
|
|
#include <linux/mm.h>
|
2018-05-02 18:01:23 +07:00
|
|
|
#include <net/sock.h>
|
|
|
|
|
2018-05-02 18:01:25 +07:00
|
|
|
struct net_device;
|
|
|
|
struct xsk_queue;
|
2018-06-04 19:05:51 +07:00
|
|
|
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
/* Masks for xdp_umem_page flags.
|
|
|
|
* The low 12-bits of the addr will be 0 since this is the page address, so we
|
|
|
|
* can use them for flags.
|
|
|
|
*/
|
|
|
|
#define XSK_NEXT_PG_CONTIG_SHIFT 0
|
|
|
|
#define XSK_NEXT_PG_CONTIG_MASK (1ULL << XSK_NEXT_PG_CONTIG_SHIFT)
|
|
|
|
|
2018-06-04 19:05:52 +07:00
|
|
|
struct xdp_umem_page {
|
|
|
|
void *addr;
|
2018-06-04 19:05:55 +07:00
|
|
|
dma_addr_t dma;
|
2018-06-04 19:05:52 +07:00
|
|
|
};
|
|
|
|
|
2018-09-07 15:18:46 +07:00
|
|
|
struct xdp_umem_fq_reuse {
|
|
|
|
u32 nentries;
|
|
|
|
u32 length;
|
|
|
|
u64 handles[];
|
|
|
|
};
|
|
|
|
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
/* Flags for the umem flags field.
|
|
|
|
*
|
|
|
|
* The NEED_WAKEUP flag is 1 due to the reuse of the flags field for public
|
|
|
|
* flags. See inlude/uapi/include/linux/if_xdp.h.
|
|
|
|
*/
|
|
|
|
#define XDP_UMEM_USES_NEED_WAKEUP (1 << 1)
|
xsk: add support for need_wakeup flag in AF_XDP rings
This commit adds support for a new flag called need_wakeup in the
AF_XDP Tx and fill rings. When this flag is set, it means that the
application has to explicitly wake up the kernel Rx (for the bit in
the fill ring) or kernel Tx (for bit in the Tx ring) processing by
issuing a syscall. Poll() can wake up both depending on the flags
submitted and sendto() will wake up tx processing only.
The main reason for introducing this new flag is to be able to
efficiently support the case when application and driver is executing
on the same core. Previously, the driver was just busy-spinning on the
fill ring if it ran out of buffers in the HW and there were none on
the fill ring. This approach works when the application is running on
another core as it can replenish the fill ring while the driver is
busy-spinning. Though, this is a lousy approach if both of them are
running on the same core as the probability of the fill ring getting
more entries when the driver is busy-spinning is zero. With this new
feature the driver now sets the need_wakeup flag and returns to the
application. The application can then replenish the fill queue and
then explicitly wake up the Rx processing in the kernel using the
syscall poll(). For Tx, the flag is only set to one if the driver has
no outstanding Tx completion interrupts. If it has some, the flag is
zero as it will be woken up by a completion interrupt anyway.
As a nice side effect, this new flag also improves the performance of
the case where application and driver are running on two different
cores as it reduces the number of syscalls to the kernel. The kernel
tells user space if it needs to be woken up by a syscall, and this
eliminates many of the syscalls.
This flag needs some simple driver support. If the driver does not
support this, the Rx flag is always zero and the Tx flag is always
one. This makes any application relying on this feature default to the
old behaviour of not requiring any syscalls in the Rx path and always
having to call sendto() in the Tx path.
For backwards compatibility reasons, this feature has to be explicitly
turned on using a new bind flag (XDP_USE_NEED_WAKEUP). I recommend
that you always turn it on as it so far always have had a positive
performance impact.
The name and inspiration of the flag has been taken from io_uring by
Jens Axboe. Details about this feature in io_uring can be found in
http://kernel.dk/io_uring.pdf, section 8.3.
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-14 14:27:17 +07:00
|
|
|
|
2018-06-04 19:05:51 +07:00
|
|
|
struct xdp_umem {
|
|
|
|
struct xsk_queue *fq;
|
|
|
|
struct xsk_queue *cq;
|
2018-06-04 19:05:52 +07:00
|
|
|
struct xdp_umem_page *pages;
|
2018-08-31 18:40:02 +07:00
|
|
|
u64 chunk_mask;
|
|
|
|
u64 size;
|
2018-06-04 19:05:51 +07:00
|
|
|
u32 headroom;
|
|
|
|
u32 chunk_size_nohr;
|
|
|
|
struct user_struct *user;
|
|
|
|
unsigned long address;
|
|
|
|
refcount_t users;
|
|
|
|
struct work_struct work;
|
2018-06-04 19:05:52 +07:00
|
|
|
struct page **pgs;
|
2018-06-04 19:05:51 +07:00
|
|
|
u32 npgs;
|
xsk: add support for need_wakeup flag in AF_XDP rings
This commit adds support for a new flag called need_wakeup in the
AF_XDP Tx and fill rings. When this flag is set, it means that the
application has to explicitly wake up the kernel Rx (for the bit in
the fill ring) or kernel Tx (for bit in the Tx ring) processing by
issuing a syscall. Poll() can wake up both depending on the flags
submitted and sendto() will wake up tx processing only.
The main reason for introducing this new flag is to be able to
efficiently support the case when application and driver is executing
on the same core. Previously, the driver was just busy-spinning on the
fill ring if it ran out of buffers in the HW and there were none on
the fill ring. This approach works when the application is running on
another core as it can replenish the fill ring while the driver is
busy-spinning. Though, this is a lousy approach if both of them are
running on the same core as the probability of the fill ring getting
more entries when the driver is busy-spinning is zero. With this new
feature the driver now sets the need_wakeup flag and returns to the
application. The application can then replenish the fill queue and
then explicitly wake up the Rx processing in the kernel using the
syscall poll(). For Tx, the flag is only set to one if the driver has
no outstanding Tx completion interrupts. If it has some, the flag is
zero as it will be woken up by a completion interrupt anyway.
As a nice side effect, this new flag also improves the performance of
the case where application and driver are running on two different
cores as it reduces the number of syscalls to the kernel. The kernel
tells user space if it needs to be woken up by a syscall, and this
eliminates many of the syscalls.
This flag needs some simple driver support. If the driver does not
support this, the Rx flag is always zero and the Tx flag is always
one. This makes any application relying on this feature default to the
old behaviour of not requiring any syscalls in the Rx path and always
having to call sendto() in the Tx path.
For backwards compatibility reasons, this feature has to be explicitly
turned on using a new bind flag (XDP_USE_NEED_WAKEUP). I recommend
that you always turn it on as it so far always have had a positive
performance impact.
The name and inspiration of the flag has been taken from io_uring by
Jens Axboe. Details about this feature in io_uring can be found in
http://kernel.dk/io_uring.pdf, section 8.3.
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-14 14:27:17 +07:00
|
|
|
u16 queue_id;
|
|
|
|
u8 need_wakeup;
|
|
|
|
u8 flags;
|
2019-01-25 01:59:38 +07:00
|
|
|
int id;
|
2018-06-04 19:05:55 +07:00
|
|
|
struct net_device *dev;
|
2018-09-07 15:18:46 +07:00
|
|
|
struct xdp_umem_fq_reuse *fq_reuse;
|
2018-06-04 19:05:55 +07:00
|
|
|
bool zc;
|
2018-06-04 19:05:57 +07:00
|
|
|
spinlock_t xsk_list_lock;
|
|
|
|
struct list_head xsk_list;
|
2018-06-04 19:05:51 +07:00
|
|
|
};
|
2018-05-02 18:01:23 +07:00
|
|
|
|
2019-08-15 16:30:13 +07:00
|
|
|
/* Nodes are linked in the struct xdp_sock map_list field, and used to
|
|
|
|
* track which maps a certain socket reside in.
|
|
|
|
*/
|
2019-11-01 18:03:46 +07:00
|
|
|
|
|
|
|
struct xsk_map {
|
|
|
|
struct bpf_map map;
|
|
|
|
spinlock_t lock; /* Synchronize map updates */
|
|
|
|
struct xdp_sock *xsk_map[];
|
|
|
|
};
|
|
|
|
|
2019-08-15 16:30:13 +07:00
|
|
|
struct xsk_map_node {
|
|
|
|
struct list_head node;
|
|
|
|
struct xsk_map *map;
|
|
|
|
struct xdp_sock **map_entry;
|
|
|
|
};
|
|
|
|
|
2018-05-02 18:01:23 +07:00
|
|
|
struct xdp_sock {
|
|
|
|
/* struct sock must be the first member of struct xdp_sock */
|
|
|
|
struct sock sk;
|
2018-05-02 18:01:25 +07:00
|
|
|
struct xsk_queue *rx;
|
|
|
|
struct net_device *dev;
|
2018-05-02 18:01:23 +07:00
|
|
|
struct xdp_umem *umem;
|
2018-05-02 18:01:28 +07:00
|
|
|
struct list_head flush_node;
|
2018-05-02 18:01:26 +07:00
|
|
|
u16 queue_id;
|
2018-06-04 19:05:57 +07:00
|
|
|
bool zc;
|
2019-06-28 15:04:07 +07:00
|
|
|
enum {
|
|
|
|
XSK_READY = 0,
|
|
|
|
XSK_BOUND,
|
|
|
|
XSK_UNBOUND,
|
|
|
|
} state;
|
2018-05-02 18:01:23 +07:00
|
|
|
/* Protects multiple processes in the control path */
|
|
|
|
struct mutex mutex;
|
2019-06-07 03:59:40 +07:00
|
|
|
struct xsk_queue *tx ____cacheline_aligned_in_smp;
|
|
|
|
struct list_head list;
|
2018-06-29 14:48:20 +07:00
|
|
|
/* Mutual exclusion of NAPI TX thread and sendmsg error paths
|
|
|
|
* in the SKB destructor callback.
|
|
|
|
*/
|
|
|
|
spinlock_t tx_completion_lock;
|
2019-07-03 19:09:16 +07:00
|
|
|
/* Protects generic receive. */
|
|
|
|
spinlock_t rx_lock;
|
2018-05-02 18:01:27 +07:00
|
|
|
u64 rx_dropped;
|
2019-08-15 16:30:13 +07:00
|
|
|
struct list_head map_list;
|
|
|
|
/* Protects map_list */
|
|
|
|
spinlock_t map_list_lock;
|
2018-05-02 18:01:23 +07:00
|
|
|
};
|
|
|
|
|
2018-05-02 18:01:27 +07:00
|
|
|
struct xdp_buff;
|
|
|
|
#ifdef CONFIG_XDP_SOCKETS
|
|
|
|
int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
|
2018-05-02 18:01:28 +07:00
|
|
|
bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs);
|
2018-06-04 19:05:57 +07:00
|
|
|
/* Used from netdev driver */
|
2019-06-26 21:35:24 +07:00
|
|
|
bool xsk_umem_has_addrs(struct xdp_umem *umem, u32 cnt);
|
2019-12-19 19:39:27 +07:00
|
|
|
bool xsk_umem_peek_addr(struct xdp_umem *umem, u64 *addr);
|
2019-12-19 19:39:28 +07:00
|
|
|
void xsk_umem_release_addr(struct xdp_umem *umem);
|
2018-06-04 19:05:57 +07:00
|
|
|
void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries);
|
2019-06-26 21:35:28 +07:00
|
|
|
bool xsk_umem_consume_tx(struct xdp_umem *umem, struct xdp_desc *desc);
|
2018-06-04 19:05:57 +07:00
|
|
|
void xsk_umem_consume_tx_done(struct xdp_umem *umem);
|
2018-09-07 15:18:46 +07:00
|
|
|
struct xdp_umem_fq_reuse *xsk_reuseq_prepare(u32 nentries);
|
|
|
|
struct xdp_umem_fq_reuse *xsk_reuseq_swap(struct xdp_umem *umem,
|
|
|
|
struct xdp_umem_fq_reuse *newq);
|
|
|
|
void xsk_reuseq_free(struct xdp_umem_fq_reuse *rq);
|
2018-10-01 19:51:36 +07:00
|
|
|
struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev, u16 queue_id);
|
xsk: add support for need_wakeup flag in AF_XDP rings
This commit adds support for a new flag called need_wakeup in the
AF_XDP Tx and fill rings. When this flag is set, it means that the
application has to explicitly wake up the kernel Rx (for the bit in
the fill ring) or kernel Tx (for bit in the Tx ring) processing by
issuing a syscall. Poll() can wake up both depending on the flags
submitted and sendto() will wake up tx processing only.
The main reason for introducing this new flag is to be able to
efficiently support the case when application and driver is executing
on the same core. Previously, the driver was just busy-spinning on the
fill ring if it ran out of buffers in the HW and there were none on
the fill ring. This approach works when the application is running on
another core as it can replenish the fill ring while the driver is
busy-spinning. Though, this is a lousy approach if both of them are
running on the same core as the probability of the fill ring getting
more entries when the driver is busy-spinning is zero. With this new
feature the driver now sets the need_wakeup flag and returns to the
application. The application can then replenish the fill queue and
then explicitly wake up the Rx processing in the kernel using the
syscall poll(). For Tx, the flag is only set to one if the driver has
no outstanding Tx completion interrupts. If it has some, the flag is
zero as it will be woken up by a completion interrupt anyway.
As a nice side effect, this new flag also improves the performance of
the case where application and driver are running on two different
cores as it reduces the number of syscalls to the kernel. The kernel
tells user space if it needs to be woken up by a syscall, and this
eliminates many of the syscalls.
This flag needs some simple driver support. If the driver does not
support this, the Rx flag is always zero and the Tx flag is always
one. This makes any application relying on this feature default to the
old behaviour of not requiring any syscalls in the Rx path and always
having to call sendto() in the Tx path.
For backwards compatibility reasons, this feature has to be explicitly
turned on using a new bind flag (XDP_USE_NEED_WAKEUP). I recommend
that you always turn it on as it so far always have had a positive
performance impact.
The name and inspiration of the flag has been taken from io_uring by
Jens Axboe. Details about this feature in io_uring can be found in
http://kernel.dk/io_uring.pdf, section 8.3.
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-14 14:27:17 +07:00
|
|
|
void xsk_set_rx_need_wakeup(struct xdp_umem *umem);
|
|
|
|
void xsk_set_tx_need_wakeup(struct xdp_umem *umem);
|
|
|
|
void xsk_clear_rx_need_wakeup(struct xdp_umem *umem);
|
|
|
|
void xsk_clear_tx_need_wakeup(struct xdp_umem *umem);
|
|
|
|
bool xsk_umem_uses_need_wakeup(struct xdp_umem *umem);
|
2018-08-28 19:44:27 +07:00
|
|
|
|
2019-08-15 16:30:13 +07:00
|
|
|
void xsk_map_try_sock_delete(struct xsk_map *map, struct xdp_sock *xs,
|
|
|
|
struct xdp_sock **map_entry);
|
|
|
|
int xsk_map_inc(struct xsk_map *map);
|
|
|
|
void xsk_map_put(struct xsk_map *map);
|
2019-12-19 13:10:02 +07:00
|
|
|
int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp);
|
|
|
|
void __xsk_map_flush(void);
|
2019-11-01 18:03:46 +07:00
|
|
|
|
|
|
|
static inline struct xdp_sock *__xsk_map_lookup_elem(struct bpf_map *map,
|
|
|
|
u32 key)
|
|
|
|
{
|
|
|
|
struct xsk_map *m = container_of(map, struct xsk_map, map);
|
|
|
|
struct xdp_sock *xs;
|
|
|
|
|
|
|
|
if (key >= map->max_entries)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
xs = READ_ONCE(m->xsk_map[key]);
|
|
|
|
return xs;
|
|
|
|
}
|
2019-08-15 16:30:13 +07:00
|
|
|
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
static inline u64 xsk_umem_extract_addr(u64 addr)
|
|
|
|
{
|
|
|
|
return addr & XSK_UNALIGNED_BUF_ADDR_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 xsk_umem_extract_offset(u64 addr)
|
|
|
|
{
|
|
|
|
return addr >> XSK_UNALIGNED_BUF_OFFSET_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 xsk_umem_add_offset_to_addr(u64 addr)
|
|
|
|
{
|
|
|
|
return xsk_umem_extract_addr(addr) + xsk_umem_extract_offset(addr);
|
|
|
|
}
|
|
|
|
|
2018-08-28 19:44:27 +07:00
|
|
|
static inline char *xdp_umem_get_data(struct xdp_umem *umem, u64 addr)
|
|
|
|
{
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
unsigned long page_addr;
|
|
|
|
|
|
|
|
addr = xsk_umem_add_offset_to_addr(addr);
|
|
|
|
page_addr = (unsigned long)umem->pages[addr >> PAGE_SHIFT].addr;
|
|
|
|
|
|
|
|
return (char *)(page_addr & PAGE_MASK) + (addr & ~PAGE_MASK);
|
2018-08-28 19:44:27 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t xdp_umem_get_dma(struct xdp_umem *umem, u64 addr)
|
|
|
|
{
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
addr = xsk_umem_add_offset_to_addr(addr);
|
|
|
|
|
|
|
|
return umem->pages[addr >> PAGE_SHIFT].dma + (addr & ~PAGE_MASK);
|
2018-08-28 19:44:27 +07:00
|
|
|
}
|
2018-09-07 15:18:46 +07:00
|
|
|
|
|
|
|
/* Reuse-queue aware version of FILL queue helpers */
|
2019-06-26 21:35:24 +07:00
|
|
|
static inline bool xsk_umem_has_addrs_rq(struct xdp_umem *umem, u32 cnt)
|
|
|
|
{
|
|
|
|
struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
|
|
|
|
|
|
|
|
if (rq->length >= cnt)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return xsk_umem_has_addrs(umem, cnt - rq->length);
|
|
|
|
}
|
|
|
|
|
2019-12-19 19:39:27 +07:00
|
|
|
static inline bool xsk_umem_peek_addr_rq(struct xdp_umem *umem, u64 *addr)
|
2018-09-07 15:18:46 +07:00
|
|
|
{
|
|
|
|
struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
|
|
|
|
|
|
|
|
if (!rq->length)
|
|
|
|
return xsk_umem_peek_addr(umem, addr);
|
|
|
|
|
|
|
|
*addr = rq->handles[rq->length - 1];
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2019-12-19 19:39:28 +07:00
|
|
|
static inline void xsk_umem_release_addr_rq(struct xdp_umem *umem)
|
2018-09-07 15:18:46 +07:00
|
|
|
{
|
|
|
|
struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
|
|
|
|
|
|
|
|
if (!rq->length)
|
2019-12-19 19:39:28 +07:00
|
|
|
xsk_umem_release_addr(umem);
|
2018-09-07 15:18:46 +07:00
|
|
|
else
|
|
|
|
rq->length--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_umem_fq_reuse(struct xdp_umem *umem, u64 addr)
|
|
|
|
{
|
|
|
|
struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
|
|
|
|
|
|
|
|
rq->handles[rq->length++] = addr;
|
|
|
|
}
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
|
|
|
|
/* Handle the offset appropriately depending on aligned or unaligned mode.
|
|
|
|
* For unaligned mode, we store the offset in the upper 16-bits of the address.
|
|
|
|
* For aligned mode, we simply add the offset to the address.
|
|
|
|
*/
|
|
|
|
static inline u64 xsk_umem_adjust_offset(struct xdp_umem *umem, u64 address,
|
|
|
|
u64 offset)
|
|
|
|
{
|
|
|
|
if (umem->flags & XDP_UMEM_UNALIGNED_CHUNK_FLAG)
|
|
|
|
return address + (offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT);
|
|
|
|
else
|
|
|
|
return address + offset;
|
|
|
|
}
|
2018-05-02 18:01:27 +07:00
|
|
|
#else
|
|
|
|
static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
|
|
|
|
{
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
2018-05-02 18:01:28 +07:00
|
|
|
static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-28 19:44:27 +07:00
|
|
|
|
2019-06-26 21:35:24 +07:00
|
|
|
static inline bool xsk_umem_has_addrs(struct xdp_umem *umem, u32 cnt)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-28 19:44:27 +07:00
|
|
|
static inline u64 *xsk_umem_peek_addr(struct xdp_umem *umem, u64 *addr)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-19 19:39:28 +07:00
|
|
|
static inline void xsk_umem_release_addr(struct xdp_umem *umem)
|
2018-08-28 19:44:27 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-26 21:35:28 +07:00
|
|
|
static inline bool xsk_umem_consume_tx(struct xdp_umem *umem,
|
|
|
|
struct xdp_desc *desc)
|
2018-08-28 19:44:27 +07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_umem_consume_tx_done(struct xdp_umem *umem)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-09-07 15:18:46 +07:00
|
|
|
static inline struct xdp_umem_fq_reuse *xsk_reuseq_prepare(u32 nentries)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct xdp_umem_fq_reuse *xsk_reuseq_swap(
|
|
|
|
struct xdp_umem *umem,
|
|
|
|
struct xdp_umem_fq_reuse *newq)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
static inline void xsk_reuseq_free(struct xdp_umem_fq_reuse *rq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-01 19:51:36 +07:00
|
|
|
static inline struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev,
|
|
|
|
u16 queue_id)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
static inline u64 xsk_umem_extract_addr(u64 addr)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 xsk_umem_extract_offset(u64 addr)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u64 xsk_umem_add_offset_to_addr(u64 addr)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-28 19:44:27 +07:00
|
|
|
static inline char *xdp_umem_get_data(struct xdp_umem *umem, u64 addr)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline dma_addr_t xdp_umem_get_dma(struct xdp_umem *umem, u64 addr)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-09-07 15:18:46 +07:00
|
|
|
|
2019-06-26 21:35:24 +07:00
|
|
|
static inline bool xsk_umem_has_addrs_rq(struct xdp_umem *umem, u32 cnt)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-07 15:18:46 +07:00
|
|
|
static inline u64 *xsk_umem_peek_addr_rq(struct xdp_umem *umem, u64 *addr)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-19 19:39:28 +07:00
|
|
|
static inline void xsk_umem_release_addr_rq(struct xdp_umem *umem)
|
2018-09-07 15:18:46 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_umem_fq_reuse(struct xdp_umem *umem, u64 addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
xsk: add support for need_wakeup flag in AF_XDP rings
This commit adds support for a new flag called need_wakeup in the
AF_XDP Tx and fill rings. When this flag is set, it means that the
application has to explicitly wake up the kernel Rx (for the bit in
the fill ring) or kernel Tx (for bit in the Tx ring) processing by
issuing a syscall. Poll() can wake up both depending on the flags
submitted and sendto() will wake up tx processing only.
The main reason for introducing this new flag is to be able to
efficiently support the case when application and driver is executing
on the same core. Previously, the driver was just busy-spinning on the
fill ring if it ran out of buffers in the HW and there were none on
the fill ring. This approach works when the application is running on
another core as it can replenish the fill ring while the driver is
busy-spinning. Though, this is a lousy approach if both of them are
running on the same core as the probability of the fill ring getting
more entries when the driver is busy-spinning is zero. With this new
feature the driver now sets the need_wakeup flag and returns to the
application. The application can then replenish the fill queue and
then explicitly wake up the Rx processing in the kernel using the
syscall poll(). For Tx, the flag is only set to one if the driver has
no outstanding Tx completion interrupts. If it has some, the flag is
zero as it will be woken up by a completion interrupt anyway.
As a nice side effect, this new flag also improves the performance of
the case where application and driver are running on two different
cores as it reduces the number of syscalls to the kernel. The kernel
tells user space if it needs to be woken up by a syscall, and this
eliminates many of the syscalls.
This flag needs some simple driver support. If the driver does not
support this, the Rx flag is always zero and the Tx flag is always
one. This makes any application relying on this feature default to the
old behaviour of not requiring any syscalls in the Rx path and always
having to call sendto() in the Tx path.
For backwards compatibility reasons, this feature has to be explicitly
turned on using a new bind flag (XDP_USE_NEED_WAKEUP). I recommend
that you always turn it on as it so far always have had a positive
performance impact.
The name and inspiration of the flag has been taken from io_uring by
Jens Axboe. Details about this feature in io_uring can be found in
http://kernel.dk/io_uring.pdf, section 8.3.
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-14 14:27:17 +07:00
|
|
|
static inline void xsk_set_rx_need_wakeup(struct xdp_umem *umem)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_set_tx_need_wakeup(struct xdp_umem *umem)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_clear_rx_need_wakeup(struct xdp_umem *umem)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void xsk_clear_tx_need_wakeup(struct xdp_umem *umem)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool xsk_umem_uses_need_wakeup(struct xdp_umem *umem)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
xsk: add support to allow unaligned chunk placement
Currently, addresses are chunk size aligned. This means, we are very
restricted in terms of where we can place chunk within the umem. For
example, if we have a chunk size of 2k, then our chunks can only be placed
at 0,2k,4k,6k,8k... and so on (ie. every 2k starting from 0).
This patch introduces the ability to use unaligned chunks. With these
changes, we are no longer bound to having to place chunks at a 2k (or
whatever your chunk size is) interval. Since we are no longer dealing with
aligned chunks, they can now cross page boundaries. Checks for page
contiguity have been added in order to keep track of which pages are
followed by a physically contiguous page.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-08-27 09:25:22 +07:00
|
|
|
static inline u64 xsk_umem_adjust_offset(struct xdp_umem *umem, u64 handle,
|
|
|
|
u64 offset)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:10:02 +07:00
|
|
|
static inline int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp)
|
2019-11-01 18:03:46 +07:00
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:10:02 +07:00
|
|
|
static inline void __xsk_map_flush(void)
|
2019-11-01 18:03:46 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct xdp_sock *__xsk_map_lookup_elem(struct bpf_map *map,
|
|
|
|
u32 key)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-05-02 18:01:27 +07:00
|
|
|
#endif /* CONFIG_XDP_SOCKETS */
|
|
|
|
|
2018-05-02 18:01:23 +07:00
|
|
|
#endif /* _LINUX_XDP_SOCK_H */
|