All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios
@ 2019-04-29  8:21 Niklas Hambüchen
  2019-04-29  8:22 ` [PATCH 1/2] x86: Check /proc/mounts before mtab for mounts Niklas Hambüchen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Niklas Hambüchen @ 2019-04-29  8:21 UTC (permalink / raw)
  To: kexec; +Cc: mail, horms

Hi,

please find below two fixes to kexec-tools that improve its operation
on read-only file systems and initial ramdisks without /etc/mtab,
as well as making detection of sysfs and debugfs more robust by relying
on the file system type instead of conventional names that are not guaranteed.

Best greetings,
Niklas

Niklas Hambüchen (2):
  x86: Check /proc/mounts before mtab for mounts
  x86: Find mounts by FS type, not name

 kexec/arch/i386/x86-linux-setup.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)


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

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

* [PATCH 1/2] x86: Check /proc/mounts before mtab for mounts
  2019-04-29  8:21 [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios Niklas Hambüchen
@ 2019-04-29  8:22 ` Niklas Hambüchen
  2019-04-29  8:23 ` [PATCH 2/2] x86: Find mounts by FS type, not name Niklas Hambüchen
  2019-05-15  7:46 ` [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios Simon Horman
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Hambüchen @ 2019-04-29  8:22 UTC (permalink / raw)
  To: kexec; +Cc: horms

In many situations, especially on read-only file systems
and initial ramdisks (intramfs/initrd), /etc/mtab does not exist.

Before this commit, kexec would fail to read mounts on such systems
in `find_mnt_by_fsname()`, such that `get_bootparam()` would not
`boot_params/data`, which would then lead to e.g. `setup_efi_data()`
not being called in `setup_efi_info()`.

As a result, kexec'ed kernels would not obtain EFI data,
subsequentially lack an `ACPI RSDP` entry, emitting:

    ACPI BIOS Error (bug): A valid RSDP was not found (20180810/tbxfroot-210)

and thus fail to turn off the machine on poweroff, instead printing only:

		reboot: System halted

This problem had to be worked around by passing `acpi_rsdp=` manually
before. This commit obviates this workaround.

See also:

* https://github.com/coreos/bugs/issues/167#issuecomment-487320879
* http://lists.infradead.org/pipermail/kexec/2012-October/006924.html

Signed-off-by: Niklas Hambüchen <mail@nh2.me>
---
 kexec/arch/i386/x86-linux-setup.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index 8fad115..74fb0c4 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -432,7 +432,7 @@ out:
 /*
  * 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.
+ * instance listed in /proc/mounts, falling back to mtab if absent.
  */
 char *find_mnt_by_fsname(char *fsname)
 {
@@ -440,7 +440,11 @@ char *find_mnt_by_fsname(char *fsname)
 	struct mntent *mnt;
 	char *mntdir;
 
-	mtab = setmntent("/etc/mtab", "r");
+	mtab = setmntent("/proc/mounts", "r");
+	if (!mtab) {
+		// Fall back to mtab
+		mtab = setmntent("/etc/mtab", "r");
+	}
 	if (!mtab)
 		return NULL;
 	for(mnt = getmntent(mtab); mnt; mnt = getmntent(mtab)) {
-- 
2.19.1


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

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

* [PATCH 2/2] x86: Find mounts by FS type, not name
  2019-04-29  8:21 [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios Niklas Hambüchen
  2019-04-29  8:22 ` [PATCH 1/2] x86: Check /proc/mounts before mtab for mounts Niklas Hambüchen
@ 2019-04-29  8:23 ` Niklas Hambüchen
  2019-05-15  7:46 ` [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios Simon Horman
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Hambüchen @ 2019-04-29  8:23 UTC (permalink / raw)
  To: kexec; +Cc: horms

The name in mount invocations like

		mount -t debugfs debugfs /sys/kernel/debug

is nothing but convention and cannot be relied upon.

For example, https://www.kernel.org/doc/Documentation/filesystems/debugfs.txt
recommends making the name "none" instead:

		mount -t debugfs none /sys/kernel/debug

and many existing systems use mounts named "none" or otherwise.

Using `mnt_type` instead of `mnt_fsname` allows kexec to work
on such systems.

This fixes another instance of `poweroff` not working on kexec'ed
kernels because the lack of correctly matched mount results in EFI
variables not being read and propagated.

Signed-off-by: Niklas Hambüchen <mail@nh2.me>
---
 kexec/arch/i386/x86-linux-setup.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kexec/arch/i386/x86-linux-setup.c b/kexec/arch/i386/x86-linux-setup.c
index 74fb0c4..b643c8b 100644
--- a/kexec/arch/i386/x86-linux-setup.c
+++ b/kexec/arch/i386/x86-linux-setup.c
@@ -433,8 +433,12 @@ out:
  * 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 /proc/mounts, falling back to mtab if absent.
+ * We search by type and not by name because the name can be anything;
+ * while setting the name equal to the mount point is common, it cannot be
+ * relied upon, as even kernel documentation examples recommends using
+ * "none" as the name e.g. for debugfs.
  */
-char *find_mnt_by_fsname(char *fsname)
+char *find_mnt_by_type(char *type)
 {
 	FILE *mtab;
 	struct mntent *mnt;
@@ -448,7 +452,7 @@ char *find_mnt_by_fsname(char *fsname)
 	if (!mtab)
 		return NULL;
 	for(mnt = getmntent(mtab); mnt; mnt = getmntent(mtab)) {
-		if (strcmp(mnt->mnt_fsname, fsname) == 0)
+		if (strcmp(mnt->mnt_type, type) == 0)
 			break;
 	}
 	mntdir = mnt ? strdup(mnt->mnt_dir) : NULL;
@@ -463,7 +467,7 @@ static int get_bootparam(void *buf, off_t offset, size_t size)
 	char filename[PATH_MAX];
 	int err, has_sysfs_params = 0;
 
-	sysfs_mnt = find_mnt_by_fsname("sysfs");
+	sysfs_mnt = find_mnt_by_type("sysfs");
 	if (sysfs_mnt) {
 		snprintf(filename, PATH_MAX, "%s/%s", sysfs_mnt,
 			"kernel/boot_params/data");
@@ -474,7 +478,7 @@ static int get_bootparam(void *buf, off_t offset, size_t size)
 	}
 
 	if (!has_sysfs_params) {
-		debugfs_mnt = find_mnt_by_fsname("debugfs");
+		debugfs_mnt = find_mnt_by_type("debugfs");
 		if (!debugfs_mnt)
 			return 1;
 		snprintf(filename, PATH_MAX, "%s/%s", debugfs_mnt,
-- 
2.19.1


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

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

* Re: [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios
  2019-04-29  8:21 [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios Niklas Hambüchen
  2019-04-29  8:22 ` [PATCH 1/2] x86: Check /proc/mounts before mtab for mounts Niklas Hambüchen
  2019-04-29  8:23 ` [PATCH 2/2] x86: Find mounts by FS type, not name Niklas Hambüchen
@ 2019-05-15  7:46 ` Simon Horman
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2019-05-15  7:46 UTC (permalink / raw)
  To: Niklas Hambüchen; +Cc: kexec

On Mon, Apr 29, 2019 at 10:21:33AM +0200, Niklas Hambüchen wrote:
> Hi,
> 
> please find below two fixes to kexec-tools that improve its operation
> on read-only file systems and initial ramdisks without /etc/mtab,
> as well as making detection of sysfs and debugfs more robust by relying
> on the file system type instead of conventional names that are not guaranteed.
> 
> Best greetings,
> Niklas
> 
> Niklas Hambüchen (2):
>   x86: Check /proc/mounts before mtab for mounts
>   x86: Find mounts by FS type, not name

Thanks Niklas,

applied.

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

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

end of thread, other threads:[~2019-05-15  7:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-29  8:21 [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios Niklas Hambüchen
2019-04-29  8:22 ` [PATCH 1/2] x86: Check /proc/mounts before mtab for mounts Niklas Hambüchen
2019-04-29  8:23 ` [PATCH 2/2] x86: Find mounts by FS type, not name Niklas Hambüchen
2019-05-15  7:46 ` [PATCH 0/2] Improve reading mounts, fixing EFI/ACPI in common scenarios 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.