[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 8/8] xen/evtchn: use READ/WRITE_ONCE() for accessing ring indices


  • To: Juergen Gross <jgross@xxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <linux-kernel@xxxxxxxxxxxxxxx>
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Wed, 17 Feb 2021 13:29:19 +0000
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Wed, 17 Feb 2021 13:29:22 +0000
  • Ironport-sdr: o7LaJcbQT5QuBw1xPwkFm1kmmIpHK9sbb9lZj5IyJs4mA6AKdPwwmE6rjsZVBkmNqq+f1rg7v9 LhPjd42AWS+GmnJwjqQu2oMcrOsirvyJVxH5cCnpbZzFpjLStPB9qB5/CJH5wL2kyX3hIiHH41 BiJdvO1WYeF49G5IAxgFWe2Doce5WdQcFnPhB0gMWpqLGNUyZ04XS+fO43Jds6xWB/x8VdXjLc TVqBAY/waBGvsB5Nt+Gp+8G4G7JcUyHaEeserRUmk28EhENWIwM7fRM4ds93N++2/jeX9TnB7a ItU=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxx>
> ---
> 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



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.