From: Greg Ungerer <gerg@kernel.org>
To: linux-riscv@lists.infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: Greg Ungerer <gerg@kernel.org>
Subject: [PATCH 2/2] riscv: support the elf-fdpic binfmt loader
Date: Tue, 28 Feb 2023 23:51:26 +1000 [thread overview]
Message-ID: <20230228135126.1686427-3-gerg@kernel.org> (raw)
In-Reply-To: <20230228135126.1686427-1-gerg@kernel.org>
Add support for enabling and using the binfmt_elf_fdpic program loader
on RISC-V platorms. The most important change is to setup registers
during program load to pass the mapping addresses to the new process.
One of the interresting features of the elf-fdpic loader is that it
also allows appropriately compiled ELF format binaries to be loaded on
nommu systems. Appropriate being those compiled with -pie.
Signed-off-by: Greg Ungerer <gerg@kernel.org>
---
arch/riscv/include/asm/elf.h | 11 ++++++++++-
arch/riscv/include/asm/mmu.h | 4 ++++
arch/riscv/include/uapi/asm/ptrace.h | 5 +++++
fs/Kconfig.binfmt | 2 +-
4 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index e7acffdf21d26..95747b35d3262 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -40,6 +40,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
#define compat_elf_check_arch compat_elf_check_arch
#define CORE_DUMP_USE_REGSET
+#define ELF_FDPIC_CORE_EFLAGS 0
#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
/*
@@ -67,6 +68,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
#define ELF_HWCAP (elf_hwcap)
extern unsigned long elf_hwcap;
+#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
+ do { \
+ (_r)->a1 = _exec_map_addr; \
+ (_r)->a2 = _interp_map_addr; \
+ (_r)->a3 = dynamic_addr; \
+ } while (0)
+
/*
* This yields a string that ld.so will use to load implementation
* specific libraries for optimization. This is more specific in
@@ -76,7 +84,6 @@ extern unsigned long elf_hwcap;
#define COMPAT_ELF_PLATFORM (NULL)
-#ifdef CONFIG_MMU
#define ARCH_DLINFO \
do { \
/* \
@@ -104,6 +111,8 @@ do { \
NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \
get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \
} while (0)
+
+#ifdef CONFIG_MMU
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h
index 5ff1f19fd45c2..af3fc3fb4d1ad 100644
--- a/arch/riscv/include/asm/mmu.h
+++ b/arch/riscv/include/asm/mmu.h
@@ -22,6 +22,10 @@ typedef struct {
/* A local tlb flush is needed before user execution can resume. */
cpumask_t tlb_stale_mask;
#endif
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+ unsigned long exec_fdpic_loadmap;
+ unsigned long interp_fdpic_loadmap;
+#endif
} mm_context_t;
void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa,
diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h
index 882547f6bd5c9..93a690509b133 100644
--- a/arch/riscv/include/uapi/asm/ptrace.h
+++ b/arch/riscv/include/uapi/asm/ptrace.h
@@ -10,6 +10,11 @@
#include <linux/types.h>
+#define PTRACE_GETFDPIC 31
+
+#define PTRACE_GETFDPIC_EXEC 0
+#define PTRACE_GETFDPIC_INTERP 1
+
/*
* User-mode register state for core dumps, ptrace, sigcontext
*
diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
index 93539aac0e5b2..f5693164ca9a3 100644
--- a/fs/Kconfig.binfmt
+++ b/fs/Kconfig.binfmt
@@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY
config BINFMT_ELF_FDPIC
bool "Kernel support for FDPIC ELF binaries"
default y if !BINFMT_ELF
- depends on ARM || ((M68K || SUPERH || XTENSA) && !MMU)
+ depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU)
select ELFCORE
help
ELF FDPIC binaries are based on ELF, but allow the individual load
--
2.25.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
WARNING: multiple messages have this Message-ID (diff)
From: Greg Ungerer <gerg@kernel.org>
To: linux-riscv@lists.infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: Greg Ungerer <gerg@kernel.org>
Subject: [PATCH 2/2] riscv: support the elf-fdpic binfmt loader
Date: Tue, 28 Feb 2023 23:51:26 +1000 [thread overview]
Message-ID: <20230228135126.1686427-3-gerg@kernel.org> (raw)
In-Reply-To: <20230228135126.1686427-1-gerg@kernel.org>
Add support for enabling and using the binfmt_elf_fdpic program loader
on RISC-V platorms. The most important change is to setup registers
during program load to pass the mapping addresses to the new process.
One of the interresting features of the elf-fdpic loader is that it
also allows appropriately compiled ELF format binaries to be loaded on
nommu systems. Appropriate being those compiled with -pie.
Signed-off-by: Greg Ungerer <gerg@kernel.org>
---
arch/riscv/include/asm/elf.h | 11 ++++++++++-
arch/riscv/include/asm/mmu.h | 4 ++++
arch/riscv/include/uapi/asm/ptrace.h | 5 +++++
fs/Kconfig.binfmt | 2 +-
4 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index e7acffdf21d26..95747b35d3262 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -40,6 +40,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
#define compat_elf_check_arch compat_elf_check_arch
#define CORE_DUMP_USE_REGSET
+#define ELF_FDPIC_CORE_EFLAGS 0
#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
/*
@@ -67,6 +68,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr);
#define ELF_HWCAP (elf_hwcap)
extern unsigned long elf_hwcap;
+#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
+ do { \
+ (_r)->a1 = _exec_map_addr; \
+ (_r)->a2 = _interp_map_addr; \
+ (_r)->a3 = dynamic_addr; \
+ } while (0)
+
/*
* This yields a string that ld.so will use to load implementation
* specific libraries for optimization. This is more specific in
@@ -76,7 +84,6 @@ extern unsigned long elf_hwcap;
#define COMPAT_ELF_PLATFORM (NULL)
-#ifdef CONFIG_MMU
#define ARCH_DLINFO \
do { \
/* \
@@ -104,6 +111,8 @@ do { \
NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \
get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \
} while (0)
+
+#ifdef CONFIG_MMU
#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
struct linux_binprm;
extern int arch_setup_additional_pages(struct linux_binprm *bprm,
diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h
index 5ff1f19fd45c2..af3fc3fb4d1ad 100644
--- a/arch/riscv/include/asm/mmu.h
+++ b/arch/riscv/include/asm/mmu.h
@@ -22,6 +22,10 @@ typedef struct {
/* A local tlb flush is needed before user execution can resume. */
cpumask_t tlb_stale_mask;
#endif
+#ifdef CONFIG_BINFMT_ELF_FDPIC
+ unsigned long exec_fdpic_loadmap;
+ unsigned long interp_fdpic_loadmap;
+#endif
} mm_context_t;
void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa,
diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h
index 882547f6bd5c9..93a690509b133 100644
--- a/arch/riscv/include/uapi/asm/ptrace.h
+++ b/arch/riscv/include/uapi/asm/ptrace.h
@@ -10,6 +10,11 @@
#include <linux/types.h>
+#define PTRACE_GETFDPIC 31
+
+#define PTRACE_GETFDPIC_EXEC 0
+#define PTRACE_GETFDPIC_INTERP 1
+
/*
* User-mode register state for core dumps, ptrace, sigcontext
*
diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
index 93539aac0e5b2..f5693164ca9a3 100644
--- a/fs/Kconfig.binfmt
+++ b/fs/Kconfig.binfmt
@@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY
config BINFMT_ELF_FDPIC
bool "Kernel support for FDPIC ELF binaries"
default y if !BINFMT_ELF
- depends on ARM || ((M68K || SUPERH || XTENSA) && !MMU)
+ depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU)
select ELFCORE
help
ELF FDPIC binaries are based on ELF, but allow the individual load
--
2.25.1
next prev parent reply other threads:[~2023-02-28 13:53 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 13:51 [PATCH 0/2] riscv: support ELF format binaries in nommu mode Greg Ungerer
2023-02-28 13:51 ` Greg Ungerer
2023-02-28 13:51 ` [PATCH 1/2] binfmt_elf_fdpic: support 64-bit systems Greg Ungerer
2023-02-28 13:51 ` Greg Ungerer
2023-03-21 22:49 ` Palmer Dabbelt
2023-03-21 22:49 ` Palmer Dabbelt
2023-03-29 13:48 ` Greg Ungerer
2023-03-29 13:48 ` Greg Ungerer
2023-04-19 3:27 ` Palmer Dabbelt
2023-04-19 3:27 ` Palmer Dabbelt
2023-04-20 14:58 ` Greg Ungerer
2023-04-20 14:58 ` Greg Ungerer
2023-07-10 23:18 ` Palmer Dabbelt
2023-07-10 23:18 ` Palmer Dabbelt
2023-07-11 11:53 ` Greg Ungerer
2023-07-11 11:53 ` Greg Ungerer
2023-02-28 13:51 ` Greg Ungerer [this message]
2023-02-28 13:51 ` [PATCH 2/2] riscv: support the elf-fdpic binfmt loader Greg Ungerer
2023-02-28 21:52 ` [PATCH 0/2] riscv: support ELF format binaries in nommu mode Palmer Dabbelt
2023-02-28 21:52 ` Palmer Dabbelt
2023-02-28 22:44 ` Maciej W. Rozycki
2023-02-28 22:44 ` Maciej W. Rozycki
2023-02-28 22:49 ` Damien Le Moal
2023-02-28 22:49 ` Damien Le Moal
2023-03-01 0:24 ` Greg Ungerer
2023-03-01 0:24 ` Greg Ungerer
2023-03-01 1:14 ` Damien Le Moal
2023-03-01 1:14 ` Damien Le Moal
2023-03-01 9:46 ` Niklas Cassel
2023-03-01 9:46 ` Niklas Cassel
2023-03-01 0:20 ` Greg Ungerer
2023-03-01 0:20 ` Greg Ungerer
2023-03-15 3:58 ` Palmer Dabbelt
2023-03-15 3:58 ` Palmer Dabbelt
2023-03-15 4:12 ` Damien Le Moal
2023-03-15 4:12 ` Damien Le Moal
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=20230228135126.1686427-3-gerg@kernel.org \
--to=gerg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-riscv@lists.infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.