Skip to content

Commit

Permalink
elf: Move arch_setup_additional_pages() to generic elf.h
Browse files Browse the repository at this point in the history
Ifdef the function in the header, not in the code.
Following kernel style, move it to Kconfig.
All it makes it easier to follow when the option is enabled/disabled.
Remove re-definition from compat_binfmt_elf, as it's always defined
under compat_arch_setup_additional_pages (to be reworked).

Signed-off-by: Dmitry Safonov <dima@arista.com>
  • Loading branch information
0x7f454c46 authored and intel-lab-lkp committed Nov 9, 2020
1 parent f6d79fc commit c46ac7d
Show file tree
Hide file tree
Showing 32 changed files with 30 additions and 74 deletions.
1 change: 1 addition & 0 deletions arch/arm/Kconfig
Expand Up @@ -15,6 +15,7 @@ config ARM
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
select ARCH_HAS_PHYS_TO_DMA
select ARCH_HAS_SETUP_ADDITIONAL_PAGES if MMU
select ARCH_HAS_SETUP_DMA_OPS
select ARCH_HAS_SET_MEMORY
select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL
Expand Down
5 changes: 0 additions & 5 deletions arch/arm/include/asm/elf.h
Expand Up @@ -132,17 +132,12 @@ extern int arm_elf_read_implies_exec(int);
extern void elf_set_personality(const struct elf32_hdr *);
#define SET_PERSONALITY(ex) elf_set_personality(&(ex))

#ifdef CONFIG_MMU
#ifdef CONFIG_VDSO
#define ARCH_DLINFO \
do { \
NEW_AUX_ENT(AT_SYSINFO_EHDR, \
(elf_addr_t)current->mm->context.vdso); \
} while (0)
#endif
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
struct linux_binprm;
int arch_setup_additional_pages(struct linux_binprm *, int);
#endif

#endif
1 change: 1 addition & 0 deletions arch/arm64/Kconfig
Expand Up @@ -26,6 +26,7 @@ config ARM64
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
select ARCH_HAS_PTE_DEVMAP
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_SETUP_DMA_OPS
select ARCH_HAS_SET_DIRECT_MAP
select ARCH_HAS_SET_MEMORY
Expand Down
6 changes: 1 addition & 5 deletions arch/arm64/include/asm/elf.h
Expand Up @@ -181,11 +181,6 @@ do { \
NEW_AUX_ENT(AT_IGNORE, 0); \
} while (0)

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);

/* 1GB of VA */
#ifdef CONFIG_COMPAT
#define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
Expand Down Expand Up @@ -242,6 +237,7 @@ do { \
#else
#define COMPAT_ARCH_DLINFO
#endif
struct linux_binprm;
extern int aarch32_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#define compat_arch_setup_additional_pages \
Expand Down
1 change: 1 addition & 0 deletions arch/csky/Kconfig
Expand Up @@ -4,6 +4,7 @@ config CSKY
select ARCH_32BIT_OFF_T
select ARCH_HAS_DMA_PREP_COHERENT
select ARCH_HAS_GCOV_PROFILE_ALL
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_SYNC_DMA_FOR_CPU
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
select ARCH_USE_BUILTIN_BSWAP
Expand Down
4 changes: 0 additions & 4 deletions arch/csky/include/asm/elf.h
Expand Up @@ -84,8 +84,4 @@ extern int dump_task_regs(struct task_struct *tsk, elf_gregset_t *elf_regs);
#define ELF_PLATFORM (NULL)
#define SET_PERSONALITY(ex) set_personality(PER_LINUX)

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#endif /* __ASM_CSKY_ELF_H */
1 change: 1 addition & 0 deletions arch/hexagon/Kconfig
Expand Up @@ -5,6 +5,7 @@ comment "Linux Kernel Configuration for Hexagon"
config HEXAGON
def_bool y
select ARCH_32BIT_OFF_T
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
select ARCH_NO_PREEMPT
select HAVE_OPROFILE
Expand Down
6 changes: 0 additions & 6 deletions arch/hexagon/include/asm/elf.h
Expand Up @@ -207,10 +207,4 @@ do { \
*/
#define ELF_PLATFORM (NULL)

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);


#endif
1 change: 1 addition & 0 deletions arch/mips/Kconfig
Expand Up @@ -7,6 +7,7 @@ config MIPS
select ARCH_HAS_FORTIFY_SOURCE
select ARCH_HAS_KCOV
select ARCH_HAS_PTE_SPECIAL if !(32BIT && CPU_HAS_RIXI)
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_HAS_UBSAN_SANITIZE_ALL
select ARCH_SUPPORTS_UPROBES
Expand Down
5 changes: 0 additions & 5 deletions arch/mips/include/asm/elf.h
Expand Up @@ -480,11 +480,6 @@ do { \
(unsigned long)current->mm->context.vdso); \
} while (0)

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);

