<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="auto">I'm sorry, but this patch can and has to be split into series of patches.</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">11 июля 2017 г. 20:48 пользователь Dmitry Safonov <dsafonov@virtuozzo.com> написал:<br type="attribution">
<blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><font size="2"><span style="font-size:10pt">
<div>Mainstream already has arch_prctl(MAP_VDSO_64), but this was<br>
ommited for simplicity and we only have arch_prctl(MAP_VDSO_32).<br>
This was not a problem as previously we needed MAP_VDSO_32 only<br>
for ia32 applications C/R.<br>
<br>
But as we've made vdso pages to be per-UTS-ns, pages differ between<br>
host and uts-ns. As CRIU restore starts from init-ns, vdso that's<br>
being preserved into restored application belongs to host and<br>
thou has host's ve_time_spec.<br>
<br>
Using this API we can map vdso in restored CT and it'll belong<br>
to uts-ns of CT.<br>
<br>
<a href="https://jira.sw.ru/browse/PSBM-67017">https://jira.sw.ru/browse/PSBM-67017</a><br>
<br>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com><br>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com><br>
---<br>
arch/x86/include/asm/elf.h | 6 +++++-<br>
arch/x86/kernel/process_64.c | 14 ++++++-------<br>
arch/x86/vdso/vdso32-setup.c | 12 +----------<br>
arch/x86/vdso/vma.c | 48 ++++++++++++++++++++++++++++++++++++--------<br>
4 files changed, 53 insertions(+), 27 deletions(-)<br>
<br>
diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h<br>
index 8b0f63910b06..920690b3a5d5 100644<br>
--- a/arch/x86/include/asm/elf.h<br>
+++ b/arch/x86/include/asm/elf.h<br>
@@ -353,7 +353,11 @@ extern int syscall32_setup_pages(struct linux_binprm *, int exstack);<br>
#define compat_arch_setup_additional_pages syscall32_setup_pages<br>
<br>
#ifdef CONFIG_X86_64<br>
-extern int do_map_compat_vdso(unsigned long addr);<br>
+extern bool vdso_or_vvar_present(struct mm_struct *mm);<br>
+extern int do_map_vdso_64(unsigned long addr);<br>
+# ifdef CONFIG_COMPAT<br>
+extern int do_map_vdso_32(unsigned long addr);<br>
+# endif<br>
#endif<br>
<br>
extern unsigned long arch_randomize_brk(struct mm_struct *mm);<br>
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c<br>
index d2e444cb7209..252f9f0ecc0f 100644<br>
--- a/arch/x86/kernel/process_64.c<br>
+++ b/arch/x86/kernel/process_64.c<br>
@@ -580,16 +580,16 @@ long do_arch_prctl(struct task_struct *task, int code, unsigned long addr)<br>
}<br>
<br>
#ifdef CONFIG_CHECKPOINT_RESTORE<br>
+# ifdef CONFIG_COMPAT<br>
case ARCH_MAP_VDSO_32:<br>
- return do_map_compat_vdso(addr);<br>
+ return do_map_vdso_32(addr);<br>
+# endif<br>
<br>
- /*<br>
- * x32 and 64 vDSO remap API is omitted for simplicity.<br>
- * We do need 32-bit vDSO blob mapping for compatible<br>
- * applications Restore, but not x32/64 (at least, for now).<br>
- */<br>
- case ARCH_MAP_VDSO_X32:<br>
case ARCH_MAP_VDSO_64:<br>
+ return do_map_vdso_64(addr);<br>
+<br>
+ /* x32 vDSO remap API is omitted for simplicity. */<br>
+ case ARCH_MAP_VDSO_X32:<br>
#endif<br>
<br>
default:<br>
diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c<br>
index 81a16c803f11..30b99959daed 100644<br>
--- a/arch/x86/vdso/vdso32-setup.c<br>
+++ b/arch/x86/vdso/vdso32-setup.c<br>
@@ -512,17 +512,7 @@ up_fail:<br>
<br>
#ifdef CONFIG_X86_64<br>
<br>
-static bool vdso_or_vvar_present(struct mm_struct *mm)<br>
-{<!-- --><br>
- struct vm_area_struct *vma;<br>
-<br>
- for (vma = mm->mmap; vma; vma = vma->vm_next)<br>
- if (vma_is_vdso_or_vvar(vma, mm))<br>
- return true;<br>
- return false;<br>
-}<br>
-<br>
-int do_map_compat_vdso(unsigned long req_addr)<br>
+int do_map_vdso_32(unsigned long req_addr)<br>
{<!-- --><br>
struct mm_struct *mm = current->mm;<br>
unsigned long vdso_addr;<br>
diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c<br>
index ad0e0ac14f83..accca8edc62b 100644<br>
--- a/arch/x86/vdso/vma.c<br>
+++ b/arch/x86/vdso/vma.c<br>
@@ -171,28 +171,52 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)<br>
return addr;<br>
}<br>
<br>
+bool vdso_or_vvar_present(struct mm_struct *mm)<br>
+{<!-- --><br>
+ struct vm_area_struct *vma;<br>
+<br>
+ for (vma = mm->mmap; vma; vma = vma->vm_next)<br>
+ if (vma_is_vdso_or_vvar(vma, mm))<br>
+ return true;<br>
+ return false;<br>
+}<br>
+<br>
/* Setup a VMA at program startup for the vsyscall page.<br>
Not called for compat tasks */<br>
static int setup_additional_pages(struct linux_binprm *bprm,<br>
int uses_interp,<br>
struct page **pages,<br>
- unsigned size)<br>
+ unsigned size,<br>
+ unsigned long req_addr)<br>
{<!-- --><br>
struct mm_struct *mm = current->mm;<br>
- unsigned long addr;<br>
+ unsigned long addr = req_addr;<br>
int ret;<br>
<br>
if (!vdso_enabled)<br>
return 0;<br>
<br>
down_write(&mm->mmap_sem);<br>
- addr = vdso_addr(mm->start_stack, size);<br>
+<br>
+ if (vdso_or_vvar_present(mm)) {<!-- --><br>
+ ret = -EEXIST;<br>
+ goto up_fail;<br>
+ }<br>
+<br>
+ if (!req_addr)<br>
+ addr = vdso_addr(mm->start_stack, size);<br>
+<br>
addr = get_unmapped_area(NULL, addr, size, 0, 0);<br>
if (IS_ERR_VALUE(addr)) {<!-- --><br>
ret = addr;<br>
goto up_fail;<br>
}<br>
<br>
+ if (req_addr && req_addr != addr) {<!-- --><br>
+ ret = -EFAULT;<br>
+ goto up_fail;<br>
+ }<br>
+<br>
current->mm->context.vdso = (void *)addr;<br>
<br>
ret = install_special_mapping(mm, addr, size,<br>
@@ -211,7 +235,8 @@ up_fail:<br>
<br>
static DEFINE_MUTEX(vdso_mutex);<br>
<br>
-static int uts_arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)<br>
+static int uts_arch_setup_additional_pages(struct linux_binprm *bprm,<br>
+ int uses_interp, unsigned long addr)<br>
{<!-- --><br>
struct uts_namespace *uts_ns = current->nsproxy->uts_ns;<br>
struct ve_struct *ve = get_exec_env();<br>
@@ -303,9 +328,11 @@ static int uts_arch_setup_additional_pages(struct linux_binprm *bprm, int uses_i<br>
LINUX_VERSION_CODE, new_version, ve->veid);<br>
<br>
map_uts:<br>
- return setup_additional_pages(bprm, uses_interp, uts_ns->vdso.pages, uts_ns->vdso.size);<br>
+ return setup_additional_pages(bprm, uses_interp, uts_ns->vdso.pages,<br>
+ uts_ns->vdso.size, addr);<br>
map_init_uts:<br>
- return setup_additional_pages(bprm, uses_interp, init_uts_ns.vdso.pages, init_uts_ns.vdso.size);<br>
+ return setup_additional_pages(bprm, uses_interp, init_uts_ns.vdso.pages,<br>
+ init_uts_ns.vdso.size, addr);<br>
out_unlock:<br>
mutex_unlock(&vdso_mutex);<br>
return -ENOMEM;<br>
@@ -313,14 +340,19 @@ out_unlock:<br>
<br>
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)<br>
{<!-- --><br>
- return uts_arch_setup_additional_pages(bprm, uses_interp);<br>
+ return uts_arch_setup_additional_pages(bprm, uses_interp, 0);<br>
+}<br>
+<br>
+int do_map_vdso_64(unsigned long req_addr)<br>
+{<!-- --><br>
+ return uts_arch_setup_additional_pages(0, 0, req_addr);<br>
}<br>
<br>
#ifdef CONFIG_X86_X32_ABI<br>
int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)<br>
{<!-- --><br>
return setup_additional_pages(bprm, uses_interp, vdsox32_pages,<br>
- vdsox32_size);<br>
+ vdsox32_size, 0);<br>
}<br>
#endif<br>
<br>
-- <br>
2.13.1<br>
<br>
_______________________________________________<br>
Devel mailing list<br>
Devel@openvz.org<br>
<a href="https://lists.openvz.org/mailman/listinfo/devel">https://lists.openvz.org/mailman/listinfo/devel</a><br>
</div>
</span></font></div>
</blockquote>
</div>
<br>
</div>
</body>
</html>