Skip to content

Commit 7d720c3

Browse files
htejundavem330
authored andcommitted
percpu: add __percpu sparse annotations to net
Add __percpu sparse annotations to net. These annotations are to make sparse consider percpu variables to be in a different address space and warn if accessed without going through percpu accessors. This patch doesn't affect normal builds. The macro and type tricks around snmp stats make things a bit interesting. DEFINE/DECLARE_SNMP_STAT() macros mark the target field as __percpu and SNMP_UPD_PO_STATS() macro is updated accordingly. All snmp_mib_*() users which used to cast the argument to (void **) are updated to cast it to (void __percpu **). Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: David S. Miller <davem@davemloft.net> Cc: Patrick McHardy <kaber@trash.net> Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Cc: Vlad Yasevich <vladislav.yasevich@hp.com> Cc: netdev@vger.kernel.org Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2bb4646 commit 7d720c3

22 files changed

Lines changed: 127 additions & 114 deletions

File tree

‎include/net/ip.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ extern struct ipv4_config ipv4_config;
174174
#define NET_ADD_STATS_BH(net, field, adnd) SNMP_ADD_STATS_BH((net)->mib.net_statistics, field, adnd)
175175
#define NET_ADD_STATS_USER(net, field, adnd) SNMP_ADD_STATS_USER((net)->mib.net_statistics, field, adnd)
176176

177-
extern unsigned long snmp_fold_field(void *mib[], int offt);
178-
extern int snmp_mib_init(void *ptr[2], size_t mibsize);
179-
extern void snmp_mib_free(void *ptr[2]);
177+
extern unsigned long snmp_fold_field(void __percpu *mib[], int offt);
178+
extern int snmp_mib_init(void __percpu *ptr[2], size_t mibsize);
179+
extern void snmp_mib_free(void __percpu *ptr[2]);
180180

181181
extern struct local_ports {
182182
seqlock_t lock;

‎include/net/ipcomp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct crypto_comp;
99

1010
struct ipcomp_data {
1111
u16 threshold;
12-
struct crypto_comp **tfms;
12+
struct crypto_comp * __percpu *tfms;
1313
};
1414

1515
struct ip_comp_hdr;

‎include/net/neighbour.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct neigh_table {
164164
rwlock_t lock;
165165
unsigned long last_rand;
166166
struct kmem_cache *kmem_cachep;
167-
struct neigh_statistics *stats;
167+
struct neigh_statistics __percpu *stats;
168168
struct neighbour **hash_buckets;
169169
unsigned int hash_mask;
170170
__u32 hash_rnd;

‎include/net/netns/conntrack.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct netns_ct {
1717
struct hlist_head *expect_hash;
1818
struct hlist_nulls_head unconfirmed;
1919
struct hlist_nulls_head dying;
20-
struct ip_conntrack_stat *stat;
20+
struct ip_conntrack_stat __percpu *stat;
2121
int sysctl_events;
2222
unsigned int sysctl_events_retry_timeout;
2323
int sysctl_acct;

‎include/net/netns/core.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct netns_core {
1010

1111
int sysctl_somaxconn;
1212

13-
struct prot_inuse *inuse;
13+
struct prot_inuse __percpu *inuse;
1414
};
1515

1616
#endif

‎include/net/route.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct rt_cache_stat {
101101
unsigned int out_hlist_search;
102102
};
103103

104-
extern struct ip_rt_acct *ip_rt_acct;
104+
extern struct ip_rt_acct __percpu *ip_rt_acct;
105105

106106
struct in_device;
107107
extern int ip_rt_init(void);

‎include/net/snmp.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ struct linux_xfrm_mib {
129129
* nonlocked_atomic_inc() primitives -AK
130130
*/
131131
#define DEFINE_SNMP_STAT(type, name) \
132-
__typeof__(type) *name[2]
132+
__typeof__(type) __percpu *name[2]
133133
#define DECLARE_SNMP_STAT(type, name) \
134-
extern __typeof__(type) *name[2]
134+
extern __typeof__(type) __percpu *name[2]
135135

136136
#define SNMP_STAT_BHPTR(name) (name[0])
137137
#define SNMP_STAT_USRPTR(name) (name[1])
@@ -148,9 +148,13 @@ struct linux_xfrm_mib {
148148
__this_cpu_add(mib[0]->mibs[field], addend)
149149
#define SNMP_ADD_STATS_USER(mib, field, addend) \
150150
this_cpu_add(mib[1]->mibs[field], addend)
151+
/*
152+
* Use "__typeof__(*mib[0]) *ptr" instead of "__typeof__(mib[0]) ptr"
153+
* to make @ptr a non-percpu pointer.
154+
*/
151155
#define SNMP_UPD_PO_STATS(mib, basefield, addend) \
152156
do { \
153-
__typeof__(mib[0]) ptr; \
157+
__typeof__(*mib[0]) *ptr; \
154158
preempt_disable(); \
155159
ptr = this_cpu_ptr((mib)[!in_softirq()]); \
156160
ptr->mibs[basefield##PKTS]++; \
@@ -159,7 +163,7 @@ struct linux_xfrm_mib {
159163
} while (0)
160164
#define SNMP_UPD_PO_STATS_BH(mib, basefield, addend) \
161165
do { \
162-
__typeof__(mib[0]) ptr = \
166+
__typeof__(*mib[0]) *ptr = \
163167
__this_cpu_ptr((mib)[!in_softirq()]); \
164168
ptr->mibs[basefield##PKTS]++; \
165169
ptr->mibs[basefield##OCTETS] += addend;\

‎include/net/tcp.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ extern int tcp_v4_md5_do_del(struct sock *sk,
11891189
#define tcp_twsk_md5_key(twsk) NULL
11901190
#endif
11911191

1192-
extern struct tcp_md5sig_pool **tcp_alloc_md5sig_pool(struct sock *);
1192+
extern struct tcp_md5sig_pool * __percpu *tcp_alloc_md5sig_pool(struct sock *);
11931193
extern void tcp_free_md5sig_pool(void);
11941194

11951195
extern struct tcp_md5sig_pool *__tcp_get_md5sig_pool(int cpu);

‎net/8021q/vlan.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct vlan_dev_info {
6161
struct proc_dir_entry *dent;
6262
unsigned long cnt_inc_headroom_on_tx;
6363
unsigned long cnt_encap_on_xmit;
64-
struct vlan_rx_stats *vlan_rx_stats;
64+
struct vlan_rx_stats __percpu *vlan_rx_stats;
6565
};
6666

6767
static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev)

‎net/dccp/proto.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,12 +1005,13 @@ EXPORT_SYMBOL_GPL(dccp_shutdown);
10051005

10061006
static inline int dccp_mib_init(void)
10071007
{
1008-
return snmp_mib_init((void**)dccp_statistics, sizeof(struct dccp_mib));
1008+
return snmp_mib_init((void __percpu **)dccp_statistics,
1009+
sizeof(struct dccp_mib));
10091010
}
10101011

10111012
static inline void dccp_mib_exit(void)
10121013
{
1013-
snmp_mib_free((void**)dccp_statistics);
1014+
snmp_mib_free((void __percpu **)dccp_statistics);
10141015
}
10151016

10161017
static int thash_entries;

0 commit comments

Comments
 (0)