All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] m68knommu: add support for elf-fdpic
@ 2022-04-28  3:33 Greg Ungerer
  2022-04-28  3:33 ` [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups Greg Ungerer
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Greg Ungerer @ 2022-04-28  3:33 UTC (permalink / raw)
  To: linux-m68k; +Cc: linux-mm, linux-kernel, dalias, Greg Ungerer

Add support to the m68k architecture code for the elf-fdpic loader.
As of commit 1bde925d2354 ("fs/binfmt_elf_fdpic.c: provide NOMMU loader
for regular ELF binaries") it is possible to run normal ELF executables
on nommu systems. These are simple enough to generate and test - even
without actual elf-fdpic toolchain support.

A few minor changes are required to have everything in place, all on the
architecture code side. The largest required addition is minimal regset
support (for elf-fdpic core dumping), otherwise a couple of cleanups and
some definitions is all that is required.

Note that this is only supporting nommu mode on the m68k at this time.
Changes will be required to the mm_context_t type to support elf-fdpic
with MMU enabled on m68k.

Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
---
 arch/m68k/include/asm/elf.h         |    9 +++++
 arch/m68k/include/asm/mmu.h         |    4 --
 arch/m68k/include/uapi/asm/ptrace.h |    5 +++
 arch/m68k/kernel/ptrace.c           |   58 ++++++++++++++++++++++++++++++++++++
 fs/Kconfig.binfmt                   |    2 -
 5 files changed, 74 insertions(+), 4 deletions(-)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups
  2022-04-28  3:33 [PATCH 0/4] m68knommu: add support for elf-fdpic Greg Ungerer
@ 2022-04-28  3:33 ` Greg Ungerer
  2022-04-28  7:16   ` Geert Uytterhoeven
  2022-04-28  3:33 ` [PATCH 2/4] m68knommu: implement minimal regset support Greg Ungerer
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Greg Ungerer @ 2022-04-28  3:33 UTC (permalink / raw)
  To: linux-m68k; +Cc: linux-mm, linux-kernel, dalias, Greg Ungerer

The nommu case defines its own local mm_context_t structure. There is
nothing special or different about the m68knommu version of this and it
can easily use the common asm-generic version.

Remove the local mmu_context struct and include the asm-generic version
instead. This will also make it easier to support ELF format executables
in the future (since the asm-generic version has support for this
already).

Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
---
 arch/m68k/include/asm/mmu.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/m68k/include/asm/mmu.h b/arch/m68k/include/asm/mmu.h
index 5c15aacb1370..e00672425b00 100644
--- a/arch/m68k/include/asm/mmu.h
+++ b/arch/m68k/include/asm/mmu.h
@@ -6,9 +6,7 @@
 /* Default "unsigned long" context */
 typedef unsigned long mm_context_t;
 #else
-typedef struct {
-	unsigned long		end_brk;
-} mm_context_t;
+#include <asm-generic/mmu.h>
 #endif
 
 #endif
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] m68knommu: implement minimal regset support
  2022-04-28  3:33 [PATCH 0/4] m68knommu: add support for elf-fdpic Greg Ungerer
  2022-04-28  3:33 ` [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups Greg Ungerer
@ 2022-04-28  3:33 ` Greg Ungerer
  2022-04-28  3:33 ` [PATCH 3/4] m68knommu: add definitions to support elf_fdpic program loader Greg Ungerer
  2022-04-28  3:33 ` [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected Greg Ungerer
  3 siblings, 0 replies; 8+ messages in thread
From: Greg Ungerer @ 2022-04-28  3:33 UTC (permalink / raw)
  To: linux-m68k; +Cc: linux-mm, linux-kernel, dalias, Greg Ungerer

Add code support to the m68k architecture for regsets.

Currently the only thing that will need to use regsets for m68k will be
coredump support of the elf_fdpic loader. So the changes are conditional
on that. The added support is the minimum definitions required to support
just that.

Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
---
 arch/m68k/kernel/ptrace.c | 58 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 6342ff4d2073..4349b9c4dd68 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -19,6 +19,8 @@
 #include <linux/ptrace.h>
 #include <linux/user.h>
 #include <linux/signal.h>
+#include <linux/regset.h>
+#include <linux/elf.h>
 
 #include <linux/uaccess.h>
 #include <asm/page.h>
@@ -291,3 +293,59 @@ asmlinkage void syscall_trace_leave(void)
 		ptrace_report_syscall_exit(task_pt_regs(current), 0);
 }
 #endif /* CONFIG_COLDFIRE */
