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 181DCC3DA6E for ; Sat, 23 Dec 2023 04:15:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 884516B0072; Fri, 22 Dec 2023 23:15:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 80CB86B0074; Fri, 22 Dec 2023 23:15:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6864A6B0078; Fri, 22 Dec 2023 23:15:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 51BD96B0072 for ; Fri, 22 Dec 2023 23:15:21 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 17E7612072D for ; Sat, 23 Dec 2023 04:15:21 +0000 (UTC) X-FDA: 81596768442.30.D2DC981 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by imf29.hostedemail.com (Postfix) with ESMTP id 29BF012000D for ; Sat, 23 Dec 2023 04:15:18 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=CqfpH6co; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf29.hostedemail.com: domain of andy.chiu@sifive.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=andy.chiu@sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703304919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=pkfSo8ZTFHLoFLmvhQ6WyvO6NSzYvB7Vfz6jJY7OI8E=; b=Bwy76u2LAhAy1/Kj4cVmCDOScLLDVAEus5S9rjF9SrwwU/Gz+ArbTZjwg5JJgVHGG9PbyK wd8uIUz9ULUKkY9xwHsrUnR0gfmaWzbHPs6Bdj154e/2trW7/MfTDtzNWLy4LyuWcVGmfv FomTTae5noH4qiETjf4SVI6BRqdAJ/U= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=CqfpH6co; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf29.hostedemail.com: domain of andy.chiu@sifive.com designates 209.85.128.47 as permitted sender) smtp.mailfrom=andy.chiu@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703304919; a=rsa-sha256; cv=none; b=ZOQUiPC1jdbdjkMN9NYquftakddEVB6ETZytn4TClJJWcvPwILiKpdldizhoFgi08dfKDa AIJTwN8cU7g6C7MIv/hAYKYu0VtH7KmF7XA1NC79ci8s5n2gDKXriyLf2QfB3VnCRh80d/ iuUiVS9zonPHoqd06ZxPMV2uR1INZZk= Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-40c2bb872e2so25030555e9.3 for ; Fri, 22 Dec 2023 20:15:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1703304917; x=1703909717; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pkfSo8ZTFHLoFLmvhQ6WyvO6NSzYvB7Vfz6jJY7OI8E=; b=CqfpH6coI0Oy3j1fyiJL6KiqIYekLTA+1Rt3iGaQSVFocxvOrY2i72FLVjB5/xA13A s9L1TJWt/p0FBAUvolBAiYWfIeOpPqfYzdQK3xBfu4zRfVU7Uqw2gnzaQagtJNJZaKdc bd+bc5u8Q4N98oJZOZF/2gpZ5/PGa1V36vAN+Yq2b8hkq+wWuQkfE4MUjVWbdaoPBL4O +SWiQzf4k0TB2NBt2vt2hP6uI7PBWch4zj8U+5lNLkv32y4jtS0lB1ZhS8ZzKNv57IJ4 KKfq+pW5R9/FOiRi+FundSpbR6iRcRoQ0gz/b7EqoN1oJiTeOmv76OAAkAdsIaIgHt+l SYxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703304917; x=1703909717; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pkfSo8ZTFHLoFLmvhQ6WyvO6NSzYvB7Vfz6jJY7OI8E=; b=ngmiH6wv69676rAPUoN6RaqPqBPp22aHmGxvrAxIsUb74v/tMtRoZiGlWxRywunGYE 2KsE2HtcENWWEO7nHKP9DxCciYUNiBvn5UdiwyFNcQD0T2S2d0O53asl0sd1ADwvWNcg LNBkqZBLPvmnetIDy3Q31HREYHO77qjUsDZNspkuX97P8ZFKyeUKJarh6oG0/Mr8UgwW VAvzCsA5XBYRcfq628qxzMQRX7Bgqzc2sswecs3Da1RWmL+Vzd7fGbP01l4fgzia/vlN 2vkc92epMWbJHeKM4+Uh2QQlFoBVms4culRm1BQuAxY6NuS1hQzM4uOWaepkzkU/Xh+s ZRZQ== X-Gm-Message-State: AOJu0YwMDEneWBrztMWl/hZpIRNaD5EwakfRihD3enSjrouM0jrGmq/j 7RlQI//u1rXGqAJHBsy6wyiUN2vK3XAbUfaZfDkYkxcY2rtpzA== X-Google-Smtp-Source: AGHT+IGaYGYDyJONneRP0Uzt2aGrgYnVBE/mhONMmNVoQkuHi7atohlfvV19NWg29CRxdGSdP2laoTU53gWTjTUIIQ0= X-Received: by 2002:a05:600c:3147:b0:40c:53c2:d7f7 with SMTP id h7-20020a05600c314700b0040c53c2d7f7mr623972wmo.114.1703304917448; Fri, 22 Dec 2023 20:15:17 -0800 (PST) MIME-Version: 1.0 References: <20231222074605.452452-1-leobras@redhat.com> <20231222074605.452452-3-leobras@redhat.com> In-Reply-To: From: Andy Chiu Date: Sat, 23 Dec 2023 12:15:06 +0800 Message-ID: Subject: Re: [RFC PATCH 2/4] riscv: add compile-time test into is_compat_task() To: Leonardo Bras Cc: Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Oleg Nesterov , Conor Dooley , Greg Ungerer , Vincent Chen , Xiao Wang , Charlie Jenkins , Andrew Morton , Alexandre Ghiti , Kemeng Shi , David Hildenbrand , "Matthew Wilcox (Oracle)" , Qinglin Pan , Greentime Hu , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 29BF012000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: fdo3h4prie8edk6jp8upc4ician4s4if X-HE-Tag: 1703304918-590828 X-HE-Meta: U2FsdGVkX1+pr/Y2jEOb46ZRcxxmVgzckLPWdVS2mhvtb27dW0OSf6Stiom7W6sidoykakoxB+8mFzC4lLaCjbot4niw2sqtLsj4aCNCP/oIpMc2VSfwoGxvks1tP/lOWNMb5HGCxfUpNGBXXg3uYj30wyQyK20NOTRsSOnODGpxydeGyUi9BsGbNsopk7KCU6wGbPTN9DpHhxVWm0i0v7isUg4MhzFbtY4wYGDV9fJSNAW+ZkUZZsFi5S4HrqA8oB1dMur1RtHvdgHVxhiD0uYkwaR7xkfUYqzoKxX/m4OrgP8TvoJSXHvLkeYnV6pGp01bwYVtRfNVEopSgeJQFsRJHcqJS1FfuvoZtC5B3pyNcE15YCA4DFASKH0z3bZewVQaZ9nvBJlimlu8gcq4ZGAfPr3kRDXO9nVW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-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sat, Dec 23, 2023 at 1:12=E2=80=AFAM Leonardo Bras = wrote: > > On Fri, Dec 22, 2023 at 05:35:20PM +0800, Guo Ren wrote: > > On Fri, Dec 22, 2023 at 5:02=E2=80=AFPM Leonardo Bras wrote: > > > > > > Currently several places will test for CONFIG_COMPAT before testing > > > is_compat_task(), probably in order to avoid a run-time test into the= task > > > structure. > > > > > > Since is_compat_task() is an inlined function, it would be helpful to= add a > > > compile-time test of CONFIG_COMPAT, making sure it always returns zer= o when > > > the option is not enabled during the kernel build. > > > > > > With this, the compiler is able to understand in build-time that > > > is_compat_task() will always return 0, and optimize-out some of the e= xtra > > > code introduced by the option. > > > > > > This will also allow removing a lot #ifdefs that were introduced, and= make > > > the code more clean. > > > > > > Signed-off-by: Leonardo Bras > > > --- > > > arch/riscv/include/asm/compat.h | 3 +++ > > > arch/riscv/include/asm/elf.h | 4 ---- > > > arch/riscv/include/asm/pgtable.h | 6 ------ > > > arch/riscv/include/asm/processor.h | 4 ++-- > > > 4 files changed, 5 insertions(+), 12 deletions(-) > > > > > > diff --git a/arch/riscv/include/asm/compat.h b/arch/riscv/include/asm= /compat.h > > > index 2ac955b51148f..91517b51b8e27 100644 > > > --- a/arch/riscv/include/asm/compat.h > > > +++ b/arch/riscv/include/asm/compat.h > > > @@ -14,6 +14,9 @@ > > > > > > static inline int is_compat_task(void) > > > { > > > + if (!IS_ENABLED(CONFIG_COMPAT)) > > > + return 0; > > > + > > > return test_thread_flag(TIF_32BIT); > > > } > > > > > > diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/el= f.h > > > index 59a08367fddd7..2e88257cafaea 100644 > > > --- a/arch/riscv/include/asm/elf.h > > > +++ b/arch/riscv/include/asm/elf.h > > > @@ -53,13 +53,9 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr)= ; > > > #define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2= ) > > > > > > #ifdef CONFIG_64BIT > > > -#ifdef CONFIG_COMPAT > > > #define STACK_RND_MASK (is_compat_task() ? \ > > > 0x7ff >> (PAGE_SHIFT - 12) : \ > > > 0x3ffff >> (PAGE_SHIFT - 12)) > > > -#else > > > -#define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12)) > > > -#endif > > > #endif > > > > > > /* > > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/as= m/pgtable.h > > > index 1d472b31e0cfe..ea5b269be223a 100644 > > > --- a/arch/riscv/include/asm/pgtable.h > > > +++ b/arch/riscv/include/asm/pgtable.h > > > @@ -127,16 +127,10 @@ > > > #define VA_USER_SV48 (UL(1) << (VA_BITS_SV48 - 1)) > > > #define VA_USER_SV57 (UL(1) << (VA_BITS_SV57 - 1)) > > > > > > -#ifdef CONFIG_COMPAT > > > #define MMAP_VA_BITS_64 ((VA_BITS >=3D VA_BITS_SV48) ? VA_BITS_SV48 = : VA_BITS) > > > #define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39) > > > #define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS= _64) > > > #define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN= _VA_BITS_64) > > > -#else > > > -#define MMAP_VA_BITS ((VA_BITS >=3D VA_BITS_SV48) ? VA_BITS_SV48 : V= A_BITS) > > > -#define MMAP_MIN_VA_BITS (VA_BITS_SV39) > > > -#endif /* CONFIG_COMPAT */ > > > - > > > #else > > > #include > > > #endif /* CONFIG_64BIT */ > > > diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/= asm/processor.h > > > index f19f861cda549..ed32e53e55999 100644 > > > --- a/arch/riscv/include/asm/processor.h > > > +++ b/arch/riscv/include/asm/processor.h > > > @@ -22,7 +22,7 @@ > > > ({ \ > > > unsigned long mmap_end; \ > > > typeof(addr) _addr =3D (addr); \ > > > - if ((_addr) =3D=3D 0 || (IS_ENABLED(CONFIG_COMPAT) && is_comp= at_task())) \ > > > + if ((_addr) =3D=3D 0 || is_compat_task()) \ > > > mmap_end =3D STACK_TOP_MAX; \ > > > else if ((_addr) >=3D VA_USER_SV57) \ > > > mmap_end =3D STACK_TOP_MAX; \ > > > @@ -39,7 +39,7 @@ > > > typeof(addr) _addr =3D (addr); \ > > > typeof(base) _base =3D (base); \ > > > unsigned long rnd_gap =3D DEFAULT_MAP_WINDOW - (_base); \ > > > - if ((_addr) =3D=3D 0 || (IS_ENABLED(CONFIG_COMPAT) && is_comp= at_task())) \ > > > + if ((_addr) =3D=3D 0 || is_compat_task()) \ > > > mmap_base =3D (_base); \ > > > else if (((_addr) >=3D VA_USER_SV57) && (VA_BITS >=3D VA_BITS= _SV57)) \ > > > mmap_base =3D VA_USER_SV57 - rnd_gap; \ > > > -- > > > 2.43.0 > > > > > Reviewed-by: Guo Ren > > Thanks! > Leo > > > > > -- > > Best Regards > > Guo Ren > > > Reviewed-by: Andy Chiu