All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
@ 2011-03-28 19:40 Chris Leech
  2011-03-28 21:40 ` Simon Horman
  2011-03-28 21:50 ` [PATCH V2] " Chris Leech
  0 siblings, 2 replies; 10+ messages in thread
From: Chris Leech @ 2011-03-28 19:40 UTC (permalink / raw)
  To: kexec

kexec needs to keep the subarch setting the same as the running kernel
in the boot parameters, or the kernel will die in early setup.  I ran
into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
future subarch that uses non-default early setup code.

This patch requires debugfs mounted at /sys/kernel/debug, as that's
the only way I know of to get at the running kernels boot_params.
Without debugfs mounted it falls back to the current behavior of
assuming subarch 0.

Signed-off-by: Chris Leech <christopher.leech@linux.intel.com>
---
 kexec/arch/i386/x86-linux-setup.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index f843ca4..b7f8bd8 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <errno.h>
 #include <limits.h>
 #include <sys/types.h>
@@ -396,12 +397,32 @@ out:
 		real_mode->eddbuf_entries);
 }
 
+#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
+
+void setup_subarch(struct x86_linux_param_header *real_mode)
+{
+	int data_file;
+	const off_t offset = offsetof(typeof(*real_mode), hardware_subarch);
+
+	data_file = open(BOOT_PARAMS_DBGFS, O_RDONLY);
+	if (data_file < 0)
+		return;
+	if (lseek(data_file, offset, SEEK_SET) < 0)
+		goto close;
+	read(data, &real_mode->hardware_subarch, sizeof(uint32_t));
+close:
+	close(data_file);
+}
+
 void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
 					unsigned long kexec_flags)
 {
 	/* Fill in information the BIOS would usually provide */
 	struct memory_range *range;
 	int i, ranges;
+
+	/* get subarch from running kernel */
+	setup_subarch(real_mode);
 	
 	/* Default screen size */
 	real_mode->orig_x = 0;


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
  2011-03-28 19:40 [PATCH] kexec, x86: fix kexec when boot_params.hardware_subarch != 0 Chris Leech
@ 2011-03-28 21:40 ` Simon Horman
  2011-03-28 21:45   ` Chris Leech
  2011-03-28 21:50 ` [PATCH V2] " Chris Leech
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Horman @ 2011-03-28 21:40 UTC (permalink / raw)
  To: Chris Leech; +Cc: kexec

On Mon, Mar 28, 2011 at 12:40:49PM -0700, Chris Leech wrote:
> kexec needs to keep the subarch setting the same as the running kernel
> in the boot parameters, or the kernel will die in early setup.  I ran
> into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
> future subarch that uses non-default early setup code.
> 
> This patch requires debugfs mounted at /sys/kernel/debug, as that's
> the only way I know of to get at the running kernels boot_params.
> Without debugfs mounted it falls back to the current behavior of
> assuming subarch 0.
> 
> Signed-off-by: Chris Leech <christopher.leech@linux.intel.com>
> ---
>  kexec/arch/i386/x86-linux-setup.c |   21 +++++++++++++++++++++
>  1 files changed, 21 insertions(+), 0 deletions(-)
> 
> diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
> index f843ca4..b7f8bd8 100644
> --- a/kexec/arch/i386/x86-linux-setup.c
> +++ b/kexec/arch/i386/x86-linux-setup.c
> @@ -20,6 +20,7 @@
>  #include <string.h>
>  #include <stdarg.h>
>  #include <stdlib.h>
> +#include <stddef.h>
>  #include <errno.h>
>  #include <limits.h>
>  #include <sys/types.h>
> @@ -396,12 +397,32 @@ out:
>  		real_mode->eddbuf_entries);
>  }
>  
> +#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
> +
> +void setup_subarch(struct x86_linux_param_header *real_mode)
> +{
> +	int data_file;
> +	const off_t offset = offsetof(typeof(*real_mode), hardware_subarch);
> +
> +	data_file = open(BOOT_PARAMS_DBGFS, O_RDONLY);
> +	if (data_file < 0)
> +		return;
> +	if (lseek(data_file, offset, SEEK_SET) < 0)
> +		goto close;
> +	read(data, &real_mode->hardware_subarch, sizeof(uint32_t));

Should data be data_file?

> +close:
> +	close(data_file);
> +}
> +
>  void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
>  					unsigned long kexec_flags)
>  {
>  	/* Fill in information the BIOS would usually provide */
>  	struct memory_range *range;
>  	int i, ranges;
> +
> +	/* get subarch from running kernel */
> +	setup_subarch(real_mode);
>  	
>  	/* Default screen size */
>  	real_mode->orig_x = 0;
> 
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
  2011-03-28 21:40 ` Simon Horman
@ 2011-03-28 21:45   ` Chris Leech
  0 siblings, 0 replies; 10+ messages in thread
From: Chris Leech @ 2011-03-28 21:45 UTC (permalink / raw)
  To: Simon Horman; +Cc: kexec

On Tue, Mar 29, 2011 at 06:40:12AM +0900, Simon Horman wrote:
> > +void setup_subarch(struct x86_linux_param_header *real_mode)
> > +{
> > +	int data_file;
> > +	const off_t offset = offsetof(typeof(*real_mode), hardware_subarch);
> > +
> > +	data_file = open(BOOT_PARAMS_DBGFS, O_RDONLY);
> > +	if (data_file < 0)
> > +		return;
> > +	if (lseek(data_file, offset, SEEK_SET) < 0)
> > +		goto close;
> > +	read(data, &real_mode->hardware_subarch, sizeof(uint32_t));
> 
> Should data be data_file?

Yes.  Sorry, looks like I sent an unrefreshed patch.

- Chris

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* [PATCH V2] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
  2011-03-28 19:40 [PATCH] kexec, x86: fix kexec when boot_params.hardware_subarch != 0 Chris Leech
  2011-03-28 21:40 ` Simon Horman
@ 2011-03-28 21:50 ` Chris Leech
  2011-03-28 22:19   ` Simon Horman
  2011-03-29  9:04   ` WANG Cong
  1 sibling, 2 replies; 10+ messages in thread
From: Chris Leech @ 2011-03-28 21:50 UTC (permalink / raw)
  To: kexec

kexec needs to keep the subarch setting the same as the running kernel
in the boot parameters, or the kernel will die in early setup.  I ran
into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
future subarch that uses non-default early setup code.

This patch requires debugfs mounted at /sys/kernel/debug, as that's
the only way I know of to get at the running kernels boot_params.
Without debugfs mounted it falls back to the current behavior of
assuming subarch 0.

Signed-off-by: Chris Leech <christopher.leech@linux.intel.com>
---
 kexec/arch/i386/x86-linux-setup.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index f843ca4..50b32be 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <stddef.h>
 #include <errno.h>
 #include <limits.h>
 #include <sys/types.h>
@@ -396,12 +397,32 @@ out:
 		real_mode->eddbuf_entries);
 }
 
+#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
+
+void setup_subarch(struct x86_linux_param_header *real_mode)
+{
+	int data_file;
+	const off_t offset = offsetof(typeof(*real_mode), hardware_subarch);
+
+	data_file = open(BOOT_PARAMS_DBGFS, O_RDONLY);
+	if (data_file < 0)
+		return;
+	if (lseek(data_file, offset, SEEK_SET) < 0)
+		goto close;
+	read(data_file, &real_mode->hardware_subarch, sizeof(uint32_t));
+close:
+	close(data_file);
+}
+
 void setup_linux_system_parameters(struct x86_linux_param_header *real_mode,
 					unsigned long kexec_flags)
 {
 	/* Fill in information the BIOS would usually provide */
 	struct memory_range *range;
 	int i, ranges;
+
+	/* get subarch from running kernel */
+	setup_subarch(real_mode);
 	
 	/* Default screen size */
 	real_mode->orig_x = 0;


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH V2] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
  2011-03-28 21:50 ` [PATCH V2] " Chris Leech
@ 2011-03-28 22:19   ` Simon Horman
  2011-03-29  9:04   ` WANG Cong
  1 sibling, 0 replies; 10+ messages in thread
From: Simon Horman @ 2011-03-28 22:19 UTC (permalink / raw)
  To: Chris Leech; +Cc: kexec

On Mon, Mar 28, 2011 at 02:50:11PM -0700, Chris Leech wrote:
> kexec needs to keep the subarch setting the same as the running kernel
> in the boot parameters, or the kernel will die in early setup.  I ran
> into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
> future subarch that uses non-default early setup code.
> 
> This patch requires debugfs mounted at /sys/kernel/debug, as that's
> the only way I know of to get at the running kernels boot_params.
> Without debugfs mounted it falls back to the current behavior of
> assuming subarch 0.

Thanks, applied.

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH V2] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
  2011-03-28 21:50 ` [PATCH V2] " Chris Leech
  2011-03-28 22:19   ` Simon Horman
