Netdev Archive on lore.kernel.org
 help / Atom feed
* [PATCH bpf] xsk: add missing smp_rmb() in xsk_mmap
@ 2019-02-08 13:13 Magnus Karlsson
  2019-02-11  4:08 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Magnus Karlsson @ 2019-02-08 13:13 UTC (permalink / raw)
  To: magnus.karlsson, bjorn.topel, ast, daniel, netdev

All the setup code in AF_XDP is protected by a mutex with the
exception of the mmap code that cannot use it. To make sure that a
process banging on the mmap call at the same time as another process
is setting up the socket, smp_wmb() calls were added in the umem
registration code and the queue creation code, so that the published
structures that xsk_mmap needs would be consistent. However, the
corresponding smp_rmb() calls were not added to the xsk_mmap
code. This patch adds these calls.

Fixes: 37b076933a8e3 ("xsk: add missing write- and data-dependency barrier")
Fixes: c0c77d8fb787c ("xsk: add user memory registration support sockopt")
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 net/xdp/xsk.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index a032684..45f3b52 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -669,6 +669,8 @@ static int xsk_mmap(struct file *file, struct socket *sock,
 		if (!umem)
 			return -EINVAL;
 
+		/* Matches the smp_wmb() in XDP_UMEM_REG */
+		smp_rmb();
 		if (offset == XDP_UMEM_PGOFF_FILL_RING)
 			q = READ_ONCE(umem->fq);
 		else if (offset == XDP_UMEM_PGOFF_COMPLETION_RING)
@@ -678,6 +680,8 @@ static int xsk_mmap(struct file *file, struct socket *sock,
 	if (!q)
 		return -EINVAL;
 
+	/* Matches the smp_wmb() in xsk_init_queue */
+	smp_rmb();
 	qpg = virt_to_head_page(q->ring);
 	if (size > (PAGE_SIZE << compound_order(qpg)))
 		return -EINVAL;
-- 
2.7.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf] xsk: add missing smp_rmb() in xsk_mmap
  2019-02-08 13:13 [PATCH bpf] xsk: add missing smp_rmb() in xsk_mmap Magnus Karlsson
@ 2019-02-11  4:08 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2019-02-11  4:08 UTC (permalink / raw)
  To: Magnus Karlsson; +Cc: bjorn.topel, ast, daniel, netdev

On Fri, Feb 08, 2019 at 02:13:50PM +0100, Magnus Karlsson wrote:
> All the setup code in AF_XDP is protected by a mutex with the
> exception of the mmap code that cannot use it. To make sure that a
> process banging on the mmap call at the same time as another process
> is setting up the socket, smp_wmb() calls were added in the umem
> registration code and the queue creation code, so that the published
> structures that xsk_mmap needs would be consistent. However, the
> corresponding smp_rmb() calls were not added to the xsk_mmap
> code. This patch adds these calls.
> 
> Fixes: 37b076933a8e3 ("xsk: add missing write- and data-dependency barrier")
> Fixes: c0c77d8fb787c ("xsk: add user memory registration support sockopt")
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>

Applied, Thanks


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-08 13:13 [PATCH bpf] xsk: add missing smp_rmb() in xsk_mmap Magnus Karlsson
2019-02-11  4:08 ` Alexei Starovoitov

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org netdev@archiver.kernel.org
	public-inbox-index netdev


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox