All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>
To: "Harsimran Singh Tungal" <harsimransingh.tungal@arm.com>,
	<u-boot@lists.u-boot-project.org>
Cc: "Abdellatif El Khlifi" <abdellatif.elkhlifi@arm.com>,
	"Tom Rini" <trini@konsulko.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Simon Glass" <sjg@chromium.org>,
	"Devaraj Ranganna" <Devaraj.Ranganna@arm.com>
Subject: Re: [PATCH v5 13/22] efi_loader: enable TEE runtime SetVariable() over FF-A
Date: Fri, 18 Sep 2026 21:20:36 +0300	[thread overview]
Message-ID: <DLINF8X5LGMM.22DVNGKNPMAM8@linaro.org> (raw)
In-Reply-To: <20260914110106.1974894-14-harsimransingh.tungal@arm.com>

Hi Harsimran


[...]

> +							   efi_uintn_t name_size,
> +							   const efi_guid_t *vendor,
> +							   struct var_check_property *var_property)
> +{
> +	struct smm_variable_var_check_property *smm_property;
> +	efi_uintn_t payload_size;
> +	u8 *comm_buf = NULL;
> +	efi_status_t ret;
> +
> +	payload_size = sizeof(*smm_property) + name_size;
> +	if (payload_size > max_payload_size) {
> +		ret = EFI_INVALID_PARAMETER;
> +		return ret;
> +	}
> +	comm_buf = setup_mm_hdr((void **)&smm_property, payload_size,
> +				SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET,
> +				&ret);
> +	if (!comm_buf)
> +		return ret;
> +
> +	efi_memcpy_runtime(&smm_property->guid, vendor, sizeof(*vendor));
> +	smm_property->name_size = name_size;
> +	efi_memcpy_runtime(&smm_property->property, var_property,
> +			   sizeof(smm_property->property));
> +	efi_memcpy_runtime(smm_property->name, variable_name, name_size);
> +
> +	ret = mm_communicate(comm_buf, payload_size);
> +
> +	return ret;
> +}
> +
>  static efi_status_t get_property_int(const u16 *variable_name,
>  				     efi_uintn_t name_size,
>  				     const efi_guid_t *vendor,
> @@ -768,6 +800,49 @@ out:
>  	return ret;
>  }
>
> +static efi_status_t __efi_runtime get_property_int_runtime(const u16 *variable_name,
> +							   efi_uintn_t name_size,
> +							   const efi_guid_t *vendor,
> +							   struct var_check_property *var_property)
> +{

The changes between this and the non-runtime version are limited to a few memcpy/memset calls.
It's pretty easy to only keep the runtime version and get rid of all the duplication. Same
goes for the set_property_int()

> +	struct smm_variable_var_check_property *smm_property;
> +	efi_uintn_t payload_size;
> +	u8 *comm_buf = NULL;
> +	efi_status_t ret;
> +
> +	efi_memset_runtime(var_property, 0, sizeof(*var_property));
> +	payload_size = sizeof(*smm_property) + name_size;
> +	if (payload_size > max_payload_size) {
> +		ret = EFI_INVALID_PARAMETER;
> +		return ret;
> +	}
> +	comm_buf = setup_mm_hdr((void **)&smm_property, payload_size,
> +				SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET,
> +				&ret);
> +	if (!comm_buf)
> +		return ret;
> +
> +	efi_memcpy_runtime(&smm_property->guid, vendor, sizeof(smm_property->guid));
> +	smm_property->name_size = name_size;
> +	efi_memcpy_runtime(smm_property->name, variable_name, name_size);
> +
> +	ret = mm_communicate(comm_buf, payload_size);
> +	/*
> +	 * Currently only R/O property is supported in StMM.
> +	 * Variables that are not set to R/O will not set the property in StMM
> +	 * and the call will return EFI_NOT_FOUND. We are setting the
> +	 * properties to 0x0 so checking against that is enough for the
> +	 * EFI_NOT_FOUND case.
> +	 */
> +	if (ret == EFI_NOT_FOUND)
> +		return EFI_SUCCESS;
> +	if (ret != EFI_SUCCESS)
> +		return ret;
> +	efi_memcpy_runtime(var_property, &smm_property->property, sizeof(*var_property));
> +
> +	return EFI_SUCCESS;
> +}
> +
>  efi_status_t efi_get_variable_int(const u16 *variable_name,
>  				  const efi_guid_t *vendor,
>  				  u32 *attributes, efi_uintn_t *data_size,
> @@ -1001,7 +1076,7 @@ efi_status_t efi_set_variable_int(const u16 *variable_name,
>  		var_property.property |= VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;
>  		var_property.attributes = attributes;
>  		var_property.minsize = 1;
> -		var_property.maxsize = var_acc->data_size;
> +		var_property.maxsize = data_size;
>  		ret = set_property_int(variable_name, name_size, vendor, &var_property);
>  	}
>
> @@ -1078,7 +1153,7 @@ efi_query_variable_info_runtime(u32 attributes, u64 *max_variable_storage_size,
>  }
>
>  /**
> - * efi_set_variable_runtime() - runtime implementation of SetVariable()
> + * efi_set_variable_int_runtime() - runtime implementation of SetVariable()
>   *
>   * @variable_name:	name of the variable
>   * @guid:		vendor GUID
> @@ -1088,11 +1163,69 @@ efi_query_variable_info_runtime(u32 attributes, u64 *max_variable_storage_size,
>   * Return:		status code
>   */
>  static efi_status_t __efi_runtime EFIAPI
> -efi_set_variable_runtime(u16 *variable_name, const efi_guid_t *guid,
> -			 u32 attributes, efi_uintn_t data_size,
> -			 const void *data)
> +efi_set_variable_int_runtime(u16 *variable_name, const efi_guid_t *guid,
> +			     u32 attributes, efi_uintn_t data_size,
> +			     const void *data)
>  {
> -	return EFI_UNSUPPORTED;
> +	efi_status_t ret, mm_communicate_ret = EFI_SUCCESS;
> +	struct var_check_property var_property;
> +	struct smm_variable_access *var_acc;
> +	efi_uintn_t payload_size;
> +	efi_uintn_t name_size;
> +	u8 *comm_buf = NULL;
> +	bool ro;
> +
> +	if (!variable_name || variable_name[0] == 0 || !guid)
> +		return EFI_INVALID_PARAMETER;
> +
> +	if (data_size > 0 && !data)
> +		return EFI_INVALID_PARAMETER;
> +
> +	/* Check payload size */
> +	name_size = u16_strsize(variable_name);
> +	payload_size = MM_VARIABLE_ACCESS_HEADER_SIZE + name_size + data_size;
> +	if (payload_size > max_payload_size)
> +		return EFI_INVALID_PARAMETER;
> +
> +	ro = !!(attributes & EFI_VARIABLE_READ_ONLY);
> +	attributes &= EFI_VARIABLE_MASK;
> +
> +	ret = get_property_int_runtime(variable_name, name_size, guid,
> +				       &var_property);
> +	if (ret != EFI_SUCCESS)
> +		return ret;
> +
> +	if (var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY)
> +		return EFI_WRITE_PROTECTED;
> +
> +	comm_buf = setup_mm_hdr((void **)&var_acc, payload_size,
> +				SMM_VARIABLE_FUNCTION_SET_VARIABLE, &ret);
> +	if (!comm_buf)
> +		return ret;
> +
> +	/* Fill in contents */
> +	efi_memcpy_runtime(&var_acc->guid, guid, sizeof(*guid));
> +	var_acc->data_size = data_size;
> +	var_acc->name_size = name_size;
> +	var_acc->attr = attributes;
> +	efi_memcpy_runtime(var_acc->name, variable_name, name_size);
> +	efi_memcpy_runtime((u8 *)var_acc->name + name_size, data, data_size);
> +
> +	/* Communicate */
> +	ret = mm_communicate(comm_buf, payload_size);
> +	if (ret != EFI_SUCCESS)
> +		mm_communicate_ret = ret;
> +
> +	if (ro && !(var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY)) {
> +		var_property.revision = VAR_CHECK_VARIABLE_PROPERTY_REVISION;
> +		var_property.property |= VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;
> +		var_property.attributes = attributes;
> +		var_property.minsize = 1;
> +		var_property.maxsize = data_size;
> +		ret = set_property_int_runtime(variable_name, name_size, guid, &var_property);
> +	}
> +
> +	return (mm_communicate_ret == EFI_SUCCESS) ? ret : mm_communicate_ret;
>  }
>
>  /**
> @@ -1129,7 +1262,7 @@ void efi_variables_boot_exit_notify(void)
>  	efi_runtime_services.get_variable = efi_get_variable_runtime;
>  	efi_runtime_services.get_next_variable_name =
>  			efi_get_next_variable_name_runtime;


All the get_variable*() calls used to point to the function from efi_var_common.c.
By changing this you are breaking the runtime case for OP-TEE since now we will get
EFI_OUT_OF_RESOURCES.
There's no easy way to fix this at runtime. For OP-TEE the kernel might replace this call
with an internal OP-TEE call if it's part of the firmware and announces it can provide
EFI runtime services. However, the default uuse case, which we don't support SetVariable
at runtime only needs to keep working.

I'll post a script next week so you can replicate and test this in QEMU with OP-TEE etc.

Cheers
/Ilias

> -	efi_runtime_services.set_variable = efi_set_variable_runtime;
> +	efi_runtime_services.set_variable = efi_set_variable_int_runtime;
>  	efi_update_table_header_crc32(&efi_runtime_services.hdr);
>
>  	/* Record that ExitBootServices() has been called */


  reply	other threads:[~2026-09-18 18:20 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 11:00 [PATCH v5 00/22] arm64: FF-A runtime transport for EFI variables Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 01/22] efi_loader: add runtime memset helper Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 02/22] arm-ffa: store boot-discovered runtime data separately Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 03/22] arm-ffa: add runtime-safe FF-A SMC wrapper Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 04/22] arm-ffa: add runtime direct-message support Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 05/22] arm-ffa: reuse direct-message helper at boot time Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 06/22] arm-ffa: enable runtime context at ExitBootServices Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 07/22] arm: cache: keep range maintenance available at EFI runtime Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 08/22] efi_loader: add MM SP status mapping for FF-A variables Harsimran Singh Tungal
