Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp427970img; Fri, 22 Mar 2019 00:46:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1uGfYnqWM7/RpxmCe4kqqoIBwnMiPzWMqzRs0m2xCri9tMHAbeL4r43YfrtY6kE+eBOGH X-Received: by 2002:a62:1647:: with SMTP id 68mr7779309pfw.113.1553240763233; Fri, 22 Mar 2019 00:46:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553240763; cv=none; d=google.com; s=arc-20160816; b=VjZcgIemjWH9UU+DkMMabElxKXDD20tX4j/FUIdwpnq9KPMx43D/RjBkXheZg2B18f zlb0UmDxIv7yZGFzwX3xzaWuQVnubZQc5EHJTiubP0HCntu7aHsu4F4h5Rb6rs1dxQke 1HG/J8edUFav+dBunQvVUc7x8tivPCkUWymWv06guR9cR6PqWFSE2Y2AXpEdvQ1iSPKu SnCRCPmNz3ROXoqgP3Bi0Y8FahV1UTa6m3Dr6wQGkPRK5eQJQ+fS4MmDMVoPKgbHRpnu T6AvADCvLLnfAW0Q2ILgSDrwBmBA0lhJs7PtyUppDdw3uR9+6J7/I4qnBnGJUUot2gwz ZfZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Uz7p6g8xsr4/tuzcqVtmbZTVNIaPsr5ZFq4yt3MBowc=; b=DnC7yg8WBc/o8d82Ac2l6xd3GMCYVCMFu8e1QrOZli44yXco45lvznoD4vGCQl8TXj oT+2TKY/D6X3yhLrTv2Mf9nZsdZ0t3E7+Al95kmpqFrDrXFAIvj0Gjvdr604FmgvcnIF +LUIsKqQiZnAIezo8Hgfd2yKjTbFCtK3kSqPdJ1pDYwqRUA1uuAobuRBFttTQgi7YJYp rudxT6E8qRZxCF0aOlb5M3itZYn5FTtw+smYs7wVwdH04VCKa1/tOz6cw77rb+WFA5M4 I6jG8ZfrLgaXJidL0RFmONl7HBpCMo0vCTgOPpnTm4Z7kOLHEaJZu1wMqCNleJnRx7+g y8wg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h124si6002153pgc.25.2019.03.22.00.45.48; Fri, 22 Mar 2019 00:46:03 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727531AbfCVHop (ORCPT + 99 others); Fri, 22 Mar 2019 03:44:45 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:38397 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726091AbfCVHop (ORCPT ); Fri, 22 Mar 2019 03:44:45 -0400 Received: from alex.numericable.fr (127.19.86.79.rev.sfr.net [79.86.19.127]) (Authenticated sender: alex@ghiti.fr) by relay12.mail.gandi.net (Postfix) with ESMTPSA id E7FFE20000D; Fri, 22 Mar 2019 07:44:38 +0000 (UTC) From: Alexandre Ghiti To: Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , Kees Cook , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: Alexandre Ghiti Subject: [PATCH 2/4] arm: Use generic mmap top-down layout Date: Fri, 22 Mar 2019 03:42:23 -0400 Message-Id: <20190322074225.22282-3-alex@ghiti.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190322074225.22282-1-alex@ghiti.fr> References: <20190322074225.22282-1-alex@ghiti.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org arm uses a top-down layout by default that fits the generic functions. At the same time, this commit allows to fix the following problems: - one uncovered and not fixed for arm here: https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1429066.html - the use of TASK_SIZE instead of STACK_TOP in mmap_base which, when address space of a task is 26 bits, would assign mmap base way too high. Signed-off-by: Alexandre Ghiti --- arch/arm/include/asm/processor.h | 2 +- arch/arm/mm/mmap.c | 52 -------------------------------- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h index 57fe73ea0f72..03837d325a2f 100644 --- a/arch/arm/include/asm/processor.h +++ b/arch/arm/include/asm/processor.h @@ -143,7 +143,7 @@ static inline void prefetchw(const void *ptr) #endif #endif -#define HAVE_ARCH_PICK_MMAP_LAYOUT +#define ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT #endif diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index f866870db749..b8d912ac9e61 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c @@ -17,33 +17,6 @@ ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \ (((pgoff)<personality & ADDR_COMPAT_LAYOUT) - return 1; - - if (rlim_stack->rlim_cur == RLIM_INFINITY) - return 1; - - return sysctl_legacy_va_layout; -} - -static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack) -{ - unsigned long gap = rlim_stack->rlim_cur; - - if (gap < MIN_GAP) - gap = MIN_GAP; - else if (gap > MAX_GAP) - gap = MAX_GAP; - - return PAGE_ALIGN(TASK_SIZE - gap - rnd); -} - /* * We need to ensure that shared mappings are correctly aligned to * avoid aliasing issues with VIPT caches. We need to ensure that @@ -171,31 +144,6 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, return addr; } -unsigned long arch_mmap_rnd(void) -{ - unsigned long rnd; - - rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1); - - return rnd << PAGE_SHIFT; -} - -void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) -{ - unsigned long random_factor = 0UL; - - if (current->flags & PF_RANDOMIZE) - random_factor = arch_mmap_rnd(); - - if (mmap_is_legacy(rlim_stack)) { - mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; - mm->get_unmapped_area = arch_get_unmapped_area; - } else { - mm->mmap_base = mmap_base(random_factor, rlim_stack); - mm->get_unmapped_area = arch_get_unmapped_area_topdown; - } -} - /* * You really shouldn't be using read() or write() on /dev/mem. This * might go away in the future. -- 2.20.1