From patchwork Wed Oct 9 18:44:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13829069 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 A1CF11E103A for ; Wed, 9 Oct 2024 18:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499451; cv=none; b=MwcuFc2mwzkBg4v10Mb7qx9KM5RcHdel5je8YwmTDL/8UI74ptLnsIoFPLGm2lCV+L05TvbfE6zlfcszjC6/qEzTtRWUoCqIm6diWti6LUViUpM+M2T0mU1DY3YVjP/DQzuEjLAlb79Q7nRNRqnwvhR8dH6ekeUg5aOupFRvo5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499451; c=relaxed/simple; bh=gLCEgORTGRUsky+98+gFQ9kchFa7YB8clJ8cqWQAaLk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=INnMAgS0muVchIZlTAeXM9wSvQDKVWYUZkWQIjD4GNifsYkJ8ENrMbD2595IBT84XFWIY6OTUFf/y7ez6tJhkkaCOLdAZmO+akS79czxRzhk/1zo1364zC52ICGSEPDbKqpKl9JKJ2wxxQy2dX8zrulorbFzFKmHSyqagAFzF3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QI+zSaFN; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QI+zSaFN" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e260d4dfc8aso121044276.1 for ; Wed, 09 Oct 2024 11:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728499448; x=1729104248; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=P/xd83mEqJtYUr4NiiZTuMNfg7s56SH4cRk7v2KOyp0=; b=QI+zSaFNsMdXbwXUqog2A2+UVIQvQLVsjCaqhudlnaGeOIquCFOpxsOPk1AsojzvSY dPBnYg2KKQmSrD24J9Zv7UBybS7e/JcLHEYwXBgD6jyhPjAV/TelhCJDuMjtssNNAOIA YXPxNUPs7j/4HXI7/2ACDSayoFrzVjqcIaKufuZYxzMj2wN5dFPbrixotzBWnozSJx/r /2jwl8otfIf1iOHqy9FYkjJma5e94e0ft7sOedfXCEJSzPU2rWwOLWWYV8G5J4GAAN2h oXgtJCQCZ8AoZoDTkI9LmBpsEo+Vpqgh6Fae2sxX7pNqqivs+H7MMenu5Dm49THtBuhA lz/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728499448; x=1729104248; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P/xd83mEqJtYUr4NiiZTuMNfg7s56SH4cRk7v2KOyp0=; b=gzECgwTKui5cso/3nWeFWHsUL23Vcy3xZlRzWQjAmR2uTTgV61JGtcTZ1rzuQyJ0yJ lDSTrPQInUsuSGyZFtR6YxNAbhDekwl6/mmtTBurNzLRRDLoApM3i0knrpRclCcU6qs0 YnCNA/d5rF1J9WxMgCoSSkbgTpF3zoNXg33wVtDb/WMLYb5PmI186c5X7liEMGj9vfEm zOZTDM4QSVW1HPfYQIgW+20XPRi0ODBR72o+T1IW/nM9h+tRV+lNaSnePoJzPYJrAlly udnsHfjaIyfFHdCLFYFgQjuYpBHxuQqCyTuPI5u+udIeBWzH6UdZsFjd3CosL1YIb0Vg yBYg== X-Forwarded-Encrypted: i=1; AJvYcCXq9PjU5JagjwmFih23/UKzrRzlTm4WYR8fsbTZ1jocZlppNkZxVYRTZy0C7mBrQLVkBiuFVKk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxg5aagC0cJSI9ChCiQrAbarm8CHPpJ4BXnhXQpp0x26PkH06am XV24euDkDHhZ8LOQbZqKulAKC+8waLrY7Ue4jKAZPzcrM61VIjl+KJxUbP36MYm+Kny+Tsznt4U 0m2u3VGpStw== X-Google-Smtp-Source: AGHT+IGQlQPOTblhOWHgi3ytvLZos1m5QQ/cZzCoRRb4TUJRlviXUYATw3kRurG3mrKcepNIFT/zP/C6GLDFTg== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a05:6902:180a:b0:dfb:22ca:1efd with SMTP id 3f1490d57ef6-e28fe665ad2mr33761276.9.1728499448618; Wed, 09 Oct 2024 11:44:08 -0700 (PDT) Date: Wed, 9 Oct 2024 18:44:01 +0000 In-Reply-To: <20241009184405.3752829-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241009184405.3752829-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241009184405.3752829-2-edumazet@google.com> Subject: [PATCH net-next 1/5] fib: rules: use READ_ONCE()/WRITE_ONCE() on ops->fib_rules_seq From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Kuniyuki Iwashima , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Using RTNL to protect ops->fib_rules_seq reads seems a big hammer. Writes are protected by RTNL. We can use READ_ONCE() on readers. Constify 'struct net' argument of fib_rules_seq_read() and lookup_rules_ops(). Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/net/fib_rules.h | 2 +- net/core/fib_rules.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/net/fib_rules.h b/include/net/fib_rules.h index d17855c52ef926383f2585a6f31094899f1e7908..04383d90a1e38847d9d10f8fd0c4bf2ef67af713 100644 --- a/include/net/fib_rules.h +++ b/include/net/fib_rules.h @@ -176,7 +176,7 @@ int fib_default_rule_add(struct fib_rules_ops *, u32 pref, u32 table); bool fib_rule_matchall(const struct fib_rule *rule); int fib_rules_dump(struct net *net, struct notifier_block *nb, int family, struct netlink_ext_ack *extack); -unsigned int fib_rules_seq_read(struct net *net, int family); +unsigned int fib_rules_seq_read(const struct net *net, int family); int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack); diff --git a/net/core/fib_rules.c b/net/core/fib_rules.c index 154a2681f55cc6861d418927c396bec5d840578c..82ef090c0037817f15902d8784467f21419b5af7 100644 --- a/net/core/fib_rules.c +++ b/net/core/fib_rules.c @@ -101,7 +101,8 @@ static void notify_rule_change(int event, struct fib_rule *rule, struct fib_rules_ops *ops, struct nlmsghdr *nlh, u32 pid); -static struct fib_rules_ops *lookup_rules_ops(struct net *net, int family) +static struct fib_rules_ops *lookup_rules_ops(const struct net *net, + int family) { struct fib_rules_ops *ops; @@ -370,7 +371,9 @@ static int call_fib_rule_notifiers(struct net *net, .rule = rule, }; - ops->fib_rules_seq++; + ASSERT_RTNL(); + /* Paired with READ_ONCE() in fib_rules_seq() */ + WRITE_ONCE(ops->fib_rules_seq, ops->fib_rules_seq + 1); return call_fib_notifiers(net, event_type, &info.info); } @@ -397,17 +400,16 @@ int fib_rules_dump(struct net *net, struct notifier_block *nb, int family, } EXPORT_SYMBOL_GPL(fib_rules_dump); -unsigned int fib_rules_seq_read(struct net *net, int family) +unsigned int fib_rules_seq_read(const struct net *net, int family) { unsigned int fib_rules_seq; struct fib_rules_ops *ops; - ASSERT_RTNL(); - ops = lookup_rules_ops(net, family); if (!ops) return 0; - fib_rules_seq = ops->fib_rules_seq; + /* Paired with WRITE_ONCE() in call_fib_rule_notifiers() */ + fib_rules_seq = READ_ONCE(ops->fib_rules_seq); rules_ops_put(ops); return fib_rules_seq; From patchwork Wed Oct 9 18:44:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13829070 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 5151C1E1305 for ; Wed, 9 Oct 2024 18:44:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499452; cv=none; b=uD85D1+KW3ajoNukhI2eG8Ig9yPX+/MlyO2PzryxMK31bsxSZ3urRr+tyFErcIs8FNOM+bBsHbX1Bg9/NXH7ZnHtsNtgt7Y1jrfhMKx0Oo4jlxNfOhpw4WbDjUKWB2q/rRaaEfoI8P5UcNlQGDIHlbNrrZSvRAQMzYow7bFBuJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499452; c=relaxed/simple; bh=U8fsdmCWU5tm80pdUdUWzBotyCsl5fCry4pinonfIkQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ReJ7earsrEmeRPta0KHGZfvfdkHBjAKpKSD2GaeyDTlMlaiWLYkBgxX8ZhyDVLu4prwjdghRFKgGxo+Xwg+gZhgqp4um3qSSrUXr9D9eprO8DhxV5x3PVeskaSQFYndam2a2oZSXu7hK+QxovgfrU/SNSaWAwSPNpDFsjLUzLdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q29BYG/k; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q29BYG/k" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e25cae769abso102356276.0 for ; Wed, 09 Oct 2024 11:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728499450; x=1729104250; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MVHu6Oqjpe1Zjs4nXBUh0ng8MyB/abNtjZH5mQJ4Iao=; b=q29BYG/k2dB8QJrWF4Y51fVwCYudmpIbKNHe3spL29HJcpKppmCpXP/PaQ0ZlDj1o5 by4C9YcPP0xyI16BFdn7ZykTAr+iuFYFEsnZrmVaGfGrZB3e0vcf1eBBOBF7RzhUOCsJ 5x0vn94j08xxUJJvKuM48NzDrdt+Qg/NimeKuJen7dl4VVrV6GkjLmoLynoFC8dyExou 7ZgRR3XD+XsF+QRCdcoAfnqOBNb5xgEJgAMQCDBemODI8FHRnmPxBHYqsS1iY88gmGuv gASp1uYWvvHjF6IsEDlHFQSrm127n9WJo9U20urxTls3JG9w2AsL/sgTWOjTScGF+qxH lxeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728499450; x=1729104250; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MVHu6Oqjpe1Zjs4nXBUh0ng8MyB/abNtjZH5mQJ4Iao=; b=Vlg7KNA69fPjDsURJ5mZ766HozArfI2N+Y/Uq/S4qazWuyZpXcf2xKMSfkq94O2p7p wT0lwbPsnQBfb/YGUf+OsLvxkQionpXL2VXZj/7hxAdrmlSVPW5VLCLZ7m4vZrdeiSU9 yLWC1O6Znb2gBLc3jaAM+pVM500xwCaU08OMglnwIP2/YvvyHOxyKRYjlEF+npJC7AGq rWIyK9J7D6cg23odAl8whGihzS7iRBIe4gWUmBBb4us5N2I1v0YxessK7Lgaa+kct6GH 72qrekb3PjeMC9pVM7qlIMbL26K7cHGlTykIbRJAnxrqKkKob9224jTLSSCJvb9odgVK PFdQ== X-Forwarded-Encrypted: i=1; AJvYcCXThE+nDRqlT8DBUVyZQxUDm1zDjJ4QwtvN/83bvv17qVNx6sEeWG1dW2DoCs5yQyKTF0CxaOU=@vger.kernel.org X-Gm-Message-State: AOJu0YwE4D+6tF5wkIVgnpoPiz4Dam3hl9xllYj3nHO6YPAu2sne2SGF 9N524fKMgfeuaPusOEIAM/7AYPN8hClsY5TRcf/RfP56c/LKHAtBdgp/FWrS9d5tx5IZnzbUprD md7AUt4mHqA== X-Google-Smtp-Source: AGHT+IGbJTJMIVOUbd/sb+2rk4KTK7bMR4N9htGC+Tw71BP+sR6E2EoUjKpMRb3OG44T7oWdIgjD9Mw7VZqgvQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:6904:0:b0:e28:ee84:e4d8 with SMTP id 3f1490d57ef6-e28fe3559f3mr2209276.3.1728499450235; Wed, 09 Oct 2024 11:44:10 -0700 (PDT) Date: Wed, 9 Oct 2024 18:44:02 +0000 In-Reply-To: <20241009184405.3752829-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241009184405.3752829-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241009184405.3752829-3-edumazet@google.com> Subject: [PATCH net-next 2/5] ipv4: use READ_ONCE()/WRITE_ONCE() on net->ipv4.fib_seq From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Kuniyuki Iwashima , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Using RTNL to protect ops->fib_rules_seq reads seems a big hammer. Writes are protected by RTNL. We can use READ_ONCE() when reading it. Constify 'struct net' argument of fib4_rules_seq_read() Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/net/ip_fib.h | 4 ++-- include/net/netns/ipv4.h | 2 +- net/ipv4/fib_notifier.c | 8 ++++---- net/ipv4/fib_rules.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 967e4dc555face31a736f6108cea6b929478beba..4c2e2d1481ebff5292b9e433f56fa7289ba8e139 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -347,7 +347,7 @@ static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb, return 0; } -static inline unsigned int fib4_rules_seq_read(struct net *net) +static inline unsigned int fib4_rules_seq_read(const struct net *net) { return 0; } @@ -411,7 +411,7 @@ static inline bool fib4_has_custom_rules(const struct net *net) bool fib4_rule_default(const struct fib_rule *rule); int fib4_rules_dump(struct net *net, struct notifier_block *nb, struct netlink_ext_ack *extack); -unsigned int fib4_rules_seq_read(struct net *net); +unsigned int fib4_rules_seq_read(const struct net *net); static inline bool fib4_rules_early_flow_dissect(struct net *net, struct sk_buff *skb, diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index 276f622f3516871c438be27bafe61c039445b335..10c0a8dc37a23e793007ee47706b402fffbd08da 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -263,7 +263,7 @@ struct netns_ipv4 { #endif struct fib_notifier_ops *notifier_ops; - unsigned int fib_seq; /* protected by rtnl_mutex */ + unsigned int fib_seq; /* writes protected by rtnl_mutex */ struct fib_notifier_ops *ipmr_notifier_ops; unsigned int ipmr_seq; /* protected by rtnl_mutex */ diff --git a/net/ipv4/fib_notifier.c b/net/ipv4/fib_notifier.c index 0e23ade74493ce10a3f2572c39e091f132684884..21c85c80de641112d66a28645b1fb17c7071863f 100644 --- a/net/ipv4/fib_notifier.c +++ b/net/ipv4/fib_notifier.c @@ -22,15 +22,15 @@ int call_fib4_notifiers(struct net *net, enum fib_event_type event_type, ASSERT_RTNL(); info->family = AF_INET; - net->ipv4.fib_seq++; + /* Paired with READ_ONCE() in fib4_seq_read() */ + WRITE_ONCE(net->ipv4.fib_seq, net->ipv4.fib_seq + 1); return call_fib_notifiers(net, event_type, info); } static unsigned int fib4_seq_read(struct net *net) { - ASSERT_RTNL(); - - return net->ipv4.fib_seq + fib4_rules_seq_read(net); + /* Paired with WRITE_ONCE() in call_fib4_notifiers() */ + return READ_ONCE(net->ipv4.fib_seq) + fib4_rules_seq_read(net); } static int fib4_dump(struct net *net, struct notifier_block *nb, diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c index b07292d50ee76603f983c81a55d45abca89266e1..8325224ef07232d05b59c58011625daae847af30 100644 --- a/net/ipv4/fib_rules.c +++ b/net/ipv4/fib_rules.c @@ -74,7 +74,7 @@ int fib4_rules_dump(struct net *net, struct notifier_block *nb, return fib_rules_dump(net, nb, AF_INET, extack); } -unsigned int fib4_rules_seq_read(struct net *net) +unsigned int fib4_rules_seq_read(const struct net *net) { return fib_rules_seq_read(net, AF_INET); } From patchwork Wed Oct 9 18:44:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13829071 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 CE07D1E1331 for ; Wed, 9 Oct 2024 18:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499454; cv=none; b=cikbF4pOgE06KaNrUFyuTp+E5GORJBoO/ze8BUNSVEKKUNzkTf80d9T9K19nt/K1XY/k2we7XQhksSsqzdtV9B9bpjURdjZgYqzgzNYsmSBr0vF8rraXxcWr/gA1kq442/HOrXtzNJ2ID62gAtAoa1RBzG3W02+Qwy46z+NyQOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499454; c=relaxed/simple; bh=OQkr6ZAA/DrRW6NsX1hc847jsnbcVIb1yQI5A7ZG7QQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JgEql+s9cqBpxiDTshA4Co19C7mib8Io1n/pmb7rTldYpCjDy/Hhw4Bg6XOtvJFY13hichvKnOHJU+yWOfHeon8b6+Q65UiNc7lecpduggGT10Fn5Taf7diOjhGGtwiP9Soi+KzGO1z3sOSJIkUSlwMd+8V7akjBlbHnNisHrUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B5sm/8z9; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B5sm/8z9" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e28fdb4f35fso162703276.0 for ; Wed, 09 Oct 2024 11:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728499452; x=1729104252; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zNapo1VlcBbiHxg0tBKVZ2iSK7BFeqVQinD62G/1cF4=; b=B5sm/8z9CtFeumcQpV9jLHyjTwXX16aIICl4sPtmwZq+pBZeqsBFj7oOaYzZrFDpc9 jqJyYuz/eXM4vpiMTUaQQiHUpxKwYdKhyb93TLfmd5TlpO1edaUJ5lDIJJYHmR0+yxWu CUGtuTnVkzx7bhLGdRpoIGWP+MwV7BeY0W3/2zz5wNzG9cj/49ytdrm9ZHSciFQ5lsDg b30wdN+w1u8bDs3uv9A/l6srz1F2FivWm0Z5VpHyxLUnna8qFVkTu6iNiHqu+DXAGtm8 l0h8s0hhlWpJbLLE+AJI6zKi5z1pPqe8QbureNIhd2jExIhhIqp+/L99ad3fBUy2MSA2 K/NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728499452; x=1729104252; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zNapo1VlcBbiHxg0tBKVZ2iSK7BFeqVQinD62G/1cF4=; b=BtS0E+18PiOhmqwBo7pWWsuXiToYIMhlWe1Al8e8Mfcw6qHsg5trNISeg5gO8s7Bwu t+fUr8EGpPouhhjHyU5M1t++7yFAcA1eKLSPN5kSAH71D+Ii9M80RBxzFYjen3Ib7XI6 PBjj13x9WuvMJF7YKPt/sYAoX1xSBM5tIKAMR1nS5QsqzDFg1kfIH46ulkY6d7NI+VKk Q030GUrOr1n7S2+Wf7r9tBeHKeVpKyapHLydj/15pELxmav0QvD7Yk0QoAh9N5mbHuZR x7vhrTNwv9FZRYOslGb/VBYNGucvD9P99IUJpzb1eelPWjzQ2ijOvQzfPON9NSqT1Jap UXnw== X-Forwarded-Encrypted: i=1; AJvYcCXjcozuWMBOQQrZLJ7k1nt2A7lEfM2oMFRTBTHbnNn7XHTcXxKymgTSCX1FzhdLIht4wTxOCYI=@vger.kernel.org X-Gm-Message-State: AOJu0YzPfvfyAN6qXLZ4ekQ+qy7YT4J+6IKt9ZCVKW10k6PgLWOmIn2a K42aLASFD5fX3FzcHINZUI5Mu0wAkAB2IGpJIELmEkimhOGF47r8GVq1Ju5bCpiruSr6Ki7K/dB u/T2oMP20gw== X-Google-Smtp-Source: AGHT+IG0GJ8qpYbl6XIrr5LGu+3QQnPK+YNmW+W8q2+wSPL/BcSEslyavrCMfIzUauywEGNapLgpBUpRsFIg8A== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a25:8287:0:b0:e29:4a5:4555 with SMTP id 3f1490d57ef6-e2904a548b7mr1891276.11.1728499451785; Wed, 09 Oct 2024 11:44:11 -0700 (PDT) Date: Wed, 9 Oct 2024 18:44:03 +0000 In-Reply-To: <20241009184405.3752829-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241009184405.3752829-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241009184405.3752829-4-edumazet@google.com> Subject: [PATCH net-next 3/5] ipv6: use READ_ONCE()/WRITE_ONCE() on fib6_table->fib_seq From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Kuniyuki Iwashima , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org Using RTNL to protect ops->fib_rules_seq reads seems a big hammer. Writes are protected by RTNL. We can use READ_ONCE() when reading it. Constify 'struct net' argument of fib6_tables_seq_read() and fib6_rules_seq_read(). Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/net/ip6_fib.h | 8 ++++---- net/ipv6/fib6_rules.c | 2 +- net/ipv6/ip6_fib.c | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 6cb867ce4878423fbb9049e69445a6dbf8f31ba7..7c87873ae211c5fa80d34e8f3b8df0e813976390 100644 --- a/include/net/ip6_fib.h +++ b/include/net/ip6_fib.h @@ -394,7 +394,7 @@ struct fib6_table { struct fib6_node tb6_root; struct inet_peer_base tb6_peers; unsigned int flags; - unsigned int fib_seq; + unsigned int fib_seq; /* writes protected by rtnl_mutex */ struct hlist_head tb6_gc_hlist; /* GC candidates */ #define RT6_TABLE_HAS_DFLT_ROUTER BIT(0) }; @@ -563,7 +563,7 @@ int call_fib6_notifiers(struct net *net, enum fib_event_type event_type, int __net_init fib6_notifier_init(struct net *net); void __net_exit fib6_notifier_exit(struct net *net); -unsigned int fib6_tables_seq_read(struct net *net); +unsigned int fib6_tables_seq_read(const struct net *net); int fib6_tables_dump(struct net *net, struct notifier_block *nb, struct netlink_ext_ack *extack); @@ -632,7 +632,7 @@ void fib6_rules_cleanup(void); bool fib6_rule_default(const struct fib_rule *rule); int fib6_rules_dump(struct net *net, struct notifier_block *nb, struct netlink_ext_ack *extack); -unsigned int fib6_rules_seq_read(struct net *net); +unsigned int fib6_rules_seq_read(const struct net *net); static inline bool fib6_rules_early_flow_dissect(struct net *net, struct sk_buff *skb, @@ -676,7 +676,7 @@ static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb, { return 0; } -static inline unsigned int fib6_rules_seq_read(struct net *net) +static inline unsigned int fib6_rules_seq_read(const struct net *net) { return 0; } diff --git a/net/ipv6/fib6_rules.c b/net/ipv6/fib6_rules.c index 04a9ed5e8310f23cb7d947b732be5dd19916bf39..c85c1627cb16ed0bdfe4c6026bb0132cdd7be6b7 100644 --- a/net/ipv6/fib6_rules.c +++ b/net/ipv6/fib6_rules.c @@ -56,7 +56,7 @@ int fib6_rules_dump(struct net *net, struct notifier_block *nb, return fib_rules_dump(net, nb, AF_INET6, extack); } -unsigned int fib6_rules_seq_read(struct net *net) +unsigned int fib6_rules_seq_read(const struct net *net) { return fib_rules_seq_read(net, AF_INET6); } diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index eb111d20615c6274647eeb413d0b9475aaa3ae6c..cea160b249d2d75d03c867d2298da76eb0c7114e 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -345,17 +345,17 @@ static void __net_init fib6_tables_init(struct net *net) #endif -unsigned int fib6_tables_seq_read(struct net *net) +unsigned int fib6_tables_seq_read(const struct net *net) { unsigned int h, fib_seq = 0; rcu_read_lock(); for (h = 0; h < FIB6_TABLE_HASHSZ; h++) { - struct hlist_head *head = &net->ipv6.fib_table_hash[h]; - struct fib6_table *tb; + const struct hlist_head *head = &net->ipv6.fib_table_hash[h]; + const struct fib6_table *tb; hlist_for_each_entry_rcu(tb, head, tb6_hlist) - fib_seq += tb->fib_seq; + fib_seq += READ_ONCE(tb->fib_seq); } rcu_read_unlock(); @@ -400,7 +400,7 @@ int call_fib6_entry_notifiers(struct net *net, .rt = rt, }; - rt->fib6_table->fib_seq++; + WRITE_ONCE(rt->fib6_table->fib_seq, rt->fib6_table->fib_seq + 1); return call_fib6_notifiers(net, event_type, &info.info); } @@ -416,7 +416,7 @@ int call_fib6_multipath_entry_notifiers(struct net *net, .nsiblings = nsiblings, }; - rt->fib6_table->fib_seq++; + WRITE_ONCE(rt->fib6_table->fib_seq, rt->fib6_table->fib_seq + 1); return call_fib6_notifiers(net, event_type, &info.info); } @@ -427,7 +427,7 @@ int call_fib6_entry_notifiers_replace(struct net *net, struct fib6_info *rt) .nsiblings = rt->fib6_nsiblings, }; - rt->fib6_table->fib_seq++; + WRITE_ONCE(rt->fib6_table->fib_seq, rt->fib6_table->fib_seq + 1); return call_fib6_notifiers(net, FIB_EVENT_ENTRY_REPLACE, &info.info); } From patchwork Wed Oct 9 18:44:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13829072 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 5B6951E1A2D for ; Wed, 9 Oct 2024 18:44:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499456; cv=none; b=XqQuBhjgima85411iumCUpFx+vvtqMHMtpqUYufl7uiGbhIEc9pP5kgWmmHRH1bAUXKmonJmyQgGwqDsrUujJOAEr0MhUHX3nqMNYZEFRp28hkLwPmOyzzWQqMIIMwbpzGyz+M+zw8N/GUUyRRTdkXwcsko06Rnn8SJTIOK2K/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499456; c=relaxed/simple; bh=bo8W9ZMvqGAnB1UHLoQV6O/9djAa9UH6iqBalojdqOs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A3u3lkUdTuk1yxN4hiyWFSXmJjuXCsGPOcLMIMAvW5w8WiG26cLZKDBwsz7CPNGaaL8gvia2pyQG4aa5Qbkr2smKFdlbpmNEEZHb0kIj1p0ZxPr+wb9+MRoOl1LRnXlyeovUB9k+mDafCQaArvL1MItsY41zD1r4gqw1kYc0Yoc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2XTYx+MQ; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2XTYx+MQ" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e29097b84c8so96614276.3 for ; Wed, 09 Oct 2024 11:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728499453; x=1729104253; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/nCTJYL1opnVGlcwAvLc4p21H9gJQSXakHqmPoxdj28=; b=2XTYx+MQHWyU6YsDaxTnnrg3eCsjstNzTxSMiE7zHWDUl+oplLWOteuwvG1JZcd0PG VdctZa44Ej1NVUJ9gOm0h9jlZb8bfgZgLJK4quHAOUQSeQKL5/+WtDEssILmOMcw70RW C0R6VHX6U2BM3AwdhnOjBD0ZrfqI95d12LhiljQAlyea73lMHv7a8fZ7mlw+aG9o895m HMbZwf9mY3z2R1pe3N/Ef4mlw8Q22t9tOYlnuTvTUBQDV4m5rEiZXRVBXv9Mt4OSaC0C 8yTwpDNM72RsgEK/J8eIQH7i5biBMM/b5mer9rO94+nHIulAAdy23+yu1tUQEW6zrv1s YTCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728499453; x=1729104253; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/nCTJYL1opnVGlcwAvLc4p21H9gJQSXakHqmPoxdj28=; b=AEtyVjdhobFJfXAm9NeKXCiypYaaz6VMwZQrXgcgGk1ok8WGQiFKauXBo9RXr4W5Pv sKTrRoIHnI1n9CMmti1NqBfZu8IyXazXBpXnSPmBXEZIrTCQDOKwEEfZ99EkYHdSpxfk KN5hF72YWKtJXg8IVhsPzT7teyETbe4Y8xQLJ9Cp4mEEpCoAgdicmWgBjkExANDySxlO hRK5LVETUw0ftbNF0fhL9pH9pT9Vj4YQ6ZDB3OvoXVE8cHbR0lm+0EU9PPDSC7eRYgYQ C0rkaKyVhPXQ19ClKA5GeB/j+I7gtr5IAZGcdpnp4FGwEXw/dd5RfT0bshe/Xg6lSsn8 hirQ== X-Forwarded-Encrypted: i=1; AJvYcCVZQRwt4B5l1AfEaZ/RFJgZQvR8Ij3rGIdNSNIHF9GZPibrW79wGJKAehNM2C6hlKAdP+Y5V1M=@vger.kernel.org X-Gm-Message-State: AOJu0YwU+8sXi1clYVCwCj6kk1IN67vpadBQ553utf5sHJiAHQKTX0IG acJT4R4pIZp/Pxbd5nlZ0iJZ1QWOCxLT+fM1KSS3AFznAd1T8GKku9CIuzvdyw5DQu1lqc2lmfs 7kKdU2CVDAQ== X-Google-Smtp-Source: AGHT+IHh1/niW8ubY/DJdz3j0Y84jTjoQPR05iwjtZrNJi/Ke1qJiTAvtlrGq4O4xgjCjq+m6FOhAy3zZ3mY3Q== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a5b:b86:0:b0:e0e:8b26:484e with SMTP id 3f1490d57ef6-e28fe516b5amr2569276.8.1728499453383; Wed, 09 Oct 2024 11:44:13 -0700 (PDT) Date: Wed, 9 Oct 2024 18:44:04 +0000 In-Reply-To: <20241009184405.3752829-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241009184405.3752829-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241009184405.3752829-5-edumazet@google.com> Subject: [PATCH net-next 4/5] ipmr: use READ_ONCE() to read net->ipv[46].ipmr_seq From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Kuniyuki Iwashima , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org mr_call_vif_notifiers() and mr_call_mfc_notifiers() already uses WRITE_ONCE() on the write side. Using RTNL to protect the reads seems a big hammer. Constify 'struct net' argument of ip6mr_rules_seq_read() and ipmr_rules_seq_read(). Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- net/ipv4/ipmr.c | 8 +++----- net/ipv6/ip6mr.c | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 089864c6a35eec146a1ba90c22d79245f8e48158..35ed0316518424c7742a93bd72d56295e1eb01aa 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -288,7 +288,7 @@ static int ipmr_rules_dump(struct net *net, struct notifier_block *nb, return fib_rules_dump(net, nb, RTNL_FAMILY_IPMR, extack); } -static unsigned int ipmr_rules_seq_read(struct net *net) +static unsigned int ipmr_rules_seq_read(const struct net *net) { return fib_rules_seq_read(net, RTNL_FAMILY_IPMR); } @@ -346,7 +346,7 @@ static int ipmr_rules_dump(struct net *net, struct notifier_block *nb, return 0; } -static unsigned int ipmr_rules_seq_read(struct net *net) +static unsigned int ipmr_rules_seq_read(const struct net *net) { return 0; } @@ -3037,9 +3037,7 @@ static const struct net_protocol pim_protocol = { static unsigned int ipmr_seq_read(struct net *net) { - ASSERT_RTNL(); - - return net->ipv4.ipmr_seq + ipmr_rules_seq_read(net); + return READ_ONCE(net->ipv4.ipmr_seq) + ipmr_rules_seq_read(net); } static int ipmr_dump(struct net *net, struct notifier_block *nb, diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 2ce4ae0d8dc3b443986d7a7b4177a057f5affaec..3f9501fd8c1ae583d4862128e8620ce6cc114d25 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -276,7 +276,7 @@ static int ip6mr_rules_dump(struct net *net, struct notifier_block *nb, return fib_rules_dump(net, nb, RTNL_FAMILY_IP6MR, extack); } -static unsigned int ip6mr_rules_seq_read(struct net *net) +static unsigned int ip6mr_rules_seq_read(const struct net *net) { return fib_rules_seq_read(net, RTNL_FAMILY_IP6MR); } @@ -335,7 +335,7 @@ static int ip6mr_rules_dump(struct net *net, struct notifier_block *nb, return 0; } -static unsigned int ip6mr_rules_seq_read(struct net *net) +static unsigned int ip6mr_rules_seq_read(const struct net *net) { return 0; } @@ -1262,9 +1262,7 @@ static int ip6mr_device_event(struct notifier_block *this, static unsigned int ip6mr_seq_read(struct net *net) { - ASSERT_RTNL(); - - return net->ipv6.ipmr_seq + ip6mr_rules_seq_read(net); + return READ_ONCE(net->ipv6.ipmr_seq) + ip6mr_rules_seq_read(net); } static int ip6mr_dump(struct net *net, struct notifier_block *nb, From patchwork Wed Oct 9 18:44:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13829073 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 707FB1E0E18 for ; Wed, 9 Oct 2024 18:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499458; cv=none; b=uPphpR95Y6nQbVqnUFc4l2pudpd3bNNnnqV3h8K+pykARJlM68qu4FZxQIL/SDRSntCRq4X56UxL8grhuzfrNs6+2ykzw3JJkszb8XFobT7uJ3+kb/rksR5b7Ow4lvOBTrplbRPcFew43KMAG7LD7yrVgdjxulzm6QSi7Qc5I34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728499458; c=relaxed/simple; bh=S6KQDYotlv/ATtlpOZmLrFooIi+XWpoH/2pjEFVGuUQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Jrw1u7X8/5AwgmmGtTOcwZUsbfVNsT9phIxjfXB8wcjkL233RHdUYFW8hgGhi3aJZajesQtESafflKA1w2BcqpfztuFGtew+/DAvOKy4cGNlfp7bUOacNnlCZ30EooHzXKyYmaiMtehngMZTt7t/xLLoSSp5URH/c0d5DlamF04= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q5nkr7+z; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edumazet.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q5nkr7+z" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e2d1860a62so4780027b3.0 for ; Wed, 09 Oct 2024 11:44:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728499455; x=1729104255; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GT31xcYBxoqSWlcbZsNBzSpSFK9DG0BWwki4n1tBv5I=; b=q5nkr7+zWNiMtYARCg9yLgjJ1Nffpu0HxJggqqDwqGWqhg1ZG2f8T0HI/7UILeB9+g wdKpfcYM/VXORkWrbP4epOXZOBw/lQkrQspXvB0GMrTTNAUj1QGHOF52Z4PRE1uVkwRQ NYLabGIx57YPYv1jmeRoGIipaHZOiot8AoJgtMYydjlkba/jeX0kYk6cU937FNp56QEb nMEkab+Z12ZGDxyyFOpOX7QylHDAhuiIZGz1T6fr6qf/4IxmhBfEWhDBe8cXONIxUOTg so8UwS4I7++cIJ9FS9VHnYO45NbsGovv4ArCgIm4lkpc0a/Z8g1jEL63AIdl6DRh2vjQ b+6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728499455; x=1729104255; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GT31xcYBxoqSWlcbZsNBzSpSFK9DG0BWwki4n1tBv5I=; b=CQFO7ZAyY7fmiP4KTt9C75VC5ei2sE4AMdC+FZqXKPc8T/NPnLn6LRk5ei7AE6+u/V zS8kcg2ucH8Eq8B7qBkHB2Bw3WGLz8kpppe5u/E7RqyinOxVDd103WVoem77B1iarpmm Zeiz4nvJ4Jb2GASG/35B904TufxmE/wDFdnvXU2zSqPkd7BhCZsg/yxaul95FbOZhwPq 2IXT56UsOzd8IO/5qnxSF0vZQcURu/kN5BLDUFlOgVksO/Pu1IRALM7X7pS2avEC4GYW Wqa2ziSiyO0VA3QZ7T1HBZsSou7dtvvoNWeahf5JufD1o3AQz4FrAjMopZcoLhTPLK/D hmhA== X-Forwarded-Encrypted: i=1; AJvYcCVHmW2uPqCTsn1t9X3upK3gEgRJJbagrgmaKmd5JYzy4RRJHK3hdJMjQP4oc6BZmVcrRd/azxc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0jS9z1Li6im1qODggpj9nYCFfhsNEQVWAytaihjipNvOSWSBA 0KQ0Ebp4odCuZ/sbFRiRzw7R+xvoYRvKiHAi4aJ+yflTyO1Djcl1O4zJnaDkWBMdunLnM2KJdkM v8iingDdIIQ== X-Google-Smtp-Source: AGHT+IGmAPO9L91hhyb+ySFdqLMfcc40xMn1Qp7io31i9GjNFBtdAaE4e2kPhkcloV+yt9Qa1RYur3c8JO3BBQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:f7:ea0b:ac12:11d6]) (user=edumazet job=sendgmr) by 2002:a05:690c:7004:b0:6dd:bc07:2850 with SMTP id 00721157ae682-6e3224dd3bfmr801297b3.6.1728499455072; Wed, 09 Oct 2024 11:44:15 -0700 (PDT) Date: Wed, 9 Oct 2024 18:44:05 +0000 In-Reply-To: <20241009184405.3752829-1-edumazet@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241009184405.3752829-1-edumazet@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog Message-ID: <20241009184405.3752829-6-edumazet@google.com> Subject: [PATCH net-next 5/5] net: do not acquire rtnl in fib_seq_sum() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: David Ahern , Kuniyuki Iwashima , Jiri Pirko , netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet X-Patchwork-Delegate: kuba@kernel.org After we made sure no fib_seq_read() handlers needs RTNL anymore, we can remove RTNL from fib_seq_sum(). Note that after RTNL was dropped, fib_seq_sum() result was possibly outdated anyway. Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima --- include/net/fib_notifier.h | 2 +- net/core/fib_notifier.c | 2 -- net/ipv4/fib_notifier.c | 2 +- net/ipv4/ipmr.c | 2 +- net/ipv6/fib6_notifier.c | 2 +- net/ipv6/ip6mr.c | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/net/fib_notifier.h b/include/net/fib_notifier.h index 6d59221ff05ad605dea6bf0e5f3d6b9d24237537..48aad6128feab6452c91e11ec31f9f1f238032d8 100644 --- a/include/net/fib_notifier.h +++ b/include/net/fib_notifier.h @@ -28,7 +28,7 @@ enum fib_event_type { struct fib_notifier_ops { int family; struct list_head list; - unsigned int (*fib_seq_read)(struct net *net); + unsigned int (*fib_seq_read)(const struct net *net); int (*fib_dump)(struct net *net, struct notifier_block *nb, struct netlink_ext_ack *extack); struct module *owner; diff --git a/net/core/fib_notifier.c b/net/core/fib_notifier.c index fc96259807b62fd2b41c47f385d7db23a7e38186..5cdca49b1d7c1cc9097c6a9fe93fae701c54eaca 100644 --- a/net/core/fib_notifier.c +++ b/net/core/fib_notifier.c @@ -43,7 +43,6 @@ static unsigned int fib_seq_sum(struct net *net) struct fib_notifier_ops *ops; unsigned int fib_seq = 0; - rtnl_lock(); rcu_read_lock(); list_for_each_entry_rcu(ops, &fn_net->fib_notifier_ops, list) { if (!try_module_get(ops->owner)) @@ -52,7 +51,6 @@ static unsigned int fib_seq_sum(struct net *net) module_put(ops->owner); } rcu_read_unlock(); - rtnl_unlock(); return fib_seq; } diff --git a/net/ipv4/fib_notifier.c b/net/ipv4/fib_notifier.c index 21c85c80de641112d66a28645b1fb17c7071863f..b1551c26554b79b70a29c9fab7f5ba8d7c0049c5 100644 --- a/net/ipv4/fib_notifier.c +++ b/net/ipv4/fib_notifier.c @@ -27,7 +27,7 @@ int call_fib4_notifiers(struct net *net, enum fib_event_type event_type, return call_fib_notifiers(net, event_type, info); } -static unsigned int fib4_seq_read(struct net *net) +static unsigned int fib4_seq_read(const struct net *net) { /* Paired with WRITE_ONCE() in call_fib4_notifiers() */ return READ_ONCE(net->ipv4.fib_seq) + fib4_rules_seq_read(net); diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 35ed0316518424c7742a93bd72d56295e1eb01aa..7a95daeb1946ad2f9c6d00a75469e37f92dddf9c 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c @@ -3035,7 +3035,7 @@ static const struct net_protocol pim_protocol = { }; #endif -static unsigned int ipmr_seq_read(struct net *net) +static unsigned int ipmr_seq_read(const struct net *net) { return READ_ONCE(net->ipv4.ipmr_seq) + ipmr_rules_seq_read(net); } diff --git a/net/ipv6/fib6_notifier.c b/net/ipv6/fib6_notifier.c index f87ae33e1d01f4e8d55f2af435bd8eff72bd9ea6..949b72610df704b6afe455daf0d680dbe4504e87 100644 --- a/net/ipv6/fib6_notifier.c +++ b/net/ipv6/fib6_notifier.c @@ -22,7 +22,7 @@ int call_fib6_notifiers(struct net *net, enum fib_event_type event_type, return call_fib_notifiers(net, event_type, info); } -static unsigned int fib6_seq_read(struct net *net) +static unsigned int fib6_seq_read(const struct net *net) { return fib6_tables_seq_read(net) + fib6_rules_seq_read(net); } diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 3f9501fd8c1ae583d4862128e8620ce6cc114d25..9528e17665fdb0ce4be07c76703ba74f06386370 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -1260,7 +1260,7 @@ static int ip6mr_device_event(struct notifier_block *this, return NOTIFY_DONE; } -static unsigned int ip6mr_seq_read(struct net *net) +static unsigned int ip6mr_seq_read(const struct net *net) { return READ_ONCE(net->ipv6.ipmr_seq) + ip6mr_rules_seq_read(net); }