diff mbox series

[bpf-next,v2,2/3] bpf: xdp, virtio_net use access ptr macro for xdp enable check

Message ID 1580011133-17784-3-git-send-email-john.fastabend@gmail.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series XDP flush cleanups | expand

Commit Message

John Fastabend Jan. 26, 2020, 3:58 a.m. UTC
virtio_net currently relies on rcu critical section to access the xdp
program in its xdp_xmit handler. However, the pointer to the xdp program
is only used to do a NULL pointer comparison to determine if xdp is
enabled or not.

Use rcu_access_pointer() instead of rcu_dereference() to reflect this.
Then later when we drop rcu_read critical section virtio_net will not
need in special handling.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jesper Dangaard Brouer Jan. 26, 2020, 9:28 p.m. UTC | #1
On Sat, 25 Jan 2020 19:58:52 -0800
John Fastabend <john.fastabend@gmail.com> wrote:

> virtio_net currently relies on rcu critical section to access the xdp
> program in its xdp_xmit handler. However, the pointer to the xdp program
> is only used to do a NULL pointer comparison to determine if xdp is
> enabled or not.
> 
> Use rcu_access_pointer() instead of rcu_dereference() to reflect this.
> Then later when we drop rcu_read critical section virtio_net will not
> need in special handling.
> 
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4d7d5434..945eabc 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -501,7 +501,7 @@  static int virtnet_xdp_xmit(struct net_device *dev,
 	/* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this
 	 * indicate XDP resources have been successfully allocated.
 	 */
-	xdp_prog = rcu_dereference(rq->xdp_prog);
+	xdp_prog = rcu_access_pointer(rq->xdp_prog);
 	if (!xdp_prog)
 		return -ENXIO;