Allow mini-os to unbind all evtchns
PATCH 1/1 Allow mini-os to unbind all evtchns
The attached patch exports a function clients can call to have all Xen ports unbound. This is necessary when using mini-os as the foundation for a boot-loader.
Regards,
Jacob
extras/mini-os/events.c +15 -0
@@ -35,6 +35,21 @@ static ev_action_t ev_actions[NR_EVS];static ev_action_t ev_actions[NR_EVS ];void default_handler (evtchn_port_t port,struct pt_regs *regs,void *data); +void unbind_all_ports (void ) +{ +int i; + +for (i=0 ;i<NR_EVS ;i++) + { +if (ev_actions[i].handler != default_handler) + { +struct evtchn_close close; +mask_evtchn (i); + close.port = i; +HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); + } + } +}/* * Demux events to different handlers.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 3 lines · Jacob Gorm Hansen
The attached patch exports a function clients can call to have all Xen ports unbound. This is necessary when using mini-os as the foundation for a boot-loader.
Sorry, that patch did not work as intended. The correct version is attached. Bound ports are tracked in an array, and a function to unbind all ports in the array is exported.
Jacob
extras/mini-os/events.c +18 -0
@@ -31,10 +31,26 @@ typedef struct _ev_action_t {u32 count; } ev_action_t; +evtchn_port_t bound_ports[NR_EVS ]; +int num_bound_ports=0 ;static ev_action_t ev_actions[NR_EVS ];void default_handler (evtchn_port_t port,struct pt_regs *regs,void *data); +void unbind_all_ports (void ) +{ +int i; + +for (i=0 ; i<num_bound_ports; i++) + { +int ret; +struct evtchn_close close; +mask_evtchn (bound_ports[i]); + close.port = bound_ports[i]; + ret =HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); + } + num_bound_ports=0 ; +}/* * Demux events to different handlers.
@@ -99,6 +115,7 @@ int bind_virq(uint32_t virq, evtchn_handprintk ("Failed to bind virtual IRQ %d\n" , virq);return 1 ; } + bound_ports[num_bound_ports++] = op.port;bind_evtchn (op.port, handler, data);return 0 ; }
@@ -173,6 +190,7 @@ int evtchn_bind_interdomain(domid_t pal,int err =HYPERVISOR_event_channel_op (EVTCHNOP_bind_interdomain, &op);if (err)return err; + bound_ports[num_bound_ports++] = op.local_port;evtchn_port_t port = op.local_port;clear_evtchn (port);/* Without, handler gets invoked now! */ *local_port =bind_evtchn (port, handler, data);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
The patch looks good to me. I only have one comment: it would be good to have unbind_all_ports in the events header file.
Cheers
Gregor
Quoted 15 lines · Jacob Gorm Hansen
Quoted 3 lines · Jacob Gorm Hansen
The attached patch exports a function clients can call to have all Xen ports unbound. This is necessary when using mini-os as the foundation for a boot-loader.
Sorry, that patch did not work as intended. The correct version is attached. Bound ports are tracked in an array, and a function to unbind all ports in the array is exported.
Jacob
<miniosunbindall.patch>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 2 lines · Grzegorz Milos
The patch looks good to me. I only have one comment: it would be good to have
unbind_all_portsin the events header file.
It looked bogus to me. What if event channels are bound/unbound/bound multiple times during the mini-os lifetime (can't happen right now, but maybe in future). The port array will overflow. Perhaps it should be a bitmap instead (set on bind; clear on unbind)?
-- Keir
Am Mittwoch, 29. November 2006 13:25 schrieb Keir Fraser:
Quoted 4 lines
...
It looked bogus to me. What if event channels are bound/unbound/bound multiple times during the mini-os lifetime (can't happen right now, but maybe in future). The port array will overflow. Perhaps it should be a
What does it means "maybe in future"?
Has it to do with:
Quoted 4 lines · Jacob Gorm Hansen
Quoted 3 lines
...
ports unbound. This is necessary when using mini-os as the foundation for a boot-loader.
Can anybody give me a hint!
Thanks.
Dietmar.
Quoted 21 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Dietmar Hahn
Sent: 29 November 2006 13:27
To: [email protected]
Cc: Jacob Gorm Hansen; Keir Fraser; Grzegorz Milos
Subject: Re: [Xen-devel] [PATCH] Allow mini-os to unbind all evtchnsAm Mittwoch, 29. November 2006 13:25 schrieb Keir Fraser:
Quoted 2 lines
...
It looked bogus to me. What if event channels arebound/unbound/bound
Quoted 1 line
multiple times during the mini-os lifetime (can't happen
right now, but
Quoted 1 line
maybe in future). The port array will overflow. Perhaps it
should be a
What does it means "maybe in future"?
Quoted 7 lines
Has it to do with:
Quoted 3 lines · Jacob Gorm Hansen
Quoted 2 lines
...
ports unbound. This is necessary when using mini-os as thefoundation
Quoted 1 line
Quoted 1 line
for a boot-loader.
Can anybody give me a hint!
I'm not sure that is what Keir meant - more like: If you implement something, you may just as well think about any future extended features if it doesn't cause too much problems, for example using a bitmap instead of a plain array.
Another solution in this case would be to search/clear the array so that multiple bind/unbind operations don't cause the array content to "grow".
--
Mats
Quoted 11 lines
Thanks.
Dietmar.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 11 lines
I'm not sure that is what Keir meant - more like: If you implement something, you may just as well think about any future extended features if it doesn't cause too much problems, for example using a bitmap instead of a plain array.
Another solution in this case would be to search/clear the array so that multiple bind/unbind operations don't cause the array content to "grow".
--
Mats
OK, I thought that maybe mini-os should play a special role in the future and there are special aims with it ;-).
Thanks.
Dietmar
I guess bitmap would work better. We won't have to rewrite the code once event channel unbounding is allowed... Shouldn't be too hard.
Thanks
Gregor
Quoted 11 lines · Keir Fraser
Quoted 2 lines · Grzegorz Milos
The patch looks good to me. I only have one comment: it would be good to have
unbind_all_portsin the events header file.It looked bogus to me. What if event channels are bound/unbound/bound multiple times during the mini-os lifetime (can't happen right now, but maybe in future). The port array will overflow. Perhaps it should be a bitmap instead (set on bind; clear on unbind)?
-- Keir
Quoted 9 lines · Keir Fraser
Quoted 2 lines · Grzegorz Milos
The patch looks good to me. I only have one comment: it would be good to have
unbind_all_portsin the events header file.It looked bogus to me. What if event channels are bound/unbound/bound multiple times during the mini-os lifetime (can't happen right now, but maybe in future). The port array will overflow. Perhaps it should be a bitmap instead (set on bind; clear on unbind)?
I have attached a new version that uses a bitmap instead and declares unbind_all_ports() in events.h.
regards,
Jacob
extras/mini-os/events.c +18 -0
@@ -31,10 +31,26 @@ typedef struct _ev_action_t {u32 count; } ev_action_t; +unsigned long bound_ports[NR_EVS /(8 *sizeof (unsigned long ))];static ev_action_t ev_actions[NR_EVS ];void default_handler (evtchn_port_t port,struct pt_regs *regs,void *data); +void unbind_all_ports (void ) +{ +int i; + +for (i=0 ; i<NR_EVS ; i++) + { +if (test_and_clear_bit (i,bound_ports)) + { +struct evtchn_close close; +mask_evtchn (i); + close.port = i; +HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); + } + } +}/* * Demux events to different handlers.
@@ -99,6 +115,7 @@ int bind_virq(uint32_t virq, evtchn_handprintk ("Failed to bind virtual IRQ %d\n" , virq);return 1 ; } +set_bit (op.port,bound_ports);bind_evtchn (op.port, handler, data);return 0 ; }
@@ -173,6 +190,7 @@ int evtchn_bind_interdomain(domid_t pal,int err =HYPERVISOR_event_channel_op (EVTCHNOP_bind_interdomain, &op);if (err)return err; +set_bit (op.local_port,bound_ports);evtchn_port_t port = op.local_port;clear_evtchn (port);/* Without, handler gets invoked now! */ *local_port =bind_evtchn (port, handler, data);
extras/mini-os/include/events.h +1 -0
@@ -36,6 +36,7 @@ int evtchn_bind_interdomain(domid_t pal,int evtchn_bind_interdomain (domid_t pal,evtchn_port_t remote_port,evtchn_handler_t handler,void *data,evtchn_port_t *local_port); +void unbind_all_ports (void );static inline int notify_remote_via_evtchn (evtchn_port_t port) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
I've reworked the patch a little bit. I've added "flags" field to ev_action_t instead of creating a separate bitmap. The basic idea is still the some though.
This patch makes sure that all the ports are marked unbound on init, which your patch failed to do.
We can merge flags and count fields together, if we care about the space wasted.
Cheers
Gregor
(Keir could you apply please?)
Quoted 71 lines · Jacob Gorm Hansen
Quoted 8 lines · Keir Fraser
Quoted 2 lines · Grzegorz Milos
The patch looks good to me. I only have one comment: it would be good to have
unbind_all_portsin the events header file.It looked bogus to me. What if event channels are bound/unbound/bound multiple times during the mini-os lifetime (can't happen right now, but maybe in future). The port array will overflow. Perhaps it should be a bitmap instead (set on bind; clear on unbind)?
I have attached a new version that uses a bitmap instead and declares
unbind_all_ports()inevents.h.regards,
Jacob------------------------------------------------------------------------
Signed-off-by Jacob Gorm Hansen <[email protected]>diff -r
52ae8dd4bc75extras/mini-os/events.cextras/mini-os/events.c +18
-0@@ -31,10 +31,26 @@ typedef struct _ev_action_t {u32 count; } ev_action_t; +unsigned long bound_ports[NR_EVS /(8 *sizeof (unsigned long ))];static ev_action_t ev_actions[NR_EVS ];void default_handler (evtchn_port_t port,struct pt_regs *regs,void *data); +void unbind_all_ports (void ) +{ +int i; + +for (i=0 ; i<NR_EVS ; i++) + { +if (test_and_clear_bit (i,bound_ports)) + { +struct evtchn_close close; +mask_evtchn (i); + close.port = i; +HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); + } + } +}/* * Demux events to different handlers. @@ -99,6 +115,7 @@ int bind_virq(uint32_t virq, evtchn_handprintk ("Failed to bind virtual IRQ %d\n" , virq);return 1 ; } +set_bit (op.port,bound_ports);bind_evtchn (op.port, handler, data);return 0 ; }@@ -173,6 +190,7 @@ int evtchn_bind_interdomain(domid_t pal,int err =HYPERVISOR_event_channel_op (EVTCHNOP_bind_interdomain, &op);if (err)return err; +set_bit (op.local_port,bound_ports);evtchn_port_t port = op.local_port;clear_evtchn (port);/* Without, handler gets invoked now! */ *local_port =bind_evtchn (port, handler, data);diff -r
52ae8dd4bc75extras/mini-os/include/events.h
extras/mini-os/include/events.h int evtchn_bind_interdomain(domid_t pal, · line 42
Quoted 7 lines
extras/mini-os/include/events.h +1
-0@@ -36,6 +36,7 @@ int evtchn_bind_interdomain(domid_t pal,int evtchn_bind_interdomain (domid_t pal,evtchn_port_t remote_port,evtchn_handler_t handler,void *data,evtchn_port_t *local_port); +void unbind_all_ports (void );static inline int notify_remote_via_evtchn (evtchn_port_t port) {
extras/mini-os/events.c +22 -1
@@ -23,18 +23,35 @@#include <lib.h> #define NR_EVS 1024 +#define EVNTS_PORT_BOUND 0x00000001/* this represents a event handler. Chaining or sharing is not allowed */ typedef struct _ev_action_t {evtchn_handler_t handler;void *data;u32 count; +u32 flags; }ev_action_t ; -static ev_action_t ev_actions[NR_EVS ];void default_handler (evtchn_port_t port,struct pt_regs *regs,void *data); +void unbind_all_ports (void ) +{ +int i; + +for (i=0 ; i<NR_EVS ; i++) + { +if (ev_actions[i].flags &EVNTS_PORT_BOUND ) + { +struct evtchn_close close; +mask_evtchn (i); + close.port = i; +HYPERVISOR_event_channel_op (EVTCHNOP_close, &close); + ev_actions[i].flags &= ~EVNTS_PORT_BOUND ; + } + } +}/* * Demux events to different handlers.
@@ -99,6 +116,7 @@ int bind_virq(uint32_t virq, evtchn_handprintk ("Failed to bind virtual IRQ %d\n" , virq);return 1 ; } + ev_actions[op.port].flags |=EVNTS_PORT_BOUND ;bind_evtchn (op.port, handler, data);return 0 ; }
@@ -131,6 +149,8 @@ void init_events(void)for ( i =0 ; i <NR_EVS ; i++ ) { ev_actions[i].handler = default_handler; +/* Clear all flags, EVNTS_PORT_BOUND in particular */ + ev_actions[i].flags =0 ;mask_evtchn (i); } }
@@ -174,6 +194,7 @@ int evtchn_bind_interdomain(domid_t pal,if (err)return err;evtchn_port_t port = op.local_port; + ev_actions[port].flags |=EVNTS_PORT_BOUND ;clear_evtchn (port);/* Without, handler gets invoked now! */ *local_port =bind_evtchn (port, handler, data);return err;
extras/mini-os/include/events.h +1 -0
@@ -36,6 +36,7 @@ int evtchn_bind_interdomain(domid_t pal,int evtchn_bind_interdomain (domid_t pal,evtchn_port_t remote_port,evtchn_handler_t handler,void *data,evtchn_port_t *local_port); +void unbind_all_ports (void );static inline int notify_remote_via_evtchn (evtchn_port_t port) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel