[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 4/5] xen/arm: ffa: Add indirect message between VM


  • To: Jens Wiklander <jens.wiklander@xxxxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Mon, 24 Mar 2025 13:06:12 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FRbY7W6nBDQ/BsFocM18S6UTOukzomdPJfz7upo31T8=; b=Fd/1r/sqKbD4y3cf2Y8Cpey9RT0hVLqajESeDtQEBokqZvsprP8XSJiwfx9VfZRs5739NzS8eHY5OqLsktJ2TxFlymi2blMd9vLMQT6A44wo0ZjKanNZ8/sT3lugOJ3e4g/U4JWZiVZGcmwZdGrSqBXRxPWjxW2fYgqCrSO5bujILoAq8MViYDj0NJWGBmnGocKzeyY1tz8ifUDhNMH0oUNEj274W9jsh8jBgZwRT5S4kMyJTqwNaD9EMQbd7Uz3Mqj8wI3sZyhb3qkrMc42rGNaLC9LAunN0rJWM0ypKnz93tIDAejltP4qyLxWOxgVz6GeV24WDob+yTgJo9wI4A==
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FRbY7W6nBDQ/BsFocM18S6UTOukzomdPJfz7upo31T8=; b=hp/KPZ53uXkHmHOy2yuMkSokpqm6RLz9g0Mho3EmYIfINKYT1fj2x+RoHKIpZHdsgFF3EOU1wi7JFzGqu7N/9YlcE4vJcN7NN5jq+kfOQCiZH3noFe4+6DnuAVJTKEZ+R1UuYJgbD0P1z5nu1FWp+ZrJIE3qU7oW9Bcp766PMrIjEDM+RGLHjaQQ0dn6aC4dj5StP6RcqSWSJM2P2WVdosC5Ozs0+Zf+rh/pP0zLAKPa6AErIAi2bP7CZwP0nfbOGgLJxJqyGOiYnV/7FJqYT0gZcDVnN0/c0L3fusFv9NtyfI6nN446zb2eycsfNzDC0srRzTG7IXqiRkJFkQjCzw==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=SDDHbR72k7lDtorM8cJ3XAPitgI+ITVNHIH5/UdT2d7boc1YJryXbhq+aEIUiRxLW3F2BcaO/MpY3asFuj6R5SIc7DKdG9UyEDPHFgDjBhy6voC3xArzKcx/hhXZQul4uscmHyNu5Kxt/t/Wu/u8SkAbMv+n0qgfzK8nK7aHBzG+Sic6nzV0oqta1MUcZ1FzqMoJtIjSwL2Vcci6sw6PO9+NHbKxHYb9d88RVN7UikfZhD1Ur/JukVNL/38VCFN1/TGvJZW5e/M9ci9Ip5/ur20t9M4lmoQFX9hXeeix0WDmyb/NWxkiMn6qwWVY6fVk2rAWRYJmAnenPYwSCmEYYg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wqoeJpvFxVFT48KU2SU3dVM9TVLYaE1fYcHMOoy39fBIk2euyi6ptvUjSfYj/A0Ox4tgt3iap/ww2q3BH3ox/Mb1XRQgZrrzC+89uUQUgkf5gZytUrjIlYjzYKhyquaolIEgL/7MxDrV34PnIEYQMxPKmMjz2yCBEzHN0k1ak5aw5zINotZuMD15feqNl8ASfypaMFt/eGD7BnJh4GFBgFHNYmNiWQVTGljy5EXDbd/VNtLZ9Hy7wJvVjnb+wji6ISrqJ8OZ2/03MzLHdRvyFad+CBvV8EGunpASVTQ0mhPfx+HDu4c6JhWTn6ZZ5beuDxP1qD0482bkB6X0EkzW0Q==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Mon, 24 Mar 2025 13:06:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHbnJ1O44fIyxP5wE6DoPXuGC0lfrOCGXgAgAAoSgA=
  • Thread-topic: [PATCH v3 4/5] xen/arm: ffa: Add indirect message between VM

Hi Jens,

