Commit 5995e4b0 authored by linke li's avatar linke li Committed by Liu Shixin
Browse files

mm/slub: mark racy accesses on slab->slabs

mainline inclusion
from mainline-v6.10-rc1
commit 87654cf7a9865c0be256d67229b7354125d7498e
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IAHY3K

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=87654cf7a9865c0be256d67229b7354125d7498e



--------------------------------

The reads of slab->slabs are racy because it may be changed by
put_cpu_partial concurrently. In slabs_cpu_partial_show() and
show_slab_objects(), slab->slabs is only used for showing information.

Data-racy reads from shared variables that are used only for diagnostic
purposes should typically use data_race(), since it is normally not a
problem if the values are off by a little.

This patch is aimed at reducing the number of benign races reported by
KCSAN in order to focus future debugging effort on harmful races.

Signed-off-by: default avatarlinke li <lilinke99@qq.com>
Reviewed-by: default avatarChengming Zhou <chengming.zhou@linux.dev>
Signed-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
Signed-off-by: default avatarLiu Shixin <liushixin2@huawei.com>
parent e426a767
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -5448,7 +5448,7 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
				else if (flags & SO_OBJECTS)
					WARN_ON_ONCE(1);
				else
					x = slab->slabs;
					x = data_race(slab->slabs);
				total += x;
				nodes[node] += x;
			}
@@ -5653,7 +5653,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)
		slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu));

		if (slab)
			slabs += slab->slabs;
			slabs += data_race(slab->slabs);
	}
#endif

@@ -5667,7 +5667,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf)

		slab = slub_percpu_partial(per_cpu_ptr(s->cpu_slab, cpu));
		if (slab) {
			slabs = READ_ONCE(slab->slabs);
			slabs = data_race(slab->slabs);
			objects = (slabs * oo_objects(s->oo)) / 2;
			len += sysfs_emit_at(buf, len, " C%d=%d(%d)",
					     cpu, objects, slabs);