All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jürgen Groß" <jgross@suse.com>
To: Julien Grall <julien@xen.org>, xen-devel@lists.xenproject.org
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Anthony PERARD" <anthony.perard@vates.tech>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>
Subject: Re: [PATCH v8 1/9] xen/events: don't allow binding a global virq from any domain
Date: Tue, 11 Mar 2025 10:51:13 +0100	[thread overview]
Message-ID: <e6352575-c2cb-4616-b305-1cd64480de1a@suse.com> (raw)
In-Reply-To: <24a909a8-c6a9-4c09-b819-24c10e0762c3@xen.org>


[-- Attachment #1.1.1: Type: text/plain, Size: 3518 bytes --]

On 11.03.25 10:35, Julien Grall wrote:
> Hi Juergen,
> 
> On 04/02/2025 11:33, Juergen Gross wrote:
>> Today Xen will happily allow binding a global virq by a domain which
>> isn't configured to receive it. This won't result in any bad actions,
>> but the bind will appear to have succeeded with no event ever being
>> received by that event channel.
>>
>> Instead of allowing the bind, error out if the domain isn't set to
>> handle that virq. Note that this check is inside the write_lock() on
>> purpose, as a future patch will put a related check into
>> set_global_virq_handler() with the addition of using the same lock.
>  > > Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> I see this patch was already committed. But I have a question about the logic.
> 
>> ---
>> V6:
>> - new patch
>> V7:
>> - move handling domain check inside locked region (Jan Beulich)
>> - style fix (Jan Beulich)
>> ---
>>   xen/common/event_channel.c | 21 +++++++++++++++++----
>>   1 file changed, 17 insertions(+), 4 deletions(-)
>>
>> diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
>> index 46281b16ce..cd6f5a1211 100644
>> --- a/xen/common/event_channel.c
>> +++ b/xen/common/event_channel.c
>> @@ -120,6 +120,13 @@ static uint8_t 
>> get_xen_consumer(xen_event_channel_notification_t fn)
>>   /* Get the notification function for a given Xen-bound event channel. */
>>   #define xen_notification_fn(e) (xen_consumers[(e)->xen_consumer-1])
>> +static struct domain *__read_mostly global_virq_handlers[NR_VIRQS];
>> +
>> +static struct domain *get_global_virq_handler(unsigned int virq)
>> +{
>> +    return global_virq_handlers[virq] ?: hardware_domain;
>> +}
>> +
>>   static bool virq_is_global(unsigned int virq)
>>   {
>>       switch ( virq )
>> @@ -469,6 +476,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, 
>> evtchn_port_t port)
>>       struct domain *d = current->domain;
>>       int            virq = bind->virq, vcpu = bind->vcpu;
>>       int            rc = 0;
>> +    bool           is_global;
>>       if ( (virq < 0) || (virq >= ARRAY_SIZE(v->virq_to_evtchn)) )
>>           return -EINVAL;
>> @@ -478,8 +486,9 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, 
>> evtchn_port_t port)
>>       * speculative execution.
>>       */
>>       virq = array_index_nospec(virq, ARRAY_SIZE(v->virq_to_evtchn));
>> +    is_global = virq_is_global(virq);
>> -    if ( virq_is_global(virq) && (vcpu != 0) )
>> +    if ( is_global && vcpu != 0 )
>>           return -EINVAL;
>>       if ( (v = domain_vcpu(d, vcpu)) == NULL )
>> @@ -487,6 +496,12 @@ int evtchn_bind_virq(evtchn_bind_virq_t *bind, 
>> evtchn_port_t port)
>>       write_lock(&d->event_lock);
>> +    if ( is_global && get_global_virq_handler(virq) != d )
> 
> What prevent a race between get_global_virq_handler() and 
> set_global_virq_handler()? Also, it is not clear in the implementation of 
> get_global_virq_handler() that it will ever only read global_virq_handlers[virq] 
> once.

set_global_virq_handler() is taking the event_lock of the domain
registered as handler.

So if a domain is registered for handling a virq, d->event_lock is
protecting against the handling domain to be changed. Concurrent
calls of set_global_virq_handler() are handled via taking the
global_virq_handlers_lock spin_lock.


Juergen

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

  reply	other threads:[~2025-03-11  9:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-04 11:33 [PATCH v8 0/9] remove libxenctrl usage from xenstored Juergen Gross
2025-02-04 11:33 ` [PATCH v8 1/9] xen/events: don't allow binding a global virq from any domain Juergen Gross
2025-03-11  9:35   ` Julien Grall
2025-03-11  9:51     ` Jürgen Groß [this message]
2025-03-11 19:04       ` Julien Grall
2025-03-12  7:05         ` Jürgen Groß
2025-02-04 11:34 ` [PATCH v8 2/9] xen/events: allow setting of global virq handler only for unbound virqs Juergen Gross
2025-02-04 11:34 ` [PATCH v8 3/9] xen: add bitmap to indicate per-domain state changes Juergen Gross
2025-03-06 15:41   ` Jan Beulich
2025-03-06 15:52     ` Jürgen Groß
2025-02-04 11:34 ` [PATCH v8 4/9] xen: add new domctl get_changed_domain Juergen Gross
2025-02-04 11:34 ` [PATCH v8 5/9] tools/libs: add a new libxenmanage library Juergen Gross
2025-02-04 11:34 ` [PATCH v8 6/9] tools/xenstored: use new stable interface instead of libxenctrl Juergen Gross
2025-02-04 11:34 ` [PATCH v8 7/9] docs: update xenstore migration stream definition Juergen Gross
2025-03-11  9:43   ` Julien Grall
2025-03-11  9:58     ` Jürgen Groß
2025-03-11 18:52       ` Julien Grall
2025-02-04 11:34 ` [PATCH v8 8/9] tools/xenstored: use unique_id to identify new domain with same domid Juergen Gross
2025-03-12 17:40   ` Jason Andryuk
2025-03-13  9:52     ` Jürgen Groß
2025-02-04 11:34 ` [PATCH v8 9/9] tools/xenstored: use xenmanage_poll_changed_domain() Juergen Gross
2025-03-12 17:45   ` Jason Andryuk
2025-03-13  9:53     ` Jürgen Groß
2025-02-25 11:10 ` [PATCH v8 0/9] remove libxenctrl usage from xenstored Juergen Gross
2025-03-05  8:23   ` Juergen Gross
2025-03-05 23:32     ` Stefano Stabellini
2025-03-06 13:13       ` Jan Beulich
2025-03-06 13:27         ` Jürgen Groß
2025-03-06 13:53           ` Jan Beulich
2025-03-06 13:56             ` Jürgen Groß

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=e6352575-c2cb-4616-b305-1cd64480de1a@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.