Skip to content

Commit 05b8f50

Browse files
committed
Merge branch 'rps-misc-changes'
Eric Dumazet says: ==================== rps: misc changes Minor changes in rps: skb_flow_limit() is probably unused these days, and data-races are quite theoretical. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 34a07c5 + 0a7de4a commit 05b8f50

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

include/net/rps.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ struct rps_dev_flow_table {
5757
* meaning we use 32-6=26 bits for the hash.
5858
*/
5959
struct rps_sock_flow_table {
60-
u32 mask;
60+
struct rcu_head rcu;
61+
u32 mask;
6162

62-
u32 ents[] ____cacheline_aligned_in_smp;
63+
u32 ents[] ____cacheline_aligned_in_smp;
6364
};
6465
#define RPS_SOCK_FLOW_TABLE_SIZE(_num) (offsetof(struct rps_sock_flow_table, ents[_num]))
6566

net/core/dev.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -4953,7 +4953,8 @@ static void rps_trigger_softirq(void *data)
49534953
struct softnet_data *sd = data;
49544954

49554955
____napi_schedule(sd, &sd->backlog);
4956-
sd->received_rps++;
4956+
/* Pairs with READ_ONCE() in softnet_seq_show() */
4957+
WRITE_ONCE(sd->received_rps, sd->received_rps + 1);
49574958
}
49584959

49594960
#endif /* CONFIG_RPS */
@@ -5038,7 +5039,7 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)
50385039
rcu_read_lock();
50395040
fl = rcu_dereference(sd->flow_limit);
50405041
if (fl) {
5041-
new_flow = skb_get_hash(skb) & (fl->num_buckets - 1);
5042+
new_flow = hash_32(skb_get_hash(skb), fl->log_buckets);
50425043
old_flow = fl->history[fl->history_head];
50435044
fl->history[fl->history_head] = new_flow;
50445045

@@ -5049,7 +5050,8 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)
50495050
fl->buckets[old_flow]--;
50505051

50515052
if (++fl->buckets[new_flow] > (FLOW_LIMIT_HISTORY >> 1)) {
5052-
fl->count++;
5053+
/* Pairs with READ_ONCE() in softnet_seq_show() */
5054+
WRITE_ONCE(fl->count, fl->count + 1);
50535055
rcu_read_unlock();
50545056
return true;
50555057
}
@@ -7522,7 +7524,8 @@ static __latent_entropy void net_rx_action(void)
75227524
*/
75237525
if (unlikely(budget <= 0 ||
75247526
time_after_eq(jiffies, time_limit))) {
7525-
sd->time_squeeze++;
7527+
/* Pairs with READ_ONCE() in softnet_seq_show() */
7528+
WRITE_ONCE(sd->time_squeeze, sd->time_squeeze + 1);
75267529
break;
75277530
}
75287531
}

net/core/dev.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ struct cpumask;
1515
/* Random bits of netdevice that don't need to be exposed */
1616
#define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */
1717
struct sd_flow_limit {
18-
u64 count;
19-
unsigned int num_buckets;
18+
struct rcu_head rcu;
19+
unsigned int count;
20+
u8 log_buckets;
2021
unsigned int history_head;
2122
u16 history[FLOW_LIMIT_HISTORY];
2223
u8 buckets[];

net/core/net-procfs.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
132132

133133
rcu_read_lock();
134134
fl = rcu_dereference(sd->flow_limit);
135+
/* Pairs with WRITE_ONCE() in skb_flow_limit() */
135136
if (fl)
136-
flow_limit_count = fl->count;
137+
flow_limit_count = READ_ONCE(fl->count);
137138
rcu_read_unlock();
138139
#endif
139140

@@ -144,11 +145,11 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
144145
seq_printf(seq,
145146
"%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x "
146147
"%08x %08x\n",
147-
sd->processed, atomic_read(&sd->dropped),
148-
sd->time_squeeze, 0,
148+
READ_ONCE(sd->processed), atomic_read(&sd->dropped),
149+
READ_ONCE(sd->time_squeeze), 0,
149150
0, 0, 0, 0, /* was fastroute */
150151
0, /* was cpu_collision */
151-
sd->received_rps, flow_limit_count,
152+
READ_ONCE(sd->received_rps), flow_limit_count,
152153
input_qlen + process_qlen, (int)seq->index,
153154
input_qlen, process_qlen);
154155
return 0;

net/core/sysctl_net_core.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int rps_sock_flow_sysctl(const struct ctl_table *table, int write,
201201
if (orig_sock_table) {
202202
static_branch_dec(&rps_needed);
203203
static_branch_dec(&rfs_needed);
204-
kvfree_rcu_mightsleep(orig_sock_table);
204+
kvfree_rcu(orig_sock_table, rcu);
205205
}
206206
}
207207
}
@@ -239,7 +239,7 @@ static int flow_limit_cpu_sysctl(const struct ctl_table *table, int write,
239239
lockdep_is_held(&flow_limit_update_mutex));
240240
if (cur && !cpumask_test_cpu(i, mask)) {
241241
RCU_INIT_POINTER(sd->flow_limit, NULL);
242-
kfree_rcu_mightsleep(cur);
242+
kfree_rcu(cur, rcu);
243243
} else if (!cur && cpumask_test_cpu(i, mask)) {
244244
cur = kzalloc_node(len, GFP_KERNEL,
245245
cpu_to_node(i));
@@ -248,7 +248,7 @@ static int flow_limit_cpu_sysctl(const struct ctl_table *table, int write,
248248
ret = -ENOMEM;
249249
goto write_unlock;
250250
}
251-
cur->num_buckets = netdev_flow_limit_table_len;
251+
cur->log_buckets = ilog2(netdev_flow_limit_table_len);
252252
rcu_assign_pointer(sd->flow_limit, cur);
253253
}
254254
}

0 commit comments

Comments
 (0)