2026-09-18 17:19   ` Ilias Apalodimas
2026-09-14 11:00 ` [PATCH v5 09/22] efi_loader: make MM transport selection runtime-safe Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 10/22] efi_loader: make FF-A MM SP notification runtime-safe Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 11/22] efi_loader: make FF-A MM communication runtime-safe Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 12/22] efi_loader: reserve FF-A shared buffer for runtime variables Harsimran Singh Tungal
2026-09-18 18:30   ` Ilias Apalodimas
2026-10-05 11:12     ` Harsimran Singh Tungal
2026-10-05 11:51       ` Ilias Apalodimas
2026-09-14 11:00 ` [PATCH v5 13/22] efi_loader: enable TEE runtime SetVariable() over FF-A Harsimran Singh Tungal
2026-09-18 18:20   ` Ilias Apalodimas [this message]
2026-10-05 13:06     ` Harsimran Singh Tungal
2026-10-05 13:15       ` Ilias Apalodimas
2026-10-08 17:32         ` Harsimran Singh Tungal
2026-10-09  8:19           ` Ilias Apalodimas
2026-10-09 11:08             ` Harsimran Singh Tungal
2026-10-09 11:15               ` Ilias Apalodimas
2026-10-09 13:25                 ` Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 14/22] efi_loader: enable TEE runtime GetVariable() " Harsimran Singh Tungal
2026-09-14 11:00 ` [PATCH v5 15/22] efi_loader: enable TEE runtime GetNextVariableName() " Harsimran Singh Tungal
2026-09-14 11:01 ` [PATCH v5 16/22] efi_loader: enable TEE runtime QueryVariableInfo() " Harsimran Singh Tungal
2026-09-14 11:01 ` [PATCH v5 17/22] charset: mark u16_strsize() as __efi_runtime Harsimran Singh Tungal
2026-09-14 11:01 ` [PATCH v5 18/22] corstone1000: enable bootefi selftest Harsimran Singh Tungal
2026-09-14 11:01 ` [PATCH v5 19/22] efi: selftest: add runtime variable tests with non-volatile storage Harsimran Singh Tungal
2026-09-14 11:01 ` [PATCH v5 20/22] test: dm: add sandbox FF-A runtime transport tests Harsimran Singh Tungal
2026-09-14 11:01 ` [PATCH v5 21/22] doc: arm64: document FF-A runtime path for EFI variables Harsimran Singh Tungal
2026-09-14 11:01 ` [PATCH v5 22/22] doc: bootefi: note two-phase runtime variables selftest Harsimran Singh Tungal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DLINF8X5LGMM.22DVNGKNPMAM8@linaro.org \
    --to=ilias.apalodimas@linaro.org \
    --cc=Devaraj.Ranganna@arm.com \
    --cc=abdellatif.elkhlifi@arm.com \
    --cc=harsimransingh.tungal@arm.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.