From patchwork Wed Apr 24 05:03:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 791496 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp650855wrq; Tue, 23 Apr 2024 22:04:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWlaKeOa0aborfoqko737bIRSnYPY8yuojLxA29xlmy5ODbhuMjnoWMzefhivfHdUcr9NdwUoXyqsABb35QoLSt X-Google-Smtp-Source: AGHT+IH1QrN4yZ4nVTRXR4HuDkcWOpRo8uRmwQlzjw07Nd101m/7Ql4emDOt1qZFx9FIKE8PpGH3 X-Received: by 2002:a5d:42cf:0:b0:346:b581:ff57 with SMTP id t15-20020a5d42cf000000b00346b581ff57mr718961wrr.68.1713935057251; Tue, 23 Apr 2024 22:04:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713935057; cv=none; d=google.com; s=arc-20160816; b=fJCcFkc5DUe5f/Ve+pwAKRgbvtzOav/WObWcWmYYWKe5hQ8wcUG8NbMLD/tfxnAK+r f2IIYnPW+jS89LkEO84fePAuHDUKpoTAYcbuT9cWZeisTYNb4QpG2zFjVS/VPCXiqZ/7 fqWaOFrcTUkozIWEDYGVwvGXQ12h+T3G+uzHU81VavKPIE8S5nw9cSOfCXHdarg3kDxr /y1uwzWzxWg+q3jmdBM5R6fhMgNP8EjOPKZFH62BJNSpkU6sSRMOQCdsdIF+IMcpA3XY 4H+Tn3MhBTTiJa4JpxjqurlntVrk01F/FYbfXbyUw11ukTfxLfw+R7IaV6HfOjCO81MZ W4tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vbFHZkLIyTsnFbIYjd2AoiBzf3B0mbR9ncwmyQR2oNk=; fh=r3T11POMt03ClPHECNN1R+djuGoIWWuXsijjvIhWVa4=; b=lLjhZVwiSU5UurXWZWzECPfUvD0C6VzNoWvFzSZMzdHn3AqpaxnDIw+xZk4QtLzntf EYFZf02pjuBCcy0uKFMIwH+JNmRRd/8IFmUfVf2h1EI2lzNnRByiPhO7HcFGw9ja/Bn5 XaRHWaM8XgP5rRuu5judfgC7ZoNTzsW3hOBolIJLrFlzKqeELZR1rSPn3obnAOx8kkwa C+ivjbR4BNXlEKo2+TmC3HLFNsmHMSkPMuhgZJxlwS6rNi1rX8Nh9KI/oHCFybeUKJxj cJwkQnbgAPtSb1BGuk28uT+x65O1zv/gAOtf96mb1fwx6Z/cRr/IHiZMmZ4O/SYW/C01 ZfWw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IqPGoS/3"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id e7-20020adfef07000000b00346c08e5997si6496151wro.279.2024.04.23.22.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:04:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IqPGoS/3"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1ABA688D9B; Wed, 24 Apr 2024 07:04:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="IqPGoS/3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 674D288CD6; Wed, 24 Apr 2024 07:04:04 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6388688D97 for ; Wed, 24 Apr 2024 07:04:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-41b086d6676so846645e9.1 for ; Tue, 23 Apr 2024 22:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713935042; x=1714539842; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vbFHZkLIyTsnFbIYjd2AoiBzf3B0mbR9ncwmyQR2oNk=; b=IqPGoS/3Hy94pgmpXyZm715H10TsmxVWdjp/D2O1gkE2VKdcC5uu8RMIGXOpcTTLJ2 w80B/7vCaYu3t1kOJA3kVakKJS0nHIqC676THTumIhPZ6MIwAg4nenPJDXe9BSkgdDip HSIyHJP5bPpgvGSY+C4SoAqX90bRYzRZFTFukTXymggtvO8rF9oduuPmuSvWZ9uwQdta Z46ADTjPvfiiweVoQpIPXt/6qYUa/n9nvEKuPFSQjBfZL7naHqoxJSF3K0p9wMCembzA 7ZqO0CzULooucZCa2tCUnSXY6XXc8bb73vlkQh4VotafKbS9k2oYMyQy5eq4mSsln8+Q IIwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713935042; x=1714539842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vbFHZkLIyTsnFbIYjd2AoiBzf3B0mbR9ncwmyQR2oNk=; b=U/VgHzVAUa5OsjQ2yq9RnniqLOvk1jlG5sD/cANsmzztH29FMQOYbMbUSDTI9s3LZI 7CKxZa+cYMrFo1g7My7ARq8iJY0M8rS8rIrj3iBxDzl3NjvWIVYG0ERmtIqiAPiCeneq aymWye9lfjKA0m/Smy9TWW7hSn3b2vcuq9fiSx82YWbSSykwx+ILaMMxPlzjUfAtykGu lzLfN/0Y+OYl1Ofl6Pwmm4qJaV1pOA3O52gnlE1JocYmzeWkgBsZSsRXf9yzZ+lIcEkn IA+qk9e0PKS21zZfN3LG/Vk+4sxL1Y+tkYrvltmv81GdQ1SghjrVwaGadKutWJ8PC1RE 4s6A== X-Gm-Message-State: AOJu0YzSvWv3XWv+H0E8cVpTHvUzNZVtRziONFRYS8zlOd6tmqshzleL QuoQnruFFGxtIVLELope6xa/JBDU+wg0d8ykcWonzTy7XUwot/ZgKfvPk+jFoOyG64Hb1U6mO1m r3/w= X-Received: by 2002:a05:600c:208:b0:41a:aad8:e393 with SMTP id 8-20020a05600c020800b0041aaad8e393mr902439wmi.30.1713935041889; Tue, 23 Apr 2024 22:04:01 -0700 (PDT) Received: from hades.. (ppp089210108048.access.hol.gr. [89.210.108.48]) by smtp.gmail.com with ESMTPSA id bi8-20020a05600c3d8800b0041afe0f2f17sm861032wmb.16.2024.04.23.22.04.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:04:01 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de, xypron.glpk@gmx.de Cc: Ilias Apalodimas Subject: [PATCH 2/3] efi_selftest: add tests for QueryVariableInfo at runtime Date: Wed, 24 Apr 2024 08:03:50 +0300 Message-Id: <20240424050351.318724-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240424050351.318724-1-ilias.apalodimas@linaro.org> References: <20240424050351.318724-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 --- 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 + * + * This unit test checks common service across boottime/runtime + */ + +#include + +#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;