From: "Björn Töpel" <bjorn.topel@gmail.com>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
magnus.karlsson@intel.com, ast@kernel.org, daniel@iogearbox.net,
maciej.fijalkowski@intel.com, sridhar.samudrala@intel.com,
jesse.brandeburg@intel.com, qi.z.zhang@intel.com,
kuba@kernel.org, edumazet@google.com, jonathan.lemon@gmail.com,
maximmi@nvidia.com
Subject: [PATCH bpf-next v2 04/10] xsk: check need wakeup flag in sendmsg()
Date: Mon, 16 Nov 2020 12:04:10 +0100 [thread overview]
Message-ID: <20201116110416.10719-5-bjorn.topel@gmail.com> (raw)
In-Reply-To: <20201116110416.10719-1-bjorn.topel@gmail.com>
From: Björn Töpel <bjorn.topel@intel.com>
Add a check for need wake up in sendmsg(), so that if a user calls
sendmsg() when no wakeup is needed, do not trigger a wakeup.
To simplify the need wakeup check in the syscall, unconditionally
enable the need wakeup flag for Tx. This has a side-effect for poll();
If poll() is called for a socket without enabled need wakeup, a Tx
wakeup is unconditionally performed.
The wakeup matrix for AF_XDP now looks like:
need wakeup | poll() | sendmsg() | recvmsg()
------------+--------------+-------------+------------
disabled | wake Tx | wake Tx | nop
enabled | check flag; | check flag; | check flag;
| wake Tx/Rx | wake Tx | wake Rx
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
net/xdp/xsk.c | 6 +++++-
net/xdp/xsk_buff_pool.c | 13 ++++++-------
2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index bda23bd919ad..1cb04b5e4247 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -465,13 +465,17 @@ static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
bool need_wait = !(m->msg_flags & MSG_DONTWAIT);
struct sock *sk = sock->sk;
struct xdp_sock *xs = xdp_sk(sk);
+ struct xsk_buff_pool *pool;
if (unlikely(!xsk_is_bound(xs)))
return -ENXIO;
if (unlikely(need_wait))
return -EOPNOTSUPP;
- return __xsk_sendmsg(sk);
+ pool = xs->pool;
+ if (pool->cached_need_wakeup & XDP_WAKEUP_TX)
+ return __xsk_sendmsg(sk);
+ return 0;
}
static int xsk_recvmsg(struct socket *sock, struct msghdr *m, size_t len, int flags)
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 8a3bf4e1318e..96bb607853ad 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -144,14 +144,13 @@ static int __xp_assign_dev(struct xsk_buff_pool *pool,
if (err)
return err;
- if (flags & XDP_USE_NEED_WAKEUP) {
+ if (flags & XDP_USE_NEED_WAKEUP)
pool->uses_need_wakeup = true;
- /* Tx needs to be explicitly woken up the first time.
- * Also for supporting drivers that do not implement this
- * feature. They will always have to call sendto().
- */
- pool->cached_need_wakeup = XDP_WAKEUP_TX;
- }
+ /* Tx needs to be explicitly woken up the first time. Also
+ * for supporting drivers that do not implement this
+ * feature. They will always have to call sendto() or poll().
+ */
+ pool->cached_need_wakeup = XDP_WAKEUP_TX;
dev_hold(netdev);
--
2.27.0
next prev parent reply other threads:[~2020-11-16 12:37 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-16 11:04 [PATCH bpf-next v2 00/10] Introduce preferred busy-polling Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 01/10] net: introduce " Björn Töpel
2020-11-16 16:04 ` Jakub Kicinski
2020-11-16 16:19 ` Björn Töpel
2020-11-16 17:28 ` Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 02/10] net: add SO_BUSY_POLL_BUDGET socket option Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 03/10] xsk: add support for recvmsg() Björn Töpel
2020-11-16 11:04 ` Björn Töpel [this message]
2020-11-16 11:04 ` [PATCH bpf-next v2 05/10] xsk: add busy-poll support for {recv,send}msg() Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 06/10] xsk: propagate napi_id to XDP socket Rx path Björn Töpel
2020-11-16 11:19 ` Tariq Toukan
2020-11-16 11:55 ` Michael S. Tsirkin
2020-11-16 12:01 ` Björn Töpel
2020-11-16 12:42 ` Michael S. Tsirkin
2020-11-16 13:24 ` Björn Töpel
2020-11-16 13:55 ` Michael S. Tsirkin
2020-11-16 17:40 ` Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 07/10] samples/bpf: use recvfrom() in xdpsock/rxdrop Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 08/10] samples/bpf: use recvfrom() in xdpsock/l2fwd Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 09/10] samples/bpf: add busy-poll support to xdpsock Björn Töpel
2020-11-16 11:04 ` [PATCH bpf-next v2 10/10] samples/bpf: add option to set the busy-poll budget Björn Töpel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201116110416.10719-5-bjorn.topel@gmail.com \
--to=bjorn.topel@gmail.com \
--cc=ast@kernel.org \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=edumazet@google.com \
--cc=jesse.brandeburg@intel.com \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=maximmi@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=qi.z.zhang@intel.com \
--cc=sridhar.samudrala@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox