https://github.com/torvalds/linux
Revision f2cbd485282014132851bf37cb2ca624a456275d authored by Davide Caratti on 20 November 2018, 21:18:44 UTC, committed by David S. Miller on 20 November 2018, 22:59:58 UTC
after 'police' configuration parameters were converted to use RCU instead
of spinlock, the state variables used to compute the traffic rate (namely
'tcfp_toks', 'tcfp_ptoks' and 'tcfp_t_c') are erroneously read/updated in
the traffic path without any protection.

Use a dedicated spinlock to avoid race conditions on these variables, and
ensure proper cache-line alignment. In this way, 'police' is still faster
than what we observed when 'tcf_lock' was used in the traffic path _ i.e.
reverting commit 2d550dbad83c ("net/sched: act_police: don't use spinlock
in the data path"). Moreover, we preserve the throughput improvement that
was obtained after 'police' started using per-cpu counters, when 'avrate'
is used instead of 'rate'.

Changes since v1 (thanks to Eric Dumazet):
- call ktime_get_ns() before acquiring the lock in the traffic path
- use a dedicated spinlock instead of tcf_lock
- improve cache-line usage

Fixes: 2d550dbad83c ("net/sched: act_police: don't use spinlock in the data path")
Reported-and-suggested-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
1 parent b1d9823
History
Tip revision: f2cbd485282014132851bf37cb2ca624a456275d authored by Davide Caratti on 20 November 2018, 21:18:44 UTC
net/sched: act_police: fix race condition on state variables
Tip revision: f2cbd48
File Mode Size
bpf
cgroup
configs
debug
dma
events
gcov
irq
livepatch
locking
power
printk
rcu
sched
time
trace
.gitignore -rw-r--r-- 69 bytes
Kconfig.freezer -rw-r--r-- 52 bytes
Kconfig.hz -rw-r--r-- 1.6 KB
Kconfig.locks -rw-r--r-- 4.8 KB
Kconfig.preempt -rw-r--r-- 2.2 KB
Makefile -rw-r--r-- 4.2 KB
acct.c -rw-r--r-- 15.4 KB
async.c -rw-r--r-- 10.1 KB
audit.c -rw-r--r-- 62.4 KB
audit.h -rw-r--r-- 11.1 KB
audit_fsnotify.c -rw-r--r-- 6.1 KB
audit_tree.c -rw-r--r-- 23.9 KB
audit_watch.c -rw-r--r-- 14.8 KB
auditfilter.c -rw-r--r-- 34.2 KB
auditsc.c -rw-r--r-- 67.0 KB
backtracetest.c -rw-r--r-- 2.1 KB
bounds.c -rw-r--r-- 751 bytes
capability.c -rw-r--r-- 13.9 KB
compat.c -rw-r--r-- 11.9 KB
configs.c -rw-r--r-- 2.8 KB
context_tracking.c -rw-r--r-- 6.3 KB
cpu.c -rw-r--r-- 55.1 KB
cpu_pm.c -rw-r--r-- 6.0 KB
crash_core.c -rw-r--r-- 11.4 KB
crash_dump.c -rw-r--r-- 1.3 KB
cred.c -rw-r--r-- 21.5 KB
delayacct.c -rw-r--r-- 5.1 KB
dma.c -rw-r--r-- 3.3 KB
elfcore.c -rw-r--r-- 432 bytes
exec_domain.c -rw-r--r-- 1.1 KB
exit.c -rw-r--r-- 44.2 KB
extable.c -rw-r--r-- 4.8 KB
fail_function.c -rw-r--r-- 7.1 KB
fork.c -rw-r--r-- 63.0 KB
freezer.c -rw-r--r-- 4.5 KB
futex.c -rw-r--r-- 97.4 KB
futex_compat.c -rw-r--r-- 4.5 KB
groups.c -rw-r--r-- 4.9 KB
hung_task.c -rw-r--r-- 7.2 KB
iomem.c -rw-r--r-- 4.7 KB
irq_work.c -rw-r--r-- 4.4 KB
jump_label.c -rw-r--r-- 19.8 KB
kallsyms.c -rw-r--r-- 17.6 KB
kcmp.c -rw-r--r-- 5.7 KB
kcov.c -rw-r--r-- 11.0 KB
kexec.c -rw-r--r-- 7.8 KB
kexec_core.c -rw-r--r-- 31.1 KB
kexec_file.c -rw-r--r-- 30.6 KB
kexec_internal.h -rw-r--r-- 924 bytes
kmod.c -rw-r--r-- 5.0 KB
kprobes.c -rw-r--r-- 62.4 KB
ksysfs.c -rw-r--r-- 6.3 KB
kthread.c -rw-r--r-- 33.7 KB
latencytop.c -rw-r--r-- 7.9 KB
memremap.c -rw-r--r-- 9.2 KB
module-internal.h -rw-r--r-- 959 bytes
module.c -rw-r--r-- 112.3 KB
module_signing.c -rw-r--r-- 2.3 KB
notifier.c -rw-r--r-- 16.3 KB
nsproxy.c -rw-r--r-- 6.5 KB
padata.c -rw-r--r-- 27.1 KB
panic.c -rw-r--r-- 16.7 KB
params.c -rw-r--r-- 23.2 KB
pid.c -rw-r--r-- 11.2 KB
pid_namespace.c -rw-r--r-- 11.4 KB
profile.c -rw-r--r-- 14.8 KB
ptrace.c -rw-r--r-- 32.6 KB
range.c -rw-r--r-- 3.0 KB
reboot.c -rw-r--r-- 13.9 KB
relay.c -rw-r--r-- 32.1 KB
resource.c -rw-r--r-- 39.9 KB
rseq.c -rw-r--r-- 10.0 KB
seccomp.c -rw-r--r-- 34.3 KB
signal.c -rw-r--r-- 106.1 KB
smp.c -rw-r--r-- 21.6 KB
smpboot.c -rw-r--r-- 11.7 KB
smpboot.h -rw-r--r-- 640 bytes
softirq.c -rw-r--r-- 18.6 KB
stackleak.c -rw-r--r-- 3.8 KB
stacktrace.c -rw-r--r-- 1.8 KB
stop_machine.c -rw-r--r-- 17.8 KB
sys.c -rw-r--r-- 61.8 KB
sys_ni.c -rw-r--r-- 8.8 KB
sysctl.c -rw-r--r-- 75.4 KB
sysctl_binary.c -rw-r--r-- 50.2 KB
task_work.c -rw-r--r-- 3.1 KB
taskstats.c -rw-r--r-- 15.4 KB
test_kprobes.c -rw-r--r-- 6.4 KB
torture.c -rw-r--r-- 21.0 KB
tracepoint.c -rw-r--r-- 15.6 KB
tsacct.c -rw-r--r-- 5.1 KB
ucount.c -rw-r--r-- 5.7 KB
uid16.c -rw-r--r-- 5.1 KB
uid16.h -rw-r--r-- 442 bytes
umh.c -rw-r--r-- 18.4 KB
up.c -rw-r--r-- 2.3 KB
user-return-notifier.c -rw-r--r-- 1.3 KB
user.c -rw-r--r-- 5.6 KB
user_namespace.c -rw-r--r-- 33.4 KB
utsname.c -rw-r--r-- 4.0 KB
utsname_sysctl.c -rw-r--r-- 3.4 KB
watchdog.c -rw-r--r-- 21.1 KB
watchdog_hld.c -rw-r--r-- 7.7 KB
workqueue.c -rw-r--r-- 159.4 KB
workqueue_internal.h -rw-r--r-- 2.2 KB

back to top