2020-11-28 01:16:38

by Colin King

[permalink] [raw]
Subject: ACK: [PATCH 1/1] efi/efi_test: read RuntimeServicesSupported

On 27/11/2020 19:20, Heinrich Schuchardt wrote:
> Since the UEFI 2.8A specification the UEFI enabled firmware provides a
> configuration table EFI_RT_PROPERTIES_TABLE which indicates which runtime
> services are enabled. The EFI stub reads this table and saves the value of
> the field RuntimeServicesSupported internally.
>
> The Firmware Test Suite requires the value to determine if UEFI runtime
> services are correctly implemented.
>
> With this patch an IOCTL call is provided to read the value of the field
> RuntimeServicesSupported, e.g.
>
> #define EFI_RUNTIME_GET_SUPPORTED_MASK \
> _IOR('p', 0x0C, unsigned int)
> unsigned int mask;
> fd = open("/dev/efi_test", O_RDWR);
> ret = ioctl(fd, EFI_RUNTIME_GET_SUPPORTED_MASK, &mask);
>
> Signed-off-by: Heinrich Schuchardt <[email protected]>
> ---
> drivers/firmware/efi/test/efi_test.c | 16 ++++++++++++++++
> drivers/firmware/efi/test/efi_test.h | 3 +++
> 2 files changed, 19 insertions(+)
>
> diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c
> index ddf9eae396fe..47d67bb0a516 100644
> --- a/drivers/firmware/efi/test/efi_test.c
> +++ b/drivers/firmware/efi/test/efi_test.c
> @@ -663,6 +663,19 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
> return rv;
> }
>
> +static long efi_runtime_get_supported_mask(unsigned long arg)
> +{
> + unsigned int __user *supported_mask;
> + int rv = 0;
> +
> + supported_mask = (unsigned int *)arg;
> +
> + if (put_user(efi.runtime_supported_mask, supported_mask))
> + rv = -EFAULT;
> +
> + return rv;
> +}
> +
> static long efi_test_ioctl(struct file *file, unsigned int cmd,
> unsigned long arg)
> {
> @@ -699,6 +712,9 @@ static long efi_test_ioctl(struct file *file, unsigned int cmd,
>
> case EFI_RUNTIME_RESET_SYSTEM:
> return efi_runtime_reset_system(arg);
> +
> + case EFI_RUNTIME_GET_SUPPORTED_MASK:
> + return efi_runtime_get_supported_mask(arg);
> }
>
> return -ENOTTY;
> diff --git a/drivers/firmware/efi/test/efi_test.h b/drivers/firmware/efi/test/efi_test.h
> index f2446aa1c2e3..117349e57993 100644
> --- a/drivers/firmware/efi/test/efi_test.h
> +++ b/drivers/firmware/efi/test/efi_test.h
> @@ -118,4 +118,7 @@ struct efi_resetsystem {
> #define EFI_RUNTIME_RESET_SYSTEM \
> _IOW('p', 0x0B, struct efi_resetsystem)
>
> +#define EFI_RUNTIME_GET_SUPPORTED_MASK \
> + _IOR('p', 0x0C, unsigned int)
> +
> #endif /* _DRIVERS_FIRMWARE_EFI_TEST_H_ */
> --
> 2.29.2
>

Looks good to me. Thanks Heinrich.

The EFI driver needs to be also updated in the linux kernel - has that
fix been submitted or do you require the fwts team to do that?

Colin


2020-11-28 01:28:47

by Colin King

[permalink] [raw]
Subject: Re: ACK: [PATCH 1/1] efi/efi_test: read RuntimeServicesSupported

On 27/11/2020 19:29, Ard Biesheuvel wrote:
> On Fri, 27 Nov 2020 at 20:28, Colin Ian King <[email protected]> wrote:
>>
>> On 27/11/2020 19:20, Heinrich Schuchardt wrote:
>>> Since the UEFI 2.8A specification the UEFI enabled firmware provides a
>>> configuration table EFI_RT_PROPERTIES_TABLE which indicates which runtime
>>> services are enabled. The EFI stub reads this table and saves the value of
>>> the field RuntimeServicesSupported internally.
>>>
>>> The Firmware Test Suite requires the value to determine if UEFI runtime
>>> services are correctly implemented.
>>>
>>> With this patch an IOCTL call is provided to read the value of the field
>>> RuntimeServicesSupported, e.g.
>>>
>>> #define EFI_RUNTIME_GET_SUPPORTED_MASK \
>>> _IOR('p', 0x0C, unsigned int)
>>> unsigned int mask;
>>> fd = open("/dev/efi_test", O_RDWR);
>>> ret = ioctl(fd, EFI_RUNTIME_GET_SUPPORTED_MASK, &mask);
>>>
>>> Signed-off-by: Heinrich Schuchardt <[email protected]>
>>> ---
>>> drivers/firmware/efi/test/efi_test.c | 16 ++++++++++++++++
>>> drivers/firmware/efi/test/efi_test.h | 3 +++
>>> 2 files changed, 19 insertions(+)
>>>
>>> diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c
>>> index ddf9eae396fe..47d67bb0a516 100644
>>> --- a/drivers/firmware/efi/test/efi_test.c
>>> +++ b/drivers/firmware/efi/test/efi_test.c
>>> @@ -663,6 +663,19 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
>>> return rv;
>>> }
>>>
>>> +static long efi_runtime_get_supported_mask(unsigned long arg)
>>> +{
>>> + unsigned int __user *supported_mask;
>>> + int rv = 0;
>>> +
>>> + supported_mask = (unsigned int *)arg;
>>> +
>>> + if (put_user(efi.runtime_supported_mask, supported_mask))
>>> + rv = -EFAULT;
>>> +
>>> + return rv;
>>> +}
>>> +
>>> static long efi_test_ioctl(struct file *file, unsigned int cmd,
>>> unsigned long arg)
>>> {
>>> @@ -699,6 +712,9 @@ static long efi_test_ioctl(struct file *file, unsigned int cmd,
>>>
>>> case EFI_RUNTIME_RESET_SYSTEM:
>>> return efi_runtime_reset_system(arg);
>>> +
>>> + case EFI_RUNTIME_GET_SUPPORTED_MASK:
>>> + return efi_runtime_get_supported_mask(arg);
>>> }
>>>
>>> return -ENOTTY;
>>> diff --git a/drivers/firmware/efi/test/efi_test.h b/drivers/firmware/efi/test/efi_test.h
>>> index f2446aa1c2e3..117349e57993 100644
>>> --- a/drivers/firmware/efi/test/efi_test.h
>>> +++ b/drivers/firmware/efi/test/efi_test.h
>>> @@ -118,4 +118,7 @@ struct efi_resetsystem {
>>> #define EFI_RUNTIME_RESET_SYSTEM \
>>> _IOW('p', 0x0B, struct efi_resetsystem)
>>>
>>> +#define EFI_RUNTIME_GET_SUPPORTED_MASK \
>>> + _IOR('p', 0x0C, unsigned int)
>>> +
>>> #endif /* _DRIVERS_FIRMWARE_EFI_TEST_H_ */
>>> --
>>> 2.29.2
>>>
>>
>> Looks good to me. Thanks Heinrich.
>>
>> The EFI driver needs to be also updated in the linux kernel - has that
>> fix been submitted or do you require the fwts team to do that?

Oops. It's been a lot week :-(

>>
>
> This /is/ the EFI driver.
>
> I'll take this as an acked-by but I'd like Ivan to chime in as well.
>
+1


2020-11-28 22:23:42

by Heinrich Schuchardt

[permalink] [raw]
Subject: Re: ACK: [PATCH 1/1] efi/efi_test: read RuntimeServicesSupported

On 11/27/20 8:29 PM, Ard Biesheuvel wrote:
> On Fri, 27 Nov 2020 at 20:28, Colin Ian King <[email protected]> wrote:
>>
>> On 27/11/2020 19:20, Heinrich Schuchardt wrote:
>>> Since the UEFI 2.8A specification the UEFI enabled firmware provides a
>>> configuration table EFI_RT_PROPERTIES_TABLE which indicates which runtime
>>> services are enabled. The EFI stub reads this table and saves the value of
>>> the field RuntimeServicesSupported internally.
>>>
>>> The Firmware Test Suite requires the value to determine if UEFI runtime
>>> services are correctly implemented.
>>>
<snip />
>> Looks good to me. Thanks Heinrich.
>>
>> The EFI driver needs to be also updated in the linux kernel - has that
>> fix been submitted or do you require the fwts team to do that?
>>
>
> This /is/ the EFI driver.
>
> I'll take this as an acked-by but I'd like Ivan to chime in as well.
>

Hello Ard, hello Colin,

I have tested the patch with Linux 5.8.9.

Somehow Linux managed to break the kernel for my board between Linux
5.8.9 and 5.8.18. It does not boot form iSCSI with a newer kernel.

You probably want to run a user program against your latest kernel. This
is what I used:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>

#define EFI_RUNTIME_GET_SUPPORTED_MASK \
_IOR('p', 0x0C, unsigned int)

int main()
{
unsigned int i, flag;
int fd, ret;
unsigned int mask;

fd = open("/dev/efi_test", O_RDWR);
if (fd == -1) {
perror("open");
return 1;
}

ret = ioctl(fd, EFI_RUNTIME_GET_SUPPORTED_MASK, &mask);
if (ret == -1) {
perror("ioctl");
return 1;
}
printf("mask 0x%08x\n", mask);

flag = 1;
for (i = 0x80000000; i; i >>= 1) {
if (i & mask) {
printf("%4s 0x%08x\n", flag ? "=" : "|", i);
flag = 0;
}
}

close(fd);

return 0;
}

Best regards

Heinrich

2020-11-28 22:25:52

by Ard Biesheuvel

[permalink] [raw]
Subject: Re: ACK: [PATCH 1/1] efi/efi_test: read RuntimeServicesSupported

On Fri, 27 Nov 2020 at 20:28, Colin Ian King <[email protected]> wrote:
>
> On 27/11/2020 19:20, Heinrich Schuchardt wrote:
> > Since the UEFI 2.8A specification the UEFI enabled firmware provides a
> > configuration table EFI_RT_PROPERTIES_TABLE which indicates which runtime
> > services are enabled. The EFI stub reads this table and saves the value of
> > the field RuntimeServicesSupported internally.
> >
> > The Firmware Test Suite requires the value to determine if UEFI runtime
> > services are correctly implemented.
> >
> > With this patch an IOCTL call is provided to read the value of the field
> > RuntimeServicesSupported, e.g.
> >
> > #define EFI_RUNTIME_GET_SUPPORTED_MASK \
> > _IOR('p', 0x0C, unsigned int)
> > unsigned int mask;
> > fd = open("/dev/efi_test", O_RDWR);
> > ret = ioctl(fd, EFI_RUNTIME_GET_SUPPORTED_MASK, &mask);
> >
> > Signed-off-by: Heinrich Schuchardt <[email protected]>
> > ---
> > drivers/firmware/efi/test/efi_test.c | 16 ++++++++++++++++
> > drivers/firmware/efi/test/efi_test.h | 3 +++
> > 2 files changed, 19 insertions(+)
> >
> > diff --git a/drivers/firmware/efi/test/efi_test.c b/drivers/firmware/efi/test/efi_test.c
> > index ddf9eae396fe..47d67bb0a516 100644
> > --- a/drivers/firmware/efi/test/efi_test.c
> > +++ b/drivers/firmware/efi/test/efi_test.c
> > @@ -663,6 +663,19 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
> > return rv;
> > }
> >
> > +static long efi_runtime_get_supported_mask(unsigned long arg)
> > +{
> > + unsigned int __user *supported_mask;
> > + int rv = 0;
> > +
> > + supported_mask = (unsigned int *)arg;
> > +
> > + if (put_user(efi.runtime_supported_mask, supported_mask))
> > + rv = -EFAULT;
> > +
> > + return rv;
> > +}
> > +
> > static long efi_test_ioctl(struct file *file, unsigned int cmd,
> > unsigned long arg)
> > {
> > @@ -699,6 +712,9 @@ static long efi_test_ioctl(struct file *file, unsigned int cmd,
> >
> > case EFI_RUNTIME_RESET_SYSTEM:
> > return efi_runtime_reset_system(arg);
> > +
> > + case EFI_RUNTIME_GET_SUPPORTED_MASK:
> > + return efi_runtime_get_supported_mask(arg);
> > }
> >
> > return -ENOTTY;
> > diff --git a/drivers/firmware/efi/test/efi_test.h b/drivers/firmware/efi/test/efi_test.h
> > index f2446aa1c2e3..117349e57993 100644
> > --- a/drivers/firmware/efi/test/efi_test.h
> > +++ b/drivers/firmware/efi/test/efi_test.h
> > @@ -118,4 +118,7 @@ struct efi_resetsystem {
> > #define EFI_RUNTIME_RESET_SYSTEM \
> > _IOW('p', 0x0B, struct efi_resetsystem)
> >
> > +#define EFI_RUNTIME_GET_SUPPORTED_MASK \
> > + _IOR('p', 0x0C, unsigned int)
> > +
> > #endif /* _DRIVERS_FIRMWARE_EFI_TEST_H_ */
> > --
> > 2.29.2
> >
>
> Looks good to me. Thanks Heinrich.
>
> The EFI driver needs to be also updated in the linux kernel - has that
> fix been submitted or do you require the fwts team to do that?
>

This /is/ the EFI driver.

I'll take this as an acked-by but I'd like Ivan to chime in as well.