#ifdef CONFIG_MIPS_FP_SUPPORT

struct arch_elf_state {
Expand Down
1 change: 1 addition & 0 deletions arch/nds32/Kconfig
Expand Up @@ -8,6 +8,7 @@ config NDS32
def_bool y
select ARCH_32BIT_OFF_T
select ARCH_HAS_DMA_PREP_COHERENT
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_SYNC_DMA_FOR_CPU
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
select ARCH_WANT_FRAME_POINTERS if FTRACE
Expand Down
3 changes: 0 additions & 3 deletions arch/nds32/include/asm/elf.h
Expand Up @@ -173,8 +173,5 @@ do { \
NEW_AUX_ENT(AT_SYSINFO_EHDR, \
(elf_addr_t)current->mm->context.vdso); \
} while (0)
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
struct linux_binprm;
int arch_setup_additional_pages(struct linux_binprm *, int);

#endif
1 change: 1 addition & 0 deletions arch/nios2/Kconfig
Expand Up @@ -3,6 +3,7 @@ config NIOS2
def_bool y
select ARCH_32BIT_OFF_T
select ARCH_HAS_DMA_PREP_COHERENT
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_SYNC_DMA_FOR_CPU
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
select ARCH_HAS_DMA_SET_UNCACHED
Expand Down
4 changes: 0 additions & 4 deletions arch/nios2/include/asm/elf.h
Expand Up @@ -28,10 +28,6 @@
/* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
now struct_user_regs, they are different) */

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#define ELF_CORE_COPY_REGS(pr_reg, regs) \
{ do { \
/* Bleech. */ \
Expand Down
1 change: 1 addition & 0 deletions arch/powerpc/Kconfig
Expand Up @@ -134,6 +134,7 @@ config PPC
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_MEMBARRIER_CALLBACKS
select ARCH_HAS_MEMBARRIER_SYNC_CORE
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_SCALED_CPUTIME if VIRT_CPU_ACCOUNTING_NATIVE && PPC_BOOK3S_64
select ARCH_HAS_STRICT_KERNEL_RWX if (PPC32 && !HIBERNATION)
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
Expand Down
5 changes: 0 additions & 5 deletions arch/powerpc/include/asm/elf.h
Expand Up @@ -111,11 +111,6 @@ extern int dcache_bsize;
extern int icache_bsize;
extern int ucache_bsize;

/* vDSO has arch_setup_additional_pages */
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#define VDSO_AUX_ENT(a,b) NEW_AUX_ENT(a,b)

/* 1GB for 64bit, 8MB for 32bit */
Expand Down
1 change: 1 addition & 0 deletions arch/riscv/Kconfig
Expand Up @@ -26,6 +26,7 @@ config RISCV
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_SET_DIRECT_MAP
select ARCH_HAS_SET_MEMORY
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_STRICT_KERNEL_RWX if MMU
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
Expand Down
5 changes: 0 additions & 5 deletions arch/riscv/include/asm/elf.h
Expand Up @@ -75,10 +75,5 @@ do { \
NEW_AUX_ENT(AT_L2_CACHEGEOMETRY, \
get_cache_geometry(2, CACHE_TYPE_UNIFIED)); \
} while (0)
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#endif /* CONFIG_MMU */

#endif /* _ASM_RISCV_ELF_H */
1 change: 1 addition & 0 deletions arch/s390/Kconfig
Expand Up @@ -67,6 +67,7 @@ config S390
select ARCH_HAS_MEM_ENCRYPT
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_SET_MEMORY
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_STRICT_KERNEL_RWX
select ARCH_HAS_STRICT_MODULE_RWX
select ARCH_HAS_SYSCALL_WRAPPER
Expand Down
5 changes: 0 additions & 5 deletions arch/s390/include/asm/elf.h
Expand Up @@ -276,9 +276,4 @@ do { \
(unsigned long)current->mm->context.vdso_base); \
} while (0)

struct linux_binprm;

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
int arch_setup_additional_pages(struct linux_binprm *, int);

#endif
1 change: 1 addition & 0 deletions arch/sh/Kconfig
Expand Up @@ -8,6 +8,7 @@ config SUPERH
select ARCH_HAS_GIGANTIC_PAGE
select ARCH_HAS_GCOV_PROFILE_ALL
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_SETUP_ADDITIONAL_PAGES if VSYSCALL
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_HIBERNATION_POSSIBLE if MMU
select ARCH_MIGHT_HAVE_PC_PARPORT
Expand Down
6 changes: 0 additions & 6 deletions arch/sh/include/asm/elf.h
Expand Up @@ -164,12 +164,6 @@ do { \
set_personality(PER_LINUX_32BIT | (current->personality & (~PER_MASK)))

#ifdef CONFIG_VSYSCALL
/* vDSO has arch_setup_additional_pages */
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);

extern unsigned int vdso_enabled;
extern void __kernel_vsyscall;

Expand Down
1 change: 1 addition & 0 deletions arch/sparc/Kconfig
Expand Up @@ -13,6 +13,7 @@ config 64BIT
config SPARC
bool
default y
select ARCH_HAS_SETUP_ADDITIONAL_PAGES if SPARC64
select ARCH_MIGHT_HAVE_PC_PARPORT if SPARC64 && PCI
select ARCH_MIGHT_HAVE_PC_SERIO
select DMA_OPS
Expand Down
6 changes: 0 additions & 6 deletions arch/sparc/include/asm/elf_64.h
Expand Up @@ -223,10 +223,4 @@ do { \
NEW_AUX_ENT(AT_ADI_NBITS, adi_state.caps.nbits); \
NEW_AUX_ENT(AT_ADI_UEONADI, adi_state.caps.ue_on_adi); \
} while (0)

struct linux_binprm;

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#endif /* !(__ASM_SPARC64_ELF_H) */
1 change: 1 addition & 0 deletions arch/x86/Kconfig
Expand Up @@ -78,6 +78,7 @@ config X86
select ARCH_HAS_COPY_MC if X86_64
select ARCH_HAS_SET_MEMORY
select ARCH_HAS_SET_DIRECT_MAP
select ARCH_HAS_SETUP_ADDITIONAL_PAGES
select ARCH_HAS_STRICT_KERNEL_RWX
select ARCH_HAS_STRICT_MODULE_RWX
select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
Expand Down
4 changes: 0 additions & 4 deletions arch/x86/include/asm/elf.h
Expand Up @@ -378,10 +378,6 @@ else \
vdso_image_32.sym___kernel_vsyscall)

struct linux_binprm;

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
Expand Down
5 changes: 0 additions & 5 deletions arch/x86/um/asm/elf.h
Expand Up @@ -181,11 +181,6 @@ do { \
#define FIXADDR_USER_START 0
#define FIXADDR_USER_END 0

#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);

extern unsigned long um_vdso_addr;
#define AT_SYSINFO_EHDR 33
#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr)
Expand Down
3 changes: 3 additions & 0 deletions fs/Kconfig.binfmt
Expand Up @@ -39,6 +39,9 @@ config ARCH_BINFMT_ELF_STATE
config ARCH_HAVE_ELF_PROT
bool

config ARCH_HAS_SETUP_ADDITIONAL_PAGES
bool

config ARCH_USE_GNU_PROPERTY
bool

Expand Down
2 changes: 0 additions & 2 deletions fs/binfmt_elf.c
Expand Up @@ -1249,11 +1249,9 @@ static int load_elf_binary(struct linux_binprm *bprm)

set_binfmt(&elf_format);

#ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES
retval = arch_setup_additional_pages(bprm, !!interpreter);
if (retval < 0)
goto out;
#endif /* ARCH_HAS_SETUP_ADDITIONAL_PAGES */

retval = create_elf_tables(bprm, elf_ex,
load_addr, interp_load_addr, e_entry);
Expand Down
3 changes: 1 addition & 2 deletions fs/binfmt_elf_fdpic.c
Expand Up @@ -374,11 +374,10 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
executable_stack);
if (retval < 0)
goto error;
#ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES

retval = arch_setup_additional_pages(bprm, !!interpreter_name);
if (retval < 0)
goto error;
#endif
#endif

/* load the executable and interpreter into memory */
Expand Down
2 changes: 0 additions & 2 deletions fs/compat_binfmt_elf.c
Expand Up @@ -116,8 +116,6 @@
#endif

#ifdef compat_arch_setup_additional_pages
#undef ARCH_HAS_SETUP_ADDITIONAL_PAGES
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
#undef arch_setup_additional_pages
#define arch_setup_additional_pages compat_arch_setup_additional_pages
#endif
Expand Down
12 changes: 12 additions & 0 deletions include/linux/elf.h
Expand Up @@ -104,4 +104,16 @@ static inline int arch_elf_adjust_prot(int prot,
}
#endif

struct linux_binprm;
#ifdef CONFIG_ARCH_HAS_SETUP_ADDITIONAL_PAGES
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#else
static inline int arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp)
{
return 0;
}
#endif

#endif /* _LINUX_ELF_H */

0 comments on commit c46ac7d

Please sign in to comment.