[PATCH 1/3] efi_loader: enable QueryVariableInfo at runtime for file backed variables

Since commit c28d32f946f0 ("efi_loader: conditionally enable SetvariableRT") we are enabling the last bits of missing runtime services. Add support for QueryVariableInfo which we already support at boottime and we just need to mark some fucntions available at runtime and move some checks around.
It's worth noting that pointer checks for maxmimum and remaining variable storage aren't when we store variables on the RPMB, since the Secure World backend is already performing them.
Signed-off-by: Ilias Apalodimas ilias.apalodimas@linaro.org --- lib/efi_loader/efi_runtime.c | 4 ++++ lib/efi_loader/efi_var_common.c | 6 ------ lib/efi_loader/efi_variable.c | 18 ++++++++++++------ lib/efi_loader/efi_variable_tee.c | 5 +++++ .../efi_selftest_variables_runtime.c | 14 +++++++++++--- 5 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 73831c527e00..011bcd04836d 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -129,6 +129,10 @@ efi_status_t efi_init_runtime_supported(void) EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP | EFI_RT_SUPPORTED_CONVERT_POINTER;
+ if (IS_ENABLED(CONFIG_EFI_VARIABLE_FILE_STORE)) + rt_table->runtime_services_supported |= + EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO; + if (IS_ENABLED(CONFIG_EFI_RT_VOLATILE_STORE)) { u8 s = 0;
diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index 961139f005af..ea8d2a4cf98c 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -1,4 +1,3 @@ -// SPDX-License-Identifier: GPL-2.0+ /* * UEFI runtime variable services * @@ -163,11 +162,6 @@ efi_status_t EFIAPI efi_query_variable_info( EFI_ENTRY("%x %p %p %p", attributes, maximum_variable_storage_size, remaining_variable_storage_size, maximum_variable_size);
- if (!maximum_variable_storage_size || - !remaining_variable_storage_size || - !maximum_variable_size) - return EFI_EXIT(EFI_INVALID_PARAMETER); - ret = efi_query_variable_info_int(attributes, maximum_variable_storage_size, remaining_variable_storage_size, diff --git a/lib/efi_loader/efi_variable.c b/lib/efi_loader/efi_variable.c index 0cbed53d1dbf..e039cecd82b6 100644 --- a/lib/efi_loader/efi_variable.c +++ b/lib/efi_loader/efi_variable.c @@ -406,12 +406,15 @@ efi_status_t efi_set_variable_int(const u16 *variable_name, return EFI_SUCCESS; }
-efi_status_t efi_query_variable_info_int(u32 attributes, - u64 *maximum_variable_storage_size, - u64 *remaining_variable_storage_size, - u64 *maximum_variable_size) +efi_status_t __efi_runtime +efi_query_variable_info_int(u32 attributes, + u64 *maximum_variable_storage_size, + u64 *remaining_variable_storage_size, + u64 *maximum_variable_size) { - if (attributes == 0) + if (!maximum_variable_storage_size || + !remaining_variable_storage_size || + !maximum_variable_size || !attributes) return EFI_INVALID_PARAMETER;
/* EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated */ @@ -460,7 +463,10 @@ static efi_status_t __efi_runtime EFIAPI efi_query_variable_info_runtime( u64 *remaining_variable_storage_size, u64 *maximum_variable_size) { - return EFI_UNSUPPORTED; + return efi_query_variable_info_int(attributes, + maximum_variable_storage_size, + remaining_variable_storage_size, + maximum_variable_size); }
/** diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index 4f1aa298da13..8b6b0a390869 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -873,6 +873,11 @@ efi_status_t efi_query_variable_info_int(u32 attributes, efi_status_t ret; u8 *comm_buf;
+ if (!max_variable_storage_size || + !remain_variable_storage_size || + !max_variable_size || !attributes) + return EFI_INVALID_PARAMETER; + payload_size = sizeof(*mm_query_info); comm_buf = setup_mm_hdr((void **)&mm_query_info, payload_size, SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO, diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c b/lib/efi_selftest/efi_selftest_variables_runtime.c index afa91be62c85..5794a7b2d405 100644 --- a/lib/efi_selftest/efi_selftest_variables_runtime.c +++ b/lib/efi_selftest/efi_selftest_variables_runtime.c @@ -60,9 +60,17 @@ static int execute(void) ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, &max_storage, &rem_storage, &max_size); - if (ret != EFI_UNSUPPORTED) { - efi_st_error("QueryVariableInfo failed\n"); - return EFI_ST_FAILURE; + + if (IS_ENABLED(CONFIG_EFI_VARIABLE_FILE_STORE)) { + if (ret != EFI_SUCCESS) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + } else { + if (ret != EFI_UNSUPPORTED) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } }
ret = runtime->set_variable(u"efi_st_var0", &guid_vendor0,

Since we support QueryVariableInfo at runtime now add the relevant tests. Since we want those to be reusable at bootime, add them in a separate file
Add tests for - Test QueryVariableInfo returns EFI_SUCCESS - Test null pointers for the function arguments - Test invalid combination of attributes
Signed-off-by: Ilias Apalodimas ilias.apalodimas@linaro.org --- include/efi_selftest.h | 9 ++ lib/efi_selftest/Makefile | 1 + .../efi_selftest_variables_common.c | 102 ++++++++++++++++++ .../efi_selftest_variables_runtime.c | 10 +- 4 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 lib/efi_selftest/efi_selftest_variables_common.c
diff --git a/include/efi_selftest.h b/include/efi_selftest.h index 5bcebb368287..ca7ae948663e 100644 --- a/include/efi_selftest.h +++ b/include/efi_selftest.h @@ -147,6 +147,15 @@ void *efi_st_get_config_table(const efi_guid_t *guid); */ u16 efi_st_get_key(void);
+/** + * efi_st_query_variable_common - Common variable tests for boottime/runtime + * + * @runtime: Pointer to services table + * + * Return: EFI_ST_SUCCESS/FAILURE + */ +int efi_st_query_variable_common(struct efi_runtime_services *runtime); + /** * struct efi_unit_test - EFI unit test * diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index e4d75420bff6..414701893f65 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -45,6 +45,7 @@ efi_selftest_textinputex.o \ efi_selftest_textoutput.o \ efi_selftest_tpl.o \ efi_selftest_util.o \ +efi_selftest_variables_common.o \ efi_selftest_variables.o \ efi_selftest_variables_runtime.o \ efi_selftest_watchdog.o diff --git a/lib/efi_selftest/efi_selftest_variables_common.c b/lib/efi_selftest/efi_selftest_variables_common.c new file mode 100644 index 000000000000..36bdfe6ff9c3 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_variables_common.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * efi_selftest_variables_runtime + * + * Copyright (c) 2024 Ilias Apalodimas ilias.apalodimas@linaro.org + * + * This unit test checks common service across boottime/runtime + */ + +#include <efi_selftest.h> + +#define EFI_INVALID_ATTR BIT(30) + +int efi_st_query_variable_common(struct efi_runtime_services *runtime) +{ + efi_status_t ret; + u64 max_storage, rem_storage, max_size; + + ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, + &max_storage, &rem_storage, + &max_size); + if (ret != EFI_SUCCESS) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, + NULL, &rem_storage, + &max_size); + if (ret != EFI_INVALID_PARAMETER) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, + &max_storage, NULL, + &max_size); + if (ret != EFI_INVALID_PARAMETER) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, + &max_storage, &rem_storage, + NULL); + if (ret != EFI_INVALID_PARAMETER) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + ret = runtime->query_variable_info(0, &max_storage, &rem_storage, + &max_size); + if (ret != EFI_INVALID_PARAMETER) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + ret = runtime->query_variable_info(EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | + EFI_VARIABLE_NON_VOLATILE, + &max_storage, &rem_storage, + &max_size); + if (ret != EFI_UNSUPPORTED) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + /* Use an attribute bit not described in the EFI spec */ + ret = runtime->query_variable_info(EFI_INVALID_ATTR, &max_storage, + &rem_storage, &max_size); + if (ret != EFI_UNSUPPORTED) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS, &max_storage, &rem_storage, + &max_size); + if (ret != EFI_INVALID_PARAMETER) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE, &max_storage, &rem_storage, + &max_size); + if (ret != EFI_INVALID_PARAMETER) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + /* + * Use a mix existing/non-existing attribute bits from the + * UEFI spec + */ + ret = runtime->query_variable_info(EFI_INVALID_ATTR | EFI_VARIABLE_NON_VOLATILE, + &max_storage, &rem_storage, + &max_size); + if (ret != EFI_INVALID_PARAMETER) { + efi_st_error("QueryVariableInfo failed\n"); + return EFI_ST_FAILURE; + } + + return EFI_ST_SUCCESS; +} diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c b/lib/efi_selftest/efi_selftest_variables_runtime.c index 5794a7b2d405..6cb86771fe78 100644 --- a/lib/efi_selftest/efi_selftest_variables_runtime.c +++ b/lib/efi_selftest/efi_selftest_variables_runtime.c @@ -55,18 +55,20 @@ static int execute(void) u16 varname[EFI_ST_MAX_VARNAME_SIZE]; efi_guid_t guid; u64 max_storage, rem_storage, max_size; + int test_ret;
memset(v2, 0x1, sizeof(v2)); - ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, - &max_storage, &rem_storage, - &max_size);
if (IS_ENABLED(CONFIG_EFI_VARIABLE_FILE_STORE)) { - if (ret != EFI_SUCCESS) { + test_ret = efi_st_query_variable_common(runtime); + if (test_ret != EFI_ST_SUCCESS) { efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE; } } else { + ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, + &max_storage, &rem_storage, + &max_size); if (ret != EFI_UNSUPPORTED) { efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE;

On 24.04.24 07:03, Ilias Apalodimas wrote:
Since we support QueryVariableInfo at runtime now add the relevant tests. Since we want those to be reusable at bootime, add them in a separate file
Add tests for
- Test QueryVariableInfo returns EFI_SUCCESS
- Test null pointers for the function arguments
- Test invalid combination of attributes
Signed-off-by: Ilias Apalodimas ilias.apalodimas@linaro.org
include/efi_selftest.h | 9 ++ lib/efi_selftest/Makefile | 1 + .../efi_selftest_variables_common.c | 102 ++++++++++++++++++ .../efi_selftest_variables_runtime.c | 10 +- 4 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 lib/efi_selftest/efi_selftest_variables_common.c
diff --git a/include/efi_selftest.h b/include/efi_selftest.h index 5bcebb368287..ca7ae948663e 100644 --- a/include/efi_selftest.h +++ b/include/efi_selftest.h @@ -147,6 +147,15 @@ void *efi_st_get_config_table(const efi_guid_t *guid); */ u16 efi_st_get_key(void);
+/**
- efi_st_query_variable_common - Common variable tests for boottime/runtime
- @runtime: Pointer to services table
- Return: EFI_ST_SUCCESS/FAILURE
- */
+int efi_st_query_variable_common(struct efi_runtime_services *runtime);
- /**
- struct efi_unit_test - EFI unit test
diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index e4d75420bff6..414701893f65 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -45,6 +45,7 @@ efi_selftest_textinputex.o \ efi_selftest_textoutput.o \ efi_selftest_tpl.o \ efi_selftest_util.o \ +efi_selftest_variables_common.o \ efi_selftest_variables.o \ efi_selftest_variables_runtime.o \ efi_selftest_watchdog.o diff --git a/lib/efi_selftest/efi_selftest_variables_common.c b/lib/efi_selftest/efi_selftest_variables_common.c new file mode 100644 index 000000000000..36bdfe6ff9c3 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_variables_common.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0+ +/*
- efi_selftest_variables_runtime
- Copyright (c) 2024 Ilias Apalodimas ilias.apalodimas@linaro.org
- This unit test checks common service across boottime/runtime
- */
+#include <efi_selftest.h>
+#define EFI_INVALID_ATTR BIT(30)
+int efi_st_query_variable_common(struct efi_runtime_services *runtime) +{
EDK2's VariableServiceQueryVariableInfo() in MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c has different attribute requirements at runtime than at boot services time.
I guess QueryVariables() should return EFI_INVALID_PARAMETER whenever SetVariables() does.
Best regards
Heinrich
Best regards
Heinrich
- efi_status_t ret;
- u64 max_storage, rem_storage, max_size;
- ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
&max_size);
- if (ret != EFI_SUCCESS) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
NULL, &rem_storage,
&max_size);
- if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, NULL,
&max_size);
- if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
NULL);
- if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- ret = runtime->query_variable_info(0, &max_storage, &rem_storage,
&max_size);
- if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- ret = runtime->query_variable_info(EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
EFI_VARIABLE_NON_VOLATILE,
&max_storage, &rem_storage,
&max_size);
- if (ret != EFI_UNSUPPORTED) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- /* Use an attribute bit not described in the EFI spec */
- ret = runtime->query_variable_info(EFI_INVALID_ATTR, &max_storage,
&rem_storage, &max_size);
- if (ret != EFI_UNSUPPORTED) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS, &max_storage, &rem_storage,
&max_size);
- if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE, &max_storage, &rem_storage,
&max_size);
- if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- /*
* Use a mix existing/non-existing attribute bits from the
* UEFI spec
*/
- ret = runtime->query_variable_info(EFI_INVALID_ATTR | EFI_VARIABLE_NON_VOLATILE,
&max_storage, &rem_storage,
&max_size);
- if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
- }
- return EFI_ST_SUCCESS;
+} diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c b/lib/efi_selftest/efi_selftest_variables_runtime.c index 5794a7b2d405..6cb86771fe78 100644 --- a/lib/efi_selftest/efi_selftest_variables_runtime.c +++ b/lib/efi_selftest/efi_selftest_variables_runtime.c @@ -55,18 +55,20 @@ static int execute(void) u16 varname[EFI_ST_MAX_VARNAME_SIZE]; efi_guid_t guid; u64 max_storage, rem_storage, max_size;
int test_ret;
memset(v2, 0x1, sizeof(v2));
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
&max_size);
if (IS_ENABLED(CONFIG_EFI_VARIABLE_FILE_STORE)) {
if (ret != EFI_SUCCESS) {
test_ret = efi_st_query_variable_common(runtime);
} } else {if (test_ret != EFI_ST_SUCCESS) { efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE;
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
if (ret != EFI_UNSUPPORTED) { efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE;&max_size);

Hi Heinrich,
On Wed, 24 Apr 2024 at 10:25, Heinrich Schuchardt xypron.glpk@gmx.de wrote:
On 24.04.24 07:03, Ilias Apalodimas wrote:
Since we support QueryVariableInfo at runtime now add the relevant tests. Since we want those to be reusable at bootime, add them in a separate file
Add tests for
- Test QueryVariableInfo returns EFI_SUCCESS
- Test null pointers for the function arguments
- Test invalid combination of attributes
Signed-off-by: Ilias Apalodimas ilias.apalodimas@linaro.org
include/efi_selftest.h | 9 ++ lib/efi_selftest/Makefile | 1 + .../efi_selftest_variables_common.c | 102 ++++++++++++++++++ .../efi_selftest_variables_runtime.c | 10 +- 4 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 lib/efi_selftest/efi_selftest_variables_common.c
diff --git a/include/efi_selftest.h b/include/efi_selftest.h index 5bcebb368287..ca7ae948663e 100644 --- a/include/efi_selftest.h +++ b/include/efi_selftest.h @@ -147,6 +147,15 @@ void *efi_st_get_config_table(const efi_guid_t *guid); */ u16 efi_st_get_key(void);
+/**
- efi_st_query_variable_common - Common variable tests for boottime/runtime
- @runtime: Pointer to services table
- Return: EFI_ST_SUCCESS/FAILURE
- */
+int efi_st_query_variable_common(struct efi_runtime_services *runtime);
- /**
- struct efi_unit_test - EFI unit test
diff --git a/lib/efi_selftest/Makefile b/lib/efi_selftest/Makefile index e4d75420bff6..414701893f65 100644 --- a/lib/efi_selftest/Makefile +++ b/lib/efi_selftest/Makefile @@ -45,6 +45,7 @@ efi_selftest_textinputex.o \ efi_selftest_textoutput.o \ efi_selftest_tpl.o \ efi_selftest_util.o \ +efi_selftest_variables_common.o \ efi_selftest_variables.o \ efi_selftest_variables_runtime.o \ efi_selftest_watchdog.o diff --git a/lib/efi_selftest/efi_selftest_variables_common.c b/lib/efi_selftest/efi_selftest_variables_common.c new file mode 100644 index 000000000000..36bdfe6ff9c3 --- /dev/null +++ b/lib/efi_selftest/efi_selftest_variables_common.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0+ +/*
- efi_selftest_variables_runtime
- Copyright (c) 2024 Ilias Apalodimas ilias.apalodimas@linaro.org
- This unit test checks common service across boottime/runtime
- */
+#include <efi_selftest.h>
+#define EFI_INVALID_ATTR BIT(30)
+int efi_st_query_variable_common(struct efi_runtime_services *runtime) +{
EDK2's VariableServiceQueryVariableInfo() in MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c has different attribute requirements at runtime than at boot services time.
I guess QueryVariables() should return EFI_INVALID_PARAMETER whenever SetVariables() does.
I think that's an easy fix. We can still keep a common file, but also pass the attributes as a function argument depending on bootime/runtime
I'll send a v2.
Thanks /Ilias
Best regards
Heinrich
Best regards
Heinrich
efi_status_t ret;
u64 max_storage, rem_storage, max_size;
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_SUCCESS) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
NULL, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, NULL,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
NULL);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(0, &max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS |
EFI_VARIABLE_NON_VOLATILE,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_UNSUPPORTED) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
/* Use an attribute bit not described in the EFI spec */
ret = runtime->query_variable_info(EFI_INVALID_ATTR, &max_storage,
&rem_storage, &max_size);
if (ret != EFI_UNSUPPORTED) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_RUNTIME_ACCESS, &max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
ret = runtime->query_variable_info(EFI_VARIABLE_NON_VOLATILE, &max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
/*
* Use a mix existing/non-existing attribute bits from the
* UEFI spec
*/
ret = runtime->query_variable_info(EFI_INVALID_ATTR | EFI_VARIABLE_NON_VOLATILE,
&max_storage, &rem_storage,
&max_size);
if (ret != EFI_INVALID_PARAMETER) {
efi_st_error("QueryVariableInfo failed\n");
return EFI_ST_FAILURE;
}
return EFI_ST_SUCCESS;
+} diff --git a/lib/efi_selftest/efi_selftest_variables_runtime.c b/lib/efi_selftest/efi_selftest_variables_runtime.c index 5794a7b2d405..6cb86771fe78 100644 --- a/lib/efi_selftest/efi_selftest_variables_runtime.c +++ b/lib/efi_selftest/efi_selftest_variables_runtime.c @@ -55,18 +55,20 @@ static int execute(void) u16 varname[EFI_ST_MAX_VARNAME_SIZE]; efi_guid_t guid; u64 max_storage, rem_storage, max_size;
int test_ret; memset(v2, 0x1, sizeof(v2));
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
&max_size); if (IS_ENABLED(CONFIG_EFI_VARIABLE_FILE_STORE)) {
if (ret != EFI_SUCCESS) {
test_ret = efi_st_query_variable_common(runtime);
if (test_ret != EFI_ST_SUCCESS) { efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE; } } else {
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
&max_storage, &rem_storage,
&max_size); if (ret != EFI_UNSUPPORTED) { efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE;

Previous patches added QueryVariableInfo at runtime tests and split a common function that can be used at boottime. Weire it up and run a similar set of tets. While at it move a test which is checiking for 0 available storage in the common code
Add tests for - Test QueryVariableInfo returns EFI_SUCCESS - Test null pointers for the function arguments - Test invalid combination of attributes
Signed-off-by: Ilias Apalodimas ilias.apalodimas@linaro.org --- lib/efi_selftest/efi_selftest_variables.c | 11 ++++------- lib/efi_selftest/efi_selftest_variables_common.c | 3 +++ 2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/efi_selftest/efi_selftest_variables.c b/lib/efi_selftest/efi_selftest_variables.c index 39ad03a090d4..3c55938be1ce 100644 --- a/lib/efi_selftest/efi_selftest_variables.c +++ b/lib/efi_selftest/efi_selftest_variables.c @@ -52,14 +52,11 @@ static int execute(void) int flag; efi_guid_t guid; u64 max_storage, rem_storage, max_size; + int test_ret;
- ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS, - &max_storage, &rem_storage, - &max_size); - if (ret != EFI_SUCCESS) { - efi_st_todo("QueryVariableInfo failed\n"); - } else if (!max_storage || !rem_storage || !max_size) { - efi_st_error("QueryVariableInfo: wrong info\n"); + test_ret = efi_st_query_variable_common(runtime); + if (test_ret != EFI_ST_SUCCESS) { + efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE; } /* Set variable 0 */ diff --git a/lib/efi_selftest/efi_selftest_variables_common.c b/lib/efi_selftest/efi_selftest_variables_common.c index 36bdfe6ff9c3..435ccf4ac13a 100644 --- a/lib/efi_selftest/efi_selftest_variables_common.c +++ b/lib/efi_selftest/efi_selftest_variables_common.c @@ -22,6 +22,9 @@ int efi_st_query_variable_common(struct efi_runtime_services *runtime) if (ret != EFI_SUCCESS) { efi_st_error("QueryVariableInfo failed\n"); return EFI_ST_FAILURE; + } else if (!max_storage || !rem_storage || !max_size) { + efi_st_error("QueryVariableInfo: wrong info\n"); + return EFI_ST_FAILURE; }
ret = runtime->query_variable_info(EFI_VARIABLE_BOOTSERVICE_ACCESS,
participants (2)
-
Heinrich Schuchardt
-
Ilias Apalodimas