linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sumit Garg <sumit.garg@linaro.org>
To: Jens Wiklander <jens.wiklander@linaro.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	OP-TEE TrustedFirmware <op-tee@lists.trustedfirmware.org>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Marc Bonnici <marc.bonnici@arm.com>,
	Jerome Forissier <jerome@forissier.org>,
	Sughosh Ganu <sughosh.ganu@linaro.org>
Subject: Re: [PATCH v3 2/5] optee: simplify optee_release()
Date: Wed, 28 Jul 2021 14:15:47 +0530	[thread overview]
Message-ID: <CAFA6WYOJ6At7p21UuWNp8k4=Qwcb_2VFuV78Z9hksyW76p-fKA@mail.gmail.com> (raw)
In-Reply-To: <20210722121757.1944658-3-jens.wiklander@linaro.org>

On Thu, 22 Jul 2021 at 17:48, Jens Wiklander <jens.wiklander@linaro.org> wrote:
>
> Simplifies optee_release() with a new helper function,
> optee_close_session_helper() which has been factored out from
> optee_close_session().
>

Simplification looks good to me.

> A separate optee_release_supp() is added for the supplicant device.
>

On similar terms, can we have separate optee_open_supp() for better
understanding?

-Sumit

> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
> ---
>  drivers/tee/optee/call.c          | 31 ++++++++++-------
>  drivers/tee/optee/core.c          | 55 +++++++++++--------------------
>  drivers/tee/optee/optee_private.h |  1 +
>  3 files changed, 39 insertions(+), 48 deletions(-)
>
> diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c
> index 6e6eb836e9b6..9d8f5a95e42f 100644
> --- a/drivers/tee/optee/call.c
> +++ b/drivers/tee/optee/call.c
> @@ -288,12 +288,28 @@ int optee_open_session(struct tee_context *ctx,
>         return rc;
>  }
>
> -int optee_close_session(struct tee_context *ctx, u32 session)
> +int optee_close_session_helper(struct tee_context *ctx, u32 session)
>  {
> -       struct optee_context_data *ctxdata = ctx->data;
>         struct tee_shm *shm;
>         struct optee_msg_arg *msg_arg;
>         phys_addr_t msg_parg;
> +
> +       shm = get_msg_arg(ctx, 0, &msg_arg, &msg_parg);
> +       if (IS_ERR(shm))
> +               return PTR_ERR(shm);
> +
> +       msg_arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION;
> +       msg_arg->session = session;
> +       optee_do_call_with_arg(ctx, msg_parg);
> +
> +       tee_shm_free(shm);
> +
> +       return 0;
> +}
> +
> +int optee_close_session(struct tee_context *ctx, u32 session)
> +{
> +       struct optee_context_data *ctxdata = ctx->data;
>         struct optee_session *sess;
>
>         /* Check that the session is valid and remove it from the list */
> @@ -306,16 +322,7 @@ int optee_close_session(struct tee_context *ctx, u32 session)
>                 return -EINVAL;
>         kfree(sess);
>
> -       shm = get_msg_arg(ctx, 0, &msg_arg, &msg_parg);
> -       if (IS_ERR(shm))
> -               return PTR_ERR(shm);
> -
> -       msg_arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION;
> -       msg_arg->session = session;
> -       optee_do_call_with_arg(ctx, msg_parg);
> -
> -       tee_shm_free(shm);
> -       return 0;
> +       return optee_close_session_helper(ctx, session);
>  }
>
>  int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
> diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> index ddb8f9ecf307..949223b214c3 100644
> --- a/drivers/tee/optee/core.c
> +++ b/drivers/tee/optee/core.c
> @@ -263,59 +263,42 @@ static int optee_open(struct tee_context *ctx)
>         return 0;
>  }
>
> -static void optee_release(struct tee_context *ctx)
> +static void optee_release_helper(struct tee_context *ctx,
> +                                int (*close_session)(struct tee_context *ctx,
> +                                                     u32 session))
>  {
>         struct optee_context_data *ctxdata = ctx->data;
> -       struct tee_device *teedev = ctx->teedev;
> -       struct optee *optee = tee_get_drvdata(teedev);
> -       struct tee_shm *shm;
> -       struct optee_msg_arg *arg = NULL;
> -       phys_addr_t parg;
>         struct optee_session *sess;
>         struct optee_session *sess_tmp;
>
>         if (!ctxdata)
>                 return;
>
> -       shm = tee_shm_alloc(ctx, sizeof(struct optee_msg_arg), TEE_SHM_MAPPED);
> -       if (!IS_ERR(shm)) {
> -               arg = tee_shm_get_va(shm, 0);
> -               /*
> -                * If va2pa fails for some reason, we can't call into
> -                * secure world, only free the memory. Secure OS will leak
> -                * sessions and finally refuse more sessions, but we will
> -                * at least let normal world reclaim its memory.
> -                */
> -               if (!IS_ERR(arg))
> -                       if (tee_shm_va2pa(shm, arg, &parg))
> -                               arg = NULL; /* prevent usage of parg below */
> -       }
> -
>         list_for_each_entry_safe(sess, sess_tmp, &ctxdata->sess_list,
>                                  list_node) {
>                 list_del(&sess->list_node);
> -               if (!IS_ERR_OR_NULL(arg)) {
> -                       memset(arg, 0, sizeof(*arg));
> -                       arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION;
> -                       arg->session = sess->session_id;
> -                       optee_do_call_with_arg(ctx, parg);
> -               }
> +               close_session(ctx, sess->session_id);
>                 kfree(sess);
>         }
>         kfree(ctxdata);
> +       ctx->data = NULL;
> +}
>
> -       if (!IS_ERR(shm))
> -               tee_shm_free(shm);
> +static void optee_release(struct tee_context *ctx)
> +{
> +       optee_release_helper(ctx, optee_close_session_helper);
> +}
>
> -       ctx->data = NULL;
> +static void optee_release_supp(struct tee_context *ctx)
> +{
> +       struct optee *optee = tee_get_drvdata(ctx->teedev);
>
> -       if (teedev == optee->supp_teedev) {
> -               if (optee->scan_bus_wq) {
> -                       destroy_workqueue(optee->scan_bus_wq);
> -                       optee->scan_bus_wq = NULL;
> -               }
> -               optee_supp_release(&optee->supp);
> +       optee_release_helper(ctx, optee_close_session_helper);
> +       if (optee->scan_bus_wq) {
> +               destroy_workqueue(optee->scan_bus_wq);
> +               optee->scan_bus_wq = NULL;
>         }
> +       optee_supp_release(&optee->supp);
>  }
>
>  static const struct tee_driver_ops optee_ops = {
> @@ -339,7 +322,7 @@ static const struct tee_desc optee_desc = {
>  static const struct tee_driver_ops optee_supp_ops = {
>         .get_version = optee_get_version,
>         .open = optee_open,
> -       .release = optee_release,
> +       .release = optee_release_supp,
>         .supp_recv = optee_supp_recv,
>         .supp_send = optee_supp_send,
>         .shm_register = optee_shm_register_supp,
> diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
> index e25b216a14ef..2b63b796645e 100644
> --- a/drivers/tee/optee/optee_private.h
> +++ b/drivers/tee/optee/optee_private.h
> @@ -152,6 +152,7 @@ u32 optee_do_call_with_arg(struct tee_context *ctx, phys_addr_t parg);
>  int optee_open_session(struct tee_context *ctx,
>                        struct tee_ioctl_open_session_arg *arg,
>                        struct tee_param *param);
> +int optee_close_session_helper(struct tee_context *ctx, u32 session);
>  int optee_close_session(struct tee_context *ctx, u32 session);
>  int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
>                       struct tee_param *param);
> --
> 2.31.1
>

  reply	other threads:[~2021-07-28  8:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22 12:17 [PATCH v3 0/5] Add FF-A support in OP-TEE driver Jens Wiklander
2021-07-22 12:17 ` [PATCH v3 1/5] tee: add sec_world_id to struct tee_shm Jens Wiklander
2021-07-28  8:41   ` Sumit Garg
2021-07-22 12:17 ` [PATCH v3 2/5] optee: simplify optee_release() Jens Wiklander
2021-07-28  8:45   ` Sumit Garg [this message]
2021-07-29  6:43     ` Jens Wiklander
2021-07-29  7:10       ` Sumit Garg
2021-07-22 12:17 ` [PATCH v3 3/5] optee: refactor driver with internal callbacks Jens Wiklander
2021-07-28  9:59   ` Sumit Garg
2021-07-29  6:56     ` Jens Wiklander
2021-07-29  7:15       ` Sumit Garg
2021-07-22 12:17 ` [PATCH v3 4/5] optee: isolate smc abi Jens Wiklander
2021-07-28 10:10   ` Sumit Garg
2021-07-29  7:10     ` Jens Wiklander
2021-07-22 12:17 ` [PATCH v3 5/5] optee: add FF-A support Jens Wiklander
2021-07-26 10:29 ` [PATCH v3 0/5] Add FF-A support in OP-TEE driver Sumit Garg
2021-07-26 10:54   ` Sudeep Holla
2021-07-26 11:41     ` Sumit Garg
2021-07-26 15:25       ` Jens Wiklander
2021-07-27  6:13         ` Sumit Garg
2021-07-28  6:40           ` Jens Wiklander
2021-07-28 10:22             ` Sumit Garg

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='CAFA6WYOJ6At7p21UuWNp8k4=Qwcb_2VFuV78Z9hksyW76p-fKA@mail.gmail.com' \
    --to=sumit.garg@linaro.org \
    --cc=jens.wiklander@linaro.org \
    --cc=jerome@forissier.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.bonnici@arm.com \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=sudeep.holla@arm.com \
    --cc=sughosh.ganu@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;
as well as URLs for NNTP newsgroup(s).