Skip to contentSkip to conversation

doubts about switch_mm

DISCUSSION Gilles Chanteperdrix 2 participants 4 messages Aug 2, 2012

lore
Share & tools
lore
#0 lore raw

Hi,

I know that switch_mm has been like this for years, and that it seems to work, but still, something seems wrong:

switch_mm code, as of 3.5 contains:

1 if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
2 check_and_switch_context(next, tsk);
3 if (cache_is_vivt())
4 cpumask_clear_cpu(cpu, mm_cpumask(prev));
5 }

Line 1 seems to mean that maybe switch_mm is called with prev == next. But then, what line 4 does is certainly wrong if prev == next.

Regards.

Signature · 1 line
                                                                Gilles.
#1 lore raw
Quoted 10 lines · Gilles Chanteperdrix

switch_mm code, as of 3.5 contains:

1 if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
2 check_and_switch_context(next, tsk);
3 if (cache_is_vivt())
4 cpumask_clear_cpu(cpu, mm_cpumask(prev));
5 }

Line 1 seems to mean that maybe switch_mm is called with prev == next. But then, what line 4 does is certainly wrong if prev == next.

Look at it more carefully.

If prev == next, then we're already running with *this* mm. The bit in the CPU mask for this CPU will be set.

So, cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) will be true, and because the condition is inverted, the first half of the if condition is false.

The second half is false, because prev == next. So lines 2-4 will not be executed.

#2 lore raw
Quoted 17 lines · Russell King - ARM Linux
Quoted 10 lines · Gilles Chanteperdrix

switch_mm code, as of 3.5 contains:

1 if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
2 check_and_switch_context(next, tsk);
3 if (cache_is_vivt())
4 cpumask_clear_cpu(cpu, mm_cpumask(prev));
5 }

Line 1 seems to mean that maybe switch_mm is called with prev == next. But then, what line 4 does is certainly wrong if prev == next.

Look at it more carefully.

If prev == next, then we're already running with *this* mm. The bit in the CPU mask for this CPU will be set.

Quoted 7 lines

So, cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) will be true, and because the condition is inverted, the first half of the if condition is false.

The second half is false, because prev == next. So lines 2-4 will not be executed.

So, prev != next on line 1 is useless ?

Signature · 1 line
                                                                Gilles.
#3 lore raw
Quoted 23 lines · Gilles Chanteperdrix
Quoted 21 lines · Russell King - ARM Linux
Quoted 10 lines · Gilles Chanteperdrix

switch_mm code, as of 3.5 contains:

1 if (!cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) || prev != next) {
2 check_and_switch_context(next, tsk);
3 if (cache_is_vivt())
4 cpumask_clear_cpu(cpu, mm_cpumask(prev));
5 }

Line 1 seems to mean that maybe switch_mm is called with prev == next. But then, what line 4 does is certainly wrong if prev == next.

Look at it more carefully.

If prev == next, then we're already running with *this* mm. The bit in the CPU mask for this CPU will be set.

So, cpumask_test_and_set_cpu(cpu, mm_cpumask(next)) will be true, and because the condition is inverted, the first half of the if condition is false.

Quoted 8 lines
Quoted 3 lines

The second half is false, because prev == next. So lines 2-4 will not be executed.

So, prev != next on line 1 is useless ?

Ok, got it, sorry for the noise.

Signature · 1 line
                                                                Gilles.