All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rahul Singh <rahul.singh@arm.com>
To: xen-devel@lists.xenproject.org
Cc: rahul.singh@arm.com, Stanislav Kinsburskii <staskins@amazon.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>,
	Julien Grall <jgrall@amazon.com>
Subject: [PATCH v4 2/7] xen/evtchn: Add an helper to reserve/allocate a port
Date: Tue,  6 Sep 2022 14:40:40 +0100	[thread overview]
Message-ID: <30832afe5dfe3a1b350c26e40a5c5fbcb93b8c57.1662462034.git.rahul.singh@arm.com> (raw)
In-Reply-To: <cover.1662462034.git.rahul.singh@arm.com>

From: Stanislav Kinsburskii <staskins@amazon.com>

In a follow-up patch we will want to either reserve or allocate a port
for various event channel helpers.

A new wrapper is introduced to either reserve a given port or allocate
a fresh 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>
Acked-by: Jan Beulich <jbeulich@suse.com>
---
Changes in v4:
 - Change the Author to Stanislav Kinsburskii <staskins@amazon.com>
Changes in v3:
 - minor comments in commit msg
Changes in v2:
 - new patch in this version
---
 xen/common/event_channel.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index f81c229358..565ab71881 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -305,6 +305,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;
@@ -462,19 +474,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);
 
-- 
2.25.1



  parent reply	other threads:[~2022-09-06 13:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-06 13:39 [PATCH v4 0/7] xen/evtchn: implement static event channel signaling Rahul Singh
2022-09-06 13:40 ` [PATCH v4 1/7] xen/evtchn: Make sure all buckets below d->valid_evtchns are allocated Rahul Singh
2022-09-06 13:45   ` Jan Beulich
2022-09-06 13:40 ` Rahul Singh [this message]
2022-09-06 13:40 ` [PATCH v4 3/7] xen/evtchn: restrict the maximum number of evtchn supported for domUs Rahul Singh
2022-09-07 13:01   ` Julien Grall
2022-09-07 14:19     ` Rahul Singh
2022-09-06 13:40 ` [PATCH v4 4/7] xen/evtchn: modify evtchn_alloc_unbound to allocate specified port Rahul Singh
2022-09-06 13:40 ` [PATCH v4 5/7] xen/evtchn: modify evtchn_bind_interdomain to support static evtchn Rahul Singh
2022-09-06 13:40 ` [PATCH v4 6/7] xen/arm: introduce new xen,enhanced property value Rahul Singh
2022-09-06 22:12   ` Stefano Stabellini
2022-09-07  8:13     ` Rahul Singh
2022-09-07 13:09   ` Julien Grall
2022-09-07 14:19     ` Rahul Singh
2022-09-06 13:40 ` [PATCH v4 7/7] xen/arm: introduce xen-evtchn dom0less property Rahul Singh
2022-09-06 22:22   ` Stefano Stabellini
2022-09-07  8:12     ` Rahul Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=30832afe5dfe3a1b350c26e40a5c5fbcb93b8c57.1662462034.git.rahul.singh@arm.com \
    --to=rahul.singh@arm.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgrall@amazon.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=staskins@amazon.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.