Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932657AbcKGRAd (ORCPT ); Mon, 7 Nov 2016 12:00:33 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:50580 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932359AbcKGRAc (ORCPT ); Mon, 7 Nov 2016 12:00:32 -0500 DMARC-Filter: OpenDMARC Filter v1.3.1 smtp.codeaurora.org A21276172C Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=pass smtp.mailfrom=cov@codeaurora.org Subject: Re: [PATCH] arm/vdso: introduce vdso_mremap hook To: Dmitry Safonov , linux-kernel@vger.kernel.org References: <20161101172214.2938-1-dsafonov@virtuozzo.com> Cc: 0x7f454c46@gmail.com, Kevin Brodsky , Andy Lutomirski , Oleg Nesterov , Russell King , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Cyrill Gorcunov , Pavel Emelyanov , Nathan Lynch , Will Deacon , Michael Ellerman From: Christopher Covington Message-ID: <0b41c28b-20ef-332f-d8d6-e381e05b8252@codeaurora.org> Date: Mon, 7 Nov 2016 12:00:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: <20161101172214.2938-1-dsafonov@virtuozzo.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4075 Lines: 102 Hi Dmitry, On 11/01/2016 01:22 PM, Dmitry Safonov wrote: > 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 by > arch_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@codeaurora.org > [2]: https://github.com/xemul/criu/blob/master/Makefile#L39 > [3]: https://marc.info/?i=20161027170948.8279-1-dsafonov@virtuozzo.com > > Cc: Kevin Brodsky > Cc: Christopher Covington > Cc: Andy Lutomirski > Cc: Oleg Nesterov > Cc: Russell King > Cc: Will Deacon > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-mm@kvack.org > Cc: Cyrill Gorcunov > Cc: Pavel Emelyanov > Signed-off-by: Dmitry Safonov > --- > arch/arm/kernel/vdso.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c > index 53cf86cf2d1a..d1001f87c2f6 100644 > --- a/arch/arm/kernel/vdso.c > +++ b/arch/arm/kernel/vdso.c > @@ -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; > 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 -- 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.