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

Re: [PATCH v16 4/6] xen/arm: scmi: introduce SCI SCMI SMC multi-agent driver


  • To: Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • From: Oleksii Moisieiev <Oleksii_Moisieiev@xxxxxxxx>
  • Date: Fri, 4 Dec 2026 17:06:03 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • 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=aPWfR6Xspx/sWWE9rFqvJQmn7CaU8Ua434DDF9MvaYw=; b=nVhlJXLIG1vk9pMx1Y3pnauKunU8VPsm957nW0Xp9J9fhZvY+II6t4n3dTJTIA7vfhGKOTB87uL4Uw+s1I1+r8YG/2mqB1Zidvi25MgAism/udiWVeSLWU6a99ZBN83HgvrlaHi1CMVCKcbDiPtLFNuc5Ip+5aQs0Rbxjuaq6j1bFId3v+VBWgEUdCmhTdS51wtqpigroFERcT6z4RpgV8FzkvCwC3LtcOLBfLfd8lYKdVc8YBPHkwrt1Mr0Uojgmh3DteWZJQDxpll57drJ3kyaH/77j5HFepZ2fF58U2BYsMPiDj3hL10IvxfOmXtbPlic+/9Zc2BU934mVieAdA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bhKaIcXSNTaTNomnOuCIU1ltSjiYXa1A9T0WYfcfAjCv32J3b2T97Dvmjn99nNvrw38V7G89oAphNTkzumaPiLQajwDLmN2BJxCE0BvxzIcu+j/k/GVjnasY000cjjEp+ddMwcYqEeEa0Fsrd4JAHUyKr8K+tSqDgdnaR1qkI3TJB5H4MnZVVsPNs7qEwpRvUi+VTVrs8hmaQbe+vrIlyZDhdbrHmwdqr1kM45YasvhWAmjSkDlcAXNEv5A+2+JfZLC56xM44DKZm3zCUggJVNcS0lAE1pwFXk9KO6ncxFmm32hzsNx3q3XPDamC2AMpL/cUBM/fxe0MlCysQTrXrA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, "michal.orzel" <michal.orzel@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Grygorii Strashko <grygorii_strashko@xxxxxxxx>
  • Delivery-date: Fri, 04 Dec 2026 17:06:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdddiWXJg4oXa1gEmNDWvyhUvCnw==
  • Thread-topic: [PATCH v16 4/6] xen/arm: scmi: introduce SCI SCMI SMC multi-agent driver

Hi Stefano,

Thank you for the review.

Please see my answer below.

On 04/12/2026 03:45, Stefano Stabellini wrote:
> On Mon, 16 Nov 2026, Oleksii Moisieiev wrote:
>> Add an SCI mediator for Arm EL3 firmware, such as Trusted Firmware-A
>> (TF-A), that provides a separate SCMI SMC shared-memory channel for each
>> agent. Xen keeps a trusted management agent and assigns secondary agents
>> exclusively to domains, as shown below.
>>
>>    +-----------------------------------------+
>>    |                                         |
>>    | EL3 TF-A SCMI                           |
>>    +-------+--+-------+--+-------+--+-------++
>>    |shmem1 |  |shmem0 |  |shmem2 |  |shmemX |
>>    +-----+-+  +---+---+  +--+----+  +---+---+
>> smc-id1 |        |         |           |
>> agent1  |        |         |           |
>>    +-----v--------+---------+-----------+----+
>>    |              |         |           |    |
>>    |              |   Xen   |           |    |
>>    +--------------+---------+-----------+----+
>>           smc-id0 |  smc-id2|    smc-idX|
>>           agent0  |  agent2 |    agentX |
>>                   |         |           |
>>              +----v---+  +--v-----+  +--v-----+
>>              |        |  |        |  |        |
>>              | Dom0   |  | Dom1   |  | DomX   |
>>              |        |  |        |  |        |
>>              |        |  |        |  |        |
>>              +--------+  +--------+  +--------+
>>
>> Each channel consists of an arm,smc-id doorbell and a shared-memory buffer
>> whose address and nonzero size are Xen page aligned. Xen maps shared
>> memory as Device memory. Guests exchange messages directly through their
>> assigned buffer; Xen checks the SMC function ID before forwarding the
>> call synchronously to EL3.
>>
>> Require BASE_SET_DEVICE_PERMISSIONS support. Query its availability using
>> Base PROTOCOL_MESSAGE_ATTRIBUTES before registering the mediator and fail
>> initialization if the command is unavailable. Firmware must enforce the
>> permissions configured by Xen and prevent untrusted agents from changing
>> other agents' permissions.
>>
>> Keep BASE_RESET_AGENT_CONFIGURATION optional. Request an agent reset
>> through the management channel when relinquishing a domain's resources.
>> Warn if reset fails, explaining that device state and permissions may
>> persist and agent reuse may be unsafe. Unsupported reset permits teardown;
>> other reset errors propagate to the caller.
>>
>> Bind only to the arm,scmi-smc management node inside a xen,sci-compatible
>> node beneath /chosen. Other SCMI nodes, including the host /firmware/scmi,
>> are ignored by the mediator. Describe secondary agents as xen,scmi-agent
>> children of its agents node, with #address-cells = <1> and
>> phandle. At least one enabled secondary agent is required.
>>
>> The optional single-cell reg property specifies an agent ID in 0..254.
>> Use a matching hexadecimal unit address for an explicit ID and retain a
>> node label for domain phandle references. For example:
>>
>> / {
>>      #address-cells = <2>;
>>      #size-cells = <2>;
>>
>>      scmi_shm_0: sram@47ff0000 {
>>          compatible = "arm,scmi-shmem";
>>          reg = <0x0 0x47ff0000 0x0 0x1000>;
>>      };
>>
>>      firmware {
>>          scmi: scmi {
>>              compatible = "arm,scmi-smc";
>>              arm,smc-id = <0x82000002>; /* Host OSPM agent smc-id */
>>              #address-cells = <1>;
>>              #size-cells = <0>;
>>              shmem = <&scmi_shm_0>; /* Host OSPM agent shmem */
>>          };
>>      };
>>
[snip]
>> +static struct scmi_data scmi_data;
>> +
>> +static bool scmi_is_under_xen_sci(const struct dt_device_node *node)
>> +{
>> +    const struct dt_device_node *p;
>> +
>> +    for ( p = node->parent; p; p = p->parent )
>> +        if ( dt_device_is_compatible(p, "xen,sci") )
>> +            return true;
>> +
>> +    return false;
>> +}
>> +
>> +static int send_smc_message(struct scmi_channel *chan_info,
>> +                            scmi_msg_header_t *hdr, void *data, int len)
>> +{
>> +    struct arm_smccc_res resp;
>> +    int ret;
>> +
>> +    ret = scmi_put_message(chan_info->shmem, hdr, data, len);
>> +    if ( ret )
>> +        return ret;
>> +
>> +    resp = arm_smccc_1_1_smc(chan_info->func_id, 0, 0, 0, 0, 0, 0, 0);
>> +
>> +    if ( resp.a0 == (unsigned long)ARM_SMCCC_INVALID_PARAMETER )
>> +        return -EINVAL;
>> +
>> +    if ( resp.a0 )
>> +        return -EOPNOTSUPP;
> scmi_put_message() has already marked the channel busy at this point.
> If the SMC fails, nobody marks it free again, so every later call on
> this channel fails with -EBUSY. For the management channel, it is a
> problem. Please mark the channel free again before returning the error
> by writing SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE.
>
nice catch, thanks.
>> +    return 0;
>> +}
>> +
>> +static int do_smc_xfer(struct scmi_channel *chan_info, scmi_msg_header_t 
>> *hdr,
>> +                       void *tx_data, int tx_size, void *rx_data, int 
>> rx_size)
>> +{
>> +    int ret = 0;
>> +
>> +    ASSERT(chan_info && chan_info->shmem);
>> +
>> +    if ( !hdr )
>> +        return -EINVAL;
>> +
>> +    spin_lock(&chan_info->lock);
>> +
>> +    printk(XENLOG_DEBUG
>> +           "scmi: agent_id = %d msg_id = %x type = %d, proto = %x\n",
>> +           chan_info->agent_id, hdr->id, hdr->type, hdr->protocol);
>> +
>> +    ret = send_smc_message(chan_info, hdr, tx_data, tx_size);
>> +    if ( ret )
>> +        goto cleanup;
>> +
>> +    ret = scmi_get_message(chan_info->shmem, hdr, rx_data, rx_size);
>> +
>> +    printk(XENLOG_DEBUG
>> +           "scmi: get smc response agent_id = %d msg_id = %x "
>> +           "proto = %x res=%d\n",
>> +           chan_info->agent_id, hdr->id, hdr->protocol, ret);
>> +
>> +cleanup:
>> +    spin_unlock(&chan_info->lock);
>> +
>> +    return ret;
>> +}
[snip]
>> +static int __init collect_agents(struct dt_device_node *scmi_node)
>> +{
>> +    struct dt_device_node *agents, *node;
>> +    unsigned int count = 0;
>> +
>> +    /* Use the configuration containing this management channel. */
>> +    for ( agents = scmi_node->parent; agents; agents = agents->parent )
>> +        if ( dt_device_is_compatible(agents, "xen,sci") )
>> +            break;
>> +
>> +    ASSERT(agents);
>> +
>> +    dt_for_each_child_node(agents, node)
>> +        if ( dt_node_name_is_equal(node, "agents") )
>> +            break;
>> +
>> +    if ( !node )
>> +    {
>> +        printk(XENLOG_ERR "scmi: missing agents node\n");
>> +        return -EINVAL;
>> +    }
>> +    agents = node;
>> +
>> +    if ( dt_child_n_addr_cells(agents) != 1 ||
>> +         dt_child_n_size_cells(agents) != 0 )
>> +        return -EINVAL;
>> +
>> +    dt_for_each_child_node(agents, node)
>> +    {
>> +        struct scmi_channel agent = {
>> +            .agent_id = SCMI_BASE_AGENT_ID_OWN,
>> +            .domain_id = DOMID_INVALID,
>> +        };
>> +        struct scmi_channel *channel;
>> +        bool discover;
>> +        uint32_t len;
>> +        uint64_t addr, size;
>> +        int ret;
>> +
>> +        if ( !dt_device_is_compatible(node, "xen,scmi-agent") ||
>> +             !dt_device_is_available(node) )
>> +            continue;
>> +
>> +        discover = !dt_find_property(node, "reg", &len);
>> +        if ( !discover )
>> +        {
>> +            if ( len != sizeof(uint32_t) ||
>> +                 !dt_property_read_u32(node, "reg", &agent.agent_id) )
>> +                return -EINVAL;
>> +        }
>> +
>> +        if ( !dt_property_read_u32(node, "arm,smc-id", &agent.func_id) )
>> +            return -EINVAL;
> Should we check that the values are not the same as the management
> channel?
>
Agreed. on collect_agent stage we shouldn't get managemet channel
>> +        ret = scmi_dt_read_channel_addr(node, &addr, &size);
>> +        if ( ret )
>> +            return ret;
>> +        agent.paddr = addr;
>> +
>> +        if ( discover )
>> +        {
>> +            /* Resolve the ID before inserting it into the channel list. */
>> +            spin_lock_init(&agent.lock);
>> +            ret = collect_agent_id(&agent);
>> +            if ( ret )
>> +                return ret;
>> +        }
>> +
>> +        /* UINT8_MAX is reserved as invalid in guest configuration. */
>> +        if ( agent.agent_id >= UINT8_MAX )
>> +            return -EINVAL;
> agent ID 0 is supposed to be the platform, should it be accepted or
> rejected?

It should be accepted, since agent ID = 0 can be used (and it is used 
for the Rcar boards) in the vendor DT.

Therefore, as we are based on the vendor DT when creating the Xen DT, 
domain 0 gets agent_id 0. In my case,

the vendor DT assigns SCMI func_id 0x82000002, which corresponds to 
agent 0, and this func_id is reused by dom0.


>
>> +        channel = smc_create_channel(agent.agent_id, agent.func_id,
>> +                                     agent.paddr, node);
>> +        if ( IS_ERR(channel) )
>> +        {
>> +            printk(XENLOG_ERR "scmi: Could not create channel for %s: 
>> %ld\n",
>> +                   node->full_name, PTR_ERR(channel));
>> +            return PTR_ERR(channel);
>> +        }
>> +
>> +        count++;
>> +        printk(XENLOG_DEBUG "scmi: Agent %u SMC %X addr %"PRIpaddr"\n",
>> +               channel->agent_id, channel->func_id, channel->paddr);
>> +    }
>> +
>> +    return count ? 0 : -EINVAL;
>> +}
>> +
>> +static int scmi_domain_init(struct domain *d,
>> +                            struct xen_domctl_createdomain *config)
>> +{
>> +    struct scmi_channel *channel;
>> +    int ret;
>> +
>> +    if ( !scmi_data.initialized )
>> +        return 0;
>> +
>> +    /*
>> +     * SCMI support is configured via:
>> +     * - For dom0: xen,dom0-sci-agent phandle under the xen,sci node
>> +     * - For dom0less: xen,sci-agent phandle in the domain node
>> +     * The config->arch.arm_sci_type and config->arch.arm_sci_agent_id
>> +     * are already set by domain_build.c or dom0less-build.c
>> +     */
>> +
>> +    if ( config->arch.arm_sci_type == XEN_DOMCTL_CONFIG_ARM_SCI_NONE )
>> +        return 0;
>> +
>> +    channel = acquire_scmi_channel(d, config->arch.arm_sci_agent_id);
>> +    if ( IS_ERR(channel) )
>> +    {
>> +        printk(XENLOG_ERR
>> +               "scmi: Failed to acquire SCMI channel for agent_id %u: 
>> %ld\n",
>> +               config->arch.arm_sci_agent_id, PTR_ERR(channel));
>> +        return PTR_ERR(channel);
>> +    }
>> +
>> +    printk(XENLOG_INFO
>> +           "scmi: Acquire channel id = 0x%x, domain = %pd "
>> +           "paddr = 0x%"PRIpaddr"\n",
>> +           channel->agent_id, d, channel->paddr);
>> +
>> +    /*
>> +     * Dom0 (if present) needs to have an access to the guest memory range
>> +     * to satisfy iomem_access_permitted() check in 
>> XEN_DOMCTL_iomem_permission
>> +     * domctl.
>> +     */
>> +    if ( hardware_domain && !is_hardware_domain(d) )
>> +    {
>> +        ret = iomem_permit_access(hardware_domain, 
>> paddr_to_pfn(channel->paddr),
>> +                                  paddr_to_pfn(channel->paddr +
>> +                                  SCMI_SHMEM_MAPPED_SIZE - 1));
> This has not corresponding revoking function
>
>
[snip]
>> +
>>   /*
>>    * Initialize SCI functionality for domain if configured.
>>    *
>> @@ -158,6 +169,12 @@ int sci_do_domctl(struct xen_domctl *domctl, struct 
>> domain *d,
>>   
>>   #include <public/arch-arm.h>
>>   
>> +static inline int sci_get_agent_id(const struct dt_device_node *node,
>> +                                   const char *property, uint8_t *agent_id)
>> +{
>> +    return -EOPNOTSUPP;
>> +}
>> +
>>   static inline bool sci_domain_is_enabled(struct domain *d)
>>   {
>>       return false;
>> diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h
>> index 14d51e0746..722c2d2e3a 100644
>> --- a/xen/include/public/arch-arm.h
>> +++ b/xen/include/public/arch-arm.h
>> @@ -329,6 +329,7 @@ DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
>>   
>>   #define XEN_DOMCTL_CONFIG_ARM_SCI_NONE      0
>>   #define XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC  1
>> +#define XEN_DOMCTL_CONFIG_ARM_SCI_SCMI_SMC_MA  2
>>   
>>   #define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_NONE    0
>>   #define XEN_DOMCTL_CONFIG_ARM_V8R_EL1_MSA_PMSA    1
>> @@ -347,7 +348,9 @@ struct xen_arch_domainconfig {
>>       uint8_t arm_sci_type;
>>       /* IN */
>>       uint8_t v8r_el1_msa;
>> -    uint16_t pad;
>> +    /* IN */
>> +    uint8_t arm_sci_agent_id;
>> +    uint8_t pad;
>>   };
>>   #endif /* __XEN__ || __XEN_TOOLS__ */
>>   
>> -- 
>> 2.43.0
>>

 


Rackspace

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