Skip to contentSkip to conversation

ARM: kexec: Assemble relocate code in ARM mode

RFC PATCH New Taras Kondratiuk 2 participants 2 messages Oct 18, 2013 – Oct 24, 2013 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode

Quoted 7 lines · Dave Martin
Quoted 3 lines · Taras Kondratiuk

I think it won't help, because here is no direct jump to this label. This code gets copied to a new page and jump is done to the beginning of that page.

Ah, right.

Quoted 8 lines

I think that the fncpy() function should work. This is for the precise purpsoe of copying a function body from one place to another, while reatining the Thumb bit.

I have to disappear early to today, but I'll try and follow up.

Currently, I have the following, but I've not been able to test it yet. If you'd like to give it a try, that would be much appreciated.

I've tried the patch on ARM ISA and looks like the code does what it should, but the reloaded kernel crashes somewhere at early stages. Without this patch it boots fine on ARM. Next week I will try to look what is going on.

Quoted 33 lines

From 94925667e650202e1baf74e1ff223671d316401d Mon Sep 17 00:00:00 2001
From: Dave Martin <[email protected]>
Date: Tue, 15 Oct 2013 11:48:46 +0100
Subject: [PATCH] ARM: kexec: Use the right ISA for relocate_new_kernel

Copying a function with memcpy() and then trying to execute the result isn't portable to Thumb.

This patch modifies the kexec soft restart code to copy its assembler trampoline relocate_new_kernel() using fncpy() instead, so that relocate_new_kernel can be in the same ISA as the rest of the kernel without problems.

---
 arch/arm/kernel/machine_kexec.c   |   20 +++++++++-----------
 arch/arm/kernel/relocate_kernel.S |    7 ++++---
 2 files changed, 13 insertions(+), 14 deletions(-)
arch/arm/kernel/machine_kexec.c +1 -0
index 57221e3..ce135b3 100644
@@ -11,6 +11,7 @@
 #include <linux/memblock.h>
 #include <asm/pgtable.h>
 #include <linux/of_fdt.h>
+#include <asm/fncpy.h>
 #include <asm/pgalloc.h>
 #include <asm/mmu_context.h>
 #include <asm/cacheflush.h>

arch/arm/kernel/machine_kexec.c line 22

Quoted 5 lines
arch/arm/kernel/machine_kexec.c +1 -1
@@ -18,7 +19,7 @@
 #include <asm/smp_plat.h>
 #include <asm/system_misc.h>
 
-extern const unsigned char relocate_new_kernel[];
+extern char relocate_new_kernel;

Shouldn't it be a function pointer?
extern void relocate_new_kernel(void);

Signature · 1 line
Taras Kondratiuk
#2 lore raw

RFC PATCH 1/1 ARM: kexec: Assemble relocate code in ARM mode

Quoted 12 lines · Taras Kondratiuk
Quoted 11 lines · Dave Martin
Quoted 3 lines · Taras Kondratiuk

I think it won't help, because here is no direct jump to this label. This code gets copied to a new page and jump is done to the beginning of that page.

Ah, right.

I think that the fncpy() function should work. This is for the precise purpsoe of copying a function body from one place to another, while reatining the Thumb bit.

Quoted 6 lines
Quoted 4 lines

I have to disappear early to today, but I'll try and follow up.

Currently, I have the following, but I've not been able to test it yet. If you'd like to give it a try, that would be much appreciated.

I've tried the patch on ARM ISA and looks like the code does what

Thanks for giving it a try.

Quoted 3 lines

it should, but the reloaded kernel crashes somewhere at early stages. Without this patch it boots fine on ARM. Next week I will try to look what is going on.

Hmmm, that's a bit strange. You're saying that the new kernel gets loaded and started OK, but crashes during boot?

If relocate_new_kernel() was failing, I would not expect the new kernel to boot at all, unless part of the kernel doesn't get relocated, or something like that.

Quoted 36 lines
Quoted 36 lines

From 94925667e650202e1baf74e1ff223671d316401d Mon Sep 17 00:00:00 2001
From: Dave Martin <[email protected]>
Date: Tue, 15 Oct 2013 11:48:46 +0100
Subject: [PATCH] ARM: kexec: Use the right ISA for relocate_new_kernel

Copying a function with memcpy() and then trying to execute the result isn't portable to Thumb.

This patch modifies the kexec soft restart code to copy its assembler trampoline relocate_new_kernel() using fncpy() instead, so that relocate_new_kernel can be in the same ISA as the rest of the kernel without problems.

---
 arch/arm/kernel/machine_kexec.c   |   20 +++++++++-----------
 arch/arm/kernel/relocate_kernel.S |    7 ++++---
 2 files changed, 13 insertions(+), 14 deletions(-)
arch/arm/kernel/machine_kexec.c +1 -0
index 57221e3..ce135b3 100644
@@ -11,6 +11,7 @@
 #include <linux/memblock.h>
 #include <asm/pgtable.h>
 #include <linux/of_fdt.h>
+#include <asm/fncpy.h>
 #include <asm/pgalloc.h>
 #include <asm/mmu_context.h>
 #include <asm/cacheflush.h>
@@ -18,7 +19,7 @@
 #include <asm/smp_plat.h>
 #include <asm/system_misc.h>
 
Quoted 5 lines

arch/arm/kernel/machine_kexec.c line 22

Quoted 2 lines
arch/arm/kernel/machine_kexec.c +1 -1
-extern const unsigned char relocate_new_kernel[];
+extern char relocate_new_kernel;

Shouldn't it be a function pointer?
extern void relocate_new_kernel(void);

Actually, it could be.

I was forgetting that fncpy was implemented as a macro, allowing it to be more forgiving about argument types.

Casting a function pointer type to a non-function pointer type is illegal in C, but fncpy dodges that problem by hiding the cast inside an asm so that the compiler can't try to do clever optimisations that might break things.

Cheers
---Dave