xen-devel.lists.xenproject.org archive mirror
 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>,
	George Dunlap <george.dunlap@citrix.com>,
	Ian Jackson <iwj@xenproject.org>, Jan Beulich <jbeulich@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>
Subject: Re: [PATCH v8 2/3] xen/events: rework fifo queue locking
Date: Fri, 27 Nov 2020 15:05:44 +0100	[thread overview]
Message-ID: <2b099865-647c-3d47-1510-d429c2a4b6c6@suse.com> (raw)
In-Reply-To: <e60e4fce-8c1b-013a-9ec2-20bd2c930619@xen.org>


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

On 27.11.20 14:58, Julien Grall wrote:
> Hi Juergen,
> 
> On 25/11/2020 10:51, Juergen Gross wrote:
>> -static struct evtchn_fifo_queue *lock_old_queue(const struct domain *d,
>> -                                                struct evtchn *evtchn,
>> -                                                unsigned long *flags)
>> -{
>> -    struct vcpu *v;
>> -    struct evtchn_fifo_queue *q, *old_q;
>> -    unsigned int try;
>> -    union evtchn_fifo_lastq lastq;
>> -
>> -    for ( try = 0; try < 3; try++ )
>> -    {
>> -        lastq.raw = read_atomic(&evtchn->fifo_lastq);
>> -        v = d->vcpu[lastq.last_vcpu_id];
>> -        old_q = &v->evtchn_fifo->queue[lastq.last_priority];
>> -
>> -        spin_lock_irqsave(&old_q->lock, *flags);
>> -
>> -        v = d->vcpu[lastq.last_vcpu_id];
>> -        q = &v->evtchn_fifo->queue[lastq.last_priority];
>> -
>> -        if ( old_q == q )
>> -            return old_q;
>> -
>> -        spin_unlock_irqrestore(&old_q->lock, *flags);
>> -    }
>> -
>> -    gprintk(XENLOG_WARNING,
>> -            "dom%d port %d lost event (too many queue changes)\n",
>> -            d->domain_id, evtchn->port);
>> -    return NULL;
>> -}
>> -
>>   static int try_set_link(event_word_t *word, event_word_t *w, 
>> uint32_t link)
>>   {
>>       event_word_t new, old;
>> @@ -190,6 +158,9 @@ static void evtchn_fifo_set_pending(struct vcpu 
>> *v, struct evtchn *evtchn)
>>       event_word_t *word;
>>       unsigned long flags;
>>       bool_t was_pending;
>> +    struct evtchn_fifo_queue *q, *old_q;
>> +    unsigned int try;
>> +    bool linked = true;
>>       port = evtchn->port;
>>       word = evtchn_fifo_word_from_port(d, port);
>> @@ -204,17 +175,67 @@ static void evtchn_fifo_set_pending(struct vcpu 
>> *v, struct evtchn *evtchn)
>>           return;
>>       }
>> +    /*
>> +     * Lock all queues related to the event channel (in case of a 
>> queue change
>> +     * this might be two).
>> +     * It is mandatory to do that before setting and testing the 
>> PENDING bit
>> +     * and to hold the current queue lock until the event has put 
>> into the
>> +     * list of pending events in order to avoid waking up a guest 
>> without the
>> +     * event being visibly pending in the guest.
>> +     */
>> +    for ( try = 0; try < 4; try++ )
> 
> May I ask why the number of try is 4 rather than the original 3?

Oh, I think this is just a typo. OTOH it doesn't really matter.

> 
>> +    {
>> +        union evtchn_fifo_lastq lastq;
>> +        const struct vcpu *old_v;
>> +
>> +        lastq.raw = read_atomic(&evtchn->fifo_lastq);
>> +        old_v = d->vcpu[lastq.last_vcpu_id];
>> +
>> +        q = &v->evtchn_fifo->queue[evtchn->priority];
>> +        old_q = &old_v->evtchn_fifo->queue[lastq.last_priority];
>> +
>> +        if ( q == old_q )
>> +            spin_lock_irqsave(&q->lock, flags);
>> +        else if ( q < old_q )
>> +        {
>> +            spin_lock_irqsave(&q->lock, flags);
>> +            spin_lock(&old_q->lock);
>> +        }
>> +        else
>> +        {
>> +            spin_lock_irqsave(&old_q->lock, flags);
>> +            spin_lock(&q->lock);
>> +        }
>> +
>> +        lastq.raw = read_atomic(&evtchn->fifo_lastq);
>> +        old_v = d->vcpu[lastq.last_vcpu_id];
>> +        if ( q == &v->evtchn_fifo->queue[evtchn->priority] &&
>> +             old_q == &old_v->evtchn_fifo->queue[lastq.last_priority] )
>> +            break;
>> +
>> +        if ( q != old_q )
>> +            spin_unlock(&old_q->lock);
>> +        spin_unlock_irqrestore(&q->lock, flags);
>> +    }
>> +
>>       was_pending = guest_test_and_set_bit(d, EVTCHN_FIFO_PENDING, word);
>> +    /* If we didn't get the lock bail out. */
>> +    if ( try == 4 )
>> +    {
>> +        gprintk(XENLOG_WARNING,
>> +                "dom%d port %d lost event (too many queue changes)\n",
>> +                d->domain_id, evtchn->port);
> 
> NIT: You can use %pd use in place of dom%d.

Yes, indeed. This was just moved around. :-)


Juergen

[-- Attachment #1.1.2: OpenPGP_0xB0DE9DD628BF132F.asc --]
[-- Type: application/pgp-keys, Size: 3135 bytes --]

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

  parent reply	other threads:[~2020-11-27 14:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25 10:51 [PATCH v8 0/3] xen/events: further locking adjustments Juergen Gross
2020-11-25 10:51 ` [PATCH v8 1/3] xen/events: modify struct evtchn layout Juergen Gross
2020-11-27 11:42   ` Jan Beulich
2020-11-27 11:57     ` Julien Grall
2020-11-27 12:41       ` Jan Beulich
2020-11-25 10:51 ` [PATCH v8 2/3] xen/events: rework fifo queue locking Juergen Gross
2020-11-27 13:11   ` Jan Beulich
2020-11-27 13:31     ` Jürgen Groß
2020-11-27 13:58   ` Julien Grall
2020-11-27 14:03     ` Jan Beulich
2020-11-27 14:05     ` Jürgen Groß [this message]
2020-11-27 14:11       ` Julien Grall
2020-11-27 14:14         ` Jürgen Groß
2020-11-27 14:26           ` Julien Grall
2020-11-25 10:51 ` [PATCH v8 3/3] xen/events: do some cleanups in evtchn_fifo_set_pending() Juergen Gross
2020-11-27 13:27   ` Jan Beulich
2020-11-27 13:52     ` Jürgen Groß
2020-11-27 14:23   ` Julien Grall
2020-11-27 14:39     ` Jürgen Groß
2020-11-27 14:48       ` Jan Beulich
2020-11-27 15:17         ` Julien Grall
2020-11-27 15:36           ` Jan Beulich
2020-11-27 14:50       ` Julien Grall

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=2b099865-647c-3d47-1510-d429c2a4b6c6@suse.com \
    --to=jgross@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=iwj@xenproject.org \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).