Re: [PATCH v2] ftrace: Clear hashes of stale ips of init memory

From: Joel Fernandes
Date: Mon Oct 09 2017 - 15:21:54 EST


On Mon, Oct 9, 2017 at 12:11 PM, Joel Fernandes <joelaf@xxxxxxxxxx> wrote:
> On Mon, Oct 9, 2017 at 11:53 AM, Joel Fernandes <joelaf@xxxxxxxxxx> wrote:
> [..]
>> +
>> void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
>> {
>> unsigned long start = (unsigned long)(start_ptr);
>> @@ -6076,8 +6135,12 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
>> struct dyn_ftrace *rec;
>> struct dyn_ftrace key;
>> struct ftrace_mod_map *mod_map = NULL;
>> + struct ftrace_init_func *func, *func_next;
>> + struct list_head clear_hash;
>> int order;
>>
>> + INIT_LIST_HEAD(&clear_hash);
>> +
>> key.ip = start;
>> key.flags = end; /* overload flags, as it is unsigned long */
>>
>> @@ -6102,6 +6165,9 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
>> if (!rec)
>> continue;
>>
>> + /* rec will be cleared from hashes after ftrace_lock unlock */
>> + add_to_clear_hash_list(&clear_hash, rec);
>> +
>> if (mod_map)
>> save_ftrace_mod_rec(mod_map, rec);
>>
>> @@ -6123,6 +6189,11 @@ void ftrace_free_mem(struct module *mod, void *start_ptr, void *end_ptr)
>> goto again;
>> }
>> mutex_unlock(&ftrace_lock);
>> +
>> + list_for_each_entry_safe(func, func_next, &clear_hash, list) {
>
> I think I screwed this list_for_each_entry up! Please ignore this
> revision, I'll send another patch revision shortly.

Actually, its correct. I got confused with how
list_for_each_entry_safe's terminating condition is defined:

&pos->member != (head)

I thought head itself had to be an entry's member, but here the
pointer offset is calculated and will take care of the termination so
its fine.

Sorry about the noise!

thanks,

- Joel