diff mbox series

[v2,2/7] xen/evtchn: Add an helper to reserve/allocate a port

Message ID a6835a7c7223635da27d4e7db002eae5d21417b8.1660902588.git.rahul.singh@arm.com (mailing list archive)
State Superseded
Headers show
Series xen/evtchn: implement static event channel signaling | expand

Commit Message

Rahul Singh Aug. 19, 2022, 10:02 a.m. UTC
In a follow-up patch we will be able to either reserve or allocate a
port for various event channel helpers.

A new wrapper is introduced to either reserved a given port or allocate
an empty one if zero.

Take the opportunity to replace the open-coded version in
evtchn_bind_virq().

Signed-off-by: Stanislav Kinsburskii <staskins@amazon.com>
Signed-off-by: Julien Grall <jgrall@amazon.com>
Signed-off-by: Rahul Singh <rahul.singh@arm.com>
---
Changes in v2:
 - new patch in this version
---
---
 xen/common/event_channel.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

Comments

Jan Beulich Aug. 22, 2022, 1:45 p.m. UTC | #1
On 19.08.2022 12:02, Rahul Singh wrote:
> In a follow-up patch we will be able to either reserve or allocate a
> port for various event channel helpers.

Maybe "... we will want to ..."?

> A new wrapper is introduced to either reserved a given port or allocate
> an empty one if zero.

Maybe a/empty/fresh/ ?

> Take the opportunity to replace the open-coded version in
> evtchn_bind_virq().
> 
> Signed-off-by: Stanislav Kinsburskii <staskins@amazon.com>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
> Signed-off-by: Rahul Singh <rahul.singh@arm.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
Rahul Singh Aug. 23, 2022, 9:14 a.m. UTC | #2
Hi Jan,

> On 22 Aug 2022, at 2:45 pm, Jan Beulich <jbeulich@suse.com> wrote:
> 
> On 19.08.2022 12:02, Rahul Singh wrote:
>> In a follow-up patch we will be able to either reserve or allocate a
>> port for various event channel helpers.
> 
> Maybe "... we will want to ..."?

Ack.
> 
>> A new wrapper is introduced to either reserved a given port or allocate
>> an empty one if zero.
> 
> Maybe a/empty/fresh/ ?

Ack. I will fix in next version.
 
Regards,
Rahul
diff mbox series

Patch

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index dbe0a27311..194f5346fb 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -304,6 +304,18 @@  void evtchn_free(struct domain *d, struct evtchn *chn)
     xsm_evtchn_close_post(chn);
 }
 
+static int evtchn_get_port(struct domain *d, evtchn_port_t port)
+{
+    int rc;
+
+    if ( port != 0 )
+        rc = evtchn_allocate_port(d, port);
+    else
+        rc = get_free_port(d);
+
+    return rc ?: port;
+}
+
 int evtchn_alloc_unbound(evtchn_alloc_unbound_t *alloc)
 {
     struct evtchn *chn;
@@ -461,19 +473,10 @@  int evtchn_bind_virq(evtchn_bind_virq_t *bind, evtchn_port_t port)
     if ( read_atomic(&v->virq_to_evtchn[virq]) )
         ERROR_EXIT(-EEXIST);
 
-    if ( port != 0 )
-    {
-        if ( (rc = evtchn_allocate_port(d, port)) != 0 )
-            ERROR_EXIT(rc);
-    }
-    else
-    {
-        int alloc_port = get_free_port(d);
-
-        if ( alloc_port < 0 )
-            ERROR_EXIT(alloc_port);
-        port = alloc_port;
-    }
+    port = rc = evtchn_get_port(d, port);
+    if ( rc < 0 )
+        ERROR_EXIT(rc);
+    rc = 0;
 
     chn = evtchn_from_port(d, port);