Skip to contentSkip to conversation

mm/slub: use unchecked percpu access within preemptible sections

PATCH In review Sasha Levin 2 participants 4 messages Jan 21, 2015 – Jan 22, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/slub: use unchecked percpu access within preemptible sections

Commit "mm/slub: optimize alloc/free fastpath by removing preemption on/off" has added access to percpu memory while the code is preemptible.

While those accesses are okay, this creates a huge amount of warnings from the code that checks for that.

---
 mm/slub.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
mm/slub.c +4 -4
index 907fabe..9b72b9c 100644
@@ -2431,8 +2431,8 @@ redo:
 	 * to check if it is matched or not.
 	 */
 	do {
-		tid = this_cpu_read(s->cpu_slab->tid);
-		c = this_cpu_ptr(s->cpu_slab);
+		tid = raw_cpu_read(s->cpu_slab->tid);
+		c = raw_cpu_ptr(s->cpu_slab);
 	} while (IS_ENABLED(CONFIG_PREEMPT) && unlikely(tid != c->tid));
 
 	/*
@@ -2700,8 +2700,8 @@ redo:
 	 * during the cmpxchg then the free will succedd.
 	 */
 	do {
-		tid = this_cpu_read(s->cpu_slab->tid);
-		c = this_cpu_ptr(s->cpu_slab);
+		tid = raw_cpu_read(s->cpu_slab->tid);
+		c = raw_cpu_ptr(s->cpu_slab);
 	} while (IS_ENABLED(CONFIG_PREEMPT) && unlikely(tid != c->tid));
 
 	/* Same with comment on barrier() in slab_alloc_node() */
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 7 lines · Sasha Levin

Commit "mm/slub: optimize alloc/free fastpath by removing preemption on/off" has added access to percpu memory while the code is preemptible.

While those accesses are okay, this creates a huge amount of warnings from the code that checks for that.

Hello,

I already sent the patch to fix this issue and it is in mmotm, but, not be released yet.

https://lkml.org/lkml/2015/1/19/17

Thanks.

#2 lore raw
Quoted 7 lines · Joonsoo Kim
Quoted 6 lines · Sasha Levin
Quoted 6 lines

Commit "mm/slub: optimize alloc/free fastpath by removing preemption on/off" has added access to percpu memory while the code is preemptible.

While those accesses are okay, this creates a huge amount of warnings from the code that checks for that.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hello,

I already sent the patch to fix this issue and it is in mmotm, but, not be released yet.

https://lkml.org/lkml/2015/1/19/17

The patch you sent out still has the issue. The one I sent goes on top of it.

+ do {
+ tid = this_cpu_read(s->cpu_slab->tid); <=== checked percpu access
+ c = raw_cpu_ptr(s->cpu_slab);
+ } while (IS_ENABLED(CONFIG_PREEMPT) && unlikely(tid != c->tid));

Thanks,
Sasha

#3 lore raw
Quoted 20 lines · Sasha Levin
Quoted 7 lines · Joonsoo Kim
Quoted 6 lines · Sasha Levin
Quoted 6 lines

Commit "mm/slub: optimize alloc/free fastpath by removing preemption on/off" has added access to percpu memory while the code is preemptible.

While those accesses are okay, this creates a huge amount of warnings from the code that checks for that.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

Hello,

I already sent the patch to fix this issue and it is in mmotm, but, not be released yet.

https://lkml.org/lkml/2015/1/19/17

The patch you sent out still has the issue. The one I sent goes on top of it.

Review

Quoted 4 lines
(quoted diff) +4 -0
+	do {
+		tid = this_cpu_read(s->cpu_slab->tid); <=== checked percpu access
+		c = raw_cpu_ptr(s->cpu_slab);
+	} while (IS_ENABLED(CONFIG_PREEMPT) && unlikely(tid != c->tid));

Hello,

this_cpu_xxx() is designed to be called regardless of interrupts and preemption.

In Documentation/this_cpu_ops.txt,

The following this_cpu() operations with implied preemption protection are defined. These operations can be used without worrying about preemption and interrupts.

        this_cpu_read(pcp)
        ...

And, for correctness of algorithm, tid should be fetched through this_cpu_read() rather than raw_cpu_read(). Generic implementation of raw_cpu_read() has a race window to fetch different cpu's tid instead of the cpu where we are at now and this will cause algorithm broken.

Thanks.