evtchn_alloc_unbound() always allocates the next available port. Static
event channel support for dom0less domains requires allocating a
specified port.
Modify the evtchn_alloc_unbound() to accept the port number as an
argument and allocate the specified port if available. If the port
number argument is zero, the next available port will be allocated.
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
---
Changes in v2:
- fix minor comments
---
---
xen/arch/arm/domain_build.c | 2 +-
xen/common/event_channel.c | 17 ++++++++++++-----
xen/include/xen/event.h | 3 ++-
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 6d447367be..11a8c6b8b5 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -3171,7 +3171,7 @@ static int __init alloc_xenstore_evtchn(struct domain *d)
alloc.dom = d->domain_id;
alloc.remote_dom = hardware_domain->domain_id;
- rc = evtchn_alloc_unbound(&alloc);
+ rc = evtchn_alloc_unbound(&alloc, 0);
if ( rc )
{
printk("Failed allocating event channel for domain\n");
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index eed0e94d07..f2d8c2d61a 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -316,11 +316,15 @@ static int evtchn_get_port(struct domain *d, evtchn_port_t port)
return rc ?: port;
}
-int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
+/*
+ * If port is zero get the next free port and allocate. If port is non-zero
+ * allocate the specified port.
+ */
+int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc, evtchn_port_t port)
{
struct evtchn *chn;
struct domain *d;
- int port, rc;
+ int rc;
domid_t dom = alloc->dom;
d = rcu_lock_domain_by_any_id(dom);
@@ -329,8 +333,11 @@ int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
write_lock(&d->event_lock);
- if ( (port = get_free_port(d)) < 0 )
- ERROR_EXIT_DOM(port, d);
+ port = rc = evtchn_get_port(d, port);
+ if ( rc < 0 )
+ ERROR_EXIT(rc);
+ rc = 0;
+
chn = evtchn_from_port(d, port);
rc = xsm_evtchn_unbound(XSM_TARGET, d, chn, alloc->remote_dom);
@@ -1229,7 +1236,7 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
struct evtchn_alloc_unbound alloc_unbound;
if ( copy_from_guest(&alloc_unbound, arg, 1) != 0 )
return -EFAULT;
- rc = evtchn_alloc_unbound(&alloc_unbound);
+ rc = evtchn_alloc_unbound(&alloc_unbound, 0);
if ( !rc && __copy_to_guest(arg, &alloc_unbound, 1) )
rc = -EFAULT; /* Cleaning up here would be a mess! */
break;
diff --git a/xen/include/xen/event.h b/xen/include/xen/event.h
index f29b1123d9..8eae9984a9 100644
--- a/xen/include/xen/event.h
+++ b/xen/include/xen/event.h
@@ -72,7 +72,8 @@ void evtchn_free(struct domain *d, struct evtchn *chn);
int evtchn_allocate_port(struct domain *d, unsigned int port);
/* Allocate a new event channel */
-int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc);
+int __must_check evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc,
+ evtchn_port_t port);
/* Bind an event channel port to interdomain */
int __must_check evtchn_bind_interdomain(evtchn_bind_interdomain_t *bind,
--
2.25.1
Hi Rahul, On 19/08/2022 11:02, Rahul Singh wrote: > evtchn_alloc_unbound() always allocates the next available port. Static > event channel support for dom0less domains requires allocating a > specified port. NIT: Same as patch #4, it is not clear you are talking about the current behavior. > > Modify the evtchn_alloc_unbound() to accept the port number as an > argument and allocate the specified port if available. If the port > number argument is zero, the next available port will be allocated. > > Signed-off-by: Rahul Singh <rahul.singh@arm.com> Reviewed-by: Julien Grall <jgrall@amazon.com> Cheers, -- Julien Grall
Hi Julien, > On 23 Aug 2022, at 9:31 am, Julien Grall <julien@xen.org> wrote: > > Hi Rahul, > > On 19/08/2022 11:02, Rahul Singh wrote: >> evtchn_alloc_unbound() always allocates the next available port. Static >> event channel support for dom0less domains requires allocating a >> specified port. > > NIT: Same as patch #4, it is not clear you are talking about the current behavior. > Ack. I will add “currently” in next version. Regards, Rahul
On 19.08.2022 12:02, Rahul Singh wrote: > evtchn_alloc_unbound() always allocates the next available port. Static > event channel support for dom0less domains requires allocating a > specified port. > > Modify the evtchn_alloc_unbound() to accept the port number as an > argument and allocate the specified port if available. If the port > number argument is zero, the next available port will be allocated. > > Signed-off-by: Rahul Singh <rahul.singh@arm.com> Acked-by: Jan Beulich <jbeulich@suse.com> As a minor remark: Personally I'd find it more logical if the alloc-unbound adjustments came ahead of the bind-interdomain ones. Jan
Hi Jan, > On 22 Aug 2022, at 2:57 pm, Jan Beulich <jbeulich@suse.com> wrote: > > On 19.08.2022 12:02, Rahul Singh wrote: >> evtchn_alloc_unbound() always allocates the next available port. Static >> event channel support for dom0less domains requires allocating a >> specified port. >> >> Modify the evtchn_alloc_unbound() to accept the port number as an >> argument and allocate the specified port if available. If the port >> number argument is zero, the next available port will be allocated. >> >> Signed-off-by: Rahul Singh <rahul.singh@arm.com> > > Acked-by: Jan Beulich <jbeulich@suse.com> > > As a minor remark: Personally I'd find it more logical if the alloc-unbound > adjustments came ahead of the bind-interdomain ones. > I will move this patch before evtchn_bind_interdomain() patch. Regard, Rahul
© 2016 - 2026 Red Hat, Inc.