Skip to contentSkip to conversation

mm/slub: mark racy access on slab->freelist

PATCH In review linke li 3 participants 4 messages Apr 27, 2024 – May 2, 2024

Subsystems (2)
lore
Share & tools
lore

linke li

author
#0 lore raw

PATCH 1/1 mm/slub: mark racy access on slab->freelist

In deactivate_slab(), slab->freelist can be changed concurrently. Mark data race on slab->freelist as benign using READ_ONCE.

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

---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
index 0d700f6ca547..bb0e05a321e9 100644
@@ -2813,7 +2813,7 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab,
 	struct slab new;
 	struct slab old;
 
-	if (slab->freelist) {
+	if (READ_ONCE(slab->freelist)) {
 		stat(s, DEACTIVATE_REMOTE_FREES);
 		tail = DEACTIVATE_TO_TAIL;
 	}
Signature · 1 line
2.39.3 (Apple Git-146)
#1 lore raw
Quoted 6 lines · linke li

In deactivate_slab(), slab->freelist can be changed concurrently. Mark data race on slab->freelist as benign using READ_ONCE.

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

Thanks! Do you have a data race report to copy+paste into the commit description so people can search for it if they stumble across the same thing?

Quoted 22 lines
---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
index 0d700f6ca547..bb0e05a321e9 100644
@@ -2813,7 +2813,7 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab,
 	struct slab new;
 	struct slab old;
 
-	if (slab->freelist) {
+	if (READ_ONCE(slab->freelist)) {
 		stat(s, DEACTIVATE_REMOTE_FREES);
 		tail = DEACTIVATE_TO_TAIL;
 	}
Signature · 1 line
2.39.3 (Apple Git-146)
author
#2 lore raw
Quoted 3 lines

Thanks! Do you have a data race report to copy+paste into the commit description so people can search for it if they stumble across the same thing?

I don't have a data race report, just try to analyze the code statically and then check it manually. I hope I could help in some way.

#3 lore raw
In reply to linke li
Quoted 7 lines · linke li

In deactivate_slab(), slab->freelist can be changed concurrently. Mark data race on slab->freelist as benign using READ_ONCE.

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

Added to slab/for-6.10, thanks

Quoted 17 lines
---
 mm/slub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/slub.c +1 -1
index 0d700f6ca547..bb0e05a321e9 100644
@@ -2813,7 +2813,7 @@ static void deactivate_slab(struct kmem_cache *s, struct slab *slab,
 	struct slab new;
 	struct slab old;
 
-	if (slab->freelist) {
+	if (READ_ONCE(slab->freelist)) {
 		stat(s, DEACTIVATE_REMOTE_FREES);
 		tail = DEACTIVATE_TO_TAIL;
 	}