From: Julien Grall <julien@xen.org>
To: Jan Beulich <jbeulich@suse.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Ian Jackson <iwj@xenproject.org>, Wei Liu <wl@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v3 2/5] evtchn: avoid access tearing for ->virq_to_evtchn[] accesses
Date: Wed, 2 Dec 2020 21:14:32 +0000 [thread overview]
Message-ID: <dae588c9-69ab-36f8-f945-b9f6fb0cb14d@xen.org> (raw)
In-Reply-To: <ce6ce543-d57a-4111-2e66-871c4f4633a8@suse.com>
Hi Jan,
On 23/11/2020 13:28, Jan Beulich wrote:
> Use {read,write}_atomic() to exclude any eventualities, in particular
> observing that accesses aren't all happening under a consistent lock.
>
> Requested-by: Julien Grall <julien@xen.org>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
Cheers,
> ---
> v3: New.
>
> --- a/xen/common/event_channel.c
> +++ b/xen/common/event_channel.c
> @@ -446,7 +446,7 @@ int evtchn_bind_virq(evtchn_bind_virq_t
>
> spin_lock(&d->event_lock);
>
> - if ( v->virq_to_evtchn[virq] != 0 )
> + if ( read_atomic(&v->virq_to_evtchn[virq]) )
> ERROR_EXIT(-EEXIST);
>
> if ( port != 0 )
> @@ -474,7 +474,8 @@ int evtchn_bind_virq(evtchn_bind_virq_t
>
> evtchn_write_unlock(chn);
>
> - v->virq_to_evtchn[virq] = bind->port = port;
> + bind->port = port;
> + write_atomic(&v->virq_to_evtchn[virq], port);
>
> out:
> spin_unlock(&d->event_lock);
> @@ -660,9 +661,9 @@ int evtchn_close(struct domain *d1, int
> case ECS_VIRQ:
> for_each_vcpu ( d1, v )
> {
> - if ( v->virq_to_evtchn[chn1->u.virq] != port1 )
> + if ( read_atomic(&v->virq_to_evtchn[chn1->u.virq]) != port1 )
> continue;
> - v->virq_to_evtchn[chn1->u.virq] = 0;
> + write_atomic(&v->virq_to_evtchn[chn1->u.virq], 0);
> spin_barrier(&v->virq_lock);
> }
> break;
> @@ -801,7 +802,7 @@ bool evtchn_virq_enabled(const struct vc
> if ( virq_is_global(virq) && v->vcpu_id )
> v = domain_vcpu(v->domain, 0);
>
> - return v->virq_to_evtchn[virq];
> + return read_atomic(&v->virq_to_evtchn[virq]);
> }
>
> void send_guest_vcpu_virq(struct vcpu *v, uint32_t virq)
> @@ -814,7 +815,7 @@ void send_guest_vcpu_virq(struct vcpu *v
>
> spin_lock_irqsave(&v->virq_lock, flags);
>
> - port = v->virq_to_evtchn[virq];
> + port = read_atomic(&v->virq_to_evtchn[virq]);
> if ( unlikely(port == 0) )
> goto out;
>
> @@ -843,7 +844,7 @@ void send_guest_global_virq(struct domai
>
> spin_lock_irqsave(&v->virq_lock, flags);
>
> - port = v->virq_to_evtchn[virq];
> + port = read_atomic(&v->virq_to_evtchn[virq]);
> if ( unlikely(port == 0) )
> goto out;
>
>
--
Julien Grall
next prev parent reply other threads:[~2020-12-02 21:14 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-23 13:26 [PATCH v3 0/5] evtchn: (not so) recent XSAs follow-on Jan Beulich
2020-11-23 13:28 ` [PATCH v3 1/5] evtchn: drop acquiring of per-channel lock from send_guest_{global,vcpu}_virq() Jan Beulich
2020-12-02 19:03 ` Julien Grall
2020-12-03 9:46 ` Jan Beulich
2020-12-09 9:53 ` Julien Grall
2020-12-09 14:24 ` Jan Beulich
2020-11-23 13:28 ` [PATCH v3 2/5] evtchn: avoid access tearing for ->virq_to_evtchn[] accesses Jan Beulich
2020-12-02 21:14 ` Julien Grall [this message]
2020-11-23 13:28 ` [PATCH v3 3/5] evtchn: convert vIRQ lock to an r/w one Jan Beulich
2020-12-09 11:16 ` Julien Grall
2020-11-23 13:29 ` [PATCH v3 4/5] evtchn: convert domain event " Jan Beulich
2020-12-09 11:54 ` Julien Grall
2020-12-11 10:32 ` Jan Beulich
2020-12-11 10:57 ` Julien Grall
2020-12-14 9:40 ` Jan Beulich
2020-12-21 17:45 ` Julien Grall
2020-12-22 9:46 ` Jan Beulich
2020-12-23 11:22 ` Julien Grall
2020-12-23 12:57 ` Jan Beulich
2020-12-23 13:19 ` Julien Grall
2020-12-23 13:36 ` Jan Beulich
2020-11-23 13:30 ` [PATCH v3 5/5] evtchn: don't call Xen consumer callback with per-channel lock held Jan Beulich
2020-11-30 10:39 ` Isaila Alexandru
2020-12-02 21:10 ` Julien Grall
2020-12-03 10:09 ` Jan Beulich
2020-12-03 14:40 ` Tamas K Lengyel
2020-12-04 11:28 ` Julien Grall
2020-12-04 11:48 ` Jan Beulich
2020-12-04 11:51 ` Julien Grall
2020-12-04 12:01 ` Jan Beulich
2020-12-04 15:09 ` Julien Grall
2020-12-07 8:02 ` Jan Beulich
2020-12-07 17:22 ` Julien Grall
2020-12-04 15:21 ` Tamas K Lengyel
2020-12-04 15:29 ` Julien Grall
2020-12-04 19:15 ` Tamas K Lengyel
2020-12-04 19:22 ` Julien Grall
2020-12-04 21:23 ` Tamas K Lengyel
2020-12-07 15:28 ` Jan Beulich
2020-12-07 17:30 ` Julien Grall
2020-12-07 17:35 ` Tamas K Lengyel
2020-12-23 13:12 ` Jan Beulich
2020-12-23 13:33 ` Julien Grall
2020-12-23 13:41 ` Jan Beulich
2020-12-23 14:44 ` Julien Grall
2020-12-23 14:56 ` Jan Beulich
2020-12-23 15:08 ` Julien Grall
2020-12-23 15:15 ` Tamas K Lengyel
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=dae588c9-69ab-36f8-f945-b9f6fb0cb14d@xen.org \
--to=julien@xen.org \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=iwj@xenproject.org \
--cc=jbeulich@suse.com \
--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).