[PATCHv3 16/27] x86/vdso: Switch image on setns()/unshare()/clone()

Dmitry Safonov 0x7f454c46 at gmail.com
Thu Apr 25 18:02:52 UTC 2019


On 4/25/19 6:53 PM, Jann Horn wrote:
> On Thu, Apr 25, 2019 at 6:15 PM Dmitry Safonov <dima at arista.com> wrote:
>> As it has been discussed on timens RFC, adding a new conditional branch
>> `if (inside_time_ns)` on VDSO for all processes is undesirable.
>> It will add a penalty for everybody as branch predictor may mispredict
>> the jump. Also there are instruction cache lines wasted on cmp/jmp.
>>
>> Those effects of introducing time namespace are very much unwanted
>> having in mind how much work have been spent on micro-optimisation
>> vdso code.
>>
>> Addressing those problems, there are two versions of VDSO's .so:
>> for host tasks (without any penalty) and for processes inside of time
>> namespace with clk_to_ns() that subtracts offsets from host's time.
>>
>> Whenever a user does setns()/unshare() or clone() with CLONE_TIMENS,
>> change VDSO image in mm and zap existing VVAR/VDSO page tables.
>> They will be re-faulted with corresponding image and VVAR offsets.
> [...]
>> +#ifdef CONFIG_TIME_NS
>> +int vdso_join_timens(struct task_struct *task, bool inside_ns)
> 
> The parameter "inside_ns" is never used, right?

Oh, yes - leftover from the previous version, where the image was
swapped in the callback. Will remove it.

> 
>> +{
>> +       struct mm_struct *mm = task->mm;
>> +       struct vm_area_struct *vma;
>> +
>> +       if (down_write_killable(&mm->mmap_sem))
>> +               return -EINTR;
>> +
>> +       for (vma = mm->mmap; vma; vma = vma->vm_next) {
>> +               unsigned long size = vma->vm_end - vma->vm_start;
>> +
>> +               if (vma_is_special_mapping(vma, &vvar_mapping))
>> +                       zap_page_range(vma, vma->vm_start, size);
>> +               if (vma_is_special_mapping(vma, &vdso_mapping))
>> +                       zap_page_range(vma, vma->vm_start, size);
> 
> Nit: This could be rewritten as:
> 
> if (vma_is_special_mapping(vma, &vvar_mapping) ||
>     vma_is_special_mapping(vma, &vdso_mapping))
>         zap_page_range(vma, vma->vm_start, size);

Yes. I thought it looks better with two if's rather than with a longer
line, but I don't mind - will change.

> 
>> +       }
>> +
>> +       up_write(&mm->mmap_sem);
>> +       return 0;
>> +}
> [...]
> 

Thanks,
          Dmitry


More information about the Containers mailing list