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 09/13] optee: add support for arbitrary shared memory
Date: Tue, 11 Sep 2018 14:37:07 +0100	[thread overview]
Message-ID: <1eb0ed93-4dc9-3650-2681-f69d2c47baa9@arm.com> (raw)
In-Reply-To: <ee29941b-f838-3b93-1bab-d7a82c563be2@epam.com>

Hi Volodymyr,

On 10/09/18 19:04, Volodymyr Babchuk wrote:
> On 10.09.18 17:02, Julien Grall wrote:
>> On 03/09/18 17:54, Volodymyr Babchuk wrote:
>>> +    struct {
>>> +        uint64_t pages_list[PAGELIST_ENTRIES_PER_PAGE];
>>> +        uint64_t next_page_data;
>>> +    } *pages_data_guest, *pages_data_xen, *pages_data_xen_start;
>>> +    struct shm_buf *shm_buf;
>>> +
>>> +    page_offset = param->u.tmem.buf_ptr & 
>>> (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1);
>>> +
>>> +    size = ROUNDUP(param->u.tmem.size + page_offset,
>>> +                   OPTEE_MSG_NONCONTIG_PAGE_SIZE);
>>> +
>>> +    num_pages = DIV_ROUND_UP(size, OPTEE_MSG_NONCONTIG_PAGE_SIZE);
>>> +
>>> +    order = get_order_from_bytes(get_pages_list_size(num_pages));
>>> +
>>> +    pages_data_xen_start = alloc_xenheap_pages(order, 0);
>>
>> This could be replaced by a _xmalloc and would avoid to allocate more 
>> memory than necessary when the order is getting bigger.
> Thanks. Would it allocate page-aligned buffer?  This is crucial in this 
> case. I can't find any documentation on it so I don't know which 
> alignment it guarantees.

_xmalloc takes in argument the alignment required for the allocation.

> 
>>
>>> +    if ( !pages_data_xen_start )
>>> +        return false;
>>> +
>>> +    shm_buf = allocate_shm_buf(ctx, param->u.tmem.shm_ref, num_pages);
>>
>> In alocate_shm_buf you are now globally limiting the number of pages ( 
>> (16384) to pin. However, this does not limit per call.
>>
>> With the current limit, you would could call up to 16384 times 
>> lookup_and_pin_guest_ram_addr(...). On Arm, for p2m related operation, 
>> we limit to 512 iterations in one go before checking the preemption.
>> So I think 16384 times is far too much.
> So, in other words, I can translate only 2MB buffer (if 4096KB pages are 
> used), is it right?

2MB for the whole command. So if you have 5 buffer in the command, then 
the sum of the buffer should not be bigger than 2MB.

However, 2MB might be too big considering that you also need to account 
the SMC call. Does buffer can be passed for fast call?

> I think, it will be okay to implement such limitation for this initial
> version of mediator. In the future, it would be possible to do RPC 
> return from XEN (as OP-TEE does) to finish this request later.
> 
>>
>>> +    if ( !shm_buf )
>>> +        goto err_free;
>>> +
>>> +    gaddr = param->u.tmem.buf_ptr & ~(OPTEE_MSG_NONCONTIG_PAGE_SIZE 
>>> - 1);
>>> +    guest_mfn = lookup_and_pin_guest_ram_addr(gaddr, NULL);
>>> +    if ( mfn_eq(guest_mfn, INVALID_MFN) )
>>> +        goto err_free;
>>> +
>>> +    pages_data_guest = map_domain_page(guest_mfn);
>>> +    if ( !pages_data_guest )
>>> +        goto err_free;
>>> +
>>> +    pages_data_xen = pages_data_xen_start;
>>> +    while ( num_pages ) {
>>> +        struct page_info *page;
>>> +        mfn_t entry_mfn = lookup_and_pin_guest_ram_addr(
>>> +            pages_data_guest->pages_list[entries_on_page], &page);
>>> +
>>> +        if ( mfn_eq(entry_mfn, INVALID_MFN) )
>>> +            goto err_unmap;
>>> +
>>> +        shm_buf->pages[shm_buf->page_cnt++] = page;
>>> +        pages_data_xen->pages_list[entries_on_page] = 
>>> mfn_to_maddr(entry_mfn);
>>> +        entries_on_page++;
>>> +
>>> +        if ( entries_on_page == PAGELIST_ENTRIES_PER_PAGE ) {
>>> +            pages_data_xen->next_page_data = 
>>> virt_to_maddr(pages_data_xen + 1);
>>> +            pages_data_xen++;
>>> +            gaddr = pages_data_guest->next_page_data;
>>
>> next_page_data is not a guest address but a machine address. For 
>> anything related to address, the variable should be named accordingly 
>> to avoid confusion.
> Why? In this case it is IPA that comes from the guest.

Because I misread the variables.

>>> +
>>> +    unmap_domain_page(pages_data_guest);
>>> +    unpin_guest_ram_addr(guest_mfn);
>>> +    return true;
>>> +
>>> +err_unmap:
>>> +    unmap_domain_page(pages_data_guest);
>>> +    unpin_guest_ram_addr(guest_mfn);
>>> +    free_shm_buf(ctx, shm_buf->cookie);
>>> +
>>> +err_free:
>>> +    free_xenheap_pages(pages_data_xen_start, order);
>>> +
>>> +    return false;
>>> +}
>>> +
>>> +static bool translate_params(struct domain_ctx *ctx,
>>> +                             struct std_call_ctx *call)
>>> +{
>>> +    unsigned int i;
>>> +    uint32_t attr;
>>> +
>>> +    for ( i = 0; i < call->xen_arg->num_params; i++ ) {
>>
>> Please pay attention to Xen coding style. I haven't pointed out 
>> everywhere, but I would all of them to be fixed in the next version.
> Yes, I'm sorry for that. I simultaneously work  with different projects
> and sometimes it is hard to track coding style. I'll fix all such
> problems.

IIRC your team is working on the checkpatch. It might be worth using it 
to see how it performs on your series.

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:37 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 [this message]
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
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=1eb0ed93-4dc9-3650-2681-f69d2c47baa9@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.