arm/vdso: introduce vdso_mremap hook
Subsystems (2)
PATCH 1/1 arm/vdso: introduce vdso_mremap hook
Add vdso_mremap hook which will fix context.vdso pointer after mremap()
on vDSO vma. This is needed for correct landing after syscall execution. Primary goal of this is for CRIU on arm - we need to restore vDSO image at the exactly same place where the vma was in dumped application. With the help of this hook we'll move vDSO at the new position.
The CRIU code handles situations like when vDSO of dumped application
was different from vDSO on restoring system. This usally happens when some new symbols are being added to vDSO. In these situations CRIU inserts jump trampolines from old vDSO blob to new vDSO on restore. By that reason even if on restore vDSO blob lies on the same address as blob in dumped application - we still need to move it if it differs.
There was previously attempt to add this functionality for arm64 byarch_mremap hook [1], while this patch introduces this with minimal effort - the same way I've added it to x86:
commit b059a453b1cf ("x86/vdso: Add mremap hook to vm_special_mapping")
At this moment, vdso restoring code is disabled for arm/arm64 arch
in CRIU [2], so C/R is only working for !CONFIG_VDSO kernels. This patch is aimed to fix that.
The same hook may be introduced for arm64 kernel, but at this moment
arm64 vdso code is actively reworked by Kevin, so we can do it on top.
Separately, I've refactored arch_remap hook out from ppc64 [3].
[1]: https://marc.info/?i=1448455781-26660-1-git-send-email-cov at codeaurora.org [2]: https://github.com/xemul/criu/blob/master/Makefile#L39
[3]: https://marc.info/?i=20161027170948.8279-1-dsafonov at virtuozzo.com
--- arch/arm/kernel/vdso.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/arm/kernel/vdso.c +21 -0
@@ -54,8 +54,11 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, }; +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma);static struct vm_special_mapping vdso_text_mapping__ro_after_init = { .name ="[vdso]" , + .mremap = vdso_mremap, };struct elfinfo {
@@ -254,6 +257,24 @@ void arm_install_vdso(struct mm_struct *mm, unsigned long addr) mm->context.vdso = addr; } +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_total_pages -1 ) <<PAGE_SHIFT ; + +/* Disallow partial vDSO blob remap */ +if (vdso_size != new_size) +return -EINVAL ; + +if (WARN_ON_ONCE (current->mm != new_vma->vm_mm)) +return -EFAULT ; + + current->mm->context.vdso = new_vma->vm_start; + +return 0 ; +} +static void vdso_write_begin (struct vdso_data *vdata) { ++vdso_data->seq_count;
Signature · 1 line
2.10.2
Hi Dmitry,
Quoted 75 lines · Dmitry Safonov
Add
vdso_mremaphook which will fix context.vdso pointer aftermremap()
on vDSO vma. This is needed for correct landing after syscall execution. Primary goal of this is for CRIU on arm - we need to restore vDSO image at the exactly same place where the vma was in dumped application. With the help of this hook we'll move vDSO at the new position.
The CRIU code handles situations like when vDSO of dumped application
was different from vDSO on restoring system. This usally happens when some new symbols are being added to vDSO. In these situations CRIU inserts jump trampolines from old vDSO blob to new vDSO on restore. By that reason even if on restore vDSO blob lies on the same address as blob in dumped application - we still need to move it if it differs.There was previously attempt to add this functionality for arm64 by
arch_mremaphook [1], while this patch introduces this with minimal effort - the same way I've added it to x86:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping")At this moment, vdso restoring code is disabled for arm/arm64 arch
in CRIU [2], so C/R is only working for !CONFIG_VDSO kernels. This patch is aimed to fix that.
The same hook may be introduced for arm64 kernel, but at this moment
arm64 vdso code is actively reworked by Kevin, so we can do it on top.
Separately, I've refactoredarch_remaphook out from ppc64 [3].[1]: https://marc.info/?i=1448455781-26660-1-git-send-email-cov at codeaurora.org [2]: https://github.com/xemul/criu/blob/master/Makefile#L39
[3]: https://marc.info/?i=20161027170948.8279-1-dsafonov at virtuozzo.comCc Kevin Brodsky <[email protected]>Cc Christopher Covington <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Russell King <[email protected]>Cc Will Deacon <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc linux-mm at kvack.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm/kernel/vdso.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)arch/arm/kernel/vdso.c +14
-0@@ -54,8 +54,11 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, }; +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma);static struct vm_special_mapping vdso_text_mapping__ro_after_init = { .name ="[vdso]" , + .mremap = vdso_mremap, };struct elfinfo {@@ -254,6 +257,24 @@ void arm_install_vdso(struct mm_struct *mm, unsigned long addr) mm->context.vdso = addr; } +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_total_pages -1 ) <<PAGE_SHIFT ; + +/* Disallow partial vDSO blob remap */ +if (vdso_size != new_size) +return -EINVAL ; + +if (WARN_ON_ONCE (current->mm != new_vma->vm_mm))
arch/arm/kernel/vdso.c void arm_install_vdso(struct mm_struct *mm, unsigned long addr) · line 280
Quoted 10 lines
arch/arm/kernel/vdso.c +7
-0+return -EFAULT ; + + current->mm->context.vdso = new_vma->vm_start; + +return 0 ; +} +static void vdso_write_begin (struct vdso_data *vdata) { ++vdso_data->seq_count;
What do you think about putting this code somewhere generic (not under arch/*), so that powerpc and arm64 can reuse it once the cosmetic changes to make them compatible are made? My thought was that it could be defined underneath CONFIG_GENERIC_VDSO, which architectures could select as they became compatible.
Thanks,
Cov
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 86 lines · Christopher Covington
Hi Dmitry,
Quoted 83 lines · Dmitry Safonov
Add
vdso_mremaphook which will fix context.vdso pointer aftermremap()
on vDSO vma. This is needed for correct landing after syscall execution. Primary goal of this is for CRIU on arm - we need to restore vDSO image at the exactly same place where the vma was in dumped application. With the help of this hook we'll move vDSO at the new position.
The CRIU code handles situations like when vDSO of dumped application
was different from vDSO on restoring system. This usally happens when some new symbols are being added to vDSO. In these situations CRIU inserts jump trampolines from old vDSO blob to new vDSO on restore. By that reason even if on restore vDSO blob lies on the same address as blob in dumped application - we still need to move it if it differs.There was previously attempt to add this functionality for arm64 by
arch_mremaphook [1], while this patch introduces this with minimal effort - the same way I've added it to x86:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping")At this moment, vdso restoring code is disabled for arm/arm64 arch
in CRIU [2], so C/R is only working for !CONFIG_VDSO kernels. This patch is aimed to fix that.
The same hook may be introduced for arm64 kernel, but at this moment
arm64 vdso code is actively reworked by Kevin, so we can do it on top.
Separately, I've refactoredarch_remaphook out from ppc64 [3].[1]: https://marc.info/?i=1448455781-26660-1-git-send-email-cov at codeaurora.org [2]: https://github.com/xemul/criu/blob/master/Makefile#L39
[3]: https://marc.info/?i=20161027170948.8279-1-dsafonov at virtuozzo.comCc Kevin Brodsky <[email protected]>Cc Christopher Covington <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Russell King <[email protected]>Cc Will Deacon <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc linux-mm at kvack.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm/kernel/vdso.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)arch/arm/kernel/vdso.c +21
-0@@ -54,8 +54,11 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, }; +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma);static struct vm_special_mapping vdso_text_mapping__ro_after_init = { .name ="[vdso]" , + .mremap = vdso_mremap, };struct elfinfo {@@ -254,6 +257,24 @@ void arm_install_vdso(struct mm_struct *mm, unsigned long addr) mm->context.vdso = addr; } +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_total_pages -1 ) <<PAGE_SHIFT ; + +/* Disallow partial vDSO blob remap */ +if (vdso_size != new_size) +return -EINVAL ; + +if (WARN_ON_ONCE (current->mm != new_vma->vm_mm)) +return -EFAULT ; + + current->mm->context.vdso = new_vma->vm_start; + +return 0 ; +} +static void vdso_write_begin (struct vdso_data *vdata) {
Quoted 8 lines
arch/arm/kernel/vdso.c void arm_install_vdso(struct mm_struct *mm, unsigned long addr) · line 280
Quoted 2 lines
arch/arm/kernel/vdso.c +0
-0++vdso_data->seq_count;What do you think about putting this code somewhere generic (not under
arch/*), so that powerpc and arm64 can reuse it once the cosmetic changes to make them compatible are made? My thought was that it could be defined underneathCONFIG_GENERIC_VDSO, which architectures could select as they became compatible.
Hi Chistopher,
Well, I don't think we won something out of generalization of simple assignment for context.vdso pointer accross arches. And a need to rename vdso over arches for saving one single line?
Also I don't like a bit this arch_mremap hook and need to nullify vdso pointer.
But, anyway, I don't mind if your patches got applied instead - this unability to move vdso prevent's to support vdso vma C/R, as you know ;)
Signature · 1 line
Dmitry
Quoted 96 lines · Dmitry Safonov
Quoted 86 lines · Christopher Covington
Hi Dmitry,
Quoted 83 lines · Dmitry Safonov
Add
vdso_mremaphook which will fix context.vdso pointer aftermremap()
on vDSO vma. This is needed for correct landing after syscall execution. Primary goal of this is for CRIU on arm - we need to restore vDSO image at the exactly same place where the vma was in dumped application. With the help of this hook we'll move vDSO at the new position.
The CRIU code handles situations like when vDSO of dumped application
was different from vDSO on restoring system. This usally happens when some new symbols are being added to vDSO. In these situations CRIU inserts jump trampolines from old vDSO blob to new vDSO on restore. By that reason even if on restore vDSO blob lies on the same address as blob in dumped application - we still need to move it if it differs.There was previously attempt to add this functionality for arm64 by
arch_mremaphook [1], while this patch introduces this with minimal effort - the same way I've added it to x86:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping")At this moment, vdso restoring code is disabled for arm/arm64 arch
in CRIU [2], so C/R is only working for !CONFIG_VDSO kernels. This patch is aimed to fix that.
The same hook may be introduced for arm64 kernel, but at this moment
arm64 vdso code is actively reworked by Kevin, so we can do it on top.
Separately, I've refactoredarch_remaphook out from ppc64 [3].[1]: https://marc.info/?i=1448455781-26660-1-git-send-email-cov at codeaurora.org [2]: https://github.com/xemul/criu/blob/master/Makefile#L39
[3]: https://marc.info/?i=20161027170948.8279-1-dsafonov at virtuozzo.comCc Kevin Brodsky <[email protected]>Cc Christopher Covington <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Russell King <[email protected]>Cc Will Deacon <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc linux-mm at kvack.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm/kernel/vdso.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)arch/arm/kernel/vdso.c +21
-0@@ -54,8 +54,11 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, }; +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma);static struct vm_special_mapping vdso_text_mapping__ro_after_init = { .name ="[vdso]" , + .mremap = vdso_mremap, };struct elfinfo {@@ -254,6 +257,24 @@ void arm_install_vdso(struct mm_struct *mm, unsigned long addr) mm->context.vdso = addr; } +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_total_pages -1 ) <<PAGE_SHIFT ; + +/* Disallow partial vDSO blob remap */ +if (vdso_size != new_size) +return -EINVAL ; + +if (WARN_ON_ONCE (current->mm != new_vma->vm_mm)) +return -EFAULT ; + + current->mm->context.vdso = new_vma->vm_start; + +return 0 ; +} +static void vdso_write_begin (struct vdso_data *vdata) {Quoted 8 lines
arch/arm/kernel/vdso.c void arm_install_vdso(struct mm_struct *mm, unsigned long addr) · line 280
Quoted 2 lines
arch/arm/kernel/vdso.c +0
-0++vdso_data->seq_count;What do you think about putting this code somewhere generic (not under
arch/*), so that powerpc and arm64 can reuse it once the cosmetic changes to make them compatible are made? My thought was that it could be defined underneathCONFIG_GENERIC_VDSO, which architectures could select as they became compatible.
Quoted 4 lines
Hi Chistopher,
Well, I don't think we won something out of generalization of simple assignment for context.vdso pointer accross arches. And a need to rename vdso over arches for saving one single line?
I count 17 lines, which duplicated across 3 architectures becomes 51 lines. Presumable in the future other architectures will want CRIU support as well. Additionally, should fixes ever be required, fixing one implementation instead of 3+ is preferred.
Quoted 2 lines
Also I don't like a bit this
arch_mremaphook and need to nullify vdso pointer.
I'm sorry for the confusion but I in no way meant to imply that the arch_mremap hook should be carried forward. I fully agree that the function pointer in struct vm_special_mapping is the better way to go.
If you don't want to implement a version with vdso_mremap defined in a generic location (using it from struct vm_special_mapping), do you mind if I propose such a version?
Thanks,
Cov
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 110 lines · Christopher Covington
Quoted 96 lines · Dmitry Safonov
Quoted 86 lines · Christopher Covington
Hi Dmitry,
Quoted 83 lines · Dmitry Safonov
Add
vdso_mremaphook which will fix context.vdso pointer aftermremap()
on vDSO vma. This is needed for correct landing after syscall execution. Primary goal of this is for CRIU on arm - we need to restore vDSO image at the exactly same place where the vma was in dumped application. With the help of this hook we'll move vDSO at the new position.
The CRIU code handles situations like when vDSO of dumped application
was different from vDSO on restoring system. This usally happens when some new symbols are being added to vDSO. In these situations CRIU inserts jump trampolines from old vDSO blob to new vDSO on restore. By that reason even if on restore vDSO blob lies on the same address as blob in dumped application - we still need to move it if it differs.There was previously attempt to add this functionality for arm64 by
arch_mremaphook [1], while this patch introduces this with minimal effort - the same way I've added it to x86:
commitb059a453b1cf("x86/vdso: Add mremap hook tovm_special_mapping")At this moment, vdso restoring code is disabled for arm/arm64 arch
in CRIU [2], so C/R is only working for !CONFIG_VDSO kernels. This patch is aimed to fix that.
The same hook may be introduced for arm64 kernel, but at this moment
arm64 vdso code is actively reworked by Kevin, so we can do it on top.
Separately, I've refactoredarch_remaphook out from ppc64 [3].[1]: https://marc.info/?i=1448455781-26660-1-git-send-email-cov at codeaurora.org [2]: https://github.com/xemul/criu/blob/master/Makefile#L39
[3]: https://marc.info/?i=20161027170948.8279-1-dsafonov at virtuozzo.comCc Kevin Brodsky <[email protected]>Cc Christopher Covington <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Oleg Nesterov <[email protected]>Cc Russell King <[email protected]>Cc Will Deacon <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc linux-mm at kvack.orgCc Cyrill Gorcunov <[email protected]>Cc Pavel Emelyanov <[email protected]>Signed-off-by Dmitry Safonov <[email protected]>--- arch/arm/kernel/vdso.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)arch/arm/kernel/vdso.c +21
-0@@ -54,8 +54,11 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, }; +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma);static struct vm_special_mapping vdso_text_mapping__ro_after_init = { .name ="[vdso]" , + .mremap = vdso_mremap, };struct elfinfo {@@ -254,6 +257,24 @@ void arm_install_vdso(struct mm_struct *mm, unsigned long addr) mm->context.vdso = addr; } +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_total_pages -1 ) <<PAGE_SHIFT ; + +/* Disallow partial vDSO blob remap */ +if (vdso_size != new_size) +return -EINVAL ; + +if (WARN_ON_ONCE (current->mm != new_vma->vm_mm)) +return -EFAULT ; + + current->mm->context.vdso = new_vma->vm_start; + +return 0 ; +} +static void vdso_write_begin (struct vdso_data *vdata) {Quoted 8 lines
arch/arm/kernel/vdso.c void arm_install_vdso(struct mm_struct *mm, unsigned long addr) · line 280
Quoted 2 lines
arch/arm/kernel/vdso.c +0
-0++vdso_data->seq_count;What do you think about putting this code somewhere generic (not under
arch/*), so that powerpc and arm64 can reuse it once the cosmetic changes to make them compatible are made? My thought was that it could be defined underneathCONFIG_GENERIC_VDSO, which architectures could select as they became compatible.Quoted 4 lines
Hi Chistopher,
Well, I don't think we won something out of generalization of simple assignment for context.vdso pointer accross arches. And a need to rename vdso over arches for saving one single line?
I count 17 lines, which duplicated across 3 architectures becomes 51 lines. Presumable in the future other architectures will want CRIU support as well. Additionally, should fixes ever be required, fixing one implementation instead of 3+ is preferred.
Quoted 2 lines
Also I don't like a bit this
arch_mremaphook and need to nullify vdso pointer.
Quoted 7 lines
I'm sorry for the confusion but I in no way meant to imply that the
arch_mremaphook should be carried forward. I fully agree that the function pointer in structvm_special_mappingis the better way to go.If you don't want to implement a version with
vdso_mremapdefined in a generic location (using it from structvm_special_mapping), do you mind if I propose such a version?
Sure, do it, no objections.
Signature · 1 line
Dmitry
Russell King - ARM Linux
maintainerarch/arm/kernel/vdso.c static const struct vm_special_mapping vdso_data_mapping = { · line 58
Quoted 10 lines · Dmitry Safonov
arch/arm/kernel/vdso.c +2
-0@@ -54,8 +54,11 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, }; +static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma);
I'd much rather avoid this forward declaration. Is there any reason the function body can't be here?
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
Quoted 9 lines · Russell King - ARM Linux
Quoted 8 lines · Dmitry Safonov
arch/arm/kernel/vdso.c +0
-0@@ -54,8 +54,11 @@ static const struct vm_special_mapping vdso_data_mapping = { .pages = &vdso_data_page, };
Quoted 6 lines
arch/arm/kernel/vdso.c static const struct vm_special_mapping vdso_data_mapping = { · line 58
Quoted 2 lines
arch/arm/kernel/vdso.c +2
-0+static int vdso_mremap (const struct vm_special_mapping *sm, +struct vm_area_struct *new_vma);I'd much rather avoid this forward declaration. Is there any reason the function body can't be here?
Well, I didn't want it to be in the middle of static file variables - those looks nice at this moment just on top of the file. No other than that.
Signature · 1 line
Dmitry