Skip to contentSkip to conversation

kexec: increase max of kexec segments and use dynamic allocation

PATCH Superseded Amerigo Wang 3 participants 9 messages Jul 22, 2010 – Jul 27, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec: increase max of kexec segments and use dynamic allocation

Currently KEXEC_SEGMENT_MAX is only 16 which is too small for machine with many memory ranges. Increase this hard limit to 1024 which is reasonably large, and change ->segment from a static array to a dynamically allocated memory.

---

arch/powerpc/kernel/machine_kexec_64.c +6 -7
index ed31a29..f115585 100644
@@ -131,10 +131,7 @@ static void copy_segments(unsigned long ind)
 void kexec_copy_flush(struct kimage *image)
 {
 	long i, nr_segments = image->nr_segments;
-	struct  kexec_segment ranges[KEXEC_SEGMENT_MAX];
-
-	/* save the ranges on the stack to efficiently flush the icache */
-	memcpy(ranges, image->segment, sizeof(ranges));
+	struct  kexec_segment range;
 
 	/*
 	 * After this call we may not use anything allocated in dynamic
@@ -148,9 +145,11 @@ void kexec_copy_flush(struct kimage *image)
 	 * we need to clear the icache for all dest pages sometime,
 	 * including ones that were in place on the original copy
 	 */
-	for (i = 0; i < nr_segments; i++)
-		flush_icache_range((unsigned long)__va(ranges[i].mem),
-			(unsigned long)__va(ranges[i].mem + ranges[i].memsz));
+	for (i = 0; i < nr_segments; i++) {
+		memcpy(&range, &image->segment[i], sizeof(range));
+		flush_icache_range((unsigned long)__va(range.mem),
+			(unsigned long)__va(range.mem + range.memsz));
+	}
 }
 
 #ifdef CONFIG_SMP
include/linux/kexec.h +2 -2
index 03e8e8d..26b70ff 100644
@@ -57,7 +57,7 @@ typedef unsigned long kimage_entry_t;
 #define IND_DONE         0x4
 #define IND_SOURCE       0x8
 