+
+#if defined(CONFIG_BINFMT_ELF_FDPIC) && defined(CONFIG_ELF_CORE)
+/*
+ * Currently the only thing that needs to use regsets for m68k is the
+ * coredump support of the elf_fdpic loader. Implement the minimum
+ * definitions required for that.
+ */
+static int m68k_regset_get(struct task_struct *target,
+			   const struct user_regset *regset,
+			   struct membuf to)
+{
+	struct pt_regs *ptregs = task_pt_regs(target);
+	u32 uregs[ELF_NGREG];
+
+	ELF_CORE_COPY_REGS(uregs, ptregs);
+	return membuf_write(&to, uregs, sizeof(uregs));
+}
+
+enum m68k_regset {
+	REGSET_GPR,
+#ifdef CONFIG_FPU
+	REGSET_FPU,
+#endif
+};
+
+static const struct user_regset m68k_user_regsets[] = {
+	[REGSET_GPR] = {
+		.core_note_type = NT_PRSTATUS,
+		.n = ELF_NGREG,
+		.size = sizeof(u32),
+		.align = sizeof(u16),
+		.regset_get = m68k_regset_get,
+	},
+#ifdef CONFIG_FPU
+	[REGSET_FPU] = {
+		.core_note_type = NT_PRFPREG,
+		.n = sizeof(struct user_m68kfp_struct) / sizeof(u32),
+		.size = sizeof(u32),
+		.align = sizeof(u32),
+	}
+#endif /* CONFIG_FPU */
+};
+
+static const struct user_regset_view user_m68k_view = {
+	.name = "m68k",
+	.e_machine = EM_68K,
+	.ei_osabi = ELF_OSABI,
+	.regsets = m68k_user_regsets,
+	.n = ARRAY_SIZE(m68k_user_regsets)
+};
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+	return &user_m68k_view;
+}
+#endif /* CONFIG_BINFMT_ELF_FDPIC && CONFIG_ELF_CORE */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] m68knommu: add definitions to support elf_fdpic program loader
  2022-04-28  3:33 [PATCH 0/4] m68knommu: add support for elf-fdpic Greg Ungerer
  2022-04-28  3:33 ` [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups Greg Ungerer
  2022-04-28  3:33 ` [PATCH 2/4] m68knommu: implement minimal regset support Greg Ungerer
@ 2022-04-28  3:33 ` Greg Ungerer
  2022-04-28  3:33 ` [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected Greg Ungerer
  3 siblings, 0 replies; 8+ messages in thread
From: Greg Ungerer @ 2022-04-28  3:33 UTC (permalink / raw)
  To: linux-m68k; +Cc: linux-mm, linux-kernel, dalias, Greg Ungerer

Add a few required defines to support using the binfmt_elf_fdpic
loader on the m68k architecture. The values are defined to be consistent
with those used on arm and sh which support this too.

The most important m68k specific change is the register initialization.
The pt_reg structure only contains a subset of the architecture general
registers, so we are more limited than to be expected on what can be used.

Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
---
 arch/m68k/include/asm/elf.h         | 9 +++++++++
 arch/m68k/include/uapi/asm/ptrace.h | 5 +++++
 2 files changed, 14 insertions(+)

diff --git a/arch/m68k/include/asm/elf.h b/arch/m68k/include/asm/elf.h
index 3d387ceaea3f..2def06a99b08 100644
--- a/arch/m68k/include/asm/elf.h
+++ b/arch/m68k/include/asm/elf.h
@@ -60,6 +60,13 @@ typedef struct user_m68kfp_struct elf_fpregset_t;
    is actually used on ASV.  */
 #define ELF_PLAT_INIT(_r, load_addr)	_r->a1 = 0
 
+#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \
+        do { \
+                (_r)->d3 = _exec_map_addr; \
+                (_r)->d4 = _interp_map_addr; \
+                (_r)->d5 = dynamic_addr; \
+        } while(0)
+
 #if defined(CONFIG_SUN3) || defined(CONFIG_COLDFIRE)
 #define ELF_EXEC_PAGESIZE	8192
 #else
@@ -114,4 +121,6 @@ typedef struct user_m68kfp_struct elf_fpregset_t;
 
 #define ELF_PLATFORM  (NULL)
 
+#define ELF_FDPIC_CORE_EFLAGS  0
+
 #endif
diff --git a/arch/m68k/include/uapi/asm/ptrace.h b/arch/m68k/include/uapi/asm/ptrace.h
index 19a1b9d0d858..5b50ea592e00 100644
--- a/arch/m68k/include/uapi/asm/ptrace.h
+++ b/arch/m68k/include/uapi/asm/ptrace.h
@@ -74,7 +74,12 @@ struct switch_stack {
 
 #define PTRACE_GET_THREAD_AREA    25
 
+#define PTRACE_GETFDPIC	31
+
 #define PTRACE_SINGLEBLOCK	33	/* resume execution until next branch */
 
+#define PTRACE_GETFDPIC_EXEC	0
+#define PTRACE_GETFDPIC_INTERP	1
+
 #endif /* __ASSEMBLY__ */
 #endif /* _UAPI_M68K_PTRACE_H */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected
  2022-04-28  3:33 [PATCH 0/4] m68knommu: add support for elf-fdpic Greg Ungerer
                   ` (2 preceding siblings ...)
  2022-04-28  3:33 ` [PATCH 3/4] m68knommu: add definitions to support elf_fdpic program loader Greg Ungerer
@ 2022-04-28  3:33 ` Greg Ungerer
  2022-04-28  7:20   ` Geert Uytterhoeven
  3 siblings, 1 reply; 8+ messages in thread
From: Greg Ungerer @ 2022-04-28  3:33 UTC (permalink / raw)
  To: linux-m68k; +Cc: linux-mm, linux-kernel, dalias, Greg Ungerer

The m68k architecture code is capable of supporting the binfmt_elf_fdpic
loader, so allow it to be configured. It is restricted to nommu
configurations at this time due to the MMU context structures/code not
supporting everything elf_fdpic needs when MMU is enabled.

Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
---
 fs/Kconfig.binfmt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
index 21c6332fa785..2666398120c4 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 || (SUPERH && !MMU))
+	depends on (ARM || ((M68K || SUPERH) && !MMU))
 	select ELFCORE
 	help
 	  ELF FDPIC binaries are based on ELF, but allow the individual load
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups
  2022-04-28  3:33 ` [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups Greg Ungerer
@ 2022-04-28  7:16   ` Geert Uytterhoeven
  0 siblings, 0 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2022-04-28  7:16 UTC (permalink / raw)
  To: Greg Ungerer; +Cc: Linux/m68k, Linux MM, Linux Kernel Mailing List, Rich Felker

On Thu, Apr 28, 2022 at 8:24 AM Greg Ungerer <gerg@linux-m68k.org> wrote:
> The nommu case defines its own local mm_context_t structure. There is
> nothing special or different about the m68knommu version of this and it
> can easily use the common asm-generic version.
>
> Remove the local mmu_context struct and include the asm-generic version
> instead. This will also make it easier to support ELF format executables
> in the future (since the asm-generic version has support for this
> already).
>
> Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected
  2022-04-28  3:33 ` [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected Greg Ungerer
@ 2022-04-28  7:20   ` Geert Uytterhoeven
  2022-04-28 13:41     ` Greg Ungerer
  0 siblings, 1 reply; 8+ messages in thread
From: Geert Uytterhoeven @ 2022-04-28  7:20 UTC (permalink / raw)
  To: Greg Ungerer; +Cc: Linux/m68k, Linux MM, Linux Kernel Mailing List, Rich Felker

Hi Greg,

On Thu, Apr 28, 2022 at 7:05 AM Greg Ungerer <gerg@linux-m68k.org> wrote:
> The m68k architecture code is capable of supporting the binfmt_elf_fdpic
> loader, so allow it to be configured. It is restricted to nommu
> configurations at this time due to the MMU context structures/code not
> supporting everything elf_fdpic needs when MMU is enabled.
>
> Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>

> --- 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 || (SUPERH && !MMU))
> +       depends on (ARM || ((M68K || SUPERH) && !MMU))

While at it, you may want to drop the unneeded outer parentheses,
as they make the expression harder to round, IMHO.

>         select ELFCORE
>         help
>           ELF FDPIC binaries are based on ELF, but allow the individual load

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected
  2022-04-28  7:20   ` Geert Uytterhoeven
@ 2022-04-28 13:41     ` Greg Ungerer
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Ungerer @ 2022-04-28 13:41 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Linux/m68k, Linux MM, Linux Kernel Mailing List, Rich Felker

Hi Geert,

On 28/4/22 17:20, Geert Uytterhoeven wrote:
> Hi Greg,
> 
> On Thu, Apr 28, 2022 at 7:05 AM Greg Ungerer <gerg@linux-m68k.org> wrote:
>> The m68k architecture code is capable of supporting the binfmt_elf_fdpic
>> loader, so allow it to be configured. It is restricted to nommu
>> configurations at this time due to the MMU context structures/code not
>> supporting everything elf_fdpic needs when MMU is enabled.
>>
>> Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
> 
> Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
> 
>> --- 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 || (SUPERH && !MMU))
>> +       depends on (ARM || ((M68K || SUPERH) && !MMU))
> 
> While at it, you may want to drop the unneeded outer parentheses,
> as they make the expression harder to round, IMHO.

Sure thing, will do,

Regards
Greg


>>          select ELFCORE
>>          help
>>            ELF FDPIC binaries are based on ELF, but allow the individual load
> 
> Gr{oetje,eeting}s,
> 
>                          Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                  -- Linus Torvalds

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-28 13:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28  3:33 [PATCH 0/4] m68knommu: add support for elf-fdpic Greg Ungerer
2022-04-28  3:33 ` [PATCH 1/4] m68knommu: use asm-generic/mmu.h for nommu setups Greg Ungerer
2022-04-28  7:16   ` Geert Uytterhoeven
2022-04-28  3:33 ` [PATCH 2/4] m68knommu: implement minimal regset support Greg Ungerer
2022-04-28  3:33 ` [PATCH 3/4] m68knommu: add definitions to support elf_fdpic program loader Greg Ungerer
2022-04-28  3:33 ` [PATCH 4/4] m68knommu: allow elf_fdpic loader to be selected Greg Ungerer
2022-04-28  7:20   ` Geert Uytterhoeven
2022-04-28 13:41     ` Greg Ungerer

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.