提交 5f121b9a 编写于 作者: W Willem de Bruijn 提交者: David S. Miller

net-rps: fixes for rps flow limit

Caught by sparse:
- __rcu: missing annotation to sd->flow_limit
- __user: direct access in cpumask_scnprintf

Also
- add endline character when printing bitmap if room in buffer
- avoid bucket overflow by reducing FLOW_LIMIT_HISTORY

The last item warrants some explanation. The hashtable buckets are
subject to overflow if FLOW_LIMIT_HISTORY is larger than or equal
to bucket size, since all packets may end up in a single bucket. The
current (rather arbitrary) history value of 256 happens to match the
buffer size (u8).

As a result, with a single flow, the first 128 packets are accepted
(correct), the second 128 packets dropped (correct) and then the
history[] array has filled, so that each subsequent new packet
causes an increment in the bucket for new_flow plus a decrement
for old_flow: a steady state.

This is fine if packets are dropped, as the steady state goes away
as soon as a mix of traffic reappears. But, because the 256th packet
overflowed the bucket to 0: no packets are dropped.

Instead of explicitly adding an overflow check, this patch changes
FLOW_LIMIT_HISTORY to never be able to overflow a single bucket.
Reported-by: NFengguang Wu <fengguang.wu@intel.com>
(first item)
Signed-off-by: NWillem de Bruijn <willemb@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 85f16525
...@@ -1840,7 +1840,7 @@ static inline int unregister_gifconf(unsigned int family) ...@@ -1840,7 +1840,7 @@ static inline int unregister_gifconf(unsigned int family)
} }
#ifdef CONFIG_NET_FLOW_LIMIT #ifdef CONFIG_NET_FLOW_LIMIT
#define FLOW_LIMIT_HISTORY (1 << 8) /* must be ^2 */ #define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */
struct sd_flow_limit { struct sd_flow_limit {
u64 count; u64 count;
unsigned int num_buckets; unsigned int num_buckets;
...@@ -1883,7 +1883,7 @@ struct softnet_data { ...@@ -1883,7 +1883,7 @@ struct softnet_data {
struct napi_struct backlog; struct napi_struct backlog;
#ifdef CONFIG_NET_FLOW_LIMIT #ifdef CONFIG_NET_FLOW_LIMIT
struct sd_flow_limit *flow_limit; struct sd_flow_limit __rcu *flow_limit;
#endif #endif
}; };
......
...@@ -132,6 +132,8 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write, ...@@ -132,6 +132,8 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
write_unlock: write_unlock:
mutex_unlock(&flow_limit_update_mutex); mutex_unlock(&flow_limit_update_mutex);
} else { } else {
char kbuf[128];
if (*ppos || !*lenp) { if (*ppos || !*lenp) {
*lenp = 0; *lenp = 0;
goto done; goto done;
...@@ -146,9 +148,20 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write, ...@@ -146,9 +148,20 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
} }
rcu_read_unlock(); rcu_read_unlock();
len = cpumask_scnprintf(buffer, *lenp, mask); len = min(sizeof(kbuf) - 1, *lenp);
*lenp = len + 1; len = cpumask_scnprintf(kbuf, len, mask);
*ppos += len + 1; if (!len) {
*lenp = 0;
goto done;
}
if (len < *lenp)
kbuf[len++] = '\n';
if (copy_to_user(buffer, kbuf, len)) {
ret = -EFAULT;
goto done;
}
*lenp = len;
*ppos += len;
} }
done: done:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册