Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp133166ybi; Tue, 2 Jul 2019 17:41:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcOJh1Eavq6KOuaLoPexHPlmS3XmDLADZ51OQkOeYguqrsmKPzhJRwmRTp6U6n+iDNBKES X-Received: by 2002:a17:90b:f0e:: with SMTP id br14mr8724440pjb.117.1562114474368; Tue, 02 Jul 2019 17:41:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562114474; cv=none; d=google.com; s=arc-20160816; b=rQ4to06ec366636BIAnpeWxgGuwnvYpx/Jt4LafYg4XsuGJG6zNei6meNgZa00fMYW CJwNno/jyq2VdnhtWcGmkIW0HJ40DK47lWVgQJmS0oFj4BcHq7myGqsfN1sev0cAoCkA islVdenNy8ZdLErF038zR9pyknWGp2lWjvWPGBJvNC6XHe0tjmkVtlCCshgoFrV6ecKb gNL1VIDQdECMDXeBx9AIZwjk0RNaX03FWC0rdZ9ZVp06sDUyuC0id+EtPewYiC1Wgoz5 aEEtN+g7pcA41AUXENdZRuCaNik2PeA/Mf0sa4MT8b7J28XXjNLzPnBbQWm57fJhzfPS FQOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=4BtV39KjV7sDRMWmrXQvT/nf8DtHimxpqWMrsA8yZ8g=; b=a13BDrZ7peiPZVqifwThkRxrN+qkJFQWN1fcY5x/6/ccEqo1C7Nw5SgOm6dKt2Wj6e 75iATX8TYCHkdF7u9yz45eW7uZtAlAvINNWIVRh1oF39C18anv4ZLGlFSN5bCaUUEs2c 03R4oMoDdENq/+K8QfXFSe3pRa9+LFNQ8BXGUdfLHqbCG4EYO4WWUUtpFJAvTrxj/GBX ejKBGaqywPvU56lSD5IL12baZKM859M2bKJj4ChnDcvixh36qk8yAmfSnHkzfw9hRo0H btk3Pilc8ZdHG6i5R0HVg9ppX7Px7o4xQ0qfH/DTPAed8M+UXX23cJ3fP5X1q5hM6SJV NKtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=CQdsRFF1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w67si312404pfb.125.2019.07.02.17.40.55; Tue, 02 Jul 2019 17:41:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@netronome-com.20150623.gappssmtp.com header.s=20150623 header.b=CQdsRFF1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727217AbfGCAkU (ORCPT + 99 others); Tue, 2 Jul 2019 20:40:20 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:45559 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726457AbfGCAkU (ORCPT ); Tue, 2 Jul 2019 20:40:20 -0400 Received: by mail-qt1-f196.google.com with SMTP id j19so640752qtr.12 for ; Tue, 02 Jul 2019 17:40:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=4BtV39KjV7sDRMWmrXQvT/nf8DtHimxpqWMrsA8yZ8g=; b=CQdsRFF171jO5+/s1qAUI1rgCzyTzJDs9gZOQMPyPjnK2ayU+zBw/Y1zuHJcS3Aqaa DOee7yY43BfLZd8G3dM1yUpHgG+YIbD8ROTNtVfGY52fSj7ya5Ed3OQroTo8Cz47Xh/E dsaGad6apPp+ZEq3MUye/V3Lzt0F7FRJxgyu40Nim3+roBef6y/zVuOZO/ydtLb1/7AV V8+ae4mRJHOin7xdq2VTx5cmL15S+2G3Ry0hVPR8zpWJTpk/CBENGKyWw6bmiU1kCm0N 0AxXt/FTvuMJ1c1JkMO+FwHTrYgADhhuWJSrhkbmeqEKELzouSnt6TgRV1MAj0P94Sef 4LpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=4BtV39KjV7sDRMWmrXQvT/nf8DtHimxpqWMrsA8yZ8g=; b=gZkP6IL4sG8qMdLtqllF89PMV44vs46HFgwwn04A9shhVa4fOY4+x/0vDgDciU08SY xEE6pXqcd1puUXbVpm/tKKVFB7Vwc5b5a8jlN6CgGJMaSWpfyjyaz5q3wXKCU9H/l2TV 1HPzLJWIhrVWNSzpQUyEle/Y+nXz8GbHTa6D35fzBjqTydRwKdewexR2Ut1CXSW+8cIf g434yyiChkFOfJl/HBFOEQoEmXmFa46hiuHTgTx2eMj708lY0WeBjXNtKOXnXS0AQKED 8lPAq+ya66my0YZx1bp4z280wmbPkkD9y72OWJgDOQqeNZ+cCbg9MsstvokyE5xCDywL MaiQ== X-Gm-Message-State: APjAAAXEy+1wcjo9lkgI2cMNwscGDaKesKnLCvuxsOuF6qaZE3v5bxzV Dwkb/0pcuJ5ftxiXYb7DnYMldQ== X-Received: by 2002:ac8:2b14:: with SMTP id 20mr28665349qtu.295.1562114419416; Tue, 02 Jul 2019 17:40:19 -0700 (PDT) Received: from cakuba.netronome.com ([66.60.152.14]) by smtp.gmail.com with ESMTPSA id c18sm220886qkm.78.2019.07.02.17.40.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 17:40:19 -0700 (PDT) Date: Tue, 2 Jul 2019 17:40:14 -0700 From: Jakub Kicinski To: Ilya Maximets Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, xdp-newbies@vger.kernel.org, "David S. Miller" , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , Jonathan Lemon , Alexei Starovoitov , Daniel Borkmann Subject: Re: [PATCH bpf] xdp: fix race on generic receive path Message-ID: <20190702174014.005a3166@cakuba.netronome.com> In-Reply-To: <20190702143634.19688-1-i.maximets@samsung.com> References: <20190702143634.19688-1-i.maximets@samsung.com> Organization: Netronome Systems, Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2 Jul 2019 17:36:34 +0300, Ilya Maximets wrote: > Unlike driver mode, generic xdp receive could be triggered > by different threads on different CPU cores at the same time > leading to the fill and rx queue breakage. For example, this > could happen while sending packets from two processes to the > first interface of veth pair while the second part of it is > open with AF_XDP socket. > > Need to take a lock for each generic receive to avoid race. > > Fixes: c497176cb2e4 ("xsk: add Rx receive functions and poll support") > Signed-off-by: Ilya Maximets > diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c > index a14e8864e4fa..19f41d2b670c 100644 > --- a/net/xdp/xsk.c > +++ b/net/xdp/xsk.c > @@ -119,17 +119,22 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp) > { > u32 metalen = xdp->data - xdp->data_meta; > u32 len = xdp->data_end - xdp->data; > + unsigned long flags; > void *buffer; > u64 addr; > int err; > > - if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index) > - return -EINVAL; > + spin_lock_irqsave(&xs->rx_lock, flags); Why _irqsave, rather than _bh? > + if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index) { > + err = -EINVAL; > + goto out_unlock; > + } > > if (!xskq_peek_addr(xs->umem->fq, &addr) || > len > xs->umem->chunk_size_nohr - XDP_PACKET_HEADROOM) { > - xs->rx_dropped++; > - return -ENOSPC; > + err = -ENOSPC; > + goto out_drop; > } > > addr += xs->umem->headroom;