Skip to contentSkip to conversation

arm64:kexec: Memstart should not be before the kernel start address

PATCH Superseded Sameer Goel 3 participants 10 messages Apr 26, 2016 – Aug 4, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64:kexec: Memstart should not be before the kernel start address

Starting 4.6-rc4 the kernel memblock start is rounded down to a desirable alignment. So, the kernel can see reserved memory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.

---
 kexec/arch/arm64/kexec-arm64.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
kexec/arch/arm64/kexec-arm64.c +10 -2
index 776596a..5e39f4f 100644
@@ -30,6 +30,12 @@
 #include "kexec-syscall.h"
 #include "arch/options.h"
 
+#define SZ_2M 0x200000
+
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
 /* Global varables the core kexec routines expect. */
 
 unsigned char reuse_initrd;
@@ -944,6 +950,10 @@ static int get_memory_ranges_iomem(struct memory_range *array,
 		str = line + consumed;
 		r.end++;
 
+		if (memcmp(str, "Kernel code\n", 12)==0) {
+			set_memstart(round_down(r.start,SZ_2M));
+		}
+
 		if (memcmp(str, "System RAM\n", 11)) {
 			dbgprintf("%s:%d: SKIP: %016Lx - %016Lx : %s", __func__,
 				__LINE__, r.start, r.end, str);
@@ -956,8 +966,6 @@ static int get_memory_ranges_iomem(struct memory_range *array,
 			__LINE__, r.start, r.end, str);
 
 		array[(*count)++] = r;
-
-		set_memstart(r.start);
 	}
 
 	fclose(fp);
Signature · 7 lines
Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#1 lore raw

Hi,

I already added a patch like this to my series. Is this different?

-Geoff

Quoted 38 lines · Sameer Goel

Starting 4.6-rc4 the kernel memblock start is rounded down to a desirable alignment. So, the kernel can see reserved memory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.

---
 kexec/arch/arm64/kexec-arm64.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
kexec/arch/arm64/kexec-arm64.c +10 -0
index 776596a..5e39f4f 100644
@@ -30,6 +30,12 @@
 #include "kexec-syscall.h"
 #include "arch/options.h"
 
+#define SZ_2M 0x200000
+
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
 /* Global varables the core kexec routines expect. */
 
 unsigned char reuse_initrd;
@@ -944,6 +950,10 @@ static int get_memory_ranges_iomem(struct memory_range *array,
 > 	> 	> str = line + consumed;
 > 	> 	> r.end++;
 
+> 	> 	> if (memcmp(str, "Kernel code\n", 12)==0) {
+> 	> 	> 	> set_memstart(round_down(r.start,SZ_2M));
+> 	> 	> }
+
 > 	> 	> if (memcmp(str, "System RAM\n", 11)) {
 > 	> 	> 	> dbgprintf("%s:%d: SKIP: %016Lx - %016Lx : %s", __func__,
 > 	> 	> 	> 	> __LINE__, r.start, r.end, str);

kexec/arch/arm64/kexec-arm64.c static int get_memory_ranges_iomem(struct memory_range *array, · line 971

Quoted 8 lines
kexec/arch/arm64/kexec-arm64.c +0 -2
@@ -956,8 +966,6 @@ static int get_memory_ranges_iomem(struct memory_range *array,
 > 	> 	> 	> __LINE__, r.start, r.end, str);
 
 > 	> 	> array[(*count)++] = r;
-
-> 	> 	> set_memstart(r.start);
 > 	> }
 
 > 	> fclose(fp);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw

No, this is not. It was just a minor change to the commit message to clarify the change a bit. Appreciate your picking up the patch.

Regards,
Sameer

Quoted 59 lines · Geoff Levand

Hi,

I already added a patch like this to my series. Is this different?

-Geoff

Quoted 38 lines · Sameer Goel

Starting 4.6-rc4 the kernel memblock start is rounded down to a desirable alignment. So, the kernel can see reserved memory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.

---
 kexec/arch/arm64/kexec-arm64.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
kexec/arch/arm64/kexec-arm64.c +10 -0
index 776596a..5e39f4f 100644
@@ -30,6 +30,12 @@
 #include "kexec-syscall.h"
 #include "arch/options.h"
 
+#define SZ_2M 0x200000
+
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
 /* Global varables the core kexec routines expect. */
 
 unsigned char reuse_initrd;
@@ -944,6 +950,10 @@ static int get_memory_ranges_iomem(struct memory_range *array,
 > 	> 	> str = line + consumed;
 > 	> 	> r.end++;
 
+> 	> 	> if (memcmp(str, "Kernel code\n", 12)==0) {
+> 	> 	> 	> set_memstart(round_down(r.start,SZ_2M));
+> 	> 	> }
+
 > 	> 	> if (memcmp(str, "System RAM\n", 11)) {
 > 	> 	> 	> dbgprintf("%s:%d: SKIP: %016Lx - %016Lx : %s", __func__,
 > 	> 	> 	> 	> __LINE__, r.start, r.end, str);

kexec/arch/arm64/kexec-arm64.c static int get_memory_ranges_iomem(struct memory_range *array, · line 971

Quoted 8 lines
kexec/arch/arm64/kexec-arm64.c +0 -2
@@ -956,8 +966,6 @@ static int get_memory_ranges_iomem(struct memory_range *array,
 > 	> 	> 	> __LINE__, r.start, r.end, str);
 
 > 	> 	> array[(*count)++] = r;
-
-> 	> 	> set_memstart(r.start);
 > 	> }
 
 > 	> fclose(fp);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Signature · 8 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#3 lore raw

Hi Sameer,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Sameer Goel
Quoted 6 lines

Starting 4.6-rc4 the kernel memblock start is rounded down to a desirable alignment. So, the kernel can see reserved memory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.
---

It is still in question whether or not your's is the correct fix. Could you provide a test case that hits this problem so we can work on the solution?

Thanks.

-Geoff

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#4 lore raw

Hi Geoff,
In our setup we cannot place the kernel starting at 0 address. So, it it placed at the first valid aligned address after placing the reserved regions in memory.

The code from the change (https://patchwork.kernel.org/patch/8325221/) adds the reserved regions to iomem ranges. So, when the kexec tool is run it picks up the first reserved region as the start address for physical ram. When the kernel is loaded at this address, it fails to boot.

So, I have put in a filter in the code that would pick up the right address of the primary kernel after this change was introduced. Thanks,
Sameer

Quoted 24 lines · Geoff Levand

Hi Sameer,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines · Sameer Goel
Quoted 6 lines

Starting 4.6-rc4 the kernel memblock start is rounded down to a desirable alignment. So, the kernel can see reserved memory regions before the kernel start address in the iomem query.
Need to make sure that the right kernel start address is picked from the iomem query.
---

It is still in question whether or not your's is the correct fix. Could you provide a test case that hits this problem so we can work on the solution?

Thanks.

-Geoff

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Signature · 8 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#5 lore raw

Hi,

Quoted 9 lines · Sameer

In our setup we cannot place the kernel starting at 0 address. So, it it placed at the first valid aligned address after placing the reserved regions in memory.

The code from the change (https://patchwork.kernel.org/patch/8325221/)
adds the reserved regions to iomem ranges. So, when the kexec tool is run it picks up the first reserved region as the start address for physical ram. When the kernel is loaded at this address, it fails to boot.

Quoted 4 lines

So, I have put in a filter in the code that would pick up the right address of the primary kernel after this change was introduced. Thanks,
Sameer

Your patch no longer applies. Please rebase it to my for-merge-arm64-v2 branch and re-post.

-Geoff

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw
Quoted 14 lines · Geoff Levand

Hi,

Quoted 11 lines · Sameer

In our setup we cannot place the kernel starting at 0 address. So, it it placed at the first valid aligned address after placing the reserved regions in memory.

The code from the change (https://patchwork.kernel.org/patch/8325221/)
adds the reserved regions to iomem ranges. So, when the kexec tool is run it picks up the first reserved region as the start address for physical ram. When the kernel is loaded at this address, it fails to boot.

So, I have put in a filter in the code that would pick up the right address of the primary kernel after this change was introduced.

You're using Image, not vmlinux, right?
I don't think that it's a good idea to add this sort of restriction because it is very system-specific.
You'd better use "--mem-min=" parameter in your case.
(In fact, this option doesn't work on the current arm64 port of kexec-tools, though.)

Thanks,
-Takahiro AKASHI

Quoted 9 lines
Quoted 2 lines

Thanks,
Sameer

Your patch no longer applies. Please rebase it to my for-merge-arm64-v2 branch and re-post.

-Geoff

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#7 lore raw

Hi,
I am using vmlinux in this case. Usually the kernel code start is at a 2M alignment from the System RAM start address. Since, kexec default options were not loading the image at the right address (same as the original kernel) and the API used to get iomem listing does not differentiate between the reserved and memblock addresses, I recommended that we look for the Kernel Code segment and round this down to get the right start address. The above should not impact any current functionality or ignore any ram regions when booting the patched kernel.
I will report the patch on V2.
Thanks,
Sameer

Quoted 41 lines · AKASHI Takahiro
Quoted 14 lines · Geoff Levand

Hi,

Quoted 11 lines · Sameer

In our setup we cannot place the kernel starting at 0 address. So, it it placed at the first valid aligned address after placing the reserved regions in memory.

The code from the change (https://patchwork.kernel.org/patch/8325221/)
adds the reserved regions to iomem ranges. So, when the kexec tool is run it picks up the first reserved region as the start address for physical ram. When the kernel is loaded at this address, it fails to boot.

So, I have put in a filter in the code that would pick up the right address of the primary kernel after this change was introduced.

You're using Image, not vmlinux, right?
I don't think that it's a good idea to add this sort of restriction because it is very system-specific.
You'd better use "--mem-min=" parameter in your case.
(In fact, this option doesn't work on the current arm64 port of kexec-tools, though.)

Thanks,
-Takahiro AKASHI

Quoted 9 lines
Quoted 2 lines

Thanks,
Sameer

Your patch no longer applies. Please rebase it to my for-merge-arm64-v2 branch and re-post.

-Geoff

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Signature · 8 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
#8 lore raw
Quoted 6 lines · Sameer

Hi,
I am using vmlinux in this case. Usually the kernel code start is at a 2M alignment from the System RAM start address. Since, kexec default options were not loading the image at the right address (same as the original kernel) and the API used to get iomem listing does not differentiate between the reserved and memblock addresses,

In your original email, you said that you cannot place the kernel at the address 0x0. Is this your problem, isn't it?

If so, you can explicitly specify the start address with "crashkernel=X@Y" parameter. Or we might better add "mem-min" support as I said.

Quoted 4 lines

I recommended that we look for the Kernel Code segment and round this down to get the right start address.
The above should not impact any current functionality or ignore any ram regions when booting the patched kernel.

no need to impose such a unnecessary restriction.

Thanks,
-Takahiro AKASHI

Quoted 39 lines

I will report the patch on V2.
Thanks,
Sameer

Quoted 33 lines · AKASHI Takahiro
Quoted 14 lines · Geoff Levand

Hi,

Quoted 11 lines · Sameer

In our setup we cannot place the kernel starting at 0 address. So, it it placed at the first valid aligned address after placing the reserved regions in memory.

The code from the change (https://patchwork.kernel.org/patch/8325221/)
adds the reserved regions to iomem ranges. So, when the kexec tool is run it picks up the first reserved region as the start address for physical ram. When the kernel is loaded at this address, it fails to boot.

So, I have put in a filter in the code that would pick up the right address of the primary kernel after this change was introduced.

You're using Image, not vmlinux, right?
I don't think that it's a good idea to add this sort of restriction because it is very system-specific.
You'd better use "--mem-min=" parameter in your case.
(In fact, this option doesn't work on the current arm64 port of kexec-tools, though.)

Thanks,
-Takahiro AKASHI

Quoted 7 lines
Quoted 2 lines

Thanks,
Sameer

Your patch no longer applies. Please rebase it to my for-merge-arm64-v2 branch and re-post.

Quoted 13 lines
Quoted 8 lines
Quoted 2 lines

-Geoff

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Signature · 3 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#9 lore raw
Quoted 2 lines

In your original email, you said that you cannot place the kernel at the address 0x0. Is this your problem, isn't it?

Not being able to put the kernel at 0 should not be considered a restriction. The kernel is not mandated to start at 0 address. The tools code was working fine till arm linux developers released a new set of changes to get the alignment right for performance reasons.

This change makes sure that he kernel start is 1GB aligned. So, once the round doen happens the regions that are reserved memblocks are also seen using the iomem query API. The reserved regions should not be considered as a part of the kernel RAM.

Quoted 2 lines

If so, you can explicitly specify the start address with "crashkernel=X@Y" parameter. Or we might better add "mem-min" support as I said.

I agree that the above options will solve this case.

As I mentioned before that not starting at address 0x0 should not be considered a limitation.So, default case of reuse-cmdline should work as is. In this code we are trying to find where the kernel code start is. Based on this info we can always clearly determine the kernel ram start. This would not be a limitation.

Any system ram region located before kernel ram should not be used unless explicitly reclaimed or added.

Thanks,
Sameer

Quoted 77 lines · AKASHI Takahiro
Quoted 6 lines · Sameer

Hi,
I am using vmlinux in this case. Usually the kernel code start is at a 2M alignment from the System RAM start address. Since, kexec default options were not loading the image at the right address (same as the original kernel) and the API used to get iomem listing does not differentiate between the reserved and memblock addresses,

In your original email, you said that you cannot place the kernel at the address 0x0. Is this your problem, isn't it?

If so, you can explicitly specify the start address with "crashkernel=X@Y" parameter. Or we might better add "mem-min" support as I said.

Quoted 4 lines

I recommended that we look for the Kernel Code segment and round this down to get the right start address.
The above should not impact any current functionality or ignore any ram regions when booting the patched kernel.

no need to impose such a unnecessary restriction.

Thanks,
-Takahiro AKASHI

Quoted 52 lines

I will report the patch on V2.
Thanks,
Sameer

Quoted 33 lines · AKASHI Takahiro
Quoted 14 lines · Geoff Levand

Hi,

Quoted 11 lines · Sameer

In our setup we cannot place the kernel starting at 0 address. So, it it placed at the first valid aligned address after placing the reserved regions in memory.

The code from the change (https://patchwork.kernel.org/patch/8325221/)
adds the reserved regions to iomem ranges. So, when the kexec tool is run it picks up the first reserved region as the start address for physical ram. When the kernel is loaded at this address, it fails to boot.

So, I have put in a filter in the code that would pick up the right address of the primary kernel after this change was introduced.

You're using Image, not vmlinux, right?
I don't think that it's a good idea to add this sort of restriction because it is very system-specific.
You'd better use "--mem-min=" parameter in your case.
(In fact, this option doesn't work on the current arm64 port of kexec-tools, though.)

Thanks,
-Takahiro AKASHI

Quoted 7 lines
Quoted 2 lines

Thanks,
Sameer

Your patch no longer applies. Please rebase it to my for-merge-arm64-v2 branch and re-post.

Quoted 8 lines
Quoted 2 lines

-Geoff

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.

Signature · 8 lines
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec