From patchwork Wed Apr 24 05:03:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 791495 Delivered-To: patch@linaro.org Received: by 2002:a5d:4884:0:b0:346:15ad:a2a with SMTP id g4csp650800wrq; Tue, 23 Apr 2024 22:04:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWPNIlaglBZO26+E5tT/xjT99PIsiaeWmU7OEwmInTOJMYywt81LxHrqmSPxcGITF/O4orc0ZFPS2PFFDmctIHW X-Google-Smtp-Source: AGHT+IEkQM3Gt0jxuxDDj8PS4tVW26xaTgeaazaJ6tpE/WlDNc4FMmCXqLQEVQ8mvofY4s0dmhWz X-Received: by 2002:a05:600c:548a:b0:41a:7ab1:fd98 with SMTP id iv10-20020a05600c548a00b0041a7ab1fd98mr964351wmb.21.1713935045831; Tue, 23 Apr 2024 22:04:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713935045; cv=none; d=google.com; s=arc-20160816; b=bmkETfHU8nRPmzsY2kFwDQskuH79jPojDP+Z7tkN2ZWK1rMniVNLM4MmAv4Bq4507p tRunMgusEMueqRaH7zghS3ck5PTugwbNWCOJBmzrf12c5TEe9naaFCNBmoNKzL9FQdjS DoYABedNhEppu+ljxkjBERx7z9DvmK0+MdDuCqJLsOso9GAmoLv5oi0t9gOsTAvZKUdh XHJiB4cjbFz1O7J0LO1uPTBpno4YWdAQIWc57D/dnxsGCoJQgyLpDAaQHrEyteRk0yu9 on0IE4WzIG0NVhB6gF0cyEnC3dwl8UM66ePcWiJyH7j7jY/LUdVQp4Wny2QikNmmv9lx nQZw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=EVHDPCZH4dUgdDh5TewEvZ9ii+SMu3g0x9ZgWOqncVY=; fh=r3T11POMt03ClPHECNN1R+djuGoIWWuXsijjvIhWVa4=; b=OT6BvURyW/jsKCdX8gnSAqnhkseBHN5VjHlR/ZKjX7Rw4knT05L1iP8/oZIjnidStL HGS/MowVpJrwKEjxzAD+YYPid50ILsEPCVr2qFSX5MLf2nxTtqTugV9tzGxodV85Oo6L lH00Hm2OEqdM1Uj5AweullUKWGhxKfBU7RS2Z7CN85ojJGCHMMqzjcskMcW2A29cEHVc wUmcBqIgu4j6YxAsmoDnLQ/jqgLJdxk4QqbDblzqwPERHgLx+deh0qKsKuz1krY9dJ2m ztuLln7E6W7N30zpjk9WtaYmQbnLZrbA5HcVrsk7TPzQqMNtPQzY4FUCpln2gTGsNrjG /C7A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x3DDcsIe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id l16-20020a7bc350000000b00418a10c1620si8530090wmj.98.2024.04.23.22.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:04:05 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x3DDcsIe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 B78EA88D96; Wed, 24 Apr 2024 07:04:04 +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="x3DDcsIe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8FA7B88D9C; Wed, 24 Apr 2024 07:04:03 +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-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (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 7919488CD6 for ; Wed, 24 Apr 2024 07:04:01 +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-x32c.google.com with SMTP id 5b1f17b1804b1-41af6701806so3480285e9.1 for ; Tue, 23 Apr 2024 22:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713935041; x=1714539841; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EVHDPCZH4dUgdDh5TewEvZ9ii+SMu3g0x9ZgWOqncVY=; b=x3DDcsIef1iipgl5A5cGq/Yk594ZaEijvGlqH9GXKlgpi4i0B+wReoQxqlSd90axEq mEvIVDL53NqUv1CuANddvPYe8l3eJ8wONfdJw4/B9/HPwIkQWT6pSZrIAKf6cCVJOK8t EhGPihOq+B2FKGbrfD+rVOF3mKyHGiKfygDHspdy3YYTQepnzvGZAn7DnHOFBEhB3bRj eke/SloXZRQAuJj4AhaSXW5oi9LUqDsvomYUF+K/2iEWhKa7RqOgXct/ZbBr46a61oWy LYAwh4t70UoWXi9ZF6m5UNnfDl1lmGntIvUi1cGcOOZStrH08xm3sLfBEvZ68UipsuBH Hx8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713935041; x=1714539841; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EVHDPCZH4dUgdDh5TewEvZ9ii+SMu3g0x9ZgWOqncVY=; b=m71b+zy15aBwy2W91IabxkLCKf+sPoty0K8gWV6dkn1TLIdf98s4ri+oZ0EQ4WEcgQ 50BqTCQ7ZOE12Pr1bFGtzEfd9257QtmIoGV71HYh0v3toXOwD5ESkK66Dxetu06bqTja D9/Yos28skewBdyfl4AEQ7AR0cOe9eeOolm4opoLKGA3a+z5PPXdOj+lDeU5Y7S22sIB D+C8MAvX5d7Yo1Mvq0O42TiDSyTdsVIV1KNeIYTHKqHXsdDm9HLnHcoD8UZ5f7d6TS5v Ob41LWMUDtXvsc//dU5yoFqllXYU6q8KvMYIU6jxKdVD3Lvv0fPigoRwhGfuPu0QKdgp C0bw== X-Gm-Message-State: AOJu0YyvSRyJ/oDURm9hIU6MAmWK3J9x7bxdhZOdBNQWiI44GHbqT6ib XVYGlvWkBx6Hd2zxoLLqd6Hf1Da9VgIPSaztZGLJRWoYuFGF/gjsy9VtFVyElTN3cYela7YIb50 jM3o= X-Received: by 2002:a05:6000:180f:b0:341:d912:1fec with SMTP id m15-20020a056000180f00b00341d9121fecmr773170wrh.49.1713935040824; Tue, 23 Apr 2024 22:04:00 -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.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 22:04:00 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de, xypron.glpk@gmx.de Cc: Ilias Apalodimas Subject: [PATCH 1/3] efi_loader: enable QueryVariableInfo at runtime for file backed variables Date: Wed, 24 Apr 2024 08:03:49 +0300 Message-Id: <20240424050351.318724-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.40.1 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 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 --- 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,