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 <[email protected]>
> ---
> 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?