@ 2011-03-29  9:04   ` WANG Cong
  2011-03-29 23:22     ` Simon Horman
  1 sibling, 1 reply; 10+ messages in thread
From: WANG Cong @ 2011-03-29  9:04 UTC (permalink / raw)
  To: kexec

On Mon, 28 Mar 2011 14:50:11 -0700, Chris Leech wrote:

> kexec needs to keep the subarch setting the same as the running kernel
> in the boot parameters, or the kernel will die in early setup.  I ran
> into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
> future subarch that uses non-default early setup code.
> 
> This patch requires debugfs mounted at /sys/kernel/debug, as that's the
> only way I know of to get at the running kernels boot_params. Without
> debugfs mounted it falls back to the current behavior of assuming
> subarch 0.
> 
...
>  
> +#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"

A minor issue here is that you are using a hard-coded debugfs path,
debugfs can be also mounted to /debug too, so it is better that if we can 
search the path dynamically here.

Thanks.


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH V2] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
  2011-03-29  9:04   ` WANG Cong
@ 2011-03-29 23:22     ` Simon Horman
  2011-03-31 17:21       ` Chris Leech
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Horman @ 2011-03-29 23:22 UTC (permalink / raw)
  To: WANG Cong; +Cc: kexec

On Tue, Mar 29, 2011 at 09:04:53AM +0000, WANG Cong wrote:
> On Mon, 28 Mar 2011 14:50:11 -0700, Chris Leech wrote:
> 
> > kexec needs to keep the subarch setting the same as the running kernel
> > in the boot parameters, or the kernel will die in early setup.  I ran
> > into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
> > future subarch that uses non-default early setup code.
> > 
> > This patch requires debugfs mounted at /sys/kernel/debug, as that's the
> > only way I know of to get at the running kernels boot_params. Without
> > debugfs mounted it falls back to the current behavior of assuming
> > subarch 0.
> > 
> ...
> >  
> > +#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
> 
> A minor issue here is that you are using a hard-coded debugfs path,
> debugfs can be also mounted to /debug too, so it is better that if we can 
> search the path dynamically here.

Do you think it would be better for the code to loop through
a few common alternatives for the path?


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH V2] kexec, x86: fix kexec when boot_params.hardware_subarch != 0
  2011-03-29 23:22     ` Simon Horman
@ 2011-03-31 17:21       ` Chris Leech
  2011-04-01  2:00         ` [PATCH V2] kexec, x86: fix kexec when?boot_params.hardware_subarch " Simon Horman
  0 siblings, 1 reply; 10+ messages in thread
From: Chris Leech @ 2011-03-31 17:21 UTC (permalink / raw)
  To: kexec

Simon Horman <horms@...> writes:

> 
> On Tue, Mar 29, 2011 at 09:04:53AM +0000, WANG Cong wrote:
> > On Mon, 28 Mar 2011 14:50:11 -0700, Chris Leech wrote:
> > 
> > > kexec needs to keep the subarch setting the same as the running kernel
> > > in the boot parameters, or the kernel will die in early setup.  I ran
> > > into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
> > > future subarch that uses non-default early setup code.
> > > 
> > > This patch requires debugfs mounted at /sys/kernel/debug, as that's the
> > > only way I know of to get at the running kernels boot_params. Without
> > > debugfs mounted it falls back to the current behavior of assuming
> > > subarch 0.
> > > 
> > ...
> > >  
> > > +#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
> > 
> > A minor issue here is that you are using a hard-coded debugfs path,
> > debugfs can be also mounted to /debug too, so it is better that if we can 
> > search the path dynamically here.
> 
> Do you think it would be better for the code to loop through
> a few common alternatives for the path?
> 

Not fully tested, but instead of looping through possible mount points maybe 
look through mtab in search of debugfs by fs type.

