|
[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
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
>>
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |