Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp863219lqt; Fri, 7 Jun 2024 00:16:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWevDu0oA5HW4+0j6RdY7OkZI2yXoYHEEJ1xrw2wbOrBCxqjPCVjaCdb/Ooy54iL0L72b1zwIio6cMDcLG0lHEs7YcHB/s9NGZlkg+BaA== X-Google-Smtp-Source: AGHT+IGDERbbw0SuioNhKuj5VTyFUIltmgXpsGewh8kKHG4wIY57PdPzG4r89vwezhb8S9l5TF2w X-Received: by 2002:a05:6e02:20e9:b0:374:a262:8522 with SMTP id e9e14a558f8ab-3758030d54emr21879055ab.14.1717744587704; Fri, 07 Jun 2024 00:16:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717744587; cv=pass; d=google.com; s=arc-20160816; b=yvGNJbgRtmaqNA+qUsh4tGbAFb3mW81EsrjfSXeke7WdqgWzHI+4s2HP0ZwtKzclO4 MIGyEr8xIcIp16MtsQN/B8Wvue0Ksd9TrXGHoK92WqZQYWpG0GDNvjwiHhmp1R0qLf0h 4AEIzXlgYRGbInN1xZpO2bh/Om7TQPYx4LGQgpqu995mVQbj+W3ZGN+IRpX3dxtmg1wD ChzIDmaB+Dd7slCLoh+x+FvzKuZzQI2j6Zbjq0TPHevXO/AugO1rl5d5aBYnPermHuX0 lD6BEXMzMNQdCMUX3nlvDw+fjoAxBOHEeGOpFmnjnzYe6K9zeHdwuqRVZJ+wotq4hu/j EANw== 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=ANCKiEga5l1DBuytNTefl4llHnehnchG20Prvletyy0=; fh=jp8QVNcBwp91otoAEykvR7pBaCzyHhrLX6ezy3SsbVI=; b=tzHmPhLfQgBQnQk+j/t5COeyA1lGwp7B46UVV6N7GrGLmaMqBSQdCE2yIU45bE25Rv VUqu7hxccuohPuhBXgQ7AYPS3gLW/iLtX7nkFAV2XW4hIPtnpJrB+gO3MhfPzHkTF8Ph GxEZkQ58DjxFy8kLthbQB7cMpsHSYqe2zWvI2yN6R8o1k7n90OTeJUTIUUYETXhYWHiH Uv46P0JJ1s7buFg9PyxGL7nXL3EX4qhhxA9/sSPOsRK1woLDET6NwlafMElWuAKSKYYY cjsT6Tp+suCef7dyAAyi8b7DvTPfu0kvz5SYvBhvTiQ9bnIZGqNcciJHg0/IPlW3Hi6D 6lEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mrtkINOP; 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-205483-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205483-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de275fee53si2574880a12.496.2024.06.07.00.16.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 00:16:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205483-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mrtkINOP; 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-205483-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205483-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id E25EAB228B4 for ; Fri, 7 Jun 2024 07:07:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AC63157E69; Fri, 7 Jun 2024 07:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mrtkINOP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IDFVa7sI" 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 9363A15531A; Fri, 7 Jun 2024 07:04:36 +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=1717743879; cv=none; b=Xcj2NzPAY2hh1inbXq6R75B5E72T+QghQNJGkjCry6dqTU330KFk5u5LaTKNJw0pgC3/EpYDSorbHVFqY0VcATHjQKAX19KZAsFRPZkbI3iqgy6bIqOaMhE2lzoRyTK68L+VjUYRP/up+f+vhlt0nZxQ+/ePt1tj54TGDMKglD4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717743879; c=relaxed/simple; bh=oi4DoqovsixUFRVfCzGtZa5ipaDq/Cpe3T13qBLJFIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oOEc44qQXYHXpeP3nUQdfEw2L0nF3QsHRADgF/uIyBeTFev6XQCo2qThfUiok4Y7vz+8a9mvcUYvIy3IZZV7qpRhtaocS1AMQZYCrdyETIrmdPXVyYzmOcgtCfKnh6jhckmKKaz7x76LDxTJQ2yppldzxBqCzuNMkw08b2LsrY8= 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=mrtkINOP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=IDFVa7sI; 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=1717743873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ANCKiEga5l1DBuytNTefl4llHnehnchG20Prvletyy0=; b=mrtkINOPc9CF6xHUwSClCHrhMbtel3ZXqAJ89OpPJcma+4INrjqOGdP0MNRAG/KHwJ3TuN t1jarmJqSaoyDxswh35X6MJ41+CToLrstgBKbOYoDqEp+IqHjLKn2P7khVz4bgb0BEZ3hy LFlTMEsgbKQ2PfqUraSlsHh0ALHjoOGQ5YVpncJgquWsxkJvfitrNFhorfR4KhhB5EcsaM 3QQIpV1krpIDqW16d7/yrH99rd7WDwtewo58JGKGHTL87VBV/+4e96e6AzaOA4tveh/jvC XLyl1H8N/RCpSIxNc0W6BN+jnDnZ3YnxebeO2cUWzQQ9gn8zMsApNHg8QiFpow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1717743873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ANCKiEga5l1DBuytNTefl4llHnehnchG20Prvletyy0=; b=IDFVa7sIQzoY7lorlb4H3oIk5b/Tt6glMN6zlC0E8In8VuqnKrTf6MiQG3UHxwpZljjkfz j23AUKVXIEJtEXAg== 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 , Florian Westphal , Jozsef Kadlecsik , Nikolay Aleksandrov , Pablo Neira Ayuso , Roopa Prabhu , bridge@lists.linux.dev, coreteam@netfilter.org, netfilter-devel@vger.kernel.org Subject: [PATCH v5 net-next 07/15] netfilter: br_netfilter: Use nested-BH locking for brnf_frag_data_storage. Date: Fri, 7 Jun 2024 08:53:10 +0200 Message-ID: <20240607070427.1379327-8-bigeasy@linutronix.de> In-Reply-To: <20240607070427.1379327-1-bigeasy@linutronix.de> References: <20240607070427.1379327-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-Transfer-Encoding: quoted-printable brnf_frag_data_storage is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. Add a local_lock_t to the data structure and use local_lock_nested_bh() for locking. This change adds only lockdep coverage and does not alter the functional behaviour for !PREEMPT_RT. Cc: Florian Westphal Cc: Jozsef Kadlecsik Cc: Nikolay Aleksandrov Cc: Pablo Neira Ayuso Cc: Roopa Prabhu Cc: bridge@lists.linux.dev Cc: coreteam@netfilter.org Cc: netfilter-devel@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior --- net/bridge/br_netfilter_hooks.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hook= s.c index bf30c50b56895..3c9f6538990ea 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -137,6 +137,7 @@ static inline bool is_pppoe_ipv6(const struct sk_buff *= skb, #define NF_BRIDGE_MAX_MAC_HEADER_LENGTH (PPPOE_SES_HLEN + ETH_HLEN) =20 struct brnf_frag_data { + local_lock_t bh_lock; char mac[NF_BRIDGE_MAX_MAC_HEADER_LENGTH]; u8 encap_size; u8 size; @@ -144,7 +145,9 @@ struct brnf_frag_data { __be16 vlan_proto; }; =20 -static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage); +static DEFINE_PER_CPU(struct brnf_frag_data, brnf_frag_data_storage) =3D { + .bh_lock =3D INIT_LOCAL_LOCK(bh_lock), +}; =20 static void nf_bridge_info_free(struct sk_buff *skb) { @@ -850,6 +853,7 @@ static int br_nf_dev_queue_xmit(struct net *net, struct= sock *sk, struct sk_buff { struct nf_bridge_info *nf_bridge =3D nf_bridge_info_get(skb); unsigned int mtu, mtu_reserved; + int ret; =20 mtu_reserved =3D nf_bridge_mtu_reduction(skb); mtu =3D skb->dev->mtu; @@ -882,6 +886,7 @@ static int br_nf_dev_queue_xmit(struct net *net, struct= sock *sk, struct sk_buff =20 IPCB(skb)->frag_max_size =3D nf_bridge->frag_max_size; =20 + local_lock_nested_bh(&brnf_frag_data_storage.bh_lock); data =3D this_cpu_ptr(&brnf_frag_data_storage); =20 if (skb_vlan_tag_present(skb)) { @@ -897,7 +902,9 @@ static int br_nf_dev_queue_xmit(struct net *net, struct= sock *sk, struct sk_buff skb_copy_from_linear_data_offset(skb, -data->size, data->mac, data->size); =20 - return br_nf_ip_fragment(net, sk, skb, br_nf_push_frag_xmit); + ret =3D br_nf_ip_fragment(net, sk, skb, br_nf_push_frag_xmit); + local_unlock_nested_bh(&brnf_frag_data_storage.bh_lock); + return ret; } if (IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) && skb->protocol =3D=3D htons(ETH_P_IPV6)) { @@ -909,6 +916,7 @@ static int br_nf_dev_queue_xmit(struct net *net, struct= sock *sk, struct sk_buff =20 IP6CB(skb)->frag_max_size =3D nf_bridge->frag_max_size; =20 + local_lock_nested_bh(&brnf_frag_data_storage.bh_lock); data =3D this_cpu_ptr(&brnf_frag_data_storage); data->encap_size =3D nf_bridge_encap_header_len(skb); data->size =3D ETH_HLEN + data->encap_size; @@ -916,8 +924,12 @@ static int br_nf_dev_queue_xmit(struct net *net, struc= t sock *sk, struct sk_buff skb_copy_from_linear_data_offset(skb, -data->size, data->mac, data->size); =20 - if (v6ops) - return v6ops->fragment(net, sk, skb, br_nf_push_frag_xmit); + if (v6ops) { + ret =3D v6ops->fragment(net, sk, skb, br_nf_push_frag_xmit); + local_unlock_nested_bh(&brnf_frag_data_storage.bh_lock); + return ret; + } + local_unlock_nested_bh(&brnf_frag_data_storage.bh_lock); =20 kfree_skb(skb); return -EMSGSIZE; --=20 2.45.1