[PATCH v2 5/9] tools/libxenevtchn: add xenevtchn_bind() under Mini-OS

Juergen Gross posted 9 patches 3 months ago
There is a newer version of this series
[PATCH v2 5/9] tools/libxenevtchn: add xenevtchn_bind() under Mini-OS
Posted by Juergen Gross 3 months ago
In order to reactivate an event channel after kexec() of Mini-OS,
libxenevtchn needs to allocate the port data for the event channel
and set the handler again. Add a new interface xenevtchn_bind()
for that purpose, available under Mini-OS only.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
---
 tools/include/xenevtchn.h  | 11 +++++++++++
 tools/libs/evtchn/minios.c | 17 +++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/tools/include/xenevtchn.h b/tools/include/xenevtchn.h
index 1255c85178..113a718d67 100644
--- a/tools/include/xenevtchn.h
+++ b/tools/include/xenevtchn.h
@@ -173,6 +173,17 @@ int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port);
  */
 int xenevtchn_restrict(xenevtchn_handle *xce, domid_t domid);
 
+/**
+ * Bind an event channel under Mini-OS.
+ *
+ * Bind an event channel specified by its known port after a kexec() of
+ * Mini-OS. This function is available under Mini-OS only!
+ *
+ * @parm xce handle to the open evtchn interface
+ * @parm port the event channel to bind again
+ * @return 0 on success, -1 on failure with errno set appropriately.
+ */
+int xenevtchn_bind(xenevtchn_handle *xce, evtchn_port_t port);
 #endif
 
 /*
diff --git a/tools/libs/evtchn/minios.c b/tools/libs/evtchn/minios.c
index 0d2a201438..36e4201249 100644
--- a/tools/libs/evtchn/minios.c
+++ b/tools/libs/evtchn/minios.c
@@ -259,6 +259,23 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce,
     return local_port;
 }
 
+int xenevtchn_bind(xenevtchn_handle *xce, evtchn_port_t port)
+{
+    struct port_info *port_info;
+    port_info = port_alloc(xce);
+    if ( port_info == NULL )
+        return -1;
+
+    printf("xenevtchn_bind(%"PRId32")\n", port);
+    bind_evtchn(port, evtchn_handler, xce);
+
+    port_info->bound = true;
+    port_info->port = port;
+    unmask_evtchn(port);
+
+    return 0;
+}
+
 int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port_t port)
 {
     int fd = xce->fd;
-- 
2.43.0
Re: [PATCH v2 5/9] tools/libxenevtchn: add xenevtchn_bind() under Mini-OS
Posted by Anthony PERARD 3 months ago
On Tue, Jul 29, 2025 at 01:01:41PM +0200, Juergen Gross wrote:
> In order to reactivate an event channel after kexec() of Mini-OS,
> libxenevtchn needs to allocate the port data for the event channel
> and set the handler again. Add a new interface xenevtchn_bind()
> for that purpose, available under Mini-OS only.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
> ---
>  tools/include/xenevtchn.h  | 11 +++++++++++
>  tools/libs/evtchn/minios.c | 17 +++++++++++++++++
>  2 files changed, 28 insertions(+)
> 
> diff --git a/tools/include/xenevtchn.h b/tools/include/xenevtchn.h
> index 1255c85178..113a718d67 100644
> --- a/tools/include/xenevtchn.h
> +++ b/tools/include/xenevtchn.h
> @@ -173,6 +173,17 @@ int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port);
>   */
>  int xenevtchn_restrict(xenevtchn_handle *xce, domid_t domid);
>  
> +/**
> + * Bind an event channel under Mini-OS.
> + *
> + * Bind an event channel specified by its known port after a kexec() of
> + * Mini-OS. This function is available under Mini-OS only!

Would guarding this prototype within "#ifdef __MINIOS__" be useful to
prevent it from been used? That would give an error earlier when
compiling, rather than later when linking a binary.

In anycase: Acked-by: Anthony PERARD <anthony.perard@vates.tech>

> + *
> + * @parm xce handle to the open evtchn interface
> + * @parm port the event channel to bind again
> + * @return 0 on success, -1 on failure with errno set appropriately.
> + */
> +int xenevtchn_bind(xenevtchn_handle *xce, evtchn_port_t port);
>  #endif
>  
>  /*

Thanks,

-- 
Anthony PERARD
Re: [PATCH v2 5/9] tools/libxenevtchn: add xenevtchn_bind() under Mini-OS
Posted by Jürgen Groß 3 months ago
On 29.07.25 19:00, Anthony PERARD wrote:
> On Tue, Jul 29, 2025 at 01:01:41PM +0200, Juergen Gross wrote:
>> In order to reactivate an event channel after kexec() of Mini-OS,
>> libxenevtchn needs to allocate the port data for the event channel
>> and set the handler again. Add a new interface xenevtchn_bind()
>> for that purpose, available under Mini-OS only.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
>> ---
>>   tools/include/xenevtchn.h  | 11 +++++++++++
>>   tools/libs/evtchn/minios.c | 17 +++++++++++++++++
>>   2 files changed, 28 insertions(+)
>>
>> diff --git a/tools/include/xenevtchn.h b/tools/include/xenevtchn.h
>> index 1255c85178..113a718d67 100644
>> --- a/tools/include/xenevtchn.h
>> +++ b/tools/include/xenevtchn.h
>> @@ -173,6 +173,17 @@ int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port);
>>    */
>>   int xenevtchn_restrict(xenevtchn_handle *xce, domid_t domid);
>>   
>> +/**
>> + * Bind an event channel under Mini-OS.
>> + *
>> + * Bind an event channel specified by its known port after a kexec() of
>> + * Mini-OS. This function is available under Mini-OS only!
> 
> Would guarding this prototype within "#ifdef __MINIOS__" be useful to
> prevent it from been used? That would give an error earlier when
> compiling, rather than later when linking a binary.

Yes, I can add that.

> 
> In anycase: Acked-by: Anthony PERARD <anthony.perard@vates.tech>

Thanks,


Juergen