xen/events: bug fixes and some diagnostic aids
Subsystems (2)
Juergen Gross
maintainerv4 cover xen/events: bug fixes and some diagnostic aids
Those are fixes for XSA-332.
The rest of the V3 patches have been applied already. There is one additional fix in patch 2 which addresses network outages when a guest is doing reboot loops.
Juergen Gross (3):
xen/events: reset affinity of 2-level event when tearing it down xen/events: don't unmask an event channel when an eoi is pending xen/events: avoid handling the same event on two cpus at the same time
drivers/xen/events/events_2l.c | 22 +++-- drivers/xen/events/events_base.c | 130 ++++++++++++++++++++------- drivers/xen/events/events_fifo.c | 7 -- drivers/xen/events/events_internal.h | 14 +-- 4 files changed, 123 insertions(+), 50 deletions(-)
Signature · 1 line
2.26.2
Juergen Gross
maintainerPATCH v4 1/3 xen/events: reset affinity of 2-level event when tearing it down
When creating a new event channel with 2-level events the affinity needs to be reset initially in order to avoid using an old affinity from earlier usage of the event channel port. So when tearing an event channel down reset all affinity bits.
The same applies to the affinity when onlining a vcpu: all old affinity settings for this vcpu must be reset. As percpu events get initialized before the percpu event channel hook is called, resetting of the affinities happens after offlining a vcpu (this is working, as initial percpu memory is zeroed out).
---
V2:
- reset affinity when tearing down the event (Julien Grall)
--- drivers/xen/events/events_2l.c | 15 +++++++++++++++ drivers/xen/events/events_base.c | 1 + drivers/xen/events/events_internal.h | 8 ++++++++ 3 files changed, 24 insertions(+)
drivers/xen/events/events_2l.c +15 -0
@@ -47,6 +47,11 @@ static unsigned evtchn_2l_max_channels(void)return EVTCHN_2L_NR_CHANNELS ; } +static void evtchn_2l_remove (evtchn_port_t evtchn,unsigned int cpu) +{ +clear_bit (evtchn,BM (per_cpu (cpu_evtchn_mask, cpu))); +} +static void evtchn_2l_bind_to_cpu (evtchn_port_t evtchn,unsigned int cpu,unsigned int old_cpu) {
@@ -355,9 +360,18 @@ static void evtchn_2l_resume(void) EVTCHN_2L_NR_CHANNELS/BITS_PER_EVTCHN_WORD); } +static int evtchn_2l_percpu_deinit (unsigned int cpu) +{ +memset (per_cpu (cpu_evtchn_mask, cpu),0 ,sizeof (xen_ulong_t) * +EVTCHN_2L_NR_CHANNELS /BITS_PER_EVTCHN_WORD ); + +return 0 ; +} +static const struct evtchn_ops evtchn_ops_2l = { .max_channels = evtchn_2l_max_channels, .nr_channels = evtchn_2l_max_channels, + .remove = evtchn_2l_remove, .bind_to_cpu = evtchn_2l_bind_to_cpu, .clear_pending = evtchn_2l_clear_pending, .set_pending = evtchn_2l_set_pending,
@@ -367,6 +381,7 @@ static const struct evtchn_ops evtchn_ops_2l = { .unmask = evtchn_2l_unmask, .handle_events = evtchn_2l_handle_events, .resume = evtchn_2l_resume, + .percpu_deinit = evtchn_2l_percpu_deinit, };void __init xen_evtchn_2l_init (void )
drivers/xen/events/events_base.c +1 -0
@@ -377,6 +377,7 @@ static int xen_irq_info_pirq_setup(unsigned irq,static void xen_irq_info_cleanup (struct irq_info *info) {set_evtchn_to_irq (info->evtchn,-1 ); +xen_evtchn_port_remove (info->evtchn, info->cpu); info->evtchn =0 ;channels_on_cpu_dec (info); }
drivers/xen/events/events_internal.h +8 -0
@@ -14,6 +14,7 @@ struct evtchn_ops {unsigned (*nr_channels)(void );int (*setup)(evtchn_port_t port); +void (*remove)(evtchn_port_t port,unsigned int cpu);void (*bind_to_cpu)(evtchn_port_t evtchn,unsigned int cpu,unsigned int old_cpu);
@@ -54,6 +55,13 @@ static inline int xen_evtchn_port_setup(evtchn_port_t evtchn)return 0 ; } +static inline void xen_evtchn_port_remove (evtchn_port_t evtchn, +unsigned int cpu) +{ +if (evtchn_ops->remove) + evtchn_ops->remove (evtchn, cpu); +} +static inline void xen_evtchn_port_bind_to_cpu (evtchn_port_t evtchn,unsigned int cpu,unsigned int old_cpu)
Signature · 1 line
2.26.2
Juergen Gross
maintainerPATCH v4 2/3 xen/events: don't unmask an event channel when an eoi is pending
In reply to Juergen GrossAn event channel should be kept masked when an eoi is pending for it. When being migrated to another cpu it might be unmasked, though.
In order to avoid this keep three different flags for each event channel to be able to distinguish "normal" masking/unmasking from eoi related masking/unmasking and temporary masking. The event channel should only be able to generate an interrupt if all flags are cleared.
---
V2:
- introduce a lock around masking/unmasking
- merge patch 3 into this one (Jan Beulich)
V4:
- don't set eoi masking flag in lateeoi_mask_ack_dynirq()
--- drivers/xen/events/events_2l.c | 7 -- drivers/xen/events/events_base.c | 101 +++++++++++++++++++++------ drivers/xen/events/events_fifo.c | 7 -- drivers/xen/events/events_internal.h | 6 -- 4 files changed, 80 insertions(+), 41 deletions(-)
drivers/xen/events/events_2l.c +0 -7
@@ -77,12 +77,6 @@ static bool evtchn_2l_is_pending(evtchn_port_t port)return sync_test_bit (port,BM (&s->evtchn_pending[0 ])); } -static bool evtchn_2l_test_and_set_mask (evtchn_port_t port) -{ -struct shared_info *s = HYPERVISOR_shared_info; -return sync_test_and_set_bit (port,BM (&s->evtchn_mask[0 ])); -} -static void evtchn_2l_mask (evtchn_port_t port) {struct shared_info *s = HYPERVISOR_shared_info;
@@ -376,7 +370,6 @@ static const struct evtchn_ops evtchn_ops_2l = { .clear_pending = evtchn_2l_clear_pending, .set_pending = evtchn_2l_set_pending, .is_pending = evtchn_2l_is_pending, - .test_and_set_mask = evtchn_2l_test_and_set_mask, .mask = evtchn_2l_mask, .unmask = evtchn_2l_unmask, .handle_events = evtchn_2l_handle_events,
drivers/xen/events/events_base.c +80 -21
208 lines not on this page · raw message
drivers/xen/events/events_fifo.c +0 -7
@@ -209,12 +209,6 @@ static bool evtchn_fifo_is_pending(evtchn_port_t port)return sync_test_bit (EVTCHN_FIFO_BIT (PENDING , word),BM (word)); } -static bool evtchn_fifo_test_and_set_mask (evtchn_port_t port) -{ -event_word_t *word =event_word_from_port (port); -return sync_test_and_set_bit (EVTCHN_FIFO_BIT (MASKED , word),BM (word)); -} -static void evtchn_fifo_mask (evtchn_port_t port) {event_word_t *word =event_word_from_port (port);
@@ -423,7 +417,6 @@ static const struct evtchn_ops evtchn_ops_fifo = { .clear_pending = evtchn_fifo_clear_pending, .set_pending = evtchn_fifo_set_pending, .is_pending = evtchn_fifo_is_pending, - .test_and_set_mask = evtchn_fifo_test_and_set_mask, .mask = evtchn_fifo_mask, .unmask = evtchn_fifo_unmask, .handle_events = evtchn_fifo_handle_events,
drivers/xen/events/events_internal.h +0 -6
@@ -21,7 +21,6 @@ struct evtchn_ops {void (*clear_pending)(evtchn_port_t port);void (*set_pending)(evtchn_port_t port);bool (*is_pending)(evtchn_port_t port); -bool (*test_and_set_mask)(evtchn_port_t port);void (*mask)(evtchn_port_t port);void (*unmask)(evtchn_port_t port);
@@ -84,11 +83,6 @@ static inline bool test_evtchn(evtchn_port_t port)return evtchn_ops->is_pending (port); } -static inline bool test_and_set_mask (evtchn_port_t port) -{ -return evtchn_ops->test_and_set_mask (port); -} -static inline void mask_evtchn (evtchn_port_t port) {return evtchn_ops->mask (port);
Signature · 1 line
2.26.2
Re: [PATCH v4 2/3] xen/events: don't unmask an event channel when an eoi is pending
Quoted 13 lines · Juergen Gross
An event channel should be kept masked when an eoi is pending for it. When being migrated to another cpu it might be unmasked, though.
In order to avoid this keep three different flags for each event channel to be able to distinguish "normal" masking/unmasking from eoi related masking/unmasking and temporary masking. The event channel should only be able to generate an interrupt if all flags are cleared.
Fixes 54c9de89895e0a36047 ("xen/events: add a new late EOI evtchn framework")Reported-by Julien Grall <[email protected]>Signed-off-by Juergen Gross <[email protected]>Reviewed-by Julien Grall <[email protected]>
Quoted 6 lines
---
V2:
- introduce a lock around masking/unmasking
- merge patch 3 into this one (Jan Beulich)
V4:
- don't set eoi masking flag inlateeoi_mask_ack_dynirq()
Ross, are you planning to test this?
-boris
Jürgen Groß
maintainerRe: [PATCH v4 2/3] xen/events: don't unmask an event channel when an eoi is pending
Quoted 23 lines · Boris Ostrovsky
Quoted 13 lines · Juergen Gross
An event channel should be kept masked when an eoi is pending for it. When being migrated to another cpu it might be unmasked, though.
In order to avoid this keep three different flags for each event channel to be able to distinguish "normal" masking/unmasking from eoi related masking/unmasking and temporary masking. The event channel should only be able to generate an interrupt if all flags are cleared.
Fixes 54c9de89895e0a36047 ("xen/events: add a new late EOI evtchn framework")Reported-by Julien Grall <[email protected]>Signed-off-by Juergen Gross <[email protected]>Reviewed-by Julien Grall <[email protected]>Quoted 6 lines
---
V2:
- introduce a lock around masking/unmasking
- merge patch 3 into this one (Jan Beulich)
V4:
- don't set eoi masking flag inlateeoi_mask_ack_dynirq()
Quoted 4 lines
Reviewed-by Boris Ostrovsky <[email protected]>Ross, are you planning to test this?
Just as another data point: With the previous version of the patches a reboot loop of a guest needed max 33 reboots to loose network in my tests (those were IIRC 6 test runs). With this patch version I stopped the test after about 1300 reboots without having seen any problems.
Juergen
Re: [PATCH v4 2/3] xen/events: don't unmask an event channel when an eoi is pending
Quoted 27 lines · Jürgen Groß
Quoted 26 lines · Boris Ostrovsky
Quoted 13 lines · Juergen Gross
An event channel should be kept masked when an eoi is pending for it. When being migrated to another cpu it might be unmasked, though.
In order to avoid this keep three different flags for each event channel to be able to distinguish "normal" masking/unmasking from eoi related masking/unmasking and temporary masking. The event channel should only be able to generate an interrupt if all flags are cleared.
Fixes 54c9de89895e0a36047 ("xen/events: add a new late EOI evtchn framework")Reported-by Julien Grall <[email protected]>Signed-off-by Juergen Gross <[email protected]>Reviewed-by Julien Grall <[email protected]>Quoted 6 lines
---
V2:
- introduce a lock around masking/unmasking
- merge patch 3 into this one (Jan Beulich)
V4:
- don't set eoi masking flag inlateeoi_mask_ack_dynirq()Reviewed-by Boris Ostrovsky <[email protected]>
Quoted 8 lines
Quoted 1 line
Ross, are you planning to test this?
Just as another data point: With the previous version of the patches a reboot loop of a guest needed max 33 reboots to loose network in my tests (those were IIRC 6 test runs). With this patch version I stopped the test after about 1300 reboots without having seen any problems.
Thanks, I'll test it today and get back to you.
Ross
Ross Lagerwall
Tested-byRe: [PATCH v4 2/3] xen/events: don't unmask an event channel when an eoi is pending
Quoted 30 lines · Ross Lagerwall
Quoted 29 lines · Jürgen Groß
Quoted 27 lines · Boris Ostrovsky
Quoted 13 lines · Juergen Gross
An event channel should be kept masked when an eoi is pending for it. When being migrated to another cpu it might be unmasked, though.
In order to avoid this keep three different flags for each event channel to be able to distinguish "normal" masking/unmasking from eoi related masking/unmasking and temporary masking. The event channel should only be able to generate an interrupt if all flags are cleared.
Fixes 54c9de89895e0a36047 ("xen/events: add a new late EOI evtchn framework")Reported-by Julien Grall <[email protected]>Signed-off-by Juergen Gross <[email protected]>Reviewed-by Julien Grall <[email protected]>Quoted 6 lines
---
V2:
- introduce a lock around masking/unmasking
- merge patch 3 into this one (Jan Beulich)
V4:
- don't set eoi masking flag inlateeoi_mask_ack_dynirq()Reviewed-by Boris Ostrovsky <[email protected]>Ross, are you planning to test this?
Quoted 9 lines
Quoted 6 lines
Just as another data point: With the previous version of the patches a reboot loop of a guest needed max 33 reboots to loose network in my tests (those were IIRC 6 test runs). With this patch version I stopped the test after about 1300 reboots without having seen any problems.
Thanks, I'll test it today and get back to you.
The updated patch seems fine in testing.
Thanks
Ross
Juergen Gross
maintainerPATCH v4 3/3 xen/events: avoid handling the same event on two cpus at the same time
In reply to Juergen GrossWhen changing the cpu affinity of an event it can happen today that (with some unlucky timing) the same event will be handled on the old and the new cpu at the same time.
Avoid that by adding an "event active" flag to the per-event data and call the handler only if this flag isn't set.
---
V2:
- new patch
V3:
- use common helper for end of handler action (Julien Grall)
- move setting is_active to 0 for lateeoi (Boris Ostrovsky)
--- drivers/xen/events/events_base.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/xen/events/events_base.c +21 -11
@@ -103,6 +103,7 @@ struct irq_info {#define EVT_MASK_REASON_EXPLICIT 0x01#define EVT_MASK_REASON_TEMPORARY 0x02#define EVT_MASK_REASON_EOI_PENDING 0x04 +u8 is_active;/* Is event just being handled? */ unsigned irq;evtchn_port_t evtchn;/* event channel */ unsigned short cpu;/* cpu bound */
@@ -810,6 +811,12 @@ static void xen_evtchn_close(evtchn_port_t port)BUG (); } +static void event_handler_exit (struct irq_info *info) +{ +smp_store_release (&info->is_active,0 ); +clear_evtchn (info->evtchn); +} +static void pirq_query_unmask (int irq) {struct physdev_irq_status_query irq_status;
@@ -828,14 +835,15 @@ static void pirq_query_unmask(int irq)static void eoi_pirq (struct irq_data *data) { -evtchn_port_t evtchn =evtchn_from_irq (data->irq); +struct irq_info *info =info_for_irq (data->irq); +evtchn_port_t evtchn = info ? info->evtchn :0 ;struct physdev_eoi eoi = { .irq =pirq_from_irq (data->irq) };int rc =0 ;if (!VALID_EVTCHN (evtchn))return ; -clear_evtchn (evtchn); +event_handler_exit (info);if (pirq_needs_eoi (data->irq)) { rc =HYPERVISOR_physdev_op (PHYSDEVOP_eoi, &eoi);
@@ -1666,6 +1674,8 @@ void handle_irq_for_port(evtchn_port_t port, struct evtchn_loop_ctrl *ctrl) } info =info_for_irq (irq); +if (xchg_acquire (&info->is_active,1 )) +return ; dev = (info->type ==IRQT_EVTCHN ) ? info->u.interdomain :NULL ;if (dev)
@@ -1853,12 +1863,11 @@ static void disable_dynirq(struct irq_data *data)static void ack_dynirq (struct irq_data *data) { -evtchn_port_t evtchn =evtchn_from_irq (data->irq); - -if (!VALID_EVTCHN (evtchn)) -return ; +struct irq_info *info =info_for_irq (data->irq); +evtchn_port_t evtchn = info ? info->evtchn :0 ; -clear_evtchn (evtchn); +if (VALID_EVTCHN (evtchn)) +event_handler_exit (info); }static void mask_ack_dynirq (struct irq_data *data)
@@ -1874,7 +1883,7 @@ static void lateeoi_ack_dynirq(struct irq_data *data)if (VALID_EVTCHN (evtchn)) {do_mask (info,EVT_MASK_REASON_EOI_PENDING ); -clear_evtchn (evtchn); +event_handler_exit (info); } }
@@ -1885,7 +1894,7 @@ static void lateeoi_mask_ack_dynirq(struct irq_data *data)if (VALID_EVTCHN (evtchn)) {do_mask (info,EVT_MASK_REASON_EXPLICIT ); -clear_evtchn (evtchn); +event_handler_exit (info); } }
@@ -1998,10 +2007,11 @@ static void restore_cpu_ipis(unsigned int cpu)/* Clear an irq's pending state, in preparation for polling on it */ void xen_clear_irq_pending (int irq) { -evtchn_port_t evtchn =evtchn_from_irq (irq); +struct irq_info *info =info_for_irq (irq); +evtchn_port_t evtchn = info ? info->evtchn :0 ;if (VALID_EVTCHN (evtchn)) -clear_evtchn (evtchn); +event_handler_exit (info); }EXPORT_SYMBOL (xen_clear_irq_pending);void xen_set_irq_pending (int irq)
Signature · 1 line
2.26.2
Boris Ostrovsky
AppliedQuoted 11 lines · Juergen Gross
Those are fixes for XSA-332.
The rest of the V3 patches have been applied already. There is one additional fix in patch 2 which addresses network outages when a guest is doing reboot loops.
Juergen Gross (3):
xen/events: reset affinity of 2-level event when tearing it down xen/events: don't unmask an event channel when an eoi is pending xen/events: avoid handling the same event on two cpus at the same time
Quoted 5 lines
drivers/xen/events/events_2l.c | 22 +++-- drivers/xen/events/events_base.c | 130 ++++++++++++++++++++------- drivers/xen/events/events_fifo.c | 7 -- drivers/xen/events/events_internal.h | 14 +-- 4 files changed, 123 insertions(+), 50 deletions(-)
Applied to for-linus-5.12b