Skip to contentSkip to conversation

Minor fixes and improvements for kexec

PATCH In review Geoff Levand 6 participants 14 messages Dec 12, 2013 – Dec 17, 2013

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Minor fixes and improvements for kexec

Hi Eric,

Here are a few minor fixes and improvements for kexec. Please consider.

-Geoff

The following changes since commit 374b105797c3d4f29c685f3be535c35f5689b30e:

Linux 3.13-rc3 (2013-12-06 09:34:04 -0800)

are available in the git repository at:

git://git.linaro.org/people/geoff.levand/linux-kexec.git for-kexec

for you to fetch changes up to 594a3d26aac66e9668edc81d7bfb4e801575514f:

sh/kexec: Fix kexec build warning (2013-12-11 16:03:27 -0800)

----------------------------------------------------------------
Geoff Levand (4):
kexec: Simplify conditional
kexec: Add IND_FLAGS macro
powerpc/kexec: Use global IND_FLAGS macro
sh/kexec: Fix kexec build warning

 arch/powerpc/kernel/machine_kexec_64.c |  2 --
 arch/sh/kernel/machine_kexec.c         |  2 +-
 include/linux/kexec.h                  |  1 +
 kernel/kexec.c                         | 17 ++++++++++-------
 4 files changed, 12 insertions(+), 10 deletions(-)
Signature · 7 lines
1.8.1.2


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

PATCH 1/4 kexec: Simplify conditional

Simplify the code around one of the conditionals in the kexec_load syscall routine.

The original code was confusing with a redundant check on KEXEC_ON_CRASH and comments outside of the conditional block. This change switches the order of the conditional check, and cleans up the comments for the conditional. There is no functional change to the code.

---
 kernel/kexec.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
kernel/kexec.c +10 -7
index 490afc0..89a6fa3 100644
@@ -980,19 +980,22 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 	if (nr_segments > 0) {
 		unsigned long i;
 
-		/* Loading another kernel to reboot into */
-		if ((flags & KEXEC_ON_CRASH) == 0)
-			result = kimage_normal_alloc(&image, entry,
-							nr_segments, segments);
-		/* Loading another kernel to switch to if this one crashes */
-		else if (flags & KEXEC_ON_CRASH) {
-			/* Free any current crash dump kernel before
+		if (flags & KEXEC_ON_CRASH) {
+			/*
+			 * Loading another kernel to switch to if this one
+			 * crashes.  Free any current crash dump kernel before
 			 * we corrupt it.
 			 */
+
 			kimage_free(xchg(&kexec_crash_image, NULL));
 			result = kimage_crash_alloc(&image, entry,
 						     nr_segments, segments);
 			crash_map_reserved_pages();
+		} else {
+			/* Loading another kernel to reboot into. */
+
+			result = kimage_normal_alloc(&image, entry,
+							nr_segments, segments);
 		}
 		if (result)
 			goto out;
Signature · 8 lines
1.8.1.2



_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] kexec: Simplify conditional

Add CCing Andrew Morton

Quoted 7 lines · Geoff Levand

Simplify the code around one of the conditionals in the kexec_load syscall routine.

The original code was confusing with a redundant check on KEXEC_ON_CRASH and comments outside of the conditional block. This change switches the order of the conditional check, and cleans up the comments for the conditional. There is no functional change to the code.

This looks good.

minor comments below.

Quoted 18 lines
---
 kernel/kexec.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
kernel/kexec.c +0 -4
index 490afc0..89a6fa3 100644
@@ -980,19 +980,22 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 	if (nr_segments > 0) {
 		unsigned long i;
 
-		/* Loading another kernel to reboot into */
-		if ((flags & KEXEC_ON_CRASH) == 0)
-			result = kimage_normal_alloc(&image, entry,
-							nr_segments, segments);

kernel/kexec.c SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, · line 989

Quoted 10 lines
kernel/kexec.c +5 -3
-		/* Loading another kernel to switch to if this one crashes */
-		else if (flags & KEXEC_ON_CRASH) {
-			/* Free any current crash dump kernel before
+		if (flags & KEXEC_ON_CRASH) {
+			/*
+			 * Loading another kernel to switch to if this one
+			 * crashes.  Free any current crash dump kernel before
 			 * we corrupt it.
 			 */
+

This empty line is not necessary, I think. But no big deal.

kernel/kexec.c SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments, · line 996

Quoted 7 lines
kernel/kexec.c +3 -0
 			kimage_free(xchg(&kexec_crash_image, NULL));
 			result = kimage_crash_alloc(&image, entry,
 						     nr_segments, segments);
 			crash_map_reserved_pages();
+		} else {
+			/* Loading another kernel to reboot into. */
+

ditto.

Quoted 6 lines
kernel/kexec.c +2 -0
+			result = kimage_normal_alloc(&image, entry,
+							nr_segments, segments);
 		}
 		if (result)
 			goto out;
Signature · 7 lines
Thanks.
Zhang Yanfei

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

Re: [PATCH 1/4] kexec: Simplify conditional

Quoted 1 line · On Thu, 12 Dec 2013 09:32:02 +0800 Zhang Yanfei <[email protected]>…

Add CCing Andrew Morton

I'm not on [email protected]. (Well, I am now!).

Quoted 9 lines · Geoff Levand
Quoted 7 lines

Simplify the code around one of the conditionals in the kexec_load syscall routine.

The original code was confusing with a redundant check on KEXEC_ON_CRASH and comments outside of the conditional block. This change switches the order of the conditional check, and cleans up the comments for the conditional. There is no functional change to the code.

Quoted 5 lines

This looks good.

minor comments below.

Please cc me on the resend?

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

#4 lore raw

PATCH 2/4 kexec: Add IND_FLAGS macro

In reply to Geoff Levand

Add a new kexec preprocessor macro IND_FLAGS, which is the bitwise OR of all the possible kexec IND_ kimage_entry indirection flags.

Having this macro allows for simplified code in the prosessing of the kexec kimage_entry items.

---
 include/linux/kexec.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/kexec.h +1 -0
index d78d28a..f755ec3 100644
@@ -67,6 +67,7 @@ typedef unsigned long kimage_entry_t;
 #define IND_INDIRECTION  0x2
 #define IND_DONE         0x4
 #define IND_SOURCE       0x8
+#define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
 
 struct kexec_segment {
 	void __user *buf;
Signature · 8 lines
1.8.1.2



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

Re: [PATCH 2/4] kexec: Add IND_FLAGS macro

Hello

Quoted 5 lines · Geoff Levand

Add a new kexec preprocessor macro IND_FLAGS, which is the bitwise OR of all the possible kexec IND_ kimage_entry indirection flags.

Having this macro allows for simplified code in the prosessing of the kexec kimage_entry items.

Where? I didn't see any place you use this macro to help simplification.

Thanks
Zhang

Quoted 19 lines
---
 include/linux/kexec.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/kexec.h +1 -0
index d78d28a..f755ec3 100644
@@ -67,6 +67,7 @@ typedef unsigned long kimage_entry_t;
 #define IND_INDIRECTION  0x2
 #define IND_DONE         0x4
 #define IND_SOURCE       0x8
+#define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
 
 struct kexec_segment {
 	void __user *buf;
Signature · 7 lines
Thanks.
Zhang Yanfei

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

Re: [PATCH 2/4] kexec: Add IND_FLAGS macro

Hi Zhang,

Quoted 8 lines · Zhang Yanfei
Quoted 5 lines · Geoff Levand

Add a new kexec preprocessor macro IND_FLAGS, which is the bitwise OR of all the possible kexec IND_ kimage_entry indirection flags.

Having this macro allows for simplified code in the prosessing of the kexec kimage_entry items.

Where? I didn't see any place you use this macro to help simplification.

As in powerpc, it allows constructions like this:

  switch (entry & IND_FLAGS) {
  case IND_DESTINATION:
  ...
  case IND_INDIRECTION:
  ...
  }

-Geoff

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

#7 lore raw

PATCH 3/4 powerpc/kexec: Use global IND_FLAGS macro

In reply to Geoff Levand

linux/kexec.h now defines an IND_FLAGS macro. Remove the local powerpc definition and use the generic one.

---
 arch/powerpc/kernel/machine_kexec_64.c | 2 --
 1 file changed, 2 deletions(-)
arch/powerpc/kernel/machine_kexec_64.c +0 -2
index be4e6d6..1fab1f0 100644
@@ -96,8 +96,6 @@ int default_machine_kexec_prepare(struct kimage *image)
 	return 0;
 }
 
-#define IND_FLAGS (IND_DESTINATION | IND_INDIRECTION | IND_DONE | IND_SOURCE)
-
 static void copy_segments(unsigned long ind)
 {
 	unsigned long entry;
Signature · 8 lines
1.8.1.2



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

PATCH 4/4 sh/kexec: Fix kexec build warning

In reply to Geoff Levand

Add a cast to a printk argument to suppress a type mismatch compiler warning.

---
 arch/sh/kernel/machine_kexec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/kernel/machine_kexec.c +1 -1
index 9fea49f..b7e65a8 100644
@@ -60,7 +60,7 @@ static void kexec_info(struct kimage *image)
 		       i,
 		       (unsigned int)image->segment[i].mem,
 		       (unsigned int)image->segment[i].mem +
-				     image->segment[i].memsz,
+		       (unsigned int)image->segment[i].memsz,
 		       (unsigned int)image->segment[i].memsz);
 	}
 	printk("  start     : 0x%08x\n\n", (unsigned int)image->start);
Signature · 7 lines
1.8.1.2


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

Re: [PATCH 4/4] sh/kexec: Fix kexec build warning

Hi Geoff,

Quoted 12 lines · Geoff Levand

Add a cast to a printk argument to suppress a type mismatch compiler warning.

---
 arch/sh/kernel/machine_kexec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sh/kernel/machine_kexec.c +0 -0
index 9fea49f..b7e65a8 100644

arch/sh/kernel/machine_kexec.c static void kexec_info(struct kimage *image) · line 66

Quoted 8 lines
arch/sh/kernel/machine_kexec.c +1 -1
@@ -60,7 +60,7 @@ static void kexec_info(struct kimage *image)
                       i,
                       (unsigned int)image->segment[i].mem,
                       (unsigned int)image->segment[i].mem +
-                                    image->segment[i].memsz,
+                      (unsigned int)image->segment[i].memsz,
                       (unsigned int)image->segment[i].memsz);
        }
        printk("  start     : 0x%08x\n\n", (unsigned int)image->start);

Wouldn't it be better to remove all casts and correct the printf-style format specifiers instead?

- mem and start are unsigned long, hence use "0x%08lx",
- memsz is size_t, hence use "0x%08zx".

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#10 lore raw

Re: [PATCH 4/4] sh/kexec: Fix kexec build warning

Hi,

Quoted 6 lines · Geert Uytterhoeven

Review

Quoted 2 lines · Geoff Levand
(quoted diff) +1 -1
-                                    image->segment[i].memsz,
+                      (unsigned int)image->segment[i].memsz,e->start);

Wouldn't it be better to remove all casts and correct the printf-style format specifiers instead?

That would be better, I'll make a new patch.

Thanks Geert!

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

Reviewed-by on the v1 series
#11 lore raw
In reply to Geoff Levand
Quoted 3 lines · Geoff Levand

Hi Eric,

Here are a few minor fixes and improvements for kexec. Please consider.

FWIW,

Quoted 37 lines

-Geoff

The following changes since commit 374b105797c3d4f29c685f3be535c35f5689b30e:

Linux 3.13-rc3 (2013-12-06 09:34:04 -0800)

are available in the git repository at:

git://git.linaro.org/people/geoff.levand/linux-kexec.git for-kexec

for you to fetch changes up to 594a3d26aac66e9668edc81d7bfb4e801575514f:

