Skip to contentSkip to conversation

Enumerate all allocated evtchns in lsevtchn

PATCH Superseded Matthew Barnes 2 participants 5 messages Apr 11, 2024 – Apr 18, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Enumerate all allocated evtchns in lsevtchn

Currently, lsevtchn aborts its event channel enumeration when it hits its first hypercall error, namely:
* When an event channel doesn't exist at the specified port
* When the event channel is owned by Xen

This results in lsevtchn missing potential relevant event channels with higher port numbers.

This patch series adds the highest allocated event channel port for a given domain in the xen_domctl_getdomaininfo hypercall struct, and uses that value as an upper bound in the lsevtchn loop.

Matthew Barnes (2):
xen/domctl: Add highest allocated evtchn port to getdomaininfo tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration

 tools/xcutils/lsevtchn.c    | 8 ++++++--
 xen/common/domctl.c         | 1 +
 xen/include/public/domctl.h | 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 xen/domctl: Add highest allocated evtchn port to getdomaininfo

For tools such as lsevtchn to enumerate through event channels, they need an upper bound on the port number.

Add the highest allocated event channel port number for a domain in the xen_domctl_getdomaininfo struct, and populate it.

The field is added above the padding to avoid implicit padding.

---
 xen/common/domctl.c         | 1 +
 xen/include/public/domctl.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
xen/common/domctl.c +1 -0
index 43b0b074c3a6..1d1ee17f6f91 100644
@@ -73,6 +73,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info)
 
     info->domain = d->domain_id;
     info->max_vcpu_id = XEN_INVALID_MAX_VCPU_ID;
+    info->highest_evtchn_port = read_atomic(&d->valid_evtchns);
 
     /*
      * - domain is marked as blocked only if all its vcpus are blocked
xen/include/public/domctl.h +2 -1
index a33f9ec32b08..d28d29180c75 100644
@@ -145,7 +145,8 @@ struct xen_domctl_getdomaininfo {
     xen_domain_handle_t handle;
     uint32_t cpupool;
     uint8_t gpaddr_bits; /* Guest physical address space size. */
-    uint8_t pad2[7];
+    uint8_t pad2[3];
+    evtchn_port_t highest_evtchn_port; /* Highest allocated event channel port. Used for enumeration */
     struct xen_arch_domainconfig arch_config;
 };
 typedef struct xen_domctl_getdomaininfo xen_domctl_getdomaininfo_t;
Signature · 1 line
2.34.1
#3 lore raw

PATCH 2/2 tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration

In reply to Matthew Barnes

lsevtchn terminates the loop when the hypercall returns an error, even if there are still event channels with higher port numbers to be enumerated over.

Use the highest allocated event channel port number for a given domain to bound the loop so that all relevant event channels can be enumerated over.

---
 tools/xcutils/lsevtchn.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/xcutils/lsevtchn.c +6 -2
index d1710613ddc5..7f8ad7c8e7ce 100644
@@ -11,6 +11,7 @@ int main(int argc, char **argv)
     xc_interface *xch;
     int domid, port, rc;
     xc_evtchn_status_t status;
+    xc_domaininfo_t info;
 
     domid = (argc > 1) ? strtol(argv[1], NULL, 10) : 0;
 
@@ -18,13 +19,16 @@ int main(int argc, char **argv)
     if ( !xch )
         errx(1, "failed to open control interface");
 
-    for ( port = 0; ; port++ )
+    if ( xc_domain_getinfo_single(xch, domid, &info) < 0 )
+        errx(1, "failed to fetch domain info");
+
+    for ( port = 0; port <= info.highest_evtchn_port; port++ )
     {
         status.dom = domid;
         status.port = port;
         rc = xc_evtchn_status(xch, &status);
         if ( rc < 0 )
-            break;
+            continue;
 
         if ( status.status == EVTCHNSTAT_closed )
             continue;
Signature · 1 line
2.34.1
#4 lore raw

Re: [XEN PATCH 2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration

Quoted 11 lines · Matthew Barnes
tools/xcutils/lsevtchn.c +1 -0
@@ -11,6 +11,7 @@ int main(int argc, char **argv)
     xc_interface *xch;
     int domid, port, rc;
     xc_evtchn_status_t status;
+    xc_domaininfo_t info;
 
     domid = (argc > 1) ? strtol(argv[1], NULL, 10) : 0;
 

tools/xcutils/lsevtchn.c int main(int argc, char **argv) · line 23

Quoted 6 lines
tools/xcutils/lsevtchn.c +2 -1
@@ -18,13 +19,16 @@ int main(int argc, char **argv)
     if ( !xch )
         errx(1, "failed to open control interface");
 
-    for ( port = 0; ; port++ )
+    if ( xc_domain_getinfo_single(xch, domid, &info) < 0 )
+        errx(1, "failed to fetch domain info");

This being backed by a domctl will make things fail when run on a DomU, which aiui is supposed to be a valid environment to run lsevtchn in (to obtain information just for the local domain). Imo instead of trying to figure out the highest valid port number (which at least in principle may even be dynamic, and hence the value returned by be stale by the time it is being used), the loop below needs to continue until receiving a specific indicator (special error code most likely).

Jan

Quoted 11 lines
tools/xcutils/lsevtchn.c +2 -1
+    for ( port = 0; port <= info.highest_evtchn_port; port++ )
     {
         status.dom = domid;
         status.port = port;
         rc = xc_evtchn_status(xch, &status);
         if ( rc < 0 )
-            break;
+            continue;
 
         if ( status.status == EVTCHNSTAT_closed )
             continue;
#2 lore raw

Re: [XEN PATCH 1/2] xen/domctl: Add highest allocated evtchn port to getdomaininfo

In reply to Matthew Barnes
Quoted 13 lines · Matthew Barnes
xen/common/domctl.c +1 -0
@@ -73,6 +73,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info)
 
     info->domain = d->domain_id;
     info->max_vcpu_id = XEN_INVALID_MAX_VCPU_ID;
+    info->highest_evtchn_port = read_atomic(&d->valid_evtchns);
 
     /*
      * - domain is marked as blocked only if all its vcpus are blocked

xen/include/public/domctl.h struct xen_domctl_getdomaininfo { · line 149

Quoted 6 lines
xen/include/public/domctl.h +2 -1
@@ -145,7 +145,8 @@ struct xen_domctl_getdomaininfo {
     xen_domain_handle_t handle;
     uint32_t cpupool;
     uint8_t gpaddr_bits; /* Guest physical address space size. */
-    uint8_t pad2[7];
+    uint8_t pad2[3];
+    evtchn_port_t highest_evtchn_port; /* Highest allocated event channel port. Used for enumeration */

While, as per my reply to patch 2, I don't think this is a viable route, I'd still like to mention that the name of the new field is wrong, leading to an off-by-1 in the consumer in patch 2. d->valid_evtchns is a count, not the "maximum valid" port number.

Jan