Skip to content

Commit 30cdb86

Browse files
jgross1gregkh
authored andcommitted
xen/events: don't unmask an event channel when an eoi is pending
commit 25da461 upstream. 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. Cc: stable@vger.kernel.org Fixes: 54c9de8 ("xen/events: add a new "late EOI" evtchn framework") Reported-by: Julien Grall <julien@xen.org> Signed-off-by: Juergen Gross <jgross@suse.com> Reviewed-by: Julien Grall <jgrall@amazon.com> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Tested-by: Ross Lagerwall <ross.lagerwall@citrix.com> Link: https://lore.kernel.org/r/20210306161833.4552-3-jgross@suse.com [boris -- corrected Fixed tag format] Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4c84191 commit 30cdb86

4 files changed

Lines changed: 88 additions & 49 deletions

File tree

‎drivers/xen/events/events_2l.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ static bool evtchn_2l_is_pending(evtchn_port_t port)
7777
return sync_test_bit(port, BM(&s->evtchn_pending[0]));
7878
}
7979

80-
static bool evtchn_2l_test_and_set_mask(evtchn_port_t port)
81-
{
82-
struct shared_info *s = HYPERVISOR_shared_info;
83-
return sync_test_and_set_bit(port, BM(&s->evtchn_mask[0]));
84-
}
85-
8680
static void evtchn_2l_mask(evtchn_port_t port)
8781
{
8882
struct shared_info *s = HYPERVISOR_shared_info;
@@ -376,7 +370,6 @@ static const struct evtchn_ops evtchn_ops_2l = {
376370
.clear_pending = evtchn_2l_clear_pending,
377371
.set_pending = evtchn_2l_set_pending,
378372
.is_pending = evtchn_2l_is_pending,
379-
.test_and_set_mask = evtchn_2l_test_and_set_mask,
380373
.mask = evtchn_2l_mask,
381374
.unmask = evtchn_2l_unmask,
382375
.handle_events = evtchn_2l_handle_events,

‎drivers/xen/events/events_base.c‎

Lines changed: 88 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,18 @@ struct irq_info {
9696
struct list_head eoi_list;
9797
short refcnt;
9898
short spurious_cnt;
99-
enum xen_irq_type type; /* type */
99+
short type; /* type */
100+
u8 mask_reason; /* Why is event channel masked */
101+
#define EVT_MASK_REASON_EXPLICIT 0x01
102+
#define EVT_MASK_REASON_TEMPORARY 0x02
103+
#define EVT_MASK_REASON_EOI_PENDING 0x04
100104
unsigned irq;
101105
evtchn_port_t evtchn; /* event channel */
102106
unsigned short cpu; /* cpu bound */
103107
unsigned short eoi_cpu; /* EOI must happen on this cpu-1 */
104108
unsigned int irq_epoch; /* If eoi_cpu valid: irq_epoch of event */
105109
u64 eoi_time; /* Time in jiffies when to EOI. */
110+
spinlock_t lock;
106111

107112
union {
108113
unsigned short virq;
@@ -151,6 +156,7 @@ static DEFINE_RWLOCK(evtchn_rwlock);
151156
* evtchn_rwlock
152157
* IRQ-desc lock
153158
* percpu eoi_list_lock
159+
* irq_info->lock
154160
*/
155161

156162
static LIST_HEAD(xen_irq_list_head);
@@ -272,6 +278,8 @@ static int xen_irq_info_common_setup(struct irq_info *info,
272278
info->irq = irq;
273279
info->evtchn = evtchn;
274280
info->cpu = cpu;
281+
info->mask_reason = EVT_MASK_REASON_EXPLICIT;
282+
spin_lock_init(&info->lock);
275283

276284
ret = set_evtchn_to_irq(evtchn, irq);
277285
if (ret < 0)
@@ -419,6 +427,34 @@ unsigned int cpu_from_evtchn(evtchn_port_t evtchn)
419427
return ret;
420428
}
421429

430+
static void do_mask(struct irq_info *info, u8 reason)
431+
{
432+
unsigned long flags;
433+
434+
spin_lock_irqsave(&info->lock, flags);
435+
436+
if (!info->mask_reason)
437+
mask_evtchn(info->evtchn);
438+
439+
info->mask_reason |= reason;
440+
441+
spin_unlock_irqrestore(&info->lock, flags);
442+
}
443+
444+
static void do_unmask(struct irq_info *info, u8 reason)
445+
{
446+
unsigned long flags;
447+
448+
spin_lock_irqsave(&info->lock, flags);
449+
450+
info->mask_reason &= ~reason;
451+
452+
if (!info->mask_reason)
453+
unmask_evtchn(info->evtchn);
454+
455+
spin_unlock_irqrestore(&info->lock, flags);
456+
}
457+
422458
#ifdef CONFIG_X86
423459
static bool pirq_check_eoi_map(unsigned irq)
424460
{
@@ -546,7 +582,7 @@ static void xen_irq_lateeoi_locked(struct irq_info *info, bool spurious)
546582
}
547583

548584
info->eoi_time = 0;
549-
unmask_evtchn(evtchn);
585+
do_unmask(info, EVT_MASK_REASON_EOI_PENDING);
550586
}
551587

552588
static void xen_irq_lateeoi_worker(struct work_struct *work)
@@ -733,7 +769,8 @@ static void pirq_query_unmask(int irq)
733769

734770
static void eoi_pirq(struct irq_data *data)
735771
{
736-
evtchn_port_t evtchn = evtchn_from_irq(data->irq);
772+
struct irq_info *info = info_for_irq(data->irq);
773+
evtchn_port_t evtchn = info ? info->evtchn : 0;
737774
struct physdev_eoi eoi = { .irq = pirq_from_irq(data->irq) };
738775
int rc = 0;
739776

@@ -742,14 +779,13 @@ static void eoi_pirq(struct irq_data *data)
742779

743780
if (unlikely(irqd_is_setaffinity_pending(data)) &&
744781
likely(!irqd_irq_disabled(data))) {
745-
int masked = test_and_set_mask(evtchn);
782+
do_mask(info, EVT_MASK_REASON_TEMPORARY);
746783

747784
clear_evtchn(evtchn);
748785

749786
irq_move_masked_irq(data);
750787

751-
if (!masked)
752-
unmask_evtchn(evtchn);
788+
do_unmask(info, EVT_MASK_REASON_TEMPORARY);
753789
} else
754790
clear_evtchn(evtchn);
755791

@@ -802,7 +838,8 @@ static unsigned int __startup_pirq(unsigned int irq)
802838
goto err;
803839

804840
out:
805-
unmask_evtchn(evtchn);
841+
do_unmask(info, EVT_MASK_REASON_EXPLICIT);
842+
806843
eoi_pirq(irq_get_irq_data(irq));
807844

808845
return 0;
@@ -829,7 +866,7 @@ static void shutdown_pirq(struct irq_data *data)
829866
if (!VALID_EVTCHN(evtchn))
830867
return;
831868

832-
mask_evtchn(evtchn);
869+
do_mask(info, EVT_MASK_REASON_EXPLICIT);
833870
xen_evtchn_close(evtchn);
834871
xen_irq_info_cleanup(info);
835872
}
@@ -1656,10 +1693,10 @@ void rebind_evtchn_irq(evtchn_port_t evtchn, int irq)
16561693
}
16571694

16581695
/* Rebind an evtchn so that it gets delivered to a specific cpu */
1659-
static int xen_rebind_evtchn_to_cpu(evtchn_port_t evtchn, unsigned int tcpu)
1696+
static int xen_rebind_evtchn_to_cpu(struct irq_info *info, unsigned int tcpu)
16601697
{
16611698
struct evtchn_bind_vcpu bind_vcpu;
1662-
int masked;
1699+
evtchn_port_t evtchn = info ? info->evtchn : 0;
16631700

16641701
if (!VALID_EVTCHN(evtchn))
16651702
return -1;
@@ -1675,7 +1712,7 @@ static int xen_rebind_evtchn_to_cpu(evtchn_port_t evtchn, unsigned int tcpu)
16751712
* Mask the event while changing the VCPU binding to prevent
16761713
* it being delivered on an unexpected VCPU.
16771714
*/
1678-
masked = test_and_set_mask(evtchn);
1715+
do_mask(info, EVT_MASK_REASON_TEMPORARY);
16791716

16801717
/*
16811718
* If this fails, it usually just indicates that we're dealing with a
@@ -1685,8 +1722,7 @@ static int xen_rebind_evtchn_to_cpu(evtchn_port_t evtchn, unsigned int tcpu)
16851722
if (HYPERVISOR_event_channel_op(EVTCHNOP_bind_vcpu, &bind_vcpu) >= 0)
16861723
bind_evtchn_to_cpu(evtchn, tcpu);
16871724

1688-
if (!masked)
1689-
unmask_evtchn(evtchn);
1725+
do_unmask(info, EVT_MASK_REASON_TEMPORARY);
16901726

16911727
return 0;
16921728
}
@@ -1695,7 +1731,7 @@ static int set_affinity_irq(struct irq_data *data, const struct cpumask *dest,
16951731
bool force)
16961732
{
16971733
unsigned tcpu = cpumask_first_and(dest, cpu_online_mask);
1698-
int ret = xen_rebind_evtchn_to_cpu(evtchn_from_irq(data->irq), tcpu);
1734+
int ret = xen_rebind_evtchn_to_cpu(info_for_irq(data->irq), tcpu);
16991735

17001736
if (!ret)
17011737
irq_data_update_effective_affinity(data, cpumask_of(tcpu));
@@ -1714,37 +1750,39 @@ EXPORT_SYMBOL_GPL(xen_set_affinity_evtchn);
17141750

17151751
static void enable_dynirq(struct irq_data *data)
17161752
{
1717-
evtchn_port_t evtchn = evtchn_from_irq(data->irq);
1753+
struct irq_info *info = info_for_irq(data->irq);
1754+
evtchn_port_t evtchn = info ? info->evtchn : 0;
17181755

17191756
if (VALID_EVTCHN(evtchn))
1720-
unmask_evtchn(evtchn);
1757+
do_unmask(info, EVT_MASK_REASON_EXPLICIT);
17211758
}
17221759

17231760
static void disable_dynirq(struct irq_data *data)
17241761
{
1725-
evtchn_port_t evtchn = evtchn_from_irq(data->irq);
1762+
struct irq_info *info = info_for_irq(data->irq);
1763+
evtchn_port_t evtchn = info ? info->evtchn : 0;
17261764

17271765
if (VALID_EVTCHN(evtchn))
1728-
mask_evtchn(evtchn);
1766+
do_mask(info, EVT_MASK_REASON_EXPLICIT);
17291767
}
17301768

17311769
static void ack_dynirq(struct irq_data *data)
17321770
{
1733-
evtchn_port_t evtchn = evtchn_from_irq(data->irq);
1771+
struct irq_info *info = info_for_irq(data->irq);
1772+
evtchn_port_t evtchn = info ? info->evtchn : 0;
17341773

17351774
if (!VALID_EVTCHN(evtchn))
17361775
return;
17371776

17381777
if (unlikely(irqd_is_setaffinity_pending(data)) &&
17391778
likely(!irqd_irq_disabled(data))) {
1740-
int masked = test_and_set_mask(evtchn);
1779+
do_mask(info, EVT_MASK_REASON_TEMPORARY);
17411780

17421781
clear_evtchn(evtchn);
17431782

17441783
irq_move_masked_irq(data);
17451784

1746-
if (!masked)
1747-
unmask_evtchn(evtchn);
1785+
do_unmask(info, EVT_MASK_REASON_TEMPORARY);
17481786
} else
17491787
clear_evtchn(evtchn);
17501788
}
@@ -1755,18 +1793,39 @@ static void mask_ack_dynirq(struct irq_data *data)
17551793
ack_dynirq(data);
17561794
}
17571795

1796+
static void lateeoi_ack_dynirq(struct irq_data *data)
1797+
{
1798+
struct irq_info *info = info_for_irq(data->irq);
1799+
evtchn_port_t evtchn = info ? info->evtchn : 0;
1800+
1801+
if (VALID_EVTCHN(evtchn)) {
1802+
do_mask(info, EVT_MASK_REASON_EOI_PENDING);
1803+
clear_evtchn(evtchn);
1804+
}
1805+
}
1806+
1807+
static void lateeoi_mask_ack_dynirq(struct irq_data *data)
1808+
{
1809+
struct irq_info *info = info_for_irq(data->irq);
1810+
evtchn_port_t evtchn = info ? info->evtchn : 0;
1811+
1812+
if (VALID_EVTCHN(evtchn)) {
1813+
do_mask(info, EVT_MASK_REASON_EXPLICIT);
1814+
clear_evtchn(evtchn);
1815+
}
1816+
}
1817+
17581818
static int retrigger_dynirq(struct irq_data *data)
17591819
{
1760-
evtchn_port_t evtchn = evtchn_from_irq(data->irq);
1761-
int masked;
1820+
struct irq_info *info = info_for_irq(data->irq);
1821+
evtchn_port_t evtchn = info ? info->evtchn : 0;
17621822

17631823
if (!VALID_EVTCHN(evtchn))
17641824
return 0;
17651825

1766-
masked = test_and_set_mask(evtchn);
1826+
do_mask(info, EVT_MASK_REASON_TEMPORARY);
17671827
set_evtchn(evtchn);
1768-
if (!masked)
1769-
unmask_evtchn(evtchn);
1828+
do_unmask(info, EVT_MASK_REASON_TEMPORARY);
17701829

17711830
return 1;
17721831
}
@@ -1974,8 +2033,8 @@ static struct irq_chip xen_lateeoi_chip __read_mostly = {
19742033
.irq_mask = disable_dynirq,
19752034
.irq_unmask = enable_dynirq,
19762035

1977-
.irq_ack = mask_ack_dynirq,
1978-
.irq_mask_ack = mask_ack_dynirq,
2036+
.irq_ack = lateeoi_ack_dynirq,
2037+
.irq_mask_ack = lateeoi_mask_ack_dynirq,
19792038

19802039
.irq_set_affinity = set_affinity_irq,
19812040
.irq_retrigger = retrigger_dynirq,

‎drivers/xen/events/events_fifo.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,6 @@ static bool evtchn_fifo_is_pending(evtchn_port_t port)
209209
return sync_test_bit(EVTCHN_FIFO_BIT(PENDING, word), BM(word));
210210
}
211211

212-
static bool evtchn_fifo_test_and_set_mask(evtchn_port_t port)
213-
{
214-
event_word_t *word = event_word_from_port(port);
215-
return sync_test_and_set_bit(EVTCHN_FIFO_BIT(MASKED, word), BM(word));
216-
}
217-
218212
static void evtchn_fifo_mask(evtchn_port_t port)
219213
{
220214
event_word_t *word = event_word_from_port(port);
@@ -423,7 +417,6 @@ static const struct evtchn_ops evtchn_ops_fifo = {
423417
.clear_pending = evtchn_fifo_clear_pending,
424418
.set_pending = evtchn_fifo_set_pending,
425419
.is_pending = evtchn_fifo_is_pending,
426-
.test_and_set_mask = evtchn_fifo_test_and_set_mask,
427420
.mask = evtchn_fifo_mask,
428421
.unmask = evtchn_fifo_unmask,
429422
.handle_events = evtchn_fifo_handle_events,

‎drivers/xen/events/events_internal.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ struct evtchn_ops {
2121
void (*clear_pending)(evtchn_port_t port);
2222
void (*set_pending)(evtchn_port_t port);
2323
bool (*is_pending)(evtchn_port_t port);
24-
bool (*test_and_set_mask)(evtchn_port_t port);
2524
void (*mask)(evtchn_port_t port);
2625
void (*unmask)(evtchn_port_t port);
2726

@@ -84,11 +83,6 @@ static inline bool test_evtchn(evtchn_port_t port)
8483
return evtchn_ops->is_pending(port);
8584
}
8685

87-
static inline bool test_and_set_mask(evtchn_port_t port)
88-
{
89-
return evtchn_ops->test_and_set_mask(port);
90-
}
91-
9286
static inline void mask_evtchn(evtchn_port_t port)
9387
{
9488
return evtchn_ops->mask(port);

0 commit comments

Comments
 (0)