All of lore.kernel.org
 help / color / mirror / Atom feed
* [XEN PATCH 0/2] Enumerate all allocated evtchns in lsevtchn
@ 2024-04-11 15:24 Matthew Barnes
  2024-04-11 15:24 ` [XEN PATCH 1/2] xen/domctl: Add highest allocated evtchn port to getdomaininfo Matthew Barnes
  2024-04-11 15:24 ` [XEN PATCH 2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration Matthew Barnes
  0 siblings, 2 replies; 5+ messages in thread
From: Matthew Barnes @ 2024-04-11 15:24 UTC (permalink / raw)
  To: Xen-devel
  Cc: Matthew Barnes, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Stefano Stabellini, Anthony PERARD

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(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [XEN PATCH 1/2] xen/domctl: Add highest allocated evtchn port to getdomaininfo
  2024-04-11 15:24 [XEN PATCH 0/2] Enumerate all allocated evtchns in lsevtchn Matthew Barnes
@ 2024-04-11 15:24 ` Matthew Barnes
  2024-04-18 14:59   ` Jan Beulich
  2024-04-11 15:24 ` [XEN PATCH 2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration Matthew Barnes
  1 sibling, 1 reply; 5+ messages in thread
From: Matthew Barnes @ 2024-04-11 15:24 UTC (permalink / raw)
  To: Xen-devel
  Cc: Matthew Barnes, Andrew Cooper, George Dunlap, Jan Beulich,
	Julien Grall, Stefano Stabellini

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.

Signed-off-by: Matthew Barnes <matthew.barnes@cloud.com>
---
 xen/common/domctl.c         | 1 +
 xen/include/public/domctl.h | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 43b0b074c3a6..1d1ee17f6f91 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -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
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index a33f9ec32b08..d28d29180c75 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [XEN PATCH 2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration
  2024-04-11 15:24 [XEN PATCH 0/2] Enumerate all allocated evtchns in lsevtchn Matthew Barnes
  2024-04-11 15:24 ` [XEN PATCH 1/2] xen/domctl: Add highest allocated evtchn port to getdomaininfo Matthew Barnes
@ 2024-04-11 15:24 ` Matthew Barnes
  2024-04-18 14:34   ` Jan Beulich
  1 sibling, 1 reply; 5+ messages in thread
From: Matthew Barnes @ 2024-04-11 15:24 UTC (permalink / raw)
  To: Xen-devel; +Cc: Matthew Barnes, Anthony PERARD

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.

Signed-off-by: Matthew Barnes <matthew.barnes@cloud.com>
---
 tools/xcutils/lsevtchn.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/xcutils/lsevtchn.c b/tools/xcutils/lsevtchn.c
index d1710613ddc5..7f8ad7c8e7ce 100644
--- a/tools/xcutils/lsevtchn.c
+++ b/tools/xcutils/lsevtchn.c
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [XEN PATCH 2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration
  2024-04-11 15:24 ` [XEN PATCH 2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration Matthew Barnes
@ 2024-04-18 14:34   ` Jan Beulich
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Beulich @ 2024-04-18 14:34 UTC (permalink / raw)
  To: Matthew Barnes; +Cc: Anthony PERARD, Xen-devel

On 11.04.2024 17:24, Matthew Barnes wrote:
> --- a/tools/xcutils/lsevtchn.c
> +++ b/tools/xcutils/lsevtchn.c
> @@ -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");

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

> +    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;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [XEN PATCH 1/2] xen/domctl: Add highest allocated evtchn port to getdomaininfo
  2024-04-11 15:24 ` [XEN PATCH 1/2] xen/domctl: Add highest allocated evtchn port to getdomaininfo Matthew Barnes
@ 2024-04-18 14:59   ` Jan Beulich
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Beulich @ 2024-04-18 14:59 UTC (permalink / raw)
  To: Matthew Barnes
  Cc: Andrew Cooper, George Dunlap, Julien Grall, Stefano Stabellini,
	Xen-devel

On 11.04.2024 17:24, Matthew Barnes wrote:
> --- a/xen/common/domctl.c
> +++ b/xen/common/domctl.c
> @@ -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
> --- a/xen/include/public/domctl.h
> +++ b/xen/include/public/domctl.h
> @@ -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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-18 14:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11 15:24 [XEN PATCH 0/2] Enumerate all allocated evtchns in lsevtchn Matthew Barnes
2024-04-11 15:24 ` [XEN PATCH 1/2] xen/domctl: Add highest allocated evtchn port to getdomaininfo Matthew Barnes
2024-04-18 14:59   ` Jan Beulich
2024-04-11 15:24 ` [XEN PATCH 2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration Matthew Barnes
2024-04-18 14:34   ` Jan Beulich

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.