From: Leonardo Bras <leobras@redhat.com>
To: Guo Ren <guoren@kernel.org>
Cc: "Leonardo Bras" <leobras@redhat.com>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Eric Biederman" <ebiederm@xmission.com>,
"Kees Cook" <keescook@chromium.org>,
"Oleg Nesterov" <oleg@redhat.com>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Andy Chiu" <andy.chiu@sifive.com>,
"Greg Ungerer" <gerg@kernel.org>,
"Vincent Chen" <vincent.chen@sifive.com>,
"Xiao Wang" <xiao.w.wang@intel.com>,
"Charlie Jenkins" <charlie@rivosinc.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Alexandre Ghiti" <alexghiti@rivosinc.com>,
"Kemeng Shi" <shikemeng@huaweicloud.com>,
"David Hildenbrand" <david@redhat.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Qinglin Pan" <panqinglin2020@iscas.ac.cn>,
"Greentime Hu" <greentime.hu@sifive.com>,
"Björn Töpel" <bjorn@rivosinc.com>,
"Clément Léger" <cleger@rivosinc.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [RFC PATCH 2/4] riscv: add compile-time test into is_compat_task()
Date: Fri, 22 Dec 2023 14:12:22 -0300 [thread overview]
Message-ID: <ZYXDdlF1CFNpDdiV@LeoBras> (raw)
In-Reply-To: <CAJF2gTQNE7OQiAbkvVNzo9PCV=Xr8KQD0_=s-G56QMZJiZnjvA@mail.gmail.com>
On Fri, Dec 22, 2023 at 05:35:20PM +0800, Guo Ren wrote:
> On Fri, Dec 22, 2023 at 5:02 PM Leonardo Bras <leobras@redhat.com> 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 zero 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 extra
> > 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 <leobras@redhat.com>
> > ---
> > 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/elf.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/asm/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 >= 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 >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS)
> > -#define MMAP_MIN_VA_BITS (VA_BITS_SV39)
> > -#endif /* CONFIG_COMPAT */
> > -
> > #else
> > #include <asm/pgtable-32.h>
> > #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 = (addr); \
> > - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \
> > + if ((_addr) == 0 || is_compat_task()) \
> > mmap_end = STACK_TOP_MAX; \
> > else if ((_addr) >= VA_USER_SV57) \
> > mmap_end = STACK_TOP_MAX; \
> > @@ -39,7 +39,7 @@
> > typeof(addr) _addr = (addr); \
> > typeof(base) _base = (base); \
> > unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \
> > - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \
> > + if ((_addr) == 0 || is_compat_task()) \
> > mmap_base = (_base); \
> > else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \
> > mmap_base = VA_USER_SV57 - rnd_gap; \
> > --
> > 2.43.0
> >
> Reviewed-by: Guo Ren <guoren@kernel.org>
Thanks!
Leo
>
> --
> Best Regards
> Guo Ren
>
next prev parent reply other threads:[~2023-12-22 17:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-22 7:46 [RFC PATCH 0/4] Introduce & Optimize compat-mode helpers Leonardo Bras
2023-12-22 7:46 ` [RFC PATCH 1/4] riscv: Replace direct thread flag check with is_compat_task() Leonardo Bras
2023-12-22 7:46 ` [RFC PATCH 2/4] riscv: add compile-time test into is_compat_task() Leonardo Bras
2023-12-22 9:35 ` Guo Ren
2023-12-22 17:12 ` Leonardo Bras [this message]
2023-12-23 4:15 ` Andy Chiu
2023-12-22 7:46 ` [RFC PATCH 3/4] riscv: Introduce is_compat_thread() into compat.h Leonardo Bras
2023-12-22 11:20 ` Guo Ren
2023-12-22 17:14 ` Leonardo Bras
2023-12-23 4:25 ` Andy Chiu
[not found] ` <CAJ6HWG4Pe0co91-tRpV-gKoVUJkobB=uz8J-pjTvyX=Ed49u_w@mail.gmail.com>
2023-12-28 3:10 ` Andy Chiu
2023-12-22 7:46 ` [RFC PATCH 4/4] riscv: Introduce set_compat_task() in asm/compat.h Leonardo Bras
2023-12-22 8:11 ` Guo Ren
2023-12-22 8:28 ` Leonardo Bras
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZYXDdlF1CFNpDdiV@LeoBras \
--to=leobras@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=alexghiti@rivosinc.com \
--cc=andy.chiu@sifive.com \
--cc=aou@eecs.berkeley.edu \
--cc=bjorn@rivosinc.com \
--cc=charlie@rivosinc.com \
--cc=cleger@rivosinc.com \
--cc=conor.dooley@microchip.com \
--cc=david@redhat.com \
--cc=ebiederm@xmission.com \
--cc=gerg@kernel.org \
--cc=greentime.hu@sifive.com \
--cc=guoren@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
--cc=oleg@redhat.com \
--cc=palmer@dabbelt.com \
--cc=panqinglin2020@iscas.ac.cn \
--cc=paul.walmsley@sifive.com \
--cc=shikemeng@huaweicloud.com \
--cc=vincent.chen@sifive.com \
--cc=willy@infradead.org \
--cc=xiao.w.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox