Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6828916rdb; Fri, 15 Dec 2023 09:18:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7Rm4k1oPJmsdKj63vye7TVHcMi6pOA05bfHKZUWDl7+eTPb+hH446S7ccONh+cxgIdIDX X-Received: by 2002:a0c:c58d:0:b0:67a:a10e:9187 with SMTP id a13-20020a0cc58d000000b0067aa10e9187mr11595845qvj.14.1702660714438; Fri, 15 Dec 2023 09:18:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702660714; cv=none; d=google.com; s=arc-20160816; b=KWMTySmujY5/TGVvQpQP6TJn0nRQdNl0lR3chxkw204owkpqQlpyDP8Qwjk0EJa1Lc GaRvrM6SV7co2AdFuuvwdXKeqN3oh3qDgxu9I3No7JMcFP1CIlVWXgzTdWpStOqy+If0 3uH3iuOhCjl/TYa+9lMGAX9jTMVhLy7IAw8mUaW7O3aKbrV5cVBfZ52tbZq6QJHXhLeQ GLSOnGhGM19Jte8Cc1cVMbaoRRxjg3UaSnW2MiEo8ZLNmlYOmd4X3521NaOmVIEQJHNI gBJiIESuVkTe1ww5cimV2YAx00EImVURZw5tak+CvC7i0GSE1eMrBqGoa7huibIkhOb4 5Aww== 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=Recusd+7IXvA5TirXIVteFQz/CPKIdbiblHLxPiaZxI=; fh=ZXoT7XgUisLD+FEi4KFPf9pD9wPkMHWhWwn6J9Z7P0U=; b=SwJUlkgxqHsIqS+zKAmAsHeA2DIPUlDHwDm+IfN/K4RpzO2t3cxfXfEiX6RI7eb4iE 1b6J0b97C6GmiInWqbTCbhUg+469B3BtFpM0wBOdN/117xxoh4TdgS4s+U50AznHM7as TTQUeHZqhbpVlPgkPHewunqHzVZY3HSZw4Xh2Pg2ucbmsJfBEcqztvGnozPSf2NFGkxX PNAxMRC4YqL/FQSx+cwkMxX7vWPXzavQl3VBzE8DG8a2pp/P3WPfvJr2EQpiB5n6SChN YGmDQ+AXPrKktlBkeSx9PX6XNdjnJLE+MYr86dJK7nc/klkZPI/hiGw50PFAStniw8aO RY8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aUResC8P; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-1384-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1384-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n19-20020a0cdc93000000b0067f1a8cf91dsi1395847qvk.181.2023.12.15.09.18.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:18:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1384-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=aUResC8P; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-1384-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1384-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 260AC1C240C4 for ; Fri, 15 Dec 2023 17:18:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AABDC6E595; Fri, 15 Dec 2023 17:10:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aUResC8P"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FII+fmLC" 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 C4D5F6A009; Fri, 15 Dec 2023 17:10:44 +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=1702660243; 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=Recusd+7IXvA5TirXIVteFQz/CPKIdbiblHLxPiaZxI=; b=aUResC8P3BrfQM2X1JaMPOmerJ/fL+xFTgQ0h+PlYjy/+qzzA8IU4zA12Gt2DftI4dwg90 vDVGZp90lgsRPLWIJaLqvlEIAu3kxfLymGyseqWwuXB9632aXbrkR38hpACqjJj1/riXUX 0A/iuTlDhmkjhXwe1/7n280Ofy2fi2ViRE/SW5jv94TBqf6cioyCWs5oOhSTXAtqekLn/b bTWJbtbdM79zG5ankAAQEbXwm0xwcIXGQ/y6S8d8nP3PKyPNn0u2aoQVKwjPX3nep3lcjd dwFzEnrDiJye3KkRP9dGlHYEWCA71AVfUu/NFmTSzaFF4Y417CqofwsVhqnbXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1702660243; 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=Recusd+7IXvA5TirXIVteFQz/CPKIdbiblHLxPiaZxI=; b=FII+fmLCYFU6/PJPm9PIVesU9ltySEE2RUfVan+2Gga/GlGuHcVIKzoQbPaWAZ6rho2K+9 cvS7J2jl2aks+ACw== 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 , Alexandre Torgue , Alexei Starovoitov , Ariel Elior , Ilias Apalodimas , Jassi Brar , Jesper Dangaard Brouer , John Fastabend , Jose Abreu , Manish Chopra , Maxime Coquelin , Ravi Gunasekaran , Roger Quadros , Siddharth Vadapalli , bpf@vger.kernel.org, linux-omap@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH net-next 23/24] net: qlogic, socionext, stmmac, cpsw: Use nested-BH locking for XDP redirect. Date: Fri, 15 Dec 2023 18:07:42 +0100 Message-ID: <20231215171020.687342-24-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: Alexandre Torgue Cc: Alexei Starovoitov Cc: Ariel Elior Cc: Ilias Apalodimas Cc: Jassi Brar Cc: Jesper Dangaard Brouer Cc: John Fastabend Cc: Jose Abreu Cc: Manish Chopra Cc: Maxime Coquelin Cc: Ravi Gunasekaran Cc: Roger Quadros Cc: Siddharth Vadapalli Cc: bpf@vger.kernel.org Cc: linux-omap@vger.kernel.org Cc: linux-stm32@st-md-mailman.stormreply.com Signed-off-by: Sebastian Andrzej Siewior --- drivers/net/ethernet/qlogic/qede/qede_fp.c | 1 + drivers/net/ethernet/socionext/netsec.c | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 1 + drivers/net/ethernet/ti/cpsw_priv.c | 15 +++++++++------ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/qlogic/qede/qede_fp.c b/drivers/net/ether= net/qlogic/qede/qede_fp.c index cb1746bc0e0c5..ce5af094fb817 100644 --- a/drivers/net/ethernet/qlogic/qede/qede_fp.c +++ b/drivers/net/ethernet/qlogic/qede/qede_fp.c @@ -1091,6 +1091,7 @@ static bool qede_rx_xdp(struct qede_dev *edev, xdp_prepare_buff(&xdp, page_address(bd->data), *data_offset, *len, false); =20 + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act =3D bpf_prog_run_xdp(prog, &xdp); =20 /* Recalculate, as XDP might have changed the headers */ diff --git a/drivers/net/ethernet/socionext/netsec.c b/drivers/net/ethernet= /socionext/netsec.c index 0891e9e49ecb5..47e314338f3f3 100644 --- a/drivers/net/ethernet/socionext/netsec.c +++ b/drivers/net/ethernet/socionext/netsec.c @@ -905,6 +905,7 @@ static u32 netsec_run_xdp(struct netsec_priv *priv, str= uct bpf_prog *prog, int err; u32 act; =20 + 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/stmicro/stmmac/stmmac_main.c b/drivers/ne= t/ethernet/stmicro/stmmac/stmmac_main.c index 37e64283f9107..9e92affc8c22c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4893,6 +4893,7 @@ static int __stmmac_xdp_run_prog(struct stmmac_priv *= priv, u32 act; int res; =20 + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); act =3D bpf_prog_run_xdp(prog, xdp); switch (act) { case XDP_PASS: diff --git a/drivers/net/ethernet/ti/cpsw_priv.c b/drivers/net/ethernet/ti/= cpsw_priv.c index 764ed298b5708..f38c49f9fab35 100644 --- a/drivers/net/ethernet/ti/cpsw_priv.c +++ b/drivers/net/ethernet/ti/cpsw_priv.c @@ -1335,9 +1335,15 @@ int cpsw_run_xdp(struct cpsw_priv *priv, int ch, str= uct xdp_buff *xdp, if (!prog) return CPSW_XDP_PASS; =20 - act =3D bpf_prog_run_xdp(prog, xdp); - /* XDP prog might have changed packet data and boundaries */ - *len =3D xdp->data_end - xdp->data; + scoped_guard(local_lock_nested_bh, &bpf_run_lock.redirect_lock) { + act =3D bpf_prog_run_xdp(prog, xdp); + /* XDP prog might have changed packet data and boundaries */ + *len =3D xdp->data_end - xdp->data; + if (act =3D=3D XDP_REDIRECT) { + if (xdp_do_redirect(ndev, xdp, prog)) + goto drop; + } + } =20 switch (act) { case XDP_PASS: @@ -1352,9 +1358,6 @@ int cpsw_run_xdp(struct cpsw_priv *priv, int ch, stru= ct xdp_buff *xdp, xdp_return_frame_rx_napi(xdpf); break; case XDP_REDIRECT: - if (xdp_do_redirect(ndev, xdp, prog)) - goto drop; - /* Have to flush here, per packet, instead of doing it in bulk * at the end of the napi handler. The RX devices on this * particular hardware is sharing a common queue, so the --=20 2.43.0