All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ross Lagerwall <ross.lagerwall@citrix.com>
To: Juergen Gross <jgross@suse.com>, <xen-devel@lists.xenproject.org>,
	<linux-kernel@vger.kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Stefano Stabellini <sstabellini@kernel.org>
Subject: Re: [PATCH v2 8/8] xen/evtchn: use READ/WRITE_ONCE() for accessing ring indices
Date: Wed, 17 Feb 2021 13:29:19 +0000	[thread overview]
Message-ID: <6818fcde-abab-1250-119c-d0ccb8c80488@citrix.com> (raw)
In-Reply-To: <20210211101616.13788-9-jgross@suse.com>

On 2021-02-11 10:16, Juergen Gross wrote:
> For avoiding read- and write-tearing by the compiler use READ_ONCE()
> and WRITE_ONCE() for accessing the ring indices in evtchn.c.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> V2:
> - modify all accesses (Julien Grall)
> ---
>  drivers/xen/evtchn.c | 25 ++++++++++++++++---------
>  1 file changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
> index 421382c73d88..620008f89dbe 100644
> --- a/drivers/xen/evtchn.c
> +++ b/drivers/xen/evtchn.c
> @@ -162,6 +162,7 @@ static irqreturn_t evtchn_interrupt(int irq, void *data)
>  {
>  	struct user_evtchn *evtchn = data;
>  	struct per_user_data *u = evtchn->user;
> +	unsigned int prod, cons;
>  
>  	WARN(!evtchn->enabled,
>  	     "Interrupt for port %u, but apparently not enabled; per-user %p\n",
> @@ -171,10 +172,14 @@ static irqreturn_t evtchn_interrupt(int irq, void *data)
>  
>  	spin_lock(&u->ring_prod_lock);
>  
> -	if ((u->ring_prod - u->ring_cons) < u->ring_size) {
> -		*evtchn_ring_entry(u, u->ring_prod) = evtchn->port;
> +	prod = READ_ONCE(u->ring_prod);
> +	cons = READ_ONCE(u->ring_cons);
> +
> +	if ((prod - cons) < u->ring_size) {
> +		*evtchn_ring_entry(u, prod) = evtchn->port;
>  		smp_wmb(); /* Ensure ring contents visible */
> -		if (u->ring_cons == u->ring_prod++) {
> +		if (cons == prod++) {
> +			WRITE_ONCE(u->ring_prod, prod);
>  			wake_up_interruptible(&u->evtchn_wait);
>  			kill_fasync(&u->evtchn_async_queue,
>  				    SIGIO, POLL_IN);

This doesn't work correctly since now u->ring_prod is only updated if cons == prod++.

Ross

  reply	other threads:[~2021-02-17 13:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 10:16 [PATCH v2 0/8] xen/events: bug fixes and some diagnostic aids Juergen Gross
2021-02-11 10:16 ` [PATCH v2 1/8] xen/events: reset affinity of 2-level event when tearing it down Juergen Gross
2021-02-14 21:17   ` Julien Grall
2021-02-11 10:16 ` [PATCH v2 2/8] xen/events: don't unmask an event channel when an eoi is pending Juergen Gross
2021-02-11 10:16 ` [PATCH v2 3/8] xen/events: avoid handling the same event on two cpus at the same time Juergen Gross
2021-02-14 21:34   ` Julien Grall
2021-02-15  6:55     ` Jürgen Groß
2021-02-15 21:35   ` Boris Ostrovsky
2021-02-18 11:47     ` Jürgen Groß
2021-02-11 10:16 ` [PATCH v2 4/8] xen/netback: fix spurious event detection for common event case Juergen Gross
2021-02-11 10:53   ` Jan Beulich
2021-02-11 14:15   ` Paul Durrant
2021-02-11 15:24   ` Wei Liu
2021-02-11 10:16 ` [PATCH v2 5/8] xen/events: link interdomain events to associated xenbus device Juergen Gross
2021-02-11 14:16   ` Paul Durrant
2021-02-11 10:16 ` [PATCH v2 6/8] xen/events: add per-xenbus device event statistics and settings Juergen Gross
2021-02-15 21:54   ` Boris Ostrovsky
2021-02-11 10:16 ` [PATCH v2 7/8] xen/evtch: use smp barriers for user event ring Juergen Gross
2021-02-11 10:16 ` [PATCH v2 8/8] xen/evtchn: use READ/WRITE_ONCE() for accessing ring indices Juergen Gross
2021-02-17 13:29   ` Ross Lagerwall [this message]
2021-02-18 11:46     ` 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=6818fcde-abab-1250-119c-d0ccb8c80488@citrix.com \
    --to=ross.lagerwall@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --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.