Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6828315rdb; Fri, 15 Dec 2023 09:17:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFOd6KY71ch8wdDLsqQveK5s6dHmoaW7QxmR8NLK4rfH3OCB6vt9qscI3C0uuu99yTq1cny X-Received: by 2002:a50:a453:0:b0:551:dda3:b4bd with SMTP id v19-20020a50a453000000b00551dda3b4bdmr3391491edb.25.1702660665901; Fri, 15 Dec 2023 09:17:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702660665; cv=none; d=google.com; s=arc-20160816; b=Yd1b/RQOh01Tq5Awf507UJ5oQWPA0RT0gLkmRwfw0McB9pD9HHrH59I8WsJPPLaw+m KudZ4xcStlOWNH0aeYRVIb3YfJm+LuEO7GxE7kSbAgnAQDPjYStA+rFb6+IW1UoEQW45 194f8sQ9dsY2GuelrK0F9ANM0cAWdrqlV6uRPEPVbhF6AeBmKPpTvjuMwtTqjsB25Bc9 oHynQRapmXi/oga4ZGiV0NQnkHcEV/vFs1sXzJ6pKL9XUyWRB+/P1L7ActOKvyoy9o6F jNzq3bU+Y5YI1+NYetR2Vg/YrPYCFHaZpme2qLWKJ1zUv54O3f55zOyVpuv3T9GW3bOj qk7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=U5e+RJtEB4QE08KKZsUA35+KJH98yIUgL+9mMUjgvNI=; fh=ea1k8QoeGuEWLJaLOHGHU1W5poGB+NQURYRIITAqnJE=; b=yURb/XicgqXYiYO1Sw82NqUZdQJKEtURBNZzHerEaTx0kHpVIba+OwgwtzPPwUiVr1 swHpCeNm1Q3msU+8l8c5dpdDpTHc6T8EwlXWCzEU1JL0cemzwwq1xhSwc2HZdkAwXivp 9AA1rkI/Pb5RBmyO4wIT4oW8Zwh2eI7wDEBfIvlBQaDTrxkOKTmhRo1rMJIW1IRE3Qml ehGVBNokNEBT/Mi/P72xecQngriRcHB6wkmcHeXcqyhmMLPr4ltMvW78AauIIS0v12Av Pf9CupvNQGu6oPf0qmc1wNKcjvXlbPyd8pwlTf4KBmxPThW7CswFVJ7KBWeqkbPVY9kO YDwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Nh4vzk05; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-1383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1383-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cy10-20020a0564021c8a00b00552e87ca98dsi148963edb.103.2023.12.15.09.17.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:17:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Nh4vzk05; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-1383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1383-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A5B231F219DE for ; Fri, 15 Dec 2023 17:17:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C60216D1CA; Fri, 15 Dec 2023 17:10:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Nh4vzk05"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="roNUcQ3I" X-Original-To: linux-kernel@vger.kernel.org Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0DB5675AE; Fri, 15 Dec 2023 17:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1702660242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5e+RJtEB4QE08KKZsUA35+KJH98yIUgL+9mMUjgvNI=; b=Nh4vzk05UBCwB1CUj6f51oueaIgsBsTvxOYK6NKH13SE2KYU3x9v2KYq+qnd5EZlhngWC3 hB3ML3BTRAZimojQ1/fb25dF0EGX8LUpT/em9vtvhSVqxRBOu5IAs1SJyeF+QZn85OnF11 6ap33KhbA2zAvHg1Xw09C1AUhqYipAMAMG/alXrSoAEcktiilnf2pR1YPjbCKpvM+Ojwhj A2CmjrudLB7y6yWijv3IcZbou/XqxD0mvUko35t5+kkPByLJfiTPbSIypDNNQNsmdXPgcz BJshvpSMzQxVuuYhPIgA5mcZIeZWhVYflCDmIZ+ai/Twf087vm4EyL2bpqz6QQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702660242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5e+RJtEB4QE08KKZsUA35+KJH98yIUgL+9mMUjgvNI=; b=roNUcQ3IAN0GribgixBXQrhWf69moqnLZoY35pCy6QQ57aBDHST2l5JfA+eIb9BvgWuar5 bTAHF6rvXFZU6oBA== To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Boqun Feng , Daniel Borkmann , Eric Dumazet , Frederic Weisbecker , Ingo Molnar , Jakub Kicinski , Paolo Abeni , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon , Sebastian Andrzej Siewior , Alexei Starovoitov , Geetha sowjanya , Jesper Dangaard Brouer , John Fastabend , Marcin Wojtas , Russell King , Subbaraya Sundeep , Sunil Goutham , Thomas Petazzoni , hariprasad , bpf@vger.kernel.org Subject: [PATCH net-next 21/24] net: marvell: Use nested-BH locking for XDP redirect. Date: Fri, 15 Dec 2023 18:07:40 +0100 Message-ID: <20231215171020.687342-22-bigeasy@linutronix.de> In-Reply-To: <20231215171020.687342-1-bigeasy@linutronix.de> References: <20231215171020.687342-1-bigeasy@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable The per-CPU variables used during bpf_prog_run_xdp() invocation and later during xdp_do_redirect() rely on disabled BH for their protection. Without locking in local_bh_disable() on PREEMPT_RT these data structure require explicit locking. This is a follow-up on the previous change which introduced bpf_run_lock.redirect_lock and uses it now within drivers. The simple way is to acquire the lock before bpf_prog_run_xdp() is invoked and hold it until the end of function. This does not always work because some drivers (cpsw, atlantic) invoke xdp_do_flush() in the same context. Acquiring the lock in bpf_prog_run_xdp() and dropping in xdp_do_redirect() (without touching drivers) does not work because not all driver, which use bpf_prog_run_xdp(), do support XDP_REDIRECT (and invoke xdp_do_redirect()). Ideally the minimal locking scope would be bpf_prog_run_xdp() + xdp_do_redirect() and everything else (error recovery, DMA unmapping, free/ alloc of memory, =E2=80=A6) would happen outside of the locked sectio= n. Cc: Alexei Starovoitov Cc: Geetha sowjanya Cc: Jesper Dangaard Brouer Cc: John Fastabend Cc: Marcin Wojtas Cc: Russell King Cc: Subbaraya Sundeep Cc: Sunil Goutham Cc: Thomas Petazzoni Cc: hariprasad Cc: bpf@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- drivers/net/ethernet/marvell/mvneta.c | 2 ++ drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 1 + drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 1 + 3 files changed, 4 insertions(+) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/m= arvell/mvneta.c index 29aac327574d6..9c7aacd73b590 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -2263,6 +2263,8 @@ mvneta_run_xdp(struct mvneta_port *pp, struct mvneta_= rx_queue *rxq, =20 len =3D xdp->data_end - xdp->data_hard_start - pp->rx_offset_correction; data_len =3D xdp->data_end - xdp->data; + + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act =3D bpf_prog_run_xdp(prog, xdp); =20 /* Due xdp_adjust_tail: DMA sync for_device cover max len CPU touch */ diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/= ethernet/marvell/mvpp2/mvpp2_main.c index 93137606869e2..3a5524ffaba68 100644 --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c @@ -3793,6 +3793,7 @@ mvpp2_run_xdp(struct mvpp2_port *port, struct bpf_pro= g *prog, u32 ret, act; =20 len =3D xdp->data_end - xdp->data_hard_start - MVPP2_SKB_HEADROOM; + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act =3D bpf_prog_run_xdp(prog, xdp); =20 /* Due xdp_adjust_tail: DMA sync for_device cover max len CPU touch */ diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drive= rs/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c index 4d519ea833b2c..e48e84d6159bc 100644 --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c @@ -1422,6 +1422,7 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic = *pfvf, xdp_prepare_buff(&xdp, hard_start, data - hard_start, cqe->sg.seg_size, false); =20 + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act =3D bpf_prog_run_xdp(prog, &xdp); =20 switch (act) { --=20 2.43.0