Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp428602img; Fri, 22 Mar 2019 00:47:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKAmP2PLWiw5X9XqMTCDUiQJYz7RgMWhn1CA9T1q9bKdVDA1HG9KMo5Zg6YksjAF2PcmC8 X-Received: by 2002:a65:6201:: with SMTP id d1mr7682642pgv.382.1553240834588; Fri, 22 Mar 2019 00:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553240834; cv=none; d=google.com; s=arc-20160816; b=HE4UBQ6Fy/2w4M6AhsMkrihcUiDhVtbvoTbbzmINykm7Nde8a6eMIV2z4a5FSr01El 9R4+6dSXBYEf7zPcTATsNfgZqFdW9Jp7+EUy4qE0qnTZUYFCl3lNjRzwMVWo6r6k/0L7 /2/15P9Q/AuUhlU+0gCv3FemZvVPsBX/BvzXt41bf3rTHSDDAxWrcFLT6+Tm7f5UwRqv tnHi9KWEMTai8cQVQnBcpgq6yAeF2HSfz8MaZPhn+GK9Zbg3Rkl9LL71HtiGvq7E368Z 10dZoO55jXUPTIoduAyP765J8V4eEUUMmMaoUSi9EK4Po861Irp7pFhpHpAQ1LxhZcWa WzQA== 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=LUGImeOjzmNJpIPAM8RQUWM+8kkl6UbTjBKYFhKUvaE=; b=tw1gc9Z6tAQrSSe+941RWVe+a2EWeXDTI2aRrmLBo1ZT8UONWaShF8BqPlTtNuDIn8 F2N7GymZNcjTJKruDQL9V1HZs3aKoIJHEzp3rTeJUjO+ufHckvIGdC9ez7Cz300nGcm6 VHLlaT+zvSkolBfHDaX28On5vpsXyI/GFdcrI5vwnp6ZtkwDnBqEOlAYYHIDvnLoBTcl VI1BLmrYN7d3hvL+oOkJklotBxLaFIwmdFAoCnhQSMV6vuI3q8C415xN1GMnSdbB7CFI bv92I4XGsDeGh9bLRyN5442OrR+PQFd4+WzyXgtNgemJp+TaQC0CKFNtz8YXJvakow/I SMGg== 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 f1si6470248plr.55.2019.03.22.00.47.00; Fri, 22 Mar 2019 00:47:14 -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 S1727708AbfCVHpu (ORCPT + 99 others); Fri, 22 Mar 2019 03:45:50 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:47575 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725974AbfCVHpu (ORCPT ); Fri, 22 Mar 2019 03:45:50 -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 4A88E20001D; Fri, 22 Mar 2019 07:45:43 +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 3/4] mips: Use generic mmap top-down layout Date: Fri, 22 Mar 2019 03:42:24 -0400 Message-Id: <20190322074225.22282-4-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 mips uses a top-down layout by default that fits the generic functions. At the same time, this commit allows to fix problem uncovered and not fixed for mips here: https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1429066.html Signed-off-by: Alexandre Ghiti --- arch/mips/include/asm/processor.h | 4 +-- arch/mips/mm/mmap.c | 57 ------------------------------- 2 files changed, 2 insertions(+), 59 deletions(-) diff --git a/arch/mips/include/asm/processor.h b/arch/mips/include/asm/processor.h index aca909bd7841..f8e04962b52d 100644 --- a/arch/mips/include/asm/processor.h +++ b/arch/mips/include/asm/processor.h @@ -30,9 +30,9 @@ extern unsigned int vced_count, vcei_count; /* - * MIPS does have an arch_pick_mmap_layout() + * MIPS uses the default implementation of topdown mmap layout. */ -#define HAVE_ARCH_PICK_MMAP_LAYOUT 1 +#define ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT #ifdef CONFIG_32BIT #ifdef CONFIG_KVM_GUEST diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index 2f616ebeb7e0..61e65a69bb09 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c @@ -20,33 +20,6 @@ unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */ EXPORT_SYMBOL(shm_align_mask); -/* gap between mmap and stack */ -#define MIN_GAP (128*1024*1024UL) -#define MAX_GAP ((TASK_SIZE)/6*5) - -static int mmap_is_legacy(struct rlimit *rlim_stack) -{ - if (current->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); -} - #define COLOUR_ALIGN(addr, pgoff) \ ((((addr) + shm_align_mask) & ~shm_align_mask) + \ (((pgoff) << PAGE_SHIFT) & shm_align_mask)) @@ -144,36 +117,6 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, addr0, len, pgoff, flags, DOWN); } -unsigned long arch_mmap_rnd(void) -{ - unsigned long rnd; - -#ifdef CONFIG_COMPAT - if (TASK_IS_32BIT_ADDR) - rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1); - else -#endif /* CONFIG_COMPAT */ - 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; - } -} - static inline unsigned long brk_rnd(void) { unsigned long rnd = get_random_long(); -- 2.20.1