Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v2] selftests/efivarfs: skip write tests if efivarfs is mounted read-only
@ 2026-08-20  3:01 Hui Wang
  2026-09-03  9:34 ` Ard Biesheuvel
  0 siblings, 1 reply; 5+ messages in thread
From: Hui Wang @ 2026-08-20  3:01 UTC (permalink / raw)
  To: shuah, skhan, ardb, linux-kselftest; +Cc: hui.wang

efivarfs is mounted read-only when the firmware does not provide a
working runtime SetVariable() service. This happens, for example, on
systems where the EFI runtime is provided by U-Boot's efi_loader (a
common case on RISC-V under QEMU booting via OpenSBI -> U-Boot -> GRUB),
or when runtime services are disabled (efi=noruntime, lockdown, etc).

In that situation every test that creates, modifies or deletes an EFI
variable is bound to fail, producing spurious test failures that do not
reflect a real kernel bug.

Detect the mount mode in check_prereqs() and store it in the global
efivarfs_mode ("ro" or "rw"). Group all tests that require a writable
efivarfs into a single "if [ "$efivarfs_mode" = "rw" ]" block, so they
are only run when efivarfs is writable; otherwise print a single message
explaining that they were skipped.

test_create_empty and test_invalid_filenames are left to run
unconditionally, since their expectation still holds on a read-only
mount; test_create_empty's stderr is silenced to avoid noise from the
read-only redirection failure.

Assisted-by: Copilot:claude-opus-4-8
Signed-off-by: Hui Wang <hui.wang@canonical.com>
---
In the v2:
 Move the rw tests in an if scope as suggested by Ard.

 tools/testing/selftests/efivarfs/efivarfs.sh | 41 ++++++++++++++------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh b/tools/testing/selftests/efivarfs/efivarfs.sh
index c62544b966ae..ec3036902b8a 100755
--- a/tools/testing/selftests/efivarfs/efivarfs.sh
+++ b/tools/testing/selftests/efivarfs/efivarfs.sh
@@ -26,6 +26,14 @@ check_prereqs()
 		echo $msg efivarfs is not mounted on $efivarfs_mount >&2
 		exit $ksft_skip
 	fi
+
+	# Determine whether efivarfs is mounted read-only or read-write
+	# and store the result ("ro" or "rw") in the global efivarfs_mode.
+	if grep -q "^\S\+ $efivarfs_mount efivarfs ro[, ]" /proc/mounts; then
+		efivarfs_mode=ro
+	else
+		efivarfs_mode=rw
+	fi
 }
 
 run_test()
@@ -74,7 +82,7 @@ test_create_empty()
 {
 	local file=$efivarfs_mount/$FUNCNAME-$test_guid
 
-	: > $file
+	: 2>/dev/null > $file
 
 	if [ -e $file ]; then
 		echo "$file can be created without writing" >&2
@@ -361,18 +369,27 @@ check_prereqs
 
 rc=0
 
-run_test test_create
+# Tests that are also valid on a read-only efivarfs run unconditionally.
 run_test test_create_empty
-run_test test_create_read
-run_test test_delete
-run_test test_zero_size_delete
-run_test test_open_unlink
-run_test test_valid_filenames
 run_test test_invalid_filenames
-run_test test_no_set_size
-setup_test_multiple
-run_test test_multiple_zero_size
-run_test test_multiple_create
-run_test test_multiple_delete_on_write
+
+# These tests need to create, modify or delete EFI variables, so they
+# require a writable efivarfs. Skip them when it is mounted read-only.
+if [ "$efivarfs_mode" = "rw" ]; then
+	run_test test_create
+	run_test test_create_read
+	run_test test_delete
+	run_test test_zero_size_delete
+	run_test test_open_unlink
+	run_test test_valid_filenames
+	run_test test_no_set_size
+	setup_test_multiple
+	run_test test_multiple_zero_size
+	run_test test_multiple_create
+	run_test test_multiple_delete_on_write
+else
+	echo "efivarfs is mounted read-only on $efivarfs_mount;" \
+	     "tests that require write access were skipped" >&2
+fi
 
 exit $rc
-- 
2.43.0


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

* Re: [PATCH v2] selftests/efivarfs: skip write tests if efivarfs is mounted read-only
  2026-08-20  3:01 [PATCH v2] selftests/efivarfs: skip write tests if efivarfs is mounted read-only Hui Wang
@ 2026-09-03  9:34 ` Ard Biesheuvel
  2026-09-04  2:06   ` Hui Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2026-09-03  9:34 UTC (permalink / raw)
  To: Hui Wang, shuah, Shuah Khan, linux-kselftest



On Thu, 20 Aug 2026, at 05:01, Hui Wang wrote:
> efivarfs is mounted read-only when the firmware does not provide a
> working runtime SetVariable() service. This happens, for example, on
> systems where the EFI runtime is provided by U-Boot's efi_loader (a
> common case on RISC-V under QEMU booting via OpenSBI -> U-Boot -> GRUB),
> or when runtime services are disabled (efi=noruntime, lockdown, etc).
>
> In that situation every test that creates, modifies or deletes an EFI
> variable is bound to fail, producing spurious test failures that do not
> reflect a real kernel bug.
>
> Detect the mount mode in check_prereqs() and store it in the global
> efivarfs_mode ("ro" or "rw"). Group all tests that require a writable
> efivarfs into a single "if [ "$efivarfs_mode" = "rw" ]" block, so they
> are only run when efivarfs is writable; otherwise print a single message
> explaining that they were skipped.
>
> test_create_empty and test_invalid_filenames are left to run
> unconditionally, since their expectation still holds on a read-only
> mount; test_create_empty's stderr is silenced to avoid noise from the
> read-only redirection failure.
>
> Assisted-by: Copilot:claude-opus-4-8
> Signed-off-by: Hui Wang <hui.wang@canonical.com>
> ---
> In the v2:
>  Move the rw tests in an if scope as suggested by Ard.
>
>  tools/testing/selftests/efivarfs/efivarfs.sh | 41 ++++++++++++++------
>  1 file changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh 
> b/tools/testing/selftests/efivarfs/efivarfs.sh
> index c62544b966ae..ec3036902b8a 100755
> --- a/tools/testing/selftests/efivarfs/efivarfs.sh
> +++ b/tools/testing/selftests/efivarfs/efivarfs.sh
> @@ -26,6 +26,14 @@ check_prereqs()
>  		echo $msg efivarfs is not mounted on $efivarfs_mount >&2
>  		exit $ksft_skip
>  	fi
> +
> +	# Determine whether efivarfs is mounted read-only or read-write
> +	# and store the result ("ro" or "rw") in the global efivarfs_mode.
> +	if grep -q "^\S\+ $efivarfs_mount efivarfs ro[, ]" /proc/mounts; then
> +		efivarfs_mode=ro
> +	else
> +		efivarfs_mode=rw
> +	fi
>  }
> 
>  run_test()
> @@ -74,7 +82,7 @@ test_create_empty()
>  {
>  	local file=$efivarfs_mount/$FUNCNAME-$test_guid
> 
> -	: > $file
> +	: 2>/dev/null > $file
> 

Why is this needed?

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

* Re: [PATCH v2] selftests/efivarfs: skip write tests if efivarfs is mounted read-only
  2026-09-03  9:34 ` Ard Biesheuvel
