All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Volodymyr Babchuk <volodymyr_babchuk@epam.com>,
	xen-devel@lists.xenproject.org, xen-devel@lists.xen.org
Cc: tee-dev@lists.linaro.org, Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v2 10/13] optee: add support for RPC commands
Date: Tue, 11 Sep 2018 14:56:30 +0100	[thread overview]
Message-ID: <a6e429fc-1147-13b5-86f0-7f4f23840b77@arm.com> (raw)
In-Reply-To: <3a15069f-59ef-8bfa-6143-56bc64c795bd@epam.com>



On 10/09/18 19:14, Volodymyr Babchuk wrote:
> On 10.09.18 18:34, Julien Grall wrote:
>> On 03/09/18 17:54, Volodymyr Babchuk wrote:
>>>   static struct shm_buf *allocate_shm_buf(struct domain_ctx *ctx,
>>>                                           uint64_t cookie,
>>>                                           int pages_cnt)
>>> @@ -704,6 +732,28 @@ static bool copy_std_request_back(struct 
>>> domain_ctx *ctx,
>>>       return true;
>>>   }
>>> +static void handle_rpc_return(struct domain_ctx *ctx,
>>> +                             struct cpu_user_regs *regs,
>>> +                             struct std_call_ctx *call)
>>> +{
>>> +    call->optee_thread_id = get_user_reg(regs, 3);
>>> +    call->rpc_op = OPTEE_SMC_RETURN_GET_RPC_FUNC(get_user_reg(regs, 
>>> 0));
>>> +
>>> +    if ( call->rpc_op == OPTEE_SMC_RPC_FUNC_CMD )
>>> +    {
>>> +        /* Copy RPC request from shadowed buffer to guest */
>>> +        uint64_t cookie = get_user_reg(regs, 1) << 32 | 
>>> get_user_reg(regs, 2);
>>> +        struct shm_rpc *shm_rpc = find_shm_rpc(ctx, cookie);
>>
>> Newline between declaration and code.
> Sorry, another habit from kernel coding style :(
I think you need to modify your habit because I am pretty sure Linux 
folks would not allow:

struct shm_rpc *rpc = find_shm(...);
if ( rpc )
   ...

The correct way is:

struct shm_rpc *rpc = find_shm(...);

if ( rpc )

Notice the newline between struct and if.

> 
>>> +        if ( !shm_rpc )
>>> +        {
>>> +            gprintk(XENLOG_ERR, "Can't find SHM-RPC with cookie 
>>> %lx\n", cookie);
>>> +            return;
>>> +        }
>>> +        memcpy(shm_rpc->guest_arg, shm_rpc->xen_arg,
>>> +               OPTEE_MSG_GET_ARG_SIZE(shm_rpc->xen_arg->num_params));
>>> +    }
>>> +}
>>> +
>>>   static bool execute_std_call(struct domain_ctx *ctx,
>>>                                struct cpu_user_regs *regs,
>>>                                struct std_call_ctx *call)
>>> @@ -715,8 +765,7 @@ static bool execute_std_call(struct domain_ctx *ctx,
>>>       optee_ret = get_user_reg(regs, 0);
>>>       if ( OPTEE_SMC_RETURN_IS_RPC(optee_ret) )
>>>       {
>>> -        call->optee_thread_id = get_user_reg(regs, 3);
>>> -        call->rpc_op = OPTEE_SMC_RETURN_GET_RPC_FUNC(optee_ret);
>>> +        handle_rpc_return(ctx, regs, call);
>>
>> It would make sense to introduce handle_rpc_return where you actually 
>> add those 2 lines.
>>
>>>           return true;
>>>       }
>>> @@ -783,6 +832,74 @@ out:
>>>       return ret;
>>>   }
>>> +
>>> +static void handle_rpc_cmd_alloc(struct domain_ctx *ctx,
>>> +                                 struct cpu_user_regs *regs,
>>> +                                 struct std_call_ctx *call,
>>> +                                 struct shm_rpc *shm_rpc)
>>> +{
>>> +    if ( shm_rpc->xen_arg->params[0].attr != 
>>> (OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT |
>>> +                                            OPTEE_MSG_ATTR_NONCONTIG) )
>>> +    {
>>> +        gprintk(XENLOG_WARNING, "Invalid attrs for shared mem 
>>> buffer\n");
>>> +        return;
>>> +    }
>>> +
>>> +    /* Last entry in non_contig array is used to hold RPC-allocated 
>>> buffer */
>>> +    if ( call->non_contig[MAX_NONCONTIG_ENTRIES - 1] )
>>> +    {
>>> +        free_xenheap_pages(call->non_contig[MAX_NONCONTIG_ENTRIES - 1],
>>> + call->non_contig_order[MAX_NONCONTIG_ENTRIES - 1]);
>>> +        call->non_contig[MAX_NONCONTIG_ENTRIES - 1] = NULL;
>>> +    }
>>
>> This is quite odd. Why don't you just deny allocating information in 
>> the non_config array? This would avoid to silently dropped any page 
>> that may have been linked together and potentially used still in use.
> No, this, actually is part of the protocol. OP-TEE can ask to allocate 
> more shared buffers, one per RPC return.

Please a give link to the spec and the paragraph.

> call->non_contig[x] is needed to hold list of pages until OP_TEE 
> consumes them. The it can be freed and reused to allocate next buffer.
> Consider this:

What is x?

> 
> 1. OP-TEE issues RPC "allocate buffer"
> 2. NW returns list of pages
> 3. Mediator translates and stores address in non_contig[x]
> 4. OP-TEE begins to consume this list
> 5. IRQ arrives and OP-TEE forced to break the work
> 6. Mediator receives control back, but it should not free non_contig[x],
>     because it is not sure of OP-TEE finished reading from it
> 7. Xen/guest handles the IRQ and returns control back to OP-TEE
> 8. OP-TEE finishes processing this buffers and asks for another one
> 9. NW returns list of pages for the next buffer
> 10. At this point mediator is sure that OP-TEE finished processing
>      old non_contig[x], so it can free it and allocated another.

Thank you for the description of the protocol. However, it is still does 
not explain why you decided to free MAX_NONCONTIG_ENTRIES - 1. Why not 0 
or 1 or n?

Overall, it feels like to me you want to write more documentation about 
how the mediator is supposed to work.


[...]

>> Please try to avoid changing the coding style in different patch. But 
>> this one is wrong.
> Yep :( this is the artifact from splitting the big patch.
> 
>>>               gprintk(XENLOG_WARNING, "Failed to allocate shm_rpc 
>>> object\n");
>>> -            ptr = 0;
>>> -        }
>>> -        else
>>> -            ptr = mfn_to_maddr(shm_rpc->guest_mfn);
>>> +            ptr = ~0;
>>
>> Can you explain why you change from 0 to ~0?
> I had to introduce this in the original patch, actually.

What do you mean?

Cheers,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-09-11 13:56 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03 16:54 [PATCH v2 00/13] TEE mediator (and OP-TEE) support in XEN Volodymyr Babchuk
2018-09-03 16:54 ` [PATCH v2 01/13] arm: add generic TEE mediator framework Volodymyr Babchuk
2018-09-03 17:22   ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 02/13] domctl: add tee_op domctl Volodymyr Babchuk
2018-09-03 17:16   ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 03/13] arm: tee: add OP-TEE header files Volodymyr Babchuk
2018-09-03 16:54 ` [PATCH v2 04/13] optee: add OP-TEE mediator skeleton Volodymyr Babchuk
2018-09-03 17:38   ` Julien Grall
2018-09-03 17:55     ` Volodymyr Babchuk
2018-09-04 19:48       ` Julien Grall
2018-09-05 12:17         ` Volodymyr Babchuk
2018-09-05 13:16           ` Julien Grall
2018-09-05 13:38             ` Volodymyr Babchuk
2018-09-05 13:47               ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 05/13] optee: add fast calls handling Volodymyr Babchuk
2018-09-05 13:36   ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 06/13] optee: add domain contexts Volodymyr Babchuk
2018-09-05 14:10   ` Julien Grall
2018-09-05 14:18     ` Andrew Cooper
2018-09-05 14:23     ` Volodymyr Babchuk
2018-09-05 14:27       ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 07/13] optee: add std call handling Volodymyr Babchuk
2018-09-05 15:17   ` Julien Grall
2018-09-10 17:37     ` Volodymyr Babchuk
2018-09-11 11:19       ` Julien Grall
2018-09-11 11:31         ` Volodymyr Babchuk
2018-09-11 13:30           ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 08/13] optee: add support for RPC SHM buffers Volodymyr Babchuk
2018-09-10 13:01   ` Julien Grall
2018-09-10 17:44     ` Volodymyr Babchuk
2018-09-11 11:53       ` Julien Grall
2018-09-11 19:30         ` Volodymyr Babchuk
2018-09-12 10:59           ` Julien Grall
2018-09-12 13:51             ` Volodymyr Babchuk
2018-09-18 16:11               ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 09/13] optee: add support for arbitrary shared memory Volodymyr Babchuk
2018-09-10 14:02   ` Julien Grall
2018-09-10 18:04     ` Volodymyr Babchuk
2018-09-11 13:37       ` Julien Grall
2018-09-11 19:33         ` Volodymyr Babchuk
2018-09-12 11:02           ` Julien Grall
2018-09-12 12:45             ` Volodymyr Babchuk
2018-09-18 16:19               ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 10/13] optee: add support for RPC commands Volodymyr Babchuk
2018-09-10 15:34   ` Julien Grall
2018-09-10 18:14     ` Volodymyr Babchuk
2018-09-11 13:56       ` Julien Grall [this message]
2018-09-11 18:58         ` Volodymyr Babchuk
2018-09-18 16:50           ` Julien Grall
2018-09-19 15:21             ` Volodymyr Babchuk
2018-09-03 16:54 ` [PATCH v2 11/13] libxc: add xc_dom_tee_enable(...) function Volodymyr Babchuk
2018-09-06 10:59   ` Wei Liu
2018-09-03 16:54 ` [PATCH v2 12/13] xl: add "tee" option for xl.cfg Volodymyr Babchuk
2018-09-11 14:23   ` Julien Grall
2018-09-03 16:54 ` [PATCH v2 13/13] lixl: arm: create optee firmware node in DT if tee=1 Volodymyr Babchuk
2018-09-11 14:48   ` Julien Grall

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=a6e429fc-1147-13b5-86f0-7f4f23840b77@arm.com \
    --to=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=tee-dev@lists.linaro.org \
    --cc=volodymyr_babchuk@epam.com \
    --cc=xen-devel@lists.xen.org \
    --cc=xen-devel@lists.xenproject.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 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.