Received: by 10.223.164.202 with SMTP id h10csp1183920wrb; Wed, 15 Nov 2017 14:46:37 -0800 (PST) X-Google-Smtp-Source: AGs4zMZn6RcWAsQyv2r5VLSdYU5NbG6njTolfvk6fUvkAwbAqFFSM3oiKDMGQDYqnuDcLPuvxvDw X-Received: by 10.101.93.141 with SMTP id f13mr16494194pgt.92.1510785997836; Wed, 15 Nov 2017 14:46:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510785997; cv=none; d=google.com; s=arc-20160816; b=wncRfYsbgKrBtsMiJlyIjlE7IJTmJ9Qti7wAGHYszr3S5aSTnCeL+4GUBTT2Ly+vyf c9r9mlf3rf5vB56rjqqY8SzhgG3iD3vvloZ5gy4LST7qtoZSlM82T4RADTPa3x/VEyIk bQv0jcDPMR3GZf6zAL3qiDGyjnMdLL1BydB+bW1JKK93V/nO5EDoO0FPHBCG7Fw1HDj3 HKBYFjC8jfOc+lgACRsnk6dFZ7uKLUD/76Z75F8PaoGSPL8qR5Wads6SqTIpa5mwZ3Rh 3NbykiFSmm7NJCwrEBkZaONJjb7nlo0JkmplLTzFh+8HMQQJ/78w++iRG8j9XqGnXqeD zCxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=bqseDCRjc7puD3+E8SvNOy/B95AsrOUJp+hFduotp54=; b=UA8UpF3EPCHxO2eMirt8TKUinl7wBL1D84wI2ARNPueTlzc2vpH5Hn1Rwvx9iY4JHu lcfifefBs3NQgWfrkXe9KHm4HFtpTUGhhaZXa41U4hpBsVL4l2IVZgho18JU6vbzzuZ7 Nmp14rF2z1hgFK093gR+ADiYzIpMyHQMB9creo8QzXA0JjTAwqXIxkfGW3J4wKgSlsR1 AWLFBYmqXl41GYHyBIh2twQM5O1R+E8oV1Bm7Pnb9WM9jq8aFbQISCM0q+zzQ7BJ6U79 zXwKlQAVs38W4F71zfyG0+UZlxvXVr/ZEzyjkVjaZBT1X2qwrqWW8GnIg2Ntwj9n+Cju gwMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=SXQ+975K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l70si15414548pge.568.2017.11.15.14.46.25; Wed, 15 Nov 2017 14:46:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=SXQ+975K; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933199AbdKOWHO (ORCPT + 89 others); Wed, 15 Nov 2017 17:07:14 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:42187 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933009AbdKOWGn (ORCPT ); Wed, 15 Nov 2017 17:06:43 -0500 Received: by mail-io0-f194.google.com with SMTP id u42so3169411ioi.9 for ; Wed, 15 Nov 2017 14:06:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bqseDCRjc7puD3+E8SvNOy/B95AsrOUJp+hFduotp54=; b=SXQ+975KH8KZ9/4s3K5m34Y6QmQMFLnfek2N00dlIv8yNUSKX5xxw+2xMZDeMdZvIF Gv9lUCY/5wEcbcWI9iHdT7h6FMcgaZPaETTx/mGwvJr9rkIzS7qRv8mE3wwRVGinwSo/ +HZzqi0zKGhvujGAedWKsbJdNOz/bzupyyffc+qD1dRdo1hVEnsyg1oIdKKpodXzJvkX /cZxBkLNknEkb8udV8c0HiLca+X7Uuuhl5eR2E+Ba9Zlvi96fMcoH2jvTbIw6v8Y02O/ QrvoNZEPp2pT1LZvt3Vlrx68uRFBgWVYUp2OGfhWX9gCEwgD7qFwYoyD+A4pZqya4/Dx eKbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bqseDCRjc7puD3+E8SvNOy/B95AsrOUJp+hFduotp54=; b=f0P++k76+lVKAFJ4e2KKz73/q4K+c1XX/mj0XjDfI8NYZBKZYNbJ1hZ+ehM8B2uv18 NV0VekzrzqZRXzuP4M+Z144+RLfrZD9O1TXD/7D4HIgApjRMc1ZpkKZ42Apa+83Cv7PI 8f71kuu5mgfelw5le6GiGdDe0Azx0p+HwVwr35Vv9U+NzZ3VU8npsCC0Xtb/Nf4UPA0P N6uCYkFxUNZD3o76zTyUEuAkWewJAUD5XI15n+66yVOM/c6f0FpbZZqVPb/on4O/NnCQ sc8GbfLaSdaf2XaHY8bBscMVFRzJhCGZDyjO1boq9JbxNJIRsXwNXpoOJxlTrmK/ow47 7MhQ== X-Gm-Message-State: AJaThX5FClH1Mq5k/v12KYfNvyN5mGRi2xRixCi5ekuEh6bA65sAholy HRCQkp4B6++ImsDX08Z+uOxbzoC6Egc= X-Received: by 10.107.142.72 with SMTP id q69mr1816093iod.205.1510783602356; Wed, 15 Nov 2017 14:06:42 -0800 (PST) Received: from nebulus.mtv.corp.google.com ([2620:0:1000:1612:b4fb:6752:f21f:3502]) by smtp.gmail.com with ESMTPSA id 14sm5224751itj.34.2017.11.15.14.06.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Nov 2017 14:06:41 -0800 (PST) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Cc: Kevin Brodsky , Mark Salyzyn , Catalin Marinas , Will Deacon , Dave Martin , "Eric W. Biederman" , linux-arm-kernel@lists.infradead.org, John Stultz , Dmitry Safonov , Kees Cook Subject: [PATCH 3/6] arm64: Refactor vDSO init/setup Date: Wed, 15 Nov 2017 14:05:13 -0800 Message-Id: <20171115220529.14458-4-salyzyn@android.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog In-Reply-To: <20171115220529.14458-1-salyzyn@android.com> References: <20171115220529.14458-1-salyzyn@android.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kevin Brodsky Move the logic for setting up mappings and pages for the vDSO into static functions. This makes the vDSO setup code more consistent with the compat side and will allow to reuse it for the future compat vDSO. Signed-off-by: Kevin Brodsky Signed-off-by: Mark Salyzyn Cc: Catalin Marinas Cc: Will Deacon Cc: Dave Martin Cc: "Eric W. Biederman" Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- arch/arm64/kernel/vdso.c | 118 ++++++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 48 deletions(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 26d510474ffa..48b4111a933f 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -39,8 +39,11 @@ #include #include -extern char vdso_start[], vdso_end[]; -static unsigned long vdso_pages __ro_after_init; +struct vdso_mappings { + unsigned long num_code_pages; + struct vm_special_mapping data_mapping; + struct vm_special_mapping code_mapping; +}; /* * The vDSO data page. @@ -164,95 +167,114 @@ static int vdso_mremap(const struct vm_special_mapping *sm, return 0; } -static struct vm_special_mapping vdso_spec[2] __ro_after_init = { - { - .name = "[vvar]", - }, - { - .name = "[vdso]", - .mremap = vdso_mremap, - }, -}; - -static int __init vdso_init(void) +static int __init vdso_mappings_init(const char *name, + const char *code_start, + const char *code_end, + struct vdso_mappings *mappings) { - int i; + unsigned long i, vdso_page; struct page **vdso_pagelist; unsigned long pfn; - if (memcmp(vdso_start, "\177ELF", 4)) { - pr_err("vDSO is not a valid ELF object!\n"); + if (memcmp(code_start, "\177ELF", 4)) { + pr_err("%s is not a valid ELF object!\n", name); return -EINVAL; } - vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT; - pr_info("vdso: %ld pages (%ld code @ %p, %ld data @ %p)\n", - vdso_pages + 1, vdso_pages, vdso_start, 1L, vdso_data); - - /* Allocate the vDSO pagelist, plus a page for the data. */ - vdso_pagelist = kcalloc(vdso_pages + 1, sizeof(struct page *), - GFP_KERNEL); + vdso_pages = (code_end - code_start) >> PAGE_SHIFT; + pr_info("%s: %ld pages (%ld code @ %p, %ld data @ %p)\n", + name, vdso_pages + 1, vdso_pages, code_start, 1L, + vdso_data); + + /* + * Allocate space for storing pointers to the vDSO code pages + the + * data page. The pointers must have the same lifetime as the mappings, + * which are static, so there is no need to keep track of the pointer + * array to free it. + */ + vdso_pagelist = kmalloc_array(vdso_pages + 1, sizeof(struct page *), + GFP_KERNEL); if (vdso_pagelist == NULL) return -ENOMEM; /* Grab the vDSO data page. */ vdso_pagelist[0] = phys_to_page(__pa_symbol(vdso_data)); - /* Grab the vDSO code pages. */ - pfn = sym_to_pfn(vdso_start); + pfn = sym_to_pfn(code_start); for (i = 0; i < vdso_pages; i++) vdso_pagelist[i + 1] = pfn_to_page(pfn + i); - vdso_spec[0].pages = &vdso_pagelist[0]; - vdso_spec[1].pages = &vdso_pagelist[1]; + /* Populate the special mapping structures */ + mappings->data_mapping = (struct vm_special_mapping) { + .name = "[vvar]", + .pages = &vdso_pagelist[0], + }; + + mappings->code_mapping = (struct vm_special_mapping) { + .name = "[vdso]", + .pages = &vdso_pagelist[1], + }; + mappings->num_code_pages = vdso_pages; return 0; } + +static struct vdso_mappings vdso_mappings __ro_after_init; + +static int __init vdso_init(void) +{ + extern char vdso_start[], vdso_end[]; + + return vdso_mappings_init("vdso", vdso_start, vdso_end, + &vdso_mappings); +} arch_initcall(vdso_init); -int arch_setup_additional_pages(struct linux_binprm *bprm, - int uses_interp) +static int vdso_setup(struct mm_struct *mm, + const struct vdso_mappings *mappings) { - struct mm_struct *mm = current->mm; unsigned long vdso_base, vdso_text_len, vdso_mapping_len; void *ret; - vdso_text_len = vdso_pages << PAGE_SHIFT; + vdso_text_len = mappings->num_code_pages << PAGE_SHIFT; /* Be sure to map the data page */ vdso_mapping_len = vdso_text_len + PAGE_SIZE; - if (down_write_killable(&mm->mmap_sem)) - return -EINTR; vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0); - if (IS_ERR_VALUE(vdso_base)) { - ret = ERR_PTR(vdso_base); - goto up_fail; - } + if (IS_ERR_VALUE(vdso_base)) + ret = PTR_ERR_OR_ZERO(ERR_PTR(vdso_base)); + ret = _install_special_mapping(mm, vdso_base, PAGE_SIZE, VM_READ|VM_MAYREAD, - &vdso_spec[0]); + &mappings->data_mapping); if (IS_ERR(ret)) - goto up_fail; + return PTR_ERR_OR_ZERO(ret); vdso_base += PAGE_SIZE; - mm->context.vdso = (void *)vdso_base; ret = _install_special_mapping(mm, vdso_base, vdso_text_len, VM_READ|VM_EXEC| VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC, - &vdso_spec[1]); - if (IS_ERR(ret)) - goto up_fail; + &mappings->code_mapping); + if (!IS_ERR(ret)) + mm->context.vdso = (void *)vdso_base; + + return PTR_ERR_OR_ZERO(ret); +} +int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) +{ + struct mm_struct *mm = current->mm; + int ret; - up_write(&mm->mmap_sem); - return 0; + if (down_write_killable(&mm->mmap_sem)) + return -EINTR; + + ret = vdso_setup(mm, &vdso_mappings); -up_fail: - mm->context.vdso = NULL; up_write(&mm->mmap_sem); - return PTR_ERR(ret); + return ret; } /* -- 2.15.0.448.gf294e3d99a-goog From 1584164851926099119@xxx Wed Nov 15 20:22:12 +0000 2017 X-GM-THRID: 1584164851926099119 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread