Re: [PATCH] mm: rcu-protected get_mm_exe_file()

From: Oleg Nesterov
Date: Mon Mar 16 2015 - 12:37:30 EST


On 03/16, Konstantin Khlebnikov wrote:
>
> On 16.03.2015 17:07, Oleg Nesterov wrote:
>> I mean, I think we can do another cleanup on top of this change.
>>
>> 1. set_mm_exe_file() should be called by exit/exec only, so
>> it should use
>>
>> rcu_dereference_protected(mm->exe_file,
>> atomic_read(&mm->mm_users) <= 1);
>>
>> 2. prctl() should not use it, it can do
>>
>> get_file(new_exe);
>> old_exe = xchg(&mm->exe_file);
>> if (old_exe)
>> fput(old_exe);
>
> I think smp_mb() is required before xchg() or
> probably this stuff should be hidden inside yet another magic RCU macro
> ( with two screens of comments =)

Not really, xchg() implies mb's on both sides. As any other atomic operation
which returns the result.

(And in fact we do not even need rcu_assign_pointer() in set_mm_exe_file(),
get_mm_exe_file() could do READ_ONCE() + inc_not_zero(). But this is off-
topic, and of course rcu_* helpers look better)

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/