percpu-refcount: fix usage of this_cpu_ops
authorSebastian Ott <sebott@linux.vnet.ibm.com>
Wed, 4 Jun 2014 13:58:24 +0000 (15:58 +0200)
committerJiri Slaby <jslaby@suse.cz>
Fri, 20 Jun 2014 15:34:11 +0000 (17:34 +0200)
commiteed37ca3ef2da47c30cc0402f44e1992d4142983
tree7ac21daa3e718434e973af4625ea003e363e8a58
parent7db4c4d2e0e04ea112a1900aea2fa3a746ebe633
percpu-refcount: fix usage of this_cpu_ops

commit 0c36b390a546055b6815d4b93a2c9fed4d980ffb upstream.

The percpu-refcount infrastructure uses the underscore variants of
this_cpu_ops in order to modify percpu reference counters.
(e.g. __this_cpu_inc()).

However the underscore variants do not atomically update the percpu
variable, instead they may be implemented using read-modify-write
semantics (more than one instruction).  Therefore it is only safe to
use the underscore variant if the context is always the same (process,
softirq, or hardirq). Otherwise it is possible to lose updates.

This problem is something that Sebastian has seen within the aio
subsystem which uses percpu refcounters both in process and softirq
context leading to reference counts that never dropped to zeroes; even
though the number of "get" and "put" calls matched.

Fix this by using the non-underscore this_cpu_ops variant which
provides correct per cpu atomic semantics and fixes the corrupted
reference counts.

Cc: Kent Overstreet <kmo@daterainc.com>
Reported-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
References: http://lkml.kernel.org/g/alpine.LFD.2.11.1406041540520.21183@denkbrett
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
include/linux/percpu-refcount.h