Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11473962ybi; Thu, 25 Jul 2019 17:21:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzyVehVc2P6zvj/4ntjsKJFeiVIMxytORE6VblR0Zp+6dnsQNJtWdaih8qe3YhMsmUL/ci1 X-Received: by 2002:a17:902:b20c:: with SMTP id t12mr94177013plr.285.1564100504009; Thu, 25 Jul 2019 17:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564100504; cv=none; d=google.com; s=arc-20160816; b=J1OuIWJmJfxEnpAK/NU5SZ9vHstSpU0hUyVY0nyh5w5taUderJ7ES8/c4AlzBL19pp ZxMO3GsXjmF73TOzZ2Fk3608XAnKYJkUGzkjTr2uarBoaEQo3/LhppQw1sLROhMYT4DO BY0NLtRMoHdCR6gbyITjhSRIHpfznnKh8uhmVFhGBlxXRAXoElK3DuhJwJqqGFne7Emd iJUukIOoiIscEPAsTO44TlxArd4DTuYzdKbFG7WTIe6q4x302A+4EXMxEUBczGaNagK/ /9/8NsZA1QJGpm1691G6mSSv4BsoE7zGDc3Yj1rbhbuc0MCfNKNQ/WAkkUtl4aRb/ZX1 B3+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=wVoyay7NO1Taf0v9T8BEjNVHV5CQV4op2+u8nOtjKhg=; b=nJju8ozV4A+2tBeYamg3PHRuyM3880SRRF38BIB2lNfoJsgb5c5XjrCmlSOHLaWbvq 8AIjQWEl5jGBUluQlJMTEUKrv10kfzIVQmvnXwDSQpxB63aL1q/NuyxHvdPCHpw8Hth0 odVf1rpHwAWMINECHXm9DfxBggXdGhzQKGB1e3hD78ejCeDFpg/JCEh8GLWVn6otLUMK Xqe9gCFDkzIDEEJxxE7iS+ep7EfGnxNy5KXHdwyi6xln8ZaeoYcJrAafxZxYcCKOYljJ eqGB8DONpDmA9MRt7DSicI7ptSGP6nwQAA0D4/w4TVEWEcK3x17+O978ksW6OqdDl+oS pYPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=jToOEjgr; 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 n10si22832849pgr.27.2019.07.25.17.21.27; Thu, 25 Jul 2019 17:21:43 -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=@sifive.com header.s=google header.b=jToOEjgr; 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 S1727038AbfGZAUy (ORCPT + 99 others); Thu, 25 Jul 2019 20:20:54 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:34128 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726942AbfGZAUx (ORCPT ); Thu, 25 Jul 2019 20:20:53 -0400 Received: by mail-io1-f67.google.com with SMTP id k8so101188974iot.1 for ; Thu, 25 Jul 2019 17:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=wVoyay7NO1Taf0v9T8BEjNVHV5CQV4op2+u8nOtjKhg=; b=jToOEjgrbrybRXQICjzzQLCzC6a+oGnvytylhhSA9uxtg6WnH51O9ifLdSV6bfGMfa q8niV4muBTTLsVTSbcEIiUpVX+Amr5OSrKkakw3SIsgJ8wNsZyQBOkBDr2dbL5g7FM01 G/XkE2FByaeoL8V88ESwf2TAB2YZjUSsL0fYgL45Wj4T/V0LKEidele78SCI55EuL/J/ sYl0p5itnLMSTOYg3+6E06sl9nRstqfUkqQp7Rox6hXNDgUyeGkR886lLScN+95mjm/T aOi3Bf5eztl/MGmlss1eZVgOtDl8Lkje5E83dmFr4AAMVpQxweZF/aXyNxTquIa66KkV 3ymw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=wVoyay7NO1Taf0v9T8BEjNVHV5CQV4op2+u8nOtjKhg=; b=lMdMywmAd1D54WbAkWpFcT4ZzRL2heM2HTL3wy94M2gj7+KtqOBNhUvH7xamlsS4ez OaJxf3tsuvNQFCCP+48tx67xmOsKUUG7NhoVs1BulUp8Kcmu5H57UwEMWDCLG4MKdL1D GeVvVfiWNBrTjDTQcLvVT8O/aB5UPjpB7w/4Kd1B3C6tB75xFhxegXispuCLGbydNEU9 2V5uaTFPYs4Lh375/tjuWypc3+GCGSUuiyoN0ZuFpzp29ojZ5QYc461ayHRm2PGB2p+N BzZjyc9axlWyWTWG+EVp+aAxMvwNNB+Kj9wBEU8eBpgh48+32Rlgte18tlLFi1v7jK+I SVVQ== X-Gm-Message-State: APjAAAWXvNmPJvsblPTcQL2AgdQteKhQA1E1Ah/lyZFJO497boDcfu9s JQqjq4NHlANYLmdkTA1s1/N5Mg== X-Received: by 2002:a6b:f80e:: with SMTP id o14mr15217081ioh.1.1564100452408; Thu, 25 Jul 2019 17:20:52 -0700 (PDT) Received: from localhost (67-0-24-96.albq.qwest.net. [67.0.24.96]) by smtp.gmail.com with ESMTPSA id 20sm54026778iog.62.2019.07.25.17.20.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 17:20:51 -0700 (PDT) Date: Thu, 25 Jul 2019 17:20:50 -0700 (PDT) From: Paul Walmsley X-X-Sender: paulw@viisi.sifive.com To: Alexandre Ghiti cc: Andrew Morton , Albert Ou , Daniel Cashman , Kees Cook , Catalin Marinas , Palmer Dabbelt , Will Deacon , Russell King , Ralf Baechle , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Paul Burton , Alexander Viro , James Hogan , linux-fsdevel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-mips@vger.kernel.org, Christoph Hellwig , linux-arm-kernel@lists.infradead.org, Luis Chamberlain Subject: Re: [PATCH REBASE v4 14/14] riscv: Make mmap allocation top-down by default In-Reply-To: <20190724055850.6232-15-alex@ghiti.fr> Message-ID: References: <20190724055850.6232-1-alex@ghiti.fr> <20190724055850.6232-15-alex@ghiti.fr> User-Agent: Alpine 2.21.9999 (DEB 301 2018-08-15) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexandre, I have a few questions about this patch. Sorry to be dense here ... On Wed, 24 Jul 2019, 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 > 2de81000-2dea2000 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 > --- > arch/riscv/Kconfig | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 59a4727ecd6c..6a63973873fd 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -54,6 +54,17 @@ config RISCV > select EDAC_SUPPORT > select ARCH_HAS_GIGANTIC_PAGE > select ARCH_WANT_HUGE_PMD_SHARE 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 Could you help me understand the rationale behind this constant? > + > +# max bits determined by the following formula: > +# VA_BITS - PAGE_SHIFT - 3 I realize that these lines are probably copied from arch/arm64/Kconfig. But the rationale behind the "- 3" is not immediately obvious. This apparently originates from commit 8f0d3aa9de57 ("arm64: mm: support ARCH_MMAP_RND_BITS"). Can you provide any additional context here? > +config ARCH_MMAP_RND_BITS_MAX > + default 33 if 64BIT # SV48 based The rationale here is clear for Sv48, per the above formula: (48 - 12 - 3) = 33 > + default 18 However, here it is less clear to me. For Sv39, shouldn't this be (39 - 12 - 3) = 24 ? And what about Sv32? - Paul