-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xsk: add umem fill queue support and mmap
Here, we add another setsockopt for registered user memory (umem) called XDP_UMEM_FILL_QUEUE. Using this socket option, the process can ask the kernel to allocate a queue (ring buffer) and also mmap it (XDP_UMEM_PGOFF_FILL_QUEUE) into the process. The queue is used to explicitly pass ownership of umem frames from the user process to the kernel. These frames will in a later patch be filled in with Rx packet data by the kernel. v2: Fixed potential crash in xsk_mmap. Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Magnus Karlsson
authored and
Alexei Starovoitov
committed
May 3, 2018
1 parent
c0c77d8
commit 423f383
Showing
7 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
obj-$(CONFIG_XDP_SOCKETS) += xsk.o xdp_umem.o | ||
obj-$(CONFIG_XDP_SOCKETS) += xsk.o xdp_umem.o xsk_queue.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* XDP user-space ring structure | ||
* Copyright(c) 2018 Intel Corporation. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms and conditions of the GNU General Public License, | ||
* version 2, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
*/ | ||
|
||
#include <linux/slab.h> | ||
|
||
#include "xsk_queue.h" | ||
|
||
static u32 xskq_umem_get_ring_size(struct xsk_queue *q) | ||
{ | ||
return sizeof(struct xdp_umem_ring) + q->nentries * sizeof(u32); | ||
} | ||
|
||
struct xsk_queue *xskq_create(u32 nentries) | ||
{ | ||
struct xsk_queue *q; | ||
gfp_t gfp_flags; | ||
size_t size; | ||
|
||
q = kzalloc(sizeof(*q), GFP_KERNEL); | ||
if (!q) | ||
return NULL; | ||
|
||
q->nentries = nentries; | ||
q->ring_mask = nentries - 1; | ||
|
||
gfp_flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN | | ||
__GFP_COMP | __GFP_NORETRY; | ||
size = xskq_umem_get_ring_size(q); | ||
|
||
q->ring = (struct xdp_ring *)__get_free_pages(gfp_flags, | ||
get_order(size)); | ||
if (!q->ring) { | ||
kfree(q); | ||
return NULL; | ||
} | ||
|
||
return q; | ||
} | ||
|
||
void xskq_destroy(struct xsk_queue *q) | ||
{ | ||
if (!q) | ||
return; | ||
|
||
page_frag_free(q->ring); | ||
kfree(q); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 | ||
* XDP user-space ring structure | ||
* Copyright(c) 2018 Intel Corporation. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms and conditions of the GNU General Public License, | ||
* version 2, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
*/ | ||
|
||
#ifndef _LINUX_XSK_QUEUE_H | ||
#define _LINUX_XSK_QUEUE_H | ||
|
||
#include <linux/types.h> | ||
#include <linux/if_xdp.h> | ||
|
||
#include "xdp_umem_props.h" | ||
|
||
struct xsk_queue { | ||
struct xdp_umem_props umem_props; | ||
u32 ring_mask; | ||
u32 nentries; | ||
u32 prod_head; | ||
u32 prod_tail; | ||
u32 cons_head; | ||
u32 cons_tail; | ||
struct xdp_ring *ring; | ||
u64 invalid_descs; | ||
}; | ||
|
||
struct xsk_queue *xskq_create(u32 nentries); | ||
void xskq_destroy(struct xsk_queue *q); | ||
|
||
#endif /* _LINUX_XSK_QUEUE_H */ |