fix the name_to_dev_t mess v2
Subsystems (15)
Hi all,
this series tries to sort out accumulated mess around the name_to_dev_t function. This function is intended to allow looking up the dev_t of a block device based on a name string before the root file systems is mounted and thus the normal path based lookup is available.
Unfortunately a few years ago it managed to get exported and used in non-init contexts, leading to the something looking like a path name also beeing lookuped up by a different and potential dangerous algorithm.
This series does a fair amount of refactoring and finally ends up with the renamed and improved name_to_dev_t only beeing available for the early init code again.
The series is against Jens' for-6.5/block tree but probably applies against current mainline just fine as well.
A git tree is also available here:
git://git.infradead.org/users/hch/block.git blk-init-cleanup
Gitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/blk-init-cleanup
Changes since v1:
- really propagate the actual error in dm_get_device
- improve the documentation in kernel-parameters.txt
- spelling fixes
Diffstat:
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 1/24 driver core: return bool from driver_probe_done
bool is the most sensible return value for a yes/no return. Also add __init as this funtion is only called from the early boot code.
--- drivers/base/dd.c | 6 ++---- include/linux/device/driver.h | 2 +- init/do_mounts.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-)
drivers/base/dd.c +2 -4
@@ -751,14 +751,12 @@ static int really_probe_debug(struct device *dev, struct device_driver *drv)* * Should somehow figure out how to use a semaphore, not an atomic variable... */ -int driver_probe_done (void ) +bool __init driver_probe_done (void ) {int local_probe_count =atomic_read (&probe_count);pr_debug ("%s: probe_count = %d\n" , __func__, local_probe_count); -if (local_probe_count) -return -EBUSY ; -return 0 ; +return !local_probe_count; }/**
include/linux/device/driver.h +1 -1
@@ -126,7 +126,7 @@ int __must_check driver_register(struct device_driver *drv);void driver_unregister (struct device_driver *drv);struct device_driver *driver_find (const char *name,const struct bus_type *bus); -int driver_probe_done (void ); +bool __init driver_probe_done (void );void wait_for_device_probe (void );void __init wait_for_init_devices_probe (void );
init/do_mounts.c +1 -1
@@ -635,7 +635,7 @@ void __init prepare_namespace(void)if ((ROOT_DEV ==0 ) && root_wait) {printk (KERN_INFO "Waiting for root device %s...\n" , saved_root_name); -while (driver_probe_done () !=0 || +while (!driver_probe_done () || (ROOT_DEV =name_to_dev_t (saved_root_name)) ==0 )msleep (5 );async_synchronize_full ();
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH 01/24] driver core: return bool from driver_probe_done
Quoted 4 lines · Christoph Hellwig
bool is the most sensible return value for a yes/no return. Also add
__initas this funtion is only called from the early boot code.
Applied, thanks!
[01/24] driver core: return bool from driver_probe_done
commit: aa5f6ed8c21ec1aa5fd688118d8d5cd87c5ffc1d
[02/24] PM: hibernate: factor out a helper to find the resume device
commit: 02b42d58f3898134b900ff3030561099e38adb32
[03/24] PM: hibernate: remove the global snapshot_test variable
commit: d6545e687271ab27472eebff770f2de6a5f1a464
[04/24] PM: hibernate: move finding the resume device out of software_resume
commit: cc89c63e2fe37d476357c82390dfb12edcd41cdd
[05/24] init: remove pointless Root_* values
commit: f5524c3fadba35c075a5131bad74e3041507a694
[06/24] init: rename mount_block_root to mount_root_generic
commit: e3102722ffe77094ba9e7e46380792b3dd8a7abd
[07/24] init: refactor mount_root
commit: a6a41d39c2d91ff2543d31b6cc6070f3957e3aea
[08/24] init: pass root_device_name explicitly
commit: c8643c72bc42781fc169c6498a3902bec447099e
[09/24] init: don't remove the /dev/ prefix from error messages
commit: 73231b58b1b496d631fa0ecf9fa7f64f5a07c6e3
[10/24] init: handle ubi/mtd root mounting like all other root types
commit: 07d63cbb67cdb5e2a7720fdd8579b3be979c2d66
[11/24] init: factor the root_wait logic in prepare_namespace into a helper
commit: 3701c600a3e735b9fbac6f7a73e4c086090c97ca
[12/24] init: move the nfs/cifs/ram special cases out of name_to_dev_t
commit: c0c1a7dcb6f5db4500e6574294674213bc24940c
[13/24] init: improve the name_to_dev_t interface
commit: cf056a43121559d3642419917d405c3237ded90a
[14/24] init: clear root_wait on all invalid root= strings
commit: 079caa35f7863cd9958b4555ae873ea4d352a502
[15/24] block: move the code to do early boot lookup of block devices to block/
commit: 702f3189e454b3c3c2f3c99dbf30acf41aab707c
[16/24] block: move more code to early-lookup.c
commit: 7cadcaf1d82618852745e7206fffa2c72c17ce4b
[17/24] dm-snap: simplify the origin_dev == cow_dev check in snapshot_ctr
commit: 26110d5afe8117d1b505fe735ac709bdf063f4da
[18/24] dm: open code dm_get_dev_t in dm_init_init
commit: 49177377e910a8fd5cd1388c966d8fbb51075c3c
[19/24] dm: remove dm_get_dev_t
commit: d4a28d7defe79006e59293a4b43d518ba8483fb0
[20/24] dm: only call early_lookup_bdev from early boot context
commit: 7a126d5bf975f082281fb9b45d110cd49b7c3ee4
[21/24] PM: hibernate: don't use early_lookup_bdev in resume_store
commit: 1e8c813b083c4122dfeaa5c3b11028331026e85d
[22/24] mtd: block2mtd: factor the early block device open logic into a helper
commit: b2baa57475e3a24bb9ad27bb9047ea3be94627f5
[23/24] mtd: block2mtd: don't call early_lookup_bdev after the system is running
commit: 8d03187ee7328af8e18ef1782289e0b034e75485
[24/24] block: mark early_lookup_bdev as __init
commit: 2577f53f42947d8ca01666e3444bb7307319ea38Best regards,
Signature · 1 line
Jens Axboe
PATCH 2/24 PM: hibernate: factor out a helper to find the resume device
In reply to Christoph HellwigSplit the logic to find the resume device out software_resume and into a separate helper to start unwindig the convoluted goto logic.
--- kernel/power/hibernate.c | 72 +++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 35 deletions(-)
kernel/power/hibernate.c +37 -35
@@ -910,6 +910,41 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data) }EXPORT_SYMBOL_GPL (hibernate_quiet_exec); +static int find_resume_device (void ) +{ +if (!strlen (resume_file)) +return -ENOENT ; + +pm_pr_dbg ("Checking hibernation image partition %s\n" , resume_file); + +if (resume_delay) { +pr_info ("Waiting %dsec before reading resume device ...\n" , + resume_delay); +ssleep (resume_delay); + } + +/* Check if the device is there */ + swsusp_resume_device =name_to_dev_t (resume_file); +if (swsusp_resume_device) +return 0 ; + +/* +* Some device discovery might still be in progress; we need to wait for +* this to finish. +*/ +wait_for_device_probe (); +if (resume_wait) { +while (!(swsusp_resume_device =name_to_dev_t (resume_file))) +msleep (10 ); +async_synchronize_full (); + } + + swsusp_resume_device =name_to_dev_t (resume_file); +if (!swsusp_resume_device) +return -ENODEV ; +return 0 ; +} +/** * software_resume - Resume from a saved hibernation image. *
@@ -949,45 +984,12 @@ static int software_resume(void) snapshot_test = false; -if (swsusp_resume_device) - goto Check_image; - -if (!strlen (resume_file)) { - error = -ENOENT ; - goto Unlock; - } - -pm_pr_dbg ("Checking hibernation image partition %s\n" , resume_file); - -if (resume_delay) { -pr_info ("Waiting %dsec before reading resume device ...\n" , - resume_delay); -ssleep (resume_delay); - } - -/* Check if the device is there */ - swsusp_resume_device =name_to_dev_t (resume_file);if (!swsusp_resume_device) { -/* -* Some device discovery might still be in progress; we need -* to wait for this to finish. -*/ -wait_for_device_probe (); - -if (resume_wait) { -while ((swsusp_resume_device =name_to_dev_t (resume_file)) ==0 ) -msleep (10 ); -async_synchronize_full (); - } - - swsusp_resume_device =name_to_dev_t (resume_file); -if (!swsusp_resume_device) { - error = -ENODEV ; + error =find_resume_device (); +if (error) goto Unlock; - } } - Check_image:pm_pr_dbg ("Hibernation image partition %d:%d present\n" ,MAJOR (swsusp_resume_device),MINOR (swsusp_resume_device));
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 3/24 PM: hibernate: remove the global snapshot_test variable
In reply to Christoph HellwigPassing call dependent variable in global variables is a huge antipattern. Fix it up.
--- kernel/power/hibernate.c | 17 ++++++----------- kernel/power/power.h | 3 +-- kernel/power/swap.c | 2 +- 3 files changed, 8 insertions(+), 14 deletions(-)
kernel/power/hibernate.c +6 -11
@@ -64,7 +64,6 @@ enum {static int hibernation_mode =HIBERNATION_SHUTDOWN ;bool freezer_test_done; -bool snapshot_test;static const struct platform_hibernation_ops *hibernation_ops;
@@ -684,7 +683,7 @@ static void power_down(void)cpu_relax (); } -static int load_image_and_restore (void ) +static int load_image_and_restore (bool snapshot_test) {int error;unsigned int flags;
@@ -721,6 +720,7 @@ static int load_image_and_restore(void)*/ int hibernate (void ) { +bool snapshot_test = false;unsigned int sleep_flags;int error;
@@ -748,9 +748,6 @@ int hibernate(void)if (error) goto Exit; -/* protected by system_transition_mutex */ - snapshot_test = false; -lock_device_hotplug ();/* Allocate memory management structures */ error =create_basic_memory_bitmaps ();
@@ -792,9 +789,9 @@ int hibernate(void)unlock_device_hotplug ();if (snapshot_test) {pm_pr_dbg ("Checking hibernation image\n" ); - error =swsusp_check (); + error =swsusp_check (snapshot_test);if (!error) - error =load_image_and_restore (); + error =load_image_and_restore (snapshot_test); }thaw_processes ();
@@ -982,8 +979,6 @@ static int software_resume(void)*/ mutex_lock_nested (&system_transition_mutex,SINGLE_DEPTH_NESTING ); - snapshot_test = false; -if (!swsusp_resume_device) { error =find_resume_device ();if (error)
@@ -994,7 +989,7 @@ static int software_resume(void) MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));pm_pr_dbg ("Looking for hibernation image.\n" ); - error =swsusp_check (); + error =swsusp_check (false);if (error) goto Unlock;
@@ -1022,7 +1017,7 @@ static int software_resume(void) goto Close_Finish; } - error =load_image_and_restore (); + error =load_image_and_restore (false);thaw_processes (); Finish:pm_notifier_call_chain (PM_POST_RESTORE );
kernel/power/power.h +1 -2
@@ -59,7 +59,6 @@ asmlinkage int swsusp_save(void);/* kernel/power/hibernate.c */ extern bool freezer_test_done; -extern bool snapshot_test;extern int hibernation_snapshot (int platform_mode);extern int hibernation_restore (int platform_mode);
@@ -174,7 +173,7 @@ extern int swsusp_swap_in_use(void);#define SF_HW_SIG 8/* kernel/power/hibernate.c */ -extern int swsusp_check (void ); +int swsusp_check (bool snapshot_test);extern void swsusp_free (void );extern int swsusp_read (unsigned int *flags_p);extern int swsusp_write (unsigned int flags);
kernel/power/swap.c +1 -1
@@ -1514,7 +1514,7 @@ int swsusp_read(unsigned int *flags_p)* swsusp_check - Check for swsusp signature in the resume device */ -int swsusp_check (void ) +int swsusp_check (bool snapshot_test) {int error;void *holder;
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 4/24 PM: hibernate: move finding the resume device out of software_resume
In reply to Christoph Hellwigsoftware_resume can be called either from an init call in the boot code, or from sysfs once the system has finished booting, and the two invocation methods this can't race with each other.
For the latter case we did just parse the suspend device manually, while the former might not have one. Split software_resume so that the search only happens for the boot case, which also means the special lockdep nesting annotation can go away as the system transition mutex can be taken a little later and doesn't have the sysfs locking nest inside it.
--- kernel/power/hibernate.c | 80 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 41 deletions(-)
kernel/power/hibernate.c +39 -41
@@ -907,7 +907,7 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data) }EXPORT_SYMBOL_GPL (hibernate_quiet_exec); -static int find_resume_device (void ) +static int __init find_resume_device (void ) {if (!strlen (resume_file))return -ENOENT ;
@@ -942,53 +942,16 @@ static int find_resume_device(void)return 0 ; } -/** -* software_resume - Resume from a saved hibernation image. -* -* This routine is called as a late initcall, when all devices have been -* discovered and initialized already. -* -* The image reading code is called to see if there is a hibernation image -* available for reading. If that is the case, devices are quiesced and the -* contents of memory is restored from the saved image. -* -* If this is successful, control reappears in the restored target kernel in -* hibernation_snapshot() which returns to hibernate(). Otherwise, the routine -* attempts to recover gracefully and make the kernel return to the normal mode -* of operation. -*/ static int software_resume (void ) {int error; -/* -* If the user said "noresume".. bail out early. -*/ -if (noresume || !hibernation_available ()) -return 0 ; - -/* -* name_to_dev_t() below takes a sysfs buffer mutex when sysfs -* is configured into the kernel. Since the regular hibernate -* trigger path is via sysfs which takes a buffer mutex before -* calling hibernate functions (which take system_transition_mutex) -* this can cause lockdep to complain about a possible ABBA deadlock -* which cannot happen since we're in the boot code here and -* sysfs can't be invoked yet. Therefore, we use a subclass -* here to avoid lockdep complaining. -*/ -mutex_lock_nested (&system_transition_mutex,SINGLE_DEPTH_NESTING ); - -if (!swsusp_resume_device) { - error =find_resume_device (); -if (error) - goto Unlock; - } -pm_pr_dbg ("Hibernation image partition %d:%d present\n" ,MAJOR (swsusp_resume_device),MINOR (swsusp_resume_device));pm_pr_dbg ("Looking for hibernation image.\n" ); + +mutex_lock (&system_transition_mutex); error =swsusp_check (false);if (error) goto Unlock;
@@ -1035,7 +998,39 @@ static int software_resume(void) goto Finish; } -late_initcall_sync (software_resume); +/** +* software_resume_initcall - Resume from a saved hibernation image. +* +* This routine is called as a late initcall, when all devices have been +* discovered and initialized already. +* +* The image reading code is called to see if there is a hibernation image +* available for reading. If that is the case, devices are quiesced and the +* contents of memory is restored from the saved image. +* +* If this is successful, control reappears in the restored target kernel in +* hibernation_snapshot() which returns to hibernate(). Otherwise, the routine +* attempts to recover gracefully and make the kernel return to the normal mode +* of operation. +*/ +static int __init software_resume_initcall (void ) +{ +/* +* If the user said "noresume".. bail out early. +*/ +if (noresume || !hibernation_available ()) +return 0 ; + +if (!swsusp_resume_device) { +int error =find_resume_device (); + +if (error) +return error; + } + +return software_resume (); +} +late_initcall_sync (software_resume_initcall);static const char *const hibernation_modes[] = {
@@ -1176,6 +1171,9 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,char *name;dev_t res; +if (!hibernation_available ()) +return 0 ; +if (len && buf[len-1 ] =='\n' ) len--; name =kstrndup (buf, len,GFP_KERNEL );
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH 04/24] PM: hibernate: move finding the resume device out of software_resume
Quoted 4 lines · Christoph Hellwig
software_resumecan be called either from an init call in the boot code, or from sysfs once the system has finished booting, and the two invocation methods this can't race with each other.
Quoted 8 lines
For the latter case we did just parse the suspend device manually, while the former might not have one. Split
software_resumeso that the search only happens for the boot case, which also means the special lockdep nesting annotation can go away as the system transition mutex can be taken a little later and doesn't have the sysfs locking nest inside it.Signed-off-by Christoph Hellwig <[email protected]>
This caused a regression for me in 6.5-rc1+, fix below.
----8<----
From 95a310ae6cfae9b3cab61e54a1bce488c3ab93a1 Mon Sep 17 00:00:00 2001
From: Vlastimil Babka <[email protected]>
Date: Wed, 2 Aug 2023 15:46:18 +0200
Subject: [PATCH] PM: hibernate: fix resume_store() return value when
hibernation not available
On a laptop with hibernation set up but not actively used, and with secure boot and lockdown enabled kernel, 6.5-rc1 gets stuck on boot with the following repeated messages:
A start job is running for Resume from hibernation using device /dev/system/swap (24s / no limit)
lockdown_is_locked_down: 25311154 callbacks suppressed
Lockdown: systemd-hiberna: hibernation is restricted; see man kernel_lockdown.7
...
Checking the resume code leads to commit cc89c63e2fe3 ("PM: hibernate:
move finding the resume device out of software_resume") which inadvertently changed the return value from resume_store() to 0 when !hibernation_available(). This apparently translates to userspace write() returning 0 as in number of bytes written, and userspace looping indefinitely in the attempt to write the intended value.
Fix this by returning the full number of bytes that were to be written, as that's what was done before the commit.
--- kernel/power/hibernate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/power/hibernate.c +1 -1
@@ -1166,7 +1166,7 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,int error;if (!hibernation_available ()) -return 0 ; +return n;if (len && buf[len-1 ] =='\n' ) len--;
Signature · 1 line
2.41.0
Christoph Hellwig
Reviewed-byRe: [PATCH 04/24] PM: hibernate: move finding the resume device out of software_resume
Looks good, thanks!
Re: [PATCH 04/24] PM: hibernate: move finding the resume device out of software_resume
Quoted 4 lines · Christoph Hellwig
Looks good, thanks!
Reviewed-by Christoph Hellwig <[email protected]>
Re: [PATCH 04/24] PM: hibernate: move finding the resume device out of software_resume
In reply to Vlastimil Babka[TLDR: I'm adding this report to the list of tracked Linux kernel regressions; the text you find below is based on a few templates paragraphs you might have encountered already in similar form. See link in footer if these mails annoy you.]
Quoted 39 lines · Vlastimil Babka
Quoted 4 lines · Christoph Hellwig
software_resumecan be called either from an init call in the boot code, or from sysfs once the system has finished booting, and the two invocation methods this can't race with each other.Quoted 8 lines
For the latter case we did just parse the suspend device manually, while the former might not have one. Split
software_resumeso that the search only happens for the boot case, which also means the special lockdep nesting annotation can go away as the system transition mutex can be taken a little later and doesn't have the sysfs locking nest inside it.Signed-off-by Christoph Hellwig <[email protected]>This caused a regression for me in 6.5-rc1+, fix below.
----8<----
Quoted 1 line
From
95a310ae6cfae9b3cab61e54a1bce488c3ab93a1Mon Sep 17 00:00:00 2001From: Vlastimil Babka <[email protected]>
Date: Wed, 2 Aug 2023 15:46:18 +0200
Subject: [PATCH] PM: hibernate: fixresume_store()return value when
hibernation not availableOn a laptop with hibernation set up but not actively used, and with secure boot and lockdown enabled kernel, 6.5-rc1 gets stuck on boot with the following repeated messages:
A start job is running for Resume from hibernation using device
/dev/system/swap(24s / no limit)
lockdown_is_locked_down: 25311154 callbacks suppressed
Lockdown: systemd-hiberna: hibernation is restricted; see man kernel_lockdown.7
...Checking the resume code leads to commit
cc89c63e2fe3("PM: hibernate:
move finding the resume device out ofsoftware_resume") which inadvertently changed the return value fromresume_store()to 0 when !hibernation_available(). This apparently translates to userspacewrite()returning 0 as in number of bytes written, and userspace looping indefinitely in the attempt to write the intended value.
Quoted 5 lines
Fix this by returning the full number of bytes that were to be written, as that's what was done before the commit.
Fixes cc89c63e2fe3 ("PM: hibernate: move finding the resume device out of software_resume")[...]
Thanks for the report. To be sure the issue doesn't fall through the cracks unnoticed, I'm adding it to regzbot, the Linux kernel regression tracking bot:
#regzbot ^introduced cc89c63e2fe3
#regzbot title pm: boot problems when hibernate is configured and kernel locked down
#regzbot fix: PM: hibernate: fix resume_store() return value when hibernation not available
#regzbot ignore-activity
This isn't a regression? This issue or a fix for it are already discussed somewhere else? It was fixed already? You want to clarify when the regression started to happen? Or point out I got the title or something else totally wrong? Then just reply and tell me -- ideally while also telling regzbot about it, as explained by the page listed in the footer of this mail.
Developers: When fixing the issue, remember to add 'Link:' tags pointing to the report (the parent of this mail). See page linked in footer for details.
Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) --
Everything you wanna know about Linux kernel regression tracking:
https://linux-regtracking.leemhuis.info/about/#tldr
That page also explains what to do if mails like this annoy you.
PATCH 5/24 init: remove pointless Root_* values
In reply to Christoph HellwigRemove all unused defines, and just use the expanded versions for the SCSI disk majors.
I've decided to keep Root_RAM0 even if it could be expanded as there is a lot of special casing for it in the init code.
--- arch/alpha/kernel/setup.c | 2 +- arch/ia64/kernel/setup.c | 2 +- arch/powerpc/platforms/powermac/setup.c | 3 ++- include/linux/root_dev.h | 8 -------- 4 files changed, 4 insertions(+), 11 deletions(-)
arch/alpha/kernel/setup.c +1 -1
@@ -658,7 +658,7 @@ setup_arch(char **cmdline_p)#endif /* Default root filesystem to sda2. */ -ROOT_DEV = Root_SDA2; +ROOT_DEV =MKDEV (SCSI_DISK0_MAJOR ,2 );#ifdef CONFIG_EISA /* FIXME: only set this when we actually have EISA in this box? */
arch/ia64/kernel/setup.c +1 -1
@@ -627,7 +627,7 @@ setup_arch (char **cmdline_p)* is physical disk 1 partition 1 and the Linux root disk is * physical disk 1 partition 2. */ -ROOT_DEV = Root_SDA2;/* default to second partition on first drive */ +ROOT_DEV =MKDEV (SCSI_DISK0_MAJOR ,2 );if (is_uv_system ())uv_setup (cmdline_p);
arch/powerpc/platforms/powermac/setup.c +2 -1
@@ -76,7 +76,8 @@ int pmac_newworld;static int current_root_goodness =-1 ; -#define DEFAULT_ROOT_DEVICE Root_SDA1/* sda1 - slightly silly choice */ +/* sda1 - slightly silly choice */ +#define DEFAULT_ROOT_DEVICE MKDEV(SCSI_DISK0_MAJOR, 1)sys_ctrler_t sys_ctrler =SYS_CTRLER_UNKNOWN ;EXPORT_SYMBOL (sys_ctrler);
include/linux/root_dev.h +0 -8
@@ -10,14 +10,6 @@ enum { Root_NFS =MKDEV (UNNAMED_MAJOR ,255 ), Root_CIFS =MKDEV (UNNAMED_MAJOR ,254 ), Root_RAM0 = MKDEV(RAMDISK_MAJOR, 0), - Root_RAM1 =MKDEV (RAMDISK_MAJOR ,1 ), - Root_FD0 =MKDEV (FLOPPY_MAJOR ,0 ), - Root_HDA1 =MKDEV (IDE0_MAJOR ,1 ), - Root_HDA2 =MKDEV (IDE0_MAJOR ,2 ), - Root_SDA1 =MKDEV (SCSI_DISK0_MAJOR ,1 ), - Root_SDA2 =MKDEV (SCSI_DISK0_MAJOR ,2 ), - Root_HDC1 =MKDEV (IDE1_MAJOR ,1 ), - Root_SR0 = MKDEV(SCSI_CDROM_MAJOR, 0), };extern dev_t ROOT_DEV ;
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 6/24 init: rename mount_block_root to mount_root_generic
In reply to Christoph Hellwigmount_block_root is also used to mount non-block file systems, so give it a better name.
--- init/do_mounts.c | 6 +++--- init/do_mounts.h | 2 +- init/do_mounts_initrd.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
init/do_mounts.c +3 -3
@@ -391,7 +391,7 @@ static int __init do_mount_root(const char *name, const char *fs,return ret; } -void __init mount_block_root (char *name,int flags) +void __init mount_root_generic (char *name,int flags) {struct page *page =alloc_page (GFP_KERNEL );char *fs_names =page_address (page);
@@ -589,7 +589,7 @@ void __init mount_root(void)if (err <0 )pr_emerg ("Failed to create /dev/root: %d\n" , err); - mount_block_root("/dev/root", root_mountflags); + mount_root_generic("/dev/root", root_mountflags); }#endif }
@@ -620,7 +620,7 @@ void __init prepare_namespace(void) root_device_name = saved_root_name;if (!strncmp (root_device_name,"mtd" ,3 ) || !strncmp (root_device_name,"ubi" ,3 )) { -mount_block_root (root_device_name, root_mountflags); +mount_root_generic (root_device_name, root_mountflags); goto out; }ROOT_DEV =name_to_dev_t (root_device_name);
init/do_mounts.h +1 -1
@@ -10,7 +10,7 @@#include <linux/root_dev.h> #include <linux/init_syscalls.h> -void mount_block_root (char *name,int flags); +void mount_root_generic (char *name,int flags);void mount_root (void );extern int root_mountflags;
init/do_mounts_initrd.c +1 -1
@@ -95,7 +95,7 @@ static void __init handle_initrd(void) real_root_dev =new_encode_dev (ROOT_DEV );create_dev ("/dev/root.old" , Root_RAM0);/* mount initrd on rootfs' /root */ -mount_block_root ("/dev/root.old" , root_mountflags & ~MS_RDONLY ); +mount_root_generic ("/dev/root.old" , root_mountflags & ~MS_RDONLY );init_mkdir ("/old" ,0700 );init_chdir ("/old" );
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 7/24 init: refactor mount_root
In reply to Christoph HellwigProvide stubs for all the lower level mount helpers, and just switch on ROOT_DEV in the main function.
--- init/do_mounts.c | 104 +++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 48 deletions(-)
init/do_mounts.c +56 -48
@@ -453,15 +453,14 @@ void __init mount_root_generic(char *name, int flags)#define NFSROOT_TIMEOUT_MAX 30#define NFSROOT_RETRY_MAX 5 -static int __init mount_nfs_root (void ) +static void __init mount_nfs_root (void ) {char *root_dev, *root_data;unsigned int timeout; -int try, err; +int try; - err =nfs_root_data (&root_dev, &root_data); -if (err !=0 ) -return 0 ; +if (nfs_root_data (&root_dev, &root_data)) + goto fail;/* * The server or network may not be ready, so try several
@@ -470,10 +469,8 @@ static int __init mount_nfs_root(void)*/ timeout =NFSROOT_TIMEOUT_MIN ;for (try =1 ; ; try++) { - err =do_mount_root (root_dev,"nfs" , - root_mountflags, root_data); -if (err ==0 ) -return 1 ; +if (!do_mount_root (root_dev,"nfs" , root_mountflags, root_data)) +return ;if (try >NFSROOT_RETRY_MAX )break ;
@@ -483,9 +480,14 @@ static int __init mount_nfs_root(void)if (timeout >NFSROOT_TIMEOUT_MAX ) timeout = NFSROOT_TIMEOUT_MAX; } -return 0 ; +fail: +pr_err ("VFS: Unable to mount root fs via NFS.\n" ); } -#endif +#else +static inline void mount_nfs_root (void ) +{ +} +#endif /* CONFIG_ROOT_NFS */ #ifdef CONFIG_CIFS_ROOT
@@ -495,22 +497,20 @@ extern int cifs_root_data(char **dev, char **opts);#define CIFSROOT_TIMEOUT_MAX 30#define CIFSROOT_RETRY_MAX 5 -static int __init mount_cifs_root (void ) +static void __init mount_cifs_root (void ) {char *root_dev, *root_data;unsigned int timeout; -int try, err; +int try; - err =cifs_root_data (&root_dev, &root_data); -if (err !=0 ) -return 0 ; +if (cifs_root_data (&root_dev, &root_data)) + goto fail; timeout =CIFSROOT_TIMEOUT_MIN ;for (try =1 ; ; try++) { - err =do_mount_root (root_dev,"cifs" , root_mountflags, - root_data); -if (err ==0 ) -return 1 ; +if (!do_mount_root (root_dev,"cifs" , root_mountflags, + root_data)) +return ;if (try >CIFSROOT_RETRY_MAX )break ;
@@ -519,9 +519,14 @@ static int __init mount_cifs_root(void)if (timeout >CIFSROOT_TIMEOUT_MAX ) timeout = CIFSROOT_TIMEOUT_MAX; } -return 0 ; +fail: +pr_err ("VFS: Unable to mount root fs via SMB.\n" ); } -#endif +#else +static inline void mount_cifs_root (void ) +{ +} +#endif /* CONFIG_CIFS_ROOT */ static bool __init fs_is_nodev (char *fstype) {
@@ -563,35 +568,38 @@ static int __init mount_nodev_root(void)return err; } -void __init mount_root (void ) -{ -#ifdef CONFIG_ROOT_NFS -if (ROOT_DEV == Root_NFS) { -if (!mount_nfs_root ()) -printk (KERN_ERR "VFS: Unable to mount root fs via NFS.\n" ); -return ; - } -#endif -#ifdef CONFIG_CIFS_ROOT -if (ROOT_DEV == Root_CIFS) { -if (!mount_cifs_root ()) -printk (KERN_ERR "VFS: Unable to mount root fs via SMB.\n" ); -return ; - } -#endif -if (ROOT_DEV ==0 && root_device_name && root_fs_names) { -if (mount_nodev_root () ==0 ) -return ; - }#ifdef CONFIG_BLOCK - { -int err =create_dev ("/dev/root" ,ROOT_DEV ); +static void __init mount_block_root (void ) +{ +int err =create_dev ("/dev/root" ,ROOT_DEV ); + +if (err <0 ) +pr_emerg ("Failed to create /dev/root: %d\n" , err); +mount_root_generic ("/dev/root" , root_mountflags); +} +#else +static inline void mount_block_root (void ) +{ +} +#endif /* CONFIG_BLOCK */ -if (err <0 ) -pr_emerg ("Failed to create /dev/root: %d\n" , err); -mount_root_generic ("/dev/root" , root_mountflags); +void __init mount_root (void ) +{ +switch (ROOT_DEV ) { +case Root_NFS: +mount_nfs_root (); +break ; +case Root_CIFS: +mount_cifs_root (); +break ; +case 0 : +if (root_device_name && root_fs_names &&mount_nodev_root () ==0 ) +break ; + fallthrough; +default : +mount_block_root (); +break ; } -#endif }/*
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 8/24 init: pass root_device_name explicitly
In reply to Christoph HellwigInstead of declaring root_device_name as a global variable pass it as an argument to the functions using it.
--- init/do_mounts.c | 29 ++++++++++++++++------------- init/do_mounts.h | 14 +++++++------- init/do_mounts_initrd.c | 11 ++++++----- 3 files changed, 29 insertions(+), 25 deletions(-)
init/do_mounts.c +16 -13
@@ -28,7 +28,6 @@#include "do_mounts.h" int root_mountflags =MS_RDONLY |MS_SILENT ; -static char *__initdata root_device_name;static char __initdata saved_root_name[64 ];static int root_wait;
@@ -391,7 +390,7 @@ static int __init do_mount_root(const char *name, const char *fs,return ret; } -void __init mount_root_generic (char *name,int flags) +void __init mount_root_generic (char *name,char *pretty_name,int flags) {struct page *page =alloc_page (GFP_KERNEL );char *fs_names =page_address (page);
@@ -425,7 +424,7 @@ void __init mount_root_generic(char *name, int flags)* and give them a list of the available devices */ printk ("VFS: Cannot open root device \"%s\" or %s: error %d\n" , - root_device_name, b, err); + pretty_name, b, err);printk ("Please append a correct \"root=\" boot option; here are the available partitions:\n" );printk_all_partitions ();
@@ -541,7 +540,7 @@ static bool __init fs_is_nodev(char *fstype)return ret; } -static int __init mount_nodev_root (void ) +static int __init mount_nodev_root (char *root_device_name) {char *fs_names, *fstype;int err = -EINVAL ;
@@ -569,21 +568,21 @@ static int __init mount_nodev_root(void) }#ifdef CONFIG_BLOCK -static void __init mount_block_root (void ) +static void __init mount_block_root (char *root_device_name) {int err =create_dev ("/dev/root" ,ROOT_DEV );if (err <0 )pr_emerg ("Failed to create /dev/root: %d\n" , err); -mount_root_generic ("/dev/root" , root_mountflags); +mount_root_generic ("/dev/root" , root_device_name, root_mountflags); }#else -static inline void mount_block_root (void ) +static inline void mount_block_root (char *root_device_name) { }#endif /* CONFIG_BLOCK */ -void __init mount_root (void ) +void __init mount_root (char *root_device_name) {switch (ROOT_DEV ) {case Root_NFS:
@@ -593,11 +592,12 @@ void __init mount_root(void)mount_cifs_root ();break ;case 0 : -if (root_device_name && root_fs_names &&mount_nodev_root () ==0 ) +if (root_device_name && root_fs_names && +mount_nodev_root (root_device_name) ==0 )break ; fallthrough;default : -mount_block_root (); +mount_block_root (root_device_name);break ; } }
@@ -607,6 +607,8 @@ void __init mount_root(void)*/ void __init prepare_namespace (void ) { +char *root_device_name; +if (root_delay) {printk (KERN_INFO "Waiting %d sec before mounting root device...\n" , root_delay);
@@ -628,7 +630,8 @@ void __init prepare_namespace(void) root_device_name = saved_root_name;if (!strncmp (root_device_name,"mtd" ,3 ) || !strncmp (root_device_name,"ubi" ,3 )) { -mount_root_generic (root_device_name, root_mountflags); +mount_root_generic (root_device_name, root_device_name, + root_mountflags); goto out; }ROOT_DEV =name_to_dev_t (root_device_name);
@@ -636,7 +639,7 @@ void __init prepare_namespace(void) root_device_name +=5 ; } -if (initrd_load ()) +if (initrd_load (root_device_name)) goto out;/* wait for any asynchronous scanning to complete */
@@ -649,7 +652,7 @@ void __init prepare_namespace(void)async_synchronize_full (); } -mount_root (); +mount_root (root_device_name); out:devtmpfs_mount ();init_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );
init/do_mounts.h +7 -7
@@ -10,8 +10,8 @@#include <linux/root_dev.h> #include <linux/init_syscalls.h> -void mount_root_generic (char *name,int flags); -void mount_root (void ); +void mount_root_generic (char *name,char *pretty_name,int flags); +void mount_root (char *root_device_name);extern int root_mountflags;static inline __init int create_dev (char *name,dev_t dev)
@@ -33,11 +33,11 @@ static inline int rd_load_image(char *from) { return 0; }#endif #ifdef CONFIG_BLK_DEV_INITRD - -bool __init initrd_load (void ); - +bool __init initrd_load (char *root_device_name);#else - -static inline bool initrd_load (void ) {return false; } +static inline bool initrd_load (char *root_device_name) +{ +return false; + }#endif
init/do_mounts_initrd.c +6 -5
@@ -83,7 +83,7 @@ static int __init init_linuxrc(struct subprocess_info *info, struct cred *new)return 0 ; } -static void __init handle_initrd (void ) +static void __init handle_initrd (char *root_device_name) {struct subprocess_info *info;static char *argv[] = {"linuxrc" ,NULL , };
@@ -95,7 +95,8 @@ static void __init handle_initrd(void) real_root_dev =new_encode_dev (ROOT_DEV );create_dev ("/dev/root.old" , Root_RAM0);/* mount initrd on rootfs' /root */ -mount_root_generic ("/dev/root.old" , root_mountflags & ~MS_RDONLY ); +mount_root_generic ("/dev/root.old" , root_device_name, + root_mountflags & ~MS_RDONLY );init_mkdir ("/old" ,0700 );init_chdir ("/old" );
@@ -117,7 +118,7 @@ static void __init handle_initrd(void)init_chdir ("/" );ROOT_DEV =new_decode_dev (real_root_dev); -mount_root (); +mount_root (root_device_name);printk (KERN_NOTICE "Trying to move old root to /initrd ... " ); error =init_mount ("/old" ,"/root/initrd" ,NULL ,MS_MOVE ,NULL );
@@ -133,7 +134,7 @@ static void __init handle_initrd(void) } } -bool __init initrd_load (void ) +bool __init initrd_load (char *root_device_name) {if (mount_initrd) {create_dev ("/dev/ram" , Root_RAM0);
@@ -145,7 +146,7 @@ bool __init initrd_load(void)*/ if (rd_load_image ("/initrd.image" ) &&ROOT_DEV != Root_RAM0) {init_unlink ("/initrd.image" ); -handle_initrd (); +handle_initrd (root_device_name);return true; } }
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH 08/24] init: pass root_device_name explicitly
Hi,
Quoted 4 lines · Christoph Hellwig
Instead of declaring
root_device_nameas a global variable pass it as an argument to the functions using it.Signed-off-by Christoph Hellwig <[email protected]>
This patch results in the following build error when trying to build xtensa:tinyconfig.
WARNING: modpost: vmlinux: section mismatch in reference: strcpy.isra.0+0x14 (section: .text.unlikely) -> initcall_level_names (section: .init.data)
ERROR: modpost: Section mismatches detected.
Unfortunately, reverting it is not possible due to conflicts, so I can not confirm the bisect results.
Bisect log attached.
Guenter
---
# bad: [8d2be868b42c08290509c60515865f4de24ea704] Add linux-next specific files for 20230623
# good: [45a3e24f65e90a047bef86f927ebdc4c710edaa1] Linux 6.4-rc7
git bisect start 'HEAD' 'v6.4-rc7'
# good: [a5838c78db6a3a02e8d221e588c948f792e7f256] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next.git
git bisect good a5838c78db6a3a02e8d221e588c948f792e7f256
# bad: [cca41cc0b5485a0ec20707316c1a00082c01a2af] Merge branch 'for-next' of git://git.kernel.dk/linux-block.git
git bisect bad cca41cc0b5485a0ec20707316c1a00082c01a2af
# good: [901bdf5ea1a836400ee69aa32b04e9c209271ec7] Merge tag 'amd-drm-next-6.5-2023-06-09' of https://gitlab.freedesktop.org/agd5f/linux into drm-next git bisect good 901bdf5ea1a836400ee69aa32b04e9c209271ec7
# good: [b4666c320b8113d94b3f4624054562e7add57e4a] Merge branch 'for-next' of https://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394.git
git bisect good b4666c320b8113d94b3f4624054562e7add57e4a
# good: [b2c28785b125acb28a681462510297410cbbabd7] ASoC: dt-bindings: microchip,sama7g5-pdmc: Simplify "microchip,mic-pos" constraints git bisect good b2c28785b125acb28a681462510297410cbbabd7
# bad: [9d217fb0e778d69b2e3988efbc441976c0fb29b5] nvme: reorder fields in 'struct nvme_ctrl'
git bisect bad 9d217fb0e778d69b2e3988efbc441976c0fb29b5
# good: [20d099756b98fa6b5b838448b1ffbce46f4f3283] block: Replace all non-returning strlcpy with strscpy
git bisect good 20d099756b98fa6b5b838448b1ffbce46f4f3283
# bad: [93c8f6f38be67e30adf8d8eb5e7e9ccb89326119] pktcdvd: Drop redundant castings for sector_t
git bisect bad 93c8f6f38be67e30adf8d8eb5e7e9ccb89326119
# bad: [c8643c72bc42781fc169c6498a3902bec447099e] init: pass root_device_name explicitly
git bisect bad c8643c72bc42781fc169c6498a3902bec447099e
# good: [87efb39075be6a288cd7f23858f15bd01c83028a] fs: add a method to shut down the file system
git bisect good 87efb39075be6a288cd7f23858f15bd01c83028a
# good: [aa5f6ed8c21ec1aa5fd688118d8d5cd87c5ffc1d] driver core: return bool from driver_probe_done
git bisect good aa5f6ed8c21ec1aa5fd688118d8d5cd87c5ffc1d
# good: [cc89c63e2fe37d476357c82390dfb12edcd41cdd] PM: hibernate: move finding the resume device out of software_resume
git bisect good cc89c63e2fe37d476357c82390dfb12edcd41cdd
# good: [e3102722ffe77094ba9e7e46380792b3dd8a7abd] init: rename mount_block_root to mount_root_generic
git bisect good e3102722ffe77094ba9e7e46380792b3dd8a7abd
# good: [a6a41d39c2d91ff2543d31b6cc6070f3957e3aea] init: refactor mount_root
git bisect good a6a41d39c2d91ff2543d31b6cc6070f3957e3aea
# first bad commit: [c8643c72bc42781fc169c6498a3902bec447099e] init: pass root_device_name explicitly
Re: [PATCH 08/24] init: pass root_device_name explicitly
Quoted 6 lines · Guenter Roeck
Hi,
Quoted 3 lines · Christoph Hellwig
Instead of declaring
root_device_nameas a global variable pass it as an argument to the functions using it.
Quoted 7 lines
Quoted 1 line
Signed-off-by Christoph Hellwig <[email protected]>This patch results in the following build error when trying to build xtensa:tinyconfig.
WARNING: modpost: vmlinux: section mismatch in reference: strcpy.isra.0+0x14 (section: .text.unlikely) ->
initcall_level_names(section: .init.data)
ERROR: modpost: Section mismatches detected.
I can reproduce these with gcc 13.1 on xtensa, but the report makes no sense to me. If I disable CONFIG_CC_OPTIMIZE_FOR_SIZE it now reports a similar warning for put_page intead of strcpy which seems just as arcance.
Re: [PATCH 08/24] init: pass root_device_name explicitly
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Guenter Roeck
Hi,
Quoted 4 lines · Christoph Hellwig
Instead of declaring
root_device_nameas a global variable pass it as an argument to the functions using it.Signed-off-by Christoph Hellwig <[email protected]>This patch results in the following build error when trying to build xtensa:tinyconfig.
Quoted 8 lines
Quoted 2 lines
WARNING: modpost: vmlinux: section mismatch in reference: strcpy.isra.0+0x14 (section: .text.unlikely) ->
initcall_level_names(section: .init.data)
ERROR: modpost: Section mismatches detected.I can reproduce these with gcc 13.1 on xtensa, but the report makes no sense to me. If I disable
CONFIG_CC_OPTIMIZE_FOR_SIZEit now reports a similar warning forput_pageintead of strcpy which seems just as arcance.
I don't see that (I tried 11.3, 11.4, 12.3, and 13.1), but then I am not sure if this is worth tracking down. I just force CONFIG_SECTION_MISMATCH_WARN_ONLY=y for xtensa builds instead.
Guenter
Re: [PATCH 08/24] init: pass root_device_name explicitly
Quoted 23 lines · Guenter Roeck
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Guenter Roeck
Hi,
Quoted 4 lines · Christoph Hellwig
Instead of declaring
root_device_nameas a global variable pass it as an argument to the functions using it.Signed-off-by Christoph Hellwig <[email protected]>This patch results in the following build error when trying to build xtensa:tinyconfig.
Quoted 8 lines
Quoted 2 lines
WARNING: modpost: vmlinux: section mismatch in reference: strcpy.isra.0+0x14 (section: .text.unlikely) ->
initcall_level_names(section: .init.data)
ERROR: modpost: Section mismatches detected.I can reproduce these with gcc 13.1 on xtensa, but the report makes no sense to me. If I disable
CONFIG_CC_OPTIMIZE_FOR_SIZEit now reports a similar warning forput_pageintead of strcpy which seems just as arcance.
Quoted 3 lines
I don't see that (I tried 11.3, 11.4, 12.3, and 13.1), but then I am not sure if this is worth tracking down. I just force
CONFIG_SECTION_MISMATCH_WARN_ONLY=yfor xtensa builds instead.
I believe it's yet another manifestation of the following issue:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92938
Hunting is still on my todo list, but it's quite low, so I guess forcing CONFIG_SECTION_MISMATCH_WARN_ONLY=y for xtensa is the right thing to do for now.
Signature · 2 lines
Thanks. -- Max
PATCH 9/24 init: don't remove the /dev/ prefix from error messages
In reply to Christoph HellwigRemove the code that drops the /dev/ prefix from root_device_name, which is only used for error messages when mounting the root device fails.
--- init/do_mounts.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
init/do_mounts.c +6 -11
@@ -607,8 +607,6 @@ void __init mount_root(char *root_device_name)*/ void __init prepare_namespace (void ) { -char *root_device_name; -if (root_delay) {printk (KERN_INFO "Waiting %d sec before mounting root device...\n" , root_delay);
@@ -627,19 +625,16 @@ void __init prepare_namespace(void)md_run_setup ();if (saved_root_name[0 ]) { - root_device_name = saved_root_name; -if (!strncmp (root_device_name,"mtd" ,3 ) || - !strncmp (root_device_name,"ubi" ,3 )) { -mount_root_generic (root_device_name, root_device_name, +if (!strncmp (saved_root_name,"mtd" ,3 ) || + !strncmp (saved_root_name,"ubi" ,3 )) { +mount_root_generic (saved_root_name, saved_root_name, root_mountflags); goto out; } -ROOT_DEV =name_to_dev_t (root_device_name); -if (strncmp (root_device_name,"/dev/" ,5 ) ==0 ) - root_device_name +=5 ; +ROOT_DEV =name_to_dev_t (saved_root_name); } -if (initrd_load (root_device_name)) +if (initrd_load (saved_root_name)) goto out;/* wait for any asynchronous scanning to complete */
@@ -652,7 +647,7 @@ void __init prepare_namespace(void)async_synchronize_full (); } -mount_root (root_device_name); +mount_root (saved_root_name); out:devtmpfs_mount ();init_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 10/24 init: handle ubi/mtd root mounting like all other root types
In reply to Christoph HellwigAssign a Root_Generic magic value for UBI/MTD root and handle the root mounting in mount_root like all other root types. Besides making the code more clear this also means that UBI/MTD root can be used together with an initrd (not that anyone should care).
Also factor parsing of the root name into a helper now that it can be easily done and will get more complicated with subsequent patches.
--- include/linux/root_dev.h | 1 + init/do_mounts.c | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-)
include/linux/root_dev.h +1 -0
@@ -9,6 +9,7 @@enum { Root_NFS =MKDEV (UNNAMED_MAJOR ,255 ), Root_CIFS =MKDEV (UNNAMED_MAJOR ,254 ), + Root_Generic =MKDEV (UNNAMED_MAJOR ,253 ), Root_RAM0 =MKDEV (RAMDISK_MAJOR ,0 ), };
init/do_mounts.c +14 -9
@@ -591,6 +591,10 @@ void __init mount_root(char *root_device_name)case Root_CIFS:mount_cifs_root ();break ; +case Root_Generic: +mount_root_generic (root_device_name, root_device_name, + root_mountflags); +break ;case 0 :if (root_device_name && root_fs_names &&mount_nodev_root (root_device_name) ==0 )
@@ -602,6 +606,14 @@ void __init mount_root(char *root_device_name) } } +static dev_t __init parse_root_device (char *root_device_name) +{ +if (!strncmp (root_device_name,"mtd" ,3 ) || + !strncmp (root_device_name,"ubi" ,3 )) +return Root_Generic; +return name_to_dev_t (root_device_name); +} +/* * Prepare the namespace - decide what/where to mount, load ramdisks, etc. */
@@ -624,15 +636,8 @@ void __init prepare_namespace(void)md_run_setup (); -if (saved_root_name[0 ]) { -if (!strncmp (saved_root_name,"mtd" ,3 ) || - !strncmp (saved_root_name,"ubi" ,3 )) { -mount_root_generic (saved_root_name, saved_root_name, - root_mountflags); - goto out; - } -ROOT_DEV =name_to_dev_t (saved_root_name); - } +if (saved_root_name[0 ]) +ROOT_DEV =parse_root_device (saved_root_name);if (initrd_load (saved_root_name)) goto out;
Signature · 1 line
2.39.2
PATCH 11/24 init: factor the root_wait logic in prepare_namespace into a helper
In reply to Christoph HellwigThe root_wait logic is a bit obsfucated right now. Expand it and move it into a helper.
--- init/do_mounts.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
init/do_mounts.c +22 -10
@@ -606,6 +606,26 @@ void __init mount_root(char *root_device_name) } } +/* wait for any asynchronous scanning to complete */ +static void __init wait_for_root (char *root_device_name) +{ +if (ROOT_DEV !=0 ) +return ; + +pr_info ("Waiting for root device %s...\n" , root_device_name); + +for (;;) { +if (driver_probe_done ()) { +ROOT_DEV =name_to_dev_t (root_device_name); +if (ROOT_DEV ) +break ; + } +msleep (5 ); + } +async_synchronize_full (); + +} +static dev_t __init parse_root_device (char *root_device_name) { if (!strncmp(root_device_name, "mtd", 3) ||
@@ -642,16 +662,8 @@ void __init prepare_namespace(void)if (initrd_load (saved_root_name)) goto out; -/* wait for any asynchronous scanning to complete */ -if ((ROOT_DEV ==0 ) && root_wait) { -printk (KERN_INFO "Waiting for root device %s...\n" , - saved_root_name); -while (!driver_probe_done () || - (ROOT_DEV =name_to_dev_t (saved_root_name)) ==0 ) -msleep (5 ); -async_synchronize_full (); - } - +if (root_wait) +wait_for_root (saved_root_name);mount_root (saved_root_name); out:devtmpfs_mount ();
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 12/24 init: move the nfs/cifs/ram special cases out of name_to_dev_t
In reply to Christoph HellwigThe nfs/cifs/ram special case only needs to be parsed once, and only in the boot code. Move them out of name_to_dev_t and into prepare_namespace.
--- Documentation/admin-guide/kernel-parameters.txt | 7 ++++++- init/do_mounts.c | 14 ++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +6 -1
@@ -5452,7 +5452,12 @@ port and the regular usb controller gets disabled. root= [KNL] Root filesystem - See name_to_dev_t comment in init/do_mounts.c. + Usually this a a block device specifier of some kind, + see the name_to_dev_t comment in init/do_mounts.c for + details. + Alternatively this can be "ram" for the legacy initial + ramdisk, "nfs" and "cifs" for root on a network file + system, or "mtd" and "ubi" for mounting from raw flash. rootdelay= [KNL] Delay (in seconds) to pause before attempting to mount the root filesystem
init/do_mounts.c +6 -8
@@ -248,7 +248,6 @@ static dev_t devt_from_devnum(const char *name)* * 1) <hex_major><hex_minor> device number in hexadecimal represents itself * no leading 0x, for example b302. -* 2) /dev/nfs represents Root_NFS (0xff) * 3) /dev/<disk_name> represents the device number of disk * 4) /dev/<disk_name><decimal> represents the device number * of partition - device number of disk plus the partition number
@@ -266,7 +265,6 @@ static dev_t devt_from_devnum(const char *name)* a colon. * 9) PARTLABEL=<name> with name being the GPT partition label. * MSDOS partitions do not support labels! -* 10) /dev/cifs represents Root_CIFS (0xfe) * * If name doesn't have fall into the categories above, we return (0,0). * block_class is used to check if something is a disk name. If the disk
@@ -275,12 +273,6 @@ static dev_t devt_from_devnum(const char *name)*/ dev_t name_to_dev_t (const char *name) { -if (strcmp (name,"/dev/nfs" ) ==0 ) -return Root_NFS; -if (strcmp (name,"/dev/cifs" ) ==0 ) -return Root_CIFS; -if (strcmp (name,"/dev/ram" ) ==0 ) -return Root_RAM0;#ifdef CONFIG_BLOCK if (strncmp (name,"PARTUUID=" ,9 ) ==0 )return devt_from_partuuid (name +9 );
@@ -631,6 +623,12 @@ static dev_t __init parse_root_device(char *root_device_name)if (!strncmp (root_device_name,"mtd" ,3 ) || !strncmp (root_device_name,"ubi" ,3 ))return Root_Generic; +if (strcmp (root_device_name,"/dev/nfs" ) ==0 ) +return Root_NFS; +if (strcmp (root_device_name,"/dev/cifs" ) ==0 ) +return Root_CIFS; +if (strcmp (root_device_name,"/dev/ram" ) ==0 ) +return Root_RAM0;return name_to_dev_t (root_device_name); }
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 13/24 init: improve the name_to_dev_t interface
In reply to Christoph Hellwigname_to_dev_t has a very misleading name, that doesn't make clear it should only be used by the early init code, and also has a bad calling convention that doesn't allow returning different kinds of errors. Rename it to early_lookup_bdev to make the use case clear, and return an errno, where -EINVAL means the string could not be parsed, and -ENODEV means it the string was valid, but there was no device found for it.
Also stub out the whole call for !CONFIG_BLOCK as all the non-block root cases are always covered in the caller.
--- .../admin-guide/kernel-parameters.txt | 4 +- drivers/md/dm-table.c | 5 +- drivers/md/md-autodetect.c | 3 +- drivers/mtd/devices/block2mtd.c | 3 +- fs/pstore/blk.c | 4 +- include/linux/blkdev.h | 5 + include/linux/mount.h | 1 - init/do_mounts.c | 102 +++++++++--------- kernel/power/hibernate.c | 22 ++-- 9 files changed, 74 insertions(+), 75 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +2 -2
@@ -5453,8 +5453,8 @@ root= [KNL] Root filesystem Usually this a a block device specifier of some kind, - see the name_to_dev_t comment in init/do_mounts.c for - details. + see the early_lookup_bdev comment in init/do_mounts.c + for details. Alternatively this can be "ram" for the legacy initial ramdisk, "nfs" and "cifs" for root on a network file system, or "mtd" and "ubi" for mounting from raw flash.
drivers/md/dm-table.c +3 -2
@@ -330,8 +330,9 @@ dev_t dm_get_dev_t(const char *path) {dev_t dev; -if (lookup_bdev (path, &dev)) - dev =name_to_dev_t (path); +if (lookup_bdev (path, &dev) && +early_lookup_bdev (path, &dev)) +return 0 ;return dev; }EXPORT_SYMBOL_GPL (dm_get_dev_t);
drivers/md/md-autodetect.c +2 -1
@@ -147,7 +147,8 @@ static void __init md_setup_drive(struct md_setup_args *args)if (p) *p++ =0 ; - dev =name_to_dev_t (devname); +if (early_lookup_bdev (devname, &dev)) + dev =0 ;if (strncmp (devname,"/dev/" ,5 ) ==0 ) devname +=5 ;snprintf (comp_name,63 ,"/dev/%s" , devname);
drivers/mtd/devices/block2mtd.c +1 -2
@@ -254,8 +254,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,msleep (1000 );wait_for_device_probe (); - devt =name_to_dev_t (devname); -if (!devt) +if (early_lookup_bdev (devname, &devt))continue ; bdev =blkdev_get_by_dev (devt, mode, dev); }
fs/pstore/blk.c +2 -2
@@ -263,9 +263,9 @@ static __init const char *early_boot_devpath(const char *initial_devname)* same scheme to find the device that we use for mounting * the root file system. */ -dev_t dev =name_to_dev_t (initial_devname); +dev_t dev; -if (!dev) { +if (early_lookup_bdev (initial_devname, &dev)) {pr_err ("failed to resolve '%s'!\n" , initial_devname);return initial_devname; }
include/linux/blkdev.h +5 -0
@@ -1495,6 +1495,7 @@ int sync_blockdev_nowait(struct block_device *bdev);void sync_bdevs (bool wait);void bdev_statx_dioalign (struct inode *inode,struct kstat *stat);void printk_all_partitions (void ); +int early_lookup_bdev (const char *pathname,dev_t *dev);#else static inline void invalidate_bdev (struct block_device *bdev) {
@@ -1516,6 +1517,10 @@ static inline void bdev_statx_dioalign(struct inode *inode, struct kstat *stat)static inline void printk_all_partitions (void ) { } +static inline int early_lookup_bdev (const char *pathname,dev_t *dev) +{ +return -EINVAL ; +}#endif /* CONFIG_BLOCK */ int fsync_bdev (struct block_device *bdev);
include/linux/mount.h +0 -1
@@ -107,7 +107,6 @@ extern struct vfsmount *vfs_submount(const struct dentry *mountpoint,extern void mnt_set_expiry (struct vfsmount *mnt,struct list_head *expiry_list);extern void mark_mounts_for_expiry (struct list_head *mounts); -extern dev_t name_to_dev_t (const char *name);extern bool path_is_mountpoint (const struct path *path);extern bool our_mnt (struct vfsmount *mnt);
init/do_mounts.c +49 -53
213 lines not on this page · raw message
kernel/power/hibernate.c +10 -12
@@ -11,6 +11,7 @@#define pr_fmt (fmt) "PM: hibernation: " fmt +#include <linux/blkdev.h> #include <linux/export.h> #include <linux/suspend.h> #include <linux/reboot.h>
@@ -921,8 +922,7 @@ static int __init find_resume_device(void) }/* Check if the device is there */ - swsusp_resume_device =name_to_dev_t (resume_file); -if (swsusp_resume_device) +if (!early_lookup_bdev (resume_file, &swsusp_resume_device))return 0 ;/*
@@ -931,15 +931,12 @@ static int __init find_resume_device(void)*/ wait_for_device_probe ();if (resume_wait) { -while (!(swsusp_resume_device =name_to_dev_t (resume_file))) +while (early_lookup_bdev (resume_file, &swsusp_resume_device))msleep (10 );async_synchronize_full (); } - swsusp_resume_device =name_to_dev_t (resume_file); -if (!swsusp_resume_device) -return -ENODEV ; -return 0 ; +return early_lookup_bdev (resume_file, &swsusp_resume_device); }static int software_resume (void )
@@ -1169,7 +1166,8 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,unsigned int sleep_flags;int len = n;char *name; -dev_t res; +dev_t dev; +int error;if (!hibernation_available ())return 0 ;
@@ -1180,13 +1178,13 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,if (!name)return -ENOMEM ; - res =name_to_dev_t (name); + error =early_lookup_bdev (name, &dev);kfree (name); -if (!res) -return -EINVAL ; +if (error) +return error; sleep_flags =lock_system_sleep (); - swsusp_resume_device = res; + swsusp_resume_device = dev;unlock_system_sleep (sleep_flags); pm_pr_dbg("Configured hibernation resume from disk to %u\n",
Signature · 1 line
2.39.2
PATCH 14/24 init: clear root_wait on all invalid root= strings
In reply to Christoph HellwigInstead of only clearing root_wait in devt_from_partuuid when the UUID format was invalid, do that in parse_root_device for all strings that failed to parse.
--- init/do_mounts.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
init/do_mounts.c +11 -7
@@ -112,14 +112,14 @@ static int devt_from_partuuid(const char *uuid_str, dev_t *devt)/* Explicitly fail on poor PARTUUID syntax. */ if (sscanf (slash +1 ,"PARTNROFF=%d%c" , &offset, &c) !=1 ) - goto clear_root_wait; + goto out_invalid; cmp.len = slash - uuid_str; }else { cmp.len =strlen (uuid_str); }if (!cmp.len) - goto clear_root_wait; + goto out_invalid; dev =class_find_device (&block_class,NULL , &cmp, &match_dev_by_uuid);if (!dev)
@@ -139,12 +139,9 @@ static int devt_from_partuuid(const char *uuid_str, dev_t *devt)put_device (dev);return 0 ; -clear_root_wait: +out_invalid:pr_err ("VFS: PARTUUID= is invalid.\n" "Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n" ); -if (root_wait) -pr_err ("Disabling rootwait; root= is invalid.\n" ); - root_wait =0 ;return -EINVAL ; }
@@ -611,6 +608,7 @@ static void __init wait_for_root(char *root_device_name)static dev_t __init parse_root_device (char *root_device_name) { +int error;dev_t dev; if (!strncmp(root_device_name, "mtd", 3) ||
@@ -623,8 +621,14 @@ static dev_t __init parse_root_device(char *root_device_name)if (strcmp (root_device_name,"/dev/ram" ) ==0 )return Root_RAM0; -if (early_lookup_bdev (root_device_name, &dev)) + error =early_lookup_bdev (root_device_name, &dev); +if (error) { +if (error == -EINVAL && root_wait) { +pr_err ("Disabling rootwait; root= is invalid.\n" ); + root_wait =0 ; + }return 0 ; + }return dev; }
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 15/24 block: move the code to do early boot lookup of block devices to block/
In reply to Christoph HellwigCreate a new block/early-lookup.c to keep the early block device lookup code instead of having this code sit with the early mount code.
--- .../admin-guide/kernel-parameters.txt | 4 +- block/Makefile | 2 +- block/early-lookup.c | 224 ++++++++++++++++++ init/do_mounts.c | 219 ----------------- 4 files changed, 227 insertions(+), 222 deletions(-) create mode 100644 block/early-lookup.c
Documentation/admin-guide/kernel-parameters.txt +2 -2
@@ -5453,8 +5453,8 @@ root= [KNL] Root filesystem Usually this a a block device specifier of some kind, - see the early_lookup_bdev comment in init/do_mounts.c - for details. + see the early_lookup_bdev comment in + block/early-lookup.c for details. Alternatively this can be "ram" for the legacy initial ramdisk, "nfs" and "cifs" for root on a network file system, or "mtd" and "ubi" for mounting from raw flash.
block/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-y := bdev.o fops.o bio.o elevator.o blk-core.o blk-sysfs.o \ blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \ blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \ genhd.o ioprio.o badblocks.o partitions/ blk-rq-qos.o \ - disk-events.o blk-ia-ranges.o + disk-events.o blk-ia-ranges.o early-lookup.o obj-$(CONFIG_BOUNCE) += bounce.o obj-$(CONFIG_BLK_DEV_BSG_COMMON) += bsg.o
block/early-lookup.c new file +224 -0
224 lines not on this page · raw message
init/do_mounts.c +0 -219
225 lines not on this page · raw message
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 16/24 block: move more code to early-lookup.c
In reply to Christoph Hellwigblk_lookup_devt is only used by code in early-lookup.c, so move it there.
printk_all_partitions and it's helper bdevt_str are only used by the early init code in init/do_mounts.c, so they should go there as well.
--- block/early-lookup.c | 92 ++++++++++++++++++++++++++++++++++++++++++ block/genhd.c | 92 ------------------------------------------ include/linux/blkdev.h | 1 - 3 files changed, 92 insertions(+), 93 deletions(-)
block/early-lookup.c +92 -0
@@ -120,6 +120,35 @@ static int devt_from_partlabel(const char *label, dev_t *devt)return 0 ; } +static dev_t blk_lookup_devt (const char *name,int partno) +{ +dev_t devt =MKDEV (0 ,0 ); +struct class_dev_iter iter; +struct device *dev; + +class_dev_iter_init (&iter, &block_class,NULL , &disk_type); +while ((dev =class_dev_iter_next (&iter))) { +struct gendisk *disk =dev_to_disk (dev); + +if (strcmp (dev_name (dev), name)) +continue ; + +if (partno < disk->minors) { +/* We need to return the right devno, even +* if the partition doesn't exist yet. +*/ + devt =MKDEV (MAJOR (dev->devt), +MINOR (dev->devt) + partno); + }else { + devt =part_devt (disk, partno); +if (devt) +break ; + } + } +class_dev_iter_exit (&iter); +return devt; +} +static int devt_from_devname (const char *name,dev_t *devt) {int part;
@@ -222,3 +251,66 @@ int early_lookup_bdev(const char *name, dev_t *devt)return devt_from_devnum (name, devt); }EXPORT_SYMBOL_GPL (early_lookup_bdev); + +static char __init *bdevt_str (dev_t devt,char *buf) +{ +if (MAJOR (devt) <=0xff &&MINOR (devt) <=0xff ) { +char tbuf[BDEVT_SIZE ]; +snprintf (tbuf,BDEVT_SIZE ,"%02x%02x" ,MAJOR (devt),MINOR (devt)); +snprintf (buf,BDEVT_SIZE ,"%-9s" , tbuf); + }else +snprintf (buf,BDEVT_SIZE ,"%03x:%05x" ,MAJOR (devt),MINOR (devt)); + +return buf; +} + +/* +* print a full list of all partitions - intended for places where the root +* filesystem can't be mounted and thus to give the victim some idea of what +* went wrong +*/ +void __init printk_all_partitions (void ) +{ +struct class_dev_iter iter; +struct device *dev; + +class_dev_iter_init (&iter, &block_class,NULL , &disk_type); +while ((dev =class_dev_iter_next (&iter))) { +struct gendisk *disk =dev_to_disk (dev); +struct block_device *part; +char devt_buf[BDEVT_SIZE ]; +unsigned long idx; + +/* +* Don't show empty devices or things that have been +* suppressed +*/ +if (get_capacity (disk) ==0 || (disk->flags &GENHD_FL_HIDDEN )) +continue ; + +/* +* Note, unlike /proc/partitions, I am showing the numbers in +* hex - the same format as the root= option takes. +*/ +rcu_read_lock (); +xa_for_each (&disk->part_tbl, idx, part) { +if (!bdev_nr_sectors (part)) +continue ; +printk ("%s%s %10llu %pg %s" , +bdev_is_partition (part) ?" " :"" , +bdevt_str (part->bd_dev, devt_buf), +bdev_nr_sectors (part) >>1 , part, + part->bd_meta_info ? + part->bd_meta_info->uuid :"" ); +if (bdev_is_partition (part)) +printk ("\n" ); +else if (dev->parent && dev->parent->driver) +printk (" driver: %s\n" , + dev->parent->driver->name); +else +printk (" (driver?)\n" ); + } +rcu_read_unlock (); + } +class_dev_iter_exit (&iter); +}
block/genhd.c +0 -92
110 lines not on this page · raw message
include/linux/blkdev.h +0 -1
@@ -838,7 +838,6 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev,dev_t part_devt (struct gendisk *disk,u8 partno);void inc_diskseq (struct gendisk *disk); -dev_t blk_lookup_devt (const char *name,int partno);void blk_request_module (dev_t devt);extern int blk_register_queue (struct gendisk *disk);
Signature · 1 line
2.39.2
PATCH 17/24 dm-snap: simplify the origin_dev == cow_dev check in snapshot_ctr
In reply to Christoph HellwigUse the block_device acquired in dm_get_device for the check instead of doing an extra lookup.
--- drivers/md/dm-snap.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/md/dm-snap.c +5 -9
@@ -1241,7 +1241,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)int i;int r = -EINVAL ;char *origin_path, *cow_path; -dev_t origin_dev, cow_dev;unsigned int args_used, num_flush_bios =1 ;fmode_t origin_mode =FMODE_READ ;
@@ -1279,24 +1278,21 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->error ="Cannot get origin device" ; goto bad_origin; } - origin_dev = s->origin->bdev->bd_dev; cow_path = argv[0 ]; argv++; argc--; - cow_dev =dm_get_dev_t (cow_path); -if (cow_dev && cow_dev == origin_dev) { - ti->error ="COW device cannot be the same as origin device" ; - r = -EINVAL ; - goto bad_cow; - } - r =dm_get_device (ti, cow_path,dm_table_get_mode (ti->table), &s->cow);if (r) { ti->error ="Cannot get COW device" ; goto bad_cow; } +if (s->cow->bdev && s->cow->bdev == s->origin->bdev) { + ti->error ="COW device cannot be the same as origin device" ; + r = -EINVAL ; + goto bad_store; + } r =dm_exception_store_create (ti, argc, argv, s, &args_used, &s->store);if (r) {
Signature · 1 line
2.39.2
PATCH 18/24 dm: open code dm_get_dev_t in dm_init_init
In reply to Christoph Hellwigdm_init_init is called from early boot code, and thus lookup_bdev will never succeed. Just open code that call to early_lookup_bdev instead.
--- drivers/md/dm-init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm-init.c +3 -1
@@ -293,8 +293,10 @@ static int __init dm_init_init(void)for (i =0 ; i <ARRAY_SIZE (waitfor); i++) {if (waitfor[i]) { +dev_t dev; +DMINFO ("waiting for device %s ..." , waitfor[i]); -while (!dm_get_dev_t (waitfor[i])) +while (early_lookup_bdev (waitfor[i], &dev))fsleep (5000 ); } }
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 19/24 dm: remove dm_get_dev_t
In reply to Christoph HellwigOpen code dm_get_dev_t in the only remaining caller, and propagate the exact error code from lookup_bdev and early_lookup_bdev.
--- drivers/md/dm-table.c | 22 +++++----------------- include/linux/device-mapper.h | 2 -- 2 files changed, 5 insertions(+), 19 deletions(-)
drivers/md/dm-table.c +5 -17
@@ -323,20 +323,6 @@ static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode,return 0 ; } -/* -* Convert the path to a device -*/ -dev_t dm_get_dev_t (const char *path) -{ -dev_t dev; - -if (lookup_bdev (path, &dev) && -early_lookup_bdev (path, &dev)) -return 0 ; -return dev; -} -EXPORT_SYMBOL_GPL (dm_get_dev_t); -/* * Add a device to the list, or just increment the usage count if * it's already present.
@@ -359,9 +345,11 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,if (MAJOR (dev) != major ||MINOR (dev) != minor)return -EOVERFLOW ; }else { - dev =dm_get_dev_t (path); -if (!dev) -return -ENODEV ; + r =lookup_bdev (path, &dev); +if (r) + r =early_lookup_bdev (path, &dev); +if (r) +return r; }if (dev ==disk_devt (t->md->disk))return -EINVAL ;
include/linux/device-mapper.h +0 -2
@@ -170,8 +170,6 @@ struct dm_dev {char name[16 ]; }; -dev_t dm_get_dev_t (const char *path); -/* * Constructors should call these functions to ensure destination devices * are opened/closed correctly.
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 20/24 dm: only call early_lookup_bdev from early boot context
In reply to Christoph Hellwigearly_lookup_bdev is supposed to only be called from the early boot code, but dm_get_device calls it as a general fallback when lookup_bdev fails, which is problematic because early_lookup_bdev bypasses all normal path based permission checking, and might cause problems with certain container environments renaming devices.
Switch to only call early_lookup_bdev when dm is built-in and the system state in not running yet. This means it is still available when tables are constructed by dm-init.c from the kernel command line, but not otherwise.
Note that this strictly speaking changes the kernel ABI as the PARTUUID= and PARTLABEL= style syntax is now not available during a running systems. They never were intended for that, but this breaks things we'll have to figure out a way to make them available again. But if avoidable in any way I'd rather avoid that.
--- drivers/md/dm-table.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/md/dm-table.c +7 -2
@@ -326,8 +326,11 @@ static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode,/* * Add a device to the list, or just increment the usage count if * it's already present. +* +* Note: the __ref annotation is because this function can call the __init +* marked early_lookup_bdev when called during early boot code from dm-init.c. */ -int dm_get_device (struct dm_target *ti,const char *path,fmode_t mode, +int __ref dm_get_device (struct dm_target *ti,const char *path,fmode_t mode,struct dm_dev **result) {int r;
@@ -346,8 +349,10 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,return -EOVERFLOW ; }else { r =lookup_bdev (path, &dev); -if (r) +#ifndef MODULE +if (r && system_state <SYSTEM_RUNNING ) r =early_lookup_bdev (path, &dev); +#endif if (r)return r; }
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 21/24 PM: hibernate: don't use early_lookup_bdev in resume_store
In reply to Christoph Hellwigresume_store is a sysfs attribute written during normal kernel runtime, and it should not use the early_lookup_bdev API that bypasses all normal path based permission checking, and might cause problems with certain container environments renaming devices.
Switch to lookup_bdev, which does a normal path lookup instead, and fall back to trying to parse a numeric dev_t just like early_lookup_bdev did.
Note that this strictly speaking changes the kernel ABI as the PARTUUID= and PARTLABEL= style syntax is now not available during a running systems. They never were intended for that, but this breaks things we'll have to figure out a way to make them available again. But if avoidable in any way I'd rather avoid that.
--- kernel/power/hibernate.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
kernel/power/hibernate.c +17 -1
@@ -1178,7 +1178,23 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,if (!name)return -ENOMEM ; - error =early_lookup_bdev (name, &dev); + error =lookup_bdev (name, &dev); +if (error) { +unsigned maj, min, offset; +char *p, dummy; + +if (sscanf (name,"%u:%u%c" , &maj, &min, &dummy) ==2 || +sscanf (name,"%u:%u:%u:%c" , &maj, &min, &offset, + &dummy) ==3 ) { + dev =MKDEV (maj, min); +if (maj !=MAJOR (dev) || min !=MINOR (dev)) + error = -EINVAL ; + }else { + dev =new_decode_dev (simple_strtoul (name, &p,16 )); +if (*p) + error = -EINVAL ; + } + }kfree (name);if (error)return error;
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 22/24 mtd: block2mtd: factor the early block device open logic into a helper
In reply to Christoph HellwigSimplify add_device a bit by splitting out the cumbersome early boot logic into a separate helper.
--- drivers/mtd/devices/block2mtd.c | 53 +++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 23 deletions(-)
drivers/mtd/devices/block2mtd.c +30 -23
@@ -215,34 +215,18 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)kfree (dev); } - -static struct block2mtd_dev *add_device (char *devname,int erase_size, -char *label,int timeout) +static struct block_device *mdtblock_early_get_bdev (const char *devname, +fmode_t mode,int timeout,struct block2mtd_dev *dev) { +struct block_device *bdev =ERR_PTR (-ENODEV );#ifndef MODULE int i; -#endif -const fmode_t mode =FMODE_READ |FMODE_WRITE |FMODE_EXCL ; -struct block_device *bdev; -struct block2mtd_dev *dev; -char *name; - -if (!devname) -return NULL ; - - dev =kzalloc (sizeof (struct block2mtd_dev ),GFP_KERNEL ); -if (!dev) -return NULL ; -/* Get a handle on the device */ - bdev =blkdev_get_by_path (devname, mode, dev); - -#ifndef MODULE /* * We might not have the root device mounted at this point. * Try to resolve the device name by other means. */ -for (i =0 ;IS_ERR (bdev) && i <= timeout; i++) { +for (i =0 ; i <= timeout; i++) {dev_t devt;if (i)
@@ -254,12 +238,35 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size,msleep (1000 );wait_for_device_probe (); -if (early_lookup_bdev (devname, &devt)) -continue ; - bdev = blkdev_get_by_dev(devt, mode, dev); +if (!early_lookup_bdev (devname, &devt)) { + bdev =blkdev_get_by_dev (devt, mode, dev); +if (!IS_ERR (bdev)) +break ; + } }#endif +return bdev; +} + +static struct block2mtd_dev *add_device (char *devname,int erase_size, +char *label,int timeout) +{ +const fmode_t mode =FMODE_READ |FMODE_WRITE |FMODE_EXCL ; +struct block_device *bdev; +struct block2mtd_dev *dev; +char *name; +if (!devname) +return NULL ; + + dev =kzalloc (sizeof (struct block2mtd_dev ),GFP_KERNEL ); +if (!dev) +return NULL ; + +/* Get a handle on the device */ + bdev =blkdev_get_by_path (devname, mode, dev); +if (IS_ERR (bdev)) + bdev =mdtblock_early_get_bdev (devname, mode, timeout, dev);if (IS_ERR (bdev)) {pr_err ("error: cannot open device %s\n" , devname); goto err_free_block2mtd;
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH 23/24 mtd: block2mtd: don't call early_lookup_bdev after the system is running
In reply to Christoph Hellwigearly_lookup_bdev is supposed to only be called from the early boot code, but mdtblock_early_get_bdev is called as a general fallback when lookup_bdev fails, which is problematic because early_lookup_bdev bypasses all normal path based permission checking, and might cause problems with certain container environments renaming devices.
Switch to only call early_lookup_bdev when block2mtd is built-in and the system state in not running yet.
Note that this strictly speaking changes the kernel ABI as the PARTUUID= and PARTLABEL= style syntax is now not available during a running systems. They never were intended for that, but this breaks things we'll have to figure out a way to make them available again. But if avoidable in any way I'd rather avoid that.
--- drivers/mtd/devices/block2mtd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/mtd/devices/block2mtd.c +11 -1
@@ -215,13 +215,23 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)kfree (dev); } -static struct block_device *mdtblock_early_get_bdev (const char *devname, +/* +* This function is marked __ref because it calls the __init marked +* early_lookup_bdev when called from the early boot code. +*/ +static struct block_device __ref *mdtblock_early_get_bdev (const char *devname,fmode_t mode,int timeout,struct block2mtd_dev *dev) {struct block_device *bdev =ERR_PTR (-ENODEV );#ifndef MODULE int i; +/* +* We can't use early_lookup_bdev from a running system. +*/ +if (system_state >=SYSTEM_RUNNING ) +return bdev; +/* * We might not have the root device mounted at this point. * Try to resolve the device name by other means.
Signature · 1 line
2.39.2
PATCH 24/24 block: mark early_lookup_bdev as __init
In reply to Christoph Hellwigearly_lookup_bdev is now only used during the early boot code as it should, so mark it __init to not waste run time memory on it.
--- block/early-lookup.c | 19 +++++++++---------- include/linux/blkdev.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-)
block/early-lookup.c +9 -10
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0-only /* * Code for looking up block devices in the early boot code before mounting the -* root file system. Unfortunately currently also abused in a few other places. +* root file system. */ #include <linux/blkdev.h> #include <linux/ctype.h>
@@ -18,7 +18,7 @@ struct uuidcmp {* * Returns 1 if the device matches, and 0 otherwise. */ -static int match_dev_by_uuid (struct device *dev,const void *data) +static int __init match_dev_by_uuid (struct device *dev,const void *data) {struct block_device *bdev =dev_to_bdev (dev);const struct uuidcmp *cmp = data;
@@ -42,7 +42,7 @@ static int match_dev_by_uuid(struct device *dev, const void *data)* * Returns the matching dev_t on success or 0 on failure. */ -static int devt_from_partuuid (const char *uuid_str,dev_t *devt) +static int __init devt_from_partuuid (const char *uuid_str,dev_t *devt) {struct uuidcmp cmp;struct device *dev =NULL ;
@@ -98,7 +98,7 @@ static int devt_from_partuuid(const char *uuid_str, dev_t *devt)* * Returns 1 if the device matches, and 0 otherwise. */ -static int match_dev_by_label (struct device *dev,const void *data) +static int __init match_dev_by_label (struct device *dev,const void *data) {struct block_device *bdev =dev_to_bdev (dev);const char *label = data;
@@ -108,7 +108,7 @@ static int match_dev_by_label(struct device *dev, const void *data)return 1 ; } -static int devt_from_partlabel (const char *label,dev_t *devt) +static int __init devt_from_partlabel (const char *label,dev_t *devt) {struct device *dev;
@@ -120,7 +120,7 @@ static int devt_from_partlabel(const char *label, dev_t *devt)return 0 ; } -static dev_t blk_lookup_devt (const char *name,int partno) +static dev_t __init blk_lookup_devt (const char *name,int partno) {dev_t devt =MKDEV (0 ,0 );struct class_dev_iter iter;
@@ -149,7 +149,7 @@ static dev_t blk_lookup_devt(const char *name, int partno)return devt; } -static int devt_from_devname (const char *name,dev_t *devt) +static int __init devt_from_devname (const char *name,dev_t *devt) {int part;char s[32 ];
@@ -193,7 +193,7 @@ static int devt_from_devname(const char *name, dev_t *devt)return -EINVAL ; } -static int devt_from_devnum (const char *name,dev_t *devt) +static int __init devt_from_devnum (const char *name,dev_t *devt) {unsigned maj, min, offset;char *p, dummy;
@@ -240,7 +240,7 @@ static int devt_from_devnum(const char *name, dev_t *devt)* name contains slashes, the device name has them replaced with * bangs. */ -int early_lookup_bdev (const char *name,dev_t *devt) +int __init early_lookup_bdev (const char *name,dev_t *devt) {if (strncmp (name,"PARTUUID=" ,9 ) ==0 )return devt_from_partuuid (name +9 , devt);
@@ -250,7 +250,6 @@ int early_lookup_bdev(const char *name, dev_t *devt)return devt_from_devname (name +5 , devt);return devt_from_devnum (name, devt); } -EXPORT_SYMBOL_GPL (early_lookup_bdev);static char __init *bdevt_str (dev_t devt,char *buf) {
include/linux/blkdev.h +1 -1
@@ -1494,7 +1494,7 @@ int sync_blockdev_nowait(struct block_device *bdev);void sync_bdevs (bool wait);void bdev_statx_dioalign (struct inode *inode,struct kstat *stat);void printk_all_partitions (void ); -int early_lookup_bdev (const char *pathname,dev_t *dev); +int __init early_lookup_bdev (const char *pathname,dev_t *dev);#else static inline void invalidate_bdev (struct block_device *bdev) {
Signature · 6 lines
2.39.2 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/