lkml.org 
[lkml]   [2024]   [Mar]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] mm/slub: mark racy accesses on slab->slabs
Date
The reads of slab->slabs are racy because it may be changed by 
put_cpu_partial concurrently. And in slabs_cpu_partial_show ->slabs is
only used for output. 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: linke li <lilinke99@qq.com>
---
mm/slub.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 2ef88bbf56a3..7b20591e7f8a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -6257,7 +6257,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

@@ -6271,7 +6271,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);
--
2.39.3 (Apple Git-146)

\
 
 \ /
  Last update: 2024-05-27 15:42    [W:0.031 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site