]>
Commit | Line | Data |
---|---|---|
7f87a3cd SL |
1 | From d126067245d71c1d4a831a86eedbc702a5c6480a Mon Sep 17 00:00:00 2001 |
2 | From: Sasha Levin <sashal@kernel.org> | |
3 | Date: Thu, 4 Apr 2024 09:57:40 +0200 | |
4 | Subject: u64_stats: fix u64_stats_init() for lockdep when used repeatedly in | |
5 | one file | |
6 | ||
7 | From: Petr Tesarik <petr@tesarici.cz> | |
8 | ||
9 | [ Upstream commit 38a15d0a50e0a43778561a5861403851f0b0194c ] | |
10 | ||
11 | Fix bogus lockdep warnings if multiple u64_stats_sync variables are | |
12 | initialized in the same file. | |
13 | ||
14 | With CONFIG_LOCKDEP, seqcount_init() is a macro which declares: | |
15 | ||
16 | static struct lock_class_key __key; | |
17 | ||
18 | Since u64_stats_init() is a function (albeit an inline one), all calls | |
19 | within the same file end up using the same instance, effectively treating | |
20 | them all as a single lock-class. | |
21 | ||
22 | Fixes: 9464ca650008 ("net: make u64_stats_init() a function") | |
23 | Closes: https://lore.kernel.org/netdev/ea1567d9-ce66-45e6-8168-ac40a47d1821@roeck-us.net/ | |
24 | Signed-off-by: Petr Tesarik <petr@tesarici.cz> | |
25 | Reviewed-by: Simon Horman <horms@kernel.org> | |
26 | Reviewed-by: Eric Dumazet <edumazet@google.com> | |
27 | Link: https://lore.kernel.org/r/20240404075740.30682-1-petr@tesarici.cz | |
28 | Signed-off-by: Jakub Kicinski <kuba@kernel.org> | |
29 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
30 | --- | |
31 | include/linux/u64_stats_sync.h | 9 +++++---- | |
32 | 1 file changed, 5 insertions(+), 4 deletions(-) | |
33 | ||
34 | diff --git a/include/linux/u64_stats_sync.h b/include/linux/u64_stats_sync.h | |
35 | index 51f2e16b9540b..11c3162dade3b 100644 | |
36 | --- a/include/linux/u64_stats_sync.h | |
37 | +++ b/include/linux/u64_stats_sync.h | |
38 | @@ -125,10 +125,11 @@ static inline void u64_stats_inc(u64_stats_t *p) | |
39 | p->v++; | |
40 | } | |
41 | ||
42 | -static inline void u64_stats_init(struct u64_stats_sync *syncp) | |
43 | -{ | |
44 | - seqcount_init(&syncp->seq); | |
45 | -} | |
46 | +#define u64_stats_init(syncp) \ | |
47 | + do { \ | |
48 | + struct u64_stats_sync *__s = (syncp); \ | |
49 | + seqcount_init(&__s->seq); \ | |
50 | + } while (0) | |
51 | ||
52 | static inline void __u64_stats_update_begin(struct u64_stats_sync *syncp) | |
53 | { | |
54 | -- | |
55 | 2.43.0 | |
56 |