From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7228AC433F5 for ; Thu, 25 Nov 2021 10:43:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D32706B0075; Thu, 25 Nov 2021 05:42:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CE1A96B007B; Thu, 25 Nov 2021 05:42:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B83076B007D; Thu, 25 Nov 2021 05:42:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0244.hostedemail.com [216.40.44.244]) by kanga.kvack.org (Postfix) with ESMTP id A4D006B0075 for ; Thu, 25 Nov 2021 05:42:50 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 61A8782DF9FD for ; Thu, 25 Nov 2021 10:42:40 +0000 (UTC) X-FDA: 78847114080.03.89C44F3 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf15.hostedemail.com (Postfix) with ESMTP id 924A8D000081 for ; Thu, 25 Nov 2021 10:42:34 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4J0DwY21xqz9sSF; Thu, 25 Nov 2021 11:42:37 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nw29zLpg9ntr; Thu, 25 Nov 2021 11:42:37 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4J0DwY0pwpz9sRt; Thu, 25 Nov 2021 11:42:37 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id F23758B77A; Thu, 25 Nov 2021 11:42:36 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id glwMjUd7MNY6; Thu, 25 Nov 2021 11:42:36 +0100 (CET) Received: from [192.168.203.227] (unknown [192.168.203.227]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 485A28B763; Thu, 25 Nov 2021 11:42:36 +0100 (CET) Message-ID: <3f3578d4-168e-54ef-a3a7-cb7ec2aed43c@csgroup.eu> Date: Thu, 25 Nov 2021 11:42:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [PATCH v2 9/9] powerpc: Simplify and move arch_randomize_brk() Content-Language: fr-FR To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , alex@ghiti.fr Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org References: <4c5a2b18774552c2226573f7069ffeee71ad77cb.1637828367.git.christophe.leroy@csgroup.eu> From: Christophe Leroy In-Reply-To: <4c5a2b18774552c2226573f7069ffeee71ad77cb.1637828367.git.christophe.leroy@csgroup.eu> Content-Type: text/plain; charset=UTF-8; format=flowed X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 924A8D000081 X-Stat-Signature: khajotc1m57x5smh9s388gm597fdkniu Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none X-HE-Tag: 1637836954-287191 Content-Transfer-Encoding: quoted-printable 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: Le 25/11/2021 =C3=A0 09:23, Christophe Leroy a =C3=A9crit=C2=A0: > arch_randomize_brk() is only needed for hash on book3s/64, for other > platforms the one provided by the default mmap layout is good enough. >=20 > Move it to hash_utils.c and use randomize_page() like the generic one. >=20 > And properly opt out the radix case instead of making an assumption > on mmu_highuser_ssize. >=20 > Also change to a 32M range like most other architectures instead of 8M. >=20 > Signed-off-by: Christophe Leroy > --- > v2: New > --- > arch/powerpc/kernel/process.c | 40 --------------------------= - > arch/powerpc/mm/book3s64/hash_utils.c | 18 ++++++++++++ > include/linux/sizes.h | 2 ++ > 3 files changed, 20 insertions(+), 40 deletions(-) >=20 > diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/proces= s.c > index 406d7ee9e322..f1f2f17543d6 100644 > --- a/arch/powerpc/kernel/process.c > +++ b/arch/powerpc/kernel/process.c > @@ -2274,43 +2274,3 @@ unsigned long arch_align_stack(unsigned long sp) > sp -=3D get_random_int() & ~PAGE_MASK; > return sp & ~0xf; > } > - > -static inline unsigned long brk_rnd(void) > -{ > - unsigned long rnd =3D 0; > - > - /* 8MB for 32bit, 1GB for 64bit */ > - if (is_32bit_task()) > - rnd =3D (get_random_long() % (1UL<<(23-PAGE_SHIFT))); > - else > - rnd =3D (get_random_long() % (1UL<<(30-PAGE_SHIFT))); > - > - return rnd << PAGE_SHIFT; > -} > - > -unsigned long arch_randomize_brk(struct mm_struct *mm) > -{ > - unsigned long base =3D mm->brk; > - unsigned long ret; > - > -#ifdef CONFIG_PPC_BOOK3S_64 > - /* > - * If we are using 1TB segments and we are allowed to randomise > - * the heap, we can put it above 1TB so it is backed by a 1TB > - * segment. Otherwise the heap will be in the bottom 1TB > - * which always uses 256MB segments and this may result in a > - * performance penalty. We don't need to worry about radix. For > - * radix, mmu_highuser_ssize remains unchanged from 256MB. > - */ > - if (!is_32bit_task() && (mmu_highuser_ssize =3D=3D MMU_SEGSIZE_1T)) > - base =3D max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T); > -#endif > - > - ret =3D PAGE_ALIGN(base + brk_rnd()); > - > - if (ret < mm->brk) > - return mm->brk; > - > - return ret; > -} > - > diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/bo= ok3s64/hash_utils.c > index 1d09d4aeddbf..3521fad6a479 100644 > --- a/arch/powerpc/mm/book3s64/hash_utils.c > +++ b/arch/powerpc/mm/book3s64/hash_utils.c > @@ -37,6 +37,7 @@ > #include > #include > #include > +#include Also need to get the declaration of=20 arch_randomize_brk() and make sparse happy :) Michael can you add it if you apply this version ? Thanks > =20 > #include > #include > @@ -2072,3 +2073,20 @@ void __init print_system_hash_info(void) > if (htab_hash_mask) > pr_info("htab_hash_mask =3D 0x%lx\n", htab_hash_mask); > } > + > +unsigned long arch_randomize_brk(struct mm_struct *mm) > +{ > + /* > + * If we are using 1TB segments and we are allowed to randomise > + * the heap, we can put it above 1TB so it is backed by a 1TB > + * segment. Otherwise the heap will be in the bottom 1TB > + * which always uses 256MB segments and this may result in a > + * performance penalty. > + */ > + if (is_32bit_task()) > + return randomize_page(mm->brk, SZ_32M); > + else if (!radix_enabled() && mmu_highuser_ssize =3D=3D MMU_SEGSIZE_1T= ) > + return randomize_page(max_t(unsigned long, mm->brk, SZ_1T), SZ_1G); > + else > + return randomize_page(mm->brk, SZ_1G); > +} > diff --git a/include/linux/sizes.h b/include/linux/sizes.h > index 1ac79bcee2bb..84aa448d8bb3 100644 > --- a/include/linux/sizes.h > +++ b/include/linux/sizes.h > @@ -47,6 +47,8 @@ > #define SZ_8G _AC(0x200000000, ULL) > #define SZ_16G _AC(0x400000000, ULL) > #define SZ_32G _AC(0x800000000, ULL) > + > +#define SZ_1T _AC(0x10000000000, ULL) > #define SZ_64T _AC(0x400000000000, ULL) > =20 > #endif /* __LINUX_SIZES_H__ */ >=20