Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp186325yba; Wed, 17 Apr 2019 22:41:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqym9Xez4sMzLcxzGE0z/sQJjbRgFxXMilnsCVDupYQhKwh8W2Yzov0BeMKxdyKsrQo9J7b/ X-Received: by 2002:a17:902:9884:: with SMTP id s4mr6628939plp.179.1555566082182; Wed, 17 Apr 2019 22:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555566082; cv=none; d=google.com; s=arc-20160816; b=WcjOZIdxFMo1KRNsmjFM/oN+5XBiQfzebEiKK9zumTEViekaQZc8JWLVPmnpED5bbv Zd8p5PkKzEz1sj0GVb1sixJDye4/M2kflPP2o+XuuuFpoXOG7GdMax/uYuBxAa1QAI9k dzg7MDLnw2TXI/GKnhx1nQSt4uTlUCkcLtGZaJ7yHe8F4b3ADWF56ZfvJr2XY9CjdKSr bLSd1rVh7DEpGBzaFSUvGP+RIaXLlXxLFx2c1KSr4oAKDHsF2fYcngX4xbUxatLg7I6N encWiGsfE3FQmIelTH9gck/DaEnMH2zJIis2lMd55K03U1BH8psD9CM6mUsL08AS5VBJ 9g7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=I49wvlYq7D5JlBzIeYIfPLcNWvP+zL3hNSqD7FZ7LkY=; b=vAIrDw0pnw4vVapEoHghlQFDP9kypHyZL37ENSq5UQzgWmva9Ncv2ioqCy7t9kcpMb KHJfIKapkaT7VRY+FPC2+hYeEm99BTA4KMnRvK4HyP7c4I+e52fCBzM/f+5HfkS/VKJq kEFMkcsNRSJ7+UIAfoy28sS0yWOGaFj/koVtO5eQUnoWuNckg9J1JnPfqYNIKdiW+Dia VTsm90rC4KQeBIMh+g/JlPZ2r5iQO9fhUy1StNgp02uGG1WwThCuFo7/6aeTUHvEuYbl ddzNJZfevynmcKgUjheaTaSt3cj4nO2hib0vys7Rs5bciXIJN38dN2VcnqKS4A+v3rPM 7JJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=eKENM7Vl; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10si1078539pll.251.2019.04.17.22.41.06; Wed, 17 Apr 2019 22:41:22 -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; dkim=pass header.i=@chromium.org header.s=google header.b=eKENM7Vl; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731192AbfDRFkL (ORCPT + 99 others); Thu, 18 Apr 2019 01:40:11 -0400 Received: from mail-ua1-f67.google.com ([209.85.222.67]:34314 "EHLO mail-ua1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725836AbfDRFkL (ORCPT ); Thu, 18 Apr 2019 01:40:11 -0400 Received: by mail-ua1-f67.google.com with SMTP id c6so399142uan.1 for ; Wed, 17 Apr 2019 22:40:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=I49wvlYq7D5JlBzIeYIfPLcNWvP+zL3hNSqD7FZ7LkY=; b=eKENM7VlYogZiu9LKw1HvlthciY0efM2NRwfvhdnWH5UYz7IY9RnPN4yev4Q+SyM9W YdiBLhyiVJeHQ9+caxTPQbD0pWn+V0WnnHXoprAgGsJToXR/dAfi6b1L2J3wzGcPrtzu FLBCSBvonUpQIBIMq//yfXcrvRxsfl6ta/QN4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=I49wvlYq7D5JlBzIeYIfPLcNWvP+zL3hNSqD7FZ7LkY=; b=scfbU2mnMvaH3U51qQNemYay9hdzbtdaWi6MHeoUqMMzQxFhcAomqCB+pta2yyp959 17gWJXHdBOhskjIIjpvCJHDL5mGLYOgHFnuCT9BJeGUccLim///nWOlDlhUHOAmWJjqL XlmSSNY0KthL33GJanPqSTppDTxg7K754idAEEFAUmZUPACMEMSqb5cmKg3+Nw9sQT5T VbWnUKCXq1DJ9EprCmDC+w7TT22O7DaVWkQh9DtwALMO3SpeosViboB+DSsioERsSmKc dnNgVquB2aT8RzEVg5UjBLva5rLcj/rmoxZiXsB58r87dvgSnUeM1S7d10iJiUJAKyMi eGWg== X-Gm-Message-State: APjAAAWLMmeoPb6cqHtShz/UTpLbuVfHZjtVUrBmQHMP14sASq63+spO bgG1v1AssoLu9MCkpY+RL3uj1cTZuoE= X-Received: by 2002:ab0:702a:: with SMTP id u10mr9791455ual.5.1555566009368; Wed, 17 Apr 2019 22:40:09 -0700 (PDT) Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com. [209.85.221.181]) by smtp.gmail.com with ESMTPSA id p135sm306074vkd.8.2019.04.17.22.40.08 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 22:40:09 -0700 (PDT) Received: by mail-vk1-f181.google.com with SMTP id x2so206860vkx.13 for ; Wed, 17 Apr 2019 22:40:08 -0700 (PDT) X-Received: by 2002:a1f:3c83:: with SMTP id j125mr2514890vka.92.1555565530282; Wed, 17 Apr 2019 22:32:10 -0700 (PDT) MIME-Version: 1.0 References: <20190417052247.17809-1-alex@ghiti.fr> <20190417052247.17809-12-alex@ghiti.fr> In-Reply-To: <20190417052247.17809-12-alex@ghiti.fr> From: Kees Cook Date: Thu, 18 Apr 2019 00:31:58 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 11/11] riscv: Make mmap allocation top-down by default To: Alexandre Ghiti Cc: Andrew Morton , Christoph Hellwig , Russell King , Catalin Marinas , Will Deacon , Ralf Baechle , Paul Burton , James Hogan , Palmer Dabbelt , Albert Ou , Alexander Viro , Luis Chamberlain , Kees Cook , LKML , linux-arm-kernel , linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, "linux-fsdevel@vger.kernel.org" , Linux-MM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 17, 2019 at 12:34 AM Alexandre Ghiti wrote: > > In order to avoid wasting user address space by using bottom-up mmap > allocation scheme, prefer top-down scheme when possible. > > Before: > root@qemuriscv64:~# cat /proc/self/maps > 00010000-00016000 r-xp 00000000 fe:00 6389 /bin/cat.coreutils > 00016000-00017000 r--p 00005000 fe:00 6389 /bin/cat.coreutils > 00017000-00018000 rw-p 00006000 fe:00 6389 /bin/cat.coreutils > 00018000-00039000 rw-p 00000000 00:00 0 [heap] > 1555556000-155556d000 r-xp 00000000 fe:00 7193 /lib/ld-2.28.so > 155556d000-155556e000 r--p 00016000 fe:00 7193 /lib/ld-2.28.so > 155556e000-155556f000 rw-p 00017000 fe:00 7193 /lib/ld-2.28.so > 155556f000-1555570000 rw-p 00000000 00:00 0 > 1555570000-1555572000 r-xp 00000000 00:00 0 [vdso] > 1555574000-1555576000 rw-p 00000000 00:00 0 > 1555576000-1555674000 r-xp 00000000 fe:00 7187 /lib/libc-2.28.so > 1555674000-1555678000 r--p 000fd000 fe:00 7187 /lib/libc-2.28.so > 1555678000-155567a000 rw-p 00101000 fe:00 7187 /lib/libc-2.28.so > 155567a000-15556a0000 rw-p 00000000 00:00 0 > 3fffb90000-3fffbb1000 rw-p 00000000 00:00 0 [stack] > > After: > root@qemuriscv64:~# cat /proc/self/maps > 00010000-00016000 r-xp 00000000 fe:00 6389 /bin/cat.coreutils > 00016000-00017000 r--p 00005000 fe:00 6389 /bin/cat.coreutils > 00017000-00018000 rw-p 00006000 fe:00 6389 /bin/cat.coreutils > 00018000-00039000 rw-p 00000000 00:00 0 [heap] > 3ff7eb6000-3ff7ed8000 rw-p 00000000 00:00 0 > 3ff7ed8000-3ff7fd6000 r-xp 00000000 fe:00 7187 /lib/libc-2.28.so > 3ff7fd6000-3ff7fda000 r--p 000fd000 fe:00 7187 /lib/libc-2.28.so > 3ff7fda000-3ff7fdc000 rw-p 00101000 fe:00 7187 /lib/libc-2.28.so > 3ff7fdc000-3ff7fe2000 rw-p 00000000 00:00 0 > 3ff7fe4000-3ff7fe6000 r-xp 00000000 00:00 0 [vdso] > 3ff7fe6000-3ff7ffd000 r-xp 00000000 fe:00 7193 /lib/ld-2.28.so > 3ff7ffd000-3ff7ffe000 r--p 00016000 fe:00 7193 /lib/ld-2.28.so > 3ff7ffe000-3ff7fff000 rw-p 00017000 fe:00 7193 /lib/ld-2.28.so > 3ff7fff000-3ff8000000 rw-p 00000000 00:00 0 > 3fff888000-3fff8a9000 rw-p 00000000 00:00 0 [stack] > > Signed-off-by: Alexandre Ghiti > Reviewed-by: Christoph Hellwig Reviewed-by: Kees Cook -Kees > --- > arch/riscv/Kconfig | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index eb56c82d8aa1..f5897e0dbc1c 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -49,6 +49,17 @@ config RISCV > select GENERIC_IRQ_MULTI_HANDLER > select ARCH_HAS_PTE_SPECIAL > select HAVE_EBPF_JIT if 64BIT > + select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU > + select HAVE_ARCH_MMAP_RND_BITS > + > +config ARCH_MMAP_RND_BITS_MIN > + default 18 > + > +# max bits determined by the following formula: > +# VA_BITS - PAGE_SHIFT - 3 > +config ARCH_MMAP_RND_BITS_MAX > + default 33 if 64BIT # SV48 based > + default 18 > > config MMU > def_bool y > -- > 2.20.1 > -- Kees Cook