Something like this?

kexec, x86: search for debugfs mountpoint in /etc/mtab

From: Chris Leech <christopher.leech@linux.intel.com>

Signed-off-by: Chris Leech <christopher.leech@linux.intel.com>
---
 kexec/arch/i386/x86-linux-setup.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-
setup.c
index 50b32be..0528cea 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -30,6 +30,7 @@
 #include <linux/fb.h>
 #include <unistd.h>
 #include <dirent.h>
+#include <mntent.h>
 #include <x86/x86-linux.h>
 #include "../../kexec.h"
 #include "kexec-x86.h"
@@ -397,14 +398,44 @@ out:
 		real_mode->eddbuf_entries);
 }
 
-#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
+/*
+ * This really only makes sense for virtual filesystems that are only expected
+ * to be mounted once (sysfs, debugsfs, proc), as it will return the first
+ * instance listed in mtab.
+ */
+char *find_mnt_by_fsname(char *fsname)
+{
+	FILE *mtab;
+	struct mntent *mnt;
+	char *mntdir;
+
+	mtab = setmntent("/etc/mtab", "r");
+	if (!mtab)
+		return NULL;
+	for(mnt = getmntent(mtab); mnt; mnt = getmntent(mtab)) {
+		if (strcmp(mnt->mnt_fsname, fsname) == 0)
+			break;
+	}
+	mntdir = mnt ? strdup(mnt->mnt_dir) : NULL;
+	endmntent(mtab);
+	return mntdir;
+}
 
 void setup_subarch(struct x86_linux_param_header *real_mode)
 {
 	int data_file;
 	const off_t offset = offsetof(typeof(*real_mode), hardware_subarch);
+	char *debugfs_mnt;
+	char filename[PATH_MAX];
+
+	debugfs_mnt = find_mnt_by_fsname("debugfs");
+	if (!debugfs_mnt)
+		return;
+	snprintf(filename, PATH_MAX, "%s/%s", debugfs_mnt, "boot_params/data");
+	filename[PATH_MAX-1] = 0;
+	free(debugfs_mnt);
 
-	data_file = open(BOOT_PARAMS_DBGFS, O_RDONLY);
+	data_file = open(filename, O_RDONLY);
 	if (data_file < 0)
 		return;
 	if (lseek(data_file, offset, SEEK_SET) < 0)





_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH V2] kexec, x86: fix kexec when?boot_params.hardware_subarch != 0
  2011-03-31 17:21       ` Chris Leech
@ 2011-04-01  2:00         ` Simon Horman
  2011-04-27  6:18           ` Simon Horman
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Horman @ 2011-04-01  2:00 UTC (permalink / raw)
  To: Chris Leech; +Cc: kexec

On Thu, Mar 31, 2011 at 05:21:15PM +0000, Chris Leech wrote:
> Simon Horman <horms@...> writes:
> 
> > 
> > On Tue, Mar 29, 2011 at 09:04:53AM +0000, WANG Cong wrote:
> > > On Mon, 28 Mar 2011 14:50:11 -0700, Chris Leech wrote:
> > > 
> > > > kexec needs to keep the subarch setting the same as the running kernel
> > > > in the boot parameters, or the kernel will die in early setup.  I ran
> > > > into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
> > > > future subarch that uses non-default early setup code.
> > > > 
> > > > This patch requires debugfs mounted at /sys/kernel/debug, as that's the
> > > > only way I know of to get at the running kernels boot_params. Without
> > > > debugfs mounted it falls back to the current behavior of assuming
> > > > subarch 0.
> > > > 
> > > ...
> > > >  
> > > > +#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
> > > 
> > > A minor issue here is that you are using a hard-coded debugfs path,
> > > debugfs can be also mounted to /debug too, so it is better that if we can 
> > > search the path dynamically here.
> > 
> > Do you think it would be better for the code to loop through
> > a few common alternatives for the path?
> > 
> 
> Not fully tested, but instead of looping through possible mount points maybe 
> look through mtab in search of debugfs by fs type.
> 
> Something like this?

This approach looks good to me.
Could you do some more testing?

> kexec, x86: search for debugfs mountpoint in /etc/mtab
> 
> From: Chris Leech <christopher.leech@linux.intel.com>
> 
> Signed-off-by: Chris Leech <christopher.leech@linux.intel.com>
> ---
>  kexec/arch/i386/x86-linux-setup.c |   35 +++++++++++++++++++++++++++++++++--
>  1 files changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-
> setup.c
> index 50b32be..0528cea 100644
> --- a/kexec/arch/i386/x86-linux-setup.c
> +++ b/kexec/arch/i386/x86-linux-setup.c
> @@ -30,6 +30,7 @@
>  #include <linux/fb.h>
>  #include <unistd.h>
>  #include <dirent.h>
> +#include <mntent.h>
>  #include <x86/x86-linux.h>
>  #include "../../kexec.h"
>  #include "kexec-x86.h"
> @@ -397,14 +398,44 @@ out:
>  		real_mode->eddbuf_entries);
>  }
>  
> -#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
> +/*
> + * This really only makes sense for virtual filesystems that are only expected
> + * to be mounted once (sysfs, debugsfs, proc), as it will return the first
> + * instance listed in mtab.
> + */
> +char *find_mnt_by_fsname(char *fsname)
> +{
> +	FILE *mtab;
> +	struct mntent *mnt;
> +	char *mntdir;
> +
> +	mtab = setmntent("/etc/mtab", "r");
> +	if (!mtab)
> +		return NULL;
> +	for(mnt = getmntent(mtab); mnt; mnt = getmntent(mtab)) {
> +		if (strcmp(mnt->mnt_fsname, fsname) == 0)
> +			break;
> +	}
> +	mntdir = mnt ? strdup(mnt->mnt_dir) : NULL;
> +	endmntent(mtab);
> +	return mntdir;
> +}
>  
>  void setup_subarch(struct x86_linux_param_header *real_mode)
>  {
>  	int data_file;
>  	const off_t offset = offsetof(typeof(*real_mode), hardware_subarch);
> +	char *debugfs_mnt;
> +	char filename[PATH_MAX];
> +
> +	debugfs_mnt = find_mnt_by_fsname("debugfs");
> +	if (!debugfs_mnt)
> +		return;
> +	snprintf(filename, PATH_MAX, "%s/%s", debugfs_mnt, "boot_params/data");

It might be worth bailing out on truncation here.
Perhaps with an error message?

> +	filename[PATH_MAX-1] = 0;
> +	free(debugfs_mnt);
>  
> -	data_file = open(BOOT_PARAMS_DBGFS, O_RDONLY);
> +	data_file = open(filename, O_RDONLY);
>  	if (data_file < 0)
>  		return;
>  	if (lseek(data_file, offset, SEEK_SET) < 0)

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH V2] kexec, x86: fix kexec when?boot_params.hardware_subarch != 0
  2011-04-01  2:00         ` [PATCH V2] kexec, x86: fix kexec when?boot_params.hardware_subarch " Simon Horman