-#define KEXEC_SEGMENT_MAX 16
+#define KEXEC_SEGMENT_MAX 1024
 struct kexec_segment {
 	void __user *buf;
 	size_t bufsz;
@@ -86,7 +86,7 @@ struct kimage {
 	struct page *swap_page;
 
 	unsigned long nr_segments;
-	struct kexec_segment segment[KEXEC_SEGMENT_MAX];
+	struct kexec_segment *segment;
 
 	struct list_head control_pages;
 	struct list_head dest_pages;
kernel/kexec.c +15 -3
index 131b170..3f97309 100644
@@ -131,6 +131,11 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry,
 	if (!image)
 		goto out;
 
+	image->segment = kzalloc(nr_segments * sizeof(struct kexec_segment),
+				 GFP_KERNEL);
+	if (!image->segment)
+		goto out;
+
 	image->head = 0;
 	image->entry = &image->head;
 	image->last_entry = &image->head;
@@ -216,8 +221,10 @@ static int do_kimage_alloc(struct kimage **rimage, unsigned long entry,
 out:
 	if (result == 0)
 		*rimage = image;
-	else
+	else if (image) {
+		kfree(image->segment);
 		kfree(image);
+	}
 
 	return result;
 
@@ -261,8 +268,10 @@ static int kimage_normal_alloc(struct kimage **rimage, unsigned long entry,
  out:
 	if (result == 0)
 		*rimage = image;
-	else
+	else if (image) {
+		kfree(image->segment);
 		kfree(image);
+	}
 
 	return result;
 }
@@ -330,8 +339,10 @@ static int kimage_crash_alloc(struct kimage **rimage, unsigned long entry,
 out:
 	if (result == 0)
 		*rimage = image;
-	else
+	else if (image) {
+		kfree(image->segment);
 		kfree(image);
+	}
 
 	return result;
 }
@@ -656,6 +667,7 @@ static void kimage_free(struct kimage *image)
 
 	/* Free the kexec control pages... */
 	kimage_free_page_list(&image->control_pages);
+	kfree(image->segment);
 	kfree(image);
 }
 
#1 lore raw
Quoted 3 lines · Amerigo Wang

Currently KEXEC_SEGMENT_MAX is only 16 which is too small for machine with many memory ranges. Increase this hard limit to 1024 which is reasonably large, and change ->segment from a static array to a dynamically allocated memory.

???

This should be about segments in the executable being loaded. What executable has one segment for each range of physical memory?

Not that generalizing this is a bad idea but with a comment that seems entirely wrong I am wondering what the problem really is.

Eric

author
#2 lore raw
Quoted 6 lines · Eric W. Biederman
Quoted 3 lines · Amerigo Wang

Currently KEXEC_SEGMENT_MAX is only 16 which is too small for machine with many memory ranges. Increase this hard limit to 1024 which is reasonably large, and change ->segment from a static array to a dynamically allocated memory.

Quoted 8 lines

???

This should be about segments in the executable being loaded. What executable has one segment for each range of physical memory?

Not that generalizing this is a bad idea but with a comment that seems entirely wrong I am wondering what the problem really is.

Ah, I think Neil should explain this.

He made a patch which includes many memory ranges, caused kexec fails to load the kernel. Increasing this limit and the corresponding one in kexec-tools fixes the problem. His patch is not in upstream kexec-tools, AFAIK.

However, even if we don't consider that patch, isn't 16 too small too?

Thanks.

Signature · 2 lines
The opposite of love is not hate, it's indifference.
 - Elie Wiesel
#3 lore raw
Quoted 16 lines · Cong Wang
Quoted 6 lines · Eric W. Biederman
Quoted 3 lines · Amerigo Wang

Currently KEXEC_SEGMENT_MAX is only 16 which is too small for machine with many memory ranges. Increase this hard limit to 1024 which is reasonably large, and change ->segment from a static array to a dynamically allocated memory.

Quoted 8 lines

???

This should be about segments in the executable being loaded. What executable has one segment for each range of physical memory?

Not that generalizing this is a bad idea but with a comment that seems entirely wrong I am wondering what the problem really is.

Quoted 8 lines

Ah, I think Neil should explain this.

He made a patch which includes many memory ranges, caused kexec fails to load the kernel. Increasing this limit and the corresponding one in kexec-tools fixes the problem. His patch is not in upstream kexec-tools, AFAIK.

However, even if we don't consider that patch, isn't 16 too small too?

Generally you just need one physical hunk for the code, maybe a second for the initrd.

It is perfectly fine to raise the number of segments as it doesn't affect the ABI, but it wants a good explanation of what kind of weird application wants to write to all over memory when it is loaded.

Eric

#4 lore raw
Quoted 25 lines · Eric W. Biederman
Quoted 23 lines · Cong Wang
Quoted 6 lines · Eric W. Biederman
Quoted 3 lines · Amerigo Wang

Currently KEXEC_SEGMENT_MAX is only 16 which is too small for machine with many memory ranges. Increase this hard limit to 1024 which is reasonably large, and change ->segment from a static array to a dynamically allocated memory.

Quoted 8 lines

???

This should be about segments in the executable being loaded.  What executable has one segment for each range of physical memory?

Not that generalizing this is a bad idea but with a comment that seems entirely wrong I am wondering what the problem really is.

Ah, I think Neil should explain this.

He made a patch which includes many memory ranges, caused kexec fails to load the kernel. Increasing this limit and the corresponding one in kexec-tools fixes the problem. His patch is not in upstream kexec-tools, AFAIK.

Quoted 8 lines
Quoted 1 line

However, even if we don't consider that patch, isn't 16 too small too?

Generally you just need one physical hunk for the code, maybe a second for the initrd.

It is perfectly fine to raise the number of segments as it doesn't affect the ABI, but it wants a good explanation of what kind of weird application wants to write to all over memory when it is loaded.

kexec can be used to load not only the kernel images, but also more complex images such as hibernation image. So I think it is good to raise the number of segments.

Best Regards,
Huang Ying

#5 lore raw
Quoted 32 lines · huang ying
Quoted 30 lines · Eric W. Biederman
Quoted 16 lines · Cong Wang
Quoted 6 lines · Eric W. Biederman
Quoted 3 lines · Amerigo Wang

Currently KEXEC_SEGMENT_MAX is only 16 which is too small for machine with many memory ranges. Increase this hard limit to 1024 which is reasonably large, and change ->segment from a static array to a dynamically allocated memory.

Quoted 8 lines

???

This should be about segments in the executable being loaded.  What executable has one segment for each range of physical memory?

Not that generalizing this is a bad idea but with a comment that seems entirely wrong I am wondering what the problem really is.

Quoted 8 lines

Ah, I think Neil should explain this.

He made a patch which includes many memory ranges, caused kexec fails to load the kernel. Increasing this limit and the corresponding one in kexec-tools fixes the problem. His patch is not in upstream kexec-tools, AFAIK.

However, even if we don't consider that patch, isn't 16 too small too?

Generally you just need one physical hunk for the code, maybe a second for the initrd.

Quoted 7 lines
Quoted 3 lines

It is perfectly fine to raise the number of segments as it doesn't affect the ABI, but it wants a good explanation of what kind of weird application wants to write to all over memory when it is loaded.

kexec can be used to load not only the kernel images, but also more complex images such as hibernation image. So I think it is good to raise the number of segments.

Totally reasonable.

And in all fairness the patch does a good job of raising the limit.

However if that is the goal 1024 is probably a bit low as I believe SGI has built machines with that many nodes. Still after the patch under discussion 1024 was only a limit in a header file so it can be trivially changed.

Eric

author
#6 lore raw
Quoted 42 lines · Eric W. Biederman
Quoted 32 lines · huang ying
Quoted 30 lines · Eric W. Biederman
Quoted 16 lines · Cong Wang
Quoted 6 lines · Eric W. Biederman
Quoted 3 lines · Amerigo Wang

Currently KEXEC_SEGMENT_MAX is only 16 which is too small for machine with many memory ranges. Increase this hard limit to 1024 which is reasonably large, and change ->segment from a static array to a dynamically allocated memory.

Quoted 8 lines

???

This should be about segments in the executable being loaded. What executable has one segment for each range of physical memory?

Not that generalizing this is a bad idea but with a comment that seems entirely wrong I am wondering what the problem really is.

Quoted 8 lines

Ah, I think Neil should explain this.

He made a patch which includes many memory ranges, caused kexec fails to load the kernel. Increasing this limit and the corresponding one in kexec-tools fixes the problem. His patch is not in upstream kexec-tools, AFAIK.

However, even if we don't consider that patch, isn't 16 too small too?

Generally you just need one physical hunk for the code, maybe a second for the initrd.

Quoted 7 lines
Quoted 3 lines

It is perfectly fine to raise the number of segments as it doesn't affect the ABI, but it wants a good explanation of what kind of weird application wants to write to all over memory when it is loaded.

kexec can be used to load not only the kernel images, but also more complex images such as hibernation image. So I think it is good to raise the number of segments.

Quoted 8 lines

Totally reasonable.

And in all fairness the patch does a good job of raising the limit.

However if that is the goal 1024 is probably a bit low as I believe SGI has built machines with that many nodes. Still after the patch under discussion 1024 was only a limit in a header file so it can be trivially changed.

So, what is a better number? 2048? :)

Thanks.

Signature · 2 lines
The opposite of love is not hate, it's indifference.
 - Elie Wiesel
#7 lore raw
Quoted 1 line · Cong Wang

So, what is a better number? 2048? :)

I was thinking something a little ridiculous like 10K or 64K.

Assuming the usage you care about is something like hibernate on a machine with disjoint memory where you truly need one segment for each memory region.

The only point of a limit at all once we introduce dynamic allocation is to catch buggy apps.

Eric

author
#8 lore raw
Quoted 4 lines · Eric W. Biederman
Quoted 1 line · Cong Wang

So, what is a better number? 2048? :)

Quoted 9 lines

I was thinking something a little ridiculous like 10K or 64K.

Assuming the usage you care about is something like hibernate on a machine with disjoint memory where you truly need one segment for each memory region.

The only point of a limit at all once we introduce dynamic allocation is to catch buggy apps.

Ok, I will change that number and improve the changelog.

Thanks.

Signature · 2 lines
The opposite of love is not hate, it's indifference.
 - Elie Wiesel