From patchwork Fri Dec 15 17:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 13494673 X-Patchwork-Delegate: kuba@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 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" 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: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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, …) would happen outside of the locked section. 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/marvell/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, len = xdp->data_end - xdp->data_hard_start - pp->rx_offset_correction; data_len = xdp->data_end - xdp->data; + + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act = bpf_prog_run_xdp(prog, xdp); /* 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_prog *prog, u32 ret, act; len = xdp->data_end - xdp->data_hard_start - MVPP2_SKB_HEADROOM; + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act = bpf_prog_run_xdp(prog, xdp); /* 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/drivers/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); + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act = bpf_prog_run_xdp(prog, &xdp); switch (act) {