Skip to content

Commit 37b0769

Browse files
Björn Töpelborkmann
authored andcommitted
xsk: add missing write- and data-dependency barrier
Here, we add a missing write-barrier, and use READ_ONCE for the data-dependency barrier. Signed-off-by: Björn Töpel <bjorn.topel@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 1c4917d commit 37b0769

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

net/xdp/xsk.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ static int xsk_init_queue(u32 entries, struct xsk_queue **queue,
228228
if (!q)
229229
return -ENOMEM;
230230

231+
/* Make sure queue is ready before it can be seen by others */
232+
smp_wmb();
231233
*queue = q;
232234
return 0;
233235
}
@@ -532,21 +534,23 @@ static int xsk_mmap(struct file *file, struct socket *sock,
532534
unsigned long size = vma->vm_end - vma->vm_start;
533535
struct xdp_sock *xs = xdp_sk(sock->sk);
534536
struct xsk_queue *q = NULL;
537+
struct xdp_umem *umem;
535538
unsigned long pfn;
536539
struct page *qpg;
537540

538541
if (offset == XDP_PGOFF_RX_RING) {
539-
q = xs->rx;
542+
q = READ_ONCE(xs->rx);
540543
} else if (offset == XDP_PGOFF_TX_RING) {
541-
q = xs->tx;
544+
q = READ_ONCE(xs->tx);
542545
} else {
543-
if (!xs->umem)
546+
umem = READ_ONCE(xs->umem);
547+
if (!umem)
544548
return -EINVAL;
545549

546550
if (offset == XDP_UMEM_PGOFF_FILL_RING)
547-
q = xs->umem->fq;
551+
q = READ_ONCE(umem->fq);
548552
else if (offset == XDP_UMEM_PGOFF_COMPLETION_RING)
549-
q = xs->umem->cq;
553+
q = READ_ONCE(umem->cq);
550554
}
551555

552556
if (!q)

0 commit comments

Comments
 (0)