Skip to contentSkip to conversation

xsk: skip polling event check for unbound socket

PATCH Applied Yewon Choi 3 participants 3 messages Dec 1, 2023 – Dec 5, 2023

Subsystems (4)
lore
Share & tools
lore

Yewon Choi

author
#0 lore raw

PATCH 1/1 xsk: skip polling event check for unbound socket

In xsk_poll(), checking available events and setting mask bits should be executed only when a socket has been bound. Setting mask bits for unbound socket is meaningless.
Currently, it checks events even when xsk_check_common() failed. To prevent this, we move goto location (skip_tx) after that checking.

Fixes 1596dae2f17e ("xsk: check IFF_UP earlier in Tx path")
---
 net/xdp/xsk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/xdp/xsk.c +2 -2
index ae9f8cb611f6..1e5a65326d1d 100644
@@ -947,7 +947,7 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
 
 	rcu_read_lock();
 	if (xsk_check_common(xs))
-		goto skip_tx;
+		goto out;
 
 	pool = xs->pool;
 
@@ -959,12 +959,12 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
 			xsk_generic_xmit(sk);
 	}
 
-skip_tx:
 	if (xs->rx && !xskq_prod_is_empty(xs->rx))
 		mask |= EPOLLIN | EPOLLRDNORM;
 	if (xs->tx && xsk_tx_writeable(xs))
 		mask |= EPOLLOUT | EPOLLWRNORM;
 
+out:
 	rcu_read_unlock();
 	return mask;
 }
Signature · 1 line
2.37.3
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Yewon Choi

In xsk_poll(), checking available events and setting mask bits should be executed only when a socket has been bound. Setting mask bits for unbound socket is meaningless.
Currently, it checks events even when xsk_check_common() failed. To prevent this, we move goto location (skip_tx) after that checking.

Thanks for the fix.

Quoted 37 lines
Fixes 1596dae2f17e ("xsk: check IFF_UP earlier in Tx path")
---
 net/xdp/xsk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/xdp/xsk.c +2 -3
index ae9f8cb611f6..1e5a65326d1d 100644
@@ -947,7 +947,7 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
 
        rcu_read_lock();
        if (xsk_check_common(xs))
-               goto skip_tx;
+               goto out;
 
        pool = xs->pool;
 
@@ -959,12 +959,12 @@ static __poll_t xsk_poll(struct file *file, struct socket *sock,
                        xsk_generic_xmit(sk);
        }
 
-skip_tx:
        if (xs->rx && !xskq_prod_is_empty(xs->rx))
                mask |= EPOLLIN | EPOLLRDNORM;
        if (xs->tx && xsk_tx_writeable(xs))
                mask |= EPOLLOUT | EPOLLWRNORM;
 
+out:
        rcu_read_unlock();
        return mask;
 }
--

2.37.3

#2 lore raw
In reply to Yewon Choi
This patch was applied to bpf/bpf.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <[email protected]>:

Quoted 10 lines · On Fri, 1 Dec 2023 15:10:52 +0900 you wrote:

In xsk_poll(), checking available events and setting mask bits should be executed only when a socket has been bound. Setting mask bits for unbound socket is meaningless.
Currently, it checks events even when xsk_check_common() failed. To prevent this, we move goto location (skip_tx) after that checking.

Fixes 1596dae2f17e ("xsk: check IFF_UP earlier in Tx path")

[...]

Here is the summary with links:
- [bpf] xsk: skip polling event check for unbound socket

    https://git.kernel.org/bpf/bpf/c/e4d008d49a71

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html