Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Hui Wang" <hui.wang@canonical.com>,
	shuah@kernel.org, "Shuah Khan" <skhan@linuxfoundation.org>,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] selftests/efivarfs: skip write tests if efivarfs is mounted read-only
Date: Sat, 01 Aug 2026 15:50:45 +0200	[thread overview]
Message-ID: <04dd6e7c-e290-477a-a4bc-45d0ace102be@app.fastmail.com> (raw)
In-Reply-To: <20260608111300.63242-1-hui.wang@canonical.com>

Hello Hui Wang,

On Mon, 8 Jun 2026, at 13:13, 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"). Extend run_test() to take an optional
> "rw" argument marking tests that require a writable efivarfs; such tests
> are reported as [SKIP] (instead of being run and failing) when efivarfs
> is read-only, along with an explanatory message.
>
> test_create_empty and test_invalid_filenames are left to run
> unconditionally, since their expectation still holds on a read-only
> mount; their stderr is silenced to avoid noise from the read-only
> redirection failures.
>
> Assisted-by: Copilot:claude-opus-4-8
> Signed-off-by: Hui Wang <hui.wang@canonical.com>
> ---
>  tools/testing/selftests/efivarfs/efivarfs.sh | 44 +++++++++++++++-----
>  1 file changed, 33 insertions(+), 11 deletions(-)
>
> diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh 
> b/tools/testing/selftests/efivarfs/efivarfs.sh
> index c62544b966ae..d8883fdf3b01 100755
> --- a/tools/testing/selftests/efivarfs/efivarfs.sh
> +++ b/tools/testing/selftests/efivarfs/efivarfs.sh
> @@ -26,16 +26,33 @@ 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()
>  {
>  	local test="$1"
> +	# Second (optional) argument: "rw" if the test needs a writable
> +	# efivarfs. Such tests are skipped when efivarfs is mounted read-only.
> +	local need_rw="$2"
> 
>  	echo "--------------------"
>  	echo "running $test"
>  	echo "--------------------"
> 
> +	if [ "$need_rw" = "rw" ] && [ "$efivarfs_mode" = "ro" ]; then
> +		echo "  [SKIP] efivarfs is mounted read-only," \
> +		     "skipping test that requires write access" >&2
> +		return
> +	fi
> +
>  	if [ "$(type -t $test)" = 'function' ]; then
>  		( $test )
>  	else
> @@ -74,7 +91,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 +378,23 @@ check_prereqs
> 
>  rc=0
> 
> -run_test test_create
> +if [ "$efivarfs_mode" = "ro" ]; then
> +	echo "efivarfs is mounted read-only on $efivarfs_mount;" \
> +	     "tests that require write access will be skipped" >&2
> +fi
> +
> +run_test test_create rw
>  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_create_read rw
> +run_test test_delete rw
> +run_test test_zero_size_delete rw
> +run_test test_open_unlink rw
> +run_test test_valid_filenames rw
>  run_test test_invalid_filenames
> -run_test test_no_set_size
> +run_test test_no_set_size rw
>  setup_test_multiple
> -run_test test_multiple_zero_size
> -run_test test_multiple_create
> -run_test test_multiple_delete_on_write
> +run_test test_multiple_zero_size rw
> +run_test test_multiple_create rw
> +run_test test_multiple_delete_on_write rw
> 

This looks rather messy to me. Can't you have the rw tests in
a single if scope that is only entered when the mount is rw?


      reply	other threads:[~2026-08-01 13:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 11:13 [PATCH] selftests/efivarfs: skip write tests if efivarfs is mounted read-only Hui Wang
2026-08-01 13:50 ` Ard Biesheuvel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=04dd6e7c-e290-477a-a4bc-45d0ace102be@app.fastmail.com \
    --to=ardb@kernel.org \
    --cc=hui.wang@canonical.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox