Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp262425rdb; Tue, 19 Dec 2023 16:26:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+EYmgTUtd2H8eKD7OMl8N89VUywcy3qlEgeMx6zsgSzz6C4oshh42klDwVz1cC3EKCb// X-Received: by 2002:ae9:e315:0:b0:77f:6810:dcff with SMTP id v21-20020ae9e315000000b0077f6810dcffmr2781632qkf.28.1703031977957; Tue, 19 Dec 2023 16:26:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703031977; cv=none; d=google.com; s=arc-20160816; b=tfeKjiyPU5TSa84LfKiZ/9+qAuAGZ4vQ0BFLrcHHHsc1ntinnR4pSk+8uQ6L6+fMiD PgyNrzKWLb+T+MzkGi3vX7qqi3bwffJHbDlqL9mK3nRX/Er+44yQHREA6tT89G1e52g/ XhG30BGaxmUEDh7PtKUyShGAPRmE6vRshTN+RLak/DV4wncxGfMRDf95vcCybZnM1dna eR77sYAOtyxfuGfT4IR4o4guggxVcYHYo/+Wxe5srYrPjOL96zwyuq9cynmecVKc/Nn2 TUHw+rpVkeydh4oPNvJIuBPvtn/daT5F3HKYNgfCXO+6dXjMvD3s80Wc5vIjzX/HWl+V jrkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=P8SdDvE7M57yXe3BWZ3ZcRgxoEXpwC009EWtj4naDlo=; fh=gZhPuK1bY+rSfZpu5/vnJyky9PHb8CccnYgTM3ZEJDM=; b=H8m6Z4Pe0pb4tvjtdFTfGfE2Ul3fze6x2BK4kwKqdBuo/Z/C1rocSVWPzqG0jwVhNN oqF8OCtcdMHRyhFyNYfn03lOJCBTzhyPKesvVIzY6OFCoqN94RSfJMM4zibcqHPpyicw GwX+0AjOU8vempFNFD8ZFGhyqW/baaZHvscQzdNUjTrHJnOhxnqVmyBdB4nrpSRs0Y7V BN7x+/3ABIFhT0l4Y0a0VKBEI6RnvHPJQGxXdtU4cUErAp3I1wgVo6z07ef1WDbJBD5a LdtOKgsSj5NDPRCG7Aa3l8oa7HaUxD/ULlin/pDrnKSj/XDrbxHLFShTRillLwObu66m EDMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jrLEakRO; spf=pass (google.com: domain of linux-kernel+bounces-6161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6161-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id qs2-20020a05620a394200b0077d91e758d2si26098190qkn.282.2023.12.19.16.26.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 16:26:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-6161-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=@gmail.com header.s=20230601 header.b=jrLEakRO; spf=pass (google.com: domain of linux-kernel+bounces-6161-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-6161-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 A59B71C25175 for ; Wed, 20 Dec 2023 00:26:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4CC83C34; Wed, 20 Dec 2023 00:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jrLEakRO" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3C7246B0; Wed, 20 Dec 2023 00:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3366e78d872so2292326f8f.3; Tue, 19 Dec 2023 16:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703031959; x=1703636759; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=P8SdDvE7M57yXe3BWZ3ZcRgxoEXpwC009EWtj4naDlo=; b=jrLEakROWtxFBmVftDc2CjXqf45zvlK0KCawG+cOgc+pdrufluELINqqlzG7yL5nQw ZthEkKrHb2UOXVyL3Khh/773a9eSdy/dL4KJFXyhsofjXS2irjv3Fpboc2bg+UJKQJ82 rIAsYIEgUoWOPd2VgrhzL/XdN/Ct17u6gxa6VHnccpMzC7XkL27VnMsMNJYuB+vAdQRw 8JrLYbwkIK0pGeVwpAnTkVzEExUCbBV6mAWVnSBmKlBmgQFizcXlxfEoYcu+bpRWYgan QrUh+vo3mqfpISd5k2OaCWxSnCKBMEVeGo7euKfS9V5u9j5MV4/teha6/mP0zjRQnEm3 EHVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703031959; x=1703636759; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P8SdDvE7M57yXe3BWZ3ZcRgxoEXpwC009EWtj4naDlo=; b=SOnhzwaXhkbu66rg5X5cnfdMK8dzxGKDHigVqL/wDwpDe2GcNQjptVdrxu9tMBxFtt hVI9i5EIL688j1Ptk6LbixYSfaoitTk1CkPFpd/eiagN7OLE8NSmTzOBl08tlsqHzqz2 wcdFMFnwJhNo/0tHja2/45S3pLQ9hYX0TdLDWjZQd/Q+afJdi/BaP5c1YqKEzmAoXuE5 IVGUt+sQpbA8J8U+ABYUNwK6V5XZOoR5d0oWnUm91IBbmfdiG966p/kdKNxwhQ2o7elV wyz7HUSSsbQhQe3+P8BtAaXEoxolJKjd9sCXMA1YKN03lMytQgb0qoUefU9fXFufljtJ v0/Q== X-Gm-Message-State: AOJu0YzMwikWSRUQ3v6CQ7xsqCdC+/CPsgVnUepGJNn297pfTjewz+n4 2G02Z8sxAz/rZY/KKUxNCNdg4tuiVhv2kYb3Aio= X-Received: by 2002:adf:e9c6:0:b0:336:5fb5:b5b with SMTP id l6-20020adfe9c6000000b003365fb50b5bmr1843366wrn.109.1703031958902; Tue, 19 Dec 2023 16:25:58 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231215171020.687342-1-bigeasy@linutronix.de> <20231215171020.687342-16-bigeasy@linutronix.de> In-Reply-To: <20231215171020.687342-16-bigeasy@linutronix.de> From: Alexei Starovoitov Date: Tue, 19 Dec 2023 16:25:47 -0800 Message-ID: Subject: Re: [PATCH net-next 15/24] net: Use nested-BH locking for XDP redirect. To: Sebastian Andrzej Siewior Cc: LKML , Network Development , "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 , Alexei Starovoitov , Andrii Nakryiko , Cong Wang , Hao Luo , Jamal Hadi Salim , Jesper Dangaard Brouer , Jiri Olsa , Jiri Pirko , John Fastabend , KP Singh , Martin KaFai Lau , Ronak Doshi , Song Liu , Stanislav Fomichev , VMware PV-Drivers Reviewers , Yonghong Song , bpf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Dec 15, 2023 at 9:10=E2=80=AFAM Sebastian Andrzej Siewior wrote: > diff --git a/net/core/dev.c b/net/core/dev.c > index 5a0f6da7b3ae5..5ba7509e88752 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -3993,6 +3993,7 @@ sch_handle_ingress(struct sk_buff *skb, struct pack= et_type **pt_prev, int *ret, > *pt_prev =3D NULL; > } > > + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); > qdisc_skb_cb(skb)->pkt_len =3D skb->len; > tcx_set_ingress(skb, true); > > @@ -4045,6 +4046,7 @@ sch_handle_egress(struct sk_buff *skb, int *ret, st= ruct net_device *dev) > if (!entry) > return skb; > > + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); > /* qdisc_skb_cb(skb)->pkt_len & tcx_set_ingress() was > * already set by the caller. > */ > @@ -5008,6 +5010,7 @@ int do_xdp_generic(struct bpf_prog *xdp_prog, struc= t sk_buff *skb) > u32 act; > int err; > > + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); > act =3D netif_receive_generic_xdp(skb, &xdp, xdp_prog); > if (act !=3D XDP_PASS) { > switch (act) { > diff --git a/net/core/filter.c b/net/core/filter.c > index 7c9653734fb60..72a7812f933a1 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -4241,6 +4241,7 @@ static const struct bpf_func_proto bpf_xdp_adjust_m= eta_proto =3D { > */ > void xdp_do_flush(void) > { > + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); > __dev_flush(); > __cpu_map_flush(); > __xsk_map_flush(); > diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c > index a94943681e5aa..74b88e897a7e3 100644 > --- a/net/core/lwt_bpf.c > +++ b/net/core/lwt_bpf.c > @@ -44,6 +44,7 @@ static int run_lwt_bpf(struct sk_buff *skb, struct bpf_= lwt_prog *lwt, > * BPF prog and skb_do_redirect(). > */ > local_bh_disable(); > + local_lock_nested_bh(&bpf_run_lock.redirect_lock); > bpf_compute_data_pointers(skb); > ret =3D bpf_prog_run_save_cb(lwt->prog, skb); > > @@ -76,6 +77,7 @@ static int run_lwt_bpf(struct sk_buff *skb, struct bpf_= lwt_prog *lwt, > break; > } > > + local_unlock_nested_bh(&bpf_run_lock.redirect_lock); > local_bh_enable(); > > return ret; > diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c > index 1976bd1639863..da61b99bc558f 100644 > --- a/net/sched/cls_api.c > +++ b/net/sched/cls_api.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -3925,6 +3926,7 @@ struct sk_buff *tcf_qevent_handle(struct tcf_qevent= *qe, struct Qdisc *sch, stru > > fl =3D rcu_dereference_bh(qe->filter_chain); > > + guard(local_lock_nested_bh)(&bpf_run_lock.redirect_lock); > switch (tcf_classify(skb, NULL, fl, &cl_res, false)) { > case TC_ACT_SHOT: > qdisc_qstats_drop(sch); Here and in all other places this patch adds locks that will kill performance of XDP, tcx and everything else in networking. I'm surprised Jesper and other folks are not jumping in with nacks. We measure performance in nanoseconds here. Extra lock is no go. Please find a different way without ruining performance.