Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp197809lqb; Tue, 4 Jun 2024 08:49:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV2TOtt7oxpC2TU/5pH3OwBVFWH4FZghWVGzMZ/6hM9AJLv/AUl8DJL/msEMi+u4lpMA34kyWe0V4N5gLVwT8G2gIeKvuRo5m4kh5ntiA== X-Google-Smtp-Source: AGHT+IGwyjOaAuSipwLbWkvhl3rXB8rNhOiLQR+RbtLM/qsHHz7l3XI8tog6yKDkeJd+NHt9WB+2 X-Received: by 2002:a17:907:7841:b0:a68:6851:68bc with SMTP id a640c23a62f3a-a699cc98c04mr4064166b.5.1717516153396; Tue, 04 Jun 2024 08:49:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717516153; cv=pass; d=google.com; s=arc-20160816; b=0a4V/qpM+QI/6MnYU1eqVbRjWLgbSyTEk5uHYkLxfzWZY8FITpz4EkxPWGdwhZDT21 XogjVHgx3CVrKTT+wqnI663yAaAayaspdv9diIFiurur3XRE0sXVUcbzuzJKpYYWQy2q GiKqNDoAh3z/8kPODuWKyYYI+JE8I1unhBsa6VDvJ/ehPgfcwQnRvURNmXV1egEI0rAl JYlwcKcDdLc6SUlaK805wY18NnrNFqMRvri5BhXN6I9NaBWjEyWLmrc6XwdP/caPBtFP wfcsL7cEidzA85DFfZ1l6NEQTjHG/roorNNyNu6rKxGX9z8uRcT4m9nuTMkCmXIm/7Do BGYw== ARC-Message-Signature: i=2; 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=yRYHHugXJFYRrTMLAzyPBKoi1eoncd3rA80pIvgdVDY=; fh=/dY0ufEjACyWGPJe5UZ/L54pv06Xxq4XaNe+8QZ4Up4=; b=NpTAUmZ1DcAbSavq4cas+Fb9EHQHsTLsiCTJjK2JJp+v08oOKl6UCRS2hwqd0CkhVd CmTZWYwZLzgphFBShiibDbR8Xf9W8UXF8uc9sNTrxmtq6tynVoblFJwQzVanL3nQuVmC CCBADvSZMuPmqTcRUm0YozL+S7rAzJSyYe1gV4KozdxMAna95JjFp2chhc81+jWJkYSY Ej0z/3riC1NUd8V7Xap0X8iTuePxe8qOnN89/EMWcRfdhQDwTZ9xrIS1MmaA9X/2WUg9 3hkHKrTwPt1iVacBpsiFYjYfa0HhldEtH0Of/I2EO4ajM/DqUL5w+6KOwqB34U+XN7EQ SLRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ed20Osur; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-200995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200995-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a68a53d386asi412854066b.825.2024.06.04.08.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 08:49:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ed20Osur; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-200995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200995-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 3B0471F2151E for ; Tue, 4 Jun 2024 15:49:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9CBBC14C5A0; Tue, 4 Jun 2024 15:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ed20Osur"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fI+MLaZ9" 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 03035149E00; Tue, 4 Jun 2024 15:44:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717515897; cv=none; b=ofdvh3aBiKcUpyL/hEeh59LMlNZj78FHqcs4NQFl2c8VE84apzrKo8KjGoN2BeyNQms3veqegJvi4UhnkRvUjebfiD5VzYyxhCGuc37tchveNUgHk2XdftzrB96Y4owC+BhD+6+Q12bctif5YqBrUenyb978UJG9bpupckY776U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717515897; c=relaxed/simple; bh=GtZ8NBiCe6kgn9Voce+rGLSVrNtYQWd7NmEC33DEzF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gZErQMdsCTECy54Pe5gVD5uZ27Y7bQTZjSQLTmy65Xe2ZcwpIvuWqyU4RSPpAKyGxMBP6HYjEBXmdvBVPP4wMM2Xq5r0DKENaCxXYm+kT+SIF1KRyEqUqzumhoU3NztJVQdXdngky2OxETviancT3bLGAp3H1Pp/wQ0krORANOI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ed20Osur; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fI+MLaZ9; arc=none smtp.client-ip=193.142.43.55 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=1717515893; 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=yRYHHugXJFYRrTMLAzyPBKoi1eoncd3rA80pIvgdVDY=; b=Ed20OsurpyNqNvNyymvBRQdgUhu++IYHcno3SlRfvp1uWVya0FRRwKpcHjRU4vhSvVJr/g VZsg8aj4LltCZ1b1IFP3K4tAXz6dRPOfsjdybHixtsvxkZvMgTS9A+2M4eJzTixRHVGbyl 9upN1H7V+XQ9K0Y9VVsGFekTMLMViAodlTb9BpNq8Kfux+NNLKTNhO172xsNhVJr+d3Lnx 67mCv250ZK8kCKCzmjnzHPIopwn0dy0JJHB8HRbWqZoU/zNwVNwBZlCN7MGyOj4vhxdOnZ 4gyphSq4ZWVsZgqOXKaXSN/nWgTs+DOsQBvgWHm0G11CJ2sXcpvTgQ02lG2AWg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717515893; 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=yRYHHugXJFYRrTMLAzyPBKoi1eoncd3rA80pIvgdVDY=; b=fI+MLaZ9Hhv5qDWuQaxxHAKvxhurfIlC20H+cXUnbtzpTSag5BYF/LG9Xw0k8c0SzzH4ul xivq4/yxHW9JA5Dg== To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Daniel Bristot de Oliveira , 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 , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Alexei Starovoitov , Andrii Nakryiko , Eduard Zingerman , Hao Luo , Jesper Dangaard Brouer , Jiri Olsa , John Fastabend , Jonathan Lemon , KP Singh , Maciej Fijalkowski , Magnus Karlsson , Martin KaFai Lau , Song Liu , Stanislav Fomichev , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Yonghong Song , bpf@vger.kernel.org Subject: [PATCH v4 net-next 14/14] net: Move per-CPU flush-lists to bpf_net_context on PREEMPT_RT. Date: Tue, 4 Jun 2024 17:24:21 +0200 Message-ID: <20240604154425.878636-15-bigeasy@linutronix.de> In-Reply-To: <20240604154425.878636-1-bigeasy@linutronix.de> References: <20240604154425.878636-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 flush lists, which are accessed from within the NAPI callback (xdp_do_flush() for instance), are per-CPU. There are subject to the same problem as struct bpf_redirect_info. Add the per-CPU lists cpu_map_flush_list, dev_map_flush_list and xskmap_map_flush_list to struct bpf_net_context. Add wrappers for the access. Cc: "Bj=C3=B6rn T=C3=B6pel" Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Eduard Zingerman Cc: Hao Luo Cc: Jesper Dangaard Brouer Cc: Jiri Olsa Cc: John Fastabend Cc: Jonathan Lemon Cc: KP Singh Cc: Maciej Fijalkowski Cc: Magnus Karlsson Cc: Martin KaFai Lau Cc: Song Liu Cc: Stanislav Fomichev Cc: Toke H=C3=B8iland-J=C3=B8rgensen Cc: Yonghong Song Cc: bpf@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- include/linux/filter.h | 32 ++++++++++++++++++++++++++++++++ kernel/bpf/cpumap.c | 19 +++---------------- kernel/bpf/devmap.c | 11 +++-------- net/xdp/xsk.c | 12 ++++-------- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/include/linux/filter.h b/include/linux/filter.h index ea69f776a09f2..d0867854c682e 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -746,6 +746,9 @@ struct bpf_redirect_info { =20 struct bpf_net_context { struct bpf_redirect_info ri; + struct list_head cpu_map_flush_list; + struct list_head dev_map_flush_list; + struct list_head xskmap_map_flush_list; }; =20 static inline struct bpf_net_context *bpf_net_ctx_set(struct bpf_net_conte= xt *bpf_net_ctx) @@ -755,6 +758,14 @@ static inline struct bpf_net_context *bpf_net_ctx_set(= struct bpf_net_context *bp if (tsk->bpf_net_context !=3D NULL) return NULL; memset(&bpf_net_ctx->ri, 0, sizeof(bpf_net_ctx->ri)); + + if (IS_ENABLED(CONFIG_BPF_SYSCALL)) { + INIT_LIST_HEAD(&bpf_net_ctx->cpu_map_flush_list); + INIT_LIST_HEAD(&bpf_net_ctx->dev_map_flush_list); + } + if (IS_ENABLED(CONFIG_XDP_SOCKETS)) + INIT_LIST_HEAD(&bpf_net_ctx->xskmap_map_flush_list); + tsk->bpf_net_context =3D bpf_net_ctx; return bpf_net_ctx; } @@ -777,6 +788,27 @@ static inline struct bpf_redirect_info *bpf_net_ctx_ge= t_ri(void) return &bpf_net_ctx->ri; } =20 +static inline struct list_head *bpf_net_ctx_get_cpu_map_flush_list(void) +{ + struct bpf_net_context *bpf_net_ctx =3D bpf_net_ctx_get(); + + return &bpf_net_ctx->cpu_map_flush_list; +} + +static inline struct list_head *bpf_net_ctx_get_dev_flush_list(void) +{ + struct bpf_net_context *bpf_net_ctx =3D bpf_net_ctx_get(); + + return &bpf_net_ctx->dev_map_flush_list; +} + +static inline struct list_head *bpf_net_ctx_get_xskmap_flush_list(void) +{ + struct bpf_net_context *bpf_net_ctx =3D bpf_net_ctx_get(); + + return &bpf_net_ctx->xskmap_map_flush_list; +} + DEFINE_FREE(bpf_net_ctx_clear, struct bpf_net_context *, bpf_net_ctx_clear= (_T)); =20 /* flags for bpf_redirect_info kern_flags */ diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index 66974bd027109..068e994ed781a 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -79,8 +79,6 @@ struct bpf_cpu_map { struct bpf_cpu_map_entry __rcu **cpu_map; }; =20 -static DEFINE_PER_CPU(struct list_head, cpu_map_flush_list); - static struct bpf_map *cpu_map_alloc(union bpf_attr *attr) { u32 value_size =3D attr->value_size; @@ -709,7 +707,7 @@ static void bq_flush_to_queue(struct xdp_bulk_queue *bq) */ static void bq_enqueue(struct bpf_cpu_map_entry *rcpu, struct xdp_frame *x= dpf) { - struct list_head *flush_list =3D this_cpu_ptr(&cpu_map_flush_list); + struct list_head *flush_list =3D bpf_net_ctx_get_cpu_map_flush_list(); struct xdp_bulk_queue *bq =3D this_cpu_ptr(rcpu->bulkq); =20 if (unlikely(bq->count =3D=3D CPU_MAP_BULK_SIZE)) @@ -761,7 +759,7 @@ int cpu_map_generic_redirect(struct bpf_cpu_map_entry *= rcpu, =20 void __cpu_map_flush(void) { - struct list_head *flush_list =3D this_cpu_ptr(&cpu_map_flush_list); + struct list_head *flush_list =3D bpf_net_ctx_get_cpu_map_flush_list(); struct xdp_bulk_queue *bq, *tmp; =20 list_for_each_entry_safe(bq, tmp, flush_list, flush_node) { @@ -775,20 +773,9 @@ void __cpu_map_flush(void) #ifdef CONFIG_DEBUG_NET bool cpu_map_check_flush(void) { - if (list_empty(this_cpu_ptr(&cpu_map_flush_list))) + if (list_empty(bpf_net_ctx_get_cpu_map_flush_list())) return false; __cpu_map_flush(); return true; } #endif - -static int __init cpu_map_init(void) -{ - int cpu; - - for_each_possible_cpu(cpu) - INIT_LIST_HEAD(&per_cpu(cpu_map_flush_list, cpu)); - return 0; -} - -subsys_initcall(cpu_map_init); diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c index 3d9d62c6525d4..c8267ed580840 100644 --- a/kernel/bpf/devmap.c +++ b/kernel/bpf/devmap.c @@ -83,7 +83,6 @@ struct bpf_dtab { u32 n_buckets; }; =20 -static DEFINE_PER_CPU(struct list_head, dev_flush_list); static DEFINE_SPINLOCK(dev_map_lock); static LIST_HEAD(dev_map_list); =20 @@ -415,7 +414,7 @@ static void bq_xmit_all(struct xdp_dev_bulk_queue *bq, = u32 flags) */ void __dev_flush(void) { - struct list_head *flush_list =3D this_cpu_ptr(&dev_flush_list); + struct list_head *flush_list =3D bpf_net_ctx_get_dev_flush_list(); struct xdp_dev_bulk_queue *bq, *tmp; =20 list_for_each_entry_safe(bq, tmp, flush_list, flush_node) { @@ -429,7 +428,7 @@ void __dev_flush(void) #ifdef CONFIG_DEBUG_NET bool dev_check_flush(void) { - if (list_empty(this_cpu_ptr(&dev_flush_list))) + if (list_empty(bpf_net_ctx_get_dev_flush_list())) return false; __dev_flush(); return true; @@ -460,7 +459,7 @@ static void *__dev_map_lookup_elem(struct bpf_map *map,= u32 key) static void bq_enqueue(struct net_device *dev, struct xdp_frame *xdpf, struct net_device *dev_rx, struct bpf_prog *xdp_prog) { - struct list_head *flush_list =3D this_cpu_ptr(&dev_flush_list); + struct list_head *flush_list =3D bpf_net_ctx_get_dev_flush_list(); struct xdp_dev_bulk_queue *bq =3D this_cpu_ptr(dev->xdp_bulkq); =20 if (unlikely(bq->count =3D=3D DEV_MAP_BULK_SIZE)) @@ -1163,15 +1162,11 @@ static struct notifier_block dev_map_notifier =3D { =20 static int __init dev_map_init(void) { - int cpu; - /* Assure tracepoint shadow struct _bpf_dtab_netdev is in sync */ BUILD_BUG_ON(offsetof(struct bpf_dtab_netdev, dev) !=3D offsetof(struct _bpf_dtab_netdev, dev)); register_netdevice_notifier(&dev_map_notifier); =20 - for_each_possible_cpu(cpu) - INIT_LIST_HEAD(&per_cpu(dev_flush_list, cpu)); return 0; } =20 diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 727aa20be4bde..8b0b557408fc2 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -35,8 +35,6 @@ #define TX_BATCH_SIZE 32 #define MAX_PER_SOCKET_BUDGET (TX_BATCH_SIZE) =20 -static DEFINE_PER_CPU(struct list_head, xskmap_flush_list); - void xsk_set_rx_need_wakeup(struct xsk_buff_pool *pool) { if (pool->cached_need_wakeup & XDP_WAKEUP_RX) @@ -375,7 +373,7 @@ static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff= *xdp) =20 int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp) { - struct list_head *flush_list =3D this_cpu_ptr(&xskmap_flush_list); + struct list_head *flush_list =3D bpf_net_ctx_get_xskmap_flush_list(); int err; =20 err =3D xsk_rcv(xs, xdp); @@ -390,7 +388,7 @@ int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_= buff *xdp) =20 void __xsk_map_flush(void) { - struct list_head *flush_list =3D this_cpu_ptr(&xskmap_flush_list); + struct list_head *flush_list =3D bpf_net_ctx_get_xskmap_flush_list(); struct xdp_sock *xs, *tmp; =20 list_for_each_entry_safe(xs, tmp, flush_list, flush_node) { @@ -402,7 +400,7 @@ void __xsk_map_flush(void) #ifdef CONFIG_DEBUG_NET bool xsk_map_check_flush(void) { - if (list_empty(this_cpu_ptr(&xskmap_flush_list))) + if (list_empty(bpf_net_ctx_get_xskmap_flush_list())) return false; __xsk_map_flush(); return true; @@ -1775,7 +1773,7 @@ static struct pernet_operations xsk_net_ops =3D { =20 static int __init xsk_init(void) { - int err, cpu; + int err; =20 err =3D proto_register(&xsk_proto, 0 /* no slab */); if (err) @@ -1793,8 +1791,6 @@ static int __init xsk_init(void) if (err) goto out_pernet; =20 - for_each_possible_cpu(cpu) - INIT_LIST_HEAD(&per_cpu(xskmap_flush_list, cpu)); return 0; =20 out_pernet: --=20 2.45.1