From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EF467EB64D7 for ; Wed, 21 Jun 2023 06:22:05 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D3321860CF; Wed, 21 Jun 2023 08:22: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=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="m1/ubMRX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D05E986168; Wed, 21 Jun 2023 08:22:00 +0200 (CEST) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) (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 D3E42860B4 for ; Wed, 21 Jun 2023 08:21:57 +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-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-51a20138617so7553235a12.2 for ; Tue, 20 Jun 2023 23:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687328517; x=1689920517; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7SQuEJ21HVsBisJJ0y8+LJlGuNYjayRxmELBOMLD8zE=; b=m1/ubMRX1y65/N2eFo0Pw9LlwsVbJUdWzHPaFiSsWFPjsxu/AYDSOZ918yRUEX1hNn ghC4E+BapuzafqzsV6Ngs/RbU2pq7jOZw43V18VJSWjtcS3bFIngom+1hbMAUrG2rsH/ rY/x0dIMmKq4wkpfVnSCAMFYI/QH9942860I+PG+FAdxxFgu+wqu2iJ+SEG15KFNRJU7 iNBfBF9PIfE9mQ7pvS4xq5BUZfaq4TJLB/jzX5PNVLz+l5c+UG5t9ww9LWjc0+pQHDcT mgmiwX/GR5xSrikCzX7L93OMCGYro/xlTl7CAfhSo5m0AN7UvJfk131m3FLkFBafpI7J ECbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687328517; x=1689920517; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7SQuEJ21HVsBisJJ0y8+LJlGuNYjayRxmELBOMLD8zE=; b=DaDHCfUbchsAae/7YMWReZTwM7Rwqdf8kCplTsi9Uhh2mT8LbEhk56NmrjnACfiRLS Oz3lWIzEnHFpY6bwtOxA37I22GLB8aFw+oI2oiGYDXpMRZPiELRUKH6zTADQUBnNpEcu vKFPv9xPaW/fvylEyiJIRmQFaNZIP4nyfL2/Rce4mNBVtKabYsEuTKszjt1OMWgCFd9f XfSKDmvw2py2ONLHwttWqrd+LecJrIyCaYdV50BvWRmTnyUQObY6zgTDkvUbvS+xumOe CJ8yzya6XIoQC9uG4g1D2PfVIgf/F9u+yge5K+ga/Y6/Y+3q1e8oZhATeIdGRJiVaYyG 9B5Q== X-Gm-Message-State: AC+VfDxGkf08pHzJnKULmBe6iy9VIe9nsbh8lghnu5oDY5oTwrr/0GTA DPi1C4aBIByXR3Ze/GQcL4aK7Q== X-Google-Smtp-Source: ACHHUZ7ks6VPmizV325t8ZmEDKhTtO/7f4YqWlKvjWfRL2yK1W1EcljtBDkO+L2QrQjv4K/SoIzBmg== X-Received: by 2002:a05:6402:1a37:b0:51a:4042:6b0a with SMTP id be23-20020a0564021a3700b0051a40426b0amr8419767edb.4.1687328517258; Tue, 20 Jun 2023 23:21:57 -0700 (PDT) Received: from hera (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id o4-20020aa7d3c4000000b0051632dc69absm2062249edr.86.2023.06.20.23.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 23:21:56 -0700 (PDT) Date: Wed, 21 Jun 2023 09:21:54 +0300 From: Ilias Apalodimas To: Abdellatif El Khlifi Cc: trini@konsulko.com, nd@arm.com, sjg@chromium.org, u-boot@lists.denx.de, achin.gupta@arm.com, jens.wiklander@linaro.org, xueliang.zhong@arm.com, Drew.Reed@arm.com, Gowtham Suresh Kumar Subject: Re: [PATCH v13 09/10] arm_ffa: efi: introduce FF-A MM communication Message-ID: References: <20230606134856.GA1871110@bill-the-cat> <20230616152817.319869-1-abdellatif.elkhlifi@arm.com> <20230616152817.319869-10-abdellatif.elkhlifi@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230616152817.319869-10-abdellatif.elkhlifi@arm.com> 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 Hi Abdellatif, On Fri, Jun 16, 2023 at 04:28:16PM +0100, Abdellatif El Khlifi wrote: > Add MM communication support using FF-A transport > > This feature allows accessing MM partitions services through > EFI MM communication protocol. MM partitions such as StandAlonneMM > or smm-gateway secure partitions which reside in secure world. > > An MM shared buffer and a door bell event are used to exchange > the data. > > The data is used by EFI services such as GetVariable()/SetVariable() > and copied from the communication buffer to the MM shared buffer. > > The secure partition is notified about availability of data in the > MM shared buffer by an FF-A message (door bell). > > On such event, MM SP can read the data and updates the MM shared > buffer with the response data. > > The response data is copied back to the communication buffer and > consumed by the EFI subsystem. > > MM communication protocol supports FF-A 64-bit direct messaging. > > Signed-off-by: Abdellatif El Khlifi > Signed-off-by: Gowtham Suresh Kumar > Cc: Tom Rini > Cc: Simon Glass > Cc: Ilias Apalodimas > Cc: Jens Wiklander > > --- > > Changelog: > =============== > > v13: > > * remove FF-A and Optee ifdefs Thanks this looks a lot saner now. I got one last nit and I think this patch is ready > + * Return: > + * > + * 0 on success > + */ > +static int ffa_notify_mm_sp(void) > +{ > + struct ffa_send_direct_data msg = {0}; > + int ret; > + int sp_event_ret = -1; > + struct udevice *dev; > + > + ret = uclass_first_device_err(UCLASS_FFA, &dev); > + if (ret) { > + log_err("EFI: Cannot find FF-A bus device, notify MM SP failure\n"); > + return ret; > + } > + > + msg.data0 = FFA_SHARED_MM_BUFFER_OFFSET; /* x3 */ > + > + ret = ffa_sync_send_receive(dev, mm_sp_id, &msg, 1); > + if (ret) > + return ret; > + > + sp_event_ret = msg.data0; /* x3 */ > + > + if (sp_event_ret == MM_SUCCESS) > + return 0; > + > + /* Failure to notify the MM SP */ > + > + return -EACCES; Doesn't FFA and the SMM_GATEWAY have discrete returns results that would make more sense? Your other patches only define MM_SUCCESS but in ffa_mm_communicate() you are trying to map ernnos to EFI return codes. I think we should map errnos to ffa errors as well in a similar fashion. You can look at optee_mm_communicate() which already does that. > +} > + > +/** > + * ffa_discover_mm_sp_id() - Query the MM partition ID > + * > +/** > + * get_mm_comms() - detect the available MM transport > + * > + * Make sure the FF-A bus is probed successfully > + * which means FF-A communication with secure world works and ready > + * for use. > + * > + * If FF-A bus is not ready, use OPTEE comms. > + * > + * Return: > + * > + * MM_COMMS_FFA or MM_COMMS_OPTEE > + */ > +static enum mm_comms_select get_mm_comms(void) > +{ > + struct udevice *dev; > + int ret; > + > + ret = uclass_first_device_err(UCLASS_FFA, &dev); > + if (ret) { > + log_err("EFI: Cannot find FF-A bus device, trying Optee comms\n"); > + return MM_COMMS_OPTEE; > + } > + > + return MM_COMMS_FFA; > +} > + > +/** > + * mm_communicate() - Adjust the communication buffer to the MM SP and send > * it to OP-TEE > * > - * @comm_buf: locally allocted communcation buffer > + * @comm_buf: locally allocated communication buffer > * @dsize: buffer size > + * > + * The SP (also called partition) can be any MM SP such as StandAlonneMM or smm-gateway. > + * The comm_buf format is the same for both partitions. > + * When using the u-boot OP-TEE driver, StandAlonneMM is supported. > + * When using the u-boot FF-A driver, any MM SP is supported. > + * > * Return: status code > */ > static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize) > { > efi_status_t ret; > + enum mm_comms_select mm_comms; > struct efi_mm_communicate_header *mm_hdr; > struct smm_variable_communicate_header *var_hdr; > > @@ -162,7 +400,12 @@ static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize) > mm_hdr = (struct efi_mm_communicate_header *)comm_buf; > var_hdr = (struct smm_variable_communicate_header *)mm_hdr->data; > > - ret = optee_mm_communicate(comm_buf, dsize); > + mm_comms = get_mm_comms(); > + if (mm_comms == MM_COMMS_FFA) > + ret = ffa_mm_communicate(comm_buf, dsize); > + else > + ret = optee_mm_communicate(comm_buf, dsize); > + > if (ret != EFI_SUCCESS) { > log_err("%s failed!\n", __func__); > return ret; > @@ -232,6 +475,7 @@ static u8 *setup_mm_hdr(void **dptr, efi_uintn_t payload_size, > */ > efi_status_t EFIAPI get_max_payload(efi_uintn_t *size) > { > + enum mm_comms_select mm_comms; > struct smm_variable_payload_size *var_payload = NULL; > efi_uintn_t payload_size; > u8 *comm_buf = NULL; > @@ -258,6 +502,12 @@ efi_status_t EFIAPI get_max_payload(efi_uintn_t *size) > goto out; > } > *size = var_payload->size; > + > + mm_comms = get_mm_comms(); > + if (mm_comms == MM_COMMS_FFA && *size > FFA_SHARED_MM_BUFFER_SIZE) > + *size = FFA_SHARED_MM_BUFFER_SIZE - MM_COMMUNICATE_HEADER_SIZE - > + MM_VARIABLE_COMMUNICATE_SIZE; > + Can you please move this check? The check preceding this is generic -- it tries to make sure there's space for at least a variable. This is ffa specific, so is there any reason ffa_mm_communicate() doesn't return the corrected size? > /* > * There seems to be a bug in EDK2 miscalculating the boundaries and > * size checks, so deduct 2 more bytes to fulfill this requirement. Fix > @@ -697,7 +947,7 @@ void efi_variables_boot_exit_notify(void) > ret = EFI_NOT_FOUND; > > if (ret != EFI_SUCCESS) > - log_err("Unable to notify StMM for ExitBootServices\n"); > + log_err("Unable to notify the MM partition for ExitBootServices\n"); > free(comm_buf); > > /* > -- > 2.25.1 > Thanks /Ilias