netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file
@ 2024-04-04  7:57 Petr Tesarik
  2024-04-05 19:51 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Petr Tesarik @ 2024-04-04  7:57 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, open list
  Cc: Linux regressions mailing list, open list,
	Linux regression tracking (Thorsten Leemhuis), Petr Tesarik

Fix bogus lockdep warnings if multiple u64_stats_sync variables are
initialized in the same file.

With CONFIG_LOCKDEP, seqcount_init() is a macro which declares:

	static struct lock_class_key __key;

Since u64_stats_init() is a function (albeit an inline one), all calls
within the same file end up using the same instance, effectively treating
them all as a single lock-class.

Fixes: 9464ca650008 ("net: make u64_stats_init() a function")
Closes: https://lore.kernel.org/netdev/ea1567d9-ce66-45e6-8168-ac40a47d1821@roeck-us.net/
Signed-off-by: Petr Tesarik <petr@tesarici.cz>
---
 include/linux/u64_stats_sync.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/linux/u64_stats_sync.h b/include/linux/u64_stats_sync.h
index ffe48e69b3f3..457879938fc1 100644
--- a/include/linux/u64_stats_sync.h
+++ b/include/linux/u64_stats_sync.h
@@ -135,10 +135,11 @@ static inline void u64_stats_inc(u64_stats_t *p)
 	p->v++;
 }
 
