From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: "Juergen Gross" <jgross@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>
Subject: [PATCH v7 1/7] xen/events: fix race with set_global_virq_handler()
Date: Thu, 9 Jan 2025 11:59:29 +0100 [thread overview]
Message-ID: <20250109105935.23585-2-jgross@suse.com> (raw)
In-Reply-To: <20250109105935.23585-1-jgross@suse.com>
There is a possible race scenario between set_global_virq_handler()
and clear_global_virq_handlers() targeting the same domain, which
might result in that domain ending as a zombie domain.
In case set_global_virq_handler() is being called for a domain which
is just dying, it might happen that clear_global_virq_handlers() is
running first, resulting in set_global_virq_handler() taking a new
reference for that domain and entering in the global_virq_handlers[]
array afterwards. The reference will never be dropped, thus the domain
will never be freed completely.
This can be fixed by checking the is_dying state of the domain inside
the region guarded by global_virq_handlers_lock. In case the domain is
dying, handle it as if the domain wouldn't exist, which will be the
case in near future anyway.
Fixes: 87521589aa6a ("xen: allow global VIRQ handlers to be delegated to other domains")
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V6:
- new patch
V7:
- add comment (Jan Beulich)
---
xen/common/event_channel.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 8db2ca4ba2..46281b16ce 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -979,6 +979,7 @@ void send_global_virq(uint32_t virq)
int set_global_virq_handler(struct domain *d, uint32_t virq)
{
struct domain *old;
+ int rc = 0;
if (virq >= NR_VIRQS)
return -EINVAL;
@@ -992,14 +993,32 @@ int set_global_virq_handler(struct domain *d, uint32_t virq)
return -EINVAL;
spin_lock(&global_virq_handlers_lock);
- old = global_virq_handlers[virq];
- global_virq_handlers[virq] = d;
+
+ /*
+ * Note that this check won't guarantee that a domain just going down can't
+ * be set as the handling domain of a virq, as the is_dying indicator might
+ * change just after testing it.
+ * This isn't going to be a major problem, as clear_global_virq_handlers()
+ * is guaranteed to run afterwards and it will reset the handling domain
+ * for the virq to the hardware domain.
+ */
+ if ( d->is_dying != DOMDYING_alive )
+ {
+ old = d;
+ rc = -EINVAL;
+ }
+ else
+ {
+ old = global_virq_handlers[virq];
+ global_virq_handlers[virq] = d;
+ }
+
spin_unlock(&global_virq_handlers_lock);
if (old != NULL)
put_domain(old);
- return 0;
+ return rc;
}
static void clear_global_virq_handlers(struct domain *d)
--
2.43.0
next prev parent reply other threads:[~2025-01-09 10:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 10:59 [PATCH v7 0/7] remove libxenctrl usage from xenstored Juergen Gross
2025-01-09 10:59 ` Juergen Gross [this message]
2025-01-09 15:46 ` [PATCH v7 1/7] xen/events: fix race with set_global_virq_handler() Jan Beulich
2025-01-09 10:59 ` [PATCH v7 2/7] xen/events: don't allow binding a global virq from any domain Juergen Gross
2025-01-09 10:59 ` [PATCH v7 3/7] xen/events: allow setting of global virq handler only for unbound virqs Juergen Gross
2025-01-09 10:59 ` [PATCH v7 4/7] xen: add bitmap to indicate per-domain state changes Juergen Gross
2025-01-09 15:49 ` Jan Beulich
2025-01-09 10:59 ` [PATCH v7 5/7] xen: add new domctl get_changed_domain Juergen Gross
2025-01-09 15:50 ` Jan Beulich
2025-01-09 10:59 ` [PATCH v7 6/7] tools/libs: add a new libxenmanage library Juergen Gross
2025-01-09 10:59 ` [PATCH v7 7/7] tools/xenstored: use new stable interface instead of libxenctrl Juergen Gross
2025-01-16 13:44 ` Anthony PERARD
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=20250109105935.23585-2-jgross@suse.com \
--to=jgross@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.