@ 2011-04-27  6:18           ` Simon Horman
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Horman @ 2011-04-27  6:18 UTC (permalink / raw)
  To: Chris Leech; +Cc: kexec

On Fri, Apr 01, 2011 at 11:00:51AM +0900, Simon Horman wrote:
> On Thu, Mar 31, 2011 at 05:21:15PM +0000, Chris Leech wrote:
> > Simon Horman <horms@...> writes:
> > 
> > > 
> > > On Tue, Mar 29, 2011 at 09:04:53AM +0000, WANG Cong wrote:
> > > > On Mon, 28 Mar 2011 14:50:11 -0700, Chris Leech wrote:
> > > > 
> > > > > kexec needs to keep the subarch setting the same as the running kernel
> > > > > in the boot parameters, or the kernel will die in early setup.  I ran
> > > > > into this with X86_SUBARCH_MRST, but it should apply to CE4100 and any
> > > > > future subarch that uses non-default early setup code.
> > > > > 
> > > > > This patch requires debugfs mounted at /sys/kernel/debug, as that's the
> > > > > only way I know of to get at the running kernels boot_params. Without
> > > > > debugfs mounted it falls back to the current behavior of assuming
> > > > > subarch 0.
> > > > > 
> > > > ...
> > > > >  
> > > > > +#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
> > > > 
> > > > A minor issue here is that you are using a hard-coded debugfs path,
> > > > debugfs can be also mounted to /debug too, so it is better that if we can 
> > > > search the path dynamically here.
> > > 
> > > Do you think it would be better for the code to loop through
> > > a few common alternatives for the path?
> > > 
> > 
> > Not fully tested, but instead of looping through possible mount points maybe 
> > look through mtab in search of debugfs by fs type.
> > 
> > Something like this?
> 
> This approach looks good to me.
> Could you do some more testing?

Ping.

> > kexec, x86: search for debugfs mountpoint in /etc/mtab
> > 
> > From: Chris Leech <christopher.leech@linux.intel.com>
> > 
> > Signed-off-by: Chris Leech <christopher.leech@linux.intel.com>
> > ---
> >  kexec/arch/i386/x86-linux-setup.c |   35 +++++++++++++++++++++++++++++++++--
> >  1 files changed, 33 insertions(+), 2 deletions(-)
> > 
> > diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-
> > setup.c
> > index 50b32be..0528cea 100644
> > --- a/kexec/arch/i386/x86-linux-setup.c
> > +++ b/kexec/arch/i386/x86-linux-setup.c
> > @@ -30,6 +30,7 @@
> >  #include <linux/fb.h>
> >  #include <unistd.h>
> >  #include <dirent.h>
> > +#include <mntent.h>
> >  #include <x86/x86-linux.h>
> >  #include "../../kexec.h"
> >  #include "kexec-x86.h"
> > @@ -397,14 +398,44 @@ out:
> >  		real_mode->eddbuf_entries);
> >  }
> >  
> > -#define BOOT_PARAMS_DBGFS	"/sys/kernel/debug/boot_params/data"
> > +/*
> > + * This really only makes sense for virtual filesystems that are only expected
> > + * to be mounted once (sysfs, debugsfs, proc), as it will return the first
> > + * instance listed in mtab.
> > + */
> > +char *find_mnt_by_fsname(char *fsname)
> > +{
> > +	FILE *mtab;
> > +	struct mntent *mnt;
> > +	char *mntdir;
> > +
> > +	mtab = setmntent("/etc/mtab", "r");
> > +	if (!mtab)
> > +		return NULL;
> > +	for(mnt = getmntent(mtab); mnt; mnt = getmntent(mtab)) {
> > +		if (strcmp(mnt->mnt_fsname, fsname) == 0)
> > +			break;
> > +	}
> > +	mntdir = mnt ? strdup(mnt->mnt_dir) : NULL;
> > +	endmntent(mtab);
> > +	return mntdir;
> > +}
> >  
> >  void setup_subarch(struct x86_linux_param_header *real_mode)
> >  {
> >  	int data_file;
> >  	const off_t offset = offsetof(typeof(*real_mode), hardware_subarch);
> > +	char *debugfs_mnt;
> > +	char filename[PATH_MAX];
> > +
> > +	debugfs_mnt = find_mnt_by_fsname("debugfs");
> > +	if (!debugfs_mnt)
> > +		return;
> > +	snprintf(filename, PATH_MAX, "%s/%s", debugfs_mnt, "boot_params/data");
> 
> It might be worth bailing out on truncation here.
> Perhaps with an error message?
> 
> > +	filename[PATH_MAX-1] = 0;
> > +	free(debugfs_mnt);
> >  
> > -	data_file = open(BOOT_PARAMS_DBGFS, O_RDONLY);
> > +	data_file = open(filename, O_RDONLY);
> >  	if (data_file < 0)
> >  		return;
> >  	if (lseek(data_file, offset, SEEK_SET) < 0)
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
> 

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

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

end of thread, other threads:[~2011-04-27  6:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-28 19:40 [PATCH] kexec, x86: fix kexec when boot_params.hardware_subarch != 0 Chris Leech
2011-03-28 21:40 ` Simon Horman
2011-03-28 21:45   ` Chris Leech
2011-03-28 21:50 ` [PATCH V2] " Chris Leech
2011-03-28 22:19   ` Simon Horman
2011-03-29  9:04   ` WANG Cong
2011-03-29 23:22     ` Simon Horman
2011-03-31 17:21       ` Chris Leech
2011-04-01  2:00         ` [PATCH V2] kexec, x86: fix kexec when?boot_params.hardware_subarch " Simon Horman
2011-04-27  6:18           ` Simon Horman

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.