lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1556786363-28743-7-git-send-email-magnus.karlsson@intel.com>
Date:   Thu,  2 May 2019 10:39:22 +0200
From:   Magnus Karlsson <magnus.karlsson@...el.com>
To:     magnus.karlsson@...el.com, bjorn.topel@...el.com, ast@...nel.org,
        daniel@...earbox.net, netdev@...r.kernel.org, brouer@...hat.com
Cc:     bpf@...r.kernel.org, bruce.richardson@...el.com,
        ciara.loftus@...el.com, jakub.kicinski@...ronome.com,
        xiaolong.ye@...el.com, qi.z.zhang@...el.com, maximmi@...lanox.com,
        sridhar.samudrala@...el.com, kevin.laatz@...el.com
Subject: [RFC bpf-next 6/7] libbpf: add busy-poll support to XDP sockets

This patch adds busy-poll support for XDP sockets to libbpf. A new
option is provided in the xsk_socket_config struct called
busy_poll. The value of it is the desired batch size. A value between
1 and NAPI_WEIGHT (64) will turn it on, 0 will turn it off and any
other value will return an error.

Signed-off-by: Magnus Karlsson <magnus.karlsson@...el.com>
---
 tools/include/uapi/linux/if_xdp.h |  1 +
 tools/lib/bpf/xsk.c               | 23 +++++++++++++----------
 tools/lib/bpf/xsk.h               |  1 +
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/tools/include/uapi/linux/if_xdp.h b/tools/include/uapi/linux/if_xdp.h
index caed8b1..be28a78 100644
--- a/tools/include/uapi/linux/if_xdp.h
+++ b/tools/include/uapi/linux/if_xdp.h
@@ -46,6 +46,7 @@ struct xdp_mmap_offsets {
 #define XDP_UMEM_FILL_RING		5
 #define XDP_UMEM_COMPLETION_RING	6
 #define XDP_STATISTICS			7
+#define XDP_BUSY_POLL_BATCH_SIZE	8
 
 struct xdp_umem_reg {
 	__u64 addr; /* Start of packet data area */
diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index 557ef8d..b5538f1 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -120,10 +120,7 @@ static void xsk_set_umem_config(struct xsk_umem_config *cfg,
 		return;
 	}
 
-	cfg->fill_size = usr_cfg->fill_size;
-	cfg->comp_size = usr_cfg->comp_size;
-	cfg->frame_size = usr_cfg->frame_size;
-	cfg->frame_headroom = usr_cfg->frame_headroom;
+	memcpy(cfg, usr_cfg, sizeof(*usr_cfg));
 }
 
 static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
@@ -135,18 +132,14 @@ static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
 		cfg->libbpf_flags = 0;
 		cfg->xdp_flags = 0;
 		cfg->bind_flags = 0;
+		cfg->busy_poll = 0;
 		return 0;
 	}
 
 	if (usr_cfg->libbpf_flags & ~XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD)
 		return -EINVAL;
 
-	cfg->rx_size = usr_cfg->rx_size;
-	cfg->tx_size = usr_cfg->tx_size;
-	cfg->libbpf_flags = usr_cfg->libbpf_flags;
-	cfg->xdp_flags = usr_cfg->xdp_flags;
-	cfg->bind_flags = usr_cfg->bind_flags;
-
+	memcpy(cfg, usr_cfg, sizeof(*usr_cfg));
 	return 0;
 }
 
@@ -632,6 +625,16 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
 	}
 	xsk->tx = tx;
 
+	if (xsk->config.busy_poll) {
+		err = setsockopt(xsk->fd, SOL_XDP, XDP_BUSY_POLL_BATCH_SIZE,
+				 &xsk->config.busy_poll,
+				 sizeof(xsk->config.busy_poll));
+		if (err) {
+			err = -errno;
+			goto out_mmap_tx;
+		}
+	}
+
 	sxdp.sxdp_family = PF_XDP;
 	sxdp.sxdp_ifindex = xsk->ifindex;
 	sxdp.sxdp_queue_id = xsk->queue_id;
diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h
index 82ea71a..517a56a 100644
--- a/tools/lib/bpf/xsk.h
+++ b/tools/lib/bpf/xsk.h
@@ -187,6 +187,7 @@ struct xsk_socket_config {
 	__u32 libbpf_flags;
 	__u32 xdp_flags;
 	__u16 bind_flags;
+	__u16 busy_poll;
 };
 
 /* Set config to NULL to get the default configuration. */
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