sh/kexec: Fix kexec build warning (2013-12-11 16:03:27 -0800)

----------------------------------------------------------------
Geoff Levand (4):
kexec: Simplify conditional
kexec: Add IND_FLAGS macro
powerpc/kexec: Use global IND_FLAGS macro
sh/kexec: Fix kexec build warning

 arch/powerpc/kernel/machine_kexec_64.c |  2 --
 arch/sh/kernel/machine_kexec.c         |  2 +-
 include/linux/kexec.h                  |  1 +
 kernel/kexec.c                         | 17 ++++++++++-------
 4 files changed, 12 insertions(+), 10 deletions(-)
Signature · 7 lines
1.8.1.2


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

PATCH v2 4/4 sh/kexec: Fix kexec build warning

In reply to Geoff Levand

Change the format specifiers in the kexec_info routine to match the data types. Eliminates the need for type casts and fixes a type mismatch compiler warning. Also replace indenting spaces with a tab character.

---

V2:
Change from type cast fix to format specifier fix.

 arch/sh/kernel/machine_kexec.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
arch/sh/kernel/machine_kexec.c +7 -7
index 9fea49f..8195c35 100644
@@ -53,17 +53,17 @@ void machine_kexec_cleanup(struct kimage *image)
 
 static void kexec_info(struct kimage *image)
 {
-        int i;
+	int i;
 	printk("kexec information\n");
 	for (i = 0; i < image->nr_segments; i++) {
-	        printk("  segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
+	        printk("  segment[%d]: 0x%08lx - 0x%08lx (0x%08zx)\n",
 		       i,
-		       (unsigned int)image->segment[i].mem,
-		       (unsigned int)image->segment[i].mem +
-				     image->segment[i].memsz,
-		       (unsigned int)image->segment[i].memsz);
+		       image->segment[i].mem,
+		       image->segment[i].mem +
+		       image->segment[i].memsz,
+		       image->segment[i].memsz);
 	}
-	printk("  start     : 0x%08x\n\n", (unsigned int)image->start);
+	printk("  start     : 0x%08lx\n\n", image->start);
 }
 
 /*
Signature · 9 lines
1.8.1.2




_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Acked-by on the v1 series
#13 lore raw
In reply to Geoff Levand
Quoted 16 lines · Geoff Levand

Hi Eric,

Here are a few minor fixes and improvements for kexec. Please consider.

-Geoff

The following changes since commit 374b105797c3d4f29c685f3be535c35f5689b30e:

Linux 3.13-rc3 (2013-12-06 09:34:04 -0800)

are available in the git repository at:

git://git.linaro.org/people/geoff.levand/linux-kexec.git for-kexec

for you to fetch changes up to 594a3d26aac66e9668edc81d7bfb4e801575514f:

Quoted 8 lines

sh/kexec: Fix kexec build warning (2013-12-11 16:03:27 -0800)

----------------------------------------------------------------
Geoff Levand (4):
kexec: Simplify conditional
kexec: Add IND_FLAGS macro
powerpc/kexec: Use global IND_FLAGS macro
sh/kexec: Fix kexec build warning

For this series (besides 4/4 v2):

Quoted 15 lines
 arch/powerpc/kernel/machine_kexec_64.c |  2 --
 arch/sh/kernel/machine_kexec.c         |  2 +-
 include/linux/kexec.h                  |  1 +
 kernel/kexec.c                         | 17 ++++++++++-------
 4 files changed, 12 insertions(+), 10 deletions(-)
Signature · 7 lines
1.8.1.2


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