[PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible

Lillian Berry posted 1 patch 7 months ago
init/main.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible
Posted by Lillian Berry 7 months ago
Avoid silently ignoring the initramfs when the file specified in rdinit
is not usable. This prints an error that clearly explains the issue
(file was not found, vs initramfs was not found).

Signed-off-by: Lillian Berry <lillian@star-ark.net>
---
 init/main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index 225a58279acd..e47984871775 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1592,7 +1592,11 @@ static noinline void __init kernel_init_freeable(void)
 	 * check if there is an early userspace init.  If yes, let it do all
 	 * the work
 	 */
-	if (init_eaccess(ramdisk_execute_command) != 0) {
+	int ramdisk_command_access;
+	ramdisk_command_access = init_eaccess(ramdisk_execute_command);
+	if (ramdisk_command_access != 0) {
+		pr_warn("check access for rdinit=%s failed: %i, ignoring\n",
+			ramdisk_execute_command, ramdisk_command_access);
 		ramdisk_execute_command = NULL;
 		prepare_namespace();
 	}
-- 
2.48.1
Re: [PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible
Posted by Ahmad Fatoum 4 months ago
Hello Lillian,

On 7/7/25 11:14 AM, Lillian Berry wrote:
> Avoid silently ignoring the initramfs when the file specified in rdinit
> is not usable. This prints an error that clearly explains the issue
> (file was not found, vs initramfs was not found).

I have a system that works just fine without an initramfs, but now the
kernel warns me about it:

[    2.805602] check access for rdinit=/init failed: -2, ignoring

I suppose that's unintended and the code here should actually check that
there is an initrd at all before checking for the rdinit?

Thanks,
Ahmad

> 
> Signed-off-by: Lillian Berry <lillian@star-ark.net>
> ---
>  init/main.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/init/main.c b/init/main.c
> index 225a58279acd..e47984871775 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1592,7 +1592,11 @@ static noinline void __init kernel_init_freeable(void)
>  	 * check if there is an early userspace init.  If yes, let it do all
>  	 * the work
>  	 */
> -	if (init_eaccess(ramdisk_execute_command) != 0) {
> +	int ramdisk_command_access;
> +	ramdisk_command_access = init_eaccess(ramdisk_execute_command);
> +	if (ramdisk_command_access != 0) {
> +		pr_warn("check access for rdinit=%s failed: %i, ignoring\n",
> +			ramdisk_execute_command, ramdisk_command_access);
>  		ramdisk_execute_command = NULL;
>  		prepare_namespace();
>  	}

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
Re: [PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible
Posted by Lillian Berry 4 months ago
Hi,

On Tue, Oct 7, 2025, at 10:57 AM, Ahmad Fatoum wrote:
> On 7/7/25 11:14 AM, Lillian Berry wrote:
>> Avoid silently ignoring the initramfs when the file specified in rdinit
>> is not usable. This prints an error that clearly explains the issue
>> (file was not found, vs initramfs was not found).
>
> I have a system that works just fine without an initramfs, but now the
> kernel warns me about it:
>
> [    2.805602] check access for rdinit=/init failed: -2, ignoring
>
> I suppose that's unintended and the code here should actually check that
> there is an initrd at all before checking for the rdinit?

This isn't directly unintended. This message informs the user their
specified rdinit= binary was not able to run, regardless of the reason.

It would be good to check presence of initrd and print a more specific
message such as "rdinit=/init specified but no initrd present".

Kindly,
Lillian
Re: [PATCH v3] init/main.c: add warning when file specified in rdinit is inaccessible
Posted by Ahmad Fatoum 4 months ago
Hello Lillian,

On 08.10.25 05:30, Lillian Berry wrote:
> Hi,
> 
> On Tue, Oct 7, 2025, at 10:57 AM, Ahmad Fatoum wrote:
>> On 7/7/25 11:14 AM, Lillian Berry wrote:
>>> Avoid silently ignoring the initramfs when the file specified in rdinit
>>> is not usable. This prints an error that clearly explains the issue
>>> (file was not found, vs initramfs was not found).
>>
>> I have a system that works just fine without an initramfs, but now the
>> kernel warns me about it:
>>
>> [    2.805602] check access for rdinit=/init failed: -2, ignoring
>>
>> I suppose that's unintended and the code here should actually check that
>> there is an initrd at all before checking for the rdinit?
> 
> This isn't directly unintended. This message informs the user their
> specified rdinit= binary was not able to run, regardless of the reason.
> 
> It would be good to check presence of initrd and print a more specific
> message such as "rdinit=/init specified but no initrd present".

I didn't explicitly set rdinit=/init on my kernel command line though:

  loglevel=7 root=/dev/mmcblk1p1 rootwait=10 rootfstype=ext4

So ramdisk_execute_command had the default value it was initialized with.

Maybe rdinit_setup should set a flag or something to discern the default
case?

Tanks,
Ahmad



> 
> Kindly,
> Lillian
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
[PATCH] init/main.c: check if rdinit was explicitly set before printing warning
Posted by Lillian Berry 4 weeks ago
The rdinit parameter is set by default, and attempted during boot even
if not specified in the command line. Only print the warning about
rdinit being inaccessible if the rdinit value was found in command line;
it's just noise otherwise.

Signed-off-by: Lillian Berry <lillian@star-ark.net>
---
 init/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/init/main.c b/init/main.c
index b84818ad9685..522fdc9b1a25 100644
--- a/init/main.c
+++ b/init/main.c
@@ -162,6 +162,7 @@ static size_t initargs_offs;
 
 static char *execute_command;
 static char *ramdisk_execute_command = "/init";
+static bool ramdisk_execute_command_set;
 
 /*
  * Used to generate warnings if static_key manipulation functions are used
@@ -623,6 +624,7 @@ static int __init rdinit_setup(char *str)
 	unsigned int i;
 
 	ramdisk_execute_command = str;
+	ramdisk_execute_command_set = true;
 	/* See "auto" comment in init_setup */
 	for (i = 1; i < MAX_INIT_ARGS; i++)
 		argv_init[i] = NULL;
@@ -1699,8 +1701,9 @@ static noinline void __init kernel_init_freeable(void)
 	int ramdisk_command_access;
 	ramdisk_command_access = init_eaccess(ramdisk_execute_command);
 	if (ramdisk_command_access != 0) {
-		pr_warn("check access for rdinit=%s failed: %i, ignoring\n",
-			ramdisk_execute_command, ramdisk_command_access);
+		if (ramdisk_execute_command_set)
+			pr_warn("check access for rdinit=%s failed: %i, ignoring\n",
+				ramdisk_execute_command, ramdisk_command_access);
 		ramdisk_execute_command = NULL;
 		prepare_namespace();
 	}
-- 
2.47.3
Re: [PATCH] init/main.c: check if rdinit was explicitly set before printing warning
Posted by Andrew Morton 3 weeks, 5 days ago
On Sun, 11 Jan 2026 07:56:35 -0500 Lillian Berry <lillian@star-ark.net> wrote:

> The rdinit parameter is set by default, and attempted during boot even
> if not specified in the command line. Only print the warning about
> rdinit being inaccessible if the rdinit value was found in command line;
> it's just noise otherwise.
> 
> ...
>
> --- a/init/main.c
> +++ b/init/main.c
> @@ -162,6 +162,7 @@ static size_t initargs_offs;
>  
>  static char *execute_command;
>  static char *ramdisk_execute_command = "/init";
> +static bool ramdisk_execute_command_set;

We can use __initdata. yes?

--- a/init/main.c~init-mainc-check-if-rdinit-was-explicitly-set-before-printing-warning-fix
+++ a/init/main.c
@@ -162,7 +162,7 @@ static size_t initargs_offs;
 
 static char *execute_command;
 static char *ramdisk_execute_command = "/init";
-static bool ramdisk_execute_command_set;
+static bool __initdata ramdisk_execute_command_set;
 
 /*
  * Used to generate warnings if static_key manipulation functions are used
_

I suspect there are other things around here which could be moved into
__initdata.