[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3ea03d61-67f8-3014-55cd-66fe9f77a166@gmail.com>
Date: Thu, 25 Apr 2019 19:02:52 +0100
From: Dmitry Safonov <0x7f454c46@...il.com>
To: Jann Horn <jannh@...gle.com>, Dmitry Safonov <dima@...sta.com>
Cc: kernel list <linux-kernel@...r.kernel.org>,
Adrian Reber <adrian@...as.de>,
Andrei Vagin <avagin@...nvz.org>,
Andy Lutomirski <luto@...nel.org>,
Arnd Bergmann <arnd@...db.de>,
Christian Brauner <christian.brauner@...ntu.com>,
Cyrill Gorcunov <gorcunov@...nvz.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
"H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
Jeff Dike <jdike@...toit.com>, Oleg Nesterov <oleg@...hat.com>,
Pavel Emelyanov <xemul@...tuozzo.com>,
Shuah Khan <shuah@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Vincenzo Frascino <vincenzo.frascino@....com>,
containers@...ts.linux-foundation.org, criu@...nvz.org,
Linux API <linux-api@...r.kernel.org>,
the arch/x86 maintainers <x86@...nel.org>,
Andrei Vagin <avagin@...il.com>
Subject: Re: [PATCHv3 16/27] x86/vdso: Switch image on
setns()/unshare()/clone()
On 4/25/19 6:53 PM, Jann Horn wrote:
> On Thu, Apr 25, 2019 at 6:15 PM Dmitry Safonov <dima@...sta.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
Powered by blists - more mailing lists