Skip to content

Commit 4c0b5a4

Browse files
Leonardo Braspalmer-dabbelt
authored andcommitted
riscv: add compile-time test into is_compat_task()
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> Reviewed-by: Guo Ren <guoren@kernel.org> Reviewed-by: Andy Chiu <andy.chiu@sifive.com> Link: https://lore.kernel.org/r/20240103160024.70305-5-leobras@redhat.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 9dc3041 commit 4c0b5a4

File tree

4 files changed

+5
-12
lines changed

4 files changed

+5
-12
lines changed

arch/riscv/include/asm/compat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
static inline int is_compat_task(void)
1616
{
17+
if (!IS_ENABLED(CONFIG_COMPAT))
18+
return 0;
19+
1720
return test_thread_flag(TIF_32BIT);
1821
}
1922

arch/riscv/include/asm/elf.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
5353
#define ELF_ET_DYN_BASE ((DEFAULT_MAP_WINDOW / 3) * 2)
5454

5555
#ifdef CONFIG_64BIT
56-
#ifdef CONFIG_COMPAT
5756
#define STACK_RND_MASK (is_compat_task() ? \
5857
0x7ff >> (PAGE_SHIFT - 12) : \
5958
0x3ffff >> (PAGE_SHIFT - 12))
60-
#else
61-
#define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
62-
#endif
6359
#endif
6460

6561
/*

arch/riscv/include/asm/pgtable.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,10 @@
127127
#define VA_USER_SV48 (UL(1) << (VA_BITS_SV48 - 1))
128128
#define VA_USER_SV57 (UL(1) << (VA_BITS_SV57 - 1))
129129

130-
#ifdef CONFIG_COMPAT
131130
#define MMAP_VA_BITS_64 ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS)
132131
#define MMAP_MIN_VA_BITS_64 (VA_BITS_SV39)
133132
#define MMAP_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_VA_BITS_64)
134133
#define MMAP_MIN_VA_BITS (is_compat_task() ? VA_BITS_SV32 : MMAP_MIN_VA_BITS_64)
135-
#else
136-
#define MMAP_VA_BITS ((VA_BITS >= VA_BITS_SV48) ? VA_BITS_SV48 : VA_BITS)
137-
#define MMAP_MIN_VA_BITS (VA_BITS_SV39)
138-
#endif /* CONFIG_COMPAT */
139-
140134
#else
141135
#include <asm/pgtable-32.h>
142136
#endif /* CONFIG_64BIT */

arch/riscv/include/asm/processor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
({ \
2929
unsigned long mmap_end; \
3030
typeof(addr) _addr = (addr); \
31-
if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \
31+
if ((_addr) == 0 || is_compat_task()) \
3232
mmap_end = STACK_TOP_MAX; \
3333
else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \
3434
mmap_end = VA_USER_SV57; \
@@ -45,7 +45,7 @@
4545
typeof(addr) _addr = (addr); \
4646
typeof(base) _base = (base); \
4747
unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \
48-
if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \
48+
if ((_addr) == 0 || is_compat_task()) \
4949
mmap_base = (_base); \
5050
else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \
5151
mmap_base = VA_USER_SV57 - rnd_gap; \

0 commit comments

Comments
 (0)