Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: stable@vger.kernel.org
Subject: [PATCH v2 04/14] xen/events: fix race in evtchn_fifo_unmask()
Date: Tue,  3 Nov 2020 15:19:12 +0100	[thread overview]
Message-ID: <20201103141922.21026-5-jgross@suse.com> (raw)
In-Reply-To: <20201103141922.21026-1-jgross@suse.com>

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.

This is upstream commit f01337197419b7e8a492e83089552b77d3b5fb90

Cc: stable@vger.kernel.org
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
 drivers/xen/events/events_fifo.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/xen/events/events_fifo.c b/drivers/xen/events/events_fifo.c
index 76b318e88382..3071256a9413 100644
--- a/drivers/xen/events/events_fifo.c
+++ b/drivers/xen/events/events_fifo.c
@@ -227,19 +227,25 @@ static bool evtchn_fifo_is_masked(unsigned port)
 	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 port)
 
 	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);
 	}
-- 
2.26.2


  parent reply	other threads:[~2020-11-03 14:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-03 14:19 [PATCH v2 00/14] Backport of patch series for stable 4.19 branch Juergen Gross
2020-11-03 14:19 ` [PATCH v2 01/14] xen/events: don't use chip_data for legacy IRQs Juergen Gross
2020-11-03 14:19 ` [PATCH v2 02/14] xen/events: avoid removing an event channel while handling it Juergen Gross
2020-11-03 14:19 ` [PATCH v2 03/14] xen/events: add a proper barrier to 2-level uevent unmasking Juergen Gross
2020-11-03 14:19 ` Juergen Gross [this message]
2020-11-03 14:19 ` [PATCH v2 05/14] xen/events: add a new "late EOI" evtchn framework Juergen Gross
2020-11-03 14:19 ` [PATCH v2 06/14] xen/blkback: use lateeoi irq binding Juergen Gross
2020-11-03 14:19 ` [PATCH v2 07/14] xen/netback: " Juergen Gross
2020-11-03 14:19 ` [PATCH v2 08/14] xen/scsiback: " Juergen Gross
2020-11-03 14:19 ` [PATCH v2 09/14] xen/pvcallsback: " Juergen Gross
2020-11-03 14:19 ` [PATCH v2 10/14] xen/pciback: " Juergen Gross
2020-11-03 14:19 ` [PATCH v2 11/14] xen/events: switch user event channels to lateeoi model Juergen Gross
2020-11-03 14:19 ` [PATCH v2 12/14] xen/events: use a common cpu hotplug hook for event channels Juergen Gross
2020-11-03 14:19 ` [PATCH v2 13/14] xen/events: defer eoi in case of excessive number of events Juergen Gross
2020-11-03 14:19 ` [PATCH v2 14/14] xen/events: block rogue events for some time Juergen Gross
2020-11-03 16:21 ` [PATCH v2 00/14] Backport of patch series for stable 4.19 branch Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2020-11-03 14:28 [PATCH v2 00/14] Backport of patch series for stable 4.14 branch Juergen Gross
2020-11-03 14:29 ` [PATCH v2 04/14] xen/events: fix race in evtchn_fifo_unmask() Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201103141922.21026-5-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox