From patchwork Tue Nov 1 17:22:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 9407753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCC5760585 for ; Tue, 1 Nov 2016 17:27:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD85429A84 for ; Tue, 1 Nov 2016 17:27:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF27829A86; Tue, 1 Nov 2016 17:27:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E668C29A84 for ; Tue, 1 Nov 2016 17:27:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1cp8-0007B8-Mo; Tue, 01 Nov 2016 17:26:10 +0000 Received: from mail-eopbgr30105.outbound.protection.outlook.com ([40.107.3.105] helo=EUR03-AM5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1cp4-00077i-GP for linux-arm-kernel@lists.infradead.org; Tue, 01 Nov 2016 17:26:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8WRgN8rn+Q+NVjfdHpfANH1TFnJfY/XFPTXy/5G4n+I=; b=ZP9ZEpiZQC9+jo42nDBCNjEGPsmNecufOdWo/kKnOQwokBhUcriyIBZ7xqqPG55rPvgvhlseZMsIsge5suTeF86BT7AVhrKgGhwcDnbz5LCIoDvJmxZS0Hd2NJFeyW92O06opzRw3kg9/rpe4gPVzxLrsCvZeNiVLA9EdzXIS40= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=dsafonov@virtuozzo.com; Received: from dsafonov.sw.ru (195.214.232.10) by VI1PR0801MB1741.eurprd08.prod.outlook.com (10.168.67.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Tue, 1 Nov 2016 17:25:40 +0000 From: Dmitry Safonov To: Subject: [PATCH] arm/vdso: introduce vdso_mremap hook Date: Tue, 1 Nov 2016 20:22:14 +0300 Message-ID: <20161101172214.2938-1-dsafonov@virtuozzo.com> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: HE1PR01CA0074.eurprd01.prod.exchangelabs.com (10.165.170.170) To VI1PR0801MB1741.eurprd08.prod.outlook.com (10.168.67.19) X-MS-Office365-Filtering-Correlation-Id: 0ae52758-364d-48b6-3537-08d4027c1b0d X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1741; 2:GuUj27XpeoLR1Jfa9PsaHXCvrVtkwJ1fCT4JtpyLCvcIYYOZuVN6O/fbciQ0AD1ZHTxGspU46DfzKa7nayoC8MbKtcTF6lNlwx/oiJNgciyIpAyhq39HXtc+4a+97G6T9iO3jFa1ThzAkcj4nBpcSeqIl2XnhrsAv03s/lOk/9ghUQROu20qb49S+ZYAneRfTdT+z0nRyjhJzcv/lu67XQ==; 3:2G7Xv6OkNDzD4itq2d0mp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Ri/t00gXO59WcynddGG2NBu4nkzkSiILIklrTAQxiIXPeqbwiQ1olSIDQDkEsm57CY1wpP+E/BRYm3uBINaJxsBwXIZrlsbgVmhP/5GFkNbvfDL3XCIR3s/QFtOhTMLO8UXajz4TzpyxIIODEsBfYfD/6lDnXiRkXUf/PdemCr+Cnw97L50iKBPSUVNl86/e8WDm4qeMWpl+qx3zXbYDzl0xCcCTKRDuaJUU9gN7BZGE4658ONC1n7+7bgQPpG1LBYAlccmBNDGd8fQpY23jjcRXqkCW7cbObVba385SD0ioBWsE9ExpA8p5zDv8dYxQWwJ4cmYwHpailTSbgbbPaLaoq3APMHnOc0VQaNVjD0R6gR2YGBoaC1T3rb2vrkDxNAtCORbIgpFSFGl2dNzNTkVDQZi9 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(166708455590820)(258649278758335); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6042046)(6043046); SRVR:VI1PR0801MB1741; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1741; X-Forefront-PRVS: 01136D2D90 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(5660300001)(77096005)(101416001)(50226002)(92566002)(36756003)(15975445007)(47776003)(68736007)(6916009)(42186005)(4001430100002)(53416004)(110136003)(7416002)(86362001)(586003)(105586002)(33646002)(2351001)(66066001)(229853001)(5003940100001)(19580395003)(81166006)(81156014)(305945005)(106356001)(19580405001)(50466002)(107886002)(6116002)(7846002)(7736002)(50986999)(48376002)(69596002)(8676002)(189998001)(97736004)(1076002)(2906002)(3846002)(6666003)(4326007)(6606295002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1741; H:dsafonov.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1741; 23:rwFosx4Dvi9nvphDuVfD2AJuQC2aJd+WXFcg4tM?= =?us-ascii?Q?MncelPNkJNY7PsY+MpPRt3j71PLHuUxrPpy57NhRTtSHJzEnkCco1Rpb3gxv?= =?us-ascii?Q?fYnBOfFlEK4QoqtC0YrZXOGbYCCpODnA0OxorNvB1G5C8Xlui+Nk5SXd2Hi2?= =?us-ascii?Q?l3OACBEuEiIIHJQf0B/dylkPXiwtdVBjvGv1CQauDNCgdSuXzcgQkMSmvHj6?= =?us-ascii?Q?/PfHXaiC6PKr80UitF5rd1u36NwvJgpMqVxv05lCKk8g3JHYOeDfMWU2zzjI?= =?us-ascii?Q?wiu37mziSECKUthOirxxomqzHOy1Iq4lNdRFd30/jtNK8X75pJEA/qF4Al7Q?= =?us-ascii?Q?yjKCT3jaSjwT5piUxUT6/VcJUcyKDD/QC83vNd0q+QYrXh84oXs1uyNo8ZwB?= =?us-ascii?Q?EMXrR8V0+/abfEcfJIdlb9PDmqTjqoSga60i3PnR8nzX42RM9fg1Fp2CK8aq?= =?us-ascii?Q?lfW/Lst7rgUikMxqoScKA+vagKOrLYhg1jaotCsmdvBaJv8Ci+d5m6HfO3pC?= =?us-ascii?Q?5+K7yp/d+dPbRokACgUjC7BTAvWG2GisSv/WsvnvBb/B5LbnJ5SLTtFx6zD9?= =?us-ascii?Q?l0SFi0lmURfnNu5X7OaDvrPjEVKILmZ/WKRNb9zbJiEkwfjSJC5hVxlDrhnl?= =?us-ascii?Q?R6Kqtwgj9EIqM+jjpAEqB1VwxXByTgl6mH9rGTxzGC/631R+8yYEKvaKcfNm?= =?us-ascii?Q?G+MBVqMbPu9zVzBoXlddHIGSFxBuxe2vKkyAwy+gUIow4zBGMXLb9DpI+Fc4?= =?us-ascii?Q?4WxTffBQVgY3zt7IRHP7r2TXoQSYBIOPSD4y3xRdJYV4pHWtjxOSvXEURffE?= =?us-ascii?Q?s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HSJuCBREo7zxNGZ40SmuaRHnuQB4GGwvZzABnJbnw=; 24:Bvp/HIZ8Kbh4nNy/viDVUKAyAdK2lQ1Fgz1DowzU2Vgh0G/Z6HZ6PFF8eQROAASkzdLRR+wIwIo0pBdnSMxFPl873qzQ6suq+6no+jGYwHE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1741; 7:xRDDuz6+nW4765rJCn9bcdqb1/uyWjfpTGjErCakLJEhHGtqv7UXYepXKW/JYnRtfPtrF2DqbxPj24EalAZq3oOk3ay+l3RvFXkDN/eQnz/eJKr6PB7lvW2UnfGqtLiiL4UYBFBprwdLUELW1sk+R/N/ksS6/0XYgOYaZto9yjbrRC757N9CFCLFsAXXF4SjcUzVSmpBpbsoExmlq3ulmQf3wCHOCCVdH2dTk26cEbXLEQ53zbywADS+wO22TKF058S8jK8sebV9ibsLRFuDLrDmzefRs/wj3sN2ziRY8B8cQIBWONoWPvN4zb14bmWoAPkecWaf/ia6XaVLI5IMEbie1gRb13IsoaQAXrE4hIQ=; 20:/kciKMmx2Hh4Z1wZswJSt5JHNrSAHfncmdpf0h+jWjudhi3bM+b4MVYbwHc/k5jGf42p5ryraBHXjZ8Ibr2zTFwrxsq8ckKQHY2LOrWFhuv2X4TzYH1fAEn9Ffw/Sn8c/yo2FU2PoNCY0eaE3RGxm07YEYdUotRD3Rks4vsjYzI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2016 17:25:40.1838 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1741 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161101_102607_097262_61ED790F X-CRM114-Status: GOOD ( 14.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dmitry Safonov , Kevin Brodsky , 0x7f454c46@gmail.com, Oleg Nesterov , Will Deacon , Andy Lutomirski , linux-mm@kvack.org, Christopher Covington , Cyrill Gorcunov , Russell King , linux-arm-kernel@lists.infradead.org, Pavel Emelyanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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;