This is a note to let you know that I've just added the patch titled xen/events: fix race in evtchn_fifo_unmask() to the 4.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: xen-events-fix-race-in-evtchn_fifo_unmask.patch and it can be found in the queue-4.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Tue Nov 17 12:26:02 PM CET 2020 From: Juergen Gross <jgross@xxxxxxxx> Date: Tue, 3 Nov 2020 17:22:29 +0100 Subject: xen/events: fix race in evtchn_fifo_unmask() To: stable@xxxxxxxxxxxxxxx Message-ID: <20201103162238.30264-5-jgross@xxxxxxxx> From: Juergen Gross <jgross@xxxxxxxx> commit f01337197419b7e8a492e83089552b77d3b5fb90 upstream. Unmasking a fifo event channel can result in unmasking it twice, once directly in the kernel and once via a hypercall in case the event was pending. Fix that by doing the local unmask only if the event is not pending. This is part of XSA-332. Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Juergen Gross <jgross@xxxxxxxx> Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/xen/events/events_fifo.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/drivers/xen/events/events_fifo.c +++ b/drivers/xen/events/events_fifo.c @@ -227,19 +227,25 @@ static bool evtchn_fifo_is_masked(unsign return sync_test_bit(EVTCHN_FIFO_BIT(MASKED, word), BM(word)); } /* - * Clear MASKED, spinning if BUSY is set. + * Clear MASKED if not PENDING, spinning if BUSY is set. + * Return true if mask was cleared. */ -static void clear_masked(volatile event_word_t *word) +static bool clear_masked_cond(volatile event_word_t *word) { event_word_t new, old, w; w = *word; do { + if (w & (1 << EVTCHN_FIFO_PENDING)) + return false; + old = w & ~(1 << EVTCHN_FIFO_BUSY); new = old & ~(1 << EVTCHN_FIFO_MASKED); w = sync_cmpxchg(word, old, new); } while (w != old); + + return true; } static void evtchn_fifo_unmask(unsigned port) @@ -248,8 +254,7 @@ static void evtchn_fifo_unmask(unsigned BUG_ON(!irqs_disabled()); - clear_masked(word); - if (evtchn_fifo_is_pending(port)) { + if (!clear_masked_cond(word)) { struct evtchn_unmask unmask = { .port = port }; (void)HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &unmask); } Patches currently in stable-queue which might be from jgross@xxxxxxxx are queue-4.4/xen-blkback-use-lateeoi-irq-binding.patch queue-4.4/xen-events-block-rogue-events-for-some-time.patch queue-4.4/xen-events-fix-race-in-evtchn_fifo_unmask.patch queue-4.4/xen-events-switch-user-event-channels-to-lateeoi-model.patch queue-4.4/xen-events-defer-eoi-in-case-of-excessive-number-of-events.patch queue-4.4/xen-events-add-a-new-late-eoi-evtchn-framework.patch queue-4.4/xen-events-use-a-common-cpu-hotplug-hook-for-event-channels.patch queue-4.4/xen-events-avoid-removing-an-event-channel-while-handling-it.patch queue-4.4/xen-netback-use-lateeoi-irq-binding.patch queue-4.4/xen-pciback-use-lateeoi-irq-binding.patch queue-4.4/xen-events-add-a-proper-barrier-to-2-level-uevent-unmasking.patch queue-4.4/xen-scsiback-use-lateeoi-irq-binding.patch