@ 2026-09-04  2:06   ` Hui Wang
  2026-09-04  6:44     ` Ard Biesheuvel
  0 siblings, 1 reply; 5+ messages in thread
From: Hui Wang @ 2026-09-04  2:06 UTC (permalink / raw)
  To: Ard Biesheuvel, shuah, Shuah Khan, linux-kselftest

The previous mail was rejected by linux-kselftest maillist because the 
html part is detected. Fixing it and re-sending the mail.

On 9/3/26 17:34, Ard Biesheuvel wrote:
>>   run_test()
>> @@ -74,7 +82,7 @@ test_create_empty()
>>   {
>>   	local file=$efivarfs_mount/$FUNCNAME-$test_guid
>>
>> -	: > $file
>> +	: 2>/dev/null > $file
>>
> Why is this needed?
The test_create_empty() will be run on read-only efivarfs, and it will 
print [PASS], but it will also print some noise message with read-only 
filesystem like:

--------------------
running test_create_empty
--------------------
$(TESTCASE_PATH)/efivarfs.sh: line 85: 
/sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27: 
Read-only file system
   [PASS]

This change is for suppressing the noise message and make the output 
clean like below:

--------------------
running test_create_empty
--------------------
   [PASS]

Thanks,

Hui.


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

* Re: [PATCH v2] selftests/efivarfs: skip write tests if efivarfs is mounted read-only
  2026-09-04  2:06   ` Hui Wang
@ 2026-09-04  6:44     ` Ard Biesheuvel
  2026-09-04  7:08       ` Hui Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2026-09-04  6:44 UTC (permalink / raw)
  To: Hui Wang, shuah, Shuah Khan, linux-kselftest



On Fri, 4 Sep 2026, at 04:06, Hui Wang wrote:
> The previous mail was rejected by linux-kselftest maillist because the 
> html part is detected. Fixing it and re-sending the mail.
>
> On 9/3/26 17:34, Ard Biesheuvel wrote:
>>>   run_test()
>>> @@ -74,7 +82,7 @@ test_create_empty()
>>>   {
>>>   	local file=$efivarfs_mount/$FUNCNAME-$test_guid
>>>
>>> -	: > $file
>>> +	: 2>/dev/null > $file
>>>
>> Why is this needed?
> The test_create_empty() will be run on read-only efivarfs, and it will 
> print [PASS], but it will also print some noise message with read-only 
> filesystem like:
>
> --------------------
> running test_create_empty
> --------------------
> $(TESTCASE_PATH)/efivarfs.sh: line 85: 
> /sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27: 
> Read-only file system
>    [PASS]
>
> This change is for suppressing the noise message and make the output 
> clean like below:
>
> --------------------
> running test_create_empty
> --------------------
>    [PASS]
>

That does not make sense.

If the file does not exist after attempting to create it, the test has failed.
But I suspect that this fails even on a read-write efivarfs, given that EFI
does not support zero-length variables.

Please fix this in a separate patch, or leave it alone. Don't paper over it
like this.



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

* Re: [PATCH v2] selftests/efivarfs: skip write tests if efivarfs is mounted read-only
  2026-09-04  6:44     ` Ard Biesheuvel
@ 2026-09-04  7:08       ` Hui Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Hui Wang @ 2026-09-04  7:08 UTC (permalink / raw)
  To: Ard Biesheuvel, shuah, Shuah Khan, linux-kselftest


On 9/4/26 14:44, Ard Biesheuvel wrote:
>
> On Fri, 4 Sep 2026, at 04:06, Hui Wang wrote:
>> The previous mail was rejected by linux-kselftest maillist because the
>> html part is detected. Fixing it and re-sending the mail.
>>
>> On 9/3/26 17:34, Ard Biesheuvel wrote:
>>>>    run_test()
>>>> @@ -74,7 +82,7 @@ test_create_empty()
>>>>    {
>>>>    	local file=$efivarfs_mount/$FUNCNAME-$test_guid
>>>>
>>>> -	: > $file
>>>> +	: 2>/dev/null > $file
>>>>
>>> Why is this needed?
>> The test_create_empty() will be run on read-only efivarfs, and it will
>> print [PASS], but it will also print some noise message with read-only
>> filesystem like:
>>
>> --------------------
>> running test_create_empty
>> --------------------
>> $(TESTCASE_PATH)/efivarfs.sh: line 85:
>> /sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27:
>> Read-only file system
>>     [PASS]
>>
>> This change is for suppressing the noise message and make the output
>> clean like below:
>>
>> --------------------
>> running test_create_empty
>> --------------------
>>     [PASS]
>>
> That does not make sense.
>
> If the file does not exist after attempting to create it, the test has failed.
> But I suspect that this fails even on a read-write efivarfs, given that EFI
> does not support zero-length variables.
>
> Please fix this in a separate patch, or leave it alone. Don't paper over it
> like this.

OK, got it.

Thanks.


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

end of thread, other threads:[~2026-09-04  7:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20  3:01 [PATCH v2] selftests/efivarfs: skip write tests if efivarfs is mounted read-only Hui Wang
2026-09-03  9:34 ` Ard Biesheuvel
2026-09-04  2:06   ` Hui Wang
2026-09-04  6:44     ` Ard Biesheuvel
2026-09-04  7:08       ` Hui Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox