mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Gavin Liu (劉哲廷)" <Gavin.Liu@mediatek.com>
To: "sumit.garg@linaro.org" <sumit.garg@linaro.org>
Cc: "jens.wiklander@linaro.org" <jens.wiklander@linaro.org>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"op-tee@lists.trustedfirmware.org"
	<op-tee@lists.trustedfirmware.org>
Subject: Re: [PATCH v3] optee: add timeout value to optee_notif_wait() to support timeout
Date: Tue, 21 May 2024 08:45:57 +0000	[thread overview]
Message-ID: <929512b561536d4ddfaeda518f2ce306b899f3a9.camel@mediatek.com> (raw)
In-Reply-To: <CAFA6WYN79E8Hyxsaxu20hkyNebMqBWV7az5ByekTuii7Y7qjng@mail.gmail.com>

Hi, Sumit,

The corresponding OPTEE-OS pull request and change is here.

https://github.com/OP-TEE/optee_os/pull/6641

On Mon, 2024-05-20 at 16:16 +0530, Sumit Garg wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  Hi,
> 
> On Tue, 7 May 2024 at 07:31, gavin.liu <gavin.liu@mediatek.com>
> wrote:
> >
> > From: Gavin Liu <gavin.liu@mediatek.com>
> >
> > Add timeout value to support self waking when timeout to avoid
> waiting
> > indefinitely.
> >
> > Signed-off-by: Gavin Liu <gavin.liu@mediatek.com>
> > ---
> > change in v3:
> > 1. change the comment in optee_rpc_cmd.h
> > 2. add macro for "TEE_ERROR_TIMEOUT"
> > 3. change from "TEEC_ERROR_BUSY" to "TEE_ERROR_TIMEOUT"
> > ---
> >  drivers/tee/optee/notif.c         |  9 +++++++--
> >  drivers/tee/optee/optee_private.h |  5 ++++-
> >  drivers/tee/optee/optee_rpc_cmd.h |  1 +
> >  drivers/tee/optee/rpc.c           | 10 ++++++++--
> >  4 files changed, 20 insertions(+), 5 deletions(-)
> >
> 
> Although the change looks reasonable to me, can you point me to
> corresponding OP-TEE OS changes to be sure that ABI compatibility is
> maintained?
> 
> -Sumit
> 
> > diff --git a/drivers/tee/optee/notif.c b/drivers/tee/optee/notif.c
> > index 0d7878e770cd..1970880c796f 100644
> > --- a/drivers/tee/optee/notif.c
> > +++ b/drivers/tee/optee/notif.c
> > @@ -29,7 +29,7 @@ static bool have_key(struct optee *optee, u_int
> key)
> >         return false;
> >  }
> >
> > -int optee_notif_wait(struct optee *optee, u_int key)
> > +int optee_notif_wait(struct optee *optee, u_int key, u32 timeout)
> >  {
> >         unsigned long flags;
> >         struct notif_entry *entry;
> > @@ -70,7 +70,12 @@ int optee_notif_wait(struct optee *optee, u_int
> key)
> >          * Unlock temporarily and wait for completion.
> >          */
> >         spin_unlock_irqrestore(&optee->notif.lock, flags);
> > -       wait_for_completion(&entry->c);
> > +       if (timeout != 0) {
> > +               if (!wait_for_completion_timeout(&entry->c,
> timeout))
> > +                       rc = -ETIMEDOUT;
> > +       } else {
> > +               wait_for_completion(&entry->c);
> > +       }
> >         spin_lock_irqsave(&optee->notif.lock, flags);
> >
> >         list_del(&entry->link);
> > diff --git a/drivers/tee/optee/optee_private.h
> b/drivers/tee/optee/optee_private.h
> > index 429cc20be5cc..424898cdc4e9 100644
> > --- a/drivers/tee/optee/optee_private.h
> > +++ b/drivers/tee/optee/optee_private.h
> > @@ -26,6 +26,9 @@
> >  #define TEEC_ERROR_BUSY                        0xFFFF000D
> >  #define TEEC_ERROR_SHORT_BUFFER                0xFFFF0010
> >
> > +/* API Return Codes are from the GP TEE Internal Core API
> Specification */
> > +#define TEE_ERROR_TIMEOUT              0xFFFF3001
> > +
> >  #define TEEC_ORIGIN_COMMS              0x00000002
> >
> >  /*
> > @@ -252,7 +255,7 @@ struct optee_call_ctx {
> >
> >  int optee_notif_init(struct optee *optee, u_int max_key);
> >  void optee_notif_uninit(struct optee *optee);
> > -int optee_notif_wait(struct optee *optee, u_int key);
> > +int optee_notif_wait(struct optee *optee, u_int key, u32 timeout);
> >  int optee_notif_send(struct optee *optee, u_int key);
> >
> >  u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t
> num_params,
> > diff --git a/drivers/tee/optee/optee_rpc_cmd.h
> b/drivers/tee/optee/optee_rpc_cmd.h
> > index f3f06e0994a7..4576751b490c 100644
> > --- a/drivers/tee/optee/optee_rpc_cmd.h
> > +++ b/drivers/tee/optee/optee_rpc_cmd.h
> > @@ -41,6 +41,7 @@
> >   * Waiting on notification
> >   * [in]    value[0].a      OPTEE_RPC_NOTIFICATION_WAIT
> >   * [in]    value[0].b      notification value
> > + * [in]    value[0].c      timeout in milliseconds or 0 if no
> timeout
> >   *
> >   * Sending a synchronous notification
> >   * [in]    value[0].a      OPTEE_RPC_NOTIFICATION_SEND
> > diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c
> > index f086812f1179..5de4504665be 100644
> > --- a/drivers/tee/optee/rpc.c
> > +++ b/drivers/tee/optee/rpc.c
> > @@ -130,6 +130,8 @@ static void
> handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
> >  static void handle_rpc_func_cmd_wq(struct optee *optee,
> >                                    struct optee_msg_arg *arg)
> >  {
> > +       int rc = 0;
> > +
> >         if (arg->num_params != 1)
> >                 goto bad;
> >
> > @@ -139,7 +141,8 @@ static void handle_rpc_func_cmd_wq(struct optee
> *optee,
> >
> >         switch (arg->params[0].u.value.a) {
> >         case OPTEE_RPC_NOTIFICATION_WAIT:
> > -               if (optee_notif_wait(optee, arg-
> >params[0].u.value.b))
> > +               rc = optee_notif_wait(optee, arg-
> >params[0].u.value.b, arg->params[0].u.value.c);
> > +               if (rc)
> >                         goto bad;
> >                 break;
> >         case OPTEE_RPC_NOTIFICATION_SEND:
> > @@ -153,7 +156,10 @@ static void handle_rpc_func_cmd_wq(struct
> optee *optee,
> >         arg->ret = TEEC_SUCCESS;
> >         return;
> >  bad:
> > -       arg->ret = TEEC_ERROR_BAD_PARAMETERS;
> > +       if (rc == -ETIMEDOUT)
> > +               arg->ret = TEE_ERROR_TIMEOUT;
> > +       else
> > +               arg->ret = TEEC_ERROR_BAD_PARAMETERS;
> >  }
> >
> >  static void handle_rpc_func_cmd_wait(struct optee_msg_arg *arg)
> > --
> > 2.18.0

Regards,
Gavin Liu
> >

  reply	other threads:[~2024-05-21  8:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-07  2:00 gavin.liu
2024-05-20 10:46 ` Sumit Garg
2024-05-21  8:45   ` Gavin Liu (劉哲廷) [this message]
2024-05-23  7:34     ` Sumit Garg
2024-05-31  6:55       ` Jens Wiklander

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=929512b561536d4ddfaeda518f2ce306b899f3a9.camel@mediatek.com \
    --to=gavin.liu@mediatek.com \
    --cc=jens.wiklander@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=sumit.garg@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®