efivar fails to read variables

Bug #2034705 reported by Heinrich Schuchardt
18
This bug affects 2 people
Affects Status Importance Assigned to Milestone
efivar (Ubuntu)
Invalid
Undecided
Unassigned
linux-meta (Ubuntu)
New
High
Unassigned
linux-meta-riscv (Ubuntu)
In Progress
High
Unassigned

Bug Description

On riscv64 StarFive VisionFive 2 with U-Boot v2023.10-rc4 and kernel 6.5.0-2-generic we see this output:

root@ubuntu-server:/var# ls /sys/firmware/efi/efivars/
AuditMode-8be4df61-93ca-11d2-aa0d-00e098032b8c
DeployedMode-8be4df61-93ca-11d2-aa0d-00e098032b8c
OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c
PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c
PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c
SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c
SetupMode-8be4df61-93ca-11d2-aa0d-00e098032b8c
VendorKeys-8be4df61-93ca-11d2-aa0d-00e098032b8c

root@ubuntu-server:/var# efivar -l
efivar: error listing variables: Function not implemented

root@ubuntu-server:/var# efibootmgr -v
EFI variables are not supported on this system.

Expected behavior would be to display the variables.

tags: added: foundations-todo
tags: added: fr-5276
Revision history for this message
Heinrich Schuchardt (xypron) wrote :

The problem is due to the kernel not supporting the deprecated statfs() call on the efivarfs file system.

To demonstrate this I have created the following program (statfs.c):

#include <sys/vfs.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
        struct statfs s;
        int ret;

        if (argc < 2) {
                printf("usage: %s <dirpath>\n", argv[0]);
                return 1;
        }

        ret = statfs(argv[1], &s);
        if (ret == -1) {
                perror("statfs");
                return 1;
        } else {
                printf("%s type: 0x%llx\n", argv[1],
                       (unsigned long long)s.f_type);
        }
        return 0;
}

When I run it I get the following output:

$ ./statfs /sys/firmware/efi
/sys/firmware/efi type: 0x62656572
$ ./statfs /sys/firmware/efi/efivars/
statfs: Invalid argument
$ mount | grep efivarfs
efivarfs on /sys/firmware/efi/efivars type efivarfs (ro,nosuid,nodev,noexec,relatime)

Though efivarfs is mounted on /sys/firmware/efi/efivars the statfs call fails.

Revision history for this message
Heinrich Schuchardt (xypron) wrote (last edit ):

Kernel commit d86ff3333cb1 ("efivarfs: expose used and total size") introduced an EFI runtime call QueryVariableInfo().

Revision history for this message
Heinrich Schuchardt (xypron) wrote :

In U-Boot's EFI_RT_PROPERTIES_TABLE_VERSION the flag EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO is not set.

Revision history for this message
Heinrich Schuchardt (xypron) wrote (last edit ):

U-Boot currently does not implement QueryVariableInfo at runtime. This function is not needed for a read only efivarfs. I think it would be more appropriate to check if GetVariable is enabled in efi.runtime_supported_mask.

Changed in efivar (Ubuntu):
status: New → Invalid
Revision history for this message
Heinrich Schuchardt (xypron) wrote :
Changed in linux-meta-riscv (Ubuntu):
assignee: nobody → Heinrich Schuchardt (xypron)
importance: Undecided → High
status: New → In Progress
tags: added: patch
Revision history for this message
Heinrich Schuchardt (xypron) wrote (last edit ):

Patch sent upstream https://lore<email address hidden>/T/#u

Without this patch the Ubuntu installer on systems using U-Boot (e.g. riscv64) will fail.

Changed in linux-meta-riscv (Ubuntu):
assignee: Heinrich Schuchardt (xypron) → nobody
Revision history for this message
Heinrich Schuchardt (xypron) wrote :

With kernel 6.5.0-6-generic #6.1-Ubuntu SMP Thu Sep 21 12:51:18 from ppa:esmil/ppa efivar works fine.

Revision history for this message
Rade0nfighter (rade0nfighter) wrote :

On the off chance that this issue has a broader impact I will leave a reference to https://answers.launchpad.net/ubuntu/+question/708251 wherein similar behaviours are being observed with 6.5.0-9-generic on amd64.

efivar -l returns: "efivar: error listing variables: Function not implemented", yet `ls /sys/firmware/efi` returns entries.

I noticed this after upgrading from Ubuntu 23.04 when efibootmgr stopped working.

Ubuntu 23.10 x86_64, 6.5.0-9-generic (Plasma 5.27.8 if that makes a difference).

Happy to provide any other info on request.

Revision history for this message
Olivier Gayot (ogayot) wrote (last edit ):

Subiquity users trying to install 23.10 on Apple hardware (amd64) have been running into problems as well because of this issue.

Thank you Heinrich for sending the patch upstream!

Revision history for this message
Heinrich Schuchardt (xypron) wrote :
Changed in linux-meta (Ubuntu):
importance: Undecided → High
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.