[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v5 06/11] tools/xenstored: Add get_domain_evtchn() to find evtchn


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Fri, 25 Jul 2025 19:58:53 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uqHjxqohFPHOSPVRyrPZTNT5elTCXWAy2c5zwbn6lSc=; b=vEgP1y7g0Gb/jpMRKye5IxfrwPr3LnVBLy+HHW8boVILcaiA+X682oEiqrqBpao9VjO0u8ZgLaUU0ebHmLuc1gDjnv12qBFbKBp7hrdDBAzA/EnC6pJaSoLBekXGCRn3ooh4NU28ea8l9QHa3UxE0/sl+TW1Z5LE3RJPsPnsbn8EXLcgOf7gERTTZltE/1xPK+sF4TAU8hUGwNjINRDcMRFuG/UcR9mIZfIv03O601GdLXl+++6yZv5bnqcbFAaVjYjUNmUWMDju4mcCOZ9gaPYI1H5hL7wK9jvAV9Hp88CcPsFfFwocfuwbbEsY0ZdLll2IzPfYx+A2N4vGrSkCpw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=udzMCsgqBJ2qN1/gSdk9JymNmZVNBOJDEfjE6co7FeqcwG27n3T8/lb5B363eBMUY/vqEzrZMChOBwvmeL339R+GdkzlE6FWapCTV8XRAZlK4qSacImTSxtNqxXUPKb22ij+A6F4z/77tjq/cxakRg7zTHswrcmOYVUt0R5yjR5qAH0UTYDNI3tpYrTRXzzf5LgyFMbWqPEw3dINgj0wtWvRV3qx1jwOpKp6CjApvDI9+iRwHZCDhzS2M7PUZLu/jE4BpuJRXigk1tl0T2euTJutryfvf/mh6XwlP4Jk1Nd30EnPjS6MorVhEhzDzkMvVwhurLnAQKq3PriUPIICbQ==
  • Cc: Jason Andryuk <jason.andryuk@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>
  • Delivery-date: Fri, 25 Jul 2025 23:59:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add helpers to lookup the event channel for a domid.  This hides some
of the differences between dom0 and stubdom xenstored.  Each version
defines its own.

It highlights the different meanings between get_xenbus_evtchn() in a
stubdom, where it looks up dom0's event channel, and dom0, where it
looks up the local event channel.

get_domain_evtchn() replaces get_xenbus_evtchn(), and
get_xenbus_evtchn() is removed from minios.c as it is inlined in the new
function.

The default return 0 will be fine as any other auto-introduced domain
will needs the event channel populated in the grant.

Signed-off-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
v5:
Split get_domain_evtchn() in minios.c and posix.c versions
s/dom0/stubdom/
---
 tools/xenstored/core.h   |  2 +-
 tools/xenstored/domain.c |  9 +++++++--
 tools/xenstored/minios.c | 17 +++++++++++++++--
 tools/xenstored/posix.c  | 16 +++++++++++++++-
 4 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h
index 1ba9592d16..877b1e1103 100644
--- a/tools/xenstored/core.h
+++ b/tools/xenstored/core.h
@@ -394,7 +394,7 @@ static inline bool domain_is_unprivileged(const struct 
connection *conn)
 }
 
 /* Return the event channel used by xenbus. */
-evtchn_port_t get_xenbus_evtchn(void);
+evtchn_port_t get_domain_evtchn(unsigned int domid);
 void early_init(bool live_update, bool dofork, const char *pidfile);
 void late_init(bool live_update);
 
diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c
index 1241f8c73e..71ab7aaad3 100644
--- a/tools/xenstored/domain.c
+++ b/tools/xenstored/domain.c
@@ -1256,7 +1256,7 @@ void dom0_init(void)
        evtchn_port_t port;
        struct domain *dom0;
 
-       port = get_xenbus_evtchn();
+       port = get_domain_evtchn(xenbus_master_domid());
        if (port == -1)
                barf_perror("Failed to initialize dom0 port");
 
@@ -1271,11 +1271,16 @@ void stubdom_init(void)
 {
 #ifdef __MINIOS__
        struct domain *stubdom;
+       evtchn_port_t port;
 
        if (stub_domid < 0)
                return;
 
-       stubdom = introduce_domain(NULL, stub_domid, xenbus_evtchn, false);
+       port = get_domain_evtchn(stub_domid);
+       if (port == -1)
+               barf_perror("Failed to initialize stubdom port");
+
+       stubdom = introduce_domain(NULL, stub_domid, port, false);
        if (!stubdom)
                barf_perror("Failed to initialize stubdom");
 
diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c
index a229954cf4..a86edbd5c8 100644
--- a/tools/xenstored/minios.c
+++ b/tools/xenstored/minios.c
@@ -41,9 +41,22 @@ struct connection *add_socket_connection(int fd)
        barf("socket based connection without sockets");
 }
 
-evtchn_port_t get_xenbus_evtchn(void)
+/*
+ * minios stubdom looks up dom0's event channel from the command line
+ * (--event).  The stubdom's own event channel is returned directly.
+ *
+ * Any other existing domains from dom0less/Hyperlaunch will have
+ * the event channel in the xenstore page, so lookup here isn't necessary.
+ * --event would not be set, so it would default to 0.
+ */
+evtchn_port_t get_domain_evtchn(unsigned int domid)
 {
-       return dom0_event;
+       if (domid == stub_domid)
+               return xenbus_evtchn;
+       else if (domid == priv_domid)
+               return dom0_event;
+
+       return 0;
 }
 
 void *xenbus_map(void)
diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c
index 6037d739d0..d850dc0da9 100644
--- a/tools/xenstored/posix.c
+++ b/tools/xenstored/posix.c
@@ -139,7 +139,7 @@ void unmap_xenbus(void *interface)
        munmap(interface, getpagesize());
 }
 
-evtchn_port_t get_xenbus_evtchn(void)
+static evtchn_port_t get_xenbus_evtchn(void)
 {
        int fd;
        int rc;
@@ -166,6 +166,20 @@ evtchn_port_t get_xenbus_evtchn(void)
        return port;
 }
 
+/*
+ * dom0 xenstored uses get_xenbus_evtchn() to lookup with XENSTORED_PORT_DEV.
+ *
+ * Any other existing domains from dom0less/Hyperlaunch will have
+ * the event channel in the xenstore page, so lookup here isn't necessary.
+ */
+evtchn_port_t get_domain_evtchn(unsigned int domid)
+{
+       if (domid == xenbus_master_domid())
+               return get_xenbus_evtchn();
+
+       return 0;
+}
+
 void *xenbus_map(void)
 {
        int fd;
-- 
2.50.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.