arm64/vdso: Support mremap() for vDSO
PATCH 1/1 arm64/vdso: Support mremap() for vDSO
vDSO VMA address is saved in mm_context for the purpose of using restorer from vDSO page to return to userspace after signal handling.
In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with arch_prctl()), we move vDSO inherited from CRIU task to restoree position by mremap().
CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288
Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commit b059a453b1cf ("x86/vdso: Add mremap hook to vm_special_mapping") commit 280e87e98c09 ("ARM: 8683/1: ARM32: Support mremap() for sigpage/vDSO").
--- arch/arm64/kernel/vdso.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm64/kernel/vdso.c +15 -0
@@ -110,12 +110,27 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) }#endif /* CONFIG_COMPAT */ +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ +unsigned long new_size = new_vma->vm_end - new_vma->vm_start; +unsigned long vdso_size = vdso_end - vdso_start; + +if (vdso_size != new_size) +return -EINVAL ; + + current->mm->context.vdso = (void *)new_vma->vm_start; + +return 0 ; +} +static struct vm_special_mapping vdso_spec[2 ]__ro_after_init = { { .name ="[vvar]" , }, { .name ="[vdso]" , + .mremap = vdso_mremap, }, };
Signature · 1 line
2.13.3
Quoted 36 lines · Dmitry Safonov
vDSO VMA address is saved in
mm_contextfor the purpose of using restorer from vDSO page to return to userspace after signal handling.In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with
arch_prctl()), we move vDSO inherited from CRIU task to restoree position bymremap().CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after
mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping") commit280e87e98c09("ARM: 8683/1: ARM32: Supportmremap()for sigpage/vDSO").Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Cc Christopher Covington <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm64/kernel/vdso.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm64/kernel/vdso.c +0
-0
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 117
Quoted 8 lines
arch/arm64/kernel/vdso.c +5
-0@@ -110,12 +110,27 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) }#endif /* CONFIG_COMPAT */ +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ +unsigned long new_size = new_vma->vm_end - new_vma->vm_start; +unsigned long vdso_size = vdso_end - vdso_start;
You might be able to use vdso_pages here, but it depends on my question below.
Quoted 6 lines
arch/arm64/kernel/vdso.c +6
-0+ +if (vdso_size != new_size) +return -EINVAL ; + + current->mm->context.vdso = (void *)new_vma->vm_start; +
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 133
Quoted 10 lines
arch/arm64/kernel/vdso.c +4
-0+return 0 ; +} +static struct vm_special_mapping vdso_spec[2 ]__ro_after_init = { { .name ="[vvar]" , }, { .name ="[vdso]" , + .mremap = vdso_mremap,
Does this mean we move the vdso text, but not the data page? How does that work?
Will
2017-07-28 19:48 GMT+03:00 Will Deacon <[email protected]>:
Quoted 40 lines · Dmitry Safonov
Quoted 39 lines
vDSO VMA address is saved in
mm_contextfor the purpose of using restorer from vDSO page to return to userspace after signal handling.In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with
arch_prctl()), we move vDSO inherited from CRIU task to restoree position bymremap().CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after
mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping") commit280e87e98c09("ARM: 8683/1: ARM32: Supportmremap()for sigpage/vDSO").Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Cc Christopher Covington <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm64/kernel/vdso.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm64/kernel/vdso.c +0
-0@@ -110,12 +110,27 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) }#endif /* CONFIG_COMPAT */
Quoted 8 lines
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 117
Quoted 5 lines
arch/arm64/kernel/vdso.c +5
-0+static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ +unsigned long new_size = new_vma->vm_end - new_vma->vm_start; +unsigned long vdso_size = vdso_end - vdso_start;You might be able to use
vdso_pageshere, but it depends on my question below.
Yes, shifting with PAGE_SHIFT.
Is it just a preference?
Quoted 12 lines
Quoted 12 lines
arch/arm64/kernel/vdso.c +9
-0+ +if (vdso_size != new_size) +return -EINVAL ; + + current->mm->context.vdso = (void *)new_vma->vm_start; + +return 0 ; +} +static struct vm_special_mapping vdso_spec[2 ]__ro_after_init = { {
Quoted 8 lines
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 133
Quoted 5 lines
arch/arm64/kernel/vdso.c +1
-0.name = "[vvar]", }, { .name = "[vdso]", + .mremap = vdso_mremap,Does this mean we move the vdso text, but not the data page? How does that work?
Well, the kernel tracks only vdso pages - to find restorer addr after a signal. In userspace one needs to move vvar and vdso vma pair accordingly, with the same order and offset of course.
Signature · 1 line
Dmitry
Quoted 50 lines · Dmitry Safonov
2017-07-28 19:48 GMT+03:00 Will Deacon <[email protected]>:
Quoted 40 lines · Dmitry Safonov
Quoted 39 lines
vDSO VMA address is saved in
mm_contextfor the purpose of using restorer from vDSO page to return to userspace after signal handling.In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with
arch_prctl()), we move vDSO inherited from CRIU task to restoree position bymremap().CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after
mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping") commit280e87e98c09("ARM: 8683/1: ARM32: Supportmremap()for sigpage/vDSO").Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Cc Christopher Covington <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm64/kernel/vdso.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm64/kernel/vdso.c +0
-0@@ -110,12 +110,27 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) }#endif /* CONFIG_COMPAT */ Quoted 8 lines
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 117
Quoted 5 lines
arch/arm64/kernel/vdso.c +5
-0+static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ +unsigned long new_size = new_vma->vm_end - new_vma->vm_start; +unsigned long vdso_size = vdso_end - vdso_start;You might be able to use
vdso_pageshere, but it depends on my question below.
Quoted 2 lines
Yes, shifting with
PAGE_SHIFT.
Is it just a preference?
Yeah, just a minor thing, although thinking about it again, I don't know what you're trying to achieve with the size check anyway. Userspace is only going to hurt itself if it screws up the layout, so why police this?
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
arch/arm64/kernel/vdso.c +9
-0+ +if (vdso_size != new_size) +return -EINVAL ; + + current->mm->context.vdso = (void *)new_vma->vm_start; + +return 0 ; +} +static struct vm_special_mapping vdso_spec[2 ]__ro_after_init = { {Quoted 8 lines
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 133
Quoted 5 lines
arch/arm64/kernel/vdso.c +1
-0.name = "[vvar]", }, { .name = "[vdso]", + .mremap = vdso_mremap,Does this mean we move the vdso text, but not the data page? How does that work?
Quoted 3 lines
Well, the kernel tracks only vdso pages - to find restorer addr after a signal. In userspace one needs to move vvar and vdso vma pair accordingly, with the same order and offset of course.
Ah, I see. I misunderstood what the .mremap callback was actually doing. I guess there's also no issue with not being able to do this atomically, either, as long as you can avoid making syscalls via the vDSO until you've relocated both mappings.
Will
2017-08-02 19:04 GMT+03:00 Will Deacon <[email protected]>:
Quoted 51 lines · Dmitry Safonov
Quoted 50 lines
2017-07-28 19:48 GMT+03:00 Will Deacon <[email protected]>:
Quoted 48 lines · Dmitry Safonov
Quoted 36 lines
vDSO VMA address is saved in
mm_contextfor the purpose of using restorer from vDSO page to return to userspace after signal handling.In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with
arch_prctl()), we move vDSO inherited from CRIU task to restoree position bymremap().CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after
mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping") commit280e87e98c09("ARM: 8683/1: ARM32: Supportmremap()for sigpage/vDSO").Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Cc Christopher Covington <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm64/kernel/vdso.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm64/kernel/vdso.c +0
-0arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 117
Quoted 8 lines
arch/arm64/kernel/vdso.c +5
-0@@ -110,12 +110,27 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) }#endif /* CONFIG_COMPAT */ +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ +unsigned long new_size = new_vma->vm_end - new_vma->vm_start; +unsigned long vdso_size = vdso_end - vdso_start;You might be able to use
vdso_pageshere, but it depends on my question below.
Quoted 6 lines
Quoted 2 lines
Yes, shifting with
PAGE_SHIFT.
Is it just a preference?Yeah, just a minor thing, although thinking about it again, I don't know what you're trying to achieve with the size check anyway. Userspace is only going to hurt itself if it screws up the layout, so why police this?
Well, it's for keeping the same semantics as on x86. The idea of restriction to partial mremap() is suggested by Andy so that userspace won't be allowed to hurt itself and to simplify kernel code on x86.
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 8 lines
arch/arm64/kernel/vdso.c +6
-0+ +if (vdso_size != new_size) +return -EINVAL ; + + current->mm->context.vdso = (void *)new_vma->vm_start; +arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 133
Quoted 10 lines
arch/arm64/kernel/vdso.c +4
-0+return 0 ; +} +static struct vm_special_mapping vdso_spec[2 ]__ro_after_init = { { .name ="[vvar]" , }, { .name ="[vdso]" , + .mremap = vdso_mremap,Does this mean we move the vdso text, but not the data page? How does that work?
Quoted 8 lines
Quoted 3 lines
Well, the kernel tracks only vdso pages - to find restorer addr after a signal. In userspace one needs to move vvar and vdso vma pair accordingly, with the same order and offset of course.
Ah, I see. I misunderstood what the .mremap callback was actually doing. I guess there's also no issue with not being able to do this atomically, either, as long as you can avoid making syscalls via the vDSO until you've relocated both mappings.
Yes, also one should keep in mind that there might be some linker work needed after mremap() of vdso. As some loaded libraries may have been linked to vdso's vma addresses.
In CRIU we have `restorer' code which is PIE code, non-linked to libc and calling raw syscalls rather than using vdso. And restoree (the application being restored) is already linked to vdso's new position.
Signature · 1 line
Dmitry
Will Deacon
Reviewed-byQuoted 55 lines · Dmitry Safonov
2017-08-02 19:04 GMT+03:00 Will Deacon <[email protected]>:
Quoted 54 lines · Dmitry Safonov
Quoted 52 lines
2017-07-28 19:48 GMT+03:00 Will Deacon <[email protected]>:
Quoted 40 lines · Dmitry Safonov
Quoted 39 lines
vDSO VMA address is saved in
mm_contextfor the purpose of using restorer from vDSO page to return to userspace after signal handling.In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with
arch_prctl()), we move vDSO inherited from CRIU task to restoree position bymremap().CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after
mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping") commit280e87e98c09("ARM: 8683/1: ARM32: Supportmremap()for sigpage/vDSO").Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Cc Christopher Covington <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm64/kernel/vdso.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm64/kernel/vdso.c +0
-0@@ -110,12 +110,27 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) }#endif /* CONFIG_COMPAT */ Quoted 8 lines
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 117
Quoted 5 lines
arch/arm64/kernel/vdso.c +5
-0+static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ +unsigned long new_size = new_vma->vm_end - new_vma->vm_start; +unsigned long vdso_size = vdso_end - vdso_start;You might be able to use
vdso_pageshere, but it depends on my question below.Yes, shifting with
PAGE_SHIFT.
Is it just a preference?
Quoted 8 lines
Quoted 3 lines
Yeah, just a minor thing, although thinking about it again, I don't know what you're trying to achieve with the size check anyway. Userspace is only going to hurt itself if it screws up the layout, so why police this?
Well, it's for keeping the same semantics as on x86. The idea of restriction to partial
mremap()is suggested by Andy so that userspace won't be allowed to hurt itself and to simplify kernel code on x86.
I still don't see why that's a useful thing for us to be doing on arm64, but ok.
Either way:
Will
2017-08-08 12:44 GMT+03:00 Will Deacon <[email protected]>:
Quoted 65 lines · Dmitry Safonov
Quoted 55 lines
2017-08-02 19:04 GMT+03:00 Will Deacon <[email protected]>:
Quoted 54 lines · Dmitry Safonov
Quoted 52 lines
2017-07-28 19:48 GMT+03:00 Will Deacon <[email protected]>:
Quoted 40 lines · Dmitry Safonov
Quoted 39 lines
vDSO VMA address is saved in
mm_contextfor the purpose of using restorer from vDSO page to return to userspace after signal handling.In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with
arch_prctl()), we move vDSO inherited from CRIU task to restoree position bymremap().CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after
mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping") commit280e87e98c09("ARM: 8683/1: ARM32: Supportmremap()for sigpage/vDSO").Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Cc Christopher Covington <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm64/kernel/vdso.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)arch/arm64/kernel/vdso.c +0
-0@@ -110,12 +110,27 @@ int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) }#endif /* CONFIG_COMPAT */ Quoted 8 lines
arch/arm64/kernel/vdso.c int aarch32_setup_vectors_page(struct linux_binprm *bprm, int uses_interp) · line 117
Quoted 5 lines
arch/arm64/kernel/vdso.c +5
-0+static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma) +{ +unsigned long new_size = new_vma->vm_end - new_vma->vm_start; +unsigned long vdso_size = vdso_end - vdso_start;You might be able to use
vdso_pageshere, but it depends on my question below.Yes, shifting with
PAGE_SHIFT.
Is it just a preference?Quoted 8 lines
Quoted 3 lines
Yeah, just a minor thing, although thinking about it again, I don't know what you're trying to achieve with the size check anyway. Userspace is only going to hurt itself if it screws up the layout, so why police this?
Well, it's for keeping the same semantics as on x86. The idea of restriction to partial
mremap()is suggested by Andy so that userspace won't be allowed to hurt itself and to simplify kernel code on x86.
Quoted 6 lines
I still don't see why that's a useful thing for us to be doing on arm64, but ok.
Either way:
Reviewed-by Will Deacon <[email protected]>
Thanks!
Signature · 1 line
Dmitry
Quoted 19 lines · Dmitry Safonov
vDSO VMA address is saved in
mm_contextfor the purpose of using restorer from vDSO page to return to userspace after signal handling.In Checkpoint Restore in Userspace (CRIU) project we place vDSO VMA on restore back to the place where it was on the dump. With the exception for x86 (where there is API to map vDSO with
arch_prctl()), we move vDSO inherited from CRIU task to restoree position bymremap().CRIU does support arm64 architecture, but kernel doesn't update context.vdso pointer after
mremap(). Which results in translation fault after signal handling on restored application:
https://github.com/xemul/criu/issues/288Make vDSO code track the VMA address by supplying .mremap() fops the same way it's done for x86 and arm32 by:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping") commit280e87e98c09("ARM: 8683/1: ARM32: Supportmremap()for sigpage/vDSO").
Quoted 8 lines
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Russell King <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Cc Christopher Covington <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>
Queued for 4.14. Thanks.
Signature · 1 line
Catalin