https://github.com/torvalds/linux
Revision 0c36b390a546055b6815d4b93a2c9fed4d980ffb authored by Sebastian Ott on 04 June 2014, 13:58:24 UTC, committed by Tejun Heo on 04 June 2014, 16:12:29 UTC
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>
Cc: <stable@vger.kernel.org> # v3.11+
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
1 parent 5a838c3
Raw File
Tip revision: 0c36b390a546055b6815d4b93a2c9fed4d980ffb authored by Sebastian Ott on 04 June 2014, 13:58:24 UTC
percpu-refcount: fix usage of this_cpu_ops
Tip revision: 0c36b39
bloat-o-meter
#!/usr/bin/python
#
# Copyright 2004 Matt Mackall <mpm@selenic.com>
#
# inspired by perl Bloat-O-Meter (c) 1997 by Andi Kleen
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

import sys, os, re

if len(sys.argv) != 3:
    sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0])
    sys.exit(-1)

def getsizes(file):
    sym = {}
    for l in os.popen("nm --size-sort " + file).readlines():
        size, type, name = l[:-1].split()
        if type in "tTdDbBrR":
            # strip generated symbols
            if name.startswith("__mod_"): continue
            if name == "linux_banner": continue
            # statics and some other optimizations adds random .NUMBER
            name = re.sub(r'\.[0-9]+', '', name)
            sym[name] = sym.get(name, 0) + int(size, 16)
    return sym

old = getsizes(sys.argv[1])
new = getsizes(sys.argv[2])
grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
delta, common = [], {}

for a in old:
    if a in new:
        common[a] = 1

for name in old:
    if name not in common:
        remove += 1
        down += old[name]
        delta.append((-old[name], name))

for name in new:
    if name not in common:
        add += 1
        up += new[name]
        delta.append((new[name], name))

for name in common:
        d = new.get(name, 0) - old.get(name, 0)
        if d>0: grow, up = grow+1, up+d
        if d<0: shrink, down = shrink+1, down-d
        delta.append((d, name))

delta.sort()
delta.reverse()

print "add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
      (add, remove, grow, shrink, up, -down, up-down)
print "%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")
for d, n in delta:
    if d: print "%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)
back to top