-static inline void u64_stats_init(struct u64_stats_sync *syncp)
-{
-	seqcount_init(&syncp->seq);
-}
+#define u64_stats_init(syncp)				\
+	do {						\
+		struct u64_stats_sync *__s = (syncp);	\
+		seqcount_init(&__s->seq);		\
+	} while (0)
 
 static inline void __u64_stats_update_begin(struct u64_stats_sync *syncp)
 {
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file
  2024-04-04  7:57 [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file Petr Tesarik
@ 2024-04-05 19:51 ` Simon Horman
  2024-04-06  8:12   ` Petr Tesařík
  2024-04-05 21:08 ` Eric Dumazet
  2024-04-06  6:10 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Simon Horman @ 2024-04-05 19:51 UTC (permalink / raw)
  To: Petr Tesarik
  Cc: David S. Miller, Eric Dumazet, open list,
	Linux regressions mailing list, open list,
	Linux regression tracking (Thorsten Leemhuis)

On Thu, Apr 04, 2024 at 09:57:40AM +0200, Petr Tesarik wrote:
> Fix bogus lockdep warnings if multiple u64_stats_sync variables are
> initialized in the same file.
> 
> With CONFIG_LOCKDEP, seqcount_init() is a macro which declares:
> 
> 	static struct lock_class_key __key;
> 
> Since u64_stats_init() is a function (albeit an inline one), all calls
> within the same file end up using the same instance, effectively treating
> them all as a single lock-class.
> 
> Fixes: 9464ca650008 ("net: make u64_stats_init() a function")
> Closes: https://lore.kernel.org/netdev/ea1567d9-ce66-45e6-8168-ac40a47d1821@roeck-us.net/
> Signed-off-by: Petr Tesarik <petr@tesarici.cz>

Reviewed-by: Simon Horman <horms@kernel.org>

Interesting bug. I'm wondering if you also looked over other users of
u64_stats_init() to see if any of them can result in unexpected aliasing of
lock keys too.

...

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file
  2024-04-04  7:57 [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file Petr Tesarik
  2024-04-05 19:51 ` Simon Horman
@ 2024-04-05 21:08 ` Eric Dumazet
  2024-04-06  7:44   ` Petr Tesařík
  2024-04-06  6:10 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2024-04-05 21:08 UTC (permalink / raw)
  To: Petr Tesarik
  Cc: David S. Miller, open list, Linux regressions mailing list,
	open list, Linux regression tracking (Thorsten Leemhuis)

On Thu, Apr 4, 2024 at 9:58 AM Petr Tesarik <petr@tesarici.cz> wrote:
>
> Fix bogus lockdep warnings if multiple u64_stats_sync variables are
> initialized in the same file.
>
> With CONFIG_LOCKDEP, seqcount_init() is a macro which declares:
>
>         static struct lock_class_key __key;
>
> Since u64_stats_init() is a function (albeit an inline one), all calls
> within the same file end up using the same instance, effectively treating
> them all as a single lock-class.
>
> Fixes: 9464ca650008 ("net: make u64_stats_init() a function")
> Closes: https://lore.kernel.org/netdev/ea1567d9-ce66-45e6-8168-ac40a47d1821@roeck-us.net/
> Signed-off-by: Petr Tesarik <petr@tesarici.cz>

I thought I gave a Reviewed-by: tag already...

Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file
  2024-04-04  7:57 [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file Petr Tesarik
  2024-04-05 19:51 ` Simon Horman
  2024-04-05 21:08 ` Eric Dumazet
@ 2024-04-06  6:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-06  6:10 UTC (permalink / raw)
  To: Petr Tesarik
  Cc: davem, edumazet, netdev, regressions, linux-kernel, regressions

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Thu,  4 Apr 2024 09:57:40 +0200 you wrote:
> Fix bogus lockdep warnings if multiple u64_stats_sync variables are
> initialized in the same file.
> 
> With CONFIG_LOCKDEP, seqcount_init() is a macro which declares:
> 
> 	static struct lock_class_key __key;
> 
> [...]

Here is the summary with links:
  - [net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file
    https://git.kernel.org/netdev/net/c/38a15d0a50e0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file
  2024-04-05 21:08 ` Eric Dumazet
@ 2024-04-06  7:44   ` Petr Tesařík
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Tesařík @ 2024-04-06  7:44 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S. Miller, open list, Linux regressions mailing list,
	open list, Linux regression tracking (Thorsten Leemhuis)

On Fri, 5 Apr 2024 23:08:58 +0200
Eric Dumazet <edumazet@google.com> wrote:

> On Thu, Apr 4, 2024 at 9:58 AM Petr Tesarik <petr@tesarici.cz> wrote:
> >
> > Fix bogus lockdep warnings if multiple u64_stats_sync variables are
> > initialized in the same file.
> >
> > With CONFIG_LOCKDEP, seqcount_init() is a macro which declares:
> >
> >         static struct lock_class_key __key;
> >
> > Since u64_stats_init() is a function (albeit an inline one), all calls
> > within the same file end up using the same instance, effectively treating
> > them all as a single lock-class.
> >
> > Fixes: 9464ca650008 ("net: make u64_stats_init() a function")
> > Closes: https://lore.kernel.org/netdev/ea1567d9-ce66-45e6-8168-ac40a47d1821@roeck-us.net/
> > Signed-off-by: Petr Tesarik <petr@tesarici.cz>  
> 
> I thought I gave a Reviewed-by: tag already...

You did, but at that time I didn't know which tree should be used to
merge the patch, so it appeared as a stranded patch on LKML. Once we
agreed it should go through net, I sent it again, but the resend didn't
have it.

Thanks for your assistance!

Petr T

> Reviewed-by: Eric Dumazet <edumazet@google.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file
  2024-04-05 19:51 ` Simon Horman
@ 2024-04-06  8:12   ` Petr Tesařík
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Tesařík @ 2024-04-06  8:12 UTC (permalink / raw)
  To: Simon Horman
  Cc: David S. Miller, Eric Dumazet, open list,
	Linux regressions mailing list, open list,
	Linux regression tracking (Thorsten Leemhuis)

On Fri, 5 Apr 2024 20:51:17 +0100
Simon Horman <horms@kernel.org> wrote:

> On Thu, Apr 04, 2024 at 09:57:40AM +0200, Petr Tesarik wrote:
> > Fix bogus lockdep warnings if multiple u64_stats_sync variables are
> > initialized in the same file.
> > 
> > With CONFIG_LOCKDEP, seqcount_init() is a macro which declares:
> > 
> > 	static struct lock_class_key __key;
> > 
> > Since u64_stats_init() is a function (albeit an inline one), all calls
> > within the same file end up using the same instance, effectively treating
> > them all as a single lock-class.
> > 
> > Fixes: 9464ca650008 ("net: make u64_stats_init() a function")
> > Closes: https://lore.kernel.org/netdev/ea1567d9-ce66-45e6-8168-ac40a47d1821@roeck-us.net/
> > Signed-off-by: Petr Tesarik <petr@tesarici.cz>  
> 
> Reviewed-by: Simon Horman <horms@kernel.org>
> 
> Interesting bug. I'm wondering if you also looked over other users of
> u64_stats_init() to see if any of them can result in unexpected aliasing of
> lock keys too.

I didn't.

I have now run `git grep u64_stats_init | sed -e 's/:.*//' | uniq -d`
and there indeed appears to be some aliasing in other files.

block/blk-cgroup.c:
- struct blkg_iostat_set.sync
- struct blkg_iostat_set.sync

drivers/net/ethernet/amazon/ena/ena_netdev.c:
- struct ena_ring.syncp
  struct ena_adapter.syncp

drivers/net/ethernet/aquantia/atlantic/aq_ring.c:
- struct aq_ring_stats_tx_s.syncp
- struct aq_ring_stats_rx_s.syncp

drivers/net/ethernet/emulex/benet/be_main.c:
- struct be_tx_stats.sync
  + aliasing between this struct in
    - struct be_tx_obj
    - struct be_rx_obj
- struct be_tx_stats.sync_compl

drivers/net/ethernet/google/gve/gve_main.c:
- struct gve_priv.rx[].statss
- struct gve_priv.tx[].statss

drivers/net/ethernet/intel/fm10k/fm10k_netdev.c:
- tx_ring->syncp
- rx_ring->syncp

drivers/net/ethernet/intel/i40e/i40e_txrx.c:
- tx_ring->syncp
- rx_ring->syncp

drivers/net/ethernet/intel/igb/igb_main.c:
- struct igb_ring.tx_syncp
- struct igb_ring.tx_syncp2
- struct igb_ring.rx_syncp

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c:
- struct ixgbe_adapter.rx_ring[]->syncp
- struct ixgbe_adapter.tx_ring[]->syncp
- struct ixgbe_adapter.xdp_ring[]->syncp

drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c:
- tx_ring->syncp
- rx_ring->syncp

drivers/net/ethernet/marvell/sky2.c:
- struct sky2_port.tx_stats.syncp
- struct sky2_port.rx_stats.syncp

drivers/net/ethernet/microsoft/mana/mana_en.c:
- struct mana_txq.stats.syncp
- struct mana_rxq.stats.syncp

drivers/net/ethernet/netronome/nfp/nfp_net_dp.c:
- struct nfp_net_tx_ring.r_vec->tx_sync
- struct nfp_net_rx_ring.r_vec->rx_sync

drivers/net/ethernet/nvidia/forcedeth.c:
- struct fe_priv.swstats_tx_syncp
- struct fe_priv.swstats_rx_syncp

drivers/net/ethernet/realtek/8139too.c:
- struct rtl8139_private.tx_stats.syncp
- struct rtl8139_private.rx_stats.syncp

drivers/net/ethernet/socionext/sni_ave.c:
- struct ave_private.stats_tx.syncp
- struct ave_private.stats_rx.syncp

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:
- this was the trigger ;-)

drivers/net/ethernet/ti/netcp_core.c:
- struct netcp_stats.syncp_tx
- struct netcp_stats.syncp_rx

drivers/net/ethernet/via/via-rhine.c:
- struct rhine_private.tx_stats.syncp
- struct rhine_private.rx_stats.syncp

drivers/net/ethernet/xilinx/xilinx_axienet_main.c:
- struct axienet_local.tx_stat_sync
- struct axienet_local.rx_stat_sync

drivers/net/hyperv/netvsc.c:
- struct netvsc_channel.tx_stats.syncp
- struct netvsc_channel.rx_stats.syncp

drivers/net/ifb.c:
- struct ifb_q_private.tx_stats.sync
- struct ifb_q_private.rx_stats.sync

drivers/net/mhi_net.c:
- struct mhi_net_stats.tx_syncp
- struct mhi_net_stats.rx_syncp

drivers/net/virtio_net.c:
- struct virtnet_info.rq[].stats.syncp
- struct virtnet_info.sq[].stats.syncp

drivers/net/wwan/mhi_wwan_mbim.c:
- struct mhi_mbim_link.tx_syncp
- struct mhi_mbim_link.rx_syncp

drivers/vdpa/vdpa_sim/vdpa_sim_net.c:
- struct vdpasim_net.tx_stats.syncp
- struct vdpasim_net.rx_stats.syncp
- struct vdpasim_net.cq_stats.syncp

HTH
Petr T

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-06  8:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-04  7:57 [PATCH net] u64_stats: fix u64_stats_init() for lockdep when used repeatedly in one file Petr Tesarik
2024-04-05 19:51 ` Simon Horman
2024-04-06  8:12   ` Petr Tesařík
2024-04-05 21:08 ` Eric Dumazet
2024-04-06  7:44   ` Petr Tesařík
2024-04-06  6:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).