Commit 51a9f5ae authored by Vlad Buslov's avatar Vlad Buslov Committed by David S. Miller

net: core: protect rate estimator statistics pointer with lock

Extend gen_new_estimator() to also take stats_lock when re-assigning rate
estimator statistics pointer. (to be used by unlocked actions)

Rename 'stats_lock' to 'lock' and change argument description to explain
that it is now also used for control path.
Signed-off-by: default avatarVlad Buslov <vladbu@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4e232818
...@@ -59,13 +59,13 @@ int gnet_stats_finish_copy(struct gnet_dump *d); ...@@ -59,13 +59,13 @@ int gnet_stats_finish_copy(struct gnet_dump *d);
int gen_new_estimator(struct gnet_stats_basic_packed *bstats, int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu_bstats, struct gnet_stats_basic_cpu __percpu *cpu_bstats,
struct net_rate_estimator __rcu **rate_est, struct net_rate_estimator __rcu **rate_est,
spinlock_t *stats_lock, spinlock_t *lock,
seqcount_t *running, struct nlattr *opt); seqcount_t *running, struct nlattr *opt);
void gen_kill_estimator(struct net_rate_estimator __rcu **ptr); void gen_kill_estimator(struct net_rate_estimator __rcu **ptr);
int gen_replace_estimator(struct gnet_stats_basic_packed *bstats, int gen_replace_estimator(struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu_bstats, struct gnet_stats_basic_cpu __percpu *cpu_bstats,
struct net_rate_estimator __rcu **ptr, struct net_rate_estimator __rcu **ptr,
spinlock_t *stats_lock, spinlock_t *lock,
seqcount_t *running, struct nlattr *opt); seqcount_t *running, struct nlattr *opt);
bool gen_estimator_active(struct net_rate_estimator __rcu **ptr); bool gen_estimator_active(struct net_rate_estimator __rcu **ptr);
bool gen_estimator_read(struct net_rate_estimator __rcu **ptr, bool gen_estimator_read(struct net_rate_estimator __rcu **ptr,
......
...@@ -112,7 +112,7 @@ static void est_timer(struct timer_list *t) ...@@ -112,7 +112,7 @@ static void est_timer(struct timer_list *t)
* @bstats: basic statistics * @bstats: basic statistics
* @cpu_bstats: bstats per cpu * @cpu_bstats: bstats per cpu
* @rate_est: rate estimator statistics * @rate_est: rate estimator statistics
* @stats_lock: statistics lock * @lock: lock for statistics and control path
* @running: qdisc running seqcount * @running: qdisc running seqcount
* @opt: rate estimator configuration TLV * @opt: rate estimator configuration TLV
* *
...@@ -128,7 +128,7 @@ static void est_timer(struct timer_list *t) ...@@ -128,7 +128,7 @@ static void est_timer(struct timer_list *t)
int gen_new_estimator(struct gnet_stats_basic_packed *bstats, int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu_bstats, struct gnet_stats_basic_cpu __percpu *cpu_bstats,
struct net_rate_estimator __rcu **rate_est, struct net_rate_estimator __rcu **rate_est,
spinlock_t *stats_lock, spinlock_t *lock,
seqcount_t *running, seqcount_t *running,
struct nlattr *opt) struct nlattr *opt)
{ {
...@@ -154,19 +154,22 @@ int gen_new_estimator(struct gnet_stats_basic_packed *bstats, ...@@ -154,19 +154,22 @@ int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
seqcount_init(&est->seq); seqcount_init(&est->seq);
intvl_log = parm->interval + 2; intvl_log = parm->interval + 2;
est->bstats = bstats; est->bstats = bstats;
est->stats_lock = stats_lock; est->stats_lock = lock;
est->running = running; est->running = running;
est->ewma_log = parm->ewma_log; est->ewma_log = parm->ewma_log;
est->intvl_log = intvl_log; est->intvl_log = intvl_log;
est->cpu_bstats = cpu_bstats; est->cpu_bstats = cpu_bstats;
if (stats_lock) if (lock)
local_bh_disable(); local_bh_disable();
est_fetch_counters(est, &b); est_fetch_counters(est, &b);
if (stats_lock) if (lock)
local_bh_enable(); local_bh_enable();
est->last_bytes = b.bytes; est->last_bytes = b.bytes;
est->last_packets = b.packets; est->last_packets = b.packets;
if (lock)
spin_lock_bh(lock);
old = rcu_dereference_protected(*rate_est, 1); old = rcu_dereference_protected(*rate_est, 1);
if (old) { if (old) {
del_timer_sync(&old->timer); del_timer_sync(&old->timer);
...@@ -179,6 +182,8 @@ int gen_new_estimator(struct gnet_stats_basic_packed *bstats, ...@@ -179,6 +182,8 @@ int gen_new_estimator(struct gnet_stats_basic_packed *bstats,
mod_timer(&est->timer, est->next_jiffies); mod_timer(&est->timer, est->next_jiffies);
rcu_assign_pointer(*rate_est, est); rcu_assign_pointer(*rate_est, est);
if (lock)
spin_unlock_bh(lock);
if (old) if (old)
kfree_rcu(old, rcu); kfree_rcu(old, rcu);
return 0; return 0;
...@@ -209,7 +214,7 @@ EXPORT_SYMBOL(gen_kill_estimator); ...@@ -209,7 +214,7 @@ EXPORT_SYMBOL(gen_kill_estimator);
* @bstats: basic statistics * @bstats: basic statistics
* @cpu_bstats: bstats per cpu * @cpu_bstats: bstats per cpu
* @rate_est: rate estimator statistics * @rate_est: rate estimator statistics
* @stats_lock: statistics lock * @lock: lock for statistics and control path
* @running: qdisc running seqcount (might be NULL) * @running: qdisc running seqcount (might be NULL)
* @opt: rate estimator configuration TLV * @opt: rate estimator configuration TLV
* *
...@@ -221,11 +226,11 @@ EXPORT_SYMBOL(gen_kill_estimator); ...@@ -221,11 +226,11 @@ EXPORT_SYMBOL(gen_kill_estimator);
int gen_replace_estimator(struct gnet_stats_basic_packed *bstats, int gen_replace_estimator(struct gnet_stats_basic_packed *bstats,
struct gnet_stats_basic_cpu __percpu *cpu_bstats, struct gnet_stats_basic_cpu __percpu *cpu_bstats,
struct net_rate_estimator __rcu **rate_est, struct net_rate_estimator __rcu **rate_est,
spinlock_t *stats_lock, spinlock_t *lock,
seqcount_t *running, struct nlattr *opt) seqcount_t *running, struct nlattr *opt)
{ {
return gen_new_estimator(bstats, cpu_bstats, rate_est, return gen_new_estimator(bstats, cpu_bstats, rate_est,
stats_lock, running, opt); lock, running, opt);
} }
EXPORT_SYMBOL(gen_replace_estimator); EXPORT_SYMBOL(gen_replace_estimator);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment