From patchwork Wed Nov 14 13:39:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10682649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E865139B for ; Wed, 14 Nov 2018 13:39:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ECE82B4AB for ; Wed, 14 Nov 2018 13:39:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82ABA2B4D7; Wed, 14 Nov 2018 13:39:46 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF0B42B4AB for ; Wed, 14 Nov 2018 13:39:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A6126B0008; Wed, 14 Nov 2018 08:39:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 255C36B000D; Wed, 14 Nov 2018 08:39:44 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F6EA6B000C; Wed, 14 Nov 2018 08:39:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id D79996B0008 for ; Wed, 14 Nov 2018 08:39:43 -0500 (EST) Received: by mail-oi1-f200.google.com with SMTP id h135-v6so9221459oic.2 for ; Wed, 14 Nov 2018 05:39:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=x96SNRincEsQHA31onatbkti/QWr/6e+l0/n3efdPs4=; b=N8wjPnzzOJfejKDGoPCEJMWHEPb0t68kYuJ1kdi1ZfE0eqBcyplpHIZCmqF2vIdGuM XxK0CubY+t7odX1NdQnlWu7S5PWwfH5uVZglEtCBtNfVDSsALcdbARzB+gB/zMXTLsPd +G2YK+VscVWae+LYjWJ0WgreldXcnycF7AbzM80lre6NZAPmPBgQblTJSNjzyBIvrKJt T20H8tTSQuqAXGGqVaRk1Yftr/rO863ZB5Jm241/tnSeFUPzeMdsjLZRCMzXD4qX/GVP 3dS5AABGv1O/MIqgviQwflegf4cztFZbOXB6G96y8wT/pyNtW55fwkdbbKt5Uz/p53H3 JxQA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com X-Gm-Message-State: AGRZ1gJBt8MzOG5ZIJND4Geezq7T+Ui4egGbLnaQLLJH9Xi08Bj9x+Mr 9HsVvxr6hdnIdaDk/Rei5vj7r0odhibXe4LYMQSz/Iw6oi0FYJYQJx0HDN7usmAehVBkvm5ZwWj 2vYsmlteinYbnx2l+WeXcqCn5zcVvsbRIEcfipfrQzRkM6prv0Pa0ULOUPJK7yNzhpA== X-Received: by 2002:a9d:59d0:: with SMTP id u16mr1101713otg.265.1542202783547; Wed, 14 Nov 2018 05:39:43 -0800 (PST) X-Google-Smtp-Source: AJdET5c/8TqEfKRKwA907Ct2IAHUzbj6V4I/9BpRAarzU0JWqM0rB9dVEH6f/TzptprbPBGHa5Rj X-Received: by 2002:a9d:59d0:: with SMTP id u16mr1101651otg.265.1542202782273; Wed, 14 Nov 2018 05:39:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542202782; cv=none; d=google.com; s=arc-20160816; b=MTb9pbqdPUb04df4Vq7wc0xDXFAtTe8Ird9jGYcRHa51uvWPwwMwMxf2j1gE3Fi8QL 3hY/3APWnanVaAV7wbwLKjA4DMaqcWuvGX56irS41iAk+4p3n8RkCi8rbjDrW7c9anRe SzLjN+o61/Id+G3/CEC0tF1YyV5qcqc64DCRztgnWF5yJCzDXioVLT0soemHyOmJljpk OYsv/N5yz/e7b57LfOC53PPpwTtlim7S3vhhis++UjxN3rAGqPIvghKFnuW5ZQB8QSdk gyRbI6AeqfEvpp+apRVkXH/YAn5MwvQxPt8VCV+lu3aV016iHyO6PGVuB3mKLWSV4A8C Q+7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=x96SNRincEsQHA31onatbkti/QWr/6e+l0/n3efdPs4=; b=gX/EknMiowsQd/g2bJvimQ4Qt6zA3gQ7nrll4IDSS2K7Eol63vK+19YeJpO3peq1M4 uCPiQgirDpYP2wG12cQzTOaGilfRm0qhRr2+QZfKEAnbXowf64gBZxprORA5ac+sOrDU EcRun7MmDyL7khM80Pp6zNc2L7Mqw5U5ClGUTx4aOZnaNHCeqvO4LP5KC6deOvfPKVu0 HCXE5rUO4WZI6UAS4SlRyLUEgzwxM6htGQcIN7RRjaZ6RlsnvqvvQneBvOZt/VU5Rf7H 9JyWONirEn8u0G8FgG8MxoYZ1zfbEgEpghJ2QoPI2MDyTqDYuxU1B9XgTIWeWtCF6v8B rB5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id e3si10688097otl.176.2018.11.14.05.39.41 for ; Wed, 14 Nov 2018 05:39:42 -0800 (PST) Received-SPF: pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7B3CE1596; Wed, 14 Nov 2018 05:39:41 -0800 (PST) Received: from capper-debian.arm.com (unknown [10.37.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 241053F718; Wed, 14 Nov 2018 05:39:39 -0800 (PST) From: Steve Capper To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, jcm@redhat.com, Steve Capper Subject: [PATCH V3 1/5] mm: mmap: Allow for "high" userspace addresses Date: Wed, 14 Nov 2018 13:39:16 +0000 Message-Id: <20181114133920.7134-2-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181114133920.7134-1-steve.capper@arm.com> References: <20181114133920.7134-1-steve.capper@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for "high" userspace addresses that are optionally supported on the system and have to be requested via a hint mechanism ("high" addr parameter to mmap). Architectures such as powerpc and x86 achieve this by making changes to their architectural versions of arch_get_unmapped_* functions. However, on arm64 we use the generic versions of these functions. Rather than duplicate the generic arch_get_unmapped_* implementations for arm64, this patch instead introduces two architectural helper macros and applies them to arch_get_unmapped_*: arch_get_mmap_end(addr) - get mmap upper limit depending on addr hint arch_get_mmap_base(addr, base) - get mmap_base depending on addr hint If these macros are not defined in architectural code then they default to (TASK_SIZE) and (base) so should not introduce any behavioural changes to architectures that do not define them. Signed-off-by: Steve Capper Reviewed-by: Catalin Marinas --- Changed in V3, commit log cleared up, explanation given for why core code change over just architectural change --- mm/mmap.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 6c04292e16a7..7bb64381e77c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2066,6 +2066,15 @@ unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) return gap_end; } + +#ifndef arch_get_mmap_end +#define arch_get_mmap_end(addr) (TASK_SIZE) +#endif + +#ifndef arch_get_mmap_base +#define arch_get_mmap_base(addr, base) (base) +#endif + /* Get an address range which is currently unmapped. * For shmat() with addr=0. * @@ -2085,8 +2094,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, struct mm_struct *mm = current->mm; struct vm_area_struct *vma, *prev; struct vm_unmapped_area_info info; + const unsigned long mmap_end = arch_get_mmap_end(addr); - if (len > TASK_SIZE - mmap_min_addr) + if (len > mmap_end - mmap_min_addr) return -ENOMEM; if (flags & MAP_FIXED) @@ -2095,7 +2105,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, if (addr) { addr = PAGE_ALIGN(addr); vma = find_vma_prev(mm, addr, &prev); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && + if (mmap_end - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vm_start_gap(vma)) && (!prev || addr >= vm_end_gap(prev))) return addr; @@ -2104,7 +2114,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, info.flags = 0; info.length = len; info.low_limit = mm->mmap_base; - info.high_limit = TASK_SIZE; + info.high_limit = mmap_end; info.align_mask = 0; return vm_unmapped_area(&info); } @@ -2124,9 +2134,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, struct mm_struct *mm = current->mm; unsigned long addr = addr0; struct vm_unmapped_area_info info; + const unsigned long mmap_end = arch_get_mmap_end(addr); /* requested length too big for entire address space */ - if (len > TASK_SIZE - mmap_min_addr) + if (len > mmap_end - mmap_min_addr) return -ENOMEM; if (flags & MAP_FIXED) @@ -2136,7 +2147,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, if (addr) { addr = PAGE_ALIGN(addr); vma = find_vma_prev(mm, addr, &prev); - if (TASK_SIZE - len >= addr && addr >= mmap_min_addr && + if (mmap_end - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vm_start_gap(vma)) && (!prev || addr >= vm_end_gap(prev))) return addr; @@ -2145,7 +2156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; info.low_limit = max(PAGE_SIZE, mmap_min_addr); - info.high_limit = mm->mmap_base; + info.high_limit = arch_get_mmap_base(addr, mm->mmap_base); info.align_mask = 0; addr = vm_unmapped_area(&info); @@ -2159,7 +2170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, VM_BUG_ON(addr != -ENOMEM); info.flags = 0; info.low_limit = TASK_UNMAPPED_BASE; - info.high_limit = TASK_SIZE; + info.high_limit = mmap_end; addr = vm_unmapped_area(&info); } From patchwork Wed Nov 14 13:39:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10682651 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 148D9139B for ; Wed, 14 Nov 2018 13:39:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0629D2B4AB for ; Wed, 14 Nov 2018 13:39:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE5952B4E0; Wed, 14 Nov 2018 13:39:48 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F63D2B4AB for ; Wed, 14 Nov 2018 13:39:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7112B6B000C; Wed, 14 Nov 2018 08:39:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6C1136B000D; Wed, 14 Nov 2018 08:39:45 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 564686B000E; Wed, 14 Nov 2018 08:39:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by kanga.kvack.org (Postfix) with ESMTP id 2E7826B000C for ; Wed, 14 Nov 2018 08:39:45 -0500 (EST) Received: by mail-ot1-f72.google.com with SMTP id c33so11005108otb.18 for ; Wed, 14 Nov 2018 05:39:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=pLjC0Gkoap3oEyvo0Prs1yFuJj+eQQIyQgvh8CQZhbI=; b=aXCN65omvV5aotLpyIsomitWJ6atFG1yqusY6AVBugpgHz+rpI61Bj4/Axq9biInca 2Wf79A7V5e8UuAWollpS19DKSAO7nPXVFHjZ8duOcT6uZlRCsOjtYu7bwXtFl9iMYa07 ocsQzlfhFPSFh1PXuT4ejxhXx6tnttYcA6DnGnbmIvE/GiyR95JjlOydUqFsxUqu63qt Z1YTQelllE3bb8bWCi1zzi2bZOQmvy8N0rPJgx0z/TA0jMNwv67zpCnrhiAyNao+MNDv RuvY8FVC+F/RUIu5VIG27KX+lt7GCuBv3C4+pEVjLGlteX8qmU6skBgSH0YGyzN9alWR sBVg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com X-Gm-Message-State: AGRZ1gIOa2dVs0x2O9TkCBM3KXJlN9kEDtDhKWUm8JPVsCJizwoPMw27 tWHiJzopCTMWE9Y39Jvjh33LMy/RpFv7grgsvhmTFLy89t8FqfzcsN1qN2B92/o3mZXACaS+8Vq kp5Eh7BV2xMyLyTRAnMIa3iQmn+kuADqpszJA/BmJfAnRrQcJdKrP8HZvuOWPz/i2TQ== X-Received: by 2002:a9d:6490:: with SMTP id g16mr1022304otl.141.1542202784922; Wed, 14 Nov 2018 05:39:44 -0800 (PST) X-Google-Smtp-Source: AJdET5eQZPUQu9atWiFGcImuqgSNg7rv90wQFh5gf3J4ArFdXzu+ys0qoLRxZGI8Mf5wFn9jcBKW X-Received: by 2002:a9d:6490:: with SMTP id g16mr1022269otl.141.1542202783928; Wed, 14 Nov 2018 05:39:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542202783; cv=none; d=google.com; s=arc-20160816; b=QvE5unlDLTCkwYGLZbVVe1rMcKQO9sBJURv88ojtkTM2zxhJCSolWVq7zGqekdxbXf u8sEyoJxtPDT2GgP6jE58ecQHx17QzsJ4AkQln4mOuN6s8DLQU2zQuupfGgupXREX/fF lKqpzocsCUIL3Vy+MAyFSfOAzRIRSE/Trg450HlFJK/nNJSyXroYGjpagaSCrc5LthOD B8lE8jFCeO8mUUxvHfhHZ3waC5gSzQXKYvZwD5nAcz7rBz25WhST2+lNgCPMEbBSPupC IBoNgyFKxeniZUKHQruHf2PeFLdyRMAt7nyopoywLY0KaQazFynz47t5q9pMRzFleBsc IN5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=pLjC0Gkoap3oEyvo0Prs1yFuJj+eQQIyQgvh8CQZhbI=; b=pUTkQcIeJn5L6x7LN7RXZYawOmPnaJTMCDPre+g2CS8Nfdk0BK7p3yVEj2YIo4KsMq jGBW2NrBj6RNvVghnih68L8NGLxmXaP/uPciPheJ5dtS9V3RscXoUZYohI6lkXhCCOsx ZZY4j9UdX3hrwwW0v6fLhmGGFY1/Tr1QsZC00Gdzm7vPb8AtCTypYgMZleDjER2lepsU lnEs8Lhl80LYVCXI25d48X1xoM4Cru9I4S+rUo/wch+VWLEAtuXZbGXEXnWUxcBzFco8 r5fJBNZ9GZW1eK5hBCRRc66Vqx8JFEuQvD00PSEqZRqEa7eZGAf+zkWJdAwEUdslRSkR Vx6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id j6-v6si9309198oiw.131.2018.11.14.05.39.43 for ; Wed, 14 Nov 2018 05:39:43 -0800 (PST) Received-SPF: pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2635E15AB; Wed, 14 Nov 2018 05:39:43 -0800 (PST) Received: from capper-debian.arm.com (unknown [10.37.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C4DE53F718; Wed, 14 Nov 2018 05:39:41 -0800 (PST) From: Steve Capper To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, jcm@redhat.com, Steve Capper Subject: [PATCH V3 2/5] arm64: mm: Introduce DEFAULT_MAP_WINDOW Date: Wed, 14 Nov 2018 13:39:17 +0000 Message-Id: <20181114133920.7134-3-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181114133920.7134-1-steve.capper@arm.com> References: <20181114133920.7134-1-steve.capper@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We wish to introduce a 52-bit virtual address space for userspace but maintain compatibility with software that assumes the maximum VA space size is 48 bit. In order to achieve this, on 52-bit VA systems, we make mmap behave as if it were running on a 48-bit VA system (unless userspace explicitly requests a VA where addr[51:48] != 0). On a system running a 52-bit userspace we need TASK_SIZE to represent the 52-bit limit as it is used in various places to distinguish between kernelspace and userspace addresses. Thus we need a new limit for mmap, stack, ELF loader and EFI (which uses TTBR0) to represent the non-extended VA space. This patch introduces DEFAULT_MAP_WINDOW and DEFAULT_MAP_WINDOW_64 and switches the appropriate logic to use that instead of TASK_SIZE. Signed-off-by: Steve Capper --- Changed in V3: corrections to allow COMPAT 32-bit EL0 mode to work --- arch/arm64/include/asm/elf.h | 2 +- arch/arm64/include/asm/processor.h | 10 ++++++++-- arch/arm64/mm/init.c | 2 +- drivers/firmware/efi/arm-runtime.c | 2 +- drivers/firmware/efi/libstub/arm-stub.c | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 433b9554c6a1..bc9bd9e77d9d 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -117,7 +117,7 @@ * 64-bit, this is above 4GB to leave the entire 32-bit address * space open for things that want to use the area for 32-bit pointers. */ -#define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3) +#define ELF_ET_DYN_BASE (2 * DEFAULT_MAP_WINDOW_64 / 3) #ifndef __ASSEMBLY__ diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index 3e2091708b8e..da41a2655b69 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -25,6 +25,9 @@ #define USER_DS (TASK_SIZE_64 - 1) #ifndef __ASSEMBLY__ + +#define DEFAULT_MAP_WINDOW_64 (UL(1) << VA_BITS) + #ifdef __KERNEL__ #include @@ -51,13 +54,16 @@ TASK_SIZE_32 : TASK_SIZE_64) #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \ TASK_SIZE_32 : TASK_SIZE_64) +#define DEFAULT_MAP_WINDOW (test_thread_flag(TIF_32BIT) ? \ + TASK_SIZE_32 : DEFAULT_MAP_WINDOW_64) #else #define TASK_SIZE TASK_SIZE_64 +#define DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64 #endif /* CONFIG_COMPAT */ -#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4)) +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4)) +#define STACK_TOP_MAX DEFAULT_MAP_WINDOW_64 -#define STACK_TOP_MAX TASK_SIZE_64 #ifdef CONFIG_COMPAT #define AARCH32_VECTORS_BASE 0xffff0000 #define STACK_TOP (test_thread_flag(TIF_32BIT) ? \ diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 9d9582cac6c4..e5a1dc0beef9 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -609,7 +609,7 @@ void __init mem_init(void) * detected at build time already. */ #ifdef CONFIG_COMPAT - BUILD_BUG_ON(TASK_SIZE_32 > TASK_SIZE_64); + BUILD_BUG_ON(TASK_SIZE_32 > DEFAULT_MAP_WINDOW_64); #endif #ifdef CONFIG_SPARSEMEM_VMEMMAP diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c index 922cfb813109..952cec5b611a 100644 --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -38,7 +38,7 @@ static struct ptdump_info efi_ptdump_info = { .mm = &efi_mm, .markers = (struct addr_marker[]){ { 0, "UEFI runtime start" }, - { TASK_SIZE_64, "UEFI runtime end" } + { DEFAULT_MAP_WINDOW_64, "UEFI runtime end" } }, .base_addr = 0, }; diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index 30ac0c975f8a..d1ec7136e3e1 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -33,7 +33,7 @@ #define EFI_RT_VIRTUAL_SIZE SZ_512M #ifdef CONFIG_ARM64 -# define EFI_RT_VIRTUAL_LIMIT TASK_SIZE_64 +# define EFI_RT_VIRTUAL_LIMIT DEFAULT_MAP_WINDOW_64 #else # define EFI_RT_VIRTUAL_LIMIT TASK_SIZE #endif From patchwork Wed Nov 14 13:39:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10682653 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E74017F3 for ; Wed, 14 Nov 2018 13:39:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 013EA2B4AB for ; Wed, 14 Nov 2018 13:39:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E96CD2B4E0; Wed, 14 Nov 2018 13:39:50 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9410F2B4AB for ; Wed, 14 Nov 2018 13:39:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C902F6B000E; Wed, 14 Nov 2018 08:39:46 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C3F036B0010; Wed, 14 Nov 2018 08:39:46 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B572C6B0266; Wed, 14 Nov 2018 08:39:46 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by kanga.kvack.org (Postfix) with ESMTP id 810B66B000E for ; Wed, 14 Nov 2018 08:39:46 -0500 (EST) Received: by mail-oi1-f198.google.com with SMTP id n196so4772398oig.15 for ; Wed, 14 Nov 2018 05:39:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=LZUXOQ5gU5hJdYZ4+hY3y1P8u/D2Cn13qO85pnKw4dI=; b=e4UtffnaAdF92zzTx/r6Z6BluTZRSWHbtnnlAA8Uyeq6yUh9cVXoP9EUxxAWU6/aAC BCDKR/2hoJUWZBlcBvawppow52nAK3j3c3r+3KZ1+UbCoSRCC7blXG1maQYOcHSoESQL +/CkX4wc+QlpBPtdO8Qod77BaxmLiy5c2FvbyWud0QtC3rQC/jsvkgou21Gey2ZQq222 gOyZgcNi6+Gm+ZHbX8Q9PBZmIdc81WgrmlMdLVbKi+KZkM0Pspv8K6d+ij8Z6kVcTSS9 sauMuQlurUj0a/mD8si1TOWZmUh47zGn/f7kEGxGnGwRnmbgz5aJd2URDUvaym05ZpSJ +FjA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com X-Gm-Message-State: AGRZ1gLlgGFU5HDZc4fFP4V/jeDsYGEST/OVP2AOTDuDTIllgBUUo4+m MdIuaMffAXKGfRNpMhF3bp67smlbRUCJYnvNc/+2rOXT+oazViTT2dNGOmRpiVT97m1LD+tKhBz c4l93UAaIKwSRLaPvenPoyHcPsCq336FhwGG4wQCF9Wzh6qxbO/Wfih156HedU/13Cw== X-Received: by 2002:aca:d00c:: with SMTP id h12-v6mr1009496oig.138.1542202786204; Wed, 14 Nov 2018 05:39:46 -0800 (PST) X-Google-Smtp-Source: AJdET5dwLvEz2P4novcrOIj/3a1LPp/dFRrTMlUrvxkIZu+oKrMGpyV/meE6diljVib+zKujxw/H X-Received: by 2002:aca:d00c:: with SMTP id h12-v6mr1009467oig.138.1542202785277; Wed, 14 Nov 2018 05:39:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542202785; cv=none; d=google.com; s=arc-20160816; b=UNsgLM5XKTLSvUCRt/swMvrq70xNcq8KMDzrbzVC/Acd10jRaSTQca+kwu6iJOZYHn +ED1BZFnlJ4Yv8B6lvuxpJn27LsTcMaSubRweLX9xduDrOMM85SCa+LEmxhbGoHKl8iA EsfvhrvT3wMsWL7TFTmuLIF274gRJqC7smhi0xMRaKp7eUxQe2f4Q0jQ8zAk7fdmrBZp ClkEqW8MoXGkfA2xrnCfA0VstzF88DJtbKhCJmeEefJ7OVcf1y3IS4GFNKA3zc2EcYXX +z45QBvb9VxrGA4AlCwAr7Qigb64mwWh+3xzFW6d+vsn6WJuq5/Xo+bhdod7CEx8a0YD g/3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=LZUXOQ5gU5hJdYZ4+hY3y1P8u/D2Cn13qO85pnKw4dI=; b=PU0nV1VX2fGgjQ7Alb3H7KAN5ajFixyly9l5/xQ7YgiF14+VrOyyQ6cdF10KlRYYIc ebq/8UR65arK2DZC0stSkzxcmuGwqWFR0SNLjOo64ly1eMsoBFyq1cpfC0gg1SGh2s7y 7rTCpQ/WVCwJneSKXXtqdiywNtZX4SRIHYvsKRsH2csvLOG7Gvc5mKTd78KYVTgu0ndN fW1yDM1pv0M+zzePet8cZnmBj1Nx7NJf8DsExtUb2hkpkFdycHiZW6qLPAwGDQGiZHhi SYOMMGj9jNVyKOVOzN4WEWRfuySrFAxyl8fnoIV4K9ebQ/2wLSZCtBajGvoQd55jSBGQ Sd+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id t53si9828697oti.205.2018.11.14.05.39.45 for ; Wed, 14 Nov 2018 05:39:45 -0800 (PST) Received-SPF: pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BC32E15BF; Wed, 14 Nov 2018 05:39:44 -0800 (PST) Received: from capper-debian.arm.com (unknown [10.37.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6AB7F3F718; Wed, 14 Nov 2018 05:39:43 -0800 (PST) From: Steve Capper To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, jcm@redhat.com, Steve Capper Subject: [PATCH V3 3/5] arm64: mm: Define arch_get_mmap_end, arch_get_mmap_base Date: Wed, 14 Nov 2018 13:39:18 +0000 Message-Id: <20181114133920.7134-4-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181114133920.7134-1-steve.capper@arm.com> References: <20181114133920.7134-1-steve.capper@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Now that we have DEFAULT_MAP_WINDOW defined, we can arch_get_mmap_end and arch_get_mmap_base helpers to allow for high addresses in mmap. Signed-off-by: Steve Capper Reviewed-by: Catalin Marinas --- arch/arm64/include/asm/processor.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index da41a2655b69..bbe602cb8fd3 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -72,6 +72,13 @@ #define STACK_TOP STACK_TOP_MAX #endif /* CONFIG_COMPAT */ +#define arch_get_mmap_end(addr) ((addr > DEFAULT_MAP_WINDOW) ? TASK_SIZE :\ + DEFAULT_MAP_WINDOW) + +#define arch_get_mmap_base(addr, base) ((addr > DEFAULT_MAP_WINDOW) ? \ + base + TASK_SIZE - DEFAULT_MAP_WINDOW :\ + base) + extern phys_addr_t arm64_dma_phys_limit; #define ARCH_LOW_ADDRESS_LIMIT (arm64_dma_phys_limit - 1) From patchwork Wed Nov 14 13:39:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10682655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0815C17F3 for ; Wed, 14 Nov 2018 13:39:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDD122B4AC for ; Wed, 14 Nov 2018 13:39:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E20B82B4E4; Wed, 14 Nov 2018 13:39:53 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 264302B4AC for ; Wed, 14 Nov 2018 13:39:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0DE36B0010; Wed, 14 Nov 2018 08:39:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C46C96B0269; Wed, 14 Nov 2018 08:39:48 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D43D6B026A; Wed, 14 Nov 2018 08:39:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by kanga.kvack.org (Postfix) with ESMTP id 6EBF76B0010 for ; Wed, 14 Nov 2018 08:39:48 -0500 (EST) Received: by mail-oi1-f197.google.com with SMTP id s22-v6so9274455oie.9 for ; Wed, 14 Nov 2018 05:39:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=y1g97RIY4+wEUaToleMdUw5W3D1LiZ8V3W5KE/Mxe+Y=; b=CJ3x7VJmpqzKU3dadl8k03L/Q7PX1ROz4aF+kWSU6mHejC86We2qKvmbineB5fU+VT iP+GWMMbHFR8GTXl3ejSxOErD07iYaGIwtMENzaDpwncAPK61bD3GYL6xTWWj1WSuRfp Hrypr1Nx7wzVwsTuy5fgja6BU5yPCMgrWRMRQjABHk978nv5njuYA+5zghx88pkRdnBi BFmLlDZzFjvHKq8g/a1YA8IrnN3oWeUUJYGcuyoStlcwXdokqQ1UMefPseUSnXC2kRvb SVZ4TDDSk7/jBqluFSb4vartAkUsZdLHVdoURciDL4RZOXRsVPohztg0kEFPKb+l+CfW Wq+w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com X-Gm-Message-State: AGRZ1gJp4LHKkzoPfcMJHyVZuIn3hdb6fPQEAM3m6mg+uXxKtDcYego4 +eH75IFBGGIXPO91//eOqVn/TZGEoX6fTNjjkLHYb/h8YB5yD4+kOK8IbcNzOKWkasJp5lX3x1t q2LpZlkurSD6tvjktLYMDI9FffSCRwQuWGtNmrjQUkbc1nlVyGAuyXJ3iGOJJtQOBfw== X-Received: by 2002:a9d:5e0f:: with SMTP id d15mr995058oti.243.1542202788089; Wed, 14 Nov 2018 05:39:48 -0800 (PST) X-Google-Smtp-Source: AJdET5et8mmq4VgDrpMAp+Q9Beqy8IS8+bA9vQs+hdUtQsr5TZqJZEru70Xz/Y8fymGK52BedDb3 X-Received: by 2002:a9d:5e0f:: with SMTP id d15mr995015oti.243.1542202787103; Wed, 14 Nov 2018 05:39:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542202787; cv=none; d=google.com; s=arc-20160816; b=Qw6SiaUQQaEBcuILOecSfx5B/1cdV13mLwLMsJN/oYaGztMV3R9S0bx8RlMeMiUYVX TYDC2tWZ1i8XKO80Fetqcc12RkMx0nofoGxEAIRe6sJMGYe4VZbrhq9hMjmAsy5jQi8T QLE/YaPsJcBiwGteept/vP62qE5VwavcZM6jko/orsuFWWe+MkRzmX6HUad7Wks2qP0F GcOzGNdZ8SNGJ5OGwg9oircw18hTwQQaWtZy9X9nxxfLMz3KrXKh3aQw29BemtB8/JQh JwjbfK5BbKy+Aanw5AerirhnzX2YYCqywigZI+C1YNjEWHOewPBDP/YyFgh/uEHOMSDU naAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=y1g97RIY4+wEUaToleMdUw5W3D1LiZ8V3W5KE/Mxe+Y=; b=OdazJIi3OK2THzzLq4gGBskfEQ1EaQBeT+ALlUE5MYVA2MWGrpd9QhxnnL4gY1cw6e ch/Sk636QmU8kPBhRlj8Aul+b2hjxBEZFs7ztEu8f48CIsQE/y/yyYZVUs1WH2iWs14D rr1l6Ab3Y4tnKe2fiIuyKHYdQ5dWHsKFe1pU7HtUbyiATbVuviHO6aB78dZqaDpHdYze n0Eb7FTkm0PKV3Cw6fRA1CF3ljmBvHhCZNoCkaU40qcujr2/m8CiCSqrqk3Hsd4NYftt u/OAyA29HkWO8l2SXK/JAGAZELjODuHmKP9/irawNXZNiZBPIvNxjXYGJj7wS72ylskZ 3A4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id j50si226230otc.124.2018.11.14.05.39.46 for ; Wed, 14 Nov 2018 05:39:47 -0800 (PST) Received-SPF: pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 75F1F1650; Wed, 14 Nov 2018 05:39:46 -0800 (PST) Received: from capper-debian.arm.com (unknown [10.37.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0D6D23F718; Wed, 14 Nov 2018 05:39:44 -0800 (PST) From: Steve Capper To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, jcm@redhat.com, Steve Capper Subject: [PATCH V3 4/5] arm64: mm: introduce 52-bit userspace support Date: Wed, 14 Nov 2018 13:39:19 +0000 Message-Id: <20181114133920.7134-5-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181114133920.7134-1-steve.capper@arm.com> References: <20181114133920.7134-1-steve.capper@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP On arm64 there is optional support for a 52-bit virtual address space. To exploit this one has to be running with a 64KB page size and be running on hardware that supports this. For an arm64 kernel supporting a 48 bit VA with a 64KB page size, a few changes are needed to support a 52-bit userspace: * TCR_EL1.T0SZ needs to be 12 instead of 16, * pgd_offset needs to work with a different PTRS_PER_PGD, * PGD_SIZE needs to be increased, * TASK_SIZE needs to reflect the new size. This patch implements the above when the support for 52-bit VAs is detected at early boot time. On arm64 userspace addresses translation is controlled by TTBR0_EL1. As well as userspace, TTBR0_EL1 controls: * The identity mapping, * EFI runtime code. It is possible to run a kernel with an identity mapping that has a larger VA size than userspace (and for this case __cpu_set_tcr_t0sz() would set TCR_EL1.T0SZ as appropriate). However, when the conditions for 52-bit userspace are met; it is possible to keep TCR_EL1.T0SZ fixed at 12. Thus in this patch, the TCR_EL1.T0SZ size changing logic is disabled. Signed-off-by: Steve Capper --- arch/arm64/Kconfig | 4 ++++ arch/arm64/include/asm/assembler.h | 7 +++---- arch/arm64/include/asm/mmu_context.h | 3 +++ arch/arm64/include/asm/pgalloc.h | 4 ++++ arch/arm64/include/asm/pgtable.h | 16 +++++++++++++--- arch/arm64/include/asm/processor.h | 13 ++++++++----- arch/arm64/kernel/head.S | 13 +++++++++++++ arch/arm64/mm/fault.c | 2 +- arch/arm64/mm/mmu.c | 1 + arch/arm64/mm/proc.S | 10 +++++++++- 10 files changed, 59 insertions(+), 14 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 787d7850e064..eab02d24f5d1 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -709,6 +709,10 @@ config ARM64_PA_BITS_52 endchoice +config ARM64_52BIT_VA + def_bool y + depends on ARM64_VA_BITS_48 && ARM64_64K_PAGES + config ARM64_PA_BITS int default 48 if ARM64_PA_BITS_48 diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 6142402c2eb4..02ce922a37a7 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -342,11 +342,10 @@ alternative_endif .endm /* - * tcr_set_idmap_t0sz - update TCR.T0SZ so that we can load the ID map + * tcr_set_t0sz - update TCR.T0SZ so that we can load the ID map */ - .macro tcr_set_idmap_t0sz, valreg, tmpreg - ldr_l \tmpreg, idmap_t0sz - bfi \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH + .macro tcr_set_t0sz, valreg, t0sz + bfi \valreg, \t0sz, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH .endm /* diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 1e58bf58c22b..b125fafc611b 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -72,6 +72,9 @@ extern u64 idmap_ptrs_per_pgd; static inline bool __cpu_uses_extended_idmap(void) { + if (IS_ENABLED(CONFIG_ARM64_52BIT_VA)) + return false; + return unlikely(idmap_t0sz != TCR_T0SZ(VA_BITS)); } diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h index 2e05bcd944c8..56c3ccabeffe 100644 --- a/arch/arm64/include/asm/pgalloc.h +++ b/arch/arm64/include/asm/pgalloc.h @@ -27,7 +27,11 @@ #define check_pgt_cache() do { } while (0) #define PGALLOC_GFP (GFP_KERNEL | __GFP_ZERO) +#ifdef CONFIG_ARM64_52BIT_VA +#define PGD_SIZE ((1 << (52 - PGDIR_SHIFT)) * sizeof(pgd_t)) +#else #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t)) +#endif #if CONFIG_PGTABLE_LEVELS > 2 diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 50b1ef8584c0..19736520b724 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -616,11 +616,21 @@ static inline phys_addr_t pgd_page_paddr(pgd_t pgd) #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd_val(pgd)) /* to find an entry in a page-table-directory */ -#define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1)) +#define pgd_index(addr, ptrs) (((addr) >> PGDIR_SHIFT) & ((ptrs) - 1)) +#define _pgd_offset_raw(pgd, addr, ptrs) ((pgd) + pgd_index(addr, ptrs)) +#define pgd_offset_raw(pgd, addr) (_pgd_offset_raw(pgd, addr, PTRS_PER_PGD)) -#define pgd_offset_raw(pgd, addr) ((pgd) + pgd_index(addr)) +static inline pgd_t *pgd_offset(const struct mm_struct *mm, unsigned long addr) +{ + pgd_t *ret; + + if (IS_ENABLED(CONFIG_ARM64_52BIT_VA) && (mm != &init_mm)) + ret = _pgd_offset_raw(mm->pgd, addr, 1ULL << (vabits_user - PGDIR_SHIFT)); + else + ret = pgd_offset_raw(mm->pgd, addr); -#define pgd_offset(mm, addr) (pgd_offset_raw((mm)->pgd, (addr))) + return ret; +} /* to find an entry in a kernel page-table-directory */ #define pgd_offset_k(addr) pgd_offset(&init_mm, addr) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index bbe602cb8fd3..403c3c106d24 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -19,13 +19,16 @@ #ifndef __ASM_PROCESSOR_H #define __ASM_PROCESSOR_H -#define TASK_SIZE_64 (UL(1) << VA_BITS) - -#define KERNEL_DS UL(-1) -#define USER_DS (TASK_SIZE_64 - 1) - +#define KERNEL_DS UL(-1) +#ifdef CONFIG_ARM64_52BIT_VA +#define USER_DS ((UL(1) << 52) - 1) +#else +#define USER_DS ((UL(1) << VA_BITS) - 1) +#endif /* CONFIG_ARM64_52IT_VA */ #ifndef __ASSEMBLY__ +extern u64 vabits_user; +#define TASK_SIZE_64 (UL(1) << vabits_user) #define DEFAULT_MAP_WINDOW_64 (UL(1) << VA_BITS) #ifdef __KERNEL__ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 4471f570a295..b9a2d9a9419a 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -318,6 +318,19 @@ __create_page_tables: adrp x0, idmap_pg_dir adrp x3, __idmap_text_start // __pa(__idmap_text_start) +#ifdef CONFIG_ARM64_52BIT_VA + mrs_s x6, SYS_ID_AA64MMFR2_EL1 + and x6, x6, #(0xf << ID_AA64MMFR2_LVA_SHIFT) + mov x5, #52 + cbnz x6, 1f +#endif + mov x5, #VA_BITS +1: + adr_l x6, vabits_user + str x5, [x6] + dmb sy + dc ivac, x6 // Invalidate potentially stale cache line + /* * VA_BITS may be too small to allow for an ID mapping to be created * that covers system RAM if that is located sufficiently high in the diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 7d9571f4ae3d..5fe6d2e40e9b 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -160,7 +160,7 @@ void show_pte(unsigned long addr) pr_alert("%s pgtable: %luk pages, %u-bit VAs, pgdp = %p\n", mm == &init_mm ? "swapper" : "user", PAGE_SIZE / SZ_1K, - VA_BITS, mm->pgd); + mm == &init_mm ? VA_BITS : (int) vabits_user, mm->pgd); pgdp = pgd_offset(mm, addr); pgd = READ_ONCE(*pgdp); pr_alert("[%016lx] pgd=%016llx", addr, pgd_val(pgd)); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 394b8d554def..f8fc393143ea 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -52,6 +52,7 @@ u64 idmap_t0sz = TCR_T0SZ(VA_BITS); u64 idmap_ptrs_per_pgd = PTRS_PER_PGD; +u64 vabits_user __ro_after_init; u64 kimage_voffset __ro_after_init; EXPORT_SYMBOL(kimage_voffset); diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 2c75b0b903ae..03454e1f92f2 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -446,7 +446,15 @@ ENTRY(__cpu_setup) ldr x10, =TCR_TxSZ(VA_BITS) | TCR_CACHE_FLAGS | TCR_SMP_FLAGS | \ TCR_TG_FLAGS | TCR_KASLR_FLAGS | TCR_ASID16 | \ TCR_TBI0 | TCR_A1 - tcr_set_idmap_t0sz x10, x9 + +#ifdef CONFIG_ARM64_52BIT_VA + ldr_l x9, vabits_user + sub x9, xzr, x9 + add x9, x9, #64 +#else + ldr_l x9, idmap_t0sz +#endif + tcr_set_t0sz x10, x9 /* * Set the IPS bits in TCR_EL1. From patchwork Wed Nov 14 13:39:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Capper X-Patchwork-Id: 10682657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90DDC139B for ; Wed, 14 Nov 2018 13:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 847E22B4AC for ; Wed, 14 Nov 2018 13:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 790E92B4E4; Wed, 14 Nov 2018 13:39:56 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EEF252B4AC for ; Wed, 14 Nov 2018 13:39:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CE626B0269; Wed, 14 Nov 2018 08:39:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 235516B026A; Wed, 14 Nov 2018 08:39:50 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F285F6B026B; Wed, 14 Nov 2018 08:39:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by kanga.kvack.org (Postfix) with ESMTP id C60E16B0269 for ; Wed, 14 Nov 2018 08:39:49 -0500 (EST) Received: by mail-ot1-f71.google.com with SMTP id s3so11246256otb.0 for ; Wed, 14 Nov 2018 05:39:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=mHgca0FaR8LiBMZ8xdTDs+iEYjZybHORbzkJTanK5Qo=; b=dV6qcS83Ub1e0+BlTKwi/PoFEfFyV1H/CnK/9Ltpw72c9WrtnyatcMb9mFD7HaTuMV s71ao4b3jd50LQJdRa2IIyclgQOYPaDUOKW53M2i0yL4ZuRgxQQVtWvaFJJ92/5rSMeG TsrEBBhiaEXeX959iTRMlxjLOvP646ZzBVKdzLkegyvng13Wrt+xLYC9yoqoAbmncRm5 mbroRhntACgOpzUjWtRahKdOSfEF5Ev9lP7GzmOnFFyG4sIaHBPjHpbPhTkhCRHx+M4t kpIaYDgSq2Y3gw2OK2jTRQXGqDXZWi3HV5q3VBN2Smpz+KWnZ99nfhG7TcOapoDzZkLA 44JA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com X-Gm-Message-State: AGRZ1gI06rn8CWOkJWfzbuK3rC1/F0X/HAX8vV9Bd+opi4A4gljq0VMg m/ObEw/vOu0h7gtSfz7/9fbwiq+vJ1ekHCWK0/mXP/ipJ5BTtEfgqkJVuV1mVqMi8Yg28+hgwat KN7USpaYyxUFdw2HKKG8L85WHGFbrBmn9h4qYVcfc5hKOV3ECUm0WvbUlySQpgX519g== X-Received: by 2002:aca:440b:: with SMTP id r11-v6mr1015126oia.3.1542202789566; Wed, 14 Nov 2018 05:39:49 -0800 (PST) X-Google-Smtp-Source: AJdET5dHi84IKQ7gsUB0ciOeKhzA0X9QBNi0QL5nio2/PQLwhFsO9ZAxrEYRWVzBwEr20oFekjSm X-Received: by 2002:aca:440b:: with SMTP id r11-v6mr1015102oia.3.1542202788792; Wed, 14 Nov 2018 05:39:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542202788; cv=none; d=google.com; s=arc-20160816; b=eclgdQ5g8cjf5ExHRpnuqyz5pIDfovokpyo3ETC0JwXBd0GERuGAp9Mr+7faPd3EJt nWSc+li/V7lNfYYUFlx2cCndOKLSpy6mFW0qFzpyI2JHcmKaeaQVNkPJeHeEjzFIksru 25pd94ou1ulokIZpTefOvXL/Iuoty72sq82of9b+AX6E81TSx5c50ykFWdLwDjRupUyD 2IoJOBC0Rx839aHqAThgdzsqnUgj8YBmdl4egvRRyDhx/HWsjK+c/QNO8IlzyKGnVAxQ CdRO6TtbrZoaLvmnvxdgXabktlI1DiNsaDoA+q8225Izwj2b7+YAUt8jJbhkCahOk8G7 WcMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=mHgca0FaR8LiBMZ8xdTDs+iEYjZybHORbzkJTanK5Qo=; b=Cz6KHtNMI5ARjCIa4TEgYJ+DiQVRaBxby99/Z4STn6mIYLWSkNgfP7dqtiUy6JoIao m3icMwslHxJjhpZYQ300A0lxUdQ8Q8MGnR1Sis4XlPbnWTyr1ydWWietN5wP781T0KhA 6n5PTy7rPDutpW0wuB6MAVz1J4/ne09Ukf2Mwr1crVNmxd0rQhtV29XdgzCvxABCHG6S NRFLcUYPDV+d44Rw3RB8Wx80D29l7VgrChCXNpvCQ62h6kN/OrtbyjXIfUHmXwF0y3o6 qTd3iDybuh4GZCI/SEpgWqekDcrfAhVMZpDDdBJF7Fw2PeY/NLG78m35JdxhpmF9oAEx hQnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id i6-v6si9321354oiy.187.2018.11.14.05.39.48 for ; Wed, 14 Nov 2018 05:39:48 -0800 (PST) Received-SPF: pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of steve.capper@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=steve.capper@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1BDD6165C; Wed, 14 Nov 2018 05:39:48 -0800 (PST) Received: from capper-debian.arm.com (unknown [10.37.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BA4C53F718; Wed, 14 Nov 2018 05:39:46 -0800 (PST) From: Steve Capper To: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will.deacon@arm.com, ard.biesheuvel@linaro.org, jcm@redhat.com, Steve Capper Subject: [PATCH V3 5/5] arm64: mm: Allow forcing all userspace addresses to 52-bit Date: Wed, 14 Nov 2018 13:39:20 +0000 Message-Id: <20181114133920.7134-6-steve.capper@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181114133920.7134-1-steve.capper@arm.com> References: <20181114133920.7134-1-steve.capper@arm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP On arm64 52-bit VAs are provided to userspace when a hint is supplied to mmap. This helps maintain compatibility with software that expects at most 48-bit VAs to be returned. In order to help identify software that has 48-bit VA assumptions, this patch allows one to compile a kernel where 52-bit VAs are returned by default on HW that supports it. This feature is intended to be for development systems only. Signed-off-by: Steve Capper --- Patch added in V3 to allow for testing/preparation for 52-bit support. --- arch/arm64/Kconfig | 14 ++++++++++++++ arch/arm64/include/asm/elf.h | 4 ++++ arch/arm64/include/asm/processor.h | 9 ++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index eab02d24f5d1..17d363e40c4d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1165,6 +1165,20 @@ config ARM64_CNP at runtime, and does not affect PEs that do not implement this feature. +config ARM64_FORCE_52BIT + bool "Force 52-bit virtual addresses for userspace" + default n + depends on ARM64_52BIT_VA && EXPERT + help + For systems with 52-bit userspace VAs enabled, the kernel will attempt + to maintain compatibility with older software by providing 48-bit VAs + unless a hint is supplied to mmap. + + This configuration option disables the 48-bit compatibility logic, and + forces all userspace addresses to be 52-bit on HW that supports it. One + should only enable this configuration option for stress testing userspace + memory management code. If unsure say N here. + endmenu config ARM64_SVE diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index bc9bd9e77d9d..6adc1a90e7e6 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -117,7 +117,11 @@ * 64-bit, this is above 4GB to leave the entire 32-bit address * space open for things that want to use the area for 32-bit pointers. */ +#ifdef CONFIG_ARM64_FORCE_52BIT +#define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3) +#else #define ELF_ET_DYN_BASE (2 * DEFAULT_MAP_WINDOW_64 / 3) +#endif /* CONFIG_ARM64_FORCE_52BIT */ #ifndef __ASSEMBLY__ diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index 403c3c106d24..1415de41d836 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -64,8 +64,13 @@ extern u64 vabits_user; #define DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64 #endif /* CONFIG_COMPAT */ -#define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4)) +#ifdef CONFIG_ARM64_FORCE_52BIT +#define STACK_TOP_MAX TASK_SIZE_64 +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 4)) +#else #define STACK_TOP_MAX DEFAULT_MAP_WINDOW_64 +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(DEFAULT_MAP_WINDOW / 4)) +#endif /* CONFIG_ARM64_FORCE_52BIT */ #ifdef CONFIG_COMPAT #define AARCH32_VECTORS_BASE 0xffff0000 @@ -75,12 +80,14 @@ extern u64 vabits_user; #define STACK_TOP STACK_TOP_MAX #endif /* CONFIG_COMPAT */ +#ifndef CONFIG_ARM64_FORCE_52BIT #define arch_get_mmap_end(addr) ((addr > DEFAULT_MAP_WINDOW) ? TASK_SIZE :\ DEFAULT_MAP_WINDOW) #define arch_get_mmap_base(addr, base) ((addr > DEFAULT_MAP_WINDOW) ? \ base + TASK_SIZE - DEFAULT_MAP_WINDOW :\ base) +#endif /* CONFIG_ARM64_FORCE_52BIT */ extern phys_addr_t arm64_dma_phys_limit; #define ARCH_LOW_ADDRESS_LIMIT (arm64_dma_phys_limit - 1)