* doubts about switch_mm
@ 2012-08-02 19:08 Gilles Chanteperdrix
2012-08-02 19:49 ` Russell King - ARM Linux
0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2012-08-02 19:08 UTC (permalink / raw)
To: linux-arm-kernel
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.
--
Gilles.
^ permalink raw reply [flat|nested] 4+ messages in thread
* doubts about switch_mm
2012-08-02 19:08 doubts about switch_mm Gilles Chanteperdrix
@ 2012-08-02 19:49 ` Russell King - ARM Linux
2012-08-02 20:02 ` Gilles Chanteperdrix
0 siblings, 1 reply; 4+ messages in thread
From: Russell King - ARM Linux @ 2012-08-02 19:49 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Aug 02, 2012 at 09:08:19PM +0200, Gilles Chanteperdrix wrote:
> 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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* doubts about switch_mm
2012-08-02 19:49 ` Russell King - ARM Linux
@ 2012-08-02 20:02 ` Gilles Chanteperdrix
2012-08-02 20:05 ` Gilles Chanteperdrix
0 siblings, 1 reply; 4+ messages in thread
From: Gilles Chanteperdrix @ 2012-08-02 20:02 UTC (permalink / raw)
To: linux-arm-kernel
On 08/02/2012 09:49 PM, Russell King - ARM Linux wrote:
> On Thu, Aug 02, 2012 at 09:08:19PM +0200, Gilles Chanteperdrix wrote:
>> 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.
>
So, prev != next on line 1 is useless ?
--
Gilles.
^ permalink raw reply [flat|nested] 4+ messages in thread
* doubts about switch_mm
2012-08-02 20:02 ` Gilles Chanteperdrix
@ 2012-08-02 20:05 ` Gilles Chanteperdrix
0 siblings, 0 replies; 4+ messages in thread
From: Gilles Chanteperdrix @ 2012-08-02 20:05 UTC (permalink / raw)
To: linux-arm-kernel
On 08/02/2012 10:02 PM, Gilles Chanteperdrix wrote:
> On 08/02/2012 09:49 PM, Russell King - ARM Linux wrote:
>
>> On Thu, Aug 02, 2012 at 09:08:19PM +0200, Gilles Chanteperdrix wrote:
>>> 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.
>>
>
>
> So, prev != next on line 1 is useless ?
>
>
Ok, got it, sorry for the noise.
--
Gilles.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-08-02 20:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-02 19:08 doubts about switch_mm Gilles Chanteperdrix
2012-08-02 19:49 ` Russell King - ARM Linux
2012-08-02 20:02 ` Gilles Chanteperdrix
2012-08-02 20:05 ` Gilles Chanteperdrix
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).