> On 24 Mar 2025, at 11:41, Jens Wiklander <jens.wiklander@xxxxxxxxxx> wrote:
> 
> Hi Bertrand,
> 
> On Mon, Mar 24, 2025 at 10:15 AM Bertrand Marquis
> <bertrand.marquis@xxxxxxx> wrote:
>> 
>> Add support for indirect messages between VMs.
>> This is only enabled if CONFIG_FFA_VM_TO_VM is selected.
>> 
>> Signed-off-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
>> ---
>> Changes in v3:
>> - Move vm to vm indirect message handling in a sub function to simplify
>>  lock handling and make implementation easier to read
>> Changes in v2:
>> - Switch ifdef to IS_ENABLED
>> ---
>> xen/arch/arm/tee/ffa_msg.c | 96 ++++++++++++++++++++++++++++++++++----
>> 1 file changed, 88 insertions(+), 8 deletions(-)
>> 
>> diff --git a/xen/arch/arm/tee/ffa_msg.c b/xen/arch/arm/tee/ffa_msg.c
>> index ee594e737fc7..c21083b5e68f 100644
>> --- a/xen/arch/arm/tee/ffa_msg.c
>> +++ b/xen/arch/arm/tee/ffa_msg.c
>> @@ -88,6 +88,72 @@ out:
>>                  resp.a7 & mask);
>> }
>> 
>> +static int32_t ffa_msg_send2_vm(uint16_t dst_id,
>> +                                const struct ffa_part_msg_rxtx *src_msg)
>> +{
>> +    struct domain *dst_d;
>> +    struct ffa_ctx *dst_ctx;
>> +    struct ffa_part_msg_rxtx *dst_msg;
>> +    int err;
>> +    int32_t ret;
>> +
>> +    if ( dst_id == 0 )
>> +        /* FF-A ID 0 is the hypervisor, this is not valid */
>> +        return FFA_RET_INVALID_PARAMETERS;
>> +
>> +    /* This is also checking that dest is not src */
>> +    err = rcu_lock_live_remote_domain_by_id(dst_id - 1, &dst_d);
>> +    if ( err )
>> +        return FFA_RET_INVALID_PARAMETERS;
>> +
>> +    if ( dst_d->arch.tee == NULL )
>> +    {
>> +        ret = FFA_RET_INVALID_PARAMETERS;
>> +        goto out_unlock;
>> +    }
>> +
>> +    dst_ctx = dst_d->arch.tee;
>> +    if ( !dst_ctx->guest_vers )
>> +    {
>> +        ret = FFA_RET_INVALID_PARAMETERS;
>> +        goto out_unlock;
>> +    }
>> +
>> +    /* we need to have enough space in the destination buffer */
>> +    if ( dst_ctx->page_count * FFA_PAGE_SIZE <
>> +            (sizeof(struct ffa_part_msg_rxtx) + src_msg->msg_size) )
>> +    {
>> +        ret = FFA_RET_NO_MEMORY;
>> +        goto out_unlock;
>> +    }
>> +
>> +    /* This also checks that destination has set a Rx buffer */
>> +    ret = ffa_rx_acquire(dst_d);
>> +    if ( ret )
>> +        goto out_unlock;
>> +
>> +    dst_msg = dst_ctx->rx;
>> +
>> +    /* prepare destination header */
>> +    dst_msg->flags = 0;
>> +    dst_msg->reserved = 0;
>> +    dst_msg->msg_offset = sizeof(struct ffa_part_msg_rxtx);
>> +    dst_msg->send_recv_id = src_msg->send_recv_id;
>> +    dst_msg->msg_size = src_msg->msg_size;
>> +
>> +    memcpy(dst_ctx->rx + sizeof(struct ffa_part_msg_rxtx),
>> +           ((void *)src_msg) + src_msg->msg_offset, src_msg->msg_size);
> 
> Is it possible for another core in the VM to modify
> src_msg->msg_offset or src_msg->msg_size after we check them but
> before we use them here (TOC/TOU)?

Yes there could be a possibility.
I will switch to a local copy of the header to prevent this.

Nice finding.

Cheers
Bertrand

> 
> Cheers,
> Jens
> 
>> +
>> +    /* receiver rx buffer will be released by the receiver*/
>> +
>> +out_unlock:
>> +    rcu_unlock_domain(dst_d);
>> +    if ( !ret )
>> +        ffa_raise_rx_buffer_full(dst_d);
>> +
>> +    return ret;
>> +}
>> +
>> int32_t ffa_handle_msg_send2(struct cpu_user_regs *regs)
>> {
>>     struct domain *src_d = current->domain;
>> @@ -96,9 +162,6 @@ int32_t ffa_handle_msg_send2(struct cpu_user_regs *regs)
>>     uint16_t dst_id, src_id;
>>     int32_t ret;
>> 
>> -    if ( !ffa_fw_supports_fid(FFA_MSG_SEND2) )
>> -        return FFA_RET_NOT_SUPPORTED;
>> -
>>     if ( !spin_trylock(&src_ctx->tx_lock) )
>>         return FFA_RET_BUSY;
>> 
>> @@ -106,10 +169,10 @@ int32_t ffa_handle_msg_send2(struct cpu_user_regs 
>> *regs)
>>     src_id = src_msg->send_recv_id >> 16;
>>     dst_id = src_msg->send_recv_id & GENMASK(15,0);
>> 
>> -    if ( src_id != ffa_get_vm_id(src_d) || !FFA_ID_IS_SECURE(dst_id) )
>> +    if ( src_id != ffa_get_vm_id(src_d) )
>>     {
>>         ret = FFA_RET_INVALID_PARAMETERS;
>> -        goto out_unlock_tx;
>> +        goto out;
>>     }
>> 
>>     /* check source message fits in buffer */
>> @@ -118,13 +181,30 @@ int32_t ffa_handle_msg_send2(struct cpu_user_regs 
>> *regs)
>>          src_msg->msg_offset < sizeof(struct ffa_part_msg_rxtx) )
>>     {
>>         ret = FFA_RET_INVALID_PARAMETERS;
>> -        goto out_unlock_tx;
>> +        goto out;
>>     }
>> 
>> -    ret = ffa_simple_call(FFA_MSG_SEND2,
>> +    if ( FFA_ID_IS_SECURE(dst_id) )
>> +    {
>> +        /* Message for a secure partition */
>> +        if ( !ffa_fw_supports_fid(FFA_MSG_SEND2) )
>> +        {
>> +            ret = FFA_RET_NOT_SUPPORTED;
>> +            goto out;
>> +        }
>> +
>> +        ret = ffa_simple_call(FFA_MSG_SEND2,
>>                           ((uint32_t)ffa_get_vm_id(src_d)) << 16, 0, 0, 0);
>> +    }
>> +    else if ( IS_ENABLED(CONFIG_FFA_VM_TO_VM) )
>> +    {
>> +        /* Message for a VM */
>> +        ret = ffa_msg_send2_vm(dst_id, src_msg);
>> +    }
>> +    else
>> +        ret = FFA_RET_INVALID_PARAMETERS;
>> 
>> -out_unlock_tx:
>> +out:
>>     spin_unlock(&src_ctx->tx_lock);
>>     return ret;
>> }
>> --
>> 2.47.1



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.