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

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


  • To: Jens Wiklander <jens.wiklander@xxxxxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Thu, 20 Mar 2025 15:59:16 +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=WVBQh5x4TD7YlHeTnLaaSSOlB6hti02fJP49NGmdcuc=; b=BQ1C1tOjP9NP+hx2UgwmFofFVd3CaBD2sPQBfdVFfwp8REwuRB43ZxsB6F7ft8YfSdabIJRggU3opzfKNiQltxlgtjgC+tUs7H5Ptx8rQD6cvaCjHU7ZqqMyb3pf7NFA1U2F1H6llWLa7NQ43jvpmldixwycNI8PPbwzpSSpjHLSg+aKMeLKPg8czn7NakSTRHiLWCzFa2Bl3Y9IGsYW4vaSsD8l5/jEG6F6Wjk/M40TJ94uTlayg9TMY/SytCfXwCJF7mSYOE7GIBRFqa9b5sNnbOlMjDZu8vpe8A6MS98Eyw9r10C+3CZwYoTCJHiLFsRIeNUwB7fkZbkFTduD4g==
  • 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=WVBQh5x4TD7YlHeTnLaaSSOlB6hti02fJP49NGmdcuc=; b=hu3+glA3ukyc6pT0YV5Qtr3Mw75y5bFn2dg0rK2diOrkfm1PZufRvp3ar4A3H7MgtKvPyegi4f5D9kW4JQSeas+K0thE4d3vExZw3NVbA0WlJlE+88jnWJ+xOBQQ6+EAt7T5s86paaT0Y06ikPYfUBJ0gxTfJlWs3yVYg9EEqcp8A14f5GTfrSpLcENuMuDaNg7MT9EMjBbeILJtumgho/Av0Fnn6eWJyW5/9gbiPZ24oUgxYuxXtNtTbHI/Z47iL+ZNNhOyhq7hQ269/e/aRrWWOu/BVo5r2UqlBbmAnfvqaozKcNN7v7yBSbYGn0PzgJ+vbHAVhvwlFoVMTTg0wg==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=r9n30UP0K28oY9TOF7dK+yKMagZMZd9nNLzw9qs8xjxsT0sFxZ4d/LmL/8TMWS2OEhoKSp09MlIWev/cK0Nj+b9OPJVehCT5F6Jg8k+eu0Mxc3W2kGOYXelmyvM0vI3+zvISBXaV92y73Odz7HNBVey3HeS4KFFTdZbCCPGDXaIIT8chhAWgt9pzOgTX83niXlXs7HW8rznnVpCMvJ6cbZLQs09C43h/3YHzdJTx1p4eiqwb2oBC21R64e2skJzXWrpqemw7BEJM2oLgrLS+kn9yYIqCcOxByHq4OoNVqlnKN5t71iaCzPk8cMoqomUJHYYqVLK77N83LqZCPnp3Iw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lIKrCfvSal/Lgf/ImSaY56BUuANST4ym1TwzYRK4YJ8Q/ZRmxcF2noR6oaZp5DzP0OhfDDkUFSnfA99QKLDxShpruvtLKoopon3+Rcxy+8bJqZxk4zta+bdwrDye4yLzrPoNrboIdRT1GO/6TB9feHfhh20j6YcR9HgK3YZ/Tg8p0/ECdvHHWBdcVss6rUquu44pcPFRWyD3b4l3bLuOR4kSlHT6bEkVhP3KhrUCPifqsuQdSv3N8WxFAJEZlyUu+gYldgIXJiPvpZ1eAuHoqUhHtZTiQV1h9scuR9goO0nwNWiIiNVOTypLO2jEkDjz6YpHsWJEiwx834JK9aznjg==
  • 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: Thu, 20 Mar 2025 16:03:55 +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: AQHbkcvpt0PUM4qxV0mEdDt9tLfY+rN8POUAgAABhwA=
  • Thread-topic: [PATCH v2 4/5] xen/arm: ffa: Add indirect message between VM

Hi Jens,

> On 20 Mar 2025, at 16:53, Jens Wiklander <jens.wiklander@xxxxxxxxxx> wrote:
> 
> Hi Bertrand,
> 
> On Mon, Mar 10, 2025 at 3:51 PM 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 v2:
>> - Switch ifdef to IS_ENABLED
>> ---
>> xen/arch/arm/tee/ffa_msg.c     | 96 +++++++++++++++++++++++++++++++---
>> xen/arch/arm/tee/ffa_private.h |  4 ++
>> 2 files changed, 92 insertions(+), 8 deletions(-)
>> 
>> diff --git a/xen/arch/arm/tee/ffa_msg.c b/xen/arch/arm/tee/ffa_msg.c
>> index ee594e737fc7..336d5bbf64f6 100644
>> --- a/xen/arch/arm/tee/ffa_msg.c
>> +++ b/xen/arch/arm/tee/ffa_msg.c
>> @@ -96,9 +96,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 +103,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 +115,96 @@ 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);
>> +        goto out;
>> +    }
>> 
>> -out_unlock_tx:
>> +    /* Message for a VM */
>> +    if ( IS_ENABLED(CONFIG_FFA_VM_TO_VM) )
>> +    {
> 
> I would move this block into a helper function to isolate the needed
> cleanup etc, but that might be more a matter of taste so do as you
> prefer.

Yes that would be better. Will do.

> 
>> +        struct domain *dst_d;
>> +        struct ffa_ctx *dst_ctx;
>> +        struct ffa_part_msg_rxtx *dst_msg;
>> +        int err;
>> +
>> +        if ( dst_id == 0 )
>> +        {
>> +            /* FF-A ID 0 is the hypervisor, this is not valid */
>> +            ret = FFA_RET_INVALID_PARAMETERS;
>> +            goto out;
>> +        }
>> +
>> +        /* This is also checking that dest is not src */
>> +        err = rcu_lock_live_remote_domain_by_id(dst_id - 1, &dst_d);
>> +        if ( err )
>> +        {
>> +            ret = FFA_RET_INVALID_PARAMETERS;
>> +            goto out;
>> +        }
>> +
>> +        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;
>> +        }
>> +
>> +        /* This also checks that destination has set a Rx buffer */
>> +        ret = ffa_rx_acquire(dst_d);
>> +        if ( ret )
>> +            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;
>> +            ffa_rx_release(dst_d);
>> +            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),
>> +               src_ctx->tx + src_msg->msg_offset, src_msg->msg_size);
>> +
>> +        /* 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);
>> +    }
>> +    else
>> +        ret = FFA_RET_INVALID_PARAMETERS;
>> +
>> +out:
>>     spin_unlock(&src_ctx->tx_lock);
>>     return ret;
>> }
>> diff --git a/xen/arch/arm/tee/ffa_private.h b/xen/arch/arm/tee/ffa_private.h
>> index 1f5067d5d0c9..340db229453c 100644
>> --- a/xen/arch/arm/tee/ffa_private.h
>> +++ b/xen/arch/arm/tee/ffa_private.h
>> @@ -380,6 +380,10 @@ int ffa_handle_notification_set(struct cpu_user_regs 
>> *regs);
>> 
>> #ifdef CONFIG_FFA_VM_TO_VM
>> void ffa_raise_rx_buffer_full(struct domain *d);
>> +#else
>> +static inline void ffa_raise_rx_buffer_full(struct domain *d)
>> +{
>> +}
> 
> Shouldn't this go in the previous patch "xen/arm: ffa: Add buffer full
> notification support"?
> 

Definitely yes. I will move it back.

Cheers
Bertrand

> Cheers,
> Jens
> 
>> #endif
>> 
>> void ffa_handle_msg_send_direct_req(struct cpu_user_regs *regs, uint32_t 
>> fid);
>> --
>> 2.47.1



 


Rackspace

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