On Wed, 16 Jul 2025, Jason Andryuk wrote:
> When used with an untargetable domain, xsm_evtchn_unbound fails even
> though the idle domain has is_privileged = true. Switch current to the
> domain under construction so that event channel creation is allowed as
> XSM_TARGET.
>
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> v2:
> New
>
> This was Jan's suggestion when dom0less originally had trouble with
> evtchn_alloc_unbound() and xsm_set_system_active() was introduced. As
> noted, is_privileged is insufficient for operating on an untargetable
> domain.
> ---
> xen/common/device-tree/dom0less-build.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/xen/common/device-tree/dom0less-build.c b/xen/common/device-tree/dom0less-build.c
> index 22af043aa5..a2789e3bdf 100644
> --- a/xen/common/device-tree/dom0less-build.c
> +++ b/xen/common/device-tree/dom0less-build.c
> @@ -77,11 +77,20 @@ bool __init is_dom0less_mode(void)
> static int __init alloc_xenstore_evtchn(struct domain *d)
> {
> evtchn_alloc_unbound_t alloc;
> + struct vcpu *old_current;
> int rc;
>
> alloc.dom = d->domain_id;
> alloc.remote_dom = xs_domid;
> + /*
> + * Switch current from the Xen idle vcpu to the domain's vcpu. This is to
> + * pass the xsm_evtchn_unbound() check for an untargetable domain.
> + */
> + old_current = current;
> + set_current(d->vcpu[0]);
> rc = evtchn_alloc_unbound(&alloc, 0);
> + /* Restore Xen idle vcpu. */
> + set_current(old_current);
> if ( rc )
> {
> printk("Failed allocating event channel for domain\n");
> --
> 2.50.0
>
>